xref: /linux/arch/m68k/mac/macints.c (revision 66a3f820cb6a88ef0481e042d4b48b2299deab7e)
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 
117*66a3f820SAl Viro #include <linux/module.h>
1181da177e4SLinus Torvalds #include <linux/types.h>
1191da177e4SLinus Torvalds #include <linux/kernel.h>
1201da177e4SLinus Torvalds #include <linux/sched.h>
1211da177e4SLinus Torvalds #include <linux/kernel_stat.h>
1221da177e4SLinus Torvalds #include <linux/interrupt.h> /* for intr_count */
1231da177e4SLinus Torvalds #include <linux/delay.h>
1241da177e4SLinus Torvalds #include <linux/seq_file.h>
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds #include <asm/system.h>
1271da177e4SLinus Torvalds #include <asm/irq.h>
1281da177e4SLinus Torvalds #include <asm/traps.h>
1291da177e4SLinus Torvalds #include <asm/bootinfo.h>
1301da177e4SLinus Torvalds #include <asm/machw.h>
1311da177e4SLinus Torvalds #include <asm/macintosh.h>
1321da177e4SLinus Torvalds #include <asm/mac_via.h>
1331da177e4SLinus Torvalds #include <asm/mac_psc.h>
1341da177e4SLinus Torvalds #include <asm/hwtest.h>
1351da177e4SLinus Torvalds #include <asm/errno.h>
1361da177e4SLinus Torvalds #include <asm/macints.h>
1372850bc27SAl Viro #include <asm/irq_regs.h>
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds #define DEBUG_SPURIOUS
1401da177e4SLinus Torvalds #define SHUTUP_SONIC
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds /* SCC interrupt mask */
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds static int scc_mask;
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds /*
1471da177e4SLinus Torvalds  * VIA/RBV hooks
1481da177e4SLinus Torvalds  */
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds extern void via_init(void);
1511da177e4SLinus Torvalds extern void via_register_interrupts(void);
1521da177e4SLinus Torvalds extern void via_irq_enable(int);
1531da177e4SLinus Torvalds extern void via_irq_disable(int);
1541da177e4SLinus Torvalds extern void via_irq_clear(int);
1551da177e4SLinus Torvalds extern int  via_irq_pending(int);
1561da177e4SLinus Torvalds 
1571da177e4SLinus Torvalds /*
1581da177e4SLinus Torvalds  * OSS hooks
1591da177e4SLinus Torvalds  */
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds extern int oss_present;
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds extern void oss_init(void);
1641da177e4SLinus Torvalds extern void oss_register_interrupts(void);
1651da177e4SLinus Torvalds extern void oss_irq_enable(int);
1661da177e4SLinus Torvalds extern void oss_irq_disable(int);
1671da177e4SLinus Torvalds extern void oss_irq_clear(int);
1681da177e4SLinus Torvalds extern int  oss_irq_pending(int);
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds /*
1711da177e4SLinus Torvalds  * PSC hooks
1721da177e4SLinus Torvalds  */
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds extern int psc_present;
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds extern void psc_init(void);
1771da177e4SLinus Torvalds extern void psc_register_interrupts(void);
1781da177e4SLinus Torvalds extern void psc_irq_enable(int);
1791da177e4SLinus Torvalds extern void psc_irq_disable(int);
1801da177e4SLinus Torvalds extern void psc_irq_clear(int);
1811da177e4SLinus Torvalds extern int  psc_irq_pending(int);
1821da177e4SLinus Torvalds 
1831da177e4SLinus Torvalds /*
1841da177e4SLinus Torvalds  * IOP hooks
1851da177e4SLinus Torvalds  */
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds extern void iop_register_interrupts(void);
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds /*
1901da177e4SLinus Torvalds  * Baboon hooks
1911da177e4SLinus Torvalds  */
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds extern int baboon_present;
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds extern void baboon_init(void);
1961da177e4SLinus Torvalds extern void baboon_register_interrupts(void);
1971da177e4SLinus Torvalds extern void baboon_irq_enable(int);
1981da177e4SLinus Torvalds extern void baboon_irq_disable(int);
1991da177e4SLinus Torvalds extern void baboon_irq_clear(int);
2001da177e4SLinus Torvalds extern int  baboon_irq_pending(int);
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds /*
2031da177e4SLinus Torvalds  * SCC interrupt routines
2041da177e4SLinus Torvalds  */
2051da177e4SLinus Torvalds 
2069c5f4afdSRoman Zippel static void scc_irq_enable(unsigned int);
2079c5f4afdSRoman Zippel static void scc_irq_disable(unsigned int);
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds /*
2101da177e4SLinus Torvalds  * console_loglevel determines NMI handler function
2111da177e4SLinus Torvalds  */
2121da177e4SLinus Torvalds 
2132850bc27SAl Viro irqreturn_t mac_nmi_handler(int, void *);
2142850bc27SAl Viro irqreturn_t mac_debug_handler(int, void *);
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds /* #define DEBUG_MACINTS */
2171da177e4SLinus Torvalds 
2189c5f4afdSRoman Zippel static void mac_enable_irq(unsigned int irq);
2199c5f4afdSRoman Zippel static void mac_disable_irq(unsigned int irq);
2209c5f4afdSRoman Zippel 
2219c5f4afdSRoman Zippel static struct irq_controller mac_irq_controller = {
2229c5f4afdSRoman Zippel 	.name		= "mac",
223241258d1SMilind Arun Choudhary 	.lock		= __SPIN_LOCK_UNLOCKED(mac_irq_controller.lock),
2249c5f4afdSRoman Zippel 	.enable		= mac_enable_irq,
2259c5f4afdSRoman Zippel 	.disable	= mac_disable_irq,
2269c5f4afdSRoman Zippel };
2279c5f4afdSRoman Zippel 
228*66a3f820SAl Viro void __init mac_init_IRQ(void)
2291da177e4SLinus Torvalds {
2301da177e4SLinus Torvalds #ifdef DEBUG_MACINTS
2311da177e4SLinus Torvalds 	printk("mac_init_IRQ(): Setting things up...\n");
2321da177e4SLinus Torvalds #endif
2331da177e4SLinus Torvalds 	scc_mask = 0;
2341da177e4SLinus Torvalds 
2359c5f4afdSRoman Zippel 	m68k_setup_irq_controller(&mac_irq_controller, IRQ_USER,
2369c5f4afdSRoman Zippel 				  NUM_MAC_SOURCES - IRQ_USER);
2371da177e4SLinus Torvalds 	/* Make sure the SONIC interrupt is cleared or things get ugly */
2381da177e4SLinus Torvalds #ifdef SHUTUP_SONIC
2391da177e4SLinus Torvalds 	printk("Killing onboard sonic... ");
2401da177e4SLinus Torvalds 	/* This address should hopefully be mapped already */
2411da177e4SLinus Torvalds 	if (hwreg_present((void*)(0x50f0a000))) {
2421da177e4SLinus Torvalds 		*(long *)(0x50f0a014) = 0x7fffL;
2431da177e4SLinus Torvalds 		*(long *)(0x50f0a010) = 0L;
2441da177e4SLinus Torvalds 	}
2451da177e4SLinus Torvalds 	printk("Done.\n");
2461da177e4SLinus Torvalds #endif /* SHUTUP_SONIC */
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds 	/*
2491da177e4SLinus Torvalds 	 * Now register the handlers for the master IRQ handlers
2501da177e4SLinus Torvalds 	 * at levels 1-7. Most of the work is done elsewhere.
2511da177e4SLinus Torvalds 	 */
2521da177e4SLinus Torvalds 
2539c5f4afdSRoman Zippel 	if (oss_present)
2541da177e4SLinus Torvalds 		oss_register_interrupts();
2559c5f4afdSRoman Zippel 	else
2561da177e4SLinus Torvalds 		via_register_interrupts();
2579c5f4afdSRoman Zippel 	if (psc_present)
2589c5f4afdSRoman Zippel 		psc_register_interrupts();
2599c5f4afdSRoman Zippel 	if (baboon_present)
2609c5f4afdSRoman Zippel 		baboon_register_interrupts();
2611da177e4SLinus Torvalds 	iop_register_interrupts();
2629c5f4afdSRoman Zippel 	request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
2631da177e4SLinus Torvalds 			mac_nmi_handler);
2641da177e4SLinus Torvalds #ifdef DEBUG_MACINTS
2651da177e4SLinus Torvalds 	printk("mac_init_IRQ(): Done!\n");
2661da177e4SLinus Torvalds #endif
2671da177e4SLinus Torvalds }
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds /*
2701da177e4SLinus Torvalds  *  mac_enable_irq - enable an interrupt source
2711da177e4SLinus Torvalds  * mac_disable_irq - disable an interrupt source
2721da177e4SLinus Torvalds  *   mac_clear_irq - clears a pending interrupt
2731da177e4SLinus Torvalds  * mac_pending_irq - Returns the pending status of an IRQ (nonzero = pending)
2741da177e4SLinus Torvalds  *
2751da177e4SLinus Torvalds  * These routines are just dispatchers to the VIA/OSS/PSC routines.
2761da177e4SLinus Torvalds  */
2771da177e4SLinus Torvalds 
2789c5f4afdSRoman Zippel static void mac_enable_irq(unsigned int irq)
2791da177e4SLinus Torvalds {
2801da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
2811da177e4SLinus Torvalds 
2821da177e4SLinus Torvalds 	switch(irq_src) {
2839c5f4afdSRoman Zippel 	case 1:
2841da177e4SLinus Torvalds 		via_irq_enable(irq);
2859c5f4afdSRoman Zippel 		break;
2869c5f4afdSRoman Zippel 	case 2:
2879c5f4afdSRoman Zippel 	case 7:
2889c5f4afdSRoman Zippel 		if (oss_present)
2899c5f4afdSRoman Zippel 			oss_irq_enable(irq);
2909c5f4afdSRoman Zippel 		else
2919c5f4afdSRoman Zippel 			via_irq_enable(irq);
2921da177e4SLinus Torvalds 		break;
2931da177e4SLinus Torvalds 	case 3:
2941da177e4SLinus Torvalds 	case 4:
2951da177e4SLinus Torvalds 	case 5:
2969c5f4afdSRoman Zippel 	case 6:
2979c5f4afdSRoman Zippel 		if (psc_present)
2981da177e4SLinus Torvalds 			psc_irq_enable(irq);
2999c5f4afdSRoman Zippel 		else if (oss_present)
3001da177e4SLinus Torvalds 			oss_irq_enable(irq);
3019c5f4afdSRoman Zippel 		else if (irq_src == 4)
3021da177e4SLinus Torvalds 			scc_irq_enable(irq);
3031da177e4SLinus Torvalds 		break;
3049c5f4afdSRoman Zippel 	case 8:
3059c5f4afdSRoman Zippel 		if (baboon_present)
3061da177e4SLinus Torvalds 			baboon_irq_enable(irq);
3071da177e4SLinus Torvalds 		break;
3081da177e4SLinus Torvalds 	}
3091da177e4SLinus Torvalds }
3101da177e4SLinus Torvalds 
3119c5f4afdSRoman Zippel static void mac_disable_irq(unsigned int irq)
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
3141da177e4SLinus Torvalds 
3151da177e4SLinus Torvalds 	switch(irq_src) {
3169c5f4afdSRoman Zippel 	case 1:
3179c5f4afdSRoman Zippel 		via_irq_disable(irq);
3181da177e4SLinus Torvalds 		break;
3191da177e4SLinus Torvalds 	case 2:
3209c5f4afdSRoman Zippel 	case 7:
3219c5f4afdSRoman Zippel 		if (oss_present)
3221da177e4SLinus Torvalds 			oss_irq_disable(irq);
3239c5f4afdSRoman Zippel 		else
3241da177e4SLinus Torvalds 			via_irq_disable(irq);
3251da177e4SLinus Torvalds 		break;
3261da177e4SLinus Torvalds 	case 3:
3271da177e4SLinus Torvalds 	case 4:
3281da177e4SLinus Torvalds 	case 5:
3299c5f4afdSRoman Zippel 	case 6:
3309c5f4afdSRoman Zippel 		if (psc_present)
3311da177e4SLinus Torvalds 			psc_irq_disable(irq);
3329c5f4afdSRoman Zippel 		else if (oss_present)
3331da177e4SLinus Torvalds 			oss_irq_disable(irq);
3349c5f4afdSRoman Zippel 		else if (irq_src == 4)
3351da177e4SLinus Torvalds 			scc_irq_disable(irq);
3361da177e4SLinus Torvalds 		break;
3379c5f4afdSRoman Zippel 	case 8:
3389c5f4afdSRoman Zippel 		if (baboon_present)
3391da177e4SLinus Torvalds 			baboon_irq_disable(irq);
3401da177e4SLinus Torvalds 		break;
3411da177e4SLinus Torvalds 	}
3421da177e4SLinus Torvalds }
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds void mac_clear_irq(unsigned int irq)
3451da177e4SLinus Torvalds {
3461da177e4SLinus Torvalds 	switch(IRQ_SRC(irq)) {
3479c5f4afdSRoman Zippel 	case 1:
3489c5f4afdSRoman Zippel 		via_irq_clear(irq);
3491da177e4SLinus Torvalds 		break;
3501da177e4SLinus Torvalds 	case 2:
3519c5f4afdSRoman Zippel 	case 7:
3529c5f4afdSRoman Zippel 		if (oss_present)
3531da177e4SLinus Torvalds 			oss_irq_clear(irq);
3549c5f4afdSRoman Zippel 		else
3551da177e4SLinus Torvalds 			via_irq_clear(irq);
3561da177e4SLinus Torvalds 		break;
3571da177e4SLinus Torvalds 	case 3:
3581da177e4SLinus Torvalds 	case 4:
3591da177e4SLinus Torvalds 	case 5:
3609c5f4afdSRoman Zippel 	case 6:
3619c5f4afdSRoman Zippel 		if (psc_present)
3621da177e4SLinus Torvalds 			psc_irq_clear(irq);
3639c5f4afdSRoman Zippel 		else if (oss_present)
3641da177e4SLinus Torvalds 			oss_irq_clear(irq);
3651da177e4SLinus Torvalds 		break;
3669c5f4afdSRoman Zippel 	case 8:
3679c5f4afdSRoman Zippel 		if (baboon_present)
3681da177e4SLinus Torvalds 			baboon_irq_clear(irq);
3691da177e4SLinus Torvalds 		break;
3701da177e4SLinus Torvalds 	}
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds int mac_irq_pending(unsigned int irq)
3741da177e4SLinus Torvalds {
3751da177e4SLinus Torvalds 	switch(IRQ_SRC(irq)) {
3769c5f4afdSRoman Zippel 	case 1:
3771da177e4SLinus Torvalds 		return via_irq_pending(irq);
3789c5f4afdSRoman Zippel 	case 2:
3799c5f4afdSRoman Zippel 	case 7:
3809c5f4afdSRoman Zippel 		if (oss_present)
3811da177e4SLinus Torvalds 			return oss_irq_pending(irq);
3829c5f4afdSRoman Zippel 		else
3839c5f4afdSRoman Zippel 			return via_irq_pending(irq);
3841da177e4SLinus Torvalds 	case 3:
3851da177e4SLinus Torvalds 	case 4:
3861da177e4SLinus Torvalds 	case 5:
3879c5f4afdSRoman Zippel 	case 6:
3889c5f4afdSRoman Zippel 		if (psc_present)
3899c5f4afdSRoman Zippel 			return psc_irq_pending(irq);
3909c5f4afdSRoman Zippel 		else if (oss_present)
3919c5f4afdSRoman Zippel 			return oss_irq_pending(irq);
3921da177e4SLinus Torvalds 	}
3931da177e4SLinus Torvalds 	return 0;
3941da177e4SLinus Torvalds }
395*66a3f820SAl Viro EXPORT_SYMBOL(mac_irq_pending);
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds static int num_debug[8];
3981da177e4SLinus Torvalds 
3992850bc27SAl Viro irqreturn_t mac_debug_handler(int irq, void *dev_id)
4001da177e4SLinus Torvalds {
4011da177e4SLinus Torvalds 	if (num_debug[irq] < 10) {
4021da177e4SLinus Torvalds 		printk("DEBUG: Unexpected IRQ %d\n", irq);
4031da177e4SLinus Torvalds 		num_debug[irq]++;
4041da177e4SLinus Torvalds 	}
4051da177e4SLinus Torvalds 	return IRQ_HANDLED;
4061da177e4SLinus Torvalds }
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds static int in_nmi;
4091da177e4SLinus Torvalds static volatile int nmi_hold;
4101da177e4SLinus Torvalds 
4112850bc27SAl Viro irqreturn_t mac_nmi_handler(int irq, void *dev_id)
4121da177e4SLinus Torvalds {
4131da177e4SLinus Torvalds 	int i;
4141da177e4SLinus Torvalds 	/*
4151da177e4SLinus Torvalds 	 * generate debug output on NMI switch if 'debug' kernel option given
4161da177e4SLinus Torvalds 	 * (only works with Penguin!)
4171da177e4SLinus Torvalds 	 */
4181da177e4SLinus Torvalds 
4191da177e4SLinus Torvalds 	in_nmi++;
4201da177e4SLinus Torvalds 	for (i=0; i<100; i++)
4211da177e4SLinus Torvalds 		udelay(1000);
4221da177e4SLinus Torvalds 
4231da177e4SLinus Torvalds 	if (in_nmi == 1) {
4241da177e4SLinus Torvalds 		nmi_hold = 1;
4251da177e4SLinus Torvalds 		printk("... pausing, press NMI to resume ...");
4261da177e4SLinus Torvalds 	} else {
4271da177e4SLinus Torvalds 		printk(" ok!\n");
4281da177e4SLinus Torvalds 		nmi_hold = 0;
4291da177e4SLinus Torvalds 	}
4301da177e4SLinus Torvalds 
4311da177e4SLinus Torvalds 	barrier();
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds 	while (nmi_hold == 1)
4341da177e4SLinus Torvalds 		udelay(1000);
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds 	if (console_loglevel >= 8) {
4371da177e4SLinus Torvalds #if 0
4382850bc27SAl Viro 		struct pt_regs *fp = get_irq_regs();
4391da177e4SLinus Torvalds 		show_state();
4401da177e4SLinus Torvalds 		printk("PC: %08lx\nSR: %04x  SP: %p\n", fp->pc, fp->sr, fp);
4411da177e4SLinus Torvalds 		printk("d0: %08lx    d1: %08lx    d2: %08lx    d3: %08lx\n",
4421da177e4SLinus Torvalds 		       fp->d0, fp->d1, fp->d2, fp->d3);
4431da177e4SLinus Torvalds 		printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
4441da177e4SLinus Torvalds 		       fp->d4, fp->d5, fp->a0, fp->a1);
4451da177e4SLinus Torvalds 
4461da177e4SLinus Torvalds 		if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
4471da177e4SLinus Torvalds 			printk("Corrupted stack page\n");
4481da177e4SLinus Torvalds 		printk("Process %s (pid: %d, stackpage=%08lx)\n",
4491da177e4SLinus Torvalds 			current->comm, current->pid, current->kernel_stack_page);
4501da177e4SLinus Torvalds 		if (intr_count == 1)
4511da177e4SLinus Torvalds 			dump_stack((struct frame *)fp);
4521da177e4SLinus Torvalds #else
4531da177e4SLinus Torvalds 		/* printk("NMI "); */
4541da177e4SLinus Torvalds #endif
4551da177e4SLinus Torvalds 	}
4561da177e4SLinus Torvalds 	in_nmi--;
4571da177e4SLinus Torvalds 	return IRQ_HANDLED;
4581da177e4SLinus Torvalds }
4591da177e4SLinus Torvalds 
4601da177e4SLinus Torvalds /*
4611da177e4SLinus Torvalds  * Simple routines for masking and unmasking
4621da177e4SLinus Torvalds  * SCC interrupts in cases where this can't be
4631da177e4SLinus Torvalds  * done in hardware (only the PSC can do that.)
4641da177e4SLinus Torvalds  */
4651da177e4SLinus Torvalds 
4669c5f4afdSRoman Zippel static void scc_irq_enable(unsigned int irq)
4679c5f4afdSRoman Zippel {
4681da177e4SLinus Torvalds 	int irq_idx = IRQ_IDX(irq);
4691da177e4SLinus Torvalds 
4701da177e4SLinus Torvalds 	scc_mask |= (1 << irq_idx);
4711da177e4SLinus Torvalds }
4721da177e4SLinus Torvalds 
4739c5f4afdSRoman Zippel static void scc_irq_disable(unsigned int irq)
4749c5f4afdSRoman Zippel {
4751da177e4SLinus Torvalds 	int irq_idx = IRQ_IDX(irq);
4761da177e4SLinus Torvalds 
4771da177e4SLinus Torvalds 	scc_mask &= ~(1 << irq_idx);
4781da177e4SLinus Torvalds }
4791da177e4SLinus Torvalds 
4801da177e4SLinus Torvalds /*
4811da177e4SLinus Torvalds  * SCC master interrupt handler. We have to do a bit of magic here
4821da177e4SLinus Torvalds  * to figure out what channel gave us the interrupt; putting this
4831da177e4SLinus Torvalds  * here is cleaner than hacking it into drivers/char/macserial.c.
4841da177e4SLinus Torvalds  */
4851da177e4SLinus Torvalds 
4862850bc27SAl Viro void mac_scc_dispatch(int irq, void *dev_id)
4871da177e4SLinus Torvalds {
4881da177e4SLinus Torvalds 	volatile unsigned char *scc = (unsigned char *) mac_bi_data.sccbase + 2;
4891da177e4SLinus Torvalds 	unsigned char reg;
4901da177e4SLinus Torvalds 	unsigned long flags;
4911da177e4SLinus Torvalds 
4921da177e4SLinus Torvalds 	/* Read RR3 from the chip. Always do this on channel A */
4931da177e4SLinus Torvalds 	/* This must be an atomic operation so disable irqs.   */
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds 	local_irq_save(flags);
4961da177e4SLinus Torvalds 	*scc = 3;
4971da177e4SLinus Torvalds 	reg = *scc;
4981da177e4SLinus Torvalds 	local_irq_restore(flags);
4991da177e4SLinus Torvalds 
5001da177e4SLinus Torvalds 	/* Now dispatch. Bits 0-2 are for channel B and */
5011da177e4SLinus Torvalds 	/* bits 3-5 are for channel A. We can safely    */
5021da177e4SLinus Torvalds 	/* ignore the remaining bits here.              */
5031da177e4SLinus Torvalds 	/*                                              */
5041da177e4SLinus Torvalds 	/* Note that we're ignoring scc_mask for now.   */
5051da177e4SLinus Torvalds 	/* If we actually mask the ints then we tend to */
5061da177e4SLinus Torvalds 	/* get hammered by very persistent SCC irqs,    */
5071da177e4SLinus Torvalds 	/* and since they're autovector interrupts they */
5081da177e4SLinus Torvalds 	/* pretty much kill the system.                 */
5091da177e4SLinus Torvalds 
5109c5f4afdSRoman Zippel 	if (reg & 0x38)
5112850bc27SAl Viro 		m68k_handle_int(IRQ_SCCA);
5129c5f4afdSRoman Zippel 	if (reg & 0x07)
5132850bc27SAl Viro 		m68k_handle_int(IRQ_SCCB);
5141da177e4SLinus Torvalds }
515