]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSec.c
OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map
[mirror_edk2.git] / OvmfPkg / Library / QemuFwCfgLib / QemuFwCfgSec.c
CommitLineData
c90decb9
LE
1/** @file\r
2\r
3 Stateless fw_cfg library implementation.\r
4\r
5 Clients must call QemuFwCfgIsAvailable() first.\r
6\r
7 Copyright (C) 2013, Red Hat, Inc.\r
8 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
6264abc2 9 Copyright (c) 2017, Advanced Micro Devices. All rights reserved.<BR>\r
c90decb9
LE
10\r
11 This program and the accompanying materials are licensed and made available\r
12 under the terms and conditions of the BSD License which accompanies this\r
13 distribution. The full text of the license may be found at\r
14 http://opensource.org/licenses/bsd-license.php\r
15\r
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
17 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
18**/\r
19\r
f6c909ae 20#include <Library/BaseLib.h>\r
c90decb9
LE
21#include <Library/DebugLib.h>\r
22#include <Library/QemuFwCfgLib.h>\r
23\r
5297c0bf 24#include "QemuFwCfgLibInternal.h"\r
c90decb9
LE
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 UINT32 Signature;\r
43 UINT32 Revision;\r
44\r
45 QemuFwCfgSelectItem (QemuFwCfgItemSignature);\r
46 Signature = QemuFwCfgRead32 ();\r
47 DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));\r
48 QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);\r
49 Revision = QemuFwCfgRead32 ();\r
50 DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));\r
51 if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||\r
52 (Revision < 1)\r
53 ) {\r
54 DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));\r
55 return FALSE;\r
56 }\r
57\r
58 DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));\r
59 return TRUE;\r
60}\r
61\r
62\r
63/**\r
64 Returns a boolean indicating if the firmware configuration interface is\r
65 available for library-internal purposes.\r
66\r
67 This function never changes fw_cfg state.\r
68\r
69 @retval TRUE The interface is available internally.\r
70 @retval FALSE The interface is not available internally.\r
71**/\r
72BOOLEAN\r
c90decb9
LE
73InternalQemuFwCfgIsAvailable (\r
74 VOID\r
75 )\r
76{\r
77 //\r
78 // We always return TRUE, because the consumer of this library ought to have\r
79 // called QemuFwCfgIsAvailable before making other calls which would hit this\r
80 // path.\r
81 //\r
82 return TRUE;\r
83}\r
2c8dcbc6
LE
84\r
85/**\r
86 Returns a boolean indicating whether QEMU provides the DMA-like access method\r
87 for fw_cfg.\r
88\r
89 @retval TRUE The DMA-like access method is available.\r
90 @retval FALSE The DMA-like access method is unavailable.\r
91**/\r
92BOOLEAN\r
93InternalQemuFwCfgDmaIsAvailable (\r
94 VOID\r
95 )\r
96{\r
97 return FALSE;\r
98}\r
6264abc2
BS
99\r
100/**\r
f6c909ae
BS
101 Transfer an array of bytes, or skip a number of bytes, using the DMA\r
102 interface.\r
6264abc2 103\r
f6c909ae 104 @param[in] Size Size in bytes to transfer or skip.\r
6264abc2 105\r
f6c909ae
BS
106 @param[in,out] Buffer Buffer to read data into or write data from. Ignored,\r
107 and may be NULL, if Size is zero, or Control is\r
108 FW_CFG_DMA_CTL_SKIP.\r
6264abc2 109\r
f6c909ae
BS
110 @param[in] Control One of the following:\r
111 FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buffer.\r
112 FW_CFG_DMA_CTL_READ - read from fw_cfg into Buffer.\r
113 FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg.\r
6264abc2
BS
114**/\r
115VOID\r
f6c909ae
BS
116InternalQemuFwCfgDmaBytes (\r
117 IN UINT32 Size,\r
118 IN OUT VOID *Buffer OPTIONAL,\r
119 IN UINT32 Control\r
6264abc2
BS
120 )\r
121{\r
122 //\r
123 // We should never reach here\r
124 //\r
125 ASSERT (FALSE);\r
f6c909ae 126 CpuDeadLoop ();\r
6264abc2 127}\r