Revision: 17963
          http://sourceforge.net/p/edk2/code/17963
Author:   lersek
Date:     2015-07-14 12:02:34 +0000 (Tue, 14 Jul 2015)
Log Message:
-----------
OvmfPkg: PciHostBridgeDxe: shorten search for extra root buses

QEMU provides an fw_cfg file called "etc/extra-pci-roots", containing a
little-endian UINT64 value that exposes the number of extra root buses. We
can use this value to terminate the scan as soon as we find the last extra
root bus.

Cc: Jordan Justen <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <[email protected]>
Regression-tested-by: Gabriel Somlo <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c
    trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf

Modified: trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c
===================================================================
--- trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c 2015-07-14 12:02:29 UTC 
(rev 17962)
+++ trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c 2015-07-14 12:02:34 UTC 
(rev 17963)
@@ -15,6 +15,8 @@
 
 **/
 
+#include <Library/QemuFwCfgLib.h>
+
 #include "PciHostBridge.h"
 
 STATIC
@@ -207,6 +209,9 @@
   )
 {
   EFI_STATUS                  Status;
+  FIRMWARE_CONFIG_ITEM        FwCfgItem;
+  UINTN                       FwCfgSize;
+  UINT64                      ExtraRootBridgesLeft;
   UINTN                       LastRootBridgeNumber;
   UINTN                       RootBridgeNumber;
   PCI_HOST_BRIDGE_INSTANCE    *HostBridge;
@@ -237,6 +242,20 @@
   }
 
   //
+  // 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 ExtraRootBridgesLeft) {
+    ExtraRootBridgesLeft = 0;
+  } else {
+    QemuFwCfgSelectItem (FwCfgItem);
+    QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridgesLeft);
+    DEBUG ((EFI_D_INFO, "%a: %Lu extra root buses reported by QEMU\n",
+      __FUNCTION__, ExtraRootBridgesLeft));
+  }
+
+  //
   // The "main" root bus is always there.
   //
   LastRootBridgeNumber = 0;
@@ -247,7 +266,7 @@
   // alive.
   //
   for (RootBridgeNumber = 1;
-       RootBridgeNumber < 256;
+       RootBridgeNumber < 256 && ExtraRootBridgesLeft > 0;
        ++RootBridgeNumber) {
     UINTN Device;
 
@@ -271,6 +290,7 @@
       }
       InsertTailList (&HostBridge->Head, &RootBus->Link);
       LastRootBridgeNumber = RootBridgeNumber;
+      --ExtraRootBridgesLeft;
     }
   }
 

Modified: trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf
===================================================================
--- trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf    2015-07-14 
12:02:29 UTC (rev 17962)
+++ trunk/edk2/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf    2015-07-14 
12:02:34 UTC (rev 17963)
@@ -26,6 +26,7 @@
 
 [Packages]
   MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
   UefiDriverEntryPoint
@@ -39,6 +40,7 @@
   DevicePathLib
   IoLib
   PciLib
+  QemuFwCfgLib
 
 [Sources]
   PciHostBridge.c


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to