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 <asm/processor.h>
15 #include <asm/machvec.h>
16 #include <asm/uaccess.h>
17 #include <asm/thread_info.h>
18 #include <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)
35 * /proc/interrupts printing:
37 static int show_other_interrupts(struct seq_file *p, int prec)
41 seq_printf(p, "%*s: ", prec, "NMI");
42 for_each_online_cpu(j)
43 seq_printf(p, "%10u ", irq_stat[j].__nmi_count);
44 seq_printf(p, " Non-maskable interrupts\n");
46 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
51 int show_interrupts(struct seq_file *p, void *v)
53 unsigned long flags, any_count = 0;
54 int i = *(loff_t *)v, j, prec;
55 struct irqaction *action;
56 struct irq_desc *desc;
61 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
65 return show_other_interrupts(p, prec);
68 seq_printf(p, "%*s", prec + 8, "");
69 for_each_online_cpu(j)
70 seq_printf(p, "CPU%-8d", j);
74 desc = irq_to_desc(i);
78 spin_lock_irqsave(&desc->lock, flags);
79 for_each_online_cpu(j)
80 any_count |= kstat_irqs_cpu(i, j);
81 action = desc->action;
82 if (!action && !any_count)
85 seq_printf(p, "%*d: ", prec, i);
86 for_each_online_cpu(j)
87 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
88 seq_printf(p, " %14s", desc->chip->name);
89 seq_printf(p, "-%-8s", desc->name);
92 seq_printf(p, " %s", action->name);
93 while ((action = action->next) != NULL)
94 seq_printf(p, ", %s", action->name);
99 spin_unlock_irqrestore(&desc->lock, flags);
104 #ifdef CONFIG_IRQSTACKS
106 * per-CPU IRQ handling contexts (thread information and stack)
109 struct thread_info tinfo;
110 u32 stack[THREAD_SIZE/sizeof(u32)];
113 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
114 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
117 asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
119 struct pt_regs *old_regs = set_irq_regs(regs);
120 #ifdef CONFIG_IRQSTACKS
121 union irq_ctx *curctx, *irqctx;
125 irq = irq_demux(irq);
127 #ifdef CONFIG_IRQSTACKS
128 curctx = (union irq_ctx *)current_thread_info();
129 irqctx = hardirq_ctx[smp_processor_id()];
132 * this is where we switch to the IRQ stack. However, if we are
133 * already using the IRQ stack (because we interrupted a hardirq
134 * handler) we can't do that and just have to keep using the
135 * current stack (which is the irq stack already after all)
137 if (curctx != irqctx) {
140 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
141 irqctx->tinfo.task = curctx->tinfo.task;
142 irqctx->tinfo.previous_sp = current_stack_pointer;
145 * Copy the softirq bits in preempt_count so that the
146 * softirq checks work in the hardirq context.
148 irqctx->tinfo.preempt_count =
149 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
150 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
152 __asm__ __volatile__ (
156 /* swith to the irq stack */
158 /* restore the stack (ring zero) */
161 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
162 : "memory", "r0", "r1", "r2", "r3", "r4",
163 "r5", "r6", "r7", "r8", "t", "pr"
167 generic_handle_irq(irq);
171 set_irq_regs(old_regs);
175 #ifdef CONFIG_IRQSTACKS
176 static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
178 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
181 * allocate per-cpu stacks for hardirq and for softirq processing
183 void irq_ctx_init(int cpu)
185 union irq_ctx *irqctx;
187 if (hardirq_ctx[cpu])
190 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
191 irqctx->tinfo.task = NULL;
192 irqctx->tinfo.exec_domain = NULL;
193 irqctx->tinfo.cpu = cpu;
194 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
195 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
197 hardirq_ctx[cpu] = irqctx;
199 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
200 irqctx->tinfo.task = NULL;
201 irqctx->tinfo.exec_domain = NULL;
202 irqctx->tinfo.cpu = cpu;
203 irqctx->tinfo.preempt_count = 0;
204 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
206 softirq_ctx[cpu] = irqctx;
208 printk("CPU %u irqstacks, hard=%p soft=%p\n",
209 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
212 void irq_ctx_exit(int cpu)
214 hardirq_ctx[cpu] = NULL;
217 asmlinkage void do_softirq(void)
220 struct thread_info *curctx;
221 union irq_ctx *irqctx;
227 local_irq_save(flags);
229 if (local_softirq_pending()) {
230 curctx = current_thread_info();
231 irqctx = softirq_ctx[smp_processor_id()];
232 irqctx->tinfo.task = curctx->task;
233 irqctx->tinfo.previous_sp = current_stack_pointer;
235 /* build the stack frame on the softirq stack */
236 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
238 __asm__ __volatile__ (
241 /* switch to the softirq stack */
243 /* restore the thread stack */
246 : "r" (__do_softirq), "r" (isp)
247 : "memory", "r0", "r1", "r2", "r3", "r4",
248 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
252 * Shouldnt happen, we returned above if in_interrupt():
254 WARN_ON_ONCE(softirq_count());
257 local_irq_restore(flags);
261 void __init init_IRQ(void)
265 /* Perform the machine specific initialisation */
266 if (sh_mv.mv_init_irq)
269 irq_ctx_init(smp_processor_id());
272 #ifdef CONFIG_SPARSE_IRQ
273 int __init arch_probe_nr_irqs(void)
275 nr_irqs = sh_mv.mv_nr_irqs;