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