]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
MdeModulePkg/PciBusDxe: Fix small memory leak in FreePciDevice
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciLib.c
index 976496379ab2bdcf1cdc3189cce107c98eb64aae..b81f81a1368a028dfb1c5bbd6df4ca714318959a 100644 (file)
@@ -29,6 +29,43 @@ CHAR16 *mBarTypeStr[] = {
   L"Unknow"\r
   };\r
 \r
+/**\r
+  Retrieve the max bus number that is assigned to the Root Bridge hierarchy.\r
+  It can support the case that there are multiple bus ranges.\r
+\r
+  @param  Bridge           Bridge device instance.\r
+\r
+  @retval                  The max bus number that is assigned to this Root Bridge hierarchy.\r
+\r
+**/\r
+UINT16\r
+PciGetMaxBusNumber (\r
+  IN PCI_IO_DEVICE                      *Bridge\r
+  )\r
+{\r
+  PCI_IO_DEVICE                      *RootBridge;\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR  *BusNumberRanges;\r
+  UINT64                             MaxNumberInRange;\r
+\r
+  //\r
+  // Get PCI Root Bridge device\r
+  //\r
+  RootBridge = Bridge;\r
+  while (RootBridge->Parent != NULL) {\r
+    RootBridge = RootBridge->Parent;\r
+  }\r
+  MaxNumberInRange = 0;\r
+  //\r
+  // Iterate the bus number ranges to get max PCI bus number\r
+  //\r
+  BusNumberRanges = RootBridge->BusNumberRanges;\r
+  while (BusNumberRanges->Desc != ACPI_END_TAG_DESCRIPTOR) {\r
+    MaxNumberInRange = BusNumberRanges->AddrRangeMin + BusNumberRanges->AddrLen - 1;\r
+    BusNumberRanges++;\r
+  }\r
+  return (UINT16) MaxNumberInRange;\r
+}\r
+\r
 /**\r
   Retrieve the PCI Card device BAR information via PciIo interface.\r
 \r
@@ -232,11 +269,11 @@ DumpBridgeResource (
 \r
 /**\r
   Find the corresponding resource node for the Device in child list of BridgeResource.\r
-  \r
+\r
   @param[in]  Device          Pointer to PCI_IO_DEVICE.\r
   @param[in]  BridgeResource  Pointer to PCI_RESOURCE_NODE.\r
   @param[out] DeviceResources Pointer to a buffer to receive resources for the Device.\r
-  \r
+\r
   @return Count of the resource descriptors returned.\r
 **/\r
 UINTN\r
@@ -269,7 +306,7 @@ FindResourceNode (
 \r
 /**\r
   Dump the resource map of all the devices under Bridge.\r
-  \r
+\r
   @param[in] Bridge        Bridge device instance.\r
   @param[in] Resources     Resource descriptors for the bridge device.\r
   @param[in] ResourceCount Count of resource descriptors.\r
@@ -1193,7 +1230,7 @@ PciScanBus (
           // Temporarily initialize SubBusNumber to maximum bus number to ensure the\r
           // PCI configuration transaction to go through any PPB\r
           //\r
-          Register  = 0xFF;\r
+          Register  = PciGetMaxBusNumber (Bridge);\r
           Address   = EFI_PCI_ADDRESS (StartBusNumber, Device, Func, PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET);\r
           Status = PciRootBridgeIo->Pci.Write (\r
                                           PciRootBridgeIo,\r