From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mx.groups.io with SMTP id smtpd.web10.1269.1604734889299066058 for ; Fri, 06 Nov 2020 23:41:30 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.191, mailfrom: cenjiahui@huawei.com) Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CSq285jx8zhc4g; Sat, 7 Nov 2020 15:41:20 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Sat, 7 Nov 2020 15:41:17 +0800 From: cenjiahui@huawei.com To: CC: , , , , , , Jiahui Cen Subject: [PATCH v2 1/4] OvmfPkg: Extract functions form PciHostBridgeLib Date: Sat, 7 Nov 2020 15:40:22 +0800 Message-ID: <20201107074025.2447-2-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201107074025.2447-1-cenjiahui@huawei.com> References: <20201107074025.2447-1-cenjiahui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.184.155] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Yubo Miao Introduce a new PciHostBridgeUtilityLib class to share duplicate code between OvmfPkg and ArmVirtPkg. Extract function PciHostBridgeResourceConflict from OvmfPkg/PciHostBridgeLib. Signed-off-by: Yubo Miao Signed-off-by: Jiahui Cen Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel --- .../Include/Library/PciHostBridgeUtilityLib.h | 33 +++++++++ .../PciHostBridgeLib/PciHostBridgeLib.c | 62 +--------------- .../PciHostBridgeLib/PciHostBridgeLib.inf | 1 + .../PciHostBridgeUtilityLib.c | 71 +++++++++++++++++++ .../PciHostBridgeUtilityLib.inf | 49 +++++++++++++ OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 9 files changed, 159 insertions(+), 61 deletions(-) create mode 100644 OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h create mode 100644 OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUt= ilityLib.c create mode 100644 OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUt= ilityLib.inf diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/In= clude/Library/PciHostBridgeUtilityLib.h new file mode 100644 index 0000000000..d2622fd907 --- /dev/null +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h @@ -0,0 +1,33 @@ +/** @file=0D + PCI Host Bridge Library consumed by PciHostBridgeDxe driver returning=0D + the platform specific information about the PCI Host Bridge.=0D +=0D + Copyright (c) 2016, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +#ifndef __PCI_HOST_BRIDGE_UTILITY_LIB_H__=0D +#define __PCI_HOST_BRIDGE_UTILITY_LIB_H__=0D +=0D +/**=0D + Inform the platform that the resource conflict happens.=0D +=0D + @param HostBridgeHandle Handle of the Host Bridge.=0D + @param Configuration Pointer to PCI I/O and PCI memory resource=0D + descriptors. The Configuration contains the reso= urces=0D + for all the root bridges. The resource for each = root=0D + bridge is terminated with END descriptor and an= =0D + additional END is appended indicating the end of= the=0D + entire resources. The resource descriptor field= =0D + values follow the description in=0D + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL= =0D + .SubmitResources().=0D +**/=0D +VOID=0D +EFIAPI=0D +PciHostBridgeResourceConflict (=0D + EFI_HANDLE HostBridgeHandle,=0D + VOID *Configuration=0D + );=0D +=0D +#endif=0D diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/= Library/PciHostBridgeLib/PciHostBridgeLib.c index e850f7d183..d6b0e00f80 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -23,6 +23,7 @@ #include =0D #include =0D #include "PciHostBridge.h"=0D +#include =0D =0D =0D #pragma pack(1)=0D @@ -34,10 +35,6 @@ typedef struct { =0D =0D GLOBAL_REMOVE_IF_UNREFERENCED=0D -CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D {=0D - L"Mem", L"I/O", L"Bus"=0D -};=0D -=0D =0D STATIC=0D CONST=0D @@ -384,60 +381,3 @@ PciHostBridgeFreeRootBridges ( =0D FreePool (Bridges);=0D }=0D -=0D -=0D -/**=0D - Inform the platform that the resource conflict happens.=0D -=0D - @param HostBridgeHandle Handle of the Host Bridge.=0D - @param Configuration Pointer to PCI I/O and PCI memory resource=0D - descriptors. The Configuration contains the reso= urces=0D - for all the root bridges. The resource for each = root=0D - bridge is terminated with END descriptor and an= =0D - additional END is appended indicating the end of= the=0D - entire resources. The resource descriptor field= =0D - values follow the description in=0D - EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL= =0D - .SubmitResources().=0D -**/=0D -VOID=0D -EFIAPI=0D -PciHostBridgeResourceConflict (=0D - EFI_HANDLE HostBridgeHandle,=0D - VOID *Configuration=0D - )=0D -{=0D - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;=0D - UINTN RootBridgeIndex;=0D - DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n"));=0D -=0D - RootBridgeIndex =3D 0;=0D - Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;=0D - while (Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR) {=0D - DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));=0D - for (; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descript= or++) {=0D - ASSERT (Descriptor->ResType <=0D - ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr)=0D - );=0D - DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n",=0D - mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType= ],=0D - Descriptor->AddrLen, Descriptor->AddrRangeMax=0D - ));=0D - if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) {=0D - DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %02x= %s\n",=0D - Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag= ,=0D - ((Descriptor->SpecificFlag &=0D - EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETC= HABLE=0D - ) !=3D 0) ? L" (Prefetchable)" : L""=0D - ));=0D - }=0D - }=0D - //=0D - // Skip the END descriptor for root bridge=0D - //=0D - ASSERT (Descriptor->Desc =3D=3D ACPI_END_TAG_DESCRIPTOR);=0D - Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(=0D - (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1=0D - );=0D - }=0D -}=0D diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPk= g/Library/PciHostBridgeLib/PciHostBridgeLib.inf index 6ec9ec7514..7d01528c94 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf @@ -41,6 +41,7 @@ MemoryAllocationLib=0D PciLib=0D QemuFwCfgLib=0D + PciHostBridgeUtilityLib=0D =0D [Pcd]=0D gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase=0D diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLi= b.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c new file mode 100644 index 0000000000..4b34f92fd8 --- /dev/null +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c @@ -0,0 +1,71 @@ +/** @file=0D + OVMF's instance of the PCI Host Bridge Library.=0D +=0D + Copyright (c) 2020, Huawei Corporation. All rights reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +#include =0D +#include =0D +=0D +CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D {=0D + L"Mem", L"I/O", L"Bus"=0D +};=0D +=0D +/**=0D + Inform the platform that the resource conflict happens.=0D +=0D + @param HostBridgeHandle Handle of the Host Bridge.=0D + @param Configuration Pointer to PCI I/O and PCI memory resource=0D + descriptors. The Configuration contains the reso= urces=0D + for all the root bridges. The resource for each = root=0D + bridge is terminated with END descriptor and an= =0D + additional END is appended indicating the end of= the=0D + entire resources. The resource descriptor field= =0D + values follow the description in=0D + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL= =0D + .SubmitResources().=0D +**/=0D +VOID=0D +EFIAPI=0D +PciHostBridgeResourceConflict (=0D + EFI_HANDLE HostBridgeHandle,=0D + VOID *Configuration=0D + )=0D +{=0D + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;=0D + UINTN RootBridgeIndex;=0D + DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n"));=0D +=0D + RootBridgeIndex =3D 0;=0D + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;=0D + while (Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR) {=0D + DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));=0D + for (; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descript= or++) {=0D + ASSERT (Descriptor->ResType <=0D + ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr)=0D + );=0D + DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n",=0D + mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType= ],=0D + Descriptor->AddrLen, Descriptor->AddrRangeMax=0D + ));=0D + if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) {=0D + DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %02x= %s\n",=0D + Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag= ,=0D + ((Descriptor->SpecificFlag &=0D + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETC= HABLE=0D + ) !=3D 0) ? L" (Prefetchable)" : L""=0D + ));=0D + }=0D + }=0D + //=0D + // Skip the END descriptor for root bridge=0D + //=0D + ASSERT (Descriptor->Desc =3D=3D ACPI_END_TAG_DESCRIPTOR);=0D + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(=0D + (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1=0D + );=0D + }=0D +}=0D +=0D diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLi= b.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf new file mode 100644 index 0000000000..c88ab8e415 --- /dev/null +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf @@ -0,0 +1,49 @@ +## @file=0D +# OVMF and Arm's instance of the PCI Host Bridge Utility Library.=0D +#=0D +# Copyright (C) 2016, Red Hat, Inc.=0D +# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
= =0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D PciHostBridgeUtilityLib=0D + FILE_GUID =3D e3aa5932-527a-42e7-86f5-81b144c7e5f1= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D PciHostBridgeUtilityLib=0D +=0D +#=0D +# The following information is for reference only and not required by the = build=0D +# tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 EBC=0D +#=0D +=0D +[Sources]=0D + PciHostBridgeUtilityLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseMemoryLib=0D + DebugLib=0D + DevicePathLib=0D + MemoryAllocationLib=0D + PciLib=0D + QemuFwCfgLib=0D +=0D +[Pcd]=0D + gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase=0D + gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize=0D + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Base=0D + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size=0D + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base=0D + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size=0D + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId=0D diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 58d9f292f9..0c2bf0b13c 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -738,6 +738,7 @@ =0D PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf=0D NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf=0D + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf=0D }=0D MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {=0D =0D diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 3551f9710a..baf36a4f7a 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -752,6 +752,7 @@ =0D PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf=0D NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf=0D + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf=0D }=0D MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {=0D =0D diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 7a8bdb8a86..219b5f559b 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -748,6 +748,7 @@ =0D PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf=0D NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf=0D + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf=0D }=0D MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {=0D =0D diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 34c9de19df..442c0730ef 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -544,6 +544,7 @@ =0D PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf=0D NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf=0D + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciH= ostBridgeUtilityLib.inf=0D }=0D MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {=0D =0D --=20 2.19.1