--- /dev/null
+/** @file\r
+ Kvmtool virtual memory map library.\r
+\r
+ Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.\r
+\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+// Number of Virtual Memory Map Descriptors\r
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5\r
+\r
+/**\r
+ Return the Virtual Memory Map of your platform\r
+\r
+ This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU\r
+ on your platform.\r
+\r
+ @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR\r
+ describing a Physical-to-Virtual Memory\r
+ mapping. This array must be ended by a\r
+ zero-filled entry. The allocated memory\r
+ will not be freed.\r
+\r
+**/\r
+VOID\r
+ArmVirtGetMemoryMap (\r
+ OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap\r
+ )\r
+{\r
+ ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r
+ UINTN Idx;\r
+ EFI_PHYSICAL_ADDRESS TopOfAddressSpace;\r
+\r
+ ASSERT (VirtualMemoryMap != NULL);\r
+\r
+ TopOfAddressSpace = LShiftU64 (1ULL, ArmGetPhysicalAddressBits ());\r
+\r
+ VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)\r
+ AllocatePages (\r
+ EFI_SIZE_TO_PAGES (\r
+ sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *\r
+ MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS\r
+ )\r
+ );\r
+ if (VirtualMemoryTable == NULL) {\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: Error: Failed to Allocate Pages\n",\r
+ __FUNCTION__\r
+ ));\r
+ return;\r
+ }\r
+\r
+ Idx = 0;\r
+ // System DRAM\r
+ VirtualMemoryTable[Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r
+ VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;\r
+ VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemorySize);\r
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r
+\r
+ // Peripheral space before DRAM\r
+ VirtualMemoryTable[++Idx].PhysicalBase = 0x0;\r
+ VirtualMemoryTable[Idx].VirtualBase = 0x0;\r
+ VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemoryBase);\r
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
+\r
+ // Peripheral space after DRAM\r
+ VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase) +\r
+ PcdGet64 (PcdSystemMemorySize);\r
+ VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;\r
+ VirtualMemoryTable[Idx].Length = TopOfAddressSpace -\r
+ VirtualMemoryTable[Idx].PhysicalBase;\r
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
+\r
+ // Map the FV region as normal executable memory\r
+ VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdFvBaseAddress);\r
+ VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;\r
+ VirtualMemoryTable[Idx].Length = FixedPcdGet32 (PcdFvSize);\r
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r
+\r
+ // End of Table\r
+ VirtualMemoryTable[++Idx].PhysicalBase = 0;\r
+ VirtualMemoryTable[Idx].VirtualBase = 0;\r
+ VirtualMemoryTable[Idx].Length = 0;\r
+ VirtualMemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;\r
+\r
+ ASSERT((Idx + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);\r
+\r
+ *VirtualMemoryMap = VirtualMemoryTable;\r
+}\r
--- /dev/null
+## @file\r
+# Kvmtool virtual memory map library.\r
+#\r
+# Copyright (c) 2018, ARM Limited. All rights reserved.\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x0001001B\r
+ BASE_NAME = KvmtoolVirtMemInfoLib\r
+ FILE_GUID = B752E953-394F-462C-811C-F8BE35C8C071\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = ArmVirtMemInfoLib\r
+\r
+[Sources]\r
+ KvmtoolVirtMemInfoLib.c\r
+\r
+[Packages]\r
+ ArmPkg/ArmPkg.dec\r
+ ArmVirtPkg/ArmVirtPkg.dec\r
+ EmbeddedPkg/EmbeddedPkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+ ArmLib\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ MemoryAllocationLib\r
+ PcdLib\r
+\r
+[Pcd]\r
+ gArmTokenSpaceGuid.PcdFvBaseAddress\r
+ gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+ gArmTokenSpaceGuid.PcdSystemMemorySize\r
+\r
+[FixedPcd]\r
+ gArmTokenSpaceGuid.PcdFvSize\r