blob: f6a9319c28e28ea13f5610410a45915f2d2eeea8 [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 Mundtba934832009-10-26 09:58:31 +090014#include <linux/ftrace.h>
Paul Mundtbf3a00f2006-01-16 22:14:14 -080015#include <asm/processor.h>
Paul Mundtbe782df2007-03-12 14:09:35 +090016#include <asm/machvec.h>
Paul Mundta6a311392006-09-27 18:22:14 +090017#include <asm/uaccess.h>
18#include <asm/thread_info.h>
Paul Mundtf15cbe62008-07-29 08:09:44 +090019#include <cpu/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Paul Mundt35f3c512006-10-06 15:31:16 +090021atomic_t irq_err_count;
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
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.
27 */
28void ack_bad_irq(unsigned int irq)
29{
Paul Mundtbaf43262006-10-12 12:03:04 +090030 atomic_inc(&irq_err_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 printk("unexpected IRQ trap at vector %02x\n", irq);
32}
33
34#if defined(CONFIG_PROC_FS)
Paul Mundtfa1d43a2009-05-22 01:26:16 +090035/*
36 * /proc/interrupts printing:
37 */
38static int show_other_interrupts(struct seq_file *p, int prec)
39{
Paul Mundt731ba332009-10-14 16:42:28 +090040 int j;
41
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");
46
Paul Mundtfa1d43a2009-05-22 01:26:16 +090047 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
Paul Mundt731ba332009-10-14 16:42:28 +090048
Paul Mundtfa1d43a2009-05-22 01:26:16 +090049 return 0;
50}
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052int show_interrupts(struct seq_file *p, void *v)
53{
Paul Mundtfa1d43a2009-05-22 01:26:16 +090054 unsigned long flags, any_count = 0;
55 int i = *(loff_t *)v, j, prec;
56 struct irqaction *action;
57 struct irq_desc *desc;
58
59 if (i > nr_irqs)
60 return 0;
61
62 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
63 j *= 10;
64
65 if (i == nr_irqs)
66 return show_other_interrupts(p, prec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 if (i == 0) {
Paul Mundtfa1d43a2009-05-22 01:26:16 +090069 seq_printf(p, "%*s", prec + 8, "");
Andrew Morton394e3902006-03-23 03:01:05 -080070 for_each_online_cpu(j)
Paul Mundtfa1d43a2009-05-22 01:26:16 +090071 seq_printf(p, "CPU%-8d", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 seq_putc(p, '\n');
73 }
74
Paul Mundtfa1d43a2009-05-22 01:26:16 +090075 desc = irq_to_desc(i);
76 if (!desc)
77 return 0;
78
Thomas Gleixner239007b2009-11-17 16:46:45 +010079 raw_spin_lock_irqsave(&desc->lock, flags);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090080 for_each_online_cpu(j)
81 any_count |= kstat_irqs_cpu(i, j);
82 action = desc->action;
83 if (!action && !any_count)
84 goto out;
85
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);
91
92 if (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 seq_printf(p, " %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090094 while ((action = action->next) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 seq_printf(p, ", %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090096 }
Paul Mundt35f3c512006-10-06 15:31:16 +090097
Paul Mundtfa1d43a2009-05-22 01:26:16 +090098 seq_putc(p, '\n');
99out:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100100 raw_spin_unlock_irqrestore(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return 0;
102}
103#endif
104
Paul Mundt110ed282007-11-02 12:16:51 +0900105#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900106/*
107 * per-CPU IRQ handling contexts (thread information and stack)
108 */
109union irq_ctx {
110 struct thread_info tinfo;
111 u32 stack[THREAD_SIZE/sizeof(u32)];
112};
113
Paul Mundt1dc41e52006-11-24 19:46:18 +0900114static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
115static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
Paul Mundta6a311392006-09-27 18:22:14 +0900116
Paul Mundtdc825b12010-04-15 13:13:52 +0900117static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
118static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
119
120static inline void handle_one_irq(unsigned int irq)
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800121{
Paul Mundta6a311392006-09-27 18:22:14 +0900122 union irq_ctx *curctx, *irqctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Paul Mundta6a311392006-09-27 18:22:14 +0900124 curctx = (union irq_ctx *)current_thread_info();
125 irqctx = hardirq_ctx[smp_processor_id()];
126
127 /*
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)
132 */
133 if (curctx != irqctx) {
134 u32 *isp;
135
136 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
137 irqctx->tinfo.task = curctx->tinfo.task;
138 irqctx->tinfo.previous_sp = current_stack_pointer;
139
Paul Mundt1dc41e52006-11-24 19:46:18 +0900140 /*
141 * Copy the softirq bits in preempt_count so that the
142 * softirq checks work in the hardirq context.
143 */
144 irqctx->tinfo.preempt_count =
145 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
146 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
147
Paul Mundta6a311392006-09-27 18:22:14 +0900148 __asm__ __volatile__ (
149 "mov %0, r4 \n"
Paul Mundt1dc41e52006-11-24 19:46:18 +0900150 "mov r15, r8 \n"
Paul Mundtbaf43262006-10-12 12:03:04 +0900151 "jsr @%1 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900152 /* swith to the irq stack */
Paul Mundtbaf43262006-10-12 12:03:04 +0900153 " mov %2, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900154 /* restore the stack (ring zero) */
Paul Mundt1dc41e52006-11-24 19:46:18 +0900155 "mov r8, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900156 : /* no outputs */
Paul Mundt35f3c512006-10-06 15:31:16 +0900157 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900158 : "memory", "r0", "r1", "r2", "r3", "r4",
159 "r5", "r6", "r7", "r8", "t", "pr"
160 );
161 } else
Paul Mundt35f3c512006-10-06 15:31:16 +0900162 generic_handle_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
Paul Mundta6a311392006-09-27 18:22:14 +0900164
Paul Mundta6a311392006-09-27 18:22:14 +0900165/*
166 * allocate per-cpu stacks for hardirq and for softirq processing
167 */
168void irq_ctx_init(int cpu)
169{
170 union irq_ctx *irqctx;
171
172 if (hardirq_ctx[cpu])
173 return;
174
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);
181
182 hardirq_ctx[cpu] = irqctx;
183
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;
Paul Mundt1dc41e52006-11-24 19:46:18 +0900188 irqctx->tinfo.preempt_count = 0;
Paul Mundta6a311392006-09-27 18:22:14 +0900189 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
190
191 softirq_ctx[cpu] = irqctx;
192
193 printk("CPU %u irqstacks, hard=%p soft=%p\n",
194 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
195}
196
197void irq_ctx_exit(int cpu)
198{
199 hardirq_ctx[cpu] = NULL;
200}
201
Paul Mundta6a311392006-09-27 18:22:14 +0900202asmlinkage void do_softirq(void)
203{
204 unsigned long flags;
205 struct thread_info *curctx;
206 union irq_ctx *irqctx;
207 u32 *isp;
208
209 if (in_interrupt())
210 return;
211
212 local_irq_save(flags);
213
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;
219
220 /* build the stack frame on the softirq stack */
221 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
222
223 __asm__ __volatile__ (
224 "mov r15, r9 \n"
225 "jsr @%0 \n"
226 /* switch to the softirq stack */
227 " mov %1, r15 \n"
228 /* restore the thread stack */
229 "mov r9, r15 \n"
230 : /* no outputs */
231 : "r" (__do_softirq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900232 : "memory", "r0", "r1", "r2", "r3", "r4",
233 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
234 );
Paul Mundt1dc41e52006-11-24 19:46:18 +0900235
236 /*
237 * Shouldnt happen, we returned above if in_interrupt():
238 */
239 WARN_ON_ONCE(softirq_count());
Paul Mundta6a311392006-09-27 18:22:14 +0900240 }
241
242 local_irq_restore(flags);
243}
Paul Mundtdc825b12010-04-15 13:13:52 +0900244#else
245static inline void handle_one_irq(unsigned int irq)
246{
247 generic_handle_irq(irq);
248}
Paul Mundta6a311392006-09-27 18:22:14 +0900249#endif
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900250
Paul Mundtdc825b12010-04-15 13:13:52 +0900251asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
252{
253 struct pt_regs *old_regs = set_irq_regs(regs);
254
255 irq_enter();
256
257 irq = irq_demux(irq_lookup(irq));
258
259 if (irq != NO_IRQ_IGNORE) {
260 handle_one_irq(irq);
261 irq_finish(irq);
262 }
263
264 irq_exit();
265
266 set_irq_regs(old_regs);
267
268 return IRQ_HANDLED;
269}
270
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900271void __init init_IRQ(void)
272{
Magnus Damm90015c82007-07-18 17:57:34 +0900273 plat_irq_setup();
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900274
Paul Mundt45b9dea2009-11-02 15:43:20 +0900275 /*
276 * Pin any of the legacy IRQ vectors that haven't already been
277 * grabbed by the platform
278 */
279 reserve_irq_legacy();
280
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900281 /* Perform the machine specific initialisation */
282 if (sh_mv.mv_init_irq)
283 sh_mv.mv_init_irq();
284
285 irq_ctx_init(smp_processor_id());
286}
Paul Mundtd8586ba2009-05-22 01:36:13 +0900287
288#ifdef CONFIG_SPARSE_IRQ
289int __init arch_probe_nr_irqs(void)
290{
291 nr_irqs = sh_mv.mv_nr_irqs;
292 return 0;
293}
294#endif