2 HOB Library implemenation 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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #define ASSERT(Expression) \
18 if (!(Expression)) { \
25 #include <Guid/HobList.h>
27 #include <Library/HobLib.h>
28 #include <Library/UefiLib.h>
29 #include <Library/BaseMemoryLib.h>
31 VOID
*mHobList
= NULL
;
34 The constructor function caches the pointer to HOB list.
36 The constructor function gets the start address of HOB list from system configuration table.
38 @param ImageHandle The firmware allocated handle for the EFI image.
39 @param SystemTable A pointer to the EFI System Table.
41 @retval EFI_SUCCESS The constructor successfully gets HobList.
42 @retval Other value The constructor can't get HobList.
48 IN EFI_HANDLE ImageHandle
,
49 IN EFI_SYSTEM_TABLE
*SystemTable
54 for (Index
= 0; Index
< SystemTable
->NumberOfTableEntries
; Index
++) {
55 if (CompareGuid (&gEfiHobListGuid
, &(SystemTable
->ConfigurationTable
[Index
].VendorGuid
))) {
56 mHobList
= SystemTable
->ConfigurationTable
[Index
].VendorTable
;
65 Returns the pointer to the HOB list.
67 This function returns the pointer to first HOB in the list.
68 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
69 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
70 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
71 Since the System Configuration Table does not exist that the time the DXE Core is
72 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
73 to manage the pointer to the HOB list.
75 If the pointer to the HOB list is NULL, then ASSERT().
77 @return The pointer to the HOB list.
86 ASSERT (mHobList
!= NULL
);
91 Returns the next instance of a HOB type from the starting HOB.
93 This function searches the first instance of a HOB type from the starting HOB pointer.
94 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
95 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
96 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
97 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
99 If HobStart is NULL, then ASSERT().
101 @param Type The HOB type to return.
102 @param HobStart The starting HOB pointer to search from.
104 @return The next instance of a HOB type from the starting HOB.
111 IN CONST VOID
*HobStart
114 EFI_PEI_HOB_POINTERS Hob
;
116 ASSERT (HobStart
!= NULL
);
118 Hob
.Raw
= (UINT8
*) HobStart
;
120 // Parse the HOB list until end of list or matching type is found.
122 while (!END_OF_HOB_LIST (Hob
)) {
123 if (Hob
.Header
->HobType
== Type
) {
126 Hob
.Raw
= GET_NEXT_HOB (Hob
);
132 Returns the first instance of a HOB type among the whole HOB list.
134 This function searches the first instance of a HOB type among the whole HOB list.
135 If there does not exist such HOB type in the HOB list, it will return NULL.
137 If the pointer to the HOB list is NULL, then ASSERT().
139 @param Type The HOB type to return.
141 @return The next instance of a HOB type from the starting HOB.
152 HobList
= GetHobList ();
153 return GetNextHob (Type
, HobList
);
157 Returns the next instance of the matched GUID HOB from the starting HOB.
159 This function searches the first instance of a HOB from the starting HOB pointer.
160 Such HOB should satisfy two conditions:
161 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
162 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
163 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
164 to extract the data section and its size information, respectively.
165 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
166 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
167 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
169 If Guid is NULL, then ASSERT().
170 If HobStart is NULL, then ASSERT().
172 @param Guid The GUID to match with in the HOB list.
173 @param HobStart A pointer to a Guid.
175 @return The next instance of the matched GUID HOB from the starting HOB.
181 IN CONST EFI_GUID
*Guid
,
182 IN CONST VOID
*HobStart
185 EFI_PEI_HOB_POINTERS GuidHob
;
187 GuidHob
.Raw
= (UINT8
*) HobStart
;
188 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
189 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
192 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
198 Returns the first instance of the matched GUID HOB among the whole HOB list.
200 This function searches the first instance of a HOB among the whole HOB list.
201 Such HOB should satisfy two conditions:
202 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
203 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
204 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
205 to extract the data section and its size information, respectively.
207 If the pointer to the HOB list is NULL, then ASSERT().
208 If Guid is NULL, then ASSERT().
210 @param Guid The GUID to match with in the HOB list.
212 @return The first instance of the matched GUID HOB among the whole HOB list.
218 IN CONST EFI_GUID
*Guid
223 HobList
= GetHobList ();
224 return GetNextGuidHob (Guid
, HobList
);
228 Get the system boot mode from the HOB list.
230 This function returns the system boot mode information from the
231 PHIT HOB in HOB list.
233 If the pointer to the HOB list is NULL, then ASSERT().
237 @return The Boot Mode.
246 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
248 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
250 return HandOffHob
->BootMode
;
254 Builds a HOB for a loaded PE32 module.
256 This function builds a HOB for a loaded PE32 module.
257 It can only be invoked during PEI phase;
258 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
260 If ModuleName is NULL, then ASSERT().
261 If there is no additional space for HOB creation, then ASSERT().
263 @param ModuleName The GUID File Name of the module.
264 @param MemoryAllocationModule The 64 bit physical address of the module.
265 @param ModuleLength The length of the module in bytes.
266 @param EntryPoint The 64 bit physical address of the module entry point.
272 IN CONST EFI_GUID
*ModuleName
,
273 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
274 IN UINT64 ModuleLength
,
275 IN EFI_PHYSICAL_ADDRESS EntryPoint
279 // PEI HOB is read only for DXE phase
285 Builds a HOB that describes a chunk of system memory.
287 This function builds a HOB that describes a chunk of system memory.
288 It can only be invoked during PEI phase;
289 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
291 If there is no additional space for HOB creation, then ASSERT().
293 @param ResourceType The type of resource described by this HOB.
294 @param ResourceAttribute The resource attributes of the memory described by this HOB.
295 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
296 @param NumberOfBytes The length of the memory described by this HOB in bytes.
301 BuildResourceDescriptorHob (
302 IN EFI_RESOURCE_TYPE ResourceType
,
303 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
304 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
305 IN UINT64 NumberOfBytes
309 // PEI HOB is read only for DXE phase
315 Builds a customized HOB tagged with a GUID for identification and returns
316 the start address of GUID HOB data.
318 This function builds a customized HOB tagged with a GUID for identification
319 and returns the start address of GUID HOB data so that caller can fill the customized data.
320 The HOB Header and Name field is already stripped.
321 It can only be invoked during PEI phase;
322 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
324 If Guid is NULL, then ASSERT().
325 If there is no additional space for HOB creation, then ASSERT().
326 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
327 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
329 @param Guid The GUID to tag the customized HOB.
330 @param DataLength The size of the data payload for the GUID HOB.
332 @retval NULL The GUID HOB could not be allocated.
333 @retval others The start address of GUID HOB data.
339 IN CONST EFI_GUID
*Guid
,
344 // PEI HOB is read only for DXE phase
351 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
352 data field, and returns the start address of the GUID HOB data.
354 This function builds a customized HOB tagged with a GUID for identification and copies the input
355 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
356 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
357 The HOB Header and Name field is already stripped.
358 It can only be invoked during PEI phase;
359 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
361 If Guid is NULL, then ASSERT().
362 If Data is NULL and DataLength > 0, then ASSERT().
363 If there is no additional space for HOB creation, then ASSERT().
364 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
365 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
367 @param Guid The GUID to tag the customized HOB.
368 @param Data The data to be copied into the data field of the GUID HOB.
369 @param DataLength The size of the data payload for the GUID HOB.
371 @retval NULL The GUID HOB could not be allocated.
372 @retval others The start address of GUID HOB data.
378 IN CONST EFI_GUID
*Guid
,
384 // PEI HOB is read only for DXE phase
391 Builds a Firmware Volume HOB.
393 This function builds a Firmware Volume HOB.
394 It can only be invoked during PEI phase;
395 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
397 If there is no additional space for HOB creation, then ASSERT().
398 If the FvImage buffer is not at its required alignment, then ASSERT().
400 @param BaseAddress The base address of the Firmware Volume.
401 @param Length The size of the Firmware Volume in bytes.
407 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
412 // PEI HOB is read only for DXE phase
418 Builds a EFI_HOB_TYPE_FV2 HOB.
420 This function builds a EFI_HOB_TYPE_FV2 HOB.
421 It can only be invoked during PEI phase;
422 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
424 If there is no additional space for HOB creation, then ASSERT().
425 If the FvImage buffer is not at its required alignment, then ASSERT().
427 @param BaseAddress The base address of the Firmware Volume.
428 @param Length The size of the Firmware Volume in bytes.
429 @param FvName The name of the Firmware Volume.
430 @param FileName The name of the file.
436 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
438 IN CONST EFI_GUID
*FvName
,
439 IN CONST EFI_GUID
*FileName
446 Builds a EFI_HOB_TYPE_FV3 HOB.
448 This function builds a EFI_HOB_TYPE_FV3 HOB.
449 It can only be invoked during PEI phase;
450 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
452 If there is no additional space for HOB creation, then ASSERT().
453 If the FvImage buffer is not at its required alignment, then ASSERT().
455 @param BaseAddress The base address of the Firmware Volume.
456 @param Length The size of the Firmware Volume in bytes.
457 @param AuthenticationStatus The authentication status.
458 @param ExtractedFv TRUE if the FV was extracted as a file within
459 another firmware volume. FALSE otherwise.
460 @param FvName The name of the Firmware Volume.
461 Valid only if IsExtractedFv is TRUE.
462 @param FileName The name of the file.
463 Valid only if IsExtractedFv is TRUE.
469 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
471 IN UINT32 AuthenticationStatus
,
472 IN BOOLEAN ExtractedFv
,
473 IN CONST EFI_GUID
*FvName
, OPTIONAL
474 IN CONST EFI_GUID
*FileName OPTIONAL
481 Builds a Capsule Volume HOB.
483 This function builds a Capsule Volume HOB.
484 It can only be invoked during PEI phase;
485 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
487 If the platform does not support Capsule Volume HOBs, then ASSERT().
488 If there is no additional space for HOB creation, then ASSERT().
490 @param BaseAddress The base address of the Capsule Volume.
491 @param Length The size of the Capsule Volume in bytes.
497 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
502 // PEI HOB is read only for DXE phase
508 Builds a HOB for the CPU.
510 This function builds a HOB for the CPU.
511 It can only be invoked during PEI phase;
512 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
514 If there is no additional space for HOB creation, then ASSERT().
516 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
517 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
523 IN UINT8 SizeOfMemorySpace
,
524 IN UINT8 SizeOfIoSpace
528 // PEI HOB is read only for DXE phase
534 Builds a HOB for the Stack.
536 This function builds a HOB for the stack.
537 It can only be invoked during PEI phase;
538 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
540 If there is no additional space for HOB creation, then ASSERT().
542 @param BaseAddress The 64 bit physical address of the Stack.
543 @param Length The length of the stack in bytes.
549 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
554 // PEI HOB is read only for DXE phase
560 Builds a HOB for the BSP store.
562 This function builds a HOB for BSP store.
563 It can only be invoked during PEI phase;
564 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
566 If there is no additional space for HOB creation, then ASSERT().
568 @param BaseAddress The 64 bit physical address of the BSP.
569 @param Length The length of the BSP store in bytes.
570 @param MemoryType Type of memory allocated by this HOB.
576 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
578 IN EFI_MEMORY_TYPE MemoryType
582 // PEI HOB is read only for DXE phase
588 Builds a HOB for the memory allocation.
590 This function builds a HOB for the memory allocation.
591 It can only be invoked during PEI phase;
592 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
594 If there is no additional space for HOB creation, then ASSERT().
596 @param BaseAddress The 64 bit physical address of the memory.
597 @param Length The length of the memory allocation in bytes.
598 @param MemoryType Type of memory allocated by this HOB.
603 BuildMemoryAllocationHob (
604 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
606 IN EFI_MEMORY_TYPE MemoryType
610 // PEI HOB is read only for DXE phase