From nobody Tue Feb 10 12:58:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+94339+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+94339+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1664180746; cv=none; d=zohomail.com; s=zohoarc; b=jpNuwrl+u00zXqEKtUNK536NbnhdhVjSgKlI0LyIXiDPIPBSgIxRdlfzxSpNb7a1XA6vjp/lN6MqF8Zv0eEHZWbDfL9lRKFBY/c5sN6eB9c5+/MQvmqNYKxcpJvD7ihoP53d6+FLQEDeRsWAaycZETLrtSkMgqkiWZZkXn0tg8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664180746; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xKFQnCf4WdlbfFfBY0IdP7wLDubNVKfUNBoVA+yUv6A=; b=AEShiadQLhnTRvkSrTNMq+oZR5l4hbq+Tw+qD29aApi23c4XDduOh91/0GGaLpKxGyHS6Lkl+AfeZI4YQgAXmGej2O3hPu+HeGq4+dDs/qZ0YmG1rsKX4gJOnm5631uWVJ3euHFBkMirj+TI5y+stlRwXTzEbyAn/mDb/wQEdTg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+94339+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1664180746454726.2316590291289; Mon, 26 Sep 2022 01:25:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jCG0YY1788612xZc9B4IwPps; Mon, 26 Sep 2022 01:25:44 -0700 X-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 X-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) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D799C4347C; Mon, 26 Sep 2022 08:25:38 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Alexander Graf Subject: [edk2-devel] [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> In-Reply-To: <20220926082511.2110797-1-ardb@kernel.org> References: <20220926082511.2110797-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org X-Gm-Message-State: 1vyFqY9fiq04SOIfCKanfrLmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664180744; bh=rbrhA75+iFdBLrSNq1ojeeoNaUFDDYf5IT74l5O0I6c=; h=Cc:Date:From:Reply-To:Subject:To; b=iSVlMEppKomqsW5fxHKyOyDjfTbMSGZAGARo0NNXMTeYc3ncv1m7HnPoERpEgYwjMcq ukLgbqHriLXtW2LgcWVGjKYReeJQzRoL9tZQ3uQ/md1ORvQUNidfXPo5qHkC9wUGb9HEo TEfAZboZkpyf70WYljXI/R7FZpu2r+NQbpk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664180748455100033 Content-Type: text/plain; charset="utf-8" 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 } } gEarlyPL011BaseAddressGuid =3D { 0xB199DEA9, 0xFD5C, 0x4A84, { 0x8= 0, 0x82, 0x2F, 0x41, 0x70, 0x78, 0x03, 0x05 } } gEarly16550UartBaseAddressGuid =3D { 0xea67ca3e, 0x1f54, 0x436b, { 0x9= 7, 0x88, 0xd4, 0xeb, 0x29, 0xc3, 0x42, 0x67 } } + gArmVirtSystemMemorySizeGuid =3D { 0x504eccb9, 0x1bf0, 0x4420, { 0x8= 6, 0x5d, 0xdc, 0x66, 0x06, 0xd4, 0x13, 0xbf } } =20 gArmVirtVariableGuid =3D { 0x50bea1e5, 0xa2c5, 0x46e9, { 0x9b, 0x3a, 0= x59, 0x59, 0x65, 0x16, 0xb0, 0x0a } } =20 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 gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot|FALSE =20 + # System Memory Size -- 128 MB initially, actual size will be fetched fr= om DT + gArmTokenSpaceGuid.PcdSystemMemorySize|0x8000000 + [PcdsFixedAtBuild.AARCH64] # Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry po= int, # if the entry point version is >=3D 3.0. AARCH64 OSes cannot assume the @@ -236,9 +239,6 @@ [PcdsDynamicDefault.common] # enumeration to complete before installing ACPI tables. gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|TRUE =20 - # System Memory Size -- 1 MB initially, actual size will be fetched from= DT - gArmTokenSpaceGuid.PcdSystemMemorySize|0x00100000 - gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerIntrNum|0x0 gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0x0 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 ( { EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; UINT64 SystemMemoryTop; + UINT64 SystemMemorySize; + VOID *Hob; =20 // Ensure PcdSystemMemorySize has been set ASSERT (PcdGet64 (PcdSystemMemorySize) !=3D 0); =20 + SystemMemorySize =3D PcdGet64 (PcdSystemMemorySize); + + Hob =3D GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid); + if (Hob !=3D NULL) { + SystemMemorySize =3D *(UINT64 *)GET_GUID_HOB_DATA (Hob); + } + // // Now, the permanent memory has been installed, we can call AllocatePag= es() // @@ -66,8 +75,7 @@ MemoryPeim ( EFI_RESOURCE_ATTRIBUTE_TESTED ); =20 - SystemMemoryTop =3D PcdGet64 (PcdSystemMemoryBase) + - PcdGet64 (PcdSystemMemorySize); + SystemMemoryTop =3D PcdGet64 (PcdSystemMemoryBase) + SystemMemorySize; =20 if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) { BuildResourceDescriptorHob ( @@ -87,7 +95,7 @@ MemoryPeim ( EFI_RESOURCE_SYSTEM_MEMORY, ResourceAttributes, PcdGet64 (PcdSystemMemoryBase), - PcdGet64 (PcdSystemMemorySize) + SystemMemorySize ); } =20 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 =20 [Guids] + gArmVirtSystemMemorySizeGuid gEfiMemoryTypeInformationGuid =20 [FeaturePcd] 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 @@ =20 **/ =20 -#include +#include +#include #include #include #include +#include #include =20 // Number of Virtual Memory Map Descriptors @@ -24,6 +26,28 @@ #define MACH_VIRT_PERIPH_BASE 0x08000000 #define MACH_VIRT_PERIPH_SIZE SIZE_128MB =20 +/** + 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 =3D PcdGet64 (PcdSystemMemorySize); + Hob =3D BuildGuidDataHob (&gArmVirtSystemMemorySizeGuid, &Size, sizeof = Size); + ASSERT (Hob !=3D NULL); + + return RETURN_SUCCESS; +} + /** Return the Virtual Memory Map of your platform =20 @@ -43,9 +67,16 @@ ArmVirtGetMemoryMap ( ) { ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; + VOID *MemorySizeHob; =20 ASSERT (VirtualMemoryMap !=3D NULL); =20 + MemorySizeHob =3D GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid); + ASSERT (MemorySizeHob !=3D NULL); + if (MemorySizeHob =3D=3D NULL) { + return; + } + VirtualMemoryTable =3D AllocatePool ( sizeof (ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS @@ -59,7 +90,7 @@ ArmVirtGetMemoryMap ( // System DRAM VirtualMemoryTable[0].PhysicalBase =3D PcdGet64 (PcdSystemMemoryBase); VirtualMemoryTable[0].VirtualBase =3D VirtualMemoryTable[0].PhysicalBas= e; - VirtualMemoryTable[0].Length =3D PcdGet64 (PcdSystemMemorySize); + VirtualMemoryTable[0].Length =3D *(UINT64 *)GET_GUID_HOB_DATA (Mem= orySizeHob); VirtualMemoryTable[0].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK; =20 DEBUG (( 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 VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D ArmVirtMemInfoLib + CONSTRUCTOR =3D QemuVirtMemInfoLibConstructor =20 [Sources] QemuVirtMemInfoLib.c @@ -30,7 +31,9 @@ [LibraryClasses] BaseMemoryLib DebugLib MemoryAllocationLib - PcdLib + +[Guids] + gArmVirtSystemMemorySizeGuid =20 [Pcd] gArmTokenSpaceGuid.PcdFvBaseAddress 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 DebugLib FdtLib - PcdLib MemoryAllocationLib =20 -[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/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 @@ =20 **/ =20 -#include +#include +#include #include -#include +#include #include =20 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; =20 NewBase =3D 0; NewSize =3D 0; @@ -86,8 +87,13 @@ QemuVirtMemInfoPeiLibConstructor ( // Make sure the start of DRAM matches our expectation // ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) =3D=3D NewBase); - PcdStatus =3D PcdSet64S (PcdSystemMemorySize, NewSize); - ASSERT_RETURN_ERROR (PcdStatus); + + Hob =3D BuildGuidDataHob ( + &gArmVirtSystemMemorySizeGuid, + &NewSize, + sizeof NewSize + ); + ASSERT (Hob !=3D NULL); =20 // // We need to make sure that the machine we are running on has at least --=20 2.35.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#94339): https://edk2.groups.io/g/devel/message/94339 Mute This Topic: https://groups.io/mt/93922707/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-