1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/kernel.h>
24#include <linux/pci.h>
25#include <linux/slab.h>
26#include <linux/ioport.h>
27#include <linux/interrupt.h>
28#include <linux/spinlock.h>
29#include <linux/init.h>
30#include <linux/io.h>
31
32#include <mach/hardware.h>
33#include <asm/irq.h>
34#include <asm/system.h>
35#include <asm/mach/pci.h>
36#include <asm/irq_regs.h>
37
38#include <asm/hardware/pci_v3.h>
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104#define v3_writeb(o,v) __raw_writeb(v, PCI_V3_VADDR + (unsigned int)(o))
105#define v3_readb(o) (__raw_readb(PCI_V3_VADDR + (unsigned int)(o)))
106
107#define v3_writew(o,v) __raw_writew(v, PCI_V3_VADDR + (unsigned int)(o))
108#define v3_readw(o) (__raw_readw(PCI_V3_VADDR + (unsigned int)(o)))
109
110#define v3_writel(o,v) __raw_writel(v, PCI_V3_VADDR + (unsigned int)(o))
111#define v3_readl(o) (__raw_readl(PCI_V3_VADDR + (unsigned int)(o)))
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165static DEFINE_SPINLOCK(v3_lock);
166
167#define PCI_BUS_NONMEM_START 0x00000000
168#define PCI_BUS_NONMEM_SIZE SZ_256M
169
170#define PCI_BUS_PREMEM_START PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE
171#define PCI_BUS_PREMEM_SIZE SZ_256M
172
173#if PCI_BUS_NONMEM_START & 0x000fffff
174#error PCI_BUS_NONMEM_START must be megabyte aligned
175#endif
176#if PCI_BUS_PREMEM_START & 0x000fffff
177#error PCI_BUS_PREMEM_START must be megabyte aligned
178#endif
179
180#undef V3_LB_BASE_PREFETCH
181#define V3_LB_BASE_PREFETCH 0
182
183static unsigned long v3_open_config_window(struct pci_bus *bus,
184 unsigned int devfn, int offset)
185{
186 unsigned int address, mapaddress, busnr;
187
188 busnr = bus->number;
189
190
191
192
193 if (offset > 255)
194 BUG();
195 if (busnr > 255)
196 BUG();
197 if (devfn > 255)
198 BUG();
199
200 if (busnr == 0) {
201 int slot = PCI_SLOT(devfn);
202
203
204
205
206
207
208
209
210
211
212
213 address = PCI_FUNC(devfn) << 8;
214 mapaddress = V3_LB_MAP_TYPE_CONFIG;
215
216 if (slot > 12)
217
218
219
220 mapaddress |= 1 << (slot - 5);
221 else
222
223
224
225 address |= 1 << (slot + 11);
226 } else {
227
228
229
230
231
232
233
234
235
236
237
238
239 mapaddress = V3_LB_MAP_TYPE_CONFIG | V3_LB_MAP_AD_LOW_EN;
240 address = (busnr << 16) | (devfn << 8);
241 }
242
243
244
245
246
247
248 v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
249 V3_LB_BASE_ADR_SIZE_512MB | V3_LB_BASE_ENABLE);
250
251
252
253
254 v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_CONFIG_BASE) |
255 V3_LB_BASE_ADR_SIZE_16MB | V3_LB_BASE_ENABLE);
256 v3_writew(V3_LB_MAP1, mapaddress);
257
258 return PCI_CONFIG_VADDR + address + offset;
259}
260
261static void v3_close_config_window(void)
262{
263
264
265
266 v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
267 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
268 V3_LB_BASE_ENABLE);
269 v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
270 V3_LB_MAP_TYPE_MEM_MULTIPLE);
271
272
273
274
275 v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
276 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
277}
278
279static int v3_read_config(struct pci_bus *bus, unsigned int devfn, int where,
280 int size, u32 *val)
281{
282 unsigned long addr;
283 unsigned long flags;
284 u32 v;
285
286 spin_lock_irqsave(&v3_lock, flags);
287 addr = v3_open_config_window(bus, devfn, where);
288
289 switch (size) {
290 case 1:
291 v = __raw_readb(addr);
292 break;
293
294 case 2:
295 v = __raw_readw(addr);
296 break;
297
298 default:
299 v = __raw_readl(addr);
300 break;
301 }
302
303 v3_close_config_window();
304 spin_unlock_irqrestore(&v3_lock, flags);
305
306 *val = v;
307 return PCIBIOS_SUCCESSFUL;
308}
309
310static int v3_write_config(struct pci_bus *bus, unsigned int devfn, int where,
311 int size, u32 val)
312{
313 unsigned long addr;
314 unsigned long flags;
315
316 spin_lock_irqsave(&v3_lock, flags);
317 addr = v3_open_config_window(bus, devfn, where);
318
319 switch (size) {
320 case 1:
321 __raw_writeb((u8)val, addr);
322 __raw_readb(addr);
323 break;
324
325 case 2:
326 __raw_writew((u16)val, addr);
327 __raw_readw(addr);
328 break;
329
330 case 4:
331 __raw_writel(val, addr);
332 __raw_readl(addr);
333 break;
334 }
335
336 v3_close_config_window();
337 spin_unlock_irqrestore(&v3_lock, flags);
338
339 return PCIBIOS_SUCCESSFUL;
340}
341
342static struct pci_ops pci_v3_ops = {
343 .read = v3_read_config,
344 .write = v3_write_config,
345};
346
347static struct resource non_mem = {
348 .name = "PCI non-prefetchable",
349 .start = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START,
350 .end = PHYS_PCI_MEM_BASE + PCI_BUS_NONMEM_START + PCI_BUS_NONMEM_SIZE - 1,
351 .flags = IORESOURCE_MEM,
352};
353
354static struct resource pre_mem = {
355 .name = "PCI prefetchable",
356 .start = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START,
357 .end = PHYS_PCI_MEM_BASE + PCI_BUS_PREMEM_START + PCI_BUS_PREMEM_SIZE - 1,
358 .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH,
359};
360
361static int __init pci_v3_setup_resources(struct resource **resource)
362{
363 if (request_resource(&iomem_resource, &non_mem)) {
364 printk(KERN_ERR "PCI: unable to allocate non-prefetchable "
365 "memory region\n");
366 return -EBUSY;
367 }
368 if (request_resource(&iomem_resource, &pre_mem)) {
369 release_resource(&non_mem);
370 printk(KERN_ERR "PCI: unable to allocate prefetchable "
371 "memory region\n");
372 return -EBUSY;
373 }
374
375
376
377
378
379
380 resource[0] = &ioport_resource;
381 resource[1] = &non_mem;
382 resource[2] = &pre_mem;
383
384 return 1;
385}
386
387
388
389
390
391
392#define SC_PCI (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_PCIENABLE_OFFSET)
393#define SC_LBFADDR (IO_ADDRESS(INTEGRATOR_SC_BASE) + 0x20)
394#define SC_LBFCODE (IO_ADDRESS(INTEGRATOR_SC_BASE) + 0x24)
395
396static int
397v3_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
398{
399 unsigned long pc = instruction_pointer(regs);
400 unsigned long instr = *(unsigned long *)pc;
401#if 0
402 char buf[128];
403
404 sprintf(buf, "V3 fault: addr 0x%08lx, FSR 0x%03x, PC 0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x ISTAT=%02x\n",
405 addr, fsr, pc, instr, __raw_readl(SC_LBFADDR), __raw_readl(SC_LBFCODE) & 255,
406 v3_readb(V3_LB_ISTAT));
407 printk(KERN_DEBUG "%s", buf);
408#endif
409
410 v3_writeb(V3_LB_ISTAT, 0);
411 __raw_writel(3, SC_PCI);
412
413
414
415
416
417 if ((instr & 0x0c100000) == 0x04100000) {
418 int reg = (instr >> 12) & 15;
419 unsigned long val;
420
421 if (instr & 0x00400000)
422 val = 255;
423 else
424 val = -1;
425
426 regs->uregs[reg] = val;
427 regs->ARM_pc += 4;
428 return 0;
429 }
430
431 if ((instr & 0x0e100090) == 0x00100090) {
432 int reg = (instr >> 12) & 15;
433
434 regs->uregs[reg] = -1;
435 regs->ARM_pc += 4;
436 return 0;
437 }
438
439 return 1;
440}
441
442static irqreturn_t v3_irq(int dummy, void *devid)
443{
444#ifdef CONFIG_DEBUG_LL
445 struct pt_regs *regs = get_irq_regs();
446 unsigned long pc = instruction_pointer(regs);
447 unsigned long instr = *(unsigned long *)pc;
448 char buf[128];
449 extern void printascii(const char *);
450
451 sprintf(buf, "V3 int %d: pc=0x%08lx [%08lx] LBFADDR=%08x LBFCODE=%02x "
452 "ISTAT=%02x\n", IRQ_AP_V3INT, pc, instr,
453 __raw_readl(SC_LBFADDR),
454 __raw_readl(SC_LBFCODE) & 255,
455 v3_readb(V3_LB_ISTAT));
456 printascii(buf);
457#endif
458
459 v3_writew(V3_PCI_STAT, 0xf000);
460 v3_writeb(V3_LB_ISTAT, 0);
461 __raw_writel(3, SC_PCI);
462
463#ifdef CONFIG_DEBUG_LL
464
465
466
467
468 if ((instr & 0x0c100000) == 0x04100000) {
469 int reg = (instr >> 16) & 15;
470 sprintf(buf, " reg%d = %08lx\n", reg, regs->uregs[reg]);
471 printascii(buf);
472 }
473#endif
474 return IRQ_HANDLED;
475}
476
477int __init pci_v3_setup(int nr, struct pci_sys_data *sys)
478{
479 int ret = 0;
480
481 if (nr == 0) {
482 sys->mem_offset = PHYS_PCI_MEM_BASE;
483 ret = pci_v3_setup_resources(sys->resource);
484 }
485
486 return ret;
487}
488
489struct pci_bus *pci_v3_scan_bus(int nr, struct pci_sys_data *sys)
490{
491 return pci_scan_bus(sys->busnr, &pci_v3_ops, sys);
492}
493
494
495
496
497
498void __init pci_v3_preinit(void)
499{
500 unsigned long flags;
501 unsigned int temp;
502 int ret;
503
504
505
506
507 hook_fault_code(4, v3_pci_fault, SIGBUS, "external abort on linefetch");
508 hook_fault_code(6, v3_pci_fault, SIGBUS, "external abort on linefetch");
509 hook_fault_code(8, v3_pci_fault, SIGBUS, "external abort on non-linefetch");
510 hook_fault_code(10, v3_pci_fault, SIGBUS, "external abort on non-linefetch");
511
512 spin_lock_irqsave(&v3_lock, flags);
513
514
515
516
517 if (v3_readw(V3_SYSTEM) & V3_SYSTEM_M_LOCK)
518 v3_writew(V3_SYSTEM, 0xa05f);
519
520
521
522
523
524 v3_writel(V3_LB_BASE0, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE) |
525 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_ENABLE);
526 v3_writew(V3_LB_MAP0, v3_addr_to_lb_map(PCI_BUS_NONMEM_START) |
527 V3_LB_MAP_TYPE_MEM);
528
529
530
531
532
533 v3_writel(V3_LB_BASE1, v3_addr_to_lb_base(PHYS_PCI_MEM_BASE + SZ_256M) |
534 V3_LB_BASE_ADR_SIZE_256MB | V3_LB_BASE_PREFETCH |
535 V3_LB_BASE_ENABLE);
536 v3_writew(V3_LB_MAP1, v3_addr_to_lb_map(PCI_BUS_PREMEM_START) |
537 V3_LB_MAP_TYPE_MEM_MULTIPLE);
538
539
540
541
542 v3_writel(V3_LB_BASE2, v3_addr_to_lb_base2(PHYS_PCI_IO_BASE) |
543 V3_LB_BASE_ENABLE);
544 v3_writew(V3_LB_MAP2, v3_addr_to_lb_map2(0));
545
546
547
548
549 temp = v3_readw(V3_PCI_CFG) & ~V3_PCI_CFG_M_I2O_EN;
550 temp |= V3_PCI_CFG_M_IO_REG_DIS | V3_PCI_CFG_M_IO_DIS;
551 v3_writew(V3_PCI_CFG, temp);
552
553 printk(KERN_DEBUG "FIFO_CFG: %04x FIFO_PRIO: %04x\n",
554 v3_readw(V3_FIFO_CFG), v3_readw(V3_FIFO_PRIORITY));
555
556
557
558
559
560
561 v3_writew(V3_FIFO_PRIORITY, 0x0a0a);
562
563
564
565
566 temp = v3_readw(V3_SYSTEM) | V3_SYSTEM_M_LOCK;
567 v3_writew(V3_SYSTEM, temp);
568
569
570
571
572 v3_writeb(V3_LB_ISTAT, 0);
573 v3_writew(V3_LB_CFG, v3_readw(V3_LB_CFG) | (1 << 10));
574 v3_writeb(V3_LB_IMASK, 0x28);
575 __raw_writel(3, SC_PCI);
576
577
578
579
580 ret = request_irq(IRQ_AP_V3INT, v3_irq, 0, "V3", NULL);
581 if (ret)
582 printk(KERN_ERR "PCI: unable to grab PCI error "
583 "interrupt: %d\n", ret);
584
585 spin_unlock_irqrestore(&v3_lock, flags);
586}
587
588void __init pci_v3_postinit(void)
589{
590 unsigned int pci_cmd;
591
592 pci_cmd = PCI_COMMAND_MEMORY |
593 PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE;
594
595 v3_writew(V3_PCI_CMD, pci_cmd);
596
597 v3_writeb(V3_LB_ISTAT, ~0x40);
598 v3_writeb(V3_LB_IMASK, 0x68);
599
600#if 0
601 ret = request_irq(IRQ_AP_LBUSTIMEOUT, lb_timeout, 0, "bus timeout", NULL);
602 if (ret)
603 printk(KERN_ERR "PCI: unable to grab local bus timeout "
604 "interrupt: %d\n", ret);
605#endif
606
607 register_isa_ports(PHYS_PCI_MEM_BASE, PHYS_PCI_IO_BASE, 0);
608}
609