2 * Code to handle IP32 IRQs
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
8 * Copyright (C) 2000 Harald Koerfgen
9 * Copyright (C) 2001 Keith M Wesolowski
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>
18 #include <linux/slab.h>
20 #include <linux/random.h>
21 #include <linux/sched.h>
23 #include <asm/irq_cpu.h>
24 #include <asm/mipsregs.h>
25 #include <asm/signal.h>
26 #include <asm/system.h>
28 #include <asm/ip32/crime.h>
29 #include <asm/ip32/mace.h>
30 #include <asm/ip32/ip32_ints.h>
32 /* issue a PIO read to make sure no PIO writes are pending */
33 static void inline flush_crime_bus(void)
38 static void inline flush_mace_bus(void)
40 mace
->perif
.ctrl
.misc
;
46 * IP0 -> software (ignored)
47 * IP1 -> software (ignored)
48 * IP2 -> (irq0) C crime 1.1 all interrupts; crime 1.5 ???
49 * IP3 -> (irq1) X unknown
50 * IP4 -> (irq2) X unknown
51 * IP5 -> (irq3) X unknown
52 * IP6 -> (irq4) X unknown
53 * IP7 -> (irq5) 7 CPU count/compare timer (system timer)
57 * CRIME_INT_STAT 31:0:
62 * 3 -> 11 Mace ethernet
63 * 4 -> S SuperIO sub-interrupt
64 * 5 -> M Miscellaneous sub-interrupt
65 * 6 -> A Audio sub-interrupt
66 * 7 -> 15 PCI bridge errors
67 * 8 -> 16 PCI SCSI aic7xxx 0
68 * 9 -> 17 PCI SCSI aic7xxx 1
70 * 11 -> 19 unused (PCI slot 1)
71 * 12 -> 20 unused (PCI slot 2)
72 * 13 -> 21 unused (PCI shared 0)
73 * 14 -> 22 unused (PCI shared 1)
74 * 15 -> 23 unused (PCI shared 2)
80 * 21 -> 29 Memory errors
81 * 22 -> 30 RE empty edge (E)
82 * 23 -> 31 RE full edge (E)
83 * 24 -> 32 RE idle edge (E)
84 * 25 -> 33 RE empty level
85 * 26 -> 34 RE full level
86 * 27 -> 35 RE idle level
87 * 28 -> 36 unused (software 0) (E)
88 * 29 -> 37 unused (software 1) (E)
89 * 30 -> 38 unused (software 2) - crime 1.5 CPU SysCorError (E)
92 * S, M, A: Use the MACE ISA interrupt register
93 * MACE_ISA_INT_STAT 31:0
98 * 10 -> X Keyboard polled
100 * 12 -> X Mouse polled
101 * 13-15 -> 53-55 Count/compare timers
102 * 16-19 -> 56-59 Parallel (16 E)
103 * 20-25 -> 60-62 Serial 1 (22 E)
104 * 26-31 -> 66-71 Serial 2 (28 E)
106 * Note that this means IRQs 12-14, 50, and 52 do not exist. This is a
107 * different IRQ map than IRIX uses, but that's OK as Linux irq handling
108 * is quite different anyway.
111 /* Some initial interrupts to set up */
112 extern irqreturn_t
crime_memerr_intr(int irq
, void *dev_id
);
113 extern irqreturn_t
crime_cpuerr_intr(int irq
, void *dev_id
);
115 struct irqaction memerr_irq
= {
116 .handler
= crime_memerr_intr
,
117 .flags
= IRQF_DISABLED
,
118 .name
= "CRIME memory error",
121 struct irqaction cpuerr_irq
= {
122 .handler
= crime_cpuerr_intr
,
123 .flags
= IRQF_DISABLED
,
124 .name
= "CRIME CPU error",
128 * This is for pure CRIME interrupts - ie not MACE. The advantage?
129 * We get to split the register in half and do faster lookups.
132 static uint64_t crime_mask
;
134 static inline void crime_enable_irq(unsigned int irq
)
136 unsigned int bit
= irq
- CRIME_IRQ_BASE
;
138 crime_mask
|= 1 << bit
;
139 crime
->imask
= crime_mask
;
142 static inline void crime_disable_irq(unsigned int irq
)
144 unsigned int bit
= irq
- CRIME_IRQ_BASE
;
146 crime_mask
&= ~(1 << bit
);
147 crime
->imask
= crime_mask
;
151 static void crime_level_mask_and_ack_irq(unsigned int irq
)
153 crime_disable_irq(irq
);
156 static void crime_level_end_irq(unsigned int irq
)
158 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
)))
159 crime_enable_irq(irq
);
162 static struct irq_chip crime_level_interrupt
= {
163 .name
= "IP32 CRIME",
164 .ack
= crime_level_mask_and_ack_irq
,
165 .mask
= crime_disable_irq
,
166 .mask_ack
= crime_level_mask_and_ack_irq
,
167 .unmask
= crime_enable_irq
,
168 .end
= crime_level_end_irq
,
171 static void crime_edge_mask_and_ack_irq(unsigned int irq
)
173 unsigned int bit
= irq
- CRIME_IRQ_BASE
;
176 /* Edge triggered interrupts must be cleared. */
178 crime_int
= crime
->hard_int
;
179 crime_int
&= ~(1 << bit
);
180 crime
->hard_int
= crime_int
;
182 crime_disable_irq(irq
);
185 static void crime_edge_end_irq(unsigned int irq
)
187 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
)))
188 crime_enable_irq(irq
);
191 static struct irq_chip crime_edge_interrupt
= {
192 .name
= "IP32 CRIME",
193 .ack
= crime_edge_mask_and_ack_irq
,
194 .mask
= crime_disable_irq
,
195 .mask_ack
= crime_edge_mask_and_ack_irq
,
196 .unmask
= crime_enable_irq
,
197 .end
= crime_edge_end_irq
,
201 * This is for MACE PCI interrupts. We can decrease bus traffic by masking
202 * as close to the source as possible. This also means we can take the
203 * next chunk of the CRIME register in one piece.
206 static unsigned long macepci_mask
;
208 static void enable_macepci_irq(unsigned int irq
)
210 macepci_mask
|= MACEPCI_CONTROL_INT(irq
- MACEPCI_SCSI0_IRQ
);
211 mace
->pci
.control
= macepci_mask
;
212 crime_mask
|= 1 << (irq
- CRIME_IRQ_BASE
);
213 crime
->imask
= crime_mask
;
216 static void disable_macepci_irq(unsigned int irq
)
218 crime_mask
&= ~(1 << (irq
- CRIME_IRQ_BASE
));
219 crime
->imask
= crime_mask
;
221 macepci_mask
&= ~MACEPCI_CONTROL_INT(irq
- MACEPCI_SCSI0_IRQ
);
222 mace
->pci
.control
= macepci_mask
;
226 static void end_macepci_irq(unsigned int irq
)
228 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
|IRQ_INPROGRESS
)))
229 enable_macepci_irq(irq
);
232 static struct irq_chip ip32_macepci_interrupt
= {
233 .name
= "IP32 MACE PCI",
234 .ack
= disable_macepci_irq
,
235 .mask
= disable_macepci_irq
,
236 .mask_ack
= disable_macepci_irq
,
237 .unmask
= enable_macepci_irq
,
238 .end
= end_macepci_irq
,
241 /* This is used for MACE ISA interrupts. That means bits 4-6 in the
245 #define MACEISA_AUDIO_INT (MACEISA_AUDIO_SW_INT | \
246 MACEISA_AUDIO_SC_INT | \
247 MACEISA_AUDIO1_DMAT_INT | \
248 MACEISA_AUDIO1_OF_INT | \
249 MACEISA_AUDIO2_DMAT_INT | \
250 MACEISA_AUDIO2_MERR_INT | \
251 MACEISA_AUDIO3_DMAT_INT | \
252 MACEISA_AUDIO3_MERR_INT)
253 #define MACEISA_MISC_INT (MACEISA_RTC_INT | \
255 MACEISA_KEYB_POLL_INT | \
256 MACEISA_MOUSE_INT | \
257 MACEISA_MOUSE_POLL_INT | \
258 MACEISA_TIMER0_INT | \
259 MACEISA_TIMER1_INT | \
261 #define MACEISA_SUPERIO_INT (MACEISA_PARALLEL_INT | \
262 MACEISA_PAR_CTXA_INT | \
263 MACEISA_PAR_CTXB_INT | \
264 MACEISA_PAR_MERR_INT | \
265 MACEISA_SERIAL1_INT | \
266 MACEISA_SERIAL1_TDMAT_INT | \
267 MACEISA_SERIAL1_TDMAPR_INT | \
268 MACEISA_SERIAL1_TDMAME_INT | \
269 MACEISA_SERIAL1_RDMAT_INT | \
270 MACEISA_SERIAL1_RDMAOR_INT | \
271 MACEISA_SERIAL2_INT | \
272 MACEISA_SERIAL2_TDMAT_INT | \
273 MACEISA_SERIAL2_TDMAPR_INT | \
274 MACEISA_SERIAL2_TDMAME_INT | \
275 MACEISA_SERIAL2_RDMAT_INT | \
276 MACEISA_SERIAL2_RDMAOR_INT)
278 static unsigned long maceisa_mask
;
280 static void enable_maceisa_irq(unsigned int irq
)
282 unsigned int crime_int
= 0;
284 pr_debug("maceisa enable: %u\n", irq
);
287 case MACEISA_AUDIO_SW_IRQ
... MACEISA_AUDIO3_MERR_IRQ
:
288 crime_int
= MACE_AUDIO_INT
;
290 case MACEISA_RTC_IRQ
... MACEISA_TIMER2_IRQ
:
291 crime_int
= MACE_MISC_INT
;
293 case MACEISA_PARALLEL_IRQ
... MACEISA_SERIAL2_RDMAOR_IRQ
:
294 crime_int
= MACE_SUPERIO_INT
;
297 pr_debug("crime_int %08x enabled\n", crime_int
);
298 crime_mask
|= crime_int
;
299 crime
->imask
= crime_mask
;
300 maceisa_mask
|= 1 << (irq
- MACEISA_AUDIO_SW_IRQ
);
301 mace
->perif
.ctrl
.imask
= maceisa_mask
;
304 static void disable_maceisa_irq(unsigned int irq
)
306 unsigned int crime_int
= 0;
308 maceisa_mask
&= ~(1 << (irq
- MACEISA_AUDIO_SW_IRQ
));
309 if (!(maceisa_mask
& MACEISA_AUDIO_INT
))
310 crime_int
|= MACE_AUDIO_INT
;
311 if (!(maceisa_mask
& MACEISA_MISC_INT
))
312 crime_int
|= MACE_MISC_INT
;
313 if (!(maceisa_mask
& MACEISA_SUPERIO_INT
))
314 crime_int
|= MACE_SUPERIO_INT
;
315 crime_mask
&= ~crime_int
;
316 crime
->imask
= crime_mask
;
318 mace
->perif
.ctrl
.imask
= maceisa_mask
;
322 static void mask_and_ack_maceisa_irq(unsigned int irq
)
324 unsigned long mace_int
;
327 case MACEISA_PARALLEL_IRQ
:
328 case MACEISA_SERIAL1_TDMAPR_IRQ
:
329 case MACEISA_SERIAL2_TDMAPR_IRQ
:
331 mace_int
= mace
->perif
.ctrl
.istat
;
332 mace_int
&= ~(1 << (irq
- MACEISA_AUDIO_SW_IRQ
));
333 mace
->perif
.ctrl
.istat
= mace_int
;
336 disable_maceisa_irq(irq
);
339 static void end_maceisa_irq(unsigned irq
)
341 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
)))
342 enable_maceisa_irq(irq
);
345 static struct irq_chip ip32_maceisa_interrupt
= {
346 .name
= "IP32 MACE ISA",
347 .ack
= mask_and_ack_maceisa_irq
,
348 .mask
= disable_maceisa_irq
,
349 .mask_ack
= mask_and_ack_maceisa_irq
,
350 .unmask
= enable_maceisa_irq
,
351 .end
= end_maceisa_irq
,
354 /* This is used for regular non-ISA, non-PCI MACE interrupts. That means
355 * bits 0-3 and 7 in the CRIME register.
358 static void enable_mace_irq(unsigned int irq
)
360 unsigned int bit
= irq
- CRIME_IRQ_BASE
;
362 crime_mask
|= (1 << bit
);
363 crime
->imask
= crime_mask
;
366 static void disable_mace_irq(unsigned int irq
)
368 unsigned int bit
= irq
- CRIME_IRQ_BASE
;
370 crime_mask
&= ~(1 << bit
);
371 crime
->imask
= crime_mask
;
375 static void end_mace_irq(unsigned int irq
)
377 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
|IRQ_INPROGRESS
)))
378 enable_mace_irq(irq
);
381 static struct irq_chip ip32_mace_interrupt
= {
383 .ack
= disable_mace_irq
,
384 .mask
= disable_mace_irq
,
385 .mask_ack
= disable_mace_irq
,
386 .unmask
= enable_mace_irq
,
390 static void ip32_unknown_interrupt(void)
392 printk("Unknown interrupt occurred!\n");
393 printk("cp0_status: %08x\n", read_c0_status());
394 printk("cp0_cause: %08x\n", read_c0_cause());
395 printk("CRIME intr mask: %016lx\n", crime
->imask
);
396 printk("CRIME intr status: %016lx\n", crime
->istat
);
397 printk("CRIME hardware intr register: %016lx\n", crime
->hard_int
);
398 printk("MACE ISA intr mask: %08lx\n", mace
->perif
.ctrl
.imask
);
399 printk("MACE ISA intr status: %08lx\n", mace
->perif
.ctrl
.istat
);
400 printk("MACE PCI control register: %08x\n", mace
->pci
.control
);
402 printk("Register dump:\n");
403 show_regs(get_irq_regs());
405 printk("Please mail this report to linux-mips@linux-mips.org\n");
406 printk("Spinning...");
410 /* CRIME 1.1 appears to deliver all interrupts to this one pin. */
411 /* change this to loop over all edge-triggered irqs, exception masked out ones */
412 static void ip32_irq0(void)
418 * Sanity check interrupt numbering enum.
419 * MACE got 32 interrupts and there are 32 MACE ISA interrupts daisy
422 BUILD_BUG_ON(CRIME_VICE_IRQ
- MACE_VID_IN1_IRQ
!= 31);
423 BUILD_BUG_ON(MACEISA_SERIAL2_RDMAOR_IRQ
- MACEISA_AUDIO_SW_IRQ
!= 31);
425 crime_int
= crime
->istat
& crime_mask
;
427 /* crime sometime delivers spurious interrupts, ignore them */
428 if (unlikely(crime_int
== 0))
431 irq
= MACE_VID_IN1_IRQ
+ __ffs(crime_int
);
433 if (crime_int
& CRIME_MACEISA_INT_MASK
) {
434 unsigned long mace_int
= mace
->perif
.ctrl
.istat
;
435 irq
= __ffs(mace_int
& maceisa_mask
) + MACEISA_AUDIO_SW_IRQ
;
438 pr_debug("*irq %u*\n", irq
);
442 static void ip32_irq1(void)
444 ip32_unknown_interrupt();
447 static void ip32_irq2(void)
449 ip32_unknown_interrupt();
452 static void ip32_irq3(void)
454 ip32_unknown_interrupt();
457 static void ip32_irq4(void)
459 ip32_unknown_interrupt();
462 static void ip32_irq5(void)
464 do_IRQ(MIPS_CPU_IRQ_BASE
+ 7);
467 asmlinkage
void plat_irq_dispatch(void)
469 unsigned int pending
= read_c0_status() & read_c0_cause();
471 if (likely(pending
& IE_IRQ0
))
473 else if (unlikely(pending
& IE_IRQ1
))
475 else if (unlikely(pending
& IE_IRQ2
))
477 else if (unlikely(pending
& IE_IRQ3
))
479 else if (unlikely(pending
& IE_IRQ4
))
481 else if (likely(pending
& IE_IRQ5
))
485 void __init
arch_init_irq(void)
489 /* Install our interrupt handler, then clear and disable all
490 * CRIME and MACE interrupts. */
494 mace
->perif
.ctrl
.istat
= 0;
495 mace
->perif
.ctrl
.imask
= 0;
498 for (irq
= CRIME_IRQ_BASE
; irq
<= IP32_IRQ_MAX
; irq
++) {
500 case MACE_VID_IN1_IRQ
... MACE_PCI_BRIDGE_IRQ
:
501 set_irq_chip(irq
, &ip32_mace_interrupt
);
503 case MACEPCI_SCSI0_IRQ
... MACEPCI_SHARED2_IRQ
:
504 set_irq_chip(irq
, &ip32_macepci_interrupt
);
506 case CRIME_GBE0_IRQ
... CRIME_GBE3_IRQ
:
507 set_irq_chip(irq
, &crime_edge_interrupt
);
509 case CRIME_CPUERR_IRQ
:
510 case CRIME_MEMERR_IRQ
:
511 set_irq_chip(irq
, &crime_level_interrupt
);
513 case CRIME_RE_EMPTY_E_IRQ
... CRIME_RE_IDLE_E_IRQ
:
514 case CRIME_SOFT0_IRQ
... CRIME_SOFT2_IRQ
:
515 set_irq_chip(irq
, &crime_edge_interrupt
);
518 set_irq_chip(irq
, &crime_edge_interrupt
);
521 set_irq_chip(irq
, &ip32_maceisa_interrupt
);
525 setup_irq(CRIME_MEMERR_IRQ
, &memerr_irq
);
526 setup_irq(CRIME_CPUERR_IRQ
, &cpuerr_irq
);
528 #define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5)
529 change_c0_status(ST0_IM
, ALLINTS
);