From nobody Tue May 7 11:04:05 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+67181+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+67181+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1604930193; cv=none; d=zohomail.com; s=zohoarc; b=Ciqj1FMRBEIVZ6Jnqs/HnFHSmnca62ml0nnKoKQ9pDg1xZ6J+UJR1Ent3c0X5a5xRKsrs3AcrS1gw2MJjwMbxwQcFxHJBwjaEnVtdGVbz7ubLlhDqCwiynpPvnsOhU3PG3gtesJVlrL4QTM/aWbB89agTIUy6qwtsS/UqFCuPwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604930193; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5nHUOeS75x/XzQ3Jgnw1hIgLKf48/b2NWcL4/qKKqd0=; b=JSKL+cSQzQytctNWJQLn9tF1UnsPz79btq/LOktRrS3DhoBfixNbqhGtpJuOlSpr/ZHYdDxDwIa09iBjjkt/nb26Yhm+rttcVP4h+gnnpGV/vgn/mtqX5FQ/yaJmfIVs7cihEKE8mV2hAS4bF3hTO29VknA3PHrSr6P+YcHD+9Q= 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+67181+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160493019385131.761408135085958; Mon, 9 Nov 2020 05:56:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6XluYY1788612xOPFLVopBb5; Mon, 09 Nov 2020 05:56:33 -0800 X-Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mx.groups.io with SMTP id smtpd.web12.11068.1604927139151975976 for ; Mon, 09 Nov 2020 05:05:39 -0800 X-Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CVB7D6rCzz71bk; Mon, 9 Nov 2020 21:05:28 +0800 (CST) X-Received: from localhost (10.174.184.155) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 21:05:25 +0800 From: "Jiahui Cen via groups.io" To: CC: , , , , , , Jiahui Cen Subject: [edk2-devel] [PATCH v2 1/4] OvmfPkg: Extract functions form PciHostBridgeLib Date: Mon, 9 Nov 2020 21:05:08 +0800 Message-ID: <20201109130511.5946-2-cenjiahui@huawei.com> In-Reply-To: <20201109130511.5946-1-cenjiahui@huawei.com> References: <20201109130511.5946-1-cenjiahui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.184.155] X-CFilter-Loop: Reflected 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,cenjiahui@huawei.com X-Gm-Message-State: OVe3wJv80cw7ppQk5hQnLOuxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604930193; bh=NWmCNFLcqrlQHuaJ54GPEYCN4xNv8Zu4uh5ERYqPH8E=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wVnpORXHR3eRh7NIEPBh/GCjtZ4+A5k91wRUSwHUOxsvkMNDAeLtZmJPKJ5gVWP06/E 8kyySnw0/7kypJOF/mKO9qB3xb/8yslF8kTN6SdYI2AGYRlQr5/6PuAZOvLMJ6rlDBGy+ 8gemF7Nxv4QTLgunLtMFVmGJbMyRY+TQ6m4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Yubo Miao Introduce a new PciHostBridgeUtilityLib class to share duplicate code between OvmfPkg and ArmVirtPkg. Extract function PciHostBridgeResourceConflict from OvmfPkg/PciHostBridgeLib. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Yubo Miao Signed-off-by: Jiahui Cen --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 + OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 49 += ++++++++++++ OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 33 += ++++++++ OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 64 += ---------------- OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 74 += +++++++++++++++++++ 9 files changed, 162 insertions(+), 63 deletions(-) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 58d9f292f9ac..0c2bf0b13c34 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -738,6 +738,7 @@ [Components] PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 3551f9710a6c..baf36a4f7a54 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -752,6 +752,7 @@ [Components.X64] PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 7a8bdb8a8697..219b5f559b53 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -748,6 +748,7 @@ [Components] PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 34c9de19dfba..442c0730ef32 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -544,6 +544,7 @@ [Components] PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPk= g/Library/PciHostBridgeLib/PciHostBridgeLib.inf index 6ec9ec751478..7d01528c94f1 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf @@ -41,6 +41,7 @@ [LibraryClasses] MemoryAllocationLib PciLib QemuFwCfgLib + PciHostBridgeUtilityLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLi= b.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf new file mode 100644 index 000000000000..c88ab8e4155d --- /dev/null +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf @@ -0,0 +1,49 @@ +## @file +# OVMF and Arm's instance of the PCI Host Bridge Utility Library. +# +# Copyright (C) 2016, Red Hat, Inc. +# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PciHostBridgeUtilityLib + FILE_GUID =3D e3aa5932-527a-42e7-86f5-81b144c7e5f1 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PciHostBridgeUtilityLib + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + PciHostBridgeUtilityLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + DevicePathLib + MemoryAllocationLib + PciLib + QemuFwCfgLib + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase + gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Base + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/In= clude/Library/PciHostBridgeUtilityLib.h new file mode 100644 index 000000000000..d2622fd907e6 --- /dev/null +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h @@ -0,0 +1,33 @@ +/** @file + PCI Host Bridge Library consumed by PciHostBridgeDxe driver returning + the platform specific information about the PCI Host Bridge. + + Copyright (c) 2016, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#ifndef __PCI_HOST_BRIDGE_UTILITY_LIB_H__ +#define __PCI_HOST_BRIDGE_UTILITY_LIB_H__ + +/** + Inform the platform that the resource conflict happens. + + @param HostBridgeHandle Handle of the Host Bridge. + @param Configuration Pointer to PCI I/O and PCI memory resource + descriptors. The Configuration contains the reso= urces + for all the root bridges. The resource for each = root + bridge is terminated with END descriptor and an + additional END is appended indicating the end of= the + entire resources. The resource descriptor field + values follow the description in + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL + .SubmitResources(). +**/ +VOID +EFIAPI +PciHostBridgeResourceConflict ( + EFI_HANDLE HostBridgeHandle, + VOID *Configuration + ); + +#endif diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/= Library/PciHostBridgeLib/PciHostBridgeLib.c index e850f7d183ee..1c8f465834f3 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "PciHostBridge.h" =20 =20 @@ -33,12 +34,6 @@ typedef struct { #pragma pack () =20 =20 -GLOBAL_REMOVE_IF_UNREFERENCED -CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D { - L"Mem", L"I/O", L"Bus" -}; - - STATIC CONST OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate =3D { @@ -384,60 +379,3 @@ PciHostBridgeFreeRootBridges ( =20 FreePool (Bridges); } - - -/** - Inform the platform that the resource conflict happens. - - @param HostBridgeHandle Handle of the Host Bridge. - @param Configuration Pointer to PCI I/O and PCI memory resource - descriptors. The Configuration contains the reso= urces - for all the root bridges. The resource for each = root - bridge is terminated with END descriptor and an - additional END is appended indicating the end of= the - entire resources. The resource descriptor field - values follow the description in - EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL - .SubmitResources(). -**/ -VOID -EFIAPI -PciHostBridgeResourceConflict ( - EFI_HANDLE HostBridgeHandle, - VOID *Configuration - ) -{ - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; - UINTN RootBridgeIndex; - DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n")); - - RootBridgeIndex =3D 0; - Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration; - while (Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR) { - DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); - for (; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descript= or++) { - ASSERT (Descriptor->ResType < - ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr) - ); - DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n", - mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType= ], - Descriptor->AddrLen, Descriptor->AddrRangeMax - )); - if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) { - DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %02x= %s\n", - Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag, - ((Descriptor->SpecificFlag & - EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETC= HABLE - ) !=3D 0) ? L" (Prefetchable)" : L"" - )); - } - } - // - // Skip the END descriptor for root bridge - // - ASSERT (Descriptor->Desc =3D=3D ACPI_END_TAG_DESCRIPTOR); - Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)( - (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1 - ); - } -} diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLi= b.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c new file mode 100644 index 000000000000..7e9512dc08f1 --- /dev/null +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c @@ -0,0 +1,74 @@ +/** @file + OVMF's instance of the PCI Host Bridge Library. + + Copyright (c) 2020, Huawei Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include + + +GLOBAL_REMOVE_IF_UNREFERENCED +CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D { + L"Mem", L"I/O", L"Bus" +}; + + +/** + Inform the platform that the resource conflict happens. + + @param HostBridgeHandle Handle of the Host Bridge. + @param Configuration Pointer to PCI I/O and PCI memory resource + descriptors. The Configuration contains the reso= urces + for all the root bridges. The resource for each = root + bridge is terminated with END descriptor and an + additional END is appended indicating the end of= the + entire resources. The resource descriptor field + values follow the description in + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL + .SubmitResources(). +**/ +VOID +EFIAPI +PciHostBridgeResourceConflict ( + EFI_HANDLE HostBridgeHandle, + VOID *Configuration + ) +{ + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; + UINTN RootBridgeIndex; + DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n")); + + RootBridgeIndex =3D 0; + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration; + while (Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR) { + DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); + for (; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descript= or++) { + ASSERT (Descriptor->ResType < + ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr) + ); + DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n", + mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType= ], + Descriptor->AddrLen, Descriptor->AddrRangeMax + )); + if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) { + DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %02x= %s\n", + Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag, + ((Descriptor->SpecificFlag & + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETC= HABLE + ) !=3D 0) ? L" (Prefetchable)" : L"" + )); + } + } + // + // Skip the END descriptor for root bridge + // + ASSERT (Descriptor->Desc =3D=3D ACPI_END_TAG_DESCRIPTOR); + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)( + (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1 + ); + } +} + --=20 2.28.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 (#67181): https://edk2.groups.io/g/devel/message/67181 Mute This Topic: https://groups.io/mt/78135579/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 7 11:04:05 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+67182+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+67182+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1604930195; cv=none; d=zohomail.com; s=zohoarc; b=GUc6zuM0fsHZ9mGs4hoXU0yrjGdeUP6T4b7e2qAmHbosmYRVyJTBkgRXq5xNWvsXgk5TYJ5r/J0dJRLwox0UFIKoH5/wI1nH61Xt7eutMyqbSOhtEU4adA1kXBcpOcAxgCjrBdJt+NefwUxuZT2qzj4CIARNm599zeaZlJoDTZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604930195; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=F79SX4FgXFnsnm2qiE7hkAO3GLhwdkcO0p8Q7RHlSUY=; b=RW/lmbnsuDTomdRtm9+kGDZ6BzwFkipNTw+rXc9QSDv6Uva8NGKuzq8h99+jUxalZ339ZPLtrTq5JGuGkYKtHdQYmSlVyp5Sfz5gVuI3KqITa6v0hdhYDXK+XocmKQUAgKleWGRvZyX6F3Qi/QARQzpX7+CpDyCNwDxijSNe3ao= 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+67182+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1604930195412257.2966367750953; Mon, 9 Nov 2020 05:56:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id iX7ZYY1788612xRoI2uppBRC; Mon, 09 Nov 2020 05:56:35 -0800 X-Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mx.groups.io with SMTP id smtpd.web09.11106.1604927139399831901 for ; Mon, 09 Nov 2020 05:05:39 -0800 X-Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CVB7G4R43z71hX; Mon, 9 Nov 2020 21:05:30 +0800 (CST) X-Received: from localhost (10.174.184.155) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 21:05:26 +0800 From: "Jiahui Cen via groups.io" To: CC: , , , , , , Jiahui Cen Subject: [edk2-devel] [PATCH v2 2/4] ArmVirtPkg: Use extracted PciHostBridgeUtilityLib Date: Mon, 9 Nov 2020 21:05:09 +0800 Message-ID: <20201109130511.5946-3-cenjiahui@huawei.com> In-Reply-To: <20201109130511.5946-1-cenjiahui@huawei.com> References: <20201109130511.5946-1-cenjiahui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.184.155] X-CFilter-Loop: Reflected 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,cenjiahui@huawei.com X-Gm-Message-State: BHPBSDjw4716fEauzcI7wCorx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604930195; bh=kWRuT8K6qgD7Ci+rRLuyGsTFsYSQlfuebVabjMWooBM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=o+gNIQuuWKqEtpqZMtx1vDAii0KQ3p3SxyZLp3jc/DeIsqIWV9h8MGAOajCTOyIliVV /S4f5QlwSGwziv/Kz5qsmU5eak7/gei/0ygTN5jxclz00cIxsyFMZreQX+GK3NSHJl7vL jlhiqBuXwriUj6BH7kTQoVlazFH32S4KjQ4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Yubo Miao Eliminate the currently duplicated code in ArmVirtPkg and use the extracted PciHostBridgeResourceConflict from PciHostBridgeUtilityLib. Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Leif Lindholm Signed-off-by: Yubo Miao Signed-off-by: Jiahui Cen --- ArmVirtPkg/ArmVirt.dsc.inc | 1 + ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 2 + ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 61 +-----= -------------- 3 files changed, 4 insertions(+), 60 deletions(-) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 4dafd1fa0f1d..593a523171ff 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -144,6 +144,7 @@ [LibraryClasses.common] PciCapLib|OvmfPkg/Library/BasePciCapLib/BasePciCapLib.inf PciCapPciSegmentLib|OvmfPkg/Library/BasePciCapPciSegmentLib/BasePciCapPc= iSegmentLib.inf PciCapPciIoLib|OvmfPkg/Library/UefiPciCapPciIoLib/UefiPciCapPciIoLib.inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostB= ridgeUtilityLib.inf =20 # USB Libraries UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf= b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf index 277ccfd24546..97e9368c8e9f 100644 --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf @@ -31,6 +31,7 @@ [Packages] ArmVirtPkg/ArmVirtPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] DebugLib @@ -38,6 +39,7 @@ [LibraryClasses] DxeServicesTableLib MemoryAllocationLib PciPcdProducerLib + PciHostBridgeUtilityLib =20 [FixedPcd] gArmTokenSpaceGuid.PcdPciMmio32Translation diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b= /ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c index 496b192d2291..3952f511b4d2 100644 --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 #include #include @@ -51,9 +52,6 @@ STATIC EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeD= evicePath =3D { }; =20 GLOBAL_REMOVE_IF_UNREFERENCED -CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D { - L"Mem", L"I/O", L"Bus" -}; =20 // // We expect the "ranges" property of "pci-host-ecam-generic" to consist of @@ -414,60 +412,3 @@ PciHostBridgeFreeRootBridges ( ASSERT (Count =3D=3D 1); } =20 -/** - Inform the platform that the resource conflict happens. - - @param HostBridgeHandle Handle of the Host Bridge. - @param Configuration Pointer to PCI I/O and PCI memory resource - descriptors. The Configuration contains the reso= urces - for all the root bridges. The resource for each = root - bridge is terminated with END descriptor and an - additional END is appended indicating the end of= the - entire resources. The resource descriptor field - values follow the description in - EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL - .SubmitResources(). -**/ -VOID -EFIAPI -PciHostBridgeResourceConflict ( - EFI_HANDLE HostBridgeHandle, - VOID *Configuration - ) -{ - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; - UINTN RootBridgeIndex; - DEBUG ((EFI_D_ERROR, "PciHostBridge: Resource conflict happens!\n")); - - RootBridgeIndex =3D 0; - Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration; - while (Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR) { - DEBUG ((EFI_D_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); - for (; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descript= or++) { - ASSERT (Descriptor->ResType < - (sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) / - sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0]) - ) - ); - DEBUG ((EFI_D_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n", - mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType= ], - Descriptor->AddrLen, Descriptor->AddrRangeMax - )); - if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) { - DEBUG ((EFI_D_ERROR, " Granularity/SpecificFlag =3D %ld / %02x= %s\n", - Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag, - ((Descriptor->SpecificFlag & - EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETC= HABLE - ) !=3D 0) ? L" (Prefetchable)" : L"" - )); - } - } - // - // Skip the END descriptor for root bridge - // - ASSERT (Descriptor->Desc =3D=3D ACPI_END_TAG_DESCRIPTOR); - Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)( - (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1 - ); - } -} --=20 2.28.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 (#67182): https://edk2.groups.io/g/devel/message/67182 Mute This Topic: https://groups.io/mt/78135580/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 7 11:04:05 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+67183+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+67183+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1604930202; cv=none; d=zohomail.com; s=zohoarc; b=Zxve5+tutxyXaUqNFFCaNrXBL6CxZWDUx+QyVmZdpn+fCMRzc8bAl2eXJRo0sw2OfVeeBjMEyHQRSzPIIIPWGXTOKZSRX92vdUepl3EOc0q8gJxkJx356I1JuEKrm95mvZSBwKfxriclDQFlzrJ+5E1BrFVytbsgr3honhrfAEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604930202; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5H7hSaYWR0wI7rkiGMUlmu7v8dm0WXEy073deBLaLUo=; b=U22DCIx1XEewQvri3JfwMF4z4WalNKfh7AYBB0LW4lEU4TXKNWajymA7cn0ZCxhb4Fj5/kf6mODUbucYiCXmL4lho/Gxy9lza8kFpqoAYtB8UQgNif1icEyW0wkak1y9C64658gzKHH0ca4AHh82W8lAE2wQdZP9PnlkVTengZg= 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+67183+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1604930202986979.9931668125699; Mon, 9 Nov 2020 05:56:42 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id EmU8YY1788612xvHwWFEyLvs; Mon, 09 Nov 2020 05:56:42 -0800 X-Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mx.groups.io with SMTP id smtpd.web08.11083.1604927140021831663 for ; Mon, 09 Nov 2020 05:05:41 -0800 X-Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CVB7G2Cz3z15RLf; Mon, 9 Nov 2020 21:05:30 +0800 (CST) X-Received: from localhost (10.174.184.155) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 21:05:27 +0800 From: "Jiahui Cen via groups.io" To: CC: , , , , , , Jiahui Cen Subject: [edk2-devel] [PATCH v2 3/4] OvmfPkg: Extract functions of extra pci roots Date: Mon, 9 Nov 2020 21:05:10 +0800 Message-ID: <20201109130511.5946-4-cenjiahui@huawei.com> In-Reply-To: <20201109130511.5946-1-cenjiahui@huawei.com> References: <20201109130511.5946-1-cenjiahui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.184.155] X-CFilter-Loop: Reflected 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,cenjiahui@huawei.com X-Gm-Message-State: Fs936i7YVp3oatKSr3lYusrEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604930202; bh=4sfLz/Wv9phcIKpO/OEWS159t5sbDGVIpLmv1lCHo7E=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UXz1NUhDxbjJm52tYb28LI7+/GVuoR0dgGgrBTjhvOcgKn1/Aqu8USoI8jt1/+ooGWe UoJ0As7c8kLD2u22QHWNh00n/5yJoPYj/tPUjigjSpyGm2J/k0XyCmWMjU4aaPzDZFCJM YkEVMVulklKROPt8fvwvZ0o4rpDOJm5N/uA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Yubo Miao To use extra pci roots in other lib, it is necessary to extract UninitRootBridge, PciHostBridgeFreeRootBridges and PciHostBridgeExtraRoots from Ovmf/PciHostBridgeLib. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Yubo Miao Signed-off-by: Jiahui Cen --- OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 2 + OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 65 = ++++++ OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 170 = ++-------------- OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 209 = ++++++++++++++++++++ 4 files changed, 287 insertions(+), 159 deletions(-) diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLi= b.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf index c88ab8e4155d..1a667870ee2f 100644 --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf @@ -28,6 +28,7 @@ [Sources] PciHostBridgeUtilityLib.c =20 [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 @@ -38,6 +39,7 @@ [LibraryClasses] MemoryAllocationLib PciLib QemuFwCfgLib + PciHostBridgeLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/In= clude/Library/PciHostBridgeUtilityLib.h index d2622fd907e6..35fe237b0801 100644 --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h @@ -9,6 +9,71 @@ #ifndef __PCI_HOST_BRIDGE_UTILITY_LIB_H__ #define __PCI_HOST_BRIDGE_UTILITY_LIB_H__ =20 +/** + Uninitialize a PCI_ROOT_BRIDGE structure set up with InitRootBridge(). + + param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the calle= r and + initialized with InitRootBridge(), that should be + uninitialized. This function doesn't free RootBus. +**/ +VOID +UninitRootBridge ( + IN PCI_ROOT_BRIDGE *RootBus + ); + +/** + Free the root bridge instances array returned from + PciHostBridgeGetRootBridges(). + + @param The root bridge instances array. + @param The count of the array. +**/ +VOID +EFIAPI +PciHostBridgeFreeRootBridges ( + PCI_ROOT_BRIDGE *Bridges, + UINTN Count + ); + +/** + Return all the root bridge instances in an array. + + @param Count Return the count of root bridge instances. + + @param[in] PMem Prefetchable MMIO aperture. + + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G. + + @param[in] BusMax The max bus number. + + @param[in] Attributes Initial attributes. + + @param[in] AllocAttributes Allocation attributes. + + @param[in] Io IO aperture. + + @param[in] Mem MMIO aperture. + + @param[in] MemAbove4G MMIO aperture above 4G. + + @return All the root bridge instances in an array. + The array should be passed into PciHostBridgeFreeRootBridges() + when it's not used. +**/ +PCI_ROOT_BRIDGE * +EFIAPI +PciHostBridgeExtraRoots ( + UINTN *Count, + PCI_ROOT_BRIDGE_APERTURE PMem, + PCI_ROOT_BRIDGE_APERTURE PMemAbove4G, + UINT32 BusMax, + UINT64 Attributes, + UINT64 AllocationAttributes, + PCI_ROOT_BRIDGE_APERTURE Io, + PCI_ROOT_BRIDGE_APERTURE Mem, + PCI_ROOT_BRIDGE_APERTURE MemAbove4G +); + /** Inform the platform that the resource conflict happens. =20 diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/= Library/PciHostBridgeLib/PciHostBridgeLib.c index 1c8f465834f3..cd9896bee14b 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -159,24 +159,6 @@ InitRootBridge ( return EFI_SUCCESS; } =20 - -/** - Uninitialize a PCI_ROOT_BRIDGE structure set up with InitRootBridge(). - - param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the calle= r and - initialized with InitRootBridge(), that should be - uninitialized. This function doesn't free RootBus. -**/ -STATIC -VOID -UninitRootBridge ( - IN PCI_ROOT_BRIDGE *RootBus - ) -{ - FreePool (RootBus->DevicePath); -} - - /** Return all the root bridge instances in an array. =20 @@ -192,14 +174,7 @@ PciHostBridgeGetRootBridges ( UINTN *Count ) { - EFI_STATUS Status; - FIRMWARE_CONFIG_ITEM FwCfgItem; - UINTN FwCfgSize; - UINT64 ExtraRootBridges; PCI_ROOT_BRIDGE *Bridges; - UINTN Initialized; - UINTN LastRootBridgeNumber; - UINTN RootBridgeNumber; UINT64 Attributes; UINT64 AllocationAttributes; PCI_ROOT_BRIDGE_APERTURE Io; @@ -239,143 +214,20 @@ PciHostBridgeGetRootBridges ( =20 *Count =3D 0; =20 - // - // QEMU provides the number of extra root buses, shortening the exhausti= ve - // search below. If there is no hint, the feature is missing. - // - Status =3D QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgS= ize); - if (EFI_ERROR (Status) || FwCfgSize !=3D sizeof ExtraRootBridges) { - ExtraRootBridges =3D 0; - } else { - QemuFwCfgSelectItem (FwCfgItem); - QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges); - - if (ExtraRootBridges > PCI_MAX_BUS) { - DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) " - "reported by QEMU\n", __FUNCTION__, ExtraRootBridges)); - return NULL; - } - DEBUG ((DEBUG_INFO, "%a: %Lu extra root buses reported by QEMU\n", - __FUNCTION__, ExtraRootBridges)); - } - - // - // 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; - } - Initialized =3D 0; - - // - // The "main" root bus is always there. - // - LastRootBridgeNumber =3D 0; - - // - // Scan all other root buses. If function 0 of any device on a bus retur= ns a - // VendorId register value different from all-bits-one, then that bus is - // alive. - // - for (RootBridgeNumber =3D 1; - RootBridgeNumber <=3D PCI_MAX_BUS && Initialized < ExtraRootBridges; - ++RootBridgeNumber) { - UINTN Device; - - for (Device =3D 0; Device <=3D PCI_MAX_DEVICE; ++Device) { - if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0, - PCI_VENDOR_ID_OFFSET)) !=3D MAX_UINT16) { - break; - } - } - if (Device <=3D PCI_MAX_DEVICE) { - // - // 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 - // subordinate buses that might exist behind PCI bridges hanging off= it. - // - Status =3D InitRootBridge ( - Attributes, - Attributes, - AllocationAttributes, - (UINT8) LastRootBridgeNumber, - (UINT8) (RootBridgeNumber - 1), - &Io, - &Mem, - &MemAbove4G, - &mNonExistAperture, - &mNonExistAperture, - &Bridges[Initialized] - ); - if (EFI_ERROR (Status)) { - goto FreeBridges; - } - ++Initialized; - LastRootBridgeNumber =3D RootBridgeNumber; - } - } - - // - // Install the last root bus (which might be the only, ie. main, root bu= s, if - // we've found no extra root buses). - // - Status =3D InitRootBridge ( - Attributes, - Attributes, - AllocationAttributes, - (UINT8) LastRootBridgeNumber, + Bridges =3D PciHostBridgeExtraRoots ( + Count, + mNonExistAperture, + mNonExistAperture, PCI_MAX_BUS, - &Io, - &Mem, - &MemAbove4G, - &mNonExistAperture, - &mNonExistAperture, - &Bridges[Initialized] + Attributes, + AllocationAttributes, + Io, + Mem, + MemAbove4G ); - if (EFI_ERROR (Status)) { - goto FreeBridges; + if (Bridges) { + return Bridges; } - ++Initialized; - - *Count =3D Initialized; - return Bridges; - -FreeBridges: - while (Initialized > 0) { - --Initialized; - UninitRootBridge (&Bridges[Initialized]); - } - - FreePool (Bridges); return NULL; } =20 - -/** - Free the root bridge instances array returned from - PciHostBridgeGetRootBridges(). - - @param The root bridge instances array. - @param The count of the array. -**/ -VOID -EFIAPI -PciHostBridgeFreeRootBridges ( - PCI_ROOT_BRIDGE *Bridges, - UINTN Count - ) -{ - if (Bridges =3D=3D NULL && Count =3D=3D 0) { - return; - } - ASSERT (Bridges !=3D NULL && Count > 0); - - do { - --Count; - UninitRootBridge (&Bridges[Count]); - } while (Count > 0); - - FreePool (Bridges); -} diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLi= b.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c index 7e9512dc08f1..422f46fef4dd 100644 --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c @@ -6,8 +6,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ +#include #include +#include +#include #include +#include +#include +#include "Library/PciHostBridgeLib/PciHostBridge.h" =20 =20 GLOBAL_REMOVE_IF_UNREFERENCED @@ -16,6 +22,209 @@ CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D { }; =20 =20 +/** + Uninitialize a PCI_ROOT_BRIDGE structure set up with InitRootBridge(). + + param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the calle= r and + initialized with InitRootBridge(), that should be + uninitialized. This function doesn't free RootBus. +**/ +VOID +UninitRootBridge ( + IN PCI_ROOT_BRIDGE *RootBus + ) +{ + FreePool (RootBus->DevicePath); +} + +/** + Free the root bridge instances array returned from + PciHostBridgeGetRootBridges(). + + @param The root bridge instances array. + @param The count of the array. +**/ +VOID +EFIAPI +PciHostBridgeFreeRootBridges ( + PCI_ROOT_BRIDGE *Bridges, + UINTN Count + ) +{ + if (Bridges =3D=3D NULL && Count =3D=3D 0) { + return; + } + ASSERT (Bridges !=3D NULL && Count > 0); + + do { + --Count; + UninitRootBridge (&Bridges[Count]); + } while (Count > 0); + + FreePool (Bridges); +} + +/** + Return all the root bridge instances in an array. + + @param Count Return the count of root bridge instances. + + @param[in] PMem Prefetchable MMIO aperture. + + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G. + + @param[in] BusMax The max bus number. + + @param[in] Attributes Initial attributes. + + @param[in] AllocAttributes Allocation attributes. + + @param[in] Io IO aperture. + + @param[in] Mem MMIO aperture. + + @param[in] MemAbove4G MMIO aperture above 4G. + + @return All the root bridge instances in an array. + The array should be passed into PciHostBridgeFreeRootBridges() + when it's not used. +**/ + +PCI_ROOT_BRIDGE * +EFIAPI +PciHostBridgeExtraRoots ( + UINTN *Count, + PCI_ROOT_BRIDGE_APERTURE PMem, + PCI_ROOT_BRIDGE_APERTURE PMemAbove4G, + UINT32 BusMax, + UINT64 Attributes, + UINT64 AllocationAttributes, + PCI_ROOT_BRIDGE_APERTURE Io, + PCI_ROOT_BRIDGE_APERTURE Mem, + PCI_ROOT_BRIDGE_APERTURE MemAbove4G +) +{ + EFI_STATUS Status; + PCI_ROOT_BRIDGE *Bridges; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + UINT64 ExtraRootBridges; + UINTN Initialized; + UINTN LastRootBridgeNumber; + UINTN RootBridgeNumber; + + // + // QEMU provides the number of extra root buses, shortening the exhausti= ve + // search below. If there is no hint, the feature is missing. + // + Status =3D QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgS= ize); + if (EFI_ERROR (Status) || FwCfgSize !=3D sizeof ExtraRootBridges) { + ExtraRootBridges =3D 0; + } else { + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges); + + if (ExtraRootBridges > BusMax) { + DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) " + "reported by QEMU\n", __FUNCTION__, ExtraRootBridges)); + return NULL; + } + DEBUG ((DEBUG_INFO, "%a: %Lu extra root buses reported by QEMU\n", + __FUNCTION__, ExtraRootBridges)); + } + + // + // 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; + } + Initialized =3D 0; + + // + // The "main" root bus is always there. + // + LastRootBridgeNumber =3D 0; + + // + // Scan all other root buses. If function 0 of any device on a bus retur= ns a + // VendorId register value different from all-bits-one, then that bus is + // alive. + // + for (RootBridgeNumber =3D 1; + RootBridgeNumber <=3D BusMax && Initialized < ExtraRootBridges; + ++RootBridgeNumber) { + UINTN Device; + + for (Device =3D 0; Device <=3D PCI_MAX_DEVICE; ++Device) { + if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0, + PCI_VENDOR_ID_OFFSET)) !=3D MAX_UINT16) { + break; + } + } + if (Device <=3D PCI_MAX_DEVICE) { + // + // 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 + // subordinate buses that might exist behind PCI bridges hanging off= it. + // + Status =3D InitRootBridge ( + Attributes, + Attributes, + AllocationAttributes, + (UINT8) LastRootBridgeNumber, + (UINT8) (RootBridgeNumber - 1), + &Io, + &Mem, + &MemAbove4G, + &PMem, + &PMemAbove4G, + &Bridges[Initialized] + ); + if (EFI_ERROR (Status)) { + goto FreeBridges; + } + ++Initialized; + LastRootBridgeNumber =3D RootBridgeNumber; + } + } + + // + // Install the last root bus (which might be the only, ie. main, root bu= s, if + // we've found no extra root buses). + // + Status =3D InitRootBridge ( + Attributes, + Attributes, + AllocationAttributes, + (UINT8) LastRootBridgeNumber, + BusMax, + &Io, + &Mem, + &MemAbove4G, + &PMem, + &PMemAbove4G, + &Bridges[Initialized] + ); + if (EFI_ERROR (Status)) { + goto FreeBridges; + } + ++Initialized; + + *Count =3D Initialized; + return Bridges; + +FreeBridges: + while (Initialized > 0) { + --Initialized; + UninitRootBridge (&Bridges[Initialized]); + } + + FreePool (Bridges); + return NULL; +} /** Inform the platform that the resource conflict happens. =20 --=20 2.28.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 (#67183): https://edk2.groups.io/g/devel/message/67183 Mute This Topic: https://groups.io/mt/78135584/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 7 11:04:05 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+67184+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+67184+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1604930198; cv=none; d=zohomail.com; s=zohoarc; b=gznxwGPxl2XVcqrLkx0xW0JLaNAlAv3I22/ZXwfXkGVBk60q7dBQ5DU87Go8nkz1t7CrXLH751iVEC+ZWcB2SVK7qGY4WiefszN77p+PA3Fu/fKiyVSocLcF0cflIAoUtux1rf9ztsAYD/eedGafx28ee1ASVuFq6qCGeXXmwTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604930198; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=iz+/7lObzW9+aTPVH5iobSTV96GmpDHqmpHPpkYu7ow=; b=gv/RIhxr0RKvW8W6RT7QnewxszzRqQECRH5ygPSYSCtCnJmtPp4nMKOxIMKkVZQE2C06+UQT9EvXNFyMTPowJXvqtv2IrLbZKS/wzJof3BRtmO/LOBUDFAnOuRPeTmZORCK0zp5zMZDJNWNnRxDdRr7mduPfZtEFo9RGbr82+RE= 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+67184+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 160493019832258.66133458862362; Mon, 9 Nov 2020 05:56:38 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id teplYY1788612xffvtEOegPy; Mon, 09 Nov 2020 05:56:37 -0800 X-Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mx.groups.io with SMTP id smtpd.web08.11084.1604927146653598207 for ; Mon, 09 Nov 2020 05:05:47 -0800 X-Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CVB7D3SXmzkf2f; Mon, 9 Nov 2020 21:05:28 +0800 (CST) X-Received: from localhost (10.174.184.155) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 21:05:27 +0800 From: "Jiahui Cen via groups.io" To: CC: , , , , , , Jiahui Cen Subject: [edk2-devel] [PATCH v2 4/4] ArmVirtPkg: Support extra pci roots Date: Mon, 9 Nov 2020 21:05:11 +0800 Message-ID: <20201109130511.5946-5-cenjiahui@huawei.com> In-Reply-To: <20201109130511.5946-1-cenjiahui@huawei.com> References: <20201109130511.5946-1-cenjiahui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.184.155] X-CFilter-Loop: Reflected 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,cenjiahui@huawei.com X-Gm-Message-State: zAzIacAK20im0rgFTXDuhW33x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604930197; bh=yrDsonf8V4s5cX5YYIwXGCPNflPNArvOWaK2MdRXtqo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=i7/Lc1rhm1du0/VFSKV6/OHDSffZhcqSeoys3Lsweje6LgdUBBKgYdfaCgJ1eyv1lUl 2HqCGyWR6E/N0bnQ3PWFQkZr5f2Ar6MC+E80nAAwrYvbX4CWdiBAnzxf4C4aYPak7YPMK 69ToQMK3+cH5PUpuuLVpTQs1nonSAdw0Ucg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Yubo Miao As the implementation of extra pci roots is shared in PciHostBridgeUtilityLib, let's call PciHostBridgeExtraRoots to support it. Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Leif Lindholm Signed-off-by: Yubo Miao Signed-off-by: Jiahui Cen --- ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 3 + ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 162 +++++= ++++++++------- 2 files changed, 111 insertions(+), 54 deletions(-) diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf= b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf index 97e9368c8e9f..1b0f9a2b9013 100644 --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf @@ -39,6 +39,9 @@ [LibraryClasses] DxeServicesTableLib MemoryAllocationLib PciPcdProducerLib + PciHostBridgeLib + BaseMemoryLib + QemuFwCfgLib PciHostBridgeUtilityLib =20 [FixedPcd] diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b= /ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c index 3952f511b4d2..d33f833a5040 100644 --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c @@ -15,6 +15,11 @@ #include #include #include +#include +#include +#include +#include +#include "Library/PciHostBridgeLib/PciHostBridge.h" =20 #include #include @@ -304,7 +309,60 @@ ProcessPciHost ( return Status; } =20 -STATIC PCI_ROOT_BRIDGE mRootBridge; +EFI_STATUS +InitRootBridge ( + IN UINT64 Supports, + IN UINT64 Attributes, + IN UINT64 AllocAttributes, + IN UINT8 RootBusNumber, + IN UINT8 MaxSubBusNumber, + IN PCI_ROOT_BRIDGE_APERTURE *Io, + IN PCI_ROOT_BRIDGE_APERTURE *Mem, + IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G, + IN PCI_ROOT_BRIDGE_APERTURE *PMem, + IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G, + OUT PCI_ROOT_BRIDGE *RootBus + ) +{ + EFI_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath; + + // + // Be safe if other fields are added to PCI_ROOT_BRIDGE later. + // + ZeroMem (RootBus, sizeof *RootBus); + + RootBus->Segment =3D 0; + RootBus->ResourceAssigned =3D FALSE; + RootBus->Supports =3D Supports; + RootBus->Attributes =3D Attributes; + + RootBus->DmaAbove4G =3D TRUE; + + RootBus->AllocationAttributes =3D AllocAttributes; + RootBus->Bus.Base =3D RootBusNumber; + RootBus->Bus.Limit =3D MaxSubBusNumber; + CopyMem (&RootBus->Io, Io, sizeof (*Io)); + CopyMem (&RootBus->Mem, Mem, sizeof (*Mem)); + CopyMem (&RootBus->MemAbove4G, MemAbove4G, sizeof (*MemAbove4G)); + CopyMem (&RootBus->PMem, PMem, sizeof (*PMem)); + CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G)); + + RootBus->NoExtendedConfigSpace =3D FALSE; + + DevicePath =3D AllocateCopyPool (sizeof mEfiPciRootBridgeDevicePath, + &mEfiPciRootBridgeDevicePath); + if (DevicePath =3D=3D NULL) { + DEBUG ((EFI_D_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES)); + return EFI_OUT_OF_RESOURCES; + } + DevicePath->AcpiDevicePath.UID =3D RootBusNumber; + RootBus->DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *)DevicePath; + + DEBUG ((EFI_D_INFO, + "%a: populated root bus %d, with room for %d subordinate bus(es)\n", + __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber)); + return EFI_SUCCESS; +} =20 /** Return all the root bridge instances in an array. @@ -321,11 +379,19 @@ PciHostBridgeGetRootBridges ( UINTN *Count ) { - UINT64 IoBase, IoSize; - UINT64 Mmio32Base, Mmio32Size; - UINT64 Mmio64Base, Mmio64Size; - UINT32 BusMin, BusMax; - EFI_STATUS Status; + UINT64 IoBase, IoSize; + UINT64 Mmio32Base, Mmio32Size; + UINT64 Mmio64Base, Mmio64Size; + UINT32 BusMin, BusMax; + PCI_ROOT_BRIDGE *Bridges; + UINT64 Attributes; + UINT64 AllocationAttributes; + EFI_STATUS Status; + PCI_ROOT_BRIDGE_APERTURE Io; + PCI_ROOT_BRIDGE_APERTURE PMem; + PCI_ROOT_BRIDGE_APERTURE PMemAbove4G; + PCI_ROOT_BRIDGE_APERTURE Mem; + PCI_ROOT_BRIDGE_APERTURE MemAbove4G; =20 if (PcdGet64 (PcdPciExpressBaseAddress) =3D=3D 0) { DEBUG ((EFI_D_INFO, "%a: PCI host bridge not present\n", __FUNCTION__)= ); @@ -343,33 +409,27 @@ PciHostBridgeGetRootBridges ( return NULL; } =20 - *Count =3D 1; + ZeroMem (&Io, sizeof (Io)); + ZeroMem (&Mem, sizeof (Mem)); + ZeroMem (&MemAbove4G, sizeof (MemAbove4G)); =20 - mRootBridge.Segment =3D 0; - mRootBridge.Supports =3D EFI_PCI_ATTRIBUTE_ISA_IO_16 | - EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO= | - EFI_PCI_ATTRIBUTE_VGA_IO_16 | - EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16; - mRootBridge.Attributes =3D mRootBridge.Supports; + Attributes =3D EFI_PCI_ATTRIBUTE_ISA_IO_16 | + EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO | + EFI_PCI_ATTRIBUTE_VGA_IO_16 | + EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16; =20 - mRootBridge.DmaAbove4G =3D TRUE; - mRootBridge.NoExtendedConfigSpace =3D FALSE; - mRootBridge.ResourceAssigned =3D FALSE; + AllocationAttributes =3D EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM; =20 - mRootBridge.AllocationAttributes =3D EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PM= EM; - - mRootBridge.Bus.Base =3D BusMin; - mRootBridge.Bus.Limit =3D BusMax; - mRootBridge.Io.Base =3D IoBase; - mRootBridge.Io.Limit =3D IoBase + IoSize - 1; - mRootBridge.Mem.Base =3D Mmio32Base; - mRootBridge.Mem.Limit =3D Mmio32Base + Mmio32Size - 1; + Io.Base =3D IoBase; + Io.Limit =3D IoBase + IoSize - 1; + Mem.Base =3D Mmio32Base; + Mem.Limit =3D Mmio32Base + Mmio32Size - 1; =20 if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { - mRootBridge.MemAbove4G.Base =3D Mmio64Base; - mRootBridge.MemAbove4G.Limit =3D Mmio64Base + Mmio64Size - 1; + MemAbove4G.Base =3D Mmio64Base; + MemAbove4G.Limit =3D Mmio64Base + Mmio64Size - 1; if (Mmio64Size > 0) { - mRootBridge.AllocationAttributes |=3D EFI_PCI_HOST_BRIDGE_MEM64_DECO= DE; + AllocationAttributes |=3D EFI_PCI_HOST_BRIDGE_MEM64_DECODE; } } else { // @@ -378,37 +438,31 @@ PciHostBridgeGetRootBridges ( // BARs unless they are allocated below 4 GB. So ignore the range above // 4 GB in this case. // - mRootBridge.MemAbove4G.Base =3D MAX_UINT64; - mRootBridge.MemAbove4G.Limit =3D 0; + MemAbove4G.Base =3D MAX_UINT64; + MemAbove4G.Limit =3D 0; } =20 // // No separate ranges for prefetchable and non-prefetchable BARs // - mRootBridge.PMem.Base =3D MAX_UINT64; - mRootBridge.PMem.Limit =3D 0; - mRootBridge.PMemAbove4G.Base =3D MAX_UINT64; - mRootBridge.PMemAbove4G.Limit =3D 0; + PMem.Base =3D MAX_UINT64; + PMem.Limit =3D 0; + PMemAbove4G.Base =3D MAX_UINT64; + PMemAbove4G.Limit =3D 0; =20 - mRootBridge.DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridg= eDevicePath; - - return &mRootBridge; + Bridges =3D PciHostBridgeExtraRoots ( + Count, + PMem, + PMemAbove4G, + BusMax, + Attributes, + AllocationAttributes, + Io, + Mem, + MemAbove4G + ); + if (Bridges) { + return Bridges; + } + return NULL; } - -/** - Free the root bridge instances array returned from - PciHostBridgeGetRootBridges(). - - @param Bridges The root bridge instances array. - @param Count The count of the array. -**/ -VOID -EFIAPI -PciHostBridgeFreeRootBridges ( - PCI_ROOT_BRIDGE *Bridges, - UINTN Count - ) -{ - ASSERT (Count =3D=3D 1); -} - --=20 2.28.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 (#67184): https://edk2.groups.io/g/devel/message/67184 Mute This Topic: https://groups.io/mt/78135585/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-