From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by mx.groups.io with SMTP id smtpd.web10.25938.1664180743575275382 for ; Mon, 26 Sep 2022 01:25:44 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HhC+cSds; spf=pass (domain: kernel.org, ip: 145.40.73.55, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 04B35CE107C; Mon, 26 Sep 2022 08:25:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D799C4347C; Mon, 26 Sep 2022 08:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664180739; bh=KHo4meqXp0NgJ79ZEMgzXVoxka+5ZxSBx1lrpwZRVcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HhC+cSdsoWdh8XYGs2NEuV2q7LaAd47GQNLAabh/y/rsFC9ydpIQojK2Nw5QIBoPp hHakd7buJfKDp0Kd43CTM+xuDgtsV7ofEFKsbrmmp9VWLX6Fg0O8n8XEFHda0iHr1L fdJFKZ8VjvR+lu/99tOPnFCnIXeUxzQRLpWpu5ERWsqrdmefV8DiDRvO75KyUbWW1P W3FSmFrKrzSWC4N790gJjtMerYNzt8BpNEQ981fEhBcVzke7gduZ1WCnID70KDn+4h D+57WreRukeIhW9svUFjpEK5i0hCxnGc8f2jUToICvtrcVDpYVicZ1n1AqDfEjCh/b /eyF7gpLAg3mw== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Alexander Graf Subject: [PATCH v3 15/16] ArmVirtPkg/QemuVirtMemInfoLib: use HOB not PCD to record the memory size Date: Mon, 26 Sep 2022 10:25:10 +0200 Message-Id: <20220926082511.2110797-16-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220926082511.2110797-1-ardb@kernel.org> References: <20220926082511.2110797-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 constructur 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 --- ArmVirtPkg/ArmVirtPkg.dec |= 1 + ArmVirtPkg/ArmVirtQemu.dsc |= 6 ++-- ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c |= 14 ++++++-- ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf |= 1 + ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c |= 35 ++++++++++++++++++-- ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf |= 5 ++- ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf |= 8 ++--- ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructor.c |= 30 ++++++++++------- 8 files changed, 75 insertions(+), 25 deletions(-) diff --git a/ArmVirtPkg/ArmVirtPkg.dec b/ArmVirtPkg/ArmVirtPkg.dec index 4e165f6cd845..89d21ec3a364 100644 --- a/ArmVirtPkg/ArmVirtPkg.dec +++ b/ArmVirtPkg/ArmVirtPkg.dec @@ -32,6 +32,7 @@ [Guids.common] gArmVirtTokenSpaceGuid =3D { 0x0B6F5CA7, 0x4F53, 0x445A, { 0xB7, 0x6E, 0= x2E, 0x36, 0x5B, 0x80, 0x63, 0x66 } }=0D gEarlyPL011BaseAddressGuid =3D { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x8= 0, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } }=0D gEarly16550UartBaseAddressGuid =3D { 0xea67ca3e, 0x1f54, 0x436b, { 0x9= 7, 0x88, 0xd4, 0xeb, 0x29, 0xc3, 0x42, 0x67 } }=0D + gArmVirtSystemMemorySizeGuid =3D { 0x504eccb9, 0x1bf0, 0x4420, { 0x8= 6, 0x5d, 0xdc, 0x66, 0x06, 0xd4, 0x13, 0xbf } }=0D =0D gArmVirtVariableGuid =3D { 0x50bea1e5, 0xa2c5, 0x46e9, { 0x9b, 0x3a, 0= x59, 0x59, 0x65, 0x16, 0xb0, 0x0a } }=0D =0D diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index c3d264077bce..43e19f605084 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -220,6 +220,9 @@ [PcdsFixedAtBuild.common] # Shadowing PEI modules is absolutely pointless when the NOR flash is em= ulated=0D gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot|FALSE=0D =0D + # System Memory Size -- 128 MB initially, actual size will be fetched fr= om DT=0D + gArmTokenSpaceGuid.PcdSystemMemorySize|0x8000000=0D +=0D [PcdsFixedAtBuild.AARCH64]=0D # Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry po= int,=0D # if the entry point version is >=3D 3.0. AARCH64 OSes cannot assume the= =0D @@ -236,9 +239,6 @@ [PcdsDynamicDefault.common] # enumeration to complete before installing ACPI tables.=0D gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE=0D =0D - # System Memory Size -- 1 MB initially, actual size will be fetched from= DT=0D - gArmTokenSpaceGuid.PcdSystemMemorySize|0x00100000=0D -=0D gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0=0D gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0=0D gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0=0D diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPe= iLib.c b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib= .c index 98d90ad4200d..72e5c65af79e 100644 --- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c +++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.c @@ -52,10 +52,19 @@ MemoryPeim ( {=0D EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;=0D UINT64 SystemMemoryTop;=0D + UINT64 SystemMemorySize;=0D + VOID *Hob;=0D =0D // Ensure PcdSystemMemorySize has been set=0D ASSERT (PcdGet64 (PcdSystemMemorySize) !=3D 0);=0D =0D + SystemMemorySize =3D PcdGet64 (PcdSystemMemorySize);=0D +=0D + Hob =3D GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);=0D + if (Hob !=3D NULL) {=0D + SystemMemorySize =3D *(UINT64 *)GET_GUID_HOB_DATA (Hob);=0D + }=0D +=0D //=0D // Now, the permanent memory has been installed, we can call AllocatePag= es()=0D //=0D @@ -66,8 +75,7 @@ MemoryPeim ( EFI_RESOURCE_ATTRIBUTE_TESTED=0D );=0D =0D - SystemMemoryTop =3D PcdGet64 (PcdSystemMemoryBase) +=0D - PcdGet64 (PcdSystemMemorySize);=0D + SystemMemoryTop =3D PcdGet64 (PcdSystemMemoryBase) + SystemMemorySize;=0D =0D if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {=0D BuildResourceDescriptorHob (=0D @@ -87,7 +95,7 @@ MemoryPeim ( EFI_RESOURCE_SYSTEM_MEMORY,=0D ResourceAttributes,=0D PcdGet64 (PcdSystemMemoryBase),=0D - PcdGet64 (PcdSystemMemorySize)=0D + SystemMemorySize=0D );=0D }=0D =0D diff --git a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPe= iLib.inf b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiL= ib.inf index 21327f79f4b9..48d9c66b22db 100644 --- a/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf +++ b/ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf @@ -34,6 +34,7 @@ [LibraryClasses] CacheMaintenanceLib=0D =0D [Guids]=0D + gArmVirtSystemMemorySizeGuid=0D gEfiMemoryTypeInformationGuid=0D =0D [FeaturePcd]=0D diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c b/A= rmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c index cf569bed99c4..9cf43f06c073 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c @@ -6,10 +6,12 @@ =0D **/=0D =0D -#include =0D +#include =0D +#include =0D #include =0D #include =0D #include =0D +#include =0D #include =0D =0D // Number of Virtual Memory Map Descriptors=0D @@ -24,6 +26,28 @@ #define MACH_VIRT_PERIPH_BASE 0x08000000=0D #define MACH_VIRT_PERIPH_SIZE SIZE_128MB=0D =0D +/**=0D + Default library constructur that obtains the memory size from a PCD.=0D +=0D + @return Always returns RETURN_SUCCESS=0D +=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +QemuVirtMemInfoLibConstructor (=0D + VOID=0D + )=0D +{=0D + UINT64 Size;=0D + VOID *Hob;=0D +=0D + Size =3D PcdGet64 (PcdSystemMemorySize);=0D + Hob =3D BuildGuidDataHob (&gArmVirtSystemMemorySizeGuid, &Size, sizeof = Size);=0D + ASSERT (Hob !=3D NULL);=0D +=0D + return RETURN_SUCCESS;=0D +}=0D +=0D /**=0D Return the Virtual Memory Map of your platform=0D =0D @@ -43,9 +67,16 @@ ArmVirtGetMemoryMap ( )=0D {=0D ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;=0D + VOID *MemorySizeHob;=0D =0D ASSERT (VirtualMemoryMap !=3D NULL);=0D =0D + MemorySizeHob =3D GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);=0D + ASSERT (MemorySizeHob !=3D NULL);=0D + if (MemorySizeHob =3D=3D NULL) {=0D + return;=0D + }=0D +=0D VirtualMemoryTable =3D AllocatePool (=0D sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *=0D MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS=0D @@ -59,7 +90,7 @@ ArmVirtGetMemoryMap ( // System DRAM=0D VirtualMemoryTable[0].PhysicalBase =3D PcdGet64 (PcdSystemMemoryBase);=0D VirtualMemoryTable[0].VirtualBase =3D VirtualMemoryTable[0].PhysicalBas= e;=0D - VirtualMemoryTable[0].Length =3D PcdGet64 (PcdSystemMemorySize);=0D + VirtualMemoryTable[0].Length =3D *(UINT64 *)GET_GUID_HOB_DATA (Mem= orySizeHob);=0D VirtualMemoryTable[0].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK;=0D =0D DEBUG ((=0D diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf b= /ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf index 7150de6c10d0..6acad8bbd7f3 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf @@ -14,6 +14,7 @@ [Defines] MODULE_TYPE =3D BASE=0D VERSION_STRING =3D 1.0=0D LIBRARY_CLASS =3D ArmVirtMemInfoLib=0D + CONSTRUCTOR =3D QemuVirtMemInfoLibConstructor=0D =0D [Sources]=0D QemuVirtMemInfoLib.c=0D @@ -30,7 +31,9 @@ [LibraryClasses] BaseMemoryLib=0D DebugLib=0D MemoryAllocationLib=0D - PcdLib=0D +=0D +[Guids]=0D + gArmVirtSystemMemorySizeGuid=0D =0D [Pcd]=0D gArmTokenSpaceGuid.PcdFvBaseAddress=0D diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.in= f b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf index 7ecf6dfbb786..f045e39a4131 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf @@ -32,16 +32,16 @@ [LibraryClasses] BaseMemoryLib=0D DebugLib=0D FdtLib=0D - PcdLib=0D MemoryAllocationLib=0D =0D -[Pcd]=0D +[Guids]=0D + gArmVirtSystemMemorySizeGuid=0D +=0D +[FixedPcd]=0D gArmTokenSpaceGuid.PcdFdBaseAddress=0D gArmTokenSpaceGuid.PcdFvBaseAddress=0D gArmTokenSpaceGuid.PcdSystemMemoryBase=0D gArmTokenSpaceGuid.PcdSystemMemorySize=0D -=0D -[FixedPcd]=0D gArmTokenSpaceGuid.PcdFdSize=0D gArmTokenSpaceGuid.PcdFvSize=0D gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress=0D diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibCon= structor.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibCon= structor.c index 33d3597d57ab..c47ab8296622 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructo= r.c +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLibConstructo= r.c @@ -6,9 +6,10 @@ =0D **/=0D =0D -#include =0D +#include =0D +#include =0D #include =0D -#include =0D +#include =0D #include =0D =0D RETURN_STATUS=0D @@ -17,14 +18,14 @@ QemuVirtMemInfoPeiLibConstructor ( VOID=0D )=0D {=0D - VOID *DeviceTreeBase;=0D - INT32 Node, Prev;=0D - UINT64 NewBase, CurBase;=0D - UINT64 NewSize, CurSize;=0D - CONST CHAR8 *Type;=0D - INT32 Len;=0D - CONST UINT64 *RegProp;=0D - RETURN_STATUS PcdStatus;=0D + VOID *DeviceTreeBase;=0D + INT32 Node, Prev;=0D + UINT64 NewBase, CurBase;=0D + UINT64 NewSize, CurSize;=0D + CONST CHAR8 *Type;=0D + INT32 Len;=0D + CONST UINT64 *RegProp;=0D + VOID *Hob;=0D =0D NewBase =3D 0;=0D NewSize =3D 0;=0D @@ -86,8 +87,13 @@ QemuVirtMemInfoPeiLibConstructor ( // Make sure the start of DRAM matches our expectation=0D //=0D ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) =3D=3D NewBase);=0D - PcdStatus =3D PcdSet64S (PcdSystemMemorySize, NewSize);=0D - ASSERT_RETURN_ERROR (PcdStatus);=0D +=0D + Hob =3D BuildGuidDataHob (=0D + &gArmVirtSystemMemorySizeGuid,=0D + &NewSize,=0D + sizeof NewSize=0D + );=0D + ASSERT (Hob !=3D NULL);=0D =0D //=0D // We need to make sure that the machine we are running on has at least= =0D --=20 2.35.1