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
;
45 #define DBG(x...) printk(x)
53 * IP0 -> software (ignored)
54 * IP1 -> software (ignored)
55 * IP2 -> (irq0) C crime 1.1 all interrupts; crime 1.5 ???
56 * IP3 -> (irq1) X unknown
57 * IP4 -> (irq2) X unknown
58 * IP5 -> (irq3) X unknown
59 * IP6 -> (irq4) X unknown
60 * IP7 -> (irq5) 7 CPU count/compare timer (system timer)
64 * CRIME_INT_STAT 31:0:
69 * 3 -> 11 Mace ethernet
70 * 4 -> S SuperIO sub-interrupt
71 * 5 -> M Miscellaneous sub-interrupt
72 * 6 -> A Audio sub-interrupt
73 * 7 -> 15 PCI bridge errors
74 * 8 -> 16 PCI SCSI aic7xxx 0
75 * 9 -> 17 PCI SCSI aic7xxx 1
77 * 11 -> 19 unused (PCI slot 1)
78 * 12 -> 20 unused (PCI slot 2)
79 * 13 -> 21 unused (PCI shared 0)
80 * 14 -> 22 unused (PCI shared 1)
81 * 15 -> 23 unused (PCI shared 2)
87 * 21 -> 29 Memory errors
88 * 22 -> 30 RE empty edge (E)
89 * 23 -> 31 RE full edge (E)
90 * 24 -> 32 RE idle edge (E)
91 * 25 -> 33 RE empty level
92 * 26 -> 34 RE full level
93 * 27 -> 35 RE idle level
94 * 28 -> 36 unused (software 0) (E)
95 * 29 -> 37 unused (software 1) (E)
96 * 30 -> 38 unused (software 2) - crime 1.5 CPU SysCorError (E)
99 * S, M, A: Use the MACE ISA interrupt register
100 * MACE_ISA_INT_STAT 31:0
105 * 10 -> X Keyboard polled
107 * 12 -> X Mouse polled
108 * 13-15 -> 53-55 Count/compare timers
109 * 16-19 -> 56-59 Parallel (16 E)
110 * 20-25 -> 60-62 Serial 1 (22 E)
111 * 26-31 -> 66-71 Serial 2 (28 E)
113 * Note that this means IRQs 12-14, 50, and 52 do not exist. This is a
114 * different IRQ map than IRIX uses, but that's OK as Linux irq handling
115 * is quite different anyway.
118 /* Some initial interrupts to set up */
119 extern irqreturn_t
crime_memerr_intr(int irq
, void *dev_id
);
120 extern irqreturn_t
crime_cpuerr_intr(int irq
, void *dev_id
);
122 struct irqaction memerr_irq
= {
123 .handler
= crime_memerr_intr
,
124 .flags
= IRQF_DISABLED
,
125 .mask
= CPU_MASK_NONE
,
126 .name
= "CRIME memory error",
128 struct irqaction cpuerr_irq
= {
129 .handler
= crime_cpuerr_intr
,
130 .flags
= IRQF_DISABLED
,
131 .mask
= CPU_MASK_NONE
,
132 .name
= "CRIME CPU error",
136 * This is for pure CRIME interrupts - ie not MACE. The advantage?
137 * We get to split the register in half and do faster lookups.
140 static uint64_t crime_mask
;
142 static void enable_crime_irq(unsigned int irq
)
144 crime_mask
|= 1 << (irq
- 1);
145 crime
->imask
= crime_mask
;
148 static void disable_crime_irq(unsigned int irq
)
150 crime_mask
&= ~(1 << (irq
- 1));
151 crime
->imask
= crime_mask
;
155 static void mask_and_ack_crime_irq(unsigned int irq
)
157 /* Edge triggered interrupts must be cleared. */
158 if ((irq
>= CRIME_GBE0_IRQ
&& irq
<= CRIME_GBE3_IRQ
)
159 || (irq
>= CRIME_RE_EMPTY_E_IRQ
&& irq
<= CRIME_RE_IDLE_E_IRQ
)
160 || (irq
>= CRIME_SOFT0_IRQ
&& irq
<= CRIME_SOFT2_IRQ
)) {
162 crime_int
= crime
->hard_int
;
163 crime_int
&= ~(1 << (irq
- 1));
164 crime
->hard_int
= crime_int
;
166 disable_crime_irq(irq
);
169 static void end_crime_irq(unsigned int irq
)
171 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
)))
172 enable_crime_irq(irq
);
175 static struct irq_chip ip32_crime_interrupt
= {
176 .name
= "IP32 CRIME",
177 .ack
= mask_and_ack_crime_irq
,
178 .mask
= disable_crime_irq
,
179 .mask_ack
= mask_and_ack_crime_irq
,
180 .unmask
= enable_crime_irq
,
181 .end
= end_crime_irq
,
185 * This is for MACE PCI interrupts. We can decrease bus traffic by masking
186 * as close to the source as possible. This also means we can take the
187 * next chunk of the CRIME register in one piece.
190 static unsigned long macepci_mask
;
192 static void enable_macepci_irq(unsigned int irq
)
194 macepci_mask
|= MACEPCI_CONTROL_INT(irq
- 9);
195 mace
->pci
.control
= macepci_mask
;
196 crime_mask
|= 1 << (irq
- 1);
197 crime
->imask
= crime_mask
;
200 static void disable_macepci_irq(unsigned int irq
)
202 crime_mask
&= ~(1 << (irq
- 1));
203 crime
->imask
= crime_mask
;
205 macepci_mask
&= ~MACEPCI_CONTROL_INT(irq
- 9);
206 mace
->pci
.control
= macepci_mask
;
210 static void end_macepci_irq(unsigned int irq
)
212 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
|IRQ_INPROGRESS
)))
213 enable_macepci_irq(irq
);
216 static struct irq_chip ip32_macepci_interrupt
= {
217 .name
= "IP32 MACE PCI",
218 .ack
= disable_macepci_irq
,
219 .mask
= disable_macepci_irq
,
220 .mask_ack
= disable_macepci_irq
,
221 .unmask
= enable_macepci_irq
,
222 .end
= end_macepci_irq
,
225 /* This is used for MACE ISA interrupts. That means bits 4-6 in the
229 #define MACEISA_AUDIO_INT (MACEISA_AUDIO_SW_INT | \
230 MACEISA_AUDIO_SC_INT | \
231 MACEISA_AUDIO1_DMAT_INT | \
232 MACEISA_AUDIO1_OF_INT | \
233 MACEISA_AUDIO2_DMAT_INT | \
234 MACEISA_AUDIO2_MERR_INT | \
235 MACEISA_AUDIO3_DMAT_INT | \
236 MACEISA_AUDIO3_MERR_INT)
237 #define MACEISA_MISC_INT (MACEISA_RTC_INT | \
239 MACEISA_KEYB_POLL_INT | \
240 MACEISA_MOUSE_INT | \
241 MACEISA_MOUSE_POLL_INT | \
242 MACEISA_TIMER0_INT | \
243 MACEISA_TIMER1_INT | \
245 #define MACEISA_SUPERIO_INT (MACEISA_PARALLEL_INT | \
246 MACEISA_PAR_CTXA_INT | \
247 MACEISA_PAR_CTXB_INT | \
248 MACEISA_PAR_MERR_INT | \
249 MACEISA_SERIAL1_INT | \
250 MACEISA_SERIAL1_TDMAT_INT | \
251 MACEISA_SERIAL1_TDMAPR_INT | \
252 MACEISA_SERIAL1_TDMAME_INT | \
253 MACEISA_SERIAL1_RDMAT_INT | \
254 MACEISA_SERIAL1_RDMAOR_INT | \
255 MACEISA_SERIAL2_INT | \
256 MACEISA_SERIAL2_TDMAT_INT | \
257 MACEISA_SERIAL2_TDMAPR_INT | \
258 MACEISA_SERIAL2_TDMAME_INT | \
259 MACEISA_SERIAL2_RDMAT_INT | \
260 MACEISA_SERIAL2_RDMAOR_INT)
262 static unsigned long maceisa_mask
;
264 static void enable_maceisa_irq(unsigned int irq
)
266 unsigned int crime_int
= 0;
268 DBG("maceisa enable: %u\n", irq
);
271 case MACEISA_AUDIO_SW_IRQ
... MACEISA_AUDIO3_MERR_IRQ
:
272 crime_int
= MACE_AUDIO_INT
;
274 case MACEISA_RTC_IRQ
... MACEISA_TIMER2_IRQ
:
275 crime_int
= MACE_MISC_INT
;
277 case MACEISA_PARALLEL_IRQ
... MACEISA_SERIAL2_RDMAOR_IRQ
:
278 crime_int
= MACE_SUPERIO_INT
;
281 DBG("crime_int %08x enabled\n", crime_int
);
282 crime_mask
|= crime_int
;
283 crime
->imask
= crime_mask
;
284 maceisa_mask
|= 1 << (irq
- 33);
285 mace
->perif
.ctrl
.imask
= maceisa_mask
;
288 static void disable_maceisa_irq(unsigned int irq
)
290 unsigned int crime_int
= 0;
292 maceisa_mask
&= ~(1 << (irq
- 33));
293 if(!(maceisa_mask
& MACEISA_AUDIO_INT
))
294 crime_int
|= MACE_AUDIO_INT
;
295 if(!(maceisa_mask
& MACEISA_MISC_INT
))
296 crime_int
|= MACE_MISC_INT
;
297 if(!(maceisa_mask
& MACEISA_SUPERIO_INT
))
298 crime_int
|= MACE_SUPERIO_INT
;
299 crime_mask
&= ~crime_int
;
300 crime
->imask
= crime_mask
;
302 mace
->perif
.ctrl
.imask
= maceisa_mask
;
306 static void mask_and_ack_maceisa_irq(unsigned int irq
)
308 unsigned long mace_int
;
311 case MACEISA_PARALLEL_IRQ
:
312 case MACEISA_SERIAL1_TDMAPR_IRQ
:
313 case MACEISA_SERIAL2_TDMAPR_IRQ
:
315 mace_int
= mace
->perif
.ctrl
.istat
;
316 mace_int
&= ~(1 << (irq
- 33));
317 mace
->perif
.ctrl
.istat
= mace_int
;
320 disable_maceisa_irq(irq
);
323 static void end_maceisa_irq(unsigned irq
)
325 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
| IRQ_INPROGRESS
)))
326 enable_maceisa_irq(irq
);
329 static struct irq_chip ip32_maceisa_interrupt
= {
330 .name
= "IP32 MACE ISA",
331 .ack
= mask_and_ack_maceisa_irq
,
332 .mask
= disable_maceisa_irq
,
333 .mask_ack
= mask_and_ack_maceisa_irq
,
334 .unmask
= enable_maceisa_irq
,
335 .end
= end_maceisa_irq
,
338 /* This is used for regular non-ISA, non-PCI MACE interrupts. That means
339 * bits 0-3 and 7 in the CRIME register.
342 static void enable_mace_irq(unsigned int irq
)
344 crime_mask
|= 1 << (irq
- 1);
345 crime
->imask
= crime_mask
;
348 static void disable_mace_irq(unsigned int irq
)
350 crime_mask
&= ~(1 << (irq
- 1));
351 crime
->imask
= crime_mask
;
355 static void end_mace_irq(unsigned int irq
)
357 if (!(irq_desc
[irq
].status
& (IRQ_DISABLED
|IRQ_INPROGRESS
)))
358 enable_mace_irq(irq
);
361 static struct irq_chip ip32_mace_interrupt
= {
363 .ack
= disable_mace_irq
,
364 .mask
= disable_mace_irq
,
365 .mask_ack
= disable_mace_irq
,
366 .unmask
= enable_mace_irq
,
370 static void ip32_unknown_interrupt(void)
372 printk("Unknown interrupt occurred!\n");
373 printk("cp0_status: %08x\n", read_c0_status());
374 printk("cp0_cause: %08x\n", read_c0_cause());
375 printk("CRIME intr mask: %016lx\n", crime
->imask
);
376 printk("CRIME intr status: %016lx\n", crime
->istat
);
377 printk("CRIME hardware intr register: %016lx\n", crime
->hard_int
);
378 printk("MACE ISA intr mask: %08lx\n", mace
->perif
.ctrl
.imask
);
379 printk("MACE ISA intr status: %08lx\n", mace
->perif
.ctrl
.istat
);
380 printk("MACE PCI control register: %08x\n", mace
->pci
.control
);
382 printk("Register dump:\n");
383 show_regs(get_irq_regs());
385 printk("Please mail this report to linux-mips@linux-mips.org\n");
386 printk("Spinning...");
390 /* CRIME 1.1 appears to deliver all interrupts to this one pin. */
391 /* change this to loop over all edge-triggered irqs, exception masked out ones */
392 static void ip32_irq0(void)
398 * Sanity check interrupt numbering enum.
399 * MACE got 32 interrupts and there are 32 MACE ISA interrupts daisy
402 BUILD_BUG_ON(CRIME_VICE_IRQ
- MACE_VID_IN1_IRQ
!= 31);
403 BUILD_BUG_ON(MACEISA_SERIAL2_RDMAOR_IRQ
- MACEISA_AUDIO_SW_IRQ
!= 31);
405 crime_int
= crime
->istat
& crime_mask
;
406 irq
= MACE_VID_IN1_IRQ
+ __ffs(crime_int
);
407 crime_int
= 1 << irq
;
409 if (crime_int
& CRIME_MACEISA_INT_MASK
) {
410 unsigned long mace_int
= mace
->perif
.ctrl
.istat
;
411 irq
= __ffs(mace_int
& maceisa_mask
) + MACEISA_AUDIO_SW_IRQ
;
414 DBG("*irq %u*\n", irq
);
418 static void ip32_irq1(void)
420 ip32_unknown_interrupt();
423 static void ip32_irq2(void)
425 ip32_unknown_interrupt();
428 static void ip32_irq3(void)
430 ip32_unknown_interrupt();
433 static void ip32_irq4(void)
435 ip32_unknown_interrupt();
438 static void ip32_irq5(void)
440 do_IRQ(MIPS_CPU_IRQ_BASE
+ 7);
443 asmlinkage
void plat_irq_dispatch(void)
445 unsigned int pending
= read_c0_status() & read_c0_cause();
447 if (likely(pending
& IE_IRQ0
))
449 else if (unlikely(pending
& IE_IRQ1
))
451 else if (unlikely(pending
& IE_IRQ2
))
453 else if (unlikely(pending
& IE_IRQ3
))
455 else if (unlikely(pending
& IE_IRQ4
))
457 else if (likely(pending
& IE_IRQ5
))
461 void __init
arch_init_irq(void)
465 /* Install our interrupt handler, then clear and disable all
466 * CRIME and MACE interrupts. */
470 mace
->perif
.ctrl
.istat
= 0;
471 mace
->perif
.ctrl
.imask
= 0;
474 for (irq
= MIPS_CPU_IRQ_BASE
+ 8; irq
<= IP32_IRQ_MAX
; irq
++) {
475 struct irq_chip
*chip
;
478 case MACE_VID_IN1_IRQ
... MACE_PCI_BRIDGE_IRQ
:
479 chip
= &ip32_mace_interrupt
;
481 case MACEPCI_SCSI0_IRQ
... MACEPCI_SHARED2_IRQ
:
482 chip
= &ip32_macepci_interrupt
;
484 case CRIME_GBE0_IRQ
... CRIME_VICE_IRQ
:
485 chip
= &ip32_crime_interrupt
;
488 chip
= &ip32_maceisa_interrupt
;
491 set_irq_chip(irq
, chip
);
493 setup_irq(CRIME_MEMERR_IRQ
, &memerr_irq
);
494 setup_irq(CRIME_CPUERR_IRQ
, &cpuerr_irq
);
496 #define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5)
497 change_c0_status(ST0_IM
, ALLINTS
);