Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6] / arch / sh / kernel / irq.c
1 /*
2  * 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  */
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/irq.h>
15 #include <asm/processor.h>
16 #include <asm/uaccess.h>
17 #include <asm/thread_info.h>
18 #include <asm/cpu/mmu_context.h>
19
20 /*
21  * 'what should we do if we get a hw irq event on an illegal vector'.
22  * each architecture has to answer this themselves, it doesn't deserve
23  * a generic callback i think.
24  */
25 void ack_bad_irq(unsigned int irq)
26 {
27         printk("unexpected IRQ trap at vector %02x\n", irq);
28 }
29
30 #if defined(CONFIG_PROC_FS)
31 int show_interrupts(struct seq_file *p, void *v)
32 {
33         int i = *(loff_t *) v, j;
34         struct irqaction * action;
35         unsigned long flags;
36
37         if (i == 0) {
38                 seq_puts(p, "           ");
39                 for_each_online_cpu(j)
40                         seq_printf(p, "CPU%d       ",j);
41                 seq_putc(p, '\n');
42         }
43
44         if (i < NR_IRQS) {
45                 spin_lock_irqsave(&irq_desc[i].lock, flags);
46                 action = irq_desc[i].action;
47                 if (!action)
48                         goto unlock;
49                 seq_printf(p, "%3d: ",i);
50                 seq_printf(p, "%10u ", kstat_irqs(i));
51                 seq_printf(p, " %14s", irq_desc[i].chip->typename);
52                 seq_printf(p, "  %s", action->name);
53
54                 for (action=action->next; action; action = action->next)
55                         seq_printf(p, ", %s", action->name);
56                 seq_putc(p, '\n');
57 unlock:
58                 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
59         }
60         return 0;
61 }
62 #endif
63
64 #ifdef CONFIG_4KSTACKS
65 /*
66  * per-CPU IRQ handling contexts (thread information and stack)
67  */
68 union irq_ctx {
69         struct thread_info      tinfo;
70         u32                     stack[THREAD_SIZE/sizeof(u32)];
71 };
72
73 static union irq_ctx *hardirq_ctx[NR_CPUS];
74 static union irq_ctx *softirq_ctx[NR_CPUS];
75 #endif
76
77 asmlinkage int do_IRQ(unsigned long r4, unsigned long r5,
78                       unsigned long r6, unsigned long r7,
79                       struct pt_regs regs)
80 {
81         int irq = r4;
82 #ifdef CONFIG_4KSTACKS
83         union irq_ctx *curctx, *irqctx;
84 #endif
85
86         irq_enter();
87
88 #ifdef CONFIG_DEBUG_STACKOVERFLOW
89         /* Debugging check for stack overflow: is there less than 1KB free? */
90         {
91                 long sp;
92
93                 __asm__ __volatile__ ("and r15, %0" :
94                                         "=r" (sp) : "0" (THREAD_SIZE - 1));
95
96                 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
97                         printk("do_IRQ: stack overflow: %ld\n",
98                                sp - sizeof(struct thread_info));
99                         dump_stack();
100                 }
101         }
102 #endif
103
104 #ifdef CONFIG_CPU_HAS_INTEVT
105         __asm__ __volatile__ (
106 #ifdef CONFIG_CPU_HAS_SR_RB
107                 "stc    r2_bank, %0\n\t"
108 #else
109                 "mov.l  @%1, %0\n\t"
110 #endif
111                 "shlr2  %0\n\t"
112                 "shlr2  %0\n\t"
113                 "shlr   %0\n\t"
114                 "add    #-16, %0\n\t"
115                 : "=z" (irq), "=r" (r4)
116                 : "1" (INTEVT)
117                 : "memory"
118         );
119 #endif
120
121         irq = irq_demux(irq);
122
123 #ifdef CONFIG_4KSTACKS
124         curctx = (union irq_ctx *)current_thread_info();
125         irqctx = hardirq_ctx[smp_processor_id()];
126
127         /*
128          * this is where we switch to the IRQ stack. However, if we are
129          * already using the IRQ stack (because we interrupted a hardirq
130          * handler) we can't do that and just have to keep using the
131          * current stack (which is the irq stack already after all)
132          */
133         if (curctx != irqctx) {
134                 u32 *isp;
135
136                 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
137                 irqctx->tinfo.task = curctx->tinfo.task;
138                 irqctx->tinfo.previous_sp = current_stack_pointer;
139
140                 __asm__ __volatile__ (
141                         "mov    %0, r4          \n"
142                         "mov    %1, r5          \n"
143                         "mov    r15, r9         \n"
144                         "jsr    @%2             \n"
145                         /* swith to the irq stack */
146                         " mov   %3, r15         \n"
147                         /* restore the stack (ring zero) */
148                         "mov    r9, r15         \n"
149                         : /* no outputs */
150                         : "r" (irq), "r" (&regs), "r" (__do_IRQ), "r" (isp)
151                         /* XXX: A somewhat excessive clobber list? -PFM */
152                         : "memory", "r0", "r1", "r2", "r3", "r4",
153                           "r5", "r6", "r7", "r8", "t", "pr"
154                 );
155         } else
156 #endif
157                 __do_IRQ(irq, &regs);
158
159         irq_exit();
160
161         return 1;
162 }
163
164 #ifdef CONFIG_4KSTACKS
165 /*
166  * These should really be __section__(".bss.page_aligned") as well, but
167  * gcc's 3.0 and earlier don't handle that correctly.
168  */
169 static char softirq_stack[NR_CPUS * THREAD_SIZE]
170                 __attribute__((__aligned__(THREAD_SIZE)));
171
172 static char hardirq_stack[NR_CPUS * THREAD_SIZE]
173                 __attribute__((__aligned__(THREAD_SIZE)));
174
175 /*
176  * allocate per-cpu stacks for hardirq and for softirq processing
177  */
178 void irq_ctx_init(int cpu)
179 {
180         union irq_ctx *irqctx;
181
182         if (hardirq_ctx[cpu])
183                 return;
184
185         irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
186         irqctx->tinfo.task              = NULL;
187         irqctx->tinfo.exec_domain       = NULL;
188         irqctx->tinfo.cpu               = cpu;
189         irqctx->tinfo.preempt_count     = HARDIRQ_OFFSET;
190         irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
191
192         hardirq_ctx[cpu] = irqctx;
193
194         irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
195         irqctx->tinfo.task              = NULL;
196         irqctx->tinfo.exec_domain       = NULL;
197         irqctx->tinfo.cpu               = cpu;
198         irqctx->tinfo.preempt_count     = SOFTIRQ_OFFSET;
199         irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
200
201         softirq_ctx[cpu] = irqctx;
202
203         printk("CPU %u irqstacks, hard=%p soft=%p\n",
204                 cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
205 }
206
207 void irq_ctx_exit(int cpu)
208 {
209         hardirq_ctx[cpu] = NULL;
210 }
211
212 extern asmlinkage void __do_softirq(void);
213
214 asmlinkage void do_softirq(void)
215 {
216         unsigned long flags;
217         struct thread_info *curctx;
218         union irq_ctx *irqctx;
219         u32 *isp;
220
221         if (in_interrupt())
222                 return;
223
224         local_irq_save(flags);
225
226         if (local_softirq_pending()) {
227                 curctx = current_thread_info();
228                 irqctx = softirq_ctx[smp_processor_id()];
229                 irqctx->tinfo.task = curctx->task;
230                 irqctx->tinfo.previous_sp = current_stack_pointer;
231
232                 /* build the stack frame on the softirq stack */
233                 isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
234
235                 __asm__ __volatile__ (
236                         "mov    r15, r9         \n"
237                         "jsr    @%0             \n"
238                         /* switch to the softirq stack */
239                         " mov   %1, r15         \n"
240                         /* restore the thread stack */
241                         "mov    r9, r15         \n"
242                         : /* no outputs */
243                         : "r" (__do_softirq), "r" (isp)
244                         /* XXX: A somewhat excessive clobber list? -PFM */
245                         : "memory", "r0", "r1", "r2", "r3", "r4",
246                           "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
247                 );
248         }
249
250         local_irq_restore(flags);
251 }
252 EXPORT_SYMBOL(do_softirq);
253 #endif