2 HOB Library implementation for Payload Phase.
4 Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/HobLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/DxeHobListLib.h>
17 Returns the pointer to the HOB list.
19 This function returns the pointer to first HOB in the list.
20 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
21 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
22 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
23 Since the System Configuration Table does not exist that the time the DXE Core is
24 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
25 to manage the pointer to the HOB list.
27 If the pointer to the HOB list is NULL, then ASSERT().
29 @return The pointer to the HOB list.
38 ASSERT (gHobList
!= NULL
);
43 Returns the next instance of a HOB type from the starting HOB.
45 This function searches the first instance of a HOB type from the starting HOB pointer.
46 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
47 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
48 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
49 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
51 If HobStart is NULL, then ASSERT().
53 @param Type The HOB type to return.
54 @param HobStart The starting HOB pointer to search from.
56 @return The next instance of a HOB type from the starting HOB.
63 IN CONST VOID
*HobStart
66 EFI_PEI_HOB_POINTERS Hob
;
68 ASSERT (HobStart
!= NULL
);
70 Hob
.Raw
= (UINT8
*) HobStart
;
72 // Parse the HOB list until end of list or matching type is found.
74 while (!END_OF_HOB_LIST (Hob
)) {
75 if (Hob
.Header
->HobType
== Type
) {
78 Hob
.Raw
= GET_NEXT_HOB (Hob
);
84 Returns the first instance of a HOB type among the whole HOB list.
86 This function searches the first instance of a HOB type among the whole HOB list.
87 If there does not exist such HOB type in the HOB list, it will return NULL.
89 If the pointer to the HOB list is NULL, then ASSERT().
91 @param Type The HOB type to return.
93 @return The next instance of a HOB type from the starting HOB.
104 HobList
= GetHobList ();
105 return GetNextHob (Type
, HobList
);
109 Returns the next instance of the matched GUID HOB from the starting HOB.
111 This function searches the first instance of a HOB from the starting HOB pointer.
112 Such HOB should satisfy two conditions:
113 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
114 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
115 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
116 to extract the data section and its size information, respectively.
117 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
118 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
119 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
121 If Guid is NULL, then ASSERT().
122 If HobStart is NULL, then ASSERT().
124 @param Guid The GUID to match with in the HOB list.
125 @param HobStart A pointer to a Guid.
127 @return The next instance of the matched GUID HOB from the starting HOB.
133 IN CONST EFI_GUID
*Guid
,
134 IN CONST VOID
*HobStart
137 EFI_PEI_HOB_POINTERS GuidHob
;
139 GuidHob
.Raw
= (UINT8
*) HobStart
;
140 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
141 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
144 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
150 Returns the first instance of the matched GUID HOB among the whole HOB list.
152 This function searches the first instance of a HOB among the whole HOB list.
153 Such HOB should satisfy two conditions:
154 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
155 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
156 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
157 to extract the data section and its size information, respectively.
159 If the pointer to the HOB list is NULL, then ASSERT().
160 If Guid is NULL, then ASSERT().
162 @param Guid The GUID to match with in the HOB list.
164 @return The first instance of the matched GUID HOB among the whole HOB list.
170 IN CONST EFI_GUID
*Guid
175 HobList
= GetHobList ();
176 return GetNextGuidHob (Guid
, HobList
);
180 Get the system boot mode from the HOB list.
182 This function returns the system boot mode information from the
183 PHIT HOB in HOB list.
185 If the pointer to the HOB list is NULL, then ASSERT().
189 @return The Boot Mode.
198 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
200 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
202 return HandOffHob
->BootMode
;
206 Builds a HOB for a loaded PE32 module.
208 This function builds a HOB for a loaded PE32 module.
209 It can only be invoked during PEI phase;
210 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
212 If ModuleName is NULL, then ASSERT().
213 If there is no additional space for HOB creation, then ASSERT().
215 @param ModuleName The GUID File Name of the module.
216 @param MemoryAllocationModule The 64 bit physical address of the module.
217 @param ModuleLength The length of the module in bytes.
218 @param EntryPoint The 64 bit physical address of the module entry point.
224 IN CONST EFI_GUID
*ModuleName
,
225 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
226 IN UINT64 ModuleLength
,
227 IN EFI_PHYSICAL_ADDRESS EntryPoint
231 // PEI HOB is read only for DXE phase
237 Builds a HOB that describes a chunk of system memory with Owner GUID.
239 This function builds a HOB that describes a chunk of system memory.
240 It can only be invoked during PEI phase;
241 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
243 If there is no additional space for HOB creation, then ASSERT().
245 @param ResourceType The type of resource described by this HOB.
246 @param ResourceAttribute The resource attributes of the memory described by this HOB.
247 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
248 @param NumberOfBytes The length of the memory described by this HOB in bytes.
249 @param OwnerGUID GUID for the owner of this resource.
254 BuildResourceDescriptorWithOwnerHob (
255 IN EFI_RESOURCE_TYPE ResourceType
,
256 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
257 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
258 IN UINT64 NumberOfBytes
,
259 IN EFI_GUID
*OwnerGUID
263 // PEI HOB is read only for DXE phase
269 Builds a HOB that describes a chunk of system memory.
271 This function builds a HOB that describes a chunk of system memory.
272 It can only be invoked during PEI phase;
273 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
275 If there is no additional space for HOB creation, then ASSERT().
277 @param ResourceType The type of resource described by this HOB.
278 @param ResourceAttribute The resource attributes of the memory described by this HOB.
279 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
280 @param NumberOfBytes The length of the memory described by this HOB in bytes.
285 BuildResourceDescriptorHob (
286 IN EFI_RESOURCE_TYPE ResourceType
,
287 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
288 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
289 IN UINT64 NumberOfBytes
293 // PEI HOB is read only for DXE phase
299 Builds a customized HOB tagged with a GUID for identification and returns
300 the start address of GUID HOB data.
302 This function builds a customized HOB tagged with a GUID for identification
303 and returns the start address of GUID HOB data so that caller can fill the customized data.
304 The HOB Header and Name field is already stripped.
305 It can only be invoked during PEI phase;
306 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
308 If Guid is NULL, then ASSERT().
309 If there is no additional space for HOB creation, then ASSERT().
310 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
311 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
313 @param Guid The GUID to tag the customized HOB.
314 @param DataLength The size of the data payload for the GUID HOB.
316 @retval NULL The GUID HOB could not be allocated.
317 @retval others The start address of GUID HOB data.
323 IN CONST EFI_GUID
*Guid
,
328 // PEI HOB is read only for DXE phase
335 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
336 data field, and returns the start address of the GUID HOB data.
338 This function builds a customized HOB tagged with a GUID for identification and copies the input
339 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
340 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
341 The HOB Header and Name field is already stripped.
342 It can only be invoked during PEI phase;
343 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
345 If Guid is NULL, then ASSERT().
346 If Data is NULL and DataLength > 0, then ASSERT().
347 If there is no additional space for HOB creation, then ASSERT().
348 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
349 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
351 @param Guid The GUID to tag the customized HOB.
352 @param Data The data to be copied into the data field of the GUID HOB.
353 @param DataLength The size of the data payload for the GUID HOB.
355 @retval NULL The GUID HOB could not be allocated.
356 @retval others The start address of GUID HOB data.
362 IN CONST EFI_GUID
*Guid
,
368 // PEI HOB is read only for DXE phase
375 Builds a Firmware Volume HOB.
377 This function builds a Firmware Volume HOB.
378 It can only be invoked during PEI phase;
379 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
381 If there is no additional space for HOB creation, then ASSERT().
382 If the FvImage buffer is not at its required alignment, then ASSERT().
384 @param BaseAddress The base address of the Firmware Volume.
385 @param Length The size of the Firmware Volume in bytes.
391 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
396 // PEI HOB is read only for DXE phase
402 Builds a EFI_HOB_TYPE_FV2 HOB.
404 This function builds a EFI_HOB_TYPE_FV2 HOB.
405 It can only be invoked during PEI phase;
406 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
408 If there is no additional space for HOB creation, then ASSERT().
409 If the FvImage buffer is not at its required alignment, then ASSERT().
411 @param BaseAddress The base address of the Firmware Volume.
412 @param Length The size of the Firmware Volume in bytes.
413 @param FvName The name of the Firmware Volume.
414 @param FileName The name of the file.
420 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
422 IN CONST EFI_GUID
*FvName
,
423 IN CONST EFI_GUID
*FileName
430 Builds a EFI_HOB_TYPE_FV3 HOB.
432 This function builds a EFI_HOB_TYPE_FV3 HOB.
433 It can only be invoked during PEI phase;
434 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
436 If there is no additional space for HOB creation, then ASSERT().
437 If the FvImage buffer is not at its required alignment, then ASSERT().
439 @param BaseAddress The base address of the Firmware Volume.
440 @param Length The size of the Firmware Volume in bytes.
441 @param AuthenticationStatus The authentication status.
442 @param ExtractedFv TRUE if the FV was extracted as a file within
443 another firmware volume. FALSE otherwise.
444 @param FvName The name of the Firmware Volume.
445 Valid only if IsExtractedFv is TRUE.
446 @param FileName The name of the file.
447 Valid only if IsExtractedFv is TRUE.
453 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
455 IN UINT32 AuthenticationStatus
,
456 IN BOOLEAN ExtractedFv
,
457 IN CONST EFI_GUID
*FvName OPTIONAL
,
458 IN CONST EFI_GUID
*FileName OPTIONAL
465 Builds a Capsule Volume HOB.
467 This function builds a Capsule Volume HOB.
468 It can only be invoked during PEI phase;
469 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
471 If the platform does not support Capsule Volume HOBs, then ASSERT().
472 If there is no additional space for HOB creation, then ASSERT().
474 @param BaseAddress The base address of the Capsule Volume.
475 @param Length The size of the Capsule Volume in bytes.
481 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
486 // PEI HOB is read only for DXE phase
492 Builds a HOB for the CPU.
494 This function builds a HOB for the CPU.
495 It can only be invoked during PEI phase;
496 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
498 If there is no additional space for HOB creation, then ASSERT().
500 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
501 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
507 IN UINT8 SizeOfMemorySpace
,
508 IN UINT8 SizeOfIoSpace
512 // PEI HOB is read only for DXE phase
518 Builds a HOB for the Stack.
520 This function builds a HOB for the stack.
521 It can only be invoked during PEI phase;
522 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
524 If there is no additional space for HOB creation, then ASSERT().
526 @param BaseAddress The 64 bit physical address of the Stack.
527 @param Length The length of the stack in bytes.
533 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
538 // PEI HOB is read only for DXE phase
544 Builds a HOB for the BSP store.
546 This function builds a HOB for BSP store.
547 It can only be invoked during PEI phase;
548 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
550 If there is no additional space for HOB creation, then ASSERT().
552 @param BaseAddress The 64 bit physical address of the BSP.
553 @param Length The length of the BSP store in bytes.
554 @param MemoryType Type of memory allocated by this HOB.
560 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
562 IN EFI_MEMORY_TYPE MemoryType
566 // PEI HOB is read only for DXE phase
572 Builds a HOB for the memory allocation.
574 This function builds a HOB for the memory allocation.
575 It can only be invoked during PEI phase;
576 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
578 If there is no additional space for HOB creation, then ASSERT().
580 @param BaseAddress The 64 bit physical address of the memory.
581 @param Length The length of the memory allocation in bytes.
582 @param MemoryType Type of memory allocated by this HOB.
587 BuildMemoryAllocationHob (
588 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
590 IN EFI_MEMORY_TYPE MemoryType
594 // PEI HOB is read only for DXE phase