blob: eac7da772fc259c3c870152b3c1155492d76e477 [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{
40 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
41 return 0;
42}
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044int show_interrupts(struct seq_file *p, void *v)
45{
Paul Mundtfa1d43a2009-05-22 01:26:16 +090046 unsigned long flags, any_count = 0;
47 int i = *(loff_t *)v, j, prec;
48 struct irqaction *action;
49 struct irq_desc *desc;
50
51 if (i > nr_irqs)
52 return 0;
53
54 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
55 j *= 10;
56
57 if (i == nr_irqs)
58 return show_other_interrupts(p, prec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 if (i == 0) {
Paul Mundtfa1d43a2009-05-22 01:26:16 +090061 seq_printf(p, "%*s", prec + 8, "");
Andrew Morton394e3902006-03-23 03:01:05 -080062 for_each_online_cpu(j)
Paul Mundtfa1d43a2009-05-22 01:26:16 +090063 seq_printf(p, "CPU%-8d", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 seq_putc(p, '\n');
65 }
66
Paul Mundtfa1d43a2009-05-22 01:26:16 +090067 desc = irq_to_desc(i);
68 if (!desc)
69 return 0;
70
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)
76 goto out;
77
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);
83
84 if (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 seq_printf(p, " %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090086 while ((action = action->next) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 seq_printf(p, ", %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090088 }
Paul Mundt35f3c512006-10-06 15:31:16 +090089
Paul Mundtfa1d43a2009-05-22 01:26:16 +090090 seq_putc(p, '\n');
91out:
92 spin_unlock_irqrestore(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return 0;
94}
95#endif
96
Paul Mundt110ed282007-11-02 12:16:51 +090097#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +090098/*
99 * per-CPU IRQ handling contexts (thread information and stack)
100 */
101union irq_ctx {
102 struct thread_info tinfo;
103 u32 stack[THREAD_SIZE/sizeof(u32)];
104};
105
Paul Mundt1dc41e52006-11-24 19:46:18 +0900106static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
107static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
Paul Mundta6a311392006-09-27 18:22:14 +0900108#endif
109
Paul Mundtba934832009-10-26 09:58:31 +0900110asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800111{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900112 struct pt_regs *old_regs = set_irq_regs(regs);
Paul Mundt110ed282007-11-02 12:16:51 +0900113#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900114 union irq_ctx *curctx, *irqctx;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 irq_enter();
Paul Mundt1e1030d2009-09-01 17:38:32 +0900118 irq = irq_demux(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900119
Paul Mundt110ed282007-11-02 12:16:51 +0900120#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900121 curctx = (union irq_ctx *)current_thread_info();
122 irqctx = hardirq_ctx[smp_processor_id()];
123
124 /*
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)
129 */
130 if (curctx != irqctx) {
131 u32 *isp;
132
133 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
134 irqctx->tinfo.task = curctx->tinfo.task;
135 irqctx->tinfo.previous_sp = current_stack_pointer;
136
Paul Mundt1dc41e52006-11-24 19:46:18 +0900137 /*
138 * Copy the softirq bits in preempt_count so that the
139 * softirq checks work in the hardirq context.
140 */
141 irqctx->tinfo.preempt_count =
142 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
143 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
144
Paul Mundta6a311392006-09-27 18:22:14 +0900145 __asm__ __volatile__ (
146 "mov %0, r4 \n"
Paul Mundt1dc41e52006-11-24 19:46:18 +0900147 "mov r15, r8 \n"
Paul Mundtbaf43262006-10-12 12:03:04 +0900148 "jsr @%1 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900149 /* swith to the irq stack */
Paul Mundtbaf43262006-10-12 12:03:04 +0900150 " mov %2, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900151 /* restore the stack (ring zero) */
Paul Mundt1dc41e52006-11-24 19:46:18 +0900152 "mov r8, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900153 : /* no outputs */
Paul Mundt35f3c512006-10-06 15:31:16 +0900154 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900155 : "memory", "r0", "r1", "r2", "r3", "r4",
156 "r5", "r6", "r7", "r8", "t", "pr"
157 );
158 } else
159#endif
Paul Mundt35f3c512006-10-06 15:31:16 +0900160 generic_handle_irq(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 irq_exit();
Paul Mundta6a311392006-09-27 18:22:14 +0900163
Paul Mundt35f3c512006-10-06 15:31:16 +0900164 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 return 1;
166}
Paul Mundta6a311392006-09-27 18:22:14 +0900167
Paul Mundt110ed282007-11-02 12:16:51 +0900168#ifdef CONFIG_IRQSTACKS
Tim Abbott02b7da32009-09-20 18:14:14 -0400169static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
Paul Mundta6a311392006-09-27 18:22:14 +0900170
Tim Abbott02b7da32009-09-20 18:14:14 -0400171static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
Paul Mundta6a311392006-09-27 18:22:14 +0900172
173/*
174 * allocate per-cpu stacks for hardirq and for softirq processing
175 */
176void irq_ctx_init(int cpu)
177{
178 union irq_ctx *irqctx;
179
180 if (hardirq_ctx[cpu])
181 return;
182
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);
189
190 hardirq_ctx[cpu] = irqctx;
191
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;
Paul Mundt1dc41e52006-11-24 19:46:18 +0900196 irqctx->tinfo.preempt_count = 0;
Paul Mundta6a311392006-09-27 18:22:14 +0900197 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
198
199 softirq_ctx[cpu] = irqctx;
200
201 printk("CPU %u irqstacks, hard=%p soft=%p\n",
202 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
203}
204
205void irq_ctx_exit(int cpu)
206{
207 hardirq_ctx[cpu] = NULL;
208}
209
Paul Mundta6a311392006-09-27 18:22:14 +0900210asmlinkage void do_softirq(void)
211{
212 unsigned long flags;
213 struct thread_info *curctx;
214 union irq_ctx *irqctx;
215 u32 *isp;
216
217 if (in_interrupt())
218 return;
219
220 local_irq_save(flags);
221
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;
227
228 /* build the stack frame on the softirq stack */
229 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
230
231 __asm__ __volatile__ (
232 "mov r15, r9 \n"
233 "jsr @%0 \n"
234 /* switch to the softirq stack */
235 " mov %1, r15 \n"
236 /* restore the thread stack */
237 "mov r9, r15 \n"
238 : /* no outputs */
239 : "r" (__do_softirq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900240 : "memory", "r0", "r1", "r2", "r3", "r4",
241 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
242 );
Paul Mundt1dc41e52006-11-24 19:46:18 +0900243
244 /*
245 * Shouldnt happen, we returned above if in_interrupt():
246 */
247 WARN_ON_ONCE(softirq_count());
Paul Mundta6a311392006-09-27 18:22:14 +0900248 }
249
250 local_irq_restore(flags);
251}
Paul Mundta6a311392006-09-27 18:22:14 +0900252#endif
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900253
254void __init init_IRQ(void)
255{
Magnus Damm90015c82007-07-18 17:57:34 +0900256 plat_irq_setup();
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900257
258 /* Perform the machine specific initialisation */
259 if (sh_mv.mv_init_irq)
260 sh_mv.mv_init_irq();
261
262 irq_ctx_init(smp_processor_id());
263}
Paul Mundtd8586ba2009-05-22 01:36:13 +0900264
265#ifdef CONFIG_SPARSE_IRQ
266int __init arch_probe_nr_irqs(void)
267{
268 nr_irqs = sh_mv.mv_nr_irqs;
269 return 0;
270}
271#endif