* [PATCH v6 01/11] OvmfPkg: Introduce PciHostBridgeUtilityLib class
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-20 11:47 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:12 ` [PATCH v6 02/11] ArmVirtPkg: Refactor with PciHostBridgeUtilityLib Jiahui Cen
` (10 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
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 <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Peter Grehan <grehan@freebsd.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
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(-)
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 {
<LibraryClasses>
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 {
<LibraryClasses>
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 {
<LibraryClasses>
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 {
<LibraryClasses>
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 {
<LibraryClasses>
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 {
<LibraryClasses>
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.<BR>
+# Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
+#
+# 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.<BR>
+ Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
+
+ 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 <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PciHostBridgeLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
#include <Library/QemuFwCfgLib.h>
#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.<BR>
+ Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <IndustryStandard/Acpi10.h>
+#include <Library/DebugLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
+
+
+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
+ );
+ }
+}
+
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 01/11] OvmfPkg: Introduce PciHostBridgeUtilityLib class
2021-01-19 1:12 ` [PATCH v6 01/11] OvmfPkg: Introduce PciHostBridgeUtilityLib class Jiahui Cen
@ 2021-01-20 11:47 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 11:47 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
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 <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Rebecca Cran <rebecca@bsdio.com>
> Cc: Peter Grehan <grehan@freebsd.org>
> Cc: Anthony Perard <anthony.perard@citrix.com>
> Cc: Julien Grall <julien@xen.org>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 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 {
> <LibraryClasses>
> 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 {
> <LibraryClasses>
> 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 {
> <LibraryClasses>
> 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 {
> <LibraryClasses>
> 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 {
> <LibraryClasses>
> 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 {
> <LibraryClasses>
> 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.<BR>
> +# Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
> +#
> +# 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.<BR>
> + Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
> +
> + 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 <Library/DevicePathLib.h>
> #include <Library/MemoryAllocationLib.h>
> #include <Library/PciHostBridgeLib.h>
> +#include <Library/PciHostBridgeUtilityLib.h>
> #include <Library/PciLib.h>
> #include <Library/QemuFwCfgLib.h>
> #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.<BR>
> + Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <IndustryStandard/Acpi10.h>
> +#include <Library/DebugLib.h>
> +#include <Library/PciHostBridgeUtilityLib.h>
> +
> +
> +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
> + );
> + }
> +}
> +
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 02/11] ArmVirtPkg: Refactor with PciHostBridgeUtilityLib
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
2021-01-19 1:12 ` [PATCH v6 01/11] OvmfPkg: Introduce PciHostBridgeUtilityLib class Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-19 1:12 ` [PATCH v6 03/11] OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency Jiahui Cen
` (9 subsequent siblings)
11 siblings, 0 replies; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
Eliminate currently duplicated code in ArmVirtPkg with the common utility
class PciHostBridgeUtilityLib.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
ArmVirtPkg/ArmVirtKvmTool.dsc | 1 +
ArmVirtPkg/ArmVirtQemu.dsc | 1 +
ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 +
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 2 +
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 44 ++------------------
5 files changed, 8 insertions(+), 41 deletions(-)
diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc
index bf008be50fcb..e027b17bec1b 100644
--- a/ArmVirtPkg/ArmVirtKvmTool.dsc
+++ b/ArmVirtPkg/ArmVirtKvmTool.dsc
@@ -58,6 +58,7 @@ [LibraryClasses.common]
PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf
PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index ef5d6dbeaddc..a11ffd9ba553 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -78,6 +78,7 @@ [LibraryClasses.common]
PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf
PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
!if $(TPM2_ENABLE) == TRUE
Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index f8f5f7f4b94b..c27752b4d5e5 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -76,6 +76,7 @@ [LibraryClasses.common]
PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf
PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
[LibraryClasses.common.DXE_DRIVER]
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
index 277ccfd24546..01d39626d14c 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
@@ -31,12 +31,14 @@ [Packages]
ArmVirtPkg/ArmVirtPkg.dec
MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
[LibraryClasses]
DebugLib
DevicePathLib
DxeServicesTableLib
MemoryAllocationLib
+ PciHostBridgeUtilityLib
PciPcdProducerLib
[FixedPcd]
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
index 496b192d2291..d554479bf0de 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
@@ -7,12 +7,13 @@
**/
#include <PiDxe.h>
-#include <Library/PciHostBridgeLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
+#include <Library/PciHostBridgeLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/FdtClient.h>
@@ -50,11 +51,6 @@ STATIC EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath = {
}
};
-GLOBAL_REMOVE_IF_UNREFERENCED
-CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] = {
- L"Mem", L"I/O", L"Bus"
-};
-
//
// We expect the "ranges" property of "pci-host-ecam-generic" to consist of
// records like this.
@@ -435,39 +431,5 @@ PciHostBridgeResourceConflict (
VOID *Configuration
)
{
- EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;
- UINTN RootBridgeIndex;
- DEBUG ((EFI_D_ERROR, "PciHostBridge: Resource conflict happens!\n"));
-
- RootBridgeIndex = 0;
- Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;
- while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
- DEBUG ((EFI_D_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));
- for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
- ASSERT (Descriptor->ResType <
- (sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) /
- sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0])
- )
- );
- DEBUG ((EFI_D_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 ((EFI_D_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);
}
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v6 03/11] OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
2021-01-19 1:12 ` [PATCH v6 01/11] OvmfPkg: Introduce PciHostBridgeUtilityLib class Jiahui Cen
2021-01-19 1:12 ` [PATCH v6 02/11] ArmVirtPkg: Refactor with PciHostBridgeUtilityLib Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-20 12:14 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:12 ` [PATCH v6 04/11] OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge() Jiahui Cen
` (8 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen
OvmfPkg/PciHostBridgeLib instance fails to list its PcdLib dependency,
both between the #include directives, and in the INF file. So let's list
the dependency.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 1 +
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 1 +
3 files changed, 3 insertions(+)
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index 4c56f3c90b3b..cec3f1631a72 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -39,6 +39,7 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
+ PcdLib
PciHostBridgeUtilityLib
PciLib
QemuFwCfgLib
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 4a176347fd49..bf32455b9f0d 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -19,6 +19,7 @@
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index e161f14375ca..95ed0a280b9b 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -17,6 +17,7 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
#include <Library/PciLib.h>
#include "PciHostBridge.h"
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 03/11] OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
2021-01-19 1:12 ` [PATCH v6 03/11] OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency Jiahui Cen
@ 2021-01-20 12:14 ` Laszlo Ersek
2021-01-20 13:29 ` Laszlo Ersek
0 siblings, 1 reply; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 12:14 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin
On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
> OvmfPkg/PciHostBridgeLib instance fails to list its PcdLib dependency,
> both between the #include directives, and in the INF file. So let's list
> the dependency.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Anthony Perard <anthony.perard@citrix.com>
> Cc: Julien Grall <julien@xen.org>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> ---
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 1 +
> OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 1 +
> 3 files changed, 3 insertions(+)
>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> index 4c56f3c90b3b..cec3f1631a72 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> @@ -39,6 +39,7 @@ [LibraryClasses]
> DebugLib
> DevicePathLib
> MemoryAllocationLib
> + PcdLib
> PciHostBridgeUtilityLib
> PciLib
> QemuFwCfgLib
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index 4a176347fd49..bf32455b9f0d 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -19,6 +19,7 @@
> #include <Library/DebugLib.h>
> #include <Library/DevicePathLib.h>
> #include <Library/MemoryAllocationLib.h>
> +#include <Library/PcdLib.h>
> #include <Library/PciHostBridgeLib.h>
> #include <Library/PciHostBridgeUtilityLib.h>
> #include <Library/PciLib.h>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> index e161f14375ca..95ed0a280b9b 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> @@ -17,6 +17,7 @@
> #include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> #include <Library/MemoryAllocationLib.h>
> +#include <Library/PcdLib.h>
> #include <Library/PciHostBridgeLib.h>
> #include <Library/PciLib.h>
> #include "PciHostBridge.h"
>
At this stage, "XenSupport.c" doesn't seem to call any PcdLib API.
But, it's not a big deal.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks,
Laszlo
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 03/11] OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
2021-01-20 12:14 ` [edk2-devel] " Laszlo Ersek
@ 2021-01-20 13:29 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 13:29 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin
On 01/20/21 13:14, Laszlo Ersek wrote:
> On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
>> OvmfPkg/PciHostBridgeLib instance fails to list its PcdLib dependency,
>> both between the #include directives, and in the INF file. So let's list
>> the dependency.
>>
>> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>>
>> Cc: Jordan Justen <jordan.l.justen@intel.com>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
>> Cc: Anthony Perard <anthony.perard@citrix.com>
>> Cc: Julien Grall <julien@xen.org>
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> ---
>> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
>> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 1 +
>> OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 1 +
>> 3 files changed, 3 insertions(+)
>>
>> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
>> index 4c56f3c90b3b..cec3f1631a72 100644
>> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
>> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
>> @@ -39,6 +39,7 @@ [LibraryClasses]
>> DebugLib
>> DevicePathLib
>> MemoryAllocationLib
>> + PcdLib
>> PciHostBridgeUtilityLib
>> PciLib
>> QemuFwCfgLib
>> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
>> index 4a176347fd49..bf32455b9f0d 100644
>> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
>> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
>> @@ -19,6 +19,7 @@
>> #include <Library/DebugLib.h>
>> #include <Library/DevicePathLib.h>
>> #include <Library/MemoryAllocationLib.h>
>> +#include <Library/PcdLib.h>
>> #include <Library/PciHostBridgeLib.h>
>> #include <Library/PciHostBridgeUtilityLib.h>
>> #include <Library/PciLib.h>
>> diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
>> index e161f14375ca..95ed0a280b9b 100644
>> --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
>> +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
>> @@ -17,6 +17,7 @@
>> #include <Library/BaseMemoryLib.h>
>> #include <Library/DebugLib.h>
>> #include <Library/MemoryAllocationLib.h>
>> +#include <Library/PcdLib.h>
>> #include <Library/PciHostBridgeLib.h>
>> #include <Library/PciLib.h>
>> #include "PciHostBridge.h"
>>
>
> At this stage, "XenSupport.c" doesn't seem to call any PcdLib API.
... Yes, the #include directive belongs to patch#5, where XenSupport.c
gains a PcdGet16() call.
But, don't bother.
Laszlo
>
> But, it's not a big deal.
>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> Thanks,
> Laszlo
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 04/11] OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge()
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (2 preceding siblings ...)
2021-01-19 1:12 ` [PATCH v6 03/11] OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-20 12:36 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:12 ` [PATCH v6 05/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge() Jiahui Cen
` (7 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
Extract InitRootBridge() / UninitRootBridge() to PciHostBridgeUtilityLib
as common utility functions. No change of functionality.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 2 -
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 8 +
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 77 ++++++++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h | 56 -------
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 158 +-------------------
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 3 +-
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 158 ++++++++++++++++++++
7 files changed, 249 insertions(+), 213 deletions(-)
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index cec3f1631a72..7944f94b7743 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -37,7 +37,6 @@ [Packages]
[LibraryClasses]
BaseMemoryLib
DebugLib
- DevicePathLib
MemoryAllocationLib
PcdLib
PciHostBridgeUtilityLib
@@ -51,5 +50,4 @@ [Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size
- gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index 1ba8ec3e03c7..e3d0a3740952 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -30,8 +30,16 @@ [Sources]
PciHostBridgeUtilityLib.c
[Packages]
+ MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
OvmfPkg/OvmfPkg.dec
[LibraryClasses]
+ BaseMemoryLib
DebugLib
+ DevicePathLib
+ MemoryAllocationLib
+ PcdLib
+
+[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index 5ea25ed2f4f4..8a1ddc2f5e02 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -14,6 +14,83 @@
#define __PCI_HOST_BRIDGE_UTILITY_LIB_H__
+#include <Library/PciHostBridgeLib.h>
+
+
+/**
+ Utility function to initialize a PCI_ROOT_BRIDGE structure.
+
+ @param[in] Supports Supported attributes.
+
+ @param[in] Attributes Initial attributes.
+
+ @param[in] AllocAttributes Allocation attributes.
+
+ @param[in] RootBusNumber The bus number to store in RootBus.
+
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
+ assigned to any subordinate bus found behind any
+ PCI bridge hanging off this root bus.
+
+ The caller is repsonsible for ensuring that
+ RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then the
+ root bus has no room for subordinate buses.
+
+ @param[in] Io IO aperture.
+
+ @param[in] Mem MMIO aperture.
+
+ @param[in] MemAbove4G MMIO aperture above 4G.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
+ caller) that should be filled in by this
+ function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node, with
+ UID = RootBusNumber, has been allocated and
+ linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+**/
+EFI_STATUS
+EFIAPI
+PciHostBridgeUtilityInitRootBridge (
+ 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
+ );
+
+
+/**
+ Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with
+ PciHostBridgeUtilityInitRootBridge().
+
+ @param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller and
+ initialized with PciHostBridgeUtilityInitRootBridge(),
+ that should be uninitialized. This function doesn't free
+ RootBus.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityUninitRootBridge (
+ IN PCI_ROOT_BRIDGE *RootBus
+ );
+
+
/**
Utility function to inform the platform that the resource conflict happens.
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
index 134d7411214d..a2e4d8696281 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
@@ -11,59 +11,3 @@ PCI_ROOT_BRIDGE *
ScanForRootBridges (
UINTN *NumberOfRootBridges
);
-
-/**
- Initialize a PCI_ROOT_BRIDGE structure.
-
- @param[in] Supports Supported attributes.
-
- @param[in] Attributes Initial attributes.
-
- @param[in] AllocAttributes Allocation attributes.
-
- @param[in] RootBusNumber The bus number to store in RootBus.
-
- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
-
- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
-
- @param[in] Io IO aperture.
-
- @param[in] Mem MMIO aperture.
-
- @param[in] MemAbove4G MMIO aperture above 4G.
-
- @param[in] PMem Prefetchable MMIO aperture.
-
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
-
- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
-
- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
-
- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
-**/
-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
- );
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index bf32455b9f0d..07fa98110e98 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -10,14 +10,12 @@
#include <PiDxe.h>
#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/Q35MchIch9.h>
#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
-#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
@@ -27,156 +25,8 @@
#include "PciHostBridge.h"
-#pragma pack(1)
-typedef struct {
- ACPI_HID_DEVICE_PATH AcpiDevicePath;
- EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
-} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;
-#pragma pack ()
-
-
-STATIC
-CONST
-OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
- {
- {
- ACPI_DEVICE_PATH,
- ACPI_DP,
- {
- (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
- (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
- }
- },
- EISA_PNP_ID(0x0A03), // HID
- 0 // UID
- },
-
- {
- END_DEVICE_PATH_TYPE,
- END_ENTIRE_DEVICE_PATH_SUBTYPE,
- {
- END_DEVICE_PATH_LENGTH,
- 0
- }
- }
-};
-
STATIC PCI_ROOT_BRIDGE_APERTURE mNonExistAperture = { MAX_UINT64, 0 };
-/**
- Initialize a PCI_ROOT_BRIDGE structure.
-
- @param[in] Supports Supported attributes.
-
- @param[in] Attributes Initial attributes.
-
- @param[in] AllocAttributes Allocation attributes.
-
- @param[in] RootBusNumber The bus number to store in RootBus.
-
- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
-
- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
-
- @param[in] Io IO aperture.
-
- @param[in] Mem MMIO aperture.
-
- @param[in] MemAbove4G MMIO aperture above 4G.
-
- @param[in] PMem Prefetchable MMIO aperture.
-
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
-
- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
-
- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
-
- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
-**/
-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
- )
-{
- OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;
-
- //
- // Be safe if other fields are added to PCI_ROOT_BRIDGE later.
- //
- ZeroMem (RootBus, sizeof *RootBus);
-
- RootBus->Segment = 0;
-
- RootBus->Supports = Supports;
- RootBus->Attributes = Attributes;
-
- RootBus->DmaAbove4G = FALSE;
-
- RootBus->AllocationAttributes = AllocAttributes;
- RootBus->Bus.Base = RootBusNumber;
- RootBus->Bus.Limit = 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 = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
- INTEL_Q35_MCH_DEVICE_ID);
-
- DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
- &mRootBridgeDevicePathTemplate);
- if (DevicePath == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
- return EFI_OUT_OF_RESOURCES;
- }
- DevicePath->AcpiDevicePath.UID = RootBusNumber;
- RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
-
- DEBUG ((DEBUG_INFO,
- "%a: populated root bus %d, with room for %d subordinate bus(es)\n",
- __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));
- return EFI_SUCCESS;
-}
-
-
-/**
- Uninitialize a PCI_ROOT_BRIDGE structure set up with InitRootBridge().
-
- param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller 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.
@@ -297,7 +147,7 @@ PciHostBridgeGetRootBridges (
// because now we know how big a bus number range *that* one has, for any
// subordinate buses that might exist behind PCI bridges hanging off it.
//
- Status = InitRootBridge (
+ Status = PciHostBridgeUtilityInitRootBridge (
Attributes,
Attributes,
AllocationAttributes,
@@ -322,7 +172,7 @@ PciHostBridgeGetRootBridges (
// Install the last root bus (which might be the only, ie. main, root bus, if
// we've found no extra root buses).
//
- Status = InitRootBridge (
+ Status = PciHostBridgeUtilityInitRootBridge (
Attributes,
Attributes,
AllocationAttributes,
@@ -346,7 +196,7 @@ PciHostBridgeGetRootBridges (
FreeBridges:
while (Initialized > 0) {
--Initialized;
- UninitRootBridge (&Bridges[Initialized]);
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
}
FreePool (Bridges);
@@ -375,7 +225,7 @@ PciHostBridgeFreeRootBridges (
do {
--Count;
- UninitRootBridge (&Bridges[Count]);
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
} while (Count > 0);
FreePool (Bridges);
diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index 95ed0a280b9b..5dfeba0e6e23 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -19,6 +19,7 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
#include "PciHostBridge.h"
@@ -453,7 +454,7 @@ ScanForRootBridges (
RootBridges
);
ASSERT (RootBridges != NULL);
- InitRootBridge (
+ PciHostBridgeUtilityInitRootBridge (
Attributes, Attributes, 0,
(UINT8) PrimaryBus, (UINT8) SubBus,
&Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture,
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index ac94e62612be..92b42566e5f8 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -11,16 +11,174 @@
**/
#include <IndustryStandard/Acpi10.h>
+#include <IndustryStandard/Q35MchIch9.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
+#pragma pack(1)
+typedef struct {
+ ACPI_HID_DEVICE_PATH AcpiDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;
+#pragma pack ()
+
+
GLOBAL_REMOVE_IF_UNREFERENCED
CHAR16 *mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[] = {
L"Mem", L"I/O", L"Bus"
};
+STATIC
+CONST
+OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
+ {
+ {
+ ACPI_DEVICE_PATH,
+ ACPI_DP,
+ {
+ (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
+ (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
+ }
+ },
+ EISA_PNP_ID(0x0A03), // HID
+ 0 // UID
+ },
+
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ END_DEVICE_PATH_LENGTH,
+ 0
+ }
+ }
+};
+
+
+/**
+ Utility function to initialize a PCI_ROOT_BRIDGE structure.
+
+ @param[in] Supports Supported attributes.
+
+ @param[in] Attributes Initial attributes.
+
+ @param[in] AllocAttributes Allocation attributes.
+
+ @param[in] RootBusNumber The bus number to store in RootBus.
+
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
+ assigned to any subordinate bus found behind any
+ PCI bridge hanging off this root bus.
+
+ The caller is repsonsible for ensuring that
+ RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then the
+ root bus has no room for subordinate buses.
+
+ @param[in] Io IO aperture.
+
+ @param[in] Mem MMIO aperture.
+
+ @param[in] MemAbove4G MMIO aperture above 4G.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
+ caller) that should be filled in by this
+ function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node, with
+ UID = RootBusNumber, has been allocated and
+ linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+**/
+EFI_STATUS
+EFIAPI
+PciHostBridgeUtilityInitRootBridge (
+ 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
+ )
+{
+ OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;
+
+ //
+ // Be safe if other fields are added to PCI_ROOT_BRIDGE later.
+ //
+ ZeroMem (RootBus, sizeof *RootBus);
+
+ RootBus->Segment = 0;
+
+ RootBus->Supports = Supports;
+ RootBus->Attributes = Attributes;
+
+ RootBus->DmaAbove4G = FALSE;
+
+ RootBus->AllocationAttributes = AllocAttributes;
+ RootBus->Bus.Base = RootBusNumber;
+ RootBus->Bus.Limit = 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 = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
+ INTEL_Q35_MCH_DEVICE_ID);
+
+ DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
+ &mRootBridgeDevicePathTemplate);
+ if (DevicePath == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
+ return EFI_OUT_OF_RESOURCES;
+ }
+ DevicePath->AcpiDevicePath.UID = RootBusNumber;
+ RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
+
+ DEBUG ((DEBUG_INFO,
+ "%a: populated root bus %d, with room for %d subordinate bus(es)\n",
+ __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));
+ return EFI_SUCCESS;
+}
+
+
+/**
+ Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with
+ PciHostBridgeUtilityInitRootBridge().
+
+ @param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller and
+ initialized with PciHostBridgeUtilityInitRootBridge(),
+ that should be uninitialized. This function doesn't free
+ RootBus.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityUninitRootBridge (
+ IN PCI_ROOT_BRIDGE *RootBus
+ )
+{
+ FreePool (RootBus->DevicePath);
+}
+
+
/**
Utility function to inform the platform that the resource conflict happens.
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 04/11] OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge()
2021-01-19 1:12 ` [PATCH v6 04/11] OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge() Jiahui Cen
@ 2021-01-20 12:36 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 12:36 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
> Extract InitRootBridge() / UninitRootBridge() to PciHostBridgeUtilityLib
> as common utility functions. No change of functionality.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Anthony Perard <anthony.perard@citrix.com>
> Cc: Julien Grall <julien@xen.org>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> ---
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 2 -
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 8 +
> OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 77 ++++++++++
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h | 56 -------
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 158 +-------------------
> OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 3 +-
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 158 ++++++++++++++++++++
> 7 files changed, 249 insertions(+), 213 deletions(-)
>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> index cec3f1631a72..7944f94b7743 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> @@ -37,7 +37,6 @@ [Packages]
> [LibraryClasses]
> BaseMemoryLib
> DebugLib
> - DevicePathLib
> MemoryAllocationLib
> PcdLib
> PciHostBridgeUtilityLib
> @@ -51,5 +50,4 @@ [Pcd]
> gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size
> gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base
> gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size
> - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
> gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> index 1ba8ec3e03c7..e3d0a3740952 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> @@ -30,8 +30,16 @@ [Sources]
> PciHostBridgeUtilityLib.c
>
> [Packages]
> + MdeModulePkg/MdeModulePkg.dec
> MdePkg/MdePkg.dec
> OvmfPkg/OvmfPkg.dec
>
> [LibraryClasses]
> + BaseMemoryLib
> DebugLib
> + DevicePathLib
> + MemoryAllocationLib
> + PcdLib
> +
> +[Pcd]
> + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> index 5ea25ed2f4f4..8a1ddc2f5e02 100644
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> @@ -14,6 +14,83 @@
> #define __PCI_HOST_BRIDGE_UTILITY_LIB_H__
>
>
> +#include <Library/PciHostBridgeLib.h>
> +
> +
> +/**
> + Utility function to initialize a PCI_ROOT_BRIDGE structure.
> +
> + @param[in] Supports Supported attributes.
> +
> + @param[in] Attributes Initial attributes.
> +
> + @param[in] AllocAttributes Allocation attributes.
> +
> + @param[in] RootBusNumber The bus number to store in RootBus.
> +
> + @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
> + assigned to any subordinate bus found behind any
> + PCI bridge hanging off this root bus.
> +
> + The caller is repsonsible for ensuring that
> + RootBusNumber <= MaxSubBusNumber. If
> + RootBusNumber equals MaxSubBusNumber, then the
> + root bus has no room for subordinate buses.
> +
> + @param[in] Io IO aperture.
> +
> + @param[in] Mem MMIO aperture.
> +
> + @param[in] MemAbove4G MMIO aperture above 4G.
> +
> + @param[in] PMem Prefetchable MMIO aperture.
> +
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> +
> + @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
> + caller) that should be filled in by this
> + function.
> +
> + @retval EFI_SUCCESS Initialization successful. A device path
> + consisting of an ACPI device path node, with
> + UID = RootBusNumber, has been allocated and
> + linked into RootBus.
> +
> + @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> +**/
> +EFI_STATUS
> +EFIAPI
> +PciHostBridgeUtilityInitRootBridge (
> + 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
> + );
> +
> +
> +/**
> + Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with
> + PciHostBridgeUtilityInitRootBridge().
> +
> + @param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller and
> + initialized with PciHostBridgeUtilityInitRootBridge(),
> + that should be uninitialized. This function doesn't free
> + RootBus.
> +**/
> +VOID
> +EFIAPI
> +PciHostBridgeUtilityUninitRootBridge (
> + IN PCI_ROOT_BRIDGE *RootBus
> + );
> +
> +
> /**
> Utility function to inform the platform that the resource conflict happens.
>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
> index 134d7411214d..a2e4d8696281 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
> @@ -11,59 +11,3 @@ PCI_ROOT_BRIDGE *
> ScanForRootBridges (
> UINTN *NumberOfRootBridges
> );
> -
> -/**
> - Initialize a PCI_ROOT_BRIDGE structure.
> -
> - @param[in] Supports Supported attributes.
> -
> - @param[in] Attributes Initial attributes.
> -
> - @param[in] AllocAttributes Allocation attributes.
> -
> - @param[in] RootBusNumber The bus number to store in RootBus.
> -
> - @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
> - assigned to any subordinate bus found behind any
> - PCI bridge hanging off this root bus.
> -
> - The caller is repsonsible for ensuring that
> - RootBusNumber <= MaxSubBusNumber. If
> - RootBusNumber equals MaxSubBusNumber, then the
> - root bus has no room for subordinate buses.
> -
> - @param[in] Io IO aperture.
> -
> - @param[in] Mem MMIO aperture.
> -
> - @param[in] MemAbove4G MMIO aperture above 4G.
> -
> - @param[in] PMem Prefetchable MMIO aperture.
> -
> - @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> -
> - @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
> - caller) that should be filled in by this
> - function.
> -
> - @retval EFI_SUCCESS Initialization successful. A device path
> - consisting of an ACPI device path node, with
> - UID = RootBusNumber, has been allocated and
> - linked into RootBus.
> -
> - @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> -**/
> -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
> - );
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index bf32455b9f0d..07fa98110e98 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -10,14 +10,12 @@
> #include <PiDxe.h>
>
> #include <IndustryStandard/Pci.h>
> -#include <IndustryStandard/Q35MchIch9.h>
>
> #include <Protocol/PciHostBridgeResourceAllocation.h>
> #include <Protocol/PciRootBridgeIo.h>
>
> #include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> -#include <Library/DevicePathLib.h>
> #include <Library/MemoryAllocationLib.h>
> #include <Library/PcdLib.h>
> #include <Library/PciHostBridgeLib.h>
> @@ -27,156 +25,8 @@
> #include "PciHostBridge.h"
>
>
> -#pragma pack(1)
> -typedef struct {
> - ACPI_HID_DEVICE_PATH AcpiDevicePath;
> - EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
> -} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;
> -#pragma pack ()
> -
> -
> -STATIC
> -CONST
> -OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
> - {
> - {
> - ACPI_DEVICE_PATH,
> - ACPI_DP,
> - {
> - (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
> - (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
> - }
> - },
> - EISA_PNP_ID(0x0A03), // HID
> - 0 // UID
> - },
> -
> - {
> - END_DEVICE_PATH_TYPE,
> - END_ENTIRE_DEVICE_PATH_SUBTYPE,
> - {
> - END_DEVICE_PATH_LENGTH,
> - 0
> - }
> - }
> -};
> -
> STATIC PCI_ROOT_BRIDGE_APERTURE mNonExistAperture = { MAX_UINT64, 0 };
>
> -/**
> - Initialize a PCI_ROOT_BRIDGE structure.
> -
> - @param[in] Supports Supported attributes.
> -
> - @param[in] Attributes Initial attributes.
> -
> - @param[in] AllocAttributes Allocation attributes.
> -
> - @param[in] RootBusNumber The bus number to store in RootBus.
> -
> - @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
> - assigned to any subordinate bus found behind any
> - PCI bridge hanging off this root bus.
> -
> - The caller is repsonsible for ensuring that
> - RootBusNumber <= MaxSubBusNumber. If
> - RootBusNumber equals MaxSubBusNumber, then the
> - root bus has no room for subordinate buses.
> -
> - @param[in] Io IO aperture.
> -
> - @param[in] Mem MMIO aperture.
> -
> - @param[in] MemAbove4G MMIO aperture above 4G.
> -
> - @param[in] PMem Prefetchable MMIO aperture.
> -
> - @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> -
> - @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
> - caller) that should be filled in by this
> - function.
> -
> - @retval EFI_SUCCESS Initialization successful. A device path
> - consisting of an ACPI device path node, with
> - UID = RootBusNumber, has been allocated and
> - linked into RootBus.
> -
> - @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> -**/
> -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
> - )
> -{
> - OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;
> -
> - //
> - // Be safe if other fields are added to PCI_ROOT_BRIDGE later.
> - //
> - ZeroMem (RootBus, sizeof *RootBus);
> -
> - RootBus->Segment = 0;
> -
> - RootBus->Supports = Supports;
> - RootBus->Attributes = Attributes;
> -
> - RootBus->DmaAbove4G = FALSE;
> -
> - RootBus->AllocationAttributes = AllocAttributes;
> - RootBus->Bus.Base = RootBusNumber;
> - RootBus->Bus.Limit = 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 = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
> - INTEL_Q35_MCH_DEVICE_ID);
> -
> - DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
> - &mRootBridgeDevicePathTemplate);
> - if (DevicePath == NULL) {
> - DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
> - return EFI_OUT_OF_RESOURCES;
> - }
> - DevicePath->AcpiDevicePath.UID = RootBusNumber;
> - RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
> -
> - DEBUG ((DEBUG_INFO,
> - "%a: populated root bus %d, with room for %d subordinate bus(es)\n",
> - __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));
> - return EFI_SUCCESS;
> -}
> -
> -
> -/**
> - Uninitialize a PCI_ROOT_BRIDGE structure set up with InitRootBridge().
> -
> - param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller 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.
> @@ -297,7 +147,7 @@ PciHostBridgeGetRootBridges (
> // because now we know how big a bus number range *that* one has, for any
> // subordinate buses that might exist behind PCI bridges hanging off it.
> //
> - Status = InitRootBridge (
> + Status = PciHostBridgeUtilityInitRootBridge (
> Attributes,
> Attributes,
> AllocationAttributes,
> @@ -322,7 +172,7 @@ PciHostBridgeGetRootBridges (
> // Install the last root bus (which might be the only, ie. main, root bus, if
> // we've found no extra root buses).
> //
> - Status = InitRootBridge (
> + Status = PciHostBridgeUtilityInitRootBridge (
> Attributes,
> Attributes,
> AllocationAttributes,
> @@ -346,7 +196,7 @@ PciHostBridgeGetRootBridges (
> FreeBridges:
> while (Initialized > 0) {
> --Initialized;
> - UninitRootBridge (&Bridges[Initialized]);
> + PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
> }
>
> FreePool (Bridges);
> @@ -375,7 +225,7 @@ PciHostBridgeFreeRootBridges (
>
> do {
> --Count;
> - UninitRootBridge (&Bridges[Count]);
> + PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
> } while (Count > 0);
>
> FreePool (Bridges);
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> index 95ed0a280b9b..5dfeba0e6e23 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> @@ -19,6 +19,7 @@
> #include <Library/MemoryAllocationLib.h>
> #include <Library/PcdLib.h>
> #include <Library/PciHostBridgeLib.h>
> +#include <Library/PciHostBridgeUtilityLib.h>
> #include <Library/PciLib.h>
> #include "PciHostBridge.h"
>
> @@ -453,7 +454,7 @@ ScanForRootBridges (
> RootBridges
> );
> ASSERT (RootBridges != NULL);
> - InitRootBridge (
> + PciHostBridgeUtilityInitRootBridge (
> Attributes, Attributes, 0,
> (UINT8) PrimaryBus, (UINT8) SubBus,
> &Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture,
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> index ac94e62612be..92b42566e5f8 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> @@ -11,16 +11,174 @@
> **/
>
> #include <IndustryStandard/Acpi10.h>
> +#include <IndustryStandard/Q35MchIch9.h>
> +#include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/PcdLib.h>
> #include <Library/PciHostBridgeUtilityLib.h>
>
>
> +#pragma pack(1)
> +typedef struct {
> + ACPI_HID_DEVICE_PATH AcpiDevicePath;
> + EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
> +} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;
> +#pragma pack ()
> +
> +
> GLOBAL_REMOVE_IF_UNREFERENCED
> CHAR16 *mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[] = {
> L"Mem", L"I/O", L"Bus"
> };
>
>
> +STATIC
> +CONST
> +OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
> + {
> + {
> + ACPI_DEVICE_PATH,
> + ACPI_DP,
> + {
> + (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
> + (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
> + }
> + },
> + EISA_PNP_ID(0x0A03), // HID
> + 0 // UID
> + },
> +
> + {
> + END_DEVICE_PATH_TYPE,
> + END_ENTIRE_DEVICE_PATH_SUBTYPE,
> + {
> + END_DEVICE_PATH_LENGTH,
> + 0
> + }
> + }
> +};
> +
> +
> +/**
> + Utility function to initialize a PCI_ROOT_BRIDGE structure.
> +
> + @param[in] Supports Supported attributes.
> +
> + @param[in] Attributes Initial attributes.
> +
> + @param[in] AllocAttributes Allocation attributes.
> +
> + @param[in] RootBusNumber The bus number to store in RootBus.
> +
> + @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
> + assigned to any subordinate bus found behind any
> + PCI bridge hanging off this root bus.
> +
> + The caller is repsonsible for ensuring that
> + RootBusNumber <= MaxSubBusNumber. If
> + RootBusNumber equals MaxSubBusNumber, then the
> + root bus has no room for subordinate buses.
> +
> + @param[in] Io IO aperture.
> +
> + @param[in] Mem MMIO aperture.
> +
> + @param[in] MemAbove4G MMIO aperture above 4G.
> +
> + @param[in] PMem Prefetchable MMIO aperture.
> +
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> +
> + @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
> + caller) that should be filled in by this
> + function.
> +
> + @retval EFI_SUCCESS Initialization successful. A device path
> + consisting of an ACPI device path node, with
> + UID = RootBusNumber, has been allocated and
> + linked into RootBus.
> +
> + @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> +**/
> +EFI_STATUS
> +EFIAPI
> +PciHostBridgeUtilityInitRootBridge (
> + 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
> + )
> +{
> + OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;
> +
> + //
> + // Be safe if other fields are added to PCI_ROOT_BRIDGE later.
> + //
> + ZeroMem (RootBus, sizeof *RootBus);
> +
> + RootBus->Segment = 0;
> +
> + RootBus->Supports = Supports;
> + RootBus->Attributes = Attributes;
> +
> + RootBus->DmaAbove4G = FALSE;
> +
> + RootBus->AllocationAttributes = AllocAttributes;
> + RootBus->Bus.Base = RootBusNumber;
> + RootBus->Bus.Limit = 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 = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
> + INTEL_Q35_MCH_DEVICE_ID);
> +
> + DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
> + &mRootBridgeDevicePathTemplate);
> + if (DevicePath == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
> + return EFI_OUT_OF_RESOURCES;
> + }
> + DevicePath->AcpiDevicePath.UID = RootBusNumber;
> + RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
> +
> + DEBUG ((DEBUG_INFO,
> + "%a: populated root bus %d, with room for %d subordinate bus(es)\n",
> + __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));
> + return EFI_SUCCESS;
> +}
> +
> +
> +/**
> + Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with
> + PciHostBridgeUtilityInitRootBridge().
> +
> + @param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller and
> + initialized with PciHostBridgeUtilityInitRootBridge(),
> + that should be uninitialized. This function doesn't free
> + RootBus.
> +**/
> +VOID
> +EFIAPI
> +PciHostBridgeUtilityUninitRootBridge (
> + IN PCI_ROOT_BRIDGE *RootBus
> + )
> +{
> + FreePool (RootBus->DevicePath);
> +}
> +
> +
> /**
> Utility function to inform the platform that the resource conflict happens.
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 05/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (3 preceding siblings ...)
2021-01-19 1:12 ` [PATCH v6 04/11] OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge() Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-20 12:41 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:12 ` [PATCH v6 06/11] ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge Jiahui Cen
` (6 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
Extend parameter list of PciHostBridgeUtilityInitRootBridge() with
DmaAbove4G and NoExtendedConfigSpace to prepare for sharing with
ArmVirtPkg.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 4 --
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 56 +++++++++--------
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 5 ++
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 1 +
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 63 +++++++++++---------
6 files changed, 73 insertions(+), 57 deletions(-)
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index 7944f94b7743..72458262cb42 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -50,4 +50,5 @@ [Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index e3d0a3740952..4d6764b702f4 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -39,7 +39,3 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
- PcdLib
-
-[Pcd]
- gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index 8a1ddc2f5e02..a44ad5034520 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -20,43 +20,49 @@
/**
Utility function to initialize a PCI_ROOT_BRIDGE structure.
- @param[in] Supports Supported attributes.
+ @param[in] Supports Supported attributes.
- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.
- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.
- @param[in] RootBusNumber The bus number to store in RootBus.
+ @param[in] DmaAbove4G DMA above 4GB memory.
- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.
- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
+ @param[in] RootBusNumber The bus number to store in RootBus.
- @param[in] Io IO aperture.
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can
+ be assigned to any subordinate bus found
+ behind any PCI bridge hanging off this
+ root bus.
- @param[in] Mem MMIO aperture.
+ The caller is repsonsible for ensuring
+ that RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then
+ the root bus has no room for subordinate
+ buses.
- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.
- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.
- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
+ @param[in] PMem Prefetchable MMIO aperture.
- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated
+ by the caller) that should be filled in by
+ this function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node,
+ with UID = RootBusNumber, has been
+ allocated and linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
**/
EFI_STATUS
EFIAPI
@@ -64,6 +70,8 @@ PciHostBridgeUtilityInitRootBridge (
IN UINT64 Supports,
IN UINT64 Attributes,
IN UINT64 AllocAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN UINT8 RootBusNumber,
IN UINT8 MaxSubBusNumber,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 07fa98110e98..8758d7c12bf0 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -10,6 +10,7 @@
#include <PiDxe.h>
#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/Q35MchIch9.h>
#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>
@@ -151,6 +152,8 @@ PciHostBridgeGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
(UINT8) LastRootBridgeNumber,
(UINT8) (RootBridgeNumber - 1),
&Io,
@@ -176,6 +179,8 @@ PciHostBridgeGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
(UINT8) LastRootBridgeNumber,
PCI_MAX_BUS,
&Io,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index 5dfeba0e6e23..9ef39f01821b 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -456,6 +456,7 @@ ScanForRootBridges (
ASSERT (RootBridges != NULL);
PciHostBridgeUtilityInitRootBridge (
Attributes, Attributes, 0,
+ FALSE, PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
(UINT8) PrimaryBus, (UINT8) SubBus,
&Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture,
&RootBridges[*NumberOfRootBridges]
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index 92b42566e5f8..bed2d87ea89c 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -11,12 +11,10 @@
**/
#include <IndustryStandard/Acpi10.h>
-#include <IndustryStandard/Q35MchIch9.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
-#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
@@ -64,43 +62,49 @@ OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
/**
Utility function to initialize a PCI_ROOT_BRIDGE structure.
- @param[in] Supports Supported attributes.
+ @param[in] Supports Supported attributes.
- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.
- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.
- @param[in] RootBusNumber The bus number to store in RootBus.
+ @param[in] DmaAbove4G DMA above 4GB memory.
- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.
- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
+ @param[in] RootBusNumber The bus number to store in RootBus.
- @param[in] Io IO aperture.
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can
+ be assigned to any subordinate bus found
+ behind any PCI bridge hanging off this
+ root bus.
- @param[in] Mem MMIO aperture.
+ The caller is repsonsible for ensuring
+ that RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then
+ the root bus has no room for subordinate
+ buses.
- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.
- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.
- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
+ @param[in] PMem Prefetchable MMIO aperture.
- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated
+ by the caller) that should be filled in by
+ this function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node,
+ with UID = RootBusNumber, has been
+ allocated and linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
**/
EFI_STATUS
EFIAPI
@@ -108,6 +112,8 @@ PciHostBridgeUtilityInitRootBridge (
IN UINT64 Supports,
IN UINT64 Attributes,
IN UINT64 AllocAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN UINT8 RootBusNumber,
IN UINT8 MaxSubBusNumber,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
@@ -130,7 +136,7 @@ PciHostBridgeUtilityInitRootBridge (
RootBus->Supports = Supports;
RootBus->Attributes = Attributes;
- RootBus->DmaAbove4G = FALSE;
+ RootBus->DmaAbove4G = DmaAbove4G;
RootBus->AllocationAttributes = AllocAttributes;
RootBus->Bus.Base = RootBusNumber;
@@ -141,8 +147,7 @@ PciHostBridgeUtilityInitRootBridge (
CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));
CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));
- RootBus->NoExtendedConfigSpace = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
- INTEL_Q35_MCH_DEVICE_ID);
+ RootBus->NoExtendedConfigSpace = NoExtendedConfigSpace;
DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
&mRootBridgeDevicePathTemplate);
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 05/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()
2021-01-19 1:12 ` [PATCH v6 05/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge() Jiahui Cen
@ 2021-01-20 12:41 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 12:41 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
> Extend parameter list of PciHostBridgeUtilityInitRootBridge() with
> DmaAbove4G and NoExtendedConfigSpace to prepare for sharing with
> ArmVirtPkg.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Anthony Perard <anthony.perard@citrix.com>
> Cc: Julien Grall <julien@xen.org>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> ---
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 4 --
> OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 56 +++++++++--------
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 5 ++
> OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 1 +
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 63 +++++++++++---------
> 6 files changed, 73 insertions(+), 57 deletions(-)
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> index 7944f94b7743..72458262cb42 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> @@ -50,4 +50,5 @@ [Pcd]
> gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size
> gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base
> gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size
> + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
> gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> index e3d0a3740952..4d6764b702f4 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> @@ -39,7 +39,3 @@ [LibraryClasses]
> DebugLib
> DevicePathLib
> MemoryAllocationLib
> - PcdLib
> -
> -[Pcd]
> - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> index 8a1ddc2f5e02..a44ad5034520 100644
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> @@ -20,43 +20,49 @@
> /**
> Utility function to initialize a PCI_ROOT_BRIDGE structure.
>
> - @param[in] Supports Supported attributes.
> + @param[in] Supports Supported attributes.
>
> - @param[in] Attributes Initial attributes.
> + @param[in] Attributes Initial attributes.
>
> - @param[in] AllocAttributes Allocation attributes.
> + @param[in] AllocAttributes Allocation attributes.
>
> - @param[in] RootBusNumber The bus number to store in RootBus.
> + @param[in] DmaAbove4G DMA above 4GB memory.
>
> - @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
> - assigned to any subordinate bus found behind any
> - PCI bridge hanging off this root bus.
> + @param[in] NoExtendedConfigSpace No Extended Config Space.
>
> - The caller is repsonsible for ensuring that
> - RootBusNumber <= MaxSubBusNumber. If
> - RootBusNumber equals MaxSubBusNumber, then the
> - root bus has no room for subordinate buses.
> + @param[in] RootBusNumber The bus number to store in RootBus.
>
> - @param[in] Io IO aperture.
> + @param[in] MaxSubBusNumber The inclusive maximum bus number that can
> + be assigned to any subordinate bus found
> + behind any PCI bridge hanging off this
> + root bus.
>
> - @param[in] Mem MMIO aperture.
> + The caller is repsonsible for ensuring
> + that RootBusNumber <= MaxSubBusNumber. If
> + RootBusNumber equals MaxSubBusNumber, then
> + the root bus has no room for subordinate
> + buses.
>
> - @param[in] MemAbove4G MMIO aperture above 4G.
> + @param[in] Io IO aperture.
>
> - @param[in] PMem Prefetchable MMIO aperture.
> + @param[in] Mem MMIO aperture.
>
> - @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> + @param[in] MemAbove4G MMIO aperture above 4G.
>
> - @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
> - caller) that should be filled in by this
> - function.
> + @param[in] PMem Prefetchable MMIO aperture.
>
> - @retval EFI_SUCCESS Initialization successful. A device path
> - consisting of an ACPI device path node, with
> - UID = RootBusNumber, has been allocated and
> - linked into RootBus.
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
>
> - @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> + @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated
> + by the caller) that should be filled in by
> + this function.
> +
> + @retval EFI_SUCCESS Initialization successful. A device path
> + consisting of an ACPI device path node,
> + with UID = RootBusNumber, has been
> + allocated and linked into RootBus.
> +
> + @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> **/
> EFI_STATUS
> EFIAPI
> @@ -64,6 +70,8 @@ PciHostBridgeUtilityInitRootBridge (
> IN UINT64 Supports,
> IN UINT64 Attributes,
> IN UINT64 AllocAttributes,
> + IN BOOLEAN DmaAbove4G,
> + IN BOOLEAN NoExtendedConfigSpace,
> IN UINT8 RootBusNumber,
> IN UINT8 MaxSubBusNumber,
> IN PCI_ROOT_BRIDGE_APERTURE *Io,
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index 07fa98110e98..8758d7c12bf0 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -10,6 +10,7 @@
> #include <PiDxe.h>
>
> #include <IndustryStandard/Pci.h>
> +#include <IndustryStandard/Q35MchIch9.h>
>
> #include <Protocol/PciHostBridgeResourceAllocation.h>
> #include <Protocol/PciRootBridgeIo.h>
> @@ -151,6 +152,8 @@ PciHostBridgeGetRootBridges (
> Attributes,
> Attributes,
> AllocationAttributes,
> + FALSE,
> + PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> (UINT8) LastRootBridgeNumber,
> (UINT8) (RootBridgeNumber - 1),
> &Io,
> @@ -176,6 +179,8 @@ PciHostBridgeGetRootBridges (
> Attributes,
> Attributes,
> AllocationAttributes,
> + FALSE,
> + PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> (UINT8) LastRootBridgeNumber,
> PCI_MAX_BUS,
> &Io,
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> index 5dfeba0e6e23..9ef39f01821b 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
> @@ -456,6 +456,7 @@ ScanForRootBridges (
> ASSERT (RootBridges != NULL);
> PciHostBridgeUtilityInitRootBridge (
> Attributes, Attributes, 0,
> + FALSE, PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> (UINT8) PrimaryBus, (UINT8) SubBus,
> &Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture,
> &RootBridges[*NumberOfRootBridges]
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> index 92b42566e5f8..bed2d87ea89c 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> @@ -11,12 +11,10 @@
> **/
>
> #include <IndustryStandard/Acpi10.h>
> -#include <IndustryStandard/Q35MchIch9.h>
> #include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> #include <Library/DevicePathLib.h>
> #include <Library/MemoryAllocationLib.h>
> -#include <Library/PcdLib.h>
> #include <Library/PciHostBridgeUtilityLib.h>
>
>
> @@ -64,43 +62,49 @@ OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
> /**
> Utility function to initialize a PCI_ROOT_BRIDGE structure.
>
> - @param[in] Supports Supported attributes.
> + @param[in] Supports Supported attributes.
>
> - @param[in] Attributes Initial attributes.
> + @param[in] Attributes Initial attributes.
>
> - @param[in] AllocAttributes Allocation attributes.
> + @param[in] AllocAttributes Allocation attributes.
>
> - @param[in] RootBusNumber The bus number to store in RootBus.
> + @param[in] DmaAbove4G DMA above 4GB memory.
>
> - @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
> - assigned to any subordinate bus found behind any
> - PCI bridge hanging off this root bus.
> + @param[in] NoExtendedConfigSpace No Extended Config Space.
>
> - The caller is repsonsible for ensuring that
> - RootBusNumber <= MaxSubBusNumber. If
> - RootBusNumber equals MaxSubBusNumber, then the
> - root bus has no room for subordinate buses.
> + @param[in] RootBusNumber The bus number to store in RootBus.
>
> - @param[in] Io IO aperture.
> + @param[in] MaxSubBusNumber The inclusive maximum bus number that can
> + be assigned to any subordinate bus found
> + behind any PCI bridge hanging off this
> + root bus.
>
> - @param[in] Mem MMIO aperture.
> + The caller is repsonsible for ensuring
> + that RootBusNumber <= MaxSubBusNumber. If
> + RootBusNumber equals MaxSubBusNumber, then
> + the root bus has no room for subordinate
> + buses.
>
> - @param[in] MemAbove4G MMIO aperture above 4G.
> + @param[in] Io IO aperture.
>
> - @param[in] PMem Prefetchable MMIO aperture.
> + @param[in] Mem MMIO aperture.
>
> - @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> + @param[in] MemAbove4G MMIO aperture above 4G.
>
> - @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
> - caller) that should be filled in by this
> - function.
> + @param[in] PMem Prefetchable MMIO aperture.
>
> - @retval EFI_SUCCESS Initialization successful. A device path
> - consisting of an ACPI device path node, with
> - UID = RootBusNumber, has been allocated and
> - linked into RootBus.
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
>
> - @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> + @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated
> + by the caller) that should be filled in by
> + this function.
> +
> + @retval EFI_SUCCESS Initialization successful. A device path
> + consisting of an ACPI device path node,
> + with UID = RootBusNumber, has been
> + allocated and linked into RootBus.
> +
> + @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
> **/
> EFI_STATUS
> EFIAPI
> @@ -108,6 +112,8 @@ PciHostBridgeUtilityInitRootBridge (
> IN UINT64 Supports,
> IN UINT64 Attributes,
> IN UINT64 AllocAttributes,
> + IN BOOLEAN DmaAbove4G,
> + IN BOOLEAN NoExtendedConfigSpace,
> IN UINT8 RootBusNumber,
> IN UINT8 MaxSubBusNumber,
> IN PCI_ROOT_BRIDGE_APERTURE *Io,
> @@ -130,7 +136,7 @@ PciHostBridgeUtilityInitRootBridge (
> RootBus->Supports = Supports;
> RootBus->Attributes = Attributes;
>
> - RootBus->DmaAbove4G = FALSE;
> + RootBus->DmaAbove4G = DmaAbove4G;
>
> RootBus->AllocationAttributes = AllocAttributes;
> RootBus->Bus.Base = RootBusNumber;
> @@ -141,8 +147,7 @@ PciHostBridgeUtilityInitRootBridge (
> CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));
> CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));
>
> - RootBus->NoExtendedConfigSpace = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
> - INTEL_Q35_MCH_DEVICE_ID);
> + RootBus->NoExtendedConfigSpace = NoExtendedConfigSpace;
>
> DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
> &mRootBridgeDevicePathTemplate);
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 06/11] ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (4 preceding siblings ...)
2021-01-19 1:12 ` [PATCH v6 05/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge() Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-20 12:46 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:12 ` [PATCH v6 07/11] OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges() Jiahui Cen
` (5 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
Rebase ArmVirtPkg/FdtPciHostBridgeLib to the new
PciHostBridgeUtilityInitRootBridge()/PciHostBridgeUtilityUninitRootBridge()
utility functions.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 1 +
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 124 ++++++++++----------
2 files changed, 61 insertions(+), 64 deletions(-)
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
index 01d39626d14c..b813a0851d2a 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
@@ -34,6 +34,7 @@ [Packages]
OvmfPkg/OvmfPkg.dec
[LibraryClasses]
+ BaseMemoryLib
DebugLib
DevicePathLib
DxeServicesTableLib
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
index d554479bf0de..3ec7992b6331 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
@@ -7,6 +7,7 @@
**/
#include <PiDxe.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DxeServicesTableLib.h>
@@ -20,37 +21,6 @@
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/PciHostBridgeResourceAllocation.h>
-#pragma pack(1)
-typedef struct {
- ACPI_HID_DEVICE_PATH AcpiDevicePath;
- EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
-} EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;
-#pragma pack ()
-
-STATIC EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath = {
- {
- {
- ACPI_DEVICE_PATH,
- ACPI_DP,
- {
- (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
- (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
- }
- },
- EISA_PNP_ID(0x0A03),
- 0
- },
-
- {
- END_DEVICE_PATH_TYPE,
- END_ENTIRE_DEVICE_PATH_SUBTYPE,
- {
- END_DEVICE_PATH_LENGTH,
- 0
- }
- }
-};
-
//
// We expect the "ranges" property of "pci-host-ecam-generic" to consist of
// records like this.
@@ -319,11 +289,18 @@ 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;
+ EFI_STATUS Status;
+ UINT64 Attributes;
+ UINT64 AllocationAttributes;
+ PCI_ROOT_BRIDGE_APERTURE Io;
+ PCI_ROOT_BRIDGE_APERTURE Mem;
+ PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
+ PCI_ROOT_BRIDGE_APERTURE PMem;
+ PCI_ROOT_BRIDGE_APERTURE PMemAbove4G;
if (PcdGet64 (PcdPciExpressBaseAddress) == 0) {
DEBUG ((EFI_D_INFO, "%a: PCI host bridge not present\n", __FUNCTION__));
@@ -341,33 +318,29 @@ PciHostBridgeGetRootBridges (
return NULL;
}
- *Count = 1;
+ ZeroMem (&Io, sizeof (Io));
+ ZeroMem (&Mem, sizeof (Mem));
+ ZeroMem (&MemAbove4G, sizeof (MemAbove4G));
+ ZeroMem (&PMem, sizeof (PMem));
+ ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G));
- mRootBridge.Segment = 0;
- mRootBridge.Supports = 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 = mRootBridge.Supports;
+ Attributes = 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.DmaAbove4G = TRUE;
- mRootBridge.NoExtendedConfigSpace = FALSE;
- mRootBridge.ResourceAssigned = FALSE;
+ AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;
- mRootBridge.AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;
-
- mRootBridge.Bus.Base = BusMin;
- mRootBridge.Bus.Limit = BusMax;
- mRootBridge.Io.Base = IoBase;
- mRootBridge.Io.Limit = IoBase + IoSize - 1;
- mRootBridge.Mem.Base = Mmio32Base;
- mRootBridge.Mem.Limit = Mmio32Base + Mmio32Size - 1;
+ Io.Base = IoBase;
+ Io.Limit = IoBase + IoSize - 1;
+ Mem.Base = Mmio32Base;
+ Mem.Limit = Mmio32Base + Mmio32Size - 1;
if (sizeof (UINTN) == sizeof (UINT64)) {
- mRootBridge.MemAbove4G.Base = Mmio64Base;
- mRootBridge.MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
+ MemAbove4G.Base = Mmio64Base;
+ MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
if (Mmio64Size > 0) {
- mRootBridge.AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
+ AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
}
} else {
//
@@ -376,19 +349,41 @@ PciHostBridgeGetRootBridges (
// BARs unless they are allocated below 4 GB. So ignore the range above
// 4 GB in this case.
//
- mRootBridge.MemAbove4G.Base = MAX_UINT64;
- mRootBridge.MemAbove4G.Limit = 0;
+ MemAbove4G.Base = MAX_UINT64;
+ MemAbove4G.Limit = 0;
}
//
// No separate ranges for prefetchable and non-prefetchable BARs
//
- mRootBridge.PMem.Base = MAX_UINT64;
- mRootBridge.PMem.Limit = 0;
- mRootBridge.PMemAbove4G.Base = MAX_UINT64;
- mRootBridge.PMemAbove4G.Limit = 0;
+ PMem.Base = MAX_UINT64;
+ PMem.Limit = 0;
+ PMemAbove4G.Base = MAX_UINT64;
+ PMemAbove4G.Limit = 0;
- mRootBridge.DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridgeDevicePath;
+ Status = PciHostBridgeUtilityInitRootBridge (
+ Attributes,
+ Attributes,
+ AllocationAttributes,
+ TRUE,
+ FALSE,
+ BusMin,
+ BusMax,
+ &Io,
+ &Mem,
+ &MemAbove4G,
+ &PMem,
+ &PMemAbove4G,
+ &mRootBridge
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to initialize PCI host bridge: %r\n",
+ __FUNCTION__, Status));
+ *Count = 0;
+ return NULL;
+ }
+
+ *Count = 1;
return &mRootBridge;
}
@@ -408,6 +403,7 @@ PciHostBridgeFreeRootBridges (
)
{
ASSERT (Count == 1);
+ PciHostBridgeUtilityUninitRootBridge (Bridges);
}
/**
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 06/11] ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge
2021-01-19 1:12 ` [PATCH v6 06/11] ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge Jiahui Cen
@ 2021-01-20 12:46 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 12:46 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
> Rebase ArmVirtPkg/FdtPciHostBridgeLib to the new
> PciHostBridgeUtilityInitRootBridge()/PciHostBridgeUtilityUninitRootBridge()
> utility functions.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Leif Lindholm <leif@nuviainc.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> ---
> ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 1 +
> ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 124 ++++++++++----------
> 2 files changed, 61 insertions(+), 64 deletions(-)
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
>
> diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
> index 01d39626d14c..b813a0851d2a 100644
> --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
> +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
> @@ -34,6 +34,7 @@ [Packages]
> OvmfPkg/OvmfPkg.dec
>
> [LibraryClasses]
> + BaseMemoryLib
> DebugLib
> DevicePathLib
> DxeServicesTableLib
> diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> index d554479bf0de..3ec7992b6331 100644
> --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> @@ -7,6 +7,7 @@
>
> **/
> #include <PiDxe.h>
> +#include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> #include <Library/DevicePathLib.h>
> #include <Library/DxeServicesTableLib.h>
> @@ -20,37 +21,6 @@
> #include <Protocol/PciRootBridgeIo.h>
> #include <Protocol/PciHostBridgeResourceAllocation.h>
>
> -#pragma pack(1)
> -typedef struct {
> - ACPI_HID_DEVICE_PATH AcpiDevicePath;
> - EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
> -} EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;
> -#pragma pack ()
> -
> -STATIC EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath = {
> - {
> - {
> - ACPI_DEVICE_PATH,
> - ACPI_DP,
> - {
> - (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
> - (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
> - }
> - },
> - EISA_PNP_ID(0x0A03),
> - 0
> - },
> -
> - {
> - END_DEVICE_PATH_TYPE,
> - END_ENTIRE_DEVICE_PATH_SUBTYPE,
> - {
> - END_DEVICE_PATH_LENGTH,
> - 0
> - }
> - }
> -};
> -
> //
> // We expect the "ranges" property of "pci-host-ecam-generic" to consist of
> // records like this.
> @@ -319,11 +289,18 @@ 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;
> + EFI_STATUS Status;
> + UINT64 Attributes;
> + UINT64 AllocationAttributes;
> + PCI_ROOT_BRIDGE_APERTURE Io;
> + PCI_ROOT_BRIDGE_APERTURE Mem;
> + PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
> + PCI_ROOT_BRIDGE_APERTURE PMem;
> + PCI_ROOT_BRIDGE_APERTURE PMemAbove4G;
>
> if (PcdGet64 (PcdPciExpressBaseAddress) == 0) {
> DEBUG ((EFI_D_INFO, "%a: PCI host bridge not present\n", __FUNCTION__));
> @@ -341,33 +318,29 @@ PciHostBridgeGetRootBridges (
> return NULL;
> }
>
> - *Count = 1;
> + ZeroMem (&Io, sizeof (Io));
> + ZeroMem (&Mem, sizeof (Mem));
> + ZeroMem (&MemAbove4G, sizeof (MemAbove4G));
> + ZeroMem (&PMem, sizeof (PMem));
> + ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G));
>
> - mRootBridge.Segment = 0;
> - mRootBridge.Supports = 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 = mRootBridge.Supports;
> + Attributes = 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.DmaAbove4G = TRUE;
> - mRootBridge.NoExtendedConfigSpace = FALSE;
> - mRootBridge.ResourceAssigned = FALSE;
> + AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;
>
> - mRootBridge.AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;
> -
> - mRootBridge.Bus.Base = BusMin;
> - mRootBridge.Bus.Limit = BusMax;
> - mRootBridge.Io.Base = IoBase;
> - mRootBridge.Io.Limit = IoBase + IoSize - 1;
> - mRootBridge.Mem.Base = Mmio32Base;
> - mRootBridge.Mem.Limit = Mmio32Base + Mmio32Size - 1;
> + Io.Base = IoBase;
> + Io.Limit = IoBase + IoSize - 1;
> + Mem.Base = Mmio32Base;
> + Mem.Limit = Mmio32Base + Mmio32Size - 1;
>
> if (sizeof (UINTN) == sizeof (UINT64)) {
> - mRootBridge.MemAbove4G.Base = Mmio64Base;
> - mRootBridge.MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
> + MemAbove4G.Base = Mmio64Base;
> + MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
> if (Mmio64Size > 0) {
> - mRootBridge.AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
> + AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
> }
> } else {
> //
> @@ -376,19 +349,41 @@ PciHostBridgeGetRootBridges (
> // BARs unless they are allocated below 4 GB. So ignore the range above
> // 4 GB in this case.
> //
> - mRootBridge.MemAbove4G.Base = MAX_UINT64;
> - mRootBridge.MemAbove4G.Limit = 0;
> + MemAbove4G.Base = MAX_UINT64;
> + MemAbove4G.Limit = 0;
> }
>
> //
> // No separate ranges for prefetchable and non-prefetchable BARs
> //
> - mRootBridge.PMem.Base = MAX_UINT64;
> - mRootBridge.PMem.Limit = 0;
> - mRootBridge.PMemAbove4G.Base = MAX_UINT64;
> - mRootBridge.PMemAbove4G.Limit = 0;
> + PMem.Base = MAX_UINT64;
> + PMem.Limit = 0;
> + PMemAbove4G.Base = MAX_UINT64;
> + PMemAbove4G.Limit = 0;
>
> - mRootBridge.DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridgeDevicePath;
> + Status = PciHostBridgeUtilityInitRootBridge (
> + Attributes,
> + Attributes,
> + AllocationAttributes,
> + TRUE,
> + FALSE,
> + BusMin,
> + BusMax,
> + &Io,
> + &Mem,
> + &MemAbove4G,
> + &PMem,
> + &PMemAbove4G,
> + &mRootBridge
> + );
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: failed to initialize PCI host bridge: %r\n",
> + __FUNCTION__, Status));
> + *Count = 0;
> + return NULL;
> + }
> +
> + *Count = 1;
>
> return &mRootBridge;
> }
> @@ -408,6 +403,7 @@ PciHostBridgeFreeRootBridges (
> )
> {
> ASSERT (Count == 1);
> + PciHostBridgeUtilityUninitRootBridge (Bridges);
> }
>
> /**
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 07/11] OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (5 preceding siblings ...)
2021-01-19 1:12 ` [PATCH v6 06/11] ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-20 13:07 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:12 ` [PATCH v6 08/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges Jiahui Cen
` (4 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
Extract PciHostBridgeGetRootBridges() / PciHostBridgeFreeRootBridges() to
PciHostBridgeUtilityLib as common utility functions to share support for
scanning extra root bridges.
No change of functionality.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 -
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 6 +
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 50 +++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 138 +-------------
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 197 ++++++++++++++++++++
5 files changed, 257 insertions(+), 135 deletions(-)
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index 72458262cb42..4610a0c1490b 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -41,7 +41,6 @@ [LibraryClasses]
PcdLib
PciHostBridgeUtilityLib
PciLib
- QemuFwCfgLib
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index 4d6764b702f4..fdae8cfe872e 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -39,3 +39,9 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
+ PcdLib
+ PciLib
+ QemuFwCfgLib
+
+[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index a44ad5034520..2b7d5d3725c3 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -99,6 +99,56 @@ PciHostBridgeUtilityUninitRootBridge (
);
+/**
+ Utility function to return all the root bridge instances in an array.
+
+ @param[out] Count The number of root bridge instances.
+
+ @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.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
+**/
+PCI_ROOT_BRIDGE *
+EFIAPI
+PciHostBridgeUtilityGetRootBridges (
+ OUT UINTN *Count,
+ IN UINT64 Attributes,
+ IN UINT64 AllocationAttributes,
+ 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
+ );
+
+
+/**
+ Utility function to free root bridge instances array from
+ PciHostBridgeUtilityGetRootBridges().
+
+ @param[in] Bridges The root bridge instances array.
+ @param[in] Count The count of the array.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityFreeRootBridges (
+ IN PCI_ROOT_BRIDGE *Bridges,
+ IN UINTN Count
+ );
+
+
/**
Utility function to inform the platform that the resource conflict happens.
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 8758d7c12bf0..6ac41ff853a9 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -9,9 +9,6 @@
**/
#include <PiDxe.h>
-#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/Q35MchIch9.h>
-
#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>
@@ -21,8 +18,6 @@
#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
-#include <Library/PciLib.h>
-#include <Library/QemuFwCfgLib.h>
#include "PciHostBridge.h"
@@ -44,14 +39,6 @@ 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;
@@ -89,123 +76,16 @@ PciHostBridgeGetRootBridges (
Mem.Base = PcdGet64 (PcdPciMmio32Base);
Mem.Limit = PcdGet64 (PcdPciMmio32Base) + (PcdGet64 (PcdPciMmio32Size) - 1);
- *Count = 0;
-
- //
- // QEMU provides the number of extra root buses, shortening the exhaustive
- // search below. If there is no hint, the feature is missing.
- //
- Status = QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgSize);
- if (EFI_ERROR (Status) || FwCfgSize != sizeof ExtraRootBridges) {
- ExtraRootBridges = 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 = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
- if (Bridges == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
- return NULL;
- }
- Initialized = 0;
-
- //
- // The "main" root bus is always there.
- //
- LastRootBridgeNumber = 0;
-
- //
- // Scan all other root buses. If function 0 of any device on a bus returns a
- // VendorId register value different from all-bits-one, then that bus is
- // alive.
- //
- for (RootBridgeNumber = 1;
- RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
- ++RootBridgeNumber) {
- UINTN Device;
-
- for (Device = 0; Device <= PCI_MAX_DEVICE; ++Device) {
- if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0,
- PCI_VENDOR_ID_OFFSET)) != MAX_UINT16) {
- break;
- }
- }
- if (Device <= 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, for any
- // subordinate buses that might exist behind PCI bridges hanging off it.
- //
- Status = PciHostBridgeUtilityInitRootBridge (
- Attributes,
- Attributes,
- AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
- (UINT8) LastRootBridgeNumber,
- (UINT8) (RootBridgeNumber - 1),
- &Io,
- &Mem,
- &MemAbove4G,
- &mNonExistAperture,
- &mNonExistAperture,
- &Bridges[Initialized]
- );
- if (EFI_ERROR (Status)) {
- goto FreeBridges;
- }
- ++Initialized;
- LastRootBridgeNumber = RootBridgeNumber;
- }
- }
-
- //
- // Install the last root bus (which might be the only, ie. main, root bus, if
- // we've found no extra root buses).
- //
- Status = PciHostBridgeUtilityInitRootBridge (
- Attributes,
+ return PciHostBridgeUtilityGetRootBridges (
+ Count,
Attributes,
AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
- (UINT8) LastRootBridgeNumber,
- PCI_MAX_BUS,
&Io,
&Mem,
&MemAbove4G,
&mNonExistAperture,
- &mNonExistAperture,
- &Bridges[Initialized]
+ &mNonExistAperture
);
- if (EFI_ERROR (Status)) {
- goto FreeBridges;
- }
- ++Initialized;
-
- *Count = Initialized;
- return Bridges;
-
-FreeBridges:
- while (Initialized > 0) {
- --Initialized;
- PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
- }
-
- FreePool (Bridges);
- return NULL;
}
@@ -223,17 +103,7 @@ PciHostBridgeFreeRootBridges (
UINTN Count
)
{
- if (Bridges == NULL && Count == 0) {
- return;
- }
- ASSERT (Bridges != NULL && Count > 0);
-
- do {
- --Count;
- PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
- } while (Count > 0);
-
- FreePool (Bridges);
+ PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
}
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index bed2d87ea89c..b1e74a469d50 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -11,11 +11,16 @@
**/
#include <IndustryStandard/Acpi10.h>
+#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/Q35MchIch9.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
+#include <Library/PciLib.h>
+#include <Library/QemuFwCfgLib.h>
#pragma pack(1)
@@ -184,6 +189,198 @@ PciHostBridgeUtilityUninitRootBridge (
}
+/**
+ Utility function to return all the root bridge instances in an array.
+
+ @param[out] Count The number of root bridge instances.
+
+ @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.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
+**/
+PCI_ROOT_BRIDGE *
+EFIAPI
+PciHostBridgeUtilityGetRootBridges (
+ OUT UINTN *Count,
+ IN UINT64 Attributes,
+ IN UINT64 AllocationAttributes,
+ 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
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ UINT64 ExtraRootBridges;
+ PCI_ROOT_BRIDGE *Bridges;
+ UINTN Initialized;
+ UINTN LastRootBridgeNumber;
+ UINTN RootBridgeNumber;
+
+ //
+ // QEMU provides the number of extra root buses, shortening the exhaustive
+ // search below. If there is no hint, the feature is missing.
+ //
+ Status = QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgSize);
+ if (EFI_ERROR (Status) || FwCfgSize != sizeof ExtraRootBridges) {
+ ExtraRootBridges = 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));
+ *Count = 0;
+ 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 = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
+ if (Bridges == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
+ *Count = 0;
+ return NULL;
+ }
+ Initialized = 0;
+
+ //
+ // The "main" root bus is always there.
+ //
+ LastRootBridgeNumber = 0;
+
+ //
+ // Scan all other root buses. If function 0 of any device on a bus returns a
+ // VendorId register value different from all-bits-one, then that bus is
+ // alive.
+ //
+ for (RootBridgeNumber = 1;
+ RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
+ ++RootBridgeNumber) {
+ UINTN Device;
+
+ for (Device = 0; Device <= PCI_MAX_DEVICE; ++Device) {
+ if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0,
+ PCI_VENDOR_ID_OFFSET)) != MAX_UINT16) {
+ break;
+ }
+ }
+ if (Device <= 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, for any
+ // subordinate buses that might exist behind PCI bridges hanging off it.
+ //
+ Status = PciHostBridgeUtilityInitRootBridge (
+ Attributes,
+ Attributes,
+ AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ (UINT8) LastRootBridgeNumber,
+ (UINT8) (RootBridgeNumber - 1),
+ Io,
+ Mem,
+ MemAbove4G,
+ PMem,
+ PMemAbove4G,
+ &Bridges[Initialized]
+ );
+ if (EFI_ERROR (Status)) {
+ goto FreeBridges;
+ }
+ ++Initialized;
+ LastRootBridgeNumber = RootBridgeNumber;
+ }
+ }
+
+ //
+ // Install the last root bus (which might be the only, ie. main, root bus, if
+ // we've found no extra root buses).
+ //
+ Status = PciHostBridgeUtilityInitRootBridge (
+ Attributes,
+ Attributes,
+ AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ (UINT8) LastRootBridgeNumber,
+ PCI_MAX_BUS,
+ Io,
+ Mem,
+ MemAbove4G,
+ PMem,
+ PMemAbove4G,
+ &Bridges[Initialized]
+ );
+ if (EFI_ERROR (Status)) {
+ goto FreeBridges;
+ }
+ ++Initialized;
+
+ *Count = Initialized;
+ return Bridges;
+
+FreeBridges:
+ while (Initialized > 0) {
+ --Initialized;
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
+ }
+
+ FreePool (Bridges);
+ *Count = 0;
+ return NULL;
+}
+
+
+/**
+ Utility function to free root bridge instances array from
+ PciHostBridgeUtilityGetRootBridges().
+
+ @param[in] Bridges The root bridge instances array.
+ @param[in] Count The count of the array.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityFreeRootBridges (
+ IN PCI_ROOT_BRIDGE *Bridges,
+ IN UINTN Count
+ )
+{
+ if (Bridges == NULL && Count == 0) {
+ return;
+ }
+ ASSERT (Bridges != NULL && Count > 0);
+
+ do {
+ --Count;
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
+ } while (Count > 0);
+
+ FreePool (Bridges);
+}
+
+
/**
Utility function to inform the platform that the resource conflict happens.
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 07/11] OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()
2021-01-19 1:12 ` [PATCH v6 07/11] OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges() Jiahui Cen
@ 2021-01-20 13:07 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 13:07 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
> Extract PciHostBridgeGetRootBridges() / PciHostBridgeFreeRootBridges() to
> PciHostBridgeUtilityLib as common utility functions to share support for
> scanning extra root bridges.
>
> No change of functionality.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> ---
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 -
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 6 +
> OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 50 +++++
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 138 +-------------
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 197 ++++++++++++++++++++
> 5 files changed, 257 insertions(+), 135 deletions(-)
>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> index 72458262cb42..4610a0c1490b 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> @@ -41,7 +41,6 @@ [LibraryClasses]
> PcdLib
> PciHostBridgeUtilityLib
> PciLib
> - QemuFwCfgLib
>
> [Pcd]
> gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> index 4d6764b702f4..fdae8cfe872e 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> @@ -39,3 +39,9 @@ [LibraryClasses]
> DebugLib
> DevicePathLib
> MemoryAllocationLib
> + PcdLib
> + PciLib
> + QemuFwCfgLib
> +
> +[Pcd]
> + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> index a44ad5034520..2b7d5d3725c3 100644
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> @@ -99,6 +99,56 @@ PciHostBridgeUtilityUninitRootBridge (
> );
>
>
> +/**
> + Utility function to return all the root bridge instances in an array.
> +
> + @param[out] Count The number of root bridge instances.
> +
> + @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.
> +
> + @param[in] PMem Prefetchable MMIO aperture.
> +
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> +
> + @return All the root bridge instances in an array.
> +**/
> +PCI_ROOT_BRIDGE *
> +EFIAPI
> +PciHostBridgeUtilityGetRootBridges (
> + OUT UINTN *Count,
> + IN UINT64 Attributes,
> + IN UINT64 AllocationAttributes,
> + 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
> + );
> +
> +
> +/**
> + Utility function to free root bridge instances array from
> + PciHostBridgeUtilityGetRootBridges().
> +
> + @param[in] Bridges The root bridge instances array.
> + @param[in] Count The count of the array.
> +**/
> +VOID
> +EFIAPI
> +PciHostBridgeUtilityFreeRootBridges (
> + IN PCI_ROOT_BRIDGE *Bridges,
> + IN UINTN Count
> + );
> +
> +
> /**
> Utility function to inform the platform that the resource conflict happens.
>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index 8758d7c12bf0..6ac41ff853a9 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -9,9 +9,6 @@
> **/
> #include <PiDxe.h>
>
> -#include <IndustryStandard/Pci.h>
> -#include <IndustryStandard/Q35MchIch9.h>
> -
> #include <Protocol/PciHostBridgeResourceAllocation.h>
> #include <Protocol/PciRootBridgeIo.h>
>
> @@ -21,8 +18,6 @@
> #include <Library/PcdLib.h>
> #include <Library/PciHostBridgeLib.h>
> #include <Library/PciHostBridgeUtilityLib.h>
> -#include <Library/PciLib.h>
> -#include <Library/QemuFwCfgLib.h>
> #include "PciHostBridge.h"
>
>
> @@ -44,14 +39,6 @@ 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;
> @@ -89,123 +76,16 @@ PciHostBridgeGetRootBridges (
> Mem.Base = PcdGet64 (PcdPciMmio32Base);
> Mem.Limit = PcdGet64 (PcdPciMmio32Base) + (PcdGet64 (PcdPciMmio32Size) - 1);
>
> - *Count = 0;
> -
> - //
> - // QEMU provides the number of extra root buses, shortening the exhaustive
> - // search below. If there is no hint, the feature is missing.
> - //
(1a) In v6, you are now removing the assignment to (*Count) here, as I
asked under v4, but:
> - Status = QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgSize);
> - if (EFI_ERROR (Status) || FwCfgSize != sizeof ExtraRootBridges) {
> - ExtraRootBridges = 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 = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
> - if (Bridges == NULL) {
> - DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
> - return NULL;
> - }
> - Initialized = 0;
> -
> - //
> - // The "main" root bus is always there.
> - //
> - LastRootBridgeNumber = 0;
> -
> - //
> - // Scan all other root buses. If function 0 of any device on a bus returns a
> - // VendorId register value different from all-bits-one, then that bus is
> - // alive.
> - //
> - for (RootBridgeNumber = 1;
> - RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
> - ++RootBridgeNumber) {
> - UINTN Device;
> -
> - for (Device = 0; Device <= PCI_MAX_DEVICE; ++Device) {
> - if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0,
> - PCI_VENDOR_ID_OFFSET)) != MAX_UINT16) {
> - break;
> - }
> - }
> - if (Device <= 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, for any
> - // subordinate buses that might exist behind PCI bridges hanging off it.
> - //
> - Status = PciHostBridgeUtilityInitRootBridge (
> - Attributes,
> - Attributes,
> - AllocationAttributes,
> - FALSE,
> - PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> - (UINT8) LastRootBridgeNumber,
> - (UINT8) (RootBridgeNumber - 1),
> - &Io,
> - &Mem,
> - &MemAbove4G,
> - &mNonExistAperture,
> - &mNonExistAperture,
> - &Bridges[Initialized]
> - );
> - if (EFI_ERROR (Status)) {
> - goto FreeBridges;
> - }
> - ++Initialized;
> - LastRootBridgeNumber = RootBridgeNumber;
> - }
> - }
> -
> - //
> - // Install the last root bus (which might be the only, ie. main, root bus, if
> - // we've found no extra root buses).
> - //
> - Status = PciHostBridgeUtilityInitRootBridge (
> - Attributes,
> + return PciHostBridgeUtilityGetRootBridges (
> + Count,
> Attributes,
> AllocationAttributes,
> - FALSE,
> - PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> - (UINT8) LastRootBridgeNumber,
> - PCI_MAX_BUS,
> &Io,
> &Mem,
> &MemAbove4G,
> &mNonExistAperture,
> - &mNonExistAperture,
> - &Bridges[Initialized]
> + &mNonExistAperture
> );
> - if (EFI_ERROR (Status)) {
> - goto FreeBridges;
> - }
> - ++Initialized;
> -
> - *Count = Initialized;
> - return Bridges;
> -
> -FreeBridges:
> - while (Initialized > 0) {
> - --Initialized;
> - PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
> - }
> -
> - FreePool (Bridges);
> - return NULL;
> }
>
>
> @@ -223,17 +103,7 @@ PciHostBridgeFreeRootBridges (
> UINTN Count
> )
> {
> - if (Bridges == NULL && Count == 0) {
> - return;
> - }
> - ASSERT (Bridges != NULL && Count > 0);
> -
> - do {
> - --Count;
> - PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
> - } while (Count > 0);
> -
> - FreePool (Bridges);
> + PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
> }
>
>
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> index bed2d87ea89c..b1e74a469d50 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> @@ -11,11 +11,16 @@
> **/
>
> #include <IndustryStandard/Acpi10.h>
> +#include <IndustryStandard/Pci.h>
> +#include <IndustryStandard/Q35MchIch9.h>
> #include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> #include <Library/DevicePathLib.h>
> #include <Library/MemoryAllocationLib.h>
> +#include <Library/PcdLib.h>
> #include <Library/PciHostBridgeUtilityLib.h>
> +#include <Library/PciLib.h>
> +#include <Library/QemuFwCfgLib.h>
>
>
> #pragma pack(1)
> @@ -184,6 +189,198 @@ PciHostBridgeUtilityUninitRootBridge (
> }
>
>
> +/**
> + Utility function to return all the root bridge instances in an array.
> +
> + @param[out] Count The number of root bridge instances.
> +
> + @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.
> +
> + @param[in] PMem Prefetchable MMIO aperture.
> +
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> +
> + @return All the root bridge instances in an array.
> +**/
> +PCI_ROOT_BRIDGE *
> +EFIAPI
> +PciHostBridgeUtilityGetRootBridges (
> + OUT UINTN *Count,
> + IN UINT64 Attributes,
> + IN UINT64 AllocationAttributes,
> + 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
> + )
> +{
> + EFI_STATUS Status;
> + FIRMWARE_CONFIG_ITEM FwCfgItem;
> + UINTN FwCfgSize;
> + UINT64 ExtraRootBridges;
> + PCI_ROOT_BRIDGE *Bridges;
> + UINTN Initialized;
> + UINTN LastRootBridgeNumber;
> + UINTN RootBridgeNumber;
> +
> + //
> + // QEMU provides the number of extra root buses, shortening the exhaustive
> + // search below. If there is no hint, the feature is missing.
> + //
(1b) you aren't introducing the assignment to the new function in the
same spot (above the comment). Instead, the assignment is now
triplicated to the "return NULL" statements:
> + Status = QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgSize);
> + if (EFI_ERROR (Status) || FwCfgSize != sizeof ExtraRootBridges) {
> + ExtraRootBridges = 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));
> + *Count = 0;
(1c) here
> + 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 = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
> + if (Bridges == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
> + *Count = 0;
(1d) here
> + return NULL;
> + }
> + Initialized = 0;
> +
> + //
> + // The "main" root bus is always there.
> + //
> + LastRootBridgeNumber = 0;
> +
> + //
> + // Scan all other root buses. If function 0 of any device on a bus returns a
> + // VendorId register value different from all-bits-one, then that bus is
> + // alive.
> + //
> + for (RootBridgeNumber = 1;
> + RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
> + ++RootBridgeNumber) {
> + UINTN Device;
> +
> + for (Device = 0; Device <= PCI_MAX_DEVICE; ++Device) {
> + if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0,
> + PCI_VENDOR_ID_OFFSET)) != MAX_UINT16) {
> + break;
> + }
> + }
> + if (Device <= 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, for any
> + // subordinate buses that might exist behind PCI bridges hanging off it.
> + //
> + Status = PciHostBridgeUtilityInitRootBridge (
> + Attributes,
> + Attributes,
> + AllocationAttributes,
> + FALSE,
> + PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> + (UINT8) LastRootBridgeNumber,
> + (UINT8) (RootBridgeNumber - 1),
> + Io,
> + Mem,
> + MemAbove4G,
> + PMem,
> + PMemAbove4G,
> + &Bridges[Initialized]
> + );
> + if (EFI_ERROR (Status)) {
> + goto FreeBridges;
> + }
> + ++Initialized;
> + LastRootBridgeNumber = RootBridgeNumber;
> + }
> + }
> +
> + //
> + // Install the last root bus (which might be the only, ie. main, root bus, if
> + // we've found no extra root buses).
> + //
> + Status = PciHostBridgeUtilityInitRootBridge (
> + Attributes,
> + Attributes,
> + AllocationAttributes,
> + FALSE,
> + PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> + (UINT8) LastRootBridgeNumber,
> + PCI_MAX_BUS,
> + Io,
> + Mem,
> + MemAbove4G,
> + PMem,
> + PMemAbove4G,
> + &Bridges[Initialized]
> + );
> + if (EFI_ERROR (Status)) {
> + goto FreeBridges;
> + }
> + ++Initialized;
> +
> + *Count = Initialized;
> + return Bridges;
> +
> +FreeBridges:
> + while (Initialized > 0) {
> + --Initialized;
> + PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
> + }
> +
> + FreePool (Bridges);
> + *Count = 0;
(1e) and here.
While functionally that's OK, it needlessly complicates the comparison
between the old and the new function bodies. Considering that the
subject of this patch is code extraction, I don't think such a change is
warranted for.
I can't see myself reviewing a v7 of this series (unless I find
something critical in the rest of v6), so I'll try to centralize the
zero-assignment to (*Count) for you, at the top of the function, before
I merge v6.
The other updates look OK.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Laszlo
> + return NULL;
> +}
> +
> +
> +/**
> + Utility function to free root bridge instances array from
> + PciHostBridgeUtilityGetRootBridges().
> +
> + @param[in] Bridges The root bridge instances array.
> + @param[in] Count The count of the array.
> +**/
> +VOID
> +EFIAPI
> +PciHostBridgeUtilityFreeRootBridges (
> + IN PCI_ROOT_BRIDGE *Bridges,
> + IN UINTN Count
> + )
> +{
> + if (Bridges == NULL && Count == 0) {
> + return;
> + }
> + ASSERT (Bridges != NULL && Count > 0);
> +
> + do {
> + --Count;
> + PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
> + } while (Count > 0);
> +
> + FreePool (Bridges);
> +}
> +
> +
> /**
> Utility function to inform the platform that the resource conflict happens.
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 08/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (6 preceding siblings ...)
2021-01-19 1:12 ` [PATCH v6 07/11] OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges() Jiahui Cen
@ 2021-01-19 1:12 ` Jiahui Cen
2021-01-20 13:34 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:13 ` [PATCH v6 09/11] OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax Jiahui Cen
` (3 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:12 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
Extend parameter list of PciHostBridgeUtilityGetRootBridges() with
DmaAbove4G, NoExtendedConfigSpace to support for ArmVirtPkg.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 4 ---
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 24 ++++++++------
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 5 +++
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 34 +++++++++++---------
4 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index fdae8cfe872e..83a734c1725e 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -39,9 +39,5 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
- PcdLib
PciLib
QemuFwCfgLib
-
-[Pcd]
- gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index 2b7d5d3725c3..a0ea44d96a67 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -102,23 +102,27 @@ PciHostBridgeUtilityUninitRootBridge (
/**
Utility function to return all the root bridge instances in an array.
- @param[out] Count The number of root bridge instances.
+ @param[out] Count The number of root bridge instances.
- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.
- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.
- @param[in] Io IO aperture.
+ @param[in] DmaAbove4G DMA above 4GB memory.
- @param[in] Mem MMIO aperture.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.
- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.
- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.
- @return All the root bridge instances in an array.
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
**/
PCI_ROOT_BRIDGE *
EFIAPI
@@ -126,6 +130,8 @@ PciHostBridgeUtilityGetRootBridges (
OUT UINTN *Count,
IN UINT64 Attributes,
IN UINT64 AllocationAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 6ac41ff853a9..91b9e6baa1e8 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -9,6 +9,9 @@
**/
#include <PiDxe.h>
+#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/Q35MchIch9.h>
+
#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>
@@ -80,6 +83,8 @@ PciHostBridgeGetRootBridges (
Count,
Attributes,
AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
&Io,
&Mem,
&MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index b1e74a469d50..1d78984b83ad 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -12,12 +12,10 @@
#include <IndustryStandard/Acpi10.h>
#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/Q35MchIch9.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
-#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
#include <Library/QemuFwCfgLib.h>
@@ -192,23 +190,27 @@ PciHostBridgeUtilityUninitRootBridge (
/**
Utility function to return all the root bridge instances in an array.
- @param[out] Count The number of root bridge instances.
+ @param[out] Count The number of root bridge instances.
- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.
- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.
- @param[in] Io IO aperture.
+ @param[in] DmaAbove4G DMA above 4GB memory.
- @param[in] Mem MMIO aperture.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.
- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.
- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.
- @return All the root bridge instances in an array.
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
**/
PCI_ROOT_BRIDGE *
EFIAPI
@@ -216,6 +218,8 @@ PciHostBridgeUtilityGetRootBridges (
OUT UINTN *Count,
IN UINT64 Attributes,
IN UINT64 AllocationAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
@@ -295,8 +299,8 @@ PciHostBridgeUtilityGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ DmaAbove4G,
+ NoExtendedConfigSpace,
(UINT8) LastRootBridgeNumber,
(UINT8) (RootBridgeNumber - 1),
Io,
@@ -322,8 +326,8 @@ PciHostBridgeUtilityGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ DmaAbove4G,
+ NoExtendedConfigSpace,
(UINT8) LastRootBridgeNumber,
PCI_MAX_BUS,
Io,
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 08/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges
2021-01-19 1:12 ` [PATCH v6 08/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges Jiahui Cen
@ 2021-01-20 13:34 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 13:34 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
> Extend parameter list of PciHostBridgeUtilityGetRootBridges() with
> DmaAbove4G, NoExtendedConfigSpace to support for ArmVirtPkg.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> ---
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 4 ---
> OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 24 ++++++++------
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 5 +++
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 34 +++++++++++---------
> 4 files changed, 39 insertions(+), 28 deletions(-)
>
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> index fdae8cfe872e..83a734c1725e 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> @@ -39,9 +39,5 @@ [LibraryClasses]
> DebugLib
> DevicePathLib
> MemoryAllocationLib
> - PcdLib
> PciLib
> QemuFwCfgLib
> -
> -[Pcd]
> - gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> index 2b7d5d3725c3..a0ea44d96a67 100644
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> @@ -102,23 +102,27 @@ PciHostBridgeUtilityUninitRootBridge (
> /**
> Utility function to return all the root bridge instances in an array.
>
> - @param[out] Count The number of root bridge instances.
> + @param[out] Count The number of root bridge instances.
>
> - @param[in] Attributes Initial attributes.
> + @param[in] Attributes Initial attributes.
>
> - @param[in] AllocAttributes Allocation attributes.
> + @param[in] AllocAttributes Allocation attributes.
>
> - @param[in] Io IO aperture.
> + @param[in] DmaAbove4G DMA above 4GB memory.
>
> - @param[in] Mem MMIO aperture.
> + @param[in] NoExtendedConfigSpace No Extended Config Space.
>
> - @param[in] MemAbove4G MMIO aperture above 4G.
> + @param[in] Io IO aperture.
>
> - @param[in] PMem Prefetchable MMIO aperture.
> + @param[in] Mem MMIO aperture.
>
> - @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> + @param[in] MemAbove4G MMIO aperture above 4G.
>
> - @return All the root bridge instances in an array.
> + @param[in] PMem Prefetchable MMIO aperture.
> +
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> +
> + @return All the root bridge instances in an array.
> **/
> PCI_ROOT_BRIDGE *
> EFIAPI
> @@ -126,6 +130,8 @@ PciHostBridgeUtilityGetRootBridges (
> OUT UINTN *Count,
> IN UINT64 Attributes,
> IN UINT64 AllocationAttributes,
> + IN BOOLEAN DmaAbove4G,
> + IN BOOLEAN NoExtendedConfigSpace,
> IN PCI_ROOT_BRIDGE_APERTURE *Io,
> IN PCI_ROOT_BRIDGE_APERTURE *Mem,
> IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index 6ac41ff853a9..91b9e6baa1e8 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -9,6 +9,9 @@
> **/
> #include <PiDxe.h>
>
> +#include <IndustryStandard/Pci.h>
(1) This #include directive does not belong in this patch. It is needed
in the next patch in the series (i.e., #9), where a reference to
PCI_MAX_BUS is added to this source file.
IOW, you didn't split patch v4 7/9 entirely correctly.
I guess I'm too tired to obsess about this though.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Laszlo
> +#include <IndustryStandard/Q35MchIch9.h>
> +
> #include <Protocol/PciHostBridgeResourceAllocation.h>
> #include <Protocol/PciRootBridgeIo.h>
>
> @@ -80,6 +83,8 @@ PciHostBridgeGetRootBridges (
> Count,
> Attributes,
> AllocationAttributes,
> + FALSE,
> + PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> &Io,
> &Mem,
> &MemAbove4G,
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> index b1e74a469d50..1d78984b83ad 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> @@ -12,12 +12,10 @@
>
> #include <IndustryStandard/Acpi10.h>
> #include <IndustryStandard/Pci.h>
> -#include <IndustryStandard/Q35MchIch9.h>
> #include <Library/BaseMemoryLib.h>
> #include <Library/DebugLib.h>
> #include <Library/DevicePathLib.h>
> #include <Library/MemoryAllocationLib.h>
> -#include <Library/PcdLib.h>
> #include <Library/PciHostBridgeUtilityLib.h>
> #include <Library/PciLib.h>
> #include <Library/QemuFwCfgLib.h>
> @@ -192,23 +190,27 @@ PciHostBridgeUtilityUninitRootBridge (
> /**
> Utility function to return all the root bridge instances in an array.
>
> - @param[out] Count The number of root bridge instances.
> + @param[out] Count The number of root bridge instances.
>
> - @param[in] Attributes Initial attributes.
> + @param[in] Attributes Initial attributes.
>
> - @param[in] AllocAttributes Allocation attributes.
> + @param[in] AllocAttributes Allocation attributes.
>
> - @param[in] Io IO aperture.
> + @param[in] DmaAbove4G DMA above 4GB memory.
>
> - @param[in] Mem MMIO aperture.
> + @param[in] NoExtendedConfigSpace No Extended Config Space.
>
> - @param[in] MemAbove4G MMIO aperture above 4G.
> + @param[in] Io IO aperture.
>
> - @param[in] PMem Prefetchable MMIO aperture.
> + @param[in] Mem MMIO aperture.
>
> - @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> + @param[in] MemAbove4G MMIO aperture above 4G.
>
> - @return All the root bridge instances in an array.
> + @param[in] PMem Prefetchable MMIO aperture.
> +
> + @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
> +
> + @return All the root bridge instances in an array.
> **/
> PCI_ROOT_BRIDGE *
> EFIAPI
> @@ -216,6 +218,8 @@ PciHostBridgeUtilityGetRootBridges (
> OUT UINTN *Count,
> IN UINT64 Attributes,
> IN UINT64 AllocationAttributes,
> + IN BOOLEAN DmaAbove4G,
> + IN BOOLEAN NoExtendedConfigSpace,
> IN PCI_ROOT_BRIDGE_APERTURE *Io,
> IN PCI_ROOT_BRIDGE_APERTURE *Mem,
> IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
> @@ -295,8 +299,8 @@ PciHostBridgeUtilityGetRootBridges (
> Attributes,
> Attributes,
> AllocationAttributes,
> - FALSE,
> - PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> + DmaAbove4G,
> + NoExtendedConfigSpace,
> (UINT8) LastRootBridgeNumber,
> (UINT8) (RootBridgeNumber - 1),
> Io,
> @@ -322,8 +326,8 @@ PciHostBridgeUtilityGetRootBridges (
> Attributes,
> Attributes,
> AllocationAttributes,
> - FALSE,
> - PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> + DmaAbove4G,
> + NoExtendedConfigSpace,
> (UINT8) LastRootBridgeNumber,
> PCI_MAX_BUS,
> Io,
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 09/11] OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (7 preceding siblings ...)
2021-01-19 1:12 ` [PATCH v6 08/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges Jiahui Cen
@ 2021-01-19 1:13 ` Jiahui Cen
2021-01-20 14:01 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:13 ` [PATCH v6 10/11] ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support Jiahui Cen
` (2 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:13 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen
Extend parameter list of PciHostBridgeUtilityGetRootBridges() with BusMin/
BusMax, so that the utility function could be compatible with ArmVirtPkg
who uses mutable bus range [BusMin, BusMax] insteand of [0, PCI_MAX_BUS].
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
---
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 6 ++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 2 ++
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 30 ++++++++++++++++----
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index a0ea44d96a67..d2dc18a1afad 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -112,6 +112,10 @@ PciHostBridgeUtilityUninitRootBridge (
@param[in] NoExtendedConfigSpace No Extended Config Space.
+ @param[in] BusMin Minimum Bus number, inclusive.
+
+ @param[in] BusMax Maximum Bus number, inclusive.
+
@param[in] Io IO aperture.
@param[in] Mem MMIO aperture.
@@ -132,6 +136,8 @@ PciHostBridgeUtilityGetRootBridges (
IN UINT64 AllocationAttributes,
IN BOOLEAN DmaAbove4G,
IN BOOLEAN NoExtendedConfigSpace,
+ IN UINTN BusMin,
+ IN UINTN BusMax,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 91b9e6baa1e8..7d9fb0fb293a 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -85,6 +85,8 @@ PciHostBridgeGetRootBridges (
AllocationAttributes,
FALSE,
PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ 0,
+ PCI_MAX_BUS,
&Io,
&Mem,
&MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index 1d78984b83ad..69bed5c7843f 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -200,6 +200,10 @@ PciHostBridgeUtilityUninitRootBridge (
@param[in] NoExtendedConfigSpace No Extended Config Space.
+ @param[in] BusMin Minimum Bus number, inclusive.
+
+ @param[in] BusMax Maximum Bus number, inclusive.
+
@param[in] Io IO aperture.
@param[in] Mem MMIO aperture.
@@ -220,6 +224,8 @@ PciHostBridgeUtilityGetRootBridges (
IN UINT64 AllocationAttributes,
IN BOOLEAN DmaAbove4G,
IN BOOLEAN NoExtendedConfigSpace,
+ IN UINTN BusMin,
+ IN UINTN BusMax,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
@@ -236,6 +242,13 @@ PciHostBridgeUtilityGetRootBridges (
UINTN LastRootBridgeNumber;
UINTN RootBridgeNumber;
+ if (BusMin > BusMax || BusMax > PCI_MAX_BUS) {
+ DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %d and BusMax %d\n",
+ __FUNCTION__, BusMin, BusMax));
+ *Count = 0;
+ return NULL;
+ }
+
//
// QEMU provides the number of extra root buses, shortening the exhaustive
// search below. If there is no hint, the feature is missing.
@@ -247,7 +260,14 @@ PciHostBridgeUtilityGetRootBridges (
QemuFwCfgSelectItem (FwCfgItem);
QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges);
- if (ExtraRootBridges > PCI_MAX_BUS) {
+ //
+ // Validate the number of extra root bridges. As BusMax is inclusive, the
+ // max bus count is (BusMax - BusMin + 1). From that, the "main" root bus
+ // is always givin, so the max count for the "extra" root bridges is one
+ // less, i.e. (BusMax - BusMin). If QEME hint exceeds that, we have invalid
+ // behavior.
+ //
+ if (ExtraRootBridges > BusMax - BusMin) {
DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
"reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
*Count = 0;
@@ -271,15 +291,15 @@ PciHostBridgeUtilityGetRootBridges (
//
// The "main" root bus is always there.
//
- LastRootBridgeNumber = 0;
+ LastRootBridgeNumber = BusMin;
//
// Scan all other root buses. If function 0 of any device on a bus returns a
// VendorId register value different from all-bits-one, then that bus is
// alive.
//
- for (RootBridgeNumber = 1;
- RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
+ for (RootBridgeNumber = BusMin + 1;
+ RootBridgeNumber <= BusMax && Initialized < ExtraRootBridges;
++RootBridgeNumber) {
UINTN Device;
@@ -329,7 +349,7 @@ PciHostBridgeUtilityGetRootBridges (
DmaAbove4G,
NoExtendedConfigSpace,
(UINT8) LastRootBridgeNumber,
- PCI_MAX_BUS,
+ (UINT8) BusMax,
Io,
Mem,
MemAbove4G,
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 09/11] OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax
2021-01-19 1:13 ` [PATCH v6 09/11] OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax Jiahui Cen
@ 2021-01-20 14:01 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 14:01 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin
On 01/19/21 02:13, Jiahui Cen via groups.io wrote:
> Extend parameter list of PciHostBridgeUtilityGetRootBridges() with BusMin/
> BusMax, so that the utility function could be compatible with ArmVirtPkg
> who uses mutable bus range [BusMin, BusMax] insteand of [0, PCI_MAX_BUS].
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> ---
> OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 6 ++++
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 2 ++
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 30 ++++++++++++++++----
> 3 files changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> index a0ea44d96a67..d2dc18a1afad 100644
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> +++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> @@ -112,6 +112,10 @@ PciHostBridgeUtilityUninitRootBridge (
>
> @param[in] NoExtendedConfigSpace No Extended Config Space.
>
> + @param[in] BusMin Minimum Bus number, inclusive.
> +
> + @param[in] BusMax Maximum Bus number, inclusive.
> +
> @param[in] Io IO aperture.
>
> @param[in] Mem MMIO aperture.
> @@ -132,6 +136,8 @@ PciHostBridgeUtilityGetRootBridges (
> IN UINT64 AllocationAttributes,
> IN BOOLEAN DmaAbove4G,
> IN BOOLEAN NoExtendedConfigSpace,
> + IN UINTN BusMin,
> + IN UINTN BusMax,
> IN PCI_ROOT_BRIDGE_APERTURE *Io,
> IN PCI_ROOT_BRIDGE_APERTURE *Mem,
> IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> index 91b9e6baa1e8..7d9fb0fb293a 100644
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
> @@ -85,6 +85,8 @@ PciHostBridgeGetRootBridges (
> AllocationAttributes,
> FALSE,
> PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
> + 0,
> + PCI_MAX_BUS,
> &Io,
> &Mem,
> &MemAbove4G,
> diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> index 1d78984b83ad..69bed5c7843f 100644
> --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
> @@ -200,6 +200,10 @@ PciHostBridgeUtilityUninitRootBridge (
>
> @param[in] NoExtendedConfigSpace No Extended Config Space.
>
> + @param[in] BusMin Minimum Bus number, inclusive.
> +
> + @param[in] BusMax Maximum Bus number, inclusive.
> +
> @param[in] Io IO aperture.
>
> @param[in] Mem MMIO aperture.
> @@ -220,6 +224,8 @@ PciHostBridgeUtilityGetRootBridges (
> IN UINT64 AllocationAttributes,
> IN BOOLEAN DmaAbove4G,
> IN BOOLEAN NoExtendedConfigSpace,
> + IN UINTN BusMin,
> + IN UINTN BusMax,
> IN PCI_ROOT_BRIDGE_APERTURE *Io,
> IN PCI_ROOT_BRIDGE_APERTURE *Mem,
> IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
> @@ -236,6 +242,13 @@ PciHostBridgeUtilityGetRootBridges (
> UINTN LastRootBridgeNumber;
> UINTN RootBridgeNumber;
>
> + if (BusMin > BusMax || BusMax > PCI_MAX_BUS) {
> + DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %d and BusMax %d\n",
> + __FUNCTION__, BusMin, BusMax));
(1) The "%d" format specifier is appropriate for INT32 values. But UINTN
is either UINT32 or UINT64 (dependent on the edk2 architecture the
platform is built for).
The safe way to print a UINTN value is to (a) cast it to UINT64, and (b)
use the "%Lu" (or "%Lx") format specifier.
I'll fix this up for you.
> + *Count = 0;
(2) As I said under patch v6 07/11, this zeroing should be centralized
at the top of the function. I'll fix it up for you.
> + return NULL;
> + }
> +
> //
> // QEMU provides the number of extra root buses, shortening the exhaustive
> // search below. If there is no hint, the feature is missing.
> @@ -247,7 +260,14 @@ PciHostBridgeUtilityGetRootBridges (
> QemuFwCfgSelectItem (FwCfgItem);
> QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges);
>
> - if (ExtraRootBridges > PCI_MAX_BUS) {
> + //
> + // Validate the number of extra root bridges. As BusMax is inclusive, the
> + // max bus count is (BusMax - BusMin + 1). From that, the "main" root bus
> + // is always givin, so the max count for the "extra" root bridges is one
(3) s/givin/a given/
I'll fix it.
> + // less, i.e. (BusMax - BusMin). If QEME hint exceeds that, we have invalid
(4) s/QEME/the QEMU/
I'll fix it.
> + // behavior.
> + //
> + if (ExtraRootBridges > BusMax - BusMin) {
> DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
> "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
> *Count = 0;
> @@ -271,15 +291,15 @@ PciHostBridgeUtilityGetRootBridges (
> //
> // The "main" root bus is always there.
> //
> - LastRootBridgeNumber = 0;
> + LastRootBridgeNumber = BusMin;
Side remark (nothing to fix): I'm slightly curious what would happen if
the DTB on the arm/aarch64 "virt" machine reported a BusMin different
from 0. What does that mean for the MMCONFIG offsets? If BusMin is
nonzero, does that mean we have a unused slice at the start of MMCONFIG?
Or does it mean that we need to shift down the bus references so that
BusMin does map to offset 0 in MMCONFIG? (See also the
"PCI_ROOT_BRIDGE.Bus.Translation" field.)
Anyway, we can look at this later, if such a DTB ever occurs in
practice. (I doubt that it ever will.)
>
> //
> // Scan all other root buses. If function 0 of any device on a bus returns a
> // VendorId register value different from all-bits-one, then that bus is
> // alive.
> //
> - for (RootBridgeNumber = 1;
> - RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
> + for (RootBridgeNumber = BusMin + 1;
> + RootBridgeNumber <= BusMax && Initialized < ExtraRootBridges;
> ++RootBridgeNumber) {
> UINTN Device;
>
> @@ -329,7 +349,7 @@ PciHostBridgeUtilityGetRootBridges (
> DmaAbove4G,
> NoExtendedConfigSpace,
> (UINT8) LastRootBridgeNumber,
> - PCI_MAX_BUS,
> + (UINT8) BusMax,
> Io,
> Mem,
> MemAbove4G,
>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 10/11] ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (8 preceding siblings ...)
2021-01-19 1:13 ` [PATCH v6 09/11] OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax Jiahui Cen
@ 2021-01-19 1:13 ` Jiahui Cen
2021-01-20 14:06 ` [edk2-devel] " Laszlo Ersek
2021-01-19 1:13 ` [PATCH v6 11/11] ArmVirtPkg/ArmVirtQemu: Add support for HotPlug Jiahui Cen
2021-01-20 16:26 ` [edk2-devel] [PATCH v6 00/11] Add extra pci roots support for Arm Laszlo Ersek
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:13 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
In order to take advantages of extra pci root buses in ArmVirtPkg, it is
necessary to scan extra root buses when getting root briges. And now
PciHostBridgeUtilityLib already provides a set of utility functions that
support for extra pci root buses, like PciHostBridgeUtilityGetRootBridges()
/ PciHostBridgeUtilityFreeRootBridges(). So let's rebase
ArmVirtPkg/FdtPciHostBridgeLib to PciHostBridgeUtilityGetRootBridges() /
PciHostBridgeUtilityFreeRootBridges() to extend ArmVirtPkg with extra
pci root buses support.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 22 ++++----------------
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
index 3ec7992b6331..0099b8e3c391 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
@@ -272,8 +272,6 @@ ProcessPciHost (
return Status;
}
-STATIC PCI_ROOT_BRIDGE mRootBridge;
-
/**
Return all the root bridge instances in an array.
@@ -361,8 +359,8 @@ PciHostBridgeGetRootBridges (
PMemAbove4G.Base = MAX_UINT64;
PMemAbove4G.Limit = 0;
- Status = PciHostBridgeUtilityInitRootBridge (
- Attributes,
+ return PciHostBridgeUtilityGetRootBridges (
+ Count,
Attributes,
AllocationAttributes,
TRUE,
@@ -373,19 +371,8 @@ PciHostBridgeGetRootBridges (
&Mem,
&MemAbove4G,
&PMem,
- &PMemAbove4G,
- &mRootBridge
+ &PMemAbove4G
);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: failed to initialize PCI host bridge: %r\n",
- __FUNCTION__, Status));
- *Count = 0;
- return NULL;
- }
-
- *Count = 1;
-
- return &mRootBridge;
}
/**
@@ -402,8 +389,7 @@ PciHostBridgeFreeRootBridges (
UINTN Count
)
{
- ASSERT (Count == 1);
- PciHostBridgeUtilityUninitRootBridge (Bridges);
+ PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
}
/**
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 10/11] ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support
2021-01-19 1:13 ` [PATCH v6 10/11] ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support Jiahui Cen
@ 2021-01-20 14:06 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 14:06 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:13, Jiahui Cen via groups.io wrote:
> In order to take advantages of extra pci root buses in ArmVirtPkg, it is
> necessary to scan extra root buses when getting root briges. And now
> PciHostBridgeUtilityLib already provides a set of utility functions that
> support for extra pci root buses, like PciHostBridgeUtilityGetRootBridges()
> / PciHostBridgeUtilityFreeRootBridges(). So let's rebase
> ArmVirtPkg/FdtPciHostBridgeLib to PciHostBridgeUtilityGetRootBridges() /
> PciHostBridgeUtilityFreeRootBridges() to extend ArmVirtPkg with extra
> pci root buses support.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Leif Lindholm <leif@nuviainc.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> ---
> ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 22 ++++----------------
> 1 file changed, 4 insertions(+), 18 deletions(-)
>
> diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> index 3ec7992b6331..0099b8e3c391 100644
> --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> @@ -272,8 +272,6 @@ ProcessPciHost (
> return Status;
> }
>
> -STATIC PCI_ROOT_BRIDGE mRootBridge;
> -
> /**
> Return all the root bridge instances in an array.
>
> @@ -361,8 +359,8 @@ PciHostBridgeGetRootBridges (
> PMemAbove4G.Base = MAX_UINT64;
> PMemAbove4G.Limit = 0;
>
> - Status = PciHostBridgeUtilityInitRootBridge (
> - Attributes,
> + return PciHostBridgeUtilityGetRootBridges (
> + Count,
> Attributes,
> AllocationAttributes,
> TRUE,
> @@ -373,19 +371,8 @@ PciHostBridgeGetRootBridges (
> &Mem,
> &MemAbove4G,
> &PMem,
> - &PMemAbove4G,
> - &mRootBridge
> + &PMemAbove4G
> );
> - if (EFI_ERROR (Status)) {
> - DEBUG ((DEBUG_ERROR, "%a: failed to initialize PCI host bridge: %r\n",
> - __FUNCTION__, Status));
> - *Count = 0;
> - return NULL;
> - }
> -
> - *Count = 1;
> -
> - return &mRootBridge;
> }
>
> /**
> @@ -402,8 +389,7 @@ PciHostBridgeFreeRootBridges (
> UINTN Count
> )
> {
> - ASSERT (Count == 1);
> - PciHostBridgeUtilityUninitRootBridge (Bridges);
> + PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
> }
>
> /**
>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v6 11/11] ArmVirtPkg/ArmVirtQemu: Add support for HotPlug
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (9 preceding siblings ...)
2021-01-19 1:13 ` [PATCH v6 10/11] ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support Jiahui Cen
@ 2021-01-19 1:13 ` Jiahui Cen
2021-01-20 14:09 ` [edk2-devel] " Laszlo Ersek
2021-01-20 16:26 ` [edk2-devel] [PATCH v6 00/11] Add extra pci roots support for Arm Laszlo Ersek
11 siblings, 1 reply; 25+ messages in thread
From: Jiahui Cen @ 2021-01-19 1:13 UTC (permalink / raw)
To: devel
Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel, Rebecca Cran,
Peter Grehan, Anthony Perard, Julien Grall, Leif Lindholm,
Sami Mujawar, xieyingtai, wu.wubin, Jiahui Cen, Yubo Miao
It is necessary to add padding for hotplugable PCI Devices like
pcie-root-port.
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
ArmVirtPkg/ArmVirtQemu.dsc | 1 +
ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 +
ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 +
3 files changed, 3 insertions(+)
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index a11ffd9ba553..d77c226d80ee 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -488,6 +488,7 @@ [Components.common]
<LibraryClasses>
NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
}
+ OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
OvmfPkg/Virtio10Dxe/Virtio10.inf
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index c27752b4d5e5..92f327eec4fb 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -424,6 +424,7 @@ [Components.common]
<LibraryClasses>
NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
}
+ OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
OvmfPkg/Virtio10Dxe/Virtio10.inf
diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
index 1752fee12b79..5b1d10057545 100644
--- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
+++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
@@ -162,6 +162,7 @@ [FV.FvMain]
INF ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf
INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
+ INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
INF OvmfPkg/Virtio10Dxe/Virtio10.inf
--
2.29.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 11/11] ArmVirtPkg/ArmVirtQemu: Add support for HotPlug
2021-01-19 1:13 ` [PATCH v6 11/11] ArmVirtPkg/ArmVirtQemu: Add support for HotPlug Jiahui Cen
@ 2021-01-20 14:09 ` Laszlo Ersek
0 siblings, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 14:09 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:13, Jiahui Cen via groups.io wrote:
> It is necessary to add padding for hotplugable PCI Devices like
> pcie-root-port.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Leif Lindholm <leif@nuviainc.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> ---
> ArmVirtPkg/ArmVirtQemu.dsc | 1 +
> ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 +
> ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 +
> 3 files changed, 3 insertions(+)
>
> diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
> index a11ffd9ba553..d77c226d80ee 100644
> --- a/ArmVirtPkg/ArmVirtQemu.dsc
> +++ b/ArmVirtPkg/ArmVirtQemu.dsc
> @@ -488,6 +488,7 @@ [Components.common]
> <LibraryClasses>
> NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
> }
> + OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
> OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
> OvmfPkg/Virtio10Dxe/Virtio10.inf
>
> diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
> index c27752b4d5e5..92f327eec4fb 100644
> --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
> +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
> @@ -424,6 +424,7 @@ [Components.common]
> <LibraryClasses>
> NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
> }
> + OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
> OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
> OvmfPkg/Virtio10Dxe/Virtio10.inf
>
> diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
> index 1752fee12b79..5b1d10057545 100644
> --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
> +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
> @@ -162,6 +162,7 @@ [FV.FvMain]
> INF ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf
> INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
> INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
> + INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
> INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
> INF OvmfPkg/Virtio10Dxe/Virtio10.inf
>
>
This patch is identical to v4 9/9, but you forgot to pick up my R-b from
there: <https://edk2.groups.io/g/devel/message/70281>.
So, once again:
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
I'm going to fix up the v6 patches now as described, and then merge the
series.
Thanks
Laszlo
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 00/11] Add extra pci roots support for Arm
2021-01-19 1:12 [PATCH v6 00/11] Add extra pci roots support for Arm Jiahui Cen
` (10 preceding siblings ...)
2021-01-19 1:13 ` [PATCH v6 11/11] ArmVirtPkg/ArmVirtQemu: Add support for HotPlug Jiahui Cen
@ 2021-01-20 16:26 ` Laszlo Ersek
2021-01-21 1:26 ` Jiahui Cen
11 siblings, 1 reply; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-20 16:26 UTC (permalink / raw)
To: devel, cenjiahui
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
> v5->v6:
> * Annotate library functions with EFIAPI, IN/OUT, @param[in]/[out].
> * Split BusMin/BusMax addtion in PciHostBridgeUtilityGetRootBridges() into
> a separate patch [09/11].
> * Add more detailed commit message for patch [10/11].
Merged via <https://github.com/tianocore/edk2/pull/1372> as commit range
ca272b9513a6..e843a21e23ea.
The following git-range-diff output shows my fixups on top of the posted
v6 series:
> 1: b757f3127929 = 1: 7a6172f88bb0 OvmfPkg: Introduce PciHostBridgeUtilityLib class
> 2: 87b14160b8ec = 2: 166a32d09ad9 ArmVirtPkg: Refactor with PciHostBridgeUtilityLib
> 3: c31534b6ac1e ! 3: 517055d29886 OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
> @@ -15,6 +15,7 @@
> Cc: Julien Grall <julien@xen.org>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Message-Id: <20210119011302.10908-4-cenjiahui@huawei.com>
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
> 4: b4a56730b94a ! 4: 7ac1f28d4dbd OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge()
> @@ -15,6 +15,7 @@
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Message-Id: <20210119011302.10908-5-cenjiahui@huawei.com>
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> 5: edb622820369 ! 5: e1b259da426b OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()
> @@ -16,6 +16,7 @@
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Message-Id: <20210119011302.10908-6-cenjiahui@huawei.com>
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> 6: a678abfd5f0c ! 6: aa445ce02b69 ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge
> @@ -14,6 +14,7 @@
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Message-Id: <20210119011302.10908-7-cenjiahui@huawei.com>
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
> --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
> 7: f072f24ca41f ! 7: 4edba29651e3 OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()
> @@ -16,6 +16,8 @@
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Message-Id: <20210119011302.10908-8-cenjiahui@huawei.com>
> + [lersek@redhat.com: keep zeroing of (*Count) centralized]
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> @@ -355,6 +357,8 @@
> + UINTN LastRootBridgeNumber;
> + UINTN RootBridgeNumber;
> +
> ++ *Count = 0;
> ++
> + //
> + // QEMU provides the number of extra root buses, shortening the exhaustive
> + // search below. If there is no hint, the feature is missing.
> @@ -369,7 +373,6 @@
> + if (ExtraRootBridges > PCI_MAX_BUS) {
> + DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
> + "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
> -+ *Count = 0;
> + return NULL;
> + }
> + DEBUG ((DEBUG_INFO, "%a: %Lu extra root buses reported by QEMU\n",
> @@ -382,7 +385,6 @@
> + Bridges = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
> + if (Bridges == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
> -+ *Count = 0;
> + return NULL;
> + }
> + Initialized = 0;
> @@ -471,7 +473,6 @@
> + }
> +
> + FreePool (Bridges);
> -+ *Count = 0;
> + return NULL;
> +}
> +
> 8: 5607d15dab2f ! 8: 14d4b6be568d OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges
> @@ -13,6 +13,7 @@
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Message-Id: <20210119011302.10908-9-cenjiahui@huawei.com>
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> 9: 7a1681682daa ! 9: f4a257a355b7 OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax
> @@ -13,6 +13,10 @@
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Message-Id: <20210119011302.10908-10-cenjiahui@huawei.com>
> + [lersek@redhat.com: fix logging of UINTN values BusMin, BusMax]
> + [lersek@redhat.com: keep zeroing of (*Count) centralized]
> + [lersek@redhat.com: fix typos in ExtraRootBridges comment]
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> @@ -75,13 +79,12 @@
> IN PCI_ROOT_BRIDGE_APERTURE *Mem,
> IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
> @@
> - UINTN LastRootBridgeNumber;
> - UINTN RootBridgeNumber;
> +
> + *Count = 0;
>
> + if (BusMin > BusMax || BusMax > PCI_MAX_BUS) {
> -+ DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %d and BusMax %d\n",
> -+ __FUNCTION__, BusMin, BusMax));
> -+ *Count = 0;
> ++ DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %Lu and BusMax "
> ++ "%Lu\n", __FUNCTION__, (UINT64)BusMin, (UINT64)BusMax));
> + return NULL;
> + }
> +
> @@ -96,14 +99,14 @@
> + //
> + // Validate the number of extra root bridges. As BusMax is inclusive, the
> + // max bus count is (BusMax - BusMin + 1). From that, the "main" root bus
> -+ // is always givin, so the max count for the "extra" root bridges is one
> -+ // less, i.e. (BusMax - BusMin). If QEME hint exceeds that, we have invalid
> -+ // behavior.
> ++ // is always a given, so the max count for the "extra" root bridges is one
> ++ // less, i.e. (BusMax - BusMin). If the QEMU hint exceeds that, we have
> ++ // invalid behavior.
> + //
> + if (ExtraRootBridges > BusMax - BusMin) {
> DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
> "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
> - *Count = 0;
> + return NULL;
> @@
> //
> // The "main" root bus is always there.
> 10: bb3538547b3e ! 10: c4cbd864933a ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support
> @@ -19,6 +19,7 @@
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Message-Id: <20210119011302.10908-11-cenjiahui@huawei.com>
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
> 11: fbf533fe9c10 ! 11: e843a21e23ea ArmVirtPkg/ArmVirtQemu: Add support for HotPlug
> @@ -13,6 +13,7 @@
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
> Message-Id: <20210119011302.10908-12-cenjiahui@huawei.com>
> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
> --- a/ArmVirtPkg/ArmVirtQemu.dsc
Thanks
Laszlo
>
> v4->v5:
> * Revert some risky renames.
> * Explicitly list PcdLib dependency.
> * Fix issues reported by PatchCheck.py.
>
> v3->v4:
> * Refactor InitRootBridges/UninitRootBridges/GetRootBridges/FreeRootBridges.
> * Fix library dependencies.
>
> v2->v3:
> * Rename utility functions under the PciHostBridgeUtilityLib namespace.
> * Remove some unused Library dependencies.
> * Sort the Include headers.
>
> v1->v2:
> * Separated into four patches.
> * Factor the same logic parts into a new library.
>
> v4: https://edk2.groups.io/g/devel/message/70147
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
> QEMU: https://lore.kernel.org/qemu-devel/20201119014841.7298-1-cenjiahui@huawei.com/
>
> This patch series adds support for extra pci roots for ARM.
>
> In order to avoid duplicated codes, we introduce a new library
> PciHostBridgeUtilityLib which extracts common interfaces from
> OvmfPkg/PciHostBridgeLib. It provides conflicts informing and extra pci
> roots scanning. Using the utility lib, the uefi could scan for extra
> root buses and recognize multiple roots for ARM.
>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Rebecca Cran <rebecca@bsdio.com>
> Cc: Peter Grehan <grehan@freebsd.org>
> Cc: Anthony Perard <anthony.perard@citrix.com>
> Cc: Julien Grall <julien@xen.org>
> Cc: Leif Lindholm <leif@nuviainc.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>
> Jiahui Cen (11):
> OvmfPkg: Introduce PciHostBridgeUtilityLib class
> ArmVirtPkg: Refactor with PciHostBridgeUtilityLib
> OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
> OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() /
> UninitRootBridge()
> OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()
> ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge
> OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()
> OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of
> GetRootBridges
> OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with
> BusMin/BusMax
> ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support
> ArmVirtPkg/ArmVirtQemu: Add support for HotPlug
>
> OvmfPkg/OvmfPkg.dec | 4 +
> ArmVirtPkg/ArmVirtKvmTool.dsc | 1 +
> ArmVirtPkg/ArmVirtQemu.dsc | 2 +
> ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +
> 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 +
> ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 3 +
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 4 +-
> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 43 +++
> OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 185 +++++++++++
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h | 56 ----
> ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 164 ++++------
> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 324 +-------------------
> OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 5 +-
> OvmfPkg/Library/{PciHostBridgeLib/PciHostBridgeLib.c => PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c} | 281 +++++++++--------
> ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 +
> 20 files changed, 467 insertions(+), 614 deletions(-)
> create mode 100644 OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
> create mode 100644 OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
> copy OvmfPkg/Library/{PciHostBridgeLib/PciHostBridgeLib.c => PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c} (50%)
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH v6 00/11] Add extra pci roots support for Arm
2021-01-20 16:26 ` [edk2-devel] [PATCH v6 00/11] Add extra pci roots support for Arm Laszlo Ersek
@ 2021-01-21 1:26 ` Jiahui Cen
0 siblings, 0 replies; 25+ messages in thread
From: Jiahui Cen @ 2021-01-21 1:26 UTC (permalink / raw)
To: devel, lersek
Cc: Jordan Justen, Ard Biesheuvel, Rebecca Cran, Peter Grehan,
Anthony Perard, Julien Grall, Leif Lindholm, Sami Mujawar,
xieyingtai, wu.wubin, Yubo Miao
Hi Laszlo,
On 2021/1/21 0:26, Laszlo Ersek wrote:
> On 01/19/21 02:12, Jiahui Cen via groups.io wrote:
>> v5->v6:
>> * Annotate library functions with EFIAPI, IN/OUT, @param[in]/[out].
>> * Split BusMin/BusMax addtion in PciHostBridgeUtilityGetRootBridges() into
>> a separate patch [09/11].
>> * Add more detailed commit message for patch [10/11].
>
> Merged via <https://github.com/tianocore/edk2/pull/1372> as commit range
> ca272b9513a6..e843a21e23ea.
>
Thanks for the review and these fixups.
Thanks,
Jiahui
> The following git-range-diff output shows my fixups on top of the posted
> v6 series:
>
>> 1: b757f3127929 = 1: 7a6172f88bb0 OvmfPkg: Introduce PciHostBridgeUtilityLib class
>> 2: 87b14160b8ec = 2: 166a32d09ad9 ArmVirtPkg: Refactor with PciHostBridgeUtilityLib
>> 3: c31534b6ac1e ! 3: 517055d29886 OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
>> @@ -15,6 +15,7 @@
>> Cc: Julien Grall <julien@xen.org>
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Message-Id: <20210119011302.10908-4-cenjiahui@huawei.com>
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
>> --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
>> 4: b4a56730b94a ! 4: 7ac1f28d4dbd OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge()
>> @@ -15,6 +15,7 @@
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>> Message-Id: <20210119011302.10908-5-cenjiahui@huawei.com>
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> 5: edb622820369 ! 5: e1b259da426b OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()
>> @@ -16,6 +16,7 @@
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>> Message-Id: <20210119011302.10908-6-cenjiahui@huawei.com>
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> 6: a678abfd5f0c ! 6: aa445ce02b69 ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge
>> @@ -14,6 +14,7 @@
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>> Message-Id: <20210119011302.10908-7-cenjiahui@huawei.com>
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
>> --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
>> 7: f072f24ca41f ! 7: 4edba29651e3 OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()
>> @@ -16,6 +16,8 @@
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>> Message-Id: <20210119011302.10908-8-cenjiahui@huawei.com>
>> + [lersek@redhat.com: keep zeroing of (*Count) centralized]
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> @@ -355,6 +357,8 @@
>> + UINTN LastRootBridgeNumber;
>> + UINTN RootBridgeNumber;
>> +
>> ++ *Count = 0;
>> ++
>> + //
>> + // QEMU provides the number of extra root buses, shortening the exhaustive
>> + // search below. If there is no hint, the feature is missing.
>> @@ -369,7 +373,6 @@
>> + if (ExtraRootBridges > PCI_MAX_BUS) {
>> + DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
>> + "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
>> -+ *Count = 0;
>> + return NULL;
>> + }
>> + DEBUG ((DEBUG_INFO, "%a: %Lu extra root buses reported by QEMU\n",
>> @@ -382,7 +385,6 @@
>> + Bridges = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
>> + if (Bridges == NULL) {
>> + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
>> -+ *Count = 0;
>> + return NULL;
>> + }
>> + Initialized = 0;
>> @@ -471,7 +473,6 @@
>> + }
>> +
>> + FreePool (Bridges);
>> -+ *Count = 0;
>> + return NULL;
>> +}
>> +
>> 8: 5607d15dab2f ! 8: 14d4b6be568d OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges
>> @@ -13,6 +13,7 @@
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>> Message-Id: <20210119011302.10908-9-cenjiahui@huawei.com>
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> 9: 7a1681682daa ! 9: f4a257a355b7 OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax
>> @@ -13,6 +13,10 @@
>> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Message-Id: <20210119011302.10908-10-cenjiahui@huawei.com>
>> + [lersek@redhat.com: fix logging of UINTN values BusMin, BusMax]
>> + [lersek@redhat.com: keep zeroing of (*Count) centralized]
>> + [lersek@redhat.com: fix typos in ExtraRootBridges comment]
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> --- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> @@ -75,13 +79,12 @@
>> IN PCI_ROOT_BRIDGE_APERTURE *Mem,
>> IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
>> @@
>> - UINTN LastRootBridgeNumber;
>> - UINTN RootBridgeNumber;
>> +
>> + *Count = 0;
>>
>> + if (BusMin > BusMax || BusMax > PCI_MAX_BUS) {
>> -+ DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %d and BusMax %d\n",
>> -+ __FUNCTION__, BusMin, BusMax));
>> -+ *Count = 0;
>> ++ DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %Lu and BusMax "
>> ++ "%Lu\n", __FUNCTION__, (UINT64)BusMin, (UINT64)BusMax));
>> + return NULL;
>> + }
>> +
>> @@ -96,14 +99,14 @@
>> + //
>> + // Validate the number of extra root bridges. As BusMax is inclusive, the
>> + // max bus count is (BusMax - BusMin + 1). From that, the "main" root bus
>> -+ // is always givin, so the max count for the "extra" root bridges is one
>> -+ // less, i.e. (BusMax - BusMin). If QEME hint exceeds that, we have invalid
>> -+ // behavior.
>> ++ // is always a given, so the max count for the "extra" root bridges is one
>> ++ // less, i.e. (BusMax - BusMin). If the QEMU hint exceeds that, we have
>> ++ // invalid behavior.
>> + //
>> + if (ExtraRootBridges > BusMax - BusMin) {
>> DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
>> "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
>> - *Count = 0;
>> + return NULL;
>> @@
>> //
>> // The "main" root bus is always there.
>> 10: bb3538547b3e ! 10: c4cbd864933a ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support
>> @@ -19,6 +19,7 @@
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>> Message-Id: <20210119011302.10908-11-cenjiahui@huawei.com>
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
>> --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
>> 11: fbf533fe9c10 ! 11: e843a21e23ea ArmVirtPkg/ArmVirtQemu: Add support for HotPlug
>> @@ -13,6 +13,7 @@
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>> Message-Id: <20210119011302.10908-12-cenjiahui@huawei.com>
>> + Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>>
>> diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
>> --- a/ArmVirtPkg/ArmVirtQemu.dsc
>
> Thanks
> Laszlo
>
>>
>> v4->v5:
>> * Revert some risky renames.
>> * Explicitly list PcdLib dependency.
>> * Fix issues reported by PatchCheck.py.
>>
>> v3->v4:
>> * Refactor InitRootBridges/UninitRootBridges/GetRootBridges/FreeRootBridges.
>> * Fix library dependencies.
>>
>> v2->v3:
>> * Rename utility functions under the PciHostBridgeUtilityLib namespace.
>> * Remove some unused Library dependencies.
>> * Sort the Include headers.
>>
>> v1->v2:
>> * Separated into four patches.
>> * Factor the same logic parts into a new library.
>>
>> v4: https://edk2.groups.io/g/devel/message/70147
>> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
>> QEMU: https://lore.kernel.org/qemu-devel/20201119014841.7298-1-cenjiahui@huawei.com/
>>
>> This patch series adds support for extra pci roots for ARM.
>>
>> In order to avoid duplicated codes, we introduce a new library
>> PciHostBridgeUtilityLib which extracts common interfaces from
>> OvmfPkg/PciHostBridgeLib. It provides conflicts informing and extra pci
>> roots scanning. Using the utility lib, the uefi could scan for extra
>> root buses and recognize multiple roots for ARM.
>>
>> Cc: Jordan Justen <jordan.l.justen@intel.com>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
>> Cc: Rebecca Cran <rebecca@bsdio.com>
>> Cc: Peter Grehan <grehan@freebsd.org>
>> Cc: Anthony Perard <anthony.perard@citrix.com>
>> Cc: Julien Grall <julien@xen.org>
>> Cc: Leif Lindholm <leif@nuviainc.com>
>> Cc: Sami Mujawar <sami.mujawar@arm.com>
>> Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
>> Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
>>
>> Jiahui Cen (11):
>> OvmfPkg: Introduce PciHostBridgeUtilityLib class
>> ArmVirtPkg: Refactor with PciHostBridgeUtilityLib
>> OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
>> OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() /
>> UninitRootBridge()
>> OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()
>> ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge
>> OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()
>> OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of
>> GetRootBridges
>> OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with
>> BusMin/BusMax
>> ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support
>> ArmVirtPkg/ArmVirtQemu: Add support for HotPlug
>>
>> OvmfPkg/OvmfPkg.dec | 4 +
>> ArmVirtPkg/ArmVirtKvmTool.dsc | 1 +
>> ArmVirtPkg/ArmVirtQemu.dsc | 2 +
>> ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +
>> 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 +
>> ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 3 +
>> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 4 +-
>> OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 43 +++
>> OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 185 +++++++++++
>> OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h | 56 ----
>> ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 164 ++++------
>> OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 324 +-------------------
>> OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 5 +-
>> OvmfPkg/Library/{PciHostBridgeLib/PciHostBridgeLib.c => PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c} | 281 +++++++++--------
>> ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 +
>> 20 files changed, 467 insertions(+), 614 deletions(-)
>> create mode 100644 OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
>> create mode 100644 OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
>> copy OvmfPkg/Library/{PciHostBridgeLib/PciHostBridgeLib.c => PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c} (50%)
>>
>
>
>
>
>
>
> .
>
^ permalink raw reply [flat|nested] 25+ messages in thread