summaryrefslogtreecommitdiff
path: root/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c')
-rwxr-xr-xArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c135
1 files changed, 69 insertions, 66 deletions
diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
index 95d40b2c44..8469c235eb 100755
--- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
+++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
@@ -67,21 +67,21 @@ MemoryPeim (
IN UINT64 UefiMemorySize
)
{
- EFI_STATUS Status;
- EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
- ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR* EfiMemoryMap;
- UINTN Index;
- EFI_PHYSICAL_ADDRESS SystemMemoryTop;
+ EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
+ UINT64 ResourceLength;
+ EFI_PEI_HOB_POINTERS NextHob;
+ EFI_PHYSICAL_ADDRESS FdTop;
+ EFI_PHYSICAL_ADDRESS SystemMemoryTop;
+ EFI_PHYSICAL_ADDRESS ResourceTop;
+ BOOLEAN Found;
// Ensure PcdSystemMemorySize has been set
ASSERT (PcdGet32 (PcdSystemMemorySize) != 0);
- SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)((UINT32)PcdGet32 (PcdSystemMemoryBase) + (UINT32)PcdGet32 (PcdSystemMemorySize));
-
//
// Now, the permanent memory has been installed, we can call AllocatePages()
//
- Attributes = (
+ ResourceAttributes = (
EFI_RESOURCE_ATTRIBUTE_PRESENT |
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
@@ -91,70 +91,73 @@ MemoryPeim (
EFI_RESOURCE_ATTRIBUTE_TESTED
);
- // If it is not a standalone build we must reserved the space above the base address of the firmware volume
- if (!PcdGet32(PcdStandalone)) {
- // Check if firmware volume has not be copied at the top of DRAM then we must reserve the extra space
- // between the firmware and the top
- if (SystemMemoryTop != PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize)) {
- BuildResourceDescriptorHob (
- EFI_RESOURCE_SYSTEM_MEMORY,
- Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),
- PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize),
- SystemMemoryTop - (PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize))
- );
- }
-
- // Reserved the memory space occupied by the firmware volume
- BuildResourceDescriptorHob (
- EFI_RESOURCE_SYSTEM_MEMORY,
- Attributes & (~EFI_RESOURCE_ATTRIBUTE_PRESENT),
- (UINT32)PcdGet32 (PcdNormalFdBaseAddress),
- (UINT32)PcdGet32 (PcdNormalFdSize)
- );
- }
-
- // Check there is no overlap between UEFI and Fix Address Regions
- ASSERT (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize) <= UefiMemoryBase);
-
- // Reserved the UEFI Memory Region
+ // Reserved the memory space occupied by the firmware volume
BuildResourceDescriptorHob (
EFI_RESOURCE_SYSTEM_MEMORY,
- Attributes,
- UefiMemoryBase,
- UefiMemorySize
- );
-
- // Reserved the Fix Address Region
- BuildResourceDescriptorHob (
- EFI_RESOURCE_SYSTEM_MEMORY,
- Attributes,
+ ResourceAttributes,
PcdGet32 (PcdSystemMemoryBase),
- PcdGet32 (PcdSystemMemoryFixRegionSize)
+ PcdGet32 (PcdSystemMemorySize)
);
- // Reserved the memory between UEFI and Fix Address regions
- if (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize) != UefiMemoryBase) {
- BuildResourceDescriptorHob (
- EFI_RESOURCE_SYSTEM_MEMORY,
- Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),
- PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize),
- UefiMemoryBase - (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize))
- );
- }
-
- // If a platform has system memory extensions, it can declare those in this function
- Status = ArmPlatformGetAdditionalSystemMemory (&EfiMemoryMap);
- if (!EFI_ERROR(Status)) {
- // Install the EFI Memory Map
- for (Index = 0; EfiMemoryMap[Index].ResourceAttribute != 0; Index++) {
- BuildResourceDescriptorHob (
- EFI_RESOURCE_SYSTEM_MEMORY,
- EfiMemoryMap[Index].ResourceAttribute,
- EfiMemoryMap[Index].PhysicalStart,
- EfiMemoryMap[Index].NumberOfBytes
- );
+ SystemMemoryTop = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize);
+ FdTop = PcdGet32(PcdNormalFdBaseAddress) + PcdGet32(PcdNormalFdSize);
+
+ // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE
+ // core to overwrite this area we must mark the region with the attribute non-present
+ if ((PcdGet32 (PcdNormalFdBaseAddress) >= PcdGet32 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) {
+ Found = FALSE;
+
+ // Search for System Memory Hob that contains the firmware
+ NextHob.Raw = GetHobList ();
+ while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {
+ if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&
+ (PcdGet32(PcdNormalFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) &&
+ (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength))
+ {
+ ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute;
+ ResourceLength = NextHob.ResourceDescriptor->ResourceLength;
+ ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength;
+
+ if (PcdGet32(PcdNormalFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) {
+ if (SystemMemoryTop == FdTop) {
+ NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT;
+ } else {
+ // Create the System Memory HOB for the firmware with the non-present attribute
+ BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,
+ ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,
+ PcdGet32(PcdNormalFdBaseAddress),
+ PcdGet32(PcdNormalFdSize));
+
+ // Top of the FD is system memory available for UEFI
+ NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdNormalFdSize);
+ NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdNormalFdSize);
+ }
+ } else {
+ // Create the System Memory HOB for the firmware with the non-present attribute
+ BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,
+ ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,
+ PcdGet32(PcdNormalFdBaseAddress),
+ PcdGet32(PcdNormalFdSize));
+
+ // Update the HOB
+ NextHob.ResourceDescriptor->ResourceLength = PcdGet32(PcdNormalFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart;
+
+ // If there is some memory available on the top of the FD then create a HOB
+ if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) {
+ // Create the System Memory HOB for the remaining region (top of the FD)
+ BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,
+ ResourceAttributes,
+ FdTop,
+ ResourceTop - FdTop);
+ }
+ }
+ Found = TRUE;
+ break;
+ }
+ NextHob.Raw = GET_NEXT_HOB (NextHob);
}
- FreePool (EfiMemoryMap);
+
+ ASSERT(Found);
}
// Build Memory Allocation Hob