2 HOB Library implemenation for Dxe Phase.
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Guid/HobList.h>
19 #include <Library/HobLib.h>
20 #include <Library/UefiLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseMemoryLib.h>
24 VOID
*mHobList
= NULL
;
27 Returns the pointer to the HOB list.
29 This function returns the pointer to first HOB in the list.
30 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
31 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
32 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
33 Since the System Configuration Table does not exist that the time the DXE Core is
34 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
35 to manage the pointer to the HOB list.
37 If the pointer to the HOB list is NULL, then ASSERT().
39 This function also caches the pointer to the HOB list retrieved.
41 @return The pointer to the HOB list.
52 if (mHobList
== NULL
) {
53 Status
= EfiGetSystemConfigurationTable (&gEfiHobListGuid
, &mHobList
);
54 ASSERT_EFI_ERROR (Status
);
55 ASSERT (mHobList
!= NULL
);
61 The constructor function caches the pointer to HOB list by calling GetHobList()
62 and will always return EFI_SUCCESS.
64 @param ImageHandle The firmware allocated handle for the EFI image.
65 @param SystemTable A pointer to the EFI System Table.
67 @retval EFI_SUCCESS The constructor successfully gets HobList.
73 IN EFI_HANDLE ImageHandle
,
74 IN EFI_SYSTEM_TABLE
*SystemTable
83 Returns the next instance of a HOB type from the starting HOB.
85 This function searches the first instance of a HOB type from the starting HOB pointer.
86 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
87 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
88 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
89 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
91 If HobStart is NULL, then ASSERT().
93 @param Type The HOB type to return.
94 @param HobStart The starting HOB pointer to search from.
96 @return The next instance of a HOB type from the starting HOB.
103 IN CONST VOID
*HobStart
106 EFI_PEI_HOB_POINTERS Hob
;
108 ASSERT (HobStart
!= NULL
);
110 Hob
.Raw
= (UINT8
*) HobStart
;
112 // Parse the HOB list until end of list or matching type is found.
114 while (!END_OF_HOB_LIST (Hob
)) {
115 if (Hob
.Header
->HobType
== Type
) {
118 Hob
.Raw
= GET_NEXT_HOB (Hob
);
124 Returns the first instance of a HOB type among the whole HOB list.
126 This function searches the first instance of a HOB type among the whole HOB list.
127 If there does not exist such HOB type in the HOB list, it will return NULL.
129 If the pointer to the HOB list is NULL, then ASSERT().
131 @param Type The HOB type to return.
133 @return The next instance of a HOB type from the starting HOB.
144 HobList
= GetHobList ();
145 return GetNextHob (Type
, HobList
);
149 Returns the next instance of the matched GUID HOB from the starting HOB.
151 This function searches the first instance of a HOB from the starting HOB pointer.
152 Such HOB should satisfy two conditions:
153 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
154 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
155 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
156 to extract the data section and its size information, respectively.
157 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
158 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
159 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
161 If Guid is NULL, then ASSERT().
162 If HobStart is NULL, then ASSERT().
164 @param Guid The GUID to match with in the HOB list.
165 @param HobStart A pointer to a Guid.
167 @return The next instance of the matched GUID HOB from the starting HOB.
173 IN CONST EFI_GUID
*Guid
,
174 IN CONST VOID
*HobStart
177 EFI_PEI_HOB_POINTERS GuidHob
;
179 GuidHob
.Raw
= (UINT8
*) HobStart
;
180 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
181 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
184 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
190 Returns the first instance of the matched GUID HOB among the whole HOB list.
192 This function searches the first instance of a HOB among the whole HOB list.
193 Such HOB should satisfy two conditions:
194 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
195 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
196 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
197 to extract the data section and its size information, respectively.
199 If the pointer to the HOB list is NULL, then ASSERT().
200 If Guid is NULL, then ASSERT().
202 @param Guid The GUID to match with in the HOB list.
204 @return The first instance of the matched GUID HOB among the whole HOB list.
210 IN CONST EFI_GUID
*Guid
215 HobList
= GetHobList ();
216 return GetNextGuidHob (Guid
, HobList
);
220 Get the system boot mode from the HOB list.
222 This function returns the system boot mode information from the
223 PHIT HOB in HOB list.
225 If the pointer to the HOB list is NULL, then ASSERT().
229 @return The Boot Mode.
238 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
240 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
242 return HandOffHob
->BootMode
;
246 Builds a HOB for a loaded PE32 module.
248 This function builds a HOB for a loaded PE32 module.
249 It can only be invoked during PEI phase;
250 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
252 If ModuleName is NULL, then ASSERT().
253 If there is no additional space for HOB creation, then ASSERT().
255 @param ModuleName The GUID File Name of the module.
256 @param MemoryAllocationModule The 64 bit physical address of the module.
257 @param ModuleLength The length of the module in bytes.
258 @param EntryPoint The 64 bit physical address of the module entry point.
264 IN CONST EFI_GUID
*ModuleName
,
265 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
266 IN UINT64 ModuleLength
,
267 IN EFI_PHYSICAL_ADDRESS EntryPoint
271 // PEI HOB is read only for DXE phase
277 Builds a HOB that describes a chunk of system memory with Owner GUID.
279 This function builds a HOB that describes a chunk of system memory.
280 It can only be invoked during PEI phase;
281 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
283 If there is no additional space for HOB creation, then ASSERT().
285 @param ResourceType The type of resource described by this HOB.
286 @param ResourceAttribute The resource attributes of the memory described by this HOB.
287 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
288 @param NumberOfBytes The length of the memory described by this HOB in bytes.
289 @param OwnerGUID GUID for the owner of this resource.
294 BuildResourceDescriptorWithOwnerHob (
295 IN EFI_RESOURCE_TYPE ResourceType
,
296 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
297 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
298 IN UINT64 NumberOfBytes
,
299 IN EFI_GUID
*OwnerGUID
303 // PEI HOB is read only for DXE phase
309 Builds a HOB that describes a chunk of system memory.
311 This function builds a HOB that describes a chunk of system memory.
312 It can only be invoked during PEI phase;
313 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
315 If there is no additional space for HOB creation, then ASSERT().
317 @param ResourceType The type of resource described by this HOB.
318 @param ResourceAttribute The resource attributes of the memory described by this HOB.
319 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
320 @param NumberOfBytes The length of the memory described by this HOB in bytes.
325 BuildResourceDescriptorHob (
326 IN EFI_RESOURCE_TYPE ResourceType
,
327 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
328 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
329 IN UINT64 NumberOfBytes
333 // PEI HOB is read only for DXE phase
339 Builds a customized HOB tagged with a GUID for identification and returns
340 the start address of GUID HOB data.
342 This function builds a customized HOB tagged with a GUID for identification
343 and returns the start address of GUID HOB data so that caller can fill the customized data.
344 The HOB Header and Name field is already stripped.
345 It can only be invoked during PEI phase;
346 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
348 If Guid is NULL, then ASSERT().
349 If there is no additional space for HOB creation, then ASSERT().
350 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
351 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
353 @param Guid The GUID to tag the customized HOB.
354 @param DataLength The size of the data payload for the GUID HOB.
356 @retval NULL The GUID HOB could not be allocated.
357 @retval others The start address of GUID HOB data.
363 IN CONST EFI_GUID
*Guid
,
368 // PEI HOB is read only for DXE phase
375 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
376 data field, and returns the start address of the GUID HOB data.
378 This function builds a customized HOB tagged with a GUID for identification and copies the input
379 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
380 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
381 The HOB Header and Name field is already stripped.
382 It can only be invoked during PEI phase;
383 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
385 If Guid is NULL, then ASSERT().
386 If Data is NULL and DataLength > 0, then ASSERT().
387 If there is no additional space for HOB creation, then ASSERT().
388 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
389 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
391 @param Guid The GUID to tag the customized HOB.
392 @param Data The data to be copied into the data field of the GUID HOB.
393 @param DataLength The size of the data payload for the GUID HOB.
395 @retval NULL The GUID HOB could not be allocated.
396 @retval others The start address of GUID HOB data.
402 IN CONST EFI_GUID
*Guid
,
408 // PEI HOB is read only for DXE phase
415 Builds a Firmware Volume HOB.
417 This function builds a Firmware Volume HOB.
418 It can only be invoked during PEI phase;
419 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
421 If there is no additional space for HOB creation, then ASSERT().
422 If the FvImage buffer is not at its required alignment, then ASSERT().
424 @param BaseAddress The base address of the Firmware Volume.
425 @param Length The size of the Firmware Volume in bytes.
431 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
436 // PEI HOB is read only for DXE phase
442 Builds a EFI_HOB_TYPE_FV2 HOB.
444 This function builds a EFI_HOB_TYPE_FV2 HOB.
445 It can only be invoked during PEI phase;
446 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
448 If there is no additional space for HOB creation, then ASSERT().
449 If the FvImage buffer is not at its required alignment, then ASSERT().
451 @param BaseAddress The base address of the Firmware Volume.
452 @param Length The size of the Firmware Volume in bytes.
453 @param FvName The name of the Firmware Volume.
454 @param FileName The name of the file.
460 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
462 IN CONST EFI_GUID
*FvName
,
463 IN CONST EFI_GUID
*FileName
471 Builds a Capsule Volume HOB.
473 This function builds a Capsule Volume HOB.
474 It can only be invoked during PEI phase;
475 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
477 If the platform does not support Capsule Volume HOBs, then ASSERT().
478 If there is no additional space for HOB creation, then ASSERT().
480 @param BaseAddress The base address of the Capsule Volume.
481 @param Length The size of the Capsule Volume in bytes.
487 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
492 // PEI HOB is read only for DXE phase
498 Builds a HOB for the CPU.
500 This function builds a HOB for the CPU.
501 It can only be invoked during PEI phase;
502 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
504 If there is no additional space for HOB creation, then ASSERT().
506 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
507 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
513 IN UINT8 SizeOfMemorySpace
,
514 IN UINT8 SizeOfIoSpace
518 // PEI HOB is read only for DXE phase
524 Builds a HOB for the Stack.
526 This function builds a HOB for the stack.
527 It can only be invoked during PEI phase;
528 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
530 If there is no additional space for HOB creation, then ASSERT().
532 @param BaseAddress The 64 bit physical address of the Stack.
533 @param Length The length of the stack in bytes.
539 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
544 // PEI HOB is read only for DXE phase
550 Builds a HOB for the BSP store.
552 This function builds a HOB for BSP store.
553 It can only be invoked during PEI phase;
554 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
556 If there is no additional space for HOB creation, then ASSERT().
558 @param BaseAddress The 64 bit physical address of the BSP.
559 @param Length The length of the BSP store in bytes.
560 @param MemoryType Type of memory allocated by this HOB.
566 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
568 IN EFI_MEMORY_TYPE MemoryType
572 // PEI HOB is read only for DXE phase
578 Builds a HOB for the memory allocation.
580 This function builds a HOB for the memory allocation.
581 It can only be invoked during PEI phase;
582 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
584 If there is no additional space for HOB creation, then ASSERT().
586 @param BaseAddress The 64 bit physical address of the memory.
587 @param Length The length of the memory allocation in bytes.
588 @param MemoryType Type of memory allocated by this HOB.
593 BuildMemoryAllocationHob (
594 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
596 IN EFI_MEMORY_TYPE MemoryType
600 // PEI HOB is read only for DXE phase