]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Include/Library/PlatformInitLib.h
051b3119119493d620386346adcaa84d38a98162
[mirror_edk2.git] / OvmfPkg / Include / Library / PlatformInitLib.h
1 /** @file
2 PlatformInitLib header file.
3
4 Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef PLATFORM_INIT_LIB_H_
10 #define PLATFORM_INIT_LIB_H_
11
12 #include <PiPei.h>
13
14 #pragma pack(1)
15 typedef struct {
16 EFI_HOB_GUID_TYPE GuidHeader;
17 UINT16 HostBridgeDevId;
18
19 UINT64 PcdConfidentialComputingGuestAttr;
20 BOOLEAN SevEsIsEnabled;
21
22 UINT32 BootMode;
23 BOOLEAN S3Supported;
24
25 BOOLEAN SmmSmramRequire;
26 BOOLEAN Q35SmramAtDefaultSmbase;
27 UINT16 Q35TsegMbytes;
28
29 UINT32 LowMemory;
30 UINT64 FirstNonAddress;
31 UINT8 PhysMemAddressWidth;
32 UINT32 Uc32Base;
33 UINT32 Uc32Size;
34
35 BOOLEAN PcdSetNxForStack;
36 UINT64 PcdTdxSharedBitMask;
37
38 UINT64 PcdPciMmio64Base;
39 UINT64 PcdPciMmio64Size;
40 UINT32 PcdPciMmio32Base;
41 UINT32 PcdPciMmio32Size;
42 UINT64 PcdPciIoBase;
43 UINT64 PcdPciIoSize;
44
45 UINT64 PcdEmuVariableNvStoreReserved;
46 UINT32 PcdCpuBootLogicalProcessorNumber;
47 UINT32 PcdCpuMaxLogicalProcessorNumber;
48 UINT32 DefaultMaxCpuNumber;
49
50 UINT32 S3AcpiReservedMemoryBase;
51 UINT32 S3AcpiReservedMemorySize;
52
53 UINT64 FeatureControlValue;
54
55 BOOLEAN QemuFwCfgChecked;
56 BOOLEAN QemuFwCfgSupported;
57 BOOLEAN QemuFwCfgDmaSupported;
58 } EFI_HOB_PLATFORM_INFO;
59 #pragma pack()
60
61 /**
62 Reads 8-bits of CMOS data.
63
64 Reads the 8-bits of CMOS data at the location specified by Index.
65 The 8-bit read value is returned.
66
67 @param Index The CMOS location to read.
68
69 @return The value read.
70
71 **/
72 UINT8
73 EFIAPI
74 PlatformCmosRead8 (
75 IN UINTN Index
76 );
77
78 /**
79 Writes 8-bits of CMOS data.
80
81 Writes 8-bits of CMOS data to the location specified by Index
82 with the value specified by Value and returns Value.
83
84 @param Index The CMOS location to write.
85 @param Value The value to write to CMOS.
86
87 @return The value written to CMOS.
88
89 **/
90 UINT8
91 EFIAPI
92 PlatformCmosWrite8 (
93 IN UINTN Index,
94 IN UINT8 Value
95 );
96
97 /**
98 Dump the CMOS content
99 */
100 VOID
101 EFIAPI
102 PlatformDebugDumpCmos (
103 VOID
104 );
105
106 VOID
107 EFIAPI
108 PlatformAddIoMemoryBaseSizeHob (
109 IN EFI_PHYSICAL_ADDRESS MemoryBase,
110 IN UINT64 MemorySize
111 );
112
113 VOID
114 EFIAPI
115 PlatformAddIoMemoryRangeHob (
116 IN EFI_PHYSICAL_ADDRESS MemoryBase,
117 IN EFI_PHYSICAL_ADDRESS MemoryLimit
118 );
119
120 VOID
121 EFIAPI
122 PlatformAddMemoryBaseSizeHob (
123 IN EFI_PHYSICAL_ADDRESS MemoryBase,
124 IN UINT64 MemorySize
125 );
126
127 VOID
128 EFIAPI
129 PlatformAddMemoryRangeHob (
130 IN EFI_PHYSICAL_ADDRESS MemoryBase,
131 IN EFI_PHYSICAL_ADDRESS MemoryLimit
132 );
133
134 VOID
135 EFIAPI
136 PlatformAddReservedMemoryBaseSizeHob (
137 IN EFI_PHYSICAL_ADDRESS MemoryBase,
138 IN UINT64 MemorySize,
139 IN BOOLEAN Cacheable
140 );
141
142 VOID
143 EFIAPI
144 PlatformQemuUc32BaseInitialization (
145 IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob
146 );
147
148 VOID
149 EFIAPI
150 PlatformGetSystemMemorySizeBelow4gb (
151 IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob
152 );
153
154 /**
155 Initialize the PhysMemAddressWidth field in PlatformInfoHob based on guest RAM size.
156 **/
157 VOID
158 EFIAPI
159 PlatformAddressWidthInitialization (
160 IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob
161 );
162
163 /**
164 Peform Memory Detection for QEMU / KVM
165
166 **/
167 VOID
168 EFIAPI
169 PlatformQemuInitializeRam (
170 IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob
171 );
172
173 VOID
174 EFIAPI
175 PlatformQemuInitializeRamForS3 (
176 IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob
177 );
178
179 VOID
180 EFIAPI
181 PlatformMemMapInitialization (
182 IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob
183 );
184
185 /**
186 * Fetch "opt/ovmf/PcdSetNxForStack" from QEMU
187 *
188 * @param Setting The pointer to the setting of "/opt/ovmf/PcdSetNxForStack".
189 * @return EFI_SUCCESS Successfully fetch the settings.
190 */
191 EFI_STATUS
192 EFIAPI
193 PlatformNoexecDxeInitialization (
194 IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob
195 );
196
197 VOID
198 EFIAPI
199 PlatformMiscInitialization (
200 IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob
201 );
202
203 /**
204 Fetch the boot CPU count and the possible CPU count from QEMU, and expose
205 them to UefiCpuPkg modules.
206 **/
207 VOID
208 EFIAPI
209 PlatformMaxCpuCountInitialization (
210 IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob
211 );
212
213 /**
214 In Tdx guest, some information need to be passed from host VMM to guest
215 firmware. For example, the memory resource, etc. These information are
216 prepared by host VMM and put in HobList which is described in TdxMetadata.
217
218 Information in HobList is treated as external input. From the security
219 perspective before it is consumed, it should be validated.
220
221 @retval EFI_SUCCESS Successfully process the hoblist
222 @retval Others Other error as indicated
223 **/
224 EFI_STATUS
225 EFIAPI
226 ProcessTdxHobList (
227 VOID
228 );
229
230 /**
231 In Tdx guest, the system memory is passed in TdHob by host VMM. So
232 the major task of PlatformTdxPublishRamRegions is to walk thru the
233 TdHob list and transfer the ResourceDescriptorHob and MemoryAllocationHob
234 to the hobs in DXE phase.
235
236 MemoryAllocationHob should also be created for Mailbox and Ovmf work area.
237 **/
238 VOID
239 EFIAPI
240 PlatformTdxPublishRamRegions (
241 VOID
242 );
243
244 /**
245 Check the integrity of NvVarStore.
246
247 @param[in] NvVarStoreBase - A pointer to NvVarStore header
248 @param[in] NvVarStoreSize - NvVarStore size
249
250 @retval TRUE - The NvVarStore is valid.
251 @retval FALSE - The NvVarStore is invalid.
252
253 **/
254 BOOLEAN
255 EFIAPI
256 PlatformValidateNvVarStore (
257 IN UINT8 *NvVarStoreBase,
258 IN UINT32 NvVarStoreSize
259 );
260
261 /**
262 Allocate storage for NV variables early on so it will be
263 at a consistent address. Since VM memory is preserved
264 across reboots, this allows the NV variable storage to survive
265 a VM reboot.
266
267 *
268 * @retval VOID* The pointer to the storage for NV Variables
269 */
270 VOID *
271 EFIAPI
272 PlatformReserveEmuVariableNvStore (
273 VOID
274 );
275
276 /**
277 When OVMF is lauched with -bios parameter, UEFI variables will be
278 partially emulated, and non-volatile variables may lose their contents
279 after a reboot. This makes the secure boot feature not working.
280
281 This function is used to initialize the EmuVariableNvStore
282 with the conent in PcdOvmfFlashNvStorageVariableBase.
283
284 @param[in] EmuVariableNvStore - A pointer to EmuVariableNvStore
285
286 @retval EFI_SUCCESS - Successfully init the EmuVariableNvStore
287 @retval Others - As the error code indicates
288 */
289 EFI_STATUS
290 EFIAPI
291 PlatformInitEmuVariableNvStore (
292 IN VOID *EmuVariableNvStore
293 );
294
295 #endif // PLATFORM_INIT_LIB_H_