3 Copyright (c) 2010, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/PeCoffLib.h>
22 #include <Library/HobLib.h>
23 #include <Library/PcdLib.h>
24 #include <Library/PrePiHobListPointerLib.h>
26 #include <Protocol/PeCoffLoader.h>
27 #include <Guid/ExtractSection.h>
28 #include <Guid/MemoryTypeInformation.h>
29 #include <Guid/MemoryAllocationHob.h>
32 BuildMemoryTypeInformationHob (
37 Returns the pointer to the HOB list.
39 This function returns the pointer to first HOB in the list.
41 @return The pointer to the HOB list.
50 return PrePeiGetHobList ();
56 Updates the pointer to the HOB list.
58 @param HobList Hob list pointer to store
67 return PrePeiSetHobList (HobList
);
74 EFI_HOB_HANDOFF_INFO_TABLE
*
76 IN VOID
*EfiMemoryBegin
,
77 IN UINTN EfiMemoryLength
,
78 IN VOID
*EfiFreeMemoryBottom
,
79 IN VOID
*EfiFreeMemoryTop
82 EFI_HOB_HANDOFF_INFO_TABLE
*Hob
;
83 EFI_HOB_GENERIC_HEADER
*HobEnd
;
85 Hob
= EfiFreeMemoryBottom
;
86 HobEnd
= (EFI_HOB_GENERIC_HEADER
*)(Hob
+1);
88 Hob
->Header
.HobType
= EFI_HOB_TYPE_HANDOFF
;
89 Hob
->Header
.HobLength
= sizeof(EFI_HOB_HANDOFF_INFO_TABLE
);
90 Hob
->Header
.Reserved
= 0;
92 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
93 HobEnd
->HobLength
= sizeof(EFI_HOB_GENERIC_HEADER
);
96 Hob
->Version
= EFI_HOB_HANDOFF_TABLE_VERSION
;
97 Hob
->BootMode
= BOOT_WITH_FULL_CONFIGURATION
;
99 Hob
->EfiMemoryTop
= (UINTN
)EfiMemoryBegin
+ EfiMemoryLength
;
100 Hob
->EfiMemoryBottom
= (UINTN
)EfiMemoryBegin
;
101 Hob
->EfiFreeMemoryTop
= (UINTN
)EfiFreeMemoryTop
;
102 Hob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(HobEnd
+1);
103 Hob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HobEnd
;
114 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
115 EFI_HOB_GENERIC_HEADER
*HobEnd
;
116 EFI_PHYSICAL_ADDRESS FreeMemory
;
119 HandOffHob
= GetHobList ();
121 HobLength
= (UINT16
)((HobLength
+ 0x7) & (~0x7));
123 FreeMemory
= HandOffHob
->EfiFreeMemoryTop
- HandOffHob
->EfiFreeMemoryBottom
;
125 if (FreeMemory
< HobLength
) {
129 Hob
= (VOID
*) (UINTN
) HandOffHob
->EfiEndOfHobList
;
130 ((EFI_HOB_GENERIC_HEADER
*) Hob
)->HobType
= HobType
;
131 ((EFI_HOB_GENERIC_HEADER
*) Hob
)->HobLength
= HobLength
;
132 ((EFI_HOB_GENERIC_HEADER
*) Hob
)->Reserved
= 0;
134 HobEnd
= (EFI_HOB_GENERIC_HEADER
*) ((UINTN
)Hob
+ HobLength
);
135 HandOffHob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HobEnd
;
137 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
138 HobEnd
->HobLength
= sizeof(EFI_HOB_GENERIC_HEADER
);
139 HobEnd
->Reserved
= 0;
141 HandOffHob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HobEnd
;
147 Builds a HOB that describes a chunk of system memory.
149 This function builds a HOB that describes a chunk of system memory.
150 If there is no additional space for HOB creation, then ASSERT().
152 @param ResourceType The type of resource described by this HOB.
153 @param ResourceAttribute The resource attributes of the memory described by this HOB.
154 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
155 @param NumberOfBytes The length of the memory described by this HOB in bytes.
160 BuildResourceDescriptorHob (
161 IN EFI_RESOURCE_TYPE ResourceType
,
162 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
163 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
164 IN UINT64 NumberOfBytes
167 EFI_HOB_RESOURCE_DESCRIPTOR
*Hob
;
169 Hob
= CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR
));
172 Hob
->ResourceType
= ResourceType
;
173 Hob
->ResourceAttribute
= ResourceAttribute
;
174 Hob
->PhysicalStart
= PhysicalStart
;
175 Hob
->ResourceLength
= NumberOfBytes
;
181 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
182 IN UINT64 NumberOfBytes
,
183 IN EFI_RESOURCE_ATTRIBUTE_TYPE
*ResourceAttribute
187 EFI_RESOURCE_ATTRIBUTE_TYPE Resource
;
189 BuildFvHob (PhysicalStart
, NumberOfBytes
);
191 if (ResourceAttribute
== NULL
) {
192 Resource
= (EFI_RESOURCE_ATTRIBUTE_PRESENT
|
193 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
194 EFI_RESOURCE_ATTRIBUTE_TESTED
|
195 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
);
197 Resource
= *ResourceAttribute
;
200 BuildResourceDescriptorHob (EFI_RESOURCE_FIRMWARE_DEVICE
, Resource
, PhysicalStart
, NumberOfBytes
);
204 Returns the next instance of a HOB type from the starting HOB.
206 This function searches the first instance of a HOB type from the starting HOB pointer.
207 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
208 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
209 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
210 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
211 If HobStart is NULL, then ASSERT().
213 @param Type The HOB type to return.
214 @param HobStart The starting HOB pointer to search from.
216 @return The next instance of a HOB type from the starting HOB.
223 IN CONST VOID
*HobStart
226 EFI_PEI_HOB_POINTERS Hob
;
228 ASSERT (HobStart
!= NULL
);
230 Hob
.Raw
= (UINT8
*) HobStart
;
232 // Parse the HOB list until end of list or matching type is found.
234 while (!END_OF_HOB_LIST (Hob
)) {
235 if (Hob
.Header
->HobType
== Type
) {
238 Hob
.Raw
= GET_NEXT_HOB (Hob
);
246 Returns the first instance of a HOB type among the whole HOB list.
248 This function searches the first instance of a HOB type among the whole HOB list.
249 If there does not exist such HOB type in the HOB list, it will return NULL.
251 @param Type The HOB type to return.
253 @return The next instance of a HOB type from the starting HOB.
264 HobList
= GetHobList ();
265 return GetNextHob (Type
, HobList
);
270 This function searches the first instance of a HOB from the starting HOB pointer.
271 Such HOB should satisfy two conditions:
272 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
273 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
274 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
275 to extract the data section and its size info respectively.
276 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
277 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
278 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
279 If Guid is NULL, then ASSERT().
280 If HobStart is NULL, then ASSERT().
282 @param Guid The GUID to match with in the HOB list.
283 @param HobStart A pointer to a Guid.
285 @return The next instance of the matched GUID HOB from the starting HOB.
291 IN CONST EFI_GUID
*Guid
,
292 IN CONST VOID
*HobStart
294 EFI_PEI_HOB_POINTERS GuidHob
;
296 GuidHob
.Raw
= (UINT8
*) HobStart
;
297 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
298 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
301 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
308 This function searches the first instance of a HOB among the whole HOB list.
309 Such HOB should satisfy two conditions:
310 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
311 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
312 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
313 to extract the data section and its size info respectively.
314 If Guid is NULL, then ASSERT().
316 @param Guid The GUID to match with in the HOB list.
318 @return The first instance of the matched GUID HOB among the whole HOB list.
324 IN CONST EFI_GUID
*Guid
329 HobList
= GetHobList ();
330 return GetNextGuidHob (Guid
, HobList
);
335 Get the Boot Mode from the HOB list.
337 This function returns the system boot mode information from the
338 PHIT HOB in HOB list.
342 @return The Boot Mode.
351 EFI_PEI_HOB_POINTERS Hob
;
353 Hob
.Raw
= GetHobList ();
354 return Hob
.HandoffInformationTable
->BootMode
;
359 Get the Boot Mode from the HOB list.
361 This function returns the system boot mode information from the
362 PHIT HOB in HOB list.
366 @return The Boot Mode.
372 IN EFI_BOOT_MODE BootMode
375 EFI_PEI_HOB_POINTERS Hob
;
377 Hob
.Raw
= GetHobList ();
378 Hob
.HandoffInformationTable
->BootMode
= BootMode
;
383 Builds a HOB for a loaded PE32 module.
385 This function builds a HOB for a loaded PE32 module.
386 It can only be invoked during PEI phase;
387 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
388 If ModuleName is NULL, then ASSERT().
389 If there is no additional space for HOB creation, then ASSERT().
391 @param ModuleName The GUID File Name of the module.
392 @param MemoryAllocationModule The 64 bit physical address of the module.
393 @param ModuleLength The length of the module in bytes.
394 @param EntryPoint The 64 bit physical address of the module entry point.
400 IN CONST EFI_GUID
*ModuleName
,
401 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
402 IN UINT64 ModuleLength
,
403 IN EFI_PHYSICAL_ADDRESS EntryPoint
406 EFI_HOB_MEMORY_ALLOCATION_MODULE
*Hob
;
408 ASSERT (((MemoryAllocationModule
& (EFI_PAGE_SIZE
- 1)) == 0) &&
409 ((ModuleLength
& (EFI_PAGE_SIZE
- 1)) == 0));
411 Hob
= CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE
));
413 CopyGuid (&(Hob
->MemoryAllocationHeader
.Name
), &gEfiHobMemoryAllocModuleGuid
);
414 Hob
->MemoryAllocationHeader
.MemoryBaseAddress
= MemoryAllocationModule
;
415 Hob
->MemoryAllocationHeader
.MemoryLength
= ModuleLength
;
416 Hob
->MemoryAllocationHeader
.MemoryType
= EfiBootServicesCode
;
419 // Zero the reserved space to match HOB spec
421 ZeroMem (Hob
->MemoryAllocationHeader
.Reserved
, sizeof (Hob
->MemoryAllocationHeader
.Reserved
));
423 CopyGuid (&Hob
->ModuleName
, ModuleName
);
424 Hob
->EntryPoint
= EntryPoint
;
428 Builds a GUID HOB with a certain data length.
430 This function builds a customized HOB tagged with a GUID for identification
431 and returns the start address of GUID HOB data so that caller can fill the customized data.
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.
435 If Guid is NULL, then ASSERT().
436 If there is no additional space for HOB creation, then ASSERT().
437 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
439 @param Guid The GUID to tag the customized HOB.
440 @param DataLength The size of the data payload for the GUID HOB.
442 @return The start address of GUID HOB data.
448 IN CONST EFI_GUID
*Guid
,
452 EFI_HOB_GUID_TYPE
*Hob
;
455 // Make sure that data length is not too long.
457 ASSERT (DataLength
<= (0xffff - sizeof (EFI_HOB_GUID_TYPE
)));
459 Hob
= CreateHob (EFI_HOB_TYPE_GUID_EXTENSION
, (UINT16
) (sizeof (EFI_HOB_GUID_TYPE
) + DataLength
));
460 CopyGuid (&Hob
->Name
, Guid
);
466 Copies a data buffer to a newly-built HOB.
468 This function builds a customized HOB tagged with a GUID for identification,
469 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
470 The HOB Header and Name field is already stripped.
471 It can only be invoked during PEI phase;
472 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
473 If Guid is NULL, then ASSERT().
474 If Data is NULL and DataLength > 0, then ASSERT().
475 If there is no additional space for HOB creation, then ASSERT().
476 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
478 @param Guid The GUID to tag the customized HOB.
479 @param Data The data to be copied into the data field of the GUID HOB.
480 @param DataLength The size of the data payload for the GUID HOB.
482 @return The start address of GUID HOB data.
488 IN CONST EFI_GUID
*Guid
,
495 ASSERT (Data
!= NULL
|| DataLength
== 0);
497 HobData
= BuildGuidHob (Guid
, DataLength
);
499 return CopyMem (HobData
, Data
, DataLength
);
504 Builds a Firmware Volume HOB.
506 This function builds a Firmware Volume HOB.
507 It can only be invoked during PEI phase;
508 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
509 If there is no additional space for HOB creation, then ASSERT().
511 @param BaseAddress The base address of the Firmware Volume.
512 @param Length The size of the Firmware Volume in bytes.
518 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
522 EFI_HOB_FIRMWARE_VOLUME
*Hob
;
524 Hob
= CreateHob (EFI_HOB_TYPE_FV
, sizeof (EFI_HOB_FIRMWARE_VOLUME
));
526 Hob
->BaseAddress
= BaseAddress
;
527 Hob
->Length
= Length
;
532 Builds a EFI_HOB_TYPE_FV2 HOB.
534 This function builds a EFI_HOB_TYPE_FV2 HOB.
535 It can only be invoked during PEI phase;
536 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
537 If there is no additional space for HOB creation, then ASSERT().
539 @param BaseAddress The base address of the Firmware Volume.
540 @param Length The size of the Firmware Volume in bytes.
541 @param FvName The name of the Firmware Volume.
542 @param FileName The name of the file.
548 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
550 IN CONST EFI_GUID
*FvName
,
551 IN CONST EFI_GUID
*FileName
554 EFI_HOB_FIRMWARE_VOLUME2
*Hob
;
556 Hob
= CreateHob (EFI_HOB_TYPE_FV2
, sizeof (EFI_HOB_FIRMWARE_VOLUME2
));
558 Hob
->BaseAddress
= BaseAddress
;
559 Hob
->Length
= Length
;
560 CopyGuid (&Hob
->FvName
, FvName
);
561 CopyGuid (&Hob
->FileName
, FileName
);
565 Builds a EFI_HOB_TYPE_FV3 HOB.
567 This function builds a EFI_HOB_TYPE_FV3 HOB.
568 It can only be invoked during PEI phase;
569 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
571 If there is no additional space for HOB creation, 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 AuthenticationStatus The authentication status.
576 @param ExtractedFv TRUE if the FV was extracted as a file within
577 another firmware volume. FALSE otherwise.
578 @param FvName The name of the Firmware Volume.
579 Valid only if IsExtractedFv is TRUE.
580 @param FileName The name of the file.
581 Valid only if IsExtractedFv is TRUE.
587 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
589 IN UINT32 AuthenticationStatus
,
590 IN BOOLEAN ExtractedFv
,
591 IN CONST EFI_GUID
*FvName
, OPTIONAL
592 IN CONST EFI_GUID
*FileName OPTIONAL
595 EFI_HOB_FIRMWARE_VOLUME3
*Hob
;
597 Hob
= CreateHob (EFI_HOB_TYPE_FV3
, sizeof (EFI_HOB_FIRMWARE_VOLUME3
));
599 Hob
->BaseAddress
= BaseAddress
;
600 Hob
->Length
= Length
;
601 Hob
->AuthenticationStatus
= AuthenticationStatus
;
602 Hob
->ExtractedFv
= ExtractedFv
;
604 CopyGuid (&Hob
->FvName
, FvName
);
605 CopyGuid (&Hob
->FileName
, FileName
);
610 Builds a Capsule Volume HOB.
612 This function builds a Capsule Volume HOB.
613 It can only be invoked during PEI phase;
614 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
615 If there is no additional space for HOB creation, then ASSERT().
617 @param BaseAddress The base address of the Capsule Volume.
618 @param Length The size of the Capsule Volume in bytes.
624 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
633 Builds a HOB for the CPU.
635 This function builds a HOB for the CPU.
636 It can only be invoked during PEI phase;
637 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
638 If there is no additional space for HOB creation, then ASSERT().
640 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
641 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
647 IN UINT8 SizeOfMemorySpace
,
648 IN UINT8 SizeOfIoSpace
653 Hob
= CreateHob (EFI_HOB_TYPE_CPU
, sizeof (EFI_HOB_CPU
));
655 Hob
->SizeOfMemorySpace
= SizeOfMemorySpace
;
656 Hob
->SizeOfIoSpace
= SizeOfIoSpace
;
659 // Zero the reserved space to match HOB spec
661 ZeroMem (Hob
->Reserved
, sizeof (Hob
->Reserved
));
666 Builds a HOB for the Stack.
668 This function builds a HOB for the stack.
669 It can only be invoked during PEI phase;
670 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
671 If there is no additional space for HOB creation, then ASSERT().
673 @param BaseAddress The 64 bit physical address of the Stack.
674 @param Length The length of the stack in bytes.
680 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
684 EFI_HOB_MEMORY_ALLOCATION_STACK
*Hob
;
686 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
687 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
689 Hob
= CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK
));
691 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocStackGuid
);
692 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
693 Hob
->AllocDescriptor
.MemoryLength
= Length
;
694 Hob
->AllocDescriptor
.MemoryType
= EfiBootServicesData
;
697 // Zero the reserved space to match HOB spec
699 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
704 Update the Stack Hob if the stack has been moved
706 @param BaseAddress The 64 bit physical address of the Stack.
707 @param Length The length of the stack in bytes.
712 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
716 EFI_PEI_HOB_POINTERS Hob
;
718 Hob
.Raw
= GetHobList ();
719 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, Hob
.Raw
)) != NULL
) {
720 if (CompareGuid (&gEfiHobMemoryAllocStackGuid
, &(Hob
.MemoryAllocationStack
->AllocDescriptor
.Name
))) {
722 // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type
723 // to be reclaimed by DXE core.
725 BuildMemoryAllocationHob (
726 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
,
727 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
,
728 EfiConventionalMemory
731 // Update the BSP Stack Hob to reflect the new stack info.
733 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
734 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
= Length
;
737 Hob
.Raw
= GET_NEXT_HOB (Hob
);
744 Builds a HOB for the memory allocation.
746 This function builds a HOB for the memory allocation.
747 It can only be invoked during PEI phase;
748 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
749 If there is no additional space for HOB creation, then ASSERT().
751 @param BaseAddress The 64 bit physical address of the memory.
752 @param Length The length of the memory allocation in bytes.
753 @param MemoryType Type of memory allocated by this HOB.
758 BuildMemoryAllocationHob (
759 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
761 IN EFI_MEMORY_TYPE MemoryType
764 EFI_HOB_MEMORY_ALLOCATION
*Hob
;
766 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
767 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
769 Hob
= CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION
));
771 ZeroMem (&(Hob
->AllocDescriptor
.Name
), sizeof (EFI_GUID
));
772 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
773 Hob
->AllocDescriptor
.MemoryLength
= Length
;
774 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
776 // Zero the reserved space to match HOB spec
778 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
785 BuildExtractSectionHob (
787 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER SectionGetInfo
,
788 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER SectionExtraction
791 EXTRACT_SECTION_DATA Data
;
793 Data
.SectionGetInfo
= SectionGetInfo
;
794 Data
.SectionExtraction
= SectionExtraction
;
795 BuildGuidDataHob (Guid
, &Data
, sizeof (Data
));
798 PE_COFF_LOADER_PROTOCOL gPeCoffProtocol
= {
799 PeCoffLoaderGetImageInfo
,
800 PeCoffLoaderLoadImage
,
801 PeCoffLoaderRelocateImage
,
802 PeCoffLoaderImageReadFromMemory
,
803 PeCoffLoaderRelocateImageForRuntime
,
804 PeCoffLoaderUnloadImage
811 BuildPeCoffLoaderHob (
817 Ptr
= &gPeCoffProtocol
;
818 BuildGuidDataHob (&gPeCoffLoaderProtocolGuid
, &Ptr
, sizeof (VOID
*));
821 // May want to put this into a library so you only need the PCD setings if you are using the feature?
823 BuildMemoryTypeInformationHob (
827 EFI_MEMORY_TYPE_INFORMATION Info
[10];
829 Info
[0].Type
= EfiACPIReclaimMemory
;
830 Info
[0].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory
);
831 Info
[1].Type
= EfiACPIMemoryNVS
;
832 Info
[1].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS
);
833 Info
[2].Type
= EfiReservedMemoryType
;
834 Info
[2].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiReservedMemoryType
);
835 Info
[3].Type
= EfiRuntimeServicesData
;
836 Info
[3].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData
);
837 Info
[4].Type
= EfiRuntimeServicesCode
;
838 Info
[4].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode
);
839 Info
[5].Type
= EfiBootServicesCode
;
840 Info
[5].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesCode
);
841 Info
[6].Type
= EfiBootServicesData
;
842 Info
[6].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesData
);
843 Info
[7].Type
= EfiLoaderCode
;
844 Info
[7].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderCode
);
845 Info
[8].Type
= EfiLoaderData
;
846 Info
[8].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderData
);
848 // Terminator for the list
849 Info
[9].Type
= EfiMaxMemoryType
;
850 Info
[9].NumberOfPages
= 0;
853 BuildGuidDataHob (&gEfiMemoryTypeInformationGuid
, &Info
, sizeof (Info
));