blob: 197e1ba8548404acd3c590c9443386e651f4f680 [file] [log] [blame]
Adrian Bunk88278ca2008-05-19 16:53:02 -07001/*
Sam Ravnborgfd49bf42011-01-28 22:08:24 +00002 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/seq_file.h>
16
Sam Ravnborga2a211c2011-02-25 22:59:20 -080017#include <asm/cacheflush.h>
Sam Ravnborg6baa9b22011-04-18 11:25:44 +000018#include <asm/cpudata.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/pcic.h>
Konrad Eisele0fd7ef12009-08-17 00:13:31 +000020#include <asm/leon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Sam Ravnborg81265fd2008-12-08 01:08:24 -080022#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070023#include "irq.h"
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#ifdef CONFIG_SMP
26#define SMP_NOP2 "nop; nop;\n\t"
27#define SMP_NOP3 "nop; nop; nop;\n\t"
28#else
29#define SMP_NOP2
30#define SMP_NOP3
31#endif /* SMP */
Sam Ravnborgfd49bf42011-01-28 22:08:24 +000032
Sam Ravnborgbbdc2662011-02-25 23:00:19 -080033/* platform specific irq setup */
34struct sparc_irq_config sparc_irq_config;
35
David Howellsdf9ee292010-10-07 14:08:55 +010036unsigned long arch_local_irq_save(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 unsigned long retval;
39 unsigned long tmp;
40
41 __asm__ __volatile__(
42 "rd %%psr, %0\n\t"
43 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
44 "or %0, %2, %1\n\t"
45 "wr %1, 0, %%psr\n\t"
46 "nop; nop; nop\n"
47 : "=&r" (retval), "=r" (tmp)
48 : "i" (PSR_PIL)
49 : "memory");
50
51 return retval;
52}
David Howellsdf9ee292010-10-07 14:08:55 +010053EXPORT_SYMBOL(arch_local_irq_save);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
David Howellsdf9ee292010-10-07 14:08:55 +010055void arch_local_irq_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 unsigned long tmp;
58
59 __asm__ __volatile__(
60 "rd %%psr, %0\n\t"
61 SMP_NOP3 /* Sun4m + Cypress + SMP bug */
62 "andn %0, %1, %0\n\t"
63 "wr %0, 0, %%psr\n\t"
64 "nop; nop; nop\n"
65 : "=&r" (tmp)
66 : "i" (PSR_PIL)
67 : "memory");
68}
David Howellsdf9ee292010-10-07 14:08:55 +010069EXPORT_SYMBOL(arch_local_irq_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
David Howellsdf9ee292010-10-07 14:08:55 +010071void arch_local_irq_restore(unsigned long old_psr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 unsigned long tmp;
74
75 __asm__ __volatile__(
76 "rd %%psr, %0\n\t"
77 "and %2, %1, %2\n\t"
78 SMP_NOP2 /* Sun4m + Cypress + SMP bug */
79 "andn %0, %1, %0\n\t"
80 "wr %0, %2, %%psr\n\t"
81 "nop; nop; nop\n"
82 : "=&r" (tmp)
83 : "i" (PSR_PIL), "r" (old_psr)
84 : "memory");
85}
David Howellsdf9ee292010-10-07 14:08:55 +010086EXPORT_SYMBOL(arch_local_irq_restore);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/*
89 * Dave Redman (djhr@tadpole.co.uk)
90 *
91 * IRQ numbers.. These are no longer restricted to 15..
92 *
93 * this is done to enable SBUS cards and onboard IO to be masked
94 * correctly. using the interrupt level isn't good enough.
95 *
96 * For example:
97 * A device interrupting at sbus level6 and the Floppy both come in
98 * at IRQ11, but enabling and disabling them requires writing to
99 * different bits in the SLAVIO/SEC.
100 *
101 * As a result of these changes sun4m machines could now support
102 * directed CPU interrupts using the existing enable/disable irq code
103 * with tweaks.
104 *
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000105 * Sun4d complicates things even further. IRQ numbers are arbitrary
106 * 32-bit values in that case. Since this is similar to sparc64,
107 * we adopt a virtual IRQ numbering scheme as is done there.
108 * Virutal interrupt numbers are allocated by build_irq(). So NR_IRQS
109 * just becomes a limit of how many interrupt sources we can handle in
110 * a single system. Even fully loaded SS2000 machines top off at
111 * about 32 interrupt sources or so, therefore a NR_IRQS value of 64
112 * is more than enough.
113 *
114 * We keep a map of per-PIL enable interrupts. These get wired
115 * up via the irq_chip->startup() method which gets invoked by
116 * the generic IRQ layer during request_irq().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 */
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000120/* Table of allocated irqs. Unused entries has irq == 0 */
121static struct irq_bucket irq_table[NR_IRQS];
122/* Protect access to irq_table */
123static DEFINE_SPINLOCK(irq_table_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000125/* Map between the irq identifier used in hw to the irq_bucket. */
126struct irq_bucket *irq_map[SUN4D_MAX_IRQ];
127/* Protect access to irq_map */
128static DEFINE_SPINLOCK(irq_map_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000130/* Allocate a new irq from the irq_table */
131unsigned int irq_alloc(unsigned int real_irq, unsigned int pil)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 unsigned long flags;
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000134 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000136 spin_lock_irqsave(&irq_table_lock, flags);
137 for (i = 1; i < NR_IRQS; i++) {
138 if (irq_table[i].real_irq == real_irq && irq_table[i].pil == pil)
139 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000141
142 for (i = 1; i < NR_IRQS; i++) {
143 if (!irq_table[i].irq)
144 break;
145 }
146
147 if (i < NR_IRQS) {
148 irq_table[i].real_irq = real_irq;
149 irq_table[i].irq = i;
150 irq_table[i].pil = pil;
151 } else {
152 printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
153 i = 0;
154 }
155found:
156 spin_unlock_irqrestore(&irq_table_lock, flags);
157
158 return i;
159}
160
161/* Based on a single pil handler_irq may need to call several
162 * interrupt handlers. Use irq_map as entry to irq_table,
163 * and let each entry in irq_table point to the next entry.
164 */
165void irq_link(unsigned int irq)
166{
167 struct irq_bucket *p;
168 unsigned long flags;
169 unsigned int pil;
170
171 BUG_ON(irq >= NR_IRQS);
172
173 spin_lock_irqsave(&irq_map_lock, flags);
174
175 p = &irq_table[irq];
176 pil = p->pil;
177 BUG_ON(pil > SUN4D_MAX_IRQ);
178 p->next = irq_map[pil];
179 irq_map[pil] = p;
180
181 spin_unlock_irqrestore(&irq_map_lock, flags);
182}
183
184void irq_unlink(unsigned int irq)
185{
186 struct irq_bucket *p, **pnext;
187 unsigned long flags;
188
189 BUG_ON(irq >= NR_IRQS);
190
191 spin_lock_irqsave(&irq_map_lock, flags);
192
193 p = &irq_table[irq];
194 BUG_ON(p->pil > SUN4D_MAX_IRQ);
195 pnext = &irq_map[p->pil];
196 while (*pnext != p)
197 pnext = &(*pnext)->next;
198 *pnext = p->next;
199
200 spin_unlock_irqrestore(&irq_map_lock, flags);
201}
202
203
204/* /proc/interrupts printing */
205int arch_show_interrupts(struct seq_file *p, int prec)
206{
207 int j;
208
209 seq_printf(p, "NMI: ");
210 for_each_online_cpu(j)
211 seq_printf(p, "%10u ", cpu_data(j).counter);
212 seq_printf(p, " Non-maskable interrupts\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return 0;
214}
215
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000216void handler_irq(unsigned int pil, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Al Viro0d844382006-10-08 14:30:44 +0100218 struct pt_regs *old_regs;
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000219 struct irq_bucket *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000221 BUG_ON(pil > 15);
Al Viro0d844382006-10-08 14:30:44 +0100222 old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 irq_enter();
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000224
225 p = irq_map[pil];
226 while (p) {
227 struct irq_bucket *next = p->next;
228
229 generic_handle_irq(p->irq);
230 p = next;
231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 irq_exit();
Al Viro0d844382006-10-08 14:30:44 +0100233 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
David S. Miller0a808a32007-08-02 00:19:14 -0700236#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000237static unsigned int floppy_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000239int sparc_floppy_request_irq(unsigned int irq, irq_handler_t irq_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 unsigned int cpu_irq;
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000242 int err;
243
Namhyung Kim51672322010-10-25 05:52:38 +0000244#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 struct tt_entry *trap_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000248 err = request_irq(irq, irq_handler, 0, "floppy", NULL);
249 if (err)
250 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000252 /* Save for later use in floppy interrupt handler */
253 floppy_irq = irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000255 cpu_irq = (irq & (NR_IRQS - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /* Dork with trap table if we get this far. */
258#define INSTANTIATE(table) \
259 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
260 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000261 SPARC_BRANCH((unsigned long) floppy_hardint, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
263 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
264 table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
265
266 INSTANTIATE(sparc_ttable)
Namhyung Kim51672322010-10-25 05:52:38 +0000267#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000268 trap_table = &trapbase_cpu1;
269 INSTANTIATE(trap_table)
270 trap_table = &trapbase_cpu2;
271 INSTANTIATE(trap_table)
272 trap_table = &trapbase_cpu3;
273 INSTANTIATE(trap_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#endif
275#undef INSTANTIATE
276 /*
277 * XXX Correct thing whould be to flush only I- and D-cache lines
278 * which contain the handler in question. But as of time of the
279 * writing we have no CPU-neutral interface to fine-grained flushes.
280 */
281 flush_cache_all();
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000282 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000284EXPORT_SYMBOL(sparc_floppy_request_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000286/*
287 * These variables are used to access state from the assembler
David S. Miller0a808a32007-08-02 00:19:14 -0700288 * interrupt handler, floppy_hardint, so we cannot put these in
289 * the floppy driver image because that would not work in the
290 * modular case.
291 */
292volatile unsigned char *fdc_status;
293EXPORT_SYMBOL(fdc_status);
294
295char *pdma_vaddr;
296EXPORT_SYMBOL(pdma_vaddr);
297
298unsigned long pdma_size;
299EXPORT_SYMBOL(pdma_size);
300
301volatile int doing_pdma;
302EXPORT_SYMBOL(doing_pdma);
303
304char *pdma_base;
305EXPORT_SYMBOL(pdma_base);
306
307unsigned long pdma_areasize;
308EXPORT_SYMBOL(pdma_areasize);
309
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000310/* Use the generic irq support to call floppy_interrupt
311 * which was setup using request_irq() in sparc_floppy_request_irq().
312 * We only have one floppy interrupt so we do not need to check
313 * for additional handlers being wired up by irq_link()
314 */
David S. Miller0a808a32007-08-02 00:19:14 -0700315void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
316{
317 struct pt_regs *old_regs;
David S. Miller0a808a32007-08-02 00:19:14 -0700318
319 old_regs = set_irq_regs(regs);
David S. Miller0a808a32007-08-02 00:19:14 -0700320 irq_enter();
Sam Ravnborg6baa9b22011-04-18 11:25:44 +0000321 generic_handle_irq(floppy_irq);
David S. Miller0a808a32007-08-02 00:19:14 -0700322 irq_exit();
David S. Miller0a808a32007-08-02 00:19:14 -0700323 set_irq_regs(old_regs);
David S. Miller0a808a32007-08-02 00:19:14 -0700324}
David S. Miller0a808a32007-08-02 00:19:14 -0700325#endif
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/* djhr
328 * This could probably be made indirect too and assigned in the CPU
329 * bits of the code. That would be much nicer I think and would also
330 * fit in with the idea of being able to tune your kernel for your machine
331 * by removing unrequired machine and device support.
332 *
333 */
334
335void __init init_IRQ(void)
336{
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000337 switch (sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 case sun4c:
339 case sun4:
340 sun4c_init_IRQ();
341 break;
342
343 case sun4m:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 pcic_probe();
Sam Ravnborg06010fb2011-04-17 13:49:55 +0200345 if (pcic_present())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 sun4m_pci_init_IRQ();
Sam Ravnborg06010fb2011-04-17 13:49:55 +0200347 else
348 sun4m_init_IRQ();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 break;
Sam Ravnborgfd49bf42011-01-28 22:08:24 +0000350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 case sun4d:
352 sun4d_init_IRQ();
353 break;
354
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000355 case sparc_leon:
356 leon_init_IRQ();
357 break;
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 default:
Simon Arlottd1a78c32007-05-11 13:51:23 -0700360 prom_printf("Cannot initialize IRQs on this Sun machine...");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 break;
362 }
363 btfixup();
364}
365