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