From: Laszlo Ersek Date: Tue, 14 Jul 2015 12:02:34 +0000 (+0000) Subject: OvmfPkg: PciHostBridgeDxe: shorten search for extra root buses X-Git-Tag: edk2-stable201903~9314 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=68306ac2f2e7b85fc0d592248f68679139809b1a;p=mirror_edk2.git 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 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Regression-tested-by: Gabriel Somlo Reviewed-by: Jordan Justen git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17963 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c b/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c index 348664438d..efef2ed79e 100644 --- a/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c +++ b/OvmfPkg/PciHostBridgeDxe/PciHostBridge.c @@ -15,6 +15,8 @@ **/ +#include + #include "PciHostBridge.h" STATIC @@ -207,6 +209,9 @@ InitializePciHostBridge ( ) { EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + UINT64 ExtraRootBridgesLeft; UINTN LastRootBridgeNumber; UINTN RootBridgeNumber; PCI_HOST_BRIDGE_INSTANCE *HostBridge; @@ -236,6 +241,20 @@ InitializePciHostBridge ( goto FreeHostBridge; } + // + // 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. // @@ -247,7 +266,7 @@ InitializePciHostBridge ( // alive. // for (RootBridgeNumber = 1; - RootBridgeNumber < 256; + RootBridgeNumber < 256 && ExtraRootBridgesLeft > 0; ++RootBridgeNumber) { UINTN Device; @@ -271,6 +290,7 @@ InitializePciHostBridge ( } InsertTailList (&HostBridge->Head, &RootBus->Link); LastRootBridgeNumber = RootBridgeNumber; + --ExtraRootBridgesLeft; } } diff --git a/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf b/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf index 40f4c3cc34..ca760b5497 100644 --- a/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf +++ b/OvmfPkg/PciHostBridgeDxe/PciHostBridgeDxe.inf @@ -26,6 +26,7 @@ [Packages] MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec [LibraryClasses] UefiDriverEntryPoint @@ -39,6 +40,7 @@ DevicePathLib IoLib PciLib + QemuFwCfgLib [Sources] PciHostBridge.c