sparc32: fix build with leon or floppy enabled
[deliverable/linux.git] / arch / sparc / kernel / irq_32.c
1 /*
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.
6 *
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)
12 */
13
14 #include <linux/kernel_stat.h>
15 #include <linux/seq_file.h>
16
17 #include <asm/cacheflush.h>
18 #include <asm/pcic.h>
19 #include <asm/leon.h>
20
21 #include "kernel.h"
22 #include "irq.h"
23
24 #ifdef CONFIG_SMP
25 #define SMP_NOP2 "nop; nop;\n\t"
26 #define SMP_NOP3 "nop; nop; nop;\n\t"
27 #else
28 #define SMP_NOP2
29 #define SMP_NOP3
30 #endif /* SMP */
31
32 unsigned long arch_local_irq_save(void)
33 {
34 unsigned long retval;
35 unsigned long tmp;
36
37 __asm__ __volatile__(
38 "rd %%psr, %0\n\t"
39 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
40 "or %0, %2, %1\n\t"
41 "wr %1, 0, %%psr\n\t"
42 "nop; nop; nop\n"
43 : "=&r" (retval), "=r" (tmp)
44 : "i" (PSR_PIL)
45 : "memory");
46
47 return retval;
48 }
49 EXPORT_SYMBOL(arch_local_irq_save);
50
51 void arch_local_irq_enable(void)
52 {
53 unsigned long tmp;
54
55 __asm__ __volatile__(
56 "rd %%psr, %0\n\t"
57 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
58 "andn %0, %1, %0\n\t"
59 "wr %0, 0, %%psr\n\t"
60 "nop; nop; nop\n"
61 : "=&r" (tmp)
62 : "i" (PSR_PIL)
63 : "memory");
64 }
65 EXPORT_SYMBOL(arch_local_irq_enable);
66
67 void arch_local_irq_restore(unsigned long old_psr)
68 {
69 unsigned long tmp;
70
71 __asm__ __volatile__(
72 "rd %%psr, %0\n\t"
73 "and %2, %1, %2\n\t"
74 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
75 "andn %0, %1, %0\n\t"
76 "wr %0, %2, %%psr\n\t"
77 "nop; nop; nop\n"
78 : "=&r" (tmp)
79 : "i" (PSR_PIL), "r" (old_psr)
80 : "memory");
81 }
82 EXPORT_SYMBOL(arch_local_irq_restore);
83
84 /*
85 * Dave Redman (djhr@tadpole.co.uk)
86 *
87 * IRQ numbers.. These are no longer restricted to 15..
88 *
89 * this is done to enable SBUS cards and onboard IO to be masked
90 * correctly. using the interrupt level isn't good enough.
91 *
92 * For example:
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.
96 *
97 * As a result of these changes sun4m machines could now support
98 * directed CPU interrupts using the existing enable/disable irq code
99 * with tweaks.
100 *
101 */
102
103 static void irq_panic(void)
104 {
105 prom_printf("machine: %s doesn't have irq handlers defined!\n",
106 &cputypval[0]);
107 prom_halt();
108 }
109
110 void (*sparc_init_timers)(irq_handler_t) = (void (*)(irq_handler_t))irq_panic;
111
112 /*
113 * Dave Redman (djhr@tadpole.co.uk)
114 *
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 :(.
119 *
120 * In fact it's the timer10 that attaches first.. then timer14
121 * then kmalloc_init is called.. then the tty interrupts attach.
122 * hmmm....
123 *
124 */
125 #define MAX_STATIC_ALLOC 4
126 struct irqaction static_irqaction[MAX_STATIC_ALLOC];
127 int static_irq_count;
128
129 static struct {
130 struct irqaction *action;
131 int flags;
132 } sparc_irq[NR_IRQS];
133 #define SPARC_IRQ_INPROGRESS 1
134
135 /* Used to protect the IRQ action lists */
136 DEFINE_SPINLOCK(irq_action_lock);
137
138 int show_interrupts(struct seq_file *p, void *v)
139 {
140 int i = *(loff_t *)v;
141 struct irqaction *action;
142 unsigned long flags;
143 #ifdef CONFIG_SMP
144 int j;
145 #endif
146
147 if (sparc_cpu_model == sun4d)
148 return show_sun4d_interrupts(p, v);
149
150 spin_lock_irqsave(&irq_action_lock, flags);
151 if (i < NR_IRQS) {
152 action = sparc_irq[i].action;
153 if (!action)
154 goto out_unlock;
155 seq_printf(p, "%3d: ", i);
156 #ifndef CONFIG_SMP
157 seq_printf(p, "%10u ", kstat_irqs(i));
158 #else
159 for_each_online_cpu(j) {
160 seq_printf(p, "%10u ",
161 kstat_cpu(j).irqs[i]);
162 }
163 #endif
164 seq_printf(p, " %c %s",
165 (action->flags & IRQF_DISABLED) ? '+' : ' ',
166 action->name);
167 for (action = action->next; action; action = action->next) {
168 seq_printf(p, ",%s %s",
169 (action->flags & IRQF_DISABLED) ? " +" : "",
170 action->name);
171 }
172 seq_putc(p, '\n');
173 }
174 out_unlock:
175 spin_unlock_irqrestore(&irq_action_lock, flags);
176 return 0;
177 }
178
179 void free_irq(unsigned int irq, void *dev_id)
180 {
181 struct irqaction *action;
182 struct irqaction **actionp;
183 unsigned long flags;
184 unsigned int cpu_irq;
185
186 if (sparc_cpu_model == sun4d) {
187 sun4d_free_irq(irq, dev_id);
188 return;
189 }
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);
193 return;
194 }
195
196 spin_lock_irqsave(&irq_action_lock, flags);
197
198 actionp = &sparc_irq[cpu_irq].action;
199 action = *actionp;
200
201 if (!action->handler) {
202 printk(KERN_ERR "Trying to free free IRQ%d\n", irq);
203 goto out_unlock;
204 }
205 if (dev_id) {
206 for (; action; action = action->next) {
207 if (action->dev_id == dev_id)
208 break;
209 actionp = &action->next;
210 }
211 if (!action) {
212 printk(KERN_ERR "Trying to free free shared IRQ%d\n",
213 irq);
214 goto out_unlock;
215 }
216 } else if (action->flags & IRQF_SHARED) {
217 printk(KERN_ERR "Trying to free shared IRQ%d with NULL device ID\n",
218 irq);
219 goto out_unlock;
220 }
221 if (action->flags & SA_STATIC_ALLOC) {
222 /*
223 * This interrupt is marked as specially allocated
224 * so it is a bad idea to free it.
225 */
226 printk(KERN_ERR "Attempt to free statically allocated IRQ%d (%s)\n",
227 irq, action->name);
228 goto out_unlock;
229 }
230
231 *actionp = action->next;
232
233 spin_unlock_irqrestore(&irq_action_lock, flags);
234
235 synchronize_irq(irq);
236
237 spin_lock_irqsave(&irq_action_lock, flags);
238
239 kfree(action);
240
241 if (!sparc_irq[cpu_irq].action)
242 __disable_irq(irq);
243
244 out_unlock:
245 spin_unlock_irqrestore(&irq_action_lock, flags);
246 }
247 EXPORT_SYMBOL(free_irq);
248
249 /*
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.
255 */
256 #ifdef CONFIG_SMP
257 void synchronize_irq(unsigned int irq)
258 {
259 unsigned int cpu_irq;
260
261 cpu_irq = irq & (NR_IRQS - 1);
262 while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
263 cpu_relax();
264 }
265 EXPORT_SYMBOL(synchronize_irq);
266 #endif /* SMP */
267
268 void unexpected_irq(int irq, void *dev_id, struct pt_regs *regs)
269 {
270 int i;
271 struct irqaction *action;
272 unsigned int cpu_irq;
273
274 cpu_irq = irq & (NR_IRQS - 1);
275 action = sparc_irq[cpu_irq].action;
276
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]);
280 if (action) {
281 printk(KERN_ERR "Expecting: ");
282 for (i = 0; i < 16; i++)
283 if (action->handler)
284 printk(KERN_CONT "[%s:%d:0x%x] ", action->name,
285 i, (unsigned int)action->handler);
286 }
287 printk(KERN_ERR "AIEEE\n");
288 panic("bogus interrupt received");
289 }
290
291 void handler_irq(int pil, struct pt_regs *regs)
292 {
293 struct pt_regs *old_regs;
294 struct irqaction *action;
295 int cpu = smp_processor_id();
296
297 old_regs = set_irq_regs(regs);
298 irq_enter();
299 disable_pil_irq(pil);
300 #ifdef CONFIG_SMP
301 /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
302 if ((sparc_cpu_model==sun4m) && (pil < 10))
303 smp4m_irq_rotate(cpu);
304 #endif
305 action = sparc_irq[pil].action;
306 sparc_irq[pil].flags |= SPARC_IRQ_INPROGRESS;
307 kstat_cpu(cpu).irqs[pil]++;
308 do {
309 if (!action || !action->handler)
310 unexpected_irq(pil, NULL, regs);
311 action->handler(pil, action->dev_id);
312 action = action->next;
313 } while (action);
314 sparc_irq[pil].flags &= ~SPARC_IRQ_INPROGRESS;
315 enable_pil_irq(pil);
316 irq_exit();
317 set_irq_regs(old_regs);
318 }
319
320 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
321
322 /*
323 * Fast IRQs on the Sparc can only have one routine attached to them,
324 * thus no sharing possible.
325 */
326 static int request_fast_irq(unsigned int irq,
327 void (*handler)(void),
328 unsigned long irqflags, const char *devname)
329 {
330 struct irqaction *action;
331 unsigned long flags;
332 unsigned int cpu_irq;
333 int ret;
334 #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
335 struct tt_entry *trap_table;
336 #endif
337 cpu_irq = irq & (NR_IRQS - 1);
338 if (cpu_irq > 14) {
339 ret = -EINVAL;
340 goto out;
341 }
342 if (!handler) {
343 ret = -EINVAL;
344 goto out;
345 }
346
347 spin_lock_irqsave(&irq_action_lock, flags);
348
349 action = sparc_irq[cpu_irq].action;
350 if (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");
355
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");
358 ret = -EBUSY;
359 goto out_unlock;
360 }
361
362 /*
363 * If this is flagged as statically allocated then we use our
364 * private struct which is never freed.
365 */
366 if (irqflags & SA_STATIC_ALLOC) {
367 if (static_irq_count < MAX_STATIC_ALLOC)
368 action = &static_irqaction[static_irq_count++];
369 else
370 printk(KERN_ERR "Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
371 irq, devname);
372 }
373
374 if (action == NULL)
375 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
376 if (!action) {
377 ret = -ENOMEM;
378 goto out_unlock;
379 }
380
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;
389
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)
398 #endif
399 #undef INSTANTIATE
400 /*
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.
404 */
405 flush_cache_all();
406
407 action->flags = irqflags;
408 action->name = devname;
409 action->dev_id = NULL;
410 action->next = NULL;
411
412 sparc_irq[cpu_irq].action = action;
413
414 __enable_irq(irq);
415
416 ret = 0;
417 out_unlock:
418 spin_unlock_irqrestore(&irq_action_lock, flags);
419 out:
420 return ret;
421 }
422
423 /*
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
427 * modular case.
428 */
429 volatile unsigned char *fdc_status;
430 EXPORT_SYMBOL(fdc_status);
431
432 char *pdma_vaddr;
433 EXPORT_SYMBOL(pdma_vaddr);
434
435 unsigned long pdma_size;
436 EXPORT_SYMBOL(pdma_size);
437
438 volatile int doing_pdma;
439 EXPORT_SYMBOL(doing_pdma);
440
441 char *pdma_base;
442 EXPORT_SYMBOL(pdma_base);
443
444 unsigned long pdma_areasize;
445 EXPORT_SYMBOL(pdma_areasize);
446
447 static irq_handler_t floppy_irq_handler;
448
449 void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
450 {
451 struct pt_regs *old_regs;
452 int cpu = smp_processor_id();
453
454 old_regs = set_irq_regs(regs);
455 disable_pil_irq(irq);
456 irq_enter();
457 kstat_cpu(cpu).irqs[irq]++;
458 floppy_irq_handler(irq, dev_id);
459 irq_exit();
460 enable_pil_irq(irq);
461 set_irq_regs(old_regs);
462 /*
463 * XXX Eek, it's totally changed with preempt_count() and such
464 * if (softirq_pending(cpu))
465 * do_softirq();
466 */
467 }
468
469 int sparc_floppy_request_irq(int irq, unsigned long flags,
470 irq_handler_t irq_handler)
471 {
472 floppy_irq_handler = irq_handler;
473 return request_fast_irq(irq, floppy_hardint, flags, "floppy");
474 }
475 EXPORT_SYMBOL(sparc_floppy_request_irq);
476
477 #endif
478
479 int request_irq(unsigned int irq,
480 irq_handler_t handler,
481 unsigned long irqflags, const char *devname, void *dev_id)
482 {
483 struct irqaction *action, **actionp;
484 unsigned long flags;
485 unsigned int cpu_irq;
486 int ret;
487
488 if (sparc_cpu_model == sun4d)
489 return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
490
491 cpu_irq = irq & (NR_IRQS - 1);
492 if (cpu_irq > 14) {
493 ret = -EINVAL;
494 goto out;
495 }
496 if (!handler) {
497 ret = -EINVAL;
498 goto out;
499 }
500
501 spin_lock_irqsave(&irq_action_lock, flags);
502
503 actionp = &sparc_irq[cpu_irq].action;
504 action = *actionp;
505 if (action) {
506 if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
507 ret = -EBUSY;
508 goto out_unlock;
509 }
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",
512 irq);
513 ret = -EBUSY;
514 goto out_unlock;
515 }
516 for ( ; action; action = *actionp)
517 actionp = &action->next;
518 }
519
520 /* If this is flagged as statically allocated then we use our
521 * private struct which is never freed.
522 */
523 if (irqflags & SA_STATIC_ALLOC) {
524 if (static_irq_count < MAX_STATIC_ALLOC)
525 action = &static_irqaction[static_irq_count++];
526 else
527 printk(KERN_ERR "Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
528 irq, devname);
529 }
530 if (action == NULL)
531 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
532 if (!action) {
533 ret = -ENOMEM;
534 goto out_unlock;
535 }
536
537 action->handler = handler;
538 action->flags = irqflags;
539 action->name = devname;
540 action->next = NULL;
541 action->dev_id = dev_id;
542
543 *actionp = action;
544
545 __enable_irq(irq);
546
547 ret = 0;
548 out_unlock:
549 spin_unlock_irqrestore(&irq_action_lock, flags);
550 out:
551 return ret;
552 }
553 EXPORT_SYMBOL(request_irq);
554
555 void disable_irq_nosync(unsigned int irq)
556 {
557 __disable_irq(irq);
558 }
559 EXPORT_SYMBOL(disable_irq_nosync);
560
561 void disable_irq(unsigned int irq)
562 {
563 __disable_irq(irq);
564 }
565 EXPORT_SYMBOL(disable_irq);
566
567 void enable_irq(unsigned int irq)
568 {
569 __enable_irq(irq);
570 }
571 EXPORT_SYMBOL(enable_irq);
572
573 /*
574 * We really don't need these at all on the Sparc. We only have
575 * stubs here because they are exported to modules.
576 */
577 unsigned long probe_irq_on(void)
578 {
579 return 0;
580 }
581 EXPORT_SYMBOL(probe_irq_on);
582
583 int probe_irq_off(unsigned long mask)
584 {
585 return 0;
586 }
587 EXPORT_SYMBOL(probe_irq_off);
588
589 /* djhr
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.
594 *
595 */
596
597 void __init init_IRQ(void)
598 {
599 switch (sparc_cpu_model) {
600 case sun4c:
601 case sun4:
602 sun4c_init_IRQ();
603 break;
604
605 case sun4m:
606 #ifdef CONFIG_PCI
607 pcic_probe();
608 if (pcic_present()) {
609 sun4m_pci_init_IRQ();
610 break;
611 }
612 #endif
613 sun4m_init_IRQ();
614 break;
615
616 case sun4d:
617 sun4d_init_IRQ();
618 break;
619
620 case sparc_leon:
621 leon_init_IRQ();
622 break;
623
624 default:
625 prom_printf("Cannot initialize IRQs on this Sun machine...");
626 break;
627 }
628 btfixup();
629 }
630
631 #ifdef CONFIG_PROC_FS
632 void init_irq_proc(void)
633 {
634 /* For now, nothing... */
635 }
636 #endif /* CONFIG_PROC_FS */
This page took 0.30843 seconds and 5 git commands to generate.