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/config.h>
15 #include <linux/module.h>
16 #include <linux/sched.h>
17 #include <linux/ptrace.h>
18 #include <linux/errno.h>
19 #include <linux/linkage.h>
20 #include <linux/kernel_stat.h>
21 #include <linux/signal.h>
22 #include <linux/sched.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/random.h>
26 #include <linux/init.h>
27 #include <linux/smp.h>
28 #include <linux/smp_lock.h>
29 #include <linux/delay.h>
30 #include <linux/threads.h>
31 #include <linux/spinlock.h>
32 #include <linux/seq_file.h>
34 #include <asm/ptrace.h>
35 #include <asm/processor.h>
36 #include <asm/system.h>
39 #include <asm/vaddrs.h>
40 #include <asm/timer.h>
41 #include <asm/openprom.h>
42 #include <asm/oplib.h>
43 #include <asm/traps.h>
46 #include <asm/pgalloc.h>
47 #include <asm/pgtable.h>
49 #include <asm/cacheflush.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)(irqreturn_t (*)(int, void *,struct pt_regs *)) =
138 (void (*)(irqreturn_t (*)(int, void *,struct pt_regs *))) 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;
157 struct irqaction *irq_action[NR_IRQS] = {
158 [0 ... (NR_IRQS-1)] = NULL
161 /* Used to protect the IRQ action lists */
162 DEFINE_SPINLOCK(irq_action_lock);
164 int show_interrupts(struct seq_file *p, void *v)
166 int i = *(loff_t *) v;
167 struct irqaction * action;
173 if (sparc_cpu_model == sun4d) {
174 extern int show_sun4d_interrupts(struct seq_file *, void *);
176 return show_sun4d_interrupts(p, v);
178 spin_lock_irqsave(&irq_action_lock, flags);
180 action = *(i + irq_action);
183 seq_printf(p, "%3d: ", i);
185 seq_printf(p, "%10u ", kstat_irqs(i));
187 for_each_online_cpu(j) {
188 seq_printf(p, "%10u ",
189 kstat_cpu(cpu_logical_map(j)).irqs[i]);
192 seq_printf(p, " %c %s",
193 (action->flags & SA_INTERRUPT) ? '+' : ' ',
195 for (action=action->next; action; action = action->next) {
196 seq_printf(p, ",%s %s",
197 (action->flags & SA_INTERRUPT) ? " +" : "",
203 spin_unlock_irqrestore(&irq_action_lock, flags);
207 void free_irq(unsigned int irq, void *dev_id)
209 struct irqaction * action;
210 struct irqaction * tmp = NULL;
212 unsigned int cpu_irq;
214 if (sparc_cpu_model == sun4d) {
215 extern void sun4d_free_irq(unsigned int, void *);
217 sun4d_free_irq(irq, dev_id);
220 cpu_irq = irq & (NR_IRQS - 1);
221 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
222 printk("Trying to free bogus IRQ %d\n", irq);
226 spin_lock_irqsave(&irq_action_lock, flags);
228 action = *(cpu_irq + irq_action);
230 if (!action->handler) {
231 printk("Trying to free free IRQ%d\n",irq);
235 for (; action; action = action->next) {
236 if (action->dev_id == dev_id)
241 printk("Trying to free free shared IRQ%d\n",irq);
244 } else if (action->flags & SA_SHIRQ) {
245 printk("Trying to free shared IRQ%d with NULL device ID\n", irq);
248 if (action->flags & SA_STATIC_ALLOC)
250 /* This interrupt is marked as specially allocated
251 * so it is a bad idea to free it.
253 printk("Attempt to free statically allocated IRQ%d (%s)\n",
259 tmp->next = action->next;
261 *(cpu_irq + irq_action) = action->next;
263 spin_unlock_irqrestore(&irq_action_lock, flags);
265 synchronize_irq(irq);
267 spin_lock_irqsave(&irq_action_lock, flags);
271 if (!(*(cpu_irq + 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 printk("synchronize_irq says: implement me!\n");
295 void unexpected_irq(int irq, void *dev_id, struct pt_regs * regs)
298 struct irqaction * action;
299 unsigned int cpu_irq;
301 cpu_irq = irq & (NR_IRQS - 1);
302 action = *(cpu_irq + irq_action);
304 printk("IO device interrupt, irq = %d\n", irq);
305 printk("PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
306 regs->npc, regs->u_regs[14]);
308 printk("Expecting: ");
309 for (i = 0; i < 16; i++)
311 printk("[%s:%d:0x%x] ", action->name,
312 (int) i, (unsigned int) action->handler);
315 panic("bogus interrupt received");
318 void handler_irq(int irq, struct pt_regs * regs)
320 struct irqaction * action;
321 int cpu = smp_processor_id();
323 extern void smp4m_irq_rotate(int cpu);
327 disable_pil_irq(irq);
329 /* Only rotate on lower priority IRQ's (scsi, ethernet, etc.). */
331 smp4m_irq_rotate(cpu);
333 action = *(irq + irq_action);
334 kstat_cpu(cpu).irqs[irq]++;
336 if (!action || !action->handler)
337 unexpected_irq(irq, NULL, regs);
338 action->handler(irq, action->dev_id, regs);
339 action = action->next;
345 #ifdef CONFIG_BLK_DEV_FD
346 extern void floppy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
348 void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
350 int cpu = smp_processor_id();
352 disable_pil_irq(irq);
354 kstat_cpu(cpu).irqs[irq]++;
355 floppy_interrupt(irq, dev_id, regs);
358 // XXX Eek, it's totally changed with preempt_count() and such
359 // if (softirq_pending(cpu))
364 /* Fast IRQ's on the Sparc can only have one routine attached to them,
365 * thus no sharing possible.
367 int request_fast_irq(unsigned int irq,
368 irqreturn_t (*handler)(int, void *, struct pt_regs *),
369 unsigned long irqflags, const char *devname)
371 struct irqaction *action;
373 unsigned int cpu_irq;
376 struct tt_entry *trap_table;
377 extern struct tt_entry trapbase_cpu1, trapbase_cpu2, trapbase_cpu3;
380 cpu_irq = irq & (NR_IRQS - 1);
390 spin_lock_irqsave(&irq_action_lock, flags);
392 action = *(cpu_irq + irq_action);
394 if(action->flags & SA_SHIRQ)
395 panic("Trying to register fast irq when already shared.\n");
396 if(irqflags & SA_SHIRQ)
397 panic("Trying to register fast irq as shared.\n");
399 /* Anyway, someone already owns it so cannot be made fast. */
400 printk("request_fast_irq: Trying to register yet already owned.\n");
405 /* If this is flagged as statically allocated then we use our
406 * private struct which is never freed.
408 if (irqflags & SA_STATIC_ALLOC) {
409 if (static_irq_count < MAX_STATIC_ALLOC)
410 action = &static_irqaction[static_irq_count++];
412 printk("Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
417 action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
425 /* Dork with trap table if we get this far. */
426 #define INSTANTIATE(table) \
427 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
428 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
429 SPARC_BRANCH((unsigned long) handler, \
430 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
431 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
432 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
434 INSTANTIATE(sparc_ttable)
436 trap_table = &trapbase_cpu1; INSTANTIATE(trap_table)
437 trap_table = &trapbase_cpu2; INSTANTIATE(trap_table)
438 trap_table = &trapbase_cpu3; INSTANTIATE(trap_table)
442 * XXX Correct thing whould be to flush only I- and D-cache lines
443 * which contain the handler in question. But as of time of the
444 * writing we have no CPU-neutral interface to fine-grained flushes.
448 action->handler = handler;
449 action->flags = irqflags;
450 cpus_clear(action->mask);
451 action->name = devname;
452 action->dev_id = NULL;
455 *(cpu_irq + irq_action) = action;
461 spin_unlock_irqrestore(&irq_action_lock, flags);
466 int request_irq(unsigned int irq,
467 irqreturn_t (*handler)(int, void *, struct pt_regs *),
468 unsigned long irqflags, const char * devname, void *dev_id)
470 struct irqaction * action, *tmp = NULL;
472 unsigned int cpu_irq;
475 if (sparc_cpu_model == sun4d) {
476 extern int sun4d_request_irq(unsigned int,
477 irqreturn_t (*)(int, void *, struct pt_regs *),
478 unsigned long, const char *, void *);
479 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
481 cpu_irq = irq & (NR_IRQS - 1);
491 spin_lock_irqsave(&irq_action_lock, flags);
493 action = *(cpu_irq + irq_action);
495 if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) {
496 for (tmp = action; tmp->next; tmp = tmp->next);
501 if ((action->flags & SA_INTERRUPT) ^ (irqflags & SA_INTERRUPT)) {
502 printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq);
506 action = NULL; /* Or else! */
509 /* If this is flagged as statically allocated then we use our
510 * private struct which is never freed.
512 if (irqflags & SA_STATIC_ALLOC) {
513 if (static_irq_count < MAX_STATIC_ALLOC)
514 action = &static_irqaction[static_irq_count++];
516 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", irq, devname);
520 action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
528 action->handler = handler;
529 action->flags = irqflags;
530 cpus_clear(action->mask);
531 action->name = devname;
533 action->dev_id = dev_id;
538 *(cpu_irq + irq_action) = action;
544 spin_unlock_irqrestore(&irq_action_lock, flags);
549 EXPORT_SYMBOL(request_irq);
551 /* We really don't need these at all on the Sparc. We only have
552 * stubs here because they are exported to modules.
554 unsigned long probe_irq_on(void)
559 EXPORT_SYMBOL(probe_irq_on);
561 int probe_irq_off(unsigned long mask)
566 EXPORT_SYMBOL(probe_irq_off);
569 * This could probably be made indirect too and assigned in the CPU
570 * bits of the code. That would be much nicer I think and would also
571 * fit in with the idea of being able to tune your kernel for your machine
572 * by removing unrequired machine and device support.
576 void __init init_IRQ(void)
578 extern void sun4c_init_IRQ( void );
579 extern void sun4m_init_IRQ( void );
580 extern void sun4d_init_IRQ( void );
582 switch(sparc_cpu_model) {
591 if (pcic_present()) {
592 sun4m_pci_init_IRQ();
604 prom_printf("Cannot initialize IRQ's on this Sun machine...");
610 void init_irq_proc(void)
612 /* For now, nothing... */