2 Instance of HOB Library using PEI Services.
4 HOB Library implementation that uses PEI Services to retrieve the HOB List.
5 This library instance uses EFI_HOB_TYPE_CV defined in Intel framework HOB specification v0.9
6 to implement HobLib BuildCvHob() API.
8 Copyright (c) 2007 - 2009, Intel Corporation<BR>
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <FrameworkPei.h>
21 #include <Guid/MemoryAllocationHob.h>
23 #include <Library/HobLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/PeiServicesLib.h>
26 #include <Library/BaseMemoryLib.h>
29 Returns the pointer to the HOB list.
31 This function returns the pointer to first HOB in the list.
32 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
33 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
34 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
35 Since the System Configuration Table does not exist that the time the DXE Core is
36 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
37 to manage the pointer to the HOB list.
39 If the pointer to the HOB list is NULL, then ASSERT().
41 @return The pointer to the HOB list.
53 Status
= PeiServicesGetHobList (&HobList
);
54 ASSERT_EFI_ERROR (Status
);
55 ASSERT (HobList
!= NULL
);
61 Returns the next instance of a HOB type from the starting HOB.
63 This function searches the first instance of a HOB type from the starting HOB pointer.
64 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
65 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
66 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
67 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
69 If HobStart is NULL, then ASSERT().
71 @param Type The HOB type to return.
72 @param HobStart The starting HOB pointer to search from.
74 @return The next instance of a HOB type from the starting HOB.
81 IN CONST VOID
*HobStart
84 EFI_PEI_HOB_POINTERS Hob
;
86 ASSERT (HobStart
!= NULL
);
88 Hob
.Raw
= (UINT8
*) HobStart
;
90 // Parse the HOB list until end of list or matching type is found.
92 while (!END_OF_HOB_LIST (Hob
)) {
93 if (Hob
.Header
->HobType
== Type
) {
96 Hob
.Raw
= GET_NEXT_HOB (Hob
);
102 Returns the first instance of a HOB type among the whole HOB list.
104 This function searches the first instance of a HOB type among the whole HOB list.
105 If there does not exist such HOB type in the HOB list, it will return NULL.
107 If the pointer to the HOB list is NULL, then ASSERT().
109 @param Type The HOB type to return.
111 @return The next instance of a HOB type from the starting HOB.
122 HobList
= GetHobList ();
123 return GetNextHob (Type
, HobList
);
127 Returns the next instance of the matched GUID HOB from the starting HOB.
129 This function searches the first instance of a HOB from the starting HOB pointer.
130 Such HOB should satisfy two conditions:
131 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
132 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
133 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
134 to extract the data section and its size info respectively.
135 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
136 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
137 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
139 If Guid is NULL, then ASSERT().
140 If HobStart is NULL, then ASSERT().
142 @param Guid The GUID to match with in the HOB list.
143 @param HobStart A pointer to a Guid.
145 @return The next instance of the matched GUID HOB from the starting HOB.
151 IN CONST EFI_GUID
*Guid
,
152 IN CONST VOID
*HobStart
155 EFI_PEI_HOB_POINTERS GuidHob
;
157 GuidHob
.Raw
= (UINT8
*) HobStart
;
158 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
159 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
162 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
168 Returns the first instance of the matched GUID HOB among the whole HOB list.
170 This function searches the first instance of a HOB among the whole HOB list.
171 Such HOB should satisfy two conditions:
172 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
173 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
174 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
175 to extract the data section and its size info respectively.
177 If the pointer to the HOB list is NULL, then ASSERT().
178 If Guid is NULL, then ASSERT().
180 @param Guid The GUID to match with in the HOB list.
182 @return The first instance of the matched GUID HOB among the whole HOB list.
188 IN CONST EFI_GUID
*Guid
193 HobList
= GetHobList ();
194 return GetNextGuidHob (Guid
, HobList
);
198 Get the system boot mode from the HOB list.
200 This function returns the system boot mode information from the
201 PHIT HOB in HOB list.
203 If the pointer to the HOB list is NULL, then ASSERT().
207 @return The Boot Mode.
217 EFI_BOOT_MODE BootMode
;
219 Status
= PeiServicesGetBootMode (&BootMode
);
220 ASSERT_EFI_ERROR (Status
);
226 Adds a new HOB to the HOB List.
228 This internal function enables PEIMs to create various types of HOBs.
230 @param Type Type of the new HOB.
231 @param Length Length of the new HOB to allocate.
233 @return The address of new HOB.
238 InternalPeiCreateHob (
246 Status
= PeiServicesCreateHob (Type
, Length
, &Hob
);
248 // Assume the process of HOB building is always successful.
250 ASSERT_EFI_ERROR (Status
);
255 Builds a HOB for a loaded PE32 module.
257 This function builds a HOB for a loaded PE32 module.
258 It can only be invoked during PEI phase;
259 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
261 If ModuleName is NULL, then ASSERT().
262 If there is no additional space for HOB creation, then ASSERT().
264 @param ModuleName The GUID File Name of the module.
265 @param MemoryAllocationModule The 64 bit physical address of the module.
266 @param ModuleLength The length of the module in bytes.
267 @param EntryPoint The 64 bit physical address of the module entry point.
273 IN CONST EFI_GUID
*ModuleName
,
274 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
275 IN UINT64 ModuleLength
,
276 IN EFI_PHYSICAL_ADDRESS EntryPoint
279 EFI_HOB_MEMORY_ALLOCATION_MODULE
*Hob
;
281 ASSERT (((MemoryAllocationModule
& (EFI_PAGE_SIZE
- 1)) == 0) &&
282 ((ModuleLength
& (EFI_PAGE_SIZE
- 1)) == 0));
284 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE
));
286 CopyGuid (&(Hob
->MemoryAllocationHeader
.Name
), &gEfiHobMemoryAllocModuleGuid
);
287 Hob
->MemoryAllocationHeader
.MemoryBaseAddress
= MemoryAllocationModule
;
288 Hob
->MemoryAllocationHeader
.MemoryLength
= ModuleLength
;
289 Hob
->MemoryAllocationHeader
.MemoryType
= EfiBootServicesCode
;
292 // Zero the reserved space to match HOB spec
294 ZeroMem (Hob
->MemoryAllocationHeader
.Reserved
, sizeof (Hob
->MemoryAllocationHeader
.Reserved
));
296 CopyGuid (&Hob
->ModuleName
, ModuleName
);
297 Hob
->EntryPoint
= EntryPoint
;
301 Builds a HOB that describes a chunk of system memory.
303 This function builds a HOB that describes a chunk of system memory.
304 It can only be invoked during PEI phase;
305 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
307 If there is no additional space for HOB creation, then ASSERT().
309 @param ResourceType The type of resource described by this HOB.
310 @param ResourceAttribute The resource attributes of the memory described by this HOB.
311 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
312 @param NumberOfBytes The length of the memory described by this HOB in bytes.
317 BuildResourceDescriptorHob (
318 IN EFI_RESOURCE_TYPE ResourceType
,
319 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
320 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
321 IN UINT64 NumberOfBytes
324 EFI_HOB_RESOURCE_DESCRIPTOR
*Hob
;
326 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR
));
328 Hob
->ResourceType
= ResourceType
;
329 Hob
->ResourceAttribute
= ResourceAttribute
;
330 Hob
->PhysicalStart
= PhysicalStart
;
331 Hob
->ResourceLength
= NumberOfBytes
;
335 Builds a customized HOB tagged with a GUID for identification and returns
336 the start address of GUID HOB data.
338 This function builds a customized HOB tagged with a GUID for identification
339 and returns the start address of GUID HOB data so that caller can fill the customized data.
340 The HOB Header and Name field is already stripped.
341 It can only be invoked during PEI phase;
342 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
344 If Guid is NULL, then ASSERT().
345 If there is no additional space for HOB creation, then ASSERT().
346 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
348 @param Guid The GUID to tag the customized HOB.
349 @param DataLength The size of the data payload for the GUID HOB.
351 @return The start address of GUID HOB data.
357 IN CONST EFI_GUID
*Guid
,
361 EFI_HOB_GUID_TYPE
*Hob
;
364 // Make sure that data length is not too long.
366 ASSERT (DataLength
<= (0xffff - sizeof (EFI_HOB_GUID_TYPE
)));
368 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION
, (UINT16
) (sizeof (EFI_HOB_GUID_TYPE
) + DataLength
));
369 CopyGuid (&Hob
->Name
, Guid
);
374 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
375 data field, and returns the start address of the GUID HOB data.
377 This function builds a customized HOB tagged with a GUID for identification and copies the input
378 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
379 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
380 The HOB Header and Name field is already stripped.
381 It can only be invoked during PEI phase;
382 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
384 If Guid is NULL, then ASSERT().
385 If Data is NULL and DataLength > 0, then ASSERT().
386 If there is no additional space for HOB creation, then ASSERT().
387 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
389 @param Guid The GUID to tag the customized HOB.
390 @param Data The data to be copied into the data field of the GUID HOB.
391 @param DataLength The size of the data payload for the GUID HOB.
393 @return The start address of GUID HOB data.
399 IN CONST EFI_GUID
*Guid
,
406 ASSERT (Data
!= NULL
|| DataLength
== 0);
408 HobData
= BuildGuidHob (Guid
, DataLength
);
410 return CopyMem (HobData
, Data
, DataLength
);
414 Builds a Firmware Volume HOB.
416 This function builds a Firmware Volume HOB.
417 It can only be invoked during PEI phase;
418 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
420 If there is no additional space for HOB creation, then ASSERT().
422 @param BaseAddress The base address of the Firmware Volume.
423 @param Length The size of the Firmware Volume in bytes.
429 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
433 EFI_HOB_FIRMWARE_VOLUME
*Hob
;
435 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_FV
, sizeof (EFI_HOB_FIRMWARE_VOLUME
));
437 Hob
->BaseAddress
= BaseAddress
;
438 Hob
->Length
= Length
;
442 Builds a EFI_HOB_TYPE_FV2 HOB.
444 This function builds a EFI_HOB_TYPE_FV2 HOB.
445 It can only be invoked during PEI phase;
446 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
448 If there is no additional space for HOB creation, then ASSERT().
450 @param BaseAddress The base address of the Firmware Volume.
451 @param Length The size of the Firmware Volume in bytes.
452 @param FvName The name of the Firmware Volume.
453 @param FileName The name of the file.
459 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
461 IN CONST EFI_GUID
*FvName
,
462 IN CONST EFI_GUID
*FileName
465 EFI_HOB_FIRMWARE_VOLUME2
*Hob
;
467 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_FV2
, sizeof (EFI_HOB_FIRMWARE_VOLUME2
));
469 Hob
->BaseAddress
= BaseAddress
;
470 Hob
->Length
= Length
;
471 CopyGuid (&Hob
->FvName
, FvName
);
472 CopyGuid (&Hob
->FileName
, FileName
);
476 Builds a Capsule Volume HOB.
478 This function builds a Capsule Volume HOB.
479 It can only be invoked during PEI phase;
480 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
482 If the platform does not support Capsule Volume HOBs, then ASSERT().
483 If there is no additional space for HOB creation, then ASSERT().
485 @param BaseAddress The base address of the Capsule Volume.
486 @param Length The size of the Capsule Volume in bytes.
492 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
496 EFI_HOB_CAPSULE_VOLUME
*Hob
;
498 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_CV
, sizeof (EFI_HOB_CAPSULE_VOLUME
));
500 Hob
->BaseAddress
= BaseAddress
;
501 Hob
->Length
= Length
;
505 Builds a HOB for the CPU.
507 This function builds a HOB for the CPU.
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.
511 If there is no additional space for HOB creation, then ASSERT().
513 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
514 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
520 IN UINT8 SizeOfMemorySpace
,
521 IN UINT8 SizeOfIoSpace
526 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_CPU
, sizeof (EFI_HOB_CPU
));
528 Hob
->SizeOfMemorySpace
= SizeOfMemorySpace
;
529 Hob
->SizeOfIoSpace
= SizeOfIoSpace
;
532 // Zero the reserved space to match HOB spec
534 ZeroMem (Hob
->Reserved
, sizeof (Hob
->Reserved
));
538 Builds a HOB for the Stack.
540 This function builds a HOB for the stack.
541 It can only be invoked during PEI phase;
542 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
544 If there is no additional space for HOB creation, then ASSERT().
546 @param BaseAddress The 64 bit physical address of the Stack.
547 @param Length The length of the stack in bytes.
553 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
557 EFI_HOB_MEMORY_ALLOCATION_STACK
*Hob
;
559 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
560 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
562 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK
));
564 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocStackGuid
);
565 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
566 Hob
->AllocDescriptor
.MemoryLength
= Length
;
567 Hob
->AllocDescriptor
.MemoryType
= EfiBootServicesData
;
570 // Zero the reserved space to match HOB spec
572 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
576 Builds a HOB for the BSP store.
578 This function builds a HOB for BSP store.
579 It can only be invoked during PEI phase;
580 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
582 If there is no additional space for HOB creation, then ASSERT().
584 @param BaseAddress The 64 bit physical address of the BSP.
585 @param Length The length of the BSP store in bytes.
586 @param MemoryType Type of memory allocated by this HOB.
592 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
594 IN EFI_MEMORY_TYPE MemoryType
597 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE
*Hob
;
599 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
600 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
602 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE
));
604 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocBspStoreGuid
);
605 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
606 Hob
->AllocDescriptor
.MemoryLength
= Length
;
607 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
610 // Zero the reserved space to match HOB spec
612 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
616 Builds a HOB for the memory allocation.
618 This function builds a HOB for the memory allocation.
619 It can only be invoked during PEI phase;
620 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
622 If there is no additional space for HOB creation, then ASSERT().
624 @param BaseAddress The 64 bit physical address of the memory.
625 @param Length The length of the memory allocation in bytes.
626 @param MemoryType Type of memory allocated by this HOB.
631 BuildMemoryAllocationHob (
632 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
634 IN EFI_MEMORY_TYPE MemoryType
637 EFI_HOB_MEMORY_ALLOCATION
*Hob
;
639 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
640 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
642 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION
));
644 ZeroMem (&(Hob
->AllocDescriptor
.Name
), sizeof (EFI_GUID
));
645 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
646 Hob
->AllocDescriptor
.MemoryLength
= Length
;
647 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
649 // Zero the reserved space to match HOB spec
651 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));