--- /dev/null
+/** @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
+#include <PiPei.h>\r
+\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#include <Chipset/ArmV7.h>\r
+\r
+VOID\r
+BuildMemoryTypeInformationHob (\r
+ VOID\r
+ );\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
+/*++\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
+MemoryPeim (\r
+ IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\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
+\r
+ // Ensure PcdSystemMemorySize has been set\r
+ ASSERT (PcdGet32 (PcdSystemMemorySize) != 0);\r
+\r
+ SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)((UINT32)PcdGet32 (PcdSystemMemoryBase) + (UINT32)PcdGet32 (PcdSystemMemorySize));\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 (!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
+ 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
+ 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
+ }\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