From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mx.groups.io with SMTP id smtpd.web10.6145.1610534029118702605 for ; Wed, 13 Jan 2021 02:33:49 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.35, mailfrom: cenjiahui@huawei.com) Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DG3g26Jl5z7KZb; Wed, 13 Jan 2021 18:32:46 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Wed, 13 Jan 2021 18:33:40 +0800 From: "Jiahui Cen" To: CC: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Rebecca Cran , Peter Grehan , Anthony Perard , Julien Grall , Leif Lindholm , Sami Mujawar , , , Jiahui Cen , Yubo Miao Subject: [PATCH v5 01/10] OvmfPkg: Introduce PciHostBridgeUtilityLib class Date: Wed, 13 Jan 2021 18:33:22 +0800 Message-ID: <20210113103331.10375-2-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210113103331.10375-1-cenjiahui@huawei.com> References: <20210113103331.10375-1-cenjiahui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.184.155] X-CFilter-Loop: Reflected Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Introduce a new PciHostBridgeUtilityLib class to share duplicate code between OvmfPkg and ArmVirtPkg. Extract function PciHostBridgeUtilityResourceConflict from PciHostBridgeResourceConflict in OvmfPkg/PciHostBridgeLib. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3059 Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Rebecca Cran Cc: Peter Grehan Cc: Anthony Perard Cc: Julien Grall Signed-off-by: Jiahui Cen Signed-off-by: Yubo Miao Reviewed-by: Laszlo Ersek --- OvmfPkg/OvmfPkg.dec | 4= + OvmfPkg/AmdSev/AmdSevX64.dsc | 1= + OvmfPkg/Bhyve/BhyveX64.dsc | 1= + 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 | 37= ++++++++++ OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 37= ++++++++++ OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 41= +---------- OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 77= ++++++++++++++++++++ 12 files changed, 164 insertions(+), 39 deletions(-) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 54804962ec02..4348bb45c64a 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -49,6 +49,10 @@ [LibraryClasses] # access. PciCapPciSegmentLib|Include/Library/PciCapPciSegmentLib.h =20 + ## @libraryclass Provide common utility functions to PciHostBridgeLi= b + # instances in ArmVirtPkg and OvmfPkg. + PciHostBridgeUtilityLib|Include/Library/PciHostBridgeUtilityLib.h + ## @libraryclass Register a status code handler for printing the Boo= t # Manager's LoadImage() and StartImage() preparations= , and # return codes, to the UEFI console. diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index dad8635c3388..62e97dbe320a 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -669,6 +669,7 @@ [Components] MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib= .inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/Pc= iHostBridgeUtilityLib.inf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 33edf3d2d6b5..9547523018e9 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -662,6 +662,7 @@ [Components] MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib= .inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/Pc= iHostBridgeUtilityLib.inf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 75c5f46a7786..3555bd1691f2 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -747,6 +747,7 @@ [Components] MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib= .inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/Pc= iHostBridgeUtilityLib.inf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 8693248b4ea0..d668c5c8eda8 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -761,6 +761,7 @@ [Components.X64] MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib= .inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/Pc= iHostBridgeUtilityLib.inf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 70ff2bcf2342..ff32efb5ba8b 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -759,6 +759,7 @@ [Components] MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib= .inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/Pc= iHostBridgeUtilityLib.inf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 7d31e88907ca..ed34efe8ce47 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -552,6 +552,7 @@ [Components] MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib= .inf + PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/Pc= iHostBridgeUtilityLib.inf NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/Ovmf= Pkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf index 6ec9ec751478..4c56f3c90b3b 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf @@ -39,6 +39,7 @@ [LibraryClasses] DebugLib DevicePathLib MemoryAllocationLib + PciHostBridgeUtilityLib PciLib QemuFwCfgLib =20 diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtility= Lib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib= .inf new file mode 100644 index 000000000000..1ba8ec3e03c7 --- /dev/null +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf @@ -0,0 +1,37 @@ +## @file +# Provide common utility functions to PciHostBridgeLib instances in +# ArmVirtPkg and OvmfPkg. +# +# Copyright (C) 2016, Red Hat, Inc. +# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved. +# Copyright (c) 2020, Huawei Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D PciHostBridgeUtilityLib + FILE_GUID =3D e3aa5932-527a-42e7-86f5-81b144c7e5f= 1 + 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 th= e build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 ARM +# + +[Sources] + PciHostBridgeUtilityLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/= Include/Library/PciHostBridgeUtilityLib.h new file mode 100644 index 000000000000..f932d412aa10 --- /dev/null +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h @@ -0,0 +1,37 @@ +/** @file + Provide common utility functions to PciHostBridgeLib instances in + ArmVirtPkg and OvmfPkg. + + Copyright (C) 2016, Red Hat, Inc. + Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2020, Huawei 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__ + + +/** + Utility function to inform the platform that the resource conflict hap= pens. + + @param Configuration Pointer to PCI I/O and PCI memory resource + descriptors. The Configuration contains the re= sources + for all the root bridges. The resource for eac= h root + bridge is terminated with END descriptor and a= n + additional END is appended indicating the end = of the + entire resources. The resource descriptor fiel= d + values follow the description in + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOC= OL + .SubmitResources(). +**/ +VOID +EFIAPI +PciHostBridgeUtilityResourceConflict ( + VOID *Configuration + ); + + +#endif // __PCI_HOST_BRIDGE_UTILITY_LIB_H__ diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPk= g/Library/PciHostBridgeLib/PciHostBridgeLib.c index e850f7d183ee..4a176347fd49 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include "PciHostBridge.h" @@ -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 { @@ -407,37 +402,5 @@ PciHostBridgeResourceConflict ( 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; Descri= ptor++) { - ASSERT (Descriptor->ResType < - ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr) - ); - DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n", - mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResTy= pe], - Descriptor->AddrLen, Descriptor->AddrRangeMax - )); - if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) { - DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %0= 2x%s\n", - Descriptor->AddrSpaceGranularity, Descriptor->SpecificFl= ag, - ((Descriptor->SpecificFlag & - EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFE= TCHABLE - ) !=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 - ); - } + PciHostBridgeUtilityResourceConflict (Configuration); } diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtility= Lib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c new file mode 100644 index 000000000000..bbaa5f830c98 --- /dev/null +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c @@ -0,0 +1,77 @@ +/** @file + Provide common utility functions to PciHostBridgeLib instances in + ArmVirtPkg and OvmfPkg. + + Copyright (C) 2016, Red Hat, Inc. + Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2020, Huawei Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + + +GLOBAL_REMOVE_IF_UNREFERENCED +CHAR16 *mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[] =3D { + L"Mem", L"I/O", L"Bus" +}; + + +/** + Utility function to inform the platform that the resource conflict hap= pens. + + @param Configuration Pointer to PCI I/O and PCI memory resource + descriptors. The Configuration contains the re= sources + for all the root bridges. The resource for eac= h root + bridge is terminated with END descriptor and a= n + additional END is appended indicating the end = of the + entire resources. The resource descriptor fiel= d + values follow the description in + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOC= OL + .SubmitResources(). +**/ +VOID +EFIAPI +PciHostBridgeUtilityResourceConflict ( + 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; Descri= ptor++) { + ASSERT (Descriptor->ResType < + ARRAY_SIZE (mPciHostBridgeUtilityLibAcpiAddressSpaceTypeSt= r) + ); + DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n", + mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[Descriptor= ->ResType], + Descriptor->AddrLen, Descriptor->AddrRangeMax + )); + if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) { + DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %0= 2x%s\n", + Descriptor->AddrSpaceGranularity, Descriptor->SpecificFl= ag, + ((Descriptor->SpecificFlag & + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFE= TCHABLE + ) !=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.29.2