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.
17 // The package level header files this module uses
21 // The protocols, PPI and GUID defintions for this module
23 #include <Guid/HobList.h>
25 // The Library classes this module consumes
27 #include <Library/HobLib.h>
28 #include <Library/UefiLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include "HobLibInternal.h"
33 STATIC VOID
*mHobList
= NULL
;
36 The constructor function caches the pointer to HOB list.
38 The constructor function gets the start address of HOB list from system configuration table.
39 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
41 @param ImageHandle The firmware allocated handle for the EFI image.
42 @param SystemTable A pointer to the EFI System Table.
44 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
50 IN EFI_HANDLE ImageHandle
,
51 IN EFI_SYSTEM_TABLE
*SystemTable
56 Status
= EfiGetSystemConfigurationTable (&gEfiHobListGuid
, &mHobList
);
57 ASSERT_EFI_ERROR (Status
);
58 ASSERT (mHobList
!= NULL
);
63 Returns the pointer to the HOB list.
65 This function returns the pointer to first HOB in the list.
67 @return The pointer to the HOB list.
80 Returns the next instance of a HOB type from the starting HOB.
82 This function searches the first instance of a HOB type from the starting HOB pointer.
83 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
84 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
85 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
86 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
87 If HobStart is NULL, then ASSERT().
89 @param Type The HOB type to return.
90 @param HobStart The starting HOB pointer to search from.
92 @return The next instance of a HOB type from the starting HOB.
99 IN CONST VOID
*HobStart
102 EFI_PEI_HOB_POINTERS Hob
;
104 ASSERT (HobStart
!= NULL
);
106 Hob
.Raw
= (UINT8
*) HobStart
;
108 // Parse the HOB list until end of list or matching type is found.
110 while (!END_OF_HOB_LIST (Hob
)) {
111 if (Hob
.Header
->HobType
== Type
) {
114 Hob
.Raw
= GET_NEXT_HOB (Hob
);
120 Returns the first instance of a HOB type among the whole HOB list.
122 This function searches the first instance of a HOB type among the whole HOB list.
123 If there does not exist such HOB type in the HOB list, it will return NULL.
125 @param Type The HOB type to return.
127 @return The next instance of a HOB type from the starting HOB.
138 HobList
= GetHobList ();
139 return GetNextHob (Type
, HobList
);
143 This function searches the first instance of a HOB from the starting HOB pointer.
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 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
150 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
151 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
152 If Guid is NULL, then ASSERT().
153 If HobStart is NULL, then ASSERT().
155 @param Guid The GUID to match with in the HOB list.
156 @param HobStart A pointer to a Guid.
158 @return The next instance of the matched GUID HOB from the starting HOB.
164 IN CONST EFI_GUID
*Guid
,
165 IN CONST VOID
*HobStart
168 EFI_PEI_HOB_POINTERS GuidHob
;
170 GuidHob
.Raw
= (UINT8
*) HobStart
;
171 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
172 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
175 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
181 This function searches the first instance of a HOB among the whole HOB list.
182 Such HOB should satisfy two conditions:
183 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
184 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
185 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
186 to extract the data section and its size info respectively.
187 If Guid is NULL, then ASSERT().
189 @param Guid The GUID to match with in the HOB list.
191 @return The first instance of the matched GUID HOB among the whole HOB list.
197 IN CONST EFI_GUID
*Guid
202 HobList
= GetHobList ();
203 return GetNextGuidHob (Guid
, HobList
);
207 Get the Boot Mode from the HOB list.
209 This function returns the system boot mode information from the
210 PHIT HOB in HOB list.
214 @return The Boot Mode.
223 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
225 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
227 return HandOffHob
->BootMode
;
231 Builds a HOB for a loaded PE32 module.
233 This function builds a HOB for a loaded PE32 module.
234 It can only be invoked during PEI phase;
235 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
236 If ModuleName is NULL, then ASSERT().
237 If there is no additional space for HOB creation, then ASSERT().
239 @param ModuleName The GUID File Name of the module.
240 @param MemoryAllocationModule The 64 bit physical address of the module.
241 @param ModuleLength The length of the module in bytes.
242 @param EntryPoint The 64 bit physical address of the module's entry point.
248 IN CONST EFI_GUID
*ModuleName
,
249 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
250 IN UINT64 ModuleLength
,
251 IN EFI_PHYSICAL_ADDRESS EntryPoint
255 // PEI HOB is read only for DXE phase
261 Builds a HOB that describes a chunk of system memory.
263 This function builds a HOB that describes a chunk of system memory.
264 It can only be invoked during PEI phase;
265 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
266 If there is no additional space for HOB creation, then ASSERT().
268 @param ResourceType The type of resource described by this HOB.
269 @param ResourceAttribute The resource attributes of the memory described by this HOB.
270 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
271 @param NumberOfBytes The length of the memory described by this HOB in bytes.
276 BuildResourceDescriptorHob (
277 IN EFI_RESOURCE_TYPE ResourceType
,
278 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
279 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
280 IN UINT64 NumberOfBytes
284 // PEI HOB is read only for DXE phase
290 Builds a GUID HOB with a certain data length.
292 This function builds a customized HOB tagged with a GUID for identification
293 and returns the start address of GUID HOB data so that caller can fill the customized data.
294 The HOB Header and Name field is already stripped.
295 It can only be invoked during PEI phase;
296 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
297 If Guid is NULL, then ASSERT().
298 If there is no additional space for HOB creation, then ASSERT().
299 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
301 @param Guid The GUID to tag the customized HOB.
302 @param DataLength The size of the data payload for the GUID HOB.
304 @return The start address of GUID HOB data.
310 IN CONST EFI_GUID
*Guid
,
315 // PEI HOB is read only for DXE phase
322 Copies a data buffer to a newly-built HOB.
324 This function builds a customized HOB tagged with a GUID for identification,
325 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
326 The HOB Header and Name field is already stripped.
327 It can only be invoked during PEI phase;
328 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
329 If Guid is NULL, then ASSERT().
330 If Data is NULL and DataLength > 0, then ASSERT().
331 If there is no additional space for HOB creation, then ASSERT().
332 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
334 @param Guid The GUID to tag the customized HOB.
335 @param Data The data to be copied into the data field of the GUID HOB.
336 @param DataLength The size of the data payload for the GUID HOB.
338 @return The start address of GUID HOB data.
344 IN CONST EFI_GUID
*Guid
,
350 // PEI HOB is read only for DXE phase
357 Builds a Firmware Volume HOB.
359 This function builds a Firmware Volume HOB.
360 It can only be invoked during PEI phase;
361 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
362 If there is no additional space for HOB creation, then ASSERT().
364 @param BaseAddress The base address of the Firmware Volume.
365 @param Length The size of the Firmware Volume in bytes.
371 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
376 // PEI HOB is read only for DXE phase
382 Builds a Capsule Volume HOB.
384 This function builds a Capsule Volume HOB.
385 It can only be invoked during PEI phase;
386 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
387 If there is no additional space for HOB creation, then ASSERT().
389 @param BaseAddress The base address of the Capsule Volume.
390 @param Length The size of the Capsule Volume in bytes.
396 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
401 // PEI HOB is read only for DXE phase
407 Builds a HOB for the CPU.
409 This function builds a HOB for the CPU.
410 It can only be invoked during PEI phase;
411 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
412 If there is no additional space for HOB creation, then ASSERT().
414 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
415 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
421 IN UINT8 SizeOfMemorySpace
,
422 IN UINT8 SizeOfIoSpace
426 // PEI HOB is read only for DXE phase
432 Builds a HOB for the Stack.
434 This function builds a HOB for the stack.
435 It can only be invoked during PEI phase;
436 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
437 If there is no additional space for HOB creation, then ASSERT().
439 @param BaseAddress The 64 bit physical address of the Stack.
440 @param Length The length of the stack in bytes.
446 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
451 // PEI HOB is read only for DXE phase
457 Builds a HOB for the BSP store.
459 This function builds a HOB for BSP store.
460 It can only be invoked during PEI phase;
461 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
462 If there is no additional space for HOB creation, then ASSERT().
464 @param BaseAddress The 64 bit physical address of the BSP.
465 @param Length The length of the BSP store in bytes.
466 @param MemoryType Type of memory allocated by this HOB.
472 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
474 IN EFI_MEMORY_TYPE MemoryType
478 // PEI HOB is read only for DXE phase
484 Builds a HOB for the memory allocation.
486 This function builds a HOB for the memory allocation.
487 It can only be invoked during PEI phase;
488 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
489 If there is no additional space for HOB creation, then ASSERT().
491 @param BaseAddress The 64 bit physical address of the memory.
492 @param Length The length of the memory allocation in bytes.
493 @param MemoryType Type of memory allocated by this HOB.
498 BuildMemoryAllocationHob (
499 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
501 IN EFI_MEMORY_TYPE MemoryType
505 // PEI HOB is read only for DXE phase