blob: 93afee00a9278d41d7b7a831beffb01eb4d5845b [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
David Howellsdf9ee292010-10-07 14:08:55 +010032unsigned long arch_local_irq_save(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 unsigned long retval;
35 unsigned long tmp;
36
37 __asm__ __volatile__(
38 "rd %%psr, %0\n\t"
39 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
40 "or %0, %2, %1\n\t"
41 "wr %1, 0, %%psr\n\t"
42 "nop; nop; nop\n"
43 : "=&r" (retval), "=r" (tmp)
44 : "i" (PSR_PIL)
45 : "memory");
46
47 return retval;
48}
David Howellsdf9ee292010-10-07 14:08:55 +010049EXPORT_SYMBOL(arch_local_irq_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
David Howellsdf9ee292010-10-07 14:08:55 +010051void arch_local_irq_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 unsigned long tmp;
54
55 __asm__ __volatile__(
56 "rd %%psr, %0\n\t"
57 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
58 "andn %0, %1, %0\n\t"
59 "wr %0, 0, %%psr\n\t"
60 "nop; nop; nop\n"
61 : "=&r" (tmp)
62 : "i" (PSR_PIL)
63 : "memory");
64}
David Howellsdf9ee292010-10-07 14:08:55 +010065EXPORT_SYMBOL(arch_local_irq_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
David Howellsdf9ee292010-10-07 14:08:55 +010067void arch_local_irq_restore(unsigned long old_psr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 unsigned long tmp;
70
71 __asm__ __volatile__(
72 "rd %%psr, %0\n\t"
73 "and %2, %1, %2\n\t"
74 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
75 "andn %0, %1, %0\n\t"
76 "wr %0, %2, %%psr\n\t"
77 "nop; nop; nop\n"
78 : "=&r" (tmp)
79 : "i" (PSR_PIL), "r" (old_psr)
80 : "memory");
81}
David Howellsdf9ee292010-10-07 14:08:55 +010082EXPORT_SYMBOL(arch_local_irq_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/*
85 * Dave Redman (djhr@tadpole.co.uk)
86 *
87 * IRQ numbers.. These are no longer restricted to 15..
88 *
89 * this is done to enable SBUS cards and onboard IO to be masked
90 * correctly. using the interrupt level isn't good enough.
91 *
92 * For example:
93 * A device interrupting at sbus level6 and the Floppy both come in
94 * at IRQ11, but enabling and disabling them requires writing to
95 * different bits in the SLAVIO/SEC.
96 *
97 * As a result of these changes sun4m machines could now support
98 * directed CPU interrupts using the existing enable/disable irq code
99 * with tweaks.
100 *
101 */
102
103static void irq_panic(void)
104{
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000105 prom_printf("machine: %s doesn't have irq handlers defined!\n",
106 &cputypval[0]);
107 prom_halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000110void (*sparc_init_timers)(irq_handler_t) = (void (*)(irq_handler_t))irq_panic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112/*
113 * Dave Redman (djhr@tadpole.co.uk)
114 *
115 * There used to be extern calls and hard coded values here.. very sucky!
116 * instead, because some of the devices attach very early, I do something
117 * equally sucky but at least we'll never try to free statically allocated
118 * space or call kmalloc before kmalloc_init :(.
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000119 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * In fact it's the timer10 that attaches first.. then timer14
121 * then kmalloc_init is called.. then the tty interrupts attach.
122 * hmmm....
123 *
124 */
125#define MAX_STATIC_ALLOC 4
126struct irqaction static_irqaction[MAX_STATIC_ALLOC];
127int static_irq_count;
128
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700129static struct {
Bob Breuera54123e2006-03-23 22:36:19 -0800130 struct irqaction *action;
131 int flags;
132} sparc_irq[NR_IRQS];
133#define SPARC_IRQ_INPROGRESS 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/* Used to protect the IRQ action lists */
136DEFINE_SPINLOCK(irq_action_lock);
137
138int show_interrupts(struct seq_file *p, void *v)
139{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000140 int i = *(loff_t *)v;
141 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 unsigned long flags;
143#ifdef CONFIG_SMP
144 int j;
145#endif
146
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000147 if (sparc_cpu_model == sun4d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return show_sun4d_interrupts(p, v);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 spin_lock_irqsave(&irq_action_lock, flags);
151 if (i < NR_IRQS) {
Bob Breuera54123e2006-03-23 22:36:19 -0800152 action = sparc_irq[i].action;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000153 if (!action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 goto out_unlock;
155 seq_printf(p, "%3d: ", i);
156#ifndef CONFIG_SMP
157 seq_printf(p, "%10u ", kstat_irqs(i));
158#else
Andrew Morton394e3902006-03-23 03:01:05 -0800159 for_each_online_cpu(j) {
160 seq_printf(p, "%10u ",
Bob Breuera54123e2006-03-23 22:36:19 -0800161 kstat_cpu(j).irqs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163#endif
164 seq_printf(p, " %c %s",
Thomas Gleixner67413202006-07-01 19:29:26 -0700165 (action->flags & IRQF_DISABLED) ? '+' : ' ',
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 action->name);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000167 for (action = action->next; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 seq_printf(p, ",%s %s",
Thomas Gleixner67413202006-07-01 19:29:26 -0700169 (action->flags & IRQF_DISABLED) ? " +" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 action->name);
171 }
172 seq_putc(p, '\n');
173 }
174out_unlock:
175 spin_unlock_irqrestore(&irq_action_lock, flags);
176 return 0;
177}
178
179void free_irq(unsigned int irq, void *dev_id)
180{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000181 struct irqaction *action;
Bob Breuera54123e2006-03-23 22:36:19 -0800182 struct irqaction **actionp;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000183 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 unsigned int cpu_irq;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 if (sparc_cpu_model == sun4d) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 sun4d_free_irq(irq, dev_id);
188 return;
189 }
190 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000191 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
192 printk(KERN_ERR "Trying to free bogus IRQ %d\n", irq);
193 return;
194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 spin_lock_irqsave(&irq_action_lock, flags);
197
Bob Breuera54123e2006-03-23 22:36:19 -0800198 actionp = &sparc_irq[cpu_irq].action;
199 action = *actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 if (!action->handler) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000202 printk(KERN_ERR "Trying to free free IRQ%d\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 goto out_unlock;
204 }
205 if (dev_id) {
206 for (; action; action = action->next) {
207 if (action->dev_id == dev_id)
208 break;
Bob Breuera54123e2006-03-23 22:36:19 -0800209 actionp = &action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211 if (!action) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000212 printk(KERN_ERR "Trying to free free shared IRQ%d\n",
213 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 goto out_unlock;
215 }
Thomas Gleixner67413202006-07-01 19:29:26 -0700216 } else if (action->flags & IRQF_SHARED) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000217 printk(KERN_ERR "Trying to free shared IRQ%d with NULL device ID\n",
218 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 goto out_unlock;
220 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000221 if (action->flags & SA_STATIC_ALLOC) {
222 /*
223 * This interrupt is marked as specially allocated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 * so it is a bad idea to free it.
225 */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000226 printk(KERN_ERR "Attempt to free statically allocated IRQ%d (%s)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 irq, action->name);
228 goto out_unlock;
229 }
Bob Breuera54123e2006-03-23 22:36:19 -0800230
231 *actionp = action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 spin_unlock_irqrestore(&irq_action_lock, flags);
234
235 synchronize_irq(irq);
236
237 spin_lock_irqsave(&irq_action_lock, flags);
238
239 kfree(action);
240
Bob Breuera54123e2006-03-23 22:36:19 -0800241 if (!sparc_irq[cpu_irq].action)
Al Viro0f516812007-07-21 19:19:38 -0700242 __disable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244out_unlock:
245 spin_unlock_irqrestore(&irq_action_lock, flags);
246}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247EXPORT_SYMBOL(free_irq);
248
249/*
250 * This is called when we want to synchronize with
251 * interrupts. We may for example tell a device to
252 * stop sending interrupts: but to make sure there
253 * are no interrupts that are executing on another
254 * CPU we need to call this function.
255 */
256#ifdef CONFIG_SMP
257void synchronize_irq(unsigned int irq)
258{
Bob Breuera54123e2006-03-23 22:36:19 -0800259 unsigned int cpu_irq;
260
261 cpu_irq = irq & (NR_IRQS - 1);
262 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
263 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800265EXPORT_SYMBOL(synchronize_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#endif /* SMP */
267
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000268void unexpected_irq(int irq, void *dev_id, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000270 int i;
271 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 unsigned int cpu_irq;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 cpu_irq = irq & (NR_IRQS - 1);
Bob Breuera54123e2006-03-23 22:36:19 -0800275 action = sparc_irq[cpu_irq].action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000277 printk(KERN_ERR "IO device interrupt, irq = %d\n", irq);
278 printk(KERN_ERR "PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 regs->npc, regs->u_regs[14]);
280 if (action) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000281 printk(KERN_ERR "Expecting: ");
282 for (i = 0; i < 16; i++)
283 if (action->handler)
284 printk(KERN_CONT "[%s:%d:0x%x] ", action->name,
285 i, (unsigned int)action->handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000287 printk(KERN_ERR "AIEEE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 panic("bogus interrupt received");
289}
290
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000291void handler_irq(int pil, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Al Viro0d844382006-10-08 14:30:44 +0100293 struct pt_regs *old_regs;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000294 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Al Viro0d844382006-10-08 14:30:44 +0100297 old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 irq_enter();
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000299 disable_pil_irq(pil);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#ifdef CONFIG_SMP
Simon Arlottd1a78c32007-05-11 13:51:23 -0700301 /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000302 if ((sparc_cpu_model==sun4m) && (pil < 10))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 smp4m_irq_rotate(cpu);
304#endif
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000305 action = sparc_irq[pil].action;
306 sparc_irq[pil].flags |= SPARC_IRQ_INPROGRESS;
307 kstat_cpu(cpu).irqs[pil]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 do {
309 if (!action || !action->handler)
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000310 unexpected_irq(pil, NULL, regs);
311 action->handler(pil, action->dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 action = action->next;
313 } while (action);
Sam Ravnborgd4d1ec42011-01-22 11:32:15 +0000314 sparc_irq[pil].flags &= ~SPARC_IRQ_INPROGRESS;
315 enable_pil_irq(pil);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 irq_exit();
Al Viro0d844382006-10-08 14:30:44 +0100317 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
David S. Miller0a808a32007-08-02 00:19:14 -0700320#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000322/*
323 * Fast IRQs on the Sparc can only have one routine attached to them,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 * thus no sharing possible.
325 */
David S. Miller0a808a32007-08-02 00:19:14 -0700326static int request_fast_irq(unsigned int irq,
327 void (*handler)(void),
328 unsigned long irqflags, const char *devname)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 struct irqaction *action;
331 unsigned long flags;
332 unsigned int cpu_irq;
333 int ret;
Namhyung Kim51672322010-10-25 05:52:38 +0000334#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 struct tt_entry *trap_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000338 if (cpu_irq > 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 ret = -EINVAL;
340 goto out;
341 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000342 if (!handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 ret = -EINVAL;
344 goto out;
345 }
346
347 spin_lock_irqsave(&irq_action_lock, flags);
348
Bob Breuera54123e2006-03-23 22:36:19 -0800349 action = sparc_irq[cpu_irq].action;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000350 if (action) {
351 if (action->flags & IRQF_SHARED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 panic("Trying to register fast irq when already shared.\n");
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000353 if (irqflags & IRQF_SHARED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 panic("Trying to register fast irq as shared.\n");
355
356 /* Anyway, someone already owns it so cannot be made fast. */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000357 printk(KERN_ERR "request_fast_irq: Trying to register yet already owned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 ret = -EBUSY;
359 goto out_unlock;
360 }
361
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000362 /*
363 * If this is flagged as statically allocated then we use our
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 * private struct which is never freed.
365 */
366 if (irqflags & SA_STATIC_ALLOC) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000367 if (static_irq_count < MAX_STATIC_ALLOC)
368 action = &static_irqaction[static_irq_count++];
369 else
370 printk(KERN_ERR "Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
371 irq, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 if (action == NULL)
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000375 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
376 if (!action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 ret = -ENOMEM;
378 goto out_unlock;
379 }
380
381 /* Dork with trap table if we get this far. */
382#define INSTANTIATE(table) \
383 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
384 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
385 SPARC_BRANCH((unsigned long) handler, \
386 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
387 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
388 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
389
390 INSTANTIATE(sparc_ttable)
Namhyung Kim51672322010-10-25 05:52:38 +0000391#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000392 trap_table = &trapbase_cpu1;
393 INSTANTIATE(trap_table)
394 trap_table = &trapbase_cpu2;
395 INSTANTIATE(trap_table)
396 trap_table = &trapbase_cpu3;
397 INSTANTIATE(trap_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398#endif
399#undef INSTANTIATE
400 /*
401 * XXX Correct thing whould be to flush only I- and D-cache lines
402 * which contain the handler in question. But as of time of the
403 * writing we have no CPU-neutral interface to fine-grained flushes.
404 */
405 flush_cache_all();
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 action->flags = irqflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 action->name = devname;
409 action->dev_id = NULL;
410 action->next = NULL;
411
Bob Breuera54123e2006-03-23 22:36:19 -0800412 sparc_irq[cpu_irq].action = action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Al Viro0f516812007-07-21 19:19:38 -0700414 __enable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 ret = 0;
417out_unlock:
418 spin_unlock_irqrestore(&irq_action_lock, flags);
419out:
420 return ret;
421}
422
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000423/*
424 * These variables are used to access state from the assembler
David S. Miller0a808a32007-08-02 00:19:14 -0700425 * interrupt handler, floppy_hardint, so we cannot put these in
426 * the floppy driver image because that would not work in the
427 * modular case.
428 */
429volatile unsigned char *fdc_status;
430EXPORT_SYMBOL(fdc_status);
431
432char *pdma_vaddr;
433EXPORT_SYMBOL(pdma_vaddr);
434
435unsigned long pdma_size;
436EXPORT_SYMBOL(pdma_size);
437
438volatile int doing_pdma;
439EXPORT_SYMBOL(doing_pdma);
440
441char *pdma_base;
442EXPORT_SYMBOL(pdma_base);
443
444unsigned long pdma_areasize;
445EXPORT_SYMBOL(pdma_areasize);
446
Jeff Garzik7c239972007-10-19 03:12:20 -0400447static irq_handler_t floppy_irq_handler;
David S. Miller0a808a32007-08-02 00:19:14 -0700448
449void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
450{
451 struct pt_regs *old_regs;
452 int cpu = smp_processor_id();
453
454 old_regs = set_irq_regs(regs);
455 disable_pil_irq(irq);
456 irq_enter();
457 kstat_cpu(cpu).irqs[irq]++;
458 floppy_irq_handler(irq, dev_id);
459 irq_exit();
460 enable_pil_irq(irq);
461 set_irq_regs(old_regs);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000462 /*
463 * XXX Eek, it's totally changed with preempt_count() and such
464 * if (softirq_pending(cpu))
465 * do_softirq();
466 */
David S. Miller0a808a32007-08-02 00:19:14 -0700467}
468
469int sparc_floppy_request_irq(int irq, unsigned long flags,
Jeff Garzik7c239972007-10-19 03:12:20 -0400470 irq_handler_t irq_handler)
David S. Miller0a808a32007-08-02 00:19:14 -0700471{
472 floppy_irq_handler = irq_handler;
473 return request_fast_irq(irq, floppy_hardint, flags, "floppy");
474}
475EXPORT_SYMBOL(sparc_floppy_request_irq);
476
477#endif
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479int request_irq(unsigned int irq,
David Howells40220c12006-10-09 12:19:47 +0100480 irq_handler_t handler,
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000481 unsigned long irqflags, const char *devname, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000483 struct irqaction *action, **actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 unsigned long flags;
485 unsigned int cpu_irq;
486 int ret;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000487
488 if (sparc_cpu_model == sun4d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 cpu_irq = irq & (NR_IRQS - 1);
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000492 if (cpu_irq > 14) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 ret = -EINVAL;
494 goto out;
495 }
496 if (!handler) {
497 ret = -EINVAL;
498 goto out;
499 }
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 spin_lock_irqsave(&irq_action_lock, flags);
502
Bob Breuera54123e2006-03-23 22:36:19 -0800503 actionp = &sparc_irq[cpu_irq].action;
504 action = *actionp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (action) {
Thomas Gleixner67413202006-07-01 19:29:26 -0700506 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 ret = -EBUSY;
508 goto out_unlock;
509 }
Thomas Gleixner67413202006-07-01 19:29:26 -0700510 if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000511 printk(KERN_ERR "Attempt to mix fast and slow interrupts on IRQ%d denied\n",
512 irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 ret = -EBUSY;
514 goto out_unlock;
Bob Breuera54123e2006-03-23 22:36:19 -0800515 }
516 for ( ; action; action = *actionp)
517 actionp = &action->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519
520 /* If this is flagged as statically allocated then we use our
521 * private struct which is never freed.
522 */
523 if (irqflags & SA_STATIC_ALLOC) {
524 if (static_irq_count < MAX_STATIC_ALLOC)
525 action = &static_irqaction[static_irq_count++];
526 else
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000527 printk(KERN_ERR "Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
528 irq, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (action == NULL)
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000531 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
532 if (!action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 ret = -ENOMEM;
534 goto out_unlock;
535 }
536
537 action->handler = handler;
538 action->flags = irqflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 action->name = devname;
540 action->next = NULL;
541 action->dev_id = dev_id;
542
Bob Breuera54123e2006-03-23 22:36:19 -0800543 *actionp = action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Al Viro0f516812007-07-21 19:19:38 -0700545 __enable_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 ret = 0;
548out_unlock:
549 spin_unlock_irqrestore(&irq_action_lock, flags);
550out:
551 return ret;
552}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553EXPORT_SYMBOL(request_irq);
554
Al Viro0f516812007-07-21 19:19:38 -0700555void disable_irq_nosync(unsigned int irq)
556{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800557 __disable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700558}
559EXPORT_SYMBOL(disable_irq_nosync);
560
561void disable_irq(unsigned int irq)
562{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800563 __disable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700564}
565EXPORT_SYMBOL(disable_irq);
566
567void enable_irq(unsigned int irq)
568{
Sam Ravnborg81265fd2008-12-08 01:08:24 -0800569 __enable_irq(irq);
Al Viro0f516812007-07-21 19:19:38 -0700570}
Al Viro0f516812007-07-21 19:19:38 -0700571EXPORT_SYMBOL(enable_irq);
572
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000573/*
574 * We really don't need these at all on the Sparc. We only have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 * stubs here because they are exported to modules.
576 */
577unsigned long probe_irq_on(void)
578{
579 return 0;
580}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581EXPORT_SYMBOL(probe_irq_on);
582
583int probe_irq_off(unsigned long mask)
584{
585 return 0;
586}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587EXPORT_SYMBOL(probe_irq_off);
588
589/* djhr
590 * This could probably be made indirect too and assigned in the CPU
591 * bits of the code. That would be much nicer I think and would also
592 * fit in with the idea of being able to tune your kernel for your machine
593 * by removing unrequired machine and device support.
594 *
595 */
596
597void __init init_IRQ(void)
598{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000599 switch (sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 case sun4c:
601 case sun4:
602 sun4c_init_IRQ();
603 break;
604
605 case sun4m:
606#ifdef CONFIG_PCI
607 pcic_probe();
608 if (pcic_present()) {
609 sun4m_pci_init_IRQ();
610 break;
611 }
612#endif
613 sun4m_init_IRQ();
614 break;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 case sun4d:
617 sun4d_init_IRQ();
618 break;
619
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000620 case sparc_leon:
621 leon_init_IRQ();
622 break;
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 default:
Simon Arlottd1a78c32007-05-11 13:51:23 -0700625 prom_printf("Cannot initialize IRQs on this Sun machine...");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 break;
627 }
628 btfixup();
629}
630
Julian Calaby4696b642009-01-05 18:13:49 -0800631#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632void init_irq_proc(void)
633{
634 /* For now, nothing... */
635}
Julian Calaby4696b642009-01-05 18:13:49 -0800636#endif /* CONFIG_PROC_FS */