From nobody Tue May 14 22:28:20 2024 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+98340+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+98340+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673516070; cv=none; d=zohomail.com; s=zohoarc; b=QPQ3b3Rm5bZRXTxgLZW0RG0siT8J6bQtItEBOmylo7W6sdRcX07RwU85Nybw+bjq66v1j8hlyBMGXF7nx/1oRqPEsrsetqfa4pKyOj8nWMsoIcSyIu+77NEBns791yjxm6x2pj7nwlVqtPQJS0k9SE+Ka/l5/XqWOcF1qoOyoyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673516070; 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=QNlg32RY4jK7FZKHvcnAvRHGWOXaxWjSfli8fxEMA4k=; b=HbqmG+upxQiIDMWtSVT3hUN8uXMrRVbQhmYA/JTiYQE9CSmDFVNDUliYooEIhcIUE4U+WOEVszDQtSxPxCe2byko5AMen4+5zCOkyi+fzq9DDTDCcD+QX5u/t6CD77FP9H7akEbvHXshYOtzIv8dU/BqgXsUhW9ZrP/K31VNM80= 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+98340+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 1673516070976970.7602101701755; Thu, 12 Jan 2023 01:34:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SsozYY1788612xbykhjAsVse; Thu, 12 Jan 2023 01:34:30 -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.web10.50848.1673516069897899752 for ; Thu, 12 Jan 2023 01:34:30 -0800 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-pW0ZpI0VM1OLw0PAGjJklA-1; Thu, 12 Jan 2023 04:34:27 -0500 X-MC-Unique: pW0ZpI0VM1OLw0PAGjJklA-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49B523C10ED2; Thu, 12 Jan 2023 09:34:27 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D15BE2026D68; Thu, 12 Jan 2023 09:34:26 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 812281800936; 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 1/8] OvmfPkg/PlatformInitLib: Add PlatformScanE820 and GetFirstNonAddressCB Date: Thu, 12 Jan 2023 10:34:18 +0100 Message-Id: <20230112093425.1228300-2-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.4 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: 1akrqWB0Ip2zxOTQ3SYmDejgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516070; bh=485DV0AW/Bi59uK8O2L+9fbZWghgmJYk18ETZsVEY5Y=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=JXEzH8R/Mps7W861EHijHLN6UMJCMCCyMSkSvGr1gmNLHw21cOUYUYwrvUUSd9C1lVf 6G0GL9TPXjdiYC5ZZIKtKOLcLnQ1O8saVMQ8rfEqzZ2godQLQmRkFiZv5C17FuYtGoyAP VdV6Zzb1e7q3xEbGsrakEbzdA2hPv0yPWN0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516072865100002 Content-Type: text/plain; charset="utf-8"; x-default="true" First step replacing the PlatformScanOrAdd64BitE820Ram() function. Add a PlatformScanE820() function which loops over the e280 entries from FwCfg and calls a callback for each of them. Add a GetFirstNonAddressCB() function which will store the first free address (right after the last RAM block) in PlatformInfoHob->FirstNonAddress. This replaces calls to PlatformScanOrAdd64BitE820Ram() with non-NULL MaxAddress. Write any actions done (setting FirstNonAddress) to the firmware log with INFO loglevel. Also drop local FirstNonAddress variables and use PlatformInfoHob->FirstNonAddress instead everywhere. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 115 ++++++++++++++++---- 1 file changed, 92 insertions(+), 23 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 0c4956852689..dd98622de561 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -251,6 +251,83 @@ PlatformScanOrAdd64BitE820Ram ( return EFI_SUCCESS; } =20 +typedef VOID (*E820_SCAN_CALLBACK) ( + EFI_E820_ENTRY64 *E820Entry, + EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ); + +/** + Store first address not used by e820 RAM entries in + PlatformInfoHob->FirstNonAddress +**/ +VOID +PlatformGetFirstNonAddressCB ( + 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 (PlatformInfoHob->FirstNonAddress < Candidate) { + DEBUG ((DEBUG_INFO, "%a: FirstNonAddress=3D0x%Lx\n", __FUNCTION__, Can= didate)); + PlatformInfoHob->FirstNonAddress =3D Candidate; + } +} + +/** + Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the + passed callback for each entry. + + @param[in] Callback The callback function to be called. + + @param[in out] PlatformInfoHob PlatformInfo struct which is passed + through to the callback. + + @retval EFI_SUCCESS The fw_cfg E820 RAM map was found and p= rocessed. + + @retval EFI_PROTOCOL_ERROR The RAM map was found, but its size was= n't a + whole multiple of sizeof(EFI_E820_ENTRY= 64). No + RAM entry was processed. + + @return Error codes from QemuFwCfgFindFile(). N= o RAM + entry was processed. +**/ +STATIC +EFI_STATUS +PlatformScanE820 ( + IN E820_SCAN_CALLBACK Callback, + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + EFI_E820_ENTRY64 E820Entry; + UINTN Processed; + + Status =3D QemuFwCfgFindFile ("etc/e820", &FwCfgItem, &FwCfgSize); + if (EFI_ERROR (Status)) { + return Status; + } + + if (FwCfgSize % sizeof E820Entry !=3D 0) { + return EFI_PROTOCOL_ERROR; + } + + QemuFwCfgSelectItem (FwCfgItem); + for (Processed =3D 0; Processed < FwCfgSize; Processed +=3D sizeof E820E= ntry) { + QemuFwCfgReadBytes (sizeof E820Entry, &E820Entry); + Callback (&E820Entry, PlatformInfoHob); + } + + return EFI_SUCCESS; +} + /** Returns PVH memmap =20 @@ -384,23 +461,17 @@ PlatformGetSystemMemorySizeAbove4gb ( Return the highest address that DXE could possibly use, plus one. **/ STATIC -UINT64 +VOID PlatformGetFirstNonAddress ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - UINT64 FirstNonAddress; UINT32 FwCfgPciMmio64Mb; EFI_STATUS Status; FIRMWARE_CONFIG_ITEM FwCfgItem; UINTN FwCfgSize; UINT64 HotPlugMemoryEnd; =20 - // - // set FirstNonAddress to suppress incorrect compiler/analyzer warnings - // - FirstNonAddress =3D 0; - // // If QEMU presents an E820 map, then get the highest exclusive >=3D4GB = RAM // address from it. This can express an address >=3D 4GB+1TB. @@ -408,9 +479,10 @@ PlatformGetFirstNonAddress ( // 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 PlatformScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); + PlatformInfoHob->FirstNonAddress =3D BASE_4GB; + Status =3D PlatformScanE820 (PlatformGetFirstN= onAddressCB, PlatformInfoHob); if (EFI_ERROR (Status)) { - FirstNonAddress =3D BASE_4GB + PlatformGetSystemMemorySizeAbove4gb (); + PlatformInfoHob->FirstNonAddress =3D BASE_4GB + PlatformGetSystemMemor= ySizeAbove4gb (); } =20 // @@ -420,7 +492,7 @@ PlatformGetFirstNonAddress ( // #ifdef MDE_CPU_IA32 if (!FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { - return FirstNonAddress; + return; } =20 #endif @@ -473,7 +545,7 @@ PlatformGetFirstNonAddress ( // determines the highest address plus one. The memory hotplug area (s= ee // below) plays no role for the firmware in this case. // - return FirstNonAddress; + return; } =20 // @@ -497,15 +569,15 @@ PlatformGetFirstNonAddress ( HotPlugMemoryEnd )); =20 - ASSERT (HotPlugMemoryEnd >=3D FirstNonAddress); - FirstNonAddress =3D HotPlugMemoryEnd; + ASSERT (HotPlugMemoryEnd >=3D PlatformInfoHob->FirstNonAddress); + PlatformInfoHob->FirstNonAddress =3D HotPlugMemoryEnd; } =20 // // SeaBIOS aligns both boundaries of the 64-bit PCI host aperture to 1GB= , so // that the host can map it with 1GB hugepages. Follow suit. // - PlatformInfoHob->PcdPciMmio64Base =3D ALIGN_VALUE (FirstNonAddress, (UIN= T64)SIZE_1GB); + PlatformInfoHob->PcdPciMmio64Base =3D ALIGN_VALUE (PlatformInfoHob->Firs= tNonAddress, (UINT64)SIZE_1GB); PlatformInfoHob->PcdPciMmio64Size =3D ALIGN_VALUE (PlatformInfoHob->PcdP= ciMmio64Size, (UINT64)SIZE_1GB); =20 // @@ -519,8 +591,8 @@ PlatformGetFirstNonAddress ( // // The useful address space ends with the 64-bit PCI host aperture. // - FirstNonAddress =3D PlatformInfoHob->PcdPciMmio64Base + PlatformInfoHob-= >PcdPciMmio64Size; - return FirstNonAddress; + PlatformInfoHob->FirstNonAddress =3D PlatformInfoHob->PcdPciMmio64Base += PlatformInfoHob->PcdPciMmio64Size; + return; } =20 /* @@ -781,7 +853,6 @@ PlatformAddressWidthInitialization ( IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { - UINT64 FirstNonAddress; UINT8 PhysMemAddressWidth; EFI_STATUS Status; =20 @@ -794,7 +865,7 @@ PlatformAddressWidthInitialization ( // First scan host-provided hardware information to assess if the address // space is already known. If so, guest must use those values. // - Status =3D PlatformScanHostProvided64BitPciMmioEnd (&FirstNonAddress); + Status =3D PlatformScanHostProvided64BitPciMmioEnd (&PlatformInfoHob->Fi= rstNonAddress); =20 if (EFI_ERROR (Status)) { // @@ -806,13 +877,12 @@ PlatformAddressWidthInitialization ( // The DXL IPL keys off of the physical address bits advertized in the= CPU // HOB. To conserve memory, we calculate the minimum address width her= e. // - FirstNonAddress =3D PlatformGetFirstNonAddress (PlatformInfoHob); + PlatformGetFirstNonAddress (PlatformInfoHob); } =20 PlatformAddressWidthFromCpuid (PlatformInfoHob, TRUE); if (PlatformInfoHob->PhysMemAddressWidth !=3D 0) { // physical address width is known - PlatformInfoHob->FirstNonAddress =3D FirstNonAddress; PlatformDynamicMmioWindow (PlatformInfoHob); return; } @@ -823,13 +893,13 @@ PlatformAddressWidthInitialization ( // -> try be conservstibe to stay below the guaranteed minimum of // 36 phys bits (aka 64 GB). // - PhysMemAddressWidth =3D (UINT8)HighBitSet64 (FirstNonAddress); + PhysMemAddressWidth =3D (UINT8)HighBitSet64 (PlatformInfoHob->FirstNonAd= dress); =20 // // If FirstNonAddress is not an integral power of two, then we need an // additional bit. // - if ((FirstNonAddress & (FirstNonAddress - 1)) !=3D 0) { + if ((PlatformInfoHob->FirstNonAddress & (PlatformInfoHob->FirstNonAddres= s - 1)) !=3D 0) { ++PhysMemAddressWidth; } =20 @@ -857,7 +927,6 @@ PlatformAddressWidthInitialization ( ASSERT (PhysMemAddressWidth <=3D 48); #endif =20 - PlatformInfoHob->FirstNonAddress =3D FirstNonAddress; PlatformInfoHob->PhysMemAddressWidth =3D PhysMemAddressWidth; } =20 --=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 (#98340): https://edk2.groups.io/g/devel/message/98340 Mute This Topic: https://groups.io/mt/96219465/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- From nobody Tue May 14 22:28:20 2024 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- From nobody Tue May 14 22:28:20 2024 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+98343+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+98343+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=SUJwvzJoy5uuSuyUamIwviXZ1jFd6sMuxDdLlCXM0ZbxkiN0VSVDposV0BWzq0G+5R1hA6Yl7DkHX9w2XVMI6+WTpNAI7n0DHAByNBOdRbsTtozzMPxoR37MJgeC+6Cij7A5xT+hc2Yby2jpXKc2F0oyh6yjMuWaF2WxCgGAz5s= 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=YSCLXbVETGL0+h5J4goKvf3tiYr1nNjz+yiVo7OXbRE=; b=RMiymlDewBHQVdCOpT6EP//N77aZfaRU88x5XNbKvUbDZxKr7s1Hpw7inWwZRxqQnTIMdvr71xPNDq4tqXOzwaeQXRSTZgpLTwwa2bVqT/Z1vuX7IqdRniwvjLQrHsbRowTGMsIVu/2Q9qNQA8anF61zds+LWnb2Bt4efVowyFM= 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+98343+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 1673516074653755.2438475810857; Thu, 12 Jan 2023 01:34:34 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id DEZCYY1788612xuL2fiFf9as; Thu, 12 Jan 2023 01:34:34 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.51057.1673516073840903506 for ; Thu, 12 Jan 2023 01:34:34 -0800 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-26-Y73MveMcO5yxzR2bE1yZLA-1; Thu, 12 Jan 2023 04:34:29 -0500 X-MC-Unique: Y73MveMcO5yxzR2bE1yZLA-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D03C43C10EDF; 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 745A52026D68; Thu, 12 Jan 2023 09:34:28 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8A4B91800987; 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 3/8] OvmfPkg/PlatformInitLib: Add PlatformAddHobCB Date: Thu, 12 Jan 2023 10:34:20 +0100 Message-Id: <20230112093425.1228300-4-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.4 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: 9S8mcM8DMevQVOXe5kRBTB2vx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516074; bh=+LmrZo6kFNwnafFLMVshAs/C6y8t0E6hH1xOoyBx/2k=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=QaPJN0DRCC+Y3+h9gxElQKQbN2wBlKJEmkywwjXyBvaw5f7z6oXKxsoeb/vHDOF5Lx6 3upIp+reh+qPzLNKv0HtCsPJl0yixHPr+RdniJQiWoFzPnw+eaJx8XNTcitOdolFkHNhL 4z3NFO509AZ58xMvZI5mBWN6M7w6vMkzIAU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516074868100009 Content-Type: text/plain; charset="utf-8"; x-default="true" Add PlatformAddHobCB() callback function for use with PlatformScanE820(). It adds HOBs for high memory and reservations (low memory is handled elsewhere because there are some special cases to consider). This replaces calls to PlatformScanOrAdd64BitE820Ram() with AddHighHobs =3D TRUE. Write any actions done (adding HOBs, skip unknown types) to the firmware log with INFO loglevel. Also remove PlatformScanOrAdd64BitE820Ram() which is not used any more. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 185 +++++--------------- 1 file changed, 47 insertions(+), 138 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 153f958b76ee..8a3a197b5fa7 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -112,143 +112,6 @@ PlatformQemuUc32BaseInitialization ( } } =20 -/** - Iterate over the RAM entries in QEMU's fw_cfg E820 RAM map that start ou= tside - of the 32-bit address range. - - Find the highest exclusive >=3D4GB RAM address, or produce memory resour= ce - descriptor HOBs for RAM entries that start at or above 4GB. - - @param[out] MaxAddress If MaxAddress is NULL, then PlatformScanOrAdd64B= itE820Ram() - produces memory resource descriptor HOBs for RAM - entries that start at or above 4GB. - - Otherwise, MaxAddress holds the highest exclusive - >=3D4GB RAM address on output. If QEMU's fw_cfg = E820 - RAM map contains no RAM entry that starts outsid= e of - the 32-bit address range, then MaxAddress is exa= ctly - 4GB on output. - - @retval EFI_SUCCESS The fw_cfg E820 RAM map was found and proces= sed. - - @retval EFI_PROTOCOL_ERROR The RAM map was found, but its size wasn't a - whole multiple of sizeof(EFI_E820_ENTRY64). = No - RAM entry was processed. - - @return Error codes from QemuFwCfgFindFile(). No RAM - entry was processed. -**/ -STATIC -EFI_STATUS -PlatformScanOrAdd64BitE820Ram ( - IN BOOLEAN AddHighHob, - OUT UINT64 *LowMemory OPTIONAL, - OUT UINT64 *MaxAddress OPTIONAL - ) -{ - EFI_STATUS Status; - FIRMWARE_CONFIG_ITEM FwCfgItem; - UINTN FwCfgSize; - EFI_E820_ENTRY64 E820Entry; - UINTN Processed; - - Status =3D QemuFwCfgFindFile ("etc/e820", &FwCfgItem, &FwCfgSize); - if (EFI_ERROR (Status)) { - return Status; - } - - if (FwCfgSize % sizeof E820Entry !=3D 0) { - return EFI_PROTOCOL_ERROR; - } - - if (LowMemory !=3D NULL) { - *LowMemory =3D 0; - } - - if (MaxAddress !=3D NULL) { - *MaxAddress =3D BASE_4GB; - } - - QemuFwCfgSelectItem (FwCfgItem); - for (Processed =3D 0; Processed < FwCfgSize; Processed +=3D sizeof E820E= ntry) { - QemuFwCfgReadBytes (sizeof E820Entry, &E820Entry); - DEBUG (( - DEBUG_VERBOSE, - "%a: Base=3D0x%Lx Length=3D0x%Lx Type=3D%u\n", - __FUNCTION__, - E820Entry.BaseAddr, - E820Entry.Length, - E820Entry.Type - )); - if (E820Entry.Type =3D=3D EfiAcpiAddressRangeMemory) { - if (AddHighHob && (E820Entry.BaseAddr >=3D BASE_4GB)) { - UINT64 Base; - UINT64 End; - - // - // Round up the start address, and round down the end address. - // - Base =3D ALIGN_VALUE (E820Entry.BaseAddr, (UINT64)EFI_PAGE_SIZE); - End =3D (E820Entry.BaseAddr + E820Entry.Length) & - ~(UINT64)EFI_PAGE_MASK; - if (Base < End) { - PlatformAddMemoryRangeHob (Base, End); - DEBUG (( - DEBUG_VERBOSE, - "%a: PlatformAddMemoryRangeHob [0x%Lx, 0x%Lx)\n", - __FUNCTION__, - Base, - End - )); - } - } - - if (MaxAddress || LowMemory) { - UINT64 Candidate; - - Candidate =3D E820Entry.BaseAddr + E820Entry.Length; - if (MaxAddress && (Candidate > *MaxAddress)) { - *MaxAddress =3D Candidate; - DEBUG (( - DEBUG_VERBOSE, - "%a: MaxAddress=3D0x%Lx\n", - __FUNCTION__, - *MaxAddress - )); - } - - if (LowMemory && (Candidate > *LowMemory) && (Candidate < BASE_4GB= )) { - *LowMemory =3D Candidate; - DEBUG (( - DEBUG_VERBOSE, - "%a: LowMemory=3D0x%Lx\n", - __FUNCTION__, - *LowMemory - )); - } - } - } else if (E820Entry.Type =3D=3D EfiAcpiAddressRangeReserved) { - if (AddHighHob) { - DEBUG (( - DEBUG_INFO, - "%a: Reserved: Base=3D0x%Lx Length=3D0x%Lx\n", - __FUNCTION__, - E820Entry.BaseAddr, - E820Entry.Length - )); - BuildResourceDescriptorHob ( - EFI_RESOURCE_MEMORY_RESERVED, - 0, - E820Entry.BaseAddr, - E820Entry.Length - ); - } - } - } - - return EFI_SUCCESS; -} - typedef VOID (*E820_SCAN_CALLBACK) ( EFI_E820_ENTRY64 *E820Entry, EFI_HOB_PLATFORM_INFO *PlatformInfoHob @@ -304,6 +167,52 @@ PlatformGetLowMemoryCB ( } } =20 +/** + Create HOBs for reservations and RAM (except low memory). +**/ +STATIC VOID +PlatformAddHobCB ( + IN EFI_E820_ENTRY64 *E820Entry, + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + UINT64 Base, End; + + Base =3D E820Entry->BaseAddr; + End =3D E820Entry->BaseAddr + E820Entry->Length; + + switch (E820Entry->Type) { + case EfiAcpiAddressRangeMemory: + if (Base >=3D BASE_4GB) { + // + // Round up the start address, and round down the end address. + // + Base =3D ALIGN_VALUE (Base, (UINT64)EFI_PAGE_SIZE); + End =3D End & ~(UINT64)EFI_PAGE_MASK; + if (Base < End) { + DEBUG ((DEBUG_INFO, "%a: HighMemory [0x%Lx, 0x%Lx)\n", __FUNCTIO= N__, Base, End-1)); + PlatformAddMemoryRangeHob (Base, End); + } + } + + break; + case EfiAcpiAddressRangeReserved: + BuildResourceDescriptorHob (EFI_RESOURCE_MEMORY_RESERVED, 0, Base, E= nd); + DEBUG ((DEBUG_INFO, "%a: Reserved [0x%Lx, 0x%Lx)\n", __FUNCTION__, B= ase, End-1)); + break; + default: + DEBUG (( + DEBUG_WARN, + "%a: Type %u [0x%Lx, 0x%Lx) (NOT HANDLED)\n", + __FUNCTION__, + E820Entry->Type, + Base, + End-1 + )); + break; + } +} + /** Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the passed callback for each entry. @@ -1049,7 +958,7 @@ PlatformQemuInitializeRam ( // entries. Otherwise, create a single memory HOB with the flat >=3D4GB // memory size read from the CMOS. // - Status =3D PlatformScanOrAdd64BitE820Ram (TRUE, NULL, NULL); + Status =3D PlatformScanE820 (PlatformAddHobCB, PlatformInfoHob); if (EFI_ERROR (Status)) { UpperMemorySize =3D PlatformGetSystemMemorySizeAbove4gb (); if (UpperMemorySize !=3D 0) { --=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 (#98343): https://edk2.groups.io/g/devel/message/98343 Mute This Topic: https://groups.io/mt/96219468/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- From nobody Tue May 14 22:28:20 2024 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+98345+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+98345+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673516075; cv=none; d=zohomail.com; s=zohoarc; b=VCPtsGe+gdi3k5/49rkyRNc5UV/Dvmu9FOovy+JNXUoCR7gvxxSoeuXx5Sc4tOI99EXj5tbNwsteMV1zMi+1E76BSCTS7jKFnaCJgQ95Btx37LXQPkTGlWNzA2suzLo/ozSucaqq1rUmxnZWwQA5G+qHfHybbK9a6MgFxWs0qFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673516075; 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=EzRCM3CCRt68ihx6PXRyUvrzS3b3cT9nUk0WOSL8FoI=; b=h8SivgjsA4lV15Az22BPTveJkLEPrJXngdFasq4WoA5Ni+HOb7fZpwt11Rsmkvx1Ov5Otg2nR3L3W9VB1H+1iFG/WIWAcx3TRQcBiiZ7cDU7lKgerLbYgABT1MZ4bkOQCrs+TSLNs6IszjetvO+VBi03KgmjBmgbsdqX8Y+bx54= 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+98345+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 1673516075741243.35239953635505; Thu, 12 Jan 2023 01:34:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0N68YY1788612xGW2BTGVCnR; Thu, 12 Jan 2023 01:34:35 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.51058.1673516074591235654 for ; Thu, 12 Jan 2023 01:34:34 -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-326-FXbAjc6pP5CnE27B1cGaLg-1; Thu, 12 Jan 2023 04:34:30 -0500 X-MC-Unique: FXbAjc6pP5CnE27B1cGaLg-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 25531858F0E; Thu, 12 Jan 2023 09:34:30 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4B3A492C14; Thu, 12 Jan 2023 09:34:29 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8DF2E180098C; 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 4/8] OvmfPkg/PlatformInitLib: Add PlatformReservationConflictCB Date: Thu, 12 Jan 2023 10:34:21 +0100 Message-Id: <20230112093425.1228300-5-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: t1UQPM4CZrmG8OBazUmZdU92x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516075; bh=MLws4RWKr6fPEIVXcXHmPPfGPQuWtq/6OWMXm8ToxRA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=iuA3mtd8vbcGMaxlR2VVx72vHrDUofFlS6gW9AkbNhBs7jLo+q8VsNmwEGh0JebwZnZ kfR+u2nxUBc2TiGsDcjunIHSA8Sqib87TgP9vS8ouZEj/nxa+mYqKiyInjQC/bwKB95eB sqxZlxHOK4xnB5233+GyJqxQYCfYwpyrNAk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516076830100018 Content-Type: text/plain; charset="utf-8"; x-default="true" Add PlatformReservationConflictCB() callback function for use with PlatformScanE820(). It checks whenever the 64bit PCI MMIO window overlaps with a reservation from qemu. If so move down the MMIO window to resolve the conflict. Write any actions done (moving mmio window) to the firmware log with INFO loglevel. This happens on (virtual) AMD machines with 1TB address space, because the AMD IOMMU uses an address window just below 1TB. Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4251 Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 8a3a197b5fa7..9b273755aaeb 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -213,6 +213,46 @@ PlatformAddHobCB ( } } =20 +/** + Check whenever the 64bit PCI MMIO window overlaps with a reservation + from qemu. If so move down the MMIO window to resolve the conflict. + + This happens on (virtual) AMD machines with 1TB address space, + because the AMD IOMMU uses an address window just below 1TB. +**/ +STATIC VOID +PlatformReservationConflictCB ( + IN EFI_E820_ENTRY64 *E820Entry, + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + UINT64 IntersectionBase =3D MAX ( + E820Entry->BaseAddr, + PlatformInfoHob->PcdPciMmio64Base + ); + UINT64 IntersectionEnd =3D MIN ( + E820Entry->BaseAddr + E820Entry->Length, + PlatformInfoHob->PcdPciMmio64Base + + PlatformInfoHob->PcdPciMmio64Size + ); + UINT64 NewBase; + + if (IntersectionBase >=3D IntersectionEnd) { + return; // no overlap + } + + NewBase =3D (PlatformInfoHob->PcdPciMmio64Base - + PlatformInfoHob->PcdPciMmio64Size); + DEBUG (( + DEBUG_INFO, + "%a: move mmio: 0x%Lx =3D> %Lx\n", + __FUNCTION__, + PlatformInfoHob->PcdPciMmio64Base, + NewBase + )); + PlatformInfoHob->PcdPciMmio64Base =3D NewBase; +} + /** Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the passed callback for each entry. @@ -650,6 +690,7 @@ PlatformDynamicMmioWindow ( DEBUG ((DEBUG_INFO, "%a: MMIO Space 0x%Lx (%Ld GB)\n", __func__, Mmi= oSpace, RShiftU64 (MmioSpace, 30))); PlatformInfoHob->PcdPciMmio64Size =3D MmioSpace; PlatformInfoHob->PcdPciMmio64Base =3D AddrSpace - MmioSpace; + PlatformScanE820 (PlatformReservationConflictCB, PlatformInfoHob); } else { DEBUG ((DEBUG_INFO, "%a: using classic mmio window\n", __func__)); } --=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 (#98345): https://edk2.groups.io/g/devel/message/98345 Mute This Topic: https://groups.io/mt/96219470/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- From nobody Tue May 14 22:28:20 2024 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+98344+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+98344+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673516075; cv=none; d=zohomail.com; s=zohoarc; b=TI0vDP8ngAu6soWd4Ypi38lsRwB4+fXo1B/WrPW5tyOJdC+m8CP3qjJzIDCFFxawcPDIx01zKg2UYMzfMsNdckgafyW7qZqCZmjkZtyyEnKTTBpcE7lnEsCaNoM3BKGwTO1rcKU0X+ljxKZJ9gqNs0PxEjEeXWpvLFrDtdGRR8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673516075; 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=0kPy6F7EtcGuBNoh/xF4/xBnjZqiuIedeOF9l7hPanY=; b=ldXxsvldJ0Y+zrtOpDrdpDdKJ50PrpimHXCkVAB+VNwoI1ziLJsAYYrKMnSsKY8fj+RDdw1/VCuY0nzsZNW8+5j/qfYUFazEyechmxuMGvc2a5mziheFn8Ro2xuv33n1nK87uWZSMqigNIWXk3outB3eKHnNBaY43ASGDsuQrzo= 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+98344+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 167351607537780.14963019238314; Thu, 12 Jan 2023 01:34:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 11H2YY1788612x8cpCSvPEyq; Thu, 12 Jan 2023 01:34:35 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.50851.1673516074432497364 for ; Thu, 12 Jan 2023 01:34:34 -0800 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-138-4191XWFQPjy-9P28aE1K1w-1; Thu, 12 Jan 2023 04:34:30 -0500 X-MC-Unique: 4191XWFQPjy-9P28aE1K1w-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 3AD0C1C05EB6; Thu, 12 Jan 2023 09:34:30 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06836492C18; Thu, 12 Jan 2023 09:34:30 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 91719180098D; 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 5/8] OvmfPkg/PlatformInitLib: reorder PlatformQemuUc32BaseInitialization Date: Thu, 12 Jan 2023 10:34:22 +0100 Message-Id: <20230112093425.1228300-6-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: Gshvld7mBQuWTBXFI6UuA7lWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516075; bh=f6N5WGiMpYDs3dEhuekVu9dPqVWIbAfhTC9YnYOVfCY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=pD49gHXaVfypkH1Y8b+0EjXcAUO2uq8H8eoNkYwBnVqgcCBD5scWnL1I94pXgmS9lhh El7OqhS33kEnA9xVfEjwNKq7EECYI24ut+Yh9LiObbQVKmUpEEq2/H3jZMEq1UCeDvNIY pUK0nwTePnE/u03amEe4slipv2PRkUd3DdQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516076830100019 Content-Type: text/plain; charset="utf-8"; x-default="true" First handle the cases which do not need know the value of PlatformInfoHob->LowMemory (microvm and cloudhv). Then call PlatformGetSystemMemorySizeBelow4gb() to get LowMemory. Finally handle the cases (q35 and pc) which need to look at LowMemory, Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 9b273755aaeb..c51c0f9af15d 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -55,8 +55,15 @@ PlatformQemuUc32BaseInitialization ( return; } =20 + if (PlatformInfoHob->HostBridgeDevId =3D=3D CLOUDHV_DEVICE_ID) { + PlatformInfoHob->Uc32Size =3D CLOUDHV_MMIO_HOLE_SIZE; + PlatformInfoHob->Uc32Base =3D CLOUDHV_MMIO_HOLE_ADDRESS; + return; + } + + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); + if (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { - PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); ASSERT (PcdGet64 (PcdPciExpressBaseAddress) <=3D MAX_UINT32); ASSERT (PcdGet64 (PcdPciExpressBaseAddress) >=3D PlatformInfoHob->LowM= emory); =20 @@ -78,19 +85,12 @@ PlatformQemuUc32BaseInitialization ( return; } =20 - if (PlatformInfoHob->HostBridgeDevId =3D=3D CLOUDHV_DEVICE_ID) { - PlatformInfoHob->Uc32Size =3D CLOUDHV_MMIO_HOLE_SIZE; - PlatformInfoHob->Uc32Base =3D CLOUDHV_MMIO_HOLE_ADDRESS; - return; - } - ASSERT (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_82441_DEVICE_ID); // // On i440fx, start with the [LowerMemorySize, 4GB) range. Make sure one // 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. // - PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); PlatformInfoHob->Uc32Size =3D GetPowerOfTwo32 ((UINT32)(SIZE_4GB - Platf= ormInfoHob->LowMemory)); PlatformInfoHob->Uc32Base =3D (UINT32)(SIZE_4GB - PlatformInfoHob->Uc32S= ize); // --=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 (#98344): https://edk2.groups.io/g/devel/message/98344 Mute This Topic: https://groups.io/mt/96219469/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- From nobody Tue May 14 22:28:20 2024 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+98348+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+98348+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673516080; cv=none; d=zohomail.com; s=zohoarc; b=oAtl2v/+wGo9z0NDnocJg7HtFrDid2urP+Ib/7aFkVx8kYERf/ID7qebLWe03aH3nwxEsd7gAlFHt+KV0QDX881BYobfbwFzZFWTdQ25Z85QnPZ/6fE56cd38p8Fb+ypaglhs1Z+Qw1bhaB2QBNmPSZqGoHRp6lt/d6z6hwekWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673516080; 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=KM4aX+2O/GImDg8EAXMBbUsaNQUdq+wBeP0Sol/46eA=; b=VaW1Ou6B+5hZ7KaJL4eUIjoTlg/DtyoP7Tnz/mvVL/NCNedM433hvn2CG8hezIVqmWYS3aCnDGKJL+3CFGDmm+wk76GfqFaGYw2EtX6ny8Dx/nN5hVM9pHwWmDXuUPg9MFw9XcIHk7OlHxAfn0vDOEZZtI9sEwo33MUADcJVmYs= 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+98348+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 1673516080495677.0201374240397; Thu, 12 Jan 2023 01:34:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id e20sYY1788612xrCjEeoA3QV; Thu, 12 Jan 2023 01:34:40 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.51060.1673516079657486476 for ; Thu, 12 Jan 2023 01:34:39 -0800 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-rKb4lcgXMwemqasIoZNyFw-1; Thu, 12 Jan 2023 04:34:32 -0500 X-MC-Unique: rKb4lcgXMwemqasIoZNyFw-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3EFA2817232; Thu, 12 Jan 2023 09:34:31 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7376540C2064; Thu, 12 Jan 2023 09:34:31 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 94FAF18009B7; 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 6/8] OvmfPkg/PlatformInitLib: update address space layout comment Date: Thu, 12 Jan 2023 10:34:23 +0100 Message-Id: <20230112093425.1228300-7-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.1 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: bk0bw2uFrKaNKzKYvoXUPaW0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516080; bh=4E3zfxswvbwvQqVPkWeTUA22QoPxTZQusoSodZJhiX4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Zaeb2xjx5T7XQJRVc8MlfbXiZZ896F+IrcSGtAa2jFpyHhlfIj0MmP+bIE4gJefj1Mh m+CYQa8CGDCdqWltYx9m5JgKc/1myFVnC+FM1X+Pmv+1CEEDxs7uS6v9xB8L9wrKr7yoF OCesqRhtr5x63vQ5bz42MODTWVzqz3CSbhk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516082877100033 Content-Type: text/plain; charset="utf-8"; x-default="true" Move the commment up so it is placed just before the address space calculations start. Also add q35 memory layout. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/Platform.c | 36 ++++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index 9ab0342fd8c0..ea3e969ca061 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -149,26 +149,12 @@ PlatformMemMapInitialization ( return; } =20 - PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); - PciExBarBase =3D 0; - if (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { - // - // The MMCONFIG area is expected to fall between the top of low RAM and - // the base of the 32-bit PCI host aperture. - // - PciExBarBase =3D PcdGet64 (PcdPciExpressBaseAddress); - ASSERT (PlatformInfoHob->LowMemory <=3D PciExBarBase); - ASSERT (PciExBarBase <=3D MAX_UINT32 - SIZE_256MB); - PciBase =3D (UINT32)(PciExBarBase + SIZE_256MB); - } else { - ASSERT (PlatformInfoHob->LowMemory <=3D PlatformInfoHob->Uc32Base); - PciBase =3D PlatformInfoHob->Uc32Base; - } - // // address purpose size // ------------ -------- ------------------------- - // max(top, 2g) PCI MMIO 0xFC000000 - max(top, 2g) + // max(top, 2g) PCI MMIO 0xFC000000 - max(top, 2g) (pc) + // 0xB0000000 MMCONFIG 256 MB (q35) + // 0xC0000000 PCI MMIO 960 MB (q35) // 0xFC000000 gap 44 MB // 0xFEC00000 IO-APIC 4 KB // 0xFEC01000 gap 1020 KB @@ -178,6 +164,22 @@ PlatformMemMapInitialization ( // 0xFED20000 gap 896 KB // 0xFEE00000 LAPIC 1 MB // + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); + PciExBarBase =3D 0; + if (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { + // + // The MMCONFIG area is expected to fall between the top of low RAM and + // the base of the 32-bit PCI host aperture. + // + PciExBarBase =3D PcdGet64 (PcdPciExpressBaseAddress); + ASSERT (PlatformInfoHob->LowMemory <=3D PciExBarBase); + ASSERT (PciExBarBase <=3D MAX_UINT32 - SIZE_256MB); + PciBase =3D (UINT32)(PciExBarBase + SIZE_256MB); + } else { + ASSERT (PlatformInfoHob->LowMemory <=3D PlatformInfoHob->Uc32Base); + PciBase =3D PlatformInfoHob->Uc32Base; + } + PciSize =3D 0xFC000000 - PciBase; PlatformAddIoMemoryBaseSizeHob (PciBase, PciSize); =20 --=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 (#98348): https://edk2.groups.io/g/devel/message/98348 Mute This Topic: https://groups.io/mt/96219473/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- From nobody Tue May 14 22:28:20 2024 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+98346+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+98346+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673516078; cv=none; d=zohomail.com; s=zohoarc; b=ebWUHlj7+0CxscFhxUYHLZV+QR7qktETDqXqYzcZC7+dYb2yliyw4L65+yK9npKdVq0Kr0fPegHJ77XEqaWv2/3M9yc0HWrLieyoPK6fxLAwJoq1EIsPqiMTjo1onFjFn7fKV64w6xBa9SXs9QvJ38wCbi7yoEc2vv8gBfQuMuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673516078; 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=L9JahtLiX31GAo8p0uWIsEP8egLCjspCcN0K0OLSzTA=; b=nmWAHjw8qxjrvRQojbruyzwxOgI1Rb0iQorsuKJR95vOnVubYq6dsyc2DntHnLIwsqPItrK4mlIkeWjfzQVDN+quGZUIOyGzNIpjbXCeBxAnz3aTRSy0KyyAcibSW8njhf55DD7hd8mBtB+j1P8gk1CPyjOJl6Uufa+ISIzNhA4= 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+98346+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 1673516078476800.9935117355521; Thu, 12 Jan 2023 01:34:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8WxeYY1788612xqmpIx1YmC2; Thu, 12 Jan 2023 01:34:38 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.51059.1673516077563801473 for ; Thu, 12 Jan 2023 01:34:37 -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-672-PsiDBJC0OZOXPqKRvTF2wA-1; Thu, 12 Jan 2023 04:34:32 -0500 X-MC-Unique: PsiDBJC0OZOXPqKRvTF2wA-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D06C785A588; Thu, 12 Jan 2023 09:34:31 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74E392026D68; Thu, 12 Jan 2023 09:34:31 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 984DA1800D53; 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 7/8] OvmfPkg/PlatformInitLib: move mmconfig to 0xe0000000 Date: Thu, 12 Jan 2023 10:34:24 +0100 Message-Id: <20230112093425.1228300-8-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.4 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: ikAh1PvwARnwuULpkeq6m1Fbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516078; bh=Sfz26gdFJgYQDYDZBd2gHDiDDTmREJGDKccxRTZ55Ug=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=NHINQnRr3/pdR+1oXa1Ud0GTOSOvA1CJiTH3QX3NRIVSO3NsjFDNL4ccANDi5vvieTv Owq5rgKGN1nKS0oavMgOFCsXmc8nnAL2lA684jg/6GaO0DA/tEjQkZ06QkS772QiLaTuq MpG2ySnOK9cA+oqz1PRmxN2Jv7E2mpbbQSI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516078854100025 Content-Type: text/plain; charset="utf-8"; x-default="true" Also swap the ordering of 32bit PCI MMIO window on q35, i.e. use the room between end of low memory and the start of the mmconfig bar. With a typical configuration on modern qemu with gigabyte-aligned memory the MMIO window start at 0x8000000, sized 1532 MB. In case there is memory present above 0x80000000 the window will start at 0xc0000000 instead, with 512 MB size. Signed-off-by: Gerd Hoffmann --- OvmfPkg/AmdSev/AmdSevX64.dsc | 2 +- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 2 +- OvmfPkg/OvmfPkgIa32.dsc | 2 +- OvmfPkg/OvmfPkgIa32X64.dsc | 2 +- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/OvmfXen.dsc | 2 +- OvmfPkg/Library/PlatformInitLib/Platform.c | 10 +++++----- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 36100f5fdc11..0e1574959cd1 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -443,7 +443,7 @@ [PcdsFixedAtBuild] # # On Q35 machine types that QEMU intends to support in the long term, QE= MU # never lets the RAM below 4 GB exceed 2816 MB. - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xB0000000 + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000 =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 81511e3556a6..0ecf10ccb1f9 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -438,7 +438,7 @@ [PcdsFixedAtBuild] # # On Q35 machine types that QEMU intends to support in the long term, QE= MU # never lets the RAM below 4 GB exceed 2816 MB. - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xB0000000 + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000 =20 # # The NumberOfPages values below are ad-hoc. They are updated sporadical= ly at diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index f232de13a7b6..d2a66e4f6717 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -557,7 +557,7 @@ [PcdsFixedAtBuild] # # On Q35 machine types that QEMU intends to support in the long term, QE= MU # never lets the RAM below 4 GB exceed 2816 MB. - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xB0000000 + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000 =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index a9d422bd9169..4a76cd7a5d44 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -562,7 +562,7 @@ [PcdsFixedAtBuild] # # On Q35 machine types that QEMU intends to support in the long term, QE= MU # never lets the RAM below 4 GB exceed 2816 MB. - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xB0000000 + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000 =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 8401d7390005..3c1843069099 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -582,7 +582,7 @@ [PcdsFixedAtBuild] # # On Q35 machine types that QEMU intends to support in the long term, QE= MU # never lets the RAM below 4 GB exceed 2816 MB. - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xB0000000 + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000 =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index c328987e8432..18144d9a6d94 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -434,7 +434,7 @@ [PcdsFixedAtBuild] # # On Q35 machine types that QEMU intends to support in the long term, QE= MU # never lets the RAM below 4 GB exceed 2816 MB. - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xB0000000 + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000 =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/P= latformInitLib/Platform.c index ea3e969ca061..c756f9af30fe 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -153,8 +153,8 @@ PlatformMemMapInitialization ( // address purpose size // ------------ -------- ------------------------- // max(top, 2g) PCI MMIO 0xFC000000 - max(top, 2g) (pc) - // 0xB0000000 MMCONFIG 256 MB (q35) - // 0xC0000000 PCI MMIO 960 MB (q35) + // max(top, 2g) PCI MMIO 0xE0000000 - max(top, 2g) (q35) + // 0xE0000000 MMCONFIG 256 MB (q35) // 0xFC000000 gap 44 MB // 0xFEC00000 IO-APIC 4 KB // 0xFEC01000 gap 1020 KB @@ -165,6 +165,7 @@ PlatformMemMapInitialization ( // 0xFEE00000 LAPIC 1 MB // PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); + PciBase =3D PlatformInfoHob->Uc32Base; PciExBarBase =3D 0; if (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { // @@ -174,13 +175,12 @@ PlatformMemMapInitialization ( PciExBarBase =3D PcdGet64 (PcdPciExpressBaseAddress); ASSERT (PlatformInfoHob->LowMemory <=3D PciExBarBase); ASSERT (PciExBarBase <=3D MAX_UINT32 - SIZE_256MB); - PciBase =3D (UINT32)(PciExBarBase + SIZE_256MB); + PciSize =3D (UINT32)(PciExBarBase - PciBase); } else { ASSERT (PlatformInfoHob->LowMemory <=3D PlatformInfoHob->Uc32Base); - PciBase =3D PlatformInfoHob->Uc32Base; + PciSize =3D 0xFC000000 - PciBase; } =20 - PciSize =3D 0xFC000000 - PciBase; PlatformAddIoMemoryBaseSizeHob (PciBase, PciSize); =20 PlatformInfoHob->PcdPciMmio32Base =3D PciBase; --=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 (#98346): https://edk2.groups.io/g/devel/message/98346 Mute This Topic: https://groups.io/mt/96219471/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- From nobody Tue May 14 22:28:20 2024 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+98347+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+98347+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673516078; cv=none; d=zohomail.com; s=zohoarc; b=iFnnctbpblQ31+s0k5T8zwKUu9f5zdO+Kv1B0nz8mU3P17YlvqEDUmeBCbCKvsB/wIWCR2hmqhOd1khlCYj/CIe+b/ZduYTgc5qVy77eMo4JWaEEm+I4PSkqaa8b7PaWIH75SbAjVHRKvUHCsEZRoVGxYWy++aae2Oyf2odbXQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673516078; 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=aBM/8Vd+Syy9+plbAtgRbjFQgtx6E0A2i4Y5h0uEgW0=; b=S0PzIH03qN0j2Q66TnAcNwY82cTtq9Npe++BxikVn7j7McIm7wYI1JVZYV78Zer3BYVKuUwWwETcLV+OACBcpB7WMzp0C8CXX0ASd7CZGt170TtuG+iHaDUCwWZZt/U7VKNrVLc6u+ncmtge7tE6wrAD9yWaPEaMiR2sofaGR3k= 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+98347+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 1673516078861345.5822700445792; Thu, 12 Jan 2023 01:34:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jvJxYY1788612xNVM2eDRxv3; Thu, 12 Jan 2023 01:34:38 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.50852.1673516077610488146 for ; Thu, 12 Jan 2023 01:34:37 -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-22-Br_gJKZnMGyXdMZCUC5MLQ-1; Thu, 12 Jan 2023 04:34:33 -0500 X-MC-Unique: Br_gJKZnMGyXdMZCUC5MLQ-1 X-Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24EB2185A78B; Thu, 12 Jan 2023 09:34:33 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF5F4492B01; Thu, 12 Jan 2023 09:34:32 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 9B9831800D5E; 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 8/8] OvmfPkg/PlatformInitLib: simplify mtrr setup Date: Thu, 12 Jan 2023 10:34:25 +0100 Message-Id: <20230112093425.1228300-9-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.10 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: t6V2xjI8256ievbEvxmaArWyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673516078; bh=Um8P2yg63EhwEoXaiSSG6Brm8ebtlvJuGVKYU2/MgdE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=qDDCH9FL1Ng5i/qwkPCiINAlO5i8+Sf8uQYrYmhIHzn7PzZwL6o2YihSyoLWPeZrRmp BZb/VpRyKu2xPBBdnrX6p5b7LyGR4zy88RSBN4s1OIgYDHa+ANgugbaGpadKlE4sR3Q3w IjAF312E5dn5NjvD4uS/2ZTwS6t8EUWoR50= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673516080853100027 Content-Type: text/plain; charset="utf-8"; x-default="true" With the new mmconfig location at 0xe0000000 above the 32-bit PCI MMIO window we don't have to special-case the mmconfig xbar any more. We'll just add a mtrr uncachable entry starting at MMIO window base and ending at 4GB. Update comments to match reality. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 38 +++++++++------------ 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index c51c0f9af15d..3eaa8104cf55 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -61,33 +61,20 @@ PlatformQemuUc32BaseInitialization ( return; } =20 + ASSERT ( + PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID || + PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_82441_DEVICE_ID + ); + PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); =20 if (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { ASSERT (PcdGet64 (PcdPciExpressBaseAddress) <=3D MAX_UINT32); ASSERT (PcdGet64 (PcdPciExpressBaseAddress) >=3D PlatformInfoHob->LowM= emory); - - 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; - } else { - // - // On q35, the 32-bit area that we'll mark as UC, through variable M= TRRs, - // starts at PcdPciExpressBaseAddress. The platform DSC is responsib= le for - // setting PcdPciExpressBaseAddress such that describing the - // [PcdPciExpressBaseAddress, 4GB) range require a very small number= of - // variable MTRRs (preferably 1 or 2). - // - PlatformInfoHob->Uc32Base =3D (UINT32)PcdGet64 (PcdPciExpressBaseAdd= ress); - } - - return; } =20 - ASSERT (PlatformInfoHob->HostBridgeDevId =3D=3D INTEL_82441_DEVICE_ID); // - // On i440fx, start with the [LowerMemorySize, 4GB) range. Make sure one + // Start with the [LowerMemorySize, 4GB) range. Make sure one // 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. // @@ -1011,7 +998,7 @@ PlatformQemuInitializeRam ( // // We'd like to keep the following ranges uncached: // - [640 KB, 1 MB) - // - [LowerMemorySize, 4 GB) + // - [PlatformInfoHob->LowMemory, 4 GB) // // Everything else should be WB. Unfortunately, programming the inverse = (ie. // keeping the default UC, and configuring the complement set of the abo= ve as @@ -1019,6 +1006,13 @@ PlatformQemuInitializeRam ( // practically any alignment, and we may not have enough variable MTRRs = to // cover it exactly. // + // Because of that PlatformQemuUc32BaseInitialization() will round + // up PlatformInfoHob->LowMemory to make sure a single mtrr register + // is enough. The the result will be stored in + // PlatformInfoHob->Uc32Base. On a typical qemu configuration with + // gigabyte-alignment being used LowMemory will be 2 or 3 GB and no + // rounding is needed, so LowMemory and Uc32Base will be identical. + // if (IsMtrrSupported () && (PlatformInfoHob->HostBridgeDevId !=3D CLOUDHV= _DEVICE_ID)) { MtrrGetAllMtrrs (&MtrrSettings); =20 @@ -1048,8 +1042,8 @@ PlatformQemuInitializeRam ( ASSERT_EFI_ERROR (Status); =20 // - // Set the memory range from the start of the 32-bit MMIO area (32-bit= PCI - // MMIO aperture on i440fx, PCIEXBAR on q35) to 4GB as uncacheable. + // Set the memory range from the start of the 32-bit PCI MMIO + // aperture to 4GB as uncacheable. // Status =3D MtrrSetMemoryAttribute ( PlatformInfoHob->Uc32Base, --=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 (#98347): https://edk2.groups.io/g/devel/message/98347 Mute This Topic: https://groups.io/mt/96219472/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-