]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiDxe.c
OvmfPkg: Modify QemuFwCfgLib to use new IoLib class library
[mirror_edk2.git] / OvmfPkg / Library / QemuFwCfgLib / QemuFwCfgPeiDxe.c
CommitLineData
2ce7e221
LE
1/** @file\r
2\r
3 Stateful and implicitly initialized fw_cfg library implementation.\r
4\r
5 Copyright (C) 2013, Red Hat, Inc.\r
6 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
7\r
8 This program and the accompanying materials are licensed and made available\r
9 under the terms and conditions of the BSD License which accompanies this\r
10 distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15**/\r
16\r
17#include <Library/DebugLib.h>\r
18#include <Library/QemuFwCfgLib.h>\r
19\r
5297c0bf
LE
20#include "QemuFwCfgLibInternal.h"\r
21\r
2ce7e221 22STATIC BOOLEAN mQemuFwCfgSupported = FALSE;\r
2c8dcbc6 23STATIC BOOLEAN mQemuFwCfgDmaSupported;\r
2ce7e221
LE
24\r
25\r
26/**\r
27 Returns a boolean indicating if the firmware configuration interface\r
28 is available or not.\r
29\r
30 This function may change fw_cfg state.\r
31\r
32 @retval TRUE The interface is available\r
33 @retval FALSE The interface is not available\r
34\r
35**/\r
36BOOLEAN\r
37EFIAPI\r
38QemuFwCfgIsAvailable (\r
39 VOID\r
40 )\r
41{\r
42 return InternalQemuFwCfgIsAvailable ();\r
43}\r
44\r
45\r
46RETURN_STATUS\r
47EFIAPI\r
48QemuFwCfgInitialize (\r
49 VOID\r
50 )\r
51{\r
52 UINT32 Signature;\r
53 UINT32 Revision;\r
54\r
55 //\r
56 // Enable the access routines while probing to see if it is supported.\r
2c8dcbc6 57 // For probing we always use the IO Port (IoReadFifo8()) access method.\r
2ce7e221
LE
58 //\r
59 mQemuFwCfgSupported = TRUE;\r
2c8dcbc6 60 mQemuFwCfgDmaSupported = FALSE;\r
2ce7e221
LE
61\r
62 QemuFwCfgSelectItem (QemuFwCfgItemSignature);\r
63 Signature = QemuFwCfgRead32 ();\r
64 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));\r
65 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);\r
66 Revision = QemuFwCfgRead32 ();\r
67 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));\r
68 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||\r
69 (Revision < 1)\r
70 ) {\r
71 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));\r
72 mQemuFwCfgSupported = FALSE;\r
73 return RETURN_SUCCESS;\r
74 }\r
75\r
2c8dcbc6
LE
76 if ((Revision & FW_CFG_F_DMA) == 0) {\r
77 DEBUG ((DEBUG_INFO, "QemuFwCfg interface (IO Port) is supported.\n"));\r
78 } else {\r
79 mQemuFwCfgDmaSupported = TRUE;\r
80 DEBUG ((DEBUG_INFO, "QemuFwCfg interface (DMA) is supported.\n"));\r
81 }\r
2ce7e221
LE
82 return RETURN_SUCCESS;\r
83}\r
84\r
85\r
86/**\r
87 Returns a boolean indicating if the firmware configuration interface is\r
88 available for library-internal purposes.\r
89\r
90 This function never changes fw_cfg state.\r
91\r
92 @retval TRUE The interface is available internally.\r
93 @retval FALSE The interface is not available internally.\r
94**/\r
95BOOLEAN\r
2ce7e221
LE
96InternalQemuFwCfgIsAvailable (\r
97 VOID\r
98 )\r
99{\r
100 return mQemuFwCfgSupported;\r
101}\r
2c8dcbc6
LE
102\r
103/**\r
104 Returns a boolean indicating whether QEMU provides the DMA-like access method\r
105 for fw_cfg.\r
106\r
107 @retval TRUE The DMA-like access method is available.\r
108 @retval FALSE The DMA-like access method is unavailable.\r
109**/\r
110BOOLEAN\r
111InternalQemuFwCfgDmaIsAvailable (\r
112 VOID\r
113 )\r
114{\r
115 return mQemuFwCfgDmaSupported;\r
116}\r