sparc32: add support for run-time patching of leon/sun single instructions
[deliverable/linux.git] / arch / sparc / kernel / irq_32.c
CommitLineData
88278ca2 1/*
fd49bf48
SR
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.
1da177e4
LT
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
1da177e4 14#include <linux/kernel_stat.h>
1da177e4 15#include <linux/seq_file.h>
7b64db60 16#include <linux/export.h>
1da177e4 17
a2a211cb 18#include <asm/cacheflush.h>
6baa9b20 19#include <asm/cpudata.h>
1da177e4 20#include <asm/pcic.h>
0fd7ef1f 21#include <asm/leon.h>
1da177e4 22
81265fd9 23#include "kernel.h"
32231a66
AV
24#include "irq.h"
25
bbdc2661 26/* platform specific irq setup */
472bc4f2 27struct sparc_config sparc_config;
bbdc2661 28
df9ee292 29unsigned long arch_local_irq_save(void)
1da177e4
LT
30{
31 unsigned long retval;
32 unsigned long tmp;
33
34 __asm__ __volatile__(
35 "rd %%psr, %0\n\t"
1da177e4
LT
36 "or %0, %2, %1\n\t"
37 "wr %1, 0, %%psr\n\t"
38 "nop; nop; nop\n"
39 : "=&r" (retval), "=r" (tmp)
40 : "i" (PSR_PIL)
41 : "memory");
42
43 return retval;
44}
df9ee292 45EXPORT_SYMBOL(arch_local_irq_save);
1da177e4 46
df9ee292 47void arch_local_irq_enable(void)
1da177e4
LT
48{
49 unsigned long tmp;
50
51 __asm__ __volatile__(
52 "rd %%psr, %0\n\t"
1da177e4
LT
53 "andn %0, %1, %0\n\t"
54 "wr %0, 0, %%psr\n\t"
55 "nop; nop; nop\n"
56 : "=&r" (tmp)
57 : "i" (PSR_PIL)
58 : "memory");
59}
df9ee292 60EXPORT_SYMBOL(arch_local_irq_enable);
1da177e4 61
df9ee292 62void arch_local_irq_restore(unsigned long old_psr)
1da177e4
LT
63{
64 unsigned long tmp;
65
66 __asm__ __volatile__(
67 "rd %%psr, %0\n\t"
68 "and %2, %1, %2\n\t"
1da177e4
LT
69 "andn %0, %1, %0\n\t"
70 "wr %0, %2, %%psr\n\t"
71 "nop; nop; nop\n"
72 : "=&r" (tmp)
73 : "i" (PSR_PIL), "r" (old_psr)
74 : "memory");
75}
df9ee292 76EXPORT_SYMBOL(arch_local_irq_restore);
1da177e4
LT
77
78/*
79 * Dave Redman (djhr@tadpole.co.uk)
80 *
81 * IRQ numbers.. These are no longer restricted to 15..
82 *
83 * this is done to enable SBUS cards and onboard IO to be masked
84 * correctly. using the interrupt level isn't good enough.
85 *
86 * For example:
87 * A device interrupting at sbus level6 and the Floppy both come in
88 * at IRQ11, but enabling and disabling them requires writing to
89 * different bits in the SLAVIO/SEC.
90 *
91 * As a result of these changes sun4m machines could now support
92 * directed CPU interrupts using the existing enable/disable irq code
93 * with tweaks.
94 *
6baa9b20
SR
95 * Sun4d complicates things even further. IRQ numbers are arbitrary
96 * 32-bit values in that case. Since this is similar to sparc64,
97 * we adopt a virtual IRQ numbering scheme as is done there.
98 * Virutal interrupt numbers are allocated by build_irq(). So NR_IRQS
99 * just becomes a limit of how many interrupt sources we can handle in
100 * a single system. Even fully loaded SS2000 machines top off at
101 * about 32 interrupt sources or so, therefore a NR_IRQS value of 64
102 * is more than enough.
103 *
104 * We keep a map of per-PIL enable interrupts. These get wired
105 * up via the irq_chip->startup() method which gets invoked by
106 * the generic IRQ layer during request_irq().
1da177e4
LT
107 */
108
1da177e4 109
6baa9b20
SR
110/* Table of allocated irqs. Unused entries has irq == 0 */
111static struct irq_bucket irq_table[NR_IRQS];
112/* Protect access to irq_table */
113static DEFINE_SPINLOCK(irq_table_lock);
1da177e4 114
6baa9b20
SR
115/* Map between the irq identifier used in hw to the irq_bucket. */
116struct irq_bucket *irq_map[SUN4D_MAX_IRQ];
117/* Protect access to irq_map */
118static DEFINE_SPINLOCK(irq_map_lock);
1da177e4 119
6baa9b20
SR
120/* Allocate a new irq from the irq_table */
121unsigned int irq_alloc(unsigned int real_irq, unsigned int pil)
1da177e4 122{
1da177e4 123 unsigned long flags;
6baa9b20
SR
124 unsigned int i;
125
126 spin_lock_irqsave(&irq_table_lock, flags);
127 for (i = 1; i < NR_IRQS; i++) {
128 if (irq_table[i].real_irq == real_irq && irq_table[i].pil == pil)
129 goto found;
130 }
1da177e4 131
6baa9b20
SR
132 for (i = 1; i < NR_IRQS; i++) {
133 if (!irq_table[i].irq)
134 break;
135 }
fd49bf48 136
1da177e4 137 if (i < NR_IRQS) {
6baa9b20
SR
138 irq_table[i].real_irq = real_irq;
139 irq_table[i].irq = i;
140 irq_table[i].pil = pil;
141 } else {
142 printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
143 i = 0;
1da177e4 144 }
6baa9b20
SR
145found:
146 spin_unlock_irqrestore(&irq_table_lock, flags);
147
148 return i;
1da177e4
LT
149}
150
6baa9b20
SR
151/* Based on a single pil handler_irq may need to call several
152 * interrupt handlers. Use irq_map as entry to irq_table,
153 * and let each entry in irq_table point to the next entry.
154 */
155void irq_link(unsigned int irq)
1da177e4 156{
6baa9b20 157 struct irq_bucket *p;
fd49bf48 158 unsigned long flags;
6baa9b20 159 unsigned int pil;
fd49bf48 160
6baa9b20 161 BUG_ON(irq >= NR_IRQS);
1da177e4 162
6baa9b20 163 spin_lock_irqsave(&irq_map_lock, flags);
1da177e4 164
6baa9b20
SR
165 p = &irq_table[irq];
166 pil = p->pil;
167 BUG_ON(pil > SUN4D_MAX_IRQ);
168 p->next = irq_map[pil];
169 irq_map[pil] = p;
1da177e4 170
6baa9b20
SR
171 spin_unlock_irqrestore(&irq_map_lock, flags);
172}
1da177e4 173
6baa9b20
SR
174void irq_unlink(unsigned int irq)
175{
176 struct irq_bucket *p, **pnext;
177 unsigned long flags;
1da177e4 178
6baa9b20 179 BUG_ON(irq >= NR_IRQS);
1da177e4 180
6baa9b20 181 spin_lock_irqsave(&irq_map_lock, flags);
1da177e4 182
6baa9b20
SR
183 p = &irq_table[irq];
184 BUG_ON(p->pil > SUN4D_MAX_IRQ);
185 pnext = &irq_map[p->pil];
186 while (*pnext != p)
187 pnext = &(*pnext)->next;
188 *pnext = p->next;
1da177e4 189
6baa9b20 190 spin_unlock_irqrestore(&irq_map_lock, flags);
1da177e4 191}
1da177e4 192
a54123e2 193
6baa9b20
SR
194/* /proc/interrupts printing */
195int arch_show_interrupts(struct seq_file *p, int prec)
1da177e4 196{
6baa9b20 197 int j;
fd49bf48 198
d6d04819
DH
199#ifdef CONFIG_SMP
200 seq_printf(p, "RES: ");
201 for_each_online_cpu(j)
202 seq_printf(p, "%10u ", cpu_data(j).irq_resched_count);
203 seq_printf(p, " IPI rescheduling interrupts\n");
204 seq_printf(p, "CAL: ");
205 for_each_online_cpu(j)
206 seq_printf(p, "%10u ", cpu_data(j).irq_call_count);
207 seq_printf(p, " IPI function call interrupts\n");
208#endif
6baa9b20
SR
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");
213 return 0;
1da177e4
LT
214}
215
6baa9b20 216void handler_irq(unsigned int pil, struct pt_regs *regs)
1da177e4 217{
0d84438d 218 struct pt_regs *old_regs;
6baa9b20 219 struct irq_bucket *p;
1da177e4 220
6baa9b20 221 BUG_ON(pil > 15);
0d84438d 222 old_regs = set_irq_regs(regs);
1da177e4 223 irq_enter();
6baa9b20
SR
224
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 }
1da177e4 232 irq_exit();
0d84438d 233 set_irq_regs(old_regs);
1da177e4
LT
234}
235
0a808a31 236#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
6baa9b20 237static unsigned int floppy_irq;
1da177e4 238
6baa9b20 239int sparc_floppy_request_irq(unsigned int irq, irq_handler_t irq_handler)
1da177e4 240{
1da177e4 241 unsigned int cpu_irq;
6baa9b20
SR
242 int err;
243
51672321 244#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
1da177e4 245 struct tt_entry *trap_table;
1da177e4 246#endif
1da177e4 247
6baa9b20
SR
248 err = request_irq(irq, irq_handler, 0, "floppy", NULL);
249 if (err)
250 return -1;
1da177e4 251
6baa9b20
SR
252 /* Save for later use in floppy interrupt handler */
253 floppy_irq = irq;
1da177e4 254
6baa9b20 255 cpu_irq = (irq & (NR_IRQS - 1));
1da177e4
LT
256
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 = \
6baa9b20 261 SPARC_BRANCH((unsigned long) floppy_hardint, \
1da177e4
LT
262 (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)
51672321 267#if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
fd49bf48
SR
268 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)
1da177e4
LT
274#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();
6baa9b20 282 return 0;
1da177e4 283}
6baa9b20 284EXPORT_SYMBOL(sparc_floppy_request_irq);
1da177e4 285
fd49bf48
SR
286/*
287 * These variables are used to access state from the assembler
0a808a31
DM
288 * 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
6baa9b20
SR
310/* 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 */
0a808a31
DM
315void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
316{
317 struct pt_regs *old_regs;
0a808a31
DM
318
319 old_regs = set_irq_regs(regs);
0a808a31 320 irq_enter();
6baa9b20 321 generic_handle_irq(floppy_irq);
0a808a31 322 irq_exit();
0a808a31 323 set_irq_regs(old_regs);
0a808a31 324}
0a808a31
DM
325#endif
326
1da177e4
LT
327/* 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{
fd49bf48 337 switch (sparc_cpu_model) {
1da177e4 338 case sun4m:
1da177e4 339 pcic_probe();
06010fb5 340 if (pcic_present())
1da177e4 341 sun4m_pci_init_IRQ();
06010fb5
SR
342 else
343 sun4m_init_IRQ();
1da177e4 344 break;
fd49bf48 345
1da177e4
LT
346 case sun4d:
347 sun4d_init_IRQ();
348 break;
349
0fd7ef1f
KE
350 case sparc_leon:
351 leon_init_IRQ();
352 break;
353
1da177e4 354 default:
d1a78c32 355 prom_printf("Cannot initialize IRQs on this Sun machine...");
1da177e4
LT
356 break;
357 }
1da177e4
LT
358}
359
This page took 0.537891 seconds and 5 git commands to generate.