4 Copyright (c) 2006 - 2007, 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 // The package level header files this module uses
23 // The protocols, PPI and GUID defintions for this module
25 #include <Guid/HobList.h>
27 // The Library classes this module consumes
29 #include <Library/HobLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include "HobLibInternal.h"
35 STATIC VOID
*mHobList
= NULL
;
38 The constructor function caches the pointer to HOB list.
40 The constructor function gets the start address of HOB list from system configuration table.
41 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
43 @param ImageHandle The firmware allocated handle for the EFI image.
44 @param SystemTable A pointer to the EFI System Table.
46 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
52 IN EFI_HANDLE ImageHandle
,
53 IN EFI_SYSTEM_TABLE
*SystemTable
58 Status
= EfiGetSystemConfigurationTable (&gEfiHobListGuid
, &mHobList
);
59 ASSERT_EFI_ERROR (Status
);
60 ASSERT (mHobList
!= NULL
);
65 Returns the pointer to the HOB list.
67 This function returns the pointer to first HOB in the list.
69 @return The pointer to the HOB list.
82 Returns the next instance of a HOB type from the starting HOB.
84 This function searches the first instance of a HOB type from the starting HOB pointer.
85 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
86 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
87 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
88 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
89 If HobStart is NULL, then ASSERT().
91 @param Type The HOB type to return.
92 @param HobStart The starting HOB pointer to search from.
94 @return The next instance of a HOB type from the starting HOB.
101 IN CONST VOID
*HobStart
104 EFI_PEI_HOB_POINTERS Hob
;
106 ASSERT (HobStart
!= NULL
);
108 Hob
.Raw
= (UINT8
*) HobStart
;
110 // Parse the HOB list until end of list or matching type is found.
112 while (!END_OF_HOB_LIST (Hob
)) {
113 if (Hob
.Header
->HobType
== Type
) {
116 Hob
.Raw
= GET_NEXT_HOB (Hob
);
122 Returns the first instance of a HOB type among the whole HOB list.
124 This function searches the first instance of a HOB type among the whole HOB list.
125 If there does not exist such HOB type in the HOB list, it will return NULL.
127 @param Type The HOB type to return.
129 @return The next instance of a HOB type from the starting HOB.
140 HobList
= GetHobList ();
141 return GetNextHob (Type
, HobList
);
145 This function searches the first instance of a HOB from the starting HOB pointer.
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 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
152 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
153 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
154 If Guid is NULL, then ASSERT().
155 If HobStart is NULL, then ASSERT().
157 @param Guid The GUID to match with in the HOB list.
158 @param HobStart A pointer to a Guid.
160 @return The next instance of the matched GUID HOB from the starting HOB.
166 IN CONST EFI_GUID
*Guid
,
167 IN CONST VOID
*HobStart
170 EFI_PEI_HOB_POINTERS GuidHob
;
172 GuidHob
.Raw
= (UINT8
*) HobStart
;
173 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
174 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
177 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
183 This function searches the first instance of a HOB among the whole HOB list.
184 Such HOB should satisfy two conditions:
185 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
186 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
187 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
188 to extract the data section and its size info respectively.
189 If Guid is NULL, then ASSERT().
191 @param Guid The GUID to match with in the HOB list.
193 @return The first instance of the matched GUID HOB among the whole HOB list.
199 IN CONST EFI_GUID
*Guid
204 HobList
= GetHobList ();
205 return GetNextGuidHob (Guid
, HobList
);
209 Get the Boot Mode from the HOB list.
211 This function returns the system boot mode information from the
212 PHIT HOB in HOB list.
216 @return The Boot Mode.
225 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
227 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
229 return HandOffHob
->BootMode
;
233 Builds a HOB for a loaded PE32 module.
235 This function builds a HOB for a loaded PE32 module.
236 It can only be invoked during PEI phase;
237 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
238 If ModuleName is NULL, then ASSERT().
239 If there is no additional space for HOB creation, then ASSERT().
241 @param ModuleName The GUID File Name of the module.
242 @param MemoryAllocationModule The 64 bit physical address of the module.
243 @param ModuleLength The length of the module in bytes.
244 @param EntryPoint The 64 bit physical address of the module's entry point.
250 IN CONST EFI_GUID
*ModuleName
,
251 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
252 IN UINT64 ModuleLength
,
253 IN EFI_PHYSICAL_ADDRESS EntryPoint
257 // PEI HOB is read only for DXE phase
263 Builds a HOB that describes a chunk of system memory.
265 This function builds a HOB that describes a chunk of system memory.
266 It can only be invoked during PEI phase;
267 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
268 If there is no additional space for HOB creation, then ASSERT().
270 @param ResourceType The type of resource described by this HOB.
271 @param ResourceAttribute The resource attributes of the memory described by this HOB.
272 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
273 @param NumberOfBytes The length of the memory described by this HOB in bytes.
278 BuildResourceDescriptorHob (
279 IN EFI_RESOURCE_TYPE ResourceType
,
280 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
281 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
282 IN UINT64 NumberOfBytes
286 // PEI HOB is read only for DXE phase
292 Builds a GUID HOB with a certain data length.
294 This function builds a customized HOB tagged with a GUID for identification
295 and returns the start address of GUID HOB data so that caller can fill the customized data.
296 The HOB Header and Name field is already stripped.
297 It can only be invoked during PEI phase;
298 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
299 If Guid is NULL, then ASSERT().
300 If there is no additional space for HOB creation, then ASSERT().
301 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
303 @param Guid The GUID to tag the customized HOB.
304 @param DataLength The size of the data payload for the GUID HOB.
306 @return The start address of GUID HOB data.
312 IN CONST EFI_GUID
*Guid
,
317 // PEI HOB is read only for DXE phase
324 Copies a data buffer to a newly-built HOB.
326 This function builds a customized HOB tagged with a GUID for identification,
327 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
328 The HOB Header and Name field is already stripped.
329 It can only be invoked during PEI phase;
330 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
331 If Guid is NULL, then ASSERT().
332 If Data is NULL and DataLength > 0, then ASSERT().
333 If there is no additional space for HOB creation, then ASSERT().
334 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
336 @param Guid The GUID to tag the customized HOB.
337 @param Data The data to be copied into the data field of the GUID HOB.
338 @param DataLength The size of the data payload for the GUID HOB.
340 @return The start address of GUID HOB data.
346 IN CONST EFI_GUID
*Guid
,
352 // PEI HOB is read only for DXE phase
359 Builds a Firmware Volume HOB.
361 This function builds a Firmware Volume HOB.
362 It can only be invoked during PEI phase;
363 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
364 If there is no additional space for HOB creation, then ASSERT().
366 @param BaseAddress The base address of the Firmware Volume.
367 @param Length The size of the Firmware Volume in bytes.
373 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
378 // PEI HOB is read only for DXE phase
384 Builds a Capsule Volume HOB.
386 This function builds a Capsule Volume HOB.
387 It can only be invoked during PEI phase;
388 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
389 If there is no additional space for HOB creation, then ASSERT().
391 @param BaseAddress The base address of the Capsule Volume.
392 @param Length The size of the Capsule Volume in bytes.
398 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
403 // PEI HOB is read only for DXE phase
409 Builds a HOB for the CPU.
411 This function builds a HOB for the CPU.
412 It can only be invoked during PEI phase;
413 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
414 If there is no additional space for HOB creation, then ASSERT().
416 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
417 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
423 IN UINT8 SizeOfMemorySpace
,
424 IN UINT8 SizeOfIoSpace
428 // PEI HOB is read only for DXE phase
434 Builds a HOB for the Stack.
436 This function builds a HOB for the stack.
437 It can only be invoked during PEI phase;
438 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
439 If there is no additional space for HOB creation, then ASSERT().
441 @param BaseAddress The 64 bit physical address of the Stack.
442 @param Length The length of the stack in bytes.
448 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
453 // PEI HOB is read only for DXE phase
459 Builds a HOB for the BSP store.
461 This function builds a HOB for BSP store.
462 It can only be invoked during PEI phase;
463 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
464 If there is no additional space for HOB creation, then ASSERT().
466 @param BaseAddress The 64 bit physical address of the BSP.
467 @param Length The length of the BSP store in bytes.
468 @param MemoryType Type of memory allocated by this HOB.
474 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
476 IN EFI_MEMORY_TYPE MemoryType
480 // PEI HOB is read only for DXE phase
486 Builds a HOB for the memory allocation.
488 This function builds a HOB for the memory allocation.
489 It can only be invoked during PEI phase;
490 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
491 If there is no additional space for HOB creation, then ASSERT().
493 @param BaseAddress The 64 bit physical address of the memory.
494 @param Length The length of the memory allocation in bytes.
495 @param MemoryType Type of memory allocated by this HOB.
500 BuildMemoryAllocationHob (
501 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
503 IN EFI_MEMORY_TYPE MemoryType
507 // PEI HOB is read only for DXE phase