From nobody Mon Feb 9 09:29:14 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+88231+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+88231+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1648597689; cv=none; d=zohomail.com; s=zohoarc; b=LTy+DiSyrpXmTyz/K5iPCD2HphP71Yd2ckCRv/jnmlfTdU5M3AK+Sicw24xmxLo8gfXcNPpwF6W+rQdbhVbJJDIh+5jwlWGknga5kX9cuasV6CYiRCdK94tP1CX7A1DymVcktdEWtMJAkSCJcDa36/NANLh3WfWqq1cxRlLLrcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648597689; 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=EeP245kk6dJerLxtjjBFxVKxMXYm5+YU/h9esWzakrg=; b=ksI/faF/hvwXiCDCF7co9HBeWx/af7yvs73IEhaR8YHXUFnz8SnYMHC61YDHnsedEPMyfY8Lw3n6Zx16QYfgAaT98t9zTGgxapb2GmCYwy8kvZWKp6xkKGRIYwvniH9xD8vDqo0937kUpl7SiHjdc4KwWxzYR2iVbEAxWHh/4eI= 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+88231+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 164859768985856.073413330047174; Tue, 29 Mar 2022 16:48:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eMCDYY1788612xccbyPevvrN; Tue, 29 Mar 2022 16:48:09 -0700 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web12.1145.1648597670632172204 for ; Tue, 29 Mar 2022 16:48:09 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259375344" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259375344" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 16:48:08 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="521658855" X-Received: from zhangpen-mobl.ccr.corp.intel.com (HELO mxu9-mobl1.ccr.corp.intel.com) ([10.255.29.230]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 16:48:05 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Ard Biesheuvel , Jordan Justen , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann , Sebastien Boeuf Subject: [edk2-devel] [PATCH V12 22/47] OvmfPkg/PlatformPei: Refactor AddressWidthInitialization Date: Wed, 30 Mar 2022 07:46:15 +0800 Message-Id: <3b53243773e14530b3a2cff1604e89f9ac0ee064.1648555175.git.min.m.xu@intel.com> In-Reply-To: References: 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,min.m.xu@intel.com X-Gm-Message-State: LBxNw2a2xMLuNluGIhR5cFH7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1648597689; bh=5Y+SmGVihR2pkXU3ayLOAXn1wEgeg+30/JIpIXcpyGI=; h=Cc:Date:From:Reply-To:Subject:To; b=FzwwkhSJeyM53xXepzlok3V2KABtvEHlxLHgi+VYQYL8A21dl7GRSY9dGYf39Jm93UA I1Xd/y1kdG9RT2pHnFen3/OvRbme6JsTbXY+a0CvV116gIScsvX1u0vwEO7lvVV5RpxKO DeyPj2DqjpoCiD4aZ55GmJxUlyXm2iRWpPA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1648597690642100005 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3863 From this patch we start to restruct the functions which set PCDs into two, one for PlatformInitLib, one for PlatformPei. AddressWidthInitialization is the first one. It is splitted into two: - PlatformAddressWidthInitialization is for PlatformInitLib - AddressWidthInitialization is for PlatformPei. It calls PlatformAddressWidthInitialization then set PCDs. Below functions are also refined for PlatformInitLib: - PlatformScanOrAdd64BitE820Ram - PlatformGetSystemMemorySizeAbove4gb - PlatformGetFirstNonAddress All the SetPcd codes are removed from above functions. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Cc: Sebastien Boeuf Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/PlatformPei/MemDetect.c | 117 ++++++++++++++++++++------------ OvmfPkg/PlatformPei/Platform.c | 6 +- 2 files changed, 78 insertions(+), 45 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index f3819b997b3b..5507d9585bab 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -189,7 +189,7 @@ QemuUc32BaseInitialization ( Find the highest exclusive >=3D4GB RAM address, or produce memory resour= ce descriptor HOBs for RAM entries that start at or above 4GB. =20 - @param[out] MaxAddress If MaxAddress is NULL, then ScanOrAdd64BitE820Ra= m() + @param[out] MaxAddress If MaxAddress is NULL, then PlatformScanOrAdd64B= itE820Ram() produces memory resource descriptor HOBs for RAM entries that start at or above 4GB. =20 @@ -210,7 +210,7 @@ QemuUc32BaseInitialization ( **/ STATIC EFI_STATUS -ScanOrAdd64BitE820Ram ( +PlatformScanOrAdd64BitE820Ram ( IN BOOLEAN AddHighHob, OUT UINT64 *LowMemory OPTIONAL, OUT UINT64 *MaxAddress OPTIONAL @@ -385,7 +385,7 @@ GetSystemMemorySizeBelow4gb ( return (UINT32)GetHighestSystemMemoryAddressFromPvhMemmap (TRUE); } =20 - Status =3D ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); + Status =3D PlatformScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); if ((Status =3D=3D EFI_SUCCESS) && (LowerMemorySize > 0)) { return (UINT32)LowerMemorySize; } @@ -407,7 +407,7 @@ GetSystemMemorySizeBelow4gb ( =20 STATIC UINT64 -GetSystemMemorySizeAbove4gb ( +PlatformGetSystemMemorySizeAbove4gb ( ) { UINT32 Size; @@ -434,7 +434,7 @@ GetSystemMemorySizeAbove4gb ( **/ STATIC UINT64 -GetFirstNonAddress ( +PlatformGetFirstNonAddress ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { @@ -444,7 +444,6 @@ GetFirstNonAddress ( FIRMWARE_CONFIG_ITEM FwCfgItem; UINTN FwCfgSize; UINT64 HotPlugMemoryEnd; - RETURN_STATUS PcdStatus; =20 // // set FirstNonAddress to suppress incorrect compiler/analyzer warnings @@ -458,9 +457,9 @@ GetFirstNonAddress ( // Otherwise, get the flat size of the memory above 4GB from the CMOS (w= hich // can only express a size smaller than 1TB), and add it to 4GB. // - Status =3D ScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); + Status =3D PlatformScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); if (EFI_ERROR (Status)) { - FirstNonAddress =3D BASE_4GB + GetSystemMemorySizeAbove4gb (); + FirstNonAddress =3D BASE_4GB + PlatformGetSystemMemorySizeAbove4gb (); } =20 // @@ -475,12 +474,6 @@ GetFirstNonAddress ( =20 #endif =20 - // - // Otherwise, in order to calculate the highest address plus one, we must - // consider the 64-bit PCI host aperture too. Fetch the default size. - // - PlatformInfoHob->PcdPciMmio64Size =3D PcdGet64 (PcdPciMmio64Size); - // // See if the user specified the number of megabytes for the 64-bit PCI = host // aperture. Accept an aperture size up to 16TB. @@ -522,8 +515,6 @@ GetFirstNonAddress ( "%a: disabling 64-bit PCI host aperture\n", __FUNCTION__ )); - PcdStatus =3D PcdSet64S (PcdPciMmio64Size, 0); - ASSERT_RETURN_ERROR (PcdStatus); } =20 // @@ -574,26 +565,6 @@ GetFirstNonAddress ( // PlatformInfoHob->PcdPciMmio64Base =3D ALIGN_VALUE (PlatformInfoHob->PcdP= ciMmio64Base, GetPowerOfTwo64 (PlatformInfoHob->PcdPciMmio64Size)); =20 - if (PlatformInfoHob->BootMode !=3D BOOT_ON_S3_RESUME) { - // - // The core PciHostBridgeDxe driver will automatically add this range = to - // the GCD memory space map through our PciHostBridgeLib instance; her= e we - // only need to set the PCDs. - // - PcdStatus =3D PcdSet64S (PcdPciMmio64Base, PlatformInfoHob->PcdPciMmio= 64Base); - ASSERT_RETURN_ERROR (PcdStatus); - PcdStatus =3D PcdSet64S (PcdPciMmio64Size, PlatformInfoHob->PcdPciMmio= 64Size); - ASSERT_RETURN_ERROR (PcdStatus); - - DEBUG (( - DEBUG_INFO, - "%a: Pci64Base=3D0x%Lx Pci64Size=3D0x%Lx\n", - __FUNCTION__, - PlatformInfoHob->PcdPciMmio64Base, - PlatformInfoHob->PcdPciMmio64Size - )); - } - // // The useful address space ends with the 64-bit PCI host aperture. // @@ -602,10 +573,11 @@ GetFirstNonAddress ( } =20 /** - Initialize the mPhysMemAddressWidth variable, based on guest RAM size. + Initialize the PhysMemAddressWidth field in PlatformInfoHob based on gue= st RAM size. **/ VOID -AddressWidthInitialization ( +EFIAPI +PlatformAddressWidthInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { @@ -618,7 +590,7 @@ AddressWidthInitialization ( // The DXL IPL keys off of the physical address bits advertized in the C= PU // HOB. To conserve memory, we calculate the minimum address width here. // - FirstNonAddress =3D GetFirstNonAddress (PlatformInfoHob); + FirstNonAddress =3D PlatformGetFirstNonAddress (PlatformInfoHob); PhysMemAddressWidth =3D (UINT8)HighBitSet64 (FirstNonAddress); =20 // @@ -645,6 +617,65 @@ AddressWidthInitialization ( PlatformInfoHob->PhysMemAddressWidth =3D PhysMemAddressWidth; } =20 +/** + Initialize the PhysMemAddressWidth field in PlatformInfoHob based on gue= st RAM size. +**/ +VOID +AddressWidthInitialization ( + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + RETURN_STATUS PcdStatus; + + PlatformAddressWidthInitialization (PlatformInfoHob); + + // + // If DXE is 32-bit, then we're done; PciBusDxe will degrade 64-bit MMIO + // resources to 32-bit anyway. See DegradeResource() in + // "PciResourceSupport.c". + // + #ifdef MDE_CPU_IA32 + if (!FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { + return; + } + + #endif + + if (PlatformInfoHob->PcdPciMmio64Size =3D=3D 0) { + if (PlatformInfoHob->BootMode !=3D BOOT_ON_S3_RESUME) { + DEBUG (( + DEBUG_INFO, + "%a: disabling 64-bit PCI host aperture\n", + __FUNCTION__ + )); + PcdStatus =3D PcdSet64S (PcdPciMmio64Size, 0); + ASSERT_RETURN_ERROR (PcdStatus); + } + + return; + } + + if (PlatformInfoHob->BootMode !=3D BOOT_ON_S3_RESUME) { + // + // The core PciHostBridgeDxe driver will automatically add this range = to + // the GCD memory space map through our PciHostBridgeLib instance; her= e we + // only need to set the PCDs. + // + PcdStatus =3D PcdSet64S (PcdPciMmio64Base, PlatformInfoHob->PcdPciMmio= 64Base); + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus =3D PcdSet64S (PcdPciMmio64Size, PlatformInfoHob->PcdPciMmio= 64Size); + ASSERT_RETURN_ERROR (PcdStatus); + + DEBUG (( + DEBUG_INFO, + "%a: Pci64Base=3D0x%Lx Pci64Size=3D0x%Lx\n", + __FUNCTION__, + PlatformInfoHob->PcdPciMmio64Base, + PlatformInfoHob->PcdPciMmio64Size + )); + } +} + /** Calculate the cap for the permanent PEI memory. **/ @@ -704,7 +735,7 @@ GetPeiMemoryCap ( =20 // // Add 64 MB for miscellaneous allocations. Note that for - // mPhysMemAddressWidth values close to 36, the cap will actually be + // PhysMemAddressWidth values close to 36, the cap will actually be // dominated by this increment. // return (UINT32)(EFI_PAGES_TO_SIZE (TotalPages) + SIZE_64MB); @@ -763,7 +794,7 @@ PublishPeiMemory ( PeiMemoryCap =3D GetPeiMemoryCap (); DEBUG (( DEBUG_INFO, - "%a: mPhysMemAddressWidth=3D%d PeiMemoryCap=3D%u KB\n", + "%a: PhysMemAddressWidth=3D%d PeiMemoryCap=3D%u KB\n", __FUNCTION__, mPlatformInfoHob.PhysMemAddressWidth, PeiMemoryCap >> 10 @@ -902,9 +933,9 @@ QemuInitializeRam ( // entries. Otherwise, create a single memory HOB with the flat >=3D4GB // memory size read from the CMOS. // - Status =3D ScanOrAdd64BitE820Ram (TRUE, NULL, NULL); + Status =3D PlatformScanOrAdd64BitE820Ram (TRUE, NULL, NULL); if (EFI_ERROR (Status)) { - UpperMemorySize =3D GetSystemMemorySizeAbove4gb (); + UpperMemorySize =3D PlatformGetSystemMemorySizeAbove4gb (); if (UpperMemorySize !=3D 0) { PlatformAddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); } diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 3e0c56db57ed..7d370c9b8fa8 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -734,8 +734,10 @@ InitializePlatform ( =20 DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); =20 - mPlatformInfoHob.SmmSmramRequire =3D FeaturePcdGet (PcdSmmSmramRequire); - mPlatformInfoHob.SevEsIsEnabled =3D MemEncryptSevEsIsEnabled (); + mPlatformInfoHob.SmmSmramRequire =3D FeaturePcdGet (PcdSmmSmramRequi= re); + mPlatformInfoHob.SevEsIsEnabled =3D MemEncryptSevEsIsEnabled (); + mPlatformInfoHob.PcdPciMmio64Size =3D PcdGet64 (PcdPciMmio64Size); + mPlatformInfoHob.DefaultMaxCpuNumber =3D PcdGet32 (PcdCpuMaxLogicalProce= ssorNumber); =20 PlatformDebugDumpCmos (); =20 --=20 2.29.2.windows.2 -=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 (#88231): https://edk2.groups.io/g/devel/message/88231 Mute This Topic: https://groups.io/mt/90121219/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-