ia64/linux-2.6.18-xen.hg

changeset 824:7544e16acfe9

PCI: reserve bus range for SR-IOV device

Reserve the bus number range used by the Virtual Function when
pcibios_assign_all_busses() returns true.

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 18 11:39:32 2009 +0000 (2009-03-18)
parents 589a78a593f3
children 002e044dc979
files drivers/pci/iov.c drivers/pci/pci.h drivers/pci/probe.c
line diff
     1.1 --- a/drivers/pci/iov.c	Wed Mar 18 11:39:18 2009 +0000
     1.2 +++ b/drivers/pci/iov.c	Wed Mar 18 11:39:32 2009 +0000
     1.3 @@ -14,6 +14,18 @@
     1.4  #include "pci.h"
     1.5  
     1.6  
     1.7 +static inline u8 virtfn_bus(struct pci_dev *dev, int id)
     1.8 +{
     1.9 +	return dev->bus->number + ((dev->devfn + dev->sriov->offset +
    1.10 +				    dev->sriov->stride * id) >> 8);
    1.11 +}
    1.12 +
    1.13 +static inline u8 virtfn_devfn(struct pci_dev *dev, int id)
    1.14 +{
    1.15 +	return (dev->devfn + dev->sriov->offset +
    1.16 +		dev->sriov->stride * id) & 0xff;
    1.17 +}
    1.18 +
    1.19  static int sriov_init(struct pci_dev *dev, int pos)
    1.20  {
    1.21  	int i;
    1.22 @@ -202,3 +214,27 @@ void pci_restore_iov_state(struct pci_de
    1.23  	if (dev->is_physfn)
    1.24  		sriov_restore_state(dev);
    1.25  }
    1.26 +
    1.27 +/**
    1.28 + * pci_iov_bus_range - find bus range used by Virtual Function
    1.29 + * @bus: the PCI bus
    1.30 + *
    1.31 + * Returns max number of buses (exclude current one) used by Virtual
    1.32 + * Functions.
    1.33 + */
    1.34 +int pci_iov_bus_range(struct pci_bus *bus)
    1.35 +{
    1.36 +	int max = 0;
    1.37 +	u8 busnr;
    1.38 +	struct pci_dev *dev;
    1.39 +
    1.40 +	list_for_each_entry(dev, &bus->devices, bus_list) {
    1.41 +		if (!dev->is_physfn)
    1.42 +			continue;
    1.43 +		busnr = virtfn_bus(dev, dev->sriov->total - 1);
    1.44 +		if (busnr > max)
    1.45 +			max = busnr;
    1.46 +	}
    1.47 +
    1.48 +	return max ? max - bus->number : 0;
    1.49 +}
     2.1 --- a/drivers/pci/pci.h	Wed Mar 18 11:39:18 2009 +0000
     2.2 +++ b/drivers/pci/pci.h	Wed Mar 18 11:39:32 2009 +0000
     2.3 @@ -155,6 +155,7 @@ extern void pci_iov_release(struct pci_d
     2.4  extern int pci_iov_resource_bar(struct pci_dev *dev, int resno,
     2.5  				enum pci_bar_type *type);
     2.6  extern void pci_restore_iov_state(struct pci_dev *dev);
     2.7 +extern int pci_iov_bus_range(struct pci_bus *bus);
     2.8  #else
     2.9  static inline int pci_iov_init(struct pci_dev *dev)
    2.10  {
    2.11 @@ -172,4 +173,8 @@ static inline int pci_iov_resource_bar(s
    2.12  static inline void pci_restore_iov_state(struct pci_dev *dev)
    2.13  {
    2.14  }
    2.15 +static inline int pci_iov_bus_range(struct pci_bus *bus)
    2.16 +{
    2.17 +	return 0;
    2.18 +}
    2.19  #endif /* CONFIG_PCI_IOV */
     3.1 --- a/drivers/pci/probe.c	Wed Mar 18 11:39:18 2009 +0000
     3.2 +++ b/drivers/pci/probe.c	Wed Mar 18 11:39:32 2009 +0000
     3.3 @@ -976,6 +976,9 @@ unsigned int __devinit pci_scan_child_bu
     3.4  	for (devfn = 0; devfn < 0x100; devfn += 8)
     3.5  		pci_scan_slot(bus, devfn);
     3.6  
     3.7 +	/* Reserve buses for SR-IOV capability. */
     3.8 +	max += pci_iov_bus_range(bus);
     3.9 +
    3.10  	/*
    3.11  	 * After performing arch-dependent fixup of the bus, look behind
    3.12  	 * all PCI-to-PCI bridges on this bus.