ip22-int.c 8.4 KB

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