1 /* $Id: irq.c,v 1.114 2001/12/11 04:55:51 davem Exp $
2 * arch/sparc/kernel/irq.c: Interrupt request handling routines. On the
3 * Sparc the IRQ's 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.
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)
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>
21 #include <linux/sched.h>
22 #include <linux/interrupt.h>
23 #include <linux/slab.h>
24 #include <linux/random.h>
25 #include <linux/init.h>
26 #include <linux/smp.h>
27 #include <linux/smp_lock.h>
28 #include <linux/delay.h>
29 #include <linux/threads.h>
30 #include <linux/spinlock.h>
31 #include <linux/seq_file.h>
33 #include <asm/ptrace.h>
34 #include <asm/processor.h>
35 #include <asm/system.h>
38 #include <asm/vaddrs.h>
39 #include <asm/timer.h>
40 #include <asm/openprom.h>
41 #include <asm/oplib.h>
42 #include <asm/traps.h>
45 #include <asm/pgalloc.h>
46 #include <asm/pgtable.h>
48 #include <asm/cacheflush.h>
49 #include <asm/irq_regs.h>
52 #define SMP_NOP2 "nop; nop;\n\t"
53 #define SMP_NOP3 "nop; nop; nop;\n\t"
58 unsigned long __local_irq_save(void)
65 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
69 : "=&r" (retval), "=r" (tmp)
76 void local_irq_enable(void)
82 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
91 void local_irq_restore(unsigned long old_psr)
98 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
100 "wr %0, %2, %%psr\n\t"
103 : "i" (PSR_PIL), "r" (old_psr)
107 EXPORT_SYMBOL(__local_irq_save);
108 EXPORT_SYMBOL(local_irq_enable);
109 EXPORT_SYMBOL(local_irq_restore);
112 * Dave Redman (djhr@tadpole.co.uk)
114 * IRQ numbers.. These are no longer restricted to 15..
116 * this is done to enable SBUS cards and onboard IO to be masked
117 * correctly. using the interrupt level isn't good enough.
120 * A device interrupting at sbus level6 and the Floppy both come in
121 * at IRQ11, but enabling and disabling them requires writing to
122 * different bits in the SLAVIO/SEC.
124 * As a result of these changes sun4m machines could now support
125 * directed CPU interrupts using the existing enable/disable irq code
130 static void irq_panic(void)
132 extern char *cputypval;
133 prom_printf("machine: %s doesn't have irq handlers defined!\n",cputypval);
137 void (*sparc_init_timers)(irq_handler_t ) =
138 (void (*)(irq_handler_t )) irq_panic;
141 * Dave Redman (djhr@tadpole.co.uk)
143 * There used to be extern calls and hard coded values here.. very sucky!
144 * instead, because some of the devices attach very early, I do something
145 * equally sucky but at least we'll never try to free statically allocated
146 * space or call kmalloc before kmalloc_init :(.
148 * In fact it's the timer10 that attaches first.. then timer14
149 * then kmalloc_init is called.. then the tty interrupts attach.
153 #define MAX_STATIC_ALLOC 4
154 struct irqaction static_irqaction[MAX_STATIC_ALLOC];
155 int static_irq_count;
158 struct irqaction *action;
160 } sparc_irq[NR_IRQS];
161 #define SPARC_IRQ_INPROGRESS 1
163 /* Used to protect the IRQ action lists */
164 DEFINE_SPINLOCK(irq_action_lock);
166 int show_interrupts(struct seq_file *p, void *v)
168 int i = *(loff_t *) v;
169 struct irqaction * action;
175 if (sparc_cpu_model == sun4d) {
176 extern int show_sun4d_interrupts(struct seq_file *, void *);
178 return show_sun4d_interrupts(p, v);
180 spin_lock_irqsave(&irq_action_lock, flags);
182 action = sparc_irq[i].action;
185 seq_printf(p, "%3d: ", i);
187 seq_printf(p, "%10u ", kstat_irqs(i));
189 for_each_online_cpu(j) {
190 seq_printf(p, "%10u ",
191 kstat_cpu(j).irqs[i]);
194 seq_printf(p, " %c %s",
195 (action->flags & IRQF_DISABLED) ? '+' : ' ',
197 for (action=action->next; action; action = action->next) {
198 seq_printf(p, ",%s %s",
199 (action->flags & IRQF_DISABLED) ? " +" : "",
205 spin_unlock_irqrestore(&irq_action_lock, flags);
209 void free_irq(unsigned int irq, void *dev_id)
211 struct irqaction * action;
212 struct irqaction **actionp;
214 unsigned int cpu_irq;
216 if (sparc_cpu_model == sun4d) {
217 extern void sun4d_free_irq(unsigned int, void *);
219 sun4d_free_irq(irq, dev_id);
222 cpu_irq = irq & (NR_IRQS - 1);
223 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
224 printk("Trying to free bogus IRQ %d\n", irq);
228 spin_lock_irqsave(&irq_action_lock, flags);
230 actionp = &sparc_irq[cpu_irq].action;
233 if (!action->handler) {
234 printk("Trying to free free IRQ%d\n",irq);
238 for (; action; action = action->next) {
239 if (action->dev_id == dev_id)
241 actionp = &action->next;
244 printk("Trying to free free shared IRQ%d\n",irq);
247 } else if (action->flags & IRQF_SHARED) {
248 printk("Trying to free shared IRQ%d with NULL device ID\n", irq);
251 if (action->flags & SA_STATIC_ALLOC)
253 /* This interrupt is marked as specially allocated
254 * so it is a bad idea to free it.
256 printk("Attempt to free statically allocated IRQ%d (%s)\n",
261 *actionp = action->next;
263 spin_unlock_irqrestore(&irq_action_lock, flags);
265 synchronize_irq(irq);
267 spin_lock_irqsave(&irq_action_lock, flags);
271 if (!sparc_irq[cpu_irq].action)
275 spin_unlock_irqrestore(&irq_action_lock, flags);
278 EXPORT_SYMBOL(free_irq);
281 * This is called when we want to synchronize with
282 * interrupts. We may for example tell a device to
283 * stop sending interrupts: but to make sure there
284 * are no interrupts that are executing on another
285 * CPU we need to call this function.
288 void synchronize_irq(unsigned int irq)
290 unsigned int cpu_irq;
292 cpu_irq = irq & (NR_IRQS - 1);
293 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
298 void unexpected_irq(int irq, void *dev_id, struct pt_regs * regs)
301 struct irqaction * action;
302 unsigned int cpu_irq;
304 cpu_irq = irq & (NR_IRQS - 1);
305 action = sparc_irq[cpu_irq].action;
307 printk("IO device interrupt, irq = %d\n", irq);
308 printk("PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
309 regs->npc, regs->u_regs[14]);
311 printk("Expecting: ");
312 for (i = 0; i < 16; i++)
314 printk("[%s:%d:0x%x] ", action->name,
315 (int) i, (unsigned int) action->handler);
318 panic("bogus interrupt received");
321 void handler_irq(int irq, struct pt_regs * regs)
323 struct pt_regs *old_regs;
324 struct irqaction * action;
325 int cpu = smp_processor_id();
327 extern void smp4m_irq_rotate(int cpu);
330 old_regs = set_irq_regs(regs);
332 disable_pil_irq(irq);
334 /* Only rotate on lower priority IRQ's (scsi, ethernet, etc.). */
335 if((sparc_cpu_model==sun4m) && (irq < 10))
336 smp4m_irq_rotate(cpu);
338 action = sparc_irq[irq].action;
339 sparc_irq[irq].flags |= SPARC_IRQ_INPROGRESS;
340 kstat_cpu(cpu).irqs[irq]++;
342 if (!action || !action->handler)
343 unexpected_irq(irq, NULL, regs);
344 action->handler(irq, action->dev_id);
345 action = action->next;
347 sparc_irq[irq].flags &= ~SPARC_IRQ_INPROGRESS;
350 set_irq_regs(old_regs);
353 #ifdef CONFIG_BLK_DEV_FD
354 extern void floppy_interrupt(int irq, void *dev_id);
356 void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
358 struct pt_regs *old_regs;
359 int cpu = smp_processor_id();
361 old_regs = set_irq_regs(regs);
362 disable_pil_irq(irq);
364 kstat_cpu(cpu).irqs[irq]++;
365 floppy_interrupt(irq, dev_id);
368 set_irq_regs(old_regs);
369 // XXX Eek, it's totally changed with preempt_count() and such
370 // if (softirq_pending(cpu))
375 /* Fast IRQ's on the Sparc can only have one routine attached to them,
376 * thus no sharing possible.
378 int request_fast_irq(unsigned int irq,
379 irq_handler_t handler,
380 unsigned long irqflags, const char *devname)
382 struct irqaction *action;
384 unsigned int cpu_irq;
387 struct tt_entry *trap_table;
388 extern struct tt_entry trapbase_cpu1, trapbase_cpu2, trapbase_cpu3;
391 cpu_irq = irq & (NR_IRQS - 1);
401 spin_lock_irqsave(&irq_action_lock, flags);
403 action = sparc_irq[cpu_irq].action;
405 if(action->flags & IRQF_SHARED)
406 panic("Trying to register fast irq when already shared.\n");
407 if(irqflags & IRQF_SHARED)
408 panic("Trying to register fast irq as shared.\n");
410 /* Anyway, someone already owns it so cannot be made fast. */
411 printk("request_fast_irq: Trying to register yet already owned.\n");
416 /* If this is flagged as statically allocated then we use our
417 * private struct which is never freed.
419 if (irqflags & SA_STATIC_ALLOC) {
420 if (static_irq_count < MAX_STATIC_ALLOC)
421 action = &static_irqaction[static_irq_count++];
423 printk("Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
428 action = kmalloc(sizeof(struct irqaction),
436 /* Dork with trap table if we get this far. */
437 #define INSTANTIATE(table) \
438 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
439 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
440 SPARC_BRANCH((unsigned long) handler, \
441 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
442 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
443 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
445 INSTANTIATE(sparc_ttable)
447 trap_table = &trapbase_cpu1; INSTANTIATE(trap_table)
448 trap_table = &trapbase_cpu2; INSTANTIATE(trap_table)
449 trap_table = &trapbase_cpu3; INSTANTIATE(trap_table)
453 * XXX Correct thing whould be to flush only I- and D-cache lines
454 * which contain the handler in question. But as of time of the
455 * writing we have no CPU-neutral interface to fine-grained flushes.
459 action->handler = handler;
460 action->flags = irqflags;
461 cpus_clear(action->mask);
462 action->name = devname;
463 action->dev_id = NULL;
466 sparc_irq[cpu_irq].action = action;
472 spin_unlock_irqrestore(&irq_action_lock, flags);
477 int request_irq(unsigned int irq,
478 irq_handler_t handler,
479 unsigned long irqflags, const char * devname, void *dev_id)
481 struct irqaction * action, **actionp;
483 unsigned int cpu_irq;
486 if (sparc_cpu_model == sun4d) {
487 extern int sun4d_request_irq(unsigned int,
489 unsigned long, const char *, void *);
490 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
492 cpu_irq = irq & (NR_IRQS - 1);
502 spin_lock_irqsave(&irq_action_lock, flags);
504 actionp = &sparc_irq[cpu_irq].action;
507 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
511 if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
512 printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq);
516 for ( ; action; action = *actionp)
517 actionp = &action->next;
520 /* If this is flagged as statically allocated then we use our
521 * private struct which is never freed.
523 if (irqflags & SA_STATIC_ALLOC) {
524 if (static_irq_count < MAX_STATIC_ALLOC)
525 action = &static_irqaction[static_irq_count++];
527 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", irq, devname);
531 action = kmalloc(sizeof(struct irqaction),
539 action->handler = handler;
540 action->flags = irqflags;
541 cpus_clear(action->mask);
542 action->name = devname;
544 action->dev_id = dev_id;
552 spin_unlock_irqrestore(&irq_action_lock, flags);
557 EXPORT_SYMBOL(request_irq);
559 /* We really don't need these at all on the Sparc. We only have
560 * stubs here because they are exported to modules.
562 unsigned long probe_irq_on(void)
567 EXPORT_SYMBOL(probe_irq_on);
569 int probe_irq_off(unsigned long mask)
574 EXPORT_SYMBOL(probe_irq_off);
577 * This could probably be made indirect too and assigned in the CPU
578 * bits of the code. That would be much nicer I think and would also
579 * fit in with the idea of being able to tune your kernel for your machine
580 * by removing unrequired machine and device support.
584 void __init init_IRQ(void)
586 extern void sun4c_init_IRQ( void );
587 extern void sun4m_init_IRQ( void );
588 extern void sun4d_init_IRQ( void );
590 switch(sparc_cpu_model) {
599 if (pcic_present()) {
600 sun4m_pci_init_IRQ();
612 prom_printf("Cannot initialize IRQ's on this Sun machine...");
618 void init_irq_proc(void)
620 /* For now, nothing... */