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)
40 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
44 int show_interrupts(struct seq_file *p, void *v)
46 unsigned long flags, any_count = 0;
47 int i = *(loff_t *)v, j, prec;
48 struct irqaction *action;
49 struct irq_desc *desc;
54 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
58 return show_other_interrupts(p, prec);
61 seq_printf(p, "%*s", prec + 8, "");
62 for_each_online_cpu(j)
63 seq_printf(p, "CPU%-8d", j);
67 desc = irq_to_desc(i);
71 spin_lock_irqsave(&desc->lock, flags);
72 for_each_online_cpu(j)
73 any_count |= kstat_irqs_cpu(i, j);
74 action = desc->action;
75 if (!action && !any_count)
78 seq_printf(p, "%*d: ", prec, i);
79 for_each_online_cpu(j)
80 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
81 seq_printf(p, " %14s", desc->chip->name);
82 seq_printf(p, "-%-8s", desc->name);
85 seq_printf(p, " %s", action->name);
86 while ((action = action->next) != NULL)
87 seq_printf(p, ", %s", action->name);
92 spin_unlock_irqrestore(&desc->lock, flags);
97 #ifdef CONFIG_IRQSTACKS
99 * per-CPU IRQ handling contexts (thread information and stack)
102 struct thread_info tinfo;
103 u32 stack[THREAD_SIZE/sizeof(u32)];
106 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
107 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
110 asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
112 struct pt_regs *old_regs = set_irq_regs(regs);
113 #ifdef CONFIG_IRQSTACKS
114 union irq_ctx *curctx, *irqctx;
118 irq = irq_demux(irq);
120 #ifdef CONFIG_IRQSTACKS
121 curctx = (union irq_ctx *)current_thread_info();
122 irqctx = hardirq_ctx[smp_processor_id()];
125 * this is where we switch to the IRQ stack. However, if we are
126 * already using the IRQ stack (because we interrupted a hardirq
127 * handler) we can't do that and just have to keep using the
128 * current stack (which is the irq stack already after all)
130 if (curctx != irqctx) {
133 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
134 irqctx->tinfo.task = curctx->tinfo.task;
135 irqctx->tinfo.previous_sp = current_stack_pointer;
138 * Copy the softirq bits in preempt_count so that the
139 * softirq checks work in the hardirq context.
141 irqctx->tinfo.preempt_count =
142 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
143 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
145 __asm__ __volatile__ (
149 /* swith to the irq stack */
151 /* restore the stack (ring zero) */
154 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
155 : "memory", "r0", "r1", "r2", "r3", "r4",
156 "r5", "r6", "r7", "r8", "t", "pr"
160 generic_handle_irq(irq);
164 set_irq_regs(old_regs);
168 #ifdef CONFIG_IRQSTACKS
169 static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
171 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
174 * allocate per-cpu stacks for hardirq and for softirq processing
176 void irq_ctx_init(int cpu)
178 union irq_ctx *irqctx;
180 if (hardirq_ctx[cpu])
183 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
184 irqctx->tinfo.task = NULL;
185 irqctx->tinfo.exec_domain = NULL;
186 irqctx->tinfo.cpu = cpu;
187 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
188 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
190 hardirq_ctx[cpu] = irqctx;
192 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
193 irqctx->tinfo.task = NULL;
194 irqctx->tinfo.exec_domain = NULL;
195 irqctx->tinfo.cpu = cpu;
196 irqctx->tinfo.preempt_count = 0;
197 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
199 softirq_ctx[cpu] = irqctx;
201 printk("CPU %u irqstacks, hard=%p soft=%p\n",
202 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
205 void irq_ctx_exit(int cpu)
207 hardirq_ctx[cpu] = NULL;
210 asmlinkage void do_softirq(void)
213 struct thread_info *curctx;
214 union irq_ctx *irqctx;
220 local_irq_save(flags);
222 if (local_softirq_pending()) {
223 curctx = current_thread_info();
224 irqctx = softirq_ctx[smp_processor_id()];
225 irqctx->tinfo.task = curctx->task;
226 irqctx->tinfo.previous_sp = current_stack_pointer;
228 /* build the stack frame on the softirq stack */
229 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
231 __asm__ __volatile__ (
234 /* switch to the softirq stack */
236 /* restore the thread stack */
239 : "r" (__do_softirq), "r" (isp)
240 : "memory", "r0", "r1", "r2", "r3", "r4",
241 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
245 * Shouldnt happen, we returned above if in_interrupt():
247 WARN_ON_ONCE(softirq_count());
250 local_irq_restore(flags);
254 void __init init_IRQ(void)
258 /* Perform the machine specific initialisation */
259 if (sh_mv.mv_init_irq)
262 irq_ctx_init(smp_processor_id());
265 #ifdef CONFIG_SPARSE_IRQ
266 int __init arch_probe_nr_irqs(void)
268 nr_irqs = sh_mv.mv_nr_irqs;