Adrian Bunk | 88278ca | 2008-05-19 16:53:02 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * arch/sparc/kernel/irq.c: Interrupt request handling routines. On the |
Simon Arlott | d1a78c3 | 2007-05-11 13:51:23 -0700 | [diff] [blame] | 3 | * Sparc the IRQs are basically 'cast in stone' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * and you are supposed to probe the prom's device |
| 5 | * node trees to find out who's got which IRQ. |
| 6 | * |
| 7 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
| 8 | * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx) |
| 9 | * Copyright (C) 1995,2002 Pete A. Zaitcev (zaitcev@yahoo.com) |
| 10 | * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk) |
| 11 | * Copyright (C) 1998-2000 Anton Blanchard (anton@samba.org) |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/ptrace.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/linkage.h> |
| 19 | #include <linux/kernel_stat.h> |
| 20 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/random.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include <linux/threads.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/seq_file.h> |
| 30 | |
| 31 | #include <asm/ptrace.h> |
| 32 | #include <asm/processor.h> |
| 33 | #include <asm/system.h> |
| 34 | #include <asm/psr.h> |
| 35 | #include <asm/smp.h> |
| 36 | #include <asm/vaddrs.h> |
| 37 | #include <asm/timer.h> |
| 38 | #include <asm/openprom.h> |
| 39 | #include <asm/oplib.h> |
| 40 | #include <asm/traps.h> |
| 41 | #include <asm/irq.h> |
| 42 | #include <asm/io.h> |
| 43 | #include <asm/pgalloc.h> |
| 44 | #include <asm/pgtable.h> |
| 45 | #include <asm/pcic.h> |
| 46 | #include <asm/cacheflush.h> |
Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 47 | #include <asm/irq_regs.h> |
Konrad Eisele | 0fd7ef1 | 2009-08-17 00:13:31 +0000 | [diff] [blame] | 48 | #include <asm/leon.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Sam Ravnborg | 81265fd | 2008-12-08 01:08:24 -0800 | [diff] [blame] | 50 | #include "kernel.h" |
Al Viro | 32231a6 | 2007-07-21 19:18:57 -0700 | [diff] [blame] | 51 | #include "irq.h" |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #ifdef CONFIG_SMP |
| 54 | #define SMP_NOP2 "nop; nop;\n\t" |
| 55 | #define SMP_NOP3 "nop; nop; nop;\n\t" |
| 56 | #else |
| 57 | #define SMP_NOP2 |
| 58 | #define SMP_NOP3 |
| 59 | #endif /* SMP */ |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame^] | 60 | unsigned long arch_local_irq_save(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
| 62 | unsigned long retval; |
| 63 | unsigned long tmp; |
| 64 | |
| 65 | __asm__ __volatile__( |
| 66 | "rd %%psr, %0\n\t" |
| 67 | SMP_NOP3 /* Sun4m + Cypress + SMP bug */ |
| 68 | "or %0, %2, %1\n\t" |
| 69 | "wr %1, 0, %%psr\n\t" |
| 70 | "nop; nop; nop\n" |
| 71 | : "=&r" (retval), "=r" (tmp) |
| 72 | : "i" (PSR_PIL) |
| 73 | : "memory"); |
| 74 | |
| 75 | return retval; |
| 76 | } |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame^] | 77 | EXPORT_SYMBOL(arch_local_irq_save); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame^] | 79 | void arch_local_irq_enable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | unsigned long tmp; |
| 82 | |
| 83 | __asm__ __volatile__( |
| 84 | "rd %%psr, %0\n\t" |
| 85 | SMP_NOP3 /* Sun4m + Cypress + SMP bug */ |
| 86 | "andn %0, %1, %0\n\t" |
| 87 | "wr %0, 0, %%psr\n\t" |
| 88 | "nop; nop; nop\n" |
| 89 | : "=&r" (tmp) |
| 90 | : "i" (PSR_PIL) |
| 91 | : "memory"); |
| 92 | } |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame^] | 93 | EXPORT_SYMBOL(arch_local_irq_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame^] | 95 | void arch_local_irq_restore(unsigned long old_psr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | unsigned long tmp; |
| 98 | |
| 99 | __asm__ __volatile__( |
| 100 | "rd %%psr, %0\n\t" |
| 101 | "and %2, %1, %2\n\t" |
| 102 | SMP_NOP2 /* Sun4m + Cypress + SMP bug */ |
| 103 | "andn %0, %1, %0\n\t" |
| 104 | "wr %0, %2, %%psr\n\t" |
| 105 | "nop; nop; nop\n" |
| 106 | : "=&r" (tmp) |
| 107 | : "i" (PSR_PIL), "r" (old_psr) |
| 108 | : "memory"); |
| 109 | } |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame^] | 110 | EXPORT_SYMBOL(arch_local_irq_restore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | /* |
| 113 | * Dave Redman (djhr@tadpole.co.uk) |
| 114 | * |
| 115 | * IRQ numbers.. These are no longer restricted to 15.. |
| 116 | * |
| 117 | * this is done to enable SBUS cards and onboard IO to be masked |
| 118 | * correctly. using the interrupt level isn't good enough. |
| 119 | * |
| 120 | * For example: |
| 121 | * A device interrupting at sbus level6 and the Floppy both come in |
| 122 | * at IRQ11, but enabling and disabling them requires writing to |
| 123 | * different bits in the SLAVIO/SEC. |
| 124 | * |
| 125 | * As a result of these changes sun4m machines could now support |
| 126 | * directed CPU interrupts using the existing enable/disable irq code |
| 127 | * with tweaks. |
| 128 | * |
| 129 | */ |
| 130 | |
| 131 | static void irq_panic(void) |
| 132 | { |
| 133 | extern char *cputypval; |
| 134 | prom_printf("machine: %s doesn't have irq handlers defined!\n",cputypval); |
| 135 | prom_halt(); |
| 136 | } |
| 137 | |
David Howells | 40220c1 | 2006-10-09 12:19:47 +0100 | [diff] [blame] | 138 | void (*sparc_init_timers)(irq_handler_t ) = |
| 139 | (void (*)(irq_handler_t )) irq_panic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * Dave Redman (djhr@tadpole.co.uk) |
| 143 | * |
| 144 | * There used to be extern calls and hard coded values here.. very sucky! |
| 145 | * instead, because some of the devices attach very early, I do something |
| 146 | * equally sucky but at least we'll never try to free statically allocated |
| 147 | * space or call kmalloc before kmalloc_init :(. |
| 148 | * |
| 149 | * In fact it's the timer10 that attaches first.. then timer14 |
| 150 | * then kmalloc_init is called.. then the tty interrupts attach. |
| 151 | * hmmm.... |
| 152 | * |
| 153 | */ |
| 154 | #define MAX_STATIC_ALLOC 4 |
| 155 | struct irqaction static_irqaction[MAX_STATIC_ALLOC]; |
| 156 | int static_irq_count; |
| 157 | |
Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 158 | static struct { |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 159 | struct irqaction *action; |
| 160 | int flags; |
| 161 | } sparc_irq[NR_IRQS]; |
| 162 | #define SPARC_IRQ_INPROGRESS 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | /* Used to protect the IRQ action lists */ |
| 165 | DEFINE_SPINLOCK(irq_action_lock); |
| 166 | |
| 167 | int show_interrupts(struct seq_file *p, void *v) |
| 168 | { |
| 169 | int i = *(loff_t *) v; |
| 170 | struct irqaction * action; |
| 171 | unsigned long flags; |
| 172 | #ifdef CONFIG_SMP |
| 173 | int j; |
| 174 | #endif |
| 175 | |
| 176 | if (sparc_cpu_model == sun4d) { |
| 177 | extern int show_sun4d_interrupts(struct seq_file *, void *); |
| 178 | |
| 179 | return show_sun4d_interrupts(p, v); |
| 180 | } |
| 181 | spin_lock_irqsave(&irq_action_lock, flags); |
| 182 | if (i < NR_IRQS) { |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 183 | action = sparc_irq[i].action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if (!action) |
| 185 | goto out_unlock; |
| 186 | seq_printf(p, "%3d: ", i); |
| 187 | #ifndef CONFIG_SMP |
| 188 | seq_printf(p, "%10u ", kstat_irqs(i)); |
| 189 | #else |
Andrew Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 190 | for_each_online_cpu(j) { |
| 191 | seq_printf(p, "%10u ", |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 192 | kstat_cpu(j).irqs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | #endif |
| 195 | seq_printf(p, " %c %s", |
Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 196 | (action->flags & IRQF_DISABLED) ? '+' : ' ', |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | action->name); |
| 198 | for (action=action->next; action; action = action->next) { |
| 199 | seq_printf(p, ",%s %s", |
Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 200 | (action->flags & IRQF_DISABLED) ? " +" : "", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | action->name); |
| 202 | } |
| 203 | seq_putc(p, '\n'); |
| 204 | } |
| 205 | out_unlock: |
| 206 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | void free_irq(unsigned int irq, void *dev_id) |
| 211 | { |
| 212 | struct irqaction * action; |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 213 | struct irqaction **actionp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | unsigned long flags; |
| 215 | unsigned int cpu_irq; |
| 216 | |
| 217 | if (sparc_cpu_model == sun4d) { |
| 218 | extern void sun4d_free_irq(unsigned int, void *); |
| 219 | |
| 220 | sun4d_free_irq(irq, dev_id); |
| 221 | return; |
| 222 | } |
| 223 | cpu_irq = irq & (NR_IRQS - 1); |
| 224 | if (cpu_irq > 14) { /* 14 irq levels on the sparc */ |
| 225 | printk("Trying to free bogus IRQ %d\n", irq); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | spin_lock_irqsave(&irq_action_lock, flags); |
| 230 | |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 231 | actionp = &sparc_irq[cpu_irq].action; |
| 232 | action = *actionp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | if (!action->handler) { |
| 235 | printk("Trying to free free IRQ%d\n",irq); |
| 236 | goto out_unlock; |
| 237 | } |
| 238 | if (dev_id) { |
| 239 | for (; action; action = action->next) { |
| 240 | if (action->dev_id == dev_id) |
| 241 | break; |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 242 | actionp = &action->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | if (!action) { |
| 245 | printk("Trying to free free shared IRQ%d\n",irq); |
| 246 | goto out_unlock; |
| 247 | } |
Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 248 | } else if (action->flags & IRQF_SHARED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | printk("Trying to free shared IRQ%d with NULL device ID\n", irq); |
| 250 | goto out_unlock; |
| 251 | } |
| 252 | if (action->flags & SA_STATIC_ALLOC) |
| 253 | { |
| 254 | /* This interrupt is marked as specially allocated |
| 255 | * so it is a bad idea to free it. |
| 256 | */ |
| 257 | printk("Attempt to free statically allocated IRQ%d (%s)\n", |
| 258 | irq, action->name); |
| 259 | goto out_unlock; |
| 260 | } |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 261 | |
| 262 | *actionp = action->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 265 | |
| 266 | synchronize_irq(irq); |
| 267 | |
| 268 | spin_lock_irqsave(&irq_action_lock, flags); |
| 269 | |
| 270 | kfree(action); |
| 271 | |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 272 | if (!sparc_irq[cpu_irq].action) |
Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 273 | __disable_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | out_unlock: |
| 276 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 277 | } |
| 278 | |
| 279 | EXPORT_SYMBOL(free_irq); |
| 280 | |
| 281 | /* |
| 282 | * This is called when we want to synchronize with |
| 283 | * interrupts. We may for example tell a device to |
| 284 | * stop sending interrupts: but to make sure there |
| 285 | * are no interrupts that are executing on another |
| 286 | * CPU we need to call this function. |
| 287 | */ |
| 288 | #ifdef CONFIG_SMP |
| 289 | void synchronize_irq(unsigned int irq) |
| 290 | { |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 291 | unsigned int cpu_irq; |
| 292 | |
| 293 | cpu_irq = irq & (NR_IRQS - 1); |
| 294 | while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS) |
| 295 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
Sam Ravnborg | 6943f3d | 2009-01-08 16:58:05 -0800 | [diff] [blame] | 297 | EXPORT_SYMBOL(synchronize_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | #endif /* SMP */ |
| 299 | |
| 300 | void unexpected_irq(int irq, void *dev_id, struct pt_regs * regs) |
| 301 | { |
| 302 | int i; |
| 303 | struct irqaction * action; |
| 304 | unsigned int cpu_irq; |
| 305 | |
| 306 | cpu_irq = irq & (NR_IRQS - 1); |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 307 | action = sparc_irq[cpu_irq].action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | printk("IO device interrupt, irq = %d\n", irq); |
| 310 | printk("PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc, |
| 311 | regs->npc, regs->u_regs[14]); |
| 312 | if (action) { |
| 313 | printk("Expecting: "); |
| 314 | for (i = 0; i < 16; i++) |
| 315 | if (action->handler) |
| 316 | printk("[%s:%d:0x%x] ", action->name, |
| 317 | (int) i, (unsigned int) action->handler); |
| 318 | } |
| 319 | printk("AIEEE\n"); |
| 320 | panic("bogus interrupt received"); |
| 321 | } |
| 322 | |
| 323 | void handler_irq(int irq, struct pt_regs * regs) |
| 324 | { |
Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 325 | struct pt_regs *old_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | struct irqaction * action; |
| 327 | int cpu = smp_processor_id(); |
| 328 | #ifdef CONFIG_SMP |
| 329 | extern void smp4m_irq_rotate(int cpu); |
| 330 | #endif |
| 331 | |
Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 332 | old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | irq_enter(); |
| 334 | disable_pil_irq(irq); |
| 335 | #ifdef CONFIG_SMP |
Simon Arlott | d1a78c3 | 2007-05-11 13:51:23 -0700 | [diff] [blame] | 336 | /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */ |
Raymond Burns | 198c167 | 2006-07-17 21:50:55 -0700 | [diff] [blame] | 337 | if((sparc_cpu_model==sun4m) && (irq < 10)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | smp4m_irq_rotate(cpu); |
| 339 | #endif |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 340 | action = sparc_irq[irq].action; |
| 341 | sparc_irq[irq].flags |= SPARC_IRQ_INPROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | kstat_cpu(cpu).irqs[irq]++; |
| 343 | do { |
| 344 | if (!action || !action->handler) |
| 345 | unexpected_irq(irq, NULL, regs); |
Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 346 | action->handler(irq, action->dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | action = action->next; |
| 348 | } while (action); |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 349 | sparc_irq[irq].flags &= ~SPARC_IRQ_INPROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | enable_pil_irq(irq); |
| 351 | irq_exit(); |
Al Viro | 0d84438 | 2006-10-08 14:30:44 +0100 | [diff] [blame] | 352 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
David S. Miller | 0a808a3 | 2007-08-02 00:19:14 -0700 | [diff] [blame] | 355 | #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Simon Arlott | d1a78c3 | 2007-05-11 13:51:23 -0700 | [diff] [blame] | 357 | /* Fast IRQs on the Sparc can only have one routine attached to them, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | * thus no sharing possible. |
| 359 | */ |
David S. Miller | 0a808a3 | 2007-08-02 00:19:14 -0700 | [diff] [blame] | 360 | static int request_fast_irq(unsigned int irq, |
| 361 | void (*handler)(void), |
| 362 | unsigned long irqflags, const char *devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
| 364 | struct irqaction *action; |
| 365 | unsigned long flags; |
| 366 | unsigned int cpu_irq; |
| 367 | int ret; |
| 368 | #ifdef CONFIG_SMP |
| 369 | struct tt_entry *trap_table; |
| 370 | extern struct tt_entry trapbase_cpu1, trapbase_cpu2, trapbase_cpu3; |
| 371 | #endif |
| 372 | |
| 373 | cpu_irq = irq & (NR_IRQS - 1); |
| 374 | if(cpu_irq > 14) { |
| 375 | ret = -EINVAL; |
| 376 | goto out; |
| 377 | } |
| 378 | if(!handler) { |
| 379 | ret = -EINVAL; |
| 380 | goto out; |
| 381 | } |
| 382 | |
| 383 | spin_lock_irqsave(&irq_action_lock, flags); |
| 384 | |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 385 | action = sparc_irq[cpu_irq].action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | if(action) { |
Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 387 | if(action->flags & IRQF_SHARED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | panic("Trying to register fast irq when already shared.\n"); |
Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 389 | if(irqflags & IRQF_SHARED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | panic("Trying to register fast irq as shared.\n"); |
| 391 | |
| 392 | /* Anyway, someone already owns it so cannot be made fast. */ |
| 393 | printk("request_fast_irq: Trying to register yet already owned.\n"); |
| 394 | ret = -EBUSY; |
| 395 | goto out_unlock; |
| 396 | } |
| 397 | |
| 398 | /* If this is flagged as statically allocated then we use our |
| 399 | * private struct which is never freed. |
| 400 | */ |
| 401 | if (irqflags & SA_STATIC_ALLOC) { |
| 402 | if (static_irq_count < MAX_STATIC_ALLOC) |
| 403 | action = &static_irqaction[static_irq_count++]; |
| 404 | else |
| 405 | printk("Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", |
| 406 | irq, devname); |
| 407 | } |
| 408 | |
| 409 | if (action == NULL) |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 410 | action = kmalloc(sizeof(struct irqaction), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | GFP_ATOMIC); |
| 412 | |
| 413 | if (!action) { |
| 414 | ret = -ENOMEM; |
| 415 | goto out_unlock; |
| 416 | } |
| 417 | |
| 418 | /* Dork with trap table if we get this far. */ |
| 419 | #define INSTANTIATE(table) \ |
| 420 | table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \ |
| 421 | table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \ |
| 422 | SPARC_BRANCH((unsigned long) handler, \ |
| 423 | (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\ |
| 424 | table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \ |
| 425 | table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP; |
| 426 | |
| 427 | INSTANTIATE(sparc_ttable) |
| 428 | #ifdef CONFIG_SMP |
| 429 | trap_table = &trapbase_cpu1; INSTANTIATE(trap_table) |
| 430 | trap_table = &trapbase_cpu2; INSTANTIATE(trap_table) |
| 431 | trap_table = &trapbase_cpu3; INSTANTIATE(trap_table) |
| 432 | #endif |
| 433 | #undef INSTANTIATE |
| 434 | /* |
| 435 | * XXX Correct thing whould be to flush only I- and D-cache lines |
| 436 | * which contain the handler in question. But as of time of the |
| 437 | * writing we have no CPU-neutral interface to fine-grained flushes. |
| 438 | */ |
| 439 | flush_cache_all(); |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | action->flags = irqflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | action->name = devname; |
| 443 | action->dev_id = NULL; |
| 444 | action->next = NULL; |
| 445 | |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 446 | sparc_irq[cpu_irq].action = action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 448 | __enable_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | ret = 0; |
| 451 | out_unlock: |
| 452 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 453 | out: |
| 454 | return ret; |
| 455 | } |
| 456 | |
David S. Miller | 0a808a3 | 2007-08-02 00:19:14 -0700 | [diff] [blame] | 457 | /* These variables are used to access state from the assembler |
| 458 | * interrupt handler, floppy_hardint, so we cannot put these in |
| 459 | * the floppy driver image because that would not work in the |
| 460 | * modular case. |
| 461 | */ |
| 462 | volatile unsigned char *fdc_status; |
| 463 | EXPORT_SYMBOL(fdc_status); |
| 464 | |
| 465 | char *pdma_vaddr; |
| 466 | EXPORT_SYMBOL(pdma_vaddr); |
| 467 | |
| 468 | unsigned long pdma_size; |
| 469 | EXPORT_SYMBOL(pdma_size); |
| 470 | |
| 471 | volatile int doing_pdma; |
| 472 | EXPORT_SYMBOL(doing_pdma); |
| 473 | |
| 474 | char *pdma_base; |
| 475 | EXPORT_SYMBOL(pdma_base); |
| 476 | |
| 477 | unsigned long pdma_areasize; |
| 478 | EXPORT_SYMBOL(pdma_areasize); |
| 479 | |
| 480 | extern void floppy_hardint(void); |
| 481 | |
Jeff Garzik | 7c23997 | 2007-10-19 03:12:20 -0400 | [diff] [blame] | 482 | static irq_handler_t floppy_irq_handler; |
David S. Miller | 0a808a3 | 2007-08-02 00:19:14 -0700 | [diff] [blame] | 483 | |
| 484 | void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs) |
| 485 | { |
| 486 | struct pt_regs *old_regs; |
| 487 | int cpu = smp_processor_id(); |
| 488 | |
| 489 | old_regs = set_irq_regs(regs); |
| 490 | disable_pil_irq(irq); |
| 491 | irq_enter(); |
| 492 | kstat_cpu(cpu).irqs[irq]++; |
| 493 | floppy_irq_handler(irq, dev_id); |
| 494 | irq_exit(); |
| 495 | enable_pil_irq(irq); |
| 496 | set_irq_regs(old_regs); |
| 497 | // XXX Eek, it's totally changed with preempt_count() and such |
| 498 | // if (softirq_pending(cpu)) |
| 499 | // do_softirq(); |
| 500 | } |
| 501 | |
| 502 | int sparc_floppy_request_irq(int irq, unsigned long flags, |
Jeff Garzik | 7c23997 | 2007-10-19 03:12:20 -0400 | [diff] [blame] | 503 | irq_handler_t irq_handler) |
David S. Miller | 0a808a3 | 2007-08-02 00:19:14 -0700 | [diff] [blame] | 504 | { |
| 505 | floppy_irq_handler = irq_handler; |
| 506 | return request_fast_irq(irq, floppy_hardint, flags, "floppy"); |
| 507 | } |
| 508 | EXPORT_SYMBOL(sparc_floppy_request_irq); |
| 509 | |
| 510 | #endif |
| 511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | int request_irq(unsigned int irq, |
David Howells | 40220c1 | 2006-10-09 12:19:47 +0100 | [diff] [blame] | 513 | irq_handler_t handler, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | unsigned long irqflags, const char * devname, void *dev_id) |
| 515 | { |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 516 | struct irqaction * action, **actionp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | unsigned long flags; |
| 518 | unsigned int cpu_irq; |
| 519 | int ret; |
| 520 | |
| 521 | if (sparc_cpu_model == sun4d) { |
| 522 | extern int sun4d_request_irq(unsigned int, |
David Howells | 40220c1 | 2006-10-09 12:19:47 +0100 | [diff] [blame] | 523 | irq_handler_t , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | unsigned long, const char *, void *); |
| 525 | return sun4d_request_irq(irq, handler, irqflags, devname, dev_id); |
| 526 | } |
| 527 | cpu_irq = irq & (NR_IRQS - 1); |
| 528 | if(cpu_irq > 14) { |
| 529 | ret = -EINVAL; |
| 530 | goto out; |
| 531 | } |
| 532 | if (!handler) { |
| 533 | ret = -EINVAL; |
| 534 | goto out; |
| 535 | } |
| 536 | |
| 537 | spin_lock_irqsave(&irq_action_lock, flags); |
| 538 | |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 539 | actionp = &sparc_irq[cpu_irq].action; |
| 540 | action = *actionp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | if (action) { |
Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 542 | if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | ret = -EBUSY; |
| 544 | goto out_unlock; |
| 545 | } |
Thomas Gleixner | 6741320 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 546 | if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq); |
| 548 | ret = -EBUSY; |
| 549 | goto out_unlock; |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 550 | } |
| 551 | for ( ; action; action = *actionp) |
| 552 | actionp = &action->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* If this is flagged as statically allocated then we use our |
| 556 | * private struct which is never freed. |
| 557 | */ |
| 558 | if (irqflags & SA_STATIC_ALLOC) { |
| 559 | if (static_irq_count < MAX_STATIC_ALLOC) |
| 560 | action = &static_irqaction[static_irq_count++]; |
| 561 | else |
| 562 | printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", irq, devname); |
| 563 | } |
| 564 | |
| 565 | if (action == NULL) |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 566 | action = kmalloc(sizeof(struct irqaction), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | GFP_ATOMIC); |
| 568 | |
| 569 | if (!action) { |
| 570 | ret = -ENOMEM; |
| 571 | goto out_unlock; |
| 572 | } |
| 573 | |
| 574 | action->handler = handler; |
| 575 | action->flags = irqflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | action->name = devname; |
| 577 | action->next = NULL; |
| 578 | action->dev_id = dev_id; |
| 579 | |
Bob Breuer | a54123e | 2006-03-23 22:36:19 -0800 | [diff] [blame] | 580 | *actionp = action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 582 | __enable_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | ret = 0; |
| 585 | out_unlock: |
| 586 | spin_unlock_irqrestore(&irq_action_lock, flags); |
| 587 | out: |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | EXPORT_SYMBOL(request_irq); |
| 592 | |
Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 593 | void disable_irq_nosync(unsigned int irq) |
| 594 | { |
Sam Ravnborg | 81265fd | 2008-12-08 01:08:24 -0800 | [diff] [blame] | 595 | __disable_irq(irq); |
Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 596 | } |
| 597 | EXPORT_SYMBOL(disable_irq_nosync); |
| 598 | |
| 599 | void disable_irq(unsigned int irq) |
| 600 | { |
Sam Ravnborg | 81265fd | 2008-12-08 01:08:24 -0800 | [diff] [blame] | 601 | __disable_irq(irq); |
Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 602 | } |
| 603 | EXPORT_SYMBOL(disable_irq); |
| 604 | |
| 605 | void enable_irq(unsigned int irq) |
| 606 | { |
Sam Ravnborg | 81265fd | 2008-12-08 01:08:24 -0800 | [diff] [blame] | 607 | __enable_irq(irq); |
Al Viro | 0f51681 | 2007-07-21 19:19:38 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | EXPORT_SYMBOL(enable_irq); |
| 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | /* We really don't need these at all on the Sparc. We only have |
| 613 | * stubs here because they are exported to modules. |
| 614 | */ |
| 615 | unsigned long probe_irq_on(void) |
| 616 | { |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | EXPORT_SYMBOL(probe_irq_on); |
| 621 | |
| 622 | int probe_irq_off(unsigned long mask) |
| 623 | { |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | EXPORT_SYMBOL(probe_irq_off); |
| 628 | |
| 629 | /* djhr |
| 630 | * This could probably be made indirect too and assigned in the CPU |
| 631 | * bits of the code. That would be much nicer I think and would also |
| 632 | * fit in with the idea of being able to tune your kernel for your machine |
| 633 | * by removing unrequired machine and device support. |
| 634 | * |
| 635 | */ |
| 636 | |
| 637 | void __init init_IRQ(void) |
| 638 | { |
| 639 | extern void sun4c_init_IRQ( void ); |
| 640 | extern void sun4m_init_IRQ( void ); |
| 641 | extern void sun4d_init_IRQ( void ); |
| 642 | |
| 643 | switch(sparc_cpu_model) { |
| 644 | case sun4c: |
| 645 | case sun4: |
| 646 | sun4c_init_IRQ(); |
| 647 | break; |
| 648 | |
| 649 | case sun4m: |
| 650 | #ifdef CONFIG_PCI |
| 651 | pcic_probe(); |
| 652 | if (pcic_present()) { |
| 653 | sun4m_pci_init_IRQ(); |
| 654 | break; |
| 655 | } |
| 656 | #endif |
| 657 | sun4m_init_IRQ(); |
| 658 | break; |
| 659 | |
| 660 | case sun4d: |
| 661 | sun4d_init_IRQ(); |
| 662 | break; |
| 663 | |
Konrad Eisele | 0fd7ef1 | 2009-08-17 00:13:31 +0000 | [diff] [blame] | 664 | case sparc_leon: |
| 665 | leon_init_IRQ(); |
| 666 | break; |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | default: |
Simon Arlott | d1a78c3 | 2007-05-11 13:51:23 -0700 | [diff] [blame] | 669 | prom_printf("Cannot initialize IRQs on this Sun machine..."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | break; |
| 671 | } |
| 672 | btfixup(); |
| 673 | } |
| 674 | |
Julian Calaby | 4696b64 | 2009-01-05 18:13:49 -0800 | [diff] [blame] | 675 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | void init_irq_proc(void) |
| 677 | { |
| 678 | /* For now, nothing... */ |
| 679 | } |
Julian Calaby | 4696b64 | 2009-01-05 18:13:49 -0800 | [diff] [blame] | 680 | #endif /* CONFIG_PROC_FS */ |