xref: /linux/arch/m68k/mac/macints.c (revision 9c5f4afdfbe72d5d1c814ad7286a4524d00c7b96)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *	Macintosh interrupts
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * General design:
51da177e4SLinus Torvalds  * In contrary to the Amiga and Atari platforms, the Mac hardware seems to
61da177e4SLinus Torvalds  * exclusively use the autovector interrupts (the 'generic level0-level7'
71da177e4SLinus Torvalds  * interrupts with exception vectors 0x19-0x1f). The following interrupt levels
81da177e4SLinus Torvalds  * are used:
91da177e4SLinus Torvalds  *	1	- VIA1
101da177e4SLinus Torvalds  *		  - slot 0: one second interrupt (CA2)
111da177e4SLinus Torvalds  *		  - slot 1: VBlank (CA1)
121da177e4SLinus Torvalds  *		  - slot 2: ADB data ready (SR full)
131da177e4SLinus Torvalds  *		  - slot 3: ADB data  (CB2)
141da177e4SLinus Torvalds  *		  - slot 4: ADB clock (CB1)
151da177e4SLinus Torvalds  *		  - slot 5: timer 2
161da177e4SLinus Torvalds  *		  - slot 6: timer 1
171da177e4SLinus Torvalds  *		  - slot 7: status of IRQ; signals 'any enabled int.'
181da177e4SLinus Torvalds  *
191da177e4SLinus Torvalds  *	2	- VIA2 or RBV
201da177e4SLinus Torvalds  *		  - slot 0: SCSI DRQ (CA2)
211da177e4SLinus Torvalds  *		  - slot 1: NUBUS IRQ (CA1) need to read port A to find which
221da177e4SLinus Torvalds  *		  - slot 2: /EXP IRQ (only on IIci)
231da177e4SLinus Torvalds  *		  - slot 3: SCSI IRQ (CB2)
241da177e4SLinus Torvalds  *		  - slot 4: ASC IRQ (CB1)
251da177e4SLinus Torvalds  *		  - slot 5: timer 2 (not on IIci)
261da177e4SLinus Torvalds  *		  - slot 6: timer 1 (not on IIci)
271da177e4SLinus Torvalds  *		  - slot 7: status of IRQ; signals 'any enabled int.'
281da177e4SLinus Torvalds  *
291da177e4SLinus Torvalds  *	2	- OSS (IIfx only?)
301da177e4SLinus Torvalds  *		  - slot 0: SCSI interrupt
311da177e4SLinus Torvalds  *		  - slot 1: Sound interrupt
321da177e4SLinus Torvalds  *
331da177e4SLinus Torvalds  * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes:
341da177e4SLinus Torvalds  *
351da177e4SLinus Torvalds  *	3	- unused (?)
361da177e4SLinus Torvalds  *
371da177e4SLinus Torvalds  *	4	- SCC (slot number determined by reading RR3 on the SSC itself)
381da177e4SLinus Torvalds  *		  - slot 1: SCC channel A
391da177e4SLinus Torvalds  *		  - slot 2: SCC channel B
401da177e4SLinus Torvalds  *
411da177e4SLinus Torvalds  *	5	- unused (?)
421da177e4SLinus Torvalds  *		  [serial errors or special conditions seem to raise level 6
431da177e4SLinus Torvalds  *		  interrupts on some models (LC4xx?)]
441da177e4SLinus Torvalds  *
451da177e4SLinus Torvalds  *	6	- off switch (?)
461da177e4SLinus Torvalds  *
471da177e4SLinus Torvalds  * For OSS Macintoshes (IIfx only at this point):
481da177e4SLinus Torvalds  *
491da177e4SLinus Torvalds  *	3	- Nubus interrupt
501da177e4SLinus Torvalds  *		  - slot 0: Slot $9
511da177e4SLinus Torvalds  *		  - slot 1: Slot $A
521da177e4SLinus Torvalds  *		  - slot 2: Slot $B
531da177e4SLinus Torvalds  *		  - slot 3: Slot $C
541da177e4SLinus Torvalds  *		  - slot 4: Slot $D
551da177e4SLinus Torvalds  *		  - slot 5: Slot $E
561da177e4SLinus Torvalds  *
571da177e4SLinus Torvalds  *	4	- SCC IOP
581da177e4SLinus Torvalds  *		  - slot 1: SCC channel A
591da177e4SLinus Torvalds  *		  - slot 2: SCC channel B
601da177e4SLinus Torvalds  *
611da177e4SLinus Torvalds  *	5	- ISM IOP (ADB?)
621da177e4SLinus Torvalds  *
631da177e4SLinus Torvalds  *	6	- unused
641da177e4SLinus Torvalds  *
651da177e4SLinus Torvalds  * For PSC Macintoshes (660AV, 840AV):
661da177e4SLinus Torvalds  *
671da177e4SLinus Torvalds  *	3	- PSC level 3
681da177e4SLinus Torvalds  *		  - slot 0: MACE
691da177e4SLinus Torvalds  *
701da177e4SLinus Torvalds  *	4	- PSC level 4
711da177e4SLinus Torvalds  *		  - slot 1: SCC channel A interrupt
721da177e4SLinus Torvalds  *		  - slot 2: SCC channel B interrupt
731da177e4SLinus Torvalds  *		  - slot 3: MACE DMA
741da177e4SLinus Torvalds  *
751da177e4SLinus Torvalds  *	5	- PSC level 5
761da177e4SLinus Torvalds  *
771da177e4SLinus Torvalds  *	6	- PSC level 6
781da177e4SLinus Torvalds  *
791da177e4SLinus Torvalds  * Finally we have good 'ole level 7, the non-maskable interrupt:
801da177e4SLinus Torvalds  *
811da177e4SLinus Torvalds  *	7	- NMI (programmer's switch on the back of some Macs)
821da177e4SLinus Torvalds  *		  Also RAM parity error on models which support it (IIc, IIfx?)
831da177e4SLinus Torvalds  *
841da177e4SLinus Torvalds  * The current interrupt logic looks something like this:
851da177e4SLinus Torvalds  *
861da177e4SLinus Torvalds  * - We install dispatchers for the autovector interrupts (1-7). These
871da177e4SLinus Torvalds  *   dispatchers are responsible for querying the hardware (the
881da177e4SLinus Torvalds  *   VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using
891da177e4SLinus Torvalds  *   this information a machspec interrupt number is generated by placing the
901da177e4SLinus Torvalds  *   index of the interrupt hardware into the low three bits and the original
911da177e4SLinus Torvalds  *   autovector interrupt number in the upper 5 bits. The handlers for the
921da177e4SLinus Torvalds  *   resulting machspec interrupt are then called.
931da177e4SLinus Torvalds  *
941da177e4SLinus Torvalds  * - Nubus is a special case because its interrupts are hidden behind two
951da177e4SLinus Torvalds  *   layers of hardware. Nubus interrupts come in as index 1 on VIA #2,
961da177e4SLinus Torvalds  *   which translates to IRQ number 17. In this spot we install _another_
971da177e4SLinus Torvalds  *   dispatcher. This dispatcher finds the interrupting slot number (9-F) and
981da177e4SLinus Torvalds  *   then forms a new machspec interrupt number as above with the slot number
991da177e4SLinus Torvalds  *   minus 9 in the low three bits and the pseudo-level 7 in the upper five
1001da177e4SLinus Torvalds  *   bits.  The handlers for this new machspec interrupt number are then
1011da177e4SLinus Torvalds  *   called. This puts Nubus interrupts into the range 56-62.
1021da177e4SLinus Torvalds  *
1031da177e4SLinus Torvalds  * - The Baboon interrupts (used on some PowerBooks) are an even more special
1041da177e4SLinus Torvalds  *   case. They're hidden behind the Nubus slot $C interrupt thus adding a
1051da177e4SLinus Torvalds  *   third layer of indirection. Why oh why did the Apple engineers do that?
1061da177e4SLinus Torvalds  *
1071da177e4SLinus Torvalds  * - We support "fast" and "slow" handlers, just like the Amiga port. The
1081da177e4SLinus Torvalds  *   fast handlers are called first and with all interrupts disabled. They
1091da177e4SLinus Torvalds  *   are expected to execute quickly (hence the name). The slow handlers are
1101da177e4SLinus Torvalds  *   called last with interrupts enabled and the interrupt level restored.
1111da177e4SLinus Torvalds  *   They must therefore be reentrant.
1121da177e4SLinus Torvalds  *
1131da177e4SLinus Torvalds  *   TODO:
1141da177e4SLinus Torvalds  *
1151da177e4SLinus Torvalds  */
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds #include <linux/types.h>
1181da177e4SLinus Torvalds #include <linux/kernel.h>
1191da177e4SLinus Torvalds #include <linux/sched.h>
1201da177e4SLinus Torvalds #include <linux/kernel_stat.h>
1211da177e4SLinus Torvalds #include <linux/interrupt.h> /* for intr_count */
1221da177e4SLinus Torvalds #include <linux/delay.h>
1231da177e4SLinus Torvalds #include <linux/seq_file.h>
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds #include <asm/system.h>
1261da177e4SLinus Torvalds #include <asm/irq.h>
1271da177e4SLinus Torvalds #include <asm/traps.h>
1281da177e4SLinus Torvalds #include <asm/bootinfo.h>
1291da177e4SLinus Torvalds #include <asm/machw.h>
1301da177e4SLinus Torvalds #include <asm/macintosh.h>
1311da177e4SLinus Torvalds #include <asm/mac_via.h>
1321da177e4SLinus Torvalds #include <asm/mac_psc.h>
1331da177e4SLinus Torvalds #include <asm/hwtest.h>
1341da177e4SLinus Torvalds #include <asm/errno.h>
1351da177e4SLinus Torvalds #include <asm/macints.h>
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds #define DEBUG_SPURIOUS
1381da177e4SLinus Torvalds #define SHUTUP_SONIC
1391da177e4SLinus Torvalds 
1401da177e4SLinus Torvalds /* SCC interrupt mask */
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds static int scc_mask;
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds /*
1451da177e4SLinus Torvalds  * VIA/RBV hooks
1461da177e4SLinus Torvalds  */
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds extern void via_init(void);
1491da177e4SLinus Torvalds extern void via_register_interrupts(void);
1501da177e4SLinus Torvalds extern void via_irq_enable(int);
1511da177e4SLinus Torvalds extern void via_irq_disable(int);
1521da177e4SLinus Torvalds extern void via_irq_clear(int);
1531da177e4SLinus Torvalds extern int  via_irq_pending(int);
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds /*
1561da177e4SLinus Torvalds  * OSS hooks
1571da177e4SLinus Torvalds  */
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds extern int oss_present;
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds extern void oss_init(void);
1621da177e4SLinus Torvalds extern void oss_register_interrupts(void);
1631da177e4SLinus Torvalds extern void oss_irq_enable(int);
1641da177e4SLinus Torvalds extern void oss_irq_disable(int);
1651da177e4SLinus Torvalds extern void oss_irq_clear(int);
1661da177e4SLinus Torvalds extern int  oss_irq_pending(int);
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds /*
1691da177e4SLinus Torvalds  * PSC hooks
1701da177e4SLinus Torvalds  */
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds extern int psc_present;
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds extern void psc_init(void);
1751da177e4SLinus Torvalds extern void psc_register_interrupts(void);
1761da177e4SLinus Torvalds extern void psc_irq_enable(int);
1771da177e4SLinus Torvalds extern void psc_irq_disable(int);
1781da177e4SLinus Torvalds extern void psc_irq_clear(int);
1791da177e4SLinus Torvalds extern int  psc_irq_pending(int);
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds /*
1821da177e4SLinus Torvalds  * IOP hooks
1831da177e4SLinus Torvalds  */
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds extern void iop_register_interrupts(void);
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds /*
1881da177e4SLinus Torvalds  * Baboon hooks
1891da177e4SLinus Torvalds  */
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds extern int baboon_present;
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds extern void baboon_init(void);
1941da177e4SLinus Torvalds extern void baboon_register_interrupts(void);
1951da177e4SLinus Torvalds extern void baboon_irq_enable(int);
1961da177e4SLinus Torvalds extern void baboon_irq_disable(int);
1971da177e4SLinus Torvalds extern void baboon_irq_clear(int);
1981da177e4SLinus Torvalds extern int  baboon_irq_pending(int);
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds /*
2011da177e4SLinus Torvalds  * SCC interrupt routines
2021da177e4SLinus Torvalds  */
2031da177e4SLinus Torvalds 
204*9c5f4afdSRoman Zippel static void scc_irq_enable(unsigned int);
205*9c5f4afdSRoman Zippel static void scc_irq_disable(unsigned int);
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds /*
2081da177e4SLinus Torvalds  * console_loglevel determines NMI handler function
2091da177e4SLinus Torvalds  */
2101da177e4SLinus Torvalds 
2111da177e4SLinus Torvalds irqreturn_t mac_nmi_handler(int, void *, struct pt_regs *);
2121da177e4SLinus Torvalds irqreturn_t mac_debug_handler(int, void *, struct pt_regs *);
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds /* #define DEBUG_MACINTS */
2151da177e4SLinus Torvalds 
216*9c5f4afdSRoman Zippel static void mac_enable_irq(unsigned int irq);
217*9c5f4afdSRoman Zippel static void mac_disable_irq(unsigned int irq);
218*9c5f4afdSRoman Zippel 
219*9c5f4afdSRoman Zippel static struct irq_controller mac_irq_controller = {
220*9c5f4afdSRoman Zippel 	.name		= "mac",
221*9c5f4afdSRoman Zippel 	.lock		= SPIN_LOCK_UNLOCKED,
222*9c5f4afdSRoman Zippel 	.enable		= mac_enable_irq,
223*9c5f4afdSRoman Zippel 	.disable	= mac_disable_irq,
224*9c5f4afdSRoman Zippel };
225*9c5f4afdSRoman Zippel 
2261da177e4SLinus Torvalds void mac_init_IRQ(void)
2271da177e4SLinus Torvalds {
2281da177e4SLinus Torvalds #ifdef DEBUG_MACINTS
2291da177e4SLinus Torvalds 	printk("mac_init_IRQ(): Setting things up...\n");
2301da177e4SLinus Torvalds #endif
2311da177e4SLinus Torvalds 	scc_mask = 0;
2321da177e4SLinus Torvalds 
233*9c5f4afdSRoman Zippel 	m68k_setup_irq_controller(&mac_irq_controller, IRQ_USER,
234*9c5f4afdSRoman Zippel 				  NUM_MAC_SOURCES - IRQ_USER);
2351da177e4SLinus Torvalds 	/* Make sure the SONIC interrupt is cleared or things get ugly */
2361da177e4SLinus Torvalds #ifdef SHUTUP_SONIC
2371da177e4SLinus Torvalds 	printk("Killing onboard sonic... ");
2381da177e4SLinus Torvalds 	/* This address should hopefully be mapped already */
2391da177e4SLinus Torvalds 	if (hwreg_present((void*)(0x50f0a000))) {
2401da177e4SLinus Torvalds 		*(long *)(0x50f0a014) = 0x7fffL;
2411da177e4SLinus Torvalds 		*(long *)(0x50f0a010) = 0L;
2421da177e4SLinus Torvalds 	}
2431da177e4SLinus Torvalds 	printk("Done.\n");
2441da177e4SLinus Torvalds #endif /* SHUTUP_SONIC */
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds 	/*
2471da177e4SLinus Torvalds 	 * Now register the handlers for the master IRQ handlers
2481da177e4SLinus Torvalds 	 * at levels 1-7. Most of the work is done elsewhere.
2491da177e4SLinus Torvalds 	 */
2501da177e4SLinus Torvalds 
251*9c5f4afdSRoman Zippel 	if (oss_present)
2521da177e4SLinus Torvalds 		oss_register_interrupts();
253*9c5f4afdSRoman Zippel 	else
2541da177e4SLinus Torvalds 		via_register_interrupts();
255*9c5f4afdSRoman Zippel 	if (psc_present)
256*9c5f4afdSRoman Zippel 		psc_register_interrupts();
257*9c5f4afdSRoman Zippel 	if (baboon_present)
258*9c5f4afdSRoman Zippel 		baboon_register_interrupts();
2591da177e4SLinus Torvalds 	iop_register_interrupts();
260*9c5f4afdSRoman Zippel 	request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
2611da177e4SLinus Torvalds 			mac_nmi_handler);
2621da177e4SLinus Torvalds #ifdef DEBUG_MACINTS
2631da177e4SLinus Torvalds 	printk("mac_init_IRQ(): Done!\n");
2641da177e4SLinus Torvalds #endif
2651da177e4SLinus Torvalds }
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds /*
2681da177e4SLinus Torvalds  *  mac_enable_irq - enable an interrupt source
2691da177e4SLinus Torvalds  * mac_disable_irq - disable an interrupt source
2701da177e4SLinus Torvalds  *   mac_clear_irq - clears a pending interrupt
2711da177e4SLinus Torvalds  * mac_pending_irq - Returns the pending status of an IRQ (nonzero = pending)
2721da177e4SLinus Torvalds  *
2731da177e4SLinus Torvalds  * These routines are just dispatchers to the VIA/OSS/PSC routines.
2741da177e4SLinus Torvalds  */
2751da177e4SLinus Torvalds 
276*9c5f4afdSRoman Zippel static void mac_enable_irq(unsigned int irq)
2771da177e4SLinus Torvalds {
2781da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
2791da177e4SLinus Torvalds 
2801da177e4SLinus Torvalds 	switch(irq_src) {
281*9c5f4afdSRoman Zippel 	case 1:
2821da177e4SLinus Torvalds 		via_irq_enable(irq);
283*9c5f4afdSRoman Zippel 		break;
284*9c5f4afdSRoman Zippel 	case 2:
285*9c5f4afdSRoman Zippel 	case 7:
286*9c5f4afdSRoman Zippel 		if (oss_present)
287*9c5f4afdSRoman Zippel 			oss_irq_enable(irq);
288*9c5f4afdSRoman Zippel 		else
289*9c5f4afdSRoman Zippel 			via_irq_enable(irq);
2901da177e4SLinus Torvalds 		break;
2911da177e4SLinus Torvalds 	case 3:
2921da177e4SLinus Torvalds 	case 4:
2931da177e4SLinus Torvalds 	case 5:
294*9c5f4afdSRoman Zippel 	case 6:
295*9c5f4afdSRoman Zippel 		if (psc_present)
2961da177e4SLinus Torvalds 			psc_irq_enable(irq);
297*9c5f4afdSRoman Zippel 		else if (oss_present)
2981da177e4SLinus Torvalds 			oss_irq_enable(irq);
299*9c5f4afdSRoman Zippel 		else if (irq_src == 4)
3001da177e4SLinus Torvalds 			scc_irq_enable(irq);
3011da177e4SLinus Torvalds 		break;
302*9c5f4afdSRoman Zippel 	case 8:
303*9c5f4afdSRoman Zippel 		if (baboon_present)
3041da177e4SLinus Torvalds 			baboon_irq_enable(irq);
3051da177e4SLinus Torvalds 		break;
3061da177e4SLinus Torvalds 	}
3071da177e4SLinus Torvalds }
3081da177e4SLinus Torvalds 
309*9c5f4afdSRoman Zippel static void mac_disable_irq(unsigned int irq)
3101da177e4SLinus Torvalds {
3111da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds 	switch(irq_src) {
314*9c5f4afdSRoman Zippel 	case 1:
315*9c5f4afdSRoman Zippel 		via_irq_disable(irq);
3161da177e4SLinus Torvalds 		break;
3171da177e4SLinus Torvalds 	case 2:
318*9c5f4afdSRoman Zippel 	case 7:
319*9c5f4afdSRoman Zippel 		if (oss_present)
3201da177e4SLinus Torvalds 			oss_irq_disable(irq);
321*9c5f4afdSRoman Zippel 		else
3221da177e4SLinus Torvalds 			via_irq_disable(irq);
3231da177e4SLinus Torvalds 		break;
3241da177e4SLinus Torvalds 	case 3:
3251da177e4SLinus Torvalds 	case 4:
3261da177e4SLinus Torvalds 	case 5:
327*9c5f4afdSRoman Zippel 	case 6:
328*9c5f4afdSRoman Zippel 		if (psc_present)
3291da177e4SLinus Torvalds 			psc_irq_disable(irq);
330*9c5f4afdSRoman Zippel 		else if (oss_present)
3311da177e4SLinus Torvalds 			oss_irq_disable(irq);
332*9c5f4afdSRoman Zippel 		else if (irq_src == 4)
3331da177e4SLinus Torvalds 			scc_irq_disable(irq);
3341da177e4SLinus Torvalds 		break;
335*9c5f4afdSRoman Zippel 	case 8:
336*9c5f4afdSRoman Zippel 		if (baboon_present)
3371da177e4SLinus Torvalds 			baboon_irq_disable(irq);
3381da177e4SLinus Torvalds 		break;
3391da177e4SLinus Torvalds 	}
3401da177e4SLinus Torvalds }
3411da177e4SLinus Torvalds 
3421da177e4SLinus Torvalds void mac_clear_irq(unsigned int irq)
3431da177e4SLinus Torvalds {
3441da177e4SLinus Torvalds 	switch(IRQ_SRC(irq)) {
345*9c5f4afdSRoman Zippel 	case 1:
346*9c5f4afdSRoman Zippel 		via_irq_clear(irq);
3471da177e4SLinus Torvalds 		break;
3481da177e4SLinus Torvalds 	case 2:
349*9c5f4afdSRoman Zippel 	case 7:
350*9c5f4afdSRoman Zippel 		if (oss_present)
3511da177e4SLinus Torvalds 			oss_irq_clear(irq);
352*9c5f4afdSRoman Zippel 		else
3531da177e4SLinus Torvalds 			via_irq_clear(irq);
3541da177e4SLinus Torvalds 		break;
3551da177e4SLinus Torvalds 	case 3:
3561da177e4SLinus Torvalds 	case 4:
3571da177e4SLinus Torvalds 	case 5:
358*9c5f4afdSRoman Zippel 	case 6:
359*9c5f4afdSRoman Zippel 		if (psc_present)
3601da177e4SLinus Torvalds 			psc_irq_clear(irq);
361*9c5f4afdSRoman Zippel 		else if (oss_present)
3621da177e4SLinus Torvalds 			oss_irq_clear(irq);
3631da177e4SLinus Torvalds 		break;
364*9c5f4afdSRoman Zippel 	case 8:
365*9c5f4afdSRoman Zippel 		if (baboon_present)
3661da177e4SLinus Torvalds 			baboon_irq_clear(irq);
3671da177e4SLinus Torvalds 		break;
3681da177e4SLinus Torvalds 	}
3691da177e4SLinus Torvalds }
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds int mac_irq_pending(unsigned int irq)
3721da177e4SLinus Torvalds {
3731da177e4SLinus Torvalds 	switch(IRQ_SRC(irq)) {
374*9c5f4afdSRoman Zippel 	case 1:
3751da177e4SLinus Torvalds 		return via_irq_pending(irq);
376*9c5f4afdSRoman Zippel 	case 2:
377*9c5f4afdSRoman Zippel 	case 7:
378*9c5f4afdSRoman Zippel 		if (oss_present)
3791da177e4SLinus Torvalds 			return oss_irq_pending(irq);
380*9c5f4afdSRoman Zippel 		else
381*9c5f4afdSRoman Zippel 			return via_irq_pending(irq);
3821da177e4SLinus Torvalds 	case 3:
3831da177e4SLinus Torvalds 	case 4:
3841da177e4SLinus Torvalds 	case 5:
385*9c5f4afdSRoman Zippel 	case 6:
386*9c5f4afdSRoman Zippel 		if (psc_present)
387*9c5f4afdSRoman Zippel 			return psc_irq_pending(irq);
388*9c5f4afdSRoman Zippel 		else if (oss_present)
389*9c5f4afdSRoman Zippel 			return oss_irq_pending(irq);
3901da177e4SLinus Torvalds 	}
3911da177e4SLinus Torvalds 	return 0;
3921da177e4SLinus Torvalds }
3931da177e4SLinus Torvalds 
3941da177e4SLinus Torvalds static int num_debug[8];
3951da177e4SLinus Torvalds 
3961da177e4SLinus Torvalds irqreturn_t mac_debug_handler(int irq, void *dev_id, struct pt_regs *regs)
3971da177e4SLinus Torvalds {
3981da177e4SLinus Torvalds 	if (num_debug[irq] < 10) {
3991da177e4SLinus Torvalds 		printk("DEBUG: Unexpected IRQ %d\n", irq);
4001da177e4SLinus Torvalds 		num_debug[irq]++;
4011da177e4SLinus Torvalds 	}
4021da177e4SLinus Torvalds 	return IRQ_HANDLED;
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds static int in_nmi;
4061da177e4SLinus Torvalds static volatile int nmi_hold;
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds irqreturn_t mac_nmi_handler(int irq, void *dev_id, struct pt_regs *fp)
4091da177e4SLinus Torvalds {
4101da177e4SLinus Torvalds 	int i;
4111da177e4SLinus Torvalds 	/*
4121da177e4SLinus Torvalds 	 * generate debug output on NMI switch if 'debug' kernel option given
4131da177e4SLinus Torvalds 	 * (only works with Penguin!)
4141da177e4SLinus Torvalds 	 */
4151da177e4SLinus Torvalds 
4161da177e4SLinus Torvalds 	in_nmi++;
4171da177e4SLinus Torvalds 	for (i=0; i<100; i++)
4181da177e4SLinus Torvalds 		udelay(1000);
4191da177e4SLinus Torvalds 
4201da177e4SLinus Torvalds 	if (in_nmi == 1) {
4211da177e4SLinus Torvalds 		nmi_hold = 1;
4221da177e4SLinus Torvalds 		printk("... pausing, press NMI to resume ...");
4231da177e4SLinus Torvalds 	} else {
4241da177e4SLinus Torvalds 		printk(" ok!\n");
4251da177e4SLinus Torvalds 		nmi_hold = 0;
4261da177e4SLinus Torvalds 	}
4271da177e4SLinus Torvalds 
4281da177e4SLinus Torvalds 	barrier();
4291da177e4SLinus Torvalds 
4301da177e4SLinus Torvalds 	while (nmi_hold == 1)
4311da177e4SLinus Torvalds 		udelay(1000);
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds 	if (console_loglevel >= 8) {
4341da177e4SLinus Torvalds #if 0
4351da177e4SLinus Torvalds 		show_state();
4361da177e4SLinus Torvalds 		printk("PC: %08lx\nSR: %04x  SP: %p\n", fp->pc, fp->sr, fp);
4371da177e4SLinus Torvalds 		printk("d0: %08lx    d1: %08lx    d2: %08lx    d3: %08lx\n",
4381da177e4SLinus Torvalds 		       fp->d0, fp->d1, fp->d2, fp->d3);
4391da177e4SLinus Torvalds 		printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
4401da177e4SLinus Torvalds 		       fp->d4, fp->d5, fp->a0, fp->a1);
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds 		if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
4431da177e4SLinus Torvalds 			printk("Corrupted stack page\n");
4441da177e4SLinus Torvalds 		printk("Process %s (pid: %d, stackpage=%08lx)\n",
4451da177e4SLinus Torvalds 			current->comm, current->pid, current->kernel_stack_page);
4461da177e4SLinus Torvalds 		if (intr_count == 1)
4471da177e4SLinus Torvalds 			dump_stack((struct frame *)fp);
4481da177e4SLinus Torvalds #else
4491da177e4SLinus Torvalds 		/* printk("NMI "); */
4501da177e4SLinus Torvalds #endif
4511da177e4SLinus Torvalds 	}
4521da177e4SLinus Torvalds 	in_nmi--;
4531da177e4SLinus Torvalds 	return IRQ_HANDLED;
4541da177e4SLinus Torvalds }
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds /*
4571da177e4SLinus Torvalds  * Simple routines for masking and unmasking
4581da177e4SLinus Torvalds  * SCC interrupts in cases where this can't be
4591da177e4SLinus Torvalds  * done in hardware (only the PSC can do that.)
4601da177e4SLinus Torvalds  */
4611da177e4SLinus Torvalds 
462*9c5f4afdSRoman Zippel static void scc_irq_enable(unsigned int irq)
463*9c5f4afdSRoman Zippel {
4641da177e4SLinus Torvalds 	int irq_idx = IRQ_IDX(irq);
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds 	scc_mask |= (1 << irq_idx);
4671da177e4SLinus Torvalds }
4681da177e4SLinus Torvalds 
469*9c5f4afdSRoman Zippel static void scc_irq_disable(unsigned int irq)
470*9c5f4afdSRoman Zippel {
4711da177e4SLinus Torvalds 	int irq_idx = IRQ_IDX(irq);
4721da177e4SLinus Torvalds 
4731da177e4SLinus Torvalds 	scc_mask &= ~(1 << irq_idx);
4741da177e4SLinus Torvalds }
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds /*
4771da177e4SLinus Torvalds  * SCC master interrupt handler. We have to do a bit of magic here
4781da177e4SLinus Torvalds  * to figure out what channel gave us the interrupt; putting this
4791da177e4SLinus Torvalds  * here is cleaner than hacking it into drivers/char/macserial.c.
4801da177e4SLinus Torvalds  */
4811da177e4SLinus Torvalds 
4821da177e4SLinus Torvalds void mac_scc_dispatch(int irq, void *dev_id, struct pt_regs *regs)
4831da177e4SLinus Torvalds {
4841da177e4SLinus Torvalds 	volatile unsigned char *scc = (unsigned char *) mac_bi_data.sccbase + 2;
4851da177e4SLinus Torvalds 	unsigned char reg;
4861da177e4SLinus Torvalds 	unsigned long flags;
4871da177e4SLinus Torvalds 
4881da177e4SLinus Torvalds 	/* Read RR3 from the chip. Always do this on channel A */
4891da177e4SLinus Torvalds 	/* This must be an atomic operation so disable irqs.   */
4901da177e4SLinus Torvalds 
4911da177e4SLinus Torvalds 	local_irq_save(flags);
4921da177e4SLinus Torvalds 	*scc = 3;
4931da177e4SLinus Torvalds 	reg = *scc;
4941da177e4SLinus Torvalds 	local_irq_restore(flags);
4951da177e4SLinus Torvalds 
4961da177e4SLinus Torvalds 	/* Now dispatch. Bits 0-2 are for channel B and */
4971da177e4SLinus Torvalds 	/* bits 3-5 are for channel A. We can safely    */
4981da177e4SLinus Torvalds 	/* ignore the remaining bits here.              */
4991da177e4SLinus Torvalds 	/*                                              */
5001da177e4SLinus Torvalds 	/* Note that we're ignoring scc_mask for now.   */
5011da177e4SLinus Torvalds 	/* If we actually mask the ints then we tend to */
5021da177e4SLinus Torvalds 	/* get hammered by very persistent SCC irqs,    */
5031da177e4SLinus Torvalds 	/* and since they're autovector interrupts they */
5041da177e4SLinus Torvalds 	/* pretty much kill the system.                 */
5051da177e4SLinus Torvalds 
506*9c5f4afdSRoman Zippel 	if (reg & 0x38)
507*9c5f4afdSRoman Zippel 		m68k_handle_int(IRQ_SCCA, regs);
508*9c5f4afdSRoman Zippel 	if (reg & 0x07)
509*9c5f4afdSRoman Zippel 		m68k_handle_int(IRQ_SCCB, regs);
5101da177e4SLinus Torvalds }
511