ArmVirtPkg/QemuVirtMemInfoLib: use HOB not PCD to record the memory size

Due to the way we inherited the formerly fixed PCDs to describe the
system memory base and size from ArmPlatformPkg, we ended up with a
MemoryInit PEIM that relies on dynamic PCDs to communicate the size of
system memory between the constructor of one of its library dependencies
and the core module. This is unnecessary, and forces us to incorporate
the PCD PEIM as well, for no good reason. So instead, let's use a HOB.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
Ard Biesheuvel
2022-09-25 16:53:27 +02:00
committed by mergify[bot]
parent fead469a3b
commit 7136d5491e
8 changed files with 75 additions and 25 deletions

View File

@@ -6,10 +6,12 @@
**/
#include <Base.h>
#include <Uefi.h>
#include <Pi/PiMultiPhase.h>
#include <Library/ArmLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/MemoryAllocationLib.h>
// Number of Virtual Memory Map Descriptors
@@ -24,6 +26,28 @@
#define MACH_VIRT_PERIPH_BASE 0x08000000
#define MACH_VIRT_PERIPH_SIZE SIZE_128MB
/**
Default library constructur that obtains the memory size from a PCD.
@return Always returns RETURN_SUCCESS
**/
RETURN_STATUS
EFIAPI
QemuVirtMemInfoLibConstructor (
VOID
)
{
UINT64 Size;
VOID *Hob;
Size = PcdGet64 (PcdSystemMemorySize);
Hob = BuildGuidDataHob (&gArmVirtSystemMemorySizeGuid, &Size, sizeof Size);
ASSERT (Hob != NULL);
return RETURN_SUCCESS;
}
/**
Return the Virtual Memory Map of your platform
@@ -43,9 +67,16 @@ ArmVirtGetMemoryMap (
)
{
ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
VOID *MemorySizeHob;
ASSERT (VirtualMemoryMap != NULL);
MemorySizeHob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);
ASSERT (MemorySizeHob != NULL);
if (MemorySizeHob == NULL) {
return;
}
VirtualMemoryTable = AllocatePool (
sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
@@ -59,7 +90,7 @@ ArmVirtGetMemoryMap (
// System DRAM
VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;
VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);
VirtualMemoryTable[0].Length = *(UINT64 *)GET_GUID_HOB_DATA (MemorySizeHob);
VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
DEBUG ((