| 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 | ba93483 | 2009-10-26 09:58:31 +0900 | [diff] [blame] | 14 | #include <linux/ftrace.h> | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 15 | #include <linux/delay.h> | 
| Paul Mundt | 9ab3a15 | 2011-06-30 15:10:06 +0900 | [diff] [blame] | 16 | #include <linux/ratelimit.h> | 
| Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 17 | #include <asm/processor.h> | 
| Paul Mundt | be782df | 2007-03-12 14:09:35 +0900 | [diff] [blame] | 18 | #include <asm/machvec.h> | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 19 | #include <asm/uaccess.h> | 
|  | 20 | #include <asm/thread_info.h> | 
| Paul Mundt | f15cbe6 | 2008-07-29 08:09:44 +0900 | [diff] [blame] | 21 | #include <cpu/mmu_context.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 |  | 
| Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 23 | atomic_t irq_err_count; | 
|  | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* | 
|  | 26 | * 'what should we do if we get a hw irq event on an illegal vector'. | 
|  | 27 | * each architecture has to answer this themselves, it doesn't deserve | 
|  | 28 | * a generic callback i think. | 
|  | 29 | */ | 
|  | 30 | void ack_bad_irq(unsigned int irq) | 
|  | 31 | { | 
| Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 32 | atomic_inc(&irq_err_count); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | printk("unexpected IRQ trap at vector %02x\n", irq); | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | #if defined(CONFIG_PROC_FS) | 
| Paul Mundt | fa1d43a | 2009-05-22 01:26:16 +0900 | [diff] [blame] | 37 | /* | 
| Paul Mundt | 3d44ae4 | 2011-03-17 17:31:51 +0900 | [diff] [blame] | 38 | * /proc/interrupts printing for arch specific interrupts | 
| Paul Mundt | fa1d43a | 2009-05-22 01:26:16 +0900 | [diff] [blame] | 39 | */ | 
| Paul Mundt | 3d44ae4 | 2011-03-17 17:31:51 +0900 | [diff] [blame] | 40 | int arch_show_interrupts(struct seq_file *p, int prec) | 
| Paul Mundt | fa1d43a | 2009-05-22 01:26:16 +0900 | [diff] [blame] | 41 | { | 
| Paul Mundt | 731ba33 | 2009-10-14 16:42:28 +0900 | [diff] [blame] | 42 | int j; | 
|  | 43 |  | 
|  | 44 | seq_printf(p, "%*s: ", prec, "NMI"); | 
|  | 45 | for_each_online_cpu(j) | 
|  | 46 | seq_printf(p, "%10u ", irq_stat[j].__nmi_count); | 
|  | 47 | seq_printf(p, "  Non-maskable interrupts\n"); | 
|  | 48 |  | 
| Paul Mundt | fa1d43a | 2009-05-22 01:26:16 +0900 | [diff] [blame] | 49 | seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count)); | 
| Paul Mundt | 731ba33 | 2009-10-14 16:42:28 +0900 | [diff] [blame] | 50 |  | 
| Paul Mundt | fa1d43a | 2009-05-22 01:26:16 +0900 | [diff] [blame] | 51 | return 0; | 
|  | 52 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #endif | 
|  | 54 |  | 
| Paul Mundt | 110ed28 | 2007-11-02 12:16:51 +0900 | [diff] [blame] | 55 | #ifdef CONFIG_IRQSTACKS | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 56 | /* | 
|  | 57 | * per-CPU IRQ handling contexts (thread information and stack) | 
|  | 58 | */ | 
|  | 59 | union irq_ctx { | 
|  | 60 | struct thread_info	tinfo; | 
|  | 61 | u32			stack[THREAD_SIZE/sizeof(u32)]; | 
|  | 62 | }; | 
|  | 63 |  | 
| Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame] | 64 | static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly; | 
|  | 65 | static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly; | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 66 |  | 
| Paul Mundt | dc825b1 | 2010-04-15 13:13:52 +0900 | [diff] [blame] | 67 | static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss; | 
|  | 68 | static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss; | 
|  | 69 |  | 
|  | 70 | static inline void handle_one_irq(unsigned int irq) | 
| Paul Mundt | bf3a00f | 2006-01-16 22:14:14 -0800 | [diff] [blame] | 71 | { | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 72 | union irq_ctx *curctx, *irqctx; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 |  | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 74 | curctx = (union irq_ctx *)current_thread_info(); | 
|  | 75 | irqctx = hardirq_ctx[smp_processor_id()]; | 
|  | 76 |  | 
|  | 77 | /* | 
|  | 78 | * this is where we switch to the IRQ stack. However, if we are | 
|  | 79 | * already using the IRQ stack (because we interrupted a hardirq | 
|  | 80 | * handler) we can't do that and just have to keep using the | 
|  | 81 | * current stack (which is the irq stack already after all) | 
|  | 82 | */ | 
|  | 83 | if (curctx != irqctx) { | 
|  | 84 | u32 *isp; | 
|  | 85 |  | 
|  | 86 | isp = (u32 *)((char *)irqctx + sizeof(*irqctx)); | 
|  | 87 | irqctx->tinfo.task = curctx->tinfo.task; | 
|  | 88 | irqctx->tinfo.previous_sp = current_stack_pointer; | 
|  | 89 |  | 
| Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame] | 90 | /* | 
|  | 91 | * Copy the softirq bits in preempt_count so that the | 
|  | 92 | * softirq checks work in the hardirq context. | 
|  | 93 | */ | 
|  | 94 | irqctx->tinfo.preempt_count = | 
|  | 95 | (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) | | 
|  | 96 | (curctx->tinfo.preempt_count & SOFTIRQ_MASK); | 
|  | 97 |  | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 98 | __asm__ __volatile__ ( | 
|  | 99 | "mov	%0, r4		\n" | 
| Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame] | 100 | "mov	r15, r8		\n" | 
| Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 101 | "jsr	@%1		\n" | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 102 | /* swith to the irq stack */ | 
| Paul Mundt | baf4326 | 2006-10-12 12:03:04 +0900 | [diff] [blame] | 103 | " mov	%2, r15		\n" | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 104 | /* restore the stack (ring zero) */ | 
| Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame] | 105 | "mov	r8, r15		\n" | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 106 | : /* no outputs */ | 
| Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 107 | : "r" (irq), "r" (generic_handle_irq), "r" (isp) | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 108 | : "memory", "r0", "r1", "r2", "r3", "r4", | 
|  | 109 | "r5", "r6", "r7", "r8", "t", "pr" | 
|  | 110 | ); | 
|  | 111 | } else | 
| Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 112 | generic_handle_irq(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 114 |  | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 115 | /* | 
|  | 116 | * allocate per-cpu stacks for hardirq and for softirq processing | 
|  | 117 | */ | 
|  | 118 | void irq_ctx_init(int cpu) | 
|  | 119 | { | 
|  | 120 | union irq_ctx *irqctx; | 
|  | 121 |  | 
|  | 122 | if (hardirq_ctx[cpu]) | 
|  | 123 | return; | 
|  | 124 |  | 
|  | 125 | irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE]; | 
|  | 126 | irqctx->tinfo.task		= NULL; | 
|  | 127 | irqctx->tinfo.exec_domain	= NULL; | 
|  | 128 | irqctx->tinfo.cpu		= cpu; | 
|  | 129 | irqctx->tinfo.preempt_count	= HARDIRQ_OFFSET; | 
|  | 130 | irqctx->tinfo.addr_limit	= MAKE_MM_SEG(0); | 
|  | 131 |  | 
|  | 132 | hardirq_ctx[cpu] = irqctx; | 
|  | 133 |  | 
|  | 134 | irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE]; | 
|  | 135 | irqctx->tinfo.task		= NULL; | 
|  | 136 | irqctx->tinfo.exec_domain	= NULL; | 
|  | 137 | irqctx->tinfo.cpu		= cpu; | 
| Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame] | 138 | irqctx->tinfo.preempt_count	= 0; | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 139 | irqctx->tinfo.addr_limit	= MAKE_MM_SEG(0); | 
|  | 140 |  | 
|  | 141 | softirq_ctx[cpu] = irqctx; | 
|  | 142 |  | 
|  | 143 | printk("CPU %u irqstacks, hard=%p soft=%p\n", | 
|  | 144 | cpu, hardirq_ctx[cpu], softirq_ctx[cpu]); | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | void irq_ctx_exit(int cpu) | 
|  | 148 | { | 
|  | 149 | hardirq_ctx[cpu] = NULL; | 
|  | 150 | } | 
|  | 151 |  | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 152 | asmlinkage void do_softirq(void) | 
|  | 153 | { | 
|  | 154 | unsigned long flags; | 
|  | 155 | struct thread_info *curctx; | 
|  | 156 | union irq_ctx *irqctx; | 
|  | 157 | u32 *isp; | 
|  | 158 |  | 
|  | 159 | if (in_interrupt()) | 
|  | 160 | return; | 
|  | 161 |  | 
|  | 162 | local_irq_save(flags); | 
|  | 163 |  | 
|  | 164 | if (local_softirq_pending()) { | 
|  | 165 | curctx = current_thread_info(); | 
|  | 166 | irqctx = softirq_ctx[smp_processor_id()]; | 
|  | 167 | irqctx->tinfo.task = curctx->task; | 
|  | 168 | irqctx->tinfo.previous_sp = current_stack_pointer; | 
|  | 169 |  | 
|  | 170 | /* build the stack frame on the softirq stack */ | 
|  | 171 | isp = (u32 *)((char *)irqctx + sizeof(*irqctx)); | 
|  | 172 |  | 
|  | 173 | __asm__ __volatile__ ( | 
|  | 174 | "mov	r15, r9		\n" | 
|  | 175 | "jsr	@%0		\n" | 
|  | 176 | /* switch to the softirq stack */ | 
|  | 177 | " mov	%1, r15		\n" | 
|  | 178 | /* restore the thread stack */ | 
|  | 179 | "mov	r9, r15		\n" | 
|  | 180 | : /* no outputs */ | 
|  | 181 | : "r" (__do_softirq), "r" (isp) | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 182 | : "memory", "r0", "r1", "r2", "r3", "r4", | 
|  | 183 | "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr" | 
|  | 184 | ); | 
| Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame] | 185 |  | 
|  | 186 | /* | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 187 | * Shouldn't happen, we returned above if in_interrupt(): | 
| Paul Mundt | 1dc41e5 | 2006-11-24 19:46:18 +0900 | [diff] [blame] | 188 | */ | 
|  | 189 | WARN_ON_ONCE(softirq_count()); | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
|  | 192 | local_irq_restore(flags); | 
|  | 193 | } | 
| Paul Mundt | dc825b1 | 2010-04-15 13:13:52 +0900 | [diff] [blame] | 194 | #else | 
|  | 195 | static inline void handle_one_irq(unsigned int irq) | 
|  | 196 | { | 
|  | 197 | generic_handle_irq(irq); | 
|  | 198 | } | 
| Paul Mundt | a6a31139 | 2006-09-27 18:22:14 +0900 | [diff] [blame] | 199 | #endif | 
| Jamie Lenehan | ea0f8fe | 2006-12-06 12:05:02 +0900 | [diff] [blame] | 200 |  | 
| Paul Mundt | dc825b1 | 2010-04-15 13:13:52 +0900 | [diff] [blame] | 201 | asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs) | 
|  | 202 | { | 
|  | 203 | struct pt_regs *old_regs = set_irq_regs(regs); | 
|  | 204 |  | 
|  | 205 | irq_enter(); | 
|  | 206 |  | 
|  | 207 | irq = irq_demux(irq_lookup(irq)); | 
|  | 208 |  | 
|  | 209 | if (irq != NO_IRQ_IGNORE) { | 
|  | 210 | handle_one_irq(irq); | 
|  | 211 | irq_finish(irq); | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | irq_exit(); | 
|  | 215 |  | 
|  | 216 | set_irq_regs(old_regs); | 
|  | 217 |  | 
|  | 218 | return IRQ_HANDLED; | 
|  | 219 | } | 
|  | 220 |  | 
| Jamie Lenehan | ea0f8fe | 2006-12-06 12:05:02 +0900 | [diff] [blame] | 221 | void __init init_IRQ(void) | 
|  | 222 | { | 
| Magnus Damm | 90015c8 | 2007-07-18 17:57:34 +0900 | [diff] [blame] | 223 | plat_irq_setup(); | 
| Jamie Lenehan | ea0f8fe | 2006-12-06 12:05:02 +0900 | [diff] [blame] | 224 |  | 
|  | 225 | /* Perform the machine specific initialisation */ | 
|  | 226 | if (sh_mv.mv_init_irq) | 
|  | 227 | sh_mv.mv_init_irq(); | 
|  | 228 |  | 
| Paul Mundt | c1e30ad | 2010-10-05 04:47:03 +0900 | [diff] [blame] | 229 | intc_finalize(); | 
|  | 230 |  | 
| Jamie Lenehan | ea0f8fe | 2006-12-06 12:05:02 +0900 | [diff] [blame] | 231 | irq_ctx_init(smp_processor_id()); | 
|  | 232 | } | 
| Paul Mundt | d8586ba | 2009-05-22 01:36:13 +0900 | [diff] [blame] | 233 |  | 
|  | 234 | #ifdef CONFIG_SPARSE_IRQ | 
|  | 235 | int __init arch_probe_nr_irqs(void) | 
|  | 236 | { | 
|  | 237 | nr_irqs = sh_mv.mv_nr_irqs; | 
| Thomas Gleixner | b683de2 | 2010-09-27 20:55:03 +0200 | [diff] [blame] | 238 | return NR_IRQS_LEGACY; | 
| Paul Mundt | d8586ba | 2009-05-22 01:36:13 +0900 | [diff] [blame] | 239 | } | 
|  | 240 | #endif | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 241 |  | 
|  | 242 | #ifdef CONFIG_HOTPLUG_CPU | 
| Paul Mundt | fb41a49 | 2010-10-28 11:33:21 +0900 | [diff] [blame] | 243 | static void route_irq(struct irq_data *data, unsigned int irq, unsigned int cpu) | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 244 | { | 
| Paul Mundt | fb41a49 | 2010-10-28 11:33:21 +0900 | [diff] [blame] | 245 | struct irq_desc *desc = irq_to_desc(irq); | 
|  | 246 | struct irq_chip *chip = irq_data_get_irq_chip(data); | 
|  | 247 |  | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 248 | printk(KERN_INFO "IRQ%u: moving from cpu%u to cpu%u\n", | 
| Paul Mundt | fb41a49 | 2010-10-28 11:33:21 +0900 | [diff] [blame] | 249 | irq, data->node, cpu); | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 250 |  | 
|  | 251 | raw_spin_lock_irq(&desc->lock); | 
| Paul Mundt | fb41a49 | 2010-10-28 11:33:21 +0900 | [diff] [blame] | 252 | chip->irq_set_affinity(data, cpumask_of(cpu), false); | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 253 | raw_spin_unlock_irq(&desc->lock); | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | /* | 
|  | 257 | * The CPU has been marked offline.  Migrate IRQs off this CPU.  If | 
|  | 258 | * the affinity settings do not allow other CPUs, force them onto any | 
|  | 259 | * available CPU. | 
|  | 260 | */ | 
|  | 261 | void migrate_irqs(void) | 
|  | 262 | { | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 263 | unsigned int irq, cpu = smp_processor_id(); | 
|  | 264 |  | 
| Paul Mundt | fb41a49 | 2010-10-28 11:33:21 +0900 | [diff] [blame] | 265 | for_each_active_irq(irq) { | 
|  | 266 | struct irq_data *data = irq_get_irq_data(irq); | 
|  | 267 |  | 
|  | 268 | if (data->node == cpu) { | 
|  | 269 | unsigned int newcpu = cpumask_any_and(data->affinity, | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 270 | cpu_online_mask); | 
|  | 271 | if (newcpu >= nr_cpu_ids) { | 
| Paul Mundt | 9ab3a15 | 2011-06-30 15:10:06 +0900 | [diff] [blame] | 272 | pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n", | 
|  | 273 | irq, cpu); | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 274 |  | 
| Paul Mundt | fb41a49 | 2010-10-28 11:33:21 +0900 | [diff] [blame] | 275 | cpumask_setall(data->affinity); | 
|  | 276 | newcpu = cpumask_any_and(data->affinity, | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 277 | cpu_online_mask); | 
|  | 278 | } | 
|  | 279 |  | 
| Paul Mundt | fb41a49 | 2010-10-28 11:33:21 +0900 | [diff] [blame] | 280 | route_irq(data, irq, newcpu); | 
| Paul Mundt | 763142d | 2010-04-26 19:08:55 +0900 | [diff] [blame] | 281 | } | 
|  | 282 | } | 
|  | 283 | } | 
|  | 284 | #endif |