diff options
author | Ard Biesheuvel <ardb@kernel.org> | 2022-09-25 16:53:27 +0200 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2022-10-26 17:28:39 +0000 |
commit | 7136d5491e225c57f1d73e4a1b7ac27ed656ff72 (patch) | |
tree | 16f18103d73b26d7dfc6959afe8a83e23ae5b80a /ArmVirtPkg/Library | |
parent | fead469a3b3174fbf9ec2df97f54f3ebcc786ca5 (diff) | |
download | edk2-7136d5491e225c57f1d73e4a1b7ac27ed656ff72.tar.gz edk2-7136d5491e225c57f1d73e4a1b7ac27ed656ff72.tar.bz2 edk2-7136d5491e225c57f1d73e4a1b7ac27ed656ff72.zip |
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>
Diffstat (limited to 'ArmVirtPkg/Library')
6 files changed, 71 insertions, 22 deletions
diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c index 98d90ad420..72e5c65af7 100644 --- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c +++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c @@ -52,10 +52,19 @@ MemoryPeim ( {
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
UINT64 SystemMemoryTop;
+ UINT64 SystemMemorySize;
+ VOID *Hob;
// Ensure PcdSystemMemorySize has been set
ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
+ SystemMemorySize = PcdGet64 (PcdSystemMemorySize);
+
+ Hob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);
+ if (Hob != NULL) {
+ SystemMemorySize = *(UINT64 *)GET_GUID_HOB_DATA (Hob);
+ }
+
//
// Now, the permanent memory has been installed, we can call AllocatePages()
//
@@ -66,8 +75,7 @@ MemoryPeim ( EFI_RESOURCE_ATTRIBUTE_TESTED
);
- SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) +
- PcdGet64 (PcdSystemMemorySize);
+ SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) + SystemMemorySize;
if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {
BuildResourceDescriptorHob (
@@ -87,7 +95,7 @@ MemoryPeim ( EFI_RESOURCE_SYSTEM_MEMORY,
ResourceAttributes,
PcdGet64 (PcdSystemMemoryBase),
- PcdGet64 (PcdSystemMemorySize)
+ SystemMemorySize
);
}
diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf index 21327f79f4..48d9c66b22 100644 --- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf +++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf @@ -34,6 +34,7 @@ CacheMaintenanceLib
[Guids]
+ gArmVirtSystemMemorySizeGuid
gEfiMemoryTypeInformationGuid
[FeaturePcd]
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c index cf569bed99..9cf43f06c0 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c @@ -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
@@ -25,6 +27,28 @@ #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
This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
@@ -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 ((
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf index 7150de6c10..6acad8bbd7 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf @@ -14,6 +14,7 @@ MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = ArmVirtMemInfoLib
+ CONSTRUCTOR = QemuVirtMemInfoLibConstructor
[Sources]
QemuVirtMemInfoLib.c
@@ -30,7 +31,9 @@ BaseMemoryLib
DebugLib
MemoryAllocationLib
- PcdLib
+
+[Guids]
+ gArmVirtSystemMemorySizeGuid
[Pcd]
gArmTokenSpaceGuid.PcdFvBaseAddress
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf index 7ecf6dfbb7..f045e39a41 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf @@ -32,16 +32,16 @@ BaseMemoryLib
DebugLib
FdtLib
- PcdLib
MemoryAllocationLib
-[Pcd]
+[Guids]
+ gArmVirtSystemMemorySizeGuid
+
+[FixedPcd]
gArmTokenSpaceGuid.PcdFdBaseAddress
gArmTokenSpaceGuid.PcdFvBaseAddress
gArmTokenSpaceGuid.PcdSystemMemoryBase
gArmTokenSpaceGuid.PcdSystemMemorySize
-
-[FixedPcd]
gArmTokenSpaceGuid.PcdFdSize
gArmTokenSpaceGuid.PcdFvSize
gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c index 33d3597d57..c47ab82966 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c @@ -6,9 +6,10 @@ **/
-#include <Base.h>
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
+#include <Library/HobLib.h>
#include <libfdt.h>
RETURN_STATUS
@@ -17,14 +18,14 @@ QemuVirtMemInfoPeiLibConstructor ( VOID
)
{
- VOID *DeviceTreeBase;
- INT32 Node, Prev;
- UINT64 NewBase, CurBase;
- UINT64 NewSize, CurSize;
- CONST CHAR8 *Type;
- INT32 Len;
- CONST UINT64 *RegProp;
- RETURN_STATUS PcdStatus;
+ VOID *DeviceTreeBase;
+ INT32 Node, Prev;
+ UINT64 NewBase, CurBase;
+ UINT64 NewSize, CurSize;
+ CONST CHAR8 *Type;
+ INT32 Len;
+ CONST UINT64 *RegProp;
+ VOID *Hob;
NewBase = 0;
NewSize = 0;
@@ -86,8 +87,13 @@ QemuVirtMemInfoPeiLibConstructor ( // Make sure the start of DRAM matches our expectation
//
ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);
- PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);
- ASSERT_RETURN_ERROR (PcdStatus);
+
+ Hob = BuildGuidDataHob (
+ &gArmVirtSystemMemorySizeGuid,
+ &NewSize,
+ sizeof NewSize
+ );
+ ASSERT (Hob != NULL);
//
// We need to make sure that the machine we are running on has at least
|