blob: 9bf19b00696ac5ae6ad0456e1a3ec981f1d0b53d [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 Mundtbf3a00f2006-01-16 22:14:14 -080018#include <asm/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)
34int show_interrupts(struct seq_file *p, void *v)
35{
36 int i = *(loff_t *) v, j;
37 struct irqaction * action;
38 unsigned long flags;
39
40 if (i == 0) {
41 seq_puts(p, " ");
Andrew Morton394e3902006-03-23 03:01:05 -080042 for_each_online_cpu(j)
43 seq_printf(p, "CPU%d ",j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 seq_putc(p, '\n');
45 }
46
Paul Mundtbe782df2007-03-12 14:09:35 +090047 if (i < sh_mv.mv_nr_irqs) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 spin_lock_irqsave(&irq_desc[i].lock, flags);
49 action = irq_desc[i].action;
50 if (!action)
51 goto unlock;
52 seq_printf(p, "%3d: ",i);
Paul Mundt35f3c512006-10-06 15:31:16 +090053 for_each_online_cpu(j)
54 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
55 seq_printf(p, " %14s", irq_desc[i].chip->name);
Paul Mundt709bc442006-10-19 17:32:56 +090056 seq_printf(p, "-%-8s", irq_desc[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 seq_printf(p, " %s", action->name);
58
59 for (action=action->next; action; action = action->next)
60 seq_printf(p, ", %s", action->name);
61 seq_putc(p, '\n');
62unlock:
63 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Paul Mundtbe782df2007-03-12 14:09:35 +090064 } else if (i == sh_mv.mv_nr_irqs)
Paul Mundt35f3c512006-10-06 15:31:16 +090065 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 return 0;
68}
69#endif
70
Paul Mundt110ed282007-11-02 12:16:51 +090071#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +090072/*
73 * per-CPU IRQ handling contexts (thread information and stack)
74 */
75union irq_ctx {
76 struct thread_info tinfo;
77 u32 stack[THREAD_SIZE/sizeof(u32)];
78};
79
Paul Mundt1dc41e52006-11-24 19:46:18 +090080static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
81static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
Paul Mundta6a311392006-09-27 18:22:14 +090082#endif
83
Paul Mundt3afb2092007-03-14 13:03:35 +090084asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
Paul Mundtbf3a00f2006-01-16 22:14:14 -080085{
Stuart Menefyf0bc8142006-11-21 11:16:57 +090086 struct pt_regs *old_regs = set_irq_regs(regs);
Paul Mundt110ed282007-11-02 12:16:51 +090087#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +090088 union irq_ctx *curctx, *irqctx;
89#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 irq_enter();
Paul Mundtbf3a00f2006-01-16 22:14:14 -080092
Paul Mundtd153ea82006-09-27 18:20:16 +090093#ifdef CONFIG_DEBUG_STACKOVERFLOW
94 /* Debugging check for stack overflow: is there less than 1KB free? */
95 {
96 long sp;
97
98 __asm__ __volatile__ ("and r15, %0" :
99 "=r" (sp) : "0" (THREAD_SIZE - 1));
100
101 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
102 printk("do_IRQ: stack overflow: %ld\n",
103 sp - sizeof(struct thread_info));
104 dump_stack();
105 }
106 }
107#endif
108
Paul Mundt3afb2092007-03-14 13:03:35 +0900109 irq = irq_demux(evt2irq(irq));
Paul Mundta6a311392006-09-27 18:22:14 +0900110
Paul Mundt110ed282007-11-02 12:16:51 +0900111#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900112 curctx = (union irq_ctx *)current_thread_info();
113 irqctx = hardirq_ctx[smp_processor_id()];
114
115 /*
116 * this is where we switch to the IRQ stack. However, if we are
117 * already using the IRQ stack (because we interrupted a hardirq
118 * handler) we can't do that and just have to keep using the
119 * current stack (which is the irq stack already after all)
120 */
121 if (curctx != irqctx) {
122 u32 *isp;
123
124 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
125 irqctx->tinfo.task = curctx->tinfo.task;
126 irqctx->tinfo.previous_sp = current_stack_pointer;
127
Paul Mundt1dc41e52006-11-24 19:46:18 +0900128 /*
129 * Copy the softirq bits in preempt_count so that the
130 * softirq checks work in the hardirq context.
131 */
132 irqctx->tinfo.preempt_count =
133 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
134 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
135
Paul Mundta6a311392006-09-27 18:22:14 +0900136 __asm__ __volatile__ (
137 "mov %0, r4 \n"
Paul Mundt1dc41e52006-11-24 19:46:18 +0900138 "mov r15, r8 \n"
Paul Mundtbaf43262006-10-12 12:03:04 +0900139 "jsr @%1 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900140 /* swith to the irq stack */
Paul Mundtbaf43262006-10-12 12:03:04 +0900141 " mov %2, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900142 /* restore the stack (ring zero) */
Paul Mundt1dc41e52006-11-24 19:46:18 +0900143 "mov r8, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900144 : /* no outputs */
Paul Mundt35f3c512006-10-06 15:31:16 +0900145 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900146 : "memory", "r0", "r1", "r2", "r3", "r4",
147 "r5", "r6", "r7", "r8", "t", "pr"
148 );
149 } else
150#endif
Paul Mundt35f3c512006-10-06 15:31:16 +0900151 generic_handle_irq(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 irq_exit();
Paul Mundta6a311392006-09-27 18:22:14 +0900154
Paul Mundt35f3c512006-10-06 15:31:16 +0900155 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return 1;
157}
Paul Mundta6a311392006-09-27 18:22:14 +0900158
Paul Mundt110ed282007-11-02 12:16:51 +0900159#ifdef CONFIG_IRQSTACKS
Paul Mundta6a311392006-09-27 18:22:14 +0900160static char softirq_stack[NR_CPUS * THREAD_SIZE]
Robert P. J. Daybdf4fa52007-07-12 10:41:52 +0900161 __attribute__((__section__(".bss.page_aligned")));
Paul Mundta6a311392006-09-27 18:22:14 +0900162
163static char hardirq_stack[NR_CPUS * THREAD_SIZE]
Robert P. J. Daybdf4fa52007-07-12 10:41:52 +0900164 __attribute__((__section__(".bss.page_aligned")));
Paul Mundta6a311392006-09-27 18:22:14 +0900165
166/*
167 * allocate per-cpu stacks for hardirq and for softirq processing
168 */
169void irq_ctx_init(int cpu)
170{
171 union irq_ctx *irqctx;
172
173 if (hardirq_ctx[cpu])
174 return;
175
176 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
177 irqctx->tinfo.task = NULL;
178 irqctx->tinfo.exec_domain = NULL;
179 irqctx->tinfo.cpu = cpu;
180 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
181 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
182
183 hardirq_ctx[cpu] = irqctx;
184
185 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
186 irqctx->tinfo.task = NULL;
187 irqctx->tinfo.exec_domain = NULL;
188 irqctx->tinfo.cpu = cpu;
Paul Mundt1dc41e52006-11-24 19:46:18 +0900189 irqctx->tinfo.preempt_count = 0;
Paul Mundta6a311392006-09-27 18:22:14 +0900190 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
191
192 softirq_ctx[cpu] = irqctx;
193
194 printk("CPU %u irqstacks, hard=%p soft=%p\n",
195 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
196}
197
198void irq_ctx_exit(int cpu)
199{
200 hardirq_ctx[cpu] = NULL;
201}
202
203extern asmlinkage void __do_softirq(void);
204
205asmlinkage void do_softirq(void)
206{
207 unsigned long flags;
208 struct thread_info *curctx;
209 union irq_ctx *irqctx;
210 u32 *isp;
211
212 if (in_interrupt())
213 return;
214
215 local_irq_save(flags);
216
217 if (local_softirq_pending()) {
218 curctx = current_thread_info();
219 irqctx = softirq_ctx[smp_processor_id()];
220 irqctx->tinfo.task = curctx->task;
221 irqctx->tinfo.previous_sp = current_stack_pointer;
222
223 /* build the stack frame on the softirq stack */
224 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
225
226 __asm__ __volatile__ (
227 "mov r15, r9 \n"
228 "jsr @%0 \n"
229 /* switch to the softirq stack */
230 " mov %1, r15 \n"
231 /* restore the thread stack */
232 "mov r9, r15 \n"
233 : /* no outputs */
234 : "r" (__do_softirq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900235 : "memory", "r0", "r1", "r2", "r3", "r4",
236 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
237 );
Paul Mundt1dc41e52006-11-24 19:46:18 +0900238
239 /*
240 * Shouldnt happen, we returned above if in_interrupt():
241 */
242 WARN_ON_ONCE(softirq_count());
Paul Mundta6a311392006-09-27 18:22:14 +0900243 }
244
245 local_irq_restore(flags);
246}
Paul Mundta6a311392006-09-27 18:22:14 +0900247#endif
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900248
249void __init init_IRQ(void)
250{
Magnus Damm90015c82007-07-18 17:57:34 +0900251 plat_irq_setup();
Jamie Lenehanea0f8fe2006-12-06 12:05:02 +0900252
253 /* Perform the machine specific initialisation */
254 if (sh_mv.mv_init_irq)
255 sh_mv.mv_init_irq();
256
257 irq_ctx_init(smp_processor_id());
258}