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