Merge branch 'for-33' of git://repo.or.cz/linux-kbuild
[linux-2.6-block.git] / arch / sh / kernel / irq.c
CommitLineData
a6a31139 1/*
1da177e4
LT
2 * linux/arch/sh/kernel/irq.c
3 *
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
5 *
6 *
7 * SuperH version: Copyright (C) 1999 Niibe Yutaka
8 */
bf3a00f8 9#include <linux/irq.h>
1da177e4 10#include <linux/interrupt.h>
a6a31139 11#include <linux/module.h>
bf3a00f8 12#include <linux/kernel_stat.h>
1da177e4 13#include <linux/seq_file.h>
ba93483f 14#include <linux/ftrace.h>
bf3a00f8 15#include <asm/processor.h>
be782df5 16#include <asm/machvec.h>
a6a31139
PM
17#include <asm/uaccess.h>
18#include <asm/thread_info.h>
f15cbe6f 19#include <cpu/mmu_context.h>
1da177e4 20
35f3c518
PM
21atomic_t irq_err_count;
22
1da177e4
LT
23/*
24 * 'what should we do if we get a hw irq event on an illegal vector'.
25 * each architecture has to answer this themselves, it doesn't deserve
26 * a generic callback i think.
27 */
28void ack_bad_irq(unsigned int irq)
29{
baf4326e 30 atomic_inc(&irq_err_count);
1da177e4
LT
31 printk("unexpected IRQ trap at vector %02x\n", irq);
32}
33
34#if defined(CONFIG_PROC_FS)
fa1d43ab
PM
35/*
36 * /proc/interrupts printing:
37 */
38static int show_other_interrupts(struct seq_file *p, int prec)
39{
731ba330
PM
40 int j;
41
42 seq_printf(p, "%*s: ", prec, "NMI");
43 for_each_online_cpu(j)
44 seq_printf(p, "%10u ", irq_stat[j].__nmi_count);
45 seq_printf(p, " Non-maskable interrupts\n");
46
fa1d43ab 47 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
731ba330 48
fa1d43ab
PM
49 return 0;
50}
51
1da177e4
LT
52int show_interrupts(struct seq_file *p, void *v)
53{
fa1d43ab
PM
54 unsigned long flags, any_count = 0;
55 int i = *(loff_t *)v, j, prec;
56 struct irqaction *action;
57 struct irq_desc *desc;
58
59 if (i > nr_irqs)
60 return 0;
61
62 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
63 j *= 10;
64
65 if (i == nr_irqs)
66 return show_other_interrupts(p, prec);
1da177e4
LT
67
68 if (i == 0) {
fa1d43ab 69 seq_printf(p, "%*s", prec + 8, "");
394e3902 70 for_each_online_cpu(j)
fa1d43ab 71 seq_printf(p, "CPU%-8d", j);
1da177e4
LT
72 seq_putc(p, '\n');
73 }
74
fa1d43ab
PM
75 desc = irq_to_desc(i);
76 if (!desc)
77 return 0;
78
239007b8 79 raw_spin_lock_irqsave(&desc->lock, flags);
fa1d43ab
PM
80 for_each_online_cpu(j)
81 any_count |= kstat_irqs_cpu(i, j);
82 action = desc->action;
83 if (!action && !any_count)
84 goto out;
1da177e4 85
fa1d43ab
PM
86 seq_printf(p, "%*d: ", prec, i);
87 for_each_online_cpu(j)
88 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
89 seq_printf(p, " %14s", desc->chip->name);
90 seq_printf(p, "-%-8s", desc->name);
91
92 if (action) {
93 seq_printf(p, " %s", action->name);
94 while ((action = action->next) != NULL)
1da177e4 95 seq_printf(p, ", %s", action->name);
fa1d43ab 96 }
35f3c518 97
fa1d43ab
PM
98 seq_putc(p, '\n');
99out:
239007b8 100 raw_spin_unlock_irqrestore(&desc->lock, flags);
1da177e4
LT
101 return 0;
102}
103#endif
104
110ed282 105#ifdef CONFIG_IRQSTACKS
a6a31139
PM
106/*
107 * per-CPU IRQ handling contexts (thread information and stack)
108 */
109union irq_ctx {
110 struct thread_info tinfo;
111 u32 stack[THREAD_SIZE/sizeof(u32)];
112};
113
1dc41e58
PM
114static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
115static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
a6a31139
PM
116#endif
117
ba93483f 118asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
bf3a00f8 119{
f0bc814c 120 struct pt_regs *old_regs = set_irq_regs(regs);
110ed282 121#ifdef CONFIG_IRQSTACKS
a6a31139
PM
122 union irq_ctx *curctx, *irqctx;
123#endif
1da177e4
LT
124
125 irq_enter();
1e1030dc 126 irq = irq_demux(irq);
a6a31139 127
110ed282 128#ifdef CONFIG_IRQSTACKS
a6a31139
PM
129 curctx = (union irq_ctx *)current_thread_info();
130 irqctx = hardirq_ctx[smp_processor_id()];
131
132 /*
133 * this is where we switch to the IRQ stack. However, if we are
134 * already using the IRQ stack (because we interrupted a hardirq
135 * handler) we can't do that and just have to keep using the
136 * current stack (which is the irq stack already after all)
137 */
138 if (curctx != irqctx) {
139 u32 *isp;
140
141 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
142 irqctx->tinfo.task = curctx->tinfo.task;
143 irqctx->tinfo.previous_sp = current_stack_pointer;
144
1dc41e58
PM
145 /*
146 * Copy the softirq bits in preempt_count so that the
147 * softirq checks work in the hardirq context.
148 */
149 irqctx->tinfo.preempt_count =
150 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
151 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
152
a6a31139
PM
153 __asm__ __volatile__ (
154 "mov %0, r4 \n"
1dc41e58 155 "mov r15, r8 \n"
baf4326e 156 "jsr @%1 \n"
a6a31139 157 /* swith to the irq stack */
baf4326e 158 " mov %2, r15 \n"
a6a31139 159 /* restore the stack (ring zero) */
1dc41e58 160 "mov r8, r15 \n"
a6a31139 161 : /* no outputs */
35f3c518 162 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
a6a31139
PM
163 : "memory", "r0", "r1", "r2", "r3", "r4",
164 "r5", "r6", "r7", "r8", "t", "pr"
165 );
166 } else
167#endif
35f3c518 168 generic_handle_irq(irq);
a6a31139 169
1da177e4 170 irq_exit();
a6a31139 171
35f3c518 172 set_irq_regs(old_regs);
1da177e4
LT
173 return 1;
174}
a6a31139 175
110ed282 176#ifdef CONFIG_IRQSTACKS
02b7da37 177static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
a6a31139 178
02b7da37 179static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
a6a31139
PM
180
181/*
182 * allocate per-cpu stacks for hardirq and for softirq processing
183 */
184void irq_ctx_init(int cpu)
185{
186 union irq_ctx *irqctx;
187
188 if (hardirq_ctx[cpu])
189 return;
190
191 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
192 irqctx->tinfo.task = NULL;
193 irqctx->tinfo.exec_domain = NULL;
194 irqctx->tinfo.cpu = cpu;
195 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
196 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
197
198 hardirq_ctx[cpu] = irqctx;
199
200 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
201 irqctx->tinfo.task = NULL;
202 irqctx->tinfo.exec_domain = NULL;
203 irqctx->tinfo.cpu = cpu;
1dc41e58 204 irqctx->tinfo.preempt_count = 0;
a6a31139
PM
205 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
206
207 softirq_ctx[cpu] = irqctx;
208
209 printk("CPU %u irqstacks, hard=%p soft=%p\n",
210 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
211}
212
213void irq_ctx_exit(int cpu)
214{
215 hardirq_ctx[cpu] = NULL;
216}
217
a6a31139
PM
218asmlinkage void do_softirq(void)
219{
220 unsigned long flags;
221 struct thread_info *curctx;
222 union irq_ctx *irqctx;
223 u32 *isp;
224
225 if (in_interrupt())
226 return;
227
228 local_irq_save(flags);
229
230 if (local_softirq_pending()) {
231 curctx = current_thread_info();
232 irqctx = softirq_ctx[smp_processor_id()];
233 irqctx->tinfo.task = curctx->task;
234 irqctx->tinfo.previous_sp = current_stack_pointer;
235
236 /* build the stack frame on the softirq stack */
237 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
238
239 __asm__ __volatile__ (
240 "mov r15, r9 \n"
241 "jsr @%0 \n"
242 /* switch to the softirq stack */
243 " mov %1, r15 \n"
244 /* restore the thread stack */
245 "mov r9, r15 \n"
246 : /* no outputs */
247 : "r" (__do_softirq), "r" (isp)
a6a31139
PM
248 : "memory", "r0", "r1", "r2", "r3", "r4",
249 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
250 );
1dc41e58
PM
251
252 /*
253 * Shouldnt happen, we returned above if in_interrupt():
254 */
255 WARN_ON_ONCE(softirq_count());
a6a31139
PM
256 }
257
258 local_irq_restore(flags);
259}
a6a31139 260#endif
ea0f8fea
JL
261
262void __init init_IRQ(void)
263{
90015c89 264 plat_irq_setup();
ea0f8fea 265
45b9deaf
PM
266 /*
267 * Pin any of the legacy IRQ vectors that haven't already been
268 * grabbed by the platform
269 */
270 reserve_irq_legacy();
271
ea0f8fea
JL
272 /* Perform the machine specific initialisation */
273 if (sh_mv.mv_init_irq)
274 sh_mv.mv_init_irq();
275
276 irq_ctx_init(smp_processor_id());
277}
d8586ba6
PM
278
279#ifdef CONFIG_SPARSE_IRQ
280int __init arch_probe_nr_irqs(void)
281{
282 nr_irqs = sh_mv.mv_nr_irqs;
283 return 0;
284}
285#endif