xref: /linux/arch/mips/sgi-ip32/ip32-irq.c (revision b17b01533b719e9949e437abf66436a875739b40)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Code to handle IP32 IRQs
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * This file is subject to the terms and conditions of the GNU General Public
51da177e4SLinus Torvalds  * License.  See the file "COPYING" in the main directory of this archive
61da177e4SLinus Torvalds  * for more details.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Copyright (C) 2000 Harald Koerfgen
91da177e4SLinus Torvalds  * Copyright (C) 2001 Keith M Wesolowski
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds #include <linux/init.h>
121da177e4SLinus Torvalds #include <linux/kernel_stat.h>
131da177e4SLinus Torvalds #include <linux/types.h>
141da177e4SLinus Torvalds #include <linux/interrupt.h>
151da177e4SLinus Torvalds #include <linux/irq.h>
161da177e4SLinus Torvalds #include <linux/bitops.h>
171da177e4SLinus Torvalds #include <linux/kernel.h>
181da177e4SLinus Torvalds #include <linux/mm.h>
191da177e4SLinus Torvalds #include <linux/random.h>
201da177e4SLinus Torvalds #include <linux/sched.h>
21*b17b0153SIngo Molnar #include <linux/sched/debug.h>
221da177e4SLinus Torvalds 
23dd67b155SRalf Baechle #include <asm/irq_cpu.h>
241da177e4SLinus Torvalds #include <asm/mipsregs.h>
251da177e4SLinus Torvalds #include <asm/signal.h>
261da177e4SLinus Torvalds #include <asm/time.h>
271da177e4SLinus Torvalds #include <asm/ip32/crime.h>
281da177e4SLinus Torvalds #include <asm/ip32/mace.h>
291da177e4SLinus Torvalds #include <asm/ip32/ip32_ints.h>
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds /* issue a PIO read to make sure no PIO writes are pending */
3242b76a1dSArnd Bergmann static inline void flush_crime_bus(void)
331da177e4SLinus Torvalds {
34b6d7c7a9SRalf Baechle 	crime->control;
351da177e4SLinus Torvalds }
361da177e4SLinus Torvalds 
3742b76a1dSArnd Bergmann static inline void flush_mace_bus(void)
381da177e4SLinus Torvalds {
39b6d7c7a9SRalf Baechle 	mace->perif.ctrl.misc;
401da177e4SLinus Torvalds }
411da177e4SLinus Torvalds 
42dd67b155SRalf Baechle /*
43dd67b155SRalf Baechle  * O2 irq map
441da177e4SLinus Torvalds  *
451da177e4SLinus Torvalds  * IP0 -> software (ignored)
461da177e4SLinus Torvalds  * IP1 -> software (ignored)
471da177e4SLinus Torvalds  * IP2 -> (irq0) C crime 1.1 all interrupts; crime 1.5 ???
481da177e4SLinus Torvalds  * IP3 -> (irq1) X unknown
491da177e4SLinus Torvalds  * IP4 -> (irq2) X unknown
501da177e4SLinus Torvalds  * IP5 -> (irq3) X unknown
511da177e4SLinus Torvalds  * IP6 -> (irq4) X unknown
52dd67b155SRalf Baechle  * IP7 -> (irq5) 7 CPU count/compare timer (system timer)
531da177e4SLinus Torvalds  *
541da177e4SLinus Torvalds  * crime: (C)
551da177e4SLinus Torvalds  *
561da177e4SLinus Torvalds  * CRIME_INT_STAT 31:0:
571da177e4SLinus Torvalds  *
58dd67b155SRalf Baechle  * 0  ->  8  Video in 1
59dd67b155SRalf Baechle  * 1  ->  9 Video in 2
60dd67b155SRalf Baechle  * 2  -> 10  Video out
61dd67b155SRalf Baechle  * 3  -> 11  Mace ethernet
621da177e4SLinus Torvalds  * 4  -> S  SuperIO sub-interrupt
631da177e4SLinus Torvalds  * 5  -> M  Miscellaneous sub-interrupt
641da177e4SLinus Torvalds  * 6  -> A  Audio sub-interrupt
65dd67b155SRalf Baechle  * 7  -> 15  PCI bridge errors
66dd67b155SRalf Baechle  * 8  -> 16  PCI SCSI aic7xxx 0
67dd67b155SRalf Baechle  * 9  -> 17 PCI SCSI aic7xxx 1
68dd67b155SRalf Baechle  * 10 -> 18 PCI slot 0
69dd67b155SRalf Baechle  * 11 -> 19 unused (PCI slot 1)
70dd67b155SRalf Baechle  * 12 -> 20 unused (PCI slot 2)
71dd67b155SRalf Baechle  * 13 -> 21 unused (PCI shared 0)
72dd67b155SRalf Baechle  * 14 -> 22 unused (PCI shared 1)
73dd67b155SRalf Baechle  * 15 -> 23 unused (PCI shared 2)
74dd67b155SRalf Baechle  * 16 -> 24 GBE0 (E)
75dd67b155SRalf Baechle  * 17 -> 25 GBE1 (E)
76dd67b155SRalf Baechle  * 18 -> 26 GBE2 (E)
77dd67b155SRalf Baechle  * 19 -> 27 GBE3 (E)
78dd67b155SRalf Baechle  * 20 -> 28 CPU errors
79dd67b155SRalf Baechle  * 21 -> 29 Memory errors
80dd67b155SRalf Baechle  * 22 -> 30 RE empty edge (E)
81dd67b155SRalf Baechle  * 23 -> 31 RE full edge (E)
82dd67b155SRalf Baechle  * 24 -> 32 RE idle edge (E)
83dd67b155SRalf Baechle  * 25 -> 33 RE empty level
84dd67b155SRalf Baechle  * 26 -> 34 RE full level
85dd67b155SRalf Baechle  * 27 -> 35 RE idle level
86dd67b155SRalf Baechle  * 28 -> 36 unused (software 0) (E)
87dd67b155SRalf Baechle  * 29 -> 37 unused (software 1) (E)
88dd67b155SRalf Baechle  * 30 -> 38 unused (software 2) - crime 1.5 CPU SysCorError (E)
89dd67b155SRalf Baechle  * 31 -> 39 VICE
901da177e4SLinus Torvalds  *
911da177e4SLinus Torvalds  * S, M, A: Use the MACE ISA interrupt register
921da177e4SLinus Torvalds  * MACE_ISA_INT_STAT 31:0
931da177e4SLinus Torvalds  *
94dd67b155SRalf Baechle  * 0-7 -> 40-47 Audio
95dd67b155SRalf Baechle  * 8 -> 48 RTC
96dd67b155SRalf Baechle  * 9 -> 49 Keyboard
971da177e4SLinus Torvalds  * 10 -> X Keyboard polled
98dd67b155SRalf Baechle  * 11 -> 51 Mouse
991da177e4SLinus Torvalds  * 12 -> X Mouse polled
100dd67b155SRalf Baechle  * 13-15 -> 53-55 Count/compare timers
101dd67b155SRalf Baechle  * 16-19 -> 56-59 Parallel (16 E)
102dd67b155SRalf Baechle  * 20-25 -> 60-62 Serial 1 (22 E)
103dd67b155SRalf Baechle  * 26-31 -> 66-71 Serial 2 (28 E)
1041da177e4SLinus Torvalds  *
105dd67b155SRalf Baechle  * Note that this means IRQs 12-14, 50, and 52 do not exist.  This is a
1061da177e4SLinus Torvalds  * different IRQ map than IRIX uses, but that's OK as Linux irq handling
1071da177e4SLinus Torvalds  * is quite different anyway.
1081da177e4SLinus Torvalds  */
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds /* Some initial interrupts to set up */
111937a8015SRalf Baechle extern irqreturn_t crime_memerr_intr(int irq, void *dev_id);
112937a8015SRalf Baechle extern irqreturn_t crime_cpuerr_intr(int irq, void *dev_id);
1131da177e4SLinus Torvalds 
114ae537387SDmitri Vorobiev static struct irqaction memerr_irq = {
1154e45171cSThomas Gleixner 	.handler = crime_memerr_intr,
1164e45171cSThomas Gleixner 	.name = "CRIME memory error",
1174e45171cSThomas Gleixner };
1188a13ecd7SRalf Baechle 
119ae537387SDmitri Vorobiev static struct irqaction cpuerr_irq = {
1204e45171cSThomas Gleixner 	.handler = crime_cpuerr_intr,
1214e45171cSThomas Gleixner 	.name = "CRIME CPU error",
1224e45171cSThomas Gleixner };
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds /*
1251da177e4SLinus Torvalds  * This is for pure CRIME interrupts - ie not MACE.  The advantage?
1261da177e4SLinus Torvalds  * We get to split the register in half and do faster lookups.
1271da177e4SLinus Torvalds  */
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds static uint64_t crime_mask;
1301da177e4SLinus Torvalds 
1314d2796f8SThomas Gleixner static inline void crime_enable_irq(struct irq_data *d)
1321da177e4SLinus Torvalds {
1334d2796f8SThomas Gleixner 	unsigned int bit = d->irq - CRIME_IRQ_BASE;
1348a13ecd7SRalf Baechle 
1358a13ecd7SRalf Baechle 	crime_mask |= 1 << bit;
1361da177e4SLinus Torvalds 	crime->imask = crime_mask;
1371da177e4SLinus Torvalds }
1381da177e4SLinus Torvalds 
1394d2796f8SThomas Gleixner static inline void crime_disable_irq(struct irq_data *d)
1401da177e4SLinus Torvalds {
1414d2796f8SThomas Gleixner 	unsigned int bit = d->irq - CRIME_IRQ_BASE;
1428a13ecd7SRalf Baechle 
1438a13ecd7SRalf Baechle 	crime_mask &= ~(1 << bit);
1441da177e4SLinus Torvalds 	crime->imask = crime_mask;
1451da177e4SLinus Torvalds 	flush_crime_bus();
1461da177e4SLinus Torvalds }
1471da177e4SLinus Torvalds 
1488a13ecd7SRalf Baechle static struct irq_chip crime_level_interrupt = {
14970d21cdeSAtsushi Nemoto 	.name		= "IP32 CRIME",
1504d2796f8SThomas Gleixner 	.irq_mask	= crime_disable_irq,
1514d2796f8SThomas Gleixner 	.irq_unmask	= crime_enable_irq,
1528a13ecd7SRalf Baechle };
1538a13ecd7SRalf Baechle 
1544d2796f8SThomas Gleixner static void crime_edge_mask_and_ack_irq(struct irq_data *d)
1558a13ecd7SRalf Baechle {
1564d2796f8SThomas Gleixner 	unsigned int bit = d->irq - CRIME_IRQ_BASE;
1578a13ecd7SRalf Baechle 	uint64_t crime_int;
1588a13ecd7SRalf Baechle 
1598a13ecd7SRalf Baechle 	/* Edge triggered interrupts must be cleared. */
1608a13ecd7SRalf Baechle 	crime_int = crime->hard_int;
1618a13ecd7SRalf Baechle 	crime_int &= ~(1 << bit);
1628a13ecd7SRalf Baechle 	crime->hard_int = crime_int;
1638a13ecd7SRalf Baechle 
1644d2796f8SThomas Gleixner 	crime_disable_irq(d);
1658a13ecd7SRalf Baechle }
1668a13ecd7SRalf Baechle 
1678a13ecd7SRalf Baechle static struct irq_chip crime_edge_interrupt = {
1688a13ecd7SRalf Baechle 	.name		= "IP32 CRIME",
1694d2796f8SThomas Gleixner 	.irq_ack	= crime_edge_mask_and_ack_irq,
1704d2796f8SThomas Gleixner 	.irq_mask	= crime_disable_irq,
1714d2796f8SThomas Gleixner 	.irq_mask_ack	= crime_edge_mask_and_ack_irq,
1724d2796f8SThomas Gleixner 	.irq_unmask	= crime_enable_irq,
1731da177e4SLinus Torvalds };
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds /*
1761da177e4SLinus Torvalds  * This is for MACE PCI interrupts.  We can decrease bus traffic by masking
1771da177e4SLinus Torvalds  * as close to the source as possible.	This also means we can take the
1781da177e4SLinus Torvalds  * next chunk of the CRIME register in one piece.
1791da177e4SLinus Torvalds  */
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds static unsigned long macepci_mask;
1821da177e4SLinus Torvalds 
1834d2796f8SThomas Gleixner static void enable_macepci_irq(struct irq_data *d)
1841da177e4SLinus Torvalds {
1854d2796f8SThomas Gleixner 	macepci_mask |= MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
1861da177e4SLinus Torvalds 	mace->pci.control = macepci_mask;
1874d2796f8SThomas Gleixner 	crime_mask |= 1 << (d->irq - CRIME_IRQ_BASE);
1881da177e4SLinus Torvalds 	crime->imask = crime_mask;
1891da177e4SLinus Torvalds }
1901da177e4SLinus Torvalds 
1914d2796f8SThomas Gleixner static void disable_macepci_irq(struct irq_data *d)
1921da177e4SLinus Torvalds {
1934d2796f8SThomas Gleixner 	crime_mask &= ~(1 << (d->irq - CRIME_IRQ_BASE));
1941da177e4SLinus Torvalds 	crime->imask = crime_mask;
1951da177e4SLinus Torvalds 	flush_crime_bus();
1964d2796f8SThomas Gleixner 	macepci_mask &= ~MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
1971da177e4SLinus Torvalds 	mace->pci.control = macepci_mask;
1981da177e4SLinus Torvalds 	flush_mace_bus();
1991da177e4SLinus Torvalds }
2001da177e4SLinus Torvalds 
20194dee171SRalf Baechle static struct irq_chip ip32_macepci_interrupt = {
20270d21cdeSAtsushi Nemoto 	.name = "IP32 MACE PCI",
2034d2796f8SThomas Gleixner 	.irq_mask = disable_macepci_irq,
2044d2796f8SThomas Gleixner 	.irq_unmask = enable_macepci_irq,
2051da177e4SLinus Torvalds };
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds /* This is used for MACE ISA interrupts.  That means bits 4-6 in the
2081da177e4SLinus Torvalds  * CRIME register.
2091da177e4SLinus Torvalds  */
2101da177e4SLinus Torvalds 
2111da177e4SLinus Torvalds #define MACEISA_AUDIO_INT	(MACEISA_AUDIO_SW_INT |		\
2121da177e4SLinus Torvalds 				 MACEISA_AUDIO_SC_INT |		\
2131da177e4SLinus Torvalds 				 MACEISA_AUDIO1_DMAT_INT |	\
2141da177e4SLinus Torvalds 				 MACEISA_AUDIO1_OF_INT |	\
2151da177e4SLinus Torvalds 				 MACEISA_AUDIO2_DMAT_INT |	\
2161da177e4SLinus Torvalds 				 MACEISA_AUDIO2_MERR_INT |	\
2171da177e4SLinus Torvalds 				 MACEISA_AUDIO3_DMAT_INT |	\
2181da177e4SLinus Torvalds 				 MACEISA_AUDIO3_MERR_INT)
2191da177e4SLinus Torvalds #define MACEISA_MISC_INT	(MACEISA_RTC_INT |		\
2201da177e4SLinus Torvalds 				 MACEISA_KEYB_INT |		\
2211da177e4SLinus Torvalds 				 MACEISA_KEYB_POLL_INT |	\
2221da177e4SLinus Torvalds 				 MACEISA_MOUSE_INT |		\
2231da177e4SLinus Torvalds 				 MACEISA_MOUSE_POLL_INT |	\
224cfbae5d3SThiemo Seufer 				 MACEISA_TIMER0_INT |		\
225cfbae5d3SThiemo Seufer 				 MACEISA_TIMER1_INT |		\
226cfbae5d3SThiemo Seufer 				 MACEISA_TIMER2_INT)
2271da177e4SLinus Torvalds #define MACEISA_SUPERIO_INT	(MACEISA_PARALLEL_INT |		\
2281da177e4SLinus Torvalds 				 MACEISA_PAR_CTXA_INT |		\
2291da177e4SLinus Torvalds 				 MACEISA_PAR_CTXB_INT |		\
2301da177e4SLinus Torvalds 				 MACEISA_PAR_MERR_INT |		\
2311da177e4SLinus Torvalds 				 MACEISA_SERIAL1_INT |		\
2321da177e4SLinus Torvalds 				 MACEISA_SERIAL1_TDMAT_INT |	\
2331da177e4SLinus Torvalds 				 MACEISA_SERIAL1_TDMAPR_INT |	\
2341da177e4SLinus Torvalds 				 MACEISA_SERIAL1_TDMAME_INT |	\
2351da177e4SLinus Torvalds 				 MACEISA_SERIAL1_RDMAT_INT |	\
2361da177e4SLinus Torvalds 				 MACEISA_SERIAL1_RDMAOR_INT |	\
2371da177e4SLinus Torvalds 				 MACEISA_SERIAL2_INT |		\
2381da177e4SLinus Torvalds 				 MACEISA_SERIAL2_TDMAT_INT |	\
2391da177e4SLinus Torvalds 				 MACEISA_SERIAL2_TDMAPR_INT |	\
2401da177e4SLinus Torvalds 				 MACEISA_SERIAL2_TDMAME_INT |	\
2411da177e4SLinus Torvalds 				 MACEISA_SERIAL2_RDMAT_INT |	\
2421da177e4SLinus Torvalds 				 MACEISA_SERIAL2_RDMAOR_INT)
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds static unsigned long maceisa_mask;
2451da177e4SLinus Torvalds 
2464d2796f8SThomas Gleixner static void enable_maceisa_irq(struct irq_data *d)
2471da177e4SLinus Torvalds {
2481da177e4SLinus Torvalds 	unsigned int crime_int = 0;
2491da177e4SLinus Torvalds 
2504d2796f8SThomas Gleixner 	pr_debug("maceisa enable: %u\n", d->irq);
2511da177e4SLinus Torvalds 
2524d2796f8SThomas Gleixner 	switch (d->irq) {
2531da177e4SLinus Torvalds 	case MACEISA_AUDIO_SW_IRQ ... MACEISA_AUDIO3_MERR_IRQ:
2541da177e4SLinus Torvalds 		crime_int = MACE_AUDIO_INT;
2551da177e4SLinus Torvalds 		break;
256cfbae5d3SThiemo Seufer 	case MACEISA_RTC_IRQ ... MACEISA_TIMER2_IRQ:
2571da177e4SLinus Torvalds 		crime_int = MACE_MISC_INT;
2581da177e4SLinus Torvalds 		break;
2591da177e4SLinus Torvalds 	case MACEISA_PARALLEL_IRQ ... MACEISA_SERIAL2_RDMAOR_IRQ:
2601da177e4SLinus Torvalds 		crime_int = MACE_SUPERIO_INT;
2611da177e4SLinus Torvalds 		break;
2621da177e4SLinus Torvalds 	}
2638a13ecd7SRalf Baechle 	pr_debug("crime_int %08x enabled\n", crime_int);
2641da177e4SLinus Torvalds 	crime_mask |= crime_int;
2651da177e4SLinus Torvalds 	crime->imask = crime_mask;
2664d2796f8SThomas Gleixner 	maceisa_mask |= 1 << (d->irq - MACEISA_AUDIO_SW_IRQ);
2671da177e4SLinus Torvalds 	mace->perif.ctrl.imask = maceisa_mask;
2681da177e4SLinus Torvalds }
2691da177e4SLinus Torvalds 
2704d2796f8SThomas Gleixner static void disable_maceisa_irq(struct irq_data *d)
2711da177e4SLinus Torvalds {
2721da177e4SLinus Torvalds 	unsigned int crime_int = 0;
2731da177e4SLinus Torvalds 
2744d2796f8SThomas Gleixner 	maceisa_mask &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
2751da177e4SLinus Torvalds 	if (!(maceisa_mask & MACEISA_AUDIO_INT))
2761da177e4SLinus Torvalds 		crime_int |= MACE_AUDIO_INT;
2771da177e4SLinus Torvalds 	if (!(maceisa_mask & MACEISA_MISC_INT))
2781da177e4SLinus Torvalds 		crime_int |= MACE_MISC_INT;
2791da177e4SLinus Torvalds 	if (!(maceisa_mask & MACEISA_SUPERIO_INT))
2801da177e4SLinus Torvalds 		crime_int |= MACE_SUPERIO_INT;
2811da177e4SLinus Torvalds 	crime_mask &= ~crime_int;
2821da177e4SLinus Torvalds 	crime->imask = crime_mask;
2831da177e4SLinus Torvalds 	flush_crime_bus();
2841da177e4SLinus Torvalds 	mace->perif.ctrl.imask = maceisa_mask;
2851da177e4SLinus Torvalds 	flush_mace_bus();
2861da177e4SLinus Torvalds }
2871da177e4SLinus Torvalds 
2884d2796f8SThomas Gleixner static void mask_and_ack_maceisa_irq(struct irq_data *d)
2891da177e4SLinus Torvalds {
2901603b5acSAtsushi Nemoto 	unsigned long mace_int;
2911da177e4SLinus Torvalds 
2921da177e4SLinus Torvalds 	/* edge triggered */
2931da177e4SLinus Torvalds 	mace_int = mace->perif.ctrl.istat;
2944d2796f8SThomas Gleixner 	mace_int &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
2951da177e4SLinus Torvalds 	mace->perif.ctrl.istat = mace_int;
296c87e0909SRalf Baechle 
2974d2796f8SThomas Gleixner 	disable_maceisa_irq(d);
2981da177e4SLinus Torvalds }
2991da177e4SLinus Torvalds 
300c87e0909SRalf Baechle static struct irq_chip ip32_maceisa_level_interrupt = {
301c87e0909SRalf Baechle 	.name		= "IP32 MACE ISA",
3024d2796f8SThomas Gleixner 	.irq_mask	= disable_maceisa_irq,
3034d2796f8SThomas Gleixner 	.irq_unmask	= enable_maceisa_irq,
304c87e0909SRalf Baechle };
305c87e0909SRalf Baechle 
306c87e0909SRalf Baechle static struct irq_chip ip32_maceisa_edge_interrupt = {
30770d21cdeSAtsushi Nemoto 	.name		= "IP32 MACE ISA",
3084d2796f8SThomas Gleixner 	.irq_ack	= mask_and_ack_maceisa_irq,
3094d2796f8SThomas Gleixner 	.irq_mask	= disable_maceisa_irq,
3104d2796f8SThomas Gleixner 	.irq_mask_ack	= mask_and_ack_maceisa_irq,
3114d2796f8SThomas Gleixner 	.irq_unmask	= enable_maceisa_irq,
3121da177e4SLinus Torvalds };
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds /* This is used for regular non-ISA, non-PCI MACE interrupts.  That means
3151da177e4SLinus Torvalds  * bits 0-3 and 7 in the CRIME register.
3161da177e4SLinus Torvalds  */
3171da177e4SLinus Torvalds 
3184d2796f8SThomas Gleixner static void enable_mace_irq(struct irq_data *d)
3191da177e4SLinus Torvalds {
3204d2796f8SThomas Gleixner 	unsigned int bit = d->irq - CRIME_IRQ_BASE;
32198ce4721SRalf Baechle 
32298ce4721SRalf Baechle 	crime_mask |= (1 << bit);
3231da177e4SLinus Torvalds 	crime->imask = crime_mask;
3241da177e4SLinus Torvalds }
3251da177e4SLinus Torvalds 
3264d2796f8SThomas Gleixner static void disable_mace_irq(struct irq_data *d)
3271da177e4SLinus Torvalds {
3284d2796f8SThomas Gleixner 	unsigned int bit = d->irq - CRIME_IRQ_BASE;
32998ce4721SRalf Baechle 
33098ce4721SRalf Baechle 	crime_mask &= ~(1 << bit);
3311da177e4SLinus Torvalds 	crime->imask = crime_mask;
3321da177e4SLinus Torvalds 	flush_crime_bus();
3331da177e4SLinus Torvalds }
3341da177e4SLinus Torvalds 
33594dee171SRalf Baechle static struct irq_chip ip32_mace_interrupt = {
33670d21cdeSAtsushi Nemoto 	.name = "IP32 MACE",
3374d2796f8SThomas Gleixner 	.irq_mask = disable_mace_irq,
3384d2796f8SThomas Gleixner 	.irq_unmask = enable_mace_irq,
3391da177e4SLinus Torvalds };
3401da177e4SLinus Torvalds 
341937a8015SRalf Baechle static void ip32_unknown_interrupt(void)
3421da177e4SLinus Torvalds {
3431da177e4SLinus Torvalds 	printk("Unknown interrupt occurred!\n");
3441da177e4SLinus Torvalds 	printk("cp0_status: %08x\n", read_c0_status());
3451da177e4SLinus Torvalds 	printk("cp0_cause: %08x\n", read_c0_cause());
3461da177e4SLinus Torvalds 	printk("CRIME intr mask: %016lx\n", crime->imask);
3471da177e4SLinus Torvalds 	printk("CRIME intr status: %016lx\n", crime->istat);
3481da177e4SLinus Torvalds 	printk("CRIME hardware intr register: %016lx\n", crime->hard_int);
3491da177e4SLinus Torvalds 	printk("MACE ISA intr mask: %08lx\n", mace->perif.ctrl.imask);
3501da177e4SLinus Torvalds 	printk("MACE ISA intr status: %08lx\n", mace->perif.ctrl.istat);
3511da177e4SLinus Torvalds 	printk("MACE PCI control register: %08x\n", mace->pci.control);
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds 	printk("Register dump:\n");
354937a8015SRalf Baechle 	show_regs(get_irq_regs());
3551da177e4SLinus Torvalds 
3561da177e4SLinus Torvalds 	printk("Please mail this report to linux-mips@linux-mips.org\n");
3571da177e4SLinus Torvalds 	printk("Spinning...");
3581da177e4SLinus Torvalds 	while(1) ;
3591da177e4SLinus Torvalds }
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds /* CRIME 1.1 appears to deliver all interrupts to this one pin. */
3621da177e4SLinus Torvalds /* change this to loop over all edge-triggered irqs, exception masked out ones */
363937a8015SRalf Baechle static void ip32_irq0(void)
3641da177e4SLinus Torvalds {
3651da177e4SLinus Torvalds 	uint64_t crime_int;
3661da177e4SLinus Torvalds 	int irq = 0;
3671da177e4SLinus Torvalds 
368dd67b155SRalf Baechle 	/*
369dd67b155SRalf Baechle 	 * Sanity check interrupt numbering enum.
370dd67b155SRalf Baechle 	 * MACE got 32 interrupts and there are 32 MACE ISA interrupts daisy
371dd67b155SRalf Baechle 	 * chained.
372dd67b155SRalf Baechle 	 */
373dd67b155SRalf Baechle 	BUILD_BUG_ON(CRIME_VICE_IRQ - MACE_VID_IN1_IRQ != 31);
374dd67b155SRalf Baechle 	BUILD_BUG_ON(MACEISA_SERIAL2_RDMAOR_IRQ - MACEISA_AUDIO_SW_IRQ != 31);
375dd67b155SRalf Baechle 
3761da177e4SLinus Torvalds 	crime_int = crime->istat & crime_mask;
3771faf7f25SThomas Bogendoerfer 
3781faf7f25SThomas Bogendoerfer 	/* crime sometime delivers spurious interrupts, ignore them */
3791faf7f25SThomas Bogendoerfer 	if (unlikely(crime_int == 0))
3801faf7f25SThomas Bogendoerfer 		return;
3811faf7f25SThomas Bogendoerfer 
382dd67b155SRalf Baechle 	irq = MACE_VID_IN1_IRQ + __ffs(crime_int);
3831da177e4SLinus Torvalds 
3841da177e4SLinus Torvalds 	if (crime_int & CRIME_MACEISA_INT_MASK) {
3851da177e4SLinus Torvalds 		unsigned long mace_int = mace->perif.ctrl.istat;
386dd67b155SRalf Baechle 		irq = __ffs(mace_int & maceisa_mask) + MACEISA_AUDIO_SW_IRQ;
3871da177e4SLinus Torvalds 	}
388dd67b155SRalf Baechle 
3898a13ecd7SRalf Baechle 	pr_debug("*irq %u*\n", irq);
390937a8015SRalf Baechle 	do_IRQ(irq);
3911da177e4SLinus Torvalds }
3921da177e4SLinus Torvalds 
393937a8015SRalf Baechle static void ip32_irq1(void)
3941da177e4SLinus Torvalds {
395937a8015SRalf Baechle 	ip32_unknown_interrupt();
3961da177e4SLinus Torvalds }
3971da177e4SLinus Torvalds 
398937a8015SRalf Baechle static void ip32_irq2(void)
3991da177e4SLinus Torvalds {
400937a8015SRalf Baechle 	ip32_unknown_interrupt();
4011da177e4SLinus Torvalds }
4021da177e4SLinus Torvalds 
403937a8015SRalf Baechle static void ip32_irq3(void)
4041da177e4SLinus Torvalds {
405937a8015SRalf Baechle 	ip32_unknown_interrupt();
4061da177e4SLinus Torvalds }
4071da177e4SLinus Torvalds 
408937a8015SRalf Baechle static void ip32_irq4(void)
4091da177e4SLinus Torvalds {
410937a8015SRalf Baechle 	ip32_unknown_interrupt();
4111da177e4SLinus Torvalds }
4121da177e4SLinus Torvalds 
413937a8015SRalf Baechle static void ip32_irq5(void)
4141da177e4SLinus Torvalds {
415dd67b155SRalf Baechle 	do_IRQ(MIPS_CPU_IRQ_BASE + 7);
4161da177e4SLinus Torvalds }
4171da177e4SLinus Torvalds 
418937a8015SRalf Baechle asmlinkage void plat_irq_dispatch(void)
419e4ac58afSRalf Baechle {
420119537c0SThiemo Seufer 	unsigned int pending = read_c0_status() & read_c0_cause();
421e4ac58afSRalf Baechle 
422e4ac58afSRalf Baechle 	if (likely(pending & IE_IRQ0))
423937a8015SRalf Baechle 		ip32_irq0();
424e4ac58afSRalf Baechle 	else if (unlikely(pending & IE_IRQ1))
425937a8015SRalf Baechle 		ip32_irq1();
426e4ac58afSRalf Baechle 	else if (unlikely(pending & IE_IRQ2))
427937a8015SRalf Baechle 		ip32_irq2();
428e4ac58afSRalf Baechle 	else if (unlikely(pending & IE_IRQ3))
429937a8015SRalf Baechle 		ip32_irq3();
430e4ac58afSRalf Baechle 	else if (unlikely(pending & IE_IRQ4))
431937a8015SRalf Baechle 		ip32_irq4();
432e4ac58afSRalf Baechle 	else if (likely(pending & IE_IRQ5))
433937a8015SRalf Baechle 		ip32_irq5();
434e4ac58afSRalf Baechle }
435e4ac58afSRalf Baechle 
4361da177e4SLinus Torvalds void __init arch_init_irq(void)
4371da177e4SLinus Torvalds {
4381da177e4SLinus Torvalds 	unsigned int irq;
4391da177e4SLinus Torvalds 
4401da177e4SLinus Torvalds 	/* Install our interrupt handler, then clear and disable all
4411da177e4SLinus Torvalds 	 * CRIME and MACE interrupts. */
4421da177e4SLinus Torvalds 	crime->imask = 0;
4431da177e4SLinus Torvalds 	crime->hard_int = 0;
4441da177e4SLinus Torvalds 	crime->soft_int = 0;
4451da177e4SLinus Torvalds 	mace->perif.ctrl.istat = 0;
4461da177e4SLinus Torvalds 	mace->perif.ctrl.imask = 0;
4471da177e4SLinus Torvalds 
448dd67b155SRalf Baechle 	mips_cpu_irq_init();
44998ce4721SRalf Baechle 	for (irq = CRIME_IRQ_BASE; irq <= IP32_IRQ_MAX; irq++) {
450dd67b155SRalf Baechle 		switch (irq) {
451dd67b155SRalf Baechle 		case MACE_VID_IN1_IRQ ... MACE_PCI_BRIDGE_IRQ:
452e4ec7989SThomas Gleixner 			irq_set_chip_and_handler_name(irq,
453e4ec7989SThomas Gleixner 						      &ip32_mace_interrupt,
454e4ec7989SThomas Gleixner 						      handle_level_irq,
455e4ec7989SThomas Gleixner 						      "level");
456dd67b155SRalf Baechle 			break;
457c87e0909SRalf Baechle 
458dd67b155SRalf Baechle 		case MACEPCI_SCSI0_IRQ ...  MACEPCI_SHARED2_IRQ:
459e4ec7989SThomas Gleixner 			irq_set_chip_and_handler_name(irq,
460e4ec7989SThomas Gleixner 						      &ip32_macepci_interrupt,
461e4ec7989SThomas Gleixner 						      handle_level_irq,
462c87e0909SRalf Baechle 						      "level");
463dd67b155SRalf Baechle 			break;
464c87e0909SRalf Baechle 
4658a13ecd7SRalf Baechle 		case CRIME_CPUERR_IRQ:
4668a13ecd7SRalf Baechle 		case CRIME_MEMERR_IRQ:
467e4ec7989SThomas Gleixner 			irq_set_chip_and_handler_name(irq,
468e4ec7989SThomas Gleixner 						      &crime_level_interrupt,
469e4ec7989SThomas Gleixner 						      handle_level_irq,
470c87e0909SRalf Baechle 						      "level");
4718a13ecd7SRalf Baechle 			break;
472c87e0909SRalf Baechle 
4732fe06260SRoel Kluin 		case CRIME_GBE0_IRQ ... CRIME_GBE3_IRQ:
4748a13ecd7SRalf Baechle 		case CRIME_RE_EMPTY_E_IRQ ... CRIME_RE_IDLE_E_IRQ:
4758a13ecd7SRalf Baechle 		case CRIME_SOFT0_IRQ ... CRIME_SOFT2_IRQ:
4768a13ecd7SRalf Baechle 		case CRIME_VICE_IRQ:
477e4ec7989SThomas Gleixner 			irq_set_chip_and_handler_name(irq,
478e4ec7989SThomas Gleixner 						      &crime_edge_interrupt,
479e4ec7989SThomas Gleixner 						      handle_edge_irq,
480e4ec7989SThomas Gleixner 						      "edge");
481dd67b155SRalf Baechle 			break;
482c87e0909SRalf Baechle 
483c87e0909SRalf Baechle 		case MACEISA_PARALLEL_IRQ:
484c87e0909SRalf Baechle 		case MACEISA_SERIAL1_TDMAPR_IRQ:
485c87e0909SRalf Baechle 		case MACEISA_SERIAL2_TDMAPR_IRQ:
486e4ec7989SThomas Gleixner 			irq_set_chip_and_handler_name(irq,
487e4ec7989SThomas Gleixner 						      &ip32_maceisa_edge_interrupt,
488e4ec7989SThomas Gleixner 						      handle_edge_irq,
489c87e0909SRalf Baechle 						      "edge");
490c87e0909SRalf Baechle 			break;
491c87e0909SRalf Baechle 
492dd67b155SRalf Baechle 		default:
493e4ec7989SThomas Gleixner 			irq_set_chip_and_handler_name(irq,
494e4ec7989SThomas Gleixner 						      &ip32_maceisa_level_interrupt,
495e4ec7989SThomas Gleixner 						      handle_level_irq,
496c87e0909SRalf Baechle 						      "level");
4978a13ecd7SRalf Baechle 			break;
498dd67b155SRalf Baechle 		}
4991da177e4SLinus Torvalds 	}
5001da177e4SLinus Torvalds 	setup_irq(CRIME_MEMERR_IRQ, &memerr_irq);
5011da177e4SLinus Torvalds 	setup_irq(CRIME_CPUERR_IRQ, &cpuerr_irq);
5021da177e4SLinus Torvalds 
5031da177e4SLinus Torvalds #define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5)
5041da177e4SLinus Torvalds 	change_c0_status(ST0_IM, ALLINTS);
5051da177e4SLinus Torvalds }
506