From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Wed, 29 May 2019 08:12:43 -0700 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 425E5309B15E; Wed, 29 May 2019 15:12:43 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-170.rdu2.redhat.com [10.10.120.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C8531715C; Wed, 29 May 2019 15:12:41 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Ard Biesheuvel , Gerd Hoffmann , Jordan Justen Subject: [PATCH for-edk2-stable201905 6/6] OvmfPkg/PlatformPei: set 32-bit UC area at PciBase / PciExBarBase (pc/q35) Date: Wed, 29 May 2019 17:12:09 +0200 Message-Id: <20190529151209.17503-7-lersek@redhat.com> In-Reply-To: <20190529151209.17503-1-lersek@redhat.com> References: <20190529151209.17503-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 29 May 2019 15:12:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable (This is a replacement for commit 39b9a5ffe661 ("OvmfPkg/PlatformPei: fix MTRR for low-RAM sizes that have many bits clear", 2019-05-16).) Reintroduce the same logic as seen in commit 39b9a5ffe661 for the pc (i440fx) board type. For q35, the same approach doesn't work any longer, given that (a) we'd like to keep the PCIEXBAR in the platform DSC a fixed-at-build PCD, and (b) QEMU expects the PCIEXBAR to reside at a lower address than the 32-bi= t PCI MMIO aperture. Therefore, introduce a helper function for determining the 32-bit "uncacheable" (MMIO) area base address: - On q35, this function behaves statically. Furthermore, the MTRR setup exploits that the range [0xB000_0000, 0xFFFF_FFFF] can be marked UC wit= h just two variable MTRRs (one at 0xB000_0000 (size 256MB), another at 0xC000_0000 (size 1GB)). - On pc (i440fx), the function behaves dynamically, implementing the same logic as commit 39b9a5ffe661 did. The PciBase value is adjusted to the value calculated, similarly to commit 39b9a5ffe661. A further simplification is that we show that the UC32 area size truncation to a whole power of two automatically guarantees a >=3D2GB base address. Cc: Ard Biesheuvel Cc: Gerd Hoffmann Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1859 Signed-off-by: Laszlo Ersek --- OvmfPkg/PlatformPei/Platform.h | 7 +++ OvmfPkg/PlatformPei/MemDetect.c | 59 ++++++++++++++++++-- OvmfPkg/PlatformPei/Platform.c | 5 +- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platfor= m.h index 81af8b71480f..2f3cebcd3a6a 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -62,6 +62,11 @@ GetSystemMemorySizeBelow4gb ( VOID ); =20 +VOID +QemuUc32BaseInitialization ( + VOID + ); + VOID InitializeRamRegions ( VOID @@ -114,4 +119,6 @@ extern UINT32 mMaxCpuCount; =20 extern UINT16 mHostBridgeDevId; =20 +extern UINT32 mQemuUc32Base; + #endif // _PLATFORM_PEI_H_INCLUDED_ diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDet= ect.c index e890e36408a6..d451989f31c9 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -14,6 +14,7 @@ Module Name: // The package level header files this module uses // #include +#include #include #include =20 @@ -42,6 +43,8 @@ STATIC UINT32 mS3AcpiReservedMemorySize; =20 STATIC UINT16 mQ35TsegMbytes; =20 +UINT32 mQemuUc32Base; + VOID Q35TsegMbytesInitialization ( VOID @@ -98,6 +101,54 @@ Q35TsegMbytesInitialization ( } =20 =20 +VOID +QemuUc32BaseInitialization ( + VOID + ) +{ + UINT32 LowerMemorySize; + UINT32 Uc32Size; + + if (mXen) { + return; + } + + if (mHostBridgeDevId =3D=3D INTEL_Q35_MCH_DEVICE_ID) { + // + // 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). + // + ASSERT (FixedPcdGet64 (PcdPciExpressBaseAddress) <=3D MAX_UINT32); + mQemuUc32Base =3D (UINT32)FixedPcdGet64 (PcdPciExpressBaseAddress); + return; + } + + ASSERT (mHostBridgeDevId =3D=3D INTEL_82441_DEVICE_ID); + // + // On i440fx, start with the [LowerMemorySize, 4GB) range. Make sure o= ne + // variable MTRR suffices by truncating the size to a whole power of t= wo, + // while keeping the end affixed to 4GB. This will round the base up. + // + LowerMemorySize =3D GetSystemMemorySizeBelow4gb (); + Uc32Size =3D GetPowerOfTwo32 ((UINT32)(SIZE_4GB - LowerMemorySize)); + mQemuUc32Base =3D (UINT32)(SIZE_4GB - Uc32Size); + // + // Assuming that LowerMemorySize is at least 1 byte, Uc32Size is at mo= st 2GB. + // Therefore mQemuUc32Base is at least 2GB. + // + ASSERT (mQemuUc32Base >=3D BASE_2GB); + + if (mQemuUc32Base !=3D LowerMemorySize) { + DEBUG ((DEBUG_VERBOSE, "%a: rounded UC32 base from 0x%x up to 0x%x, = for " + "an UC32 size of 0x%x\n", __FUNCTION__, LowerMemorySize, mQemuUc32= Base, + Uc32Size)); + } +} + + /** Iterate over the RAM entries in QEMU's fw_cfg E820 RAM map that start = outside of the 32-bit address range. @@ -688,11 +739,11 @@ QemuInitializeRam ( ASSERT_EFI_ERROR (Status); =20 // - // Set memory range from the "top of lower RAM" (RAM below 4GB) to 4= GB as - // uncacheable + // Set the memory range from the start of the 32-bit MMIO area (32-b= it PCI + // MMIO aperture on i440fx, PCIEXBAR on q35) to 4GB as uncacheable. // - Status =3D MtrrSetMemoryAttribute (LowerMemorySize, - SIZE_4GB - LowerMemorySize, CacheUncacheable); + Status =3D MtrrSetMemoryAttribute (mQemuUc32Base, SIZE_4GB - mQemuUc= 32Base, + CacheUncacheable); ASSERT_EFI_ERROR (Status); } } diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platfor= m.c index 0876316eefbc..3ba2459872d9 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -191,7 +191,8 @@ MemMapInitialization ( ASSERT (PciExBarBase <=3D MAX_UINT32 - SIZE_256MB); PciBase =3D (UINT32)(PciExBarBase + SIZE_256MB); } else { - PciBase =3D (TopOfLowRam < BASE_2GB) ? BASE_2GB : TopOfLowRam; + ASSERT (TopOfLowRam <=3D mQemuUc32Base); + PciBase =3D mQemuUc32Base; } =20 // @@ -650,6 +651,8 @@ InitializePlatform ( =20 PublishPeiMemory (); =20 + QemuUc32BaseInitialization (); + InitializeRamRegions (); =20 if (mXen) { --=20 2.19.1.3.g30247aa5d201