ip22-int.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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 (dm@engr.sgi.com)
  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/config.h>
  13. #include <linux/types.h>
  14. #include <linux/init.h>
  15. #include <linux/kernel_stat.h>
  16. #include <linux/signal.h>
  17. #include <linux/sched.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/irq.h>
  20. #include <asm/mipsregs.h>
  21. #include <asm/addrspace.h>
  22. #include <asm/sgi/ioc.h>
  23. #include <asm/sgi/hpc3.h>
  24. #include <asm/sgi/ip22.h>
  25. /* #define DEBUG_SGINT */
  26. /* So far nothing hangs here */
  27. #undef USE_LIO3_IRQ
  28. struct sgint_regs *sgint;
  29. static char lc0msk_to_irqnr[256];
  30. static char lc1msk_to_irqnr[256];
  31. static char lc2msk_to_irqnr[256];
  32. static char lc3msk_to_irqnr[256];
  33. extern int ip22_eisa_init(void);
  34. static void enable_local0_irq(unsigned int irq)
  35. {
  36. unsigned long flags;
  37. local_irq_save(flags);
  38. /* don't allow mappable interrupt to be enabled from setup_irq,
  39. * we have our own way to do so */
  40. if (irq != SGI_MAP_0_IRQ)
  41. sgint->imask0 |= (1 << (irq - SGINT_LOCAL0));
  42. local_irq_restore(flags);
  43. }
  44. static unsigned int startup_local0_irq(unsigned int irq)
  45. {
  46. enable_local0_irq(irq);
  47. return 0; /* Never anything pending */
  48. }
  49. static void disable_local0_irq(unsigned int irq)
  50. {
  51. unsigned long flags;
  52. local_irq_save(flags);
  53. sgint->imask0 &= ~(1 << (irq - SGINT_LOCAL0));
  54. local_irq_restore(flags);
  55. }
  56. #define shutdown_local0_irq disable_local0_irq
  57. #define mask_and_ack_local0_irq disable_local0_irq
  58. static void end_local0_irq (unsigned int irq)
  59. {
  60. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  61. enable_local0_irq(irq);
  62. }
  63. static struct hw_interrupt_type ip22_local0_irq_type = {
  64. .typename = "IP22 local 0",
  65. .startup = startup_local0_irq,
  66. .shutdown = shutdown_local0_irq,
  67. .enable = enable_local0_irq,
  68. .disable = disable_local0_irq,
  69. .ack = mask_and_ack_local0_irq,
  70. .end = end_local0_irq,
  71. };
  72. static void enable_local1_irq(unsigned int irq)
  73. {
  74. unsigned long flags;
  75. local_irq_save(flags);
  76. /* don't allow mappable interrupt to be enabled from setup_irq,
  77. * we have our own way to do so */
  78. if (irq != SGI_MAP_1_IRQ)
  79. sgint->imask1 |= (1 << (irq - SGINT_LOCAL1));
  80. local_irq_restore(flags);
  81. }
  82. static unsigned int startup_local1_irq(unsigned int irq)
  83. {
  84. enable_local1_irq(irq);
  85. return 0; /* Never anything pending */
  86. }
  87. void disable_local1_irq(unsigned int irq)
  88. {
  89. unsigned long flags;
  90. local_irq_save(flags);
  91. sgint->imask1 &= ~(1 << (irq - SGINT_LOCAL1));
  92. local_irq_restore(flags);
  93. }
  94. #define shutdown_local1_irq disable_local1_irq
  95. #define mask_and_ack_local1_irq disable_local1_irq
  96. static void end_local1_irq (unsigned int irq)
  97. {
  98. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  99. enable_local1_irq(irq);
  100. }
  101. static struct hw_interrupt_type ip22_local1_irq_type = {
  102. .typename = "IP22 local 1",
  103. .startup = startup_local1_irq,
  104. .shutdown = shutdown_local1_irq,
  105. .enable = enable_local1_irq,
  106. .disable = disable_local1_irq,
  107. .ack = mask_and_ack_local1_irq,
  108. .end = end_local1_irq,
  109. };
  110. static void enable_local2_irq(unsigned int irq)
  111. {
  112. unsigned long flags;
  113. local_irq_save(flags);
  114. sgint->imask0 |= (1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
  115. sgint->cmeimask0 |= (1 << (irq - SGINT_LOCAL2));
  116. local_irq_restore(flags);
  117. }
  118. static unsigned int startup_local2_irq(unsigned int irq)
  119. {
  120. enable_local2_irq(irq);
  121. return 0; /* Never anything pending */
  122. }
  123. void disable_local2_irq(unsigned int irq)
  124. {
  125. unsigned long flags;
  126. local_irq_save(flags);
  127. sgint->cmeimask0 &= ~(1 << (irq - SGINT_LOCAL2));
  128. if (!sgint->cmeimask0)
  129. sgint->imask0 &= ~(1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
  130. local_irq_restore(flags);
  131. }
  132. #define shutdown_local2_irq disable_local2_irq
  133. #define mask_and_ack_local2_irq disable_local2_irq
  134. static void end_local2_irq (unsigned int irq)
  135. {
  136. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  137. enable_local2_irq(irq);
  138. }
  139. static struct hw_interrupt_type ip22_local2_irq_type = {
  140. .typename = "IP22 local 2",
  141. .startup = startup_local2_irq,
  142. .shutdown = shutdown_local2_irq,
  143. .enable = enable_local2_irq,
  144. .disable = disable_local2_irq,
  145. .ack = mask_and_ack_local2_irq,
  146. .end = end_local2_irq,
  147. };
  148. static void enable_local3_irq(unsigned int irq)
  149. {
  150. unsigned long flags;
  151. local_irq_save(flags);
  152. sgint->imask1 |= (1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
  153. sgint->cmeimask1 |= (1 << (irq - SGINT_LOCAL3));
  154. local_irq_restore(flags);
  155. }
  156. static unsigned int startup_local3_irq(unsigned int irq)
  157. {
  158. enable_local3_irq(irq);
  159. return 0; /* Never anything pending */
  160. }
  161. void disable_local3_irq(unsigned int irq)
  162. {
  163. unsigned long flags;
  164. local_irq_save(flags);
  165. sgint->cmeimask1 &= ~(1 << (irq - SGINT_LOCAL3));
  166. if (!sgint->cmeimask1)
  167. sgint->imask1 &= ~(1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
  168. local_irq_restore(flags);
  169. }
  170. #define shutdown_local3_irq disable_local3_irq
  171. #define mask_and_ack_local3_irq disable_local3_irq
  172. static void end_local3_irq (unsigned int irq)
  173. {
  174. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  175. enable_local3_irq(irq);
  176. }
  177. static struct hw_interrupt_type ip22_local3_irq_type = {
  178. .typename = "IP22 local 3",
  179. .startup = startup_local3_irq,
  180. .shutdown = shutdown_local3_irq,
  181. .enable = enable_local3_irq,
  182. .disable = disable_local3_irq,
  183. .ack = mask_and_ack_local3_irq,
  184. .end = end_local3_irq,
  185. };
  186. static void indy_local0_irqdispatch(struct pt_regs *regs)
  187. {
  188. u8 mask = sgint->istat0 & sgint->imask0;
  189. u8 mask2;
  190. int irq;
  191. if (mask & SGINT_ISTAT0_LIO2) {
  192. mask2 = sgint->vmeistat & sgint->cmeimask0;
  193. irq = lc2msk_to_irqnr[mask2];
  194. } else
  195. irq = lc0msk_to_irqnr[mask];
  196. /* if irq == 0, then the interrupt has already been cleared */
  197. if (irq)
  198. do_IRQ(irq, regs);
  199. return;
  200. }
  201. static void indy_local1_irqdispatch(struct pt_regs *regs)
  202. {
  203. u8 mask = sgint->istat1 & sgint->imask1;
  204. u8 mask2;
  205. int irq;
  206. if (mask & SGINT_ISTAT1_LIO3) {
  207. mask2 = sgint->vmeistat & sgint->cmeimask1;
  208. irq = lc3msk_to_irqnr[mask2];
  209. } else
  210. irq = lc1msk_to_irqnr[mask];
  211. /* if irq == 0, then the interrupt has already been cleared */
  212. if (irq)
  213. do_IRQ(irq, regs);
  214. return;
  215. }
  216. extern void ip22_be_interrupt(int irq, struct pt_regs *regs);
  217. static void indy_buserror_irq(struct pt_regs *regs)
  218. {
  219. int irq = SGI_BUSERR_IRQ;
  220. irq_enter();
  221. kstat_this_cpu.irqs[irq]++;
  222. ip22_be_interrupt(irq, regs);
  223. irq_exit();
  224. }
  225. static struct irqaction local0_cascade = {
  226. .handler = no_action,
  227. .flags = SA_INTERRUPT,
  228. .name = "local0 cascade",
  229. };
  230. static struct irqaction local1_cascade = {
  231. .handler = no_action,
  232. .flags = SA_INTERRUPT,
  233. .name = "local1 cascade",
  234. };
  235. static struct irqaction buserr = {
  236. .handler = no_action,
  237. .flags = SA_INTERRUPT,
  238. .name = "Bus Error",
  239. };
  240. static struct irqaction map0_cascade = {
  241. .handler = no_action,
  242. .flags = SA_INTERRUPT,
  243. .name = "mapable0 cascade",
  244. };
  245. #ifdef USE_LIO3_IRQ
  246. static struct irqaction map1_cascade = {
  247. .handler = no_action,
  248. .flags = SA_INTERRUPT,
  249. .name = "mapable1 cascade",
  250. };
  251. #define SGI_INTERRUPTS SGINT_END
  252. #else
  253. #define SGI_INTERRUPTS SGINT_LOCAL3
  254. #endif
  255. extern void indy_r4k_timer_interrupt(struct pt_regs *regs);
  256. extern void indy_8254timer_irq(struct pt_regs *regs);
  257. /*
  258. * IRQs on the INDY look basically (barring software IRQs which we don't use
  259. * at all) like:
  260. *
  261. * MIPS IRQ Source
  262. * -------- ------
  263. * 0 Software (ignored)
  264. * 1 Software (ignored)
  265. * 2 Local IRQ level zero
  266. * 3 Local IRQ level one
  267. * 4 8254 Timer zero
  268. * 5 8254 Timer one
  269. * 6 Bus Error
  270. * 7 R4k timer (what we use)
  271. *
  272. * We handle the IRQ according to _our_ priority which is:
  273. *
  274. * Highest ---- R4k Timer
  275. * Local IRQ zero
  276. * Local IRQ one
  277. * Bus Error
  278. * 8254 Timer zero
  279. * Lowest ---- 8254 Timer one
  280. *
  281. * then we just return, if multiple IRQs are pending then we will just take
  282. * another exception, big deal.
  283. */
  284. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  285. {
  286. unsigned int pending = read_c0_cause();
  287. /*
  288. * First we check for r4k counter/timer IRQ.
  289. */
  290. if (pending & CAUSEF_IP7)
  291. indy_r4k_timer_interrupt(regs);
  292. else if (pending & CAUSEF_IP2)
  293. indy_local0_irqdispatch(regs);
  294. else if (pending & CAUSEF_IP3)
  295. indy_local1_irqdispatch(regs);
  296. else if (pending & CAUSEF_IP6)
  297. indy_buserror_irq(regs);
  298. else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
  299. indy_8254timer_irq(regs);
  300. }
  301. extern void mips_cpu_irq_init(unsigned int irq_base);
  302. void __init arch_init_irq(void)
  303. {
  304. int i;
  305. /* Init local mask --> irq tables. */
  306. for (i = 0; i < 256; i++) {
  307. if (i & 0x80) {
  308. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 7;
  309. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 7;
  310. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 7;
  311. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 7;
  312. } else if (i & 0x40) {
  313. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 6;
  314. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 6;
  315. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 6;
  316. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 6;
  317. } else if (i & 0x20) {
  318. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 5;
  319. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 5;
  320. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 5;
  321. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 5;
  322. } else if (i & 0x10) {
  323. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 4;
  324. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 4;
  325. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 4;
  326. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 4;
  327. } else if (i & 0x08) {
  328. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 3;
  329. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 3;
  330. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 3;
  331. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 3;
  332. } else if (i & 0x04) {
  333. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 2;
  334. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 2;
  335. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 2;
  336. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 2;
  337. } else if (i & 0x02) {
  338. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 1;
  339. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 1;
  340. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 1;
  341. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 1;
  342. } else if (i & 0x01) {
  343. lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 0;
  344. lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 0;
  345. lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 0;
  346. lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 0;
  347. } else {
  348. lc0msk_to_irqnr[i] = 0;
  349. lc1msk_to_irqnr[i] = 0;
  350. lc2msk_to_irqnr[i] = 0;
  351. lc3msk_to_irqnr[i] = 0;
  352. }
  353. }
  354. /* Mask out all interrupts. */
  355. sgint->imask0 = 0;
  356. sgint->imask1 = 0;
  357. sgint->cmeimask0 = 0;
  358. sgint->cmeimask1 = 0;
  359. /* init CPU irqs */
  360. mips_cpu_irq_init(SGINT_CPU);
  361. for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
  362. hw_irq_controller *handler;
  363. if (i < SGINT_LOCAL1)
  364. handler = &ip22_local0_irq_type;
  365. else if (i < SGINT_LOCAL2)
  366. handler = &ip22_local1_irq_type;
  367. else if (i < SGINT_LOCAL3)
  368. handler = &ip22_local2_irq_type;
  369. else
  370. handler = &ip22_local3_irq_type;
  371. irq_desc[i].status = IRQ_DISABLED;
  372. irq_desc[i].action = 0;
  373. irq_desc[i].depth = 1;
  374. irq_desc[i].handler = handler;
  375. }
  376. /* vector handler. this register the IRQ as non-sharable */
  377. setup_irq(SGI_LOCAL_0_IRQ, &local0_cascade);
  378. setup_irq(SGI_LOCAL_1_IRQ, &local1_cascade);
  379. setup_irq(SGI_BUSERR_IRQ, &buserr);
  380. /* cascade in cascade. i love Indy ;-) */
  381. setup_irq(SGI_MAP_0_IRQ, &map0_cascade);
  382. #ifdef USE_LIO3_IRQ
  383. setup_irq(SGI_MAP_1_IRQ, &map1_cascade);
  384. #endif
  385. #ifdef CONFIG_EISA
  386. if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */
  387. ip22_eisa_init ();
  388. #endif
  389. }