[PATCH 5/6 v3] PCI: reserve bus range for SR-IOV

Previous thread: [PATCH 4/6 v3] PCI: support SR-IOV capability by Zhao, Yu on Saturday, September 27, 2008 - 1:28 am. (5 messages)

Next thread: [PATCH 6/6 v3] PCI: document the change by Zhao, Yu on Saturday, September 27, 2008 - 1:28 am. (12 messages)
From: Zhao, Yu
Date: Saturday, September 27, 2008 - 1:28 am

Reserve bus range for SR-IOV at device scanning stage.

Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Grant Grundler <grundler@parisc-linux.org>
Cc: Alex Chiang <achiang@hp.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Roland Dreier <rdreier@cisco.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Yu Zhao <yu.zhao@intel.com>

---
 drivers/pci/iov.c   |   24 ++++++++++++++++++++++++
 drivers/pci/pci.h   |    5 +++++
 drivers/pci/probe.c |    3 +++
 3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index a2b2de9..17ada58 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -600,6 +600,30 @@ void pci_iov_remove_sysfs(struct pci_dev *dev)
        kfree(iov->ve);
 }

+/**
+ * pci_iov_bus_range - find bus range used by SR-IOV capability
+ * @bus: the PCI bus
+ *
+ * Returns max number of buses (exclude current one) used by Virtual
+ * Functions.
+ */
+int pci_iov_bus_range(struct pci_bus *bus)
+{
+       int max = 0;
+       u8 busnr, devfn;
+       struct pci_dev *dev;
+
+       list_for_each_entry(dev, &bus->devices, bus_list) {
+               if (!dev->iov)
+                       continue;
+               vf_rid(dev, dev->iov->totalvfs - 1, &busnr, &devfn);
+               if (busnr > max)
+                       max = busnr;
+       }
+
+       return max ? max - bus->number : 0;
+}
+
 int pci_iov_resource_align(struct pci_dev *dev, int resno)
 {
        if (resno < PCI_IOV_RESOURCES || resno > PCI_IOV_RESOURCES_END)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 11b1d17..7039243 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -208,6 +208,7 @@ void pci_iov_remove_sysfs(struct pci_dev *dev);
 extern int pci_iov_resource_align(struct pci_dev *dev, int resno);
 extern int pci_iov_resource_bar(struct pci_dev *dev, int resno,
                                enum pci_bar_type *type);
+extern int pci_iov_bus_range(struct pci_bus *bus);
 ...
Previous thread: [PATCH 4/6 v3] PCI: support SR-IOV capability by Zhao, Yu on Saturday, September 27, 2008 - 1:28 am. (5 messages)

Next thread: [PATCH 6/6 v3] PCI: document the change by Zhao, Yu on Saturday, September 27, 2008 - 1:28 am. (12 messages)