blob: 11c289ecc0909cde27c39c7eff343158208ea7e6 [file] [log] [blame]
Paul Mundta6a311392006-09-27 18:22:14 +09001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * linux/arch/sh/kernel/irq.c
3 *
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
5 *
6 *
7 * SuperH version: Copyright (C) 1999 Niibe Yutaka
8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/irq.h>
Paul Mundtbf3a00f2006-01-16 22:14:14 -080010#include <linux/interrupt.h>
Paul Mundta6a311392006-09-27 18:22:14 +090011#include <linux/module.h>
Paul Mundtbf3a00f2006-01-16 22:14:14 -080012#include <linux/kernel_stat.h>
13#include <linux/seq_file.h>
Paul Mundtbf3a00f2006-01-16 22:14:14 -080014#include <asm/processor.h>
Paul Mundtbe782df2007-03-12 14:09:35 +090015#include <asm/machvec.h>
Paul Mundta6a311392006-09-27 18:22:14 +090016#include <asm/uaccess.h>
17#include <asm/thread_info.h>
Paul Mundtf15cbe62008-07-29 08:09:44 +090018#include <cpu/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Paul Mundt35f3c512006-10-06 15:31:16 +090020atomic_t irq_err_count;
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/*
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.
26 */
27void ack_bad_irq(unsigned int irq)
28{
Paul Mundtbaf43262006-10-12 12:03:04 +090029 atomic_inc(&irq_err_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 printk("unexpected IRQ trap at vector %02x\n", irq);
31}
32
33#if defined(CONFIG_PROC_FS)
Paul Mundtfa1d43a2009-05-22 01:26:16 +090034/*
35 * /proc/interrupts printing:
36 */
37static int show_other_interrupts(struct seq_file *p, int prec)
38{
Paul Mundt731ba332009-10-14 16:42:28 +090039 int j;
40
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");
45
Paul Mundtfa1d43a2009-05-22 01:26:16 +090046 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
Paul Mundt731ba332009-10-14 16:42:28 +090047
Paul Mundtfa1d43a2009-05-22 01:26:16 +090048 return 0;
49}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051int show_interrupts(struct seq_file *p, void *v)
52{
Paul Mundtfa1d43a2009-05-22 01:26:16 +090053 unsigned long flags, any_count = 0;
54 int i = *(loff_t *)v, j, prec;
55 struct irqaction *action;
56 struct irq_desc *desc;
57
58 if (i > nr_irqs)
59 return 0;
60
61 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
62 j *= 10;
63
64 if (i == nr_irqs)
65 return show_other_interrupts(p, prec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 if (i == 0) {
Paul Mundtfa1d43a2009-05-22 01:26:16 +090068 seq_printf(p, "%*s", prec + 8, "");
Andrew Morton394e3902006-03-23 03:01:05 -080069 for_each_online_cpu(j)
Paul Mundtfa1d43a2009-05-22 01:26:16 +090070 seq_printf(p, "CPU%-8d", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 seq_putc(p, '\n');
72 }
73
Paul Mundtfa1d43a2009-05-22 01:26:16 +090074 desc = irq_to_desc(i);
75 if (!desc)
76 return 0;
77
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)
83 goto out;
84
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);
90
91 if (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 seq_printf(p, " %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090093 while ((action = action->next) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 seq_printf(p, ", %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090095 }
Paul Mundt35f3c512006-10-06 15:31:16 +090096
Paul Mundtfa1d43a2009-05-22 01:26:16 +090097 seq_putc(p, '\n');
98out:
99 spin_unlock_irqrestore(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return 0;
101}
102#endif
103
Paul Mundt110ed282007-11-02 12:16:51 +0900104#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900105/*
106 * per-CPU IRQ handling contexts (thread information and stack)
107 */
108union irq_ctx {
109 struct thread_info tinfo;
110 u32 stack[THREAD_SIZE/sizeof(u32)];
111};
112
Paul Mundt1dc41e52006-11-24 19:46:18 +0900113static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
114static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
Paul Mundta6a311392006-09-27 18:22:14 +0900115#endif
116
Paul Mundt3afb2092007-03-14 13:03:35 +0900117asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800118{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900119 struct pt_regs *old_regs = set_irq_regs(regs);
Paul Mundt110ed282007-11-02 12:16:51 +0900120#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900121 union irq_ctx *curctx, *irqctx;
122#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 irq_enter();
Paul Mundt1e1030d2009-09-01 17:38:32 +0900125 irq = irq_demux(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900126
Paul Mundt110ed282007-11-02 12:16:51 +0900127#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900128 curctx = (union irq_ctx *)current_thread_info();
129 irqctx = hardirq_ctx[smp_processor_id()];
130
131 /*
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)
136 */
137 if (curctx != irqctx) {
138 u32 *isp;
139
140 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
141 irqctx->tinfo.task = curctx->tinfo.task;
142 irqctx->tinfo.previous_sp = current_stack_pointer;
143
Paul Mundt1dc41e52006-11-24 19:46:18 +0900144 /*
145 * Copy the softirq bits in preempt_count so that the
146 * softirq checks work in the hardirq context.
147 */
148 irqctx->tinfo.preempt_count =
149 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
150 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
151
Paul Mundta6a311392006-09-27 18:22:14 +0900152 __asm__ __volatile__ (
153 "mov %0, r4 \n"
Paul Mundt1dc41e52006-11-24 19:46:18 +0900154 "mov r15, r8 \n"
Paul Mundtbaf43262006-10-12 12:03:04 +0900155 "jsr @%1 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900156 /* swith to the irq stack */
Paul Mundtbaf43262006-10-12 12:03:04 +0900157 " mov %2, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900158 /* restore the stack (ring zero) */
Paul Mundt1dc41e52006-11-24 19:46:18 +0900159 "mov r8, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900160 : /* no outputs */
Paul Mundt35f3c512006-10-06 15:31:16 +0900161 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900162 : "memory", "r0", "r1", "r2", "r3", "r4",
163 "r5", "r6", "r7", "r8", "t", "pr"
164 );
165 } else
166#endif
Paul Mundt35f3c512006-10-06 15:31:16 +0900167 generic_handle_irq(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 irq_exit();
Paul Mundta6a311392006-09-27 18:22:14 +0900170
Paul Mundt35f3c512006-10-06 15:31:16 +0900171 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return 1;
173}
Paul Mundta6a311392006-09-27 18:22:14 +0900174
Paul Mundt110ed282007-11-02 12:16:51 +0900175#ifdef CONFIG_IRQSTACKS
Tim Abbott02b7da32009-09-20 18:14:14 -0400176static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
Paul Mundta6a311392006-09-27 18:22:14 +0900177
Tim Abbott02b7da32009-09-20 18:14:14 -0400178static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
Paul Mundta6a311392006-09-27 18:22:14 +0900179
180/*
181 * allocate per-cpu stacks for hardirq and for softirq processing
182 */
183void irq_ctx_init(int cpu)
184{
185 union irq_ctx *irqctx;
186
187 if (hardirq_ctx[cpu])
188 return;
189
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);
196
197 hardirq_ctx[cpu] = irqctx;
198
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;
Paul Mundt1dc41e52006-11-24 19:46:18 +0900203 irqctx->tinfo.preempt_count = 0;
Paul Mundta6a311392006-09-27 18:22:14 +0900204 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
205
206 softirq_ctx[cpu] = irqctx;
207
208 printk("CPU %u irqstacks, hard=%p soft=%p\n",
209 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
210}
211
212void irq_ctx_exit(int cpu)
213{
214 hardirq_ctx[cpu] = NULL;
215}
216
Paul Mundta6a311392006-09-27 18:22:14 +0900217asmlinkage void do_softirq(void)
218{
219 unsigned long flags;
220 struct thread_info *curctx;
221 union irq_ctx *irqctx;
222 u32 *isp;
223
224 if (in_interrupt())
225 return;
226
227 local_irq_save(flags);
228
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;
234
235 /* build the stack frame on the softirq stack */
236 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
237
238 __asm__ __volatile__ (
239 "mov r15, r9 \n"
240 "jsr @%0 \n"
241 /* switch to the softirq stack */
242 " mov %1, r15 \n"
243 /* restore the thread stack */
244 "mov r9, r15 \n"
245 : /* no outputs */
246 : "r" (__do_softirq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900247 : "memory", "r0", "r1", "r2", "r3", "r4",
248 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
249 );
Paul Mundt1dc41e52006-11-24 19:46:18 +0900250
251 /*
252 * Shouldnt happen, we returned above if in_interrupt():
253 */
254 WARN_ON_ONCE(softirq_count());
Paul Mundta6a311392006-09-27 18:22:14 +0900255 }
256
257 local_irq_restore(flags);
258}
Paul Mundta6a311392006-09-27 18:22:14 +0900259#endif
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900260
261void __init init_IRQ(void)
262{
Magnus Damm90015c82007-07-18 17:57:34 +0900263 plat_irq_setup();
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900264
265 /* Perform the machine specific initialisation */
266 if (sh_mv.mv_init_irq)
267 sh_mv.mv_init_irq();
268
269 irq_ctx_init(smp_processor_id());
270}
Paul Mundtd8586ba2009-05-22 01:36:13 +0900271
272#ifdef CONFIG_SPARSE_IRQ
273int __init arch_probe_nr_irqs(void)
274{
275 nr_irqs = sh_mv.mv_nr_irqs;
276 return 0;
277}
278#endif