ip22-int.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * ip22-int.c: Routines for generic manipulation of the INT[23] ASIC
  3. * found on INDY and Indigo2 workstations.
  4. *
  5. * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
  6. * Copyright (C) 1997, 1998 Ralf Baechle (ralf@gnu.org)
  7. * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu)
  8. * - Indigo2 changes
  9. * - Interrupt handling fixes
  10. * Copyright (C) 2001, 2003 Ladislav Michl (ladis@linux-mips.org)
  11. */
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/ftrace.h>
  17. #include <asm/irq_cpu.h>
  18. #include <asm/sgi/hpc3.h>
  19. #include <asm/sgi/ip22.h>
  20. /* So far nothing hangs here */
  21. #undef USE_LIO3_IRQ
  22. struct sgint_regs *sgint;
  23. static char lc0msk_to_irqnr[256];
  24. static char lc1msk_to_irqnr[256];
  25. static char lc2msk_to_irqnr[256];
  26. static char lc3msk_to_irqnr[256];
  27. extern int ip22_eisa_init(void);
  28. static void enable_local0_irq(struct irq_data *d)
  29. {
  30. /* don't allow mappable interrupt to be enabled from setup_irq,
  31. * we have our own way to do so */
  32. if (d->irq != SGI_MAP_0_IRQ)
  33. sgint->imask0 |= (1 << (d->irq - SGINT_LOCAL0));
  34. }
  35. static void disable_local0_irq(struct irq_data *d)
  36. {
  37. sgint->imask0 &= ~(1 << (d->irq - SGINT_LOCAL0));
  38. }
  39. static struct irq_chip ip22_local0_irq_type = {
  40. .name = "IP22 local 0",
  41. .irq_mask = disable_local0_irq,
  42. .irq_unmask = enable_local0_irq,
  43. };
  44. static void enable_local1_irq(struct irq_data *d)
  45. {
  46. /* don't allow mappable interrupt to be enabled from setup_irq,
  47. * we have our own way to do so */
  48. if (d->irq != SGI_MAP_1_IRQ)
  49. sgint->imask1 |= (1 << (d->irq - SGINT_LOCAL1));
  50. }
  51. static void disable_local1_irq(struct irq_data *d)
  52. {
  53. sgint->imask1 &= ~(1 << (d->irq - SGINT_LOCAL1));
  54. }
  55. static struct irq_chip ip22_local1_irq_type = {
  56. .name = "IP22 local 1",
  57. .irq_mask = disable_local1_irq,
  58. .irq_unmask = enable_local1_irq,
  59. };
  60. static void enable_local2_irq(struct irq_data *d)
  61. {
  62. sgint->imask0 |= (1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
  63. sgint->cmeimask0 |= (1 << (d->irq - SGINT_LOCAL2));
  64. }
  65. static void disable_local2_irq(struct irq_data *d)
  66. {
  67. sgint->cmeimask0 &= ~(1 << (d->irq - SGINT_LOCAL2));
  68. if (!sgint->cmeimask0)
  69. sgint->imask0 &= ~(1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
  70. }
  71. static struct irq_chip ip22_local2_irq_type = {
  72. .name = "IP22 local 2",
  73. .irq_mask = disable_local2_irq,
  74. .irq_unmask = enable_local2_irq,
  75. };
  76. static void enable_local3_irq(struct irq_data *d)
  77. {
  78. sgint->imask1 |= (1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
  79. sgint->cmeimask1 |= (1 << (d->irq - SGINT_LOCAL3));
  80. }
  81. static void disable_local3_irq(struct irq_data *d)
  82. {
  83. sgint->cmeimask1 &= ~(1 << (d->irq - SGINT_LOCAL3));
  84. if (!sgint->cmeimask1)
  85. sgint->imask1 &= ~(1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
  86. }
  87. static struct irq_chip ip22_local3_irq_type = {
  88. .name = "IP22 local 3",
  89. .irq_mask = disable_local3_irq,
  90. .irq_unmask = enable_local3_irq,
  91. };
  92. static void indy_local0_irqdispatch(void)
  93. {
  94. u8 mask = sgint->istat0 & sgint->imask0;
  95. u8 mask2;
  96. int irq;
  97. if (mask & SGINT_ISTAT0_LIO2) {
  98. mask2 = sgint->vmeistat & sgint->cmeimask0;
  99. irq = lc2msk_to_irqnr[mask2];
  100. } else
  101. irq = lc0msk_to_irqnr[mask];
  102. /*
  103. * workaround for INT2 bug; if irq == 0, INT2 has seen a fifo full
  104. * irq, but failed to latch it into status register
  105. */
  106. if (irq)
  107. do_IRQ(irq);
  108. else
  109. do_IRQ(SGINT_LOCAL0 + 0);
  110. }
  111. static void indy_local1_irqdispatch(void)
  112. {
  113. u8 mask = sgint->istat1 & sgint->imask1;
  114. u8 mask2;
  115. int irq;
  116. if (mask & SGINT_ISTAT1_LIO3) {
  117. mask2 = sgint->vmeistat & sgint->cmeimask1;
  118. irq = lc3msk_to_irqnr[mask2];
  119. } else
  120. irq = lc1msk_to_irqnr[mask];
  121. /* if irq == 0, then the interrupt has already been cleared */
  122. if (irq)
  123. do_IRQ(irq);
  124. }
  125. extern void ip22_be_interrupt(int irq);
  126. static void __irq_entry indy_buserror_irq(void)
  127. {
  128. int irq = SGI_BUSERR_IRQ;
  129. irq_enter();
  130. kstat_incr_irq_this_cpu(irq);
  131. ip22_be_interrupt(irq);
  132. irq_exit();
  133. }
  134. static struct irqaction local0_cascade = {
  135. .handler = no_action,
  136. .flags = IRQF_NO_THREAD,
  137. .name = "local0 cascade",
  138. };
  139. static struct irqaction local1_cascade = {
  140. .handler = no_action,
  141. .flags = IRQF_NO_THREAD,
  142. .name = "local1 cascade",
  143. };
  144. static struct irqaction buserr = {
  145. .handler = no_action,
  146. .flags = IRQF_NO_THREAD,
  147. .name = "Bus Error",
  148. };
  149. static struct irqaction map0_cascade = {
  150. .handler = no_action,
  151. .flags = IRQF_NO_THREAD,
  152. .name = "mapable0 cascade",
  153. };
  154. #ifdef USE_LIO3_IRQ
  155. static struct irqaction map1_cascade = {
  156. .handler = no_action,
  157. .flags = IRQF_NO_THREAD,
  158. .name = "mapable1 cascade",
  159. };
  160. #define SGI_INTERRUPTS SGINT_END
  161. #else
  162. #define SGI_INTERRUPTS SGINT_LOCAL3
  163. #endif
  164. extern void indy_8254timer_irq(void);
  165. /*
  166. * IRQs on the INDY look basically (barring software IRQs which we don't use
  167. * at all) like:
  168. *
  169. * MIPS IRQ Source
  170. * -------- ------
  171. * 0 Software (ignored)
  172. * 1 Software (ignored)
  173. * 2 Local IRQ level zero
  174. * 3 Local IRQ level one
  175. * 4 8254 Timer zero
  176. * 5 8254 Timer one
  177. * 6 Bus Error
  178. * 7 R4k timer (what we use)
  179. *
  180. * We handle the IRQ according to _our_ priority which is:
  181. *
  182. * Highest ---- R4k Timer
  183. * Local IRQ zero
  184. * Local IRQ one
  185. * Bus Error
  186. * 8254 Timer zero
  187. * Lowest ---- 8254 Timer one
  188. *
  189. * then we just return, if multiple IRQs are pending then we will just take
  190. * another exception, big deal.
  191. */
  192. asmlinkage void plat_irq_dispatch(void)
  193. {
  194. unsigned int pending = read_c0_status() & read_c0_cause();
  195. /*
  196. * First we check for r4k counter/timer IRQ.
  197. */
  198. if (pending & CAUSEF_IP7)
  199. do_IRQ(SGI_TIMER_IRQ);
  200. else if (pending & CAUSEF_IP2)
  201. indy_local0_irqdispatch();
  202. else if (pending & CAUSEF_IP3)
  203. indy_local1_irqdispatch();
  204. else if (pending & CAUSEF_IP6)
  205. indy_buserror_irq();
  206. else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
  207. indy_8254timer_irq();
  208. }
  209. void __init arch_init_irq(void)
  210. {
  211. int i;
  212. /* Init local mask --> irq tables. */
  213. for (i = 0; i < 256; i++) {
  214. if (i & 0x80) {
  215. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 7;
  216. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 7;
  217. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 7;
  218. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 7;
  219. } else if (i & 0x40) {
  220. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 6;
  221. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 6;
  222. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 6;
  223. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 6;
  224. } else if (i & 0x20) {
  225. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 5;
  226. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 5;
  227. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 5;
  228. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 5;
  229. } else if (i & 0x10) {
  230. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 4;
  231. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 4;
  232. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 4;
  233. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 4;
  234. } else if (i & 0x08) {
  235. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 3;
  236. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 3;
  237. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 3;
  238. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 3;
  239. } else if (i & 0x04) {
  240. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 2;
  241. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 2;
  242. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 2;
  243. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 2;
  244. } else if (i & 0x02) {
  245. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 1;
  246. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 1;
  247. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 1;
  248. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 1;
  249. } else if (i & 0x01) {
  250. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 0;
  251. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 0;
  252. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 0;
  253. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 0;
  254. } else {
  255. lc0msk_to_irqnr[i] = 0;
  256. lc1msk_to_irqnr[i] = 0;
  257. lc2msk_to_irqnr[i] = 0;
  258. lc3msk_to_irqnr[i] = 0;
  259. }
  260. }
  261. /* Mask out all interrupts. */
  262. sgint->imask0 = 0;
  263. sgint->imask1 = 0;
  264. sgint->cmeimask0 = 0;
  265. sgint->cmeimask1 = 0;
  266. /* init CPU irqs */
  267. mips_cpu_irq_init();
  268. for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
  269. struct irq_chip *handler;
  270. if (i < SGINT_LOCAL1)
  271. handler = &ip22_local0_irq_type;
  272. else if (i < SGINT_LOCAL2)
  273. handler = &ip22_local1_irq_type;
  274. else if (i < SGINT_LOCAL3)
  275. handler = &ip22_local2_irq_type;
  276. else
  277. handler = &ip22_local3_irq_type;
  278. irq_set_chip_and_handler(i, handler, handle_level_irq);
  279. }
  280. /* vector handler. this register the IRQ as non-sharable */
  281. setup_irq(SGI_LOCAL_0_IRQ, &local0_cascade);
  282. setup_irq(SGI_LOCAL_1_IRQ, &local1_cascade);
  283. setup_irq(SGI_BUSERR_IRQ, &buserr);
  284. /* cascade in cascade. i love Indy ;-) */
  285. setup_irq(SGI_MAP_0_IRQ, &map0_cascade);
  286. #ifdef USE_LIO3_IRQ
  287. setup_irq(SGI_MAP_1_IRQ, &map1_cascade);
  288. #endif
  289. #ifdef CONFIG_EISA
  290. if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */
  291. ip22_eisa_init();
  292. #endif
  293. }