irq.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  4. *
  5. * arch/mips/ddb5xxx/ddb5477/irq.c
  6. * The irq setup and misc routines for DDB5476.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/init.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/irq.h>
  17. #include <linux/types.h>
  18. #include <linux/ptrace.h>
  19. #include <asm/i8259.h>
  20. #include <asm/system.h>
  21. #include <asm/mipsregs.h>
  22. #include <asm/debug.h>
  23. #include <asm/addrspace.h>
  24. #include <asm/bootinfo.h>
  25. #include <asm/ddb5xxx/ddb5xxx.h>
  26. /*
  27. * IRQ mapping
  28. *
  29. * 0-7: 8 CPU interrupts
  30. * 0 - software interrupt 0
  31. * 1 - software interrupt 1
  32. * 2 - most Vrc5477 interrupts are routed to this pin
  33. * 3 - (optional) some other interrupts routed to this pin for debugg
  34. * 4 - not used
  35. * 5 - not used
  36. * 6 - not used
  37. * 7 - cpu timer (used by default)
  38. *
  39. * 8-39: 32 Vrc5477 interrupt sources
  40. * (refer to the Vrc5477 manual)
  41. */
  42. #define PCI0 DDB_INTPPES0
  43. #define PCI1 DDB_INTPPES1
  44. #define ACTIVE_LOW 1
  45. #define ACTIVE_HIGH 0
  46. #define LEVEL_SENSE 2
  47. #define EDGE_TRIGGER 0
  48. #define INTA 0
  49. #define INTB 1
  50. #define INTC 2
  51. #define INTD 3
  52. #define INTE 4
  53. static inline void
  54. set_pci_int_attr(u32 pci, u32 intn, u32 active, u32 trigger)
  55. {
  56. u32 reg_value;
  57. u32 reg_bitmask;
  58. reg_value = ddb_in32(pci);
  59. reg_bitmask = 0x3 << (intn * 2);
  60. reg_value &= ~reg_bitmask;
  61. reg_value |= (active | trigger) << (intn * 2);
  62. ddb_out32(pci, reg_value);
  63. }
  64. extern void vrc5477_irq_init(u32 base);
  65. extern void mips_cpu_irq_init(u32 base);
  66. extern int setup_irq(unsigned int irq, struct irqaction *irqaction);
  67. static struct irqaction irq_cascade = { no_action, 0, CPU_MASK_NONE, "cascade", NULL, NULL };
  68. void __init arch_init_irq(void)
  69. {
  70. /* by default, we disable all interrupts and route all vrc5477
  71. * interrupts to pin 0 (irq 2) */
  72. ddb_out32(DDB_INTCTRL0, 0);
  73. ddb_out32(DDB_INTCTRL1, 0);
  74. ddb_out32(DDB_INTCTRL2, 0);
  75. ddb_out32(DDB_INTCTRL3, 0);
  76. clear_c0_status(0xff00);
  77. set_c0_status(0x0400);
  78. /* setup PCI interrupt attributes */
  79. set_pci_int_attr(PCI0, INTA, ACTIVE_LOW, LEVEL_SENSE);
  80. set_pci_int_attr(PCI0, INTB, ACTIVE_LOW, LEVEL_SENSE);
  81. if (mips_machtype == MACH_NEC_ROCKHOPPERII)
  82. set_pci_int_attr(PCI0, INTC, ACTIVE_HIGH, LEVEL_SENSE);
  83. else
  84. set_pci_int_attr(PCI0, INTC, ACTIVE_LOW, LEVEL_SENSE);
  85. set_pci_int_attr(PCI0, INTD, ACTIVE_LOW, LEVEL_SENSE);
  86. set_pci_int_attr(PCI0, INTE, ACTIVE_LOW, LEVEL_SENSE);
  87. set_pci_int_attr(PCI1, INTA, ACTIVE_LOW, LEVEL_SENSE);
  88. set_pci_int_attr(PCI1, INTB, ACTIVE_LOW, LEVEL_SENSE);
  89. set_pci_int_attr(PCI1, INTC, ACTIVE_LOW, LEVEL_SENSE);
  90. set_pci_int_attr(PCI1, INTD, ACTIVE_LOW, LEVEL_SENSE);
  91. set_pci_int_attr(PCI1, INTE, ACTIVE_LOW, LEVEL_SENSE);
  92. /*
  93. * for debugging purpose, we enable several error interrupts
  94. * and route them to pin 1. (IP3)
  95. */
  96. /* cpu parity check - 0 */
  97. ll_vrc5477_irq_route(0, 1); ll_vrc5477_irq_enable(0);
  98. /* cpu no-target decode - 1 */
  99. ll_vrc5477_irq_route(1, 1); ll_vrc5477_irq_enable(1);
  100. /* local bus read time-out - 7 */
  101. ll_vrc5477_irq_route(7, 1); ll_vrc5477_irq_enable(7);
  102. /* PCI SERR# - 14 */
  103. ll_vrc5477_irq_route(14, 1); ll_vrc5477_irq_enable(14);
  104. /* PCI internal error - 15 */
  105. ll_vrc5477_irq_route(15, 1); ll_vrc5477_irq_enable(15);
  106. /* IOPCI SERR# - 30 */
  107. ll_vrc5477_irq_route(30, 1); ll_vrc5477_irq_enable(30);
  108. /* IOPCI internal error - 31 */
  109. ll_vrc5477_irq_route(31, 1); ll_vrc5477_irq_enable(31);
  110. /* init all controllers */
  111. init_i8259_irqs();
  112. mips_cpu_irq_init(CPU_IRQ_BASE);
  113. vrc5477_irq_init(VRC5477_IRQ_BASE);
  114. /* setup cascade interrupts */
  115. setup_irq(VRC5477_IRQ_BASE + VRC5477_I8259_CASCADE, &irq_cascade);
  116. setup_irq(CPU_IRQ_BASE + CPU_VRC5477_CASCADE, &irq_cascade);
  117. }
  118. u8 i8259_interrupt_ack(void)
  119. {
  120. u8 irq;
  121. u32 reg;
  122. /* Set window 0 for interrupt acknowledge */
  123. reg = ddb_in32(DDB_PCIINIT10);
  124. ddb_set_pmr(DDB_PCIINIT10, DDB_PCICMD_IACK, 0, DDB_PCI_ACCESS_32);
  125. irq = *(volatile u8 *) KSEG1ADDR(DDB_PCI_IACK_BASE);
  126. ddb_out32(DDB_PCIINIT10, reg);
  127. /* i8259.c set the base vector to be 0x0 */
  128. return irq + I8259_IRQ_BASE;
  129. }
  130. /*
  131. * the first level int-handler will jump here if it is a vrc5477 irq
  132. */
  133. #define NUM_5477_IRQS 32
  134. static void
  135. vrc5477_irq_dispatch(struct pt_regs *regs)
  136. {
  137. u32 intStatus;
  138. u32 bitmask;
  139. u32 i;
  140. db_assert(ddb_in32(DDB_INT2STAT) == 0);
  141. db_assert(ddb_in32(DDB_INT3STAT) == 0);
  142. db_assert(ddb_in32(DDB_INT4STAT) == 0);
  143. db_assert(ddb_in32(DDB_NMISTAT) == 0);
  144. if (ddb_in32(DDB_INT1STAT) != 0) {
  145. #if defined(CONFIG_RUNTIME_DEBUG)
  146. vrc5477_show_int_regs();
  147. #endif
  148. panic("error interrupt has happened.");
  149. }
  150. intStatus = ddb_in32(DDB_INT0STAT);
  151. if (mips_machtype == MACH_NEC_ROCKHOPPERII) {
  152. /* check for i8259 interrupts */
  153. if (intStatus & (1 << VRC5477_I8259_CASCADE)) {
  154. int i8259_irq = i8259_interrupt_ack();
  155. do_IRQ(I8259_IRQ_BASE + i8259_irq, regs);
  156. return;
  157. }
  158. }
  159. for (i=0, bitmask=1; i<= NUM_5477_IRQS; bitmask <<=1, i++) {
  160. /* do we need to "and" with the int mask? */
  161. if (intStatus & bitmask) {
  162. do_IRQ(VRC5477_IRQ_BASE + i, regs);
  163. return;
  164. }
  165. }
  166. }
  167. #define VR5477INTS (STATUSF_IP2|STATUSF_IP3|STATUSF_IP4|STATUSF_IP5|STATUSF_IP6)
  168. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  169. {
  170. unsigned int pending = read_c0_cause() & read_c0_status();
  171. if (pending & STATUSF_IP7)
  172. do_IRQ(CPU_IRQ_BASE + 7, regs);
  173. else if (pending & VR5477INTS)
  174. vrc5477_irq_dispatch(regs);
  175. else if (pending & STATUSF_IP0)
  176. do_IRQ(CPU_IRQ_BASE, regs);
  177. else if (pending & STATUSF_IP1)
  178. do_IRQ(CPU_IRQ_BASE + 1, regs);
  179. else
  180. spurious_interrupt(regs);
  181. }