2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.
4 * Copyright (C) 2001 Ralf Baechle
6 * This program is free software; you can distribute it and/or modify it
7 * under the terms of the GNU General Public License (Version 2) as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
19 * Routines for generic manipulation of the interrupts found on the MIPS
21 * The interrupt controller is located in the South Bridge a PIIX4 device
22 * with two internal 82C95 interrupt controllers.
24 #include <linux/init.h>
25 #include <linux/irq.h>
26 #include <linux/sched.h>
27 #include <linux/slab.h>
28 #include <linux/interrupt.h>
29 #include <linux/kernel_stat.h>
30 #include <linux/kernel.h>
31 #include <linux/random.h>
33 #include <asm/i8259.h>
34 #include <asm/irq_cpu.h>
36 #include <asm/irq_regs.h>
37 #include <asm/mips-boards/malta.h>
38 #include <asm/mips-boards/maltaint.h>
39 #include <asm/mips-boards/piix4.h>
40 #include <asm/gt64120.h>
41 #include <asm/mips-boards/generic.h>
42 #include <asm/mips-boards/msc01_pci.h>
43 #include <asm/msc01_ic.h>
45 static DEFINE_SPINLOCK(mips_irq_lock);
47 static inline int mips_pcibios_iack(void)
53 * Determine highest priority pending interrupt by performing
54 * a PCI Interrupt Acknowledge cycle.
56 switch (mips_revision_sconid) {
57 case MIPS_REVISION_SCON_SOCIT:
58 case MIPS_REVISION_SCON_ROCIT:
59 case MIPS_REVISION_SCON_SOCITSC:
60 case MIPS_REVISION_SCON_SOCITSCP:
61 MSC_READ(MSC01_PCI_IACK, irq);
64 case MIPS_REVISION_SCON_GT64120:
65 irq = GT_READ(GT_PCI0_IACK_OFS);
68 case MIPS_REVISION_SCON_BONITO:
69 /* The following will generate a PCI IACK cycle on the
70 * Bonito controller. It's a little bit kludgy, but it
71 * was the easiest way to implement it in hardware at
74 BONITO_PCIMAP_CFG = 0x20000;
76 /* Flush Bonito register block */
77 dummy = BONITO_PCIMAP_CFG;
80 irq = readl((u32 *)_pcictrl_bonito_pcicfg);
83 BONITO_PCIMAP_CFG = 0;
86 printk(KERN_WARNING "Unknown system controller.\n");
92 static inline int get_int(void)
96 spin_lock_irqsave(&mips_irq_lock, flags);
98 irq = mips_pcibios_iack();
101 * The only way we can decide if an interrupt is spurious
102 * is by checking the 8259 registers. This needs a spinlock
103 * on an SMP system, so leave it up to the generic code...
106 spin_unlock_irqrestore(&mips_irq_lock, flags);
111 static void malta_hw0_irqdispatch(void)
117 return; /* interrupt has already been cleared */
120 do_IRQ(MALTA_INT_BASE + irq);
123 static void corehi_irqdispatch(void)
125 unsigned int intedge, intsteer, pcicmd, pcibadaddr;
126 unsigned int pcimstat, intisr, inten, intpol;
127 unsigned int intrcause, datalo, datahi;
128 struct pt_regs *regs = get_irq_regs();
130 printk(KERN_EMERG "CoreHI interrupt, shouldn't happen, we die here!\n");
131 printk(KERN_EMERG "epc : %08lx\nStatus: %08lx\n"
132 "Cause : %08lx\nbadVaddr : %08lx\n",
133 regs->cp0_epc, regs->cp0_status,
134 regs->cp0_cause, regs->cp0_badvaddr);
136 /* Read all the registers and then print them as there is a
137 problem with interspersed printk's upsetting the Bonito controller.
138 Do it for the others too.
141 switch (mips_revision_sconid) {
142 case MIPS_REVISION_SCON_SOCIT:
143 case MIPS_REVISION_SCON_ROCIT:
144 case MIPS_REVISION_SCON_SOCITSC:
145 case MIPS_REVISION_SCON_SOCITSCP:
148 case MIPS_REVISION_SCON_GT64120:
149 intrcause = GT_READ(GT_INTRCAUSE_OFS);
150 datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
151 datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
152 printk(KERN_EMERG "GT_INTRCAUSE = %08x\n", intrcause);
153 printk(KERN_EMERG "GT_CPUERR_ADDR = %02x%08x\n",
156 case MIPS_REVISION_SCON_BONITO:
157 pcibadaddr = BONITO_PCIBADADDR;
158 pcimstat = BONITO_PCIMSTAT;
159 intisr = BONITO_INTISR;
160 inten = BONITO_INTEN;
161 intpol = BONITO_INTPOL;
162 intedge = BONITO_INTEDGE;
163 intsteer = BONITO_INTSTEER;
164 pcicmd = BONITO_PCICMD;
165 printk(KERN_EMERG "BONITO_INTISR = %08x\n", intisr);
166 printk(KERN_EMERG "BONITO_INTEN = %08x\n", inten);
167 printk(KERN_EMERG "BONITO_INTPOL = %08x\n", intpol);
168 printk(KERN_EMERG "BONITO_INTEDGE = %08x\n", intedge);
169 printk(KERN_EMERG "BONITO_INTSTEER = %08x\n", intsteer);
170 printk(KERN_EMERG "BONITO_PCICMD = %08x\n", pcicmd);
171 printk(KERN_EMERG "BONITO_PCIBADADDR = %08x\n", pcibadaddr);
172 printk(KERN_EMERG "BONITO_PCIMSTAT = %08x\n", pcimstat);
177 die("CoreHi interrupt", regs);
180 static inline int clz(unsigned long x)
194 * Version of ffs that only looks at bits 12..15.
196 static inline unsigned int irq_ffs(unsigned int pending)
198 #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
199 return -clz(pending) + 31 - CAUSEB_IP;
204 t0 = pending & 0xf000;
208 pending = pending << t0;
210 t0 = pending & 0xc000;
214 pending = pending << t0;
216 t0 = pending & 0x8000;
220 //pending = pending << t0;
227 * IRQs on the Malta board look basically (barring software IRQs which we
228 * don't use at all and all external interrupt sources are combined together
229 * on hardware interrupt 0 (MIPS IRQ 2)) like:
233 * 0 Software (ignored)
234 * 1 Software (ignored)
235 * 2 Combined hardware interrupt (hw0)
236 * 3 Hardware (ignored)
237 * 4 Hardware (ignored)
238 * 5 Hardware (ignored)
239 * 6 Hardware (ignored)
240 * 7 R4k timer (what we use)
242 * We handle the IRQ according to _our_ priority which is:
244 * Highest ---- R4k Timer
245 * Lowest ---- Combined hardware interrupt
247 * then we just return, if multiple IRQs are pending then we will just take
248 * another exception, big deal.
251 asmlinkage void plat_irq_dispatch(void)
253 unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
256 irq = irq_ffs(pending);
258 if (irq == MIPSCPU_INT_I8259A)
259 malta_hw0_irqdispatch();
261 do_IRQ(MIPS_CPU_IRQ_BASE + irq);
263 spurious_interrupt();
266 static struct irqaction i8259irq = {
267 .handler = no_action,
268 .name = "XT-PIC cascade"
271 static struct irqaction corehi_irqaction = {
272 .handler = no_action,
276 msc_irqmap_t __initdata msc_irqmap[] = {
277 {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
278 {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
280 int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap);
282 msc_irqmap_t __initdata msc_eicirqmap[] = {
283 {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
284 {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
285 {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
286 {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
287 {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
288 {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
289 {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
290 {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
291 {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
292 {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
294 int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
296 void __init arch_init_irq(void)
303 switch (mips_revision_sconid) {
304 case MIPS_REVISION_SCON_SOCIT:
305 case MIPS_REVISION_SCON_ROCIT:
307 init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
308 MSC01E_INT_BASE, msc_eicirqmap,
311 init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
312 MSC01C_INT_BASE, msc_irqmap,
316 case MIPS_REVISION_SCON_SOCITSC:
317 case MIPS_REVISION_SCON_SOCITSCP:
319 init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
320 MSC01E_INT_BASE, msc_eicirqmap,
323 init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
324 MSC01C_INT_BASE, msc_irqmap,
329 set_vi_handler(MSC01E_INT_I8259A, malta_hw0_irqdispatch);
330 set_vi_handler(MSC01E_INT_COREHI, corehi_irqdispatch);
331 setup_irq(MSC01E_INT_BASE+MSC01E_INT_I8259A, &i8259irq);
332 setup_irq(MSC01E_INT_BASE+MSC01E_INT_COREHI, &corehi_irqaction);
334 else if (cpu_has_vint) {
335 set_vi_handler(MIPSCPU_INT_I8259A, malta_hw0_irqdispatch);
336 set_vi_handler(MIPSCPU_INT_COREHI, corehi_irqdispatch);
337 #ifdef CONFIG_MIPS_MT_SMTC
338 setup_irq_smtc(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq,
339 (0x100 << MIPSCPU_INT_I8259A));
340 setup_irq_smtc(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
341 &corehi_irqaction, (0x100 << MIPSCPU_INT_COREHI));
343 * Temporary hack to ensure that the subsidiary device
344 * interrupts coing in via the i8259A, but associated
345 * with low IRQ numbers, will restore the Status.IM
346 * value associated with the i8259A.
351 for (i = 0; i < 16; i++)
352 irq_hwmask[i] = (0x100 << MIPSCPU_INT_I8259A);
355 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
356 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
358 #endif /* CONFIG_MIPS_MT_SMTC */
361 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
362 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,