ip32-irq.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. /*
  2. * Code to handle IP32 IRQs
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2000 Harald Koerfgen
  9. * Copyright (C) 2001 Keith M Wesolowski
  10. */
  11. #include <linux/init.h>
  12. #include <linux/kernel_stat.h>
  13. #include <linux/types.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/bitops.h>
  17. #include <linux/kernel.h>
  18. #include <linux/mm.h>
  19. #include <linux/random.h>
  20. #include <linux/sched.h>
  21. #include <asm/irq_cpu.h>
  22. #include <asm/mipsregs.h>
  23. #include <asm/signal.h>
  24. #include <asm/time.h>
  25. #include <asm/ip32/crime.h>
  26. #include <asm/ip32/mace.h>
  27. #include <asm/ip32/ip32_ints.h>
  28. /* issue a PIO read to make sure no PIO writes are pending */
  29. static void inline flush_crime_bus(void)
  30. {
  31. crime->control;
  32. }
  33. static void inline flush_mace_bus(void)
  34. {
  35. mace->perif.ctrl.misc;
  36. }
  37. /*
  38. * O2 irq map
  39. *
  40. * IP0 -> software (ignored)
  41. * IP1 -> software (ignored)
  42. * IP2 -> (irq0) C crime 1.1 all interrupts; crime 1.5 ???
  43. * IP3 -> (irq1) X unknown
  44. * IP4 -> (irq2) X unknown
  45. * IP5 -> (irq3) X unknown
  46. * IP6 -> (irq4) X unknown
  47. * IP7 -> (irq5) 7 CPU count/compare timer (system timer)
  48. *
  49. * crime: (C)
  50. *
  51. * CRIME_INT_STAT 31:0:
  52. *
  53. * 0 -> 8 Video in 1
  54. * 1 -> 9 Video in 2
  55. * 2 -> 10 Video out
  56. * 3 -> 11 Mace ethernet
  57. * 4 -> S SuperIO sub-interrupt
  58. * 5 -> M Miscellaneous sub-interrupt
  59. * 6 -> A Audio sub-interrupt
  60. * 7 -> 15 PCI bridge errors
  61. * 8 -> 16 PCI SCSI aic7xxx 0
  62. * 9 -> 17 PCI SCSI aic7xxx 1
  63. * 10 -> 18 PCI slot 0
  64. * 11 -> 19 unused (PCI slot 1)
  65. * 12 -> 20 unused (PCI slot 2)
  66. * 13 -> 21 unused (PCI shared 0)
  67. * 14 -> 22 unused (PCI shared 1)
  68. * 15 -> 23 unused (PCI shared 2)
  69. * 16 -> 24 GBE0 (E)
  70. * 17 -> 25 GBE1 (E)
  71. * 18 -> 26 GBE2 (E)
  72. * 19 -> 27 GBE3 (E)
  73. * 20 -> 28 CPU errors
  74. * 21 -> 29 Memory errors
  75. * 22 -> 30 RE empty edge (E)
  76. * 23 -> 31 RE full edge (E)
  77. * 24 -> 32 RE idle edge (E)
  78. * 25 -> 33 RE empty level
  79. * 26 -> 34 RE full level
  80. * 27 -> 35 RE idle level
  81. * 28 -> 36 unused (software 0) (E)
  82. * 29 -> 37 unused (software 1) (E)
  83. * 30 -> 38 unused (software 2) - crime 1.5 CPU SysCorError (E)
  84. * 31 -> 39 VICE
  85. *
  86. * S, M, A: Use the MACE ISA interrupt register
  87. * MACE_ISA_INT_STAT 31:0
  88. *
  89. * 0-7 -> 40-47 Audio
  90. * 8 -> 48 RTC
  91. * 9 -> 49 Keyboard
  92. * 10 -> X Keyboard polled
  93. * 11 -> 51 Mouse
  94. * 12 -> X Mouse polled
  95. * 13-15 -> 53-55 Count/compare timers
  96. * 16-19 -> 56-59 Parallel (16 E)
  97. * 20-25 -> 60-62 Serial 1 (22 E)
  98. * 26-31 -> 66-71 Serial 2 (28 E)
  99. *
  100. * Note that this means IRQs 12-14, 50, and 52 do not exist. This is a
  101. * different IRQ map than IRIX uses, but that's OK as Linux irq handling
  102. * is quite different anyway.
  103. */
  104. /* Some initial interrupts to set up */
  105. extern irqreturn_t crime_memerr_intr(int irq, void *dev_id);
  106. extern irqreturn_t crime_cpuerr_intr(int irq, void *dev_id);
  107. static struct irqaction memerr_irq = {
  108. .handler = crime_memerr_intr,
  109. .name = "CRIME memory error",
  110. };
  111. static struct irqaction cpuerr_irq = {
  112. .handler = crime_cpuerr_intr,
  113. .name = "CRIME CPU error",
  114. };
  115. /*
  116. * This is for pure CRIME interrupts - ie not MACE. The advantage?
  117. * We get to split the register in half and do faster lookups.
  118. */
  119. static uint64_t crime_mask;
  120. static inline void crime_enable_irq(struct irq_data *d)
  121. {
  122. unsigned int bit = d->irq - CRIME_IRQ_BASE;
  123. crime_mask |= 1 << bit;
  124. crime->imask = crime_mask;
  125. }
  126. static inline void crime_disable_irq(struct irq_data *d)
  127. {
  128. unsigned int bit = d->irq - CRIME_IRQ_BASE;
  129. crime_mask &= ~(1 << bit);
  130. crime->imask = crime_mask;
  131. flush_crime_bus();
  132. }
  133. static struct irq_chip crime_level_interrupt = {
  134. .name = "IP32 CRIME",
  135. .irq_mask = crime_disable_irq,
  136. .irq_unmask = crime_enable_irq,
  137. };
  138. static void crime_edge_mask_and_ack_irq(struct irq_data *d)
  139. {
  140. unsigned int bit = d->irq - CRIME_IRQ_BASE;
  141. uint64_t crime_int;
  142. /* Edge triggered interrupts must be cleared. */
  143. crime_int = crime->hard_int;
  144. crime_int &= ~(1 << bit);
  145. crime->hard_int = crime_int;
  146. crime_disable_irq(d);
  147. }
  148. static struct irq_chip crime_edge_interrupt = {
  149. .name = "IP32 CRIME",
  150. .irq_ack = crime_edge_mask_and_ack_irq,
  151. .irq_mask = crime_disable_irq,
  152. .irq_mask_ack = crime_edge_mask_and_ack_irq,
  153. .irq_unmask = crime_enable_irq,
  154. };
  155. /*
  156. * This is for MACE PCI interrupts. We can decrease bus traffic by masking
  157. * as close to the source as possible. This also means we can take the
  158. * next chunk of the CRIME register in one piece.
  159. */
  160. static unsigned long macepci_mask;
  161. static void enable_macepci_irq(struct irq_data *d)
  162. {
  163. macepci_mask |= MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
  164. mace->pci.control = macepci_mask;
  165. crime_mask |= 1 << (d->irq - CRIME_IRQ_BASE);
  166. crime->imask = crime_mask;
  167. }
  168. static void disable_macepci_irq(struct irq_data *d)
  169. {
  170. crime_mask &= ~(1 << (d->irq - CRIME_IRQ_BASE));
  171. crime->imask = crime_mask;
  172. flush_crime_bus();
  173. macepci_mask &= ~MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
  174. mace->pci.control = macepci_mask;
  175. flush_mace_bus();
  176. }
  177. static struct irq_chip ip32_macepci_interrupt = {
  178. .name = "IP32 MACE PCI",
  179. .irq_mask = disable_macepci_irq,
  180. .irq_unmask = enable_macepci_irq,
  181. };
  182. /* This is used for MACE ISA interrupts. That means bits 4-6 in the
  183. * CRIME register.
  184. */
  185. #define MACEISA_AUDIO_INT (MACEISA_AUDIO_SW_INT | \
  186. MACEISA_AUDIO_SC_INT | \
  187. MACEISA_AUDIO1_DMAT_INT | \
  188. MACEISA_AUDIO1_OF_INT | \
  189. MACEISA_AUDIO2_DMAT_INT | \
  190. MACEISA_AUDIO2_MERR_INT | \
  191. MACEISA_AUDIO3_DMAT_INT | \
  192. MACEISA_AUDIO3_MERR_INT)
  193. #define MACEISA_MISC_INT (MACEISA_RTC_INT | \
  194. MACEISA_KEYB_INT | \
  195. MACEISA_KEYB_POLL_INT | \
  196. MACEISA_MOUSE_INT | \
  197. MACEISA_MOUSE_POLL_INT | \
  198. MACEISA_TIMER0_INT | \
  199. MACEISA_TIMER1_INT | \
  200. MACEISA_TIMER2_INT)
  201. #define MACEISA_SUPERIO_INT (MACEISA_PARALLEL_INT | \
  202. MACEISA_PAR_CTXA_INT | \
  203. MACEISA_PAR_CTXB_INT | \
  204. MACEISA_PAR_MERR_INT | \
  205. MACEISA_SERIAL1_INT | \
  206. MACEISA_SERIAL1_TDMAT_INT | \
  207. MACEISA_SERIAL1_TDMAPR_INT | \
  208. MACEISA_SERIAL1_TDMAME_INT | \
  209. MACEISA_SERIAL1_RDMAT_INT | \
  210. MACEISA_SERIAL1_RDMAOR_INT | \
  211. MACEISA_SERIAL2_INT | \
  212. MACEISA_SERIAL2_TDMAT_INT | \
  213. MACEISA_SERIAL2_TDMAPR_INT | \
  214. MACEISA_SERIAL2_TDMAME_INT | \
  215. MACEISA_SERIAL2_RDMAT_INT | \
  216. MACEISA_SERIAL2_RDMAOR_INT)
  217. static unsigned long maceisa_mask;
  218. static void enable_maceisa_irq(struct irq_data *d)
  219. {
  220. unsigned int crime_int = 0;
  221. pr_debug("maceisa enable: %u\n", d->irq);
  222. switch (d->irq) {
  223. case MACEISA_AUDIO_SW_IRQ ... MACEISA_AUDIO3_MERR_IRQ:
  224. crime_int = MACE_AUDIO_INT;
  225. break;
  226. case MACEISA_RTC_IRQ ... MACEISA_TIMER2_IRQ:
  227. crime_int = MACE_MISC_INT;
  228. break;
  229. case MACEISA_PARALLEL_IRQ ... MACEISA_SERIAL2_RDMAOR_IRQ:
  230. crime_int = MACE_SUPERIO_INT;
  231. break;
  232. }
  233. pr_debug("crime_int %08x enabled\n", crime_int);
  234. crime_mask |= crime_int;
  235. crime->imask = crime_mask;
  236. maceisa_mask |= 1 << (d->irq - MACEISA_AUDIO_SW_IRQ);
  237. mace->perif.ctrl.imask = maceisa_mask;
  238. }
  239. static void disable_maceisa_irq(struct irq_data *d)
  240. {
  241. unsigned int crime_int = 0;
  242. maceisa_mask &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
  243. if (!(maceisa_mask & MACEISA_AUDIO_INT))
  244. crime_int |= MACE_AUDIO_INT;
  245. if (!(maceisa_mask & MACEISA_MISC_INT))
  246. crime_int |= MACE_MISC_INT;
  247. if (!(maceisa_mask & MACEISA_SUPERIO_INT))
  248. crime_int |= MACE_SUPERIO_INT;
  249. crime_mask &= ~crime_int;
  250. crime->imask = crime_mask;
  251. flush_crime_bus();
  252. mace->perif.ctrl.imask = maceisa_mask;
  253. flush_mace_bus();
  254. }
  255. static void mask_and_ack_maceisa_irq(struct irq_data *d)
  256. {
  257. unsigned long mace_int;
  258. /* edge triggered */
  259. mace_int = mace->perif.ctrl.istat;
  260. mace_int &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
  261. mace->perif.ctrl.istat = mace_int;
  262. disable_maceisa_irq(d);
  263. }
  264. static struct irq_chip ip32_maceisa_level_interrupt = {
  265. .name = "IP32 MACE ISA",
  266. .irq_mask = disable_maceisa_irq,
  267. .irq_unmask = enable_maceisa_irq,
  268. };
  269. static struct irq_chip ip32_maceisa_edge_interrupt = {
  270. .name = "IP32 MACE ISA",
  271. .irq_ack = mask_and_ack_maceisa_irq,
  272. .irq_mask = disable_maceisa_irq,
  273. .irq_mask_ack = mask_and_ack_maceisa_irq,
  274. .irq_unmask = enable_maceisa_irq,
  275. };
  276. /* This is used for regular non-ISA, non-PCI MACE interrupts. That means
  277. * bits 0-3 and 7 in the CRIME register.
  278. */
  279. static void enable_mace_irq(struct irq_data *d)
  280. {
  281. unsigned int bit = d->irq - CRIME_IRQ_BASE;
  282. crime_mask |= (1 << bit);
  283. crime->imask = crime_mask;
  284. }
  285. static void disable_mace_irq(struct irq_data *d)
  286. {
  287. unsigned int bit = d->irq - CRIME_IRQ_BASE;
  288. crime_mask &= ~(1 << bit);
  289. crime->imask = crime_mask;
  290. flush_crime_bus();
  291. }
  292. static struct irq_chip ip32_mace_interrupt = {
  293. .name = "IP32 MACE",
  294. .irq_mask = disable_mace_irq,
  295. .irq_unmask = enable_mace_irq,
  296. };
  297. static void ip32_unknown_interrupt(void)
  298. {
  299. printk("Unknown interrupt occurred!\n");
  300. printk("cp0_status: %08x\n", read_c0_status());
  301. printk("cp0_cause: %08x\n", read_c0_cause());
  302. printk("CRIME intr mask: %016lx\n", crime->imask);
  303. printk("CRIME intr status: %016lx\n", crime->istat);
  304. printk("CRIME hardware intr register: %016lx\n", crime->hard_int);
  305. printk("MACE ISA intr mask: %08lx\n", mace->perif.ctrl.imask);
  306. printk("MACE ISA intr status: %08lx\n", mace->perif.ctrl.istat);
  307. printk("MACE PCI control register: %08x\n", mace->pci.control);
  308. printk("Register dump:\n");
  309. show_regs(get_irq_regs());
  310. printk("Please mail this report to linux-mips@linux-mips.org\n");
  311. printk("Spinning...");
  312. while(1) ;
  313. }
  314. /* CRIME 1.1 appears to deliver all interrupts to this one pin. */
  315. /* change this to loop over all edge-triggered irqs, exception masked out ones */
  316. static void ip32_irq0(void)
  317. {
  318. uint64_t crime_int;
  319. int irq = 0;
  320. /*
  321. * Sanity check interrupt numbering enum.
  322. * MACE got 32 interrupts and there are 32 MACE ISA interrupts daisy
  323. * chained.
  324. */
  325. BUILD_BUG_ON(CRIME_VICE_IRQ - MACE_VID_IN1_IRQ != 31);
  326. BUILD_BUG_ON(MACEISA_SERIAL2_RDMAOR_IRQ - MACEISA_AUDIO_SW_IRQ != 31);
  327. crime_int = crime->istat & crime_mask;
  328. /* crime sometime delivers spurious interrupts, ignore them */
  329. if (unlikely(crime_int == 0))
  330. return;
  331. irq = MACE_VID_IN1_IRQ + __ffs(crime_int);
  332. if (crime_int & CRIME_MACEISA_INT_MASK) {
  333. unsigned long mace_int = mace->perif.ctrl.istat;
  334. irq = __ffs(mace_int & maceisa_mask) + MACEISA_AUDIO_SW_IRQ;
  335. }
  336. pr_debug("*irq %u*\n", irq);
  337. do_IRQ(irq);
  338. }
  339. static void ip32_irq1(void)
  340. {
  341. ip32_unknown_interrupt();
  342. }
  343. static void ip32_irq2(void)
  344. {
  345. ip32_unknown_interrupt();
  346. }
  347. static void ip32_irq3(void)
  348. {
  349. ip32_unknown_interrupt();
  350. }
  351. static void ip32_irq4(void)
  352. {
  353. ip32_unknown_interrupt();
  354. }
  355. static void ip32_irq5(void)
  356. {
  357. do_IRQ(MIPS_CPU_IRQ_BASE + 7);
  358. }
  359. asmlinkage void plat_irq_dispatch(void)
  360. {
  361. unsigned int pending = read_c0_status() & read_c0_cause();
  362. if (likely(pending & IE_IRQ0))
  363. ip32_irq0();
  364. else if (unlikely(pending & IE_IRQ1))
  365. ip32_irq1();
  366. else if (unlikely(pending & IE_IRQ2))
  367. ip32_irq2();
  368. else if (unlikely(pending & IE_IRQ3))
  369. ip32_irq3();
  370. else if (unlikely(pending & IE_IRQ4))
  371. ip32_irq4();
  372. else if (likely(pending & IE_IRQ5))
  373. ip32_irq5();
  374. }
  375. void __init arch_init_irq(void)
  376. {
  377. unsigned int irq;
  378. /* Install our interrupt handler, then clear and disable all
  379. * CRIME and MACE interrupts. */
  380. crime->imask = 0;
  381. crime->hard_int = 0;
  382. crime->soft_int = 0;
  383. mace->perif.ctrl.istat = 0;
  384. mace->perif.ctrl.imask = 0;
  385. mips_cpu_irq_init();
  386. for (irq = CRIME_IRQ_BASE; irq <= IP32_IRQ_MAX; irq++) {
  387. switch (irq) {
  388. case MACE_VID_IN1_IRQ ... MACE_PCI_BRIDGE_IRQ:
  389. irq_set_chip_and_handler_name(irq,
  390. &ip32_mace_interrupt,
  391. handle_level_irq,
  392. "level");
  393. break;
  394. case MACEPCI_SCSI0_IRQ ... MACEPCI_SHARED2_IRQ:
  395. irq_set_chip_and_handler_name(irq,
  396. &ip32_macepci_interrupt,
  397. handle_level_irq,
  398. "level");
  399. break;
  400. case CRIME_CPUERR_IRQ:
  401. case CRIME_MEMERR_IRQ:
  402. irq_set_chip_and_handler_name(irq,
  403. &crime_level_interrupt,
  404. handle_level_irq,
  405. "level");
  406. break;
  407. case CRIME_GBE0_IRQ ... CRIME_GBE3_IRQ:
  408. case CRIME_RE_EMPTY_E_IRQ ... CRIME_RE_IDLE_E_IRQ:
  409. case CRIME_SOFT0_IRQ ... CRIME_SOFT2_IRQ:
  410. case CRIME_VICE_IRQ:
  411. irq_set_chip_and_handler_name(irq,
  412. &crime_edge_interrupt,
  413. handle_edge_irq,
  414. "edge");
  415. break;
  416. case MACEISA_PARALLEL_IRQ:
  417. case MACEISA_SERIAL1_TDMAPR_IRQ:
  418. case MACEISA_SERIAL2_TDMAPR_IRQ:
  419. irq_set_chip_and_handler_name(irq,
  420. &ip32_maceisa_edge_interrupt,
  421. handle_edge_irq,
  422. "edge");
  423. break;
  424. default:
  425. irq_set_chip_and_handler_name(irq,
  426. &ip32_maceisa_level_interrupt,
  427. handle_level_irq,
  428. "level");
  429. break;
  430. }
  431. }
  432. setup_irq(CRIME_MEMERR_IRQ, &memerr_irq);
  433. setup_irq(CRIME_CPUERR_IRQ, &cpuerr_irq);
  434. #define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5)
  435. change_c0_status(ST0_IM, ALLINTS);
  436. }