blob: 64db07d4dbe500d5c3a66355ff1f19c9f6e9ec34 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.
4 * Copyright (C) 2001 Ralf Baechle
5 *
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.
9 *
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
13 * for more details.
14 *
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.
18 *
19 * Routines for generic manipulation of the interrupts found on the MIPS
20 * Malta board.
21 * The interrupt controller is located in the South Bridge a PIIX4 device
22 * with two internal 82C95 interrupt controllers.
23 */
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/random.h>
31
32#include <asm/i8259.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000033#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/io.h>
35#include <asm/mips-boards/malta.h>
36#include <asm/mips-boards/maltaint.h>
37#include <asm/mips-boards/piix4.h>
38#include <asm/gt64120.h>
39#include <asm/mips-boards/generic.h>
40#include <asm/mips-boards/msc01_pci.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000041#include <asm/msc01_ic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Ralf Baechlee01402b2005-07-14 15:57:16 +000043extern void mips_timer_interrupt(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45static DEFINE_SPINLOCK(mips_irq_lock);
46
47static inline int mips_pcibios_iack(void)
48{
49 int irq;
50 u32 dummy;
51
52 /*
53 * Determine highest priority pending interrupt by performing
54 * a PCI Interrupt Acknowledge cycle.
55 */
56 switch(mips_revision_corid) {
57 case MIPS_REVISION_CORID_CORE_MSC:
58 case MIPS_REVISION_CORID_CORE_FPGA2:
Ralf Baechle479a0e32005-08-16 15:44:06 +000059 case MIPS_REVISION_CORID_CORE_FPGA3:
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 case MIPS_REVISION_CORID_CORE_EMUL_MSC:
61 MSC_READ(MSC01_PCI_IACK, irq);
62 irq &= 0xff;
63 break;
64 case MIPS_REVISION_CORID_QED_RM5261:
65 case MIPS_REVISION_CORID_CORE_LV:
66 case MIPS_REVISION_CORID_CORE_FPGA:
67 case MIPS_REVISION_CORID_CORE_FPGAR2:
68 irq = GT_READ(GT_PCI0_IACK_OFS);
69 irq &= 0xff;
70 break;
71 case MIPS_REVISION_CORID_BONITO64:
72 case MIPS_REVISION_CORID_CORE_20K:
73 case MIPS_REVISION_CORID_CORE_EMUL_BON:
74 /* The following will generate a PCI IACK cycle on the
75 * Bonito controller. It's a little bit kludgy, but it
76 * was the easiest way to implement it in hardware at
77 * the given time.
78 */
79 BONITO_PCIMAP_CFG = 0x20000;
80
81 /* Flush Bonito register block */
82 dummy = BONITO_PCIMAP_CFG;
83 iob(); /* sync */
84
85 irq = *(volatile u32 *)(_pcictrl_bonito_pcicfg);
86 iob(); /* sync */
87 irq &= 0xff;
88 BONITO_PCIMAP_CFG = 0;
89 break;
90 default:
91 printk("Unknown Core card, don't know the system controller.\n");
92 return -1;
93 }
94 return irq;
95}
96
Ralf Baechlee01402b2005-07-14 15:57:16 +000097static inline int get_int(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
99 unsigned long flags;
Ralf Baechlee01402b2005-07-14 15:57:16 +0000100 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 spin_lock_irqsave(&mips_irq_lock, flags);
102
Ralf Baechlee01402b2005-07-14 15:57:16 +0000103 irq = mips_pcibios_iack();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 /*
Ralf Baechle479a0e32005-08-16 15:44:06 +0000106 * The only way we can decide if an interrupt is spurious
107 * is by checking the 8259 registers. This needs a spinlock
108 * on an SMP system, so leave it up to the generic code...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 spin_unlock_irqrestore(&mips_irq_lock, flags);
112
Ralf Baechlee01402b2005-07-14 15:57:16 +0000113 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100116static void malta_hw0_irqdispatch(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 int irq;
119
Ralf Baechlee01402b2005-07-14 15:57:16 +0000120 irq = get_int();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100121 if (irq < 0) {
Ralf Baechlee01402b2005-07-14 15:57:16 +0000122 return; /* interrupt has already been cleared */
Ralf Baechle41c594a2006-04-05 09:45:45 +0100123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Ralf Baechlee01402b2005-07-14 15:57:16 +0000125 do_IRQ(MALTA_INT_BASE+irq, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
128void corehi_irqdispatch(struct pt_regs *regs)
129{
Ralf Baechlee01402b2005-07-14 15:57:16 +0000130 unsigned int intrcause,datalo,datahi;
131 unsigned int pcimstat, intisr, inten, intpol, intedge, intsteer, pcicmd, pcibadaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 printk("CoreHI interrupt, shouldn't happen, so we die here!!!\n");
134 printk("epc : %08lx\nStatus: %08lx\nCause : %08lx\nbadVaddr : %08lx\n"
135, regs->cp0_epc, regs->cp0_status, regs->cp0_cause, regs->cp0_badvaddr);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000136
137 /* Read all the registers and then print them as there is a
138 problem with interspersed printk's upsetting the Bonito controller.
139 Do it for the others too.
140 */
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 switch(mips_revision_corid) {
143 case MIPS_REVISION_CORID_CORE_MSC:
144 case MIPS_REVISION_CORID_CORE_FPGA2:
Ralf Baechle479a0e32005-08-16 15:44:06 +0000145 case MIPS_REVISION_CORID_CORE_FPGA3:
Ralf Baechlee01402b2005-07-14 15:57:16 +0000146 case MIPS_REVISION_CORID_CORE_EMUL_MSC:
147 ll_msc_irq(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 break;
149 case MIPS_REVISION_CORID_QED_RM5261:
150 case MIPS_REVISION_CORID_CORE_LV:
151 case MIPS_REVISION_CORID_CORE_FPGA:
152 case MIPS_REVISION_CORID_CORE_FPGAR2:
Ralf Baechlee01402b2005-07-14 15:57:16 +0000153 intrcause = GT_READ(GT_INTRCAUSE_OFS);
154 datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000156 printk("GT_INTRCAUSE = %08x\n", intrcause);
157 printk("GT_CPUERR_ADDR = %02x%08x\n", datahi, datalo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 break;
159 case MIPS_REVISION_CORID_BONITO64:
160 case MIPS_REVISION_CORID_CORE_20K:
161 case MIPS_REVISION_CORID_CORE_EMUL_BON:
Ralf Baechlee01402b2005-07-14 15:57:16 +0000162 pcibadaddr = BONITO_PCIBADADDR;
163 pcimstat = BONITO_PCIMSTAT;
164 intisr = BONITO_INTISR;
165 inten = BONITO_INTEN;
166 intpol = BONITO_INTPOL;
167 intedge = BONITO_INTEDGE;
168 intsteer = BONITO_INTSTEER;
169 pcicmd = BONITO_PCICMD;
170 printk("BONITO_INTISR = %08x\n", intisr);
171 printk("BONITO_INTEN = %08x\n", inten);
172 printk("BONITO_INTPOL = %08x\n", intpol);
173 printk("BONITO_INTEDGE = %08x\n", intedge);
174 printk("BONITO_INTSTEER = %08x\n", intsteer);
175 printk("BONITO_PCICMD = %08x\n", pcicmd);
176 printk("BONITO_PCIBADADDR = %08x\n", pcibadaddr);
177 printk("BONITO_PCIMSTAT = %08x\n", pcimstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 break;
179 }
180
181 /* We die here*/
182 die("CoreHi interrupt", regs);
183}
184
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100185static inline int clz(unsigned long x)
186{
187 __asm__ (
188 " .set push \n"
189 " .set mips32 \n"
190 " clz %0, %1 \n"
191 " .set pop \n"
192 : "=r" (x)
193 : "r" (x));
194
195 return x;
196}
197
198/*
199 * Version of ffs that only looks at bits 12..15.
200 */
201static inline unsigned int irq_ffs(unsigned int pending)
202{
203#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
204 return -clz(pending) + 31 - CAUSEB_IP;
205#else
206 unsigned int a0 = 7;
207 unsigned int t0;
208
209 t0 = s0 & 0xf000;
210 t0 = t0 < 1;
211 t0 = t0 << 2;
212 a0 = a0 - t0;
213 s0 = s0 << t0;
214
215 t0 = s0 & 0xc000;
216 t0 = t0 < 1;
217 t0 = t0 << 1;
218 a0 = a0 - t0;
219 s0 = s0 << t0;
220
221 t0 = s0 & 0x8000;
222 t0 = t0 < 1;
223 //t0 = t0 << 2;
224 a0 = a0 - t0;
225 //s0 = s0 << t0;
226
227 return a0;
228#endif
229}
230
231/*
232 * IRQs on the Malta board look basically (barring software IRQs which we
233 * don't use at all and all external interrupt sources are combined together
234 * on hardware interrupt 0 (MIPS IRQ 2)) like:
235 *
236 * MIPS IRQ Source
237 * -------- ------
238 * 0 Software (ignored)
239 * 1 Software (ignored)
240 * 2 Combined hardware interrupt (hw0)
241 * 3 Hardware (ignored)
242 * 4 Hardware (ignored)
243 * 5 Hardware (ignored)
244 * 6 Hardware (ignored)
245 * 7 R4k timer (what we use)
246 *
247 * We handle the IRQ according to _our_ priority which is:
248 *
249 * Highest ---- R4k Timer
250 * Lowest ---- Combined hardware interrupt
251 *
252 * then we just return, if multiple IRQs are pending then we will just take
253 * another exception, big deal.
254 */
255
256asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
257{
258 unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
259 int irq;
260
261 irq = irq_ffs(pending);
262
263 if (irq == MIPSCPU_INT_I8259A)
264 malta_hw0_irqdispatch(regs);
265 else if (irq > 0)
266 do_IRQ(MIPSCPU_INT_BASE + irq, regs);
267 else
268 spurious_interrupt(regs);
269}
270
Ralf Baechlee01402b2005-07-14 15:57:16 +0000271static struct irqaction i8259irq = {
272 .handler = no_action,
273 .name = "XT-PIC cascade"
274};
275
276static struct irqaction corehi_irqaction = {
277 .handler = no_action,
278 .name = "CoreHi"
279};
280
281msc_irqmap_t __initdata msc_irqmap[] = {
282 {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
283 {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
284};
285int __initdata msc_nr_irqs = sizeof(msc_irqmap)/sizeof(msc_irqmap_t);
286
287msc_irqmap_t __initdata msc_eicirqmap[] = {
288 {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
289 {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
290 {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
291 {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
292 {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
293 {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
294 {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
295 {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
296 {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
297 {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
298};
299int __initdata msc_nr_eicirqs = sizeof(msc_eicirqmap)/sizeof(msc_irqmap_t);
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301void __init arch_init_irq(void)
302{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 init_i8259_irqs();
Ralf Baechlee01402b2005-07-14 15:57:16 +0000304
305 if (!cpu_has_veic)
306 mips_cpu_irq_init (MIPSCPU_INT_BASE);
307
308 switch(mips_revision_corid) {
309 case MIPS_REVISION_CORID_CORE_MSC:
310 case MIPS_REVISION_CORID_CORE_FPGA2:
Ralf Baechle479a0e32005-08-16 15:44:06 +0000311 case MIPS_REVISION_CORID_CORE_FPGA3:
Ralf Baechlee01402b2005-07-14 15:57:16 +0000312 case MIPS_REVISION_CORID_CORE_EMUL_MSC:
313 if (cpu_has_veic)
314 init_msc_irqs (MSC01E_INT_BASE, msc_eicirqmap, msc_nr_eicirqs);
315 else
316 init_msc_irqs (MSC01C_INT_BASE, msc_irqmap, msc_nr_irqs);
317 }
318
319 if (cpu_has_veic) {
320 set_vi_handler (MSC01E_INT_I8259A, malta_hw0_irqdispatch);
321 set_vi_handler (MSC01E_INT_COREHI, corehi_irqdispatch);
322 setup_irq (MSC01E_INT_BASE+MSC01E_INT_I8259A, &i8259irq);
323 setup_irq (MSC01E_INT_BASE+MSC01E_INT_COREHI, &corehi_irqaction);
324 }
325 else if (cpu_has_vint) {
326 set_vi_handler (MIPSCPU_INT_I8259A, malta_hw0_irqdispatch);
327 set_vi_handler (MIPSCPU_INT_COREHI, corehi_irqdispatch);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100328#ifdef CONFIG_MIPS_MT_SMTC
329 setup_irq_smtc (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq,
330 (0x100 << MIPSCPU_INT_I8259A));
331 setup_irq_smtc (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI,
332 &corehi_irqaction, (0x100 << MIPSCPU_INT_COREHI));
333#else /* Not SMTC */
Ralf Baechlee01402b2005-07-14 15:57:16 +0000334 setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq);
335 setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI, &corehi_irqaction);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100336#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechlee01402b2005-07-14 15:57:16 +0000337 }
338 else {
Ralf Baechlee01402b2005-07-14 15:57:16 +0000339 setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq);
340 setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI, &corehi_irqaction);
341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}