Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar |
| 3 | * Copyright (C) 2005-2006, Thomas Gleixner, Russell King |
| 4 | * |
| 5 | * This file contains the interrupt descriptor management code |
| 6 | * |
| 7 | * Detailed information is available in Documentation/DocBook/genericirq |
| 8 | * |
| 9 | */ |
| 10 | #include <linux/irq.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/kernel_stat.h> |
| 15 | #include <linux/radix-tree.h> |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 16 | #include <linux/bitmap.h> |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 17 | |
| 18 | #include "internals.h" |
| 19 | |
| 20 | /* |
| 21 | * lockdep: we want to handle all irq_desc locks as a single lock-class: |
| 22 | */ |
Thomas Gleixner | 78f90d9 | 2010-09-29 17:18:47 +0200 | [diff] [blame] | 23 | static struct lock_class_key irq_desc_lock_class; |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 24 | |
| 25 | #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS) |
| 26 | static void __init init_irq_default_affinity(void) |
| 27 | { |
| 28 | alloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT); |
| 29 | cpumask_setall(irq_default_affinity); |
| 30 | } |
| 31 | #else |
| 32 | static void __init init_irq_default_affinity(void) |
| 33 | { |
| 34 | } |
| 35 | #endif |
| 36 | |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 37 | #ifdef CONFIG_SMP |
| 38 | static int alloc_masks(struct irq_desc *desc, gfp_t gfp, int node) |
| 39 | { |
| 40 | if (!zalloc_cpumask_var_node(&desc->irq_data.affinity, gfp, node)) |
| 41 | return -ENOMEM; |
| 42 | |
| 43 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
| 44 | if (!zalloc_cpumask_var_node(&desc->pending_mask, gfp, node)) { |
| 45 | free_cpumask_var(desc->irq_data.affinity); |
| 46 | return -ENOMEM; |
| 47 | } |
| 48 | #endif |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static void desc_smp_init(struct irq_desc *desc, int node) |
| 53 | { |
Thomas Gleixner | aa99ec0 | 2010-09-27 20:02:56 +0200 | [diff] [blame] | 54 | desc->irq_data.node = node; |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 55 | cpumask_copy(desc->irq_data.affinity, irq_default_affinity); |
Thomas Gleixner | b7b2933 | 2010-09-29 18:46:55 +0200 | [diff] [blame] | 56 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
| 57 | cpumask_clear(desc->pending_mask); |
| 58 | #endif |
| 59 | } |
| 60 | |
| 61 | static inline int desc_node(struct irq_desc *desc) |
| 62 | { |
| 63 | return desc->irq_data.node; |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | #else |
| 67 | static inline int |
| 68 | alloc_masks(struct irq_desc *desc, gfp_t gfp, int node) { return 0; } |
| 69 | static inline void desc_smp_init(struct irq_desc *desc, int node) { } |
Thomas Gleixner | b7b2933 | 2010-09-29 18:46:55 +0200 | [diff] [blame] | 70 | static inline int desc_node(struct irq_desc *desc) { return 0; } |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 71 | #endif |
| 72 | |
| 73 | static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node) |
| 74 | { |
| 75 | desc->irq_data.irq = irq; |
| 76 | desc->irq_data.chip = &no_irq_chip; |
| 77 | desc->irq_data.chip_data = NULL; |
| 78 | desc->irq_data.handler_data = NULL; |
| 79 | desc->irq_data.msi_desc = NULL; |
| 80 | desc->status = IRQ_DEFAULT_INIT_FLAGS; |
| 81 | desc->handle_irq = handle_bad_irq; |
| 82 | desc->depth = 1; |
Thomas Gleixner | b7b2933 | 2010-09-29 18:46:55 +0200 | [diff] [blame] | 83 | desc->irq_count = 0; |
| 84 | desc->irqs_unhandled = 0; |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 85 | desc->name = NULL; |
| 86 | memset(desc->kstat_irqs, 0, nr_cpu_ids * sizeof(*(desc->kstat_irqs))); |
| 87 | desc_smp_init(desc, node); |
| 88 | } |
| 89 | |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 90 | int nr_irqs = NR_IRQS; |
| 91 | EXPORT_SYMBOL_GPL(nr_irqs); |
| 92 | |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 93 | static DEFINE_MUTEX(sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 94 | static DECLARE_BITMAP(allocated_irqs, NR_IRQS); |
| 95 | |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 96 | #ifdef CONFIG_SPARSE_IRQ |
| 97 | |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 98 | static RADIX_TREE(irq_desc_tree, GFP_ATOMIC); |
| 99 | |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 100 | static void irq_insert_desc(unsigned int irq, struct irq_desc *desc) |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 101 | { |
| 102 | radix_tree_insert(&irq_desc_tree, irq, desc); |
| 103 | } |
| 104 | |
| 105 | struct irq_desc *irq_to_desc(unsigned int irq) |
| 106 | { |
| 107 | return radix_tree_lookup(&irq_desc_tree, irq); |
| 108 | } |
| 109 | |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 110 | static void delete_irq_desc(unsigned int irq) |
| 111 | { |
| 112 | radix_tree_delete(&irq_desc_tree, irq); |
| 113 | } |
| 114 | |
| 115 | #ifdef CONFIG_SMP |
| 116 | static void free_masks(struct irq_desc *desc) |
| 117 | { |
| 118 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
| 119 | free_cpumask_var(desc->pending_mask); |
| 120 | #endif |
| 121 | free_cpumask_var(desc->affinity); |
| 122 | } |
| 123 | #else |
| 124 | static inline void free_masks(struct irq_desc *desc) { } |
| 125 | #endif |
| 126 | |
| 127 | static struct irq_desc *alloc_desc(int irq, int node) |
| 128 | { |
Thomas Gleixner | aa99ec0 | 2010-09-27 20:02:56 +0200 | [diff] [blame] | 129 | /* Temporary hack until we can switch to GFP_KERNEL */ |
| 130 | gfp_t gfp = gfp_allowed_mask == GFP_BOOT_MASK ? GFP_NOWAIT : GFP_ATOMIC; |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 131 | struct irq_desc *desc; |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 132 | |
| 133 | desc = kzalloc_node(sizeof(*desc), gfp, node); |
| 134 | if (!desc) |
| 135 | return NULL; |
| 136 | /* allocate based on nr_cpu_ids */ |
| 137 | desc->kstat_irqs = kzalloc_node(nr_cpu_ids * sizeof(*desc->kstat_irqs), |
| 138 | gfp, node); |
| 139 | if (!desc->kstat_irqs) |
| 140 | goto err_desc; |
| 141 | |
| 142 | if (alloc_masks(desc, gfp, node)) |
| 143 | goto err_kstat; |
| 144 | |
| 145 | raw_spin_lock_init(&desc->lock); |
| 146 | lockdep_set_class(&desc->lock, &irq_desc_lock_class); |
| 147 | |
| 148 | desc_set_defaults(irq, desc, node); |
| 149 | |
| 150 | return desc; |
| 151 | |
| 152 | err_kstat: |
| 153 | kfree(desc->kstat_irqs); |
| 154 | err_desc: |
| 155 | kfree(desc); |
| 156 | return NULL; |
| 157 | } |
| 158 | |
| 159 | static void free_desc(unsigned int irq) |
| 160 | { |
| 161 | struct irq_desc *desc = irq_to_desc(irq); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 162 | |
Thomas Gleixner | 13bfe99 | 2010-09-30 02:46:07 +0200 | [diff] [blame] | 163 | unregister_irq_proc(irq, desc); |
| 164 | |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 165 | mutex_lock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 166 | delete_irq_desc(irq); |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 167 | mutex_unlock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 168 | |
| 169 | free_masks(desc); |
| 170 | kfree(desc->kstat_irqs); |
| 171 | kfree(desc); |
| 172 | } |
| 173 | |
| 174 | static int alloc_descs(unsigned int start, unsigned int cnt, int node) |
| 175 | { |
| 176 | struct irq_desc *desc; |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 177 | int i; |
| 178 | |
| 179 | for (i = 0; i < cnt; i++) { |
| 180 | desc = alloc_desc(start + i, node); |
| 181 | if (!desc) |
| 182 | goto err; |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 183 | mutex_lock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 184 | irq_insert_desc(start + i, desc); |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 185 | mutex_unlock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 186 | } |
| 187 | return start; |
| 188 | |
| 189 | err: |
| 190 | for (i--; i >= 0; i--) |
| 191 | free_desc(start + i); |
| 192 | |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 193 | mutex_lock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 194 | bitmap_clear(allocated_irqs, start, cnt); |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 195 | mutex_unlock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 196 | return -ENOMEM; |
| 197 | } |
| 198 | |
Thomas Gleixner | aa99ec0 | 2010-09-27 20:02:56 +0200 | [diff] [blame] | 199 | struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) |
| 200 | { |
| 201 | int res = irq_alloc_descs(irq, irq, 1, node); |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 202 | |
Thomas Gleixner | aa99ec0 | 2010-09-27 20:02:56 +0200 | [diff] [blame] | 203 | if (res == -EEXIST || res == irq) |
| 204 | return irq_to_desc(irq); |
| 205 | return NULL; |
| 206 | } |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 207 | |
| 208 | int __init early_irq_init(void) |
| 209 | { |
Thomas Gleixner | b683de2 | 2010-09-27 20:55:03 +0200 | [diff] [blame] | 210 | int i, initcnt, node = first_online_node; |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 211 | struct irq_desc *desc; |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 212 | |
| 213 | init_irq_default_affinity(); |
| 214 | |
Thomas Gleixner | b683de2 | 2010-09-27 20:55:03 +0200 | [diff] [blame] | 215 | /* Let arch update nr_irqs and return the nr of preallocated irqs */ |
| 216 | initcnt = arch_probe_nr_irqs(); |
| 217 | printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d %d\n", NR_IRQS, nr_irqs, initcnt); |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 218 | |
Thomas Gleixner | b683de2 | 2010-09-27 20:55:03 +0200 | [diff] [blame] | 219 | for (i = 0; i < initcnt; i++) { |
Thomas Gleixner | aa99ec0 | 2010-09-27 20:02:56 +0200 | [diff] [blame] | 220 | desc = alloc_desc(i, node); |
| 221 | set_bit(i, allocated_irqs); |
| 222 | irq_insert_desc(i, desc); |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 223 | } |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 224 | return arch_early_irq_init(); |
| 225 | } |
| 226 | |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 227 | #else /* !CONFIG_SPARSE_IRQ */ |
| 228 | |
| 229 | struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { |
| 230 | [0 ... NR_IRQS-1] = { |
Thomas Gleixner | 1318a48 | 2010-09-27 21:01:37 +0200 | [diff] [blame] | 231 | .status = IRQ_DEFAULT_INIT_FLAGS, |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 232 | .handle_irq = handle_bad_irq, |
| 233 | .depth = 1, |
| 234 | .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock), |
| 235 | } |
| 236 | }; |
| 237 | |
| 238 | static unsigned int kstat_irqs_all[NR_IRQS][NR_CPUS]; |
| 239 | int __init early_irq_init(void) |
| 240 | { |
Thomas Gleixner | aa99ec0 | 2010-09-27 20:02:56 +0200 | [diff] [blame] | 241 | int count, i, node = first_online_node; |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 242 | struct irq_desc *desc; |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 243 | |
| 244 | init_irq_default_affinity(); |
| 245 | |
| 246 | printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS); |
| 247 | |
| 248 | desc = irq_desc; |
| 249 | count = ARRAY_SIZE(irq_desc); |
| 250 | |
| 251 | for (i = 0; i < count; i++) { |
| 252 | desc[i].irq_data.irq = i; |
| 253 | desc[i].irq_data.chip = &no_irq_chip; |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 254 | desc[i].kstat_irqs = kstat_irqs_all[i]; |
Thomas Gleixner | aa99ec0 | 2010-09-27 20:02:56 +0200 | [diff] [blame] | 255 | alloc_masks(desc + i, GFP_KERNEL, node); |
| 256 | desc_smp_init(desc + i, node); |
Thomas Gleixner | 154cd38 | 2010-09-22 15:58:45 +0200 | [diff] [blame] | 257 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 258 | } |
| 259 | return arch_early_irq_init(); |
| 260 | } |
| 261 | |
| 262 | struct irq_desc *irq_to_desc(unsigned int irq) |
| 263 | { |
| 264 | return (irq < NR_IRQS) ? irq_desc + irq : NULL; |
| 265 | } |
| 266 | |
| 267 | struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node) |
| 268 | { |
| 269 | return irq_to_desc(irq); |
| 270 | } |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 271 | |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 272 | static void free_desc(unsigned int irq) |
| 273 | { |
Thomas Gleixner | b7b2933 | 2010-09-29 18:46:55 +0200 | [diff] [blame] | 274 | dynamic_irq_cleanup(irq); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static inline int alloc_descs(unsigned int start, unsigned int cnt, int node) |
| 278 | { |
| 279 | return start; |
| 280 | } |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 281 | #endif /* !CONFIG_SPARSE_IRQ */ |
| 282 | |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 283 | /* Dynamic interrupt handling */ |
| 284 | |
| 285 | /** |
| 286 | * irq_free_descs - free irq descriptors |
| 287 | * @from: Start of descriptor range |
| 288 | * @cnt: Number of consecutive irqs to free |
| 289 | */ |
| 290 | void irq_free_descs(unsigned int from, unsigned int cnt) |
| 291 | { |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 292 | int i; |
| 293 | |
| 294 | if (from >= nr_irqs || (from + cnt) > nr_irqs) |
| 295 | return; |
| 296 | |
| 297 | for (i = 0; i < cnt; i++) |
| 298 | free_desc(from + i); |
| 299 | |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 300 | mutex_lock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 301 | bitmap_clear(allocated_irqs, from, cnt); |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 302 | mutex_unlock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /** |
| 306 | * irq_alloc_descs - allocate and initialize a range of irq descriptors |
| 307 | * @irq: Allocate for specific irq number if irq >= 0 |
| 308 | * @from: Start the search from this irq number |
| 309 | * @cnt: Number of consecutive irqs to allocate. |
| 310 | * @node: Preferred node on which the irq descriptor should be allocated |
| 311 | * |
| 312 | * Returns the first irq number or error code |
| 313 | */ |
| 314 | int __ref |
| 315 | irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node) |
| 316 | { |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 317 | int start, ret; |
| 318 | |
| 319 | if (!cnt) |
| 320 | return -EINVAL; |
| 321 | |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 322 | mutex_lock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 323 | |
| 324 | start = bitmap_find_next_zero_area(allocated_irqs, nr_irqs, from, cnt, 0); |
| 325 | ret = -EEXIST; |
| 326 | if (irq >=0 && start != irq) |
| 327 | goto err; |
| 328 | |
| 329 | ret = -ENOMEM; |
| 330 | if (start >= nr_irqs) |
| 331 | goto err; |
| 332 | |
| 333 | bitmap_set(allocated_irqs, start, cnt); |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 334 | mutex_unlock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 335 | return alloc_descs(start, cnt, node); |
| 336 | |
| 337 | err: |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 338 | mutex_unlock(&sparse_irq_lock); |
Thomas Gleixner | 1f5a5b8 | 2010-09-27 17:48:26 +0200 | [diff] [blame] | 339 | return ret; |
| 340 | } |
| 341 | |
Thomas Gleixner | a98d24b | 2010-09-30 10:45:07 +0200 | [diff] [blame] | 342 | /** |
Thomas Gleixner | 06f6c33 | 2010-10-12 12:31:46 +0200 | [diff] [blame] | 343 | * irq_reserve_irqs - mark irqs allocated |
| 344 | * @from: mark from irq number |
| 345 | * @cnt: number of irqs to mark |
| 346 | * |
| 347 | * Returns 0 on success or an appropriate error code |
| 348 | */ |
| 349 | int irq_reserve_irqs(unsigned int from, unsigned int cnt) |
| 350 | { |
Thomas Gleixner | 06f6c33 | 2010-10-12 12:31:46 +0200 | [diff] [blame] | 351 | unsigned int start; |
| 352 | int ret = 0; |
| 353 | |
| 354 | if (!cnt || (from + cnt) > nr_irqs) |
| 355 | return -EINVAL; |
| 356 | |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 357 | mutex_lock(&sparse_irq_lock); |
Thomas Gleixner | 06f6c33 | 2010-10-12 12:31:46 +0200 | [diff] [blame] | 358 | start = bitmap_find_next_zero_area(allocated_irqs, nr_irqs, from, cnt, 0); |
| 359 | if (start == from) |
| 360 | bitmap_set(allocated_irqs, start, cnt); |
| 361 | else |
| 362 | ret = -EEXIST; |
Thomas Gleixner | a05a900 | 2010-10-08 12:47:53 +0200 | [diff] [blame^] | 363 | mutex_unlock(&sparse_irq_lock); |
Thomas Gleixner | 06f6c33 | 2010-10-12 12:31:46 +0200 | [diff] [blame] | 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | /** |
Thomas Gleixner | a98d24b | 2010-09-30 10:45:07 +0200 | [diff] [blame] | 368 | * irq_get_next_irq - get next allocated irq number |
| 369 | * @offset: where to start the search |
| 370 | * |
| 371 | * Returns next irq number after offset or nr_irqs if none is found. |
| 372 | */ |
| 373 | unsigned int irq_get_next_irq(unsigned int offset) |
| 374 | { |
| 375 | return find_next_bit(allocated_irqs, nr_irqs, offset); |
| 376 | } |
| 377 | |
Thomas Gleixner | b7b2933 | 2010-09-29 18:46:55 +0200 | [diff] [blame] | 378 | /** |
| 379 | * dynamic_irq_cleanup - cleanup a dynamically allocated irq |
| 380 | * @irq: irq number to initialize |
| 381 | */ |
| 382 | void dynamic_irq_cleanup(unsigned int irq) |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 383 | { |
Thomas Gleixner | b7b2933 | 2010-09-29 18:46:55 +0200 | [diff] [blame] | 384 | struct irq_desc *desc = irq_to_desc(irq); |
| 385 | unsigned long flags; |
| 386 | |
| 387 | raw_spin_lock_irqsave(&desc->lock, flags); |
| 388 | desc_set_defaults(irq, desc, desc_node(desc)); |
| 389 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Thomas Gleixner | 3795de2 | 2010-09-22 17:09:43 +0200 | [diff] [blame] | 392 | unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) |
| 393 | { |
| 394 | struct irq_desc *desc = irq_to_desc(irq); |
| 395 | return desc ? desc->kstat_irqs[cpu] : 0; |
| 396 | } |