blob: a092860d5196818b1f4942dc4070af4abdac1bdc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Code to handle IP32 IRQs
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2000 Harald Koerfgen
9 * Copyright (C) 2001 Keith M Wesolowski
10 */
11#include <linux/init.h>
12#include <linux/kernel_stat.h>
13#include <linux/types.h>
14#include <linux/interrupt.h>
15#include <linux/irq.h>
16#include <linux/bitops.h>
17#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/mm.h>
19#include <linux/random.h>
20#include <linux/sched.h>
21
Ralf Baechledd67b152007-10-14 14:02:26 +010022#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/mipsregs.h>
24#include <asm/signal.h>
25#include <asm/system.h>
26#include <asm/time.h>
27#include <asm/ip32/crime.h>
28#include <asm/ip32/mace.h>
29#include <asm/ip32/ip32_ints.h>
30
31/* issue a PIO read to make sure no PIO writes are pending */
32static void inline flush_crime_bus(void)
33{
Ralf Baechleb6d7c7a2006-05-30 02:13:16 +010034 crime->control;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
37static void inline flush_mace_bus(void)
38{
Ralf Baechleb6d7c7a2006-05-30 02:13:16 +010039 mace->perif.ctrl.misc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
Ralf Baechledd67b152007-10-14 14:02:26 +010042/*
43 * O2 irq map
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 *
45 * IP0 -> software (ignored)
46 * IP1 -> software (ignored)
47 * IP2 -> (irq0) C crime 1.1 all interrupts; crime 1.5 ???
48 * IP3 -> (irq1) X unknown
49 * IP4 -> (irq2) X unknown
50 * IP5 -> (irq3) X unknown
51 * IP6 -> (irq4) X unknown
Ralf Baechledd67b152007-10-14 14:02:26 +010052 * IP7 -> (irq5) 7 CPU count/compare timer (system timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 *
54 * crime: (C)
55 *
56 * CRIME_INT_STAT 31:0:
57 *
Ralf Baechledd67b152007-10-14 14:02:26 +010058 * 0 -> 8 Video in 1
59 * 1 -> 9 Video in 2
60 * 2 -> 10 Video out
61 * 3 -> 11 Mace ethernet
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * 4 -> S SuperIO sub-interrupt
63 * 5 -> M Miscellaneous sub-interrupt
64 * 6 -> A Audio sub-interrupt
Ralf Baechledd67b152007-10-14 14:02:26 +010065 * 7 -> 15 PCI bridge errors
66 * 8 -> 16 PCI SCSI aic7xxx 0
67 * 9 -> 17 PCI SCSI aic7xxx 1
68 * 10 -> 18 PCI slot 0
69 * 11 -> 19 unused (PCI slot 1)
70 * 12 -> 20 unused (PCI slot 2)
71 * 13 -> 21 unused (PCI shared 0)
72 * 14 -> 22 unused (PCI shared 1)
73 * 15 -> 23 unused (PCI shared 2)
74 * 16 -> 24 GBE0 (E)
75 * 17 -> 25 GBE1 (E)
76 * 18 -> 26 GBE2 (E)
77 * 19 -> 27 GBE3 (E)
78 * 20 -> 28 CPU errors
79 * 21 -> 29 Memory errors
80 * 22 -> 30 RE empty edge (E)
81 * 23 -> 31 RE full edge (E)
82 * 24 -> 32 RE idle edge (E)
83 * 25 -> 33 RE empty level
84 * 26 -> 34 RE full level
85 * 27 -> 35 RE idle level
86 * 28 -> 36 unused (software 0) (E)
87 * 29 -> 37 unused (software 1) (E)
88 * 30 -> 38 unused (software 2) - crime 1.5 CPU SysCorError (E)
89 * 31 -> 39 VICE
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 *
91 * S, M, A: Use the MACE ISA interrupt register
92 * MACE_ISA_INT_STAT 31:0
93 *
Ralf Baechledd67b152007-10-14 14:02:26 +010094 * 0-7 -> 40-47 Audio
95 * 8 -> 48 RTC
96 * 9 -> 49 Keyboard
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 * 10 -> X Keyboard polled
Ralf Baechledd67b152007-10-14 14:02:26 +010098 * 11 -> 51 Mouse
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 * 12 -> X Mouse polled
Ralf Baechledd67b152007-10-14 14:02:26 +0100100 * 13-15 -> 53-55 Count/compare timers
101 * 16-19 -> 56-59 Parallel (16 E)
102 * 20-25 -> 60-62 Serial 1 (22 E)
103 * 26-31 -> 66-71 Serial 2 (28 E)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 *
Ralf Baechledd67b152007-10-14 14:02:26 +0100105 * Note that this means IRQs 12-14, 50, and 52 do not exist. This is a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 * different IRQ map than IRIX uses, but that's OK as Linux irq handling
107 * is quite different anyway.
108 */
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/* Some initial interrupts to set up */
Ralf Baechle937a8012006-10-07 19:44:33 +0100111extern irqreturn_t crime_memerr_intr(int irq, void *dev_id);
112extern irqreturn_t crime_cpuerr_intr(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Dmitri Vorobievae537382009-03-30 22:53:25 +0300114static struct irqaction memerr_irq = {
Thomas Gleixner4e451712007-08-28 09:03:01 +0000115 .handler = crime_memerr_intr,
Thomas Gleixner4e451712007-08-28 09:03:01 +0000116 .name = "CRIME memory error",
117};
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000118
Dmitri Vorobievae537382009-03-30 22:53:25 +0300119static struct irqaction cpuerr_irq = {
Thomas Gleixner4e451712007-08-28 09:03:01 +0000120 .handler = crime_cpuerr_intr,
Thomas Gleixner4e451712007-08-28 09:03:01 +0000121 .name = "CRIME CPU error",
122};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * This is for pure CRIME interrupts - ie not MACE. The advantage?
126 * We get to split the register in half and do faster lookups.
127 */
128
129static uint64_t crime_mask;
130
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000131static inline void crime_enable_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000133 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000134
135 crime_mask |= 1 << bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 crime->imask = crime_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000139static inline void crime_disable_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000141 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000142
143 crime_mask &= ~(1 << bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 crime->imask = crime_mask;
145 flush_crime_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000148static struct irq_chip crime_level_interrupt = {
149 .name = "IP32 CRIME",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000150 .irq_mask = crime_disable_irq,
151 .irq_unmask = crime_enable_irq,
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000152};
153
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000154static void crime_edge_mask_and_ack_irq(struct irq_data *d)
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000155{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000156 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000157 uint64_t crime_int;
158
159 /* Edge triggered interrupts must be cleared. */
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000160 crime_int = crime->hard_int;
161 crime_int &= ~(1 << bit);
162 crime->hard_int = crime_int;
163
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000164 crime_disable_irq(d);
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000165}
166
167static struct irq_chip crime_edge_interrupt = {
168 .name = "IP32 CRIME",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000169 .irq_ack = crime_edge_mask_and_ack_irq,
170 .irq_mask = crime_disable_irq,
171 .irq_mask_ack = crime_edge_mask_and_ack_irq,
172 .irq_unmask = crime_enable_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
175/*
176 * This is for MACE PCI interrupts. We can decrease bus traffic by masking
177 * as close to the source as possible. This also means we can take the
178 * next chunk of the CRIME register in one piece.
179 */
180
181static unsigned long macepci_mask;
182
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000183static void enable_macepci_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000185 macepci_mask |= MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 mace->pci.control = macepci_mask;
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000187 crime_mask |= 1 << (d->irq - CRIME_IRQ_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 crime->imask = crime_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000191static void disable_macepci_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000193 crime_mask &= ~(1 << (d->irq - CRIME_IRQ_BASE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 crime->imask = crime_mask;
195 flush_crime_bus();
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000196 macepci_mask &= ~MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 mace->pci.control = macepci_mask;
198 flush_mace_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Ralf Baechle94dee172006-07-02 14:41:42 +0100201static struct irq_chip ip32_macepci_interrupt = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +0900202 .name = "IP32 MACE PCI",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000203 .irq_mask = disable_macepci_irq,
204 .irq_unmask = enable_macepci_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
207/* This is used for MACE ISA interrupts. That means bits 4-6 in the
208 * CRIME register.
209 */
210
211#define MACEISA_AUDIO_INT (MACEISA_AUDIO_SW_INT | \
212 MACEISA_AUDIO_SC_INT | \
213 MACEISA_AUDIO1_DMAT_INT | \
214 MACEISA_AUDIO1_OF_INT | \
215 MACEISA_AUDIO2_DMAT_INT | \
216 MACEISA_AUDIO2_MERR_INT | \
217 MACEISA_AUDIO3_DMAT_INT | \
218 MACEISA_AUDIO3_MERR_INT)
219#define MACEISA_MISC_INT (MACEISA_RTC_INT | \
220 MACEISA_KEYB_INT | \
221 MACEISA_KEYB_POLL_INT | \
222 MACEISA_MOUSE_INT | \
223 MACEISA_MOUSE_POLL_INT | \
Thiemo Seufercfbae5d2006-07-05 18:43:29 +0100224 MACEISA_TIMER0_INT | \
225 MACEISA_TIMER1_INT | \
226 MACEISA_TIMER2_INT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define MACEISA_SUPERIO_INT (MACEISA_PARALLEL_INT | \
228 MACEISA_PAR_CTXA_INT | \
229 MACEISA_PAR_CTXB_INT | \
230 MACEISA_PAR_MERR_INT | \
231 MACEISA_SERIAL1_INT | \
232 MACEISA_SERIAL1_TDMAT_INT | \
233 MACEISA_SERIAL1_TDMAPR_INT | \
234 MACEISA_SERIAL1_TDMAME_INT | \
235 MACEISA_SERIAL1_RDMAT_INT | \
236 MACEISA_SERIAL1_RDMAOR_INT | \
237 MACEISA_SERIAL2_INT | \
238 MACEISA_SERIAL2_TDMAT_INT | \
239 MACEISA_SERIAL2_TDMAPR_INT | \
240 MACEISA_SERIAL2_TDMAME_INT | \
241 MACEISA_SERIAL2_RDMAT_INT | \
242 MACEISA_SERIAL2_RDMAOR_INT)
243
244static unsigned long maceisa_mask;
245
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000246static void enable_maceisa_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 unsigned int crime_int = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000250 pr_debug("maceisa enable: %u\n", d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000252 switch (d->irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 case MACEISA_AUDIO_SW_IRQ ... MACEISA_AUDIO3_MERR_IRQ:
254 crime_int = MACE_AUDIO_INT;
255 break;
Thiemo Seufercfbae5d2006-07-05 18:43:29 +0100256 case MACEISA_RTC_IRQ ... MACEISA_TIMER2_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 crime_int = MACE_MISC_INT;
258 break;
259 case MACEISA_PARALLEL_IRQ ... MACEISA_SERIAL2_RDMAOR_IRQ:
260 crime_int = MACE_SUPERIO_INT;
261 break;
262 }
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000263 pr_debug("crime_int %08x enabled\n", crime_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 crime_mask |= crime_int;
265 crime->imask = crime_mask;
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000266 maceisa_mask |= 1 << (d->irq - MACEISA_AUDIO_SW_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 mace->perif.ctrl.imask = maceisa_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
269
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000270static void disable_maceisa_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 unsigned int crime_int = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000274 maceisa_mask &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000275 if (!(maceisa_mask & MACEISA_AUDIO_INT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 crime_int |= MACE_AUDIO_INT;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000277 if (!(maceisa_mask & MACEISA_MISC_INT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 crime_int |= MACE_MISC_INT;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000279 if (!(maceisa_mask & MACEISA_SUPERIO_INT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 crime_int |= MACE_SUPERIO_INT;
281 crime_mask &= ~crime_int;
282 crime->imask = crime_mask;
283 flush_crime_bus();
284 mace->perif.ctrl.imask = maceisa_mask;
285 flush_mace_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000288static void mask_and_ack_maceisa_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900290 unsigned long mace_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Ralf Baechlec87e0902009-03-30 14:49:44 +0200292 /* edge triggered */
293 mace_int = mace->perif.ctrl.istat;
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000294 mace_int &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
Ralf Baechlec87e0902009-03-30 14:49:44 +0200295 mace->perif.ctrl.istat = mace_int;
296
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000297 disable_maceisa_irq(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Ralf Baechlec87e0902009-03-30 14:49:44 +0200300static struct irq_chip ip32_maceisa_level_interrupt = {
301 .name = "IP32 MACE ISA",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000302 .irq_mask = disable_maceisa_irq,
303 .irq_unmask = enable_maceisa_irq,
Ralf Baechlec87e0902009-03-30 14:49:44 +0200304};
305
306static struct irq_chip ip32_maceisa_edge_interrupt = {
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000307 .name = "IP32 MACE ISA",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000308 .irq_ack = mask_and_ack_maceisa_irq,
309 .irq_mask = disable_maceisa_irq,
310 .irq_mask_ack = mask_and_ack_maceisa_irq,
311 .irq_unmask = enable_maceisa_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312};
313
314/* This is used for regular non-ISA, non-PCI MACE interrupts. That means
315 * bits 0-3 and 7 in the CRIME register.
316 */
317
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000318static void enable_mace_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000320 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle98ce4722007-10-30 15:43:44 +0000321
322 crime_mask |= (1 << bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 crime->imask = crime_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000326static void disable_mace_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000328 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle98ce4722007-10-30 15:43:44 +0000329
330 crime_mask &= ~(1 << bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 crime->imask = crime_mask;
332 flush_crime_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Ralf Baechle94dee172006-07-02 14:41:42 +0100335static struct irq_chip ip32_mace_interrupt = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +0900336 .name = "IP32 MACE",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000337 .irq_mask = disable_mace_irq,
338 .irq_unmask = enable_mace_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339};
340
Ralf Baechle937a8012006-10-07 19:44:33 +0100341static void ip32_unknown_interrupt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100343 printk("Unknown interrupt occurred!\n");
344 printk("cp0_status: %08x\n", read_c0_status());
345 printk("cp0_cause: %08x\n", read_c0_cause());
346 printk("CRIME intr mask: %016lx\n", crime->imask);
347 printk("CRIME intr status: %016lx\n", crime->istat);
348 printk("CRIME hardware intr register: %016lx\n", crime->hard_int);
349 printk("MACE ISA intr mask: %08lx\n", mace->perif.ctrl.imask);
350 printk("MACE ISA intr status: %08lx\n", mace->perif.ctrl.istat);
351 printk("MACE PCI control register: %08x\n", mace->pci.control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 printk("Register dump:\n");
Ralf Baechle937a8012006-10-07 19:44:33 +0100354 show_regs(get_irq_regs());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 printk("Please mail this report to linux-mips@linux-mips.org\n");
357 printk("Spinning...");
358 while(1) ;
359}
360
361/* CRIME 1.1 appears to deliver all interrupts to this one pin. */
362/* change this to loop over all edge-triggered irqs, exception masked out ones */
Ralf Baechle937a8012006-10-07 19:44:33 +0100363static void ip32_irq0(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 uint64_t crime_int;
366 int irq = 0;
367
Ralf Baechledd67b152007-10-14 14:02:26 +0100368 /*
369 * Sanity check interrupt numbering enum.
370 * MACE got 32 interrupts and there are 32 MACE ISA interrupts daisy
371 * chained.
372 */
373 BUILD_BUG_ON(CRIME_VICE_IRQ - MACE_VID_IN1_IRQ != 31);
374 BUILD_BUG_ON(MACEISA_SERIAL2_RDMAOR_IRQ - MACEISA_AUDIO_SW_IRQ != 31);
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 crime_int = crime->istat & crime_mask;
Thomas Bogendoerfer1faf7f22008-06-24 00:48:05 +0200377
378 /* crime sometime delivers spurious interrupts, ignore them */
379 if (unlikely(crime_int == 0))
380 return;
381
Ralf Baechledd67b152007-10-14 14:02:26 +0100382 irq = MACE_VID_IN1_IRQ + __ffs(crime_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 if (crime_int & CRIME_MACEISA_INT_MASK) {
385 unsigned long mace_int = mace->perif.ctrl.istat;
Ralf Baechledd67b152007-10-14 14:02:26 +0100386 irq = __ffs(mace_int & maceisa_mask) + MACEISA_AUDIO_SW_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
Ralf Baechledd67b152007-10-14 14:02:26 +0100388
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000389 pr_debug("*irq %u*\n", irq);
Ralf Baechle937a8012006-10-07 19:44:33 +0100390 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
Ralf Baechle937a8012006-10-07 19:44:33 +0100393static void ip32_irq1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Ralf Baechle937a8012006-10-07 19:44:33 +0100395 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Ralf Baechle937a8012006-10-07 19:44:33 +0100398static void ip32_irq2(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Ralf Baechle937a8012006-10-07 19:44:33 +0100400 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401}
402
Ralf Baechle937a8012006-10-07 19:44:33 +0100403static void ip32_irq3(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Ralf Baechle937a8012006-10-07 19:44:33 +0100405 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406}
407
Ralf Baechle937a8012006-10-07 19:44:33 +0100408static void ip32_irq4(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Ralf Baechle937a8012006-10-07 19:44:33 +0100410 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
Ralf Baechle937a8012006-10-07 19:44:33 +0100413static void ip32_irq5(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Ralf Baechledd67b152007-10-14 14:02:26 +0100415 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
Ralf Baechle937a8012006-10-07 19:44:33 +0100418asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100419{
Thiemo Seufer119537c2007-03-19 00:13:37 +0000420 unsigned int pending = read_c0_status() & read_c0_cause();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100421
422 if (likely(pending & IE_IRQ0))
Ralf Baechle937a8012006-10-07 19:44:33 +0100423 ip32_irq0();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100424 else if (unlikely(pending & IE_IRQ1))
Ralf Baechle937a8012006-10-07 19:44:33 +0100425 ip32_irq1();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100426 else if (unlikely(pending & IE_IRQ2))
Ralf Baechle937a8012006-10-07 19:44:33 +0100427 ip32_irq2();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100428 else if (unlikely(pending & IE_IRQ3))
Ralf Baechle937a8012006-10-07 19:44:33 +0100429 ip32_irq3();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100430 else if (unlikely(pending & IE_IRQ4))
Ralf Baechle937a8012006-10-07 19:44:33 +0100431 ip32_irq4();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100432 else if (likely(pending & IE_IRQ5))
Ralf Baechle937a8012006-10-07 19:44:33 +0100433 ip32_irq5();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100434}
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436void __init arch_init_irq(void)
437{
438 unsigned int irq;
439
440 /* Install our interrupt handler, then clear and disable all
441 * CRIME and MACE interrupts. */
442 crime->imask = 0;
443 crime->hard_int = 0;
444 crime->soft_int = 0;
445 mace->perif.ctrl.istat = 0;
446 mace->perif.ctrl.imask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Ralf Baechledd67b152007-10-14 14:02:26 +0100448 mips_cpu_irq_init();
Ralf Baechle98ce4722007-10-30 15:43:44 +0000449 for (irq = CRIME_IRQ_BASE; irq <= IP32_IRQ_MAX; irq++) {
Ralf Baechledd67b152007-10-14 14:02:26 +0100450 switch (irq) {
451 case MACE_VID_IN1_IRQ ... MACE_PCI_BRIDGE_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200452 irq_set_chip_and_handler_name(irq,
453 &ip32_mace_interrupt,
454 handle_level_irq,
455 "level");
Ralf Baechledd67b152007-10-14 14:02:26 +0100456 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200457
Ralf Baechledd67b152007-10-14 14:02:26 +0100458 case MACEPCI_SCSI0_IRQ ... MACEPCI_SHARED2_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200459 irq_set_chip_and_handler_name(irq,
460 &ip32_macepci_interrupt,
461 handle_level_irq,
462 "level");
Ralf Baechledd67b152007-10-14 14:02:26 +0100463 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200464
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000465 case CRIME_CPUERR_IRQ:
466 case CRIME_MEMERR_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200467 irq_set_chip_and_handler_name(irq,
468 &crime_level_interrupt,
469 handle_level_irq,
470 "level");
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000471 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200472
Roel Kluin2fe06262010-01-20 00:59:27 +0100473 case CRIME_GBE0_IRQ ... CRIME_GBE3_IRQ:
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000474 case CRIME_RE_EMPTY_E_IRQ ... CRIME_RE_IDLE_E_IRQ:
475 case CRIME_SOFT0_IRQ ... CRIME_SOFT2_IRQ:
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000476 case CRIME_VICE_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200477 irq_set_chip_and_handler_name(irq,
478 &crime_edge_interrupt,
479 handle_edge_irq,
480 "edge");
Ralf Baechledd67b152007-10-14 14:02:26 +0100481 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200482
483 case MACEISA_PARALLEL_IRQ:
484 case MACEISA_SERIAL1_TDMAPR_IRQ:
485 case MACEISA_SERIAL2_TDMAPR_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200486 irq_set_chip_and_handler_name(irq,
487 &ip32_maceisa_edge_interrupt,
488 handle_edge_irq,
489 "edge");
Ralf Baechlec87e0902009-03-30 14:49:44 +0200490 break;
491
Ralf Baechledd67b152007-10-14 14:02:26 +0100492 default:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200493 irq_set_chip_and_handler_name(irq,
494 &ip32_maceisa_level_interrupt,
495 handle_level_irq,
496 "level");
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000497 break;
Ralf Baechledd67b152007-10-14 14:02:26 +0100498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500 setup_irq(CRIME_MEMERR_IRQ, &memerr_irq);
501 setup_irq(CRIME_CPUERR_IRQ, &cpuerr_irq);
502
503#define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5)
504 change_c0_status(ST0_IM, ALLINTS);
505}