]> xenbits.xensource.com Git - legacy/linux-2.6.18-xen.git/commitdiff
Backport: PCI: add a new function to map BAR offsets
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 13 Mar 2009 08:51:09 +0000 (08:51 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 13 Mar 2009 08:51:09 +0000 (08:51 +0000)
    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>
drivers/pci/pci.c
drivers/pci/pci.h
drivers/pci/setup-res.c

index f810e9eeb2cffce65d152b5aaf1738297be35299..0361192725d414b1d64ff4ca4bdd0b5d2a20595a 100644 (file)
@@ -949,6 +949,28 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
 }
 #endif
      
+/**
+ * pci_resource_bar - get position of the BAR associated with a resource
+ * @dev: the PCI device
+ * @resno: the resource number
+ * @type: the BAR type to be filled in
+ *
+ * Returns BAR position in config space, or 0 if the BAR is invalid.
+ */
+int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type)
+{
+       if (resno < PCI_ROM_RESOURCE) {
+               *type = pci_bar_unknown;
+               return PCI_BASE_ADDRESS_0 + 4 * resno;
+       } else if (resno == PCI_ROM_RESOURCE) {
+               *type = pci_bar_mem32;
+               return dev->rom_base_reg;
+       }
+
+       dev_err(&dev->dev, "BAR: invalid resource #%d\n", resno);
+       return 0;
+}
+
 static int __devinit pci_init(void)
 {
        struct pci_dev *dev = NULL;
index 76b3078b7ac576b9532094d33dcc3cdc3339323d..eb4fbd64f6e1f1dd7c9e013090fe850283dae4c2 100644 (file)
@@ -119,6 +119,8 @@ enum pci_bar_type {
 
 extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
                                struct resource *res, unsigned int reg);
+extern int pci_resource_bar(struct pci_dev *dev, int resno,
+                           enum pci_bar_type *type);
 extern void pci_enable_ari(struct pci_dev *dev);
 /**
  * pci_ari_enabled - query ARI forwarding status
index c41ab2e3b2f07a2c52395287277150052840f011..61bc32c56e4c497b0bc91e3a755bdb3b51bfffe0 100644 (file)
@@ -32,6 +32,7 @@ pci_update_resource(struct pci_dev *dev, int resno)
        struct pci_bus_region region;
        u32 new, check, mask;
        int reg;
+       enum pci_bar_type type;
        struct resource *res = dev->resource + resno;
 
        /* Ignore resources for unimplemented BARs and unused resource slots
@@ -52,17 +53,13 @@ pci_update_resource(struct pci_dev *dev, int resno)
        else
                mask = (u32)PCI_BASE_ADDRESS_MEM_MASK;
 
-       if (resno < 6) {
-               reg = PCI_BASE_ADDRESS_0 + 4 * resno;
-       } else if (resno == PCI_ROM_RESOURCE) {
+       reg = pci_resource_bar(dev, resno, &type);
+       if (!reg)
+               return;
+       if (type != pci_bar_unknown) {
                if (!(res->flags & IORESOURCE_ROM_ENABLE))
                        return;
                new |= PCI_ROM_ADDRESS_ENABLE;
-               reg = dev->rom_base_reg;
-       } else {
-               /* Hmm, non-standard resource. */
-       
-               return;         /* kill uninitialised var warning */
        }
 
        pci_write_config_dword(dev, reg, new);