ia64/linux-2.6.18-xen.hg

changeset 818:13a42de2f9c5

Backport: PCI: add a new function to map BAR offsets

commit 613e7ed6f72b1a115f7ece8ce1b66cf095de1348
Author: Yu Zhao <yu.zhao@intel.com>
Date: Sat Nov 22 02:41:27 2008 +0800

PCI: add a new function to map BAR offsets

Add a function to map a given resource number to a corresponding
register so drivers can get the offset and type of device specific
BARs.

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Mar 13 08:51:09 2009 +0000 (2009-03-13)
parents 9b150690cb22
children e8a9f8910a3f
files drivers/pci/pci.c drivers/pci/pci.h drivers/pci/setup-res.c
line diff
     1.1 --- a/drivers/pci/pci.c	Fri Mar 13 08:50:44 2009 +0000
     1.2 +++ b/drivers/pci/pci.c	Fri Mar 13 08:51:09 2009 +0000
     1.3 @@ -949,6 +949,28 @@ pci_set_consistent_dma_mask(struct pci_d
     1.4  }
     1.5  #endif
     1.6       
     1.7 +/**
     1.8 + * pci_resource_bar - get position of the BAR associated with a resource
     1.9 + * @dev: the PCI device
    1.10 + * @resno: the resource number
    1.11 + * @type: the BAR type to be filled in
    1.12 + *
    1.13 + * Returns BAR position in config space, or 0 if the BAR is invalid.
    1.14 + */
    1.15 +int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type)
    1.16 +{
    1.17 +	if (resno < PCI_ROM_RESOURCE) {
    1.18 +		*type = pci_bar_unknown;
    1.19 +		return PCI_BASE_ADDRESS_0 + 4 * resno;
    1.20 +	} else if (resno == PCI_ROM_RESOURCE) {
    1.21 +		*type = pci_bar_mem32;
    1.22 +		return dev->rom_base_reg;
    1.23 +	}
    1.24 +
    1.25 +	dev_err(&dev->dev, "BAR: invalid resource #%d\n", resno);
    1.26 +	return 0;
    1.27 +}
    1.28 +
    1.29  static int __devinit pci_init(void)
    1.30  {
    1.31  	struct pci_dev *dev = NULL;
     2.1 --- a/drivers/pci/pci.h	Fri Mar 13 08:50:44 2009 +0000
     2.2 +++ b/drivers/pci/pci.h	Fri Mar 13 08:51:09 2009 +0000
     2.3 @@ -119,6 +119,8 @@ enum pci_bar_type {
     2.4  
     2.5  extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
     2.6  				struct resource *res, unsigned int reg);
     2.7 +extern int pci_resource_bar(struct pci_dev *dev, int resno,
     2.8 +			    enum pci_bar_type *type);
     2.9  extern void pci_enable_ari(struct pci_dev *dev);
    2.10  /**
    2.11   * pci_ari_enabled - query ARI forwarding status
     3.1 --- a/drivers/pci/setup-res.c	Fri Mar 13 08:50:44 2009 +0000
     3.2 +++ b/drivers/pci/setup-res.c	Fri Mar 13 08:51:09 2009 +0000
     3.3 @@ -32,6 +32,7 @@ pci_update_resource(struct pci_dev *dev,
     3.4  	struct pci_bus_region region;
     3.5  	u32 new, check, mask;
     3.6  	int reg;
     3.7 +	enum pci_bar_type type;
     3.8  	struct resource *res = dev->resource + resno;
     3.9  
    3.10  	/* Ignore resources for unimplemented BARs and unused resource slots
    3.11 @@ -52,17 +53,13 @@ pci_update_resource(struct pci_dev *dev,
    3.12  	else
    3.13  		mask = (u32)PCI_BASE_ADDRESS_MEM_MASK;
    3.14  
    3.15 -	if (resno < 6) {
    3.16 -		reg = PCI_BASE_ADDRESS_0 + 4 * resno;
    3.17 -	} else if (resno == PCI_ROM_RESOURCE) {
    3.18 +	reg = pci_resource_bar(dev, resno, &type);
    3.19 +	if (!reg)
    3.20 +		return;
    3.21 +	if (type != pci_bar_unknown) {
    3.22  		if (!(res->flags & IORESOURCE_ROM_ENABLE))
    3.23  			return;
    3.24  		new |= PCI_ROM_ADDRESS_ENABLE;
    3.25 -		reg = dev->rom_base_reg;
    3.26 -	} else {
    3.27 -		/* Hmm, non-standard resource. */
    3.28 -	
    3.29 -		return;		/* kill uninitialised var warning */
    3.30  	}
    3.31  
    3.32  	pci_write_config_dword(dev, reg, new);