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 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.
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/delay.h>
28 #include <linux/threads.h>
29 #include <linux/spinlock.h>
30 #include <linux/seq_file.h>
32 #include <asm/ptrace.h>
33 #include <asm/processor.h>
34 #include <asm/system.h>
37 #include <asm/vaddrs.h>
38 #include <asm/timer.h>
39 #include <asm/openprom.h>
40 #include <asm/oplib.h>
41 #include <asm/traps.h>
44 #include <asm/pgalloc.h>
45 #include <asm/pgtable.h>
47 #include <asm/cacheflush.h>
48 #include <asm/irq_regs.h>
53 #define SMP_NOP2 "nop; nop;\n\t"
54 #define SMP_NOP3 "nop; nop; nop;\n\t"
59 unsigned long __raw_local_irq_save(void)
66 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
70 : "=&r" (retval), "=r" (tmp)
77 void raw_local_irq_enable(void)
83 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
92 void raw_local_irq_restore(unsigned long old_psr)
99 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
100 "andn %0, %1, %0\n\t"
101 "wr %0, %2, %%psr\n\t"
104 : "i" (PSR_PIL), "r" (old_psr)
108 EXPORT_SYMBOL(__raw_local_irq_save);
109 EXPORT_SYMBOL(raw_local_irq_enable);
110 EXPORT_SYMBOL(raw_local_irq_restore);
113 * Dave Redman (djhr@tadpole.co.uk)
115 * IRQ numbers.. These are no longer restricted to 15..
117 * this is done to enable SBUS cards and onboard IO to be masked
118 * correctly. using the interrupt level isn't good enough.
121 * A device interrupting at sbus level6 and the Floppy both come in
122 * at IRQ11, but enabling and disabling them requires writing to
123 * different bits in the SLAVIO/SEC.
125 * As a result of these changes sun4m machines could now support
126 * directed CPU interrupts using the existing enable/disable irq code
131 static void irq_panic(void)
133 extern char *cputypval;
134 prom_printf("machine: %s doesn't have irq handlers defined!\n",cputypval);
138 void (*sparc_init_timers)(irq_handler_t ) =
139 (void (*)(irq_handler_t )) irq_panic;
142 * Dave Redman (djhr@tadpole.co.uk)
144 * There used to be extern calls and hard coded values here.. very sucky!
145 * instead, because some of the devices attach very early, I do something
146 * equally sucky but at least we'll never try to free statically allocated
147 * space or call kmalloc before kmalloc_init :(.
149 * In fact it's the timer10 that attaches first.. then timer14
150 * then kmalloc_init is called.. then the tty interrupts attach.
154 #define MAX_STATIC_ALLOC 4
155 struct irqaction static_irqaction[MAX_STATIC_ALLOC];
156 int static_irq_count;
159 struct irqaction *action;
161 } sparc_irq[NR_IRQS];
162 #define SPARC_IRQ_INPROGRESS 1
164 /* Used to protect the IRQ action lists */
165 DEFINE_SPINLOCK(irq_action_lock);
167 int show_interrupts(struct seq_file *p, void *v)
169 int i = *(loff_t *) v;
170 struct irqaction * action;
176 if (sparc_cpu_model == sun4d) {
177 extern int show_sun4d_interrupts(struct seq_file *, void *);
179 return show_sun4d_interrupts(p, v);
181 spin_lock_irqsave(&irq_action_lock, flags);
183 action = sparc_irq[i].action;
186 seq_printf(p, "%3d: ", i);
188 seq_printf(p, "%10u ", kstat_irqs(i));
190 for_each_online_cpu(j) {
191 seq_printf(p, "%10u ",
192 kstat_cpu(j).irqs[i]);
195 seq_printf(p, " %c %s",
196 (action->flags & IRQF_DISABLED) ? '+' : ' ',
198 for (action=action->next; action; action = action->next) {
199 seq_printf(p, ",%s %s",
200 (action->flags & IRQF_DISABLED) ? " +" : "",
206 spin_unlock_irqrestore(&irq_action_lock, flags);
210 void free_irq(unsigned int irq, void *dev_id)
212 struct irqaction * action;
213 struct irqaction **actionp;
215 unsigned int cpu_irq;
217 if (sparc_cpu_model == sun4d) {
218 extern void sun4d_free_irq(unsigned int, void *);
220 sun4d_free_irq(irq, dev_id);
223 cpu_irq = irq & (NR_IRQS - 1);
224 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
225 printk("Trying to free bogus IRQ %d\n", irq);
229 spin_lock_irqsave(&irq_action_lock, flags);
231 actionp = &sparc_irq[cpu_irq].action;
234 if (!action->handler) {
235 printk("Trying to free free IRQ%d\n",irq);
239 for (; action; action = action->next) {
240 if (action->dev_id == dev_id)
242 actionp = &action->next;
245 printk("Trying to free free shared IRQ%d\n",irq);
248 } else if (action->flags & IRQF_SHARED) {
249 printk("Trying to free shared IRQ%d with NULL device ID\n", irq);
252 if (action->flags & SA_STATIC_ALLOC)
254 /* This interrupt is marked as specially allocated
255 * so it is a bad idea to free it.
257 printk("Attempt to free statically allocated IRQ%d (%s)\n",
262 *actionp = action->next;
264 spin_unlock_irqrestore(&irq_action_lock, flags);
266 synchronize_irq(irq);
268 spin_lock_irqsave(&irq_action_lock, flags);
272 if (!sparc_irq[cpu_irq].action)
276 spin_unlock_irqrestore(&irq_action_lock, flags);
279 EXPORT_SYMBOL(free_irq);
282 * This is called when we want to synchronize with
283 * interrupts. We may for example tell a device to
284 * stop sending interrupts: but to make sure there
285 * are no interrupts that are executing on another
286 * CPU we need to call this function.
289 void synchronize_irq(unsigned int irq)
291 unsigned int cpu_irq;
293 cpu_irq = irq & (NR_IRQS - 1);
294 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
299 void unexpected_irq(int irq, void *dev_id, struct pt_regs * regs)
302 struct irqaction * action;
303 unsigned int cpu_irq;
305 cpu_irq = irq & (NR_IRQS - 1);
306 action = sparc_irq[cpu_irq].action;
308 printk("IO device interrupt, irq = %d\n", irq);
309 printk("PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
310 regs->npc, regs->u_regs[14]);
312 printk("Expecting: ");
313 for (i = 0; i < 16; i++)
315 printk("[%s:%d:0x%x] ", action->name,
316 (int) i, (unsigned int) action->handler);
319 panic("bogus interrupt received");
322 void handler_irq(int irq, struct pt_regs * regs)
324 struct pt_regs *old_regs;
325 struct irqaction * action;
326 int cpu = smp_processor_id();
328 extern void smp4m_irq_rotate(int cpu);
331 old_regs = set_irq_regs(regs);
333 disable_pil_irq(irq);
335 /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
336 if((sparc_cpu_model==sun4m) && (irq < 10))
337 smp4m_irq_rotate(cpu);
339 action = sparc_irq[irq].action;
340 sparc_irq[irq].flags |= SPARC_IRQ_INPROGRESS;
341 kstat_cpu(cpu).irqs[irq]++;
343 if (!action || !action->handler)
344 unexpected_irq(irq, NULL, regs);
345 action->handler(irq, action->dev_id);
346 action = action->next;
348 sparc_irq[irq].flags &= ~SPARC_IRQ_INPROGRESS;
351 set_irq_regs(old_regs);
354 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
356 /* Fast IRQs on the Sparc can only have one routine attached to them,
357 * thus no sharing possible.
359 static int request_fast_irq(unsigned int irq,
360 void (*handler)(void),
361 unsigned long irqflags, const char *devname)
363 struct irqaction *action;
365 unsigned int cpu_irq;
368 struct tt_entry *trap_table;
369 extern struct tt_entry trapbase_cpu1, trapbase_cpu2, trapbase_cpu3;
372 cpu_irq = irq & (NR_IRQS - 1);
382 spin_lock_irqsave(&irq_action_lock, flags);
384 action = sparc_irq[cpu_irq].action;
386 if(action->flags & IRQF_SHARED)
387 panic("Trying to register fast irq when already shared.\n");
388 if(irqflags & IRQF_SHARED)
389 panic("Trying to register fast irq as shared.\n");
391 /* Anyway, someone already owns it so cannot be made fast. */
392 printk("request_fast_irq: Trying to register yet already owned.\n");
397 /* If this is flagged as statically allocated then we use our
398 * private struct which is never freed.
400 if (irqflags & SA_STATIC_ALLOC) {
401 if (static_irq_count < MAX_STATIC_ALLOC)
402 action = &static_irqaction[static_irq_count++];
404 printk("Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
409 action = kmalloc(sizeof(struct irqaction),
417 /* Dork with trap table if we get this far. */
418 #define INSTANTIATE(table) \
419 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
420 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
421 SPARC_BRANCH((unsigned long) handler, \
422 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
423 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
424 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
426 INSTANTIATE(sparc_ttable)
428 trap_table = &trapbase_cpu1; INSTANTIATE(trap_table)
429 trap_table = &trapbase_cpu2; INSTANTIATE(trap_table)
430 trap_table = &trapbase_cpu3; INSTANTIATE(trap_table)
434 * XXX Correct thing whould be to flush only I- and D-cache lines
435 * which contain the handler in question. But as of time of the
436 * writing we have no CPU-neutral interface to fine-grained flushes.
440 action->flags = irqflags;
441 cpus_clear(action->mask);
442 action->name = devname;
443 action->dev_id = NULL;
446 sparc_irq[cpu_irq].action = action;
452 spin_unlock_irqrestore(&irq_action_lock, flags);
457 /* These variables are used to access state from the assembler
458 * interrupt handler, floppy_hardint, so we cannot put these in
459 * the floppy driver image because that would not work in the
462 volatile unsigned char *fdc_status;
463 EXPORT_SYMBOL(fdc_status);
466 EXPORT_SYMBOL(pdma_vaddr);
468 unsigned long pdma_size;
469 EXPORT_SYMBOL(pdma_size);
471 volatile int doing_pdma;
472 EXPORT_SYMBOL(doing_pdma);
475 EXPORT_SYMBOL(pdma_base);
477 unsigned long pdma_areasize;
478 EXPORT_SYMBOL(pdma_areasize);
480 extern void floppy_hardint(void);
482 static irqreturn_t (*floppy_irq_handler)(int irq, void *dev_id);
484 void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
486 struct pt_regs *old_regs;
487 int cpu = smp_processor_id();
489 old_regs = set_irq_regs(regs);
490 disable_pil_irq(irq);
492 kstat_cpu(cpu).irqs[irq]++;
493 floppy_irq_handler(irq, dev_id);
496 set_irq_regs(old_regs);
497 // XXX Eek, it's totally changed with preempt_count() and such
498 // if (softirq_pending(cpu))
502 int sparc_floppy_request_irq(int irq, unsigned long flags,
503 irqreturn_t (*irq_handler)(int irq, void *))
505 floppy_irq_handler = irq_handler;
506 return request_fast_irq(irq, floppy_hardint, flags, "floppy");
508 EXPORT_SYMBOL(sparc_floppy_request_irq);
512 int request_irq(unsigned int irq,
513 irq_handler_t handler,
514 unsigned long irqflags, const char * devname, void *dev_id)
516 struct irqaction * action, **actionp;
518 unsigned int cpu_irq;
521 if (sparc_cpu_model == sun4d) {
522 extern int sun4d_request_irq(unsigned int,
524 unsigned long, const char *, void *);
525 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
527 cpu_irq = irq & (NR_IRQS - 1);
537 spin_lock_irqsave(&irq_action_lock, flags);
539 actionp = &sparc_irq[cpu_irq].action;
542 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
546 if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
547 printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq);
551 for ( ; action; action = *actionp)
552 actionp = &action->next;
555 /* If this is flagged as statically allocated then we use our
556 * private struct which is never freed.
558 if (irqflags & SA_STATIC_ALLOC) {
559 if (static_irq_count < MAX_STATIC_ALLOC)
560 action = &static_irqaction[static_irq_count++];
562 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", irq, devname);
566 action = kmalloc(sizeof(struct irqaction),
574 action->handler = handler;
575 action->flags = irqflags;
576 cpus_clear(action->mask);
577 action->name = devname;
579 action->dev_id = dev_id;
587 spin_unlock_irqrestore(&irq_action_lock, flags);
592 EXPORT_SYMBOL(request_irq);
594 void disable_irq_nosync(unsigned int irq)
596 return __disable_irq(irq);
598 EXPORT_SYMBOL(disable_irq_nosync);
600 void disable_irq(unsigned int irq)
602 return __disable_irq(irq);
604 EXPORT_SYMBOL(disable_irq);
606 void enable_irq(unsigned int irq)
608 return __enable_irq(irq);
611 EXPORT_SYMBOL(enable_irq);
613 /* We really don't need these at all on the Sparc. We only have
614 * stubs here because they are exported to modules.
616 unsigned long probe_irq_on(void)
621 EXPORT_SYMBOL(probe_irq_on);
623 int probe_irq_off(unsigned long mask)
628 EXPORT_SYMBOL(probe_irq_off);
631 * This could probably be made indirect too and assigned in the CPU
632 * bits of the code. That would be much nicer I think and would also
633 * fit in with the idea of being able to tune your kernel for your machine
634 * by removing unrequired machine and device support.
638 void __init init_IRQ(void)
640 extern void sun4c_init_IRQ( void );
641 extern void sun4m_init_IRQ( void );
642 extern void sun4d_init_IRQ( void );
644 switch(sparc_cpu_model) {
653 if (pcic_present()) {
654 sun4m_pci_init_IRQ();
666 prom_printf("Cannot initialize IRQs on this Sun machine...");
672 void init_irq_proc(void)
674 /* For now, nothing... */