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.
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/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 unsigned long arch_local_irq_save(void)
39 SMP_NOP3
/* Sun4m + Cypress + SMP bug */
43 : "=&r" (retval
), "=r" (tmp
)
49 EXPORT_SYMBOL(arch_local_irq_save
);
51 void arch_local_irq_enable(void)
57 SMP_NOP3
/* Sun4m + Cypress + SMP bug */
65 EXPORT_SYMBOL(arch_local_irq_enable
);
67 void arch_local_irq_restore(unsigned long old_psr
)
74 SMP_NOP2
/* Sun4m + Cypress + SMP bug */
76 "wr %0, %2, %%psr\n\t"
79 : "i" (PSR_PIL
), "r" (old_psr
)
82 EXPORT_SYMBOL(arch_local_irq_restore
);
85 * Dave Redman (djhr@tadpole.co.uk)
87 * IRQ numbers.. These are no longer restricted to 15..
89 * this is done to enable SBUS cards and onboard IO to be masked
90 * correctly. using the interrupt level isn't good enough.
93 * A device interrupting at sbus level6 and the Floppy both come in
94 * at IRQ11, but enabling and disabling them requires writing to
95 * different bits in the SLAVIO/SEC.
97 * As a result of these changes sun4m machines could now support
98 * directed CPU interrupts using the existing enable/disable irq code
103 static void irq_panic(void)
105 prom_printf("machine: %s doesn't have irq handlers defined!\n",
110 void (*sparc_init_timers
)(irq_handler_t
) = (void (*)(irq_handler_t
))irq_panic
;
113 * Dave Redman (djhr@tadpole.co.uk)
115 * There used to be extern calls and hard coded values here.. very sucky!
116 * instead, because some of the devices attach very early, I do something
117 * equally sucky but at least we'll never try to free statically allocated
118 * space or call kmalloc before kmalloc_init :(.
120 * In fact it's the timer10 that attaches first.. then timer14
121 * then kmalloc_init is called.. then the tty interrupts attach.
125 #define MAX_STATIC_ALLOC 4
126 struct irqaction static_irqaction
[MAX_STATIC_ALLOC
];
127 int static_irq_count
;
130 struct irqaction
*action
;
132 } sparc_irq
[NR_IRQS
];
133 #define SPARC_IRQ_INPROGRESS 1
135 /* Used to protect the IRQ action lists */
136 DEFINE_SPINLOCK(irq_action_lock
);
138 int show_interrupts(struct seq_file
*p
, void *v
)
140 int i
= *(loff_t
*)v
;
141 struct irqaction
*action
;
147 if (sparc_cpu_model
== sun4d
)
148 return show_sun4d_interrupts(p
, v
);
150 spin_lock_irqsave(&irq_action_lock
, flags
);
152 action
= sparc_irq
[i
].action
;
155 seq_printf(p
, "%3d: ", i
);
157 seq_printf(p
, "%10u ", kstat_irqs(i
));
159 for_each_online_cpu(j
) {
160 seq_printf(p
, "%10u ",
161 kstat_cpu(j
).irqs
[i
]);
164 seq_printf(p
, " %c %s",
165 (action
->flags
& IRQF_DISABLED
) ? '+' : ' ',
167 for (action
= action
->next
; action
; action
= action
->next
) {
168 seq_printf(p
, ",%s %s",
169 (action
->flags
& IRQF_DISABLED
) ? " +" : "",
175 spin_unlock_irqrestore(&irq_action_lock
, flags
);
179 void free_irq(unsigned int irq
, void *dev_id
)
181 struct irqaction
*action
;
182 struct irqaction
**actionp
;
184 unsigned int cpu_irq
;
186 if (sparc_cpu_model
== sun4d
) {
187 sun4d_free_irq(irq
, dev_id
);
190 cpu_irq
= irq
& (NR_IRQS
- 1);
191 if (cpu_irq
> 14) { /* 14 irq levels on the sparc */
192 printk(KERN_ERR
"Trying to free bogus IRQ %d\n", irq
);
196 spin_lock_irqsave(&irq_action_lock
, flags
);
198 actionp
= &sparc_irq
[cpu_irq
].action
;
201 if (!action
->handler
) {
202 printk(KERN_ERR
"Trying to free free IRQ%d\n", irq
);
206 for (; action
; action
= action
->next
) {
207 if (action
->dev_id
== dev_id
)
209 actionp
= &action
->next
;
212 printk(KERN_ERR
"Trying to free free shared IRQ%d\n",
216 } else if (action
->flags
& IRQF_SHARED
) {
217 printk(KERN_ERR
"Trying to free shared IRQ%d with NULL device ID\n",
221 if (action
->flags
& SA_STATIC_ALLOC
) {
223 * This interrupt is marked as specially allocated
224 * so it is a bad idea to free it.
226 printk(KERN_ERR
"Attempt to free statically allocated IRQ%d (%s)\n",
231 *actionp
= action
->next
;
233 spin_unlock_irqrestore(&irq_action_lock
, flags
);
235 synchronize_irq(irq
);
237 spin_lock_irqsave(&irq_action_lock
, flags
);
241 if (!sparc_irq
[cpu_irq
].action
)
245 spin_unlock_irqrestore(&irq_action_lock
, flags
);
247 EXPORT_SYMBOL(free_irq
);
250 * This is called when we want to synchronize with
251 * interrupts. We may for example tell a device to
252 * stop sending interrupts: but to make sure there
253 * are no interrupts that are executing on another
254 * CPU we need to call this function.
257 void synchronize_irq(unsigned int irq
)
259 unsigned int cpu_irq
;
261 cpu_irq
= irq
& (NR_IRQS
- 1);
262 while (sparc_irq
[cpu_irq
].flags
& SPARC_IRQ_INPROGRESS
)
265 EXPORT_SYMBOL(synchronize_irq
);
268 void unexpected_irq(int irq
, void *dev_id
, struct pt_regs
*regs
)
271 struct irqaction
*action
;
272 unsigned int cpu_irq
;
274 cpu_irq
= irq
& (NR_IRQS
- 1);
275 action
= sparc_irq
[cpu_irq
].action
;
277 printk(KERN_ERR
"IO device interrupt, irq = %d\n", irq
);
278 printk(KERN_ERR
"PC = %08lx NPC = %08lx FP=%08lx\n", regs
->pc
,
279 regs
->npc
, regs
->u_regs
[14]);
281 printk(KERN_ERR
"Expecting: ");
282 for (i
= 0; i
< 16; i
++)
284 printk(KERN_CONT
"[%s:%d:0x%x] ", action
->name
,
285 i
, (unsigned int)action
->handler
);
287 printk(KERN_ERR
"AIEEE\n");
288 panic("bogus interrupt received");
291 void handler_irq(int pil
, struct pt_regs
*regs
)
293 struct pt_regs
*old_regs
;
294 struct irqaction
*action
;
295 int cpu
= smp_processor_id();
297 old_regs
= set_irq_regs(regs
);
299 disable_pil_irq(pil
);
301 /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
302 if ((sparc_cpu_model
==sun4m
) && (pil
< 10))
303 smp4m_irq_rotate(cpu
);
305 action
= sparc_irq
[pil
].action
;
306 sparc_irq
[pil
].flags
|= SPARC_IRQ_INPROGRESS
;
307 kstat_cpu(cpu
).irqs
[pil
]++;
309 if (!action
|| !action
->handler
)
310 unexpected_irq(pil
, NULL
, regs
);
311 action
->handler(pil
, action
->dev_id
);
312 action
= action
->next
;
314 sparc_irq
[pil
].flags
&= ~SPARC_IRQ_INPROGRESS
;
317 set_irq_regs(old_regs
);
320 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
323 * Fast IRQs on the Sparc can only have one routine attached to them,
324 * thus no sharing possible.
326 static int request_fast_irq(unsigned int irq
,
327 void (*handler
)(void),
328 unsigned long irqflags
, const char *devname
)
330 struct irqaction
*action
;
332 unsigned int cpu_irq
;
334 #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
335 struct tt_entry
*trap_table
;
337 cpu_irq
= irq
& (NR_IRQS
- 1);
347 spin_lock_irqsave(&irq_action_lock
, flags
);
349 action
= sparc_irq
[cpu_irq
].action
;
351 if (action
->flags
& IRQF_SHARED
)
352 panic("Trying to register fast irq when already shared.\n");
353 if (irqflags
& IRQF_SHARED
)
354 panic("Trying to register fast irq as shared.\n");
356 /* Anyway, someone already owns it so cannot be made fast. */
357 printk(KERN_ERR
"request_fast_irq: Trying to register yet already owned.\n");
363 * If this is flagged as statically allocated then we use our
364 * private struct which is never freed.
366 if (irqflags
& SA_STATIC_ALLOC
) {
367 if (static_irq_count
< MAX_STATIC_ALLOC
)
368 action
= &static_irqaction
[static_irq_count
++];
370 printk(KERN_ERR
"Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
375 action
= kmalloc(sizeof(struct irqaction
), GFP_ATOMIC
);
381 /* Dork with trap table if we get this far. */
382 #define INSTANTIATE(table) \
383 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
384 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
385 SPARC_BRANCH((unsigned long) handler, \
386 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
387 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
388 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
390 INSTANTIATE(sparc_ttable
)
391 #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
392 trap_table
= &trapbase_cpu1
;
393 INSTANTIATE(trap_table
)
394 trap_table
= &trapbase_cpu2
;
395 INSTANTIATE(trap_table
)
396 trap_table
= &trapbase_cpu3
;
397 INSTANTIATE(trap_table
)
401 * XXX Correct thing whould be to flush only I- and D-cache lines
402 * which contain the handler in question. But as of time of the
403 * writing we have no CPU-neutral interface to fine-grained flushes.
407 action
->flags
= irqflags
;
408 action
->name
= devname
;
409 action
->dev_id
= NULL
;
412 sparc_irq
[cpu_irq
].action
= action
;
418 spin_unlock_irqrestore(&irq_action_lock
, flags
);
424 * These variables are used to access state from the assembler
425 * interrupt handler, floppy_hardint, so we cannot put these in
426 * the floppy driver image because that would not work in the
429 volatile unsigned char *fdc_status
;
430 EXPORT_SYMBOL(fdc_status
);
433 EXPORT_SYMBOL(pdma_vaddr
);
435 unsigned long pdma_size
;
436 EXPORT_SYMBOL(pdma_size
);
438 volatile int doing_pdma
;
439 EXPORT_SYMBOL(doing_pdma
);
442 EXPORT_SYMBOL(pdma_base
);
444 unsigned long pdma_areasize
;
445 EXPORT_SYMBOL(pdma_areasize
);
447 static irq_handler_t floppy_irq_handler
;
449 void sparc_floppy_irq(int irq
, void *dev_id
, struct pt_regs
*regs
)
451 struct pt_regs
*old_regs
;
452 int cpu
= smp_processor_id();
454 old_regs
= set_irq_regs(regs
);
455 disable_pil_irq(irq
);
457 kstat_cpu(cpu
).irqs
[irq
]++;
458 floppy_irq_handler(irq
, dev_id
);
461 set_irq_regs(old_regs
);
463 * XXX Eek, it's totally changed with preempt_count() and such
464 * if (softirq_pending(cpu))
469 int sparc_floppy_request_irq(int irq
, unsigned long flags
,
470 irq_handler_t irq_handler
)
472 floppy_irq_handler
= irq_handler
;
473 return request_fast_irq(irq
, floppy_hardint
, flags
, "floppy");
475 EXPORT_SYMBOL(sparc_floppy_request_irq
);
479 int request_irq(unsigned int irq
,
480 irq_handler_t handler
,
481 unsigned long irqflags
, const char *devname
, void *dev_id
)
483 struct irqaction
*action
, **actionp
;
485 unsigned int cpu_irq
;
488 if (sparc_cpu_model
== sun4d
)
489 return sun4d_request_irq(irq
, handler
, irqflags
, devname
, dev_id
);
491 cpu_irq
= irq
& (NR_IRQS
- 1);
501 spin_lock_irqsave(&irq_action_lock
, flags
);
503 actionp
= &sparc_irq
[cpu_irq
].action
;
506 if (!(action
->flags
& IRQF_SHARED
) || !(irqflags
& IRQF_SHARED
)) {
510 if ((action
->flags
& IRQF_DISABLED
) != (irqflags
& IRQF_DISABLED
)) {
511 printk(KERN_ERR
"Attempt to mix fast and slow interrupts on IRQ%d denied\n",
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(KERN_ERR
"Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
531 action
= kmalloc(sizeof(struct irqaction
), GFP_ATOMIC
);
537 action
->handler
= handler
;
538 action
->flags
= irqflags
;
539 action
->name
= devname
;
541 action
->dev_id
= dev_id
;
549 spin_unlock_irqrestore(&irq_action_lock
, flags
);
553 EXPORT_SYMBOL(request_irq
);
555 void disable_irq_nosync(unsigned int irq
)
559 EXPORT_SYMBOL(disable_irq_nosync
);
561 void disable_irq(unsigned int irq
)
565 EXPORT_SYMBOL(disable_irq
);
567 void enable_irq(unsigned int irq
)
571 EXPORT_SYMBOL(enable_irq
);
574 * We really don't need these at all on the Sparc. We only have
575 * stubs here because they are exported to modules.
577 unsigned long probe_irq_on(void)
581 EXPORT_SYMBOL(probe_irq_on
);
583 int probe_irq_off(unsigned long mask
)
587 EXPORT_SYMBOL(probe_irq_off
);
590 * This could probably be made indirect too and assigned in the CPU
591 * bits of the code. That would be much nicer I think and would also
592 * fit in with the idea of being able to tune your kernel for your machine
593 * by removing unrequired machine and device support.
597 void __init
init_IRQ(void)
599 switch (sparc_cpu_model
) {
608 if (pcic_present()) {
609 sun4m_pci_init_IRQ();
625 prom_printf("Cannot initialize IRQs on this Sun machine...");
631 #ifdef CONFIG_PROC_FS
632 void init_irq_proc(void)
634 /* For now, nothing... */
636 #endif /* CONFIG_PROC_FS */