blob: 039b889ea053abf0ac72cd77809490d202ad0121 [file] [log] [blame]
Thomas Gleixner3795de22010-09-22 17:09:43 +02001/*
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 Gleixner1f5a5b82010-09-27 17:48:26 +020016#include <linux/bitmap.h>
Thomas Gleixner3795de22010-09-22 17:09:43 +020017
18#include "internals.h"
19
20/*
21 * lockdep: we want to handle all irq_desc locks as a single lock-class:
22 */
Thomas Gleixner78f90d92010-09-29 17:18:47 +020023static struct lock_class_key irq_desc_lock_class;
Thomas Gleixner3795de22010-09-22 17:09:43 +020024
Thomas Gleixnerfe051432011-05-18 12:53:03 +020025#if defined(CONFIG_SMP)
Thomas Gleixner3795de22010-09-22 17:09:43 +020026static 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
32static void __init init_irq_default_affinity(void)
33{
34}
35#endif
36
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020037#ifdef CONFIG_SMP
38static 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
52static void desc_smp_init(struct irq_desc *desc, int node)
53{
Thomas Gleixneraa99ec02010-09-27 20:02:56 +020054 desc->irq_data.node = node;
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020055 cpumask_copy(desc->irq_data.affinity, irq_default_affinity);
Thomas Gleixnerb7b29332010-09-29 18:46:55 +020056#ifdef CONFIG_GENERIC_PENDING_IRQ
57 cpumask_clear(desc->pending_mask);
58#endif
59}
60
61static inline int desc_node(struct irq_desc *desc)
62{
63 return desc->irq_data.node;
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020064}
65
66#else
67static inline int
68alloc_masks(struct irq_desc *desc, gfp_t gfp, int node) { return 0; }
69static inline void desc_smp_init(struct irq_desc *desc, int node) { }
Thomas Gleixnerb7b29332010-09-29 18:46:55 +020070static inline int desc_node(struct irq_desc *desc) { return 0; }
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020071#endif
72
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +020073static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node,
74 struct module *owner)
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020075{
Eric Dumazet6c9ae002011-01-13 15:45:38 -080076 int cpu;
77
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020078 desc->irq_data.irq = irq;
79 desc->irq_data.chip = &no_irq_chip;
80 desc->irq_data.chip_data = NULL;
81 desc->irq_data.handler_data = NULL;
82 desc->irq_data.msi_desc = NULL;
Thomas Gleixnerf9e49892011-02-09 14:54:49 +010083 irq_settings_clr_and_set(desc, ~0, _IRQ_DEFAULT_INIT_FLAGS);
Thomas Gleixner801a0e92011-03-27 11:02:49 +020084 irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020085 desc->handle_irq = handle_bad_irq;
86 desc->depth = 1;
Thomas Gleixnerb7b29332010-09-29 18:46:55 +020087 desc->irq_count = 0;
88 desc->irqs_unhandled = 0;
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020089 desc->name = NULL;
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +020090 desc->owner = owner;
Eric Dumazet6c9ae002011-01-13 15:45:38 -080091 for_each_possible_cpu(cpu)
92 *per_cpu_ptr(desc->kstat_irqs, cpu) = 0;
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +020093 desc_smp_init(desc, node);
94}
95
Thomas Gleixner3795de22010-09-22 17:09:43 +020096int nr_irqs = NR_IRQS;
97EXPORT_SYMBOL_GPL(nr_irqs);
98
Thomas Gleixnera05a9002010-10-08 12:47:53 +020099static DEFINE_MUTEX(sparse_irq_lock);
Thomas Gleixnerc1ee6262011-02-17 17:45:15 +0100100static DECLARE_BITMAP(allocated_irqs, IRQ_BITMAP_BITS);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200101
Thomas Gleixner3795de22010-09-22 17:09:43 +0200102#ifdef CONFIG_SPARSE_IRQ
103
Thomas Gleixnerbaa0d232010-10-05 15:14:35 +0200104static RADIX_TREE(irq_desc_tree, GFP_KERNEL);
Thomas Gleixner3795de22010-09-22 17:09:43 +0200105
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200106static void irq_insert_desc(unsigned int irq, struct irq_desc *desc)
Thomas Gleixner3795de22010-09-22 17:09:43 +0200107{
108 radix_tree_insert(&irq_desc_tree, irq, desc);
109}
110
111struct irq_desc *irq_to_desc(unsigned int irq)
112{
113 return radix_tree_lookup(&irq_desc_tree, irq);
114}
115
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200116static void delete_irq_desc(unsigned int irq)
117{
118 radix_tree_delete(&irq_desc_tree, irq);
119}
120
121#ifdef CONFIG_SMP
122static void free_masks(struct irq_desc *desc)
123{
124#ifdef CONFIG_GENERIC_PENDING_IRQ
125 free_cpumask_var(desc->pending_mask);
126#endif
Thomas Gleixnerc0a19eb2010-10-12 21:58:27 +0200127 free_cpumask_var(desc->irq_data.affinity);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200128}
129#else
130static inline void free_masks(struct irq_desc *desc) { }
131#endif
132
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200133static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200134{
135 struct irq_desc *desc;
Thomas Gleixnerbaa0d232010-10-05 15:14:35 +0200136 gfp_t gfp = GFP_KERNEL;
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200137
138 desc = kzalloc_node(sizeof(*desc), gfp, node);
139 if (!desc)
140 return NULL;
141 /* allocate based on nr_cpu_ids */
Eric Dumazet6c9ae002011-01-13 15:45:38 -0800142 desc->kstat_irqs = alloc_percpu(unsigned int);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200143 if (!desc->kstat_irqs)
144 goto err_desc;
145
146 if (alloc_masks(desc, gfp, node))
147 goto err_kstat;
148
149 raw_spin_lock_init(&desc->lock);
150 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
151
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200152 desc_set_defaults(irq, desc, node, owner);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200153
154 return desc;
155
156err_kstat:
Eric Dumazet6c9ae002011-01-13 15:45:38 -0800157 free_percpu(desc->kstat_irqs);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200158err_desc:
159 kfree(desc);
160 return NULL;
161}
162
163static void free_desc(unsigned int irq)
164{
165 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200166
Thomas Gleixner13bfe992010-09-30 02:46:07 +0200167 unregister_irq_proc(irq, desc);
168
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200169 mutex_lock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200170 delete_irq_desc(irq);
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200171 mutex_unlock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200172
173 free_masks(desc);
Eric Dumazet6c9ae002011-01-13 15:45:38 -0800174 free_percpu(desc->kstat_irqs);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200175 kfree(desc);
176}
177
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200178static int alloc_descs(unsigned int start, unsigned int cnt, int node,
179 struct module *owner)
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200180{
181 struct irq_desc *desc;
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200182 int i;
183
184 for (i = 0; i < cnt; i++) {
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200185 desc = alloc_desc(start + i, node, owner);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200186 if (!desc)
187 goto err;
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200188 mutex_lock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200189 irq_insert_desc(start + i, desc);
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200190 mutex_unlock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200191 }
192 return start;
193
194err:
195 for (i--; i >= 0; i--)
196 free_desc(start + i);
197
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200198 mutex_lock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200199 bitmap_clear(allocated_irqs, start, cnt);
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200200 mutex_unlock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200201 return -ENOMEM;
202}
203
Yinghai Lued4dea62011-02-19 11:07:37 -0800204static int irq_expand_nr_irqs(unsigned int nr)
Thomas Gleixnere7bcecb2011-02-16 17:12:57 +0100205{
Yinghai Lued4dea62011-02-19 11:07:37 -0800206 if (nr > IRQ_BITMAP_BITS)
Thomas Gleixnere7bcecb2011-02-16 17:12:57 +0100207 return -ENOMEM;
Yinghai Lued4dea62011-02-19 11:07:37 -0800208 nr_irqs = nr;
Thomas Gleixnere7bcecb2011-02-16 17:12:57 +0100209 return 0;
210}
211
Thomas Gleixner3795de22010-09-22 17:09:43 +0200212int __init early_irq_init(void)
213{
Thomas Gleixnerb683de22010-09-27 20:55:03 +0200214 int i, initcnt, node = first_online_node;
Thomas Gleixner3795de22010-09-22 17:09:43 +0200215 struct irq_desc *desc;
Thomas Gleixner3795de22010-09-22 17:09:43 +0200216
217 init_irq_default_affinity();
218
Thomas Gleixnerb683de22010-09-27 20:55:03 +0200219 /* Let arch update nr_irqs and return the nr of preallocated irqs */
220 initcnt = arch_probe_nr_irqs();
221 printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d %d\n", NR_IRQS, nr_irqs, initcnt);
Thomas Gleixner3795de22010-09-22 17:09:43 +0200222
Thomas Gleixnerc1ee6262011-02-17 17:45:15 +0100223 if (WARN_ON(nr_irqs > IRQ_BITMAP_BITS))
224 nr_irqs = IRQ_BITMAP_BITS;
225
226 if (WARN_ON(initcnt > IRQ_BITMAP_BITS))
227 initcnt = IRQ_BITMAP_BITS;
228
229 if (initcnt > nr_irqs)
230 nr_irqs = initcnt;
231
Thomas Gleixnerb683de22010-09-27 20:55:03 +0200232 for (i = 0; i < initcnt; i++) {
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200233 desc = alloc_desc(i, node, NULL);
Thomas Gleixneraa99ec02010-09-27 20:02:56 +0200234 set_bit(i, allocated_irqs);
235 irq_insert_desc(i, desc);
Thomas Gleixner3795de22010-09-22 17:09:43 +0200236 }
Thomas Gleixner3795de22010-09-22 17:09:43 +0200237 return arch_early_irq_init();
238}
239
Thomas Gleixner3795de22010-09-22 17:09:43 +0200240#else /* !CONFIG_SPARSE_IRQ */
241
242struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
243 [0 ... NR_IRQS-1] = {
Thomas Gleixner3795de22010-09-22 17:09:43 +0200244 .handle_irq = handle_bad_irq,
245 .depth = 1,
246 .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock),
247 }
248};
249
Thomas Gleixner3795de22010-09-22 17:09:43 +0200250int __init early_irq_init(void)
251{
Thomas Gleixneraa99ec02010-09-27 20:02:56 +0200252 int count, i, node = first_online_node;
Thomas Gleixner3795de22010-09-22 17:09:43 +0200253 struct irq_desc *desc;
Thomas Gleixner3795de22010-09-22 17:09:43 +0200254
255 init_irq_default_affinity();
256
257 printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
258
259 desc = irq_desc;
260 count = ARRAY_SIZE(irq_desc);
261
262 for (i = 0; i < count; i++) {
Eric Dumazet6c9ae002011-01-13 15:45:38 -0800263 desc[i].kstat_irqs = alloc_percpu(unsigned int);
Linus Walleije7fbad32011-05-31 18:14:39 +0200264 alloc_masks(&desc[i], GFP_KERNEL, node);
265 raw_spin_lock_init(&desc[i].lock);
Thomas Gleixner154cd382010-09-22 15:58:45 +0200266 lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200267 desc_set_defaults(i, &desc[i], node, NULL);
Thomas Gleixner3795de22010-09-22 17:09:43 +0200268 }
269 return arch_early_irq_init();
270}
271
272struct irq_desc *irq_to_desc(unsigned int irq)
273{
274 return (irq < NR_IRQS) ? irq_desc + irq : NULL;
275}
276
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200277static void free_desc(unsigned int irq)
278{
Thomas Gleixnerb7b29332010-09-29 18:46:55 +0200279 dynamic_irq_cleanup(irq);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200280}
281
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200282static inline int alloc_descs(unsigned int start, unsigned int cnt, int node,
283 struct module *owner)
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200284{
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200285 u32 i;
286
287 for (i = 0; i < cnt; i++) {
288 struct irq_desc *desc = irq_to_desc(start + i);
289
290 desc->owner = owner;
291 }
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200292 return start;
293}
Thomas Gleixnere7bcecb2011-02-16 17:12:57 +0100294
Yinghai Lued4dea62011-02-19 11:07:37 -0800295static int irq_expand_nr_irqs(unsigned int nr)
Thomas Gleixnere7bcecb2011-02-16 17:12:57 +0100296{
297 return -ENOMEM;
298}
299
Thomas Gleixner3795de22010-09-22 17:09:43 +0200300#endif /* !CONFIG_SPARSE_IRQ */
301
Thomas Gleixnerfe12bc22011-05-18 12:48:00 +0200302/**
303 * generic_handle_irq - Invoke the handler for a particular irq
304 * @irq: The irq number to handle
305 *
306 */
307int generic_handle_irq(unsigned int irq)
308{
309 struct irq_desc *desc = irq_to_desc(irq);
310
311 if (!desc)
312 return -EINVAL;
313 generic_handle_irq_desc(irq, desc);
314 return 0;
315}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100316EXPORT_SYMBOL_GPL(generic_handle_irq);
Thomas Gleixnerfe12bc22011-05-18 12:48:00 +0200317
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200318/* Dynamic interrupt handling */
319
320/**
321 * irq_free_descs - free irq descriptors
322 * @from: Start of descriptor range
323 * @cnt: Number of consecutive irqs to free
324 */
325void irq_free_descs(unsigned int from, unsigned int cnt)
326{
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200327 int i;
328
329 if (from >= nr_irqs || (from + cnt) > nr_irqs)
330 return;
331
332 for (i = 0; i < cnt; i++)
333 free_desc(from + i);
334
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200335 mutex_lock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200336 bitmap_clear(allocated_irqs, from, cnt);
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200337 mutex_unlock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200338}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100339EXPORT_SYMBOL_GPL(irq_free_descs);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200340
341/**
342 * irq_alloc_descs - allocate and initialize a range of irq descriptors
343 * @irq: Allocate for specific irq number if irq >= 0
344 * @from: Start the search from this irq number
345 * @cnt: Number of consecutive irqs to allocate.
346 * @node: Preferred node on which the irq descriptor should be allocated
Randy Dunlapd522a0d2011-08-18 12:19:27 -0700347 * @owner: Owning module (can be NULL)
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200348 *
349 * Returns the first irq number or error code
350 */
351int __ref
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200352__irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
353 struct module *owner)
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200354{
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200355 int start, ret;
356
357 if (!cnt)
358 return -EINVAL;
359
Mark Brownc5182b82011-06-02 18:55:13 +0100360 if (irq >= 0) {
361 if (from > irq)
362 return -EINVAL;
363 from = irq;
364 }
365
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200366 mutex_lock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200367
Yinghai Lued4dea62011-02-19 11:07:37 -0800368 start = bitmap_find_next_zero_area(allocated_irqs, IRQ_BITMAP_BITS,
369 from, cnt, 0);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200370 ret = -EEXIST;
371 if (irq >=0 && start != irq)
372 goto err;
373
Yinghai Lued4dea62011-02-19 11:07:37 -0800374 if (start + cnt > nr_irqs) {
375 ret = irq_expand_nr_irqs(start + cnt);
Thomas Gleixnere7bcecb2011-02-16 17:12:57 +0100376 if (ret)
377 goto err;
378 }
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200379
380 bitmap_set(allocated_irqs, start, cnt);
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200381 mutex_unlock(&sparse_irq_lock);
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200382 return alloc_descs(start, cnt, node, owner);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200383
384err:
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200385 mutex_unlock(&sparse_irq_lock);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200386 return ret;
387}
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200388EXPORT_SYMBOL_GPL(__irq_alloc_descs);
Thomas Gleixner1f5a5b82010-09-27 17:48:26 +0200389
Thomas Gleixnera98d24b2010-09-30 10:45:07 +0200390/**
Thomas Gleixner06f6c332010-10-12 12:31:46 +0200391 * irq_reserve_irqs - mark irqs allocated
392 * @from: mark from irq number
393 * @cnt: number of irqs to mark
394 *
395 * Returns 0 on success or an appropriate error code
396 */
397int irq_reserve_irqs(unsigned int from, unsigned int cnt)
398{
Thomas Gleixner06f6c332010-10-12 12:31:46 +0200399 unsigned int start;
400 int ret = 0;
401
402 if (!cnt || (from + cnt) > nr_irqs)
403 return -EINVAL;
404
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200405 mutex_lock(&sparse_irq_lock);
Thomas Gleixner06f6c332010-10-12 12:31:46 +0200406 start = bitmap_find_next_zero_area(allocated_irqs, nr_irqs, from, cnt, 0);
407 if (start == from)
408 bitmap_set(allocated_irqs, start, cnt);
409 else
410 ret = -EEXIST;
Thomas Gleixnera05a9002010-10-08 12:47:53 +0200411 mutex_unlock(&sparse_irq_lock);
Thomas Gleixner06f6c332010-10-12 12:31:46 +0200412 return ret;
413}
414
415/**
Thomas Gleixnera98d24b2010-09-30 10:45:07 +0200416 * irq_get_next_irq - get next allocated irq number
417 * @offset: where to start the search
418 *
419 * Returns next irq number after offset or nr_irqs if none is found.
420 */
421unsigned int irq_get_next_irq(unsigned int offset)
422{
423 return find_next_bit(allocated_irqs, nr_irqs, offset);
424}
425
Thomas Gleixnerd5eb4ad22011-02-12 12:16:16 +0100426struct irq_desc *
427__irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus)
428{
429 struct irq_desc *desc = irq_to_desc(irq);
430
431 if (desc) {
432 if (bus)
433 chip_bus_lock(desc);
434 raw_spin_lock_irqsave(&desc->lock, *flags);
435 }
436 return desc;
437}
438
439void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus)
440{
441 raw_spin_unlock_irqrestore(&desc->lock, flags);
442 if (bus)
443 chip_bus_sync_unlock(desc);
444}
445
Thomas Gleixnerb7b29332010-09-29 18:46:55 +0200446/**
447 * dynamic_irq_cleanup - cleanup a dynamically allocated irq
448 * @irq: irq number to initialize
449 */
450void dynamic_irq_cleanup(unsigned int irq)
Thomas Gleixner3795de22010-09-22 17:09:43 +0200451{
Thomas Gleixnerb7b29332010-09-29 18:46:55 +0200452 struct irq_desc *desc = irq_to_desc(irq);
453 unsigned long flags;
454
455 raw_spin_lock_irqsave(&desc->lock, flags);
Sebastian Andrzej Siewiorb6873802011-07-11 12:17:31 +0200456 desc_set_defaults(irq, desc, desc_node(desc), NULL);
Thomas Gleixnerb7b29332010-09-29 18:46:55 +0200457 raw_spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixner3795de22010-09-22 17:09:43 +0200458}
459
Thomas Gleixner3795de22010-09-22 17:09:43 +0200460unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
461{
462 struct irq_desc *desc = irq_to_desc(irq);
Eric Dumazet6c9ae002011-01-13 15:45:38 -0800463
464 return desc && desc->kstat_irqs ?
465 *per_cpu_ptr(desc->kstat_irqs, cpu) : 0;
Thomas Gleixner3795de22010-09-22 17:09:43 +0200466}
KAMEZAWA Hiroyuki478735e32010-10-27 15:34:15 -0700467
KAMEZAWA Hiroyuki478735e32010-10-27 15:34:15 -0700468unsigned int kstat_irqs(unsigned int irq)
469{
470 struct irq_desc *desc = irq_to_desc(irq);
471 int cpu;
472 int sum = 0;
473
Eric Dumazet6c9ae002011-01-13 15:45:38 -0800474 if (!desc || !desc->kstat_irqs)
KAMEZAWA Hiroyuki478735e32010-10-27 15:34:15 -0700475 return 0;
476 for_each_possible_cpu(cpu)
Eric Dumazet6c9ae002011-01-13 15:45:38 -0800477 sum += *per_cpu_ptr(desc->kstat_irqs, cpu);
KAMEZAWA Hiroyuki478735e32010-10-27 15:34:15 -0700478 return sum;
479}