macints.c 12 KB

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