]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c
OvmfPkg/QemuFwCfgLib: move InternalQemuFwCfgIsAvailable() to lib instances
[mirror_edk2.git] / OvmfPkg / Library / QemuFwCfgLib / QemuFwCfgPeiDxe.c
1 /** @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
20 #include "QemuFwCfgLibInternal.h"
21
22 STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
23
24
25 /**
26 Returns a boolean indicating if the firmware configuration interface
27 is available or not.
28
29 This function may change fw_cfg state.
30
31 @retval TRUE The interface is available
32 @retval FALSE The interface is not available
33
34 **/
35 BOOLEAN
36 EFIAPI
37 QemuFwCfgIsAvailable (
38 VOID
39 )
40 {
41 return InternalQemuFwCfgIsAvailable ();
42 }
43
44
45 RETURN_STATUS
46 EFIAPI
47 QemuFwCfgInitialize (
48 VOID
49 )
50 {
51 UINT32 Signature;
52 UINT32 Revision;
53
54 //
55 // Enable the access routines while probing to see if it is supported.
56 //
57 mQemuFwCfgSupported = TRUE;
58
59 QemuFwCfgSelectItem (QemuFwCfgItemSignature);
60 Signature = QemuFwCfgRead32 ();
61 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));
62 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
63 Revision = QemuFwCfgRead32 ();
64 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));
65 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
66 (Revision < 1)
67 ) {
68 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));
69 mQemuFwCfgSupported = FALSE;
70 return RETURN_SUCCESS;
71 }
72
73 DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));
74 return RETURN_SUCCESS;
75 }
76
77
78 /**
79 Returns a boolean indicating if the firmware configuration interface is
80 available for library-internal purposes.
81
82 This function never changes fw_cfg state.
83
84 @retval TRUE The interface is available internally.
85 @retval FALSE The interface is not available internally.
86 **/
87 BOOLEAN
88 InternalQemuFwCfgIsAvailable (
89 VOID
90 )
91 {
92 return mQemuFwCfgSupported;
93 }