blob: f693cff29e012c03a960e274f57ae4e52047690f [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @file
2
3 Stateful and implicitly initialized fw_cfg library implementation.
4
5 Copyright (C) 2013, Red Hat, Inc.
6 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
7
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15**/
16
17#include <Library/DebugLib.h>
18#include <Library/QemuFwCfgLib.h>
19
20STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
21
22
23/**
24 Returns a boolean indicating if the firmware configuration interface
25 is available or not.
26
27 This function may change fw_cfg state.
28
29 @retval TRUE The interface is available
30 @retval FALSE The interface is not available
31
32**/
33BOOLEAN
34EFIAPI
35QemuFwCfgIsAvailable (
36 VOID
37 )
38{
39 return InternalQemuFwCfgIsAvailable ();
40}
41
42
43RETURN_STATUS
44EFIAPI
45QemuFwCfgInitialize (
46 VOID
47 )
48{
49 UINT32 Signature;
50 UINT32 Revision;
51
52 //
53 // Enable the access routines while probing to see if it is supported.
54 //
55 mQemuFwCfgSupported = TRUE;
56
57 QemuFwCfgSelectItem (QemuFwCfgItemSignature);
58 Signature = QemuFwCfgRead32 ();
59 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
60 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
61 Revision = QemuFwCfgRead32 ();
62 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
63 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
64 (Revision < 1)
65 ) {
66 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
67 mQemuFwCfgSupported = FALSE;
68 return RETURN_SUCCESS;
69 }
70
71 DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
72 return RETURN_SUCCESS;
73}
74
75
76/**
77 Returns a boolean indicating if the firmware configuration interface is
78 available for library-internal purposes.
79
80 This function never changes fw_cfg state.
81
82 @retval TRUE The interface is available internally.
83 @retval FALSE The interface is not available internally.
84**/
85BOOLEAN
86EFIAPI
87InternalQemuFwCfgIsAvailable (
88 VOID
89 )
90{
91 return mQemuFwCfgSupported;
92}