From nobody Mon Feb 9 21:20:45 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+98342+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+98342+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673516074; cv=none; d=zohomail.com; s=zohoarc; b=BDqux1swEuXXAhNQ1ey0GzqfS+0z9A8Ka6ahAYPeN96+JXVghS3OyylnRIiIXH07I59aUz/7XUmgaieFzTem2qFkVC5iLNUxPE/4HBU6WW0W9MWVo1WmkC6W7yylkShzyZcXrTM00skLR64i+FdKtw8StcV9iy1nkLaq7AwofNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673516074; h=Content-Type: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=Qi3jl318rI0oQcvAtcmBDZ6wNPsOnPXKKW5mFvI1j7U=; b=XZtLlYtQEiqJnJjK7vS1wxRPs+mQeeuxDcJ7IRL+ySy8y898X33yjAD39A6B1e5JkDPMk/oz0Y20XGmxo6bhpC4luqO0S8FtFz5FwMjnmEaM7Y0Ev4KkBEQn+e+2fMHXZPorYttSRWxGh9CRsNcIPGwWJnkAhsEnTbXZHbywdY8= 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+98342+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 1673516074183487.34452520594857; Thu, 12 Jan 2023 01:34:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id JsKIYY1788612x58aHBXCiRm; Thu, 12 Jan 2023 01:34:33 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.51056.1673516073007074483 for ; Thu, 12 Jan 2023 01:34:33 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-Qt0q5Od0PA268skohlQR2Q-1; Thu, 12 Jan 2023 04:34:29 -0500 X-MC-Unique: Qt0q5Od0PA268skohlQR2Q-1 X-Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B9AAC85C064; Thu, 12 Jan 2023 09:34:28 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D070492C14; Thu, 12 Jan 2023 09:34:28 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 86ECF180093D; Thu, 12 Jan 2023 10:34:25 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Oliver Steffen , =?UTF-8?q?L=C3=A1szl=C3=B3=20=C3=89rsek?= , Ard Biesheuvel , Jordan Justen , Pawel Polawski , Jiewen Yao , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 2/8] OvmfPkg/PlatformInitLib: Add PlatformGetLowMemoryCB Date: Thu, 12 Jan 2023 10:34:19 +0100 Message-Id: <20230112093425.1228300-3-kraxel@redhat.com> In-Reply-To: <20230112093425.1228300-1-kraxel@redhat.com> References: <20230112093425.1228300-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,kraxel@redhat.com X-Gm-Message-State: wJuuDIUMvVdypHCRcu22LZG2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516073; bh=oKFKedehwxz5OpG3wBodQcCB+X5tdkB4ncjPVm5mwRo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=ARFm3cRG6gCro9Je6SzoEgZ2vsVeqgl+0GorjllG3L8BkEROEG9pswg0XJp9Ko4li6M S3eeFev2VVo+ljgHUO2N1+u9TbdcUDpuaQ0E2tnfvipPbgFhL6U+lSmeCUinD7Zlg1Mpv N+Rj6YizUAVrypZ86ufW5WvQlp/ZSU068n0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516074889100011 Content-Type: text/plain; charset="utf-8"; x-default="true" Add PlatformGetLowMemoryCB() callback function for use with PlatformScanE820(). It stores the low memory size in PlatformInfoHob->LowMemory. This replaces calls to PlatformScanOrAdd64BitE820Ram() with non-NULL LowMemory. Write any actions done (setting LowMemory) to the firmware log with INFO loglevel. Also change PlatformGetSystemMemorySizeBelow4gb() to likewise set PlatformInfoHob->LowMemory instead of returning the value. Update all Callers to the new convention. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Include/Library/PlatformInitLib.h | 3 +- OvmfPkg/Library/PeilessStartupLib/Hob.c | 3 +- .../PeilessStartupLib/PeilessStartup.c | 7 +- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 69 +++++++++++++------ OvmfPkg/Library/PlatformInitLib/Platform.c | 7 +- OvmfPkg/PlatformPei/MemDetect.c | 3 +- 6 files changed, 59 insertions(+), 33 deletions(-) diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Li= brary/PlatformInitLib.h index bf6f90a5761c..051b31191194 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -26,6 +26,7 @@ typedef struct { BOOLEAN Q35SmramAtDefaultSmbase; UINT16 Q35TsegMbytes; =20 + UINT32 LowMemory; UINT64 FirstNonAddress; UINT8 PhysMemAddressWidth; UINT32 Uc32Base; @@ -144,7 +145,7 @@ PlatformQemuUc32BaseInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); =20 -UINT32 +VOID EFIAPI PlatformGetSystemMemorySizeBelow4gb ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/Peil= essStartupLib/Hob.c index 630ce445ebec..318b74c95d8e 100644 --- a/OvmfPkg/Library/PeilessStartupLib/Hob.c +++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c @@ -42,7 +42,8 @@ ConstructSecHobList ( =20 ZeroMem (&PlatformInfoHob, sizeof (PlatformInfoHob)); PlatformInfoHob.HostBridgeDevId =3D PciRead16 (OVMF_HOSTBRIDGE_DID); - LowMemorySize =3D PlatformGetSystemMemorySizeBelow4gb = (&PlatformInfoHob); + PlatformGetSystemMemorySizeBelow4gb (&PlatformInfoHob); + LowMemorySize =3D PlatformInfoHob.LowMemory; ASSERT (LowMemorySize !=3D 0); LowMemoryStart =3D FixedPcdGet32 (PcdOvmfDxeMemFvBase) + FixedPcdGet32 (= PcdOvmfDxeMemFvSize); LowMemorySize -=3D LowMemoryStart; diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/L= ibrary/PeilessStartupLib/PeilessStartup.c index 380e71597206..928120d183ba 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c @@ -41,8 +41,7 @@ InitializePlatform ( EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - UINT32 LowerMemorySize; - VOID *VariableStore; + VOID *VariableStore; =20 DEBUG ((DEBUG_INFO, "InitializePlatform in Pei-less boot\n")); PlatformDebugDumpCmos (); @@ -70,14 +69,14 @@ InitializePlatform ( PlatformInfoHob->PcdCpuBootLogicalProcessorNumber )); =20 - LowerMemorySize =3D PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob= ); + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); PlatformQemuUc32BaseInitialization (PlatformInfoHob); DEBUG (( DEBUG_INFO, "Uc32Base =3D 0x%x, Uc32Size =3D 0x%x, LowerMemorySize =3D 0x%x\n", PlatformInfoHob->Uc32Base, PlatformInfoHob->Uc32Size, - LowerMemorySize + PlatformInfoHob->LowMemory )); =20 VariableStore =3D PlatformReserveEmuVar= iableNvStore (); diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index dd98622de561..153f958b76ee 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -51,18 +51,16 @@ PlatformQemuUc32BaseInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - UINT32 LowerMemorySize; - if (PlatformInfoHob->HostBridgeDevId =3D=3D 0xffff /* microvm */) { return; } =20 if (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { - LowerMemorySize =3D PlatformGetSystemMemorySizeBelow4gb (PlatformInfoH= ob); + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); ASSERT (PcdGet64 (PcdPciExpressBaseAddress) <=3D MAX_UINT32); - ASSERT (PcdGet64 (PcdPciExpressBaseAddress) >=3D LowerMemorySize); + ASSERT (PcdGet64 (PcdPciExpressBaseAddress) >=3D PlatformInfoHob->LowM= emory); =20 - if (LowerMemorySize <=3D BASE_2GB) { + if (PlatformInfoHob->LowMemory <=3D BASE_2GB) { // Newer qemu with gigabyte aligned memory, // 32-bit pci mmio window is 2G -> 4G then. PlatformInfoHob->Uc32Base =3D BASE_2GB; @@ -92,8 +90,8 @@ PlatformQemuUc32BaseInitialization ( // variable MTRR suffices by truncating the size to a whole power of two, // while keeping the end affixed to 4GB. This will round the base up. // - LowerMemorySize =3D PlatformGetSystemMemorySizeBelow4gb (Platf= ormInfoHob); - PlatformInfoHob->Uc32Size =3D GetPowerOfTwo32 ((UINT32)(SIZE_4GB - Lower= MemorySize)); + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); + PlatformInfoHob->Uc32Size =3D GetPowerOfTwo32 ((UINT32)(SIZE_4GB - Platf= ormInfoHob->LowMemory)); PlatformInfoHob->Uc32Base =3D (UINT32)(SIZE_4GB - PlatformInfoHob->Uc32S= ize); // // Assuming that LowerMemorySize is at least 1 byte, Uc32Size is at most= 2GB. @@ -101,13 +99,13 @@ PlatformQemuUc32BaseInitialization ( // ASSERT (PlatformInfoHob->Uc32Base >=3D BASE_2GB); =20 - if (PlatformInfoHob->Uc32Base !=3D LowerMemorySize) { + if (PlatformInfoHob->Uc32Base !=3D PlatformInfoHob->LowMemory) { DEBUG (( DEBUG_VERBOSE, "%a: rounded UC32 base from 0x%x up to 0x%x, for " "an UC32 size of 0x%x\n", __FUNCTION__, - LowerMemorySize, + PlatformInfoHob->LowMemory, PlatformInfoHob->Uc32Base, PlatformInfoHob->Uc32Size )); @@ -279,6 +277,33 @@ PlatformGetFirstNonAddressCB ( } } =20 +/** + Store the low (below 4G) memory size in + PlatformInfoHob->LowMemory +**/ +STATIC VOID +PlatformGetLowMemoryCB ( + IN EFI_E820_ENTRY64 *E820Entry, + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + UINT64 Candidate; + + if (E820Entry->Type !=3D EfiAcpiAddressRangeMemory) { + return; + } + + Candidate =3D E820Entry->BaseAddr + E820Entry->Length; + if (Candidate >=3D BASE_4GB) { + return; + } + + if (PlatformInfoHob->LowMemory < Candidate) { + DEBUG ((DEBUG_INFO, "%a: LowMemory=3D0x%Lx\n", __FUNCTION__, Candidate= )); + PlatformInfoHob->LowMemory =3D (UINT32)Candidate; + } +} + /** Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the passed callback for each entry. @@ -395,14 +420,13 @@ GetHighestSystemMemoryAddressFromPvhMemmap ( return HighestAddress; } =20 -UINT32 +VOID EFIAPI PlatformGetSystemMemorySizeBelow4gb ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { EFI_STATUS Status; - UINT64 LowerMemorySize =3D 0; UINT8 Cmos0x34; UINT8 Cmos0x35; =20 @@ -410,12 +434,13 @@ PlatformGetSystemMemorySizeBelow4gb ( (CcProbe () !=3D CcGuestTypeIntelTdx)) { // Get the information from PVH memmap - return (UINT32)GetHighestSystemMemoryAddressFromPvhMemmap (TRUE); + PlatformInfoHob->LowMemory =3D (UINT32)GetHighestSystemMemoryAddressFr= omPvhMemmap (TRUE); + return; } =20 - Status =3D PlatformScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); - if ((Status =3D=3D EFI_SUCCESS) && (LowerMemorySize > 0)) { - return (UINT32)LowerMemorySize; + Status =3D PlatformScanE820 (PlatformGetLowMemoryCB, PlatformInfoHob); + if (!EFI_ERROR (Status) && (PlatformInfoHob->LowMemory > 0)) { + return; } =20 // @@ -430,7 +455,7 @@ PlatformGetSystemMemorySizeBelow4gb ( Cmos0x34 =3D (UINT8)PlatformCmosRead8 (0x34); Cmos0x35 =3D (UINT8)PlatformCmosRead8 (0x35); =20 - return (UINT32)(((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB); + PlatformInfoHob->LowMemory =3D (UINT32)(((UINTN)((Cmos0x35 << 8) + Cmos0= x34) << 16) + SIZE_16MB); } =20 STATIC @@ -966,7 +991,6 @@ PlatformQemuInitializeRam ( IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - UINT64 LowerMemorySize; UINT64 UpperMemorySize; MTRR_SETTINGS MtrrSettings; EFI_STATUS Status; @@ -976,7 +1000,7 @@ PlatformQemuInitializeRam ( // // Determine total memory size available // - LowerMemorySize =3D PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob= ); + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); =20 if (PlatformInfoHob->BootMode =3D=3D BOOT_ON_S3_RESUME) { // @@ -1010,14 +1034,14 @@ PlatformQemuInitializeRam ( UINT32 TsegSize; =20 TsegSize =3D PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; - PlatformAddMemoryRangeHob (BASE_1MB, LowerMemorySize - TsegSize); + PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - Ts= egSize); PlatformAddReservedMemoryBaseSizeHob ( - LowerMemorySize - TsegSize, + PlatformInfoHob->LowMemory - TsegSize, TsegSize, TRUE ); } else { - PlatformAddMemoryRangeHob (BASE_1MB, LowerMemorySize); + PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory); } =20 // @@ -1195,9 +1219,10 @@ PlatformQemuInitializeRamForS3 ( // Make sure the TSEG area that we reported as a reserved memory res= ource // cannot be used for reserved memory allocations. // + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); TsegSize =3D PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; BuildMemoryAllocationHob ( - PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob) - TsegSize, + PlatformInfoHob->LowMemory - TsegSize, TsegSize, EfiReservedMemoryType ); diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index 3e13c5d4b34f..9ab0342fd8c0 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -128,7 +128,6 @@ PlatformMemMapInitialization ( { UINT64 PciIoBase; UINT64 PciIoSize; - UINT32 TopOfLowRam; UINT64 PciExBarBase; UINT32 PciBase; UINT32 PciSize; @@ -150,7 +149,7 @@ PlatformMemMapInitialization ( return; } =20 - TopOfLowRam =3D PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); PciExBarBase =3D 0; if (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { // @@ -158,11 +157,11 @@ PlatformMemMapInitialization ( // the base of the 32-bit PCI host aperture. // PciExBarBase =3D PcdGet64 (PcdPciExpressBaseAddress); - ASSERT (TopOfLowRam <=3D PciExBarBase); + ASSERT (PlatformInfoHob->LowMemory <=3D PciExBarBase); ASSERT (PciExBarBase <=3D MAX_UINT32 - SIZE_256MB); PciBase =3D (UINT32)(PciExBarBase + SIZE_256MB); } else { - ASSERT (TopOfLowRam <=3D PlatformInfoHob->Uc32Base); + ASSERT (PlatformInfoHob->LowMemory <=3D PlatformInfoHob->Uc32Base); PciBase =3D PlatformInfoHob->Uc32Base; } =20 diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 3d8375320dcb..41d186986ba8 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -271,7 +271,8 @@ PublishPeiMemory ( UINT32 S3AcpiReservedMemoryBase; UINT32 S3AcpiReservedMemorySize; =20 - LowerMemorySize =3D PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob= ); + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); + LowerMemorySize =3D PlatformInfoHob->LowMemory; if (PlatformInfoHob->SmmSmramRequire) { // // TSEG is chipped from the end of low RAM --=20 2.39.0 -=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 (#98342): https://edk2.groups.io/g/devel/message/98342 Mute This Topic: https://groups.io/mt/96219467/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-