macints.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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/machw.h>
  129. #include <asm/macintosh.h>
  130. #include <asm/mac_via.h>
  131. #include <asm/mac_psc.h>
  132. #include <asm/hwtest.h>
  133. #include <asm/errno.h>
  134. #include <asm/macints.h>
  135. #include <asm/irq_regs.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_init(void);
  144. extern void via_register_interrupts(void);
  145. extern void via_irq_enable(int);
  146. extern void via_irq_disable(int);
  147. extern void via_irq_clear(int);
  148. extern int via_irq_pending(int);
  149. /*
  150. * OSS hooks
  151. */
  152. extern int oss_present;
  153. extern void oss_init(void);
  154. extern void oss_register_interrupts(void);
  155. extern void oss_irq_enable(int);
  156. extern void oss_irq_disable(int);
  157. extern void oss_irq_clear(int);
  158. extern int oss_irq_pending(int);
  159. /*
  160. * PSC hooks
  161. */
  162. extern int psc_present;
  163. extern void psc_init(void);
  164. extern void psc_register_interrupts(void);
  165. extern void psc_irq_enable(int);
  166. extern void psc_irq_disable(int);
  167. extern void psc_irq_clear(int);
  168. extern int psc_irq_pending(int);
  169. /*
  170. * IOP hooks
  171. */
  172. extern void iop_register_interrupts(void);
  173. /*
  174. * Baboon hooks
  175. */
  176. extern int baboon_present;
  177. extern void baboon_init(void);
  178. extern void baboon_register_interrupts(void);
  179. extern void baboon_irq_enable(int);
  180. extern void baboon_irq_disable(int);
  181. extern void baboon_irq_clear(int);
  182. extern int baboon_irq_pending(int);
  183. /*
  184. * SCC interrupt routines
  185. */
  186. static void scc_irq_enable(unsigned int);
  187. static void scc_irq_disable(unsigned int);
  188. /*
  189. * console_loglevel determines NMI handler function
  190. */
  191. irqreturn_t mac_nmi_handler(int, void *);
  192. irqreturn_t mac_debug_handler(int, void *);
  193. /* #define DEBUG_MACINTS */
  194. static void mac_enable_irq(unsigned int irq);
  195. static void mac_disable_irq(unsigned int irq);
  196. static struct irq_controller mac_irq_controller = {
  197. .name = "mac",
  198. .lock = __SPIN_LOCK_UNLOCKED(mac_irq_controller.lock),
  199. .enable = mac_enable_irq,
  200. .disable = mac_disable_irq,
  201. };
  202. void __init mac_init_IRQ(void)
  203. {
  204. #ifdef DEBUG_MACINTS
  205. printk("mac_init_IRQ(): Setting things up...\n");
  206. #endif
  207. scc_mask = 0;
  208. m68k_setup_irq_controller(&mac_irq_controller, IRQ_USER,
  209. NUM_MAC_SOURCES - IRQ_USER);
  210. /* Make sure the SONIC interrupt is cleared or things get ugly */
  211. #ifdef SHUTUP_SONIC
  212. printk("Killing onboard sonic... ");
  213. /* This address should hopefully be mapped already */
  214. if (hwreg_present((void*)(0x50f0a000))) {
  215. *(long *)(0x50f0a014) = 0x7fffL;
  216. *(long *)(0x50f0a010) = 0L;
  217. }
  218. printk("Done.\n");
  219. #endif /* SHUTUP_SONIC */
  220. /*
  221. * Now register the handlers for the master IRQ handlers
  222. * at levels 1-7. Most of the work is done elsewhere.
  223. */
  224. if (oss_present)
  225. oss_register_interrupts();
  226. else
  227. via_register_interrupts();
  228. if (psc_present)
  229. psc_register_interrupts();
  230. if (baboon_present)
  231. baboon_register_interrupts();
  232. iop_register_interrupts();
  233. request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
  234. mac_nmi_handler);
  235. #ifdef DEBUG_MACINTS
  236. printk("mac_init_IRQ(): Done!\n");
  237. #endif
  238. }
  239. /*
  240. * mac_enable_irq - enable an interrupt source
  241. * mac_disable_irq - disable an interrupt source
  242. * mac_clear_irq - clears a pending interrupt
  243. * mac_pending_irq - Returns the pending status of an IRQ (nonzero = pending)
  244. *
  245. * These routines are just dispatchers to the VIA/OSS/PSC routines.
  246. */
  247. static void mac_enable_irq(unsigned int irq)
  248. {
  249. int irq_src = IRQ_SRC(irq);
  250. switch(irq_src) {
  251. case 1:
  252. via_irq_enable(irq);
  253. break;
  254. case 2:
  255. case 7:
  256. if (oss_present)
  257. oss_irq_enable(irq);
  258. else
  259. via_irq_enable(irq);
  260. break;
  261. case 3:
  262. case 4:
  263. case 5:
  264. case 6:
  265. if (psc_present)
  266. psc_irq_enable(irq);
  267. else if (oss_present)
  268. oss_irq_enable(irq);
  269. else if (irq_src == 4)
  270. scc_irq_enable(irq);
  271. break;
  272. case 8:
  273. if (baboon_present)
  274. baboon_irq_enable(irq);
  275. break;
  276. }
  277. }
  278. static void mac_disable_irq(unsigned int irq)
  279. {
  280. int irq_src = IRQ_SRC(irq);
  281. switch(irq_src) {
  282. case 1:
  283. via_irq_disable(irq);
  284. break;
  285. case 2:
  286. case 7:
  287. if (oss_present)
  288. oss_irq_disable(irq);
  289. else
  290. via_irq_disable(irq);
  291. break;
  292. case 3:
  293. case 4:
  294. case 5:
  295. case 6:
  296. if (psc_present)
  297. psc_irq_disable(irq);
  298. else if (oss_present)
  299. oss_irq_disable(irq);
  300. else if (irq_src == 4)
  301. scc_irq_disable(irq);
  302. break;
  303. case 8:
  304. if (baboon_present)
  305. baboon_irq_disable(irq);
  306. break;
  307. }
  308. }
  309. void mac_clear_irq(unsigned int irq)
  310. {
  311. switch(IRQ_SRC(irq)) {
  312. case 1:
  313. via_irq_clear(irq);
  314. break;
  315. case 2:
  316. case 7:
  317. if (oss_present)
  318. oss_irq_clear(irq);
  319. else
  320. via_irq_clear(irq);
  321. break;
  322. case 3:
  323. case 4:
  324. case 5:
  325. case 6:
  326. if (psc_present)
  327. psc_irq_clear(irq);
  328. else if (oss_present)
  329. oss_irq_clear(irq);
  330. break;
  331. case 8:
  332. if (baboon_present)
  333. baboon_irq_clear(irq);
  334. break;
  335. }
  336. }
  337. int mac_irq_pending(unsigned int irq)
  338. {
  339. switch(IRQ_SRC(irq)) {
  340. case 1:
  341. return via_irq_pending(irq);
  342. case 2:
  343. case 7:
  344. if (oss_present)
  345. return oss_irq_pending(irq);
  346. else
  347. return via_irq_pending(irq);
  348. case 3:
  349. case 4:
  350. case 5:
  351. case 6:
  352. if (psc_present)
  353. return psc_irq_pending(irq);
  354. else if (oss_present)
  355. return oss_irq_pending(irq);
  356. }
  357. return 0;
  358. }
  359. EXPORT_SYMBOL(mac_irq_pending);
  360. static int num_debug[8];
  361. irqreturn_t mac_debug_handler(int irq, void *dev_id)
  362. {
  363. if (num_debug[irq] < 10) {
  364. printk("DEBUG: Unexpected IRQ %d\n", irq);
  365. num_debug[irq]++;
  366. }
  367. return IRQ_HANDLED;
  368. }
  369. static int in_nmi;
  370. static volatile int nmi_hold;
  371. irqreturn_t mac_nmi_handler(int irq, void *dev_id)
  372. {
  373. int i;
  374. /*
  375. * generate debug output on NMI switch if 'debug' kernel option given
  376. * (only works with Penguin!)
  377. */
  378. in_nmi++;
  379. for (i=0; i<100; i++)
  380. udelay(1000);
  381. if (in_nmi == 1) {
  382. nmi_hold = 1;
  383. printk("... pausing, press NMI to resume ...");
  384. } else {
  385. printk(" ok!\n");
  386. nmi_hold = 0;
  387. }
  388. barrier();
  389. while (nmi_hold == 1)
  390. udelay(1000);
  391. if (console_loglevel >= 8) {
  392. #if 0
  393. struct pt_regs *fp = get_irq_regs();
  394. show_state();
  395. printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp);
  396. printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
  397. fp->d0, fp->d1, fp->d2, fp->d3);
  398. printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
  399. fp->d4, fp->d5, fp->a0, fp->a1);
  400. if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
  401. printk("Corrupted stack page\n");
  402. printk("Process %s (pid: %d, stackpage=%08lx)\n",
  403. current->comm, current->pid, current->kernel_stack_page);
  404. if (intr_count == 1)
  405. dump_stack((struct frame *)fp);
  406. #else
  407. /* printk("NMI "); */
  408. #endif
  409. }
  410. in_nmi--;
  411. return IRQ_HANDLED;
  412. }
  413. /*
  414. * Simple routines for masking and unmasking
  415. * SCC interrupts in cases where this can't be
  416. * done in hardware (only the PSC can do that.)
  417. */
  418. static void scc_irq_enable(unsigned int irq)
  419. {
  420. int irq_idx = IRQ_IDX(irq);
  421. scc_mask |= (1 << irq_idx);
  422. }
  423. static void scc_irq_disable(unsigned int irq)
  424. {
  425. int irq_idx = IRQ_IDX(irq);
  426. scc_mask &= ~(1 << irq_idx);
  427. }
  428. /*
  429. * SCC master interrupt handler. We have to do a bit of magic here
  430. * to figure out what channel gave us the interrupt; putting this
  431. * here is cleaner than hacking it into drivers/char/macserial.c.
  432. */
  433. void mac_scc_dispatch(int irq, void *dev_id)
  434. {
  435. volatile unsigned char *scc = (unsigned char *) mac_bi_data.sccbase + 2;
  436. unsigned char reg;
  437. unsigned long flags;
  438. /* Read RR3 from the chip. Always do this on channel A */
  439. /* This must be an atomic operation so disable irqs. */
  440. local_irq_save(flags);
  441. *scc = 3;
  442. reg = *scc;
  443. local_irq_restore(flags);
  444. /* Now dispatch. Bits 0-2 are for channel B and */
  445. /* bits 3-5 are for channel A. We can safely */
  446. /* ignore the remaining bits here. */
  447. /* */
  448. /* Note that we're ignoring scc_mask for now. */
  449. /* If we actually mask the ints then we tend to */
  450. /* get hammered by very persistent SCC irqs, */
  451. /* and since they're autovector interrupts they */
  452. /* pretty much kill the system. */
  453. if (reg & 0x38)
  454. m68k_handle_int(IRQ_SCCA);
  455. if (reg & 0x07)
  456. m68k_handle_int(IRQ_SCCB);
  457. }