Merge branch 'pci/config' into next
authorBjorn Helgaas <bhelgaas@google.com>
Mon, 2 Feb 2015 20:49:29 +0000 (14:49 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 2 Feb 2015 20:49:29 +0000 (14:49 -0600)
* pci/config:
  PCI: xilinx: Convert to use generic config accessors
  PCI: xgene: Convert to use generic config accessors
  PCI: tegra: Convert to use generic config accessors
  PCI: rcar: Convert to use generic config accessors
  PCI: generic: Convert to use generic config accessors
  powerpc/powermac: Convert PCI to use generic config accessors
  powerpc/fsl_pci: Convert PCI to use generic config accessors
  ARM: ks8695: Convert PCI to use generic config accessors
  ARM: sa1100: Convert PCI to use generic config accessors
  ARM: integrator: Convert PCI to use generic config accessors
  ARM: cns3xxx: Convert PCI to use generic config accessors
  PCI: Add generic config accessors
  powerpc/PCI: Add struct pci_ops member names to initialization
  mn10300/PCI: Add struct pci_ops member names to initialization
  MIPS: PCI: Add struct pci_ops member names to initialization
  frv/PCI: Add struct pci_ops member names to initialization

1  2 
arch/arm/mach-cns3xxx/pcie.c
drivers/pci/host/pci-tegra.c
drivers/pci/host/pci-xgene.c
drivers/pci/host/pcie-xilinx.c
include/linux/pci.h

index f6bf9f623d70b68bb7732029f436391de1253627,85fc72e875d28b0238dcc440fa8b265157bb620c..c622c306c390719f95cfac1eb8b3eff46f38c340
@@@ -30,15 -30,18 +30,15 @@@ struct cns3xxx_pcie 
        unsigned int irqs[2];
        struct resource res_io;
        struct resource res_mem;
 -      struct hw_pci hw_pci;
 -
 +      int port;
        bool linked;
  };
  
 -static struct cns3xxx_pcie cns3xxx_pcie[]; /* forward decl. */
 -
  static struct cns3xxx_pcie *sysdata_to_cnspci(void *sysdata)
  {
        struct pci_sys_data *root = sysdata;
  
 -      return &cns3xxx_pcie[root->domain];
 +      return root->private_data;
  }
  
  static struct cns3xxx_pcie *pdev_to_cnspci(const struct pci_dev *dev)
@@@ -51,8 -54,8 +51,8 @@@ static struct cns3xxx_pcie *pbus_to_cns
        return sysdata_to_cnspci(bus->sysdata);
  }
  
- static void __iomem *cns3xxx_pci_cfg_base(struct pci_bus *bus,
-                                 unsigned int devfn, int where)
+ static void __iomem *cns3xxx_pci_map_bus(struct pci_bus *bus,
+                                        unsigned int devfn, int where)
  {
        struct cns3xxx_pcie *cnspci = pbus_to_cnspci(bus);
        int busno = bus->number;
  static int cns3xxx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
                                   int where, int size, u32 *val)
  {
-       u32 v;
-       void __iomem *base;
+       int ret;
        u32 mask = (0x1ull << (size * 8)) - 1;
        int shift = (where % 4) * 8;
  
-       base = cns3xxx_pci_cfg_base(bus, devfn, where);
-       if (!base) {
-               *val = 0xffffffff;
-               return PCIBIOS_SUCCESSFUL;
-       }
-       v = __raw_readl(base);
+       ret = pci_generic_config_read32(bus, devfn, where, size, val);
  
-       if (bus->number == 0 && devfn == 0 &&
-                       (where & 0xffc) == PCI_CLASS_REVISION) {
+       if (ret == PCIBIOS_SUCCESSFUL && !bus->number && !devfn &&
+           (where & 0xffc) == PCI_CLASS_REVISION)
                /*
                 * RC's class is 0xb, but Linux PCI driver needs 0x604
                 * for a PCIe bridge. So we must fixup the class code
                 * to 0x604 here.
                 */
-               v &= 0xff;
-               v |= 0x604 << 16;
-       }
-       *val = (v >> shift) & mask;
-       return PCIBIOS_SUCCESSFUL;
- }
- static int cns3xxx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
-                                   int where, int size, u32 val)
- {
-       u32 v;
-       void __iomem *base;
-       u32 mask = (0x1ull << (size * 8)) - 1;
-       int shift = (where % 4) * 8;
-       base = cns3xxx_pci_cfg_base(bus, devfn, where);
-       if (!base)
-               return PCIBIOS_SUCCESSFUL;
-       v = __raw_readl(base);
-       v &= ~(mask << shift);
-       v |= (val & mask) << shift;
-       __raw_writel(v, base);
+               *val = ((((*val << shift) & 0xff) | (0x604 << 16)) >> shift) & mask;
  
-       return PCIBIOS_SUCCESSFUL;
+       return ret;
  }
  
  static int cns3xxx_pci_setup(int nr, struct pci_sys_data *sys)
  }
  
  static struct pci_ops cns3xxx_pcie_ops = {
+       .map_bus = cns3xxx_pci_map_bus,
        .read = cns3xxx_pci_read_config,
-       .write = cns3xxx_pci_write_config,
+       .write = pci_generic_config_write,
  };
  
  static int cns3xxx_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
@@@ -189,7 -160,13 +157,7 @@@ static struct cns3xxx_pcie cns3xxx_pcie
                        .flags = IORESOURCE_MEM,
                },
                .irqs = { IRQ_CNS3XXX_PCIE0_RC, IRQ_CNS3XXX_PCIE0_DEVICE, },
 -              .hw_pci = {
 -                      .domain = 0,
 -                      .nr_controllers = 1,
 -                      .ops = &cns3xxx_pcie_ops,
 -                      .setup = cns3xxx_pci_setup,
 -                      .map_irq = cns3xxx_pcie_map_irq,
 -              },
 +              .port = 0,
        },
        [1] = {
                .host_regs = (void __iomem *)CNS3XXX_PCIE1_HOST_BASE_VIRT,
                        .flags = IORESOURCE_MEM,
                },
                .irqs = { IRQ_CNS3XXX_PCIE1_RC, IRQ_CNS3XXX_PCIE1_DEVICE, },
 -              .hw_pci = {
 -                      .domain = 1,
 -                      .nr_controllers = 1,
 -                      .ops = &cns3xxx_pcie_ops,
 -                      .setup = cns3xxx_pci_setup,
 -                      .map_irq = cns3xxx_pcie_map_irq,
 -              },
 +              .port = 1,
        },
  };
  
  static void __init cns3xxx_pcie_check_link(struct cns3xxx_pcie *cnspci)
  {
 -      int port = cnspci->hw_pci.domain;
 +      int port = cnspci->port;
        u32 reg;
        unsigned long time;
  
  
  static void __init cns3xxx_pcie_hw_init(struct cns3xxx_pcie *cnspci)
  {
 -      int port = cnspci->hw_pci.domain;
 +      int port = cnspci->port;
        struct pci_sys_data sd = {
 -              .domain = port,
 +              .private_data = cnspci,
        };
        struct pci_bus bus = {
                .number = 0,
@@@ -308,14 -291,6 +276,14 @@@ static int cns3xxx_pcie_abort_handler(u
  void __init cns3xxx_pcie_init_late(void)
  {
        int i;
 +      void *private_data;
 +      struct hw_pci hw_pci = {
 +             .nr_controllers = 1,
 +             .ops = &cns3xxx_pcie_ops,
 +             .setup = cns3xxx_pci_setup,
 +             .map_irq = cns3xxx_pcie_map_irq,
 +             .private_data = &private_data,
 +      };
  
        pcibios_min_io = 0;
        pcibios_min_mem = 0;
                cns3xxx_pwr_soft_rst(0x1 << PM_SOFT_RST_REG_OFFST_PCIE(i));
                cns3xxx_pcie_check_link(&cns3xxx_pcie[i]);
                cns3xxx_pcie_hw_init(&cns3xxx_pcie[i]);
 -              pci_common_init(&cns3xxx_pcie[i].hw_pci);
 +              private_data = &cns3xxx_pcie[i];
 +              pci_common_init(&hw_pci);
        }
  
        pci_assign_unassigned_resources();
index 6f9c29fa70e7258203033efccb9c7fdbc8e79aff,44fd31b9fa2db372a52262b8750611fc0e072e1b..00e92720d7f79a37c1eca85d4059fc8d535b9107
@@@ -480,59 -480,10 +480,10 @@@ static void __iomem *tegra_pcie_conf_ad
        return addr;
  }
  
- static int tegra_pcie_read_conf(struct pci_bus *bus, unsigned int devfn,
-                               int where, int size, u32 *value)
- {
-       void __iomem *addr;
-       addr = tegra_pcie_conf_address(bus, devfn, where);
-       if (!addr) {
-               *value = 0xffffffff;
-               return PCIBIOS_DEVICE_NOT_FOUND;
-       }
-       *value = readl(addr);
-       if (size == 1)
-               *value = (*value >> (8 * (where & 3))) & 0xff;
-       else if (size == 2)
-               *value = (*value >> (8 * (where & 3))) & 0xffff;
-       return PCIBIOS_SUCCESSFUL;
- }
- static int tegra_pcie_write_conf(struct pci_bus *bus, unsigned int devfn,
-                                int where, int size, u32 value)
- {
-       void __iomem *addr;
-       u32 mask, tmp;
-       addr = tegra_pcie_conf_address(bus, devfn, where);
-       if (!addr)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-       if (size == 4) {
-               writel(value, addr);
-               return PCIBIOS_SUCCESSFUL;
-       }
-       if (size == 2)
-               mask = ~(0xffff << ((where & 0x3) * 8));
-       else if (size == 1)
-               mask = ~(0xff << ((where & 0x3) * 8));
-       else
-               return PCIBIOS_BAD_REGISTER_NUMBER;
-       tmp = readl(addr) & mask;
-       tmp |= value << ((where & 0x3) * 8);
-       writel(tmp, addr);
-       return PCIBIOS_SUCCESSFUL;
- }
  static struct pci_ops tegra_pcie_ops = {
-       .read = tegra_pcie_read_conf,
-       .write = tegra_pcie_write_conf,
+       .map_bus = tegra_pcie_conf_address,
+       .read = pci_generic_config_read32,
+       .write = pci_generic_config_write32,
  };
  
  static unsigned long tegra_pcie_port_get_pex_ctrl(struct tegra_pcie_port *port)
@@@ -625,6 -576,19 +576,6 @@@ static void tegra_pcie_port_free(struc
        devm_kfree(pcie->dev, port);
  }
  
 -static void tegra_pcie_fixup_bridge(struct pci_dev *dev)
 -{
 -      u16 reg;
 -
 -      if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) {
 -              pci_read_config_word(dev, PCI_COMMAND, &reg);
 -              reg |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
 -                      PCI_COMMAND_MASTER | PCI_COMMAND_SERR);
 -              pci_write_config_word(dev, PCI_COMMAND, reg);
 -      }
 -}
 -DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, tegra_pcie_fixup_bridge);
 -
  /* Tegra PCIE root complex wrongly reports device class */
  static void tegra_pcie_fixup_class(struct pci_dev *dev)
  {
index fdb348d3ccd32eaf2cebc8ac4872c8693f63ca15,ee6a3d3105d8f65c51e28da11d271f4f1c2c8bc1..e77d831dc24136eedfe80568dbff8840b2567f51
@@@ -16,7 -16,7 +16,7 @@@
   * GNU General Public License for more details.
   *
   */
 -#include <linux/clk-private.h>
 +#include <linux/clk.h>
  #include <linux/delay.h>
  #include <linux/io.h>
  #include <linux/jiffies.h>
@@@ -74,92 -74,6 +74,6 @@@ static inline u32 pcie_bar_low_val(u32 
        return (addr & PCI_BASE_ADDRESS_MEM_MASK) | flags;
  }
  
- /* PCIe Configuration Out/In */
- static inline void xgene_pcie_cfg_out32(void __iomem *addr, int offset, u32 val)
- {
-       writel(val, addr + offset);
- }
- static inline void xgene_pcie_cfg_out16(void __iomem *addr, int offset, u16 val)
- {
-       u32 val32 = readl(addr + (offset & ~0x3));
-       switch (offset & 0x3) {
-       case 2:
-               val32 &= ~0xFFFF0000;
-               val32 |= (u32)val << 16;
-               break;
-       case 0:
-       default:
-               val32 &= ~0xFFFF;
-               val32 |= val;
-               break;
-       }
-       writel(val32, addr + (offset & ~0x3));
- }
- static inline void xgene_pcie_cfg_out8(void __iomem *addr, int offset, u8 val)
- {
-       u32 val32 = readl(addr + (offset & ~0x3));
-       switch (offset & 0x3) {
-       case 0:
-               val32 &= ~0xFF;
-               val32 |= val;
-               break;
-       case 1:
-               val32 &= ~0xFF00;
-               val32 |= (u32)val << 8;
-               break;
-       case 2:
-               val32 &= ~0xFF0000;
-               val32 |= (u32)val << 16;
-               break;
-       case 3:
-       default:
-               val32 &= ~0xFF000000;
-               val32 |= (u32)val << 24;
-               break;
-       }
-       writel(val32, addr + (offset & ~0x3));
- }
- static inline void xgene_pcie_cfg_in32(void __iomem *addr, int offset, u32 *val)
- {
-       *val = readl(addr + offset);
- }
- static inline void xgene_pcie_cfg_in16(void __iomem *addr, int offset, u32 *val)
- {
-       *val = readl(addr + (offset & ~0x3));
-       switch (offset & 0x3) {
-       case 2:
-               *val >>= 16;
-               break;
-       }
-       *val &= 0xFFFF;
- }
- static inline void xgene_pcie_cfg_in8(void __iomem *addr, int offset, u32 *val)
- {
-       *val = readl(addr + (offset & ~0x3));
-       switch (offset & 0x3) {
-       case 3:
-               *val = *val >> 24;
-               break;
-       case 2:
-               *val = *val >> 16;
-               break;
-       case 1:
-               *val = *val >> 8;
-               break;
-       }
-       *val &= 0xFF;
- }
  /*
   * When the address bit [17:16] is 2'b01, the Configuration access will be
   * treated as Type 1 and it will be forwarded to external PCIe device.
@@@ -213,69 -127,23 +127,23 @@@ static bool xgene_pcie_hide_rc_bars(str
        return false;
  }
  
- static int xgene_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
-                                 int offset, int len, u32 *val)
+ static int xgene_pcie_map_bus(struct pci_bus *bus, unsigned int devfn,
+                             int offset)
  {
        struct xgene_pcie_port *port = bus->sysdata;
-       void __iomem *addr;
-       if ((pci_is_root_bus(bus) && devfn != 0) || !port->link_up)
-               return PCIBIOS_DEVICE_NOT_FOUND;
  
-       if (xgene_pcie_hide_rc_bars(bus, offset)) {
-               *val = 0;
-               return PCIBIOS_SUCCESSFUL;
-       }
+       if ((pci_is_root_bus(bus) && devfn != 0) || !port->link_up ||
+           xgene_pcie_hide_rc_bars(bus, offset))
+               return NULL;
  
        xgene_pcie_set_rtdid_reg(bus, devfn);
-       addr = xgene_pcie_get_cfg_base(bus);
-       switch (len) {
-       case 1:
-               xgene_pcie_cfg_in8(addr, offset, val);
-               break;
-       case 2:
-               xgene_pcie_cfg_in16(addr, offset, val);
-               break;
-       default:
-               xgene_pcie_cfg_in32(addr, offset, val);
-               break;
-       }
-       return PCIBIOS_SUCCESSFUL;
- }
- static int xgene_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
-                                  int offset, int len, u32 val)
- {
-       struct xgene_pcie_port *port = bus->sysdata;
-       void __iomem *addr;
-       if ((pci_is_root_bus(bus) && devfn != 0) || !port->link_up)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-       if (xgene_pcie_hide_rc_bars(bus, offset))
-               return PCIBIOS_SUCCESSFUL;
-       xgene_pcie_set_rtdid_reg(bus, devfn);
-       addr = xgene_pcie_get_cfg_base(bus);
-       switch (len) {
-       case 1:
-               xgene_pcie_cfg_out8(addr, offset, (u8)val);
-               break;
-       case 2:
-               xgene_pcie_cfg_out16(addr, offset, (u16)val);
-               break;
-       default:
-               xgene_pcie_cfg_out32(addr, offset, val);
-               break;
-       }
-       return PCIBIOS_SUCCESSFUL;
+       return xgene_pcie_get_cfg_base(bus);
  }
  
  static struct pci_ops xgene_pcie_ops = {
-       .read = xgene_pcie_read_config,
-       .write = xgene_pcie_write_config
+       .map_bus = xgene_pcie_map_bus,
+       .read = pci_generic_config_read32,
+       .write = pci_generic_config_write32,
  };
  
  static u64 xgene_pcie_set_ib_mask(void __iomem *csr_base, u32 addr,
index ce1c61d85b2c25c5874c31f9d795b5e1674b3925,f67d0363e3c973c23c2739beb5aa090ca4d4e8bc..eac4a4b957caa7062d5bfbfe39b4e58ea5cb3b81
@@@ -148,10 -148,10 +148,10 @@@ static inline bool xilinx_pcie_link_is_
   */
  static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie_port *port)
  {
 -      u32 val = pcie_read(port, XILINX_PCIE_REG_RPEFR);
 +      unsigned long val = pcie_read(port, XILINX_PCIE_REG_RPEFR);
  
        if (val & XILINX_PCIE_RPEFR_ERR_VALID) {
 -              dev_dbg(port->dev, "Requester ID %d\n",
 +              dev_dbg(port->dev, "Requester ID %lu\n",
                        val & XILINX_PCIE_RPEFR_REQ_ID);
                pcie_write(port, XILINX_PCIE_RPEFR_ALL_MASK,
                           XILINX_PCIE_REG_RPEFR);
@@@ -189,7 -189,7 +189,7 @@@ static bool xilinx_pcie_valid_device(st
  }
  
  /**
-  * xilinx_pcie_config_base - Get configuration base
+  * xilinx_pcie_map_bus - Get configuration base
   * @bus: PCI Bus structure
   * @devfn: Device/function
   * @where: Offset from base
   * Return: Base address of the configuration space needed to be
   *       accessed.
   */
- static void __iomem *xilinx_pcie_config_base(struct pci_bus *bus,
-                                            unsigned int devfn, int where)
+ static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
+                                        unsigned int devfn, int where)
  {
        struct xilinx_pcie_port *port = sys_to_pcie(bus->sysdata);
        int relbus;
  
+       if (!xilinx_pcie_valid_device(bus, devfn))
+               return NULL;
        relbus = (bus->number << ECAM_BUS_NUM_SHIFT) |
                 (devfn << ECAM_DEV_NUM_SHIFT);
  
        return port->reg_base + relbus + where;
  }
  
- /**
-  * xilinx_pcie_read_config - Read configuration space
-  * @bus: PCI Bus structure
-  * @devfn: Device/function
-  * @where: Offset from base
-  * @size: Byte/word/dword
-  * @val: Value to be read
-  *
-  * Return: PCIBIOS_SUCCESSFUL on success
-  *       PCIBIOS_DEVICE_NOT_FOUND on failure
-  */
- static int xilinx_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
-                                  int where, int size, u32 *val)
- {
-       void __iomem *addr;
-       if (!xilinx_pcie_valid_device(bus, devfn)) {
-               *val = 0xFFFFFFFF;
-               return PCIBIOS_DEVICE_NOT_FOUND;
-       }
-       addr = xilinx_pcie_config_base(bus, devfn, where);
-       switch (size) {
-       case 1:
-               *val = readb(addr);
-               break;
-       case 2:
-               *val = readw(addr);
-               break;
-       default:
-               *val = readl(addr);
-               break;
-       }
-       return PCIBIOS_SUCCESSFUL;
- }
- /**
-  * xilinx_pcie_write_config - Write configuration space
-  * @bus: PCI Bus structure
-  * @devfn: Device/function
-  * @where: Offset from base
-  * @size: Byte/word/dword
-  * @val: Value to be written to device
-  *
-  * Return: PCIBIOS_SUCCESSFUL on success
-  *       PCIBIOS_DEVICE_NOT_FOUND on failure
-  */
- static int xilinx_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
-                                   int where, int size, u32 val)
- {
-       void __iomem *addr;
-       if (!xilinx_pcie_valid_device(bus, devfn))
-               return PCIBIOS_DEVICE_NOT_FOUND;
-       addr = xilinx_pcie_config_base(bus, devfn, where);
-       switch (size) {
-       case 1:
-               writeb(val, addr);
-               break;
-       case 2:
-               writew(val, addr);
-               break;
-       default:
-               writel(val, addr);
-               break;
-       }
-       return PCIBIOS_SUCCESSFUL;
- }
  /* PCIe operations */
  static struct pci_ops xilinx_pcie_ops = {
-       .read  = xilinx_pcie_read_config,
-       .write = xilinx_pcie_write_config,
+       .map_bus = xilinx_pcie_map_bus,
+       .read   = pci_generic_config_read,
+       .write  = pci_generic_config_write,
  };
  
  /* MSI functions */
diff --combined include/linux/pci.h
index 7bed32b3fd5433c3a07d6365e9c023306161e56d,e7fd519001827f4693e160694ef219764293c045..10028a94eeb362aebb3b8be53f85f1ec26611609
@@@ -175,10 -175,6 +175,10 @@@ enum pci_dev_flags 
        PCI_DEV_FLAGS_DMA_ALIAS_DEVFN = (__force pci_dev_flags_t) (1 << 4),
        /* Use a PCIe-to-PCI bridge alias even if !pci_is_pcie */
        PCI_DEV_FLAG_PCIE_BRIDGE_ALIAS = (__force pci_dev_flags_t) (1 << 5),
 +      /* Do not use bus resets for device */
 +      PCI_DEV_FLAGS_NO_BUS_RESET = (__force pci_dev_flags_t) (1 << 6),
 +      /* Do not use PM reset even if device advertises NoSoftRst- */
 +      PCI_DEV_FLAGS_NO_PM_RESET = (__force pci_dev_flags_t) (1 << 7),
  };
  
  enum pci_irq_reroute_variant {
@@@ -564,6 -560,7 +564,7 @@@ static inline int pcibios_err_to_errno(
  /* Low-level architecture-dependent routines */
  
  struct pci_ops {
+       void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
        int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
        int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
  };
@@@ -861,6 -858,16 +862,16 @@@ int pci_bus_write_config_word(struct pc
                              int where, u16 val);
  int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
                               int where, u32 val);
+ int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
+                           int where, int size, u32 *val);
+ int pci_generic_config_write(struct pci_bus *bus, unsigned int devfn,
+                           int where, int size, u32 val);
+ int pci_generic_config_read32(struct pci_bus *bus, unsigned int devfn,
+                             int where, int size, u32 *val);
+ int pci_generic_config_write32(struct pci_bus *bus, unsigned int devfn,
+                              int where, int size, u32 val);
  struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
  
  static inline int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val)