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>
14 #include <linux/irq.h>
15 #include <asm/processor.h>
16 #include <asm/machvec.h>
17 #include <asm/uaccess.h>
18 #include <asm/thread_info.h>
19 #include <asm/cpu/mmu_context.h>
21 atomic_t irq_err_count;
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.
28 void ack_bad_irq(unsigned int irq)
30 atomic_inc(&irq_err_count);
31 printk("unexpected IRQ trap at vector %02x\n", irq);
34 #if defined(CONFIG_PROC_FS)
35 int show_interrupts(struct seq_file *p, void *v)
37 int i = *(loff_t *) v, j;
38 struct irqaction * action;
43 for_each_online_cpu(j)
44 seq_printf(p, "CPU%d ",j);
48 if (i < sh_mv.mv_nr_irqs) {
49 spin_lock_irqsave(&irq_desc[i].lock, flags);
50 action = irq_desc[i].action;
53 seq_printf(p, "%3d: ",i);
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);
57 seq_printf(p, "-%-8s", irq_desc[i].name);
58 seq_printf(p, " %s", action->name);
60 for (action=action->next; action; action = action->next)
61 seq_printf(p, ", %s", action->name);
64 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
65 } else if (i == sh_mv.mv_nr_irqs)
66 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
72 #ifdef CONFIG_4KSTACKS
74 * per-CPU IRQ handling contexts (thread information and stack)
77 struct thread_info tinfo;
78 u32 stack[THREAD_SIZE/sizeof(u32)];
81 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
82 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
85 asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
87 struct pt_regs *old_regs = set_irq_regs(regs);
88 #ifdef CONFIG_4KSTACKS
89 union irq_ctx *curctx, *irqctx;
94 #ifdef CONFIG_DEBUG_STACKOVERFLOW
95 /* Debugging check for stack overflow: is there less than 1KB free? */
99 __asm__ __volatile__ ("and r15, %0" :
100 "=r" (sp) : "0" (THREAD_SIZE - 1));
102 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
103 printk("do_IRQ: stack overflow: %ld\n",
104 sp - sizeof(struct thread_info));
110 irq = irq_demux(evt2irq(irq));
112 #ifdef CONFIG_4KSTACKS
113 curctx = (union irq_ctx *)current_thread_info();
114 irqctx = hardirq_ctx[smp_processor_id()];
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)
122 if (curctx != irqctx) {
125 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
126 irqctx->tinfo.task = curctx->tinfo.task;
127 irqctx->tinfo.previous_sp = current_stack_pointer;
130 * Copy the softirq bits in preempt_count so that the
131 * softirq checks work in the hardirq context.
133 irqctx->tinfo.preempt_count =
134 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
135 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
137 __asm__ __volatile__ (
141 /* swith to the irq stack */
143 /* restore the stack (ring zero) */
146 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
147 : "memory", "r0", "r1", "r2", "r3", "r4",
148 "r5", "r6", "r7", "r8", "t", "pr"
152 generic_handle_irq(irq);
156 set_irq_regs(old_regs);
160 #ifdef CONFIG_4KSTACKS
161 static char softirq_stack[NR_CPUS * THREAD_SIZE]
162 __attribute__((__section__(".bss.page_aligned")));
164 static char hardirq_stack[NR_CPUS * THREAD_SIZE]
165 __attribute__((__section__(".bss.page_aligned")));
168 * allocate per-cpu stacks for hardirq and for softirq processing
170 void irq_ctx_init(int cpu)
172 union irq_ctx *irqctx;
174 if (hardirq_ctx[cpu])
177 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
178 irqctx->tinfo.task = NULL;
179 irqctx->tinfo.exec_domain = NULL;
180 irqctx->tinfo.cpu = cpu;
181 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
182 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
184 hardirq_ctx[cpu] = irqctx;
186 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
187 irqctx->tinfo.task = NULL;
188 irqctx->tinfo.exec_domain = NULL;
189 irqctx->tinfo.cpu = cpu;
190 irqctx->tinfo.preempt_count = 0;
191 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
193 softirq_ctx[cpu] = irqctx;
195 printk("CPU %u irqstacks, hard=%p soft=%p\n",
196 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
199 void irq_ctx_exit(int cpu)
201 hardirq_ctx[cpu] = NULL;
204 extern asmlinkage void __do_softirq(void);
206 asmlinkage void do_softirq(void)
209 struct thread_info *curctx;
210 union irq_ctx *irqctx;
216 local_irq_save(flags);
218 if (local_softirq_pending()) {
219 curctx = current_thread_info();
220 irqctx = softirq_ctx[smp_processor_id()];
221 irqctx->tinfo.task = curctx->task;
222 irqctx->tinfo.previous_sp = current_stack_pointer;
224 /* build the stack frame on the softirq stack */
225 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
227 __asm__ __volatile__ (
230 /* switch to the softirq stack */
232 /* restore the thread stack */
235 : "r" (__do_softirq), "r" (isp)
236 : "memory", "r0", "r1", "r2", "r3", "r4",
237 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
241 * Shouldnt happen, we returned above if in_interrupt():
243 WARN_ON_ONCE(softirq_count());
246 local_irq_restore(flags);
250 void __init init_IRQ(void)
252 #ifdef CONFIG_CPU_HAS_PINT_IRQ
257 /* Perform the machine specific initialisation */
258 if (sh_mv.mv_init_irq)
261 irq_ctx_init(smp_processor_id());