From nobody Wed Nov 27 04:49:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+41630+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41630+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559142765; cv=none; d=zoho.com; s=zohoarc; b=i1azk2TrgT1u7uZiRinbzE6+wEYLoO8atK3uwgTYogrFKWPunUwH7DPwuilyxfBBhQznSIt6WXYo28gKZtWgg+n3XIXkLMldgICYaaO2F+EEXhLJjEJlyRZIk+GOYmJ6d71KREFTSA+tk0Mmspue71xJHMtR/qIQhA2ZAISyuQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559142765; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=88P8P8g/aT8F40rwYv/2tDwjzt5eukSyNS6n+RL5vsg=; b=XaViIsE3GI1kKdxgM5IXm2BCYpv1qCQ2iAm8oV1ZxIQ1Pd+5GLjLIj9GcbMelNUC7diyGL54F/ABwgu1r73zZociwKHDCKxxOZq9lrcTLn8x40+DqwifyPJmPXRTb4sp0f/KXDCaFCMfZqGyQ6RyIcgY60EYYu3oPk/mJmY285w= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41630+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1559142765004964.4583582065417; Wed, 29 May 2019 08:12:45 -0700 (PDT) Return-Path: X-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 X-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) X-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: [edk2-devel] [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) Precedence: Bulk List-Unsubscribe: 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,lersek@redhat.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1559142764; bh=v7QH/cjgEZJb/t6Fn7AHB6vsyWgWEB/BVUtXk/K8r80=; h=Cc:Date:From:Reply-To:Subject:To; b=F+KjAHHlxZpamMIDkg12dlrxUyfXUN0/eqti6ptNdYthrOOru08Jh09YZib8BsOzpYj QX5C7PKB+uJaGCXaqQAJKA4uqU3gfbyRdQLPnJ5V8JAeGSf5LAlCAuLdriTkyqtjy7+2B 0ZvOtnD1dZZoJiAciV4/lavlGfa4Chto1c0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" (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-bit 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 with 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 Reviewed-by: Philippe Mathieu-Daude --- 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/Platform.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/MemDetec= t.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 MTR= Rs, + // starts at PcdPciExpressBaseAddress. The platform DSC is responsible= 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 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. + // + 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 most= 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, fo= r " + "an UC32 size of 0x%x\n", __FUNCTION__, LowerMemorySize, mQemuUc32Ba= se, + Uc32Size)); + } +} + + /** Iterate over the RAM entries in QEMU's fw_cfg E820 RAM map that start ou= tside 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 4GB= as - // uncacheable + // 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. // - Status =3D MtrrSetMemoryAttribute (LowerMemorySize, - SIZE_4GB - LowerMemorySize, CacheUncacheable); + Status =3D MtrrSetMemoryAttribute (mQemuUc32Base, SIZE_4GB - mQemuUc32= Base, + CacheUncacheable); ASSERT_EFI_ERROR (Status); } } diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.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 -=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 (#41630): https://edk2.groups.io/g/devel/message/41630 Mute This Topic: https://groups.io/mt/31834722/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-