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.
26 ASSERT() if the HOB list returned by GetHobList() is NULL.
28 This function returns the pointer to first HOB in the list.
30 @return The pointer to the HOB list.
39 ASSERT (gHobList
!= NULL
);
44 Returns the next instance of a HOB type from the starting HOB.
46 This function searches the first instance of a HOB type from the starting HOB pointer.
47 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
48 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
49 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
50 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
) {
78 Hob
.Raw
= GET_NEXT_HOB (Hob
);
84 Returns the first instance of a HOB type among the whole HOB list.
86 This function searches the first instance of a HOB type among the whole HOB list.
87 If there does not exist such HOB type in the HOB list, it will return NULL.
89 @param Type The HOB type to return.
91 @return The next instance of a HOB type from the starting HOB.
102 HobList
= GetHobList ();
103 return GetNextHob (Type
, HobList
);
107 This function searches the first instance of a HOB from the starting HOB pointer.
108 Such HOB should satisfy two conditions:
109 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
110 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
111 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
112 to extract the data section and its size info respectively.
113 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
114 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
115 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
116 If Guid is NULL, then ASSERT().
117 If HobStart is NULL, then ASSERT().
119 @param Guid The GUID to match with in the HOB list.
120 @param HobStart A pointer to a Guid.
122 @return The next instance of the matched GUID HOB from the starting HOB.
128 IN CONST EFI_GUID
*Guid
,
129 IN CONST VOID
*HobStart
132 EFI_PEI_HOB_POINTERS GuidHob
;
134 GuidHob
.Raw
= (UINT8
*) HobStart
;
135 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
136 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
139 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
145 This function searches the first instance of a HOB among the whole HOB list.
146 Such HOB should satisfy two conditions:
147 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
148 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
149 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
150 to extract the data section and its size info respectively.
151 If Guid is NULL, then ASSERT().
153 @param Guid The GUID to match with in the HOB list.
155 @return The first instance of the matched GUID HOB among the whole HOB list.
161 IN CONST EFI_GUID
*Guid
166 HobList
= GetHobList ();
167 return GetNextGuidHob (Guid
, HobList
);
171 Get the Boot Mode from the HOB list.
173 This function returns the system boot mode information from the
174 PHIT HOB in HOB list.
178 @return The Boot Mode.
187 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
189 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
191 return HandOffHob
->BootMode
;
194 Builds a HOB for a loaded PE32 module.
196 This function builds a HOB for a loaded PE32 module.
197 It can only be invoked during PEI phase;
198 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
199 If ModuleName is NULL, then ASSERT().
200 If there is no additional space for HOB creation, then ASSERT().
202 @param ModuleName The GUID File Name of the module.
203 @param MemoryAllocationModule The 64 bit physical address of the module.
204 @param ModuleLength The length of the module in bytes.
205 @param EntryPoint The 64 bit physical address of the module's entry point.
211 IN CONST EFI_GUID
*ModuleName
,
212 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
213 IN UINT64 ModuleLength
,
214 IN EFI_PHYSICAL_ADDRESS EntryPoint
218 // PEI HOB is read only for DXE phase
224 Builds a HOB that describes a chunk of system memory.
226 This function builds a HOB that describes a chunk of system memory.
227 It can only be invoked during PEI phase;
228 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
229 If there is no additional space for HOB creation, then ASSERT().
231 @param ResourceType The type of resource described by this HOB.
232 @param ResourceAttribute The resource attributes of the memory described by this HOB.
233 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
234 @param NumberOfBytes The length of the memory described by this HOB in bytes.
239 BuildResourceDescriptorHob (
240 IN EFI_RESOURCE_TYPE ResourceType
,
241 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
242 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
243 IN UINT64 NumberOfBytes
247 // PEI HOB is read only for DXE phase
253 Builds a GUID HOB with a certain data length.
255 This function builds a customized HOB tagged with a GUID for identification
256 and returns the start address of GUID HOB data so that caller can fill the customized data.
257 The HOB Header and Name field is already stripped.
258 It can only be invoked during PEI phase;
259 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
260 If Guid is NULL, then ASSERT().
261 If there is no additional space for HOB creation, then ASSERT().
262 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
264 @param Guid The GUID to tag the customized HOB.
265 @param DataLength The size of the data payload for the GUID HOB.
267 @return The start address of GUID HOB data.
273 IN CONST EFI_GUID
*Guid
,
278 // PEI HOB is read only for DXE phase
285 Copies a data buffer to a newly-built HOB.
287 This function builds a customized HOB tagged with a GUID for identification,
288 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
289 The HOB Header and Name field is already stripped.
290 It can only be invoked during PEI phase;
291 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
292 If Guid is NULL, then ASSERT().
293 If Data is NULL and DataLength > 0, then ASSERT().
294 If there is no additional space for HOB creation, then ASSERT().
295 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
297 @param Guid The GUID to tag the customized HOB.
298 @param Data The data to be copied into the data field of the GUID HOB.
299 @param DataLength The size of the data payload for the GUID HOB.
301 @return The start address of GUID HOB data.
307 IN CONST EFI_GUID
*Guid
,
313 // PEI HOB is read only for DXE phase
320 Builds a Firmware Volume HOB.
322 This function builds a Firmware Volume HOB.
323 It can only be invoked during PEI phase;
324 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
325 If there is no additional space for HOB creation, then ASSERT().
327 @param BaseAddress The base address of the Firmware Volume.
328 @param Length The size of the Firmware Volume in bytes.
334 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
339 // PEI HOB is read only for DXE phase
345 Builds a EFI_HOB_TYPE_FV2 HOB.
347 This function builds a EFI_HOB_TYPE_FV2 HOB.
348 It can only be invoked during PEI phase;
349 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
350 If there is no additional space for HOB creation, then ASSERT().
352 @param BaseAddress The base address of the Firmware Volume.
353 @param Length The size of the Firmware Volume in bytes.
354 @param FvName The name of the Firmware Volume.
355 @param FileName The name of the file.
361 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
363 IN CONST EFI_GUID
*FvName
,
364 IN CONST EFI_GUID
*FileName
371 Builds a Capsule Volume HOB.
373 This function builds a Capsule Volume HOB.
374 It can only be invoked during PEI phase;
375 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
376 If there is no additional space for HOB creation, then ASSERT().
378 @param BaseAddress The base address of the Capsule Volume.
379 @param Length The size of the Capsule Volume in bytes.
385 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
390 // PEI HOB is read only for DXE phase
396 Builds a HOB for the CPU.
398 This function builds a HOB for the CPU.
399 It can only be invoked during PEI phase;
400 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
401 If there is no additional space for HOB creation, then ASSERT().
403 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
404 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
410 IN UINT8 SizeOfMemorySpace
,
411 IN UINT8 SizeOfIoSpace
415 // PEI HOB is read only for DXE phase
421 Builds a HOB for the Stack.
423 This function builds a HOB for the stack.
424 It can only be invoked during PEI phase;
425 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
426 If there is no additional space for HOB creation, then ASSERT().
428 @param BaseAddress The 64 bit physical address of the Stack.
429 @param Length The length of the stack in bytes.
435 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
440 // PEI HOB is read only for DXE phase
446 Builds a HOB for the BSP store.
448 This function builds a HOB for BSP store.
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.
451 If there is no additional space for HOB creation, then ASSERT().
453 @param BaseAddress The 64 bit physical address of the BSP.
454 @param Length The length of the BSP store in bytes.
455 @param MemoryType Type of memory allocated by this HOB.
461 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
463 IN EFI_MEMORY_TYPE MemoryType
467 // PEI HOB is read only for DXE phase
473 Builds a HOB for the memory allocation.
475 This function builds a HOB for the memory allocation.
476 It can only be invoked during PEI phase;
477 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
478 If there is no additional space for HOB creation, then ASSERT().
480 @param BaseAddress The 64 bit physical address of the memory.
481 @param Length The length of the memory allocation in bytes.
482 @param MemoryType Type of memory allocated by this HOB.
487 BuildMemoryAllocationHob (
488 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
490 IN EFI_MEMORY_TYPE MemoryType
494 // PEI HOB is read only for DXE phase