macints.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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 (slot number determined by reading RR3 on the SSC itself)
  38. * - slot 1: SCC channel A
  39. * - slot 2: SCC channel B
  40. *
  41. * 5 - unused (?)
  42. * [serial errors or special conditions seem to raise level 6
  43. * interrupts on some models (LC4xx?)]
  44. *
  45. * 6 - off switch (?)
  46. *
  47. * For OSS Macintoshes (IIfx only at this point):
  48. *
  49. * 3 - Nubus interrupt
  50. * - slot 0: Slot $9
  51. * - slot 1: Slot $A
  52. * - slot 2: Slot $B
  53. * - slot 3: Slot $C
  54. * - slot 4: Slot $D
  55. * - slot 5: Slot $E
  56. *
  57. * 4 - SCC IOP
  58. * - slot 1: SCC channel A
  59. * - slot 2: SCC channel B
  60. *
  61. * 5 - ISM IOP (ADB?)
  62. *
  63. * 6 - unused
  64. *
  65. * For PSC Macintoshes (660AV, 840AV):
  66. *
  67. * 3 - PSC level 3
  68. * - slot 0: MACE
  69. *
  70. * 4 - PSC level 4
  71. * - slot 1: SCC channel A interrupt
  72. * - slot 2: SCC channel B interrupt
  73. * - slot 3: MACE DMA
  74. *
  75. * 5 - PSC level 5
  76. *
  77. * 6 - PSC level 6
  78. *
  79. * Finally we have good 'ole level 7, the non-maskable interrupt:
  80. *
  81. * 7 - NMI (programmer's switch on the back of some Macs)
  82. * Also RAM parity error on models which support it (IIc, IIfx?)
  83. *
  84. * The current interrupt logic looks something like this:
  85. *
  86. * - We install dispatchers for the autovector interrupts (1-7). These
  87. * dispatchers are responsible for querying the hardware (the
  88. * VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using
  89. * this information a machspec interrupt number is generated by placing the
  90. * index of the interrupt hardware into the low three bits and the original
  91. * autovector interrupt number in the upper 5 bits. The handlers for the
  92. * resulting machspec interrupt are then called.
  93. *
  94. * - Nubus is a special case because its interrupts are hidden behind two
  95. * layers of hardware. Nubus interrupts come in as index 1 on VIA #2,
  96. * which translates to IRQ number 17. In this spot we install _another_
  97. * dispatcher. This dispatcher finds the interrupting slot number (9-F) and
  98. * then forms a new machspec interrupt number as above with the slot number
  99. * minus 9 in the low three bits and the pseudo-level 7 in the upper five
  100. * bits. The handlers for this new machspec interrupt number are then
  101. * called. This puts Nubus interrupts into the range 56-62.
  102. *
  103. * - The Baboon interrupts (used on some PowerBooks) are an even more special
  104. * case. They're hidden behind the Nubus slot $C interrupt thus adding a
  105. * third layer of indirection. Why oh why did the Apple engineers do that?
  106. *
  107. * - We support "fast" and "slow" handlers, just like the Amiga port. The
  108. * fast handlers are called first and with all interrupts disabled. They
  109. * are expected to execute quickly (hence the name). The slow handlers are
  110. * called last with interrupts enabled and the interrupt level restored.
  111. * They must therefore be reentrant.
  112. *
  113. * TODO:
  114. *
  115. */
  116. #include <linux/module.h>
  117. #include <linux/types.h>
  118. #include <linux/kernel.h>
  119. #include <linux/sched.h>
  120. #include <linux/kernel_stat.h>
  121. #include <linux/interrupt.h> /* for intr_count */
  122. #include <linux/delay.h>
  123. #include <linux/seq_file.h>
  124. #include <asm/system.h>
  125. #include <asm/irq.h>
  126. #include <asm/traps.h>
  127. #include <asm/bootinfo.h>
  128. #include <asm/macintosh.h>
  129. #include <asm/mac_via.h>
  130. #include <asm/mac_psc.h>
  131. #include <asm/hwtest.h>
  132. #include <asm/errno.h>
  133. #include <asm/macints.h>
  134. #include <asm/irq_regs.h>
  135. #include <asm/mac_oss.h>
  136. #define DEBUG_SPURIOUS
  137. #define SHUTUP_SONIC
  138. /* SCC interrupt mask */
  139. static int scc_mask;
  140. /*
  141. * VIA/RBV hooks
  142. */
  143. extern void via_register_interrupts(void);
  144. extern void via_irq_enable(int);
  145. extern void via_irq_disable(int);
  146. extern void via_irq_clear(int);
  147. extern int via_irq_pending(int);
  148. /*
  149. * OSS hooks
  150. */
  151. extern void oss_register_interrupts(void);
  152. extern void oss_irq_enable(int);
  153. extern void oss_irq_disable(int);
  154. extern void oss_irq_clear(int);
  155. extern int oss_irq_pending(int);
  156. /*
  157. * PSC hooks
  158. */
  159. extern void psc_register_interrupts(void);
  160. extern void psc_irq_enable(int);
  161. extern void psc_irq_disable(int);
  162. extern void psc_irq_clear(int);
  163. extern int psc_irq_pending(int);
  164. /*
  165. * IOP hooks
  166. */
  167. extern void iop_register_interrupts(void);
  168. /*
  169. * Baboon hooks
  170. */
  171. extern int baboon_present;
  172. extern void baboon_register_interrupts(void);
  173. extern void baboon_irq_enable(int);
  174. extern void baboon_irq_disable(int);
  175. extern void baboon_irq_clear(int);
  176. /*
  177. * SCC interrupt routines
  178. */
  179. static void scc_irq_enable(unsigned int);
  180. static void scc_irq_disable(unsigned int);
  181. /*
  182. * console_loglevel determines NMI handler function
  183. */
  184. irqreturn_t mac_nmi_handler(int, void *);
  185. irqreturn_t mac_debug_handler(int, void *);
  186. /* #define DEBUG_MACINTS */
  187. void mac_enable_irq(unsigned int irq);
  188. void mac_disable_irq(unsigned int irq);
  189. static struct irq_controller mac_irq_controller = {
  190. .name = "mac",
  191. .lock = __SPIN_LOCK_UNLOCKED(mac_irq_controller.lock),
  192. .enable = mac_enable_irq,
  193. .disable = mac_disable_irq,
  194. };
  195. void __init mac_init_IRQ(void)
  196. {
  197. #ifdef DEBUG_MACINTS
  198. printk("mac_init_IRQ(): Setting things up...\n");
  199. #endif
  200. scc_mask = 0;
  201. m68k_setup_irq_controller(&mac_irq_controller, IRQ_USER,
  202. NUM_MAC_SOURCES - IRQ_USER);
  203. /* Make sure the SONIC interrupt is cleared or things get ugly */
  204. #ifdef SHUTUP_SONIC
  205. printk("Killing onboard sonic... ");
  206. /* This address should hopefully be mapped already */
  207. if (hwreg_present((void*)(0x50f0a000))) {
  208. *(long *)(0x50f0a014) = 0x7fffL;
  209. *(long *)(0x50f0a010) = 0L;
  210. }
  211. printk("Done.\n");
  212. #endif /* SHUTUP_SONIC */
  213. /*
  214. * Now register the handlers for the master IRQ handlers
  215. * at levels 1-7. Most of the work is done elsewhere.
  216. */
  217. if (oss_present)
  218. oss_register_interrupts();
  219. else
  220. via_register_interrupts();
  221. if (psc_present)
  222. psc_register_interrupts();
  223. if (baboon_present)
  224. baboon_register_interrupts();
  225. iop_register_interrupts();
  226. if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
  227. mac_nmi_handler))
  228. pr_err("Couldn't register NMI\n");
  229. #ifdef DEBUG_MACINTS
  230. printk("mac_init_IRQ(): Done!\n");
  231. #endif
  232. }
  233. /*
  234. * mac_enable_irq - enable an interrupt source
  235. * mac_disable_irq - disable an interrupt source
  236. * mac_clear_irq - clears a pending interrupt
  237. * mac_pending_irq - Returns the pending status of an IRQ (nonzero = pending)
  238. *
  239. * These routines are just dispatchers to the VIA/OSS/PSC routines.
  240. */
  241. void mac_enable_irq(unsigned int irq)
  242. {
  243. int irq_src = IRQ_SRC(irq);
  244. switch(irq_src) {
  245. case 1:
  246. via_irq_enable(irq);
  247. break;
  248. case 2:
  249. case 7:
  250. if (oss_present)
  251. oss_irq_enable(irq);
  252. else
  253. via_irq_enable(irq);
  254. break;
  255. case 3:
  256. case 4:
  257. case 5:
  258. case 6:
  259. if (psc_present)
  260. psc_irq_enable(irq);
  261. else if (oss_present)
  262. oss_irq_enable(irq);
  263. else if (irq_src == 4)
  264. scc_irq_enable(irq);
  265. break;
  266. case 8:
  267. if (baboon_present)
  268. baboon_irq_enable(irq);
  269. break;
  270. }
  271. }
  272. void mac_disable_irq(unsigned int irq)
  273. {
  274. int irq_src = IRQ_SRC(irq);
  275. switch(irq_src) {
  276. case 1:
  277. via_irq_disable(irq);
  278. break;
  279. case 2:
  280. case 7:
  281. if (oss_present)
  282. oss_irq_disable(irq);
  283. else
  284. via_irq_disable(irq);
  285. break;
  286. case 3:
  287. case 4:
  288. case 5:
  289. case 6:
  290. if (psc_present)
  291. psc_irq_disable(irq);
  292. else if (oss_present)
  293. oss_irq_disable(irq);
  294. else if (irq_src == 4)
  295. scc_irq_disable(irq);
  296. break;
  297. case 8:
  298. if (baboon_present)
  299. baboon_irq_disable(irq);
  300. break;
  301. }
  302. }
  303. void mac_clear_irq(unsigned int irq)
  304. {
  305. switch(IRQ_SRC(irq)) {
  306. case 1:
  307. via_irq_clear(irq);
  308. break;
  309. case 2:
  310. case 7:
  311. if (oss_present)
  312. oss_irq_clear(irq);
  313. else
  314. via_irq_clear(irq);
  315. break;
  316. case 3:
  317. case 4:
  318. case 5:
  319. case 6:
  320. if (psc_present)
  321. psc_irq_clear(irq);
  322. else if (oss_present)
  323. oss_irq_clear(irq);
  324. break;
  325. case 8:
  326. if (baboon_present)
  327. baboon_irq_clear(irq);
  328. break;
  329. }
  330. }
  331. int mac_irq_pending(unsigned int irq)
  332. {
  333. switch(IRQ_SRC(irq)) {
  334. case 1:
  335. return via_irq_pending(irq);
  336. case 2:
  337. case 7:
  338. if (oss_present)
  339. return oss_irq_pending(irq);
  340. else
  341. return via_irq_pending(irq);
  342. case 3:
  343. case 4:
  344. case 5:
  345. case 6:
  346. if (psc_present)
  347. return psc_irq_pending(irq);
  348. else if (oss_present)
  349. return oss_irq_pending(irq);
  350. }
  351. return 0;
  352. }
  353. EXPORT_SYMBOL(mac_irq_pending);
  354. static int num_debug[8];
  355. irqreturn_t mac_debug_handler(int irq, void *dev_id)
  356. {
  357. if (num_debug[irq] < 10) {
  358. printk("DEBUG: Unexpected IRQ %d\n", irq);
  359. num_debug[irq]++;
  360. }
  361. return IRQ_HANDLED;
  362. }
  363. static int in_nmi;
  364. static volatile int nmi_hold;
  365. irqreturn_t mac_nmi_handler(int irq, void *dev_id)
  366. {
  367. int i;
  368. /*
  369. * generate debug output on NMI switch if 'debug' kernel option given
  370. * (only works with Penguin!)
  371. */
  372. in_nmi++;
  373. for (i=0; i<100; i++)
  374. udelay(1000);
  375. if (in_nmi == 1) {
  376. nmi_hold = 1;
  377. printk("... pausing, press NMI to resume ...");
  378. } else {
  379. printk(" ok!\n");
  380. nmi_hold = 0;
  381. }
  382. barrier();
  383. while (nmi_hold == 1)
  384. udelay(1000);
  385. if (console_loglevel >= 8) {
  386. #if 0
  387. struct pt_regs *fp = get_irq_regs();
  388. show_state();
  389. printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp);
  390. printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
  391. fp->d0, fp->d1, fp->d2, fp->d3);
  392. printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
  393. fp->d4, fp->d5, fp->a0, fp->a1);
  394. if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
  395. printk("Corrupted stack page\n");
  396. printk("Process %s (pid: %d, stackpage=%08lx)\n",
  397. current->comm, current->pid, current->kernel_stack_page);
  398. if (intr_count == 1)
  399. dump_stack((struct frame *)fp);
  400. #else
  401. /* printk("NMI "); */
  402. #endif
  403. }
  404. in_nmi--;
  405. return IRQ_HANDLED;
  406. }
  407. /*
  408. * Simple routines for masking and unmasking
  409. * SCC interrupts in cases where this can't be
  410. * done in hardware (only the PSC can do that.)
  411. */
  412. static void scc_irq_enable(unsigned int irq)
  413. {
  414. int irq_idx = IRQ_IDX(irq);
  415. scc_mask |= (1 << irq_idx);
  416. }
  417. static void scc_irq_disable(unsigned int irq)
  418. {
  419. int irq_idx = IRQ_IDX(irq);
  420. scc_mask &= ~(1 << irq_idx);
  421. }
  422. /*
  423. * SCC master interrupt handler. We have to do a bit of magic here
  424. * to figure out what channel gave us the interrupt; putting this
  425. * here is cleaner than hacking it into drivers/char/macserial.c.
  426. */
  427. void mac_scc_dispatch(int irq, void *dev_id)
  428. {
  429. volatile unsigned char *scc = (unsigned char *) mac_bi_data.sccbase + 2;
  430. unsigned char reg;
  431. unsigned long flags;
  432. /* Read RR3 from the chip. Always do this on channel A */
  433. /* This must be an atomic operation so disable irqs. */
  434. local_irq_save(flags);
  435. *scc = 3;
  436. reg = *scc;
  437. local_irq_restore(flags);
  438. /* Now dispatch. Bits 0-2 are for channel B and */
  439. /* bits 3-5 are for channel A. We can safely */
  440. /* ignore the remaining bits here. */
  441. /* */
  442. /* Note that we're ignoring scc_mask for now. */
  443. /* If we actually mask the ints then we tend to */
  444. /* get hammered by very persistent SCC irqs, */
  445. /* and since they're autovector interrupts they */
  446. /* pretty much kill the system. */
  447. if (reg & 0x38)
  448. m68k_handle_int(IRQ_SCCA);
  449. if (reg & 0x07)
  450. m68k_handle_int(IRQ_SCCB);
  451. }