Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/irq/handle.c |
| 3 | * |
Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 4 | * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar |
| 5 | * Copyright (C) 2005-2006, Thomas Gleixner, Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This file contains the core interrupt handling code. |
Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 8 | * |
| 9 | * Detailed information is available in Documentation/DocBook/genericirq |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/irq.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/random.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/kernel_stat.h> |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 18 | #include <linux/rculist.h> |
| 19 | #include <linux/hash.h> |
Mike Travis | 0fa0ebb | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 20 | #include <linux/bootmem.h> |
Steven Rostedt | ad8d75f | 2009-04-14 19:39:12 -0400 | [diff] [blame] | 21 | #include <trace/events/irq.h> |
Steven Rostedt | a8d154b | 2009-04-10 09:36:00 -0400 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "internals.h" |
| 24 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 25 | /* |
| 26 | * lockdep: we want to handle all irq_desc locks as a single lock-class: |
| 27 | */ |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 28 | struct lock_class_key irq_desc_lock_class; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 29 | |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 30 | /** |
| 31 | * handle_bad_irq - handle spurious and unhandled irqs |
Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 32 | * @irq: the interrupt number |
| 33 | * @desc: description of the interrupt |
Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 34 | * |
| 35 | * Handles spurious and unhandled IRQ's. It also prints a debugmessage. |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 36 | */ |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 37 | void handle_bad_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 38 | { |
Ingo Molnar | 43f7775 | 2006-06-29 02:24:58 -0700 | [diff] [blame] | 39 | print_irq_desc(irq, desc); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 40 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 41 | ack_bad_irq(irq); |
| 42 | } |
| 43 | |
David Daney | 97179fd | 2009-01-27 09:53:22 -0800 | [diff] [blame] | 44 | #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS) |
| 45 | static void __init init_irq_default_affinity(void) |
| 46 | { |
| 47 | alloc_bootmem_cpumask_var(&irq_default_affinity); |
| 48 | cpumask_setall(irq_default_affinity); |
| 49 | } |
| 50 | #else |
| 51 | static void __init init_irq_default_affinity(void) |
| 52 | { |
| 53 | } |
| 54 | #endif |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Linux has a controller-independent interrupt architecture. |
| 58 | * Every controller has a 'controller-template', that is used |
| 59 | * by the main code to do the right thing. Each driver-visible |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 60 | * interrupt source is transparently wired to the appropriate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * controller. Thus drivers need not be aware of the |
| 62 | * interrupt-controller. |
| 63 | * |
| 64 | * The code is designed to be easily extended with new/different |
| 65 | * interrupt controllers, without having to do assembly magic or |
| 66 | * having to touch the generic code. |
| 67 | * |
| 68 | * Controller mappings for all interrupt sources: |
| 69 | */ |
Yinghai Lu | 85c0f90 | 2008-08-19 20:49:47 -0700 | [diff] [blame] | 70 | int nr_irqs = NR_IRQS; |
Ingo Molnar | fa42d10 | 2008-08-19 20:50:30 -0700 | [diff] [blame] | 71 | EXPORT_SYMBOL_GPL(nr_irqs); |
Yinghai Lu | d60458b | 2008-08-19 20:50:00 -0700 | [diff] [blame] | 72 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 73 | #ifdef CONFIG_SPARSE_IRQ |
Mike Travis | 92296c6 | 2009-01-11 09:22:58 -0800 | [diff] [blame] | 74 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 75 | static struct irq_desc irq_desc_init = { |
| 76 | .irq = -1, |
| 77 | .status = IRQ_DISABLED, |
| 78 | .chip = &no_irq_chip, |
| 79 | .handle_irq = handle_bad_irq, |
| 80 | .depth = 1, |
| 81 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock), |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 84 | void init_kstat_irqs(struct irq_desc *desc, int cpu, int nr) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 85 | { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 86 | int node; |
Yinghai Lu | 005bf0e6 | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 87 | void *ptr; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 88 | |
| 89 | node = cpu_to_node(cpu); |
Yinghai Lu | 005bf0e6 | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 90 | ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 91 | |
Yinghai Lu | 005bf0e6 | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 92 | /* |
| 93 | * don't overwite if can not get new one |
| 94 | * init_copy_kstat_irqs() could still use old one |
| 95 | */ |
| 96 | if (ptr) { |
| 97 | printk(KERN_DEBUG " alloc kstat_irqs on cpu %d node %d\n", |
| 98 | cpu, node); |
| 99 | desc->kstat_irqs = ptr; |
| 100 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 103 | static void init_one_irq_desc(int irq, struct irq_desc *desc, int cpu) |
| 104 | { |
| 105 | memcpy(desc, &irq_desc_init, sizeof(struct irq_desc)); |
Ingo Molnar | 793f7b1 | 2008-12-26 19:02:20 +0100 | [diff] [blame] | 106 | |
| 107 | spin_lock_init(&desc->lock); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 108 | desc->irq = irq; |
| 109 | #ifdef CONFIG_SMP |
| 110 | desc->cpu = cpu; |
| 111 | #endif |
| 112 | lockdep_set_class(&desc->lock, &irq_desc_lock_class); |
| 113 | init_kstat_irqs(desc, cpu, nr_cpu_ids); |
| 114 | if (!desc->kstat_irqs) { |
| 115 | printk(KERN_ERR "can not alloc kstat_irqs\n"); |
| 116 | BUG_ON(1); |
| 117 | } |
Mike Travis | 802bf93 | 2009-01-10 21:58:09 -0800 | [diff] [blame] | 118 | if (!init_alloc_desc_masks(desc, cpu, false)) { |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 119 | printk(KERN_ERR "can not alloc irq_desc cpumasks\n"); |
| 120 | BUG_ON(1); |
| 121 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 122 | arch_init_chip_data(desc, cpu); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Protect the sparse_irqs: |
| 127 | */ |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 128 | DEFINE_SPINLOCK(sparse_irq_lock); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 129 | |
Mike Travis | 0fa0ebb | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 130 | struct irq_desc **irq_desc_ptrs __read_mostly; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 131 | |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame] | 132 | static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = { |
| 133 | [0 ... NR_IRQS_LEGACY-1] = { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 134 | .irq = -1, |
| 135 | .status = IRQ_DISABLED, |
| 136 | .chip = &no_irq_chip, |
| 137 | .handle_irq = handle_bad_irq, |
| 138 | .depth = 1, |
| 139 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock), |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 140 | } |
| 141 | }; |
| 142 | |
Mike Travis | 542d865 | 2009-01-10 22:24:07 -0800 | [diff] [blame] | 143 | static unsigned int *kstat_irqs_legacy; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 144 | |
Yinghai Lu | 13a0c3c | 2008-12-26 02:05:47 -0800 | [diff] [blame] | 145 | int __init early_irq_init(void) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 146 | { |
| 147 | struct irq_desc *desc; |
| 148 | int legacy_count; |
| 149 | int i; |
| 150 | |
David Daney | 97179fd | 2009-01-27 09:53:22 -0800 | [diff] [blame] | 151 | init_irq_default_affinity(); |
| 152 | |
Yinghai Lu | 4a046d1 | 2009-01-12 17:39:24 -0800 | [diff] [blame] | 153 | /* initialize nr_irqs based on nr_cpu_ids */ |
| 154 | arch_probe_nr_irqs(); |
Mike Travis | 9594949 | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 155 | printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d\n", NR_IRQS, nr_irqs); |
| 156 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 157 | desc = irq_desc_legacy; |
| 158 | legacy_count = ARRAY_SIZE(irq_desc_legacy); |
| 159 | |
Mike Travis | 0fa0ebb | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 160 | /* allocate irq_desc_ptrs array based on nr_irqs */ |
| 161 | irq_desc_ptrs = alloc_bootmem(nr_irqs * sizeof(void *)); |
| 162 | |
Mike Travis | 542d865 | 2009-01-10 22:24:07 -0800 | [diff] [blame] | 163 | /* allocate based on nr_cpu_ids */ |
| 164 | /* FIXME: invert kstat_irgs, and it'd be a per_cpu_alloc'd thing */ |
| 165 | kstat_irqs_legacy = alloc_bootmem(NR_IRQS_LEGACY * nr_cpu_ids * |
| 166 | sizeof(int)); |
| 167 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 168 | for (i = 0; i < legacy_count; i++) { |
| 169 | desc[i].irq = i; |
Mike Travis | 542d865 | 2009-01-10 22:24:07 -0800 | [diff] [blame] | 170 | desc[i].kstat_irqs = kstat_irqs_legacy + i * nr_cpu_ids; |
Yinghai Lu | fa6beb3 | 2008-12-22 20:24:09 -0800 | [diff] [blame] | 171 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 172 | init_alloc_desc_masks(&desc[i], 0, true); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 173 | irq_desc_ptrs[i] = desc + i; |
| 174 | } |
| 175 | |
Mike Travis | 9594949 | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 176 | for (i = legacy_count; i < nr_irqs; i++) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 177 | irq_desc_ptrs[i] = NULL; |
| 178 | |
Yinghai Lu | 13a0c3c | 2008-12-26 02:05:47 -0800 | [diff] [blame] | 179 | return arch_early_irq_init(); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | struct irq_desc *irq_to_desc(unsigned int irq) |
| 183 | { |
Mike Travis | 0fa0ebb | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 184 | if (irq_desc_ptrs && irq < nr_irqs) |
| 185 | return irq_desc_ptrs[irq]; |
| 186 | |
| 187 | return NULL; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu) |
| 191 | { |
| 192 | struct irq_desc *desc; |
| 193 | unsigned long flags; |
| 194 | int node; |
| 195 | |
Mike Travis | 9594949 | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 196 | if (irq >= nr_irqs) { |
Mike Travis | e2f4d06 | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 197 | WARN(1, "irq (%d) >= nr_irqs (%d) in irq_to_desc_alloc\n", |
| 198 | irq, nr_irqs); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 199 | return NULL; |
| 200 | } |
| 201 | |
| 202 | desc = irq_desc_ptrs[irq]; |
| 203 | if (desc) |
| 204 | return desc; |
| 205 | |
| 206 | spin_lock_irqsave(&sparse_irq_lock, flags); |
| 207 | |
| 208 | /* We have to check it to avoid races with another CPU */ |
| 209 | desc = irq_desc_ptrs[irq]; |
| 210 | if (desc) |
| 211 | goto out_unlock; |
| 212 | |
| 213 | node = cpu_to_node(cpu); |
| 214 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); |
| 215 | printk(KERN_DEBUG " alloc irq_desc for %d on cpu %d node %d\n", |
| 216 | irq, cpu, node); |
| 217 | if (!desc) { |
| 218 | printk(KERN_ERR "can not alloc irq_desc\n"); |
| 219 | BUG_ON(1); |
| 220 | } |
| 221 | init_one_irq_desc(irq, desc, cpu); |
| 222 | |
| 223 | irq_desc_ptrs[irq] = desc; |
| 224 | |
| 225 | out_unlock: |
| 226 | spin_unlock_irqrestore(&sparse_irq_lock, flags); |
| 227 | |
| 228 | return desc; |
| 229 | } |
| 230 | |
KOSAKI Motohiro | f9af0e7 | 2008-12-26 12:24:24 +0900 | [diff] [blame] | 231 | #else /* !CONFIG_SPARSE_IRQ */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 232 | |
Ravikiran G Thirumalai | e729aa1 | 2007-05-08 00:29:13 -0700 | [diff] [blame] | 233 | struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | [0 ... NR_IRQS-1] = { |
Zhang, Yanmin | 4f167fb | 2005-05-16 21:53:43 -0700 | [diff] [blame] | 235 | .status = IRQ_DISABLED, |
Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 236 | .chip = &no_irq_chip, |
Ingo Molnar | 7a55713 | 2006-06-29 02:24:54 -0700 | [diff] [blame] | 237 | .handle_irq = handle_bad_irq, |
Thomas Gleixner | 94d39e1 | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 238 | .depth = 1, |
Yinghai Lu | aac3f2b | 2008-09-24 19:04:35 -0700 | [diff] [blame] | 239 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | }; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 242 | |
Yinghai Lu | d7e51e6 | 2009-01-07 15:03:13 -0800 | [diff] [blame] | 243 | static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS]; |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 244 | int __init early_irq_init(void) |
| 245 | { |
| 246 | struct irq_desc *desc; |
| 247 | int count; |
| 248 | int i; |
| 249 | |
David Daney | 97179fd | 2009-01-27 09:53:22 -0800 | [diff] [blame] | 250 | init_irq_default_affinity(); |
| 251 | |
Mike Travis | 9594949 | 2009-01-10 22:24:06 -0800 | [diff] [blame] | 252 | printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS); |
| 253 | |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 254 | desc = irq_desc; |
| 255 | count = ARRAY_SIZE(irq_desc); |
| 256 | |
Yinghai Lu | d7e51e6 | 2009-01-07 15:03:13 -0800 | [diff] [blame] | 257 | for (i = 0; i < count; i++) { |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 258 | desc[i].irq = i; |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 259 | init_alloc_desc_masks(&desc[i], 0, true); |
Yinghai Lu | d7e51e6 | 2009-01-07 15:03:13 -0800 | [diff] [blame] | 260 | desc[i].kstat_irqs = kstat_irqs_all[i]; |
| 261 | } |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 262 | return arch_early_irq_init(); |
| 263 | } |
| 264 | |
KOSAKI Motohiro | f9af0e7 | 2008-12-26 12:24:24 +0900 | [diff] [blame] | 265 | struct irq_desc *irq_to_desc(unsigned int irq) |
| 266 | { |
| 267 | return (irq < NR_IRQS) ? irq_desc + irq : NULL; |
| 268 | } |
| 269 | |
| 270 | struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu) |
| 271 | { |
| 272 | return irq_to_desc(irq); |
| 273 | } |
| 274 | #endif /* !CONFIG_SPARSE_IRQ */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 275 | |
Yinghai Lu | 0f3c2a8 | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 276 | void clear_kstat_irqs(struct irq_desc *desc) |
| 277 | { |
| 278 | memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs))); |
| 279 | } |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 282 | * What should we do if we get a hw irq event on an illegal vector? |
| 283 | * Each architecture has to answer this themself. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | */ |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 285 | static void ack_bad(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 287 | struct irq_desc *desc = irq_to_desc(irq); |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 288 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 289 | print_irq_desc(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | ack_bad_irq(irq); |
| 291 | } |
| 292 | |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 293 | /* |
| 294 | * NOP functions |
| 295 | */ |
| 296 | static void noop(unsigned int irq) |
| 297 | { |
| 298 | } |
| 299 | |
| 300 | static unsigned int noop_ret(unsigned int irq) |
| 301 | { |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * Generic no controller implementation |
| 307 | */ |
Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 308 | struct irq_chip no_irq_chip = { |
| 309 | .name = "none", |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 310 | .startup = noop_ret, |
| 311 | .shutdown = noop, |
| 312 | .enable = noop, |
| 313 | .disable = noop, |
| 314 | .ack = ack_bad, |
| 315 | .end = noop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | /* |
Thomas Gleixner | f8b5473 | 2006-07-01 22:30:08 +0100 | [diff] [blame] | 319 | * Generic dummy implementation which can be used for |
| 320 | * real dumb interrupt sources |
| 321 | */ |
| 322 | struct irq_chip dummy_irq_chip = { |
| 323 | .name = "dummy", |
| 324 | .startup = noop_ret, |
| 325 | .shutdown = noop, |
| 326 | .enable = noop, |
| 327 | .disable = noop, |
| 328 | .ack = noop, |
| 329 | .mask = noop, |
| 330 | .unmask = noop, |
| 331 | .end = noop, |
| 332 | }; |
| 333 | |
| 334 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | * Special, empty irq handler: |
| 336 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 337 | irqreturn_t no_action(int cpl, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
| 339 | return IRQ_NONE; |
| 340 | } |
| 341 | |
Thomas Gleixner | f48fe81 | 2009-03-24 11:46:22 +0100 | [diff] [blame] | 342 | static void warn_no_thread(unsigned int irq, struct irqaction *action) |
| 343 | { |
| 344 | if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags)) |
| 345 | return; |
| 346 | |
| 347 | printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD " |
| 348 | "but no thread function available.", irq, action->name); |
| 349 | } |
| 350 | |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 351 | /** |
| 352 | * handle_IRQ_event - irq action chain handler |
| 353 | * @irq: the interrupt number |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 354 | * @action: the interrupt action chain for this irq |
| 355 | * |
| 356 | * Handles the action chain of an irq event |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 358 | irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Jan Beulich | 908dcec | 2006-06-23 02:06:00 -0700 | [diff] [blame] | 360 | irqreturn_t ret, retval = IRQ_NONE; |
| 361 | unsigned int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Peter Zijlstra | 044d408 | 2009-03-02 16:13:32 +0100 | [diff] [blame] | 363 | WARN_ONCE(!in_irq(), "BUG: IRQ handler called from non-hardirq context!"); |
| 364 | |
Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 365 | if (!(action->flags & IRQF_DISABLED)) |
Ingo Molnar | 366c7f5 | 2006-07-03 00:25:25 -0700 | [diff] [blame] | 366 | local_irq_enable_in_hardirq(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | do { |
Jason Baron | af39241 | 2009-02-26 10:11:05 -0500 | [diff] [blame] | 369 | trace_irq_handler_entry(irq, action); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 370 | ret = action->handler(irq, action->dev_id); |
Jason Baron | af39241 | 2009-02-26 10:11:05 -0500 | [diff] [blame] | 371 | trace_irq_handler_exit(irq, action, ret); |
Thomas Gleixner | 3aa551c | 2009-03-23 18:28:15 +0100 | [diff] [blame] | 372 | |
| 373 | switch (ret) { |
| 374 | case IRQ_WAKE_THREAD: |
| 375 | /* |
Thomas Gleixner | f48fe81 | 2009-03-24 11:46:22 +0100 | [diff] [blame] | 376 | * Set result to handled so the spurious check |
| 377 | * does not trigger. |
| 378 | */ |
| 379 | ret = IRQ_HANDLED; |
| 380 | |
| 381 | /* |
| 382 | * Catch drivers which return WAKE_THREAD but |
| 383 | * did not set up a thread function |
| 384 | */ |
| 385 | if (unlikely(!action->thread_fn)) { |
| 386 | warn_no_thread(irq, action); |
| 387 | break; |
| 388 | } |
| 389 | |
| 390 | /* |
Thomas Gleixner | 3aa551c | 2009-03-23 18:28:15 +0100 | [diff] [blame] | 391 | * Wake up the handler thread for this |
| 392 | * action. In case the thread crashed and was |
| 393 | * killed we just pretend that we handled the |
| 394 | * interrupt. The hardirq handler above has |
| 395 | * disabled the device interrupt, so no irq |
| 396 | * storm is lurking. |
| 397 | */ |
| 398 | if (likely(!test_bit(IRQTF_DIED, |
| 399 | &action->thread_flags))) { |
| 400 | set_bit(IRQTF_RUNTHREAD, &action->thread_flags); |
| 401 | wake_up_process(action->thread); |
| 402 | } |
| 403 | |
Thomas Gleixner | 3aa551c | 2009-03-23 18:28:15 +0100 | [diff] [blame] | 404 | /* Fall through to add to randomness */ |
| 405 | case IRQ_HANDLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | status |= action->flags; |
Thomas Gleixner | 3aa551c | 2009-03-23 18:28:15 +0100 | [diff] [blame] | 407 | break; |
| 408 | |
| 409 | default: |
| 410 | break; |
| 411 | } |
| 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | retval |= ret; |
| 414 | action = action->next; |
| 415 | } while (action); |
| 416 | |
Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 417 | if (status & IRQF_SAMPLE_RANDOM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | add_interrupt_randomness(irq); |
| 419 | local_irq_disable(); |
| 420 | |
| 421 | return retval; |
| 422 | } |
| 423 | |
David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 424 | #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ |
Thomas Gleixner | 0e57aa1 | 2009-03-13 14:34:05 +0100 | [diff] [blame] | 425 | |
| 426 | #ifdef CONFIG_ENABLE_WARN_DEPRECATED |
| 427 | # warning __do_IRQ is deprecated. Please convert to proper flow handlers |
| 428 | #endif |
| 429 | |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 430 | /** |
| 431 | * __do_IRQ - original all in one highlevel IRQ handler |
| 432 | * @irq: the interrupt number |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 433 | * |
| 434 | * __do_IRQ handles all normal device IRQ's (the special |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | * SMP cross-CPU interrupts have their own specific |
| 436 | * handlers). |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 437 | * |
| 438 | * This is the original x86 implementation which is used for every |
| 439 | * interrupt type. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 441 | unsigned int __do_IRQ(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 443 | struct irq_desc *desc = irq_to_desc(irq); |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 444 | struct irqaction *action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | unsigned int status; |
| 446 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 447 | kstat_incr_irqs_this_cpu(irq, desc); |
| 448 | |
Karsten Wiese | f26fdd5 | 2005-09-06 15:17:25 -0700 | [diff] [blame] | 449 | if (CHECK_IRQ_PER_CPU(desc->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | irqreturn_t action_ret; |
| 451 | |
| 452 | /* |
| 453 | * No locking required for CPU-local interrupts: |
| 454 | */ |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 455 | if (desc->chip->ack) { |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 456 | desc->chip->ack(irq); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 457 | /* get new one */ |
| 458 | desc = irq_remap_to_desc(irq, desc); |
| 459 | } |
Russ Anderson | c642b83 | 2007-11-14 17:00:15 -0800 | [diff] [blame] | 460 | if (likely(!(desc->status & IRQ_DISABLED))) { |
| 461 | action_ret = handle_IRQ_event(irq, desc->action); |
| 462 | if (!noirqdebug) |
| 463 | note_interrupt(irq, desc, action_ret); |
| 464 | } |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 465 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return 1; |
| 467 | } |
| 468 | |
| 469 | spin_lock(&desc->lock); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 470 | if (desc->chip->ack) { |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 471 | desc->chip->ack(irq); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 472 | desc = irq_remap_to_desc(irq, desc); |
| 473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /* |
| 475 | * REPLAY is when Linux resends an IRQ that was dropped earlier |
| 476 | * WAITING is used by probe to mark irqs that are being tested |
| 477 | */ |
| 478 | status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING); |
| 479 | status |= IRQ_PENDING; /* we _want_ to handle it */ |
| 480 | |
| 481 | /* |
| 482 | * If the IRQ is disabled for whatever reason, we cannot |
| 483 | * use the action we have. |
| 484 | */ |
| 485 | action = NULL; |
| 486 | if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) { |
| 487 | action = desc->action; |
| 488 | status &= ~IRQ_PENDING; /* we commit to handling */ |
| 489 | status |= IRQ_INPROGRESS; /* we are handling it */ |
| 490 | } |
| 491 | desc->status = status; |
| 492 | |
| 493 | /* |
| 494 | * If there is no IRQ handler or it was disabled, exit early. |
| 495 | * Since we set PENDING, if another processor is handling |
| 496 | * a different instance of this same irq, the other processor |
| 497 | * will take care of it. |
| 498 | */ |
| 499 | if (unlikely(!action)) |
| 500 | goto out; |
| 501 | |
| 502 | /* |
| 503 | * Edge triggered interrupts need to remember |
| 504 | * pending events. |
| 505 | * This applies to any hw interrupts that allow a second |
| 506 | * instance of the same irq to arrive while we are in do_IRQ |
| 507 | * or in the handler. But the code here only handles the _second_ |
| 508 | * instance of the irq, not the third or fourth. So it is mostly |
| 509 | * useful for irq hardware that does not mask cleanly in an |
| 510 | * SMP environment. |
| 511 | */ |
| 512 | for (;;) { |
| 513 | irqreturn_t action_ret; |
| 514 | |
| 515 | spin_unlock(&desc->lock); |
| 516 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 517 | action_ret = handle_IRQ_event(irq, action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (!noirqdebug) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 519 | note_interrupt(irq, desc, action_ret); |
Linus Torvalds | b42172f | 2006-11-22 09:32:06 -0800 | [diff] [blame] | 520 | |
| 521 | spin_lock(&desc->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (likely(!(desc->status & IRQ_PENDING))) |
| 523 | break; |
| 524 | desc->status &= ~IRQ_PENDING; |
| 525 | } |
| 526 | desc->status &= ~IRQ_INPROGRESS; |
| 527 | |
| 528 | out: |
| 529 | /* |
| 530 | * The ->end() handler has to deal with interrupts which got |
| 531 | * disabled while the handler was running. |
| 532 | */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 533 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | spin_unlock(&desc->lock); |
| 535 | |
| 536 | return 1; |
| 537 | } |
David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 538 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 540 | void early_init_irq_lock_class(void) |
| 541 | { |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame] | 542 | struct irq_desc *desc; |
Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 543 | int i; |
| 544 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 545 | for_each_irq_desc(i, desc) { |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame] | 546 | lockdep_set_class(&desc->lock, &irq_desc_lock_class); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 547 | } |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 548 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 549 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 550 | unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) |
| 551 | { |
| 552 | struct irq_desc *desc = irq_to_desc(irq); |
KOSAKI Motohiro | 26ddd8d | 2008-12-26 14:24:10 +0900 | [diff] [blame] | 553 | return desc ? desc->kstat_irqs[cpu] : 0; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 554 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 555 | EXPORT_SYMBOL(kstat_irqs_cpu); |
| 556 | |