4 Copyright (c) 2006, 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.
20 Returns the pointer to the HOB list.
22 This function returns the pointer to first HOB in the list.
24 @return The pointer to the HOB list.
36 Status
= PeiServicesGetHobList (&HobList
);
37 ASSERT_EFI_ERROR (Status
);
38 ASSERT (HobList
!= 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 Adds a new HOB to the HOB List.
173 This internal function enables PEIMs to create various types of HOBs.
175 @param Type Type of the new HOB.
176 @param Length Length of the new HOB to allocate.
178 @return The address of new HOB.
183 InternalPeiCreateHob (
191 Status
= PeiServicesCreateHob (Type
, Length
, &Hob
);
193 // Assume the process of HOB building is always successful.
195 ASSERT_EFI_ERROR (Status
);
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
223 EFI_HOB_MEMORY_ALLOCATION_MODULE
*Hob
;
225 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE
));
227 CopyGuid (&(Hob
->MemoryAllocationHeader
.Name
), &gEfiHobMemoryAllocModuleGuid
);
228 Hob
->MemoryAllocationHeader
.MemoryBaseAddress
= MemoryAllocationModule
;
229 Hob
->MemoryAllocationHeader
.MemoryLength
= ModuleLength
;
230 Hob
->MemoryAllocationHeader
.MemoryType
= EfiBootServicesCode
;
233 // Zero the reserved space to match HOB spec
235 ZeroMem (Hob
->MemoryAllocationHeader
.Reserved
, sizeof (Hob
->MemoryAllocationHeader
.Reserved
));
237 CopyGuid (&Hob
->ModuleName
, ModuleName
);
238 Hob
->EntryPoint
= EntryPoint
;
242 Builds a HOB that describes a chunk of system memory.
244 This function builds a HOB that describes a chunk of system memory.
245 It can only be invoked during PEI phase;
246 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
247 If there is no additional space for HOB creation, then ASSERT().
249 @param ResourceType The type of resource described by this HOB.
250 @param ResourceAttribute The resource attributes of the memory described by this HOB.
251 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
252 @param NumberOfBytes The length of the memory described by this HOB in bytes.
257 BuildResourceDescriptorHob (
258 IN EFI_RESOURCE_TYPE ResourceType
,
259 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
260 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
261 IN UINT64 NumberOfBytes
264 EFI_HOB_RESOURCE_DESCRIPTOR
*Hob
;
266 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR
));
268 Hob
->ResourceType
= ResourceType
;
269 Hob
->ResourceAttribute
= ResourceAttribute
;
270 Hob
->PhysicalStart
= PhysicalStart
;
271 Hob
->ResourceLength
= NumberOfBytes
;
275 Builds a GUID HOB with a certain data length.
277 This function builds a customized HOB tagged with a GUID for identification
278 and returns the start address of GUID HOB data so that caller can fill the customized data.
279 The HOB Header and Name field is already stripped.
280 It can only be invoked during PEI phase;
281 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
282 If Guid is NULL, then ASSERT().
283 If there is no additional space for HOB creation, then ASSERT().
284 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
286 @param Guid The GUID to tag the customized HOB.
287 @param DataLength The size of the data payload for the GUID HOB.
289 @return The start address of GUID HOB data.
295 IN CONST EFI_GUID
*Guid
,
299 EFI_HOB_GUID_TYPE
*Hob
;
302 // Make sure that data length is not too long.
304 ASSERT (DataLength
<= (0xffff - sizeof (EFI_HOB_GUID_TYPE
)));
306 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION
, (UINT16
) (sizeof (EFI_HOB_GUID_TYPE
) + DataLength
));
307 CopyGuid (&Hob
->Name
, Guid
);
312 Copies a data buffer to a newly-built HOB.
314 This function builds a customized HOB tagged with a GUID for identification,
315 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
316 The HOB Header and Name field is already stripped.
317 It can only be invoked during PEI phase;
318 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
319 If Guid is NULL, then ASSERT().
320 If Data is NULL and DataLength > 0, then ASSERT().
321 If there is no additional space for HOB creation, then ASSERT().
322 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
324 @param Guid The GUID to tag the customized HOB.
325 @param Data The data to be copied into the data field of the GUID HOB.
326 @param DataLength The size of the data payload for the GUID HOB.
328 @return The start address of GUID HOB data.
334 IN CONST EFI_GUID
*Guid
,
341 ASSERT (Data
!= NULL
|| DataLength
== 0);
343 HobData
= BuildGuidHob (Guid
, DataLength
);
345 return CopyMem (HobData
, Data
, DataLength
);
349 Builds a Firmware Volume HOB.
351 This function builds a Firmware Volume HOB.
352 It can only be invoked during PEI phase;
353 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
354 If there is no additional space for HOB creation, then ASSERT().
356 @param BaseAddress The base address of the Firmware Volume.
357 @param Length The size of the Firmware Volume in bytes.
363 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
367 EFI_HOB_FIRMWARE_VOLUME
*Hob
;
369 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_FV
, sizeof (EFI_HOB_FIRMWARE_VOLUME
));
371 Hob
->BaseAddress
= BaseAddress
;
372 Hob
->Length
= Length
;
376 Builds a Capsule Volume HOB.
378 This function builds a Capsule Volume HOB.
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 BaseAddress The base address of the Capsule Volume.
384 @param Length The size of the Capsule Volume in bytes.
390 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
394 EFI_HOB_CAPSULE_VOLUME
*Hob
;
396 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_CV
, sizeof (EFI_HOB_CAPSULE_VOLUME
));
398 Hob
->BaseAddress
= BaseAddress
;
399 Hob
->Length
= Length
;
403 Builds a HOB for the CPU.
405 This function builds a HOB for the CPU.
406 It can only be invoked during PEI phase;
407 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
408 If there is no additional space for HOB creation, then ASSERT().
410 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
411 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
417 IN UINT8 SizeOfMemorySpace
,
418 IN UINT8 SizeOfIoSpace
423 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_CPU
, sizeof (EFI_HOB_CPU
));
425 Hob
->SizeOfMemorySpace
= SizeOfMemorySpace
;
426 Hob
->SizeOfIoSpace
= SizeOfIoSpace
;
429 // Zero the reserved space to match HOB spec
431 ZeroMem (Hob
->Reserved
, sizeof (Hob
->Reserved
));
435 Builds a HOB for the Stack.
437 This function builds a HOB for the stack.
438 It can only be invoked during PEI phase;
439 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
440 If there is no additional space for HOB creation, then ASSERT().
442 @param BaseAddress The 64 bit physical address of the Stack.
443 @param Length The length of the stack in bytes.
449 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
453 EFI_HOB_MEMORY_ALLOCATION_STACK
*Hob
;
455 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK
));
457 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocStackGuid
);
458 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
459 Hob
->AllocDescriptor
.MemoryLength
= Length
;
460 Hob
->AllocDescriptor
.MemoryType
= EfiConventionalMemory
;
463 // Zero the reserved space to match HOB spec
465 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
469 Builds a HOB for the BSP store.
471 This function builds a HOB for BSP store.
472 It can only be invoked during PEI phase;
473 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
474 If there is no additional space for HOB creation, then ASSERT().
476 @param BaseAddress The 64 bit physical address of the BSP.
477 @param Length The length of the BSP store in bytes.
478 @param MemoryType Type of memory allocated by this HOB.
484 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
486 IN EFI_MEMORY_TYPE MemoryType
489 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE
*Hob
;
491 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE
));
493 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocBspStoreGuid
);
494 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
495 Hob
->AllocDescriptor
.MemoryLength
= Length
;
496 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
499 // Zero the reserved space to match HOB spec
501 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
505 Builds a HOB for the memory allocation.
507 This function builds a HOB for the memory allocation.
508 It can only be invoked during PEI phase;
509 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
510 If there is no additional space for HOB creation, then ASSERT().
512 @param BaseAddress The 64 bit physical address of the memory.
513 @param Length The length of the memory allocation in bytes.
514 @param MemoryType Type of memory allocated by this HOB.
519 BuildMemoryAllocationHob (
520 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
522 IN EFI_MEMORY_TYPE MemoryType
525 EFI_HOB_MEMORY_ALLOCATION
*Hob
;
527 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION
));
529 ZeroMem (&(Hob
->AllocDescriptor
.Name
), sizeof (EFI_GUID
));
530 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
531 Hob
->AllocDescriptor
.MemoryLength
= Length
;
532 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
534 // Zero the reserved space to match HOB spec
536 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));