ArmPlatformPkg: Change the memory model for the ARM Platform components

In the former memory model, the UEFI firmware was expected to be located
at the top of the system memory. Stacks & Pi memory regions were set below
the firmware.
On some platform, the UEFI firmware could be shadowed by the ROM firmware
(case of the BeagleBoard) and in some cases the firmware is copied at the
beginning of the system memory.

With this new memory model, stack and Pi/DXE memory regions are set at the
top of the system memory wherever the UEFI firmware is located in the memory
map.
Because DXE core does not support shadowed firmwares, the system memory covered
by the UEFI firmware is marked as 'Non Present' to avoid to be overlapped by
DXE allocations.



git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11992 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
oliviermartin
2011-07-06 16:27:21 +00:00
parent a6caee65ac
commit d269095b71
16 changed files with 413 additions and 359 deletions

View File

@@ -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))
);
}
SystemMemoryTop = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize);
FdTop = PcdGet32(PcdNormalFdBaseAddress) + PcdGet32(PcdNormalFdSize);
// 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
);
// 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