Skip to content

Commit 14868d7

Browse files
committed
Merge branch 'remotes/lorenzo/pci/misc'
- Add macros for PCI Configuration Mechanism #1 and use them in the ftpci100, mt7621, and tegra drivers (Pali Rohár) * remotes/lorenzo/pci/misc: PCI: tegra: Use PCI_CONF1_EXT_ADDRESS() macro PCI: mt7621: Use PCI_CONF1_EXT_ADDRESS() macro PCI: ftpci100: Use PCI_CONF1_ADDRESS() macro PCI: Add standard PCI Config Address macros
2 parents e302baf + 8bb7ff1 commit 14868d7

File tree

4 files changed

+58
-36
lines changed

4 files changed

+58
-36
lines changed

drivers/pci/controller/pci-ftpci100.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@
103103
#define FARADAY_PCI_DMA_MEM2_BASE 0x00000000
104104
#define FARADAY_PCI_DMA_MEM3_BASE 0x00000000
105105

106-
/* Defines for PCI configuration command register */
107-
#define PCI_CONF_ENABLE BIT(31)
108-
#define PCI_CONF_WHERE(r) ((r) & 0xFC)
109-
#define PCI_CONF_BUS(b) (((b) & 0xFF) << 16)
110-
#define PCI_CONF_DEVICE(d) (((d) & 0x1F) << 11)
111-
#define PCI_CONF_FUNCTION(f) (((f) & 0x07) << 8)
112-
113106
/**
114107
* struct faraday_pci_variant - encodes IP block differences
115108
* @cascaded_irq: this host has cascaded IRQs from an interrupt controller
@@ -190,11 +183,8 @@ static int faraday_raw_pci_read_config(struct faraday_pci *p, int bus_number,
190183
unsigned int fn, int config, int size,
191184
u32 *value)
192185
{
193-
writel(PCI_CONF_BUS(bus_number) |
194-
PCI_CONF_DEVICE(PCI_SLOT(fn)) |
195-
PCI_CONF_FUNCTION(PCI_FUNC(fn)) |
196-
PCI_CONF_WHERE(config) |
197-
PCI_CONF_ENABLE,
186+
writel(PCI_CONF1_ADDRESS(bus_number, PCI_SLOT(fn),
187+
PCI_FUNC(fn), config),
198188
p->base + FTPCI_CONFIG);
199189

200190
*value = readl(p->base + FTPCI_DATA);
@@ -225,11 +215,8 @@ static int faraday_raw_pci_write_config(struct faraday_pci *p, int bus_number,
225215
{
226216
int ret = PCIBIOS_SUCCESSFUL;
227217

228-
writel(PCI_CONF_BUS(bus_number) |
229-
PCI_CONF_DEVICE(PCI_SLOT(fn)) |
230-
PCI_CONF_FUNCTION(PCI_FUNC(fn)) |
231-
PCI_CONF_WHERE(config) |
232-
PCI_CONF_ENABLE,
218+
writel(PCI_CONF1_ADDRESS(bus_number, PCI_SLOT(fn),
219+
PCI_FUNC(fn), config),
233220
p->base + FTPCI_CONFIG);
234221

235222
switch (size) {

drivers/pci/controller/pci-tegra.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,6 @@ static inline u32 pads_readl(struct tegra_pcie *pcie, unsigned long offset)
415415
* address (access to which generates correct config transaction) falls in
416416
* this 4 KiB region.
417417
*/
418-
static unsigned int tegra_pcie_conf_offset(u8 bus, unsigned int devfn,
419-
unsigned int where)
420-
{
421-
return ((where & 0xf00) << 16) | (bus << 16) | (PCI_SLOT(devfn) << 11) |
422-
(PCI_FUNC(devfn) << 8) | (where & 0xff);
423-
}
424-
425418
static void __iomem *tegra_pcie_map_bus(struct pci_bus *bus,
426419
unsigned int devfn,
427420
int where)
@@ -443,7 +436,9 @@ static void __iomem *tegra_pcie_map_bus(struct pci_bus *bus,
443436
unsigned int offset;
444437
u32 base;
445438

446-
offset = tegra_pcie_conf_offset(bus->number, devfn, where);
439+
offset = PCI_CONF1_EXT_ADDRESS(bus->number, PCI_SLOT(devfn),
440+
PCI_FUNC(devfn), where) &
441+
~PCI_CONF1_ENABLE;
447442

448443
/* move 4 KiB window to offset within the FPCI region */
449444
base = 0xfe100000 + ((offset & ~(SZ_4K - 1)) >> 8);

drivers/pci/controller/pcie-mt7621.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <linux/reset.h>
3131
#include <linux/sys_soc.h>
3232

33+
#include "../pci.h"
34+
3335
/* MediaTek-specific configuration registers */
3436
#define PCIE_FTS_NUM 0x70c
3537
#define PCIE_FTS_NUM_MASK GENMASK(15, 8)
@@ -120,19 +122,12 @@ static inline void pcie_port_write(struct mt7621_pcie_port *port,
120122
writel_relaxed(val, port->base + reg);
121123
}
122124

123-
static inline u32 mt7621_pcie_get_cfgaddr(unsigned int bus, unsigned int slot,
124-
unsigned int func, unsigned int where)
125-
{
126-
return (((where & 0xf00) >> 8) << 24) | (bus << 16) | (slot << 11) |
127-
(func << 8) | (where & 0xfc) | 0x80000000;
128-
}
129-
130125
static void __iomem *mt7621_pcie_map_bus(struct pci_bus *bus,
131126
unsigned int devfn, int where)
132127
{
133128
struct mt7621_pcie *pcie = bus->sysdata;
134-
u32 address = mt7621_pcie_get_cfgaddr(bus->number, PCI_SLOT(devfn),
135-
PCI_FUNC(devfn), where);
129+
u32 address = PCI_CONF1_EXT_ADDRESS(bus->number, PCI_SLOT(devfn),
130+
PCI_FUNC(devfn), where);
136131

137132
writel_relaxed(address, pcie->base + RALINK_PCI_CONFIG_ADDR);
138133

@@ -147,7 +142,7 @@ static struct pci_ops mt7621_pcie_ops = {
147142

148143
static u32 read_config(struct mt7621_pcie *pcie, unsigned int dev, u32 reg)
149144
{
150-
u32 address = mt7621_pcie_get_cfgaddr(0, dev, 0, reg);
145+
u32 address = PCI_CONF1_EXT_ADDRESS(0, dev, 0, reg);
151146

152147
pcie_write(pcie, address, RALINK_PCI_CONFIG_ADDR);
153148
return pcie_read(pcie, RALINK_PCI_CONFIG_DATA);
@@ -156,7 +151,7 @@ static u32 read_config(struct mt7621_pcie *pcie, unsigned int dev, u32 reg)
156151
static void write_config(struct mt7621_pcie *pcie, unsigned int dev,
157152
u32 reg, u32 val)
158153
{
159-
u32 address = mt7621_pcie_get_cfgaddr(0, dev, 0, reg);
154+
u32 address = PCI_CONF1_EXT_ADDRESS(0, dev, 0, reg);
160155

161156
pcie_write(pcie, address, RALINK_PCI_CONFIG_ADDR);
162157
pcie_write(pcie, val, RALINK_PCI_CONFIG_DATA);

drivers/pci/pci.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,4 +776,49 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
776776
}
777777
#endif
778778

779+
/*
780+
* Config Address for PCI Configuration Mechanism #1
781+
*
782+
* See PCI Local Bus Specification, Revision 3.0,
783+
* Section 3.2.2.3.2, Figure 3-2, p. 50.
784+
*/
785+
786+
#define PCI_CONF1_BUS_SHIFT 16 /* Bus number */
787+
#define PCI_CONF1_DEV_SHIFT 11 /* Device number */
788+
#define PCI_CONF1_FUNC_SHIFT 8 /* Function number */
789+
790+
#define PCI_CONF1_BUS_MASK 0xff
791+
#define PCI_CONF1_DEV_MASK 0x1f
792+
#define PCI_CONF1_FUNC_MASK 0x7
793+
#define PCI_CONF1_REG_MASK 0xfc /* Limit aligned offset to a maximum of 256B */
794+
795+
#define PCI_CONF1_ENABLE BIT(31)
796+
#define PCI_CONF1_BUS(x) (((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT)
797+
#define PCI_CONF1_DEV(x) (((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT)
798+
#define PCI_CONF1_FUNC(x) (((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT)
799+
#define PCI_CONF1_REG(x) ((x) & PCI_CONF1_REG_MASK)
800+
801+
#define PCI_CONF1_ADDRESS(bus, dev, func, reg) \
802+
(PCI_CONF1_ENABLE | \
803+
PCI_CONF1_BUS(bus) | \
804+
PCI_CONF1_DEV(dev) | \
805+
PCI_CONF1_FUNC(func) | \
806+
PCI_CONF1_REG(reg))
807+
808+
/*
809+
* Extension of PCI Config Address for accessing extended PCIe registers
810+
*
811+
* No standardized specification, but used on lot of non-ECAM-compliant ARM SoCs
812+
* or on AMD Barcelona and new CPUs. Reserved bits [27:24] of PCI Config Address
813+
* are used for specifying additional 4 high bits of PCI Express register.
814+
*/
815+
816+
#define PCI_CONF1_EXT_REG_SHIFT 16
817+
#define PCI_CONF1_EXT_REG_MASK 0xf00
818+
#define PCI_CONF1_EXT_REG(x) (((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT)
819+
820+
#define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \
821+
(PCI_CONF1_ADDRESS(bus, dev, func, reg) | \
822+
PCI_CONF1_EXT_REG(reg))
823+
779824
#endif /* DRIVERS_PCI_H */

0 commit comments

Comments
 (0)