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