blob: cb675ec6f283ee9d08071e9b112845bddd5c1594 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Steven J. Hill5792bf62014-01-01 16:35:32 +01002 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Carsten Langgaard, carstenl@mips.com
7 * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.
8 * Copyright (C) 2001 Ralf Baechle
Deng-Cheng Zhu13361132013-10-30 15:52:10 -05009 * Copyright (C) 2013 Imagination Technologies Ltd.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * Routines for generic manipulation of the interrupts found on the MIPS
Steven J. Hill5792bf62014-01-01 16:35:32 +010012 * Malta board. The interrupt controller is located in the South Bridge
13 * a PIIX4 device with two internal 82C95 interrupt controllers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15#include <linux/init.h>
16#include <linux/irq.h>
Paul Burton38ec82f2016-09-19 22:21:23 +010017#include <linux/irqchip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/sched.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010019#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/interrupt.h>
Dmitri Vorobiev54bf0382008-01-24 19:52:49 +030021#include <linux/io.h>
Andrew Bresticker4060bbe2014-10-20 12:03:53 -070022#include <linux/irqchip/mips-gic.h>
Paul Burton38ec82f2016-09-19 22:21:23 +010023#include <linux/of_irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/kernel_stat.h>
Ahmed S. Darwish25b8ac32007-02-05 04:42:11 +020025#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/random.h>
27
Ralf Baechle39b8d522008-04-28 17:14:26 +010028#include <asm/traps.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/i8259.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000030#include <asm/irq_cpu.h>
Ralf Baechleba38cdf2006-10-15 09:17:43 +010031#include <asm/irq_regs.h>
Paul Burton237036d2014-01-15 10:31:54 +000032#include <asm/mips-cm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/mips-boards/malta.h>
34#include <asm/mips-boards/maltaint.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/gt64120.h>
36#include <asm/mips-boards/generic.h>
37#include <asm/mips-boards/msc01_pci.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000038#include <asm/msc01_ic.h>
David Howellsb81947c2012-03-28 18:30:02 +010039#include <asm/setup.h>
Deng-Cheng Zhu13361132013-10-30 15:52:10 -050040#include <asm/rtlx.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static inline int mips_pcibios_iack(void)
43{
44 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46 /*
47 * Determine highest priority pending interrupt by performing
48 * a PCI Interrupt Acknowledge cycle.
49 */
Chris Dearmanb72c0522007-04-27 15:58:41 +010050 switch (mips_revision_sconid) {
51 case MIPS_REVISION_SCON_SOCIT:
52 case MIPS_REVISION_SCON_ROCIT:
53 case MIPS_REVISION_SCON_SOCITSC:
54 case MIPS_REVISION_SCON_SOCITSCP:
Dmitri Vorobievaf825582008-01-24 19:52:45 +030055 MSC_READ(MSC01_PCI_IACK, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 irq &= 0xff;
57 break;
Chris Dearmanb72c0522007-04-27 15:58:41 +010058 case MIPS_REVISION_SCON_GT64120:
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 irq = GT_READ(GT_PCI0_IACK_OFS);
60 irq &= 0xff;
61 break;
Chris Dearmanb72c0522007-04-27 15:58:41 +010062 case MIPS_REVISION_SCON_BONITO:
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 /* The following will generate a PCI IACK cycle on the
64 * Bonito controller. It's a little bit kludgy, but it
65 * was the easiest way to implement it in hardware at
66 * the given time.
67 */
68 BONITO_PCIMAP_CFG = 0x20000;
69
70 /* Flush Bonito register block */
Ralf Baechle6be63bb2011-03-29 11:48:22 +020071 (void) BONITO_PCIMAP_CFG;
Ralf Baechle70342282013-01-22 12:59:30 +010072 iob(); /* sync */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Chris Dearmanaccfd352009-07-10 01:53:54 -070074 irq = __raw_readl((u32 *)_pcictrl_bonito_pcicfg);
Ralf Baechle70342282013-01-22 12:59:30 +010075 iob(); /* sync */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 irq &= 0xff;
77 BONITO_PCIMAP_CFG = 0;
78 break;
79 default:
Steven J. Hill5792bf62014-01-01 16:35:32 +010080 pr_emerg("Unknown system controller.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return -1;
82 }
83 return irq;
84}
85
Ralf Baechle937a8012006-10-07 19:44:33 +010086static void corehi_irqdispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Ralf Baechle937a8012006-10-07 19:44:33 +010088 unsigned int intedge, intsteer, pcicmd, pcibadaddr;
Dmitri Vorobievaf825582008-01-24 19:52:45 +030089 unsigned int pcimstat, intisr, inten, intpol;
Ralf Baechle21a151d2007-10-11 23:46:15 +010090 unsigned int intrcause, datalo, datahi;
Ralf Baechleba38cdf2006-10-15 09:17:43 +010091 struct pt_regs *regs = get_irq_regs();
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Steven J. Hill5792bf62014-01-01 16:35:32 +010093 pr_emerg("CoreHI interrupt, shouldn't happen, we die here!\n");
94 pr_emerg("epc : %08lx\nStatus: %08lx\n"
95 "Cause : %08lx\nbadVaddr : %08lx\n",
96 regs->cp0_epc, regs->cp0_status,
97 regs->cp0_cause, regs->cp0_badvaddr);
Ralf Baechlee01402b2005-07-14 15:57:16 +000098
99 /* Read all the registers and then print them as there is a
100 problem with interspersed printk's upsetting the Bonito controller.
101 Do it for the others too.
102 */
103
Chris Dearmanb72c0522007-04-27 15:58:41 +0100104 switch (mips_revision_sconid) {
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300105 case MIPS_REVISION_SCON_SOCIT:
Chris Dearmanb72c0522007-04-27 15:58:41 +0100106 case MIPS_REVISION_SCON_ROCIT:
107 case MIPS_REVISION_SCON_SOCITSC:
108 case MIPS_REVISION_SCON_SOCITSCP:
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300109 ll_msc_irq();
110 break;
111 case MIPS_REVISION_SCON_GT64120:
112 intrcause = GT_READ(GT_INTRCAUSE_OFS);
113 datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
114 datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
Steven J. Hill5792bf62014-01-01 16:35:32 +0100115 pr_emerg("GT_INTRCAUSE = %08x\n", intrcause);
116 pr_emerg("GT_CPUERR_ADDR = %02x%08x\n",
Dmitri Vorobiev8216d342008-01-24 19:52:42 +0300117 datahi, datalo);
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300118 break;
119 case MIPS_REVISION_SCON_BONITO:
120 pcibadaddr = BONITO_PCIBADADDR;
121 pcimstat = BONITO_PCIMSTAT;
122 intisr = BONITO_INTISR;
123 inten = BONITO_INTEN;
124 intpol = BONITO_INTPOL;
125 intedge = BONITO_INTEDGE;
126 intsteer = BONITO_INTSTEER;
127 pcicmd = BONITO_PCICMD;
Steven J. Hill5792bf62014-01-01 16:35:32 +0100128 pr_emerg("BONITO_INTISR = %08x\n", intisr);
129 pr_emerg("BONITO_INTEN = %08x\n", inten);
130 pr_emerg("BONITO_INTPOL = %08x\n", intpol);
131 pr_emerg("BONITO_INTEDGE = %08x\n", intedge);
132 pr_emerg("BONITO_INTSTEER = %08x\n", intsteer);
133 pr_emerg("BONITO_PCICMD = %08x\n", pcicmd);
134 pr_emerg("BONITO_PCIBADADDR = %08x\n", pcibadaddr);
135 pr_emerg("BONITO_PCIMSTAT = %08x\n", pcimstat);
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300136 break;
137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300139 die("CoreHi interrupt", regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Andrew Bresticker18743d22014-09-18 14:47:24 -0700142static irqreturn_t corehi_handler(int irq, void *dev_id)
143{
144 corehi_irqdispatch();
145 return IRQ_HANDLED;
146}
147
Ralf Baechle39b8d522008-04-28 17:14:26 +0100148#ifdef CONFIG_MIPS_MT_SMP
149
Ralf Baechle39b8d522008-04-28 17:14:26 +0100150#define MIPS_CPU_IPI_RESCHED_IRQ 0 /* SW int 0 for resched */
151#define C_RESCHED C_SW0
152#define MIPS_CPU_IPI_CALL_IRQ 1 /* SW int 1 for resched */
153#define C_CALL C_SW1
154static int cpu_ipi_resched_irq, cpu_ipi_call_irq;
155
156static void ipi_resched_dispatch(void)
157{
158 do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ);
159}
160
161static void ipi_call_dispatch(void)
162{
163 do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ);
164}
165
166static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
167{
Deng-Cheng Zhu9c1f6e02014-02-28 10:23:01 -0800168#ifdef CONFIG_MIPS_VPE_APSP_API_CMP
Deng-Cheng Zhu13361132013-10-30 15:52:10 -0500169 if (aprp_hook)
170 aprp_hook();
171#endif
172
Peter Zijlstra184748c2011-04-05 17:23:39 +0200173 scheduler_ipi();
174
Ralf Baechle39b8d522008-04-28 17:14:26 +0100175 return IRQ_HANDLED;
176}
177
178static irqreturn_t ipi_call_interrupt(int irq, void *dev_id)
179{
Alex Smith4ace6132015-07-24 16:57:49 +0100180 generic_smp_call_function_interrupt();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100181
182 return IRQ_HANDLED;
183}
184
185static struct irqaction irq_resched = {
186 .handler = ipi_resched_interrupt,
Yong Zhang8b5690f2011-11-22 14:38:03 +0000187 .flags = IRQF_PERCPU,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100188 .name = "IPI_resched"
189};
190
191static struct irqaction irq_call = {
192 .handler = ipi_call_interrupt,
Yong Zhang8b5690f2011-11-22 14:38:03 +0000193 .flags = IRQF_PERCPU,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100194 .name = "IPI_call"
195};
Andrew Bresticker18743d22014-09-18 14:47:24 -0700196#endif /* CONFIG_MIPS_MT_SMP */
Ralf Baechle39b8d522008-04-28 17:14:26 +0100197
Ralf Baechlee01402b2005-07-14 15:57:16 +0000198static struct irqaction corehi_irqaction = {
Andrew Bresticker18743d22014-09-18 14:47:24 -0700199 .handler = corehi_handler,
Wu Zhangjin5a4a4ad2011-07-23 12:41:24 +0000200 .name = "CoreHi",
201 .flags = IRQF_NO_THREAD,
Ralf Baechlee01402b2005-07-14 15:57:16 +0000202};
203
Steven J. Hill5792bf62014-01-01 16:35:32 +0100204static msc_irqmap_t msc_irqmap[] __initdata = {
Ralf Baechlee01402b2005-07-14 15:57:16 +0000205 {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
206 {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
207};
Steven J. Hill5792bf62014-01-01 16:35:32 +0100208static int msc_nr_irqs __initdata = ARRAY_SIZE(msc_irqmap);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000209
Steven J. Hill5792bf62014-01-01 16:35:32 +0100210static msc_irqmap_t msc_eicirqmap[] __initdata = {
Ralf Baechlee01402b2005-07-14 15:57:16 +0000211 {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
212 {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
213 {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
214 {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
215 {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
216 {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
217 {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
218 {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
219 {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
220 {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
221};
Ralf Baechle39b8d522008-04-28 17:14:26 +0100222
Steven J. Hill5792bf62014-01-01 16:35:32 +0100223static int msc_nr_eicirqs __initdata = ARRAY_SIZE(msc_eicirqmap);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000224
Chris Dearman7098f742009-07-10 01:54:09 -0700225void __init arch_init_ipiirq(int irq, struct irqaction *action)
226{
227 setup_irq(irq, action);
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200228 irq_set_handler(irq, handle_percpu_irq);
Chris Dearman7098f742009-07-10 01:54:09 -0700229}
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231void __init arch_init_irq(void)
232{
Paul Burton38ec82f2016-09-19 22:21:23 +0100233 int corehi_irq;
Andrew Bresticker18743d22014-09-18 14:47:24 -0700234
Paul Burton38ec82f2016-09-19 22:21:23 +0100235 i8259_set_poll(mips_pcibios_iack);
236 irqchip_init();
Ralf Baechle39b8d522008-04-28 17:14:26 +0100237
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300238 switch (mips_revision_sconid) {
239 case MIPS_REVISION_SCON_SOCIT:
240 case MIPS_REVISION_SCON_ROCIT:
Ralf Baechlee01402b2005-07-14 15:57:16 +0000241 if (cpu_has_veic)
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300242 init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
243 MSC01E_INT_BASE, msc_eicirqmap,
244 msc_nr_eicirqs);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000245 else
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300246 init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
247 MSC01C_INT_BASE, msc_irqmap,
248 msc_nr_irqs);
Chris Dearmand725cf32007-05-08 14:05:39 +0100249 break;
250
Dmitri Vorobievaf825582008-01-24 19:52:45 +0300251 case MIPS_REVISION_SCON_SOCITSC:
252 case MIPS_REVISION_SCON_SOCITSCP:
Chris Dearmand725cf32007-05-08 14:05:39 +0100253 if (cpu_has_veic)
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300254 init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
255 MSC01E_INT_BASE, msc_eicirqmap,
256 msc_nr_eicirqs);
Chris Dearmand725cf32007-05-08 14:05:39 +0100257 else
Dmitri Vorobievf8071492008-01-24 19:52:47 +0300258 init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
259 MSC01C_INT_BASE, msc_irqmap,
260 msc_nr_irqs);
Ralf Baechlee01402b2005-07-14 15:57:16 +0000261 }
262
Ralf Baechle39b8d522008-04-28 17:14:26 +0100263 if (gic_present) {
Andrew Bresticker18743d22014-09-18 14:47:24 -0700264 corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100265 } else {
Chris Dearman7098f742009-07-10 01:54:09 -0700266#if defined(CONFIG_MIPS_MT_SMP)
Ralf Baechle39b8d522008-04-28 17:14:26 +0100267 /* set up ipi interrupts */
268 if (cpu_has_veic) {
269 set_vi_handler (MSC01E_INT_SW0, ipi_resched_dispatch);
270 set_vi_handler (MSC01E_INT_SW1, ipi_call_dispatch);
271 cpu_ipi_resched_irq = MSC01E_INT_SW0;
272 cpu_ipi_call_irq = MSC01E_INT_SW1;
273 } else {
Steven J. Hill5792bf62014-01-01 16:35:32 +0100274 cpu_ipi_resched_irq = MIPS_CPU_IRQ_BASE +
275 MIPS_CPU_IPI_RESCHED_IRQ;
276 cpu_ipi_call_irq = MIPS_CPU_IRQ_BASE +
277 MIPS_CPU_IPI_CALL_IRQ;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100278 }
Chris Dearman7098f742009-07-10 01:54:09 -0700279 arch_init_ipiirq(cpu_ipi_resched_irq, &irq_resched);
280 arch_init_ipiirq(cpu_ipi_call_irq, &irq_call);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100281#endif
Andrew Bresticker18743d22014-09-18 14:47:24 -0700282 if (cpu_has_veic) {
Andrew Bresticker18743d22014-09-18 14:47:24 -0700283 set_vi_handler(MSC01E_INT_COREHI,
284 corehi_irqdispatch);
Andrew Bresticker18743d22014-09-18 14:47:24 -0700285 corehi_irq = MSC01E_INT_BASE + MSC01E_INT_COREHI;
286 } else {
Andrew Bresticker18743d22014-09-18 14:47:24 -0700287 corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI;
288 }
Chris Dearman7098f742009-07-10 01:54:09 -0700289 }
Andrew Bresticker18743d22014-09-18 14:47:24 -0700290
Andrew Bresticker18743d22014-09-18 14:47:24 -0700291 setup_irq(corehi_irq, &corehi_irqaction);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100292}