blob: 7cb933ba49579d7c97391119cb18d1e6cbfe08d5 [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{
39 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
40 return 0;
41}
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043int show_interrupts(struct seq_file *p, void *v)
44{
Paul Mundtfa1d43a2009-05-22 01:26:16 +090045 unsigned long flags, any_count = 0;
46 int i = *(loff_t *)v, j, prec;
47 struct irqaction *action;
48 struct irq_desc *desc;
49
50 if (i > nr_irqs)
51 return 0;
52
53 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
54 j *= 10;
55
56 if (i == nr_irqs)
57 return show_other_interrupts(p, prec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 if (i == 0) {
Paul Mundtfa1d43a2009-05-22 01:26:16 +090060 seq_printf(p, "%*s", prec + 8, "");
Andrew Morton394e3902006-03-23 03:01:05 -080061 for_each_online_cpu(j)
Paul Mundtfa1d43a2009-05-22 01:26:16 +090062 seq_printf(p, "CPU%-8d", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 seq_putc(p, '\n');
64 }
65
Paul Mundtfa1d43a2009-05-22 01:26:16 +090066 desc = irq_to_desc(i);
67 if (!desc)
68 return 0;
69
70 spin_lock_irqsave(&desc->lock, flags);
71 for_each_online_cpu(j)
72 any_count |= kstat_irqs_cpu(i, j);
73 action = desc->action;
74 if (!action && !any_count)
75 goto out;
76
77 seq_printf(p, "%*d: ", prec, i);
78 for_each_online_cpu(j)
79 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
80 seq_printf(p, " %14s", desc->chip->name);
81 seq_printf(p, "-%-8s", desc->name);
82
83 if (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 seq_printf(p, " %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090085 while ((action = action->next) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 seq_printf(p, ", %s", action->name);
Paul Mundtfa1d43a2009-05-22 01:26:16 +090087 }
Paul Mundt35f3c512006-10-06 15:31:16 +090088
Paul Mundtfa1d43a2009-05-22 01:26:16 +090089 seq_putc(p, '\n');
90out:
91 spin_unlock_irqrestore(&desc->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return 0;
93}
94#endif
95
Paul Mundt110ed282007-11-02 12:16:51 +090096#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +090097/*
98 * per-CPU IRQ handling contexts (thread information and stack)
99 */
100union irq_ctx {
101 struct thread_info tinfo;
102 u32 stack[THREAD_SIZE/sizeof(u32)];
103};
104
Paul Mundt1dc41e52006-11-24 19:46:18 +0900105static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
106static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
Paul Mundta6a311392006-09-27 18:22:14 +0900107#endif
108
Paul Mundt3afb2092007-03-14 13:03:35 +0900109asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800110{
Stuart Menefyf0bc8142006-11-21 11:16:57 +0900111 struct pt_regs *old_regs = set_irq_regs(regs);
Paul Mundt110ed282007-11-02 12:16:51 +0900112#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900113 union irq_ctx *curctx, *irqctx;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 irq_enter();
Paul Mundt1e1030d2009-09-01 17:38:32 +0900117 irq = irq_demux(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900118
Paul Mundt110ed282007-11-02 12:16:51 +0900119#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900120 curctx = (union irq_ctx *)current_thread_info();
121 irqctx = hardirq_ctx[smp_processor_id()];
122
123 /*
124 * this is where we switch to the IRQ stack. However, if we are
125 * already using the IRQ stack (because we interrupted a hardirq
126 * handler) we can't do that and just have to keep using the
127 * current stack (which is the irq stack already after all)
128 */
129 if (curctx != irqctx) {
130 u32 *isp;
131
132 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
133 irqctx->tinfo.task = curctx->tinfo.task;
134 irqctx->tinfo.previous_sp = current_stack_pointer;
135
Paul Mundt1dc41e52006-11-24 19:46:18 +0900136 /*
137 * Copy the softirq bits in preempt_count so that the
138 * softirq checks work in the hardirq context.
139 */
140 irqctx->tinfo.preempt_count =
141 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
142 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
143
Paul Mundta6a311392006-09-27 18:22:14 +0900144 __asm__ __volatile__ (
145 "mov %0, r4 \n"
Paul Mundt1dc41e52006-11-24 19:46:18 +0900146 "mov r15, r8 \n"
Paul Mundtbaf43262006-10-12 12:03:04 +0900147 "jsr @%1 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900148 /* swith to the irq stack */
Paul Mundtbaf43262006-10-12 12:03:04 +0900149 " mov %2, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900150 /* restore the stack (ring zero) */
Paul Mundt1dc41e52006-11-24 19:46:18 +0900151 "mov r8, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900152 : /* no outputs */
Paul Mundt35f3c512006-10-06 15:31:16 +0900153 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900154 : "memory", "r0", "r1", "r2", "r3", "r4",
155 "r5", "r6", "r7", "r8", "t", "pr"
156 );
157 } else
158#endif
Paul Mundt35f3c512006-10-06 15:31:16 +0900159 generic_handle_irq(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 irq_exit();
Paul Mundta6a311392006-09-27 18:22:14 +0900162
Paul Mundt35f3c512006-10-06 15:31:16 +0900163 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 return 1;
165}
Paul Mundta6a311392006-09-27 18:22:14 +0900166
Paul Mundt110ed282007-11-02 12:16:51 +0900167#ifdef CONFIG_IRQSTACKS
Tim Abbott02b7da32009-09-20 18:14:14 -0400168static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
Paul Mundta6a311392006-09-27 18:22:14 +0900169
Tim Abbott02b7da32009-09-20 18:14:14 -0400170static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
Paul Mundta6a311392006-09-27 18:22:14 +0900171
172/*
173 * allocate per-cpu stacks for hardirq and for softirq processing
174 */
175void irq_ctx_init(int cpu)
176{
177 union irq_ctx *irqctx;
178
179 if (hardirq_ctx[cpu])
180 return;
181
182 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
183 irqctx->tinfo.task = NULL;
184 irqctx->tinfo.exec_domain = NULL;
185 irqctx->tinfo.cpu = cpu;
186 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
187 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
188
189 hardirq_ctx[cpu] = irqctx;
190
191 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
192 irqctx->tinfo.task = NULL;
193 irqctx->tinfo.exec_domain = NULL;
194 irqctx->tinfo.cpu = cpu;
Paul Mundt1dc41e52006-11-24 19:46:18 +0900195 irqctx->tinfo.preempt_count = 0;
Paul Mundta6a311392006-09-27 18:22:14 +0900196 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
197
198 softirq_ctx[cpu] = irqctx;
199
200 printk("CPU %u irqstacks, hard=%p soft=%p\n",
201 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
202}
203
204void irq_ctx_exit(int cpu)
205{
206 hardirq_ctx[cpu] = NULL;
207}
208
Paul Mundta6a311392006-09-27 18:22:14 +0900209asmlinkage void do_softirq(void)
210{
211 unsigned long flags;
212 struct thread_info *curctx;
213 union irq_ctx *irqctx;
214 u32 *isp;
215
216 if (in_interrupt())
217 return;
218
219 local_irq_save(flags);
220
221 if (local_softirq_pending()) {
222 curctx = current_thread_info();
223 irqctx = softirq_ctx[smp_processor_id()];
224 irqctx->tinfo.task = curctx->task;
225 irqctx->tinfo.previous_sp = current_stack_pointer;
226
227 /* build the stack frame on the softirq stack */
228 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
229
230 __asm__ __volatile__ (
231 "mov r15, r9 \n"
232 "jsr @%0 \n"
233 /* switch to the softirq stack */
234 " mov %1, r15 \n"
235 /* restore the thread stack */
236 "mov r9, r15 \n"
237 : /* no outputs */
238 : "r" (__do_softirq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900239 : "memory", "r0", "r1", "r2", "r3", "r4",
240 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
241 );
Paul Mundt1dc41e52006-11-24 19:46:18 +0900242
243 /*
244 * Shouldnt happen, we returned above if in_interrupt():
245 */
246 WARN_ON_ONCE(softirq_count());
Paul Mundta6a311392006-09-27 18:22:14 +0900247 }
248
249 local_irq_restore(flags);
250}
Paul Mundta6a311392006-09-27 18:22:14 +0900251#endif
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900252
253void __init init_IRQ(void)
254{
Magnus Damm90015c82007-07-18 17:57:34 +0900255 plat_irq_setup();
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900256
257 /* Perform the machine specific initialisation */
258 if (sh_mv.mv_init_irq)
259 sh_mv.mv_init_irq();
260
261 irq_ctx_init(smp_processor_id());
262}
Paul Mundtd8586ba2009-05-22 01:36:13 +0900263
264#ifdef CONFIG_SPARSE_IRQ
265int __init arch_probe_nr_irqs(void)
266{
267 nr_irqs = sh_mv.mv_nr_irqs;
268 return 0;
269}
270#endif