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/ftrace.h>
15 #include <asm/processor.h>
16 #include <asm/machvec.h>
17 #include <asm/uaccess.h>
18 #include <asm/thread_info.h>
19 #include <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)
36 * /proc/interrupts printing:
38 static int show_other_interrupts(struct seq_file *p, int prec)
42 seq_printf(p, "%*s: ", prec, "NMI");
43 for_each_online_cpu(j)
44 seq_printf(p, "%10u ", irq_stat[j].__nmi_count);
45 seq_printf(p, " Non-maskable interrupts\n");
47 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
52 int show_interrupts(struct seq_file *p, void *v)
54 unsigned long flags, any_count = 0;
55 int i = *(loff_t *)v, j, prec;
56 struct irqaction *action;
57 struct irq_desc *desc;
62 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
66 return show_other_interrupts(p, prec);
69 seq_printf(p, "%*s", prec + 8, "");
70 for_each_online_cpu(j)
71 seq_printf(p, "CPU%-8d", j);
75 desc = irq_to_desc(i);
79 raw_spin_lock_irqsave(&desc->lock, flags);
80 for_each_online_cpu(j)
81 any_count |= kstat_irqs_cpu(i, j);
82 action = desc->action;
83 if (!action && !any_count)
86 seq_printf(p, "%*d: ", prec, i);
87 for_each_online_cpu(j)
88 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
89 seq_printf(p, " %14s", desc->chip->name);
90 seq_printf(p, "-%-8s", desc->name);
93 seq_printf(p, " %s", action->name);
94 while ((action = action->next) != NULL)
95 seq_printf(p, ", %s", action->name);
100 raw_spin_unlock_irqrestore(&desc->lock, flags);
105 #ifdef CONFIG_IRQSTACKS
107 * per-CPU IRQ handling contexts (thread information and stack)
110 struct thread_info tinfo;
111 u32 stack[THREAD_SIZE/sizeof(u32)];
114 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
115 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
117 static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
118 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
120 static inline void handle_one_irq(unsigned int irq)
122 union irq_ctx *curctx, *irqctx;
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;
141 * Copy the softirq bits in preempt_count so that the
142 * softirq checks work in the hardirq context.
144 irqctx->tinfo.preempt_count =
145 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
146 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
148 __asm__ __volatile__ (
152 /* swith to the irq stack */
154 /* restore the stack (ring zero) */
157 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
158 : "memory", "r0", "r1", "r2", "r3", "r4",
159 "r5", "r6", "r7", "r8", "t", "pr"
162 generic_handle_irq(irq);
166 * allocate per-cpu stacks for hardirq and for softirq processing
168 void irq_ctx_init(int cpu)
170 union irq_ctx *irqctx;
172 if (hardirq_ctx[cpu])
175 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
176 irqctx->tinfo.task = NULL;
177 irqctx->tinfo.exec_domain = NULL;
178 irqctx->tinfo.cpu = cpu;
179 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
180 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
182 hardirq_ctx[cpu] = irqctx;
184 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
185 irqctx->tinfo.task = NULL;
186 irqctx->tinfo.exec_domain = NULL;
187 irqctx->tinfo.cpu = cpu;
188 irqctx->tinfo.preempt_count = 0;
189 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
191 softirq_ctx[cpu] = irqctx;
193 printk("CPU %u irqstacks, hard=%p soft=%p\n",
194 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
197 void irq_ctx_exit(int cpu)
199 hardirq_ctx[cpu] = NULL;
202 asmlinkage void do_softirq(void)
205 struct thread_info *curctx;
206 union irq_ctx *irqctx;
212 local_irq_save(flags);
214 if (local_softirq_pending()) {
215 curctx = current_thread_info();
216 irqctx = softirq_ctx[smp_processor_id()];
217 irqctx->tinfo.task = curctx->task;
218 irqctx->tinfo.previous_sp = current_stack_pointer;
220 /* build the stack frame on the softirq stack */
221 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
223 __asm__ __volatile__ (
226 /* switch to the softirq stack */
228 /* restore the thread stack */
231 : "r" (__do_softirq), "r" (isp)
232 : "memory", "r0", "r1", "r2", "r3", "r4",
233 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
237 * Shouldnt happen, we returned above if in_interrupt():
239 WARN_ON_ONCE(softirq_count());
242 local_irq_restore(flags);
245 static inline void handle_one_irq(unsigned int irq)
247 generic_handle_irq(irq);
251 asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
253 struct pt_regs *old_regs = set_irq_regs(regs);
257 irq = irq_demux(irq_lookup(irq));
259 if (irq != NO_IRQ_IGNORE) {
266 set_irq_regs(old_regs);
271 void __init init_IRQ(void)
276 * Pin any of the legacy IRQ vectors that haven't already been
277 * grabbed by the platform
279 reserve_irq_legacy();
281 /* Perform the machine specific initialisation */
282 if (sh_mv.mv_init_irq)
285 irq_ctx_init(smp_processor_id());
288 #ifdef CONFIG_SPARSE_IRQ
289 int __init arch_probe_nr_irqs(void)
291 nr_irqs = sh_mv.mv_nr_irqs;