)\r
{\r
EFI_STATUS Status;\r
+ UINTN SystemMemoryBase;\r
UINTN SystemMemoryTop;\r
+ UINTN FdBase;\r
+ UINTN FdTop;\r
UINTN UefiMemoryBase;\r
\r
DEBUG ((EFI_D_ERROR, "Memory Init PEIM Loaded\n"));\r
// Ensure PcdSystemMemorySize has been set\r
ASSERT (FixedPcdGet32 (PcdSystemMemorySize) != 0);\r
\r
- SystemMemoryTop = (UINTN)FixedPcdGet32 (PcdSystemMemoryBase) + (UINTN)FixedPcdGet32 (PcdSystemMemorySize);\r
+ SystemMemoryBase = (UINTN)FixedPcdGet32 (PcdSystemMemoryBase);\r
+ SystemMemoryTop = SystemMemoryBase + (UINTN)FixedPcdGet32 (PcdSystemMemorySize);\r
+ FdBase = (UINTN)PcdGet32 (PcdFdBaseAddress);\r
+ FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize);\r
\r
//\r
// Initialize the System Memory (DRAM)\r
//\r
- if (PcdGet32 (PcdStandalone)) {\r
- // In case of a standalone version, the DRAM is already initialized\r
- ArmPlatformInitializeSystemMemory();\r
+ if (!FeaturePcdGet (PcdSystemMemoryInitializeInSec)) {\r
+ // In case the DRAM has not been initialized by the secure firmware\r
+ ArmPlatformInitializeSystemMemory ();\r
}\r
\r
//\r
// Declare the UEFI memory to PEI\r
//\r
- if (PcdGet32 (PcdStandalone)) {\r
- // In case of standalone UEFI, we set the UEFI memory region at the top of the DRAM\r
- UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+\r
+ // In case the firmware has been shadowed in the System Memory\r
+ if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) {\r
+ // Check if there is enough space between the top of the system memory and the top of the\r
+ // firmware to place the UEFI memory (for PEI & DXE phases)\r
+ if (SystemMemoryTop - FdTop >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) {\r
+ UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+ } else {\r
+ // Check there is enough space for the UEFI memory\r
+ ASSERT (SystemMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) <= FdBase);\r
+\r
+ UefiMemoryBase = FdBase - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+ }\r
} else {\r
- // In case of a non standalone UEFI, we set the UEFI memory below the Firmware Volume\r
- UefiMemoryBase = FixedPcdGet32 (PcdNormalFdBaseAddress) - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+ // Check the Firmware does not overlapped with the system memory\r
+ ASSERT ((FdBase < SystemMemoryBase) || (FdBase >= SystemMemoryTop));\r
+ ASSERT ((FdTop <= SystemMemoryBase) || (FdTop > SystemMemoryTop));\r
+\r
+ UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
}\r
- Status = PeiServicesInstallPeiMemory (UefiMemoryBase,FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
+\r
+ Status = PeiServicesInstallPeiMemory (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
ASSERT_EFI_ERROR (Status);\r
\r
// Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r