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/mipsregs.h>
24 #include <asm/signal.h>
25 #include <asm/system.h>
27 #include <asm/ip32/crime.h>
28 #include <asm/ip32/mace.h>
29 #include <asm/ip32/ip32_ints.h>
31 /* issue a PIO read to make sure no PIO writes are pending */
32 static void inline flush_crime_bus(void)
34 volatile unsigned long junk = crime->control;
37 static void inline flush_mace_bus(void)
39 volatile unsigned long junk = mace->perif.ctrl.misc;
44 #define DBG(x...) printk(x)
51 * IP0 -> software (ignored)
52 * IP1 -> software (ignored)
53 * IP2 -> (irq0) C crime 1.1 all interrupts; crime 1.5 ???
54 * IP3 -> (irq1) X unknown
55 * IP4 -> (irq2) X unknown
56 * IP5 -> (irq3) X unknown
57 * IP6 -> (irq4) X unknown
58 * IP7 -> (irq5) 0 CPU count/compare timer (system timer)
62 * CRIME_INT_STAT 31:0:
67 * 3 -> 4 Mace ethernet
68 * 4 -> S SuperIO sub-interrupt
69 * 5 -> M Miscellaneous sub-interrupt
70 * 6 -> A Audio sub-interrupt
71 * 7 -> 8 PCI bridge errors
72 * 8 -> 9 PCI SCSI aic7xxx 0
73 * 9 -> 10 PCI SCSI aic7xxx 1
75 * 11 -> 12 unused (PCI slot 1)
76 * 12 -> 13 unused (PCI slot 2)
77 * 13 -> 14 unused (PCI shared 0)
78 * 14 -> 15 unused (PCI shared 1)
79 * 15 -> 16 unused (PCI shared 2)
85 * 21 -> 22 Memory errors
86 * 22 -> 23 RE empty edge (E)
87 * 23 -> 24 RE full edge (E)
88 * 24 -> 25 RE idle edge (E)
89 * 25 -> 26 RE empty level
90 * 26 -> 27 RE full level
91 * 27 -> 28 RE idle level
92 * 28 -> 29 unused (software 0) (E)
93 * 29 -> 30 unused (software 1) (E)
94 * 30 -> 31 unused (software 2) - crime 1.5 CPU SysCorError (E)
97 * S, M, A: Use the MACE ISA interrupt register
98 * MACE_ISA_INT_STAT 31:0
103 * 10 -> X Keyboard polled
105 * 12 -> X Mouse polled
106 * 13-15 -> 46-48 Count/compare timers
107 * 16-19 -> 49-52 Parallel (16 E)
108 * 20-25 -> 53-58 Serial 1 (22 E)
109 * 26-31 -> 59-64 Serial 2 (28 E)
111 * Note that this means IRQs 5-7, 43, and 45 do not exist. This is a
112 * different IRQ map than IRIX uses, but that's OK as Linux irq handling
113 * is quite different anyway.
117 * IRQ spinlock - Ralf says not to disable CPU interrupts,
118 * and I think he knows better.
120 static DEFINE_SPINLOCK(ip32_irq_lock);
122 /* Some initial interrupts to set up */
123 extern irqreturn_t crime_memerr_intr (int irq, void *dev_id,
124 struct pt_regs *regs);
125 extern irqreturn_t crime_cpuerr_intr (int irq, void *dev_id,
126 struct pt_regs *regs);
128 struct irqaction memerr_irq = { crime_memerr_intr, SA_INTERRUPT,
129 CPU_MASK_NONE, "CRIME memory error", NULL, NULL };
130 struct irqaction cpuerr_irq = { crime_cpuerr_intr, SA_INTERRUPT,
131 CPU_MASK_NONE, "CRIME CPU error", NULL, NULL };
133 extern void ip32_handle_int(void);
136 * For interrupts wired from a single device to the CPU. Only the clock
137 * uses this it seems, which is IRQ 0 and IP7.
140 static void enable_cpu_irq(unsigned int irq)
142 set_c0_status(STATUSF_IP7);
145 static unsigned int startup_cpu_irq(unsigned int irq)
151 static void disable_cpu_irq(unsigned int irq)
153 clear_c0_status(STATUSF_IP7);
156 static void end_cpu_irq(unsigned int irq)
158 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
159 enable_cpu_irq (irq);
162 #define shutdown_cpu_irq disable_cpu_irq
163 #define mask_and_ack_cpu_irq disable_cpu_irq
165 static struct hw_interrupt_type ip32_cpu_interrupt = {
166 .typename = "IP32 CPU",
167 .startup = startup_cpu_irq,
168 .shutdown = shutdown_cpu_irq,
169 .enable = enable_cpu_irq,
170 .disable = disable_cpu_irq,
171 .ack = mask_and_ack_cpu_irq,
176 * This is for pure CRIME interrupts - ie not MACE. The advantage?
177 * We get to split the register in half and do faster lookups.
180 static uint64_t crime_mask;
182 static void enable_crime_irq(unsigned int irq)
186 spin_lock_irqsave(&ip32_irq_lock, flags);
187 crime_mask |= 1 << (irq - 1);
188 crime->imask = crime_mask;
189 spin_unlock_irqrestore(&ip32_irq_lock, flags);
192 static unsigned int startup_crime_irq(unsigned int irq)
194 enable_crime_irq(irq);
195 return 0; /* This is probably not right; we could have pending irqs */
198 static void disable_crime_irq(unsigned int irq)
202 spin_lock_irqsave(&ip32_irq_lock, flags);
203 crime_mask &= ~(1 << (irq - 1));
204 crime->imask = crime_mask;
206 spin_unlock_irqrestore(&ip32_irq_lock, flags);
209 static void mask_and_ack_crime_irq(unsigned int irq)
213 /* Edge triggered interrupts must be cleared. */
214 if ((irq >= CRIME_GBE0_IRQ && irq <= CRIME_GBE3_IRQ)
215 || (irq >= CRIME_RE_EMPTY_E_IRQ && irq <= CRIME_RE_IDLE_E_IRQ)
216 || (irq >= CRIME_SOFT0_IRQ && irq <= CRIME_SOFT2_IRQ)) {
218 spin_lock_irqsave(&ip32_irq_lock, flags);
219 crime_int = crime->hard_int;
220 crime_int &= ~(1 << (irq - 1));
221 crime->hard_int = crime_int;
222 spin_unlock_irqrestore(&ip32_irq_lock, flags);
224 disable_crime_irq(irq);
227 static void end_crime_irq(unsigned int irq)
229 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
230 enable_crime_irq(irq);
233 #define shutdown_crime_irq disable_crime_irq
235 static struct hw_interrupt_type ip32_crime_interrupt = {
236 .typename = "IP32 CRIME",
237 .startup = startup_crime_irq,
238 .shutdown = shutdown_crime_irq,
239 .enable = enable_crime_irq,
240 .disable = disable_crime_irq,
241 .ack = mask_and_ack_crime_irq,
242 .end = end_crime_irq,
246 * This is for MACE PCI interrupts. We can decrease bus traffic by masking
247 * as close to the source as possible. This also means we can take the
248 * next chunk of the CRIME register in one piece.
251 static unsigned long macepci_mask;
253 static void enable_macepci_irq(unsigned int irq)
257 spin_lock_irqsave(&ip32_irq_lock, flags);
258 macepci_mask |= MACEPCI_CONTROL_INT(irq - 9);
259 mace->pci.control = macepci_mask;
260 crime_mask |= 1 << (irq - 1);
261 crime->imask = crime_mask;
262 spin_unlock_irqrestore(&ip32_irq_lock, flags);
265 static unsigned int startup_macepci_irq(unsigned int irq)
267 enable_macepci_irq (irq);
271 static void disable_macepci_irq(unsigned int irq)
275 spin_lock_irqsave(&ip32_irq_lock, flags);
276 crime_mask &= ~(1 << (irq - 1));
277 crime->imask = crime_mask;
279 macepci_mask &= ~MACEPCI_CONTROL_INT(irq - 9);
280 mace->pci.control = macepci_mask;
282 spin_unlock_irqrestore(&ip32_irq_lock, flags);
285 static void end_macepci_irq(unsigned int irq)
287 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
288 enable_macepci_irq(irq);
291 #define shutdown_macepci_irq disable_macepci_irq
292 #define mask_and_ack_macepci_irq disable_macepci_irq
294 static struct hw_interrupt_type ip32_macepci_interrupt = {
295 .typename = "IP32 MACE PCI",
296 .startup = startup_macepci_irq,
297 .shutdown = shutdown_macepci_irq,
298 .enable = enable_macepci_irq,
299 .disable = disable_macepci_irq,
300 .ack = mask_and_ack_macepci_irq,
301 .end = end_macepci_irq,
304 /* This is used for MACE ISA interrupts. That means bits 4-6 in the
308 #define MACEISA_AUDIO_INT (MACEISA_AUDIO_SW_INT | \
309 MACEISA_AUDIO_SC_INT | \
310 MACEISA_AUDIO1_DMAT_INT | \
311 MACEISA_AUDIO1_OF_INT | \
312 MACEISA_AUDIO2_DMAT_INT | \
313 MACEISA_AUDIO2_MERR_INT | \
314 MACEISA_AUDIO3_DMAT_INT | \
315 MACEISA_AUDIO3_MERR_INT)
316 #define MACEISA_MISC_INT (MACEISA_RTC_INT | \
318 MACEISA_KEYB_POLL_INT | \
319 MACEISA_MOUSE_INT | \
320 MACEISA_MOUSE_POLL_INT | \
321 MACEISA_TIMER0_INT | \
322 MACEISA_TIMER1_INT | \
324 #define MACEISA_SUPERIO_INT (MACEISA_PARALLEL_INT | \
325 MACEISA_PAR_CTXA_INT | \
326 MACEISA_PAR_CTXB_INT | \
327 MACEISA_PAR_MERR_INT | \
328 MACEISA_SERIAL1_INT | \
329 MACEISA_SERIAL1_TDMAT_INT | \
330 MACEISA_SERIAL1_TDMAPR_INT | \
331 MACEISA_SERIAL1_TDMAME_INT | \
332 MACEISA_SERIAL1_RDMAT_INT | \
333 MACEISA_SERIAL1_RDMAOR_INT | \
334 MACEISA_SERIAL2_INT | \
335 MACEISA_SERIAL2_TDMAT_INT | \
336 MACEISA_SERIAL2_TDMAPR_INT | \
337 MACEISA_SERIAL2_TDMAME_INT | \
338 MACEISA_SERIAL2_RDMAT_INT | \
339 MACEISA_SERIAL2_RDMAOR_INT)
341 static unsigned long maceisa_mask;
343 static void enable_maceisa_irq (unsigned int irq)
345 unsigned int crime_int = 0;
348 DBG ("maceisa enable: %u\n", irq);
351 case MACEISA_AUDIO_SW_IRQ ... MACEISA_AUDIO3_MERR_IRQ:
352 crime_int = MACE_AUDIO_INT;
354 case MACEISA_RTC_IRQ ... MACEISA_TIMER2_IRQ:
355 crime_int = MACE_MISC_INT;
357 case MACEISA_PARALLEL_IRQ ... MACEISA_SERIAL2_RDMAOR_IRQ:
358 crime_int = MACE_SUPERIO_INT;
361 DBG ("crime_int %08x enabled\n", crime_int);
362 spin_lock_irqsave(&ip32_irq_lock, flags);
363 crime_mask |= crime_int;
364 crime->imask = crime_mask;
365 maceisa_mask |= 1 << (irq - 33);
366 mace->perif.ctrl.imask = maceisa_mask;
367 spin_unlock_irqrestore(&ip32_irq_lock, flags);
370 static unsigned int startup_maceisa_irq(unsigned int irq)
372 enable_maceisa_irq(irq);
376 static void disable_maceisa_irq(unsigned int irq)
378 unsigned int crime_int = 0;
381 spin_lock_irqsave(&ip32_irq_lock, flags);
382 maceisa_mask &= ~(1 << (irq - 33));
383 if(!(maceisa_mask & MACEISA_AUDIO_INT))
384 crime_int |= MACE_AUDIO_INT;
385 if(!(maceisa_mask & MACEISA_MISC_INT))
386 crime_int |= MACE_MISC_INT;
387 if(!(maceisa_mask & MACEISA_SUPERIO_INT))
388 crime_int |= MACE_SUPERIO_INT;
389 crime_mask &= ~crime_int;
390 crime->imask = crime_mask;
392 mace->perif.ctrl.imask = maceisa_mask;
394 spin_unlock_irqrestore(&ip32_irq_lock, flags);
397 static void mask_and_ack_maceisa_irq(unsigned int irq)
399 unsigned long mace_int, flags;
402 case MACEISA_PARALLEL_IRQ:
403 case MACEISA_SERIAL1_TDMAPR_IRQ:
404 case MACEISA_SERIAL2_TDMAPR_IRQ:
406 spin_lock_irqsave(&ip32_irq_lock, flags);
407 mace_int = mace->perif.ctrl.istat;
408 mace_int &= ~(1 << (irq - 33));
409 mace->perif.ctrl.istat = mace_int;
410 spin_unlock_irqrestore(&ip32_irq_lock, flags);
413 disable_maceisa_irq(irq);
416 static void end_maceisa_irq(unsigned irq)
418 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
419 enable_maceisa_irq(irq);
422 #define shutdown_maceisa_irq disable_maceisa_irq
424 static struct hw_interrupt_type ip32_maceisa_interrupt = {
425 .typename = "IP32 MACE ISA",
426 .startup = startup_maceisa_irq,
427 .shutdown = shutdown_maceisa_irq,
428 .enable = enable_maceisa_irq,
429 .disable = disable_maceisa_irq,
430 .ack = mask_and_ack_maceisa_irq,
431 .end = end_maceisa_irq,
434 /* This is used for regular non-ISA, non-PCI MACE interrupts. That means
435 * bits 0-3 and 7 in the CRIME register.
438 static void enable_mace_irq(unsigned int irq)
442 spin_lock_irqsave(&ip32_irq_lock, flags);
443 crime_mask |= 1 << (irq - 1);
444 crime->imask = crime_mask;
445 spin_unlock_irqrestore(&ip32_irq_lock, flags);
448 static unsigned int startup_mace_irq(unsigned int irq)
450 enable_mace_irq(irq);
454 static void disable_mace_irq(unsigned int irq)
458 spin_lock_irqsave(&ip32_irq_lock, flags);
459 crime_mask &= ~(1 << (irq - 1));
460 crime->imask = crime_mask;
462 spin_unlock_irqrestore(&ip32_irq_lock, flags);
465 static void end_mace_irq(unsigned int irq)
467 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
468 enable_mace_irq(irq);
471 #define shutdown_mace_irq disable_mace_irq
472 #define mask_and_ack_mace_irq disable_mace_irq
474 static struct hw_interrupt_type ip32_mace_interrupt = {
475 .typename = "IP32 MACE",
476 .startup = startup_mace_irq,
477 .shutdown = shutdown_mace_irq,
478 .enable = enable_mace_irq,
479 .disable = disable_mace_irq,
480 .ack = mask_and_ack_mace_irq,
484 static void ip32_unknown_interrupt(struct pt_regs *regs)
486 printk ("Unknown interrupt occurred!\n");
487 printk ("cp0_status: %08x\n", read_c0_status());
488 printk ("cp0_cause: %08x\n", read_c0_cause());
489 printk ("CRIME intr mask: %016lx\n", crime->imask);
490 printk ("CRIME intr status: %016lx\n", crime->istat);
491 printk ("CRIME hardware intr register: %016lx\n", crime->hard_int);
492 printk ("MACE ISA intr mask: %08lx\n", mace->perif.ctrl.imask);
493 printk ("MACE ISA intr status: %08lx\n", mace->perif.ctrl.istat);
494 printk ("MACE PCI control register: %08x\n", mace->pci.control);
496 printk("Register dump:\n");
499 printk("Please mail this report to linux-mips@linux-mips.org\n");
500 printk("Spinning...");
504 /* CRIME 1.1 appears to deliver all interrupts to this one pin. */
505 /* change this to loop over all edge-triggered irqs, exception masked out ones */
506 void ip32_irq0(struct pt_regs *regs)
511 crime_int = crime->istat & crime_mask;
512 irq = ffs(crime_int);
513 crime_int = 1 << (irq - 1);
515 if (crime_int & CRIME_MACEISA_INT_MASK) {
516 unsigned long mace_int = mace->perif.ctrl.istat;
517 irq = ffs(mace_int & maceisa_mask) + 32;
519 DBG("*irq %u*\n", irq);
523 void ip32_irq1(struct pt_regs *regs)
525 ip32_unknown_interrupt(regs);
528 void ip32_irq2(struct pt_regs *regs)
530 ip32_unknown_interrupt(regs);
533 void ip32_irq3(struct pt_regs *regs)
535 ip32_unknown_interrupt(regs);
538 void ip32_irq4(struct pt_regs *regs)
540 ip32_unknown_interrupt(regs);
543 void ip32_irq5(struct pt_regs *regs)
545 ll_timer_interrupt(IP32_R4K_TIMER_IRQ, regs);
548 void __init arch_init_irq(void)
552 /* Install our interrupt handler, then clear and disable all
553 * CRIME and MACE interrupts. */
557 mace->perif.ctrl.istat = 0;
558 mace->perif.ctrl.imask = 0;
559 set_except_vector(0, ip32_handle_int);
561 for (irq = 0; irq <= IP32_IRQ_MAX; irq++) {
562 hw_irq_controller *controller;
564 if (irq == IP32_R4K_TIMER_IRQ)
565 controller = &ip32_cpu_interrupt;
566 else if (irq <= MACE_PCI_BRIDGE_IRQ && irq >= MACE_VID_IN1_IRQ)
567 controller = &ip32_mace_interrupt;
568 else if (irq <= MACEPCI_SHARED2_IRQ && irq >= MACEPCI_SCSI0_IRQ)
569 controller = &ip32_macepci_interrupt;
570 else if (irq <= CRIME_VICE_IRQ && irq >= CRIME_GBE0_IRQ)
571 controller = &ip32_crime_interrupt;
573 controller = &ip32_maceisa_interrupt;
575 irq_desc[irq].status = IRQ_DISABLED;
576 irq_desc[irq].action = 0;
577 irq_desc[irq].depth = 0;
578 irq_desc[irq].handler = controller;
580 setup_irq(CRIME_MEMERR_IRQ, &memerr_irq);
581 setup_irq(CRIME_CPUERR_IRQ, &cpuerr_irq);
583 #define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5)
584 change_c0_status(ST0_IM, ALLINTS);