From nobody Mon Feb 9 01:47:27 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+80300+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+80300+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1631027441; cv=none; d=zohomail.com; s=zohoarc; b=GZ7Q0nbu5p1HNA6vIwGRB8joCq+fdFZw+1r/pz8CHlD42pynbPXU/HcAkRTNXs6ei/3NQiI4P39U9PboUE0syIkSNJ4NDib19oqR8z8jCMBiBiugCUjrJTL49WkgFD3eDhiqpsFlRH6JWDfCtVXzG7BgW5FJ4hDeqfi8NPS/pm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631027441; 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=QMGYW2gXqkzzaiN03/ETlxpRHSoyXwhFZEkYQ+RSlK4=; b=Wfs+XD9Qm8XHCTFObFK5b5F8K3pkr88WhCm85QvR0iPHOG6o0avRdkIj+i4L/ZqlN2SBIukJQg175h/eaWKoozgb45Co8leda+ItgDu0WwI/QYTZnloL2VAhHnJaeWjewZQY45r3E+BzlcNU5Sg0u/klfjP7T8YKB6BfDGDw6Eo= 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+80300+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1631027441867432.72644239417866; Tue, 7 Sep 2021 08:10:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4og4YY1788612xdpEg7OJcsU; Tue, 07 Sep 2021 08:10:41 -0700 X-Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by mx.groups.io with SMTP id smtpd.web08.11837.1630766529733325108 for ; Sat, 04 Sep 2021 07:42:09 -0700 X-IronPort-AV: E=Sophos;i="5.85,268,1624320000"; d="scan'208";a="145980319" X-Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-27fb8269.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP; 04 Sep 2021 14:42:02 +0000 X-Received: from EX13D49EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1e-27fb8269.us-east-1.amazon.com (Postfix) with ESMTPS id 7EF6BA1E17 for ; Sat, 4 Sep 2021 14:42:01 +0000 (UTC) X-Received: from ub4014a598e6c52.ant.amazon.com (10.43.162.52) by EX13D49EUC003.ant.amazon.com (10.43.164.91) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sat, 4 Sep 2021 14:41:58 +0000 From: "Nicolas Ojeda Leon via groups.io" To: CC: Nicolas Ojeda Leon , Alexander Graf Subject: [edk2-devel] [PATCH 2/5] OvmfPkg/PciHostBridgeUtilityLib: Initialize RootBridges apertures with spec Date: Sat, 4 Sep 2021 16:37:53 +0200 Message-ID: <60082b721c455f0762bdf4fd96c3544f7cdfb0c3.1630676569.git.ncoleon@amazon.com> In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.43.162.52] X-ClientProxiedBy: EX13D16UWC001.ant.amazon.com (10.43.162.117) 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: lxnVOWv8xFwkIL6L7OahRlbax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1631027441; bh=6dxWC+KsrEm5s7AylKYOx26RgN9aUW915mvu/VGUiac=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=QDBPRkOwTBVisljmK/57WOGO2d+mUFFIVI5nLgy/sefFDG+fwkpH4t2aO1fZdKzKs0w 5utOOZ989Hxrj+KK9Yt+7R7TXOa2CN5vIhyN5o9Btmg4fUh1E1OHcPwNS5Fvsi3cBZuO6 p59wTW7uQw9582i0fY8aXqOOJavJ/lZhSKI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1631027443015100007 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Considering the "host-bridge-info" item from fw-cfg, the apertures for all root bridges are initialized and used in the creation of the root bridge objects that determine the resources each host bridge can use. PCI MMIO apertures are merged to produce a single low memory and a single high memory apertures matching current Ovmf allocation strategy which includes the EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM attribute. Prefetchable and non-prefetchable ranges are merged together to produce a single aperture covering both ranges. Therefore, if both prefetchable and non-prefetchable apertures are defined for one of the address spaces (32-bit or 64-bit), these 2 must be contiguous. For platforms having multiple PCI host bridges, hypervisor builds and propagates the resource specification (MMIO apertures) for each of the host bridges over fw-cfg. These specifications determine the usable windows in low and high memory, overwriting any calculated range and providing both control for the hypervisor to configure the apertures as well as possibility to use multiple host bridges. Signed-off-by: Nicolas Ojeda Leon Cc: Alexander Graf --- .../PciHostBridgeUtilityLib.c | 128 +++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLi= b.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c index d2296f3308..7567da8423 100644 --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c @@ -18,6 +18,7 @@ #include #include #include +#include #include =20 =20 @@ -186,6 +187,66 @@ PciHostBridgeUtilityUninitRootBridge ( FreePool (RootBus->DevicePath); } =20 +/** + Interpret the MMIO resources in HostBridge and set the apertures + in 32-bit space (Mem) and 64-bit space (MemABove4G) accordingly. + + The 2 types of apertures in each space (prefetchable and + non-prefetchable) are merged into a single window, hence if both + types of apertures are defined for a root bridges, these must be + contiguous. + + @param[in] HostBridge Root bridge's resources specification + + @param[out] Mem 32-bit MMIO aperture + + @param[out] MemAbove4G 64-bit MMIO aperture +**/ +STATIC +VOID +InitRootBridgeApertures ( + IN HOST_BRIDGE_INFO *HostBridge, + OUT PCI_ROOT_BRIDGE_APERTURE *Mem, + OUT PCI_ROOT_BRIDGE_APERTURE *MemAbove4G + + ) +{ + if (HostBridge =3D=3D NULL || Mem =3D=3D NULL || MemAbove4G =3D=3D NULL)= { + return; + } + + MemAbove4G->Base =3D MAX_UINT64; + MemAbove4G->Limit =3D 0; + + if (HostBridge->highmem_start !=3D MAX_UINT64 && + HostBridge->highmem_end !=3D MAX_UINT64) { + MemAbove4G->Base =3D HostBridge->highmem_start; + MemAbove4G->Limit =3D HostBridge->highmem_end; + } + + if (HostBridge->highmem_pref_start !=3D MAX_UINT64 && + HostBridge->highmem_pref_end !=3D MAX_UINT64) { + if (HostBridge->highmem_pref_start < MemAbove4G->Base) + MemAbove4G->Base =3D HostBridge->highmem_pref_start; + + if (HostBridge->highmem_pref_end > MemAbove4G->Limit) + MemAbove4G->Limit =3D HostBridge->highmem_pref_end; + } + + // + // Check if prefetchable range is valid and merge both ranges into a sin= gle + // 32-bit aperture. + // In case both prefetchable and non-prefetchable ranges are defined, + // these must be contiguous. + // + Mem->Base =3D HostBridge->lowmem_start; + if (HostBridge->lowmem_pref_end !=3D MAX_UINT32) { + Mem->Limit =3D HostBridge->lowmem_pref_end; + } else { + Mem->Limit =3D HostBridge->lowmem_end; + } +} + =20 /** Utility function to return all the root bridge instances in an array. @@ -241,6 +302,7 @@ PciHostBridgeUtilityGetRootBridges ( UINTN Initialized; UINTN LastRootBridgeNumber; UINTN RootBridgeNumber; + HOST_BRIDGE_INFO *RootBridgesInfo; =20 *Count =3D 0; =20 @@ -277,13 +339,54 @@ PciHostBridgeUtilityGetRootBridges ( __FUNCTION__, ExtraRootBridges)); } =20 + // + // Initialize RootBridgeInfo pointer, so in case no fw-cfg item is found + // the default configuration is used. + // + RootBridgesInfo =3D NULL; + Initialized =3D 0; + Bridges =3D NULL; + + // + // Hypervisor can provide, over fw-cfg, resource specifications for one = or + // more PCI host bridges. + // + Status =3D QemuFwCfgFindFile ("etc/host-bridge-info", &FwCfgItem, &FwCfg= Size); + + if (!EFI_ERROR (Status)) { + UINTN RootBridgesInfoSize =3D (1 + (UINTN)ExtraRootBridges) * + sizeof(HOST_BRIDGE_INFO); + RootBridgesInfo =3D AllocatePool (RootBridgesInfoSize); + + if (RootBridgesInfo =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, + "%a: Failed to allocate memory for resources info\n", __FUNCTION__= )); + return NULL; + } + + // + // Read the resource information of all Root Bridges from fw-cfg + // + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (FwCfgSize, RootBridgesInfo); + + if (FwCfgSize !=3D RootBridgesInfoSize) { + DEBUG ((DEBUG_ERROR, + "%a: Invalid HostBridgeInfo fw-cfg item size. Expected %ld, got %l= d\n", + __FUNCTION__, RootBridgesInfoSize, FwCfgSize)); + goto FreeBridges; + } + DEBUG ((DEBUG_INFO, "%a: Resources for %Lu root buses found in fw-cfg\= n", + __FUNCTION__, ExtraRootBridges + 1)); + } + // // Allocate the "main" root bridge, and any extra root bridges. // Bridges =3D AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridge= s); if (Bridges =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES)); - return NULL; + goto FreeBridges; } Initialized =3D 0; =20 @@ -309,6 +412,11 @@ PciHostBridgeUtilityGetRootBridges ( } } if (Device <=3D PCI_MAX_DEVICE) { + // + // If resources obtained from fw-cfg, use those values + // + InitRootBridgeApertures(&RootBridgesInfo[Initialized], Mem, MemAbove= 4G); + // // Found the next root bus. We can now install the *previous* one, // because now we know how big a bus number range *that* one has, fo= r any @@ -341,6 +449,8 @@ PciHostBridgeUtilityGetRootBridges ( // Install the last root bus (which might be the only, ie. main, root bu= s, if // we've found no extra root buses). // + InitRootBridgeApertures(&RootBridgesInfo[Initialized], Mem, MemAbove4G); + Status =3D PciHostBridgeUtilityInitRootBridge ( Attributes, Attributes, @@ -362,6 +472,14 @@ PciHostBridgeUtilityGetRootBridges ( ++Initialized; =20 *Count =3D Initialized; + + // + // If resources were allocated for host bridges info, release them + // + if (RootBridgesInfo) { + FreePool(RootBridgesInfo); + } + return Bridges; =20 FreeBridges: @@ -370,7 +488,13 @@ FreeBridges: PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]); } =20 - FreePool (Bridges); + if (Bridges) { + FreePool (Bridges); + } + + if (RootBridgesInfo) { + FreePool(RootBridgesInfo); + } return NULL; } =20 --=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 (#80300): https://edk2.groups.io/g/devel/message/80300 Mute This Topic: https://groups.io/mt/85437210/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-