[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [linux-2.6.18-xen] Backport: PCI: add a new function to map BAR offsets



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1236934269 0
# Node ID 13a42de2f9c53345dae1afa1f0348fc29df65803
# Parent  9b150690cb22eeb0504d00a884314f288088aeae
Backport: PCI: add a new function to map BAR offsets

    commit 613e7ed6f72b1a115f7ece8ce1b66cf095de1348
    Author: Yu Zhao <yu.zhao@xxxxxxxxx>
    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@xxxxxxxxx>
    Signed-off-by: Jesse Barnes <jbarnes@xxxxxxxxxxxxxxxx>

Signed-off-by: Yu Zhao <yu.zhao@xxxxxxxxx>
---
 drivers/pci/pci.c       |   22 ++++++++++++++++++++++
 drivers/pci/pci.h       |    2 ++
 drivers/pci/setup-res.c |   13 +++++--------
 3 files changed, 29 insertions(+), 8 deletions(-)

diff -r 9b150690cb22 -r 13a42de2f9c5 drivers/pci/pci.c
--- a/drivers/pci/pci.c Fri Mar 13 08:50:44 2009 +0000
+++ b/drivers/pci/pci.c Fri Mar 13 08:51:09 2009 +0000
@@ -949,6 +949,28 @@ pci_set_consistent_dma_mask(struct pci_d
 }
 #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;
diff -r 9b150690cb22 -r 13a42de2f9c5 drivers/pci/pci.h
--- a/drivers/pci/pci.h Fri Mar 13 08:50:44 2009 +0000
+++ b/drivers/pci/pci.h Fri Mar 13 08:51:09 2009 +0000
@@ -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
diff -r 9b150690cb22 -r 13a42de2f9c5 drivers/pci/setup-res.c
--- a/drivers/pci/setup-res.c   Fri Mar 13 08:50:44 2009 +0000
+++ b/drivers/pci/setup-res.c   Fri Mar 13 08:51:09 2009 +0000
@@ -32,6 +32,7 @@ pci_update_resource(struct pci_dev *dev,
        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,
        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);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.