From 2f91cf9045bf43a24c99c8df799a92841eb9ad28 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Mon, 15 Jun 2026 18:03:33 +0100 Subject: [PATCH] ArmVirtPkg: Refactor memory map configuration for Kvmtool Guest VM Refactor the memory mapping configuration for Kvmtool Guest VM to only setup the memory map for the System Memory, FV and the Serial Port. The memory mappings for he remaining devices are expected to be configured by the respective drivers, this could be done as part of the DXE drivers itself or using a Probe Library that adds the device memory regions to the memory map. The only special cases that remain are the System Memory, FV and the Serial Port for which the memory mappings are created by the KvmtoolVirtMemInfoLib. The memory mapping for the Serial port is added as it is utilised for logging before the DXE driver is loaded. Signed-off-by: Sami Mujawar --- ArmVirtPkg/ArmVirtKvmTool.dsc | 1 + .../KvmtoolVirtMemInfoLib.c | 24 +++++-------------- .../KvmtoolVirtMemInfoLib.inf | 3 +-- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 91411b5264..b91a64a0e0 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -227,6 +227,7 @@ HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf + NULL|ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf } # diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c index 79412897f2..e5612bb75d 100644 --- a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.c @@ -1,7 +1,7 @@ /** @file Kvmtool virtual memory map library. - Copyright (c) 2018 - 2020, ARM Limited. All rights reserved. + Copyright (c) 2018 - 2026, ARM Limited. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -9,8 +9,6 @@ #include #include -#include -#include #include #include @@ -37,12 +35,9 @@ ArmVirtGetMemoryMap ( { 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 ( @@ -66,20 +61,13 @@ ArmVirtGetMemoryMap ( 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); + // Map the UART + ASSERT (IS_ALIGNED (PcdGet64 (PcdSerialRegisterBase), EFI_PAGE_SIZE)); + VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdSerialRegisterBase); + VirtualMemoryTable[Idx].VirtualBase = PcdGet64 (PcdSerialRegisterBase); + VirtualMemoryTable[Idx].Length = EFI_PAGE_SIZE; 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; diff --git a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf index a354e734ab..16b3564e48 100644 --- a/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf +++ b/ArmVirtPkg/Library/KvmtoolVirtMemInfoLib/KvmtoolVirtMemInfoLib.inf @@ -27,8 +27,6 @@ [LibraryClasses] ArmLib - BaseLib - BaseMemoryLib DebugLib MemoryAllocationLib PcdLib @@ -37,6 +35,7 @@ gArmTokenSpaceGuid.PcdFvBaseAddress gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase [FixedPcd] gArmTokenSpaceGuid.PcdFvSize