blob: e0c7d9e142fa8c3c8b68f86c5990eae2d07506b5 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/time.h>
26#include <asm/ip32/crime.h>
27#include <asm/ip32/mace.h>
28#include <asm/ip32/ip32_ints.h>
29
30/* issue a PIO read to make sure no PIO writes are pending */
31static void inline flush_crime_bus(void)
32{
Ralf Baechleb6d7c7a2006-05-30 02:13:16 +010033 crime->control;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
36static void inline flush_mace_bus(void)
37{
Ralf Baechleb6d7c7a2006-05-30 02:13:16 +010038 mace->perif.ctrl.misc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
Ralf Baechledd67b152007-10-14 14:02:26 +010041/*
42 * O2 irq map
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 *
44 * IP0 -> software (ignored)
45 * IP1 -> software (ignored)
46 * IP2 -> (irq0) C crime 1.1 all interrupts; crime 1.5 ???
47 * IP3 -> (irq1) X unknown
48 * IP4 -> (irq2) X unknown
49 * IP5 -> (irq3) X unknown
50 * IP6 -> (irq4) X unknown
Ralf Baechledd67b152007-10-14 14:02:26 +010051 * IP7 -> (irq5) 7 CPU count/compare timer (system timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 *
53 * crime: (C)
54 *
55 * CRIME_INT_STAT 31:0:
56 *
Ralf Baechledd67b152007-10-14 14:02:26 +010057 * 0 -> 8 Video in 1
58 * 1 -> 9 Video in 2
59 * 2 -> 10 Video out
60 * 3 -> 11 Mace ethernet
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 * 4 -> S SuperIO sub-interrupt
62 * 5 -> M Miscellaneous sub-interrupt
63 * 6 -> A Audio sub-interrupt
Ralf Baechledd67b152007-10-14 14:02:26 +010064 * 7 -> 15 PCI bridge errors
65 * 8 -> 16 PCI SCSI aic7xxx 0
66 * 9 -> 17 PCI SCSI aic7xxx 1
67 * 10 -> 18 PCI slot 0
68 * 11 -> 19 unused (PCI slot 1)
69 * 12 -> 20 unused (PCI slot 2)
70 * 13 -> 21 unused (PCI shared 0)
71 * 14 -> 22 unused (PCI shared 1)
72 * 15 -> 23 unused (PCI shared 2)
73 * 16 -> 24 GBE0 (E)
74 * 17 -> 25 GBE1 (E)
75 * 18 -> 26 GBE2 (E)
76 * 19 -> 27 GBE3 (E)
77 * 20 -> 28 CPU errors
78 * 21 -> 29 Memory errors
79 * 22 -> 30 RE empty edge (E)
80 * 23 -> 31 RE full edge (E)
81 * 24 -> 32 RE idle edge (E)
82 * 25 -> 33 RE empty level
83 * 26 -> 34 RE full level
84 * 27 -> 35 RE idle level
85 * 28 -> 36 unused (software 0) (E)
86 * 29 -> 37 unused (software 1) (E)
87 * 30 -> 38 unused (software 2) - crime 1.5 CPU SysCorError (E)
88 * 31 -> 39 VICE
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 *
90 * S, M, A: Use the MACE ISA interrupt register
91 * MACE_ISA_INT_STAT 31:0
92 *
Ralf Baechledd67b152007-10-14 14:02:26 +010093 * 0-7 -> 40-47 Audio
94 * 8 -> 48 RTC
95 * 9 -> 49 Keyboard
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 * 10 -> X Keyboard polled
Ralf Baechledd67b152007-10-14 14:02:26 +010097 * 11 -> 51 Mouse
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 * 12 -> X Mouse polled
Ralf Baechledd67b152007-10-14 14:02:26 +010099 * 13-15 -> 53-55 Count/compare timers
100 * 16-19 -> 56-59 Parallel (16 E)
101 * 20-25 -> 60-62 Serial 1 (22 E)
102 * 26-31 -> 66-71 Serial 2 (28 E)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 *
Ralf Baechledd67b152007-10-14 14:02:26 +0100104 * Note that this means IRQs 12-14, 50, and 52 do not exist. This is a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 * different IRQ map than IRIX uses, but that's OK as Linux irq handling
106 * is quite different anyway.
107 */
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* Some initial interrupts to set up */
Ralf Baechle937a8012006-10-07 19:44:33 +0100110extern irqreturn_t crime_memerr_intr(int irq, void *dev_id);
111extern irqreturn_t crime_cpuerr_intr(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Dmitri Vorobievae537382009-03-30 22:53:25 +0300113static struct irqaction memerr_irq = {
Thomas Gleixner4e451712007-08-28 09:03:01 +0000114 .handler = crime_memerr_intr,
Thomas Gleixner4e451712007-08-28 09:03:01 +0000115 .name = "CRIME memory error",
116};
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000117
Dmitri Vorobievae537382009-03-30 22:53:25 +0300118static struct irqaction cpuerr_irq = {
Thomas Gleixner4e451712007-08-28 09:03:01 +0000119 .handler = crime_cpuerr_intr,
Thomas Gleixner4e451712007-08-28 09:03:01 +0000120 .name = "CRIME CPU error",
121};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 * This is for pure CRIME interrupts - ie not MACE. The advantage?
125 * We get to split the register in half and do faster lookups.
126 */
127
128static uint64_t crime_mask;
129
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000130static inline void crime_enable_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000132 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000133
134 crime_mask |= 1 << bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 crime->imask = crime_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000138static inline void crime_disable_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000140 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000141
142 crime_mask &= ~(1 << bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 crime->imask = crime_mask;
144 flush_crime_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000147static struct irq_chip crime_level_interrupt = {
148 .name = "IP32 CRIME",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000149 .irq_mask = crime_disable_irq,
150 .irq_unmask = crime_enable_irq,
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000151};
152
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000153static void crime_edge_mask_and_ack_irq(struct irq_data *d)
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000154{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000155 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000156 uint64_t crime_int;
157
158 /* Edge triggered interrupts must be cleared. */
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000159 crime_int = crime->hard_int;
160 crime_int &= ~(1 << bit);
161 crime->hard_int = crime_int;
162
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000163 crime_disable_irq(d);
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000164}
165
166static struct irq_chip crime_edge_interrupt = {
167 .name = "IP32 CRIME",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000168 .irq_ack = crime_edge_mask_and_ack_irq,
169 .irq_mask = crime_disable_irq,
170 .irq_mask_ack = crime_edge_mask_and_ack_irq,
171 .irq_unmask = crime_enable_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
174/*
175 * This is for MACE PCI interrupts. We can decrease bus traffic by masking
Ralf Baechle70342282013-01-22 12:59:30 +0100176 * as close to the source as possible. This also means we can take the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 * next chunk of the CRIME register in one piece.
178 */
179
180static unsigned long macepci_mask;
181
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000182static void enable_macepci_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000184 macepci_mask |= MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 mace->pci.control = macepci_mask;
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000186 crime_mask |= 1 << (d->irq - CRIME_IRQ_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 crime->imask = crime_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000190static void disable_macepci_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000192 crime_mask &= ~(1 << (d->irq - CRIME_IRQ_BASE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 crime->imask = crime_mask;
194 flush_crime_bus();
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000195 macepci_mask &= ~MACEPCI_CONTROL_INT(d->irq - MACEPCI_SCSI0_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 mace->pci.control = macepci_mask;
197 flush_mace_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Ralf Baechle94dee172006-07-02 14:41:42 +0100200static struct irq_chip ip32_macepci_interrupt = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +0900201 .name = "IP32 MACE PCI",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000202 .irq_mask = disable_macepci_irq,
203 .irq_unmask = enable_macepci_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204};
205
206/* This is used for MACE ISA interrupts. That means bits 4-6 in the
207 * CRIME register.
208 */
209
210#define MACEISA_AUDIO_INT (MACEISA_AUDIO_SW_INT | \
211 MACEISA_AUDIO_SC_INT | \
212 MACEISA_AUDIO1_DMAT_INT | \
213 MACEISA_AUDIO1_OF_INT | \
214 MACEISA_AUDIO2_DMAT_INT | \
215 MACEISA_AUDIO2_MERR_INT | \
216 MACEISA_AUDIO3_DMAT_INT | \
217 MACEISA_AUDIO3_MERR_INT)
218#define MACEISA_MISC_INT (MACEISA_RTC_INT | \
219 MACEISA_KEYB_INT | \
220 MACEISA_KEYB_POLL_INT | \
221 MACEISA_MOUSE_INT | \
222 MACEISA_MOUSE_POLL_INT | \
Thiemo Seufercfbae5d2006-07-05 18:43:29 +0100223 MACEISA_TIMER0_INT | \
224 MACEISA_TIMER1_INT | \
225 MACEISA_TIMER2_INT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define MACEISA_SUPERIO_INT (MACEISA_PARALLEL_INT | \
227 MACEISA_PAR_CTXA_INT | \
228 MACEISA_PAR_CTXB_INT | \
229 MACEISA_PAR_MERR_INT | \
230 MACEISA_SERIAL1_INT | \
231 MACEISA_SERIAL1_TDMAT_INT | \
232 MACEISA_SERIAL1_TDMAPR_INT | \
233 MACEISA_SERIAL1_TDMAME_INT | \
234 MACEISA_SERIAL1_RDMAT_INT | \
235 MACEISA_SERIAL1_RDMAOR_INT | \
236 MACEISA_SERIAL2_INT | \
237 MACEISA_SERIAL2_TDMAT_INT | \
238 MACEISA_SERIAL2_TDMAPR_INT | \
239 MACEISA_SERIAL2_TDMAME_INT | \
240 MACEISA_SERIAL2_RDMAT_INT | \
241 MACEISA_SERIAL2_RDMAOR_INT)
242
243static unsigned long maceisa_mask;
244
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000245static void enable_maceisa_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 unsigned int crime_int = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000249 pr_debug("maceisa enable: %u\n", d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000251 switch (d->irq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 case MACEISA_AUDIO_SW_IRQ ... MACEISA_AUDIO3_MERR_IRQ:
253 crime_int = MACE_AUDIO_INT;
254 break;
Thiemo Seufercfbae5d2006-07-05 18:43:29 +0100255 case MACEISA_RTC_IRQ ... MACEISA_TIMER2_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 crime_int = MACE_MISC_INT;
257 break;
258 case MACEISA_PARALLEL_IRQ ... MACEISA_SERIAL2_RDMAOR_IRQ:
259 crime_int = MACE_SUPERIO_INT;
260 break;
261 }
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000262 pr_debug("crime_int %08x enabled\n", crime_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 crime_mask |= crime_int;
264 crime->imask = crime_mask;
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000265 maceisa_mask |= 1 << (d->irq - MACEISA_AUDIO_SW_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 mace->perif.ctrl.imask = maceisa_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000269static void disable_maceisa_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
271 unsigned int crime_int = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000273 maceisa_mask &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
Ralf Baechle70342282013-01-22 12:59:30 +0100274 if (!(maceisa_mask & MACEISA_AUDIO_INT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 crime_int |= MACE_AUDIO_INT;
Ralf Baechle70342282013-01-22 12:59:30 +0100276 if (!(maceisa_mask & MACEISA_MISC_INT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 crime_int |= MACE_MISC_INT;
Ralf Baechle70342282013-01-22 12:59:30 +0100278 if (!(maceisa_mask & MACEISA_SUPERIO_INT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 crime_int |= MACE_SUPERIO_INT;
280 crime_mask &= ~crime_int;
281 crime->imask = crime_mask;
282 flush_crime_bus();
283 mace->perif.ctrl.imask = maceisa_mask;
284 flush_mace_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000287static void mask_and_ack_maceisa_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900289 unsigned long mace_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Ralf Baechlec87e0902009-03-30 14:49:44 +0200291 /* edge triggered */
292 mace_int = mace->perif.ctrl.istat;
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000293 mace_int &= ~(1 << (d->irq - MACEISA_AUDIO_SW_IRQ));
Ralf Baechlec87e0902009-03-30 14:49:44 +0200294 mace->perif.ctrl.istat = mace_int;
295
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000296 disable_maceisa_irq(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
Ralf Baechlec87e0902009-03-30 14:49:44 +0200299static struct irq_chip ip32_maceisa_level_interrupt = {
300 .name = "IP32 MACE ISA",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000301 .irq_mask = disable_maceisa_irq,
302 .irq_unmask = enable_maceisa_irq,
Ralf Baechlec87e0902009-03-30 14:49:44 +0200303};
304
305static struct irq_chip ip32_maceisa_edge_interrupt = {
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000306 .name = "IP32 MACE ISA",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000307 .irq_ack = mask_and_ack_maceisa_irq,
308 .irq_mask = disable_maceisa_irq,
309 .irq_mask_ack = mask_and_ack_maceisa_irq,
310 .irq_unmask = enable_maceisa_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311};
312
313/* This is used for regular non-ISA, non-PCI MACE interrupts. That means
314 * bits 0-3 and 7 in the CRIME register.
315 */
316
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000317static void enable_mace_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000319 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle98ce4722007-10-30 15:43:44 +0000320
321 crime_mask |= (1 << bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 crime->imask = crime_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323}
324
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000325static void disable_mace_irq(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000327 unsigned int bit = d->irq - CRIME_IRQ_BASE;
Ralf Baechle98ce4722007-10-30 15:43:44 +0000328
329 crime_mask &= ~(1 << bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 crime->imask = crime_mask;
331 flush_crime_bus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Ralf Baechle94dee172006-07-02 14:41:42 +0100334static struct irq_chip ip32_mace_interrupt = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +0900335 .name = "IP32 MACE",
Thomas Gleixner4d2796f2011-03-23 21:09:13 +0000336 .irq_mask = disable_mace_irq,
337 .irq_unmask = enable_mace_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338};
339
Ralf Baechle937a8012006-10-07 19:44:33 +0100340static void ip32_unknown_interrupt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100342 printk("Unknown interrupt occurred!\n");
343 printk("cp0_status: %08x\n", read_c0_status());
344 printk("cp0_cause: %08x\n", read_c0_cause());
345 printk("CRIME intr mask: %016lx\n", crime->imask);
346 printk("CRIME intr status: %016lx\n", crime->istat);
347 printk("CRIME hardware intr register: %016lx\n", crime->hard_int);
348 printk("MACE ISA intr mask: %08lx\n", mace->perif.ctrl.imask);
349 printk("MACE ISA intr status: %08lx\n", mace->perif.ctrl.istat);
350 printk("MACE PCI control register: %08x\n", mace->pci.control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 printk("Register dump:\n");
Ralf Baechle937a8012006-10-07 19:44:33 +0100353 show_regs(get_irq_regs());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 printk("Please mail this report to linux-mips@linux-mips.org\n");
356 printk("Spinning...");
357 while(1) ;
358}
359
360/* CRIME 1.1 appears to deliver all interrupts to this one pin. */
361/* change this to loop over all edge-triggered irqs, exception masked out ones */
Ralf Baechle937a8012006-10-07 19:44:33 +0100362static void ip32_irq0(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 uint64_t crime_int;
365 int irq = 0;
366
Ralf Baechledd67b152007-10-14 14:02:26 +0100367 /*
368 * Sanity check interrupt numbering enum.
369 * MACE got 32 interrupts and there are 32 MACE ISA interrupts daisy
370 * chained.
371 */
372 BUILD_BUG_ON(CRIME_VICE_IRQ - MACE_VID_IN1_IRQ != 31);
373 BUILD_BUG_ON(MACEISA_SERIAL2_RDMAOR_IRQ - MACEISA_AUDIO_SW_IRQ != 31);
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 crime_int = crime->istat & crime_mask;
Thomas Bogendoerfer1faf7f22008-06-24 00:48:05 +0200376
377 /* crime sometime delivers spurious interrupts, ignore them */
378 if (unlikely(crime_int == 0))
379 return;
380
Ralf Baechledd67b152007-10-14 14:02:26 +0100381 irq = MACE_VID_IN1_IRQ + __ffs(crime_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 if (crime_int & CRIME_MACEISA_INT_MASK) {
384 unsigned long mace_int = mace->perif.ctrl.istat;
Ralf Baechledd67b152007-10-14 14:02:26 +0100385 irq = __ffs(mace_int & maceisa_mask) + MACEISA_AUDIO_SW_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
Ralf Baechledd67b152007-10-14 14:02:26 +0100387
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000388 pr_debug("*irq %u*\n", irq);
Ralf Baechle937a8012006-10-07 19:44:33 +0100389 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390}
391
Ralf Baechle937a8012006-10-07 19:44:33 +0100392static void ip32_irq1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Ralf Baechle937a8012006-10-07 19:44:33 +0100394 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
Ralf Baechle937a8012006-10-07 19:44:33 +0100397static void ip32_irq2(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Ralf Baechle937a8012006-10-07 19:44:33 +0100399 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
Ralf Baechle937a8012006-10-07 19:44:33 +0100402static void ip32_irq3(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Ralf Baechle937a8012006-10-07 19:44:33 +0100404 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
Ralf Baechle937a8012006-10-07 19:44:33 +0100407static void ip32_irq4(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Ralf Baechle937a8012006-10-07 19:44:33 +0100409 ip32_unknown_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
Ralf Baechle937a8012006-10-07 19:44:33 +0100412static void ip32_irq5(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Ralf Baechledd67b152007-10-14 14:02:26 +0100414 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
Ralf Baechle937a8012006-10-07 19:44:33 +0100417asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100418{
Thiemo Seufer119537c2007-03-19 00:13:37 +0000419 unsigned int pending = read_c0_status() & read_c0_cause();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100420
421 if (likely(pending & IE_IRQ0))
Ralf Baechle937a8012006-10-07 19:44:33 +0100422 ip32_irq0();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100423 else if (unlikely(pending & IE_IRQ1))
Ralf Baechle937a8012006-10-07 19:44:33 +0100424 ip32_irq1();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100425 else if (unlikely(pending & IE_IRQ2))
Ralf Baechle937a8012006-10-07 19:44:33 +0100426 ip32_irq2();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100427 else if (unlikely(pending & IE_IRQ3))
Ralf Baechle937a8012006-10-07 19:44:33 +0100428 ip32_irq3();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100429 else if (unlikely(pending & IE_IRQ4))
Ralf Baechle937a8012006-10-07 19:44:33 +0100430 ip32_irq4();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100431 else if (likely(pending & IE_IRQ5))
Ralf Baechle937a8012006-10-07 19:44:33 +0100432 ip32_irq5();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100433}
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435void __init arch_init_irq(void)
436{
437 unsigned int irq;
438
439 /* Install our interrupt handler, then clear and disable all
440 * CRIME and MACE interrupts. */
441 crime->imask = 0;
442 crime->hard_int = 0;
443 crime->soft_int = 0;
444 mace->perif.ctrl.istat = 0;
445 mace->perif.ctrl.imask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Ralf Baechledd67b152007-10-14 14:02:26 +0100447 mips_cpu_irq_init();
Ralf Baechle98ce4722007-10-30 15:43:44 +0000448 for (irq = CRIME_IRQ_BASE; irq <= IP32_IRQ_MAX; irq++) {
Ralf Baechledd67b152007-10-14 14:02:26 +0100449 switch (irq) {
450 case MACE_VID_IN1_IRQ ... MACE_PCI_BRIDGE_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200451 irq_set_chip_and_handler_name(irq,
452 &ip32_mace_interrupt,
453 handle_level_irq,
454 "level");
Ralf Baechledd67b152007-10-14 14:02:26 +0100455 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200456
Ralf Baechledd67b152007-10-14 14:02:26 +0100457 case MACEPCI_SCSI0_IRQ ... MACEPCI_SHARED2_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200458 irq_set_chip_and_handler_name(irq,
459 &ip32_macepci_interrupt,
460 handle_level_irq,
461 "level");
Ralf Baechledd67b152007-10-14 14:02:26 +0100462 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200463
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000464 case CRIME_CPUERR_IRQ:
465 case CRIME_MEMERR_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200466 irq_set_chip_and_handler_name(irq,
467 &crime_level_interrupt,
468 handle_level_irq,
469 "level");
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000470 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200471
Roel Kluin2fe06262010-01-20 00:59:27 +0100472 case CRIME_GBE0_IRQ ... CRIME_GBE3_IRQ:
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000473 case CRIME_RE_EMPTY_E_IRQ ... CRIME_RE_IDLE_E_IRQ:
474 case CRIME_SOFT0_IRQ ... CRIME_SOFT2_IRQ:
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000475 case CRIME_VICE_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200476 irq_set_chip_and_handler_name(irq,
477 &crime_edge_interrupt,
478 handle_edge_irq,
479 "edge");
Ralf Baechledd67b152007-10-14 14:02:26 +0100480 break;
Ralf Baechlec87e0902009-03-30 14:49:44 +0200481
482 case MACEISA_PARALLEL_IRQ:
483 case MACEISA_SERIAL1_TDMAPR_IRQ:
484 case MACEISA_SERIAL2_TDMAPR_IRQ:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200485 irq_set_chip_and_handler_name(irq,
486 &ip32_maceisa_edge_interrupt,
487 handle_edge_irq,
488 "edge");
Ralf Baechlec87e0902009-03-30 14:49:44 +0200489 break;
490
Ralf Baechledd67b152007-10-14 14:02:26 +0100491 default:
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200492 irq_set_chip_and_handler_name(irq,
493 &ip32_maceisa_level_interrupt,
494 handle_level_irq,
495 "level");
Ralf Baechle8a13ecd2007-10-28 18:46:39 +0000496 break;
Ralf Baechledd67b152007-10-14 14:02:26 +0100497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499 setup_irq(CRIME_MEMERR_IRQ, &memerr_irq);
500 setup_irq(CRIME_CPUERR_IRQ, &cpuerr_irq);
501
502#define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5)
503 change_c0_status(ST0_IM, ALLINTS);
504}