2 Provide Hob Library functions for Pei phase.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Guid/MemoryAllocationHob.h>
13 #include <Library/HobLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Library/BaseMemoryLib.h>
19 Returns the pointer to the HOB list.
21 This function returns the pointer to first HOB in the list.
22 For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
23 to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
24 the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
25 Since the System Configuration Table does not exist that the time the DXE Core is
26 launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
27 to manage the pointer to the HOB list.
29 If the pointer to the HOB list is NULL, then ASSERT().
31 @return The pointer to the HOB list.
43 Status
= PeiServicesGetHobList (&HobList
);
44 ASSERT_EFI_ERROR (Status
);
45 ASSERT (HobList
!= NULL
);
51 Returns the next instance of a HOB type from the starting HOB.
53 This function searches the first instance of a HOB type from the starting HOB pointer.
54 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
55 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
56 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
57 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
59 If HobStart is NULL, then ASSERT().
61 @param Type The HOB type to return.
62 @param HobStart The starting HOB pointer to search from.
64 @return The next instance of a HOB type from the starting HOB.
71 IN CONST VOID
*HobStart
74 EFI_PEI_HOB_POINTERS Hob
;
76 ASSERT (HobStart
!= NULL
);
78 Hob
.Raw
= (UINT8
*) HobStart
;
80 // Parse the HOB list until end of list or matching type is found.
82 while (!END_OF_HOB_LIST (Hob
)) {
83 if (Hob
.Header
->HobType
== Type
) {
86 Hob
.Raw
= GET_NEXT_HOB (Hob
);
92 Returns the first instance of a HOB type among the whole HOB list.
94 This function searches the first instance of a HOB type among the whole HOB list.
95 If there does not exist such HOB type in the HOB list, it will return NULL.
97 If the pointer to the HOB list is NULL, then ASSERT().
99 @param Type The HOB type to return.
101 @return The next instance of a HOB type from the starting HOB.
112 HobList
= GetHobList ();
113 return GetNextHob (Type
, HobList
);
117 Returns the next instance of the matched GUID HOB from the starting HOB.
119 This function searches the first instance of a HOB from the starting HOB pointer.
120 Such HOB should satisfy two conditions:
121 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
122 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
123 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
124 to extract the data section and its size information, respectively.
125 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
126 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
127 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
129 If Guid is NULL, then ASSERT().
130 If HobStart is NULL, then ASSERT().
132 @param Guid The GUID to match with in the HOB list.
133 @param HobStart A pointer to a Guid.
135 @return The next instance of the matched GUID HOB from the starting HOB.
141 IN CONST EFI_GUID
*Guid
,
142 IN CONST VOID
*HobStart
145 EFI_PEI_HOB_POINTERS GuidHob
;
147 GuidHob
.Raw
= (UINT8
*) HobStart
;
148 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
149 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
152 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
158 Returns the first instance of the matched GUID HOB among the whole HOB list.
160 This function searches the first instance of a HOB among the whole HOB list.
161 Such HOB should satisfy two conditions:
162 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
163 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
164 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
165 to extract the data section and its size information, respectively.
167 If the pointer to the HOB list is NULL, then ASSERT().
168 If Guid is NULL, then ASSERT().
170 @param Guid The GUID to match with in the HOB list.
172 @return The first instance of the matched GUID HOB among the whole HOB list.
178 IN CONST EFI_GUID
*Guid
183 HobList
= GetHobList ();
184 return GetNextGuidHob (Guid
, HobList
);
188 Get the system boot mode from the HOB list.
190 This function returns the system boot mode information from the
191 PHIT HOB in HOB list.
193 If the pointer to the HOB list is NULL, then ASSERT().
197 @return The Boot Mode.
207 EFI_BOOT_MODE BootMode
;
209 Status
= PeiServicesGetBootMode (&BootMode
);
210 ASSERT_EFI_ERROR (Status
);
216 Adds a new HOB to the HOB List.
218 This internal function enables PEIMs to create various types of HOBs.
220 @param Type Type of the new HOB.
221 @param Length Length of the new HOB to allocate.
223 @retval NULL The HOB could not be allocated.
224 @retval others The address of new HOB.
229 InternalPeiCreateHob (
237 Status
= PeiServicesCreateHob (Type
, Length
, &Hob
);
238 if (EFI_ERROR (Status
)) {
242 // Assume the process of HOB building is always successful.
244 ASSERT (Hob
!= NULL
);
249 Builds a HOB for a loaded PE32 module.
251 This function builds a HOB for a loaded PE32 module.
252 It can only be invoked during PEI phase;
253 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
255 If ModuleName is NULL, then ASSERT().
256 If there is no additional space for HOB creation, then ASSERT().
258 @param ModuleName The GUID File Name of the module.
259 @param MemoryAllocationModule The 64 bit physical address of the module.
260 @param ModuleLength The length of the module in bytes.
261 @param EntryPoint The 64 bit physical address of the module entry point.
267 IN CONST EFI_GUID
*ModuleName
,
268 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
269 IN UINT64 ModuleLength
,
270 IN EFI_PHYSICAL_ADDRESS EntryPoint
273 EFI_HOB_MEMORY_ALLOCATION_MODULE
*Hob
;
275 ASSERT (((MemoryAllocationModule
& (EFI_PAGE_SIZE
- 1)) == 0) &&
276 ((ModuleLength
& (EFI_PAGE_SIZE
- 1)) == 0));
278 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, (UINT16
) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE
));
283 CopyGuid (&(Hob
->MemoryAllocationHeader
.Name
), &gEfiHobMemoryAllocModuleGuid
);
284 Hob
->MemoryAllocationHeader
.MemoryBaseAddress
= MemoryAllocationModule
;
285 Hob
->MemoryAllocationHeader
.MemoryLength
= ModuleLength
;
286 Hob
->MemoryAllocationHeader
.MemoryType
= EfiBootServicesCode
;
289 // Zero the reserved space to match HOB spec
291 ZeroMem (Hob
->MemoryAllocationHeader
.Reserved
, sizeof (Hob
->MemoryAllocationHeader
.Reserved
));
293 CopyGuid (&Hob
->ModuleName
, ModuleName
);
294 Hob
->EntryPoint
= EntryPoint
;
298 Builds a HOB that describes a chunk of system memory with Owner GUID.
300 This function builds a HOB that describes a chunk of system memory.
301 It can only be invoked during PEI phase;
302 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
304 If there is no additional space for HOB creation, then ASSERT().
306 @param ResourceType The type of resource described by this HOB.
307 @param ResourceAttribute The resource attributes of the memory described by this HOB.
308 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
309 @param NumberOfBytes The length of the memory described by this HOB in bytes.
310 @param OwnerGUID GUID for the owner of this resource.
315 BuildResourceDescriptorWithOwnerHob (
316 IN EFI_RESOURCE_TYPE ResourceType
,
317 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
318 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
319 IN UINT64 NumberOfBytes
,
320 IN EFI_GUID
*OwnerGUID
323 EFI_HOB_RESOURCE_DESCRIPTOR
*Hob
;
325 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, (UINT16
) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR
));
330 Hob
->ResourceType
= ResourceType
;
331 Hob
->ResourceAttribute
= ResourceAttribute
;
332 Hob
->PhysicalStart
= PhysicalStart
;
333 Hob
->ResourceLength
= NumberOfBytes
;
335 CopyGuid (&Hob
->Owner
, OwnerGUID
);
339 Builds a HOB that describes a chunk of system memory.
341 This function builds a HOB that describes a chunk of system memory.
342 It can only be invoked during PEI phase;
343 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
345 If there is no additional space for HOB creation, then ASSERT().
347 @param ResourceType The type of resource described by this HOB.
348 @param ResourceAttribute The resource attributes of the memory described by this HOB.
349 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
350 @param NumberOfBytes The length of the memory described by this HOB in bytes.
355 BuildResourceDescriptorHob (
356 IN EFI_RESOURCE_TYPE ResourceType
,
357 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
358 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
359 IN UINT64 NumberOfBytes
362 EFI_HOB_RESOURCE_DESCRIPTOR
*Hob
;
364 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, (UINT16
) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR
));
369 Hob
->ResourceType
= ResourceType
;
370 Hob
->ResourceAttribute
= ResourceAttribute
;
371 Hob
->PhysicalStart
= PhysicalStart
;
372 Hob
->ResourceLength
= NumberOfBytes
;
373 ZeroMem (&(Hob
->Owner
), sizeof (EFI_GUID
));
377 Builds a customized HOB tagged with a GUID for identification and returns
378 the start address of GUID HOB data.
380 This function builds a customized HOB tagged with a GUID for identification
381 and returns the start address of GUID HOB data so that caller can fill the customized data.
382 The HOB Header and Name field is already stripped.
383 It can only be invoked during PEI phase;
384 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
386 If Guid is NULL, then ASSERT().
387 If there is no additional space for HOB creation, then ASSERT().
388 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
389 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
391 @param Guid The GUID to tag the customized HOB.
392 @param DataLength The size of the data payload for the GUID HOB.
394 @retval NULL The GUID HOB could not be allocated.
395 @retval others The start address of GUID HOB data.
401 IN CONST EFI_GUID
*Guid
,
405 EFI_HOB_GUID_TYPE
*Hob
;
408 // Make sure Guid is valid
410 ASSERT (Guid
!= NULL
);
413 // Make sure that data length is not too long.
415 ASSERT (DataLength
<= (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE
)));
417 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION
, (UINT16
) (sizeof (EFI_HOB_GUID_TYPE
) + DataLength
));
421 CopyGuid (&Hob
->Name
, Guid
);
426 Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
427 data field, and returns the start address of the GUID HOB data.
429 This function builds a customized HOB tagged with a GUID for identification and copies the input
430 data to the HOB data field and returns the start address of the GUID HOB data. It can only be
431 invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
432 The HOB Header and Name field is already stripped.
433 It can only be invoked during PEI phase;
434 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
436 If Guid is NULL, then ASSERT().
437 If Data is NULL and DataLength > 0, then ASSERT().
438 If there is no additional space for HOB creation, then ASSERT().
439 If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
440 HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
442 @param Guid The GUID to tag the customized HOB.
443 @param Data The data to be copied into the data field of the GUID HOB.
444 @param DataLength The size of the data payload for the GUID HOB.
446 @retval NULL The GUID HOB could not be allocated.
447 @retval others The start address of GUID HOB data.
453 IN CONST EFI_GUID
*Guid
,
460 ASSERT (Data
!= NULL
|| DataLength
== 0);
462 HobData
= BuildGuidHob (Guid
, DataLength
);
463 if (HobData
== NULL
) {
467 return CopyMem (HobData
, Data
, DataLength
);
473 @param BaseAddress The base address of the Firmware Volume.
474 @param Length The size of the Firmware Volume in bytes.
476 @retval TRUE FvImage buffer is at its required alignment.
477 @retval FALSE FvImage buffer is not at its required alignment.
481 InternalCheckFvAlignment (
482 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
486 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
490 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) BaseAddress
;
493 // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
494 // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
495 // its initial linked location and maintain its alignment.
497 if ((FwVolHeader
->Attributes
& EFI_FVB2_WEAK_ALIGNMENT
) != EFI_FVB2_WEAK_ALIGNMENT
) {
499 // Get FvHeader alignment
501 FvAlignment
= 1 << ((FwVolHeader
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
503 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
505 if (FvAlignment
< 8) {
508 if ((UINTN
)BaseAddress
% FvAlignment
!= 0) {
510 // FvImage buffer is not at its required alignment.
514 "Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",
527 Builds a Firmware Volume HOB.
529 This function builds a Firmware Volume HOB.
530 It can only be invoked during PEI phase;
531 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
533 If there is no additional space for HOB creation, then ASSERT().
534 If the FvImage buffer is not at its required alignment, then ASSERT().
536 @param BaseAddress The base address of the Firmware Volume.
537 @param Length The size of the Firmware Volume in bytes.
543 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
547 EFI_HOB_FIRMWARE_VOLUME
*Hob
;
549 if (!InternalCheckFvAlignment (BaseAddress
, Length
)) {
554 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_FV
, (UINT16
) sizeof (EFI_HOB_FIRMWARE_VOLUME
));
559 Hob
->BaseAddress
= BaseAddress
;
560 Hob
->Length
= Length
;
564 Builds a EFI_HOB_TYPE_FV2 HOB.
566 This function builds a EFI_HOB_TYPE_FV2 HOB.
567 It can only be invoked during PEI phase;
568 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
570 If there is no additional space for HOB creation, then ASSERT().
571 If the FvImage buffer is not at its required alignment, then ASSERT().
573 @param BaseAddress The base address of the Firmware Volume.
574 @param Length The size of the Firmware Volume in bytes.
575 @param FvName The name of the Firmware Volume.
576 @param FileName The name of the file.
582 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
584 IN CONST EFI_GUID
*FvName
,
585 IN CONST EFI_GUID
*FileName
588 EFI_HOB_FIRMWARE_VOLUME2
*Hob
;
590 if (!InternalCheckFvAlignment (BaseAddress
, Length
)) {
595 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_FV2
, (UINT16
) sizeof (EFI_HOB_FIRMWARE_VOLUME2
));
600 Hob
->BaseAddress
= BaseAddress
;
601 Hob
->Length
= Length
;
602 CopyGuid (&Hob
->FvName
, FvName
);
603 CopyGuid (&Hob
->FileName
, FileName
);
607 Builds a EFI_HOB_TYPE_FV3 HOB.
609 This function builds a EFI_HOB_TYPE_FV3 HOB.
610 It can only be invoked during PEI phase;
611 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
613 If there is no additional space for HOB creation, then ASSERT().
614 If the FvImage buffer is not at its required alignment, then ASSERT().
616 @param BaseAddress The base address of the Firmware Volume.
617 @param Length The size of the Firmware Volume in bytes.
618 @param AuthenticationStatus The authentication status.
619 @param ExtractedFv TRUE if the FV was extracted as a file within
620 another firmware volume. FALSE otherwise.
621 @param FvName The name of the Firmware Volume.
622 Valid only if IsExtractedFv is TRUE.
623 @param FileName The name of the file.
624 Valid only if IsExtractedFv is TRUE.
630 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
632 IN UINT32 AuthenticationStatus
,
633 IN BOOLEAN ExtractedFv
,
634 IN CONST EFI_GUID
*FvName
, OPTIONAL
635 IN CONST EFI_GUID
*FileName OPTIONAL
638 EFI_HOB_FIRMWARE_VOLUME3
*Hob
;
640 if (!InternalCheckFvAlignment (BaseAddress
, Length
)) {
645 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_FV3
, (UINT16
) sizeof (EFI_HOB_FIRMWARE_VOLUME3
));
650 Hob
->BaseAddress
= BaseAddress
;
651 Hob
->Length
= Length
;
652 Hob
->AuthenticationStatus
= AuthenticationStatus
;
653 Hob
->ExtractedFv
= ExtractedFv
;
655 CopyGuid (&Hob
->FvName
, FvName
);
656 CopyGuid (&Hob
->FileName
, FileName
);
661 Builds a Capsule Volume HOB.
663 This function builds a Capsule Volume HOB.
664 It can only be invoked during PEI phase;
665 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
667 If the platform does not support Capsule Volume HOBs, then ASSERT().
668 If there is no additional space for HOB creation, then ASSERT().
670 @param BaseAddress The base address of the Capsule Volume.
671 @param Length The size of the Capsule Volume in bytes.
677 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
681 EFI_HOB_UEFI_CAPSULE
*Hob
;
683 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_UEFI_CAPSULE
, (UINT16
) sizeof (EFI_HOB_UEFI_CAPSULE
));
688 Hob
->BaseAddress
= BaseAddress
;
689 Hob
->Length
= Length
;
693 Builds a HOB for the CPU.
695 This function builds a HOB for the CPU.
696 It can only be invoked during PEI phase;
697 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
699 If there is no additional space for HOB creation, then ASSERT().
701 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
702 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
708 IN UINT8 SizeOfMemorySpace
,
709 IN UINT8 SizeOfIoSpace
714 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_CPU
, (UINT16
) sizeof (EFI_HOB_CPU
));
719 Hob
->SizeOfMemorySpace
= SizeOfMemorySpace
;
720 Hob
->SizeOfIoSpace
= SizeOfIoSpace
;
723 // Zero the reserved space to match HOB spec
725 ZeroMem (Hob
->Reserved
, sizeof (Hob
->Reserved
));
729 Builds a HOB for the Stack.
731 This function builds a HOB for the stack.
732 It can only be invoked during PEI phase;
733 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
735 If there is no additional space for HOB creation, then ASSERT().
737 @param BaseAddress The 64 bit physical address of the Stack.
738 @param Length The length of the stack in bytes.
744 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
748 EFI_HOB_MEMORY_ALLOCATION_STACK
*Hob
;
750 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
751 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
753 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, (UINT16
) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK
));
758 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocStackGuid
);
759 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
760 Hob
->AllocDescriptor
.MemoryLength
= Length
;
761 Hob
->AllocDescriptor
.MemoryType
= EfiBootServicesData
;
764 // Zero the reserved space to match HOB spec
766 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
770 Builds a HOB for the BSP store.
772 This function builds a HOB for BSP store.
773 It can only be invoked during PEI phase;
774 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
776 If there is no additional space for HOB creation, then ASSERT().
778 @param BaseAddress The 64 bit physical address of the BSP.
779 @param Length The length of the BSP store in bytes.
780 @param MemoryType The type of memory allocated by this HOB.
786 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
788 IN EFI_MEMORY_TYPE MemoryType
791 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE
*Hob
;
793 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
794 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
796 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, (UINT16
) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE
));
801 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocBspStoreGuid
);
802 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
803 Hob
->AllocDescriptor
.MemoryLength
= Length
;
804 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
807 // Zero the reserved space to match HOB spec
809 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
813 Builds a HOB for the memory allocation.
815 This function builds a HOB for the memory allocation.
816 It can only be invoked during PEI phase;
817 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
819 If there is no additional space for HOB creation, then ASSERT().
821 @param BaseAddress The 64 bit physical address of the memory.
822 @param Length The length of the memory allocation in bytes.
823 @param MemoryType The type of memory allocated by this HOB.
828 BuildMemoryAllocationHob (
829 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
831 IN EFI_MEMORY_TYPE MemoryType
834 EFI_HOB_MEMORY_ALLOCATION
*Hob
;
836 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
837 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
839 Hob
= InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, (UINT16
) sizeof (EFI_HOB_MEMORY_ALLOCATION
));
844 ZeroMem (&(Hob
->AllocDescriptor
.Name
), sizeof (EFI_GUID
));
845 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
846 Hob
->AllocDescriptor
.MemoryLength
= Length
;
847 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
849 // Zero the reserved space to match HOB spec
851 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));