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