2 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
3 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
5 * This file contains the interrupt descriptor management code
7 * Detailed information is available in Documentation/DocBook/genericirq
10 #include <linux/irq.h>
11 #include <linux/slab.h>
12 #include <linux/export.h>
13 #include <linux/interrupt.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/radix-tree.h>
16 #include <linux/bitmap.h>
17 #include <linux/irqdomain.h>
18 #include <linux/sysfs.h>
20 #include "internals.h"
23 * lockdep: we want to handle all irq_desc locks as a single lock-class:
25 static struct lock_class_key irq_desc_lock_class
;
27 #if defined(CONFIG_SMP)
28 static int __init
irq_affinity_setup(char *str
)
30 zalloc_cpumask_var(&irq_default_affinity
, GFP_NOWAIT
);
31 cpulist_parse(str
, irq_default_affinity
);
33 * Set at least the boot cpu. We don't want to end up with
34 * bugreports caused by random comandline masks
36 cpumask_set_cpu(smp_processor_id(), irq_default_affinity
);
39 __setup("irqaffinity=", irq_affinity_setup
);
41 static void __init
init_irq_default_affinity(void)
43 #ifdef CONFIG_CPUMASK_OFFSTACK
44 if (!irq_default_affinity
)
45 zalloc_cpumask_var(&irq_default_affinity
, GFP_NOWAIT
);
47 if (cpumask_empty(irq_default_affinity
))
48 cpumask_setall(irq_default_affinity
);
51 static void __init
init_irq_default_affinity(void)
57 static int alloc_masks(struct irq_desc
*desc
, gfp_t gfp
, int node
)
59 if (!zalloc_cpumask_var_node(&desc
->irq_common_data
.affinity
,
63 #ifdef CONFIG_GENERIC_PENDING_IRQ
64 if (!zalloc_cpumask_var_node(&desc
->pending_mask
, gfp
, node
)) {
65 free_cpumask_var(desc
->irq_common_data
.affinity
);
72 static void desc_smp_init(struct irq_desc
*desc
, int node
,
73 const struct cpumask
*affinity
)
76 affinity
= irq_default_affinity
;
77 cpumask_copy(desc
->irq_common_data
.affinity
, affinity
);
79 #ifdef CONFIG_GENERIC_PENDING_IRQ
80 cpumask_clear(desc
->pending_mask
);
83 desc
->irq_common_data
.node
= node
;
89 alloc_masks(struct irq_desc
*desc
, gfp_t gfp
, int node
) { return 0; }
91 desc_smp_init(struct irq_desc
*desc
, int node
, const struct cpumask
*affinity
) { }
94 static void desc_set_defaults(unsigned int irq
, struct irq_desc
*desc
, int node
,
95 const struct cpumask
*affinity
, struct module
*owner
)
99 desc
->irq_common_data
.handler_data
= NULL
;
100 desc
->irq_common_data
.msi_desc
= NULL
;
102 desc
->irq_data
.common
= &desc
->irq_common_data
;
103 desc
->irq_data
.irq
= irq
;
104 desc
->irq_data
.chip
= &no_irq_chip
;
105 desc
->irq_data
.chip_data
= NULL
;
106 irq_settings_clr_and_set(desc
, ~0, _IRQ_DEFAULT_INIT_FLAGS
);
107 irqd_set(&desc
->irq_data
, IRQD_IRQ_DISABLED
);
108 desc
->handle_irq
= handle_bad_irq
;
111 desc
->irqs_unhandled
= 0;
115 for_each_possible_cpu(cpu
)
116 *per_cpu_ptr(desc
->kstat_irqs
, cpu
) = 0;
117 desc_smp_init(desc
, node
, affinity
);
120 int nr_irqs
= NR_IRQS
;
121 EXPORT_SYMBOL_GPL(nr_irqs
);
123 static DEFINE_MUTEX(sparse_irq_lock
);
124 static DECLARE_BITMAP(allocated_irqs
, IRQ_BITMAP_BITS
);
126 #ifdef CONFIG_SPARSE_IRQ
128 static void irq_kobj_release(struct kobject
*kobj
);
131 static struct kobject
*irq_kobj_base
;
133 #define IRQ_ATTR_RO(_name) \
134 static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
136 static ssize_t
per_cpu_count_show(struct kobject
*kobj
,
137 struct kobj_attribute
*attr
, char *buf
)
139 struct irq_desc
*desc
= container_of(kobj
, struct irq_desc
, kobj
);
140 int cpu
, irq
= desc
->irq_data
.irq
;
144 for_each_possible_cpu(cpu
) {
145 unsigned int c
= kstat_irqs_cpu(irq
, cpu
);
147 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s%u", p
, c
);
151 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
154 IRQ_ATTR_RO(per_cpu_count
);
156 static ssize_t
chip_name_show(struct kobject
*kobj
,
157 struct kobj_attribute
*attr
, char *buf
)
159 struct irq_desc
*desc
= container_of(kobj
, struct irq_desc
, kobj
);
162 raw_spin_lock_irq(&desc
->lock
);
163 if (desc
->irq_data
.chip
&& desc
->irq_data
.chip
->name
) {
164 ret
= scnprintf(buf
, PAGE_SIZE
, "%s\n",
165 desc
->irq_data
.chip
->name
);
167 raw_spin_unlock_irq(&desc
->lock
);
171 IRQ_ATTR_RO(chip_name
);
173 static ssize_t
hwirq_show(struct kobject
*kobj
,
174 struct kobj_attribute
*attr
, char *buf
)
176 struct irq_desc
*desc
= container_of(kobj
, struct irq_desc
, kobj
);
179 raw_spin_lock_irq(&desc
->lock
);
180 if (desc
->irq_data
.domain
)
181 ret
= sprintf(buf
, "%d\n", (int)desc
->irq_data
.hwirq
);
182 raw_spin_unlock_irq(&desc
->lock
);
188 static ssize_t
type_show(struct kobject
*kobj
,
189 struct kobj_attribute
*attr
, char *buf
)
191 struct irq_desc
*desc
= container_of(kobj
, struct irq_desc
, kobj
);
194 raw_spin_lock_irq(&desc
->lock
);
195 ret
= sprintf(buf
, "%s\n",
196 irqd_is_level_type(&desc
->irq_data
) ? "level" : "edge");
197 raw_spin_unlock_irq(&desc
->lock
);
204 static ssize_t
name_show(struct kobject
*kobj
,
205 struct kobj_attribute
*attr
, char *buf
)
207 struct irq_desc
*desc
= container_of(kobj
, struct irq_desc
, kobj
);
210 raw_spin_lock_irq(&desc
->lock
);
212 ret
= scnprintf(buf
, PAGE_SIZE
, "%s\n", desc
->name
);
213 raw_spin_unlock_irq(&desc
->lock
);
219 static ssize_t
actions_show(struct kobject
*kobj
,
220 struct kobj_attribute
*attr
, char *buf
)
222 struct irq_desc
*desc
= container_of(kobj
, struct irq_desc
, kobj
);
223 struct irqaction
*action
;
227 raw_spin_lock_irq(&desc
->lock
);
228 for (action
= desc
->action
; action
!= NULL
; action
= action
->next
) {
229 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s%s",
233 raw_spin_unlock_irq(&desc
->lock
);
236 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
, "\n");
240 IRQ_ATTR_RO(actions
);
242 static struct attribute
*irq_attrs
[] = {
243 &per_cpu_count_attr
.attr
,
244 &chip_name_attr
.attr
,
252 static struct kobj_type irq_kobj_type
= {
253 .release
= irq_kobj_release
,
254 .sysfs_ops
= &kobj_sysfs_ops
,
255 .default_attrs
= irq_attrs
,
258 static void irq_sysfs_add(int irq
, struct irq_desc
*desc
)
262 * Continue even in case of failure as this is nothing
265 if (kobject_add(&desc
->kobj
, irq_kobj_base
, "%d", irq
))
266 pr_warn("Failed to add kobject for irq %d\n", irq
);
270 static void irq_sysfs_del(struct irq_desc
*desc
)
273 * If irq_sysfs_init() has not yet been invoked (early boot), then
274 * irq_kobj_base is NULL and the descriptor was never added.
275 * kobject_del() complains about a object with no parent, so make
279 kobject_del(&desc
->kobj
);
282 static int __init
irq_sysfs_init(void)
284 struct irq_desc
*desc
;
287 /* Prevent concurrent irq alloc/free */
290 irq_kobj_base
= kobject_create_and_add("irq", kernel_kobj
);
291 if (!irq_kobj_base
) {
296 /* Add the already allocated interrupts */
297 for_each_irq_desc(irq
, desc
)
298 irq_sysfs_add(irq
, desc
);
303 postcore_initcall(irq_sysfs_init
);
305 #else /* !CONFIG_SYSFS */
307 static struct kobj_type irq_kobj_type
= {
308 .release
= irq_kobj_release
,
311 static void irq_sysfs_add(int irq
, struct irq_desc
*desc
) {}
312 static void irq_sysfs_del(struct irq_desc
*desc
) {}
314 #endif /* CONFIG_SYSFS */
316 static RADIX_TREE(irq_desc_tree
, GFP_KERNEL
);
318 static void irq_insert_desc(unsigned int irq
, struct irq_desc
*desc
)
320 radix_tree_insert(&irq_desc_tree
, irq
, desc
);
323 struct irq_desc
*irq_to_desc(unsigned int irq
)
325 return radix_tree_lookup(&irq_desc_tree
, irq
);
327 EXPORT_SYMBOL(irq_to_desc
);
329 static void delete_irq_desc(unsigned int irq
)
331 radix_tree_delete(&irq_desc_tree
, irq
);
335 static void free_masks(struct irq_desc
*desc
)
337 #ifdef CONFIG_GENERIC_PENDING_IRQ
338 free_cpumask_var(desc
->pending_mask
);
340 free_cpumask_var(desc
->irq_common_data
.affinity
);
343 static inline void free_masks(struct irq_desc
*desc
) { }
346 void irq_lock_sparse(void)
348 mutex_lock(&sparse_irq_lock
);
351 void irq_unlock_sparse(void)
353 mutex_unlock(&sparse_irq_lock
);
356 static struct irq_desc
*alloc_desc(int irq
, int node
, unsigned int flags
,
357 const struct cpumask
*affinity
,
358 struct module
*owner
)
360 struct irq_desc
*desc
;
361 gfp_t gfp
= GFP_KERNEL
;
363 desc
= kzalloc_node(sizeof(*desc
), gfp
, node
);
366 /* allocate based on nr_cpu_ids */
367 desc
->kstat_irqs
= alloc_percpu(unsigned int);
368 if (!desc
->kstat_irqs
)
371 if (alloc_masks(desc
, gfp
, node
))
374 raw_spin_lock_init(&desc
->lock
);
375 lockdep_set_class(&desc
->lock
, &irq_desc_lock_class
);
376 init_rcu_head(&desc
->rcu
);
378 desc_set_defaults(irq
, desc
, node
, affinity
, owner
);
379 irqd_set(&desc
->irq_data
, flags
);
380 kobject_init(&desc
->kobj
, &irq_kobj_type
);
385 free_percpu(desc
->kstat_irqs
);
391 static void irq_kobj_release(struct kobject
*kobj
)
393 struct irq_desc
*desc
= container_of(kobj
, struct irq_desc
, kobj
);
396 free_percpu(desc
->kstat_irqs
);
400 static void delayed_free_desc(struct rcu_head
*rhp
)
402 struct irq_desc
*desc
= container_of(rhp
, struct irq_desc
, rcu
);
404 kobject_put(&desc
->kobj
);
407 static void free_desc(unsigned int irq
)
409 struct irq_desc
*desc
= irq_to_desc(irq
);
411 unregister_irq_proc(irq
, desc
);
414 * sparse_irq_lock protects also show_interrupts() and
415 * kstat_irq_usr(). Once we deleted the descriptor from the
416 * sparse tree we can free it. Access in proc will fail to
417 * lookup the descriptor.
419 * The sysfs entry must be serialized against a concurrent
420 * irq_sysfs_init() as well.
423 delete_irq_desc(irq
);
426 * We free the descriptor, masks and stat fields via RCU. That
427 * allows demultiplex interrupts to do rcu based management of
428 * the child interrupts.
430 call_rcu(&desc
->rcu
, delayed_free_desc
);
433 static int alloc_descs(unsigned int start
, unsigned int cnt
, int node
,
434 const struct cpumask
*affinity
, struct module
*owner
)
436 const struct cpumask
*mask
= NULL
;
437 struct irq_desc
*desc
;
441 /* Validate affinity mask(s) */
443 for (i
= 0, mask
= affinity
; i
< cnt
; i
++, mask
++) {
444 if (cpumask_empty(mask
))
449 flags
= affinity
? IRQD_AFFINITY_MANAGED
: 0;
452 for (i
= 0; i
< cnt
; i
++) {
454 node
= cpu_to_node(cpumask_first(affinity
));
458 desc
= alloc_desc(start
+ i
, node
, flags
, mask
, owner
);
461 irq_insert_desc(start
+ i
, desc
);
462 irq_sysfs_add(start
+ i
, desc
);
464 bitmap_set(allocated_irqs
, start
, cnt
);
468 for (i
--; i
>= 0; i
--)
469 free_desc(start
+ i
);
473 static int irq_expand_nr_irqs(unsigned int nr
)
475 if (nr
> IRQ_BITMAP_BITS
)
481 int __init
early_irq_init(void)
483 int i
, initcnt
, node
= first_online_node
;
484 struct irq_desc
*desc
;
486 init_irq_default_affinity();
488 /* Let arch update nr_irqs and return the nr of preallocated irqs */
489 initcnt
= arch_probe_nr_irqs();
490 printk(KERN_INFO
"NR_IRQS:%d nr_irqs:%d %d\n", NR_IRQS
, nr_irqs
, initcnt
);
492 if (WARN_ON(nr_irqs
> IRQ_BITMAP_BITS
))
493 nr_irqs
= IRQ_BITMAP_BITS
;
495 if (WARN_ON(initcnt
> IRQ_BITMAP_BITS
))
496 initcnt
= IRQ_BITMAP_BITS
;
498 if (initcnt
> nr_irqs
)
501 for (i
= 0; i
< initcnt
; i
++) {
502 desc
= alloc_desc(i
, node
, 0, NULL
, NULL
);
503 set_bit(i
, allocated_irqs
);
504 irq_insert_desc(i
, desc
);
506 return arch_early_irq_init();
509 #else /* !CONFIG_SPARSE_IRQ */
511 struct irq_desc irq_desc
[NR_IRQS
] __cacheline_aligned_in_smp
= {
512 [0 ... NR_IRQS
-1] = {
513 .handle_irq
= handle_bad_irq
,
515 .lock
= __RAW_SPIN_LOCK_UNLOCKED(irq_desc
->lock
),
519 int __init
early_irq_init(void)
521 int count
, i
, node
= first_online_node
;
522 struct irq_desc
*desc
;
524 init_irq_default_affinity();
526 printk(KERN_INFO
"NR_IRQS:%d\n", NR_IRQS
);
529 count
= ARRAY_SIZE(irq_desc
);
531 for (i
= 0; i
< count
; i
++) {
532 desc
[i
].kstat_irqs
= alloc_percpu(unsigned int);
533 alloc_masks(&desc
[i
], GFP_KERNEL
, node
);
534 raw_spin_lock_init(&desc
[i
].lock
);
535 lockdep_set_class(&desc
[i
].lock
, &irq_desc_lock_class
);
536 desc_set_defaults(i
, &desc
[i
], node
, NULL
, NULL
);
538 return arch_early_irq_init();
541 struct irq_desc
*irq_to_desc(unsigned int irq
)
543 return (irq
< NR_IRQS
) ? irq_desc
+ irq
: NULL
;
545 EXPORT_SYMBOL(irq_to_desc
);
547 static void free_desc(unsigned int irq
)
549 struct irq_desc
*desc
= irq_to_desc(irq
);
552 raw_spin_lock_irqsave(&desc
->lock
, flags
);
553 desc_set_defaults(irq
, desc
, irq_desc_get_node(desc
), NULL
, NULL
);
554 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
557 static inline int alloc_descs(unsigned int start
, unsigned int cnt
, int node
,
558 const struct cpumask
*affinity
,
559 struct module
*owner
)
563 for (i
= 0; i
< cnt
; i
++) {
564 struct irq_desc
*desc
= irq_to_desc(start
+ i
);
568 bitmap_set(allocated_irqs
, start
, cnt
);
572 static int irq_expand_nr_irqs(unsigned int nr
)
577 void irq_mark_irq(unsigned int irq
)
579 mutex_lock(&sparse_irq_lock
);
580 bitmap_set(allocated_irqs
, irq
, 1);
581 mutex_unlock(&sparse_irq_lock
);
584 #ifdef CONFIG_GENERIC_IRQ_LEGACY
585 void irq_init_desc(unsigned int irq
)
591 #endif /* !CONFIG_SPARSE_IRQ */
594 * generic_handle_irq - Invoke the handler for a particular irq
595 * @irq: The irq number to handle
598 int generic_handle_irq(unsigned int irq
)
600 struct irq_desc
*desc
= irq_to_desc(irq
);
604 generic_handle_irq_desc(desc
);
607 EXPORT_SYMBOL_GPL(generic_handle_irq
);
609 #ifdef CONFIG_HANDLE_DOMAIN_IRQ
611 * __handle_domain_irq - Invoke the handler for a HW irq belonging to a domain
612 * @domain: The domain where to perform the lookup
613 * @hwirq: The HW irq number to convert to a logical one
614 * @lookup: Whether to perform the domain lookup or not
615 * @regs: Register file coming from the low-level handling code
617 * Returns: 0 on success, or -EINVAL if conversion has failed
619 int __handle_domain_irq(struct irq_domain
*domain
, unsigned int hwirq
,
620 bool lookup
, struct pt_regs
*regs
)
622 struct pt_regs
*old_regs
= set_irq_regs(regs
);
623 unsigned int irq
= hwirq
;
628 #ifdef CONFIG_IRQ_DOMAIN
630 irq
= irq_find_mapping(domain
, hwirq
);
634 * Some hardware gives randomly wrong interrupts. Rather
635 * than crashing, do something sensible.
637 if (unlikely(!irq
|| irq
>= nr_irqs
)) {
641 generic_handle_irq(irq
);
645 set_irq_regs(old_regs
);
650 /* Dynamic interrupt handling */
653 * irq_free_descs - free irq descriptors
654 * @from: Start of descriptor range
655 * @cnt: Number of consecutive irqs to free
657 void irq_free_descs(unsigned int from
, unsigned int cnt
)
661 if (from
>= nr_irqs
|| (from
+ cnt
) > nr_irqs
)
664 mutex_lock(&sparse_irq_lock
);
665 for (i
= 0; i
< cnt
; i
++)
668 bitmap_clear(allocated_irqs
, from
, cnt
);
669 mutex_unlock(&sparse_irq_lock
);
671 EXPORT_SYMBOL_GPL(irq_free_descs
);
674 * irq_alloc_descs - allocate and initialize a range of irq descriptors
675 * @irq: Allocate for specific irq number if irq >= 0
676 * @from: Start the search from this irq number
677 * @cnt: Number of consecutive irqs to allocate.
678 * @node: Preferred node on which the irq descriptor should be allocated
679 * @owner: Owning module (can be NULL)
680 * @affinity: Optional pointer to an affinity mask array of size @cnt which
681 * hints where the irq descriptors should be allocated and which
682 * default affinities to use
684 * Returns the first irq number or error code
687 __irq_alloc_descs(int irq
, unsigned int from
, unsigned int cnt
, int node
,
688 struct module
*owner
, const struct cpumask
*affinity
)
701 * For interrupts which are freely allocated the
702 * architecture can force a lower bound to the @from
703 * argument. x86 uses this to exclude the GSI space.
705 from
= arch_dynirq_lower_bound(from
);
708 mutex_lock(&sparse_irq_lock
);
710 start
= bitmap_find_next_zero_area(allocated_irqs
, IRQ_BITMAP_BITS
,
713 if (irq
>=0 && start
!= irq
)
716 if (start
+ cnt
> nr_irqs
) {
717 ret
= irq_expand_nr_irqs(start
+ cnt
);
721 ret
= alloc_descs(start
, cnt
, node
, affinity
, owner
);
723 mutex_unlock(&sparse_irq_lock
);
726 EXPORT_SYMBOL_GPL(__irq_alloc_descs
);
728 #ifdef CONFIG_GENERIC_IRQ_LEGACY_ALLOC_HWIRQ
730 * irq_alloc_hwirqs - Allocate an irq descriptor and initialize the hardware
731 * @cnt: number of interrupts to allocate
732 * @node: node on which to allocate
734 * Returns an interrupt number > 0 or 0, if the allocation fails.
736 unsigned int irq_alloc_hwirqs(int cnt
, int node
)
738 int i
, irq
= __irq_alloc_descs(-1, 0, cnt
, node
, NULL
, NULL
);
743 for (i
= irq
; cnt
> 0; i
++, cnt
--) {
744 if (arch_setup_hwirq(i
, node
))
746 irq_clear_status_flags(i
, _IRQ_NOREQUEST
);
751 for (i
--; i
>= irq
; i
--) {
752 irq_set_status_flags(i
, _IRQ_NOREQUEST
| _IRQ_NOPROBE
);
753 arch_teardown_hwirq(i
);
755 irq_free_descs(irq
, cnt
);
758 EXPORT_SYMBOL_GPL(irq_alloc_hwirqs
);
761 * irq_free_hwirqs - Free irq descriptor and cleanup the hardware
762 * @from: Free from irq number
763 * @cnt: number of interrupts to free
766 void irq_free_hwirqs(unsigned int from
, int cnt
)
770 for (i
= from
, j
= cnt
; j
> 0; i
++, j
--) {
771 irq_set_status_flags(i
, _IRQ_NOREQUEST
| _IRQ_NOPROBE
);
772 arch_teardown_hwirq(i
);
774 irq_free_descs(from
, cnt
);
776 EXPORT_SYMBOL_GPL(irq_free_hwirqs
);
780 * irq_get_next_irq - get next allocated irq number
781 * @offset: where to start the search
783 * Returns next irq number after offset or nr_irqs if none is found.
785 unsigned int irq_get_next_irq(unsigned int offset
)
787 return find_next_bit(allocated_irqs
, nr_irqs
, offset
);
791 __irq_get_desc_lock(unsigned int irq
, unsigned long *flags
, bool bus
,
794 struct irq_desc
*desc
= irq_to_desc(irq
);
797 if (check
& _IRQ_DESC_CHECK
) {
798 if ((check
& _IRQ_DESC_PERCPU
) &&
799 !irq_settings_is_per_cpu_devid(desc
))
802 if (!(check
& _IRQ_DESC_PERCPU
) &&
803 irq_settings_is_per_cpu_devid(desc
))
809 raw_spin_lock_irqsave(&desc
->lock
, *flags
);
814 void __irq_put_desc_unlock(struct irq_desc
*desc
, unsigned long flags
, bool bus
)
816 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
818 chip_bus_sync_unlock(desc
);
821 int irq_set_percpu_devid_partition(unsigned int irq
,
822 const struct cpumask
*affinity
)
824 struct irq_desc
*desc
= irq_to_desc(irq
);
829 if (desc
->percpu_enabled
)
832 desc
->percpu_enabled
= kzalloc(sizeof(*desc
->percpu_enabled
), GFP_KERNEL
);
834 if (!desc
->percpu_enabled
)
838 desc
->percpu_affinity
= affinity
;
840 desc
->percpu_affinity
= cpu_possible_mask
;
842 irq_set_percpu_devid_flags(irq
);
846 int irq_set_percpu_devid(unsigned int irq
)
848 return irq_set_percpu_devid_partition(irq
, NULL
);
851 int irq_get_percpu_devid_partition(unsigned int irq
, struct cpumask
*affinity
)
853 struct irq_desc
*desc
= irq_to_desc(irq
);
855 if (!desc
|| !desc
->percpu_enabled
)
859 cpumask_copy(affinity
, desc
->percpu_affinity
);
864 void kstat_incr_irq_this_cpu(unsigned int irq
)
866 kstat_incr_irqs_this_cpu(irq_to_desc(irq
));
870 * kstat_irqs_cpu - Get the statistics for an interrupt on a cpu
871 * @irq: The interrupt number
872 * @cpu: The cpu number
874 * Returns the sum of interrupt counts on @cpu since boot for
875 * @irq. The caller must ensure that the interrupt is not removed
878 unsigned int kstat_irqs_cpu(unsigned int irq
, int cpu
)
880 struct irq_desc
*desc
= irq_to_desc(irq
);
882 return desc
&& desc
->kstat_irqs
?
883 *per_cpu_ptr(desc
->kstat_irqs
, cpu
) : 0;
887 * kstat_irqs - Get the statistics for an interrupt
888 * @irq: The interrupt number
890 * Returns the sum of interrupt counts on all cpus since boot for
891 * @irq. The caller must ensure that the interrupt is not removed
894 unsigned int kstat_irqs(unsigned int irq
)
896 struct irq_desc
*desc
= irq_to_desc(irq
);
897 unsigned int sum
= 0;
900 if (!desc
|| !desc
->kstat_irqs
)
902 if (!irq_settings_is_per_cpu_devid(desc
) &&
903 !irq_settings_is_per_cpu(desc
))
904 return desc
->tot_count
;
906 for_each_possible_cpu(cpu
)
907 sum
+= *per_cpu_ptr(desc
->kstat_irqs
, cpu
);
912 * kstat_irqs_usr - Get the statistics for an interrupt
913 * @irq: The interrupt number
915 * Returns the sum of interrupt counts on all cpus since boot for
916 * @irq. Contrary to kstat_irqs() this can be called from any
917 * preemptible context. It's protected against concurrent removal of
918 * an interrupt descriptor when sparse irqs are enabled.
920 unsigned int kstat_irqs_usr(unsigned int irq
)
925 sum
= kstat_irqs(irq
);