]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg: kvmtool platform memory map
authorSami Mujawar <sami.mujawar@arm.com>
Fri, 2 Oct 2020 21:13:59 +0000 (22:13 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 16 Oct 2020 17:21:04 +0000 (17:21 +0000)
Kvmtool is a virtual machine manager that enables
hosting KVM guests. Kvmtool allows to vary the
hardware configuration of the virtual platform
it provides to the guest partition. It provides
the current hardware configuration to the firmware
by handing off a device tree containing the hardware
information.

This library parses the kvmtool provided device
tree and populates the system memory map for the
kvmtool virtual platform.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Ard Biesheuvel <Ard.Biesheuvel@arm.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c [new file with mode: 0644]
ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf [new file with mode: 0644]

diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c
new file mode 100644 (file)
index 0000000..63bb81e
--- /dev/null
@@ -0,0 +1,98 @@
+/** @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
diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf
new file mode 100644 (file)
index 0000000..a354e73
--- /dev/null
@@ -0,0 +1,42 @@
+## @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