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 <sami.mujawar@arm.com>
This commit is contained in:
Sami Mujawar 2026-06-15 18:03:33 +01:00 committed by mergify[bot]
parent 2adf8dc56d
commit 2f91cf9045
3 changed files with 8 additions and 20 deletions

View file

@ -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
}
#

View file

@ -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 <Base.h>
#include <Library/ArmLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
@ -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;

View file

@ -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