From nobody Mon Feb 9 00:55:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+85874+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+85874+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1642702648; cv=none; d=zohomail.com; s=zohoarc; b=AS+AvXzxVM+U18KvQoimnP+JU5mQznRYVeIkYOlfmaBeq3+VkRL1dGcdhTAyeMLfZND+VHPudFaxuwAEq+toiy8CVgDJZE5cL/JKmgAd8OjN++wLQa9/ivZVdkOwiBNmV0jssZJ7MKW/ljMFGp8AmRaxDwE2wk6Tk5RneOW6Jbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642702648; h=Content-Type: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=0qSBGmhoE93UfrpQSAPxpCig+3pDM5L4MNd7WIc1GQI=; b=as+8MTRyxaxDjr3fbkaCzc4iM64uP3+A9IWHPJPRYXbMZPvZMcX2UsQmfznLMf6tk+Ew3WpVVTgOmKnsh5u+voiEi19Oxh1xl9u/haRNpXS7nzjBLVXkacAwjPxQs7voAPeElEqYNcCX5uEUx74jIbyMwt+6a9QtkymhEubVKDg= 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+85874+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1642702648893717.7022405765318; Thu, 20 Jan 2022 10:17:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id vJw5YY1788612x4wnK4kbhVI; Thu, 20 Jan 2022 10:17:28 -0800 X-Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by mx.groups.io with SMTP id smtpd.web10.15136.1642698761974239638 for ; Thu, 20 Jan 2022 09:12:42 -0800 X-IronPort-AV: E=Sophos;i="5.88,302,1635206400"; d="scan'208";a="56730530" X-Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-54a073b7.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP; 20 Jan 2022 17:12:40 +0000 X-Received: from EX13D49EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-54a073b7.us-east-1.amazon.com (Postfix) with ESMTPS id 026B990F1E; Thu, 20 Jan 2022 17:12:38 +0000 (UTC) X-Received: from ub4014a598e6c52.ant.amazon.com (10.43.162.8) by EX13D49EUC003.ant.amazon.com (10.43.164.91) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Thu, 20 Jan 2022 17:12:35 +0000 From: "Ojeda Leon, Nicolas via groups.io" To: CC: , Nicolas Ojeda Leon , Alexander Graf , Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 4/8] Ovmf/PlatformPei: Extend 64-bit MMIO range to fit resources Date: Thu, 20 Jan 2022 18:10:17 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.43.162.8] X-ClientProxiedBy: EX13D12UWA004.ant.amazon.com (10.43.160.168) To EX13D49EUC003.ant.amazon.com (10.43.164.91) 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,ncoleon@amazon.com X-Gm-Message-State: Gkz5lBD5zYMHHjgFn94Q4oFFx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1642702648; bh=kE1l+dGMgXz4DhN3K9pQg7OBpUVuOgnbaw9jg1+VoSg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=YrAA9HyBlJjghpI+41t+h1mdihzqMukyxWCTHWfc3t16gxadr+dHNivHiQyBQRBp2Og ToRPww66RA3Uq/uuKwEUlpyn2O3IZq7ZVdxHekJG2eUiFhqs81lFaMNR+bRiwdsOZHtdL 8Jq9WXaIi8UWXOkyDrDrC4Dqw8Cc0GdWJGI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1642702651161100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Read the "hardware-info" item from fw-cfg to extract specifications of PCI host bridges and analyze the 64-bit apertures of them to find out if 64-bit PCI size needs to be increased in order to allocate enough address space to fit all the host bridges in a valid region. Using the static Hardware Info Lib API, read the fw-cfg file of hardware information to extract, one by one, all the host bridges. Find the last 64-bit MMIO address of each host bridge, using the HardwareInfoPciHostBridgeLib API, and compare it to an accumulate value to discover the highest address used, which corresponds to the highest value that must be covered by the 64-bit PCI MMIO window. Given that platforms with multiple host bridges may provide the PCI apertures' addresses, the PCD token used to initialize the available address space (PcdPciMmio64Size) must include those addresses for the allocation process to be able to place resources in the intended regions. Since the Pcd entry defining the 64-bit PCI MMIO size is dynamic and initialized with a platform-dependent value, it is updated to a higher value if that is required for all high memory PCI host bridge apertures to fit in the valid address space. As an example, if the PcdPciMmio64Size is initialized to 0x800000000 and the runtime calculated base address produces the value 0x800000000, the last 64-bit MMIO address a PCI host bridge may use would be 0xFFFFFFFFF. If one of the host-specified bridges defines a high memory window 0x1000000000 - 0x17FFFFFFFF (inclusive) it would be outside of the valid range defined by the Base address + PcdPciMmio64Size. Therefore, parsing the HardwwareInfo resource allows to notice the higher requirement and increase the size to 0x1000000000 so that the MMIO address space solicited by the host can be met and the range effectively extended to 0x17FFFFFFFF. Cc: Alexander Graf Cc: Gerd Hoffmann Signed-off-by: Nicolas Ojeda Leon --- OvmfPkg/PlatformPei/MemDetect.c | 110 ++++++++++++++++++++++++++++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + 2 files changed, 111 insertions(+) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 1bcb5a08bc..b0bdd435cb 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -36,6 +36,7 @@ Module Name: #include #include #include +#include =20 #include "Platform.h" #include "Cmos.h" @@ -369,6 +370,110 @@ GetSystemMemorySizeAbove4gb ( return LShiftU64 (Size, 16); } =20 +/** + Iterate over the PCI host bridges resources information optionally provi= ded + in fw-cfg. + + Find the highest address used by the PCI bridges in 64-bit MMIO space to + calculate and modify the PCI aperture size accordingly (PciMmio64Size) + + @param[in] PciMmio64Base Base address (start) of the 64-bit PCI MMIO + address space. + + @param[inout] PciMmio64Size Size of the PCI 64-bit MMIO aperture provided + as input and modified (output) if the resour= ces + indicated by fw_cfg require a larger address + space. + + @retval EFI_SUCCESS The fw_cfg host-bridges-info was found and + processed. + + @retval EFI_PROTOCOL_ERROR The host bridges information file was found, + but its size wasn't a whole multiple of + sizeof(HOST_BRIDGE_INFO). No entry was proce= ssed. + + @retval EFI_NOT_FOUND fw-cfg file with host bridges information wa= s not + found. Does not constitute an errro since th= e file + is optional and used in special cases. + + @retval EFI_UNSUPPORTED fw-cfg is unavailable + +**/ +STATIC +EFI_STATUS +ScanPci64BitApertureSize ( + IN UINT64 PciMmio64Base, + IN OUT UINT64 *PciMmio64Size + ) +{ + EFI_STATUS Status; + HOST_BRIDGE_INFO HostBridge; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + UINTN FwCfgReadIndex; + UINTN ReadDataSize; + UINT64 PciEnd; + UINT64 PcdPciEnd; + UINT64 Above4GMmioEnd; + + PciEnd =3D 0; + Above4GMmioEnd =3D 0; + PcdPciEnd =3D PciMmio64Base + *PciMmio64Size - 1; + + Status =3D QemuFwCfgFindFile ("etc/hardware-info", &FwCfgItem, &FwCfgSiz= e); + if (EFI_ERROR (Status)) { + return Status; + } + + QemuFwCfgSelectItem (FwCfgItem); + + FwCfgReadIndex =3D 0; + while (FwCfgReadIndex < FwCfgSize) { + Status =3D QemuFwCfgReadNextHardwareInfoByType ( + HardwareInfoTypeHostBridge, + sizeof (HostBridge), + FwCfgSize, + &HostBridge, + &ReadDataSize, + &FwCfgReadIndex + ); + + if (Status !=3D EFI_SUCCESS) { + // + // No more data available to read in the file, break + // loop and finish process + // + break; + } + + Status =3D HardwareInfoPciHostBridgeLastMmioAddress ( + &HostBridge, + ReadDataSize, + TRUE, + &Above4GMmioEnd + ); + + if (Status !=3D EFI_SUCCESS) { + // + // Error parsing MMIO apertures and extracting last MMIO + // address, bail out and propagate error + // + return Status; + } + + if (Above4GMmioEnd > PciEnd) { + PciEnd =3D Above4GMmioEnd; + } + } + + if (PciEnd > PcdPciEnd) { + *PciMmio64Size =3D PciEnd - PciMmio64Base + 1; + *PciMmio64Size =3D ALIGN_VALUE (*PciMmio64Size, (UINT64)SIZE_1GB); + } + + return EFI_SUCCESS; +} + /** Return the highest address that DXE could possibly use, plus one. **/ @@ -515,6 +620,11 @@ GetFirstNonAddress ( // Pci64Base =3D ALIGN_VALUE (Pci64Base, GetPowerOfTwo64 (Pci64Size)); =20 + // + // Extend Pci64Size if fw_cfg Host bridges specification requires it + // + ScanPci64BitApertureSize (Pci64Base, &Pci64Size); + if (mBootMode !=3D BOOT_ON_S3_RESUME) { // // The core PciHostBridgeDxe driver will automatically add this range = to diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 8ef404168c..413b92b855 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -64,6 +64,7 @@ MemEncryptSevLib PcdLib VmgExitLib + QemuFwCfgHardwareInfoLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase --=20 2.17.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 -=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 (#85874): https://edk2.groups.io/g/devel/message/85874 Mute This Topic: https://groups.io/mt/88565405/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-