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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include "internals.h" |
| 22 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 23 | /* |
| 24 | * lockdep: we want to handle all irq_desc locks as a single lock-class: |
| 25 | */ |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 26 | struct lock_class_key irq_desc_lock_class; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 27 | |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 28 | /** |
| 29 | * handle_bad_irq - handle spurious and unhandled irqs |
Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 30 | * @irq: the interrupt number |
| 31 | * @desc: description of the interrupt |
Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 32 | * |
| 33 | * Handles spurious and unhandled IRQ's. It also prints a debugmessage. |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 34 | */ |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 35 | void handle_bad_irq(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 36 | { |
Ingo Molnar | 43f7775 | 2006-06-29 02:24:58 -0700 | [diff] [blame] | 37 | print_irq_desc(irq, desc); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 38 | kstat_incr_irqs_this_cpu(irq, desc); |
Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 39 | ack_bad_irq(irq); |
| 40 | } |
| 41 | |
David Daney | 97179fd | 2009-01-27 09:53:22 -0800 | [diff] [blame] | 42 | #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS) |
| 43 | static void __init init_irq_default_affinity(void) |
| 44 | { |
| 45 | alloc_bootmem_cpumask_var(&irq_default_affinity); |
| 46 | cpumask_setall(irq_default_affinity); |
| 47 | } |
| 48 | #else |
| 49 | static void __init init_irq_default_affinity(void) |
| 50 | { |
| 51 | } |
| 52 | #endif |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Linux has a controller-independent interrupt architecture. |
| 56 | * Every controller has a 'controller-template', that is used |
| 57 | * by the main code to do the right thing. Each driver-visible |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 58 | * interrupt source is transparently wired to the appropriate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * controller. Thus drivers need not be aware of the |
| 60 | * interrupt-controller. |
| 61 | * |
| 62 | * The code is designed to be easily extended with new/different |
| 63 | * interrupt controllers, without having to do assembly magic or |
| 64 | * having to touch the generic code. |
| 65 | * |
| 66 | * Controller mappings for all interrupt sources: |
| 67 | */ |
Yinghai Lu | 85c0f90 | 2008-08-19 20:49:47 -0700 | [diff] [blame] | 68 | int nr_irqs = NR_IRQS; |
Ingo Molnar | fa42d10 | 2008-08-19 20:50:30 -0700 | [diff] [blame] | 69 | EXPORT_SYMBOL_GPL(nr_irqs); |
Yinghai Lu | d60458b | 2008-08-19 20:50:00 -0700 | [diff] [blame] | 70 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 71 | #ifdef CONFIG_SPARSE_IRQ |
| 72 | static struct irq_desc irq_desc_init = { |
| 73 | .irq = -1, |
| 74 | .status = IRQ_DISABLED, |
| 75 | .chip = &no_irq_chip, |
| 76 | .handle_irq = handle_bad_irq, |
| 77 | .depth = 1, |
| 78 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock), |
| 79 | #ifdef CONFIG_SMP |
| 80 | .affinity = CPU_MASK_ALL |
| 81 | #endif |
| 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 | } |
| 118 | arch_init_chip_data(desc, cpu); |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Protect the sparse_irqs: |
| 123 | */ |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 124 | DEFINE_SPINLOCK(sparse_irq_lock); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 125 | |
| 126 | struct irq_desc *irq_desc_ptrs[NR_IRQS] __read_mostly; |
| 127 | |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame] | 128 | static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = { |
| 129 | [0 ... NR_IRQS_LEGACY-1] = { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 130 | .irq = -1, |
| 131 | .status = IRQ_DISABLED, |
| 132 | .chip = &no_irq_chip, |
| 133 | .handle_irq = handle_bad_irq, |
| 134 | .depth = 1, |
| 135 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock), |
| 136 | #ifdef CONFIG_SMP |
| 137 | .affinity = CPU_MASK_ALL |
| 138 | #endif |
| 139 | } |
| 140 | }; |
| 141 | |
| 142 | /* FIXME: use bootmem alloc ...*/ |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame] | 143 | static unsigned int kstat_irqs_legacy[NR_IRQS_LEGACY][NR_CPUS]; |
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 | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 153 | desc = irq_desc_legacy; |
| 154 | legacy_count = ARRAY_SIZE(irq_desc_legacy); |
| 155 | |
| 156 | for (i = 0; i < legacy_count; i++) { |
| 157 | desc[i].irq = i; |
| 158 | desc[i].kstat_irqs = kstat_irqs_legacy[i]; |
Yinghai Lu | fa6beb3 | 2008-12-22 20:24:09 -0800 | [diff] [blame] | 159 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 160 | |
| 161 | irq_desc_ptrs[i] = desc + i; |
| 162 | } |
| 163 | |
| 164 | for (i = legacy_count; i < NR_IRQS; i++) |
| 165 | irq_desc_ptrs[i] = NULL; |
| 166 | |
Yinghai Lu | 13a0c3c | 2008-12-26 02:05:47 -0800 | [diff] [blame] | 167 | return arch_early_irq_init(); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | struct irq_desc *irq_to_desc(unsigned int irq) |
| 171 | { |
| 172 | return (irq < NR_IRQS) ? irq_desc_ptrs[irq] : NULL; |
| 173 | } |
| 174 | |
| 175 | struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu) |
| 176 | { |
| 177 | struct irq_desc *desc; |
| 178 | unsigned long flags; |
| 179 | int node; |
| 180 | |
| 181 | if (irq >= NR_IRQS) { |
| 182 | printk(KERN_WARNING "irq >= NR_IRQS in irq_to_desc_alloc: %d %d\n", |
| 183 | irq, NR_IRQS); |
| 184 | WARN_ON(1); |
| 185 | return NULL; |
| 186 | } |
| 187 | |
| 188 | desc = irq_desc_ptrs[irq]; |
| 189 | if (desc) |
| 190 | return desc; |
| 191 | |
| 192 | spin_lock_irqsave(&sparse_irq_lock, flags); |
| 193 | |
| 194 | /* We have to check it to avoid races with another CPU */ |
| 195 | desc = irq_desc_ptrs[irq]; |
| 196 | if (desc) |
| 197 | goto out_unlock; |
| 198 | |
| 199 | node = cpu_to_node(cpu); |
| 200 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); |
| 201 | printk(KERN_DEBUG " alloc irq_desc for %d on cpu %d node %d\n", |
| 202 | irq, cpu, node); |
| 203 | if (!desc) { |
| 204 | printk(KERN_ERR "can not alloc irq_desc\n"); |
| 205 | BUG_ON(1); |
| 206 | } |
| 207 | init_one_irq_desc(irq, desc, cpu); |
| 208 | |
| 209 | irq_desc_ptrs[irq] = desc; |
| 210 | |
| 211 | out_unlock: |
| 212 | spin_unlock_irqrestore(&sparse_irq_lock, flags); |
| 213 | |
| 214 | return desc; |
| 215 | } |
| 216 | |
KOSAKI Motohiro | f9af0e7 | 2008-12-26 12:24:24 +0900 | [diff] [blame] | 217 | #else /* !CONFIG_SPARSE_IRQ */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 218 | |
Ravikiran G Thirumalai | e729aa1 | 2007-05-08 00:29:13 -0700 | [diff] [blame] | 219 | struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | [0 ... NR_IRQS-1] = { |
Zhang, Yanmin | 4f167fb | 2005-05-16 21:53:43 -0700 | [diff] [blame] | 221 | .status = IRQ_DISABLED, |
Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 222 | .chip = &no_irq_chip, |
Ingo Molnar | 7a55713 | 2006-06-29 02:24:54 -0700 | [diff] [blame] | 223 | .handle_irq = handle_bad_irq, |
Thomas Gleixner | 94d39e1 | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 224 | .depth = 1, |
Yinghai Lu | aac3f2b | 2008-09-24 19:04:35 -0700 | [diff] [blame] | 225 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock), |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 226 | #ifdef CONFIG_SMP |
| 227 | .affinity = CPU_MASK_ALL |
| 228 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | }; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 231 | |
Yinghai Lu | d7e51e6 | 2009-01-07 15:03:13 -0800 | [diff] [blame] | 232 | static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS]; |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 233 | int __init early_irq_init(void) |
| 234 | { |
| 235 | struct irq_desc *desc; |
| 236 | int count; |
| 237 | int i; |
| 238 | |
David Daney | 97179fd | 2009-01-27 09:53:22 -0800 | [diff] [blame] | 239 | init_irq_default_affinity(); |
| 240 | |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 241 | desc = irq_desc; |
| 242 | count = ARRAY_SIZE(irq_desc); |
| 243 | |
Yinghai Lu | d7e51e6 | 2009-01-07 15:03:13 -0800 | [diff] [blame] | 244 | for (i = 0; i < count; i++) { |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 245 | desc[i].irq = i; |
Yinghai Lu | d7e51e6 | 2009-01-07 15:03:13 -0800 | [diff] [blame] | 246 | desc[i].kstat_irqs = kstat_irqs_all[i]; |
| 247 | } |
Yinghai Lu | 12026ea | 2008-12-26 22:38:15 -0800 | [diff] [blame] | 248 | |
| 249 | return arch_early_irq_init(); |
| 250 | } |
| 251 | |
KOSAKI Motohiro | f9af0e7 | 2008-12-26 12:24:24 +0900 | [diff] [blame] | 252 | struct irq_desc *irq_to_desc(unsigned int irq) |
| 253 | { |
| 254 | return (irq < NR_IRQS) ? irq_desc + irq : NULL; |
| 255 | } |
| 256 | |
| 257 | struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu) |
| 258 | { |
| 259 | return irq_to_desc(irq); |
| 260 | } |
| 261 | #endif /* !CONFIG_SPARSE_IRQ */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 262 | |
Yinghai Lu | 0f3c2a8 | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 263 | void clear_kstat_irqs(struct irq_desc *desc) |
| 264 | { |
| 265 | memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs))); |
| 266 | } |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /* |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 269 | * What should we do if we get a hw irq event on an illegal vector? |
| 270 | * Each architecture has to answer this themself. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | */ |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 272 | static void ack_bad(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 274 | struct irq_desc *desc = irq_to_desc(irq); |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 275 | |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 276 | print_irq_desc(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | ack_bad_irq(irq); |
| 278 | } |
| 279 | |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 280 | /* |
| 281 | * NOP functions |
| 282 | */ |
| 283 | static void noop(unsigned int irq) |
| 284 | { |
| 285 | } |
| 286 | |
| 287 | static unsigned int noop_ret(unsigned int irq) |
| 288 | { |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Generic no controller implementation |
| 294 | */ |
Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 295 | struct irq_chip no_irq_chip = { |
| 296 | .name = "none", |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 297 | .startup = noop_ret, |
| 298 | .shutdown = noop, |
| 299 | .enable = noop, |
| 300 | .disable = noop, |
| 301 | .ack = ack_bad, |
| 302 | .end = noop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | /* |
Thomas Gleixner | f8b5473 | 2006-07-01 22:30:08 +0100 | [diff] [blame] | 306 | * Generic dummy implementation which can be used for |
| 307 | * real dumb interrupt sources |
| 308 | */ |
| 309 | struct irq_chip dummy_irq_chip = { |
| 310 | .name = "dummy", |
| 311 | .startup = noop_ret, |
| 312 | .shutdown = noop, |
| 313 | .enable = noop, |
| 314 | .disable = noop, |
| 315 | .ack = noop, |
| 316 | .mask = noop, |
| 317 | .unmask = noop, |
| 318 | .end = noop, |
| 319 | }; |
| 320 | |
| 321 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | * Special, empty irq handler: |
| 323 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 324 | irqreturn_t no_action(int cpl, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | return IRQ_NONE; |
| 327 | } |
| 328 | |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 329 | /** |
| 330 | * handle_IRQ_event - irq action chain handler |
| 331 | * @irq: the interrupt number |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 332 | * @action: the interrupt action chain for this irq |
| 333 | * |
| 334 | * Handles the action chain of an irq event |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 336 | irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Jan Beulich | 908dcec | 2006-06-23 02:06:00 -0700 | [diff] [blame] | 338 | irqreturn_t ret, retval = IRQ_NONE; |
| 339 | unsigned int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Peter Zijlstra | 044d408 | 2009-03-02 16:13:32 +0100 | [diff] [blame] | 341 | WARN_ONCE(!in_irq(), "BUG: IRQ handler called from non-hardirq context!"); |
| 342 | |
Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 343 | if (!(action->flags & IRQF_DISABLED)) |
Ingo Molnar | 366c7f5 | 2006-07-03 00:25:25 -0700 | [diff] [blame] | 344 | local_irq_enable_in_hardirq(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | do { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 347 | ret = action->handler(irq, action->dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | if (ret == IRQ_HANDLED) |
| 349 | status |= action->flags; |
| 350 | retval |= ret; |
| 351 | action = action->next; |
| 352 | } while (action); |
| 353 | |
Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 354 | if (status & IRQF_SAMPLE_RANDOM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | add_interrupt_randomness(irq); |
| 356 | local_irq_disable(); |
| 357 | |
| 358 | return retval; |
| 359 | } |
| 360 | |
David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 361 | #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ |
Thomas Gleixner | 0e57aa1 | 2009-03-13 14:34:05 +0100 | [diff] [blame] | 362 | |
| 363 | #ifdef CONFIG_ENABLE_WARN_DEPRECATED |
| 364 | # warning __do_IRQ is deprecated. Please convert to proper flow handlers |
| 365 | #endif |
| 366 | |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 367 | /** |
| 368 | * __do_IRQ - original all in one highlevel IRQ handler |
| 369 | * @irq: the interrupt number |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 370 | * |
| 371 | * __do_IRQ handles all normal device IRQ's (the special |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | * SMP cross-CPU interrupts have their own specific |
| 373 | * handlers). |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 374 | * |
| 375 | * This is the original x86 implementation which is used for every |
| 376 | * interrupt type. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | */ |
Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 378 | unsigned int __do_IRQ(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 380 | struct irq_desc *desc = irq_to_desc(irq); |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 381 | struct irqaction *action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | unsigned int status; |
| 383 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 384 | kstat_incr_irqs_this_cpu(irq, desc); |
| 385 | |
Karsten Wiese | f26fdd5 | 2005-09-06 15:17:25 -0700 | [diff] [blame] | 386 | if (CHECK_IRQ_PER_CPU(desc->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | irqreturn_t action_ret; |
| 388 | |
| 389 | /* |
| 390 | * No locking required for CPU-local interrupts: |
| 391 | */ |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 392 | if (desc->chip->ack) { |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 393 | desc->chip->ack(irq); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 394 | /* get new one */ |
| 395 | desc = irq_remap_to_desc(irq, desc); |
| 396 | } |
Russ Anderson | c642b83 | 2007-11-14 17:00:15 -0800 | [diff] [blame] | 397 | if (likely(!(desc->status & IRQ_DISABLED))) { |
| 398 | action_ret = handle_IRQ_event(irq, desc->action); |
| 399 | if (!noirqdebug) |
| 400 | note_interrupt(irq, desc, action_ret); |
| 401 | } |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 402 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return 1; |
| 404 | } |
| 405 | |
| 406 | spin_lock(&desc->lock); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 407 | if (desc->chip->ack) { |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 408 | desc->chip->ack(irq); |
Yinghai Lu | 48a1b10 | 2008-12-11 00:15:01 -0800 | [diff] [blame] | 409 | desc = irq_remap_to_desc(irq, desc); |
| 410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* |
| 412 | * REPLAY is when Linux resends an IRQ that was dropped earlier |
| 413 | * WAITING is used by probe to mark irqs that are being tested |
| 414 | */ |
| 415 | status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING); |
| 416 | status |= IRQ_PENDING; /* we _want_ to handle it */ |
| 417 | |
| 418 | /* |
| 419 | * If the IRQ is disabled for whatever reason, we cannot |
| 420 | * use the action we have. |
| 421 | */ |
| 422 | action = NULL; |
| 423 | if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) { |
| 424 | action = desc->action; |
| 425 | status &= ~IRQ_PENDING; /* we commit to handling */ |
| 426 | status |= IRQ_INPROGRESS; /* we are handling it */ |
| 427 | } |
| 428 | desc->status = status; |
| 429 | |
| 430 | /* |
| 431 | * If there is no IRQ handler or it was disabled, exit early. |
| 432 | * Since we set PENDING, if another processor is handling |
| 433 | * a different instance of this same irq, the other processor |
| 434 | * will take care of it. |
| 435 | */ |
| 436 | if (unlikely(!action)) |
| 437 | goto out; |
| 438 | |
| 439 | /* |
| 440 | * Edge triggered interrupts need to remember |
| 441 | * pending events. |
| 442 | * This applies to any hw interrupts that allow a second |
| 443 | * instance of the same irq to arrive while we are in do_IRQ |
| 444 | * or in the handler. But the code here only handles the _second_ |
| 445 | * instance of the irq, not the third or fourth. So it is mostly |
| 446 | * useful for irq hardware that does not mask cleanly in an |
| 447 | * SMP environment. |
| 448 | */ |
| 449 | for (;;) { |
| 450 | irqreturn_t action_ret; |
| 451 | |
| 452 | spin_unlock(&desc->lock); |
| 453 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 454 | action_ret = handle_IRQ_event(irq, action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | if (!noirqdebug) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 456 | note_interrupt(irq, desc, action_ret); |
Linus Torvalds | b42172f | 2006-11-22 09:32:06 -0800 | [diff] [blame] | 457 | |
| 458 | spin_lock(&desc->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | if (likely(!(desc->status & IRQ_PENDING))) |
| 460 | break; |
| 461 | desc->status &= ~IRQ_PENDING; |
| 462 | } |
| 463 | desc->status &= ~IRQ_INPROGRESS; |
| 464 | |
| 465 | out: |
| 466 | /* |
| 467 | * The ->end() handler has to deal with interrupts which got |
| 468 | * disabled while the handler was running. |
| 469 | */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 470 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | spin_unlock(&desc->lock); |
| 472 | |
| 473 | return 1; |
| 474 | } |
David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 475 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 477 | void early_init_irq_lock_class(void) |
| 478 | { |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame] | 479 | struct irq_desc *desc; |
Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 480 | int i; |
| 481 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 482 | for_each_irq_desc(i, desc) { |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame] | 483 | lockdep_set_class(&desc->lock, &irq_desc_lock_class); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 484 | } |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 485 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 486 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 487 | unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) |
| 488 | { |
| 489 | struct irq_desc *desc = irq_to_desc(irq); |
KOSAKI Motohiro | 26ddd8d | 2008-12-26 14:24:10 +0900 | [diff] [blame] | 490 | return desc ? desc->kstat_irqs[cpu] : 0; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 491 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 492 | EXPORT_SYMBOL(kstat_irqs_cpu); |
| 493 | |