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