2 HOB Library implementation for DxeCore driver.
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
5 All rights reserved. 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.
19 #include <Library/HobLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/DxeCoreEntryPoint.h>
25 Returns the pointer to the HOB list.
27 This function returns the pointer to first HOB in the list.
29 @return The pointer to the HOB list.
42 Returns the next instance of a HOB type from the starting HOB.
44 This function searches the first instance of a HOB type from the starting HOB pointer.
45 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
46 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
47 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
48 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
49 If HobStart is NULL, then ASSERT().
51 @param Type The HOB type to return.
52 @param HobStart The starting HOB pointer to search from.
54 @return The next instance of a HOB type from the starting HOB.
61 IN CONST VOID
*HobStart
64 EFI_PEI_HOB_POINTERS Hob
;
66 ASSERT (HobStart
!= NULL
);
68 Hob
.Raw
= (UINT8
*) HobStart
;
70 // Parse the HOB list until end of list or matching type is found.
72 while (!END_OF_HOB_LIST (Hob
)) {
73 if (Hob
.Header
->HobType
== Type
) {
76 Hob
.Raw
= GET_NEXT_HOB (Hob
);
82 Returns the first instance of a HOB type among the whole HOB list.
84 This function searches the first instance of a HOB type among the whole HOB list.
85 If there does not exist such HOB type in the HOB list, it will return NULL.
87 @param Type The HOB type to return.
89 @return The next instance of a HOB type from the starting HOB.
100 HobList
= GetHobList ();
101 return GetNextHob (Type
, HobList
);
105 This function searches the first instance of a HOB from the starting HOB pointer.
106 Such HOB should satisfy two conditions:
107 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
108 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
109 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
110 to extract the data section and its size info respectively.
111 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
112 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
113 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
114 If Guid is NULL, then ASSERT().
115 If HobStart is NULL, then ASSERT().
117 @param Guid The GUID to match with in the HOB list.
118 @param HobStart A pointer to a Guid.
120 @return The next instance of the matched GUID HOB from the starting HOB.
126 IN CONST EFI_GUID
*Guid
,
127 IN CONST VOID
*HobStart
130 EFI_PEI_HOB_POINTERS GuidHob
;
132 GuidHob
.Raw
= (UINT8
*) HobStart
;
133 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
134 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
137 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
143 This function searches the first instance of a HOB among the whole HOB list.
144 Such HOB should satisfy two conditions:
145 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
146 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
147 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
148 to extract the data section and its size info respectively.
149 If Guid is NULL, then ASSERT().
151 @param Guid The GUID to match with in the HOB list.
153 @return The first instance of the matched GUID HOB among the whole HOB list.
159 IN CONST EFI_GUID
*Guid
164 HobList
= GetHobList ();
165 return GetNextGuidHob (Guid
, HobList
);
169 Get the Boot Mode from the HOB list.
171 This function returns the system boot mode information from the
172 PHIT HOB in HOB list.
176 @return The Boot Mode.
185 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
187 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
188 ASSERT (HandOffHob
!= NULL
);
190 return HandOffHob
->BootMode
;
193 Builds a HOB for a loaded PE32 module.
195 This function builds a HOB for a loaded PE32 module.
196 It can only be invoked during PEI phase;
197 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
198 If ModuleName is NULL, then ASSERT().
199 If there is no additional space for HOB creation, then ASSERT().
201 @param ModuleName The GUID File Name of the module.
202 @param MemoryAllocationModule The 64 bit physical address of the module.
203 @param ModuleLength The length of the module in bytes.
204 @param EntryPoint The 64 bit physical address of the module's entry point.
210 IN CONST EFI_GUID
*ModuleName
,
211 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
212 IN UINT64 ModuleLength
,
213 IN EFI_PHYSICAL_ADDRESS EntryPoint
217 // PEI HOB is read only for DXE phase
223 Builds a HOB that describes a chunk of system memory.
225 This function builds a HOB that describes a chunk of system memory.
226 It can only be invoked during PEI phase;
227 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
228 If there is no additional space for HOB creation, then ASSERT().
230 @param ResourceType The type of resource described by this HOB.
231 @param ResourceAttribute The resource attributes of the memory described by this HOB.
232 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
233 @param NumberOfBytes The length of the memory described by this HOB in bytes.
238 BuildResourceDescriptorHob (
239 IN EFI_RESOURCE_TYPE ResourceType
,
240 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
241 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
242 IN UINT64 NumberOfBytes
246 // PEI HOB is read only for DXE phase
252 Builds a GUID HOB with a certain data length.
254 This function builds a customized HOB tagged with a GUID for identification
255 and returns the start address of GUID HOB data so that caller can fill the customized data.
256 The HOB Header and Name field is already stripped.
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.
259 If Guid is NULL, then ASSERT().
260 If there is no additional space for HOB creation, then ASSERT().
261 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
263 @param Guid The GUID to tag the customized HOB.
264 @param DataLength The size of the data payload for the GUID HOB.
266 @return The start address of GUID HOB data.
272 IN CONST EFI_GUID
*Guid
,
277 // PEI HOB is read only for DXE phase
284 Copies a data buffer to a newly-built HOB.
286 This function builds a customized HOB tagged with a GUID for identification,
287 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
288 The HOB Header and Name field is already stripped.
289 It can only be invoked during PEI phase;
290 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
291 If Guid is NULL, then ASSERT().
292 If Data is NULL and DataLength > 0, then ASSERT().
293 If there is no additional space for HOB creation, then ASSERT().
294 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
296 @param Guid The GUID to tag the customized HOB.
297 @param Data The data to be copied into the data field of the GUID HOB.
298 @param DataLength The size of the data payload for the GUID HOB.
300 @return The start address of GUID HOB data.
306 IN CONST EFI_GUID
*Guid
,
312 // PEI HOB is read only for DXE phase
319 Builds a Firmware Volume HOB.
321 This function builds a Firmware Volume HOB.
322 It can only be invoked during PEI phase;
323 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
324 If there is no additional space for HOB creation, then ASSERT().
326 @param BaseAddress The base address of the Firmware Volume.
327 @param Length The size of the Firmware Volume in bytes.
333 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
338 // PEI HOB is read only for DXE phase
344 Builds a EFI_HOB_TYPE_FV2 HOB.
346 This function builds a EFI_HOB_TYPE_FV2 HOB.
347 It can only be invoked during PEI phase;
348 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
349 If there is no additional space for HOB creation, then ASSERT().
351 @param BaseAddress The base address of the Firmware Volume.
352 @param Length The size of the Firmware Volume in bytes.
353 @param FvName The name of the Firmware Volume.
354 @param FileName The name of the file.
360 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
362 IN CONST EFI_GUID
*FvName
,
363 IN CONST EFI_GUID
*FileName
370 Builds a Capsule Volume HOB.
372 This function builds a Capsule Volume HOB.
373 It can only be invoked during PEI phase;
374 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
375 If there is no additional space for HOB creation, then ASSERT().
377 @param BaseAddress The base address of the Capsule Volume.
378 @param Length The size of the Capsule Volume in bytes.
384 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
389 // PEI HOB is read only for DXE phase
395 Builds a HOB for the CPU.
397 This function builds a HOB for the CPU.
398 It can only be invoked during PEI phase;
399 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
400 If there is no additional space for HOB creation, then ASSERT().
402 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
403 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
409 IN UINT8 SizeOfMemorySpace
,
410 IN UINT8 SizeOfIoSpace
414 // PEI HOB is read only for DXE phase
420 Builds a HOB for the Stack.
422 This function builds a HOB for the stack.
423 It can only be invoked during PEI phase;
424 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
425 If there is no additional space for HOB creation, then ASSERT().
427 @param BaseAddress The 64 bit physical address of the Stack.
428 @param Length The length of the stack in bytes.
434 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
439 // PEI HOB is read only for DXE phase
445 Builds a HOB for the BSP store.
447 This function builds a HOB for BSP store.
448 It can only be invoked during PEI phase;
449 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().
452 @param BaseAddress The 64 bit physical address of the BSP.
453 @param Length The length of the BSP store in bytes.
454 @param MemoryType Type of memory allocated by this HOB.
460 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
462 IN EFI_MEMORY_TYPE MemoryType
466 // PEI HOB is read only for DXE phase
472 Builds a HOB for the memory allocation.
474 This function builds a HOB for the memory allocation.
475 It can only be invoked during PEI phase;
476 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
477 If there is no additional space for HOB creation, then ASSERT().
479 @param BaseAddress The 64 bit physical address of the memory.
480 @param Length The length of the memory allocation in bytes.
481 @param MemoryType Type of memory allocated by this HOB.
486 BuildMemoryAllocationHob (
487 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
489 IN EFI_MEMORY_TYPE MemoryType
493 // PEI HOB is read only for DXE phase