]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/MemoryInitPei/MemoryInit.c
ArmPlatformPkg/MemoryInitPei: Generate a library from the PEI Module
[mirror_edk2.git] / ArmPlatformPkg / MemoryInitPei / MemoryInit.c
diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInit.c b/ArmPlatformPkg/MemoryInitPei/MemoryInit.c
deleted file mode 100644 (file)
index 3c7588f..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-/** @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
-*\r
-**/\r
-\r
-//\r
-// The package level header files this module uses\r
-//\r
-#include <PiPei.h>\r
-\r
-//\r
-// The protocols, PPI and GUID defintions for this module\r
-//\r
-#include <Ppi/MasterBootMode.h>\r
-#include <Ppi/BootInRecoveryMode.h>\r
-#include <Guid/MemoryTypeInformation.h>\r
-//\r
-// The Library classes this module consumes\r
-//\r
-#include <Library/DebugLib.h>\r
-#include <Library/PeimEntryPoint.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/HobLib.h>\r
-#include <Library/PeiServicesLib.h>\r
-#include <Library/ArmLib.h>\r
-#include <Library/IoLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/ArmPlatformLib.h>\r
-\r
-VOID\r
-InitMmu (\r
-  VOID\r
-  )\r
-{\r
-  ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable;\r
-  VOID                          *TranslationTableBase;\r
-  UINTN                         TranslationTableSize;\r
-\r
-  // Get Virtual Memory Map from the Platform Library\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
-}\r
-\r
-// May want to put this into a library so you only need the PCD settings if you are using the feature?\r
-VOID\r
-BuildMemoryTypeInformationHob (\r
-  VOID\r
-  )\r
-{\r
-  EFI_MEMORY_TYPE_INFORMATION   Info[10];\r
-\r
-  Info[0].Type          = EfiACPIReclaimMemory;\r
-  Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);\r
-  Info[1].Type          = EfiACPIMemoryNVS;\r
-  Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);\r
-  Info[2].Type          = EfiReservedMemoryType;\r
-  Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);\r
-  Info[3].Type          = EfiRuntimeServicesData;\r
-  Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);\r
-  Info[4].Type          = EfiRuntimeServicesCode;\r
-  Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);\r
-  Info[5].Type          = EfiBootServicesCode;\r
-  Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode);\r
-  Info[6].Type          = EfiBootServicesData;\r
-  Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData);\r
-  Info[7].Type          = EfiLoaderCode;\r
-  Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);\r
-  Info[8].Type          = EfiLoaderData;\r
-  Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);\r
-  \r
-  // Terminator for the list\r
-  Info[9].Type          = EfiMaxMemoryType;\r
-  Info[9].NumberOfPages = 0;\r
-\r
-  BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));\r
-}\r
-/*++\r
-\r
-Routine Description:\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
-Returns:\r
-\r
-  Status -  EFI_SUCCESS if the boot mode could be set\r
-\r
---*/\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeMemory (\r
-  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
-  IN CONST EFI_PEI_SERVICES     **PeiServices\r
-  )\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                                 UefiMemoryBase;\r
-  UINTN                                 UefiMemorySize;\r
-\r
-  DEBUG ((EFI_D_ERROR, "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
-\r
-  //\r
-  // Initialize the System Memory (DRAM)\r
-  //\r
-  if (FeaturePcdGet(PcdStandalone)) {\r
-    // In case of a standalone version, the DRAM is already initialized\r
-    ArmPlatformInitializeSystemMemory();\r
-  }\r
-\r
-  //\r
-  // Declare the UEFI memory to PEI\r
-  //\r
-  if (FeaturePcdGet(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
-  } 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
-  }\r
-  UefiMemorySize = FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
-  Status = PeiServicesInstallPeiMemory (UefiMemoryBase,UefiMemorySize);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Now, the permanent memory has been installed, we can call AllocatePages()\r
-  //\r
-  Attributes = (\r
-      EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
-      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
-      EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
-      EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
-      EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
-      EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\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 (!FeaturePcdGet(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 != FixedPcdGet32 (PcdNormalFdBaseAddress) + FixedPcdGet32 (PcdNormalFdSize)) {\r
-      BuildResourceDescriptorHob (\r
-          EFI_RESOURCE_SYSTEM_MEMORY,\r
-          Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),\r
-          FixedPcdGet32 (PcdNormalFdBaseAddress) + FixedPcdGet32 (PcdNormalFdSize),\r
-          SystemMemoryTop - (FixedPcdGet32 (PcdNormalFdBaseAddress) + FixedPcdGet32 (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)FixedPcdGet32 (PcdNormalFdBaseAddress),\r
-        (UINT32)FixedPcdGet32 (PcdNormalFdSize)\r
-    );\r
-  }\r
-\r
-  // Check there is no overlap between UEFI and Fix Address Regions\r
-  ASSERT (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemoryFixRegionSize) <= UefiMemoryBase);\r
-\r
-  // Reserved the UEFI Memory Region\r
-  BuildResourceDescriptorHob (\r
-      EFI_RESOURCE_SYSTEM_MEMORY,\r
-      Attributes,\r
-      UefiMemoryBase,\r
-      UefiMemorySize\r
-  );\r
-\r
-  // Reserved the Fix Address Region\r
-  BuildResourceDescriptorHob (\r
-      EFI_RESOURCE_SYSTEM_MEMORY,\r
-      Attributes,\r
-      FixedPcdGet32 (PcdSystemMemoryBase),\r
-      FixedPcdGet32 (PcdSystemMemoryFixRegionSize)\r
-  );\r
-\r
-  // Reserved the memory between UEFI and Fix Address regions\r
-  if (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemoryFixRegionSize) != UefiMemoryBase) {\r
-    BuildResourceDescriptorHob (\r
-        EFI_RESOURCE_SYSTEM_MEMORY,\r
-        Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),\r
-        FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemoryFixRegionSize),\r
-        UefiMemoryBase - (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (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
-    }\r
-    FreePool (EfiMemoryMap);\r
-  }\r
-\r
-  // Build Memory Allocation Hob\r
-  InitMmu ();\r
-\r
-  if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
-    // Optional feature that helps prevent EFI memory map fragmentation.\r
-    BuildMemoryTypeInformationHob ();\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r