Merge branch 'pci/ecam'

- Unify ECAM constants in native PCI Express drivers (Krzysztof Wilczyński)

- Add thunder-pem constant for custom ".bus_shift" initialiser (Krzysztof
  Wilczyński)

- Convert iproc to use new ECAM constants (Krzysztof Wilczyński)

- Change vmd __iomem pointers from "char *" to "void *" (Krzysztof
  Wilczyński)

- Remove unused xgene .bus_shift initialisers (Krzysztof Wilczyński)

* pci/ecam:
  PCI: xgene: Removed unused ".bus_shift" initialisers from pci-xgene.c
  PCI: vmd: Update type of the __iomem pointers
  PCI: iproc: Convert to use the new ECAM constants
  PCI: thunder-pem: Add constant for custom ".bus_shift" initialiser
  PCI: Unify ECAM constants in native PCI Express drivers
This commit is contained in:
Bjorn Helgaas 2020-12-15 15:11:10 -06:00
commit 7c250f8293
17 changed files with 103 additions and 122 deletions

View File

@ -76,7 +76,6 @@ static int al_pcie_init(struct pci_config_window *cfg)
} }
const struct pci_ecam_ops al_pcie_ops = { const struct pci_ecam_ops al_pcie_ops = {
.bus_shift = 20,
.init = al_pcie_init, .init = al_pcie_init,
.pci_ops = { .pci_ops = {
.map_bus = al_pcie_map_bus, .map_bus = al_pcie_map_bus,
@ -138,8 +137,6 @@ struct al_pcie {
struct al_pcie_target_bus_cfg target_bus_cfg; struct al_pcie_target_bus_cfg target_bus_cfg;
}; };
#define PCIE_ECAM_DEVFN(x) (((x) & 0xff) << 12)
#define to_al_pcie(x) dev_get_drvdata((x)->dev) #define to_al_pcie(x) dev_get_drvdata((x)->dev)
static inline u32 al_pcie_controller_readl(struct al_pcie *pcie, u32 offset) static inline u32 al_pcie_controller_readl(struct al_pcie *pcie, u32 offset)
@ -226,11 +223,6 @@ static void __iomem *al_pcie_conf_addr_map_bus(struct pci_bus *bus,
struct al_pcie_target_bus_cfg *target_bus_cfg = &pcie->target_bus_cfg; struct al_pcie_target_bus_cfg *target_bus_cfg = &pcie->target_bus_cfg;
unsigned int busnr_ecam = busnr & target_bus_cfg->ecam_mask; unsigned int busnr_ecam = busnr & target_bus_cfg->ecam_mask;
unsigned int busnr_reg = busnr & target_bus_cfg->reg_mask; unsigned int busnr_reg = busnr & target_bus_cfg->reg_mask;
void __iomem *pci_base_addr;
pci_base_addr = (void __iomem *)((uintptr_t)pp->va_cfg0_base +
(busnr_ecam << 20) +
PCIE_ECAM_DEVFN(devfn));
if (busnr_reg != target_bus_cfg->reg_val) { if (busnr_reg != target_bus_cfg->reg_val) {
dev_dbg(pcie->pci->dev, "Changing target bus busnum val from 0x%x to 0x%x\n", dev_dbg(pcie->pci->dev, "Changing target bus busnum val from 0x%x to 0x%x\n",
@ -241,7 +233,7 @@ static void __iomem *al_pcie_conf_addr_map_bus(struct pci_bus *bus,
target_bus_cfg->reg_mask); target_bus_cfg->reg_mask);
} }
return pci_base_addr + where; return pp->va_cfg0_base + PCIE_ECAM_OFFSET(busnr_ecam, devfn, where);
} }
static struct pci_ops al_child_pci_ops = { static struct pci_ops al_child_pci_ops = {
@ -264,7 +256,7 @@ static void al_pcie_config_prepare(struct al_pcie *pcie)
target_bus_cfg = &pcie->target_bus_cfg; target_bus_cfg = &pcie->target_bus_cfg;
ecam_bus_mask = (pcie->ecam_size >> 20) - 1; ecam_bus_mask = (pcie->ecam_size >> PCIE_ECAM_BUS_SHIFT) - 1;
if (ecam_bus_mask > 255) { if (ecam_bus_mask > 255) {
dev_warn(pcie->dev, "ECAM window size is larger than 256MB. Cutting off at 256\n"); dev_warn(pcie->dev, "ECAM window size is larger than 256MB. Cutting off at 256\n");
ecam_bus_mask = 255; ecam_bus_mask = 255;

View File

@ -100,7 +100,6 @@ static int hisi_pcie_init(struct pci_config_window *cfg)
} }
const struct pci_ecam_ops hisi_pcie_ops = { const struct pci_ecam_ops hisi_pcie_ops = {
.bus_shift = 20,
.init = hisi_pcie_init, .init = hisi_pcie_init,
.pci_ops = { .pci_ops = {
.map_bus = hisi_pcie_map_bus, .map_bus = hisi_pcie_map_bus,
@ -135,7 +134,6 @@ static int hisi_pcie_platform_init(struct pci_config_window *cfg)
} }
static const struct pci_ecam_ops hisi_pcie_platform_ops = { static const struct pci_ecam_ops hisi_pcie_platform_ops = {
.bus_shift = 20,
.init = hisi_pcie_platform_init, .init = hisi_pcie_platform_init,
.pci_ops = { .pci_ops = {
.map_bus = hisi_pcie_map_bus, .map_bus = hisi_pcie_map_bus,

View File

@ -16,6 +16,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci-ecam.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/phy/phy.h> #include <linux/phy/phy.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
@ -164,14 +165,6 @@
#define PCIE_CONFIG_WR_TYPE0 0xa #define PCIE_CONFIG_WR_TYPE0 0xa
#define PCIE_CONFIG_WR_TYPE1 0xb #define PCIE_CONFIG_WR_TYPE1 0xb
#define PCIE_CONF_BUS(bus) (((bus) & 0xff) << 20)
#define PCIE_CONF_DEV(dev) (((dev) & 0x1f) << 15)
#define PCIE_CONF_FUNC(fun) (((fun) & 0x7) << 12)
#define PCIE_CONF_REG(reg) ((reg) & 0xffc)
#define PCIE_CONF_ADDR(bus, devfn, where) \
(PCIE_CONF_BUS(bus) | PCIE_CONF_DEV(PCI_SLOT(devfn)) | \
PCIE_CONF_FUNC(PCI_FUNC(devfn)) | PCIE_CONF_REG(where))
#define PIO_RETRY_CNT 500 #define PIO_RETRY_CNT 500
#define PIO_RETRY_DELAY 2 /* 2 us*/ #define PIO_RETRY_DELAY 2 /* 2 us*/
@ -687,7 +680,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
advk_writel(pcie, reg, PIO_CTRL); advk_writel(pcie, reg, PIO_CTRL);
/* Program the address registers */ /* Program the address registers */
reg = PCIE_CONF_ADDR(bus->number, devfn, where); reg = ALIGN_DOWN(PCIE_ECAM_OFFSET(bus->number, devfn, where), 4);
advk_writel(pcie, reg, PIO_ADDR_LS); advk_writel(pcie, reg, PIO_ADDR_LS);
advk_writel(pcie, 0, PIO_ADDR_MS); advk_writel(pcie, 0, PIO_ADDR_MS);
@ -748,7 +741,7 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
advk_writel(pcie, reg, PIO_CTRL); advk_writel(pcie, reg, PIO_CTRL);
/* Program the address registers */ /* Program the address registers */
reg = PCIE_CONF_ADDR(bus->number, devfn, where); reg = ALIGN_DOWN(PCIE_ECAM_OFFSET(bus->number, devfn, where), 4);
advk_writel(pcie, reg, PIO_ADDR_LS); advk_writel(pcie, reg, PIO_ADDR_LS);
advk_writel(pcie, 0, PIO_ADDR_MS); advk_writel(pcie, 0, PIO_ADDR_MS);

View File

@ -49,7 +49,6 @@ static void __iomem *pci_dw_ecam_map_bus(struct pci_bus *bus,
} }
static const struct pci_ecam_ops pci_dw_ecam_bus_ops = { static const struct pci_ecam_ops pci_dw_ecam_bus_ops = {
.bus_shift = 20,
.pci_ops = { .pci_ops = {
.map_bus = pci_dw_ecam_map_bus, .map_bus = pci_dw_ecam_map_bus,
.read = pci_generic_config_read, .read = pci_generic_config_read,

View File

@ -346,7 +346,6 @@ static int thunder_ecam_config_write(struct pci_bus *bus, unsigned int devfn,
} }
const struct pci_ecam_ops pci_thunder_ecam_ops = { const struct pci_ecam_ops pci_thunder_ecam_ops = {
.bus_shift = 20,
.pci_ops = { .pci_ops = {
.map_bus = pci_ecam_map_bus, .map_bus = pci_ecam_map_bus,
.read = thunder_ecam_config_read, .read = thunder_ecam_config_read,

View File

@ -19,6 +19,15 @@
#define PEM_CFG_WR 0x28 #define PEM_CFG_WR 0x28
#define PEM_CFG_RD 0x30 #define PEM_CFG_RD 0x30
/*
* Enhanced Configuration Access Mechanism (ECAM)
*
* N.B. This is a non-standard platform-specific ECAM bus shift value. For
* standard values defined in the PCI Express Base Specification see
* include/linux/pci-ecam.h.
*/
#define THUNDER_PCIE_ECAM_BUS_SHIFT 24
struct thunder_pem_pci { struct thunder_pem_pci {
u32 ea_entry[3]; u32 ea_entry[3];
void __iomem *pem_reg_base; void __iomem *pem_reg_base;
@ -404,7 +413,7 @@ static int thunder_pem_acpi_init(struct pci_config_window *cfg)
} }
const struct pci_ecam_ops thunder_pem_ecam_ops = { const struct pci_ecam_ops thunder_pem_ecam_ops = {
.bus_shift = 24, .bus_shift = THUNDER_PCIE_ECAM_BUS_SHIFT,
.init = thunder_pem_acpi_init, .init = thunder_pem_acpi_init,
.pci_ops = { .pci_ops = {
.map_bus = pci_ecam_map_bus, .map_bus = pci_ecam_map_bus,
@ -441,7 +450,7 @@ static int thunder_pem_platform_init(struct pci_config_window *cfg)
} }
static const struct pci_ecam_ops pci_thunder_pem_ops = { static const struct pci_ecam_ops pci_thunder_pem_ops = {
.bus_shift = 24, .bus_shift = THUNDER_PCIE_ECAM_BUS_SHIFT,
.init = thunder_pem_platform_init, .init = thunder_pem_platform_init,
.pci_ops = { .pci_ops = {
.map_bus = pci_ecam_map_bus, .map_bus = pci_ecam_map_bus,

View File

@ -257,7 +257,6 @@ static int xgene_v1_pcie_ecam_init(struct pci_config_window *cfg)
} }
const struct pci_ecam_ops xgene_v1_pcie_ecam_ops = { const struct pci_ecam_ops xgene_v1_pcie_ecam_ops = {
.bus_shift = 16,
.init = xgene_v1_pcie_ecam_init, .init = xgene_v1_pcie_ecam_init,
.pci_ops = { .pci_ops = {
.map_bus = xgene_pcie_map_bus, .map_bus = xgene_pcie_map_bus,
@ -272,7 +271,6 @@ static int xgene_v2_pcie_ecam_init(struct pci_config_window *cfg)
} }
const struct pci_ecam_ops xgene_v2_pcie_ecam_ops = { const struct pci_ecam_ops xgene_v2_pcie_ecam_ops = {
.bus_shift = 16,
.init = xgene_v2_pcie_ecam_init, .init = xgene_v2_pcie_ecam_init,
.pci_ops = { .pci_ops = {
.map_bus = xgene_pcie_map_bus, .map_bus = xgene_pcie_map_bus,

View File

@ -22,6 +22,7 @@
#include <linux/of_pci.h> #include <linux/of_pci.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci-ecam.h>
#include <linux/printk.h> #include <linux/printk.h>
#include <linux/reset.h> #include <linux/reset.h>
#include <linux/sizes.h> #include <linux/sizes.h>
@ -127,11 +128,7 @@
#define MSI_INT_MASK_CLR 0x14 #define MSI_INT_MASK_CLR 0x14
#define PCIE_EXT_CFG_DATA 0x8000 #define PCIE_EXT_CFG_DATA 0x8000
#define PCIE_EXT_CFG_INDEX 0x9000 #define PCIE_EXT_CFG_INDEX 0x9000
#define PCIE_EXT_BUSNUM_SHIFT 20
#define PCIE_EXT_SLOT_SHIFT 15
#define PCIE_EXT_FUNC_SHIFT 12
#define PCIE_RGR1_SW_INIT_1_PERST_MASK 0x1 #define PCIE_RGR1_SW_INIT_1_PERST_MASK 0x1
#define PCIE_RGR1_SW_INIT_1_PERST_SHIFT 0x0 #define PCIE_RGR1_SW_INIT_1_PERST_SHIFT 0x0
@ -695,15 +692,6 @@ static bool brcm_pcie_link_up(struct brcm_pcie *pcie)
return dla && plu; return dla && plu;
} }
/* Configuration space read/write support */
static inline int brcm_pcie_cfg_index(int busnr, int devfn, int reg)
{
return ((PCI_SLOT(devfn) & 0x1f) << PCIE_EXT_SLOT_SHIFT)
| ((PCI_FUNC(devfn) & 0x07) << PCIE_EXT_FUNC_SHIFT)
| (busnr << PCIE_EXT_BUSNUM_SHIFT)
| (reg & ~3);
}
static void __iomem *brcm_pcie_map_conf(struct pci_bus *bus, unsigned int devfn, static void __iomem *brcm_pcie_map_conf(struct pci_bus *bus, unsigned int devfn,
int where) int where)
{ {
@ -716,7 +704,7 @@ static void __iomem *brcm_pcie_map_conf(struct pci_bus *bus, unsigned int devfn,
return PCI_SLOT(devfn) ? NULL : base + where; return PCI_SLOT(devfn) ? NULL : base + where;
/* For devices, write to the config space index register */ /* For devices, write to the config space index register */
idx = brcm_pcie_cfg_index(bus->number, devfn, 0); idx = PCIE_ECAM_OFFSET(bus->number, devfn, 0);
writel(idx, pcie->base + PCIE_EXT_CFG_INDEX); writel(idx, pcie->base + PCIE_EXT_CFG_INDEX);
return base + PCIE_EXT_CFG_DATA + where; return base + PCIE_EXT_CFG_DATA + where;
} }

View File

@ -6,6 +6,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci-ecam.h>
#include <linux/msi.h> #include <linux/msi.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/module.h> #include <linux/module.h>
@ -39,16 +40,8 @@
#define CFG_IND_ADDR_MASK 0x00001ffc #define CFG_IND_ADDR_MASK 0x00001ffc
#define CFG_ADDR_BUS_NUM_SHIFT 20
#define CFG_ADDR_BUS_NUM_MASK 0x0ff00000
#define CFG_ADDR_DEV_NUM_SHIFT 15
#define CFG_ADDR_DEV_NUM_MASK 0x000f8000
#define CFG_ADDR_FUNC_NUM_SHIFT 12
#define CFG_ADDR_FUNC_NUM_MASK 0x00007000
#define CFG_ADDR_REG_NUM_SHIFT 2
#define CFG_ADDR_REG_NUM_MASK 0x00000ffc #define CFG_ADDR_REG_NUM_MASK 0x00000ffc
#define CFG_ADDR_CFG_TYPE_SHIFT 0 #define CFG_ADDR_CFG_TYPE_1 1
#define CFG_ADDR_CFG_TYPE_MASK 0x00000003
#define SYS_RC_INTX_MASK 0xf #define SYS_RC_INTX_MASK 0xf
@ -459,19 +452,15 @@ static inline void iproc_pcie_apb_err_disable(struct pci_bus *bus,
static void __iomem *iproc_pcie_map_ep_cfg_reg(struct iproc_pcie *pcie, static void __iomem *iproc_pcie_map_ep_cfg_reg(struct iproc_pcie *pcie,
unsigned int busno, unsigned int busno,
unsigned int slot, unsigned int devfn,
unsigned int fn,
int where) int where)
{ {
u16 offset; u16 offset;
u32 val; u32 val;
/* EP device access */ /* EP device access */
val = (busno << CFG_ADDR_BUS_NUM_SHIFT) | val = ALIGN_DOWN(PCIE_ECAM_OFFSET(busno, devfn, where), 4) |
(slot << CFG_ADDR_DEV_NUM_SHIFT) | CFG_ADDR_CFG_TYPE_1;
(fn << CFG_ADDR_FUNC_NUM_SHIFT) |
(where & CFG_ADDR_REG_NUM_MASK) |
(1 & CFG_ADDR_CFG_TYPE_MASK);
iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_ADDR, val); iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_ADDR, val);
offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_DATA); offset = iproc_pcie_reg_offset(pcie, IPROC_PCIE_CFG_DATA);
@ -574,8 +563,6 @@ static int iproc_pcie_config_read(struct pci_bus *bus, unsigned int devfn,
int where, int size, u32 *val) int where, int size, u32 *val)
{ {
struct iproc_pcie *pcie = iproc_data(bus); struct iproc_pcie *pcie = iproc_data(bus);
unsigned int slot = PCI_SLOT(devfn);
unsigned int fn = PCI_FUNC(devfn);
unsigned int busno = bus->number; unsigned int busno = bus->number;
void __iomem *cfg_data_p; void __iomem *cfg_data_p;
unsigned int data; unsigned int data;
@ -590,7 +577,7 @@ static int iproc_pcie_config_read(struct pci_bus *bus, unsigned int devfn,
return ret; return ret;
} }
cfg_data_p = iproc_pcie_map_ep_cfg_reg(pcie, busno, slot, fn, where); cfg_data_p = iproc_pcie_map_ep_cfg_reg(pcie, busno, devfn, where);
if (!cfg_data_p) if (!cfg_data_p)
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
@ -631,13 +618,11 @@ static void __iomem *iproc_pcie_map_cfg_bus(struct iproc_pcie *pcie,
int busno, unsigned int devfn, int busno, unsigned int devfn,
int where) int where)
{ {
unsigned slot = PCI_SLOT(devfn);
unsigned fn = PCI_FUNC(devfn);
u16 offset; u16 offset;
/* root complex access */ /* root complex access */
if (busno == 0) { if (busno == 0) {
if (slot > 0 || fn > 0) if (PCIE_ECAM_DEVFN(devfn) > 0)
return NULL; return NULL;
iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_IND_ADDR, iproc_pcie_write_reg(pcie, IPROC_PCIE_CFG_IND_ADDR,
@ -649,7 +634,7 @@ static void __iomem *iproc_pcie_map_cfg_bus(struct iproc_pcie *pcie,
return (pcie->base + offset); return (pcie->base + offset);
} }
return iproc_pcie_map_ep_cfg_reg(pcie, busno, slot, fn, where); return iproc_pcie_map_ep_cfg_reg(pcie, busno, devfn, where);
} }
static void __iomem *iproc_pcie_bus_map_cfg_bus(struct pci_bus *bus, static void __iomem *iproc_pcie_bus_map_cfg_bus(struct pci_bus *bus,

View File

@ -157,12 +157,11 @@ static int rockchip_pcie_rd_other_conf(struct rockchip_pcie *rockchip,
struct pci_bus *bus, u32 devfn, struct pci_bus *bus, u32 devfn,
int where, int size, u32 *val) int where, int size, u32 *val)
{ {
u32 busdev; void __iomem *addr;
busdev = PCIE_ECAM_ADDR(bus->number, PCI_SLOT(devfn), addr = rockchip->reg_base + PCIE_ECAM_OFFSET(bus->number, devfn, where);
PCI_FUNC(devfn), where);
if (!IS_ALIGNED(busdev, size)) { if (!IS_ALIGNED((uintptr_t)addr, size)) {
*val = 0; *val = 0;
return PCIBIOS_BAD_REGISTER_NUMBER; return PCIBIOS_BAD_REGISTER_NUMBER;
} }
@ -175,11 +174,11 @@ static int rockchip_pcie_rd_other_conf(struct rockchip_pcie *rockchip,
AXI_WRAPPER_TYPE1_CFG); AXI_WRAPPER_TYPE1_CFG);
if (size == 4) { if (size == 4) {
*val = readl(rockchip->reg_base + busdev); *val = readl(addr);
} else if (size == 2) { } else if (size == 2) {
*val = readw(rockchip->reg_base + busdev); *val = readw(addr);
} else if (size == 1) { } else if (size == 1) {
*val = readb(rockchip->reg_base + busdev); *val = readb(addr);
} else { } else {
*val = 0; *val = 0;
return PCIBIOS_BAD_REGISTER_NUMBER; return PCIBIOS_BAD_REGISTER_NUMBER;
@ -191,11 +190,11 @@ static int rockchip_pcie_wr_other_conf(struct rockchip_pcie *rockchip,
struct pci_bus *bus, u32 devfn, struct pci_bus *bus, u32 devfn,
int where, int size, u32 val) int where, int size, u32 val)
{ {
u32 busdev; void __iomem *addr;
busdev = PCIE_ECAM_ADDR(bus->number, PCI_SLOT(devfn), addr = rockchip->reg_base + PCIE_ECAM_OFFSET(bus->number, devfn, where);
PCI_FUNC(devfn), where);
if (!IS_ALIGNED(busdev, size)) if (!IS_ALIGNED((uintptr_t)addr, size))
return PCIBIOS_BAD_REGISTER_NUMBER; return PCIBIOS_BAD_REGISTER_NUMBER;
if (pci_is_root_bus(bus->parent)) if (pci_is_root_bus(bus->parent))
@ -206,11 +205,11 @@ static int rockchip_pcie_wr_other_conf(struct rockchip_pcie *rockchip,
AXI_WRAPPER_TYPE1_CFG); AXI_WRAPPER_TYPE1_CFG);
if (size == 4) if (size == 4)
writel(val, rockchip->reg_base + busdev); writel(val, addr);
else if (size == 2) else if (size == 2)
writew(val, rockchip->reg_base + busdev); writew(val, addr);
else if (size == 1) else if (size == 1)
writeb(val, rockchip->reg_base + busdev); writeb(val, addr);
else else
return PCIBIOS_BAD_REGISTER_NUMBER; return PCIBIOS_BAD_REGISTER_NUMBER;

View File

@ -13,6 +13,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci-ecam.h>
/* /*
* The upper 16 bits of PCIE_CLIENT_CONFIG are a write mask for the lower 16 * The upper 16 bits of PCIE_CLIENT_CONFIG are a write mask for the lower 16
@ -178,13 +179,6 @@
#define MIN_AXI_ADDR_BITS_PASSED 8 #define MIN_AXI_ADDR_BITS_PASSED 8
#define PCIE_RC_SEND_PME_OFF 0x11960 #define PCIE_RC_SEND_PME_OFF 0x11960
#define ROCKCHIP_VENDOR_ID 0x1d87 #define ROCKCHIP_VENDOR_ID 0x1d87
#define PCIE_ECAM_BUS(x) (((x) & 0xff) << 20)
#define PCIE_ECAM_DEV(x) (((x) & 0x1f) << 15)
#define PCIE_ECAM_FUNC(x) (((x) & 0x7) << 12)
#define PCIE_ECAM_REG(x) (((x) & 0xfff) << 0)
#define PCIE_ECAM_ADDR(bus, dev, func, reg) \
(PCIE_ECAM_BUS(bus) | PCIE_ECAM_DEV(dev) | \
PCIE_ECAM_FUNC(func) | PCIE_ECAM_REG(reg))
#define PCIE_LINK_IS_L2(x) \ #define PCIE_LINK_IS_L2(x) \
(((x) & PCIE_CLIENT_DEBUG_LTSSM_MASK) == PCIE_CLIENT_DEBUG_LTSSM_L2) (((x) & PCIE_CLIENT_DEBUG_LTSSM_MASK) == PCIE_CLIENT_DEBUG_LTSSM_L2)
#define PCIE_LINK_UP(x) \ #define PCIE_LINK_UP(x) \

View File

@ -208,7 +208,6 @@ static int smp8759_config_write(struct pci_bus *bus, unsigned int devfn,
} }
static const struct pci_ecam_ops smp8759_ecam_ops = { static const struct pci_ecam_ops smp8759_ecam_ops = {
.bus_shift = 20,
.pci_ops = { .pci_ops = {
.map_bus = pci_ecam_map_bus, .map_bus = pci_ecam_map_bus,
.read = smp8759_config_read, .read = smp8759_config_read,

View File

@ -18,6 +18,7 @@
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci-ecam.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/irqchip/chained_irq.h> #include <linux/irqchip/chained_irq.h>
@ -124,8 +125,6 @@
#define E_ECAM_CR_ENABLE BIT(0) #define E_ECAM_CR_ENABLE BIT(0)
#define E_ECAM_SIZE_LOC GENMASK(20, 16) #define E_ECAM_SIZE_LOC GENMASK(20, 16)
#define E_ECAM_SIZE_SHIFT 16 #define E_ECAM_SIZE_SHIFT 16
#define ECAM_BUS_LOC_SHIFT 20
#define ECAM_DEV_LOC_SHIFT 12
#define NWL_ECAM_VALUE_DEFAULT 12 #define NWL_ECAM_VALUE_DEFAULT 12
#define CFG_DMA_REG_BAR GENMASK(2, 0) #define CFG_DMA_REG_BAR GENMASK(2, 0)
@ -240,15 +239,11 @@ static void __iomem *nwl_pcie_map_bus(struct pci_bus *bus, unsigned int devfn,
int where) int where)
{ {
struct nwl_pcie *pcie = bus->sysdata; struct nwl_pcie *pcie = bus->sysdata;
int relbus;
if (!nwl_pcie_valid_device(bus, devfn)) if (!nwl_pcie_valid_device(bus, devfn))
return NULL; return NULL;
relbus = (bus->number << ECAM_BUS_LOC_SHIFT) | return pcie->ecam_base + PCIE_ECAM_OFFSET(bus->number, devfn, where);
(devfn << ECAM_DEV_LOC_SHIFT);
return pcie->ecam_base + relbus + where;
} }
/* PCIe operations */ /* PCIe operations */

View File

@ -21,6 +21,7 @@
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci-ecam.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include "../pci.h" #include "../pci.h"
@ -86,10 +87,6 @@
/* Phy Status/Control Register definitions */ /* Phy Status/Control Register definitions */
#define XILINX_PCIE_REG_PSCR_LNKUP BIT(11) #define XILINX_PCIE_REG_PSCR_LNKUP BIT(11)
/* ECAM definitions */
#define ECAM_BUS_NUM_SHIFT 20
#define ECAM_DEV_NUM_SHIFT 12
/* Number of MSI IRQs */ /* Number of MSI IRQs */
#define XILINX_NUM_MSI_IRQS 128 #define XILINX_NUM_MSI_IRQS 128
@ -183,15 +180,11 @@ static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
unsigned int devfn, int where) unsigned int devfn, int where)
{ {
struct xilinx_pcie_port *port = bus->sysdata; struct xilinx_pcie_port *port = bus->sysdata;
int relbus;
if (!xilinx_pcie_valid_device(bus, devfn)) if (!xilinx_pcie_valid_device(bus, devfn))
return NULL; return NULL;
relbus = (bus->number << ECAM_BUS_NUM_SHIFT) | return port->reg_base + PCIE_ECAM_OFFSET(bus->number, devfn, where);
(devfn << ECAM_DEV_NUM_SHIFT);
return port->reg_base + relbus + where;
} }
/* PCIe operations */ /* PCIe operations */

View File

@ -11,6 +11,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/msi.h> #include <linux/msi.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/pci-ecam.h>
#include <linux/srcu.h> #include <linux/srcu.h>
#include <linux/rculist.h> #include <linux/rculist.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
@ -94,7 +95,7 @@ struct vmd_dev {
struct pci_dev *dev; struct pci_dev *dev;
spinlock_t cfg_lock; spinlock_t cfg_lock;
char __iomem *cfgbar; void __iomem *cfgbar;
int msix_count; int msix_count;
struct vmd_irq_list *irqs; struct vmd_irq_list *irqs;
@ -325,18 +326,16 @@ static void vmd_remove_irq_domain(struct vmd_dev *vmd)
} }
} }
static char __iomem *vmd_cfg_addr(struct vmd_dev *vmd, struct pci_bus *bus, static void __iomem *vmd_cfg_addr(struct vmd_dev *vmd, struct pci_bus *bus,
unsigned int devfn, int reg, int len) unsigned int devfn, int reg, int len)
{ {
char __iomem *addr = vmd->cfgbar + unsigned int busnr_ecam = bus->number - vmd->busn_start;
((bus->number - vmd->busn_start) << 20) + u32 offset = PCIE_ECAM_OFFSET(busnr_ecam, devfn, reg);
(devfn << 12) + reg;
if ((addr - vmd->cfgbar) + len >= if (offset + len >= resource_size(&vmd->dev->resource[VMD_CFGBAR]))
resource_size(&vmd->dev->resource[VMD_CFGBAR]))
return NULL; return NULL;
return addr; return vmd->cfgbar + offset;
} }
/* /*
@ -347,7 +346,7 @@ static int vmd_pci_read(struct pci_bus *bus, unsigned int devfn, int reg,
int len, u32 *value) int len, u32 *value)
{ {
struct vmd_dev *vmd = vmd_from_bus(bus); struct vmd_dev *vmd = vmd_from_bus(bus);
char __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len);
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;
@ -382,7 +381,7 @@ static int vmd_pci_write(struct pci_bus *bus, unsigned int devfn, int reg,
int len, u32 value) int len, u32 value)
{ {
struct vmd_dev *vmd = vmd_from_bus(bus); struct vmd_dev *vmd = vmd_from_bus(bus);
char __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len);
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;

View File

@ -28,6 +28,7 @@ struct pci_config_window *pci_ecam_create(struct device *dev,
struct resource *cfgres, struct resource *busr, struct resource *cfgres, struct resource *busr,
const struct pci_ecam_ops *ops) const struct pci_ecam_ops *ops)
{ {
unsigned int bus_shift = ops->bus_shift;
struct pci_config_window *cfg; struct pci_config_window *cfg;
unsigned int bus_range, bus_range_max, bsz; unsigned int bus_range, bus_range_max, bsz;
struct resource *conflict; struct resource *conflict;
@ -40,20 +41,24 @@ struct pci_config_window *pci_ecam_create(struct device *dev,
if (!cfg) if (!cfg)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
/* ECAM-compliant platforms need not supply ops->bus_shift */
if (!bus_shift)
bus_shift = PCIE_ECAM_BUS_SHIFT;
cfg->parent = dev; cfg->parent = dev;
cfg->ops = ops; cfg->ops = ops;
cfg->busr.start = busr->start; cfg->busr.start = busr->start;
cfg->busr.end = busr->end; cfg->busr.end = busr->end;
cfg->busr.flags = IORESOURCE_BUS; cfg->busr.flags = IORESOURCE_BUS;
bus_range = resource_size(&cfg->busr); bus_range = resource_size(&cfg->busr);
bus_range_max = resource_size(cfgres) >> ops->bus_shift; bus_range_max = resource_size(cfgres) >> bus_shift;
if (bus_range > bus_range_max) { if (bus_range > bus_range_max) {
bus_range = bus_range_max; bus_range = bus_range_max;
cfg->busr.end = busr->start + bus_range - 1; cfg->busr.end = busr->start + bus_range - 1;
dev_warn(dev, "ECAM area %pR can only accommodate %pR (reduced from %pR desired)\n", dev_warn(dev, "ECAM area %pR can only accommodate %pR (reduced from %pR desired)\n",
cfgres, &cfg->busr, busr); cfgres, &cfg->busr, busr);
} }
bsz = 1 << ops->bus_shift; bsz = 1 << bus_shift;
cfg->res.start = cfgres->start; cfg->res.start = cfgres->start;
cfg->res.end = cfgres->end; cfg->res.end = cfgres->end;
@ -131,25 +136,36 @@ void __iomem *pci_ecam_map_bus(struct pci_bus *bus, unsigned int devfn,
int where) int where)
{ {
struct pci_config_window *cfg = bus->sysdata; struct pci_config_window *cfg = bus->sysdata;
unsigned int bus_shift = cfg->ops->bus_shift;
unsigned int devfn_shift = cfg->ops->bus_shift - 8; unsigned int devfn_shift = cfg->ops->bus_shift - 8;
unsigned int busn = bus->number; unsigned int busn = bus->number;
void __iomem *base; void __iomem *base;
u32 bus_offset, devfn_offset;
if (busn < cfg->busr.start || busn > cfg->busr.end) if (busn < cfg->busr.start || busn > cfg->busr.end)
return NULL; return NULL;
busn -= cfg->busr.start; busn -= cfg->busr.start;
if (per_bus_mapping) if (per_bus_mapping) {
base = cfg->winp[busn]; base = cfg->winp[busn];
else busn = 0;
base = cfg->win + (busn << cfg->ops->bus_shift); } else
return base + (devfn << devfn_shift) + where; base = cfg->win;
if (cfg->ops->bus_shift) {
bus_offset = (busn & PCIE_ECAM_BUS_MASK) << bus_shift;
devfn_offset = (devfn & PCIE_ECAM_DEVFN_MASK) << devfn_shift;
where &= PCIE_ECAM_REG_MASK;
return base + (bus_offset | devfn_offset | where);
}
return base + PCIE_ECAM_OFFSET(busn, devfn, where);
} }
EXPORT_SYMBOL_GPL(pci_ecam_map_bus); EXPORT_SYMBOL_GPL(pci_ecam_map_bus);
/* ECAM ops */ /* ECAM ops */
const struct pci_ecam_ops pci_generic_ecam_ops = { const struct pci_ecam_ops pci_generic_ecam_ops = {
.bus_shift = 20,
.pci_ops = { .pci_ops = {
.map_bus = pci_ecam_map_bus, .map_bus = pci_ecam_map_bus,
.read = pci_generic_config_read, .read = pci_generic_config_read,
@ -161,7 +177,6 @@ EXPORT_SYMBOL_GPL(pci_generic_ecam_ops);
#if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS) #if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS)
/* ECAM ops for 32-bit access only (non-compliant) */ /* ECAM ops for 32-bit access only (non-compliant) */
const struct pci_ecam_ops pci_32b_ops = { const struct pci_ecam_ops pci_32b_ops = {
.bus_shift = 20,
.pci_ops = { .pci_ops = {
.map_bus = pci_ecam_map_bus, .map_bus = pci_ecam_map_bus,
.read = pci_generic_config_read32, .read = pci_generic_config_read32,
@ -171,7 +186,6 @@ const struct pci_ecam_ops pci_32b_ops = {
/* ECAM ops for 32-bit read only (non-compliant) */ /* ECAM ops for 32-bit read only (non-compliant) */
const struct pci_ecam_ops pci_32b_read_ops = { const struct pci_ecam_ops pci_32b_read_ops = {
.bus_shift = 20,
.pci_ops = { .pci_ops = {
.map_bus = pci_ecam_map_bus, .map_bus = pci_ecam_map_bus,
.read = pci_generic_config_read32, .read = pci_generic_config_read32,

View File

@ -9,6 +9,33 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
/*
* Memory address shift values for the byte-level address that
* can be used when accessing the PCI Express Configuration Space.
*/
/*
* Enhanced Configuration Access Mechanism (ECAM)
*
* See PCI Express Base Specification, Revision 5.0, Version 1.0,
* Section 7.2.2, Table 7-1, p. 677.
*/
#define PCIE_ECAM_BUS_SHIFT 20 /* Bus number */
#define PCIE_ECAM_DEVFN_SHIFT 12 /* Device and Function number */
#define PCIE_ECAM_BUS_MASK 0xff
#define PCIE_ECAM_DEVFN_MASK 0xff
#define PCIE_ECAM_REG_MASK 0xfff /* Limit offset to a maximum of 4K */
#define PCIE_ECAM_BUS(x) (((x) & PCIE_ECAM_BUS_MASK) << PCIE_ECAM_BUS_SHIFT)
#define PCIE_ECAM_DEVFN(x) (((x) & PCIE_ECAM_DEVFN_MASK) << PCIE_ECAM_DEVFN_SHIFT)
#define PCIE_ECAM_REG(x) ((x) & PCIE_ECAM_REG_MASK)
#define PCIE_ECAM_OFFSET(bus, devfn, where) \
(PCIE_ECAM_BUS(bus) | \
PCIE_ECAM_DEVFN(devfn) | \
PCIE_ECAM_REG(where))
/* /*
* struct to hold pci ops and bus shift of the config window * struct to hold pci ops and bus shift of the config window
* for a PCI controller. * for a PCI controller.