2 HOB Library implementation for Dxe Phase with DebugLib dependency removed
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #define ASSERT(Expression) \
12 if (!(Expression)) { \
19 #include <Guid/HobList.h>
21 #include <Library/HobLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/BaseMemoryLib.h>
25 VOID
*mHobList
= NULL
;
28 The constructor function caches the pointer to HOB list.
30 The constructor function gets the start address of HOB list from system configuration table.
32 @param ImageHandle The firmware allocated handle for the EFI image.
33 @param SystemTable A pointer to the EFI System Table.
35 @retval EFI_SUCCESS The constructor successfully gets HobList.
36 @retval Other value The constructor can't get HobList.
42 IN EFI_HANDLE ImageHandle
,
43 IN EFI_SYSTEM_TABLE
*SystemTable
48 for (Index
= 0; Index
< SystemTable
->NumberOfTableEntries
; Index
++) {
49 if (CompareGuid (&gEfiHobListGuid
, &(SystemTable
->ConfigurationTable
[Index
].VendorGuid
))) {
50 mHobList
= SystemTable
->ConfigurationTable
[Index
].VendorTable
;
59 Returns the pointer to the HOB list.
61 This function returns the pointer to first HOB in the list.
62 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
63 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
64 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
65 Since the System Configuration Table does not exist that the time the DXE Core is
66 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
67 to manage the pointer to the HOB list.
69 If the pointer to the HOB list is NULL, then ASSERT().
71 @return The pointer to the HOB list.
80 ASSERT (mHobList
!= NULL
);
85 Returns the next instance of a HOB type from the starting HOB.
87 This function searches the first instance of a HOB type from the starting HOB pointer.
88 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
89 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
90 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
91 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
93 If HobStart is NULL, then ASSERT().
95 @param Type The HOB type to return.
96 @param HobStart The starting HOB pointer to search from.
98 @return The next instance of a HOB type from the starting HOB.
105 IN CONST VOID
*HobStart
108 EFI_PEI_HOB_POINTERS Hob
;
110 ASSERT (HobStart
!= NULL
);
112 Hob
.Raw
= (UINT8
*)HobStart
;
114 // Parse the HOB list until end of list or matching type is found.
116 while (!END_OF_HOB_LIST (Hob
)) {
117 if (Hob
.Header
->HobType
== Type
) {
121 Hob
.Raw
= GET_NEXT_HOB (Hob
);
128 Returns the first instance of a HOB type among the whole HOB list.
130 This function searches the first instance of a HOB type among the whole HOB list.
131 If there does not exist such HOB type in the HOB list, it will return NULL.
133 If the pointer to the HOB list is NULL, then ASSERT().
135 @param Type The HOB type to return.
137 @return The next instance of a HOB type from the starting HOB.
148 HobList
= GetHobList ();
149 return GetNextHob (Type
, HobList
);
153 Returns the next instance of the matched GUID HOB from the starting HOB.
155 This function searches the first instance of a HOB from the starting HOB pointer.
156 Such HOB should satisfy two conditions:
157 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
158 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
159 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
160 to extract the data section and its size information, respectively.
161 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
162 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
163 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
165 If Guid is NULL, then ASSERT().
166 If HobStart is NULL, then ASSERT().
168 @param Guid The GUID to match with in the HOB list.
169 @param HobStart A pointer to a Guid.
171 @return The next instance of the matched GUID HOB from the starting HOB.
177 IN CONST EFI_GUID
*Guid
,
178 IN CONST VOID
*HobStart
181 EFI_PEI_HOB_POINTERS GuidHob
;
183 GuidHob
.Raw
= (UINT8
*)HobStart
;
184 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
185 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
189 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
196 Returns the first instance of the matched GUID HOB among the whole HOB list.
198 This function searches the first instance of a HOB among the whole HOB list.
199 Such HOB should satisfy two conditions:
200 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
201 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
202 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
203 to extract the data section and its size information, respectively.
205 If the pointer to the HOB list is NULL, then ASSERT().
206 If Guid is NULL, then ASSERT().
208 @param Guid The GUID to match with in the HOB list.
210 @return The first instance of the matched GUID HOB among the whole HOB list.
216 IN CONST EFI_GUID
*Guid
221 HobList
= GetHobList ();
222 return GetNextGuidHob (Guid
, HobList
);
226 Get the system boot mode from the HOB list.
228 This function returns the system boot mode information from the
229 PHIT HOB in HOB list.
231 If the pointer to the HOB list is NULL, then ASSERT().
235 @return The Boot Mode.
244 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
246 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*)GetHobList ();
248 return HandOffHob
->BootMode
;
252 Builds a HOB for a loaded PE32 module.
254 This function builds a HOB for a loaded PE32 module.
255 It can only be invoked during PEI phase;
256 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
258 If ModuleName is NULL, then ASSERT().
259 If there is no additional space for HOB creation, then ASSERT().
261 @param ModuleName The GUID File Name of the module.
262 @param MemoryAllocationModule The 64 bit physical address of the module.
263 @param ModuleLength The length of the module in bytes.
264 @param EntryPoint The 64 bit physical address of the module entry point.
270 IN CONST EFI_GUID
*ModuleName
,
271 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
272 IN UINT64 ModuleLength
,
273 IN EFI_PHYSICAL_ADDRESS EntryPoint
277 // PEI HOB is read only for DXE phase
283 Builds a HOB that describes a chunk of system memory.
285 This function builds a HOB that describes a chunk of system memory.
286 It can only be invoked during PEI phase;
287 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
289 If there is no additional space for HOB creation, then ASSERT().
291 @param ResourceType The type of resource described by this HOB.
292 @param ResourceAttribute The resource attributes of the memory described by this HOB.
293 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
294 @param NumberOfBytes The length of the memory described by this HOB in bytes.
299 BuildResourceDescriptorHob (
300 IN EFI_RESOURCE_TYPE ResourceType
,
301 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
302 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
303 IN UINT64 NumberOfBytes
307 // PEI HOB is read only for DXE phase
313 Builds a customized HOB tagged with a GUID for identification and returns
314 the start address of GUID HOB data.
316 This function builds a customized HOB tagged with a GUID for identification
317 and returns the start address of GUID HOB data so that caller can fill the customized data.
318 The HOB Header and Name field is already stripped.
319 It can only be invoked during PEI phase;
320 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
322 If Guid is NULL, then ASSERT().
323 If there is no additional space for HOB creation, then ASSERT().
324 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
325 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
327 @param Guid The GUID to tag the customized HOB.
328 @param DataLength The size of the data payload for the GUID HOB.
330 @retval NULL The GUID HOB could not be allocated.
331 @retval others The start address of GUID HOB data.
337 IN CONST EFI_GUID
*Guid
,
342 // PEI HOB is read only for DXE phase
349 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
350 data field, and returns the start address of the GUID HOB data.
352 This function builds a customized HOB tagged with a GUID for identification and copies the input
353 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
354 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
355 The HOB Header and Name field is already stripped.
356 It can only be invoked during PEI phase;
357 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
359 If Guid is NULL, then ASSERT().
360 If Data is NULL and DataLength > 0, then ASSERT().
361 If there is no additional space for HOB creation, then ASSERT().
362 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
363 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
365 @param Guid The GUID to tag the customized HOB.
366 @param Data The data to be copied into the data field of the GUID HOB.
367 @param DataLength The size of the data payload for the GUID HOB.
369 @retval NULL The GUID HOB could not be allocated.
370 @retval others The start address of GUID HOB data.
376 IN CONST EFI_GUID
*Guid
,
382 // PEI HOB is read only for DXE phase
389 Builds a Firmware Volume HOB.
391 This function builds a Firmware Volume HOB.
392 It can only be invoked during PEI phase;
393 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
395 If there is no additional space for HOB creation, then ASSERT().
396 If the FvImage buffer is not at its required alignment, then ASSERT().
398 @param BaseAddress The base address of the Firmware Volume.
399 @param Length The size of the Firmware Volume in bytes.
405 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
410 // PEI HOB is read only for DXE phase
416 Builds a EFI_HOB_TYPE_FV2 HOB.
418 This function builds a EFI_HOB_TYPE_FV2 HOB.
419 It can only be invoked during PEI phase;
420 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
422 If there is no additional space for HOB creation, then ASSERT().
423 If the FvImage buffer is not at its required alignment, then ASSERT().
425 @param BaseAddress The base address of the Firmware Volume.
426 @param Length The size of the Firmware Volume in bytes.
427 @param FvName The name of the Firmware Volume.
428 @param FileName The name of the file.
434 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
436 IN CONST EFI_GUID
*FvName
,
437 IN CONST EFI_GUID
*FileName
444 Builds a EFI_HOB_TYPE_FV3 HOB.
446 This function builds a EFI_HOB_TYPE_FV3 HOB.
447 It can only be invoked during PEI phase;
448 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
450 If there is no additional space for HOB creation, then ASSERT().
451 If the FvImage buffer is not at its required alignment, then ASSERT().
453 @param BaseAddress The base address of the Firmware Volume.
454 @param Length The size of the Firmware Volume in bytes.
455 @param AuthenticationStatus The authentication status.
456 @param ExtractedFv TRUE if the FV was extracted as a file within
457 another firmware volume. FALSE otherwise.
458 @param FvName The name of the Firmware Volume.
459 Valid only if IsExtractedFv is TRUE.
460 @param FileName The name of the file.
461 Valid only if IsExtractedFv is TRUE.
467 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
469 IN UINT32 AuthenticationStatus
,
470 IN BOOLEAN ExtractedFv
,
471 IN CONST EFI_GUID
*FvName OPTIONAL
,
472 IN CONST EFI_GUID
*FileName OPTIONAL
479 Builds a Capsule Volume HOB.
481 This function builds a Capsule Volume HOB.
482 It can only be invoked during PEI phase;
483 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
485 If the platform does not support Capsule Volume HOBs, then ASSERT().
486 If there is no additional space for HOB creation, then ASSERT().
488 @param BaseAddress The base address of the Capsule Volume.
489 @param Length The size of the Capsule Volume in bytes.
495 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
500 // PEI HOB is read only for DXE phase
506 Builds a HOB for the CPU.
508 This function builds a HOB for the CPU.
509 It can only be invoked during PEI phase;
510 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
512 If there is no additional space for HOB creation, then ASSERT().
514 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
515 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
521 IN UINT8 SizeOfMemorySpace
,
522 IN UINT8 SizeOfIoSpace
526 // PEI HOB is read only for DXE phase
532 Builds a HOB for the Stack.
534 This function builds a HOB for the stack.
535 It can only be invoked during PEI phase;
536 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
538 If there is no additional space for HOB creation, then ASSERT().
540 @param BaseAddress The 64 bit physical address of the Stack.
541 @param Length The length of the stack in bytes.
547 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
552 // PEI HOB is read only for DXE phase
558 Builds a HOB for the BSP store.
560 This function builds a HOB for BSP store.
561 It can only be invoked during PEI phase;
562 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
564 If there is no additional space for HOB creation, then ASSERT().
566 @param BaseAddress The 64 bit physical address of the BSP.
567 @param Length The length of the BSP store in bytes.
568 @param MemoryType Type of memory allocated by this HOB.
574 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
576 IN EFI_MEMORY_TYPE MemoryType
580 // PEI HOB is read only for DXE phase
586 Builds a HOB for the memory allocation.
588 This function builds a HOB for the memory allocation.
589 It can only be invoked during PEI phase;
590 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
592 If there is no additional space for HOB creation, then ASSERT().
594 @param BaseAddress The 64 bit physical address of the memory.
595 @param Length The length of the memory allocation in bytes.
596 @param MemoryType Type of memory allocated by this HOB.
601 BuildMemoryAllocationHob (
602 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
604 IN EFI_MEMORY_TYPE MemoryType
608 // PEI HOB is read only for DXE phase