2 * linux/arch/sh/kernel/irq.c
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
7 * SuperH version: Copyright (C) 1999 Niibe Yutaka
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/seq_file.h>
15 #include <asm/processor.h>
16 #include <asm/uaccess.h>
17 #include <asm/thread_info.h>
18 #include <asm/cpu/mmu_context.h>
21 * 'what should we do if we get a hw irq event on an illegal vector'.
22 * each architecture has to answer this themselves, it doesn't deserve
23 * a generic callback i think.
25 void ack_bad_irq(unsigned int irq)
27 printk("unexpected IRQ trap at vector %02x\n", irq);
30 #if defined(CONFIG_PROC_FS)
31 int show_interrupts(struct seq_file *p, void *v)
33 int i = *(loff_t *) v, j;
34 struct irqaction * action;
39 for_each_online_cpu(j)
40 seq_printf(p, "CPU%d ",j);
45 spin_lock_irqsave(&irq_desc[i].lock, flags);
46 action = irq_desc[i].action;
49 seq_printf(p, "%3d: ",i);
50 seq_printf(p, "%10u ", kstat_irqs(i));
51 seq_printf(p, " %14s", irq_desc[i].chip->typename);
52 seq_printf(p, " %s", action->name);
54 for (action=action->next; action; action = action->next)
55 seq_printf(p, ", %s", action->name);
58 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
64 #ifdef CONFIG_4KSTACKS
66 * per-CPU IRQ handling contexts (thread information and stack)
69 struct thread_info tinfo;
70 u32 stack[THREAD_SIZE/sizeof(u32)];
73 static union irq_ctx *hardirq_ctx[NR_CPUS];
74 static union irq_ctx *softirq_ctx[NR_CPUS];
77 asmlinkage int do_IRQ(unsigned long r4, unsigned long r5,
78 unsigned long r6, unsigned long r7,
82 #ifdef CONFIG_4KSTACKS
83 union irq_ctx *curctx, *irqctx;
88 #ifdef CONFIG_DEBUG_STACKOVERFLOW
89 /* Debugging check for stack overflow: is there less than 1KB free? */
93 __asm__ __volatile__ ("and r15, %0" :
94 "=r" (sp) : "0" (THREAD_SIZE - 1));
96 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
97 printk("do_IRQ: stack overflow: %ld\n",
98 sp - sizeof(struct thread_info));
104 #ifdef CONFIG_CPU_HAS_INTEVT
105 __asm__ __volatile__ (
106 #ifdef CONFIG_CPU_HAS_SR_RB
107 "stc r2_bank, %0\n\t"
115 : "=z" (irq), "=r" (r4)
121 irq = irq_demux(irq);
123 #ifdef CONFIG_4KSTACKS
124 curctx = (union irq_ctx *)current_thread_info();
125 irqctx = hardirq_ctx[smp_processor_id()];
128 * this is where we switch to the IRQ stack. However, if we are
129 * already using the IRQ stack (because we interrupted a hardirq
130 * handler) we can't do that and just have to keep using the
131 * current stack (which is the irq stack already after all)
133 if (curctx != irqctx) {
136 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
137 irqctx->tinfo.task = curctx->tinfo.task;
138 irqctx->tinfo.previous_sp = current_stack_pointer;
140 __asm__ __volatile__ (
145 /* swith to the irq stack */
147 /* restore the stack (ring zero) */
150 : "r" (irq), "r" (®s), "r" (__do_IRQ), "r" (isp)
151 /* XXX: A somewhat excessive clobber list? -PFM */
152 : "memory", "r0", "r1", "r2", "r3", "r4",
153 "r5", "r6", "r7", "r8", "t", "pr"
157 __do_IRQ(irq, ®s);
164 #ifdef CONFIG_4KSTACKS
166 * These should really be __section__(".bss.page_aligned") as well, but
167 * gcc's 3.0 and earlier don't handle that correctly.
169 static char softirq_stack[NR_CPUS * THREAD_SIZE]
170 __attribute__((__aligned__(THREAD_SIZE)));
172 static char hardirq_stack[NR_CPUS * THREAD_SIZE]
173 __attribute__((__aligned__(THREAD_SIZE)));
176 * allocate per-cpu stacks for hardirq and for softirq processing
178 void irq_ctx_init(int cpu)
180 union irq_ctx *irqctx;
182 if (hardirq_ctx[cpu])
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);
192 hardirq_ctx[cpu] = irqctx;
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;
198 irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
199 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
201 softirq_ctx[cpu] = irqctx;
203 printk("CPU %u irqstacks, hard=%p soft=%p\n",
204 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
207 void irq_ctx_exit(int cpu)
209 hardirq_ctx[cpu] = NULL;
212 extern asmlinkage void __do_softirq(void);
214 asmlinkage void do_softirq(void)
217 struct thread_info *curctx;
218 union irq_ctx *irqctx;
224 local_irq_save(flags);
226 if (local_softirq_pending()) {
227 curctx = current_thread_info();
228 irqctx = softirq_ctx[smp_processor_id()];
229 irqctx->tinfo.task = curctx->task;
230 irqctx->tinfo.previous_sp = current_stack_pointer;
232 /* build the stack frame on the softirq stack */
233 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
235 __asm__ __volatile__ (
238 /* switch to the softirq stack */
240 /* restore the thread stack */
243 : "r" (__do_softirq), "r" (isp)
244 /* XXX: A somewhat excessive clobber list? -PFM */
245 : "memory", "r0", "r1", "r2", "r3", "r4",
246 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
250 local_irq_restore(flags);
252 EXPORT_SYMBOL(do_softirq);