macints.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. * Macintosh interrupts
  3. *
  4. * General design:
  5. * In contrary to the Amiga and Atari platforms, the Mac hardware seems to
  6. * exclusively use the autovector interrupts (the 'generic level0-level7'
  7. * interrupts with exception vectors 0x19-0x1f). The following interrupt levels
  8. * are used:
  9. * 1 - VIA1
  10. * - slot 0: one second interrupt (CA2)
  11. * - slot 1: VBlank (CA1)
  12. * - slot 2: ADB data ready (SR full)
  13. * - slot 3: ADB data (CB2)
  14. * - slot 4: ADB clock (CB1)
  15. * - slot 5: timer 2
  16. * - slot 6: timer 1
  17. * - slot 7: status of IRQ; signals 'any enabled int.'
  18. *
  19. * 2 - VIA2 or RBV
  20. * - slot 0: SCSI DRQ (CA2)
  21. * - slot 1: NUBUS IRQ (CA1) need to read port A to find which
  22. * - slot 2: /EXP IRQ (only on IIci)
  23. * - slot 3: SCSI IRQ (CB2)
  24. * - slot 4: ASC IRQ (CB1)
  25. * - slot 5: timer 2 (not on IIci)
  26. * - slot 6: timer 1 (not on IIci)
  27. * - slot 7: status of IRQ; signals 'any enabled int.'
  28. *
  29. * 2 - OSS (IIfx only?)
  30. * - slot 0: SCSI interrupt
  31. * - slot 1: Sound interrupt
  32. *
  33. * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes:
  34. *
  35. * 3 - unused (?)
  36. *
  37. * 4 - SCC
  38. *
  39. * 5 - unused (?)
  40. * [serial errors or special conditions seem to raise level 6
  41. * interrupts on some models (LC4xx?)]
  42. *
  43. * 6 - off switch (?)
  44. *
  45. * For OSS Macintoshes (IIfx only at this point):
  46. *
  47. * 3 - Nubus interrupt
  48. * - slot 0: Slot $9
  49. * - slot 1: Slot $A
  50. * - slot 2: Slot $B
  51. * - slot 3: Slot $C
  52. * - slot 4: Slot $D
  53. * - slot 5: Slot $E
  54. *
  55. * 4 - SCC IOP
  56. *
  57. * 5 - ISM IOP (ADB?)
  58. *
  59. * 6 - unused
  60. *
  61. * For PSC Macintoshes (660AV, 840AV):
  62. *
  63. * 3 - PSC level 3
  64. * - slot 0: MACE
  65. *
  66. * 4 - PSC level 4
  67. * - slot 1: SCC channel A interrupt
  68. * - slot 2: SCC channel B interrupt
  69. * - slot 3: MACE DMA
  70. *
  71. * 5 - PSC level 5
  72. *
  73. * 6 - PSC level 6
  74. *
  75. * Finally we have good 'ole level 7, the non-maskable interrupt:
  76. *
  77. * 7 - NMI (programmer's switch on the back of some Macs)
  78. * Also RAM parity error on models which support it (IIc, IIfx?)
  79. *
  80. * The current interrupt logic looks something like this:
  81. *
  82. * - We install dispatchers for the autovector interrupts (1-7). These
  83. * dispatchers are responsible for querying the hardware (the
  84. * VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using
  85. * this information a machspec interrupt number is generated by placing the
  86. * index of the interrupt hardware into the low three bits and the original
  87. * autovector interrupt number in the upper 5 bits. The handlers for the
  88. * resulting machspec interrupt are then called.
  89. *
  90. * - Nubus is a special case because its interrupts are hidden behind two
  91. * layers of hardware. Nubus interrupts come in as index 1 on VIA #2,
  92. * which translates to IRQ number 17. In this spot we install _another_
  93. * dispatcher. This dispatcher finds the interrupting slot number (9-F) and
  94. * then forms a new machspec interrupt number as above with the slot number
  95. * minus 9 in the low three bits and the pseudo-level 7 in the upper five
  96. * bits. The handlers for this new machspec interrupt number are then
  97. * called. This puts Nubus interrupts into the range 56-62.
  98. *
  99. * - The Baboon interrupts (used on some PowerBooks) are an even more special
  100. * case. They're hidden behind the Nubus slot $C interrupt thus adding a
  101. * third layer of indirection. Why oh why did the Apple engineers do that?
  102. *
  103. * - We support "fast" and "slow" handlers, just like the Amiga port. The
  104. * fast handlers are called first and with all interrupts disabled. They
  105. * are expected to execute quickly (hence the name). The slow handlers are
  106. * called last with interrupts enabled and the interrupt level restored.
  107. * They must therefore be reentrant.
  108. *
  109. * TODO:
  110. *
  111. */
  112. #include <linux/module.h>
  113. #include <linux/types.h>
  114. #include <linux/kernel.h>
  115. #include <linux/sched.h>
  116. #include <linux/kernel_stat.h>
  117. #include <linux/interrupt.h> /* for intr_count */
  118. #include <linux/delay.h>
  119. #include <linux/seq_file.h>
  120. #include <asm/system.h>
  121. #include <asm/irq.h>
  122. #include <asm/traps.h>
  123. #include <asm/bootinfo.h>
  124. #include <asm/macintosh.h>
  125. #include <asm/mac_via.h>
  126. #include <asm/mac_psc.h>
  127. #include <asm/hwtest.h>
  128. #include <asm/errno.h>
  129. #include <asm/macints.h>
  130. #include <asm/irq_regs.h>
  131. #include <asm/mac_oss.h>
  132. #define SHUTUP_SONIC
  133. /*
  134. * VIA/RBV hooks
  135. */
  136. extern void via_register_interrupts(void);
  137. extern void via_irq_enable(int);
  138. extern void via_irq_disable(int);
  139. extern void via_irq_clear(int);
  140. extern int via_irq_pending(int);
  141. /*
  142. * OSS hooks
  143. */
  144. extern void oss_register_interrupts(void);
  145. extern void oss_irq_enable(int);
  146. extern void oss_irq_disable(int);
  147. extern void oss_irq_clear(int);
  148. extern int oss_irq_pending(int);
  149. /*
  150. * PSC hooks
  151. */
  152. extern void psc_register_interrupts(void);
  153. extern void psc_irq_enable(int);
  154. extern void psc_irq_disable(int);
  155. extern void psc_irq_clear(int);
  156. extern int psc_irq_pending(int);
  157. /*
  158. * IOP hooks
  159. */
  160. extern void iop_register_interrupts(void);
  161. /*
  162. * Baboon hooks
  163. */
  164. extern int baboon_present;
  165. extern void baboon_register_interrupts(void);
  166. extern void baboon_irq_enable(int);
  167. extern void baboon_irq_disable(int);
  168. extern void baboon_irq_clear(int);
  169. /*
  170. * console_loglevel determines NMI handler function
  171. */
  172. irqreturn_t mac_nmi_handler(int, void *);
  173. irqreturn_t mac_debug_handler(int, void *);
  174. /* #define DEBUG_MACINTS */
  175. void mac_enable_irq(unsigned int irq);
  176. void mac_disable_irq(unsigned int irq);
  177. static void mac_irq_enable(struct irq_data *data)
  178. {
  179. mac_enable_irq(data->irq);
  180. }
  181. static void mac_irq_disable(struct irq_data *data)
  182. {
  183. mac_disable_irq(data->irq);
  184. }
  185. static struct irq_chip mac_irq_chip = {
  186. .name = "mac",
  187. .irq_enable = mac_irq_enable,
  188. .irq_disable = mac_irq_disable,
  189. };
  190. void __init mac_init_IRQ(void)
  191. {
  192. #ifdef DEBUG_MACINTS
  193. printk("mac_init_IRQ(): Setting things up...\n");
  194. #endif
  195. m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER,
  196. NUM_MAC_SOURCES - IRQ_USER);
  197. /* Make sure the SONIC interrupt is cleared or things get ugly */
  198. #ifdef SHUTUP_SONIC
  199. printk("Killing onboard sonic... ");
  200. /* This address should hopefully be mapped already */
  201. if (hwreg_present((void*)(0x50f0a000))) {
  202. *(long *)(0x50f0a014) = 0x7fffL;
  203. *(long *)(0x50f0a010) = 0L;
  204. }
  205. printk("Done.\n");
  206. #endif /* SHUTUP_SONIC */
  207. /*
  208. * Now register the handlers for the master IRQ handlers
  209. * at levels 1-7. Most of the work is done elsewhere.
  210. */
  211. if (oss_present)
  212. oss_register_interrupts();
  213. else
  214. via_register_interrupts();
  215. if (psc_present)
  216. psc_register_interrupts();
  217. if (baboon_present)
  218. baboon_register_interrupts();
  219. iop_register_interrupts();
  220. if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
  221. mac_nmi_handler))
  222. pr_err("Couldn't register NMI\n");
  223. #ifdef DEBUG_MACINTS
  224. printk("mac_init_IRQ(): Done!\n");
  225. #endif
  226. }
  227. /*
  228. * mac_enable_irq - enable an interrupt source
  229. * mac_disable_irq - disable an interrupt source
  230. * mac_clear_irq - clears a pending interrupt
  231. * mac_pending_irq - Returns the pending status of an IRQ (nonzero = pending)
  232. *
  233. * These routines are just dispatchers to the VIA/OSS/PSC routines.
  234. */
  235. void mac_enable_irq(unsigned int irq)
  236. {
  237. int irq_src = IRQ_SRC(irq);
  238. switch(irq_src) {
  239. case 1:
  240. via_irq_enable(irq);
  241. break;
  242. case 2:
  243. case 7:
  244. if (oss_present)
  245. oss_irq_enable(irq);
  246. else
  247. via_irq_enable(irq);
  248. break;
  249. case 3:
  250. case 5:
  251. case 6:
  252. if (psc_present)
  253. psc_irq_enable(irq);
  254. else if (oss_present)
  255. oss_irq_enable(irq);
  256. break;
  257. case 4:
  258. if (psc_present)
  259. psc_irq_enable(irq);
  260. break;
  261. case 8:
  262. if (baboon_present)
  263. baboon_irq_enable(irq);
  264. break;
  265. }
  266. }
  267. void mac_disable_irq(unsigned int irq)
  268. {
  269. int irq_src = IRQ_SRC(irq);
  270. switch(irq_src) {
  271. case 1:
  272. via_irq_disable(irq);
  273. break;
  274. case 2:
  275. case 7:
  276. if (oss_present)
  277. oss_irq_disable(irq);
  278. else
  279. via_irq_disable(irq);
  280. break;
  281. case 3:
  282. case 5:
  283. case 6:
  284. if (psc_present)
  285. psc_irq_disable(irq);
  286. else if (oss_present)
  287. oss_irq_disable(irq);
  288. break;
  289. case 4:
  290. if (psc_present)
  291. psc_irq_disable(irq);
  292. break;
  293. case 8:
  294. if (baboon_present)
  295. baboon_irq_disable(irq);
  296. break;
  297. }
  298. }
  299. void mac_clear_irq(unsigned int irq)
  300. {
  301. switch(IRQ_SRC(irq)) {
  302. case 1:
  303. via_irq_clear(irq);
  304. break;
  305. case 2:
  306. case 7:
  307. if (oss_present)
  308. oss_irq_clear(irq);
  309. else
  310. via_irq_clear(irq);
  311. break;
  312. case 3:
  313. case 5:
  314. case 6:
  315. if (psc_present)
  316. psc_irq_clear(irq);
  317. else if (oss_present)
  318. oss_irq_clear(irq);
  319. break;
  320. case 4:
  321. if (psc_present)
  322. psc_irq_clear(irq);
  323. break;
  324. case 8:
  325. if (baboon_present)
  326. baboon_irq_clear(irq);
  327. break;
  328. }
  329. }
  330. int mac_irq_pending(unsigned int irq)
  331. {
  332. switch(IRQ_SRC(irq)) {
  333. case 1:
  334. return via_irq_pending(irq);
  335. case 2:
  336. case 7:
  337. if (oss_present)
  338. return oss_irq_pending(irq);
  339. else
  340. return via_irq_pending(irq);
  341. case 3:
  342. case 5:
  343. case 6:
  344. if (psc_present)
  345. return psc_irq_pending(irq);
  346. else if (oss_present)
  347. return oss_irq_pending(irq);
  348. break;
  349. case 4:
  350. if (psc_present)
  351. return psc_irq_pending(irq);
  352. break;
  353. }
  354. return 0;
  355. }
  356. EXPORT_SYMBOL(mac_irq_pending);
  357. static int num_debug[8];
  358. irqreturn_t mac_debug_handler(int irq, void *dev_id)
  359. {
  360. if (num_debug[irq] < 10) {
  361. printk("DEBUG: Unexpected IRQ %d\n", irq);
  362. num_debug[irq]++;
  363. }
  364. return IRQ_HANDLED;
  365. }
  366. static int in_nmi;
  367. static volatile int nmi_hold;
  368. irqreturn_t mac_nmi_handler(int irq, void *dev_id)
  369. {
  370. int i;
  371. /*
  372. * generate debug output on NMI switch if 'debug' kernel option given
  373. * (only works with Penguin!)
  374. */
  375. in_nmi++;
  376. for (i=0; i<100; i++)
  377. udelay(1000);
  378. if (in_nmi == 1) {
  379. nmi_hold = 1;
  380. printk("... pausing, press NMI to resume ...");
  381. } else {
  382. printk(" ok!\n");
  383. nmi_hold = 0;
  384. }
  385. barrier();
  386. while (nmi_hold == 1)
  387. udelay(1000);
  388. if (console_loglevel >= 8) {
  389. #if 0
  390. struct pt_regs *fp = get_irq_regs();
  391. show_state();
  392. printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp);
  393. printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
  394. fp->d0, fp->d1, fp->d2, fp->d3);
  395. printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
  396. fp->d4, fp->d5, fp->a0, fp->a1);
  397. if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
  398. printk("Corrupted stack page\n");
  399. printk("Process %s (pid: %d, stackpage=%08lx)\n",
  400. current->comm, current->pid, current->kernel_stack_page);
  401. if (intr_count == 1)
  402. dump_stack((struct frame *)fp);
  403. #else
  404. /* printk("NMI "); */
  405. #endif
  406. }
  407. in_nmi--;
  408. return IRQ_HANDLED;
  409. }