9 #include <linux/kernel.h>
10 #include <linux/pci.h>
12 #include <linux/export.h>
16 #include <asm/sections.h>
62 #undef GRPCI2_DEBUG_CFGACCESS
90 #define REGLOAD(a) (be32_to_cpu(__raw_readl(&(a))))
91 #define REGSTORE(a, v) (__raw_writel(cpu_to_be32(v), &(a)))
93 #define CTRL_BUS_BIT 16
95 #define CTRL_RESET (1<<31)
96 #define CTRL_SI (1<<27)
97 #define CTRL_PE (1<<26)
98 #define CTRL_EI (1<<25)
99 #define CTRL_ER (1<<24)
100 #define CTRL_BUS (0xff<<CTRL_BUS_BIT)
101 #define CTRL_HOSTINT 0xf
103 #define STS_HOST_BIT 31
104 #define STS_MST_BIT 30
105 #define STS_TAR_BIT 29
106 #define STS_DMA_BIT 28
107 #define STS_DI_BIT 27
108 #define STS_HI_BIT 26
109 #define STS_IRQMODE_BIT 24
110 #define STS_TRACE_BIT 23
111 #define STS_CFGERRVALID_BIT 20
112 #define STS_CFGERR_BIT 19
113 #define STS_INTTYPE_BIT 12
114 #define STS_INTSTS_BIT 8
115 #define STS_FDEPTH_BIT 2
116 #define STS_FNUM_BIT 0
118 #define STS_HOST (1<<STS_HOST_BIT)
119 #define STS_MST (1<<STS_MST_BIT)
120 #define STS_TAR (1<<STS_TAR_BIT)
121 #define STS_DMA (1<<STS_DMA_BIT)
122 #define STS_DI (1<<STS_DI_BIT)
123 #define STS_HI (1<<STS_HI_BIT)
124 #define STS_IRQMODE (0x3<<STS_IRQMODE_BIT)
125 #define STS_TRACE (1<<STS_TRACE_BIT)
126 #define STS_CFGERRVALID (1<<STS_CFGERRVALID_BIT)
127 #define STS_CFGERR (1<<STS_CFGERR_BIT)
128 #define STS_INTTYPE (0x3f<<STS_INTTYPE_BIT)
129 #define STS_INTSTS (0xf<<STS_INTSTS_BIT)
130 #define STS_FDEPTH (0x7<<STS_FDEPTH_BIT)
131 #define STS_FNUM (0x3<<STS_FNUM_BIT)
133 #define STS_ISYSERR (1<<17)
134 #define STS_IDMA (1<<16)
135 #define STS_IDMAERR (1<<15)
136 #define STS_IMSTABRT (1<<14)
137 #define STS_ITGTABRT (1<<13)
138 #define STS_IPARERR (1<<12)
140 #define STS_ERR_IRQ (STS_ISYSERR | STS_IMSTABRT | STS_ITGTABRT | STS_IPARERR)
149 #define BD_CHAN_EN 0x80000000
150 #define BD_CHAN_TYPE 0x00300000
151 #define BD_CHAN_BDCNT 0x0000ffff
152 #define BD_CHAN_EN_BIT 31
153 #define BD_CHAN_TYPE_BIT 20
154 #define BD_CHAN_BDCNT_BIT 0
163 #define BD_DATA_EN 0x80000000
164 #define BD_DATA_IE 0x40000000
165 #define BD_DATA_DR 0x20000000
166 #define BD_DATA_TYPE 0x00300000
167 #define BD_DATA_ER 0x00080000
168 #define BD_DATA_LEN 0x0000ffff
169 #define BD_DATA_EN_BIT 31
170 #define BD_DATA_IE_BIT 30
171 #define BD_DATA_DR_BIT 29
172 #define BD_DATA_TYPE_BIT 20
173 #define BD_DATA_ER_BIT 19
174 #define BD_DATA_LEN_BIT 0
184 #define CAP9_CTRL_OFS 0
185 #define CAP9_BAR_OFS 0x4
186 #define CAP9_IOMAP_OFS 0x20
187 #define CAP9_BARSIZE_OFS 0x24
224 irq_group = slot & 0x3;
225 pin = ((pin - 1) + irq_group) & 0x3;
240 if (bus == 0 &&
PCI_SLOT(devfn) != 0)
247 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
252 pci_conf = (
unsigned int *) (priv->
pci_conf |
253 (devfn << 8) | (where & 0xfc));
266 *val = flip_dword(tmp);
272 static int grpci2_cfg_r16(
struct grpci2_priv *priv,
unsigned int bus,
273 unsigned int devfn,
int where,
u32 *val)
280 ret = grpci2_cfg_r32(priv, bus, devfn, where & ~0x3, &v);
281 *val = 0xffff & (v >> (8 * (where & 0x3)));
285 static int grpci2_cfg_r8(
struct grpci2_priv *priv,
unsigned int bus,
286 unsigned int devfn,
int where,
u32 *val)
291 ret = grpci2_cfg_r32(priv, bus, devfn, where & ~0x3, &v);
292 *val = 0xff & (v >> (8 * (where & 3)));
297 static int grpci2_cfg_w32(
struct grpci2_priv *priv,
unsigned int bus,
298 unsigned int devfn,
int where,
u32 val)
306 if (bus == 0 &&
PCI_SLOT(devfn) != 0)
313 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
318 pci_conf = (
unsigned int *) (priv->
pci_conf |
319 (devfn << 8) | (where & 0xfc));
331 static int grpci2_cfg_w16(
struct grpci2_priv *priv,
unsigned int bus,
332 unsigned int devfn,
int where,
u32 val)
339 ret = grpci2_cfg_r32(priv, bus, devfn, where&~3, &v);
342 v = (v & ~(0xffff << (8 * (where & 0x3)))) |
343 ((0xffff &
val) << (8 * (where & 0x3)));
344 return grpci2_cfg_w32(priv, bus, devfn, where & ~0x3, v);
347 static int grpci2_cfg_w8(
struct grpci2_priv *priv,
unsigned int bus,
348 unsigned int devfn,
int where,
u32 val)
353 ret = grpci2_cfg_r32(priv, bus, devfn, where & ~0x3, &v);
356 v = (v & ~(0xff << (8 * (where & 0x3)))) |
357 ((0xff &
val) << (8 * (where & 0x3)));
358 return grpci2_cfg_w32(priv, bus, devfn, where & ~0x3, v);
364 static int grpci2_read_config(
struct pci_bus *bus,
unsigned int devfn,
368 unsigned int busno = bus->
number;
378 ret = grpci2_cfg_r8(priv, busno, devfn, where, val);
381 ret = grpci2_cfg_r16(priv, busno, devfn, where, val);
384 ret = grpci2_cfg_r32(priv, busno, devfn, where, val);
391 #ifdef GRPCI2_DEBUG_CFGACCESS
403 static int grpci2_write_config(
struct pci_bus *bus,
unsigned int devfn,
404 int where,
int size,
u32 val)
407 unsigned int busno = bus->
number;
412 #ifdef GRPCI2_DEBUG_CFGACCESS
422 return grpci2_cfg_w8(priv, busno, devfn, where, val);
424 return grpci2_cfg_w16(priv, busno, devfn, where, val);
426 return grpci2_cfg_w32(priv, busno, devfn, where, val);
430 static struct pci_ops grpci2_ops = {
431 .read = grpci2_read_config,
432 .write = grpci2_write_config,
452 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
455 static void grpci2_unmask_irq(
struct irq_data *data)
467 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
470 static unsigned int grpci2_startup_irq(
struct irq_data *data)
472 grpci2_unmask_irq(data);
476 static void grpci2_shutdown_irq(
struct irq_data *data)
478 grpci2_mask_irq(data);
481 static struct irq_chip grpci2_irq = {
483 .irq_startup = grpci2_startup_irq,
484 .irq_shutdown = grpci2_shutdown_irq,
485 .irq_mask = grpci2_mask_irq,
486 .irq_unmask = grpci2_unmask_irq,
490 static void grpci2_pci_flow_irq(
unsigned int irq,
struct irq_desc *
desc)
494 unsigned int ctrl, sts_cap, pci_ints;
509 for (i = 0; i < 4; i++) {
510 if (pci_ints & (1 << i))
536 static unsigned int grpci2_build_device_irq(
unsigned int irq)
538 unsigned int virq = 0, pil;
555 u32 ahbadr, pciadr, bar_sz, capptr, io_map,
data;
577 for (i = 0; i < 16; i++)
588 io_map = (io_map & ~0x1) | (priv->
bt_enabled ? 1 : 0);
601 for (i = 0; i < 6; i++) {
602 if (barcfg[i].pciadr != ~0 && barcfg[i].ahbadr != ~0) {
606 bar_sz = ((pciadr - 1) & ~pciadr) + 1;
612 (
unsigned long) &
_end));
622 grpci2_cfg_w32(priv, 0, 0, capptr+
CAP9_BAR_OFS+i*4, ahbadr);
650 if ((status & STS_ERR_IRQ) == 0)
692 "grlib-grpci2 regs");
710 if (grpci2priv ==
NULL) {
714 memset(grpci2priv, 0,
sizeof(*grpci2priv));
726 if (tmp && (len == 2*4*6))
733 if (tmp && (len == 4))
740 if (tmp && (len == 4))
758 "GRPCI2: MEMORY SPACE [0x%08lx - 0x%08lx]\n"
759 " I/O SPACE [0x%08lx - 0x%08lx]\n"
760 " CONFIG SPACE [0x%08lx - 0x%08lx]\n",
771 priv->
info.io_space.name =
"GRPCI2 PCI I/O Space";
781 priv->
info.mem_space.name =
"GRPCI2 PCI MEM Space";
802 priv->
irq_map[0] = grpci2_build_device_irq(1);
803 priv->
irq_map[1] = grpci2_build_device_irq(2);
804 priv->
irq_map[2] = grpci2_build_device_irq(3);
805 priv->
irq_map[3] = grpci2_build_device_irq(4);
807 priv->
virq_err = grpci2_build_device_irq(5);
811 priv->
virq_dma = grpci2_build_device_irq(6);
815 "GRPCI2_JUMP", priv);
820 for (i = 0; i < 4; i++) {
852 priv->
info.ops = &grpci2_ops;
869 resource_size(&ofdev->
resource[0]));
875 .name =
"GAISLER_GRPCI2",
887 .of_match_table = grpci2_of_match,
889 .probe = grpci2_of_probe,
892 static int __init grpci2_init(
void)