blob: 3b93682bf18b416fc6bf58256cd707790f4af52b [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>
14#include <asm/irq.h>
15#include <asm/processor.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{
29 printk("unexpected IRQ trap at vector %02x\n", irq);
30}
31
32#if defined(CONFIG_PROC_FS)
33int show_interrupts(struct seq_file *p, void *v)
34{
35 int i = *(loff_t *) v, j;
36 struct irqaction * action;
37 unsigned long flags;
38
39 if (i == 0) {
40 seq_puts(p, " ");
Andrew Morton394e3902006-03-23 03:01:05 -080041 for_each_online_cpu(j)
42 seq_printf(p, "CPU%d ",j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 seq_putc(p, '\n');
44 }
45
Paul Mundtbf3a00f2006-01-16 22:14:14 -080046 if (i < NR_IRQS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 spin_lock_irqsave(&irq_desc[i].lock, flags);
48 action = irq_desc[i].action;
49 if (!action)
50 goto unlock;
51 seq_printf(p, "%3d: ",i);
Paul Mundt35f3c512006-10-06 15:31:16 +090052 for_each_online_cpu(j)
53 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
54 seq_printf(p, " %14s", irq_desc[i].chip->name);
55 seq_printf(p, "-%s", handle_irq_name(irq_desc[i].handle_irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 seq_printf(p, " %s", action->name);
57
58 for (action=action->next; action; action = action->next)
59 seq_printf(p, ", %s", action->name);
60 seq_putc(p, '\n');
61unlock:
62 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Paul Mundt35f3c512006-10-06 15:31:16 +090063 } else if (i == NR_IRQS)
64 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return 0;
67}
68#endif
69
Paul Mundta6a311392006-09-27 18:22:14 +090070#ifdef CONFIG_4KSTACKS
71/*
72 * per-CPU IRQ handling contexts (thread information and stack)
73 */
74union irq_ctx {
75 struct thread_info tinfo;
76 u32 stack[THREAD_SIZE/sizeof(u32)];
77};
78
79static union irq_ctx *hardirq_ctx[NR_CPUS];
80static union irq_ctx *softirq_ctx[NR_CPUS];
81#endif
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083asmlinkage int do_IRQ(unsigned long r4, unsigned long r5,
84 unsigned long r6, unsigned long r7,
85 struct pt_regs regs)
Paul Mundtbf3a00f2006-01-16 22:14:14 -080086{
Paul Mundt35f3c512006-10-06 15:31:16 +090087 struct pt_regs *old_regs = set_irq_regs(&regs);
Paul Mundtbf3a00f2006-01-16 22:14:14 -080088 int irq = r4;
Paul Mundta6a311392006-09-27 18:22:14 +090089#ifdef CONFIG_4KSTACKS
90 union irq_ctx *curctx, *irqctx;
91#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 irq_enter();
Paul Mundtbf3a00f2006-01-16 22:14:14 -080094
Paul Mundtd153ea82006-09-27 18:20:16 +090095#ifdef CONFIG_DEBUG_STACKOVERFLOW
96 /* Debugging check for stack overflow: is there less than 1KB free? */
97 {
98 long sp;
99
100 __asm__ __volatile__ ("and r15, %0" :
101 "=r" (sp) : "0" (THREAD_SIZE - 1));
102
103 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
104 printk("do_IRQ: stack overflow: %ld\n",
105 sp - sizeof(struct thread_info));
106 dump_stack();
107 }
108 }
109#endif
110
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800111#ifdef CONFIG_CPU_HAS_INTEVT
112 __asm__ __volatile__ (
113#ifdef CONFIG_CPU_HAS_SR_RB
114 "stc r2_bank, %0\n\t"
115#else
116 "mov.l @%1, %0\n\t"
117#endif
118 "shlr2 %0\n\t"
119 "shlr2 %0\n\t"
120 "shlr %0\n\t"
121 "add #-16, %0\n\t"
122 : "=z" (irq), "=r" (r4)
123 : "1" (INTEVT)
124 : "memory"
125 );
126#endif
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 irq = irq_demux(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900129
130#ifdef CONFIG_4KSTACKS
131 curctx = (union irq_ctx *)current_thread_info();
132 irqctx = hardirq_ctx[smp_processor_id()];
133
134 /*
135 * this is where we switch to the IRQ stack. However, if we are
136 * already using the IRQ stack (because we interrupted a hardirq
137 * handler) we can't do that and just have to keep using the
138 * current stack (which is the irq stack already after all)
139 */
140 if (curctx != irqctx) {
141 u32 *isp;
142
143 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
144 irqctx->tinfo.task = curctx->tinfo.task;
145 irqctx->tinfo.previous_sp = current_stack_pointer;
146
147 __asm__ __volatile__ (
148 "mov %0, r4 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900149 "mov r15, r9 \n"
150 "jsr @%2 \n"
151 /* swith to the irq stack */
152 " mov %3, r15 \n"
153 /* restore the stack (ring zero) */
154 "mov r9, r15 \n"
155 : /* no outputs */
Paul Mundt35f3c512006-10-06 15:31:16 +0900156 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900157 /* XXX: A somewhat excessive clobber list? -PFM */
158 : "memory", "r0", "r1", "r2", "r3", "r4",
159 "r5", "r6", "r7", "r8", "t", "pr"
160 );
161 } else
162#endif
Paul Mundt35f3c512006-10-06 15:31:16 +0900163 generic_handle_irq(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 irq_exit();
Paul Mundta6a311392006-09-27 18:22:14 +0900166
Paul Mundt35f3c512006-10-06 15:31:16 +0900167 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return 1;
169}
Paul Mundta6a311392006-09-27 18:22:14 +0900170
171#ifdef CONFIG_4KSTACKS
172/*
173 * These should really be __section__(".bss.page_aligned") as well, but
174 * gcc's 3.0 and earlier don't handle that correctly.
175 */
176static char softirq_stack[NR_CPUS * THREAD_SIZE]
177 __attribute__((__aligned__(THREAD_SIZE)));
178
179static char hardirq_stack[NR_CPUS * THREAD_SIZE]
180 __attribute__((__aligned__(THREAD_SIZE)));
181
182/*
183 * allocate per-cpu stacks for hardirq and for softirq processing
184 */
185void irq_ctx_init(int cpu)
186{
187 union irq_ctx *irqctx;
188
189 if (hardirq_ctx[cpu])
190 return;
191
192 irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
193 irqctx->tinfo.task = NULL;
194 irqctx->tinfo.exec_domain = NULL;
195 irqctx->tinfo.cpu = cpu;
196 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
197 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
198
199 hardirq_ctx[cpu] = irqctx;
200
201 irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
202 irqctx->tinfo.task = NULL;
203 irqctx->tinfo.exec_domain = NULL;
204 irqctx->tinfo.cpu = cpu;
205 irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
206 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
207
208 softirq_ctx[cpu] = irqctx;
209
210 printk("CPU %u irqstacks, hard=%p soft=%p\n",
211 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
212}
213
214void irq_ctx_exit(int cpu)
215{
216 hardirq_ctx[cpu] = NULL;
217}
218
219extern asmlinkage void __do_softirq(void);
220
221asmlinkage void do_softirq(void)
222{
223 unsigned long flags;
224 struct thread_info *curctx;
225 union irq_ctx *irqctx;
226 u32 *isp;
227
228 if (in_interrupt())
229 return;
230
231 local_irq_save(flags);
232
233 if (local_softirq_pending()) {
234 curctx = current_thread_info();
235 irqctx = softirq_ctx[smp_processor_id()];
236 irqctx->tinfo.task = curctx->task;
237 irqctx->tinfo.previous_sp = current_stack_pointer;
238
239 /* build the stack frame on the softirq stack */
240 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
241
242 __asm__ __volatile__ (
243 "mov r15, r9 \n"
244 "jsr @%0 \n"
245 /* switch to the softirq stack */
246 " mov %1, r15 \n"
247 /* restore the thread stack */
248 "mov r9, r15 \n"
249 : /* no outputs */
250 : "r" (__do_softirq), "r" (isp)
251 /* XXX: A somewhat excessive clobber list? -PFM */
252 : "memory", "r0", "r1", "r2", "r3", "r4",
253 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
254 );
255 }
256
257 local_irq_restore(flags);
258}
259EXPORT_SYMBOL(do_softirq);
260#endif