2 HOB Library implemenation for Dxe Phase.
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 <Guid/HobList.h>
21 #include <Library/HobLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseMemoryLib.h>
26 STATIC VOID
*mHobList
= NULL
;
29 The constructor function caches the pointer to HOB list.
31 The constructor function gets the start address of HOB list from system configuration table.
32 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
34 @param ImageHandle The firmware allocated handle for the EFI image.
35 @param SystemTable A pointer to the EFI System Table.
37 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
43 IN EFI_HANDLE ImageHandle
,
44 IN EFI_SYSTEM_TABLE
*SystemTable
49 Status
= EfiGetSystemConfigurationTable (&gEfiHobListGuid
, &mHobList
);
50 ASSERT_EFI_ERROR (Status
);
51 ASSERT (mHobList
!= NULL
);
57 Returns the pointer to the HOB list.
59 This function returns the pointer to first HOB in the list.
61 @return The pointer to the HOB list.
74 Returns the next instance of a HOB type from the starting HOB.
76 This function searches the first instance of a HOB type from the starting HOB pointer.
77 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
78 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
79 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
80 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
81 If HobStart is NULL, then ASSERT().
83 @param Type The HOB type to return.
84 @param HobStart The starting HOB pointer to search from.
86 @return The next instance of a HOB type from the starting HOB.
93 IN CONST VOID
*HobStart
96 EFI_PEI_HOB_POINTERS Hob
;
98 ASSERT (HobStart
!= NULL
);
100 Hob
.Raw
= (UINT8
*) HobStart
;
102 // Parse the HOB list until end of list or matching type is found.
104 while (!END_OF_HOB_LIST (Hob
)) {
105 if (Hob
.Header
->HobType
== Type
) {
108 Hob
.Raw
= GET_NEXT_HOB (Hob
);
114 Returns the first instance of a HOB type among the whole HOB list.
116 This function searches the first instance of a HOB type among the whole HOB list.
117 If there does not exist such HOB type in the HOB list, it will return NULL.
119 @param Type The HOB type to return.
121 @return The next instance of a HOB type from the starting HOB.
132 HobList
= GetHobList ();
133 return GetNextHob (Type
, HobList
);
137 This function searches the first instance of a HOB from the starting HOB pointer.
138 Such HOB should satisfy two conditions:
139 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
140 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
141 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
142 to extract the data section and its size info respectively.
143 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
144 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
145 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
146 If Guid is NULL, then ASSERT().
147 If HobStart is NULL, then ASSERT().
149 @param Guid The GUID to match with in the HOB list.
150 @param HobStart A pointer to a Guid.
152 @return The next instance of the matched GUID HOB from the starting HOB.
158 IN CONST EFI_GUID
*Guid
,
159 IN CONST VOID
*HobStart
162 EFI_PEI_HOB_POINTERS GuidHob
;
164 GuidHob
.Raw
= (UINT8
*) HobStart
;
165 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
166 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
169 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
175 This function searches the first instance of a HOB among the whole HOB list.
176 Such HOB should satisfy two conditions:
177 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
178 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
179 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
180 to extract the data section and its size info respectively.
181 If Guid is NULL, then ASSERT().
183 @param Guid The GUID to match with in the HOB list.
185 @return The first instance of the matched GUID HOB among the whole HOB list.
191 IN CONST EFI_GUID
*Guid
196 HobList
= GetHobList ();
197 return GetNextGuidHob (Guid
, HobList
);
201 Get the Boot Mode from the HOB list.
203 This function returns the system boot mode information from the
204 PHIT HOB in HOB list. If PHIT HOB is NULL, then ASSERT().
208 @return The Boot Mode.
217 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
219 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
220 ASSERT (HandOffHob
!= NULL
);
222 return HandOffHob
->BootMode
;
226 Builds a HOB for a loaded PE32 module.
228 This function builds a HOB for a loaded PE32 module.
229 It can only be invoked during PEI phase;
230 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
231 If ModuleName is NULL, then ASSERT().
232 If there is no additional space for HOB creation, then ASSERT().
234 @param ModuleName The GUID File Name of the module.
235 @param MemoryAllocationModule The 64 bit physical address of the module.
236 @param ModuleLength The length of the module in bytes.
237 @param EntryPoint The 64 bit physical address of the module's entry point.
243 IN CONST EFI_GUID
*ModuleName
,
244 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
245 IN UINT64 ModuleLength
,
246 IN EFI_PHYSICAL_ADDRESS EntryPoint
250 // PEI HOB is read only for DXE phase
256 Builds a HOB that describes a chunk of system memory.
258 This function builds a HOB that describes a chunk of system memory.
259 It can only be invoked during PEI phase;
260 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
261 If there is no additional space for HOB creation, then ASSERT().
263 @param ResourceType The type of resource described by this HOB.
264 @param ResourceAttribute The resource attributes of the memory described by this HOB.
265 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
266 @param NumberOfBytes The length of the memory described by this HOB in bytes.
271 BuildResourceDescriptorHob (
272 IN EFI_RESOURCE_TYPE ResourceType
,
273 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
274 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
275 IN UINT64 NumberOfBytes
279 // PEI HOB is read only for DXE phase
285 Builds a GUID HOB with a certain data length.
287 This function builds a customized HOB tagged with a GUID for identification
288 and returns the start address of GUID HOB data so that caller can fill the customized 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 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 DataLength The size of the data payload for the GUID HOB.
299 @return The start address of GUID HOB data.
305 IN CONST EFI_GUID
*Guid
,
310 // PEI HOB is read only for DXE phase
317 Copies a data buffer to a newly-built HOB.
319 This function builds a customized HOB tagged with a GUID for identification,
320 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
321 The HOB Header and Name field is already stripped.
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 Guid is NULL, then ASSERT().
325 If Data is NULL and DataLength > 0, then ASSERT().
326 If there is no additional space for HOB creation, then ASSERT().
327 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
329 @param Guid The GUID to tag the customized HOB.
330 @param Data The data to be copied into the data field of the GUID HOB.
331 @param DataLength The size of the data payload for the GUID HOB.
333 @return The start address of GUID HOB data.
339 IN CONST EFI_GUID
*Guid
,
345 // PEI HOB is read only for DXE phase
352 Builds a Firmware Volume HOB.
354 This function builds a Firmware Volume HOB.
355 It can only be invoked during PEI phase;
356 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
357 If there is no additional space for HOB creation, then ASSERT().
359 @param BaseAddress The base address of the Firmware Volume.
360 @param Length The size of the Firmware Volume in bytes.
366 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
371 // PEI HOB is read only for DXE phase
377 Builds a EFI_HOB_TYPE_FV2 HOB.
379 This function builds a EFI_HOB_TYPE_FV2 HOB.
380 It can only be invoked during PEI phase;
381 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
382 If there is no additional space for HOB creation, then ASSERT().
384 @param BaseAddress The base address of the Firmware Volume.
385 @param Length The size of the Firmware Volume in bytes.
386 @param FvName The name of the Firmware Volume.
387 @param FileName The name of the file.
393 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
395 IN CONST EFI_GUID
*FvName
,
396 IN CONST EFI_GUID
*FileName
404 Builds a Capsule Volume HOB.
406 This function builds a Capsule Volume HOB.
407 It can only be invoked during PEI phase;
408 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
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() since PEI HOB is read-only for DXE phase.
434 If there is no additional space for HOB creation, then ASSERT().
436 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
437 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
443 IN UINT8 SizeOfMemorySpace
,
444 IN UINT8 SizeOfIoSpace
448 // PEI HOB is read only for DXE phase
454 Builds a HOB for the Stack.
456 This function builds a HOB for the stack.
457 It can only be invoked during PEI phase;
458 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
459 If there is no additional space for HOB creation, then ASSERT().
461 @param BaseAddress The 64 bit physical address of the Stack.
462 @param Length The length of the stack in bytes.
468 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
473 // PEI HOB is read only for DXE phase
479 Builds a HOB for the BSP store.
481 This function builds a HOB for BSP store.
482 It can only be invoked during PEI phase;
483 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
484 If there is no additional space for HOB creation, then ASSERT().
486 @param BaseAddress The 64 bit physical address of the BSP.
487 @param Length The length of the BSP store in bytes.
488 @param MemoryType Type of memory allocated by this HOB.
494 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
496 IN EFI_MEMORY_TYPE MemoryType
500 // PEI HOB is read only for DXE phase
506 Builds a HOB for the memory allocation.
508 This function builds a HOB for the memory allocation.
509 It can only be invoked during PEI phase;
510 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
511 If there is no additional space for HOB creation, then ASSERT().
513 @param BaseAddress The 64 bit physical address of the memory.
514 @param Length The length of the memory allocation in bytes.
515 @param MemoryType Type of memory allocated by this HOB.
520 BuildMemoryAllocationHob (
521 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
523 IN EFI_MEMORY_TYPE MemoryType
527 // PEI HOB is read only for DXE phase