blob: 974dab046a040aceb082185d190b0a726f1caa42 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/pcic.h>
Konrad Eisele0fd7ef12009-08-17 00:13:31 +000018#include <asm/leon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Sam Ravnborg81265fd2008-12-08 01:08:24 -080020#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070021#include "irq.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#ifdef CONFIG_SMP
24#define SMP_NOP2 "nop; nop;\n\t"
25#define SMP_NOP3 "nop; nop; nop;\n\t"
26#else
27#define SMP_NOP2
28#define SMP_NOP3
29#endif /* SMP */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +000030
David Howellsdf9ee292010-10-07 14:08:55 +010031unsigned long arch_local_irq_save(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
33 unsigned long retval;
34 unsigned long tmp;
35
36 __asm__ __volatile__(
37 "rd %%psr, %0\n\t"
38 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
39 "or %0, %2, %1\n\t"
40 "wr %1, 0, %%psr\n\t"
41 "nop; nop; nop\n"
42 : "=&r" (retval), "=r" (tmp)
43 : "i" (PSR_PIL)
44 : "memory");
45
46 return retval;
47}
David Howellsdf9ee292010-10-07 14:08:55 +010048EXPORT_SYMBOL(arch_local_irq_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
David Howellsdf9ee292010-10-07 14:08:55 +010050void arch_local_irq_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
52 unsigned long tmp;
53
54 __asm__ __volatile__(
55 "rd %%psr, %0\n\t"
56 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
57 "andn %0, %1, %0\n\t"
58 "wr %0, 0, %%psr\n\t"
59 "nop; nop; nop\n"
60 : "=&r" (tmp)
61 : "i" (PSR_PIL)
62 : "memory");
63}
David Howellsdf9ee292010-10-07 14:08:55 +010064EXPORT_SYMBOL(arch_local_irq_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
David Howellsdf9ee292010-10-07 14:08:55 +010066void arch_local_irq_restore(unsigned long old_psr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 unsigned long tmp;
69
70 __asm__ __volatile__(
71 "rd %%psr, %0\n\t"
72 "and %2, %1, %2\n\t"
73 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
74 "andn %0, %1, %0\n\t"
75 "wr %0, %2, %%psr\n\t"
76 "nop; nop; nop\n"
77 : "=&r" (tmp)
78 : "i" (PSR_PIL), "r" (old_psr)
79 : "memory");
80}
David Howellsdf9ee292010-10-07 14:08:55 +010081EXPORT_SYMBOL(arch_local_irq_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/*
84 * Dave Redman (djhr@tadpole.co.uk)
85 *
86 * IRQ numbers.. These are no longer restricted to 15..
87 *
88 * this is done to enable SBUS cards and onboard IO to be masked
89 * correctly. using the interrupt level isn't good enough.
90 *
91 * For example:
92 * A device interrupting at sbus level6 and the Floppy both come in
93 * at IRQ11, but enabling and disabling them requires writing to
94 * different bits in the SLAVIO/SEC.
95 *
96 * As a result of these changes sun4m machines could now support
97 * directed CPU interrupts using the existing enable/disable irq code
98 * with tweaks.
99 *
100 */
101
102static void irq_panic(void)
103{
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000104 prom_printf("machine: %s doesn't have irq handlers defined!\n",
105 &cputypval[0]);
106 prom_halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000109void (*sparc_init_timers)(irq_handler_t) = (void (*)(irq_handler_t))irq_panic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/*
112 * Dave Redman (djhr@tadpole.co.uk)
113 *
114 * There used to be extern calls and hard coded values here.. very sucky!
115 * instead, because some of the devices attach very early, I do something
116 * equally sucky but at least we'll never try to free statically allocated
117 * space or call kmalloc before kmalloc_init :(.
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000118 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 * In fact it's the timer10 that attaches first.. then timer14
120 * then kmalloc_init is called.. then the tty interrupts attach.
121 * hmmm....
122 *
123 */
124#define MAX_STATIC_ALLOC 4
125struct irqaction static_irqaction[MAX_STATIC_ALLOC];
126int static_irq_count;
127
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700128static struct {
Bob Breuera54123e2006-03-23 22:36:19 -0800129 struct irqaction *action;
130 int flags;
131} sparc_irq[NR_IRQS];
132#define SPARC_IRQ_INPROGRESS 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/* Used to protect the IRQ action lists */
135DEFINE_SPINLOCK(irq_action_lock);
136
137int show_interrupts(struct seq_file *p, void *v)
138{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000139 int i = *(loff_t *)v;
140 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 unsigned long flags;
142#ifdef CONFIG_SMP
143 int j;
144#endif
145
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000146 if (sparc_cpu_model == sun4d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return show_sun4d_interrupts(p, v);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 spin_lock_irqsave(&irq_action_lock, flags);
150 if (i < NR_IRQS) {
Bob Breuera54123e2006-03-23 22:36:19 -0800151 action = sparc_irq[i].action;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000152 if (!action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 goto out_unlock;
154 seq_printf(p, "%3d: ", i);
155#ifndef CONFIG_SMP
156 seq_printf(p, "%10u ", kstat_irqs(i));
157#else
Andrew Morton394e3902006-03-23 03:01:05 -0800158 for_each_online_cpu(j) {
159 seq_printf(p, "%10u ",
Bob Breuera54123e2006-03-23 22:36:19 -0800160 kstat_cpu(j).irqs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162#endif
163 seq_printf(p, " %c %s",
Thomas Gleixner67413202006-07-01 19:29:26 -0700164 (action->flags & IRQF_DISABLED) ? '+' : ' ',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 action->name);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000166 for (action = action->next; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 seq_printf(p, ",%s %s",
Thomas Gleixner67413202006-07-01 19:29:26 -0700168 (action->flags & IRQF_DISABLED) ? " +" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 action->name);
170 }
171 seq_putc(p, '\n');
172 }
173out_unlock:
174 spin_unlock_irqrestore(&irq_action_lock, flags);
175 return 0;
176}
177
178void free_irq(unsigned int irq, void *dev_id)
179{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000180 struct irqaction *action;
Bob Breuera54123e2006-03-23 22:36:19 -0800181 struct irqaction **actionp;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000182 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 unsigned int cpu_irq;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (sparc_cpu_model == sun4d) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 sun4d_free_irq(irq, dev_id);
187 return;
188 }
189 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000190 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
191 printk(KERN_ERR "Trying to free bogus IRQ %d\n", irq);
192 return;
193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 spin_lock_irqsave(&irq_action_lock, flags);
196
Bob Breuera54123e2006-03-23 22:36:19 -0800197 actionp = &sparc_irq[cpu_irq].action;
198 action = *actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 if (!action->handler) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000201 printk(KERN_ERR "Trying to free free IRQ%d\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 goto out_unlock;
203 }
204 if (dev_id) {
205 for (; action; action = action->next) {
206 if (action->dev_id == dev_id)
207 break;
Bob Breuera54123e2006-03-23 22:36:19 -0800208 actionp = &action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210 if (!action) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000211 printk(KERN_ERR "Trying to free free shared IRQ%d\n",
212 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 goto out_unlock;
214 }
Thomas Gleixner67413202006-07-01 19:29:26 -0700215 } else if (action->flags & IRQF_SHARED) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000216 printk(KERN_ERR "Trying to free shared IRQ%d with NULL device ID\n",
217 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 goto out_unlock;
219 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000220 if (action->flags & SA_STATIC_ALLOC) {
221 /*
222 * This interrupt is marked as specially allocated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 * so it is a bad idea to free it.
224 */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000225 printk(KERN_ERR "Attempt to free statically allocated IRQ%d (%s)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 irq, action->name);
227 goto out_unlock;
228 }
Bob Breuera54123e2006-03-23 22:36:19 -0800229
230 *actionp = action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 spin_unlock_irqrestore(&irq_action_lock, flags);
233
234 synchronize_irq(irq);
235
236 spin_lock_irqsave(&irq_action_lock, flags);
237
238 kfree(action);
239
Bob Breuera54123e2006-03-23 22:36:19 -0800240 if (!sparc_irq[cpu_irq].action)
Al Viro0f516812007-07-21 19:19:38 -0700241 __disable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243out_unlock:
244 spin_unlock_irqrestore(&irq_action_lock, flags);
245}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246EXPORT_SYMBOL(free_irq);
247
248/*
249 * This is called when we want to synchronize with
250 * interrupts. We may for example tell a device to
251 * stop sending interrupts: but to make sure there
252 * are no interrupts that are executing on another
253 * CPU we need to call this function.
254 */
255#ifdef CONFIG_SMP
256void synchronize_irq(unsigned int irq)
257{
Bob Breuera54123e2006-03-23 22:36:19 -0800258 unsigned int cpu_irq;
259
260 cpu_irq = irq & (NR_IRQS - 1);
261 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
262 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800264EXPORT_SYMBOL(synchronize_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#endif /* SMP */
266
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000267void unexpected_irq(int irq, void *dev_id, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000269 int i;
270 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 unsigned int cpu_irq;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 cpu_irq = irq & (NR_IRQS - 1);
Bob Breuera54123e2006-03-23 22:36:19 -0800274 action = sparc_irq[cpu_irq].action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000276 printk(KERN_ERR "IO device interrupt, irq = %d\n", irq);
277 printk(KERN_ERR "PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 regs->npc, regs->u_regs[14]);
279 if (action) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000280 printk(KERN_ERR "Expecting: ");
281 for (i = 0; i < 16; i++)
282 if (action->handler)
283 printk(KERN_CONT "[%s:%d:0x%x] ", action->name,
284 i, (unsigned int)action->handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000286 printk(KERN_ERR "AIEEE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 panic("bogus interrupt received");
288}
289
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000290void handler_irq(int pil, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Al Viro0d844382006-10-08 14:30:44 +0100292 struct pt_regs *old_regs;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000293 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Al Viro0d844382006-10-08 14:30:44 +0100296 old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 irq_enter();
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000298 disable_pil_irq(pil);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299#ifdef CONFIG_SMP
Simon Arlottd1a78c32007-05-11 13:51:23 -0700300 /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000301 if ((sparc_cpu_model==sun4m) && (pil < 10))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 smp4m_irq_rotate(cpu);
303#endif
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000304 action = sparc_irq[pil].action;
305 sparc_irq[pil].flags |= SPARC_IRQ_INPROGRESS;
306 kstat_cpu(cpu).irqs[pil]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 do {
308 if (!action || !action->handler)
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000309 unexpected_irq(pil, NULL, regs);
310 action->handler(pil, action->dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 action = action->next;
312 } while (action);
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000313 sparc_irq[pil].flags &= ~SPARC_IRQ_INPROGRESS;
314 enable_pil_irq(pil);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 irq_exit();
Al Viro0d844382006-10-08 14:30:44 +0100316 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
David S. Miller0a808a32007-08-02 00:19:14 -0700319#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000321/*
322 * Fast IRQs on the Sparc can only have one routine attached to them,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 * thus no sharing possible.
324 */
David S. Miller0a808a32007-08-02 00:19:14 -0700325static int request_fast_irq(unsigned int irq,
326 void (*handler)(void),
327 unsigned long irqflags, const char *devname)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
329 struct irqaction *action;
330 unsigned long flags;
331 unsigned int cpu_irq;
332 int ret;
Namhyung Kim51672322010-10-25 05:52:38 +0000333#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 struct tt_entry *trap_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000337 if (cpu_irq > 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 ret = -EINVAL;
339 goto out;
340 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000341 if (!handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 ret = -EINVAL;
343 goto out;
344 }
345
346 spin_lock_irqsave(&irq_action_lock, flags);
347
Bob Breuera54123e2006-03-23 22:36:19 -0800348 action = sparc_irq[cpu_irq].action;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000349 if (action) {
350 if (action->flags & IRQF_SHARED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 panic("Trying to register fast irq when already shared.\n");
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000352 if (irqflags & IRQF_SHARED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 panic("Trying to register fast irq as shared.\n");
354
355 /* Anyway, someone already owns it so cannot be made fast. */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000356 printk(KERN_ERR "request_fast_irq: Trying to register yet already owned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 ret = -EBUSY;
358 goto out_unlock;
359 }
360
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000361 /*
362 * If this is flagged as statically allocated then we use our
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 * private struct which is never freed.
364 */
365 if (irqflags & SA_STATIC_ALLOC) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000366 if (static_irq_count < MAX_STATIC_ALLOC)
367 action = &static_irqaction[static_irq_count++];
368 else
369 printk(KERN_ERR "Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
370 irq, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (action == NULL)
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000374 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
375 if (!action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 ret = -ENOMEM;
377 goto out_unlock;
378 }
379
380 /* Dork with trap table if we get this far. */
381#define INSTANTIATE(table) \
382 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
383 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
384 SPARC_BRANCH((unsigned long) handler, \
385 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
386 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
387 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
388
389 INSTANTIATE(sparc_ttable)
Namhyung Kim51672322010-10-25 05:52:38 +0000390#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000391 trap_table = &trapbase_cpu1;
392 INSTANTIATE(trap_table)
393 trap_table = &trapbase_cpu2;
394 INSTANTIATE(trap_table)
395 trap_table = &trapbase_cpu3;
396 INSTANTIATE(trap_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#endif
398#undef INSTANTIATE
399 /*
400 * XXX Correct thing whould be to flush only I- and D-cache lines
401 * which contain the handler in question. But as of time of the
402 * writing we have no CPU-neutral interface to fine-grained flushes.
403 */
404 flush_cache_all();
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 action->flags = irqflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 action->name = devname;
408 action->dev_id = NULL;
409 action->next = NULL;
410
Bob Breuera54123e2006-03-23 22:36:19 -0800411 sparc_irq[cpu_irq].action = action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Al Viro0f516812007-07-21 19:19:38 -0700413 __enable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 ret = 0;
416out_unlock:
417 spin_unlock_irqrestore(&irq_action_lock, flags);
418out:
419 return ret;
420}
421
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000422/*
423 * These variables are used to access state from the assembler
David S. Miller0a808a32007-08-02 00:19:14 -0700424 * interrupt handler, floppy_hardint, so we cannot put these in
425 * the floppy driver image because that would not work in the
426 * modular case.
427 */
428volatile unsigned char *fdc_status;
429EXPORT_SYMBOL(fdc_status);
430
431char *pdma_vaddr;
432EXPORT_SYMBOL(pdma_vaddr);
433
434unsigned long pdma_size;
435EXPORT_SYMBOL(pdma_size);
436
437volatile int doing_pdma;
438EXPORT_SYMBOL(doing_pdma);
439
440char *pdma_base;
441EXPORT_SYMBOL(pdma_base);
442
443unsigned long pdma_areasize;
444EXPORT_SYMBOL(pdma_areasize);
445
Jeff Garzik7c239972007-10-19 03:12:20 -0400446static irq_handler_t floppy_irq_handler;
David S. Miller0a808a32007-08-02 00:19:14 -0700447
448void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
449{
450 struct pt_regs *old_regs;
451 int cpu = smp_processor_id();
452
453 old_regs = set_irq_regs(regs);
454 disable_pil_irq(irq);
455 irq_enter();
456 kstat_cpu(cpu).irqs[irq]++;
457 floppy_irq_handler(irq, dev_id);
458 irq_exit();
459 enable_pil_irq(irq);
460 set_irq_regs(old_regs);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000461 /*
462 * XXX Eek, it's totally changed with preempt_count() and such
463 * if (softirq_pending(cpu))
464 * do_softirq();
465 */
David S. Miller0a808a32007-08-02 00:19:14 -0700466}
467
468int sparc_floppy_request_irq(int irq, unsigned long flags,
Jeff Garzik7c239972007-10-19 03:12:20 -0400469 irq_handler_t irq_handler)
David S. Miller0a808a32007-08-02 00:19:14 -0700470{
471 floppy_irq_handler = irq_handler;
472 return request_fast_irq(irq, floppy_hardint, flags, "floppy");
473}
474EXPORT_SYMBOL(sparc_floppy_request_irq);
475
476#endif
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478int request_irq(unsigned int irq,
David Howells40220c12006-10-09 12:19:47 +0100479 irq_handler_t handler,
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000480 unsigned long irqflags, const char *devname, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000482 struct irqaction *action, **actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 unsigned long flags;
484 unsigned int cpu_irq;
485 int ret;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000486
487 if (sparc_cpu_model == sun4d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000491 if (cpu_irq > 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 ret = -EINVAL;
493 goto out;
494 }
495 if (!handler) {
496 ret = -EINVAL;
497 goto out;
498 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 spin_lock_irqsave(&irq_action_lock, flags);
501
Bob Breuera54123e2006-03-23 22:36:19 -0800502 actionp = &sparc_irq[cpu_irq].action;
503 action = *actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (action) {
Thomas Gleixner67413202006-07-01 19:29:26 -0700505 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 ret = -EBUSY;
507 goto out_unlock;
508 }
Thomas Gleixner67413202006-07-01 19:29:26 -0700509 if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000510 printk(KERN_ERR "Attempt to mix fast and slow interrupts on IRQ%d denied\n",
511 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 ret = -EBUSY;
513 goto out_unlock;
Bob Breuera54123e2006-03-23 22:36:19 -0800514 }
515 for ( ; action; action = *actionp)
516 actionp = &action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
518
519 /* If this is flagged as statically allocated then we use our
520 * private struct which is never freed.
521 */
522 if (irqflags & SA_STATIC_ALLOC) {
523 if (static_irq_count < MAX_STATIC_ALLOC)
524 action = &static_irqaction[static_irq_count++];
525 else
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000526 printk(KERN_ERR "Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
527 irq, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (action == NULL)
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000530 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
531 if (!action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 ret = -ENOMEM;
533 goto out_unlock;
534 }
535
536 action->handler = handler;
537 action->flags = irqflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 action->name = devname;
539 action->next = NULL;
540 action->dev_id = dev_id;
541
Bob Breuera54123e2006-03-23 22:36:19 -0800542 *actionp = action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Al Viro0f516812007-07-21 19:19:38 -0700544 __enable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 ret = 0;
547out_unlock:
548 spin_unlock_irqrestore(&irq_action_lock, flags);
549out:
550 return ret;
551}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552EXPORT_SYMBOL(request_irq);
553
Al Viro0f516812007-07-21 19:19:38 -0700554void disable_irq_nosync(unsigned int irq)
555{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800556 __disable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700557}
558EXPORT_SYMBOL(disable_irq_nosync);
559
560void disable_irq(unsigned int irq)
561{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800562 __disable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700563}
564EXPORT_SYMBOL(disable_irq);
565
566void enable_irq(unsigned int irq)
567{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800568 __enable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700569}
Al Viro0f516812007-07-21 19:19:38 -0700570EXPORT_SYMBOL(enable_irq);
571
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000572/*
573 * We really don't need these at all on the Sparc. We only have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 * stubs here because they are exported to modules.
575 */
576unsigned long probe_irq_on(void)
577{
578 return 0;
579}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580EXPORT_SYMBOL(probe_irq_on);
581
582int probe_irq_off(unsigned long mask)
583{
584 return 0;
585}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586EXPORT_SYMBOL(probe_irq_off);
587
588/* djhr
589 * This could probably be made indirect too and assigned in the CPU
590 * bits of the code. That would be much nicer I think and would also
591 * fit in with the idea of being able to tune your kernel for your machine
592 * by removing unrequired machine and device support.
593 *
594 */
595
596void __init init_IRQ(void)
597{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000598 switch (sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 case sun4c:
600 case sun4:
601 sun4c_init_IRQ();
602 break;
603
604 case sun4m:
605#ifdef CONFIG_PCI
606 pcic_probe();
607 if (pcic_present()) {
608 sun4m_pci_init_IRQ();
609 break;
610 }
611#endif
612 sun4m_init_IRQ();
613 break;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 case sun4d:
616 sun4d_init_IRQ();
617 break;
618
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000619 case sparc_leon:
620 leon_init_IRQ();
621 break;
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 default:
Simon Arlottd1a78c32007-05-11 13:51:23 -0700624 prom_printf("Cannot initialize IRQs on this Sun machine...");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 break;
626 }
627 btfixup();
628}
629
Julian Calaby4696b642009-01-05 18:13:49 -0800630#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631void init_irq_proc(void)
632{
633 /* For now, nothing... */
634}
Julian Calaby4696b642009-01-05 18:13:49 -0800635#endif /* CONFIG_PROC_FS */