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
24 // The Library classes this module consumes
26 #include <Library/HobLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/BaseMemoryLib.h>
30 #include "InternalHobLib.h"
33 Returns the pointer to the HOB list.
35 This function returns the pointer to first HOB in the list.
37 @return The pointer to the HOB list.
50 Returns the next instance of a HOB type from the starting HOB.
52 This function searches the first instance of a HOB type from the starting HOB pointer.
53 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
54 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
55 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
56 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
57 If HobStart is NULL, then ASSERT().
59 @param Type The HOB type to return.
60 @param HobStart The starting HOB pointer to search from.
62 @return The next instance of a HOB type from the starting HOB.
69 IN CONST VOID
*HobStart
72 EFI_PEI_HOB_POINTERS Hob
;
74 ASSERT (HobStart
!= NULL
);
76 Hob
.Raw
= (UINT8
*) HobStart
;
78 // Parse the HOB list until end of list or matching type is found.
80 while (!END_OF_HOB_LIST (Hob
)) {
81 if (Hob
.Header
->HobType
== Type
) {
84 Hob
.Raw
= GET_NEXT_HOB (Hob
);
90 Returns the first instance of a HOB type among the whole HOB list.
92 This function searches the first instance of a HOB type among the whole HOB list.
93 If there does not exist such HOB type in the HOB list, it will return NULL.
95 @param Type The HOB type to return.
97 @return The next instance of a HOB type from the starting HOB.
108 HobList
= GetHobList ();
109 return GetNextHob (Type
, HobList
);
113 This function searches the first instance of a HOB from the starting HOB pointer.
114 Such HOB should satisfy two conditions:
115 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
116 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
117 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
118 to extract the data section and its size info respectively.
119 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
120 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
121 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
122 If Guid is NULL, then ASSERT().
123 If HobStart is NULL, then ASSERT().
125 @param Guid The GUID to match with in the HOB list.
126 @param HobStart A pointer to a Guid.
128 @return The next instance of the matched GUID HOB from the starting HOB.
134 IN CONST EFI_GUID
*Guid
,
135 IN CONST VOID
*HobStart
138 EFI_PEI_HOB_POINTERS GuidHob
;
140 GuidHob
.Raw
= (UINT8
*) HobStart
;
141 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
142 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
145 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
151 This function searches the first instance of a HOB among the whole HOB list.
152 Such HOB should satisfy two conditions:
153 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
154 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
155 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
156 to extract the data section and its size info respectively.
157 If Guid is NULL, then ASSERT().
159 @param Guid The GUID to match with in the HOB list.
161 @return The first instance of the matched GUID HOB among the whole HOB list.
167 IN CONST EFI_GUID
*Guid
172 HobList
= GetHobList ();
173 return GetNextGuidHob (Guid
, HobList
);
177 Get the Boot Mode from the HOB list.
179 This function returns the system boot mode information from the
180 PHIT HOB in HOB list.
184 @return The Boot Mode.
193 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
195 HandOffHob
= (EFI_HOB_HANDOFF_INFO_TABLE
*) GetHobList ();
197 return HandOffHob
->BootMode
;
200 Builds a HOB for a loaded PE32 module.
202 This function builds a HOB for a loaded PE32 module.
203 It can only be invoked during PEI phase;
204 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
205 If ModuleName is NULL, then ASSERT().
206 If there is no additional space for HOB creation, then ASSERT().
208 @param ModuleName The GUID File Name of the module.
209 @param MemoryAllocationModule The 64 bit physical address of the module.
210 @param ModuleLength The length of the module in bytes.
211 @param EntryPoint The 64 bit physical address of the module's entry point.
217 IN CONST EFI_GUID
*ModuleName
,
218 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
219 IN UINT64 ModuleLength
,
220 IN EFI_PHYSICAL_ADDRESS EntryPoint
224 // PEI HOB is read only for DXE phase
230 Builds a HOB that describes a chunk of system memory.
232 This function builds a HOB that describes a chunk of system memory.
233 It can only be invoked during PEI phase;
234 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
235 If there is no additional space for HOB creation, then ASSERT().
237 @param ResourceType The type of resource described by this HOB.
238 @param ResourceAttribute The resource attributes of the memory described by this HOB.
239 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
240 @param NumberOfBytes The length of the memory described by this HOB in bytes.
245 BuildResourceDescriptorHob (
246 IN EFI_RESOURCE_TYPE ResourceType
,
247 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
248 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
249 IN UINT64 NumberOfBytes
253 // PEI HOB is read only for DXE phase
259 Builds a GUID HOB with a certain data length.
261 This function builds a customized HOB tagged with a GUID for identification
262 and returns the start address of GUID HOB data so that caller can fill the customized data.
263 The HOB Header and Name field is already stripped.
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 Guid is NULL, then ASSERT().
267 If there is no additional space for HOB creation, then ASSERT().
268 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
270 @param Guid The GUID to tag the customized HOB.
271 @param DataLength The size of the data payload for the GUID HOB.
273 @return The start address of GUID HOB data.
279 IN CONST EFI_GUID
*Guid
,
284 // PEI HOB is read only for DXE phase
291 Copies a data buffer to a newly-built HOB.
293 This function builds a customized HOB tagged with a GUID for identification,
294 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
295 The HOB Header and Name field is already stripped.
296 It can only be invoked during PEI phase;
297 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
298 If Guid is NULL, then ASSERT().
299 If Data is NULL and DataLength > 0, 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 Data The data to be copied into the data field of the GUID HOB.
305 @param DataLength The size of the data payload for the GUID HOB.
307 @return The start address of GUID HOB data.
313 IN CONST EFI_GUID
*Guid
,
319 // PEI HOB is read only for DXE phase
326 Builds a Firmware Volume HOB.
328 This function builds a Firmware Volume HOB.
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 there is no additional space for HOB creation, then ASSERT().
333 @param BaseAddress The base address of the Firmware Volume.
334 @param Length The size of the Firmware Volume in bytes.
340 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
345 // PEI HOB is read only for DXE phase
351 Builds a Capsule Volume HOB.
353 This function builds a Capsule Volume HOB.
354 It can only be invoked during PEI phase;
355 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
356 If there is no additional space for HOB creation, then ASSERT().
358 @param BaseAddress The base address of the Capsule Volume.
359 @param Length The size of the Capsule Volume in bytes.
365 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
370 // PEI HOB is read only for DXE phase
376 Builds a HOB for the CPU.
378 This function builds a HOB for the CPU.
379 It can only be invoked during PEI phase;
380 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
381 If there is no additional space for HOB creation, then ASSERT().
383 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
384 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
390 IN UINT8 SizeOfMemorySpace
,
391 IN UINT8 SizeOfIoSpace
395 // PEI HOB is read only for DXE phase
401 Builds a HOB for the Stack.
403 This function builds a HOB for the stack.
404 It can only be invoked during PEI phase;
405 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
406 If there is no additional space for HOB creation, then ASSERT().
408 @param BaseAddress The 64 bit physical address of the Stack.
409 @param Length The length of the stack in bytes.
415 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
420 // PEI HOB is read only for DXE phase
426 Builds a HOB for the BSP store.
428 This function builds a HOB for BSP store.
429 It can only be invoked during PEI phase;
430 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
431 If there is no additional space for HOB creation, then ASSERT().
433 @param BaseAddress The 64 bit physical address of the BSP.
434 @param Length The length of the BSP store in bytes.
435 @param MemoryType Type of memory allocated by this HOB.
441 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
443 IN EFI_MEMORY_TYPE MemoryType
447 // PEI HOB is read only for DXE phase
453 Builds a HOB for the memory allocation.
455 This function builds a HOB for the memory allocation.
456 It can only be invoked during PEI phase;
457 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
458 If there is no additional space for HOB creation, then ASSERT().
460 @param BaseAddress The 64 bit physical address of the memory.
461 @param Length The length of the memory allocation in bytes.
462 @param MemoryType Type of memory allocated by this HOB.
467 BuildMemoryAllocationHob (
468 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
470 IN EFI_MEMORY_TYPE MemoryType
474 // PEI HOB is read only for DXE phase