sh: Fix bogus regs pointer in do_IRQ().
[linux-2.6/cjktty.git] / arch / sh / kernel / irq.c
blob9bdd8a00cd4a3a8b5dffb10a0911bdff37f13079
1 /*
2 * linux/arch/sh/kernel/irq.c
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
7 * SuperH version: Copyright (C) 1999 Niibe Yutaka
8 */
9 #include <linux/irq.h>
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/seq_file.h>
14 #include <linux/irq.h>
15 #include <asm/processor.h>
16 #include <asm/uaccess.h>
17 #include <asm/thread_info.h>
18 #include <asm/cpu/mmu_context.h>
20 atomic_t irq_err_count;
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.
27 void ack_bad_irq(unsigned int irq)
29 atomic_inc(&irq_err_count);
30 printk("unexpected IRQ trap at vector %02x\n", irq);
33 #if defined(CONFIG_PROC_FS)
34 int show_interrupts(struct seq_file *p, void *v)
36 int i = *(loff_t *) v, j;
37 struct irqaction * action;
38 unsigned long flags;
40 if (i == 0) {
41 seq_puts(p, " ");
42 for_each_online_cpu(j)
43 seq_printf(p, "CPU%d ",j);
44 seq_putc(p, '\n');
47 if (i < NR_IRQS) {
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);
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);
56 seq_printf(p, "-%-8s", irq_desc[i].name);
57 seq_printf(p, " %s", action->name);
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);
64 } else if (i == NR_IRQS)
65 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
67 return 0;
69 #endif
71 #ifdef CONFIG_4KSTACKS
73 * per-CPU IRQ handling contexts (thread information and stack)
75 union irq_ctx {
76 struct thread_info tinfo;
77 u32 stack[THREAD_SIZE/sizeof(u32)];
80 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
81 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
82 #endif
84 asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
86 struct pt_regs *old_regs = set_irq_regs(regs);
87 #ifdef CONFIG_4KSTACKS
88 union irq_ctx *curctx, *irqctx;
89 #endif
91 irq_enter();
93 #ifdef CONFIG_DEBUG_STACKOVERFLOW
94 /* Debugging check for stack overflow: is there less than 1KB free? */
96 long sp;
98 __asm__ __volatile__ ("and r15, %0" :
99 "=r" (sp) : "0" (THREAD_SIZE - 1));
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();
107 #endif
109 irq = irq_demux(evt2irq(irq));
111 #ifdef CONFIG_4KSTACKS
112 curctx = (union irq_ctx *)current_thread_info();
113 irqctx = hardirq_ctx[smp_processor_id()];
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)
121 if (curctx != irqctx) {
122 u32 *isp;
124 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
125 irqctx->tinfo.task = curctx->tinfo.task;
126 irqctx->tinfo.previous_sp = current_stack_pointer;
129 * Copy the softirq bits in preempt_count so that the
130 * softirq checks work in the hardirq context.
132 irqctx->tinfo.preempt_count =
133 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
134 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
136 __asm__ __volatile__ (
137 "mov %0, r4 \n"
138 "mov r15, r8 \n"
139 "jsr @%1 \n"
140 /* swith to the irq stack */
141 " mov %2, r15 \n"
142 /* restore the stack (ring zero) */
143 "mov r8, r15 \n"
144 : /* no outputs */
145 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
146 : "memory", "r0", "r1", "r2", "r3", "r4",
147 "r5", "r6", "r7", "r8", "t", "pr"
149 } else
150 #endif
151 generic_handle_irq(irq);
153 irq_exit();
155 set_irq_regs(old_regs);
156 return 1;
159 #ifdef CONFIG_4KSTACKS
161 * These should really be __section__(".bss.page_aligned") as well, but
162 * gcc's 3.0 and earlier don't handle that correctly.
164 static char softirq_stack[NR_CPUS * THREAD_SIZE]
165 __attribute__((__aligned__(THREAD_SIZE)));
167 static char hardirq_stack[NR_CPUS * THREAD_SIZE]
168 __attribute__((__aligned__(THREAD_SIZE)));
171 * allocate per-cpu stacks for hardirq and for softirq processing
173 void irq_ctx_init(int cpu)
175 union irq_ctx *irqctx;
177 if (hardirq_ctx[cpu])
178 return;
180 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
181 irqctx->tinfo.task = NULL;
182 irqctx->tinfo.exec_domain = NULL;
183 irqctx->tinfo.cpu = cpu;
184 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
185 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
187 hardirq_ctx[cpu] = irqctx;
189 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
190 irqctx->tinfo.task = NULL;
191 irqctx->tinfo.exec_domain = NULL;
192 irqctx->tinfo.cpu = cpu;
193 irqctx->tinfo.preempt_count = 0;
194 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
196 softirq_ctx[cpu] = irqctx;
198 printk("CPU %u irqstacks, hard=%p soft=%p\n",
199 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
202 void irq_ctx_exit(int cpu)
204 hardirq_ctx[cpu] = NULL;
207 extern asmlinkage void __do_softirq(void);
209 asmlinkage void do_softirq(void)
211 unsigned long flags;
212 struct thread_info *curctx;
213 union irq_ctx *irqctx;
214 u32 *isp;
216 if (in_interrupt())
217 return;
219 local_irq_save(flags);
221 if (local_softirq_pending()) {
222 curctx = current_thread_info();
223 irqctx = softirq_ctx[smp_processor_id()];
224 irqctx->tinfo.task = curctx->task;
225 irqctx->tinfo.previous_sp = current_stack_pointer;
227 /* build the stack frame on the softirq stack */
228 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
230 __asm__ __volatile__ (
231 "mov r15, r9 \n"
232 "jsr @%0 \n"
233 /* switch to the softirq stack */
234 " mov %1, r15 \n"
235 /* restore the thread stack */
236 "mov r9, r15 \n"
237 : /* no outputs */
238 : "r" (__do_softirq), "r" (isp)
239 : "memory", "r0", "r1", "r2", "r3", "r4",
240 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
244 * Shouldnt happen, we returned above if in_interrupt():
246 WARN_ON_ONCE(softirq_count());
249 local_irq_restore(flags);
251 EXPORT_SYMBOL(do_softirq);
252 #endif
254 void __init init_IRQ(void)
256 #ifdef CONFIG_CPU_HAS_PINT_IRQ
257 init_IRQ_pint();
258 #endif
260 #ifdef CONFIG_CPU_HAS_INTC2_IRQ
261 init_IRQ_intc2();
262 #endif
264 #ifdef CONFIG_CPU_HAS_IPR_IRQ
265 init_IRQ_ipr();
266 #endif
268 /* Perform the machine specific initialisation */
269 if (sh_mv.mv_init_irq)
270 sh_mv.mv_init_irq();
272 irq_ctx_init(smp_processor_id());