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>
51 #define SMP_NOP2 "nop; nop;\n\t"
52 #define SMP_NOP3 "nop; nop; nop;\n\t"
57 unsigned long __local_irq_save(void)
64 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
68 : "=&r" (retval), "=r" (tmp)
75 void local_irq_enable(void)
81 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
90 void local_irq_restore(unsigned long old_psr)
97 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
99 "wr %0, %2, %%psr\n\t"
102 : "i" (PSR_PIL), "r" (old_psr)
106 EXPORT_SYMBOL(__local_irq_save);
107 EXPORT_SYMBOL(local_irq_enable);
108 EXPORT_SYMBOL(local_irq_restore);
111 * Dave Redman (djhr@tadpole.co.uk)
113 * IRQ numbers.. These are no longer restricted to 15..
115 * this is done to enable SBUS cards and onboard IO to be masked
116 * correctly. using the interrupt level isn't good enough.
119 * A device interrupting at sbus level6 and the Floppy both come in
120 * at IRQ11, but enabling and disabling them requires writing to
121 * different bits in the SLAVIO/SEC.
123 * As a result of these changes sun4m machines could now support
124 * directed CPU interrupts using the existing enable/disable irq code
129 static void irq_panic(void)
131 extern char *cputypval;
132 prom_printf("machine: %s doesn't have irq handlers defined!\n",cputypval);
136 void (*sparc_init_timers)(irqreturn_t (*)(int, void *,struct pt_regs *)) =
137 (void (*)(irqreturn_t (*)(int, void *,struct pt_regs *))) irq_panic;
140 * Dave Redman (djhr@tadpole.co.uk)
142 * There used to be extern calls and hard coded values here.. very sucky!
143 * instead, because some of the devices attach very early, I do something
144 * equally sucky but at least we'll never try to free statically allocated
145 * space or call kmalloc before kmalloc_init :(.
147 * In fact it's the timer10 that attaches first.. then timer14
148 * then kmalloc_init is called.. then the tty interrupts attach.
152 #define MAX_STATIC_ALLOC 4
153 struct irqaction static_irqaction[MAX_STATIC_ALLOC];
154 int static_irq_count;
157 struct irqaction *action;
159 } sparc_irq[NR_IRQS];
160 #define SPARC_IRQ_INPROGRESS 1
162 /* Used to protect the IRQ action lists */
163 DEFINE_SPINLOCK(irq_action_lock);
165 int show_interrupts(struct seq_file *p, void *v)
167 int i = *(loff_t *) v;
168 struct irqaction * action;
174 if (sparc_cpu_model == sun4d) {
175 extern int show_sun4d_interrupts(struct seq_file *, void *);
177 return show_sun4d_interrupts(p, v);
179 spin_lock_irqsave(&irq_action_lock, flags);
181 action = sparc_irq[i].action;
184 seq_printf(p, "%3d: ", i);
186 seq_printf(p, "%10u ", kstat_irqs(i));
188 for_each_online_cpu(j) {
189 seq_printf(p, "%10u ",
190 kstat_cpu(j).irqs[i]);
193 seq_printf(p, " %c %s",
194 (action->flags & IRQF_DISABLED) ? '+' : ' ',
196 for (action=action->next; action; action = action->next) {
197 seq_printf(p, ",%s %s",
198 (action->flags & IRQF_DISABLED) ? " +" : "",
204 spin_unlock_irqrestore(&irq_action_lock, flags);
208 void free_irq(unsigned int irq, void *dev_id)
210 struct irqaction * action;
211 struct irqaction **actionp;
213 unsigned int cpu_irq;
215 if (sparc_cpu_model == sun4d) {
216 extern void sun4d_free_irq(unsigned int, void *);
218 sun4d_free_irq(irq, dev_id);
221 cpu_irq = irq & (NR_IRQS - 1);
222 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
223 printk("Trying to free bogus IRQ %d\n", irq);
227 spin_lock_irqsave(&irq_action_lock, flags);
229 actionp = &sparc_irq[cpu_irq].action;
232 if (!action->handler) {
233 printk("Trying to free free IRQ%d\n",irq);
237 for (; action; action = action->next) {
238 if (action->dev_id == dev_id)
240 actionp = &action->next;
243 printk("Trying to free free shared IRQ%d\n",irq);
246 } else if (action->flags & IRQF_SHARED) {
247 printk("Trying to free shared IRQ%d with NULL device ID\n", irq);
250 if (action->flags & SA_STATIC_ALLOC)
252 /* This interrupt is marked as specially allocated
253 * so it is a bad idea to free it.
255 printk("Attempt to free statically allocated IRQ%d (%s)\n",
260 *actionp = action->next;
262 spin_unlock_irqrestore(&irq_action_lock, flags);
264 synchronize_irq(irq);
266 spin_lock_irqsave(&irq_action_lock, flags);
270 if (!sparc_irq[cpu_irq].action)
274 spin_unlock_irqrestore(&irq_action_lock, flags);
277 EXPORT_SYMBOL(free_irq);
280 * This is called when we want to synchronize with
281 * interrupts. We may for example tell a device to
282 * stop sending interrupts: but to make sure there
283 * are no interrupts that are executing on another
284 * CPU we need to call this function.
287 void synchronize_irq(unsigned int irq)
289 unsigned int cpu_irq;
291 cpu_irq = irq & (NR_IRQS - 1);
292 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
297 void unexpected_irq(int irq, void *dev_id, struct pt_regs * regs)
300 struct irqaction * action;
301 unsigned int cpu_irq;
303 cpu_irq = irq & (NR_IRQS - 1);
304 action = sparc_irq[cpu_irq].action;
306 printk("IO device interrupt, irq = %d\n", irq);
307 printk("PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
308 regs->npc, regs->u_regs[14]);
310 printk("Expecting: ");
311 for (i = 0; i < 16; i++)
313 printk("[%s:%d:0x%x] ", action->name,
314 (int) i, (unsigned int) action->handler);
317 panic("bogus interrupt received");
320 void handler_irq(int irq, struct pt_regs * regs)
322 struct irqaction * action;
323 int cpu = smp_processor_id();
325 extern void smp4m_irq_rotate(int cpu);
329 disable_pil_irq(irq);
331 /* Only rotate on lower priority IRQ's (scsi, ethernet, etc.). */
332 if((sparc_cpu_model==sun4m) && (irq < 10))
333 smp4m_irq_rotate(cpu);
335 action = sparc_irq[irq].action;
336 sparc_irq[irq].flags |= SPARC_IRQ_INPROGRESS;
337 kstat_cpu(cpu).irqs[irq]++;
339 if (!action || !action->handler)
340 unexpected_irq(irq, NULL, regs);
341 action->handler(irq, action->dev_id, regs);
342 action = action->next;
344 sparc_irq[irq].flags &= ~SPARC_IRQ_INPROGRESS;
349 #ifdef CONFIG_BLK_DEV_FD
350 extern void floppy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
352 void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
354 int cpu = smp_processor_id();
356 disable_pil_irq(irq);
358 kstat_cpu(cpu).irqs[irq]++;
359 floppy_interrupt(irq, dev_id, regs);
362 // XXX Eek, it's totally changed with preempt_count() and such
363 // if (softirq_pending(cpu))
368 /* Fast IRQ's on the Sparc can only have one routine attached to them,
369 * thus no sharing possible.
371 int request_fast_irq(unsigned int irq,
372 irqreturn_t (*handler)(int, void *, struct pt_regs *),
373 unsigned long irqflags, const char *devname)
375 struct irqaction *action;
377 unsigned int cpu_irq;
380 struct tt_entry *trap_table;
381 extern struct tt_entry trapbase_cpu1, trapbase_cpu2, trapbase_cpu3;
384 cpu_irq = irq & (NR_IRQS - 1);
394 spin_lock_irqsave(&irq_action_lock, flags);
396 action = sparc_irq[cpu_irq].action;
398 if(action->flags & IRQF_SHARED)
399 panic("Trying to register fast irq when already shared.\n");
400 if(irqflags & IRQF_SHARED)
401 panic("Trying to register fast irq as shared.\n");
403 /* Anyway, someone already owns it so cannot be made fast. */
404 printk("request_fast_irq: Trying to register yet already owned.\n");
409 /* If this is flagged as statically allocated then we use our
410 * private struct which is never freed.
412 if (irqflags & SA_STATIC_ALLOC) {
413 if (static_irq_count < MAX_STATIC_ALLOC)
414 action = &static_irqaction[static_irq_count++];
416 printk("Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
421 action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
429 /* Dork with trap table if we get this far. */
430 #define INSTANTIATE(table) \
431 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
432 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
433 SPARC_BRANCH((unsigned long) handler, \
434 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
435 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
436 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
438 INSTANTIATE(sparc_ttable)
440 trap_table = &trapbase_cpu1; INSTANTIATE(trap_table)
441 trap_table = &trapbase_cpu2; INSTANTIATE(trap_table)
442 trap_table = &trapbase_cpu3; INSTANTIATE(trap_table)
446 * XXX Correct thing whould be to flush only I- and D-cache lines
447 * which contain the handler in question. But as of time of the
448 * writing we have no CPU-neutral interface to fine-grained flushes.
452 action->handler = handler;
453 action->flags = irqflags;
454 cpus_clear(action->mask);
455 action->name = devname;
456 action->dev_id = NULL;
459 sparc_irq[cpu_irq].action = action;
465 spin_unlock_irqrestore(&irq_action_lock, flags);
470 int request_irq(unsigned int irq,
471 irqreturn_t (*handler)(int, void *, struct pt_regs *),
472 unsigned long irqflags, const char * devname, void *dev_id)
474 struct irqaction * action, **actionp;
476 unsigned int cpu_irq;
479 if (sparc_cpu_model == sun4d) {
480 extern int sun4d_request_irq(unsigned int,
481 irqreturn_t (*)(int, void *, struct pt_regs *),
482 unsigned long, const char *, void *);
483 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
485 cpu_irq = irq & (NR_IRQS - 1);
495 spin_lock_irqsave(&irq_action_lock, flags);
497 actionp = &sparc_irq[cpu_irq].action;
500 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
504 if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
505 printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq);
509 for ( ; action; action = *actionp)
510 actionp = &action->next;
513 /* If this is flagged as statically allocated then we use our
514 * private struct which is never freed.
516 if (irqflags & SA_STATIC_ALLOC) {
517 if (static_irq_count < MAX_STATIC_ALLOC)
518 action = &static_irqaction[static_irq_count++];
520 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", irq, devname);
524 action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
532 action->handler = handler;
533 action->flags = irqflags;
534 cpus_clear(action->mask);
535 action->name = devname;
537 action->dev_id = dev_id;
545 spin_unlock_irqrestore(&irq_action_lock, flags);
550 EXPORT_SYMBOL(request_irq);
552 /* We really don't need these at all on the Sparc. We only have
553 * stubs here because they are exported to modules.
555 unsigned long probe_irq_on(void)
560 EXPORT_SYMBOL(probe_irq_on);
562 int probe_irq_off(unsigned long mask)
567 EXPORT_SYMBOL(probe_irq_off);
570 * This could probably be made indirect too and assigned in the CPU
571 * bits of the code. That would be much nicer I think and would also
572 * fit in with the idea of being able to tune your kernel for your machine
573 * by removing unrequired machine and device support.
577 void __init init_IRQ(void)
579 extern void sun4c_init_IRQ( void );
580 extern void sun4m_init_IRQ( void );
581 extern void sun4d_init_IRQ( void );
583 switch(sparc_cpu_model) {
592 if (pcic_present()) {
593 sun4m_pci_init_IRQ();
605 prom_printf("Cannot initialize IRQ's on this Sun machine...");
611 void init_irq_proc(void)
613 /* For now, nothing... */