From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.26616.1611143254513541667 for ; Wed, 20 Jan 2021 03:47:35 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eu5NhTQQ; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611143253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JJFTSi7CgftLFF1KCqixCNU6sRnzyEjyyvuVRgq30IE=; b=eu5NhTQQ1MYDP6mwilN+zzAcGQ9S9uVpMGiojfsyV8bHZLFTD8KEFfAroFDVJraeEaucIS vm1zIoaV3prmsOEZ3iRGLhp8sssyiXVfyzTEFPC3W+9eE3OHgfCdV70vReL4gNvOhxFuIa tdmFt/XRrxOxmeiLTDOf7R+Ga0+bWDQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-Bt7uggEGM-OG5_VROQZ4qg-1; Wed, 20 Jan 2021 06:47:29 -0500 X-MC-Unique: Bt7uggEGM-OG5_VROQZ4qg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33E69801817; Wed, 20 Jan 2021 11:47:27 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-96.ams2.redhat.com [10.36.115.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A40C3AA2; Wed, 20 Jan 2021 11:47:21 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v6 01/11] OvmfPkg: Introduce PciHostBridgeUtilityLib class To: devel@edk2.groups.io, cenjiahui@huawei.com Cc: Jordan Justen , Ard Biesheuvel , Rebecca Cran , Peter Grehan , Anthony Perard , Julien Grall , Leif Lindholm , Sami Mujawar , xieyingtai@huawei.com, wu.wubin@huawei.com, Yubo Miao References: <20210119011302.10908-1-cenjiahui@huawei.com> <20210119011302.10908-2-cenjiahui@huawei.com> From: "Laszlo Ersek" Message-ID: Date: Wed, 20 Jan 2021 12:47:20 +0100 MIME-Version: 1.0 In-Reply-To: <20210119011302.10908-2-cenjiahui@huawei.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 01/19/21 02:12, Jiahui Cen via groups.io wrote: > 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=3059 > > 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 | 38 ++++++++++ > OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 41 +--------- > OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 78 ++++++++++++++++++++ > 12 files changed, 166 insertions(+), 39 deletions(-) Thanks for updating the patch, it looks OK. Laszlo > 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 > > + ## @libraryclass Provide common utility functions to PciHostBridgeLib > + # instances in ArmVirtPkg and OvmfPkg. > + PciHostBridgeUtilityLib|Include/Library/PciHostBridgeUtilityLib.h > + > ## @libraryclass Register a status code handler for printing the Boot > # 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/PciHostBridgeUtilityLib.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/PciHostBridgeUtilityLib.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/PciHostBridgeUtilityLib.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/PciHostBridgeUtilityLib.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/PciHostBridgeUtilityLib.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/PciHostBridgeUtilityLib.inf > NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf > } > MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { > diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/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 > > diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.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 = 1.29 > + BASE_NAME = PciHostBridgeUtilityLib > + FILE_GUID = e3aa5932-527a-42e7-86f5-81b144c7e5f1 > + MODULE_TYPE = DXE_DRIVER > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = PciHostBridgeUtilityLib > + > +# > +# The following information is for reference only and not required by the build > +# tools. > +# > +# VALID_ARCHITECTURES = 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..5ea25ed2f4f4 > --- /dev/null > +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h > @@ -0,0 +1,38 @@ > +/** @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 happens. > + > + @param[in] Configuration Pointer to PCI I/O and PCI memory resource > + descriptors. The Configuration contains the > + resources 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 > +PciHostBridgeUtilityResourceConflict ( > + IN VOID *Configuration > + ); > + > + > +#endif // __PCI_HOST_BRIDGE_UTILITY_LIB_H__ > diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/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 () > > > -GLOBAL_REMOVE_IF_UNREFERENCED > -CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] = { > - L"Mem", L"I/O", L"Bus" > -}; > - > - > STATIC > CONST > OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = { > @@ -407,37 +402,5 @@ PciHostBridgeResourceConflict ( > VOID *Configuration > ) > { > - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; > - UINTN RootBridgeIndex; > - DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n")); > - > - RootBridgeIndex = 0; > - Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration; > - while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) { > - DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); > - for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) { > - ASSERT (Descriptor->ResType < > - ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr) > - ); > - DEBUG ((DEBUG_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n", > - mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType], > - Descriptor->AddrLen, Descriptor->AddrRangeMax > - )); > - if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) { > - DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag = %ld / %02x%s\n", > - Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag, > - ((Descriptor->SpecificFlag & > - EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE > - ) != 0) ? L" (Prefetchable)" : L"" > - )); > - } > - } > - // > - // Skip the END descriptor for root bridge > - // > - ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR); > - Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)( > - (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1 > - ); > - } > + PciHostBridgeUtilityResourceConflict (Configuration); > } > diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c > new file mode 100644 > index 000000000000..ac94e62612be > --- /dev/null > +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c > @@ -0,0 +1,78 @@ > +/** @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[] = { > + L"Mem", L"I/O", L"Bus" > +}; > + > + > +/** > + Utility function to inform the platform that the resource conflict happens. > + > + @param[in] Configuration Pointer to PCI I/O and PCI memory resource > + descriptors. The Configuration contains the > + resources 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 > +PciHostBridgeUtilityResourceConflict ( > + IN VOID *Configuration > + ) > +{ > + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; > + UINTN RootBridgeIndex; > + DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n")); > + > + RootBridgeIndex = 0; > + Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration; > + while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) { > + DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); > + for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) { > + ASSERT (Descriptor->ResType < > + ARRAY_SIZE (mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr) > + ); > + DEBUG ((DEBUG_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n", > + mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[Descriptor->ResType], > + Descriptor->AddrLen, Descriptor->AddrRangeMax > + )); > + if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) { > + DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag = %ld / %02x%s\n", > + Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag, > + ((Descriptor->SpecificFlag & > + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE > + ) != 0) ? L" (Prefetchable)" : L"" > + )); > + } > + } > + // > + // Skip the END descriptor for root bridge > + // > + ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR); > + Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)( > + (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1 > + ); > + } > +} > + >