2 * linux/arch/alpha/kernel/sys_dp264.c
4 * Copyright (C) 1995 David A Rusling
5 * Copyright (C) 1996, 1999 Jay A Estabrook
6 * Copyright (C) 1998, 1999 Richard Henderson
8 * Modified by Christopher C. Chimelis, 2001 to
9 * add support for the addition of Shark to the
12 * Code supporting the DP264 (EV6+TSUNAMI).
15 #include <linux/config.h>
16 #include <linux/kernel.h>
17 #include <linux/types.h>
19 #include <linux/sched.h>
20 #include <linux/pci.h>
21 #include <linux/init.h>
23 #include <asm/ptrace.h>
24 #include <asm/system.h>
27 #include <asm/bitops.h>
28 #include <asm/mmu_context.h>
30 #include <asm/pgtable.h>
31 #include <asm/core_tsunami.h>
32 #include <asm/hwrpb.h>
33 #include <asm/tlbflush.h>
38 #include "machvec_impl.h"
41 /* Note mask bit is true for ENABLED irqs. */
42 static unsigned long cached_irq_mask;
43 /* dp264 boards handle at max four CPUs */
44 static unsigned long cpu_irq_affinity[4] = { 0UL, 0UL, 0UL, 0UL };
46 spinlock_t dp264_irq_lock = SPIN_LOCK_UNLOCKED;
49 tsunami_update_irq_hw(unsigned long mask)
51 register tsunami_cchip *cchip = TSUNAMI_cchip;
52 unsigned long isa_enable = 1UL << 55;
53 register int bcpu = boot_cpuid;
56 register unsigned long cpm = cpu_present_mask;
57 volatile unsigned long *dim0, *dim1, *dim2, *dim3;
58 unsigned long mask0, mask1, mask2, mask3, dummy;
61 mask0 = mask & cpu_irq_affinity[0];
62 mask1 = mask & cpu_irq_affinity[1];
63 mask2 = mask & cpu_irq_affinity[2];
64 mask3 = mask & cpu_irq_affinity[3];
66 if (bcpu == 0) mask0 |= isa_enable;
67 else if (bcpu == 1) mask1 |= isa_enable;
68 else if (bcpu == 2) mask2 |= isa_enable;
69 else mask3 |= isa_enable;
71 dim0 = &cchip->dim0.csr;
72 dim1 = &cchip->dim1.csr;
73 dim2 = &cchip->dim2.csr;
74 dim3 = &cchip->dim3.csr;
75 if ((cpm & 1) == 0) dim0 = &dummy;
76 if ((cpm & 2) == 0) dim1 = &dummy;
77 if ((cpm & 4) == 0) dim2 = &dummy;
78 if ((cpm & 8) == 0) dim3 = &dummy;
90 volatile unsigned long *dimB;
91 if (bcpu == 0) dimB = &cchip->dim0.csr;
92 else if (bcpu == 1) dimB = &cchip->dim1.csr;
93 else if (bcpu == 2) dimB = &cchip->dim2.csr;
94 else dimB = &cchip->dim3.csr;
96 *dimB = mask | isa_enable;
103 dp264_enable_irq(unsigned int irq)
105 spin_lock(&dp264_irq_lock);
106 cached_irq_mask |= 1UL << irq;
107 tsunami_update_irq_hw(cached_irq_mask);
108 spin_unlock(&dp264_irq_lock);
112 dp264_disable_irq(unsigned int irq)
114 spin_lock(&dp264_irq_lock);
115 cached_irq_mask &= ~(1UL << irq);
116 tsunami_update_irq_hw(cached_irq_mask);
117 spin_unlock(&dp264_irq_lock);
121 dp264_startup_irq(unsigned int irq)
123 dp264_enable_irq(irq);
124 return 0; /* never anything pending */
128 dp264_end_irq(unsigned int irq)
130 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
131 dp264_enable_irq(irq);
135 clipper_enable_irq(unsigned int irq)
137 spin_lock(&dp264_irq_lock);
138 cached_irq_mask |= 1UL << (irq - 16);
139 tsunami_update_irq_hw(cached_irq_mask);
140 spin_unlock(&dp264_irq_lock);
144 clipper_disable_irq(unsigned int irq)
146 spin_lock(&dp264_irq_lock);
147 cached_irq_mask &= ~(1UL << (irq - 16));
148 tsunami_update_irq_hw(cached_irq_mask);
149 spin_unlock(&dp264_irq_lock);
153 clipper_startup_irq(unsigned int irq)
155 clipper_enable_irq(irq);
156 return 0; /* never anything pending */
160 clipper_end_irq(unsigned int irq)
162 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
163 clipper_enable_irq(irq);
167 cpu_set_irq_affinity(unsigned int irq, unsigned long affinity)
171 for (cpu = 0; cpu < 4; cpu++) {
172 unsigned long aff = cpu_irq_affinity[cpu];
173 if (affinity & (1UL << cpu))
176 aff &= ~(1UL << irq);
177 cpu_irq_affinity[cpu] = aff;
182 dp264_set_affinity(unsigned int irq, unsigned long affinity)
184 spin_lock(&dp264_irq_lock);
185 cpu_set_irq_affinity(irq, affinity);
186 tsunami_update_irq_hw(cached_irq_mask);
187 spin_unlock(&dp264_irq_lock);
191 clipper_set_affinity(unsigned int irq, unsigned long affinity)
193 spin_lock(&dp264_irq_lock);
194 cpu_set_irq_affinity(irq - 16, affinity);
195 tsunami_update_irq_hw(cached_irq_mask);
196 spin_unlock(&dp264_irq_lock);
199 static struct hw_interrupt_type dp264_irq_type = {
201 .startup = dp264_startup_irq,
202 .shutdown = dp264_disable_irq,
203 .enable = dp264_enable_irq,
204 .disable = dp264_disable_irq,
205 .ack = dp264_disable_irq,
206 .end = dp264_end_irq,
207 .set_affinity = dp264_set_affinity,
210 static struct hw_interrupt_type clipper_irq_type = {
211 .typename = "CLIPPER",
212 .startup = clipper_startup_irq,
213 .shutdown = clipper_disable_irq,
214 .enable = clipper_enable_irq,
215 .disable = clipper_disable_irq,
216 .ack = clipper_disable_irq,
217 .end = clipper_end_irq,
218 .set_affinity = clipper_set_affinity,
222 dp264_device_interrupt(unsigned long vector, struct pt_regs * regs)
225 printk("dp264_device_interrupt: NOT IMPLEMENTED YET!! \n");
230 /* Read the interrupt summary register of TSUNAMI */
231 pld = TSUNAMI_cchip->dir0.csr;
234 * Now for every possible bit set, work through them and call
235 * the appropriate interrupt handler.
239 pld &= pld - 1; /* clear least bit set */
241 isa_device_interrupt(vector, regs);
243 handle_irq(16 + i, 16 + i, regs);
245 TSUNAMI_cchip->dir0.csr = 1UL << i; mb();
246 tmp = TSUNAMI_cchip->dir0.csr;
253 dp264_srm_device_interrupt(unsigned long vector, struct pt_regs * regs)
257 irq = (vector - 0x800) >> 4;
260 * The SRM console reports PCI interrupts with a vector calculated by:
262 * 0x900 + (0x10 * DRIR-bit)
264 * So bit 16 shows up as IRQ 32, etc.
266 * On DP264/BRICK/MONET, we adjust it down by 16 because at least
267 * that many of the low order bits of the DRIR are not used, and
268 * so we don't count them.
273 handle_irq(irq, regs);
277 clipper_srm_device_interrupt(unsigned long vector, struct pt_regs * regs)
281 irq = (vector - 0x800) >> 4;
284 * The SRM console reports PCI interrupts with a vector calculated by:
286 * 0x900 + (0x10 * DRIR-bit)
288 * So bit 16 shows up as IRQ 32, etc.
290 * CLIPPER uses bits 8-47 for PCI interrupts, so we do not need
291 * to scale down the vector reported, we just use it.
293 * Eg IRQ 24 is DRIR bit 8, etc, etc
295 handle_irq(irq, regs);
299 init_tsunami_irqs(struct hw_interrupt_type * ops, int imin, int imax)
302 for (i = imin; i <= imax; ++i) {
303 irq_desc[i].status = IRQ_DISABLED | IRQ_LEVEL;
304 irq_desc[i].handler = ops;
311 outb(0, DMA1_RESET_REG);
312 outb(0, DMA2_RESET_REG);
313 outb(DMA_MODE_CASCADE, DMA2_MODE_REG);
314 outb(0, DMA2_MASK_REG);
317 alpha_mv.device_interrupt = dp264_srm_device_interrupt;
319 tsunami_update_irq_hw(0);
322 init_tsunami_irqs(&dp264_irq_type, 16, 47);
326 clipper_init_irq(void)
328 outb(0, DMA1_RESET_REG);
329 outb(0, DMA2_RESET_REG);
330 outb(DMA_MODE_CASCADE, DMA2_MODE_REG);
331 outb(0, DMA2_MASK_REG);
334 alpha_mv.device_interrupt = clipper_srm_device_interrupt;
336 tsunami_update_irq_hw(0);
339 init_tsunami_irqs(&clipper_irq_type, 24, 63);
344 * PCI Fixup configuration.
346 * Summary @ TSUNAMI_CSR_DIM0:
349 *18 Interrupt SCSI B (Adaptec 7895 builtin)
350 *19 Interrupt SCSI A (Adaptec 7895 builtin)
351 *20 Interrupt Line D from slot 2 PCI0
352 *21 Interrupt Line C from slot 2 PCI0
353 *22 Interrupt Line B from slot 2 PCI0
354 *23 Interrupt Line A from slot 2 PCI0
355 *24 Interrupt Line D from slot 1 PCI0
356 *25 Interrupt Line C from slot 1 PCI0
357 *26 Interrupt Line B from slot 1 PCI0
358 *27 Interrupt Line A from slot 1 PCI0
359 *28 Interrupt Line D from slot 0 PCI0
360 *29 Interrupt Line C from slot 0 PCI0
361 *30 Interrupt Line B from slot 0 PCI0
362 *31 Interrupt Line A from slot 0 PCI0
364 *32 Interrupt Line D from slot 3 PCI1
365 *33 Interrupt Line C from slot 3 PCI1
366 *34 Interrupt Line B from slot 3 PCI1
367 *35 Interrupt Line A from slot 3 PCI1
368 *36 Interrupt Line D from slot 2 PCI1
369 *37 Interrupt Line C from slot 2 PCI1
370 *38 Interrupt Line B from slot 2 PCI1
371 *39 Interrupt Line A from slot 2 PCI1
372 *40 Interrupt Line D from slot 1 PCI1
373 *41 Interrupt Line C from slot 1 PCI1
374 *42 Interrupt Line B from slot 1 PCI1
375 *43 Interrupt Line A from slot 1 PCI1
376 *44 Interrupt Line D from slot 0 PCI1
377 *45 Interrupt Line C from slot 0 PCI1
378 *46 Interrupt Line B from slot 0 PCI1
379 *47 Interrupt Line A from slot 0 PCI1
381 *53 PCI0 NMI (from Cypress)
382 *54 PCI0 SMI INT (from Cypress)
383 *55 PCI0 ISA Interrupt (from Cypress)
390 * 5 Cypress Bridge I/O
391 * 6 SCSI Adaptec builtin
392 * 7 64 bit PCI option slot 0 (all busses)
393 * 8 64 bit PCI option slot 1 (all busses)
394 * 9 64 bit PCI option slot 2 (all busses)
395 * 10 64 bit PCI option slot 3 (not bus 0)
399 dp264_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
401 static char irq_tab[6][5] __initdata = {
402 /*INT INTA INTB INTC INTD */
403 { -1, -1, -1, -1, -1}, /* IdSel 5 ISA Bridge */
404 { 16+ 3, 16+ 3, 16+ 2, 16+ 2, 16+ 2}, /* IdSel 6 SCSI builtin*/
405 { 16+15, 16+15, 16+14, 16+13, 16+12}, /* IdSel 7 slot 0 */
406 { 16+11, 16+11, 16+10, 16+ 9, 16+ 8}, /* IdSel 8 slot 1 */
407 { 16+ 7, 16+ 7, 16+ 6, 16+ 5, 16+ 4}, /* IdSel 9 slot 2 */
408 { 16+ 3, 16+ 3, 16+ 2, 16+ 1, 16+ 0} /* IdSel 10 slot 3 */
410 const long min_idsel = 5, max_idsel = 10, irqs_per_slot = 5;
412 struct pci_controller *hose = dev->sysdata;
413 int irq = COMMON_TABLE_LOOKUP;
416 irq += 16 * hose->index;
418 /* ??? The Contaq IDE controller on the ISA bridge uses
419 "legacy" interrupts 14 and 15. I don't know if anything
420 can wind up at the same slot+pin on hose1, so we'll
421 just have to trust whatever value the console might
425 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq8);
433 monet_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
435 static char irq_tab[13][5] __initdata = {
436 /*INT INTA INTB INTC INTD */
437 { 45, 45, 45, 45, 45}, /* IdSel 3 21143 PCI1 */
438 { -1, -1, -1, -1, -1}, /* IdSel 4 unused */
439 { -1, -1, -1, -1, -1}, /* IdSel 5 unused */
440 { 47, 47, 47, 47, 47}, /* IdSel 6 SCSI PCI1 */
441 { -1, -1, -1, -1, -1}, /* IdSel 7 ISA Bridge */
442 { -1, -1, -1, -1, -1}, /* IdSel 8 P2P PCI1 */
444 { 28, 28, 29, 30, 31}, /* IdSel 14 slot 4 PCI2*/
445 { 24, 24, 25, 26, 27}, /* IdSel 15 slot 5 PCI2*/
447 { -1, -1, -1, -1, -1}, /* IdSel 9 unused */
448 { -1, -1, -1, -1, -1}, /* IdSel 10 unused */
450 { 40, 40, 41, 42, 43}, /* IdSel 11 slot 1 PCI0*/
451 { 36, 36, 37, 38, 39}, /* IdSel 12 slot 2 PCI0*/
452 { 32, 32, 33, 34, 35}, /* IdSel 13 slot 3 PCI0*/
453 { 28, 28, 29, 30, 31}, /* IdSel 14 slot 4 PCI2*/
454 { 24, 24, 25, 26, 27} /* IdSel 15 slot 5 PCI2*/
456 const long min_idsel = 3, max_idsel = 15, irqs_per_slot = 5;
457 return COMMON_TABLE_LOOKUP;
461 monet_swizzle(struct pci_dev *dev, u8 *pinp)
463 struct pci_controller *hose = dev->sysdata;
464 int slot, pin = *pinp;
466 if (!dev->bus->parent) {
467 slot = PCI_SLOT(dev->devfn);
469 /* Check for the built-in bridge on hose 1. */
470 else if (hose->index == 1 && PCI_SLOT(dev->bus->self->devfn) == 8) {
471 slot = PCI_SLOT(dev->devfn);
473 /* Must be a card-based bridge. */
475 /* Check for built-in bridge on hose 1. */
476 if (hose->index == 1 &&
477 PCI_SLOT(dev->bus->self->devfn) == 8) {
478 slot = PCI_SLOT(dev->devfn);
481 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn)) ;
483 /* Move up the chain of bridges. */
484 dev = dev->bus->self;
485 /* Slot of the next bridge. */
486 slot = PCI_SLOT(dev->devfn);
487 } while (dev->bus->self);
494 webbrick_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
496 static char irq_tab[13][5] __initdata = {
497 /*INT INTA INTB INTC INTD */
498 { -1, -1, -1, -1, -1}, /* IdSel 7 ISA Bridge */
499 { -1, -1, -1, -1, -1}, /* IdSel 8 unused */
500 { 29, 29, 29, 29, 29}, /* IdSel 9 21143 #1 */
501 { -1, -1, -1, -1, -1}, /* IdSel 10 unused */
502 { 30, 30, 30, 30, 30}, /* IdSel 11 21143 #2 */
503 { -1, -1, -1, -1, -1}, /* IdSel 12 unused */
504 { -1, -1, -1, -1, -1}, /* IdSel 13 unused */
505 { 35, 35, 34, 33, 32}, /* IdSel 14 slot 0 */
506 { 39, 39, 38, 37, 36}, /* IdSel 15 slot 1 */
507 { 43, 43, 42, 41, 40}, /* IdSel 16 slot 2 */
508 { 47, 47, 46, 45, 44}, /* IdSel 17 slot 3 */
510 const long min_idsel = 7, max_idsel = 17, irqs_per_slot = 5;
511 return COMMON_TABLE_LOOKUP;
515 clipper_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
517 static char irq_tab[7][5] __initdata = {
518 /*INT INTA INTB INTC INTD */
519 { 16+ 8, 16+ 8, 16+ 9, 16+10, 16+11}, /* IdSel 1 slot 1 */
520 { 16+12, 16+12, 16+13, 16+14, 16+15}, /* IdSel 2 slot 2 */
521 { 16+16, 16+16, 16+17, 16+18, 16+19}, /* IdSel 3 slot 3 */
522 { 16+20, 16+20, 16+21, 16+22, 16+23}, /* IdSel 4 slot 4 */
523 { 16+24, 16+24, 16+25, 16+26, 16+27}, /* IdSel 5 slot 5 */
524 { 16+28, 16+28, 16+29, 16+30, 16+31}, /* IdSel 6 slot 6 */
525 { -1, -1, -1, -1, -1} /* IdSel 7 ISA Bridge */
527 const long min_idsel = 1, max_idsel = 7, irqs_per_slot = 5;
529 struct pci_controller *hose = dev->sysdata;
530 int irq = COMMON_TABLE_LOOKUP;
533 irq += 16 * hose->index;
554 webbrick_init_arch(void)
558 /* Tsunami caches 4 PTEs at a time; DS10 has only 1 hose. */
559 hose_head->sg_isa->align_entry = 4;
560 hose_head->sg_pci->align_entry = 4;
568 struct alpha_machine_vector dp264_mv __initmv = {
569 .vector_name = "DP264",
574 .machine_check = tsunami_machine_check,
575 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
576 .min_io_address = DEFAULT_IO_BASE,
577 .min_mem_address = DEFAULT_MEM_BASE,
578 .pci_dac_offset = TSUNAMI_DAC_OFFSET,
581 .device_interrupt = dp264_device_interrupt,
583 .init_arch = tsunami_init_arch,
584 .init_irq = dp264_init_irq,
585 .init_rtc = common_init_rtc,
586 .init_pci = dp264_init_pci,
587 .kill_arch = tsunami_kill_arch,
588 .pci_map_irq = dp264_map_irq,
589 .pci_swizzle = common_swizzle,
593 struct alpha_machine_vector monet_mv __initmv = {
594 .vector_name = "Monet",
599 .machine_check = tsunami_machine_check,
600 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
601 .min_io_address = DEFAULT_IO_BASE,
602 .min_mem_address = DEFAULT_MEM_BASE,
603 .pci_dac_offset = TSUNAMI_DAC_OFFSET,
606 .device_interrupt = dp264_device_interrupt,
608 .init_arch = tsunami_init_arch,
609 .init_irq = dp264_init_irq,
610 .init_rtc = common_init_rtc,
611 .init_pci = monet_init_pci,
612 .kill_arch = tsunami_kill_arch,
613 .pci_map_irq = monet_map_irq,
614 .pci_swizzle = monet_swizzle,
617 struct alpha_machine_vector webbrick_mv __initmv = {
618 .vector_name = "Webbrick",
623 .machine_check = tsunami_machine_check,
624 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
625 .min_io_address = DEFAULT_IO_BASE,
626 .min_mem_address = DEFAULT_MEM_BASE,
627 .pci_dac_offset = TSUNAMI_DAC_OFFSET,
630 .device_interrupt = dp264_device_interrupt,
632 .init_arch = webbrick_init_arch,
633 .init_irq = dp264_init_irq,
634 .init_rtc = common_init_rtc,
635 .init_pci = common_init_pci,
636 .kill_arch = tsunami_kill_arch,
637 .pci_map_irq = webbrick_map_irq,
638 .pci_swizzle = common_swizzle,
641 struct alpha_machine_vector clipper_mv __initmv = {
642 .vector_name = "Clipper",
647 .machine_check = tsunami_machine_check,
648 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
649 .min_io_address = DEFAULT_IO_BASE,
650 .min_mem_address = DEFAULT_MEM_BASE,
651 .pci_dac_offset = TSUNAMI_DAC_OFFSET,
654 .device_interrupt = dp264_device_interrupt,
656 .init_arch = tsunami_init_arch,
657 .init_irq = clipper_init_irq,
658 .init_rtc = common_init_rtc,
659 .init_pci = common_init_pci,
660 .kill_arch = tsunami_kill_arch,
661 .pci_map_irq = clipper_map_irq,
662 .pci_swizzle = common_swizzle,
665 /* Sharks strongly resemble Clipper, at least as far
666 * as interrupt routing, etc, so we're using the
667 * same functions as Clipper does
670 struct alpha_machine_vector shark_mv __initmv = {
671 .vector_name = "Shark",
676 .machine_check = tsunami_machine_check,
677 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
678 .min_io_address = DEFAULT_IO_BASE,
679 .min_mem_address = DEFAULT_MEM_BASE,
680 .pci_dac_offset = TSUNAMI_DAC_OFFSET,
683 .device_interrupt = dp264_device_interrupt,
685 .init_arch = tsunami_init_arch,
686 .init_irq = clipper_init_irq,
687 .init_rtc = common_init_rtc,
688 .init_pci = common_init_pci,
689 .kill_arch = tsunami_kill_arch,
690 .pci_map_irq = clipper_map_irq,
691 .pci_swizzle = common_swizzle,
694 /* No alpha_mv alias for webbrick/monet/clipper, since we compile them
695 in unconditionally with DP264; setup_arch knows how to cope. */