Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/irq.h> |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 10 | #include <linux/interrupt.h> |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 11 | #include <linux/module.h> |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 12 | #include <linux/kernel_stat.h> |
| 13 | #include <linux/seq_file.h> |
| 14 | #include <asm/irq.h> |
| 15 | #include <asm/processor.h> |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 16 | #include <asm/uaccess.h> |
| 17 | #include <asm/thread_info.h> |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 18 | #include <asm/cpu/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame^] | 20 | atomic_t irq_err_count; |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /* |
| 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 | */ |
| 27 | void 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) |
| 33 | int 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 Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 41 | for_each_online_cpu(j) |
| 42 | seq_printf(p, "CPU%d ",j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | seq_putc(p, '\n'); |
| 44 | } |
| 45 | |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 46 | if (i < NR_IRQS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | 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 Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame^] | 52 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | 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'); |
| 61 | unlock: |
| 62 | spin_unlock_irqrestore(&irq_desc[i].lock, flags); |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame^] | 63 | } else if (i == NR_IRQS) |
| 64 | seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count)); |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | #endif |
| 69 | |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 70 | #ifdef CONFIG_4KSTACKS |
| 71 | /* |
| 72 | * per-CPU IRQ handling contexts (thread information and stack) |
| 73 | */ |
| 74 | union irq_ctx { |
| 75 | struct thread_info tinfo; |
| 76 | u32 stack[THREAD_SIZE/sizeof(u32)]; |
| 77 | }; |
| 78 | |
| 79 | static union irq_ctx *hardirq_ctx[NR_CPUS]; |
| 80 | static union irq_ctx *softirq_ctx[NR_CPUS]; |
| 81 | #endif |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | asmlinkage int do_IRQ(unsigned long r4, unsigned long r5, |
| 84 | unsigned long r6, unsigned long r7, |
| 85 | struct pt_regs regs) |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 86 | { |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame^] | 87 | struct pt_regs *old_regs = set_irq_regs(®s); |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 88 | int irq = r4; |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 89 | #ifdef CONFIG_4KSTACKS |
| 90 | union irq_ctx *curctx, *irqctx; |
| 91 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | irq_enter(); |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 94 | |
Paul Mundt | d153ea8 | 2006-09-27 18:20:16 +0900 | [diff] [blame] | 95 | #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 Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 111 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | irq = irq_demux(irq); |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 129 | |
| 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 Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 149 | "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 Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame^] | 156 | : "r" (irq), "r" (generic_handle_irq), "r" (isp) |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 157 | /* 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 Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame^] | 163 | generic_handle_irq(irq); |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | irq_exit(); |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 166 | |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame^] | 167 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return 1; |
| 169 | } |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 170 | |
| 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 | */ |
| 176 | static char softirq_stack[NR_CPUS * THREAD_SIZE] |
| 177 | __attribute__((__aligned__(THREAD_SIZE))); |
| 178 | |
| 179 | static 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 | */ |
| 185 | void 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 | |
| 214 | void irq_ctx_exit(int cpu) |
| 215 | { |
| 216 | hardirq_ctx[cpu] = NULL; |
| 217 | } |
| 218 | |
| 219 | extern asmlinkage void __do_softirq(void); |
| 220 | |
| 221 | asmlinkage 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 | } |
| 259 | EXPORT_SYMBOL(do_softirq); |
| 260 | #endif |