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