ia64/linux-2.6.18-xen.hg

changeset 861:366c31f3ab4b

backport Linux changeset of bf4162bcf82ebc3258d6bc0ddd6453132abde72d

Without this patch, fakephp with reassigndev fails
to allocate memory resource.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

commit bf4162bcf82ebc3258d6bc0ddd6453132abde72d
Author: Darrick J. Wong <djwong@us.ibm.com>
Date: Tue Nov 25 13:51:44 2008 -0800

PCI hotplug: fakephp: Allocate PCI resources before adding the
device

For PCI devices, pci_bus_assign_resources() must be called to set
up the pci_device->resource array before pci_bus_add_devices() can
be called, else attempts to load drivers results in BAR collision
errors where there are none.
This is not done in fakephp, so devices can be "unplugged" but
scanning the
parent bus won't bring the devices back due to resource
unallocation. Move the
pci_bus_add_device-calling logic into pci_rescan_bus and preface
it with a call
to pci_bus_assign_resources so that we only have to (re)allocate
resources once
per bus where a new device is found.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Acked-by: Alex Chiang <achiang@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 14 11:17:47 2009 +0100 (2009-04-14)
parents 3a8677ef8fd0
children dfd2adc58740
files drivers/pci/hotplug/fakephp.c
line diff
     1.1 --- a/drivers/pci/hotplug/fakephp.c	Tue Apr 14 11:16:26 2009 +0100
     1.2 +++ b/drivers/pci/hotplug/fakephp.c	Tue Apr 14 11:17:47 2009 +0100
     1.3 @@ -171,12 +171,14 @@ static void remove_slot(struct dummy_slo
     1.4   *
     1.5   * @param temp   Device template. Should be set: bus and devfn.
     1.6   */
     1.7 -static void pci_rescan_slot(struct pci_dev *temp)
     1.8 +static int pci_rescan_slot(struct pci_dev *temp)
     1.9  {
    1.10  	struct pci_bus *bus = temp->bus;
    1.11  	struct pci_dev *dev;
    1.12  	int func;
    1.13  	u8 hdr_type;
    1.14 +	int count = 0;
    1.15 +
    1.16  	if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) {
    1.17  		temp->hdr_type = hdr_type & 0x7f;
    1.18  		if (!pci_find_slot(bus->number, temp->devfn)) {
    1.19 @@ -185,13 +187,12 @@ static void pci_rescan_slot(struct pci_d
    1.20  				dbg("New device on %s function %x:%x\n",
    1.21  					bus->name, temp->devfn >> 3,
    1.22  					temp->devfn & 7);
    1.23 -				pci_bus_add_device(dev);
    1.24 -				add_slot(dev);
    1.25 +				count++;
    1.26  			}
    1.27  		}
    1.28  		/* multifunction device? */
    1.29  		if (!(hdr_type & 0x80))
    1.30 -			return;
    1.31 +			return count;
    1.32  
    1.33  		/* continue scanning for other functions */
    1.34  		for (func = 1, temp->devfn++; func < 8; func++, temp->devfn++) {
    1.35 @@ -205,12 +206,12 @@ static void pci_rescan_slot(struct pci_d
    1.36  					dbg("New device on %s function %x:%x\n",
    1.37  						bus->name, temp->devfn >> 3,
    1.38  						temp->devfn & 7);
    1.39 -					pci_bus_add_device(dev);
    1.40 -					add_slot(dev);
    1.41 +					count++;
    1.42  				}
    1.43  			}
    1.44  		}
    1.45  	}
    1.46 +	return count;
    1.47  }
    1.48  
    1.49  
    1.50 @@ -220,10 +221,11 @@ static void pci_rescan_slot(struct pci_d
    1.51   *
    1.52   * @param bus
    1.53   */
    1.54 -static void pci_rescan_bus(const struct pci_bus *bus)
    1.55 +static void pci_rescan_bus(struct pci_bus *bus)
    1.56  {
    1.57  	unsigned int devfn;
    1.58  	struct pci_dev *dev;
    1.59 +	int found = 0;
    1.60  	dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
    1.61  	if (!dev)
    1.62  		return;
    1.63 @@ -232,7 +234,20 @@ static void pci_rescan_bus(const struct 
    1.64  	dev->sysdata = bus->sysdata;
    1.65  	for (devfn = 0; devfn < 0x100; devfn += 8) {
    1.66  		dev->devfn = devfn;
    1.67 -		pci_rescan_slot(dev);
    1.68 +		found += pci_rescan_slot(dev);
    1.69 +	}
    1.70 +
    1.71 +	if (found) {
    1.72 +		struct pci_dev *tmp;
    1.73 +		pci_bus_assign_resources(bus);
    1.74 +		list_for_each_entry(tmp, &bus->devices, bus_list) {
    1.75 +			/* Skip already-added devices */
    1.76 +			if (!list_empty(&tmp->global_list))
    1.77 +				continue;
    1.78 +			pci_bus_add_device(tmp);
    1.79 +			add_slot(tmp);
    1.80 +		}
    1.81 +		pci_bus_add_devices(bus);
    1.82  	}
    1.83  	kfree(dev);
    1.84  }
    1.85 @@ -242,7 +257,7 @@ static void pci_rescan_buses(const struc
    1.86  {
    1.87  	const struct list_head *l;
    1.88  	list_for_each(l,list) {
    1.89 -		const struct pci_bus *b = pci_bus_b(l);
    1.90 +		struct pci_bus *b = pci_bus_b(l);
    1.91  		pci_rescan_bus(b);
    1.92  		pci_rescan_buses(&b->children);
    1.93  	}