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