ia64/linux-2.6.18-xen.hg

changeset 825:002e044dc979

PCI: centralize device setup code

Move the device setup stuff into pci_setup_device() which will be used
to setup the Virtual Function later.

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 18 11:39:56 2009 +0000 (2009-03-18)
parents 7544e16acfe9
children 64c8f9fbf609
files drivers/pci/pci.h drivers/pci/probe.c
line diff
     1.1 --- a/drivers/pci/pci.h	Wed Mar 18 11:39:32 2009 +0000
     1.2 +++ b/drivers/pci/pci.h	Wed Mar 18 11:39:56 2009 +0000
     1.3 @@ -117,6 +117,7 @@ enum pci_bar_type {
     1.4  	pci_bar_mem64,		/* A 64-bit memory BAR */
     1.5  };
     1.6  
     1.7 +extern int pci_setup_device(struct pci_dev *dev);
     1.8  extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
     1.9  				struct resource *res, unsigned int reg);
    1.10  extern int pci_resource_bar(struct pci_dev *dev, int resno,
     2.1 --- a/drivers/pci/probe.c	Wed Mar 18 11:39:32 2009 +0000
     2.2 +++ b/drivers/pci/probe.c	Wed Mar 18 11:39:56 2009 +0000
     2.3 @@ -683,13 +683,28 @@ static void pci_read_irq(struct pci_dev 
     2.4   * Initialize the device structure with information about the device's 
     2.5   * vendor,class,memory and IO-space addresses,IRQ lines etc.
     2.6   * Called at initialisation of the PCI subsystem and by CardBus services.
     2.7 - * Returns 0 on success and -1 if unknown type of device (not normal, bridge
     2.8 - * or CardBus).
     2.9 + * Returns 0 on success and negative if unknown type of device (not normal,
    2.10 + * bridge or CardBus).
    2.11   */
    2.12 -static int pci_setup_device(struct pci_dev * dev)
    2.13 +int pci_setup_device(struct pci_dev *dev)
    2.14  {
    2.15  	u32 class;
    2.16 +	u8 hdr_type;
    2.17  
    2.18 +	if (pci_read_config_byte(dev, PCI_HEADER_TYPE, &hdr_type))
    2.19 +		return -EIO;
    2.20 +
    2.21 +	dev->sysdata = dev->bus->sysdata;
    2.22 +	dev->dev.parent = dev->bus->bridge;
    2.23 +	dev->dev.bus = &pci_bus_type;
    2.24 +	dev->hdr_type = hdr_type & 0x7f;
    2.25 +	dev->multifunction = !!(hdr_type & 0x80);
    2.26 +	dev->cfg_size = pci_cfg_space_size(dev);
    2.27 +	dev->error_state = pci_channel_io_normal;
    2.28 +
    2.29 +	/* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
    2.30 +	   set this higher, assuming the system even supports it.  */
    2.31 +	dev->dma_mask = 0xffffffff;
    2.32  	sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus),
    2.33  		dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
    2.34  
    2.35 @@ -706,7 +721,6 @@ static int pci_setup_device(struct pci_d
    2.36  
    2.37  	/* Early fixups, before probing the BARs */
    2.38  	pci_fixup_device(pci_fixup_early, dev);
    2.39 -	class = dev->class >> 8;
    2.40  
    2.41  	switch (dev->hdr_type) {		    /* header type */
    2.42  	case PCI_HEADER_TYPE_NORMAL:		    /* standard header */
    2.43 @@ -741,7 +755,7 @@ static int pci_setup_device(struct pci_d
    2.44  	default:				    /* unknown header */
    2.45  		printk(KERN_ERR "PCI: device %s has unknown header type %02x, ignoring.\n",
    2.46  			pci_name(dev), dev->hdr_type);
    2.47 -		return -1;
    2.48 +		return -EIO;
    2.49  
    2.50  	bad:
    2.51  		printk(KERN_ERR "PCI: %s: class %x doesn't match header type %02x. Ignoring class.\n",
    2.52 @@ -823,7 +837,6 @@ pci_scan_device(struct pci_bus *bus, int
    2.53  {
    2.54  	struct pci_dev *dev;
    2.55  	u32 l;
    2.56 -	u8 hdr_type;
    2.57  	int delay = 1;
    2.58  
    2.59  	if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, &l))
    2.60 @@ -850,29 +863,16 @@ pci_scan_device(struct pci_bus *bus, int
    2.61  		}
    2.62  	}
    2.63  
    2.64 -	if (pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type))
    2.65 -		return NULL;
    2.66 -
    2.67  	dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
    2.68  	if (!dev)
    2.69  		return NULL;
    2.70  
    2.71  	dev->bus = bus;
    2.72 -	dev->sysdata = bus->sysdata;
    2.73 -	dev->dev.parent = bus->bridge;
    2.74 -	dev->dev.bus = &pci_bus_type;
    2.75  	dev->devfn = devfn;
    2.76 -	dev->hdr_type = hdr_type & 0x7f;
    2.77 -	dev->multifunction = !!(hdr_type & 0x80);
    2.78  	dev->vendor = l & 0xffff;
    2.79  	dev->device = (l >> 16) & 0xffff;
    2.80 -	dev->cfg_size = pci_cfg_space_size(dev);
    2.81 -	dev->error_state = pci_channel_io_normal;
    2.82  
    2.83 -	/* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
    2.84 -	   set this higher, assuming the system even supports it.  */
    2.85 -	dev->dma_mask = 0xffffffff;
    2.86 -	if (pci_setup_device(dev) < 0) {
    2.87 +	if (pci_setup_device(dev)) {
    2.88  		kfree(dev);
    2.89  		return NULL;
    2.90  	}