blob: b80b8bf0bf00c1b12862eac58a811ee099462417 [file] [log] [blame]
Adrian Bunk88278ca2008-05-19 16:53:02 -07001/*
Sam Ravnborgfd49bf42011-01-28 22:08:24 +00002 * Interrupt request handling routines. On the
3 * Sparc the IRQs are basically 'cast in stone'
4 * and you are supposed to probe the prom's device
5 * node trees to find out who's got which IRQ.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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 Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/seq_file.h>
16
Sam Ravnborga2a211c2011-02-25 22:59:20 -080017#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/pcic.h>
Konrad Eisele0fd7ef12009-08-17 00:13:31 +000019#include <asm/leon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Sam Ravnborg81265fd2008-12-08 01:08:24 -080021#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070022#include "irq.h"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#ifdef CONFIG_SMP
25#define SMP_NOP2 "nop; nop;\n\t"
26#define SMP_NOP3 "nop; nop; nop;\n\t"
27#else
28#define SMP_NOP2
29#define SMP_NOP3
30#endif /* SMP */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +000031
Sam Ravnborgbbdc2662011-02-25 23:00:19 -080032/* platform specific irq setup */
33struct sparc_irq_config sparc_irq_config;
34
David Howellsdf9ee292010-10-07 14:08:55 +010035unsigned long arch_local_irq_save(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
37 unsigned long retval;
38 unsigned long tmp;
39
40 __asm__ __volatile__(
41 "rd %%psr, %0\n\t"
42 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
43 "or %0, %2, %1\n\t"
44 "wr %1, 0, %%psr\n\t"
45 "nop; nop; nop\n"
46 : "=&r" (retval), "=r" (tmp)
47 : "i" (PSR_PIL)
48 : "memory");
49
50 return retval;
51}
David Howellsdf9ee292010-10-07 14:08:55 +010052EXPORT_SYMBOL(arch_local_irq_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
David Howellsdf9ee292010-10-07 14:08:55 +010054void arch_local_irq_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 unsigned long tmp;
57
58 __asm__ __volatile__(
59 "rd %%psr, %0\n\t"
60 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
61 "andn %0, %1, %0\n\t"
62 "wr %0, 0, %%psr\n\t"
63 "nop; nop; nop\n"
64 : "=&r" (tmp)
65 : "i" (PSR_PIL)
66 : "memory");
67}
David Howellsdf9ee292010-10-07 14:08:55 +010068EXPORT_SYMBOL(arch_local_irq_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Howellsdf9ee292010-10-07 14:08:55 +010070void arch_local_irq_restore(unsigned long old_psr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
72 unsigned long tmp;
73
74 __asm__ __volatile__(
75 "rd %%psr, %0\n\t"
76 "and %2, %1, %2\n\t"
77 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
78 "andn %0, %1, %0\n\t"
79 "wr %0, %2, %%psr\n\t"
80 "nop; nop; nop\n"
81 : "=&r" (tmp)
82 : "i" (PSR_PIL), "r" (old_psr)
83 : "memory");
84}
David Howellsdf9ee292010-10-07 14:08:55 +010085EXPORT_SYMBOL(arch_local_irq_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87/*
88 * Dave Redman (djhr@tadpole.co.uk)
89 *
90 * IRQ numbers.. These are no longer restricted to 15..
91 *
92 * this is done to enable SBUS cards and onboard IO to be masked
93 * correctly. using the interrupt level isn't good enough.
94 *
95 * For example:
96 * A device interrupting at sbus level6 and the Floppy both come in
97 * at IRQ11, but enabling and disabling them requires writing to
98 * different bits in the SLAVIO/SEC.
99 *
100 * As a result of these changes sun4m machines could now support
101 * directed CPU interrupts using the existing enable/disable irq code
102 * with tweaks.
103 *
104 */
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108/*
109 * Dave Redman (djhr@tadpole.co.uk)
110 *
111 * There used to be extern calls and hard coded values here.. very sucky!
112 * instead, because some of the devices attach very early, I do something
113 * equally sucky but at least we'll never try to free statically allocated
114 * space or call kmalloc before kmalloc_init :(.
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000115 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * In fact it's the timer10 that attaches first.. then timer14
117 * then kmalloc_init is called.. then the tty interrupts attach.
118 * hmmm....
119 *
120 */
121#define MAX_STATIC_ALLOC 4
122struct irqaction static_irqaction[MAX_STATIC_ALLOC];
123int static_irq_count;
124
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700125static struct {
Bob Breuera54123e2006-03-23 22:36:19 -0800126 struct irqaction *action;
127 int flags;
128} sparc_irq[NR_IRQS];
129#define SPARC_IRQ_INPROGRESS 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131/* Used to protect the IRQ action lists */
132DEFINE_SPINLOCK(irq_action_lock);
133
134int show_interrupts(struct seq_file *p, void *v)
135{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000136 int i = *(loff_t *)v;
137 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 unsigned long flags;
139#ifdef CONFIG_SMP
140 int j;
141#endif
142
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000143 if (sparc_cpu_model == sun4d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return show_sun4d_interrupts(p, v);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 spin_lock_irqsave(&irq_action_lock, flags);
147 if (i < NR_IRQS) {
Bob Breuera54123e2006-03-23 22:36:19 -0800148 action = sparc_irq[i].action;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000149 if (!action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 goto out_unlock;
151 seq_printf(p, "%3d: ", i);
152#ifndef CONFIG_SMP
153 seq_printf(p, "%10u ", kstat_irqs(i));
154#else
Andrew Morton394e3902006-03-23 03:01:05 -0800155 for_each_online_cpu(j) {
156 seq_printf(p, "%10u ",
Bob Breuera54123e2006-03-23 22:36:19 -0800157 kstat_cpu(j).irqs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159#endif
160 seq_printf(p, " %c %s",
Thomas Gleixner67413202006-07-01 19:29:26 -0700161 (action->flags & IRQF_DISABLED) ? '+' : ' ',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 action->name);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000163 for (action = action->next; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 seq_printf(p, ",%s %s",
Thomas Gleixner67413202006-07-01 19:29:26 -0700165 (action->flags & IRQF_DISABLED) ? " +" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 action->name);
167 }
168 seq_putc(p, '\n');
169 }
170out_unlock:
171 spin_unlock_irqrestore(&irq_action_lock, flags);
172 return 0;
173}
174
175void free_irq(unsigned int irq, void *dev_id)
176{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000177 struct irqaction *action;
Bob Breuera54123e2006-03-23 22:36:19 -0800178 struct irqaction **actionp;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000179 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 unsigned int cpu_irq;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 if (sparc_cpu_model == sun4d) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 sun4d_free_irq(irq, dev_id);
184 return;
185 }
186 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000187 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
188 printk(KERN_ERR "Trying to free bogus IRQ %d\n", irq);
189 return;
190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 spin_lock_irqsave(&irq_action_lock, flags);
193
Bob Breuera54123e2006-03-23 22:36:19 -0800194 actionp = &sparc_irq[cpu_irq].action;
195 action = *actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 if (!action->handler) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000198 printk(KERN_ERR "Trying to free free IRQ%d\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 goto out_unlock;
200 }
201 if (dev_id) {
202 for (; action; action = action->next) {
203 if (action->dev_id == dev_id)
204 break;
Bob Breuera54123e2006-03-23 22:36:19 -0800205 actionp = &action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207 if (!action) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000208 printk(KERN_ERR "Trying to free free shared IRQ%d\n",
209 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 goto out_unlock;
211 }
Thomas Gleixner67413202006-07-01 19:29:26 -0700212 } else if (action->flags & IRQF_SHARED) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000213 printk(KERN_ERR "Trying to free shared IRQ%d with NULL device ID\n",
214 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 goto out_unlock;
216 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000217 if (action->flags & SA_STATIC_ALLOC) {
218 /*
219 * This interrupt is marked as specially allocated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 * so it is a bad idea to free it.
221 */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000222 printk(KERN_ERR "Attempt to free statically allocated IRQ%d (%s)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 irq, action->name);
224 goto out_unlock;
225 }
Bob Breuera54123e2006-03-23 22:36:19 -0800226
227 *actionp = action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 spin_unlock_irqrestore(&irq_action_lock, flags);
230
231 synchronize_irq(irq);
232
233 spin_lock_irqsave(&irq_action_lock, flags);
234
235 kfree(action);
236
Bob Breuera54123e2006-03-23 22:36:19 -0800237 if (!sparc_irq[cpu_irq].action)
Al Viro0f516812007-07-21 19:19:38 -0700238 __disable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240out_unlock:
241 spin_unlock_irqrestore(&irq_action_lock, flags);
242}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243EXPORT_SYMBOL(free_irq);
244
245/*
246 * This is called when we want to synchronize with
247 * interrupts. We may for example tell a device to
248 * stop sending interrupts: but to make sure there
249 * are no interrupts that are executing on another
250 * CPU we need to call this function.
251 */
252#ifdef CONFIG_SMP
253void synchronize_irq(unsigned int irq)
254{
Bob Breuera54123e2006-03-23 22:36:19 -0800255 unsigned int cpu_irq;
256
257 cpu_irq = irq & (NR_IRQS - 1);
258 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
259 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800261EXPORT_SYMBOL(synchronize_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#endif /* SMP */
263
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000264void unexpected_irq(int irq, void *dev_id, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000266 int i;
267 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 unsigned int cpu_irq;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 cpu_irq = irq & (NR_IRQS - 1);
Bob Breuera54123e2006-03-23 22:36:19 -0800271 action = sparc_irq[cpu_irq].action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000273 printk(KERN_ERR "IO device interrupt, irq = %d\n", irq);
274 printk(KERN_ERR "PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 regs->npc, regs->u_regs[14]);
276 if (action) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000277 printk(KERN_ERR "Expecting: ");
278 for (i = 0; i < 16; i++)
279 if (action->handler)
280 printk(KERN_CONT "[%s:%d:0x%x] ", action->name,
281 i, (unsigned int)action->handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000283 printk(KERN_ERR "AIEEE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 panic("bogus interrupt received");
285}
286
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000287void handler_irq(int pil, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Al Viro0d844382006-10-08 14:30:44 +0100289 struct pt_regs *old_regs;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000290 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Al Viro0d844382006-10-08 14:30:44 +0100293 old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 irq_enter();
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000295 disable_pil_irq(pil);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#ifdef CONFIG_SMP
Simon Arlottd1a78c32007-05-11 13:51:23 -0700297 /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000298 if ((sparc_cpu_model==sun4m) && (pil < 10))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 smp4m_irq_rotate(cpu);
300#endif
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000301 action = sparc_irq[pil].action;
302 sparc_irq[pil].flags |= SPARC_IRQ_INPROGRESS;
303 kstat_cpu(cpu).irqs[pil]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 do {
305 if (!action || !action->handler)
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000306 unexpected_irq(pil, NULL, regs);
307 action->handler(pil, action->dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 action = action->next;
309 } while (action);
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000310 sparc_irq[pil].flags &= ~SPARC_IRQ_INPROGRESS;
311 enable_pil_irq(pil);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 irq_exit();
Al Viro0d844382006-10-08 14:30:44 +0100313 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
David S. Miller0a808a32007-08-02 00:19:14 -0700316#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000318/*
319 * Fast IRQs on the Sparc can only have one routine attached to them,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 * thus no sharing possible.
321 */
David S. Miller0a808a32007-08-02 00:19:14 -0700322static int request_fast_irq(unsigned int irq,
323 void (*handler)(void),
324 unsigned long irqflags, const char *devname)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
326 struct irqaction *action;
327 unsigned long flags;
328 unsigned int cpu_irq;
329 int ret;
Namhyung Kim51672322010-10-25 05:52:38 +0000330#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 struct tt_entry *trap_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000334 if (cpu_irq > 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 ret = -EINVAL;
336 goto out;
337 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000338 if (!handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 ret = -EINVAL;
340 goto out;
341 }
342
343 spin_lock_irqsave(&irq_action_lock, flags);
344
Bob Breuera54123e2006-03-23 22:36:19 -0800345 action = sparc_irq[cpu_irq].action;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000346 if (action) {
347 if (action->flags & IRQF_SHARED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 panic("Trying to register fast irq when already shared.\n");
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000349 if (irqflags & IRQF_SHARED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 panic("Trying to register fast irq as shared.\n");
351
352 /* Anyway, someone already owns it so cannot be made fast. */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000353 printk(KERN_ERR "request_fast_irq: Trying to register yet already owned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 ret = -EBUSY;
355 goto out_unlock;
356 }
357
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000358 /*
359 * If this is flagged as statically allocated then we use our
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 * private struct which is never freed.
361 */
362 if (irqflags & SA_STATIC_ALLOC) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000363 if (static_irq_count < MAX_STATIC_ALLOC)
364 action = &static_irqaction[static_irq_count++];
365 else
366 printk(KERN_ERR "Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
367 irq, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 if (action == NULL)
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000371 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
372 if (!action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 ret = -ENOMEM;
374 goto out_unlock;
375 }
376
377 /* Dork with trap table if we get this far. */
378#define INSTANTIATE(table) \
379 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
380 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
381 SPARC_BRANCH((unsigned long) handler, \
382 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
383 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
384 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
385
386 INSTANTIATE(sparc_ttable)
Namhyung Kim51672322010-10-25 05:52:38 +0000387#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000388 trap_table = &trapbase_cpu1;
389 INSTANTIATE(trap_table)
390 trap_table = &trapbase_cpu2;
391 INSTANTIATE(trap_table)
392 trap_table = &trapbase_cpu3;
393 INSTANTIATE(trap_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#endif
395#undef INSTANTIATE
396 /*
397 * XXX Correct thing whould be to flush only I- and D-cache lines
398 * which contain the handler in question. But as of time of the
399 * writing we have no CPU-neutral interface to fine-grained flushes.
400 */
401 flush_cache_all();
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 action->flags = irqflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 action->name = devname;
405 action->dev_id = NULL;
406 action->next = NULL;
407
Bob Breuera54123e2006-03-23 22:36:19 -0800408 sparc_irq[cpu_irq].action = action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Al Viro0f516812007-07-21 19:19:38 -0700410 __enable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 ret = 0;
413out_unlock:
414 spin_unlock_irqrestore(&irq_action_lock, flags);
415out:
416 return ret;
417}
418
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000419/*
420 * These variables are used to access state from the assembler
David S. Miller0a808a32007-08-02 00:19:14 -0700421 * interrupt handler, floppy_hardint, so we cannot put these in
422 * the floppy driver image because that would not work in the
423 * modular case.
424 */
425volatile unsigned char *fdc_status;
426EXPORT_SYMBOL(fdc_status);
427
428char *pdma_vaddr;
429EXPORT_SYMBOL(pdma_vaddr);
430
431unsigned long pdma_size;
432EXPORT_SYMBOL(pdma_size);
433
434volatile int doing_pdma;
435EXPORT_SYMBOL(doing_pdma);
436
437char *pdma_base;
438EXPORT_SYMBOL(pdma_base);
439
440unsigned long pdma_areasize;
441EXPORT_SYMBOL(pdma_areasize);
442
Jeff Garzik7c239972007-10-19 03:12:20 -0400443static irq_handler_t floppy_irq_handler;
David S. Miller0a808a32007-08-02 00:19:14 -0700444
445void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
446{
447 struct pt_regs *old_regs;
448 int cpu = smp_processor_id();
449
450 old_regs = set_irq_regs(regs);
451 disable_pil_irq(irq);
452 irq_enter();
453 kstat_cpu(cpu).irqs[irq]++;
454 floppy_irq_handler(irq, dev_id);
455 irq_exit();
456 enable_pil_irq(irq);
457 set_irq_regs(old_regs);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000458 /*
459 * XXX Eek, it's totally changed with preempt_count() and such
460 * if (softirq_pending(cpu))
461 * do_softirq();
462 */
David S. Miller0a808a32007-08-02 00:19:14 -0700463}
464
465int sparc_floppy_request_irq(int irq, unsigned long flags,
Jeff Garzik7c239972007-10-19 03:12:20 -0400466 irq_handler_t irq_handler)
David S. Miller0a808a32007-08-02 00:19:14 -0700467{
468 floppy_irq_handler = irq_handler;
469 return request_fast_irq(irq, floppy_hardint, flags, "floppy");
470}
471EXPORT_SYMBOL(sparc_floppy_request_irq);
472
473#endif
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475int request_irq(unsigned int irq,
David Howells40220c12006-10-09 12:19:47 +0100476 irq_handler_t handler,
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000477 unsigned long irqflags, const char *devname, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000479 struct irqaction *action, **actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 unsigned long flags;
481 unsigned int cpu_irq;
482 int ret;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000483
484 if (sparc_cpu_model == sun4d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000488 if (cpu_irq > 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 ret = -EINVAL;
490 goto out;
491 }
492 if (!handler) {
493 ret = -EINVAL;
494 goto out;
495 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 spin_lock_irqsave(&irq_action_lock, flags);
498
Bob Breuera54123e2006-03-23 22:36:19 -0800499 actionp = &sparc_irq[cpu_irq].action;
500 action = *actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 if (action) {
Thomas Gleixner67413202006-07-01 19:29:26 -0700502 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 ret = -EBUSY;
504 goto out_unlock;
505 }
Thomas Gleixner67413202006-07-01 19:29:26 -0700506 if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000507 printk(KERN_ERR "Attempt to mix fast and slow interrupts on IRQ%d denied\n",
508 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 ret = -EBUSY;
510 goto out_unlock;
Bob Breuera54123e2006-03-23 22:36:19 -0800511 }
512 for ( ; action; action = *actionp)
513 actionp = &action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
515
516 /* If this is flagged as statically allocated then we use our
517 * private struct which is never freed.
518 */
519 if (irqflags & SA_STATIC_ALLOC) {
520 if (static_irq_count < MAX_STATIC_ALLOC)
521 action = &static_irqaction[static_irq_count++];
522 else
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000523 printk(KERN_ERR "Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
524 irq, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (action == NULL)
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000527 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
528 if (!action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 ret = -ENOMEM;
530 goto out_unlock;
531 }
532
533 action->handler = handler;
534 action->flags = irqflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 action->name = devname;
536 action->next = NULL;
537 action->dev_id = dev_id;
538
Bob Breuera54123e2006-03-23 22:36:19 -0800539 *actionp = action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Al Viro0f516812007-07-21 19:19:38 -0700541 __enable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 ret = 0;
544out_unlock:
545 spin_unlock_irqrestore(&irq_action_lock, flags);
546out:
547 return ret;
548}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549EXPORT_SYMBOL(request_irq);
550
Al Viro0f516812007-07-21 19:19:38 -0700551void disable_irq_nosync(unsigned int irq)
552{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800553 __disable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700554}
555EXPORT_SYMBOL(disable_irq_nosync);
556
557void disable_irq(unsigned int irq)
558{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800559 __disable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700560}
561EXPORT_SYMBOL(disable_irq);
562
563void enable_irq(unsigned int irq)
564{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800565 __enable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700566}
Al Viro0f516812007-07-21 19:19:38 -0700567EXPORT_SYMBOL(enable_irq);
568
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000569/*
570 * We really don't need these at all on the Sparc. We only have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * stubs here because they are exported to modules.
572 */
573unsigned long probe_irq_on(void)
574{
575 return 0;
576}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577EXPORT_SYMBOL(probe_irq_on);
578
579int probe_irq_off(unsigned long mask)
580{
581 return 0;
582}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583EXPORT_SYMBOL(probe_irq_off);
584
585/* djhr
586 * This could probably be made indirect too and assigned in the CPU
587 * bits of the code. That would be much nicer I think and would also
588 * fit in with the idea of being able to tune your kernel for your machine
589 * by removing unrequired machine and device support.
590 *
591 */
592
593void __init init_IRQ(void)
594{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000595 switch (sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 case sun4c:
597 case sun4:
598 sun4c_init_IRQ();
599 break;
600
601 case sun4m:
602#ifdef CONFIG_PCI
603 pcic_probe();
604 if (pcic_present()) {
605 sun4m_pci_init_IRQ();
606 break;
607 }
608#endif
609 sun4m_init_IRQ();
610 break;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 case sun4d:
613 sun4d_init_IRQ();
614 break;
615
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000616 case sparc_leon:
617 leon_init_IRQ();
618 break;
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 default:
Simon Arlottd1a78c32007-05-11 13:51:23 -0700621 prom_printf("Cannot initialize IRQs on this Sun machine...");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 break;
623 }
624 btfixup();
625}
626
Julian Calaby4696b642009-01-05 18:13:49 -0800627#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628void init_irq_proc(void)
629{
630 /* For now, nothing... */
631}
Julian Calaby4696b642009-01-05 18:13:49 -0800632#endif /* CONFIG_PROC_FS */