/** @file\r
*\r
-* Copyright (c) 2011, ARM Limited. All rights reserved.\r
+* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
*\r
* This program and the accompanying materials\r
* are licensed and made available under the terms and conditions of the BSD License\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/PcdLib.h>\r
\r
-#include <Chipset/ArmV7.h>\r
-\r
VOID\r
BuildMemoryTypeInformationHob (\r
VOID\r
ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r
VOID *TranslationTableBase;\r
UINTN TranslationTableSize;\r
+ RETURN_STATUS Status;\r
\r
// Get Virtual Memory Map from the Platform Library\r
- ArmPlatformGetVirtualMemoryMap(&MemoryTable);\r
+ ArmPlatformGetVirtualMemoryMap (&MemoryTable);\r
\r
//Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r
// DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r
- ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
+ Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));\r
+ }\r
}\r
\r
/*++\r
IN UINT64 UefiMemorySize\r
)\r
{\r
- EFI_STATUS Status;\r
- EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
- ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR* EfiMemoryMap;\r
- UINTN Index;\r
- EFI_PHYSICAL_ADDRESS SystemMemoryTop;\r
+ EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r
+ UINT64 ResourceLength;\r
+ EFI_PEI_HOB_POINTERS NextHob;\r
+ EFI_PHYSICAL_ADDRESS FdTop;\r
+ EFI_PHYSICAL_ADDRESS SystemMemoryTop;\r
+ EFI_PHYSICAL_ADDRESS ResourceTop;\r
+ BOOLEAN Found;\r
\r
// Ensure PcdSystemMemorySize has been set\r
- ASSERT (PcdGet32 (PcdSystemMemorySize) != 0);\r
-\r
- SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)((UINT32)PcdGet32 (PcdSystemMemoryBase) + (UINT32)PcdGet32 (PcdSystemMemorySize));\r
+ ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
\r
//\r
// Now, the permanent memory has been installed, we can call AllocatePages()\r
//\r
- Attributes = (\r
+ ResourceAttributes = (\r
EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
EFI_RESOURCE_ATTRIBUTE_TESTED\r
);\r
\r
- // If it is not a standalone build we must reserved the space above the base address of the firmware volume\r
- if (!PcdGet32(PcdStandalone)) {\r
- // Check if firmware volume has not be copied at the top of DRAM then we must reserve the extra space\r
- // between the firmware and the top\r
- if (SystemMemoryTop != PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize)) {\r
- BuildResourceDescriptorHob (\r
- EFI_RESOURCE_SYSTEM_MEMORY,\r
- Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),\r
- PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize),\r
- SystemMemoryTop - (PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize))\r
- );\r
- }\r
-\r
- // Reserved the memory space occupied by the firmware volume\r
- BuildResourceDescriptorHob (\r
- EFI_RESOURCE_SYSTEM_MEMORY,\r
- Attributes & (~EFI_RESOURCE_ATTRIBUTE_PRESENT),\r
- (UINT32)PcdGet32 (PcdNormalFdBaseAddress),\r
- (UINT32)PcdGet32 (PcdNormalFdSize)\r
- );\r
- }\r
-\r
- // Check there is no overlap between UEFI and Fix Address Regions\r
- ASSERT (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize) <= UefiMemoryBase);\r
-\r
- // Reserved the UEFI Memory Region\r
+ // Reserved the memory space occupied by the firmware volume\r
BuildResourceDescriptorHob (\r
EFI_RESOURCE_SYSTEM_MEMORY,\r
- Attributes,\r
- UefiMemoryBase,\r
- UefiMemorySize\r
+ ResourceAttributes,\r
+ PcdGet64 (PcdSystemMemoryBase),\r
+ PcdGet64 (PcdSystemMemorySize)\r
);\r
\r
- // Reserved the Fix Address Region\r
- BuildResourceDescriptorHob (\r
- EFI_RESOURCE_SYSTEM_MEMORY,\r
- Attributes,\r
- PcdGet32 (PcdSystemMemoryBase),\r
- PcdGet32 (PcdSystemMemoryFixRegionSize)\r
- );\r
-\r
- // Reserved the memory between UEFI and Fix Address regions\r
- if (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize) != UefiMemoryBase) {\r
- BuildResourceDescriptorHob (\r
- EFI_RESOURCE_SYSTEM_MEMORY,\r
- Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),\r
- PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize),\r
- UefiMemoryBase - (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize))\r
- );\r
- }\r
-\r
- // If a platform has system memory extensions, it can declare those in this function\r
- Status = ArmPlatformGetAdditionalSystemMemory (&EfiMemoryMap);\r
- if (!EFI_ERROR(Status)) {\r
- // Install the EFI Memory Map\r
- for (Index = 0; EfiMemoryMap[Index].ResourceAttribute != 0; Index++) {\r
- BuildResourceDescriptorHob (\r
- EFI_RESOURCE_SYSTEM_MEMORY,\r
- EfiMemoryMap[Index].ResourceAttribute,\r
- EfiMemoryMap[Index].PhysicalStart,\r
- EfiMemoryMap[Index].NumberOfBytes\r
- );\r
+ SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize);\r
+ FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize);\r
+\r
+ // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE\r
+ // core to overwrite this area we must mark the region with the attribute non-present\r
+ if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) {\r
+ Found = FALSE;\r
+\r
+ // Search for System Memory Hob that contains the firmware\r
+ NextHob.Raw = GetHobList ();\r
+ while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r
+ if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&\r
+ (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) &&\r
+ (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength))\r
+ {\r
+ ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute;\r
+ ResourceLength = NextHob.ResourceDescriptor->ResourceLength;\r
+ ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength;\r
+\r
+ if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) {\r
+ if (SystemMemoryTop == FdTop) {\r
+ NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT;\r
+ } else {\r
+ // Create the System Memory HOB for the firmware with the non-present attribute\r
+ BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
+ ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r
+ PcdGet64 (PcdFdBaseAddress),\r
+ PcdGet32 (PcdFdSize));\r
+\r
+ // Top of the FD is system memory available for UEFI\r
+ NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize);\r
+ NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize);\r
+ }\r
+ } else {\r
+ // Create the System Memory HOB for the firmware with the non-present attribute\r
+ BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
+ ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r
+ PcdGet64 (PcdFdBaseAddress),\r
+ PcdGet32 (PcdFdSize));\r
+\r
+ // Update the HOB\r
+ NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart;\r
+\r
+ // If there is some memory available on the top of the FD then create a HOB\r
+ if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) {\r
+ // Create the System Memory HOB for the remaining region (top of the FD)\r
+ BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
+ ResourceAttributes,\r
+ FdTop,\r
+ ResourceTop - FdTop);\r
+ }\r
+ }\r
+ Found = TRUE;\r
+ break;\r
+ }\r
+ NextHob.Raw = GET_NEXT_HOB (NextHob);\r
}\r
- FreePool (EfiMemoryMap);\r
+\r
+ ASSERT(Found);\r
}\r
\r
// Build Memory Allocation Hob\r