[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / arch / sh / kernel / irq.c
blob7cb933ba49579d7c97391119cb18d1e6cbfe08d5
1 /*
2 * linux/arch/sh/kernel/irq.c
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
7 * SuperH version: Copyright (C) 1999 Niibe Yutaka
8 */
9 #include <linux/irq.h>
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/seq_file.h>
14 #include <asm/processor.h>
15 #include <asm/machvec.h>
16 #include <asm/uaccess.h>
17 #include <asm/thread_info.h>
18 #include <cpu/mmu_context.h>
20 atomic_t irq_err_count;
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.
27 void ack_bad_irq(unsigned int irq)
29 atomic_inc(&irq_err_count);
30 printk("unexpected IRQ trap at vector %02x\n", irq);
33 #if defined(CONFIG_PROC_FS)
35 * /proc/interrupts printing:
37 static int show_other_interrupts(struct seq_file *p, int prec)
39 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
40 return 0;
43 int show_interrupts(struct seq_file *p, void *v)
45 unsigned long flags, any_count = 0;
46 int i = *(loff_t *)v, j, prec;
47 struct irqaction *action;
48 struct irq_desc *desc;
50 if (i > nr_irqs)
51 return 0;
53 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
54 j *= 10;
56 if (i == nr_irqs)
57 return show_other_interrupts(p, prec);
59 if (i == 0) {
60 seq_printf(p, "%*s", prec + 8, "");
61 for_each_online_cpu(j)
62 seq_printf(p, "CPU%-8d", j);
63 seq_putc(p, '\n');
66 desc = irq_to_desc(i);
67 if (!desc)
68 return 0;
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;
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);
83 if (action) {
84 seq_printf(p, " %s", action->name);
85 while ((action = action->next) != NULL)
86 seq_printf(p, ", %s", action->name);
89 seq_putc(p, '\n');
90 out:
91 spin_unlock_irqrestore(&desc->lock, flags);
92 return 0;
94 #endif
96 #ifdef CONFIG_IRQSTACKS
98 * per-CPU IRQ handling contexts (thread information and stack)
100 union irq_ctx {
101 struct thread_info tinfo;
102 u32 stack[THREAD_SIZE/sizeof(u32)];
105 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
106 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
107 #endif
109 asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
111 struct pt_regs *old_regs = set_irq_regs(regs);
112 #ifdef CONFIG_IRQSTACKS
113 union irq_ctx *curctx, *irqctx;
114 #endif
116 irq_enter();
117 irq = irq_demux(irq);
119 #ifdef CONFIG_IRQSTACKS
120 curctx = (union irq_ctx *)current_thread_info();
121 irqctx = hardirq_ctx[smp_processor_id()];
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)
129 if (curctx != irqctx) {
130 u32 *isp;
132 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
133 irqctx->tinfo.task = curctx->tinfo.task;
134 irqctx->tinfo.previous_sp = current_stack_pointer;
137 * Copy the softirq bits in preempt_count so that the
138 * softirq checks work in the hardirq context.
140 irqctx->tinfo.preempt_count =
141 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
142 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
144 __asm__ __volatile__ (
145 "mov %0, r4 \n"
146 "mov r15, r8 \n"
147 "jsr @%1 \n"
148 /* swith to the irq stack */
149 " mov %2, r15 \n"
150 /* restore the stack (ring zero) */
151 "mov r8, r15 \n"
152 : /* no outputs */
153 : "r" (irq), "r" (generic_handle_irq), "r" (isp)
154 : "memory", "r0", "r1", "r2", "r3", "r4",
155 "r5", "r6", "r7", "r8", "t", "pr"
157 } else
158 #endif
159 generic_handle_irq(irq);
161 irq_exit();
163 set_irq_regs(old_regs);
164 return 1;
167 #ifdef CONFIG_IRQSTACKS
168 static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
170 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
173 * allocate per-cpu stacks for hardirq and for softirq processing
175 void irq_ctx_init(int cpu)
177 union irq_ctx *irqctx;
179 if (hardirq_ctx[cpu])
180 return;
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);
189 hardirq_ctx[cpu] = irqctx;
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;
195 irqctx->tinfo.preempt_count = 0;
196 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
198 softirq_ctx[cpu] = irqctx;
200 printk("CPU %u irqstacks, hard=%p soft=%p\n",
201 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
204 void irq_ctx_exit(int cpu)
206 hardirq_ctx[cpu] = NULL;
209 asmlinkage void do_softirq(void)
211 unsigned long flags;
212 struct thread_info *curctx;
213 union irq_ctx *irqctx;
214 u32 *isp;
216 if (in_interrupt())
217 return;
219 local_irq_save(flags);
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;
227 /* build the stack frame on the softirq stack */
228 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
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)
239 : "memory", "r0", "r1", "r2", "r3", "r4",
240 "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
244 * Shouldnt happen, we returned above if in_interrupt():
246 WARN_ON_ONCE(softirq_count());
249 local_irq_restore(flags);
251 #endif
253 void __init init_IRQ(void)
255 plat_irq_setup();
257 /* Perform the machine specific initialisation */
258 if (sh_mv.mv_init_irq)
259 sh_mv.mv_init_irq();
261 irq_ctx_init(smp_processor_id());
264 #ifdef CONFIG_SPARSE_IRQ
265 int __init arch_probe_nr_irqs(void)
267 nr_irqs = sh_mv.mv_nr_irqs;
268 return 0;
270 #endif