summaryrefslogtreecommitdiffstats
path: root/ArmVirtPkg
diff options
context:
space:
mode:
authorSami Mujawar <sami.mujawar@arm.com>2020-10-02 22:13:59 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-10-16 17:21:04 +0000
commit4c5e875ec140b2a01099a8b37ca1a3ca43f57201 (patch)
tree7f2fd68fe2c479179c66c2b6ddbe3d5be44264a1 /ArmVirtPkg
parent39d76b25965d2cc55e32845e586ee5611b75895a (diff)
downloadedk2-4c5e875ec140b2a01099a8b37ca1a3ca43f57201.tar.gz
edk2-4c5e875ec140b2a01099a8b37ca1a3ca43f57201.tar.bz2
edk2-4c5e875ec140b2a01099a8b37ca1a3ca43f57201.zip
ArmVirtPkg: kvmtool platform memory map
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>
Diffstat (limited to 'ArmVirtPkg')
-rw-r--r--ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c98
-rw-r--r--ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf42
2 files changed, 140 insertions, 0 deletions
diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c
new file mode 100644
index 0000000000..63bb81ef91
--- /dev/null
+++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c
@@ -0,0 +1,98 @@
+/** @file
+ Kvmtool virtual memory map library.
+
+ Copyright (c) 2018 - 2020, ARM Limited. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/ArmLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+// Number of Virtual Memory Map Descriptors
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
+
+/**
+ Return the Virtual Memory Map of your platform
+
+ This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
+ on your platform.
+
+ @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
+ describing a Physical-to-Virtual Memory
+ mapping. This array must be ended by a
+ zero-filled entry. The allocated memory
+ will not be freed.
+
+**/
+VOID
+ArmVirtGetMemoryMap (
+ OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
+ )
+{
+ ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
+ UINTN Idx;
+ EFI_PHYSICAL_ADDRESS TopOfAddressSpace;
+
+ ASSERT (VirtualMemoryMap != NULL);
+
+ TopOfAddressSpace = LShiftU64 (1ULL, ArmGetPhysicalAddressBits ());
+
+ VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)
+ AllocatePages (
+ EFI_SIZE_TO_PAGES (
+ sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
+ MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
+ )
+ );
+ if (VirtualMemoryTable == NULL) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Error: Failed to Allocate Pages\n",
+ __FUNCTION__
+ ));
+ return;
+ }
+
+ Idx = 0;
+ // System DRAM
+ VirtualMemoryTable[Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
+ VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;
+ VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemorySize);
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+
+ // Peripheral space before DRAM
+ VirtualMemoryTable[++Idx].PhysicalBase = 0x0;
+ VirtualMemoryTable[Idx].VirtualBase = 0x0;
+ VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemoryBase);
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+ // Peripheral space after DRAM
+ VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase) +
+ PcdGet64 (PcdSystemMemorySize);
+ VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;
+ VirtualMemoryTable[Idx].Length = TopOfAddressSpace -
+ VirtualMemoryTable[Idx].PhysicalBase;
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+ // Map the FV region as normal executable memory
+ VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
+ VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;
+ VirtualMemoryTable[Idx].Length = FixedPcdGet32 (PcdFvSize);
+ VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+
+ // End of Table
+ VirtualMemoryTable[++Idx].PhysicalBase = 0;
+ VirtualMemoryTable[Idx].VirtualBase = 0;
+ VirtualMemoryTable[Idx].Length = 0;
+ VirtualMemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
+
+ ASSERT((Idx + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
+
+ *VirtualMemoryMap = VirtualMemoryTable;
+}
diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf
new file mode 100644
index 0000000000..a354e734ab
--- /dev/null
+++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf
@@ -0,0 +1,42 @@
+## @file
+# Kvmtool virtual memory map library.
+#
+# Copyright (c) 2018, ARM Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = KvmtoolVirtMemInfoLib
+ FILE_GUID = B752E953-394F-462C-811C-F8BE35C8C071
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmVirtMemInfoLib
+
+[Sources]
+ KvmtoolVirtMemInfoLib.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ ArmVirtPkg/ArmVirtPkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ ArmLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ MemoryAllocationLib
+ PcdLib
+
+[Pcd]
+ gArmTokenSpaceGuid.PcdFvBaseAddress
+ gArmTokenSpaceGuid.PcdSystemMemoryBase
+ gArmTokenSpaceGuid.PcdSystemMemorySize
+
+[FixedPcd]
+ gArmTokenSpaceGuid.PcdFvSize