]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg/QemuVirtMemInfoLib: use HOB not PCD to record the memory size
authorArd Biesheuvel <ardb@kernel.org>
Sun, 25 Sep 2022 14:53:27 +0000 (16:53 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 26 Oct 2022 17:28:39 +0000 (17:28 +0000)
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>
ArmVirtPkg/ArmVirtPkg.dec
ArmVirtPkg/ArmVirtQemu.dsc
ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c
ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf
ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf
ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c

index 4e165f6cd8452458bce5ac93495c1312e8d2150d..89d21ec3a364ee7ee941dbf0d44e7654867778da 100644 (file)
@@ -32,6 +32,7 @@
   gArmVirtTokenSpaceGuid = { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }\r
   gEarlyPL011BaseAddressGuid       = { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x80, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }\r
   gEarly16550UartBaseAddressGuid   = { 0xea67ca3e, 0x1f54, 0x436b, { 0x97, 0x88, 0xd4, 0xeb, 0x29, 0xc3, 0x42, 0x67 } }\r
+  gArmVirtSystemMemorySizeGuid     = { 0x504eccb9, 0x1bf0, 0x4420, { 0x86, 0x5d, 0xdc, 0x66, 0x06, 0xd4, 0x13, 0xbf } }\r
 \r
   gArmVirtVariableGuid   = { 0x50bea1e5, 0xa2c5, 0x46e9, { 0x9b, 0x3a, 0x59, 0x59, 0x65, 0x16, 0xb0, 0x0a } }\r
 \r
index d9c43e294c6ec62f9a0ebb5f47701da36e873bf5..e3686c7ee35414c68e9ac41462df99e8889b06fd 100644 (file)
   # Shadowing PEI modules is absolutely pointless when the NOR flash is emulated\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot|FALSE\r
 \r
+  # System Memory Size -- 128 MB initially, actual size will be fetched from DT\r
+  gArmTokenSpaceGuid.PcdSystemMemorySize|0x8000000\r
+\r
 [PcdsFixedAtBuild.AARCH64]\r
   # Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry point,\r
   # if the entry point version is >= 3.0. AARCH64 OSes cannot assume the\r
   #  enumeration to complete before installing ACPI tables.\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE\r
 \r
-  # System Memory Size -- 1 MB initially, actual size will be fetched from DT\r
-  gArmTokenSpaceGuid.PcdSystemMemorySize|0x00100000\r
-\r
   gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0\r
   gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0\r
   gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0\r
index 98d90ad4200db9405c311ac3959923b9fd9b083c..72e5c65af79e98c1cb9b69fdd4757b3f820e700d 100644 (file)
@@ -52,10 +52,19 @@ MemoryPeim (
 {\r
   EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;\r
   UINT64                       SystemMemoryTop;\r
+  UINT64                       SystemMemorySize;\r
+  VOID                         *Hob;\r
 \r
   // Ensure PcdSystemMemorySize has been set\r
   ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
 \r
+  SystemMemorySize = PcdGet64 (PcdSystemMemorySize);\r
+\r
+  Hob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);\r
+  if (Hob != NULL) {\r
+    SystemMemorySize = *(UINT64 *)GET_GUID_HOB_DATA (Hob);\r
+  }\r
+\r
   //\r
   // Now, the permanent memory has been installed, we can call AllocatePages()\r
   //\r
@@ -66,8 +75,7 @@ MemoryPeim (
                         EFI_RESOURCE_ATTRIBUTE_TESTED\r
                         );\r
 \r
-  SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) +\r
-                    PcdGet64 (PcdSystemMemorySize);\r
+  SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) + SystemMemorySize;\r
 \r
   if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {\r
     BuildResourceDescriptorHob (\r
@@ -87,7 +95,7 @@ MemoryPeim (
       EFI_RESOURCE_SYSTEM_MEMORY,\r
       ResourceAttributes,\r
       PcdGet64 (PcdSystemMemoryBase),\r
-      PcdGet64 (PcdSystemMemorySize)\r
+      SystemMemorySize\r
       );\r
   }\r
 \r
index 21327f79f4b92ccfe7dd7d8c1da9ba53ed8f4253..48d9c66b22dbd7642797b374ed5c531ca3876017 100644 (file)
@@ -34,6 +34,7 @@
   CacheMaintenanceLib\r
 \r
 [Guids]\r
+  gArmVirtSystemMemorySizeGuid\r
   gEfiMemoryTypeInformationGuid\r
 \r
 [FeaturePcd]\r
index cf569bed99c4cb831b1b91a952433292d419a386..9cf43f06c073edbdaf6b9bf27abaaa20c8a38f61 100644 (file)
@@ -6,10 +6,12 @@
 \r
 **/\r
 \r
-#include <Base.h>\r
+#include <Uefi.h>\r
+#include <Pi/PiMultiPhase.h>\r
 #include <Library/ArmLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 \r
 // Number of Virtual Memory Map Descriptors\r
 #define MACH_VIRT_PERIPH_BASE  0x08000000\r
 #define MACH_VIRT_PERIPH_SIZE  SIZE_128MB\r
 \r
+/**\r
+  Default library constructur that obtains the memory size from a PCD.\r
+\r
+  @return  Always returns RETURN_SUCCESS\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+QemuVirtMemInfoLibConstructor (\r
+  VOID\r
+  )\r
+{\r
+  UINT64  Size;\r
+  VOID    *Hob;\r
+\r
+  Size = PcdGet64 (PcdSystemMemorySize);\r
+  Hob  = BuildGuidDataHob (&gArmVirtSystemMemorySizeGuid, &Size, sizeof Size);\r
+  ASSERT (Hob != NULL);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
 /**\r
   Return the Virtual Memory Map of your platform\r
 \r
@@ -43,9 +67,16 @@ ArmVirtGetMemoryMap (
   )\r
 {\r
   ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;\r
+  VOID                          *MemorySizeHob;\r
 \r
   ASSERT (VirtualMemoryMap != NULL);\r
 \r
+  MemorySizeHob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);\r
+  ASSERT (MemorySizeHob != NULL);\r
+  if (MemorySizeHob == NULL) {\r
+    return;\r
+  }\r
+\r
   VirtualMemoryTable = AllocatePool (\r
                          sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *\r
                          MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS\r
@@ -59,7 +90,7 @@ ArmVirtGetMemoryMap (
   // System DRAM\r
   VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r
   VirtualMemoryTable[0].VirtualBase  = VirtualMemoryTable[0].PhysicalBase;\r
-  VirtualMemoryTable[0].Length       = PcdGet64 (PcdSystemMemorySize);\r
+  VirtualMemoryTable[0].Length       = *(UINT64 *)GET_GUID_HOB_DATA (MemorySizeHob);\r
   VirtualMemoryTable[0].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r
 \r
   DEBUG ((\r
index 7150de6c10d06799a5e5561886b7de707b5448dc..6acad8bbd7f3aa91477198462d3685bb23f05a3d 100644 (file)
@@ -14,6 +14,7 @@
   MODULE_TYPE                    = BASE\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = ArmVirtMemInfoLib\r
+  CONSTRUCTOR                    = QemuVirtMemInfoLibConstructor\r
 \r
 [Sources]\r
   QemuVirtMemInfoLib.c\r
@@ -30,7 +31,9 @@
   BaseMemoryLib\r
   DebugLib\r
   MemoryAllocationLib\r
-  PcdLib\r
+\r
+[Guids]\r
+  gArmVirtSystemMemorySizeGuid\r
 \r
 [Pcd]\r
   gArmTokenSpaceGuid.PcdFvBaseAddress\r
index 7ecf6dfbb78649376f0dc15909e0fb9c4d8e9224..f045e39a41319681fee2554bfddb865ef315c531 100644 (file)
   BaseMemoryLib\r
   DebugLib\r
   FdtLib\r
-  PcdLib\r
   MemoryAllocationLib\r
 \r
-[Pcd]\r
+[Guids]\r
+  gArmVirtSystemMemorySizeGuid\r
+\r
+[FixedPcd]\r
   gArmTokenSpaceGuid.PcdFdBaseAddress\r
   gArmTokenSpaceGuid.PcdFvBaseAddress\r
   gArmTokenSpaceGuid.PcdSystemMemoryBase\r
   gArmTokenSpaceGuid.PcdSystemMemorySize\r
-\r
-[FixedPcd]\r
   gArmTokenSpaceGuid.PcdFdSize\r
   gArmTokenSpaceGuid.PcdFvSize\r
   gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress\r
index 33d3597d57ab35c941609b502e574805243ea7bd..c47ab8296622a28a5f73e04aa2242dfeae2896a1 100644 (file)
@@ -6,9 +6,10 @@
 \r
 **/\r
 \r
-#include <Base.h>\r
+#include <Uefi.h>\r
+#include <Pi/PiMultiPhase.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/PcdLib.h>\r
+#include <Library/HobLib.h>\r
 #include <libfdt.h>\r
 \r
 RETURN_STATUS\r
@@ -17,14 +18,14 @@ QemuVirtMemInfoPeiLibConstructor (
   VOID\r
   )\r
 {\r
-  VOID           *DeviceTreeBase;\r
-  INT32          Node, Prev;\r
-  UINT64         NewBase, CurBase;\r
-  UINT64         NewSize, CurSize;\r
-  CONST CHAR8    *Type;\r
-  INT32          Len;\r
-  CONST UINT64   *RegProp;\r
-  RETURN_STATUS  PcdStatus;\r
+  VOID          *DeviceTreeBase;\r
+  INT32         Node, Prev;\r
+  UINT64        NewBase, CurBase;\r
+  UINT64        NewSize, CurSize;\r
+  CONST CHAR8   *Type;\r
+  INT32         Len;\r
+  CONST UINT64  *RegProp;\r
+  VOID          *Hob;\r
 \r
   NewBase = 0;\r
   NewSize = 0;\r
@@ -86,8 +87,13 @@ QemuVirtMemInfoPeiLibConstructor (
   // Make sure the start of DRAM matches our expectation\r
   //\r
   ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);\r
-  PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);\r
-  ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
+  Hob = BuildGuidDataHob (\r
+          &gArmVirtSystemMemorySizeGuid,\r
+          &NewSize,\r
+          sizeof NewSize\r
+          );\r
+  ASSERT (Hob != NULL);\r
 \r
   //\r
   // We need to make sure that the machine we are running on has at least\r