Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 2 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Carsten Langgaard, carstenl@mips.com |
| 7 | * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc. |
| 8 | * Copyright (C) 2001 Ralf Baechle |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 9 | * Copyright (C) 2013 Imagination Technologies Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Routines for generic manipulation of the interrupts found on the MIPS |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 12 | * Malta board. The interrupt controller is located in the South Bridge |
| 13 | * a PIIX4 device with two internal 82C95 interrupt controllers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/irq.h> |
Paul Burton | 38ec82f | 2016-09-19 22:21:23 +0100 | [diff] [blame] | 17 | #include <linux/irqchip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/sched.h> |
Ralf Baechle | 631330f | 2009-06-19 14:05:26 +0100 | [diff] [blame] | 19 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
Dmitri Vorobiev | 54bf038 | 2008-01-24 19:52:49 +0300 | [diff] [blame] | 21 | #include <linux/io.h> |
Paul Burton | 38ec82f | 2016-09-19 22:21:23 +0100 | [diff] [blame] | 22 | #include <linux/of_irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kernel_stat.h> |
Ahmed S. Darwish | 25b8ac3 | 2007-02-05 04:42:11 +0200 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/random.h> |
| 26 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 27 | #include <asm/traps.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/i8259.h> |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 29 | #include <asm/irq_cpu.h> |
Ralf Baechle | ba38cdf | 2006-10-15 09:17:43 +0100 | [diff] [blame] | 30 | #include <asm/irq_regs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/mips-boards/malta.h> |
| 32 | #include <asm/mips-boards/maltaint.h> |
Paul Burton | 72eb299 | 2017-08-12 21:36:34 -0700 | [diff] [blame] | 33 | #include <asm/mips-cps.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/gt64120.h> |
| 35 | #include <asm/mips-boards/generic.h> |
| 36 | #include <asm/mips-boards/msc01_pci.h> |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 37 | #include <asm/msc01_ic.h> |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 38 | #include <asm/setup.h> |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 39 | #include <asm/rtlx.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static inline int mips_pcibios_iack(void) |
| 42 | { |
| 43 | int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * Determine highest priority pending interrupt by performing |
| 47 | * a PCI Interrupt Acknowledge cycle. |
| 48 | */ |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 49 | switch (mips_revision_sconid) { |
| 50 | case MIPS_REVISION_SCON_SOCIT: |
| 51 | case MIPS_REVISION_SCON_ROCIT: |
| 52 | case MIPS_REVISION_SCON_SOCITSC: |
| 53 | case MIPS_REVISION_SCON_SOCITSCP: |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 54 | MSC_READ(MSC01_PCI_IACK, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | irq &= 0xff; |
| 56 | break; |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 57 | case MIPS_REVISION_SCON_GT64120: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | irq = GT_READ(GT_PCI0_IACK_OFS); |
| 59 | irq &= 0xff; |
| 60 | break; |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 61 | case MIPS_REVISION_SCON_BONITO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* The following will generate a PCI IACK cycle on the |
| 63 | * Bonito controller. It's a little bit kludgy, but it |
| 64 | * was the easiest way to implement it in hardware at |
| 65 | * the given time. |
| 66 | */ |
| 67 | BONITO_PCIMAP_CFG = 0x20000; |
| 68 | |
| 69 | /* Flush Bonito register block */ |
Ralf Baechle | 6be63bb | 2011-03-29 11:48:22 +0200 | [diff] [blame] | 70 | (void) BONITO_PCIMAP_CFG; |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 71 | iob(); /* sync */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Chris Dearman | accfd35 | 2009-07-10 01:53:54 -0700 | [diff] [blame] | 73 | irq = __raw_readl((u32 *)_pcictrl_bonito_pcicfg); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 74 | iob(); /* sync */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | irq &= 0xff; |
| 76 | BONITO_PCIMAP_CFG = 0; |
| 77 | break; |
| 78 | default: |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 79 | pr_emerg("Unknown system controller.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return -1; |
| 81 | } |
| 82 | return irq; |
| 83 | } |
| 84 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 85 | static void corehi_irqdispatch(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 87 | unsigned int intedge, intsteer, pcicmd, pcibadaddr; |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 88 | unsigned int pcimstat, intisr, inten, intpol; |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 89 | unsigned int intrcause, datalo, datahi; |
Ralf Baechle | ba38cdf | 2006-10-15 09:17:43 +0100 | [diff] [blame] | 90 | struct pt_regs *regs = get_irq_regs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 92 | pr_emerg("CoreHI interrupt, shouldn't happen, we die here!\n"); |
| 93 | pr_emerg("epc : %08lx\nStatus: %08lx\n" |
| 94 | "Cause : %08lx\nbadVaddr : %08lx\n", |
| 95 | regs->cp0_epc, regs->cp0_status, |
| 96 | regs->cp0_cause, regs->cp0_badvaddr); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 97 | |
| 98 | /* Read all the registers and then print them as there is a |
| 99 | problem with interspersed printk's upsetting the Bonito controller. |
| 100 | Do it for the others too. |
| 101 | */ |
| 102 | |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 103 | switch (mips_revision_sconid) { |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 104 | case MIPS_REVISION_SCON_SOCIT: |
Chris Dearman | b72c052 | 2007-04-27 15:58:41 +0100 | [diff] [blame] | 105 | case MIPS_REVISION_SCON_ROCIT: |
| 106 | case MIPS_REVISION_SCON_SOCITSC: |
| 107 | case MIPS_REVISION_SCON_SOCITSCP: |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 108 | ll_msc_irq(); |
| 109 | break; |
| 110 | case MIPS_REVISION_SCON_GT64120: |
| 111 | intrcause = GT_READ(GT_INTRCAUSE_OFS); |
| 112 | datalo = GT_READ(GT_CPUERR_ADDRLO_OFS); |
| 113 | datahi = GT_READ(GT_CPUERR_ADDRHI_OFS); |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 114 | pr_emerg("GT_INTRCAUSE = %08x\n", intrcause); |
| 115 | pr_emerg("GT_CPUERR_ADDR = %02x%08x\n", |
Dmitri Vorobiev | 8216d34 | 2008-01-24 19:52:42 +0300 | [diff] [blame] | 116 | datahi, datalo); |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 117 | break; |
| 118 | case MIPS_REVISION_SCON_BONITO: |
| 119 | pcibadaddr = BONITO_PCIBADADDR; |
| 120 | pcimstat = BONITO_PCIMSTAT; |
| 121 | intisr = BONITO_INTISR; |
| 122 | inten = BONITO_INTEN; |
| 123 | intpol = BONITO_INTPOL; |
| 124 | intedge = BONITO_INTEDGE; |
| 125 | intsteer = BONITO_INTSTEER; |
| 126 | pcicmd = BONITO_PCICMD; |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 127 | pr_emerg("BONITO_INTISR = %08x\n", intisr); |
| 128 | pr_emerg("BONITO_INTEN = %08x\n", inten); |
| 129 | pr_emerg("BONITO_INTPOL = %08x\n", intpol); |
| 130 | pr_emerg("BONITO_INTEDGE = %08x\n", intedge); |
| 131 | pr_emerg("BONITO_INTSTEER = %08x\n", intsteer); |
| 132 | pr_emerg("BONITO_PCICMD = %08x\n", pcicmd); |
| 133 | pr_emerg("BONITO_PCIBADADDR = %08x\n", pcibadaddr); |
| 134 | pr_emerg("BONITO_PCIMSTAT = %08x\n", pcimstat); |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 135 | break; |
| 136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 138 | die("CoreHi interrupt", regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 141 | static irqreturn_t corehi_handler(int irq, void *dev_id) |
| 142 | { |
| 143 | corehi_irqdispatch(); |
| 144 | return IRQ_HANDLED; |
| 145 | } |
| 146 | |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 147 | static msc_irqmap_t msc_irqmap[] __initdata = { |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 148 | {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0}, |
| 149 | {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0}, |
| 150 | }; |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 151 | static int msc_nr_irqs __initdata = ARRAY_SIZE(msc_irqmap); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 152 | |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 153 | static msc_irqmap_t msc_eicirqmap[] __initdata = { |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 154 | {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0}, |
| 155 | {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0}, |
| 156 | {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0}, |
| 157 | {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0}, |
| 158 | {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0}, |
| 159 | {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0}, |
| 160 | {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0}, |
| 161 | {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0}, |
| 162 | {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0}, |
| 163 | {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0} |
| 164 | }; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 165 | |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 166 | static int msc_nr_eicirqs __initdata = ARRAY_SIZE(msc_eicirqmap); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | void __init arch_init_irq(void) |
| 169 | { |
Paul Burton | 38ec82f | 2016-09-19 22:21:23 +0100 | [diff] [blame] | 170 | int corehi_irq; |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 171 | |
Matt Redfearn | 9eec1c0 | 2017-04-06 16:58:09 +0100 | [diff] [blame] | 172 | /* |
| 173 | * Preallocate the i8259's expected virq's here. Since irqchip_init() |
| 174 | * will probe the irqchips in hierarchial order, i8259 is probed last. |
| 175 | * If anything allocates a virq before the i8259 is probed, it will |
| 176 | * be given one of the i8259's expected range and consequently setup |
| 177 | * of the i8259 will fail. |
| 178 | */ |
| 179 | WARN(irq_alloc_descs(I8259A_IRQ_BASE, I8259A_IRQ_BASE, |
| 180 | 16, numa_node_id()) < 0, |
| 181 | "Cannot reserve i8259 virqs at IRQ%d\n", I8259A_IRQ_BASE); |
| 182 | |
Paul Burton | 38ec82f | 2016-09-19 22:21:23 +0100 | [diff] [blame] | 183 | i8259_set_poll(mips_pcibios_iack); |
| 184 | irqchip_init(); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 185 | |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 186 | switch (mips_revision_sconid) { |
| 187 | case MIPS_REVISION_SCON_SOCIT: |
| 188 | case MIPS_REVISION_SCON_ROCIT: |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 189 | if (cpu_has_veic) |
Dmitri Vorobiev | f807149 | 2008-01-24 19:52:47 +0300 | [diff] [blame] | 190 | init_msc_irqs(MIPS_MSC01_IC_REG_BASE, |
| 191 | MSC01E_INT_BASE, msc_eicirqmap, |
| 192 | msc_nr_eicirqs); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 193 | else |
Dmitri Vorobiev | f807149 | 2008-01-24 19:52:47 +0300 | [diff] [blame] | 194 | init_msc_irqs(MIPS_MSC01_IC_REG_BASE, |
| 195 | MSC01C_INT_BASE, msc_irqmap, |
| 196 | msc_nr_irqs); |
Chris Dearman | d725cf3 | 2007-05-08 14:05:39 +0100 | [diff] [blame] | 197 | break; |
| 198 | |
Dmitri Vorobiev | af82558 | 2008-01-24 19:52:45 +0300 | [diff] [blame] | 199 | case MIPS_REVISION_SCON_SOCITSC: |
| 200 | case MIPS_REVISION_SCON_SOCITSCP: |
Chris Dearman | d725cf3 | 2007-05-08 14:05:39 +0100 | [diff] [blame] | 201 | if (cpu_has_veic) |
Dmitri Vorobiev | f807149 | 2008-01-24 19:52:47 +0300 | [diff] [blame] | 202 | init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE, |
| 203 | MSC01E_INT_BASE, msc_eicirqmap, |
| 204 | msc_nr_eicirqs); |
Chris Dearman | d725cf3 | 2007-05-08 14:05:39 +0100 | [diff] [blame] | 205 | else |
Dmitri Vorobiev | f807149 | 2008-01-24 19:52:47 +0300 | [diff] [blame] | 206 | init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE, |
| 207 | MSC01C_INT_BASE, msc_irqmap, |
| 208 | msc_nr_irqs); |
Ralf Baechle | e01402b | 2005-07-14 15:57:16 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Paul Burton | 72eb299 | 2017-08-12 21:36:34 -0700 | [diff] [blame] | 211 | if (mips_gic_present()) { |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 212 | corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI; |
Paul Burton | 1eed400 | 2017-03-30 12:06:12 -0700 | [diff] [blame] | 213 | } else if (cpu_has_veic) { |
| 214 | set_vi_handler(MSC01E_INT_COREHI, corehi_irqdispatch); |
| 215 | corehi_irq = MSC01E_INT_BASE + MSC01E_INT_COREHI; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 216 | } else { |
Paul Burton | 1eed400 | 2017-03-30 12:06:12 -0700 | [diff] [blame] | 217 | corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI; |
Chris Dearman | 7098f74 | 2009-07-10 01:54:09 -0700 | [diff] [blame] | 218 | } |
Andrew Bresticker | 18743d2 | 2014-09-18 14:47:24 -0700 | [diff] [blame] | 219 | |
afzal mohammed | ac8fd12 | 2020-03-05 17:27:53 +0530 | [diff] [blame] | 220 | if (request_irq(corehi_irq, corehi_handler, IRQF_NO_THREAD, "CoreHi", |
| 221 | NULL)) |
| 222 | pr_err("Failed to request irq %d (CoreHi)\n", corehi_irq); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 223 | } |