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> |
Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 14 | #include <linux/io.h> |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 15 | #include <asm/irq.h> |
| 16 | #include <asm/processor.h> |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 17 | #include <asm/uaccess.h> |
| 18 | #include <asm/thread_info.h> |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 19 | #include <asm/cpu/mmu_context.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 21 | atomic_t irq_err_count; |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* |
| 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 | */ |
| 28 | void ack_bad_irq(unsigned int irq) |
| 29 | { |
Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 30 | atomic_inc(&irq_err_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | printk("unexpected IRQ trap at vector %02x\n", irq); |
| 32 | } |
| 33 | |
| 34 | #if defined(CONFIG_PROC_FS) |
| 35 | int 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 Morton | 394e390 | 2006-03-23 03:01:05 -0800 | [diff] [blame] | 43 | for_each_online_cpu(j) |
| 44 | seq_printf(p, "CPU%d ",j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | seq_putc(p, '\n'); |
| 46 | } |
| 47 | |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 48 | if (i < NR_IRQS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | 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 Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 54 | 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); |
Paul Mundt | 709bc44 | 2006-10-19 17:32:56 +0900 | [diff] [blame] | 57 | seq_printf(p, "-%-8s", irq_desc[i].name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | 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'); |
| 63 | unlock: |
| 64 | spin_unlock_irqrestore(&irq_desc[i].lock, flags); |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 65 | } else if (i == NR_IRQS) |
| 66 | seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count)); |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | #endif |
| 71 | |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 72 | #ifdef CONFIG_4KSTACKS |
| 73 | /* |
| 74 | * per-CPU IRQ handling contexts (thread information and stack) |
| 75 | */ |
| 76 | union irq_ctx { |
| 77 | struct thread_info tinfo; |
| 78 | u32 stack[THREAD_SIZE/sizeof(u32)]; |
| 79 | }; |
| 80 | |
Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame^] | 81 | static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly; |
| 82 | static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly; |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 83 | #endif |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | asmlinkage int do_IRQ(unsigned long r4, unsigned long r5, |
| 86 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 87 | struct pt_regs __regs) |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 88 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 89 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
| 90 | struct pt_regs *old_regs = set_irq_regs(regs); |
Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 91 | int irq; |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 92 | #ifdef CONFIG_4KSTACKS |
| 93 | union irq_ctx *curctx, *irqctx; |
| 94 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | irq_enter(); |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 97 | |
Paul Mundt | d153ea8 | 2006-09-27 18:20:16 +0900 | [diff] [blame] | 98 | #ifdef CONFIG_DEBUG_STACKOVERFLOW |
| 99 | /* Debugging check for stack overflow: is there less than 1KB free? */ |
| 100 | { |
| 101 | long sp; |
| 102 | |
| 103 | __asm__ __volatile__ ("and r15, %0" : |
| 104 | "=r" (sp) : "0" (THREAD_SIZE - 1)); |
| 105 | |
| 106 | if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) { |
| 107 | printk("do_IRQ: stack overflow: %ld\n", |
| 108 | sp - sizeof(struct thread_info)); |
| 109 | dump_stack(); |
| 110 | } |
| 111 | } |
| 112 | #endif |
| 113 | |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 114 | #ifdef CONFIG_CPU_HAS_INTEVT |
Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 115 | irq = (ctrl_inl(INTEVT) >> 5) - 16; |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 116 | #else |
Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 117 | irq = r4; |
Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 118 | #endif |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | irq = irq_demux(irq); |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 121 | |
| 122 | #ifdef CONFIG_4KSTACKS |
| 123 | curctx = (union irq_ctx *)current_thread_info(); |
| 124 | irqctx = hardirq_ctx[smp_processor_id()]; |
| 125 | |
| 126 | /* |
| 127 | * this is where we switch to the IRQ stack. However, if we are |
| 128 | * already using the IRQ stack (because we interrupted a hardirq |
| 129 | * handler) we can't do that and just have to keep using the |
| 130 | * current stack (which is the irq stack already after all) |
| 131 | */ |
| 132 | if (curctx != irqctx) { |
| 133 | u32 *isp; |
| 134 | |
| 135 | isp = (u32 *)((char *)irqctx + sizeof(*irqctx)); |
| 136 | irqctx->tinfo.task = curctx->tinfo.task; |
| 137 | irqctx->tinfo.previous_sp = current_stack_pointer; |
| 138 | |
Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame^] | 139 | /* |
| 140 | * Copy the softirq bits in preempt_count so that the |
| 141 | * softirq checks work in the hardirq context. |
| 142 | */ |
| 143 | irqctx->tinfo.preempt_count = |
| 144 | (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) | |
| 145 | (curctx->tinfo.preempt_count & SOFTIRQ_MASK); |
| 146 | |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 147 | __asm__ __volatile__ ( |
| 148 | "mov %0, r4 \n" |
Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame^] | 149 | "mov r15, r8 \n" |
Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 150 | "jsr @%1 \n" |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 151 | /* swith to the irq stack */ |
Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 152 | " mov %2, r15 \n" |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 153 | /* restore the stack (ring zero) */ |
Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame^] | 154 | "mov r8, r15 \n" |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 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 | : "memory", "r0", "r1", "r2", "r3", "r4", |
| 158 | "r5", "r6", "r7", "r8", "t", "pr" |
| 159 | ); |
| 160 | } else |
| 161 | #endif |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 162 | generic_handle_irq(irq); |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | irq_exit(); |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 165 | |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 166 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return 1; |
| 168 | } |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 169 | |
| 170 | #ifdef CONFIG_4KSTACKS |
| 171 | /* |
| 172 | * These should really be __section__(".bss.page_aligned") as well, but |
| 173 | * gcc's 3.0 and earlier don't handle that correctly. |
| 174 | */ |
| 175 | static char softirq_stack[NR_CPUS * THREAD_SIZE] |
| 176 | __attribute__((__aligned__(THREAD_SIZE))); |
| 177 | |
| 178 | static char hardirq_stack[NR_CPUS * THREAD_SIZE] |
| 179 | __attribute__((__aligned__(THREAD_SIZE))); |
| 180 | |
| 181 | /* |
| 182 | * allocate per-cpu stacks for hardirq and for softirq processing |
| 183 | */ |
| 184 | void irq_ctx_init(int cpu) |
| 185 | { |
| 186 | union irq_ctx *irqctx; |
| 187 | |
| 188 | if (hardirq_ctx[cpu]) |
| 189 | return; |
| 190 | |
| 191 | irqctx = (union irq_ctx *)&hardirq_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 = HARDIRQ_OFFSET; |
| 196 | irqctx->tinfo.addr_limit = MAKE_MM_SEG(0); |
| 197 | |
| 198 | hardirq_ctx[cpu] = irqctx; |
| 199 | |
| 200 | irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE]; |
| 201 | irqctx->tinfo.task = NULL; |
| 202 | irqctx->tinfo.exec_domain = NULL; |
| 203 | irqctx->tinfo.cpu = cpu; |
Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame^] | 204 | irqctx->tinfo.preempt_count = 0; |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 205 | irqctx->tinfo.addr_limit = MAKE_MM_SEG(0); |
| 206 | |
| 207 | softirq_ctx[cpu] = irqctx; |
| 208 | |
| 209 | printk("CPU %u irqstacks, hard=%p soft=%p\n", |
| 210 | cpu, hardirq_ctx[cpu], softirq_ctx[cpu]); |
| 211 | } |
| 212 | |
| 213 | void irq_ctx_exit(int cpu) |
| 214 | { |
| 215 | hardirq_ctx[cpu] = NULL; |
| 216 | } |
| 217 | |
| 218 | extern asmlinkage void __do_softirq(void); |
| 219 | |
| 220 | asmlinkage void do_softirq(void) |
| 221 | { |
| 222 | unsigned long flags; |
| 223 | struct thread_info *curctx; |
| 224 | union irq_ctx *irqctx; |
| 225 | u32 *isp; |
| 226 | |
| 227 | if (in_interrupt()) |
| 228 | return; |
| 229 | |
| 230 | local_irq_save(flags); |
| 231 | |
| 232 | if (local_softirq_pending()) { |
| 233 | curctx = current_thread_info(); |
| 234 | irqctx = softirq_ctx[smp_processor_id()]; |
| 235 | irqctx->tinfo.task = curctx->task; |
| 236 | irqctx->tinfo.previous_sp = current_stack_pointer; |
| 237 | |
| 238 | /* build the stack frame on the softirq stack */ |
| 239 | isp = (u32 *)((char *)irqctx + sizeof(*irqctx)); |
| 240 | |
| 241 | __asm__ __volatile__ ( |
| 242 | "mov r15, r9 \n" |
| 243 | "jsr @%0 \n" |
| 244 | /* switch to the softirq stack */ |
| 245 | " mov %1, r15 \n" |
| 246 | /* restore the thread stack */ |
| 247 | "mov r9, r15 \n" |
| 248 | : /* no outputs */ |
| 249 | : "r" (__do_softirq), "r" (isp) |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 250 | : "memory", "r0", "r1", "r2", "r3", "r4", |
| 251 | "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr" |
| 252 | ); |
Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame^] | 253 | |
| 254 | /* |
| 255 | * Shouldnt happen, we returned above if in_interrupt(): |
| 256 | */ |
| 257 | WARN_ON_ONCE(softirq_count()); |
Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | local_irq_restore(flags); |
| 261 | } |
| 262 | EXPORT_SYMBOL(do_softirq); |
| 263 | #endif |