2 * 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.
14 #include <linux/kernel_stat.h>
15 #include <linux/seq_file.h>
17 #include <asm/cacheflush.h>
25 #define SMP_NOP2 "nop; nop;\n\t"
26 #define SMP_NOP3 "nop; nop; nop;\n\t"
32 /* platform specific irq setup */
33 struct sparc_irq_config sparc_irq_config;
35 unsigned long arch_local_irq_save(void)
42 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
46 : "=&r" (retval), "=r" (tmp)
52 EXPORT_SYMBOL(arch_local_irq_save);
54 void arch_local_irq_enable(void)
60 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
68 EXPORT_SYMBOL(arch_local_irq_enable);
70 void arch_local_irq_restore(unsigned long old_psr)
77 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
79 "wr %0, %2, %%psr\n\t"
82 : "i" (PSR_PIL), "r" (old_psr)
85 EXPORT_SYMBOL(arch_local_irq_restore);
90 * IRQ numbers.. These are no longer restricted to 15..
92 * this is done to enable SBUS cards and onboard IO to be masked
93 * correctly. using the interrupt level isn't good enough.
96 * A device interrupting at sbus level6 and the Floppy both come in
97 * at IRQ11, but enabling and disabling them requires writing to
98 * different bits in the SLAVIO/SEC.
100 * As a result of these changes sun4m machines could now support
101 * directed CPU interrupts using the existing enable/disable irq code
111 * There used to be extern calls and hard coded values here.. very sucky!
112 * instead, because some of the devices attach very early, I do something
113 * equally sucky but at least we'll never try to free statically allocated
114 * space or call kmalloc before kmalloc_init :(.
116 * In fact it's the timer10 that attaches first.. then timer14
117 * then kmalloc_init is called.. then the tty interrupts attach.
121 #define MAX_STATIC_ALLOC 4
122 struct irqaction static_irqaction[MAX_STATIC_ALLOC];
123 int static_irq_count;
126 struct irqaction *action;
128 } sparc_irq[NR_IRQS];
129 #define SPARC_IRQ_INPROGRESS 1
131 /* Used to protect the IRQ action lists */
132 DEFINE_SPINLOCK(irq_action_lock);
134 int show_interrupts(struct seq_file *p, void *v)
136 int i = *(loff_t *)v;
137 struct irqaction *action;
143 if (sparc_cpu_model == sun4d)
144 return show_sun4d_interrupts(p, v);
146 spin_lock_irqsave(&irq_action_lock, flags);
148 action = sparc_irq[i].action;
151 seq_printf(p, "%3d: ", i);
153 seq_printf(p, "%10u ", kstat_irqs(i));
155 for_each_online_cpu(j) {
156 seq_printf(p, "%10u ",
157 kstat_cpu(j).irqs[i]);
160 seq_printf(p, " %c %s",
161 (action->flags & IRQF_DISABLED) ? '+' : ' ',
163 for (action = action->next; action; action = action->next) {
164 seq_printf(p, ",%s %s",
165 (action->flags & IRQF_DISABLED) ? " +" : "",
171 spin_unlock_irqrestore(&irq_action_lock, flags);
175 void free_irq(unsigned int irq, void *dev_id)
177 struct irqaction *action;
178 struct irqaction **actionp;
180 unsigned int cpu_irq;
182 if (sparc_cpu_model == sun4d) {
183 sun4d_free_irq(irq, dev_id);
186 cpu_irq = irq & (NR_IRQS - 1);
187 if (cpu_irq > 14) { /* 14 irq levels on the sparc */
188 printk(KERN_ERR "Trying to free bogus IRQ %d\n", irq);
192 spin_lock_irqsave(&irq_action_lock, flags);
194 actionp = &sparc_irq[cpu_irq].action;
197 if (!action->handler) {
198 printk(KERN_ERR "Trying to free free IRQ%d\n", irq);
202 for (; action; action = action->next) {
203 if (action->dev_id == dev_id)
205 actionp = &action->next;
208 printk(KERN_ERR "Trying to free free shared IRQ%d\n",
212 } else if (action->flags & IRQF_SHARED) {
213 printk(KERN_ERR "Trying to free shared IRQ%d with NULL device ID\n",
217 if (action->flags & SA_STATIC_ALLOC) {
219 * This interrupt is marked as specially allocated
220 * so it is a bad idea to free it.
222 printk(KERN_ERR "Attempt to free statically allocated IRQ%d (%s)\n",
227 *actionp = action->next;
229 spin_unlock_irqrestore(&irq_action_lock, flags);
231 synchronize_irq(irq);
233 spin_lock_irqsave(&irq_action_lock, flags);
237 if (!sparc_irq[cpu_irq].action)
241 spin_unlock_irqrestore(&irq_action_lock, flags);
243 EXPORT_SYMBOL(free_irq);
246 * This is called when we want to synchronize with
247 * interrupts. We may for example tell a device to
248 * stop sending interrupts: but to make sure there
249 * are no interrupts that are executing on another
250 * CPU we need to call this function.
253 void synchronize_irq(unsigned int irq)
255 unsigned int cpu_irq;
257 cpu_irq = irq & (NR_IRQS - 1);
258 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
261 EXPORT_SYMBOL(synchronize_irq);
264 void unexpected_irq(int irq, void *dev_id, struct pt_regs *regs)
267 struct irqaction *action;
268 unsigned int cpu_irq;
270 cpu_irq = irq & (NR_IRQS - 1);
271 action = sparc_irq[cpu_irq].action;
273 printk(KERN_ERR "IO device interrupt, irq = %d\n", irq);
274 printk(KERN_ERR "PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
275 regs->npc, regs->u_regs[14]);
277 printk(KERN_ERR "Expecting: ");
278 for (i = 0; i < 16; i++)
280 printk(KERN_CONT "[%s:%d:0x%x] ", action->name,
281 i, (unsigned int)action->handler);
283 printk(KERN_ERR "AIEEE\n");
284 panic("bogus interrupt received");
287 void handler_irq(int pil, struct pt_regs *regs)
289 struct pt_regs *old_regs;
290 struct irqaction *action;
291 int cpu = smp_processor_id();
293 old_regs = set_irq_regs(regs);
295 disable_pil_irq(pil);
297 /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
298 if ((sparc_cpu_model==sun4m) && (pil < 10))
299 smp4m_irq_rotate(cpu);
301 action = sparc_irq[pil].action;
302 sparc_irq[pil].flags |= SPARC_IRQ_INPROGRESS;
303 kstat_cpu(cpu).irqs[pil]++;
305 if (!action || !action->handler)
306 unexpected_irq(pil, NULL, regs);
307 action->handler(pil, action->dev_id);
308 action = action->next;
310 sparc_irq[pil].flags &= ~SPARC_IRQ_INPROGRESS;
313 set_irq_regs(old_regs);
316 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
319 * Fast IRQs on the Sparc can only have one routine attached to them,
320 * thus no sharing possible.
322 static int request_fast_irq(unsigned int irq,
323 void (*handler)(void),
324 unsigned long irqflags, const char *devname)
326 struct irqaction *action;
328 unsigned int cpu_irq;
330 #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
331 struct tt_entry *trap_table;
333 cpu_irq = irq & (NR_IRQS - 1);
343 spin_lock_irqsave(&irq_action_lock, flags);
345 action = sparc_irq[cpu_irq].action;
347 if (action->flags & IRQF_SHARED)
348 panic("Trying to register fast irq when already shared.\n");
349 if (irqflags & IRQF_SHARED)
350 panic("Trying to register fast irq as shared.\n");
352 /* Anyway, someone already owns it so cannot be made fast. */
353 printk(KERN_ERR "request_fast_irq: Trying to register yet already owned.\n");
359 * If this is flagged as statically allocated then we use our
360 * private struct which is never freed.
362 if (irqflags & SA_STATIC_ALLOC) {
363 if (static_irq_count < MAX_STATIC_ALLOC)
364 action = &static_irqaction[static_irq_count++];
366 printk(KERN_ERR "Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
371 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
377 /* Dork with trap table if we get this far. */
378 #define INSTANTIATE(table) \
379 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
380 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
381 SPARC_BRANCH((unsigned long) handler, \
382 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
383 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
384 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
386 INSTANTIATE(sparc_ttable)
387 #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
388 trap_table = &trapbase_cpu1;
389 INSTANTIATE(trap_table)
390 trap_table = &trapbase_cpu2;
391 INSTANTIATE(trap_table)
392 trap_table = &trapbase_cpu3;
393 INSTANTIATE(trap_table)
397 * XXX Correct thing whould be to flush only I- and D-cache lines
398 * which contain the handler in question. But as of time of the
399 * writing we have no CPU-neutral interface to fine-grained flushes.
403 action->flags = irqflags;
404 action->name = devname;
405 action->dev_id = NULL;
408 sparc_irq[cpu_irq].action = action;
414 spin_unlock_irqrestore(&irq_action_lock, flags);
420 * These variables are used to access state from the assembler
421 * interrupt handler, floppy_hardint, so we cannot put these in
422 * the floppy driver image because that would not work in the
425 volatile unsigned char *fdc_status;
426 EXPORT_SYMBOL(fdc_status);
429 EXPORT_SYMBOL(pdma_vaddr);
431 unsigned long pdma_size;
432 EXPORT_SYMBOL(pdma_size);
434 volatile int doing_pdma;
435 EXPORT_SYMBOL(doing_pdma);
438 EXPORT_SYMBOL(pdma_base);
440 unsigned long pdma_areasize;
441 EXPORT_SYMBOL(pdma_areasize);
443 static irq_handler_t floppy_irq_handler;
445 void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
447 struct pt_regs *old_regs;
448 int cpu = smp_processor_id();
450 old_regs = set_irq_regs(regs);
451 disable_pil_irq(irq);
453 kstat_cpu(cpu).irqs[irq]++;
454 floppy_irq_handler(irq, dev_id);
457 set_irq_regs(old_regs);
459 * XXX Eek, it's totally changed with preempt_count() and such
460 * if (softirq_pending(cpu))
465 int sparc_floppy_request_irq(int irq, unsigned long flags,
466 irq_handler_t irq_handler)
468 floppy_irq_handler = irq_handler;
469 return request_fast_irq(irq, floppy_hardint, flags, "floppy");
471 EXPORT_SYMBOL(sparc_floppy_request_irq);
475 int request_irq(unsigned int irq,
476 irq_handler_t handler,
477 unsigned long irqflags, const char *devname, void *dev_id)
479 struct irqaction *action, **actionp;
481 unsigned int cpu_irq;
484 if (sparc_cpu_model == sun4d)
485 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
487 cpu_irq = irq & (NR_IRQS - 1);
497 spin_lock_irqsave(&irq_action_lock, flags);
499 actionp = &sparc_irq[cpu_irq].action;
502 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
506 if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
507 printk(KERN_ERR "Attempt to mix fast and slow interrupts on IRQ%d denied\n",
512 for ( ; action; action = *actionp)
513 actionp = &action->next;
516 /* If this is flagged as statically allocated then we use our
517 * private struct which is never freed.
519 if (irqflags & SA_STATIC_ALLOC) {
520 if (static_irq_count < MAX_STATIC_ALLOC)
521 action = &static_irqaction[static_irq_count++];
523 printk(KERN_ERR "Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
527 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
533 action->handler = handler;
534 action->flags = irqflags;
535 action->name = devname;
537 action->dev_id = dev_id;
545 spin_unlock_irqrestore(&irq_action_lock, flags);
549 EXPORT_SYMBOL(request_irq);
551 void disable_irq_nosync(unsigned int irq)
555 EXPORT_SYMBOL(disable_irq_nosync);
557 void disable_irq(unsigned int irq)
561 EXPORT_SYMBOL(disable_irq);
563 void enable_irq(unsigned int irq)
567 EXPORT_SYMBOL(enable_irq);
570 * We really don't need these at all on the Sparc. We only have
571 * stubs here because they are exported to modules.
573 unsigned long probe_irq_on(void)
577 EXPORT_SYMBOL(probe_irq_on);
579 int probe_irq_off(unsigned long mask)
583 EXPORT_SYMBOL(probe_irq_off);
586 * This could probably be made indirect too and assigned in the CPU
587 * bits of the code. That would be much nicer I think and would also
588 * fit in with the idea of being able to tune your kernel for your machine
589 * by removing unrequired machine and device support.
593 void __init init_IRQ(void)
595 switch (sparc_cpu_model) {
604 if (pcic_present()) {
605 sun4m_pci_init_IRQ();
621 prom_printf("Cannot initialize IRQs on this Sun machine...");
627 #ifdef CONFIG_PROC_FS
628 void init_irq_proc(void)
630 /* For now, nothing... */
632 #endif /* CONFIG_PROC_FS */