Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 2 | * Copyright (C) 1999, 2000, 2006 MIPS Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * Authors: Carsten Langgaard <carstenl@mips.com> |
| 5 | * Maciej W. Rozycki <macro@mips.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * ######################################################################## |
| 8 | * |
| 9 | * This program is free software; you can distribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License (Version 2) as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | * for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 21 | * |
| 22 | * ######################################################################## |
| 23 | * |
| 24 | * Routines for generic manipulation of the interrupts found on the MIPS |
| 25 | * Atlas board. |
| 26 | * |
| 27 | */ |
| 28 | #include <linux/compiler.h> |
| 29 | #include <linux/init.h> |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 30 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/sched.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/interrupt.h> |
| 34 | #include <linux/kernel_stat.h> |
Ahmed S. Darwish | 25b8ac3 | 2007-02-05 04:42:11 +0200 | [diff] [blame] | 35 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 37 | #include <asm/gdb-stub.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/io.h> |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 39 | #include <asm/irq_cpu.h> |
| 40 | #include <asm/msc01_ic.h> |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/mips-boards/atlas.h> |
| 43 | #include <asm/mips-boards/atlasint.h> |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 44 | #include <asm/mips-boards/generic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | static struct atlas_ictrl_regs *atlas_hw0_icregs; |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #if 0 |
| 49 | #define DEBUG_INT(x...) printk(x) |
| 50 | #else |
| 51 | #define DEBUG_INT(x...) |
| 52 | #endif |
| 53 | |
| 54 | void disable_atlas_irq(unsigned int irq_nr) |
| 55 | { |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 56 | atlas_hw0_icregs->intrsten = 1 << (irq_nr - ATLAS_INT_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | iob(); |
| 58 | } |
| 59 | |
| 60 | void enable_atlas_irq(unsigned int irq_nr) |
| 61 | { |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 62 | atlas_hw0_icregs->intseten = 1 << (irq_nr - ATLAS_INT_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | iob(); |
| 64 | } |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void end_atlas_irq(unsigned int irq) |
| 67 | { |
| 68 | if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 69 | enable_atlas_irq(irq); |
| 70 | } |
| 71 | |
Ralf Baechle | 94dee17 | 2006-07-02 14:41:42 +0100 | [diff] [blame] | 72 | static struct irq_chip atlas_irq_type = { |
Atsushi Nemoto | 70d21cd | 2007-01-15 00:07:25 +0900 | [diff] [blame] | 73 | .name = "Atlas", |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 74 | .ack = disable_atlas_irq, |
| 75 | .mask = disable_atlas_irq, |
| 76 | .mask_ack = disable_atlas_irq, |
| 77 | .unmask = enable_atlas_irq, |
Atsushi Nemoto | 1417836 | 2006-11-14 01:13:18 +0900 | [diff] [blame] | 78 | .eoi = enable_atlas_irq, |
Ralf Baechle | 8ab00b9 | 2005-02-28 13:39:57 +0000 | [diff] [blame] | 79 | .end = end_atlas_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static inline int ls1bit32(unsigned int x) |
| 83 | { |
| 84 | int b = 31, s; |
| 85 | |
| 86 | s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s; |
| 87 | s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s; |
| 88 | s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s; |
| 89 | s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s; |
| 90 | s = 1; if (x << 1 == 0) s = 0; b -= s; |
| 91 | |
| 92 | return b; |
| 93 | } |
| 94 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 95 | static inline void atlas_hw0_irqdispatch(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | unsigned long int_status; |
| 98 | int irq; |
| 99 | |
| 100 | int_status = atlas_hw0_icregs->intstatus; |
| 101 | |
| 102 | /* if int_status == 0, then the interrupt has already been cleared */ |
| 103 | if (unlikely(int_status == 0)) |
| 104 | return; |
| 105 | |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 106 | irq = ATLAS_INT_BASE + ls1bit32(int_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq); |
| 109 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 110 | do_IRQ(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 113 | static inline int clz(unsigned long x) |
| 114 | { |
| 115 | __asm__ ( |
| 116 | " .set push \n" |
| 117 | " .set mips32 \n" |
| 118 | " clz %0, %1 \n" |
| 119 | " .set pop \n" |
| 120 | : "=r" (x) |
| 121 | : "r" (x)); |
| 122 | |
| 123 | return x; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Version of ffs that only looks at bits 12..15. |
| 128 | */ |
| 129 | static inline unsigned int irq_ffs(unsigned int pending) |
| 130 | { |
| 131 | #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) |
| 132 | return -clz(pending) + 31 - CAUSEB_IP; |
| 133 | #else |
| 134 | unsigned int a0 = 7; |
| 135 | unsigned int t0; |
| 136 | |
| 137 | t0 = s0 & 0xf000; |
| 138 | t0 = t0 < 1; |
| 139 | t0 = t0 << 2; |
| 140 | a0 = a0 - t0; |
| 141 | s0 = s0 << t0; |
| 142 | |
| 143 | t0 = s0 & 0xc000; |
| 144 | t0 = t0 < 1; |
| 145 | t0 = t0 << 1; |
| 146 | a0 = a0 - t0; |
| 147 | s0 = s0 << t0; |
| 148 | |
| 149 | t0 = s0 & 0x8000; |
| 150 | t0 = t0 < 1; |
| 151 | //t0 = t0 << 2; |
| 152 | a0 = a0 - t0; |
| 153 | //s0 = s0 << t0; |
| 154 | |
| 155 | return a0; |
| 156 | #endif |
| 157 | } |
| 158 | |
| 159 | /* |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 160 | * IRQs on the Atlas board look basically like (all external interrupt |
| 161 | * sources are combined together on hardware interrupt 0 (MIPS IRQ 2)): |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 162 | * |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 163 | * MIPS IRQ Source |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 164 | * -------- ------ |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 165 | * 0 Software 0 (reschedule IPI on MT) |
| 166 | * 1 Software 1 (remote call IPI on MT) |
| 167 | * 2 Combined Atlas hardware interrupt (hw0) |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 168 | * 3 Hardware (ignored) |
| 169 | * 4 Hardware (ignored) |
| 170 | * 5 Hardware (ignored) |
| 171 | * 6 Hardware (ignored) |
| 172 | * 7 R4k timer (what we use) |
| 173 | * |
| 174 | * We handle the IRQ according to _our_ priority which is: |
| 175 | * |
| 176 | * Highest ---- R4k Timer |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 177 | * Lowest ---- Software 0 |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 178 | * |
| 179 | * then we just return, if multiple IRQs are pending then we will just take |
| 180 | * another exception, big deal. |
| 181 | */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 182 | asmlinkage void plat_irq_dispatch(void) |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 183 | { |
| 184 | unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM; |
| 185 | int irq; |
| 186 | |
| 187 | irq = irq_ffs(pending); |
| 188 | |
| 189 | if (irq == MIPSCPU_INT_ATLAS) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 190 | atlas_hw0_irqdispatch(); |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 191 | else if (irq >= 0) |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 192 | do_IRQ(MIPS_CPU_IRQ_BASE + irq); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 193 | else |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 194 | spurious_interrupt(); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 197 | static inline void init_atlas_irqs (int base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | int i; |
| 200 | |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 201 | atlas_hw0_icregs = (struct atlas_ictrl_regs *) |
| 202 | ioremap(ATLAS_ICTRL_REGS_BASE, |
| 203 | sizeof(struct atlas_ictrl_regs *)); |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /* |
| 206 | * Mask out all interrupt by writing "1" to all bit position in |
| 207 | * the interrupt reset reg. |
| 208 | */ |
| 209 | atlas_hw0_icregs->intrsten = 0xffffffff; |
| 210 | |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 211 | for (i = ATLAS_INT_BASE; i <= ATLAS_INT_END; i++) |
Atsushi Nemoto | 1417836 | 2006-11-14 01:13:18 +0900 | [diff] [blame] | 212 | set_irq_chip_and_handler(i, &atlas_irq_type, handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 214 | |
| 215 | static struct irqaction atlasirq = { |
| 216 | .handler = no_action, |
| 217 | .name = "Atlas cascade" |
| 218 | }; |
| 219 | |
| 220 | msc_irqmap_t __initdata msc_irqmap[] = { |
| 221 | {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0}, |
| 222 | {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0}, |
| 223 | }; |
Ahmed S. Darwish | 25b8ac3 | 2007-02-05 04:42:11 +0200 | [diff] [blame] | 224 | int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap); |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 225 | |
| 226 | msc_irqmap_t __initdata msc_eicirqmap[] = { |
| 227 | {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0}, |
| 228 | {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0}, |
| 229 | {MSC01E_INT_ATLAS, MSC01_IRQ_LEVEL, 0}, |
| 230 | {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0}, |
| 231 | {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0}, |
| 232 | {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0}, |
| 233 | {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0} |
| 234 | }; |
Ahmed S. Darwish | 25b8ac3 | 2007-02-05 04:42:11 +0200 | [diff] [blame] | 235 | int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap); |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 236 | |
| 237 | void __init arch_init_irq(void) |
| 238 | { |
| 239 | init_atlas_irqs(ATLAS_INT_BASE); |
| 240 | |
| 241 | if (!cpu_has_veic) |
Atsushi Nemoto | 97dcb82 | 2007-01-08 02:14:29 +0900 | [diff] [blame] | 242 | mips_cpu_irq_init(); |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 243 | |
| 244 | switch(mips_revision_corid) { |
| 245 | case MIPS_REVISION_CORID_CORE_MSC: |
| 246 | case MIPS_REVISION_CORID_CORE_FPGA2: |
| 247 | case MIPS_REVISION_CORID_CORE_FPGA3: |
| 248 | case MIPS_REVISION_CORID_CORE_24K: |
| 249 | case MIPS_REVISION_CORID_CORE_EMUL_MSC: |
| 250 | if (cpu_has_veic) |
Ralf Baechle | d3a5091 | 2007-05-25 15:46:38 +0100 | [diff] [blame] | 251 | init_msc_irqs (MSC01E_INT_BASE, MSC01E_INT_BASE, |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 252 | msc_eicirqmap, msc_nr_eicirqs); |
| 253 | else |
Ralf Baechle | d3a5091 | 2007-05-25 15:46:38 +0100 | [diff] [blame] | 254 | init_msc_irqs (MSC01E_INT_BASE, MSC01C_INT_BASE, |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 255 | msc_irqmap, msc_nr_irqs); |
| 256 | } |
| 257 | |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 258 | if (cpu_has_veic) { |
| 259 | set_vi_handler (MSC01E_INT_ATLAS, atlas_hw0_irqdispatch); |
| 260 | setup_irq (MSC01E_INT_BASE + MSC01E_INT_ATLAS, &atlasirq); |
| 261 | } else if (cpu_has_vint) { |
| 262 | set_vi_handler (MIPSCPU_INT_ATLAS, atlas_hw0_irqdispatch); |
| 263 | #ifdef CONFIG_MIPS_MT_SMTC |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 264 | setup_irq_smtc (MIPS_CPU_IRQ_BASE + MIPSCPU_INT_ATLAS, |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 265 | &atlasirq, (0x100 << MIPSCPU_INT_ATLAS)); |
| 266 | #else /* Not SMTC */ |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 267 | setup_irq(MIPS_CPU_IRQ_BASE + MIPSCPU_INT_ATLAS, &atlasirq); |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 268 | #endif /* CONFIG_MIPS_MT_SMTC */ |
| 269 | } else |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 270 | setup_irq(MIPS_CPU_IRQ_BASE + MIPSCPU_INT_ATLAS, &atlasirq); |
Maciej W. Rozycki | fc095a9 | 2006-09-12 19:12:18 +0100 | [diff] [blame] | 271 | } |