blob: 1b4b9c507e28684b42da22929cd58f392f8aefd6 [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>
Ahmed S. Darwish25b8ac32007-02-05 04:42:11 +020030#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/random.h>
32
33#include <asm/i8259.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000034#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/io.h>
Ralf Baechleba38cdf2006-10-15 09:17:43 +010036#include <asm/irq_regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#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>
Ralf Baechlee01402b2005-07-14 15:57:16 +000043#include <asm/msc01_ic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static DEFINE_SPINLOCK(mips_irq_lock);
46
47static inline int mips_pcibios_iack(void)
48{
49 int irq;
Dmitri Vorobievaf825582008-01-24 19:52:45 +030050 u32 dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 /*
53 * Determine highest priority pending interrupt by performing
54 * a PCI Interrupt Acknowledge cycle.
55 */
Chris Dearmanb72c0522007-04-27 15:58:41 +010056 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:
Dmitri Vorobievaf825582008-01-24 19:52:45 +030061 MSC_READ(MSC01_PCI_IACK, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 irq &= 0xff;
63 break;
Chris Dearmanb72c0522007-04-27 15:58:41 +010064 case MIPS_REVISION_SCON_GT64120:
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 irq = GT_READ(GT_PCI0_IACK_OFS);
66 irq &= 0xff;
67 break;
Chris Dearmanb72c0522007-04-27 15:58:41 +010068 case MIPS_REVISION_SCON_BONITO:
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 /* 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
72 * the given time.
73 */
74 BONITO_PCIMAP_CFG = 0x20000;
75
76 /* Flush Bonito register block */
77 dummy = BONITO_PCIMAP_CFG;
78 iob(); /* sync */
79
Ralf Baechlef1974652007-04-26 15:46:24 +010080 irq = readl((u32 *)_pcictrl_bonito_pcicfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 iob(); /* sync */
82 irq &= 0xff;
83 BONITO_PCIMAP_CFG = 0;
84 break;
85 default:
Dmitri Vorobiev8216d342008-01-24 19:52:42 +030086 printk(KERN_WARNING "Unknown system controller.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return -1;
88 }
89 return irq;
90}
91
Ralf Baechlee01402b2005-07-14 15:57:16 +000092static inline int get_int(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 unsigned long flags;
Ralf Baechlee01402b2005-07-14 15:57:16 +000095 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 spin_lock_irqsave(&mips_irq_lock, flags);
97
Ralf Baechlee01402b2005-07-14 15:57:16 +000098 irq = mips_pcibios_iack();
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 /*
Ralf Baechle479a0e32005-08-16 15:44:06 +0000101 * 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...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 spin_unlock_irqrestore(&mips_irq_lock, flags);
107
Ralf Baechlee01402b2005-07-14 15:57:16 +0000108 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Ralf Baechle937a8012006-10-07 19:44:33 +0100111static void malta_hw0_irqdispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 int irq;
114
Ralf Baechlee01402b2005-07-14 15:57:16 +0000115 irq = get_int();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100116 if (irq < 0) {
Ralf Baechlee01402b2005-07-14 15:57:16 +0000117 return; /* interrupt has already been cleared */
Ralf Baechle41c594a2006-04-05 09:45:45 +0100118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Ralf Baechle937a8012006-10-07 19:44:33 +0100120 do_IRQ(MALTA_INT_BASE + irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
Ralf Baechle937a8012006-10-07 19:44:33 +0100123static void corehi_irqdispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Ralf Baechle937a8012006-10-07 19:44:33 +0100125 unsigned int intedge, intsteer, pcicmd, pcibadaddr;
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300126 unsigned int pcimstat, intisr, inten, intpol;
Ralf Baechle21a151d2007-10-11 23:46:15 +0100127 unsigned int intrcause, datalo, datahi;
Ralf Baechleba38cdf2006-10-15 09:17:43 +0100128 struct pt_regs *regs = get_irq_regs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Dmitri Vorobiev8216d342008-01-24 19:52:42 +0300130 printk(KERN_EMERG "CoreHI interrupt, shouldn't happen, we die here!\n");
131 printk(KERN_EMERG "epc : %08lx\nStatus: %08lx\n"
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300132 "Cause : %08lx\nbadVaddr : %08lx\n",
133 regs->cp0_epc, regs->cp0_status,
134 regs->cp0_cause, regs->cp0_badvaddr);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000135
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.
139 */
140
Chris Dearmanb72c0522007-04-27 15:58:41 +0100141 switch (mips_revision_sconid) {
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300142 case MIPS_REVISION_SCON_SOCIT:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100143 case MIPS_REVISION_SCON_ROCIT:
144 case MIPS_REVISION_SCON_SOCITSC:
145 case MIPS_REVISION_SCON_SOCITSCP:
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300146 ll_msc_irq();
147 break;
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);
Dmitri Vorobiev8216d342008-01-24 19:52:42 +0300152 printk(KERN_EMERG "GT_INTRCAUSE = %08x\n", intrcause);
153 printk(KERN_EMERG "GT_CPUERR_ADDR = %02x%08x\n",
154 datahi, datalo);
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300155 break;
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;
Dmitri Vorobiev8216d342008-01-24 19:52:42 +0300165 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);
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300173 break;
174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300176 /* We die here*/
177 die("CoreHi interrupt", regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100180static inline int clz(unsigned long x)
181{
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100182 __asm__(
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100183 " .set push \n"
184 " .set mips32 \n"
185 " clz %0, %1 \n"
186 " .set pop \n"
187 : "=r" (x)
188 : "r" (x));
189
190 return x;
191}
192
193/*
194 * Version of ffs that only looks at bits 12..15.
195 */
196static inline unsigned int irq_ffs(unsigned int pending)
197{
198#if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
199 return -clz(pending) + 31 - CAUSEB_IP;
200#else
201 unsigned int a0 = 7;
202 unsigned int t0;
203
Ralf Baechle0118c3c2006-06-05 11:54:41 +0100204 t0 = pending & 0xf000;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100205 t0 = t0 < 1;
206 t0 = t0 << 2;
207 a0 = a0 - t0;
Ralf Baechle0118c3c2006-06-05 11:54:41 +0100208 pending = pending << t0;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100209
Ralf Baechle0118c3c2006-06-05 11:54:41 +0100210 t0 = pending & 0xc000;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100211 t0 = t0 < 1;
212 t0 = t0 << 1;
213 a0 = a0 - t0;
Ralf Baechle0118c3c2006-06-05 11:54:41 +0100214 pending = pending << t0;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100215
Ralf Baechle0118c3c2006-06-05 11:54:41 +0100216 t0 = pending & 0x8000;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100217 t0 = t0 < 1;
218 //t0 = t0 << 2;
219 a0 = a0 - t0;
Ralf Baechle0118c3c2006-06-05 11:54:41 +0100220 //pending = pending << t0;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100221
222 return a0;
223#endif
224}
225
226/*
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:
230 *
231 * MIPS IRQ Source
232 * -------- ------
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)
241 *
242 * We handle the IRQ according to _our_ priority which is:
243 *
244 * Highest ---- R4k Timer
245 * Lowest ---- Combined hardware interrupt
246 *
247 * then we just return, if multiple IRQs are pending then we will just take
248 * another exception, big deal.
249 */
250
Ralf Baechle937a8012006-10-07 19:44:33 +0100251asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100252{
253 unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
254 int irq;
255
256 irq = irq_ffs(pending);
257
258 if (irq == MIPSCPU_INT_I8259A)
Ralf Baechle937a8012006-10-07 19:44:33 +0100259 malta_hw0_irqdispatch();
Ralf Baechle48d480b2007-09-13 17:36:22 +0100260 else if (irq >= 0)
Ralf Baechle3b1d4ed2007-06-20 22:27:10 +0100261 do_IRQ(MIPS_CPU_IRQ_BASE + irq);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100262 else
Ralf Baechle937a8012006-10-07 19:44:33 +0100263 spurious_interrupt();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100264}
265
Ralf Baechlee01402b2005-07-14 15:57:16 +0000266static struct irqaction i8259irq = {
267 .handler = no_action,
268 .name = "XT-PIC cascade"
269};
270
271static struct irqaction corehi_irqaction = {
272 .handler = no_action,
273 .name = "CoreHi"
274};
275
276msc_irqmap_t __initdata msc_irqmap[] = {
277 {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
278 {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
279};
Ahmed S. Darwish25b8ac32007-02-05 04:42:11 +0200280int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000281
282msc_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}
293};
Ahmed S. Darwish25b8ac32007-02-05 04:42:11 +0200294int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296void __init arch_init_irq(void)
297{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 init_i8259_irqs();
Ralf Baechlee01402b2005-07-14 15:57:16 +0000299
300 if (!cpu_has_veic)
Atsushi Nemoto97dcb822007-01-08 02:14:29 +0900301 mips_cpu_irq_init();
Ralf Baechlee01402b2005-07-14 15:57:16 +0000302
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300303 switch (mips_revision_sconid) {
304 case MIPS_REVISION_SCON_SOCIT:
305 case MIPS_REVISION_SCON_ROCIT:
Ralf Baechlee01402b2005-07-14 15:57:16 +0000306 if (cpu_has_veic)
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300307 init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
308 MSC01E_INT_BASE, msc_eicirqmap,
309 msc_nr_eicirqs);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000310 else
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300311 init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
312 MSC01C_INT_BASE, msc_irqmap,
313 msc_nr_irqs);
Chris Dearmand725cf32007-05-08 14:05:39 +0100314 break;
315
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300316 case MIPS_REVISION_SCON_SOCITSC:
317 case MIPS_REVISION_SCON_SOCITSCP:
Chris Dearmand725cf32007-05-08 14:05:39 +0100318 if (cpu_has_veic)
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300319 init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
320 MSC01E_INT_BASE, msc_eicirqmap,
321 msc_nr_eicirqs);
Chris Dearmand725cf32007-05-08 14:05:39 +0100322 else
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300323 init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
324 MSC01C_INT_BASE, msc_irqmap,
325 msc_nr_irqs);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000326 }
327
328 if (cpu_has_veic) {
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100329 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);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000333 }
334 else if (cpu_has_vint) {
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100335 set_vi_handler(MIPSCPU_INT_I8259A, malta_hw0_irqdispatch);
336 set_vi_handler(MIPSCPU_INT_COREHI, corehi_irqdispatch);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100337#ifdef CONFIG_MIPS_MT_SMTC
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100338 setup_irq_smtc(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq,
Ralf Baechle41c594a2006-04-05 09:45:45 +0100339 (0x100 << MIPSCPU_INT_I8259A));
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100340 setup_irq_smtc(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
Ralf Baechle41c594a2006-04-05 09:45:45 +0100341 &corehi_irqaction, (0x100 << MIPSCPU_INT_COREHI));
Kevin D. Kissellc3a005f2007-07-27 18:45:25 +0100342 /*
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.
347 */
348 {
349 int i;
350
351 for (i = 0; i < 16; i++)
352 irq_hwmask[i] = (0x100 << MIPSCPU_INT_I8259A);
353 }
Ralf Baechle41c594a2006-04-05 09:45:45 +0100354#else /* Not SMTC */
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100355 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300356 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
357 &corehi_irqaction);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100358#endif /* CONFIG_MIPS_MT_SMTC */
Ralf Baechlee01402b2005-07-14 15:57:16 +0000359 }
360 else {
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100361 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300362 setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
363 &corehi_irqaction);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}