2 HOB Library implementation for DxeCore driver.
4 Copyright (c) 2006 - 2018, 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/DxeCoreEntryPoint.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
) {
79 Hob
.Raw
= GET_NEXT_HOB (Hob
);
86 Returns the first instance of a HOB type among the whole HOB list.
88 This function searches the first instance of a HOB type among the whole HOB list.
89 If there does not exist such HOB type in the HOB list, it will return NULL.
91 If the pointer to the HOB list is NULL, then ASSERT().
93 @param Type The HOB type to return.
95 @return The next instance of a HOB type from the starting HOB.
106 HobList
= GetHobList ();
107 return GetNextHob (Type
, HobList
);
111 Returns the next instance of the matched GUID HOB from the starting HOB.
113 This function searches the first instance of a HOB from the starting HOB pointer.
114 Such HOB should satisfy two conditions:
115 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION, and its GUID Name equals to the input Guid.
116 If such a HOB from the starting HOB pointer does not exist, it will return NULL.
117 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
118 to extract the data section and its size information, respectively.
119 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
120 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
121 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
123 If Guid is NULL, then ASSERT().
124 If HobStart is NULL, then ASSERT().
126 @param Guid The GUID to match with in the HOB list.
127 @param HobStart A pointer to a Guid.
129 @return The next instance of the matched GUID HOB from the starting HOB.
135 IN CONST EFI_GUID
*Guid
,
136 IN CONST VOID
*HobStart
139 EFI_PEI_HOB_POINTERS GuidHob
;
141 GuidHob
.Raw
= (UINT8
*)HobStart
;
142 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
143 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
147 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
154 Returns the first instance of the matched GUID HOB among the whole HOB list.
156 This function searches the first instance of a HOB among the whole HOB list.
157 Such HOB should satisfy two conditions:
158 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
159 If such a HOB from the starting HOB pointer does not exist, it will return NULL.
160 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
161 to extract the data section and its size information, respectively.
163 If the pointer to the HOB list is NULL, then ASSERT().
164 If Guid is NULL, then ASSERT().
166 @param Guid The GUID to match with in the HOB list.
168 @return The first instance of the matched GUID HOB among the whole HOB list.
174 IN CONST EFI_GUID
*Guid
179 HobList
= GetHobList ();
180 return GetNextGuidHob (Guid
, HobList
);
184 Get the system boot mode from the HOB list.
186 This function returns the system boot mode information from the
187 PHIT HOB in HOB list.
189 If the pointer to the HOB list is NULL, then ASSERT().
193 @return The Boot Mode.
202 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
204 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*)GetHobList ();
206 return HandOffHob
->BootMode
;
210 Builds a HOB for a loaded PE32 module.
212 This function builds a HOB for a loaded PE32 module.
213 It can only be invoked during PEI phase;
214 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
216 If ModuleName is NULL, then ASSERT().
217 If there is no additional space for HOB creation, then ASSERT().
219 @param ModuleName The GUID File Name of the module.
220 @param MemoryAllocationModule The 64 bit physical address of the module.
221 @param ModuleLength The length of the module in bytes.
222 @param EntryPoint The 64 bit physical address of the module entry point.
228 IN CONST EFI_GUID
*ModuleName
,
229 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
230 IN UINT64 ModuleLength
,
231 IN EFI_PHYSICAL_ADDRESS EntryPoint
235 // PEI HOB is read only for DXE phase
241 Builds a HOB that describes a chunk of system memory with Owner GUID.
243 This function builds a HOB that describes a chunk of system memory.
244 It can only be invoked during PEI phase;
245 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
247 If there is no additional space for HOB creation, then ASSERT().
249 @param ResourceType The type of resource described by this HOB.
250 @param ResourceAttribute The resource attributes of the memory described by this HOB.
251 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
252 @param NumberOfBytes The length of the memory described by this HOB in bytes.
253 @param OwnerGUID GUID for the owner of this resource.
258 BuildResourceDescriptorWithOwnerHob (
259 IN EFI_RESOURCE_TYPE ResourceType
,
260 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
261 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
262 IN UINT64 NumberOfBytes
,
263 IN EFI_GUID
*OwnerGUID
267 // PEI HOB is read only for DXE phase
273 Builds a HOB that describes a chunk of system memory.
275 This function builds a HOB that describes a chunk of system memory.
276 It can only be invoked during PEI phase;
277 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
279 If there is no additional space for HOB creation, then ASSERT().
281 @param ResourceType The type of resource described by this HOB.
282 @param ResourceAttribute The resource attributes of the memory described by this HOB.
283 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
284 @param NumberOfBytes The length of the memory described by this HOB in bytes.
289 BuildResourceDescriptorHob (
290 IN EFI_RESOURCE_TYPE ResourceType
,
291 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
292 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
293 IN UINT64 NumberOfBytes
297 // PEI HOB is read only for DXE phase
303 Builds a customized HOB tagged with a GUID for identification and returns
304 the start address of GUID HOB data.
306 This function builds a customized HOB tagged with a GUID for identification
307 and returns the start address of GUID HOB data so that caller can fill the customized data.
308 The HOB Header and Name field is already stripped.
309 It can only be invoked during PEI phase.
310 For DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
312 If Guid is NULL, then ASSERT().
313 If there is no additional space for HOB creation, then ASSERT().
314 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
315 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
317 @param Guid The GUID to tag the customized HOB.
318 @param DataLength The size of the data payload for the GUID HOB.
320 @retval NULL The GUID HOB could not be allocated.
321 @retval others The start address of GUID HOB data.
327 IN CONST EFI_GUID
*Guid
,
332 // PEI HOB is read only for DXE phase
339 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
340 data field, and returns the start address of the GUID HOB data.
342 This function builds a customized HOB tagged with a GUID for identification and copies the input
343 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
344 invoked during PEI phase; for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
345 The HOB Header and Name field is already stripped.
346 It can only be invoked during PEI phase.
347 For DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
349 If Guid is NULL, then ASSERT().
350 If Data is NULL and DataLength > 0, then ASSERT().
351 If there is no additional space for HOB creation, then ASSERT().
352 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
353 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
355 @param Guid The GUID to tag the customized HOB.
356 @param Data The data to be copied into the data field of the GUID HOB.
357 @param DataLength The size of the data payload for the GUID HOB.
359 @retval NULL The GUID HOB could not be allocated.
360 @retval others The start address of GUID HOB data.
366 IN CONST EFI_GUID
*Guid
,
372 // PEI HOB is read only for DXE phase
379 Builds a Firmware Volume HOB.
381 This function builds a Firmware Volume HOB.
382 It can only be invoked during PEI phase;
383 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
385 If there is no additional space for HOB creation, then ASSERT().
386 If the FvImage buffer is not at its required alignment, then ASSERT().
388 @param BaseAddress The base address of the Firmware Volume.
389 @param Length The size of the Firmware Volume in bytes.
395 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
400 // PEI HOB is read only for DXE phase
406 Builds a EFI_HOB_TYPE_FV2 HOB.
408 This function builds a EFI_HOB_TYPE_FV2 HOB.
409 It can only be invoked during PEI phase;
410 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
412 If there is no additional space for HOB creation, then ASSERT().
413 If the FvImage buffer is not at its required alignment, then ASSERT().
415 @param BaseAddress The base address of the Firmware Volume.
416 @param Length The size of the Firmware Volume in bytes.
417 @param FvName The name of the Firmware Volume.
418 @param FileName The name of the file.
424 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
426 IN CONST EFI_GUID
*FvName
,
427 IN CONST EFI_GUID
*FileName
434 Builds a EFI_HOB_TYPE_FV3 HOB.
436 This function builds a EFI_HOB_TYPE_FV3 HOB.
437 It can only be invoked during PEI phase;
438 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
440 If there is no additional space for HOB creation, then ASSERT().
441 If the FvImage buffer is not at its required alignment, then ASSERT().
443 @param BaseAddress The base address of the Firmware Volume.
444 @param Length The size of the Firmware Volume in bytes.
445 @param AuthenticationStatus The authentication status.
446 @param ExtractedFv TRUE if the FV was extracted as a file within
447 another firmware volume. FALSE otherwise.
448 @param FvName The name of the Firmware Volume.
449 Valid only if IsExtractedFv is TRUE.
450 @param FileName The name of the file.
451 Valid only if IsExtractedFv is TRUE.
457 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
459 IN UINT32 AuthenticationStatus
,
460 IN BOOLEAN ExtractedFv
,
461 IN CONST EFI_GUID
*FvName OPTIONAL
,
462 IN CONST EFI_GUID
*FileName OPTIONAL
469 Builds a Capsule Volume HOB.
471 This function builds a Capsule Volume HOB.
472 It can only be invoked during PEI phase;
473 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
475 If the platform does not support Capsule Volume HOBs, then ASSERT().
476 If there is no additional space for HOB creation, then ASSERT().
478 @param BaseAddress The base address of the Capsule Volume.
479 @param Length The size of the Capsule Volume in bytes.
485 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
490 // PEI HOB is read only for DXE phase
496 Builds a HOB for the CPU.
498 This function builds a HOB for the CPU.
499 It can only be invoked during PEI phase;
500 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
502 If there is no additional space for HOB creation, then ASSERT().
504 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
505 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
511 IN UINT8 SizeOfMemorySpace
,
512 IN UINT8 SizeOfIoSpace
516 // PEI HOB is read only for DXE phase
522 Builds a HOB for the Stack.
524 This function builds a HOB for the stack.
525 It can only be invoked during PEI phase;
526 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
528 If there is no additional space for HOB creation, then ASSERT().
530 @param BaseAddress The 64 bit physical address of the Stack.
531 @param Length The length of the stack in bytes.
537 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
542 // PEI HOB is read only for DXE phase
548 Builds a HOB for the BSP store.
550 This function builds a HOB for BSP store.
551 It can only be invoked during PEI phase;
552 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
554 If there is no additional space for HOB creation, then ASSERT().
556 @param BaseAddress The 64 bit physical address of the BSP.
557 @param Length The length of the BSP store in bytes.
558 @param MemoryType Type of memory allocated by this HOB.
564 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
566 IN EFI_MEMORY_TYPE MemoryType
570 // PEI HOB is read only for DXE phase
576 Builds a HOB for the memory allocation.
578 This function builds a HOB for the memory allocation.
579 It can only be invoked during PEI phase;
580 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
582 If there is no additional space for HOB creation, then ASSERT().
584 @param BaseAddress The 64 bit physical address of the memory.
585 @param Length The length of the memory allocation in bytes.
586 @param MemoryType Type of memory allocated by this HOB.
591 BuildMemoryAllocationHob (
592 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
594 IN EFI_MEMORY_TYPE MemoryType
598 // PEI HOB is read only for DXE phase