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