]>
Commit | Line | Data |
---|---|---|
7c4ab1c2 GD |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2010, Apple Inc. All rights reserved.<BR>\r | |
82f727c4 | 4 | Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>\r |
7c4ab1c2 GD |
5 | \r |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
10 | #include <PiPei.h>\r | |
11 | \r | |
12 | #include <Library/BaseLib.h>\r | |
13 | #include <Library/BaseMemoryLib.h>\r | |
14 | #include <Library/DebugLib.h>\r | |
15 | #include <Library/HobLib.h>\r | |
16 | #include <Library/PcdLib.h>\r | |
17 | \r | |
18 | VOID *mHobList;\r | |
19 | \r | |
20 | /**\r | |
21 | Returns the pointer to the HOB list.\r | |
22 | \r | |
23 | This function returns the pointer to first HOB in the list.\r | |
24 | \r | |
25 | @return The pointer to the HOB list.\r | |
26 | \r | |
27 | **/\r | |
28 | VOID *\r | |
29 | EFIAPI\r | |
30 | GetHobList (\r | |
31 | VOID\r | |
32 | )\r | |
33 | {\r | |
34 | ASSERT (mHobList != NULL);\r | |
35 | return mHobList;\r | |
36 | }\r | |
37 | \r | |
38 | \r | |
39 | /**\r | |
40 | Build a Handoff Information Table HOB\r | |
41 | \r | |
d63595c3 ZL |
42 | This function initialize a HOB region from EfiMemoryBegin to\r |
43 | EfiMemoryTop. And EfiFreeMemoryBottom and EfiFreeMemoryTop should\r | |
7c4ab1c2 GD |
44 | be inside the HOB region.\r |
45 | \r | |
d63595c3 ZL |
46 | @param[in] EfiMemoryBottom Total memory start address\r |
47 | @param[in] EfiMemoryTop Total memory end address.\r | |
48 | @param[in] EfiFreeMemoryBottom Free memory start address\r | |
49 | @param[in] EfiFreeMemoryTop Free memory end address.\r | |
7c4ab1c2 GD |
50 | \r |
51 | @return The pointer to the handoff HOB table.\r | |
52 | \r | |
53 | **/\r | |
54 | EFI_HOB_HANDOFF_INFO_TABLE*\r | |
55 | EFIAPI\r | |
56 | HobConstructor (\r | |
d63595c3 ZL |
57 | IN VOID *EfiMemoryBottom,\r |
58 | IN VOID *EfiMemoryTop,\r | |
7c4ab1c2 GD |
59 | IN VOID *EfiFreeMemoryBottom,\r |
60 | IN VOID *EfiFreeMemoryTop\r | |
61 | )\r | |
62 | {\r | |
63 | EFI_HOB_HANDOFF_INFO_TABLE *Hob;\r | |
64 | EFI_HOB_GENERIC_HEADER *HobEnd;\r | |
65 | \r | |
66 | Hob = EfiFreeMemoryBottom;\r | |
67 | HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);\r | |
68 | \r | |
69 | Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;\r | |
70 | Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);\r | |
71 | Hob->Header.Reserved = 0;\r | |
72 | \r | |
73 | HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r | |
74 | HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r | |
75 | HobEnd->Reserved = 0;\r | |
76 | \r | |
77 | Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;\r | |
78 | Hob->BootMode = BOOT_WITH_FULL_CONFIGURATION;\r | |
79 | \r | |
f0fe55bc | 80 | Hob->EfiMemoryTop = (EFI_PHYSICAL_ADDRESS) (UINTN) EfiMemoryTop;\r |
81 | Hob->EfiMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) EfiMemoryBottom;\r | |
82 | Hob->EfiFreeMemoryTop = (EFI_PHYSICAL_ADDRESS) (UINTN) EfiFreeMemoryTop;\r | |
d63595c3 ZL |
83 | Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd+1);\r |
84 | Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r | |
7c4ab1c2 GD |
85 | \r |
86 | mHobList = Hob;\r | |
87 | return Hob;\r | |
88 | }\r | |
89 | \r | |
90 | /**\r | |
91 | Add a new HOB to the HOB List.\r | |
92 | \r | |
93 | @param HobType Type of the new HOB.\r | |
94 | @param HobLength Length of the new HOB to allocate.\r | |
95 | \r | |
96 | @return NULL if there is no space to create a hob.\r | |
97 | @return The address point to the new created hob.\r | |
98 | \r | |
99 | **/\r | |
100 | VOID *\r | |
101 | EFIAPI\r | |
102 | CreateHob (\r | |
103 | IN UINT16 HobType,\r | |
104 | IN UINT16 HobLength\r | |
105 | )\r | |
106 | {\r | |
107 | EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r | |
108 | EFI_HOB_GENERIC_HEADER *HobEnd;\r | |
109 | EFI_PHYSICAL_ADDRESS FreeMemory;\r | |
110 | VOID *Hob;\r | |
111 | \r | |
112 | HandOffHob = GetHobList ();\r | |
113 | \r | |
114 | HobLength = (UINT16)((HobLength + 0x7) & (~0x7));\r | |
115 | \r | |
116 | FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;\r | |
117 | \r | |
118 | if (FreeMemory < HobLength) {\r | |
119 | return NULL;\r | |
120 | }\r | |
121 | \r | |
122 | Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;\r | |
123 | ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;\r | |
124 | ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;\r | |
125 | ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;\r | |
126 | \r | |
127 | HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);\r | |
128 | HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r | |
129 | \r | |
130 | HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r | |
131 | HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r | |
132 | HobEnd->Reserved = 0;\r | |
133 | HobEnd++;\r | |
134 | HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r | |
135 | \r | |
136 | return Hob;\r | |
137 | }\r | |
138 | \r | |
139 | /**\r | |
140 | Builds a HOB that describes a chunk of system memory.\r | |
141 | \r | |
142 | This function builds a HOB that describes a chunk of system memory.\r | |
143 | If there is no additional space for HOB creation, then ASSERT().\r | |
144 | \r | |
145 | @param ResourceType The type of resource described by this HOB.\r | |
146 | @param ResourceAttribute The resource attributes of the memory described by this HOB.\r | |
147 | @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r | |
148 | @param NumberOfBytes The length of the memory described by this HOB in bytes.\r | |
149 | \r | |
150 | **/\r | |
151 | VOID\r | |
152 | EFIAPI\r | |
153 | BuildResourceDescriptorHob (\r | |
154 | IN EFI_RESOURCE_TYPE ResourceType,\r | |
155 | IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r | |
156 | IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r | |
157 | IN UINT64 NumberOfBytes\r | |
158 | )\r | |
159 | {\r | |
160 | EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r | |
161 | \r | |
162 | Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));\r | |
163 | ASSERT(Hob != NULL);\r | |
164 | \r | |
165 | Hob->ResourceType = ResourceType;\r | |
166 | Hob->ResourceAttribute = ResourceAttribute;\r | |
167 | Hob->PhysicalStart = PhysicalStart;\r | |
168 | Hob->ResourceLength = NumberOfBytes;\r | |
169 | }\r | |
170 | \r | |
7c4ab1c2 GD |
171 | /**\r |
172 | Returns the next instance of a HOB type from the starting HOB.\r | |
173 | \r | |
174 | This function searches the first instance of a HOB type from the starting HOB pointer.\r | |
175 | If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r | |
176 | In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r | |
177 | unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r | |
178 | caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r | |
179 | If HobStart is NULL, then ASSERT().\r | |
180 | \r | |
181 | @param Type The HOB type to return.\r | |
182 | @param HobStart The starting HOB pointer to search from.\r | |
183 | \r | |
184 | @return The next instance of a HOB type from the starting HOB.\r | |
185 | \r | |
186 | **/\r | |
187 | VOID *\r | |
188 | EFIAPI\r | |
189 | GetNextHob (\r | |
190 | IN UINT16 Type,\r | |
191 | IN CONST VOID *HobStart\r | |
192 | )\r | |
193 | {\r | |
194 | EFI_PEI_HOB_POINTERS Hob;\r | |
195 | \r | |
196 | ASSERT (HobStart != NULL);\r | |
197 | \r | |
198 | Hob.Raw = (UINT8 *) HobStart;\r | |
199 | //\r | |
200 | // Parse the HOB list until end of list or matching type is found.\r | |
201 | //\r | |
202 | while (!END_OF_HOB_LIST (Hob)) {\r | |
203 | if (Hob.Header->HobType == Type) {\r | |
204 | return Hob.Raw;\r | |
205 | }\r | |
206 | Hob.Raw = GET_NEXT_HOB (Hob);\r | |
207 | }\r | |
208 | return NULL;\r | |
209 | }\r | |
210 | \r | |
211 | \r | |
212 | \r | |
213 | /**\r | |
214 | Returns the first instance of a HOB type among the whole HOB list.\r | |
215 | \r | |
216 | This function searches the first instance of a HOB type among the whole HOB list.\r | |
217 | If there does not exist such HOB type in the HOB list, it will return NULL.\r | |
218 | \r | |
219 | @param Type The HOB type to return.\r | |
220 | \r | |
221 | @return The next instance of a HOB type from the starting HOB.\r | |
222 | \r | |
223 | **/\r | |
224 | VOID *\r | |
225 | EFIAPI\r | |
226 | GetFirstHob (\r | |
227 | IN UINT16 Type\r | |
228 | )\r | |
229 | {\r | |
230 | VOID *HobList;\r | |
231 | \r | |
232 | HobList = GetHobList ();\r | |
233 | return GetNextHob (Type, HobList);\r | |
234 | }\r | |
235 | \r | |
236 | \r | |
237 | /**\r | |
238 | This function searches the first instance of a HOB from the starting HOB pointer.\r | |
239 | Such HOB should satisfy two conditions:\r | |
240 | its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r | |
241 | If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r | |
242 | Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r | |
243 | to extract the data section and its size info respectively.\r | |
244 | In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r | |
245 | unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r | |
246 | caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r | |
247 | If Guid is NULL, then ASSERT().\r | |
248 | If HobStart is NULL, then ASSERT().\r | |
249 | \r | |
250 | @param Guid The GUID to match with in the HOB list.\r | |
251 | @param HobStart A pointer to a Guid.\r | |
252 | \r | |
253 | @return The next instance of the matched GUID HOB from the starting HOB.\r | |
254 | \r | |
255 | **/\r | |
256 | VOID *\r | |
257 | EFIAPI\r | |
258 | GetNextGuidHob (\r | |
259 | IN CONST EFI_GUID *Guid,\r | |
260 | IN CONST VOID *HobStart\r | |
6ef57974 GD |
261 | )\r |
262 | {\r | |
7c4ab1c2 GD |
263 | EFI_PEI_HOB_POINTERS GuidHob;\r |
264 | \r | |
265 | GuidHob.Raw = (UINT8 *) HobStart;\r | |
266 | while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r | |
267 | if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r | |
268 | break;\r | |
269 | }\r | |
270 | GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r | |
271 | }\r | |
272 | return GuidHob.Raw;\r | |
273 | }\r | |
274 | \r | |
275 | \r | |
276 | /**\r | |
277 | This function searches the first instance of a HOB among the whole HOB list.\r | |
278 | Such HOB should satisfy two conditions:\r | |
279 | its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r | |
280 | If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r | |
281 | Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r | |
282 | to extract the data section and its size info respectively.\r | |
283 | If Guid is NULL, then ASSERT().\r | |
284 | \r | |
285 | @param Guid The GUID to match with in the HOB list.\r | |
286 | \r | |
287 | @return The first instance of the matched GUID HOB among the whole HOB list.\r | |
288 | \r | |
289 | **/\r | |
290 | VOID *\r | |
291 | EFIAPI\r | |
292 | GetFirstGuidHob (\r | |
293 | IN CONST EFI_GUID *Guid\r | |
294 | )\r | |
295 | {\r | |
296 | VOID *HobList;\r | |
297 | \r | |
298 | HobList = GetHobList ();\r | |
299 | return GetNextGuidHob (Guid, HobList);\r | |
300 | }\r | |
301 | \r | |
302 | \r | |
303 | \r | |
304 | \r | |
305 | /**\r | |
306 | Builds a HOB for a loaded PE32 module.\r | |
307 | \r | |
308 | This function builds a HOB for a loaded PE32 module.\r | |
309 | It can only be invoked during PEI phase;\r | |
310 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
311 | If ModuleName is NULL, then ASSERT().\r | |
312 | If there is no additional space for HOB creation, then ASSERT().\r | |
313 | \r | |
314 | @param ModuleName The GUID File Name of the module.\r | |
315 | @param MemoryAllocationModule The 64 bit physical address of the module.\r | |
316 | @param ModuleLength The length of the module in bytes.\r | |
317 | @param EntryPoint The 64 bit physical address of the module entry point.\r | |
318 | \r | |
319 | **/\r | |
320 | VOID\r | |
321 | EFIAPI\r | |
322 | BuildModuleHob (\r | |
323 | IN CONST EFI_GUID *ModuleName,\r | |
324 | IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r | |
325 | IN UINT64 ModuleLength,\r | |
326 | IN EFI_PHYSICAL_ADDRESS EntryPoint\r | |
327 | )\r | |
328 | {\r | |
329 | EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;\r | |
330 | \r | |
331 | ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&\r | |
332 | ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));\r | |
333 | \r | |
334 | Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));\r | |
335 | \r | |
336 | CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);\r | |
337 | Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r | |
338 | Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;\r | |
339 | Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;\r | |
340 | \r | |
341 | //\r | |
342 | // Zero the reserved space to match HOB spec\r | |
343 | //\r | |
344 | ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));\r | |
345 | \r | |
346 | CopyGuid (&Hob->ModuleName, ModuleName);\r | |
347 | Hob->EntryPoint = EntryPoint;\r | |
348 | }\r | |
349 | \r | |
350 | /**\r | |
351 | Builds a GUID HOB with a certain data length.\r | |
352 | \r | |
353 | This function builds a customized HOB tagged with a GUID for identification\r | |
354 | and returns the start address of GUID HOB data so that caller can fill the customized data.\r | |
355 | The HOB Header and Name field is already stripped.\r | |
356 | It can only be invoked during PEI phase;\r | |
357 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
358 | If Guid is NULL, then ASSERT().\r | |
359 | If there is no additional space for HOB creation, then ASSERT().\r | |
360 | If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r | |
361 | \r | |
362 | @param Guid The GUID to tag the customized HOB.\r | |
363 | @param DataLength The size of the data payload for the GUID HOB.\r | |
364 | \r | |
365 | @return The start address of GUID HOB data.\r | |
366 | \r | |
367 | **/\r | |
368 | VOID *\r | |
369 | EFIAPI\r | |
370 | BuildGuidHob (\r | |
371 | IN CONST EFI_GUID *Guid,\r | |
372 | IN UINTN DataLength\r | |
373 | )\r | |
374 | {\r | |
375 | EFI_HOB_GUID_TYPE *Hob;\r | |
376 | \r | |
377 | //\r | |
378 | // Make sure that data length is not too long.\r | |
379 | //\r | |
380 | ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));\r | |
381 | \r | |
382 | Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));\r | |
383 | CopyGuid (&Hob->Name, Guid);\r | |
384 | return Hob + 1;\r | |
385 | }\r | |
386 | \r | |
387 | \r | |
388 | /**\r | |
389 | Copies a data buffer to a newly-built HOB.\r | |
390 | \r | |
391 | This function builds a customized HOB tagged with a GUID for identification,\r | |
392 | copies the input data to the HOB data field and returns the start address of the GUID HOB data.\r | |
393 | The HOB Header and Name field is already stripped.\r | |
394 | It can only be invoked during PEI phase;\r | |
395 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
396 | If Guid is NULL, then ASSERT().\r | |
397 | If Data is NULL and DataLength > 0, then ASSERT().\r | |
398 | If there is no additional space for HOB creation, then ASSERT().\r | |
399 | If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r | |
400 | \r | |
401 | @param Guid The GUID to tag the customized HOB.\r | |
402 | @param Data The data to be copied into the data field of the GUID HOB.\r | |
403 | @param DataLength The size of the data payload for the GUID HOB.\r | |
404 | \r | |
405 | @return The start address of GUID HOB data.\r | |
406 | \r | |
407 | **/\r | |
408 | VOID *\r | |
409 | EFIAPI\r | |
410 | BuildGuidDataHob (\r | |
411 | IN CONST EFI_GUID *Guid,\r | |
412 | IN VOID *Data,\r | |
413 | IN UINTN DataLength\r | |
414 | )\r | |
415 | {\r | |
416 | VOID *HobData;\r | |
417 | \r | |
418 | ASSERT (Data != NULL || DataLength == 0);\r | |
419 | \r | |
420 | HobData = BuildGuidHob (Guid, DataLength);\r | |
421 | \r | |
422 | return CopyMem (HobData, Data, DataLength);\r | |
423 | }\r | |
424 | \r | |
425 | \r | |
426 | /**\r | |
427 | Builds a Firmware Volume HOB.\r | |
428 | \r | |
429 | This function builds a Firmware Volume HOB.\r | |
430 | It can only be invoked during PEI phase;\r | |
431 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
432 | If there is no additional space for HOB creation, then ASSERT().\r | |
433 | \r | |
434 | @param BaseAddress The base address of the Firmware Volume.\r | |
435 | @param Length The size of the Firmware Volume in bytes.\r | |
436 | \r | |
437 | **/\r | |
438 | VOID\r | |
439 | EFIAPI\r | |
440 | BuildFvHob (\r | |
441 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
442 | IN UINT64 Length\r | |
443 | )\r | |
444 | {\r | |
445 | EFI_HOB_FIRMWARE_VOLUME *Hob;\r | |
446 | \r | |
447 | Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));\r | |
448 | \r | |
449 | Hob->BaseAddress = BaseAddress;\r | |
450 | Hob->Length = Length;\r | |
451 | }\r | |
452 | \r | |
453 | \r | |
454 | /**\r | |
455 | Builds a EFI_HOB_TYPE_FV2 HOB.\r | |
456 | \r | |
457 | This function builds a EFI_HOB_TYPE_FV2 HOB.\r | |
458 | It can only be invoked during PEI phase;\r | |
459 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
460 | If there is no additional space for HOB creation, then ASSERT().\r | |
461 | \r | |
462 | @param BaseAddress The base address of the Firmware Volume.\r | |
463 | @param Length The size of the Firmware Volume in bytes.\r | |
464 | @param FvName The name of the Firmware Volume.\r | |
465 | @param FileName The name of the file.\r | |
466 | \r | |
467 | **/\r | |
468 | VOID\r | |
469 | EFIAPI\r | |
470 | BuildFv2Hob (\r | |
471 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
472 | IN UINT64 Length,\r | |
473 | IN CONST EFI_GUID *FvName,\r | |
474 | IN CONST EFI_GUID *FileName\r | |
475 | )\r | |
476 | {\r | |
477 | EFI_HOB_FIRMWARE_VOLUME2 *Hob;\r | |
478 | \r | |
479 | Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));\r | |
480 | \r | |
481 | Hob->BaseAddress = BaseAddress;\r | |
482 | Hob->Length = Length;\r | |
483 | CopyGuid (&Hob->FvName, FvName);\r | |
484 | CopyGuid (&Hob->FileName, FileName);\r | |
485 | }\r | |
486 | \r | |
487 | /**\r | |
488 | Builds a EFI_HOB_TYPE_FV3 HOB.\r | |
489 | \r | |
490 | This function builds a EFI_HOB_TYPE_FV3 HOB.\r | |
491 | It can only be invoked during PEI phase;\r | |
492 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
493 | \r | |
494 | If there is no additional space for HOB creation, then ASSERT().\r | |
495 | \r | |
496 | @param BaseAddress The base address of the Firmware Volume.\r | |
497 | @param Length The size of the Firmware Volume in bytes.\r | |
498 | @param AuthenticationStatus The authentication status.\r | |
499 | @param ExtractedFv TRUE if the FV was extracted as a file within\r | |
500 | another firmware volume. FALSE otherwise.\r | |
501 | @param FvName The name of the Firmware Volume.\r | |
502 | Valid only if IsExtractedFv is TRUE.\r | |
503 | @param FileName The name of the file.\r | |
504 | Valid only if IsExtractedFv is TRUE.\r | |
505 | \r | |
506 | **/\r | |
507 | VOID\r | |
508 | EFIAPI\r | |
509 | BuildFv3Hob (\r | |
510 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
511 | IN UINT64 Length,\r | |
512 | IN UINT32 AuthenticationStatus,\r | |
513 | IN BOOLEAN ExtractedFv,\r | |
514 | IN CONST EFI_GUID *FvName, OPTIONAL\r | |
515 | IN CONST EFI_GUID *FileName OPTIONAL\r | |
516 | )\r | |
517 | {\r | |
518 | EFI_HOB_FIRMWARE_VOLUME3 *Hob;\r | |
519 | \r | |
520 | Hob = CreateHob (EFI_HOB_TYPE_FV3, sizeof (EFI_HOB_FIRMWARE_VOLUME3));\r | |
521 | \r | |
522 | Hob->BaseAddress = BaseAddress;\r | |
523 | Hob->Length = Length;\r | |
524 | Hob->AuthenticationStatus = AuthenticationStatus;\r | |
525 | Hob->ExtractedFv = ExtractedFv;\r | |
526 | if (ExtractedFv) {\r | |
527 | CopyGuid (&Hob->FvName, FvName);\r | |
528 | CopyGuid (&Hob->FileName, FileName);\r | |
529 | }\r | |
530 | }\r | |
531 | \r | |
532 | \r | |
533 | /**\r | |
534 | Builds a HOB for the CPU.\r | |
535 | \r | |
536 | This function builds a HOB for the CPU.\r | |
537 | It can only be invoked during PEI phase;\r | |
538 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
539 | If there is no additional space for HOB creation, then ASSERT().\r | |
540 | \r | |
541 | @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r | |
542 | @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r | |
543 | \r | |
544 | **/\r | |
545 | VOID\r | |
546 | EFIAPI\r | |
547 | BuildCpuHob (\r | |
548 | IN UINT8 SizeOfMemorySpace,\r | |
549 | IN UINT8 SizeOfIoSpace\r | |
550 | )\r | |
551 | {\r | |
552 | EFI_HOB_CPU *Hob;\r | |
553 | \r | |
554 | Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));\r | |
555 | \r | |
556 | Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r | |
557 | Hob->SizeOfIoSpace = SizeOfIoSpace;\r | |
558 | \r | |
559 | //\r | |
560 | // Zero the reserved space to match HOB spec\r | |
561 | //\r | |
562 | ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));\r | |
563 | }\r | |
564 | \r | |
565 | \r | |
566 | /**\r | |
567 | Builds a HOB for the Stack.\r | |
568 | \r | |
569 | This function builds a HOB for the stack.\r | |
570 | It can only be invoked during PEI phase;\r | |
571 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
572 | If there is no additional space for HOB creation, then ASSERT().\r | |
573 | \r | |
574 | @param BaseAddress The 64 bit physical address of the Stack.\r | |
575 | @param Length The length of the stack in bytes.\r | |
576 | \r | |
577 | **/\r | |
578 | VOID\r | |
579 | EFIAPI\r | |
580 | BuildStackHob (\r | |
581 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
582 | IN UINT64 Length\r | |
583 | )\r | |
584 | {\r | |
585 | EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r | |
586 | \r | |
587 | ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r | |
588 | ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r | |
589 | \r | |
590 | Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));\r | |
591 | \r | |
592 | CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);\r | |
593 | Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
594 | Hob->AllocDescriptor.MemoryLength = Length;\r | |
595 | Hob->AllocDescriptor.MemoryType = EfiBootServicesData;\r | |
596 | \r | |
597 | //\r | |
598 | // Zero the reserved space to match HOB spec\r | |
599 | //\r | |
600 | ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r | |
601 | }\r | |
602 | \r | |
603 | \r | |
604 | /**\r | |
605 | Update the Stack Hob if the stack has been moved\r | |
606 | \r | |
607 | @param BaseAddress The 64 bit physical address of the Stack.\r | |
608 | @param Length The length of the stack in bytes.\r | |
609 | \r | |
610 | **/\r | |
611 | VOID\r | |
612 | EFIAPI\r | |
613 | UpdateStackHob (\r | |
614 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
615 | IN UINT64 Length\r | |
616 | )\r | |
617 | {\r | |
618 | EFI_PEI_HOB_POINTERS Hob;\r | |
619 | \r | |
620 | Hob.Raw = GetHobList ();\r | |
621 | while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {\r | |
622 | if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {\r | |
623 | //\r | |
624 | // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type\r | |
625 | // to be reclaimed by DXE core.\r | |
626 | //\r | |
627 | BuildMemoryAllocationHob (\r | |
628 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,\r | |
629 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,\r | |
630 | EfiConventionalMemory\r | |
631 | );\r | |
632 | //\r | |
633 | // Update the BSP Stack Hob to reflect the new stack info.\r | |
634 | //\r | |
635 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
636 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;\r | |
637 | break;\r | |
638 | }\r | |
639 | Hob.Raw = GET_NEXT_HOB (Hob);\r | |
640 | }\r | |
641 | }\r | |
642 | \r | |
643 | \r | |
644 | \r | |
645 | /**\r | |
646 | Builds a HOB for the memory allocation.\r | |
647 | \r | |
648 | This function builds a HOB for the memory allocation.\r | |
649 | It can only be invoked during PEI phase;\r | |
650 | for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r | |
651 | If there is no additional space for HOB creation, then ASSERT().\r | |
652 | \r | |
653 | @param BaseAddress The 64 bit physical address of the memory.\r | |
654 | @param Length The length of the memory allocation in bytes.\r | |
655 | @param MemoryType Type of memory allocated by this HOB.\r | |
656 | \r | |
657 | **/\r | |
658 | VOID\r | |
659 | EFIAPI\r | |
660 | BuildMemoryAllocationHob (\r | |
661 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
662 | IN UINT64 Length,\r | |
663 | IN EFI_MEMORY_TYPE MemoryType\r | |
664 | )\r | |
665 | {\r | |
666 | EFI_HOB_MEMORY_ALLOCATION *Hob;\r | |
667 | \r | |
668 | ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&\r | |
669 | ((Length & (EFI_PAGE_SIZE - 1)) == 0));\r | |
670 | \r | |
671 | Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));\r | |
672 | \r | |
673 | ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));\r | |
674 | Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
675 | Hob->AllocDescriptor.MemoryLength = Length;\r | |
676 | Hob->AllocDescriptor.MemoryType = MemoryType;\r | |
677 | //\r | |
678 | // Zero the reserved space to match HOB spec\r | |
679 | //\r | |
680 | ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));\r | |
681 | }\r | |
682 | \r |