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