]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c
ArmPlatformPkg: Change the memory model for the ARM Platform components
[mirror_edk2.git] / ArmPlatformPkg / MemoryInitPei / MemoryInitPeim.c
index f4c27c57505a9b62c51ffc7044034ae5681f15dc..3559e08862b3ee7ec64c5ee1a706d69d5687c3a3 100755 (executable)
@@ -95,7 +95,10 @@ InitializeMemory (
   )\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
@@ -103,27 +106,44 @@ InitializeMemory (
   // 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 (PcdNormalFdBaseAddress);\r
+  FdTop = FdBase + (UINTN)PcdGet32 (PcdNormalFdSize);\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