2 HOB Library implementation for DxeCore driver.
4 Copyright (c) 2006 - 2012, 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 <Library/HobLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/DxeCoreEntryPoint.h>
23 Returns the pointer to the HOB list.
25 This function returns the pointer to first HOB in the list.
26 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
27 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
28 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
29 Since the System Configuration Table does not exist that the time the DXE Core is
30 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
31 to manage the pointer to the HOB list.
33 If the pointer to the HOB list is NULL, then ASSERT().
35 @return The pointer to the HOB list.
44 ASSERT (gHobList
!= NULL
);
49 Returns the next instance of a HOB type from the starting HOB.
51 This function searches the first instance of a HOB type from the starting HOB pointer.
52 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
53 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
54 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
55 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
57 If HobStart is NULL, then ASSERT().
59 @param Type The HOB type to return.
60 @param HobStart The starting HOB pointer to search from.
62 @return The next instance of a HOB type from the starting HOB.
69 IN CONST VOID
*HobStart
72 EFI_PEI_HOB_POINTERS Hob
;
74 ASSERT (HobStart
!= NULL
);
76 Hob
.Raw
= (UINT8
*) HobStart
;
78 // Parse the HOB list until end of list or matching type is found.
80 while (!END_OF_HOB_LIST (Hob
)) {
81 if (Hob
.Header
->HobType
== Type
) {
84 Hob
.Raw
= GET_NEXT_HOB (Hob
);
90 Returns the first instance of a HOB type among the whole HOB list.
92 This function searches the first instance of a HOB type among the whole HOB list.
93 If there does not exist such HOB type in the HOB list, it will return NULL.
95 If the pointer to the HOB list is NULL, then ASSERT().
97 @param Type The HOB type to return.
99 @return The next instance of a HOB type from the starting HOB.
110 HobList
= GetHobList ();
111 return GetNextHob (Type
, HobList
);
115 Returns the next instance of the matched GUID HOB from the starting HOB.
117 This function searches the first instance of a HOB from the starting HOB pointer.
118 Such HOB should satisfy two conditions:
119 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION, and its GUID Name equals to the input Guid.
120 If such a HOB from the starting HOB pointer does not exist, it will return NULL.
121 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
122 to extract the data section and its size information, respectively.
123 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
124 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
125 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
127 If Guid is NULL, then ASSERT().
128 If HobStart is NULL, then ASSERT().
130 @param Guid The GUID to match with in the HOB list.
131 @param HobStart A pointer to a Guid.
133 @return The next instance of the matched GUID HOB from the starting HOB.
139 IN CONST EFI_GUID
*Guid
,
140 IN CONST VOID
*HobStart
143 EFI_PEI_HOB_POINTERS GuidHob
;
145 GuidHob
.Raw
= (UINT8
*) HobStart
;
146 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
147 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
150 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
156 Returns the first instance of the matched GUID HOB among the whole HOB list.
158 This function searches the first instance of a HOB among the whole HOB list.
159 Such HOB should satisfy two conditions:
160 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
161 If such a HOB from the starting HOB pointer does not exist, it will return NULL.
162 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
163 to extract the data section and its size information, respectively.
165 If the pointer to the HOB list is NULL, then ASSERT().
166 If Guid is NULL, then ASSERT().
168 @param Guid The GUID to match with in the HOB list.
170 @return The first instance of the matched GUID HOB among the whole HOB list.
176 IN CONST EFI_GUID
*Guid
181 HobList
= GetHobList ();
182 return GetNextGuidHob (Guid
, HobList
);
186 Get the system boot mode from the HOB list.
188 This function returns the system boot mode information from the
189 PHIT HOB in HOB list.
191 If the pointer to the HOB list is NULL, then ASSERT().
195 @return The Boot Mode.
204 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
206 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
208 return HandOffHob
->BootMode
;
212 Builds a HOB for a loaded PE32 module.
214 This function builds a HOB for a loaded PE32 module.
215 It can only be invoked during PEI phase;
216 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
218 If ModuleName is NULL, then ASSERT().
219 If there is no additional space for HOB creation, then ASSERT().
221 @param ModuleName The GUID File Name of the module.
222 @param MemoryAllocationModule The 64 bit physical address of the module.
223 @param ModuleLength The length of the module in bytes.
224 @param EntryPoint The 64 bit physical address of the module entry point.
230 IN CONST EFI_GUID
*ModuleName
,
231 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
232 IN UINT64 ModuleLength
,
233 IN EFI_PHYSICAL_ADDRESS EntryPoint
237 // PEI HOB is read only for DXE phase
243 Builds a HOB that describes a chunk of system memory.
245 This function builds a HOB that describes a chunk of system memory.
246 It can only be invoked during PEI phase;
247 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
249 If there is no additional space for HOB creation, then ASSERT().
251 @param ResourceType The type of resource described by this HOB.
252 @param ResourceAttribute The resource attributes of the memory described by this HOB.
253 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
254 @param NumberOfBytes The length of the memory described by this HOB in bytes.
259 BuildResourceDescriptorHob (
260 IN EFI_RESOURCE_TYPE ResourceType
,
261 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
262 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
263 IN UINT64 NumberOfBytes
267 // PEI HOB is read only for DXE phase
273 Builds a customized HOB tagged with a GUID for identification and returns
274 the start address of GUID HOB data.
276 This function builds a customized HOB tagged with a GUID for identification
277 and returns the start address of GUID HOB data so that caller can fill the customized data.
278 The HOB Header and Name field is already stripped.
279 It can only be invoked during PEI phase.
280 For DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
282 If Guid is NULL, then ASSERT().
283 If there is no additional space for HOB creation, then ASSERT().
284 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
285 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
287 @param Guid The GUID to tag the customized HOB.
288 @param DataLength The size of the data payload for the GUID HOB.
290 @retval NULL The GUID HOB could not be allocated.
291 @retval others The start address of GUID HOB data.
297 IN CONST EFI_GUID
*Guid
,
302 // PEI HOB is read only for DXE phase
309 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
310 data field, and returns the start address of the GUID HOB data.
312 This function builds a customized HOB tagged with a GUID for identification and copies the input
313 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
314 invoked during PEI phase; for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
315 The HOB Header and Name field is already stripped.
316 It can only be invoked during PEI phase.
317 For DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
319 If Guid is NULL, then ASSERT().
320 If Data is NULL and DataLength > 0, then ASSERT().
321 If there is no additional space for HOB creation, then ASSERT().
322 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
323 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
325 @param Guid The GUID to tag the customized HOB.
326 @param Data The data to be copied into the data field of the GUID HOB.
327 @param DataLength The size of the data payload for the GUID HOB.
329 @retval NULL The GUID HOB could not be allocated.
330 @retval others The start address of GUID HOB data.
336 IN CONST EFI_GUID
*Guid
,
342 // PEI HOB is read only for DXE phase
349 Builds a Firmware Volume HOB.
351 This function builds a Firmware Volume HOB.
352 It can only be invoked during PEI phase;
353 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
355 If there is no additional space for HOB creation, then ASSERT().
357 @param BaseAddress The base address of the Firmware Volume.
358 @param Length The size of the Firmware Volume in bytes.
364 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
369 // PEI HOB is read only for DXE phase
375 Builds a EFI_HOB_TYPE_FV2 HOB.
377 This function builds a EFI_HOB_TYPE_FV2 HOB.
378 It can only be invoked during PEI phase;
379 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
381 If there is no additional space for HOB creation, then ASSERT().
383 @param BaseAddress The base address of the Firmware Volume.
384 @param Length The size of the Firmware Volume in bytes.
385 @param FvName The name of the Firmware Volume.
386 @param FileName The name of the file.
392 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
394 IN CONST EFI_GUID
*FvName
,
395 IN CONST EFI_GUID
*FileName
402 Builds a Capsule Volume HOB.
404 This function builds a Capsule Volume HOB.
405 It can only be invoked during PEI phase;
406 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
408 If the platform does not support Capsule Volume HOBs, then ASSERT().
409 If there is no additional space for HOB creation, then ASSERT().
411 @param BaseAddress The base address of the Capsule Volume.
412 @param Length The size of the Capsule Volume in bytes.
418 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
423 // PEI HOB is read only for DXE phase
429 Builds a HOB for the CPU.
431 This function builds a HOB for the CPU.
432 It can only be invoked during PEI phase;
433 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
435 If there is no additional space for HOB creation, then ASSERT().
437 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
438 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
444 IN UINT8 SizeOfMemorySpace
,
445 IN UINT8 SizeOfIoSpace
449 // PEI HOB is read only for DXE phase
455 Builds a HOB for the Stack.
457 This function builds a HOB for the stack.
458 It can only be invoked during PEI phase;
459 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
461 If there is no additional space for HOB creation, then ASSERT().
463 @param BaseAddress The 64 bit physical address of the Stack.
464 @param Length The length of the stack in bytes.
470 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
475 // PEI HOB is read only for DXE phase
481 Builds a HOB for the BSP store.
483 This function builds a HOB for BSP store.
484 It can only be invoked during PEI phase;
485 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
487 If there is no additional space for HOB creation, then ASSERT().
489 @param BaseAddress The 64 bit physical address of the BSP.
490 @param Length The length of the BSP store in bytes.
491 @param MemoryType Type of memory allocated by this HOB.
497 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
499 IN EFI_MEMORY_TYPE MemoryType
503 // PEI HOB is read only for DXE phase
509 Builds a HOB for the memory allocation.
511 This function builds a HOB for the memory allocation.
512 It can only be invoked during PEI phase;
513 for DXE phase, it will ASSERT() because PEI HOB is read-only for DXE phase.
515 If there is no additional space for HOB creation, then ASSERT().
517 @param BaseAddress The 64 bit physical address of the memory.
518 @param Length The length of the memory allocation in bytes.
519 @param MemoryType Type of memory allocated by this HOB.
524 BuildMemoryAllocationHob (
525 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
527 IN EFI_MEMORY_TYPE MemoryType
531 // PEI HOB is read only for DXE phase