]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: Introduce PciHostBridgeUtilityLib class
authorJiahui Cen via groups.io <cenjiahui=huawei.com@groups.io>
Tue, 19 Jan 2021 01:12:52 +0000 (09:12 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 20 Jan 2021 16:14:20 +0000 (16:14 +0000)
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>
Message-Id: <20210119011302.10908-2-cenjiahui@huawei.com>

12 files changed:
OvmfPkg/AmdSev/AmdSevX64.dsc
OvmfPkg/Bhyve/BhyveX64.dsc
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h [new file with mode: 0644]
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c [new file with mode: 0644]
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf [new file with mode: 0644]
OvmfPkg/OvmfPkg.dec
OvmfPkg/OvmfPkgIa32.dsc
OvmfPkg/OvmfPkgIa32X64.dsc
OvmfPkg/OvmfPkgX64.dsc
OvmfPkg/OvmfXen.dsc

index e6d545ab522f957baf02c7d5414bfe5e475277fa..65c42284d94149e2345098887f569787d7a9534a 100644 (file)
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
     <LibraryClasses>\r
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf\r
+      PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
       NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
index a1f43eaa4d9c4becb36d2e5f38c9ce268b93af0d..4a1cdf5acad0e6b09a50ed3b75e928eceb4e70a3 100644 (file)
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
     <LibraryClasses>\r
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf\r
+      PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
       NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
new file mode 100644 (file)
index 0000000..5ea25ed
--- /dev/null
@@ -0,0 +1,38 @@
+/** @file\r
+  Provide common utility functions to PciHostBridgeLib instances in\r
+  ArmVirtPkg and OvmfPkg.\r
+\r
+  Copyright (C) 2016, Red Hat, Inc.\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef __PCI_HOST_BRIDGE_UTILITY_LIB_H__\r
+#define __PCI_HOST_BRIDGE_UTILITY_LIB_H__\r
+\r
+\r
+/**\r
+  Utility function to inform the platform that the resource conflict happens.\r
+\r
+  @param[in] Configuration  Pointer to PCI I/O and PCI memory resource\r
+                            descriptors. The Configuration contains the\r
+                            resources for all the root bridges. The resource\r
+                            for each root bridge is terminated with END\r
+                            descriptor and an additional END is appended\r
+                            indicating the end of the entire resources. The\r
+                            resource descriptor field values follow the\r
+                            description in\r
+                            EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r
+                            .SubmitResources().\r
+**/\r
+VOID\r
+EFIAPI\r
+PciHostBridgeUtilityResourceConflict (\r
+  IN VOID  *Configuration\r
+  );\r
+\r
+\r
+#endif // __PCI_HOST_BRIDGE_UTILITY_LIB_H__\r
index e850f7d183eeefab8ffeef317f74556055a64318..4a176347fd49944c24e244fb80889fe6447e0576 100644 (file)
@@ -20,6 +20,7 @@
 #include <Library/DevicePathLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PciHostBridgeLib.h>\r
+#include <Library/PciHostBridgeUtilityLib.h>\r
 #include <Library/PciLib.h>\r
 #include <Library/QemuFwCfgLib.h>\r
 #include "PciHostBridge.h"\r
@@ -33,12 +34,6 @@ typedef struct {
 #pragma pack ()\r
 \r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED\r
-CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] = {\r
-  L"Mem", L"I/O", L"Bus"\r
-};\r
-\r
-\r
 STATIC\r
 CONST\r
 OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {\r
@@ -407,37 +402,5 @@ PciHostBridgeResourceConflict (
   VOID                              *Configuration\r
   )\r
 {\r
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;\r
-  UINTN                             RootBridgeIndex;\r
-  DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n"));\r
-\r
-  RootBridgeIndex = 0;\r
-  Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;\r
-  while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {\r
-    DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));\r
-    for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {\r
-      ASSERT (Descriptor->ResType <\r
-              ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr)\r
-              );\r
-      DEBUG ((DEBUG_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n",\r
-              mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType],\r
-              Descriptor->AddrLen, Descriptor->AddrRangeMax\r
-              ));\r
-      if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {\r
-        DEBUG ((DEBUG_ERROR, "     Granularity/SpecificFlag = %ld / %02x%s\n",\r
-                Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag,\r
-                ((Descriptor->SpecificFlag &\r
-                  EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE\r
-                  ) != 0) ? L" (Prefetchable)" : L""\r
-                ));\r
-      }\r
-    }\r
-    //\r
-    // Skip the END descriptor for root bridge\r
-    //\r
-    ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR);\r
-    Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(\r
-                   (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1\r
-                   );\r
-  }\r
+  PciHostBridgeUtilityResourceConflict (Configuration);\r
 }\r
index 6ec9ec751478c66e6b9984f87bf542e00bb2c87c..4c56f3c90b3b26db758fa3ac41611d07ffd8c2b3 100644 (file)
@@ -39,6 +39,7 @@
   DebugLib\r
   DevicePathLib\r
   MemoryAllocationLib\r
+  PciHostBridgeUtilityLib\r
   PciLib\r
   QemuFwCfgLib\r
 \r
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
new file mode 100644 (file)
index 0000000..ac94e62
--- /dev/null
@@ -0,0 +1,78 @@
+/** @file\r
+  Provide common utility functions to PciHostBridgeLib instances in\r
+  ArmVirtPkg and OvmfPkg.\r
+\r
+  Copyright (C) 2016, Red Hat, Inc.\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <IndustryStandard/Acpi10.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PciHostBridgeUtilityLib.h>\r
+\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+CHAR16 *mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[] = {\r
+  L"Mem", L"I/O", L"Bus"\r
+};\r
+\r
+\r
+/**\r
+  Utility function to inform the platform that the resource conflict happens.\r
+\r
+  @param[in] Configuration  Pointer to PCI I/O and PCI memory resource\r
+                            descriptors. The Configuration contains the\r
+                            resources for all the root bridges. The resource\r
+                            for each root bridge is terminated with END\r
+                            descriptor and an additional END is appended\r
+                            indicating the end of the entire resources. The\r
+                            resource descriptor field values follow the\r
+                            description in\r
+                            EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r
+                            .SubmitResources().\r
+**/\r
+VOID\r
+EFIAPI\r
+PciHostBridgeUtilityResourceConflict (\r
+  IN VOID  *Configuration\r
+  )\r
+{\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;\r
+  UINTN                             RootBridgeIndex;\r
+  DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n"));\r
+\r
+  RootBridgeIndex = 0;\r
+  Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;\r
+  while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {\r
+    DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));\r
+    for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {\r
+      ASSERT (Descriptor->ResType <\r
+              ARRAY_SIZE (mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr)\r
+              );\r
+      DEBUG ((DEBUG_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n",\r
+              mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[Descriptor->ResType],\r
+              Descriptor->AddrLen, Descriptor->AddrRangeMax\r
+              ));\r
+      if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {\r
+        DEBUG ((DEBUG_ERROR, "     Granularity/SpecificFlag = %ld / %02x%s\n",\r
+                Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag,\r
+                ((Descriptor->SpecificFlag &\r
+                  EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE\r
+                  ) != 0) ? L" (Prefetchable)" : L""\r
+                ));\r
+      }\r
+    }\r
+    //\r
+    // Skip the END descriptor for root bridge\r
+    //\r
+    ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR);\r
+    Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(\r
+                   (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1\r
+                   );\r
+  }\r
+}\r
+\r
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
new file mode 100644 (file)
index 0000000..1ba8ec3
--- /dev/null
@@ -0,0 +1,37 @@
+## @file\r
+#  Provide common utility functions to PciHostBridgeLib instances in\r
+#  ArmVirtPkg and OvmfPkg.\r
+#\r
+#  Copyright (C) 2016, Red Hat, Inc.\r
+#  Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 1.29\r
+  BASE_NAME                      = PciHostBridgeUtilityLib\r
+  FILE_GUID                      = e3aa5932-527a-42e7-86f5-81b144c7e5f1\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PciHostBridgeUtilityLib\r
+\r
+#\r
+# The following information is for reference only and not required by the build\r
+# tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 AARCH64 ARM\r
+#\r
+\r
+[Sources]\r
+  PciHostBridgeUtilityLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
index 54804962ec02a04603423a5e4bd20ab957bfb2d6..4348bb45c64a979011c8b08a91abce76444f6fc4 100644 (file)
   #                  access.\r
   PciCapPciSegmentLib|Include/Library/PciCapPciSegmentLib.h\r
 \r
+  ##  @libraryclass  Provide common utility functions to PciHostBridgeLib\r
+  #                  instances in ArmVirtPkg and OvmfPkg.\r
+  PciHostBridgeUtilityLib|Include/Library/PciHostBridgeUtilityLib.h\r
+\r
   ##  @libraryclass  Register a status code handler for printing the Boot\r
   #                  Manager's LoadImage() and StartImage() preparations, and\r
   #                  return codes, to the UEFI console.\r
index e5184ef06731fc93fe20e85307eb22fd73b1d253..1b8d34052b01d25022a3382fb23a9968234f86fb 100644 (file)
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
     <LibraryClasses>\r
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf\r
+      PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
       NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
index 3bfec9196eba18a25a3ecf8ff37376b93d891129..9c1aee87e7832872a68b3c710de83de3c076e203 100644 (file)
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
     <LibraryClasses>\r
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf\r
+      PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
       NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
index 1376158e37e33fe0f3241d64117c6518d38f2994..fabb8b2f29e4e668196d1a00e29f6a0658e2c590 100644 (file)
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
     <LibraryClasses>\r
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf\r
+      PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
       NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
index b79ee866c5bba1e9457007c00a7dcba6a08351a7..507029404f0bbdf449849bac7f81f6b7f0567919 100644 (file)
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
     <LibraryClasses>\r
       PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf\r
+      PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
       NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r