]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge()
authorJiahui Cen via groups.io <cenjiahui=huawei.com@groups.io>
Tue, 19 Jan 2021 01:12:55 +0000 (09:12 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 20 Jan 2021 16:14:20 +0000 (16:14 +0000)
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>
Message-Id: <20210119011302.10908-5-cenjiahui@huawei.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf

index 5ea25ed2f4f4b6adf71f1a9ceadaca72b276722a..8a1ddc2f5e02c5d5038e082019359fc25a1dd034 100644 (file)
 #define __PCI_HOST_BRIDGE_UTILITY_LIB_H__\r
 \r
 \r
+#include <Library/PciHostBridgeLib.h>\r
+\r
+\r
+/**\r
+  Utility function to initialize a PCI_ROOT_BRIDGE structure.\r
+\r
+  @param[in]  Supports         Supported attributes.\r
+\r
+  @param[in]  Attributes       Initial attributes.\r
+\r
+  @param[in]  AllocAttributes  Allocation attributes.\r
+\r
+  @param[in]  RootBusNumber    The bus number to store in RootBus.\r
+\r
+  @param[in]  MaxSubBusNumber  The inclusive maximum bus number that can be\r
+                               assigned to any subordinate bus found behind any\r
+                               PCI bridge hanging off this root bus.\r
+\r
+                               The caller is repsonsible for ensuring that\r
+                               RootBusNumber <= MaxSubBusNumber. If\r
+                               RootBusNumber equals MaxSubBusNumber, then the\r
+                               root bus has no room for subordinate buses.\r
+\r
+  @param[in]  Io               IO aperture.\r
+\r
+  @param[in]  Mem              MMIO aperture.\r
+\r
+  @param[in]  MemAbove4G       MMIO aperture above 4G.\r
+\r
+  @param[in]  PMem             Prefetchable MMIO aperture.\r
+\r
+  @param[in]  PMemAbove4G      Prefetchable MMIO aperture above 4G.\r
+\r
+  @param[out] RootBus          The PCI_ROOT_BRIDGE structure (allocated by the\r
+                               caller) that should be filled in by this\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS           Initialization successful. A device path\r
+                                consisting of an ACPI device path node, with\r
+                                UID = RootBusNumber, has been allocated and\r
+                                linked into RootBus.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PciHostBridgeUtilityInitRootBridge (\r
+  IN  UINT64                   Supports,\r
+  IN  UINT64                   Attributes,\r
+  IN  UINT64                   AllocAttributes,\r
+  IN  UINT8                    RootBusNumber,\r
+  IN  UINT8                    MaxSubBusNumber,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *Io,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *Mem,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *PMem,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,\r
+  OUT PCI_ROOT_BRIDGE          *RootBus\r
+  );\r
+\r
+\r
+/**\r
+  Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with\r
+  PciHostBridgeUtilityInitRootBridge().\r
+\r
+  @param[in] RootBus  The PCI_ROOT_BRIDGE structure, allocated by the caller and\r
+                      initialized with PciHostBridgeUtilityInitRootBridge(),\r
+                      that should be uninitialized. This function doesn't free\r
+                      RootBus.\r
+**/\r
+VOID\r
+EFIAPI\r
+PciHostBridgeUtilityUninitRootBridge (\r
+  IN PCI_ROOT_BRIDGE *RootBus\r
+  );\r
+\r
+\r
 /**\r
   Utility function to inform the platform that the resource conflict happens.\r
 \r
index 134d7411214d1576968d444feebe79fce7aefe9b..a2e4d8696281fff4be6b014a9c9d6f341e4fd773 100644 (file)
@@ -11,59 +11,3 @@ PCI_ROOT_BRIDGE *
 ScanForRootBridges (\r
   UINTN      *NumberOfRootBridges\r
 );\r
-\r
-/**\r
-  Initialize a PCI_ROOT_BRIDGE structure.\r
-\r
-  @param[in]  Supports         Supported attributes.\r
-\r
-  @param[in]  Attributes       Initial attributes.\r
-\r
-  @param[in]  AllocAttributes  Allocation attributes.\r
-\r
-  @param[in]  RootBusNumber    The bus number to store in RootBus.\r
-\r
-  @param[in]  MaxSubBusNumber  The inclusive maximum bus number that can be\r
-                               assigned to any subordinate bus found behind any\r
-                               PCI bridge hanging off this root bus.\r
-\r
-                               The caller is repsonsible for ensuring that\r
-                               RootBusNumber <= MaxSubBusNumber. If\r
-                               RootBusNumber equals MaxSubBusNumber, then the\r
-                               root bus has no room for subordinate buses.\r
-\r
-  @param[in]  Io               IO aperture.\r
-\r
-  @param[in]  Mem              MMIO aperture.\r
-\r
-  @param[in]  MemAbove4G       MMIO aperture above 4G.\r
-\r
-  @param[in]  PMem             Prefetchable MMIO aperture.\r
-\r
-  @param[in]  PMemAbove4G      Prefetchable MMIO aperture above 4G.\r
-\r
-  @param[out] RootBus          The PCI_ROOT_BRIDGE structure (allocated by the\r
-                               caller) that should be filled in by this\r
-                               function.\r
-\r
-  @retval EFI_SUCCESS           Initialization successful. A device path\r
-                                consisting of an ACPI device path node, with\r
-                                UID = RootBusNumber, has been allocated and\r
-                                linked into RootBus.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
-**/\r
-EFI_STATUS\r
-InitRootBridge (\r
-  IN  UINT64                   Supports,\r
-  IN  UINT64                   Attributes,\r
-  IN  UINT64                   AllocAttributes,\r
-  IN  UINT8                    RootBusNumber,\r
-  IN  UINT8                    MaxSubBusNumber,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *Io,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *Mem,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *PMem,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,\r
-  OUT PCI_ROOT_BRIDGE          *RootBus\r
-  );\r
index bf32455b9f0df45af203de0914dd1fe4b0021636..07fa98110e98c8ca695985bd780a10f5dff156ba 100644 (file)
 #include <PiDxe.h>\r
 \r
 #include <IndustryStandard/Pci.h>\r
-#include <IndustryStandard/Q35MchIch9.h>\r
 \r
 #include <Protocol/PciHostBridgeResourceAllocation.h>\r
 #include <Protocol/PciRootBridgeIo.h>\r
 \r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/DevicePathLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/PciHostBridgeLib.h>\r
 #include "PciHostBridge.h"\r
 \r
 \r
-#pragma pack(1)\r
-typedef struct {\r
-  ACPI_HID_DEVICE_PATH     AcpiDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL EndDevicePath;\r
-} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;\r
-#pragma pack ()\r
-\r
-\r
-STATIC\r
-CONST\r
-OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {\r
-  {\r
-    {\r
-      ACPI_DEVICE_PATH,\r
-      ACPI_DP,\r
-      {\r
-        (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),\r
-        (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)\r
-      }\r
-    },\r
-    EISA_PNP_ID(0x0A03), // HID\r
-    0                    // UID\r
-  },\r
-\r
-  {\r
-    END_DEVICE_PATH_TYPE,\r
-    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    {\r
-      END_DEVICE_PATH_LENGTH,\r
-      0\r
-    }\r
-  }\r
-};\r
-\r
 STATIC PCI_ROOT_BRIDGE_APERTURE mNonExistAperture = { MAX_UINT64, 0 };\r
 \r
-/**\r
-  Initialize a PCI_ROOT_BRIDGE structure.\r
-\r
-  @param[in]  Supports         Supported attributes.\r
-\r
-  @param[in]  Attributes       Initial attributes.\r
-\r
-  @param[in]  AllocAttributes  Allocation attributes.\r
-\r
-  @param[in]  RootBusNumber    The bus number to store in RootBus.\r
-\r
-  @param[in]  MaxSubBusNumber  The inclusive maximum bus number that can be\r
-                               assigned to any subordinate bus found behind any\r
-                               PCI bridge hanging off this root bus.\r
-\r
-                               The caller is repsonsible for ensuring that\r
-                               RootBusNumber <= MaxSubBusNumber. If\r
-                               RootBusNumber equals MaxSubBusNumber, then the\r
-                               root bus has no room for subordinate buses.\r
-\r
-  @param[in]  Io               IO aperture.\r
-\r
-  @param[in]  Mem              MMIO aperture.\r
-\r
-  @param[in]  MemAbove4G       MMIO aperture above 4G.\r
-\r
-  @param[in]  PMem             Prefetchable MMIO aperture.\r
-\r
-  @param[in]  PMemAbove4G      Prefetchable MMIO aperture above 4G.\r
-\r
-  @param[out] RootBus          The PCI_ROOT_BRIDGE structure (allocated by the\r
-                               caller) that should be filled in by this\r
-                               function.\r
-\r
-  @retval EFI_SUCCESS           Initialization successful. A device path\r
-                                consisting of an ACPI device path node, with\r
-                                UID = RootBusNumber, has been allocated and\r
-                                linked into RootBus.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
-**/\r
-EFI_STATUS\r
-InitRootBridge (\r
-  IN  UINT64                   Supports,\r
-  IN  UINT64                   Attributes,\r
-  IN  UINT64                   AllocAttributes,\r
-  IN  UINT8                    RootBusNumber,\r
-  IN  UINT8                    MaxSubBusNumber,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *Io,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *Mem,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *PMem,\r
-  IN  PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,\r
-  OUT PCI_ROOT_BRIDGE          *RootBus\r
-  )\r
-{\r
-  OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;\r
-\r
-  //\r
-  // Be safe if other fields are added to PCI_ROOT_BRIDGE later.\r
-  //\r
-  ZeroMem (RootBus, sizeof *RootBus);\r
-\r
-  RootBus->Segment = 0;\r
-\r
-  RootBus->Supports   = Supports;\r
-  RootBus->Attributes = Attributes;\r
-\r
-  RootBus->DmaAbove4G = FALSE;\r
-\r
-  RootBus->AllocationAttributes = AllocAttributes;\r
-  RootBus->Bus.Base  = RootBusNumber;\r
-  RootBus->Bus.Limit = MaxSubBusNumber;\r
-  CopyMem (&RootBus->Io, Io, sizeof (*Io));\r
-  CopyMem (&RootBus->Mem, Mem, sizeof (*Mem));\r
-  CopyMem (&RootBus->MemAbove4G, MemAbove4G, sizeof (*MemAbove4G));\r
-  CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));\r
-  CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));\r
-\r
-  RootBus->NoExtendedConfigSpace = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=\r
-                                    INTEL_Q35_MCH_DEVICE_ID);\r
-\r
-  DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,\r
-                 &mRootBridgeDevicePathTemplate);\r
-  if (DevicePath == NULL) {\r
-    DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  DevicePath->AcpiDevicePath.UID = RootBusNumber;\r
-  RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;\r
-\r
-  DEBUG ((DEBUG_INFO,\r
-    "%a: populated root bus %d, with room for %d subordinate bus(es)\n",\r
-    __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
-  Uninitialize a PCI_ROOT_BRIDGE structure set up with InitRootBridge().\r
-\r
-  param[in] RootBus  The PCI_ROOT_BRIDGE structure, allocated by the caller and\r
-                     initialized with InitRootBridge(), that should be\r
-                     uninitialized. This function doesn't free RootBus.\r
-**/\r
-STATIC\r
-VOID\r
-UninitRootBridge (\r
-  IN PCI_ROOT_BRIDGE *RootBus\r
-  )\r
-{\r
-  FreePool (RootBus->DevicePath);\r
-}\r
-\r
 \r
 /**\r
   Return all the root bridge instances in an array.\r
@@ -297,7 +147,7 @@ PciHostBridgeGetRootBridges (
       // because now we know how big a bus number range *that* one has, for any\r
       // subordinate buses that might exist behind PCI bridges hanging off it.\r
       //\r
-      Status = InitRootBridge (\r
+      Status = PciHostBridgeUtilityInitRootBridge (\r
         Attributes,\r
         Attributes,\r
         AllocationAttributes,\r
@@ -322,7 +172,7 @@ PciHostBridgeGetRootBridges (
   // Install the last root bus (which might be the only, ie. main, root bus, if\r
   // we've found no extra root buses).\r
   //\r
-  Status = InitRootBridge (\r
+  Status = PciHostBridgeUtilityInitRootBridge (\r
     Attributes,\r
     Attributes,\r
     AllocationAttributes,\r
@@ -346,7 +196,7 @@ PciHostBridgeGetRootBridges (
 FreeBridges:\r
   while (Initialized > 0) {\r
     --Initialized;\r
-    UninitRootBridge (&Bridges[Initialized]);\r
+    PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);\r
   }\r
 \r
   FreePool (Bridges);\r
@@ -375,7 +225,7 @@ PciHostBridgeFreeRootBridges (
 \r
   do {\r
     --Count;\r
-    UninitRootBridge (&Bridges[Count]);\r
+    PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);\r
   } while (Count > 0);\r
 \r
   FreePool (Bridges);\r
index cec3f1631a72a5efb3ecba0790e0c5fcba0f55a6..7944f94b77437dab9cc8e18fad0597549277f5b3 100644 (file)
@@ -37,7 +37,6 @@
 [LibraryClasses]\r
   BaseMemoryLib\r
   DebugLib\r
-  DevicePathLib\r
   MemoryAllocationLib\r
   PcdLib\r
   PciHostBridgeUtilityLib\r
@@ -51,5 +50,4 @@
   gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size\r
   gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base\r
   gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size\r
-  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration\r
index 95ed0a280b9bb905af51a0b7e755f5cb26c2d921..5dfeba0e6e2335c36105b88378fdbee78e69c742 100644 (file)
@@ -19,6 +19,7 @@
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/PciHostBridgeLib.h>\r
+#include <Library/PciHostBridgeUtilityLib.h>\r
 #include <Library/PciLib.h>\r
 #include "PciHostBridge.h"\r
 \r
@@ -453,7 +454,7 @@ ScanForRootBridges (
         RootBridges\r
       );\r
       ASSERT (RootBridges != NULL);\r
-      InitRootBridge (\r
+      PciHostBridgeUtilityInitRootBridge (\r
         Attributes, Attributes, 0,\r
         (UINT8) PrimaryBus, (UINT8) SubBus,\r
         &Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture,\r
index ac94e62612be3eacce22973289e90fea7ae0af6c..92b42566e5f8d9bd0fdca9b6eb512241f449ccfc 100644 (file)
 **/\r
 \r
 #include <IndustryStandard/Acpi10.h>\r
+#include <IndustryStandard/Q35MchIch9.h>\r
+#include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
 #include <Library/PciHostBridgeUtilityLib.h>\r
 \r
 \r
+#pragma pack(1)\r
+typedef struct {\r
+  ACPI_HID_DEVICE_PATH     AcpiDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL EndDevicePath;\r
+} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;\r
+#pragma pack ()\r
+\r
+\r
 GLOBAL_REMOVE_IF_UNREFERENCED\r
 CHAR16 *mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[] = {\r
   L"Mem", L"I/O", L"Bus"\r
 };\r
 \r
 \r
+STATIC\r
+CONST\r
+OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {\r
+  {\r
+    {\r
+      ACPI_DEVICE_PATH,\r
+      ACPI_DP,\r
+      {\r
+        (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),\r
+        (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)\r
+      }\r
+    },\r
+    EISA_PNP_ID(0x0A03), // HID\r
+    0                    // UID\r
+  },\r
+\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    {\r
+      END_DEVICE_PATH_LENGTH,\r
+      0\r
+    }\r
+  }\r
+};\r
+\r
+\r
+/**\r
+  Utility function to initialize a PCI_ROOT_BRIDGE structure.\r
+\r
+  @param[in]  Supports         Supported attributes.\r
+\r
+  @param[in]  Attributes       Initial attributes.\r
+\r
+  @param[in]  AllocAttributes  Allocation attributes.\r
+\r
+  @param[in]  RootBusNumber    The bus number to store in RootBus.\r
+\r
+  @param[in]  MaxSubBusNumber  The inclusive maximum bus number that can be\r
+                               assigned to any subordinate bus found behind any\r
+                               PCI bridge hanging off this root bus.\r
+\r
+                               The caller is repsonsible for ensuring that\r
+                               RootBusNumber <= MaxSubBusNumber. If\r
+                               RootBusNumber equals MaxSubBusNumber, then the\r
+                               root bus has no room for subordinate buses.\r
+\r
+  @param[in]  Io               IO aperture.\r
+\r
+  @param[in]  Mem              MMIO aperture.\r
+\r
+  @param[in]  MemAbove4G       MMIO aperture above 4G.\r
+\r
+  @param[in]  PMem             Prefetchable MMIO aperture.\r
+\r
+  @param[in]  PMemAbove4G      Prefetchable MMIO aperture above 4G.\r
+\r
+  @param[out] RootBus          The PCI_ROOT_BRIDGE structure (allocated by the\r
+                               caller) that should be filled in by this\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS           Initialization successful. A device path\r
+                                consisting of an ACPI device path node, with\r
+                                UID = RootBusNumber, has been allocated and\r
+                                linked into RootBus.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PciHostBridgeUtilityInitRootBridge (\r
+  IN  UINT64                   Supports,\r
+  IN  UINT64                   Attributes,\r
+  IN  UINT64                   AllocAttributes,\r
+  IN  UINT8                    RootBusNumber,\r
+  IN  UINT8                    MaxSubBusNumber,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *Io,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *Mem,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *PMem,\r
+  IN  PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,\r
+  OUT PCI_ROOT_BRIDGE          *RootBus\r
+  )\r
+{\r
+  OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;\r
+\r
+  //\r
+  // Be safe if other fields are added to PCI_ROOT_BRIDGE later.\r
+  //\r
+  ZeroMem (RootBus, sizeof *RootBus);\r
+\r
+  RootBus->Segment = 0;\r
+\r
+  RootBus->Supports   = Supports;\r
+  RootBus->Attributes = Attributes;\r
+\r
+  RootBus->DmaAbove4G = FALSE;\r
+\r
+  RootBus->AllocationAttributes = AllocAttributes;\r
+  RootBus->Bus.Base  = RootBusNumber;\r
+  RootBus->Bus.Limit = MaxSubBusNumber;\r
+  CopyMem (&RootBus->Io, Io, sizeof (*Io));\r
+  CopyMem (&RootBus->Mem, Mem, sizeof (*Mem));\r
+  CopyMem (&RootBus->MemAbove4G, MemAbove4G, sizeof (*MemAbove4G));\r
+  CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));\r
+  CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));\r
+\r
+  RootBus->NoExtendedConfigSpace = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=\r
+                                    INTEL_Q35_MCH_DEVICE_ID);\r
+\r
+  DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,\r
+                 &mRootBridgeDevicePathTemplate);\r
+  if (DevicePath == NULL) {\r
+    DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  DevicePath->AcpiDevicePath.UID = RootBusNumber;\r
+  RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;\r
+\r
+  DEBUG ((DEBUG_INFO,\r
+    "%a: populated root bus %d, with room for %d subordinate bus(es)\n",\r
+    __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with\r
+  PciHostBridgeUtilityInitRootBridge().\r
+\r
+  @param[in] RootBus  The PCI_ROOT_BRIDGE structure, allocated by the caller and\r
+                      initialized with PciHostBridgeUtilityInitRootBridge(),\r
+                      that should be uninitialized. This function doesn't free\r
+                      RootBus.\r
+**/\r
+VOID\r
+EFIAPI\r
+PciHostBridgeUtilityUninitRootBridge (\r
+  IN PCI_ROOT_BRIDGE *RootBus\r
+  )\r
+{\r
+  FreePool (RootBus->DevicePath);\r
+}\r
+\r
+\r
 /**\r
   Utility function to inform the platform that the resource conflict happens.\r
 \r
index 1ba8ec3e03c725a5e6d51b5f2cb5cfc94965e948..e3d0a3740952e161c9dfc190f71a63b4c1cfb6f0 100644 (file)
   PciHostBridgeUtilityLib.c\r
 \r
 [Packages]\r
+  MdeModulePkg/MdeModulePkg.dec\r
   MdePkg/MdePkg.dec\r
   OvmfPkg/OvmfPkg.dec\r
 \r
 [LibraryClasses]\r
+  BaseMemoryLib\r
   DebugLib\r
+  DevicePathLib\r
+  MemoryAllocationLib\r
+  PcdLib\r
+\r
+[Pcd]\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId\r