blob: acf2602569c4928a5ecd6dc023ede793afd64d2e [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 Mundtbaf43262006-10-12 12:03:04 +090014#include <linux/io.h>
Paul Mundtbf3a00f2006-01-16 22:14:14 -080015#include <asm/irq.h>
16#include <asm/processor.h>
Paul Mundta6a311392006-09-27 18:22:14 +090017#include <asm/uaccess.h>
18#include <asm/thread_info.h>
Paul Mundtbf3a00f2006-01-16 22:14:14 -080019#include <asm/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)
35int show_interrupts(struct seq_file *p, void *v)
36{
37 int i = *(loff_t *) v, j;
38 struct irqaction * action;
39 unsigned long flags;
40
41 if (i == 0) {
42 seq_puts(p, " ");
Andrew Morton394e3902006-03-23 03:01:05 -080043 for_each_online_cpu(j)
44 seq_printf(p, "CPU%d ",j);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 seq_putc(p, '\n');
46 }
47
Paul Mundtbf3a00f2006-01-16 22:14:14 -080048 if (i < NR_IRQS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 spin_lock_irqsave(&irq_desc[i].lock, flags);
50 action = irq_desc[i].action;
51 if (!action)
52 goto unlock;
53 seq_printf(p, "%3d: ",i);
Paul Mundt35f3c512006-10-06 15:31:16 +090054 for_each_online_cpu(j)
55 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
56 seq_printf(p, " %14s", irq_desc[i].chip->name);
57 seq_printf(p, "-%s", handle_irq_name(irq_desc[i].handle_irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 seq_printf(p, " %s", action->name);
59
60 for (action=action->next; action; action = action->next)
61 seq_printf(p, ", %s", action->name);
62 seq_putc(p, '\n');
63unlock:
64 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
Paul Mundt35f3c512006-10-06 15:31:16 +090065 } else if (i == NR_IRQS)
66 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 return 0;
69}
70#endif
71
Paul Mundta6a311392006-09-27 18:22:14 +090072#ifdef CONFIG_4KSTACKS
73/*
74 * per-CPU IRQ handling contexts (thread information and stack)
75 */
76union irq_ctx {
77 struct thread_info tinfo;
78 u32 stack[THREAD_SIZE/sizeof(u32)];
79};
80
81static union irq_ctx *hardirq_ctx[NR_CPUS];
82static union irq_ctx *softirq_ctx[NR_CPUS];
83#endif
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085asmlinkage int do_IRQ(unsigned long r4, unsigned long r5,
86 unsigned long r6, unsigned long r7,
87 struct pt_regs regs)
Paul Mundtbf3a00f2006-01-16 22:14:14 -080088{
Paul Mundt35f3c512006-10-06 15:31:16 +090089 struct pt_regs *old_regs = set_irq_regs(&regs);
Paul Mundtbaf43262006-10-12 12:03:04 +090090 int irq;
Paul Mundta6a311392006-09-27 18:22:14 +090091#ifdef CONFIG_4KSTACKS
92 union irq_ctx *curctx, *irqctx;
93#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 irq_enter();
Paul Mundtbf3a00f2006-01-16 22:14:14 -080096
Paul Mundtd153ea82006-09-27 18:20:16 +090097#ifdef CONFIG_DEBUG_STACKOVERFLOW
98 /* Debugging check for stack overflow: is there less than 1KB free? */
99 {
100 long sp;
101
102 __asm__ __volatile__ ("and r15, %0" :
103 "=r" (sp) : "0" (THREAD_SIZE - 1));
104
105 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
106 printk("do_IRQ: stack overflow: %ld\n",
107 sp - sizeof(struct thread_info));
108 dump_stack();
109 }
110 }
111#endif
112
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800113#ifdef CONFIG_CPU_HAS_INTEVT
Paul Mundtbaf43262006-10-12 12:03:04 +0900114 irq = (ctrl_inl(INTEVT) >> 5) - 16;
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800115#else
Paul Mundtbaf43262006-10-12 12:03:04 +0900116 irq = r4;
Paul Mundtbf3a00f2006-01-16 22:14:14 -0800117#endif
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 irq = irq_demux(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900120
121#ifdef CONFIG_4KSTACKS
122 curctx = (union irq_ctx *)current_thread_info();
123 irqctx = hardirq_ctx[smp_processor_id()];
124
125 /*
126 * this is where we switch to the IRQ stack. However, if we are
127 * already using the IRQ stack (because we interrupted a hardirq
128 * handler) we can't do that and just have to keep using the
129 * current stack (which is the irq stack already after all)
130 */
131 if (curctx != irqctx) {
132 u32 *isp;
133
134 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
135 irqctx->tinfo.task = curctx->tinfo.task;
136 irqctx->tinfo.previous_sp = current_stack_pointer;
137
138 __asm__ __volatile__ (
139 "mov %0, r4 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900140 "mov r15, r9 \n"
Paul Mundtbaf43262006-10-12 12:03:04 +0900141 "jsr @%1 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900142 /* swith to the irq stack */
Paul Mundtbaf43262006-10-12 12:03:04 +0900143 " mov %2, r15 \n"
Paul Mundta6a311392006-09-27 18:22:14 +0900144 /* restore the stack (ring zero) */
145 "mov r9, r15 \n"
146 : /* no outputs */
Paul Mundt35f3c512006-10-06 15:31:16 +0900147 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
Paul Mundta6a311392006-09-27 18:22:14 +0900148 /* XXX: A somewhat excessive clobber list? -PFM */
149 : "memory", "r0", "r1", "r2", "r3", "r4",
150 "r5", "r6", "r7", "r8", "t", "pr"
151 );
152 } else
153#endif
Paul Mundt35f3c512006-10-06 15:31:16 +0900154 generic_handle_irq(irq);
Paul Mundta6a311392006-09-27 18:22:14 +0900155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 irq_exit();
Paul Mundta6a311392006-09-27 18:22:14 +0900157
Paul Mundt35f3c512006-10-06 15:31:16 +0900158 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return 1;
160}
Paul Mundta6a311392006-09-27 18:22:14 +0900161
162#ifdef CONFIG_4KSTACKS
163/*
164 * These should really be __section__(".bss.page_aligned") as well, but
165 * gcc's 3.0 and earlier don't handle that correctly.
166 */
167static char softirq_stack[NR_CPUS * THREAD_SIZE]
168 __attribute__((__aligned__(THREAD_SIZE)));
169
170static char hardirq_stack[NR_CPUS * THREAD_SIZE]
171 __attribute__((__aligned__(THREAD_SIZE)));
172
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;
196 irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
197 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
210extern asmlinkage void __do_softirq(void);
211
212asmlinkage void do_softirq(void)
213{
214 unsigned long flags;
215 struct thread_info *curctx;
216 union irq_ctx *irqctx;
217 u32 *isp;
218
219 if (in_interrupt())
220 return;
221
222 local_irq_save(flags);
223
224 if (local_softirq_pending()) {
225 curctx = current_thread_info();
226 irqctx = softirq_ctx[smp_processor_id()];
227 irqctx->tinfo.task = curctx->task;
228 irqctx->tinfo.previous_sp = current_stack_pointer;
229
230 /* build the stack frame on the softirq stack */
231 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
232
233 __asm__ __volatile__ (
234 "mov r15, r9 \n"
235 "jsr @%0 \n"
236 /* switch to the softirq stack */
237 " mov %1, r15 \n"
238 /* restore the thread stack */
239 "mov r9, r15 \n"
240 : /* no outputs */
241 : "r" (__do_softirq), "r" (isp)
242 /* XXX: A somewhat excessive clobber list? -PFM */
243 : "memory", "r0", "r1", "r2", "r3", "r4",
244 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
245 );
246 }
247
248 local_irq_restore(flags);
249}
250EXPORT_SYMBOL(do_softirq);
251#endif