]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c
BaseTools/Capsule: Do not support -o with --dump-info
[mirror_edk2.git] / ArmPlatformPkg / MemoryInitPei / MemoryInitPeim.c
old mode 100755 (executable)
new mode 100644 (file)
index d745357..389a2e6
@@ -1,14 +1,14 @@
 /** @file\r
 *\r
 *  Copyright (c) 2011, 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
-*  which accompanies this distribution.  The full text of the license may be found at        \r
-*  http://opensource.org/licenses/bsd-license.php                                            \r
 *\r
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 *\r
 **/\r
 \r
@@ -63,7 +63,7 @@ BuildMemoryTypeInformationHob (
   Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);\r
   Info[8].Type          = EfiLoaderData;\r
   Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);\r
-  \r
+\r
   // Terminator for the list\r
   Info[9].Type          = EfiMaxMemoryType;\r
   Info[9].NumberOfPages = 0;\r
@@ -75,13 +75,13 @@ BuildMemoryTypeInformationHob (
 \r
 Routine Description:\r
 \r
-  \r
+\r
 \r
 Arguments:\r
 \r
   FileHandle  - Handle of the file being invoked.\r
   PeiServices - Describes the list of possible PEI Services.\r
-    \r
+\r
 Returns:\r
 \r
   Status -  EFI_SUCCESS if the boot mode could be set\r
@@ -95,39 +95,51 @@ InitializeMemory (
   )\r
 {\r
   EFI_STATUS                            Status;\r
-  EFI_RESOURCE_ATTRIBUTE_TYPE           Attributes;\r
-  ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR*  EfiMemoryMap;\r
-  UINTN                                 Index;\r
-  UINTN                                 SystemMemoryTop;\r
+  UINTN                                 SystemMemoryBase;\r
+  UINT64                                SystemMemoryTop;\r
+  UINTN                                 FdBase;\r
+  UINTN                                 FdTop;\r
   UINTN                                 UefiMemoryBase;\r
-  UINTN                                 UefiMemorySize;\r
 \r
-  DEBUG ((EFI_D_ERROR, "Memory Init PEIM Loaded\n"));\r
+  DEBUG ((EFI_D_LOAD | EFI_D_INFO, "Memory Init PEIM Loaded\n"));\r
 \r
   // Ensure PcdSystemMemorySize has been set\r
-  ASSERT (FixedPcdGet32 (PcdSystemMemorySize) != 0);\r
-\r
-  SystemMemoryTop = (UINTN)FixedPcdGet32 (PcdSystemMemoryBase) + (UINTN)FixedPcdGet32 (PcdSystemMemorySize);\r
+  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
+  ASSERT (PcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ADDRESS);\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
+  SystemMemoryBase = (UINTN)PcdGet64 (PcdSystemMemoryBase);\r
+  SystemMemoryTop = SystemMemoryBase + PcdGet64 (PcdSystemMemorySize);\r
+  if (SystemMemoryTop - 1 > MAX_ADDRESS) {\r
+    SystemMemoryTop = (UINT64)MAX_ADDRESS + 1;\r
   }\r
+  FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress);\r
+  FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize);\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