Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * This file contains the interrupt descriptor management code. Detailed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * information is available in Documentation/core-api/genericirq.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/radix-tree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/irqdomain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "internals.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * lockdep: we want to handle all irq_desc locks as a single lock-class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) static struct lock_class_key irq_desc_lock_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #if defined(CONFIG_SMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) static int __init irq_affinity_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 	alloc_bootmem_cpumask_var(&irq_default_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	cpulist_parse(str, irq_default_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	 * Set at least the boot cpu. We don't want to end up with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 	 * bugreports caused by random comandline masks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 	cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) __setup("irqaffinity=", irq_affinity_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) static void __init init_irq_default_affinity(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	if (!cpumask_available(irq_default_affinity))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 		zalloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	if (cpumask_empty(irq_default_affinity))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 		cpumask_setall(irq_default_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) static void __init init_irq_default_affinity(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) static int alloc_masks(struct irq_desc *desc, int node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	if (!zalloc_cpumask_var_node(&desc->irq_common_data.affinity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 				     GFP_KERNEL, node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	if (!zalloc_cpumask_var_node(&desc->irq_common_data.effective_affinity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 				     GFP_KERNEL, node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		free_cpumask_var(desc->irq_common_data.affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #ifdef CONFIG_GENERIC_PENDING_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	if (!zalloc_cpumask_var_node(&desc->pending_mask, GFP_KERNEL, node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 		free_cpumask_var(desc->irq_common_data.effective_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		free_cpumask_var(desc->irq_common_data.affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) static void desc_smp_init(struct irq_desc *desc, int node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 			  const struct cpumask *affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	if (!affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 		affinity = irq_default_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	cpumask_copy(desc->irq_common_data.affinity, affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #ifdef CONFIG_GENERIC_PENDING_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	cpumask_clear(desc->pending_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #ifdef CONFIG_NUMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	desc->irq_common_data.node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) alloc_masks(struct irq_desc *desc, int node) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) desc_smp_init(struct irq_desc *desc, int node, const struct cpumask *affinity) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 			      const struct cpumask *affinity, struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	desc->irq_common_data.handler_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	desc->irq_common_data.msi_desc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	desc->irq_data.common = &desc->irq_common_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	desc->irq_data.irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	desc->irq_data.chip = &no_irq_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	desc->irq_data.chip_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	irq_settings_clr_and_set(desc, ~0, _IRQ_DEFAULT_INIT_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	desc->handle_irq = handle_bad_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	desc->depth = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	desc->irq_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	desc->irqs_unhandled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	desc->tot_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	desc->name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	desc->owner = owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	for_each_possible_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		*per_cpu_ptr(desc->kstat_irqs, cpu) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	desc_smp_init(desc, node, affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) int nr_irqs = NR_IRQS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) EXPORT_SYMBOL_GPL(nr_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) static DEFINE_MUTEX(sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static DECLARE_BITMAP(allocated_irqs, IRQ_BITMAP_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #ifdef CONFIG_SPARSE_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static void irq_kobj_release(struct kobject *kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) #ifdef CONFIG_SYSFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static struct kobject *irq_kobj_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) #define IRQ_ATTR_RO(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) static ssize_t per_cpu_count_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 				  struct kobj_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	int cpu, irq = desc->irq_data.irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	char *p = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		unsigned int c = kstat_irqs_cpu(irq, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s%u", p, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		p = ",";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) IRQ_ATTR_RO(per_cpu_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) static ssize_t chip_name_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 			      struct kobj_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	raw_spin_lock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	if (desc->irq_data.chip && desc->irq_data.chip->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		ret = scnprintf(buf, PAGE_SIZE, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 				desc->irq_data.chip->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	raw_spin_unlock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) IRQ_ATTR_RO(chip_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) static ssize_t hwirq_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 			  struct kobj_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	raw_spin_lock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	if (desc->irq_data.domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		ret = sprintf(buf, "%d\n", (int)desc->irq_data.hwirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	raw_spin_unlock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) IRQ_ATTR_RO(hwirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) static ssize_t type_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 			 struct kobj_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	raw_spin_lock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	ret = sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		      irqd_is_level_type(&desc->irq_data) ? "level" : "edge");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	raw_spin_unlock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) IRQ_ATTR_RO(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) static ssize_t wakeup_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 			   struct kobj_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	raw_spin_lock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	ret = sprintf(buf, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		      irqd_is_wakeup_set(&desc->irq_data) ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	raw_spin_unlock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) IRQ_ATTR_RO(wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) static ssize_t name_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 			 struct kobj_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	raw_spin_lock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	if (desc->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		ret = scnprintf(buf, PAGE_SIZE, "%s\n", desc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	raw_spin_unlock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) IRQ_ATTR_RO(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) static ssize_t actions_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 			    struct kobj_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	struct irqaction *action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	char *p = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	raw_spin_lock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	for (action = desc->action; action != NULL; action = action->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 				 p, action->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		p = ",";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	raw_spin_unlock_irq(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) IRQ_ATTR_RO(actions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) static struct attribute *irq_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	&per_cpu_count_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	&chip_name_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	&hwirq_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	&type_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	&wakeup_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	&name_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	&actions_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) ATTRIBUTE_GROUPS(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) static struct kobj_type irq_kobj_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	.release	= irq_kobj_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	.sysfs_ops	= &kobj_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	.default_groups = irq_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) static void irq_sysfs_add(int irq, struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	if (irq_kobj_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		 * Continue even in case of failure as this is nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		 * crucial.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		if (kobject_add(&desc->kobj, irq_kobj_base, "%d", irq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 			pr_warn("Failed to add kobject for irq %d\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static void irq_sysfs_del(struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	 * If irq_sysfs_init() has not yet been invoked (early boot), then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	 * irq_kobj_base is NULL and the descriptor was never added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	 * kobject_del() complains about a object with no parent, so make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	 * it conditional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	if (irq_kobj_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		kobject_del(&desc->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) static int __init irq_sysfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	/* Prevent concurrent irq alloc/free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	irq_lock_sparse();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	irq_kobj_base = kobject_create_and_add("irq", kernel_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	if (!irq_kobj_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		irq_unlock_sparse();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	/* Add the already allocated interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	for_each_irq_desc(irq, desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		irq_sysfs_add(irq, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	irq_unlock_sparse();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) postcore_initcall(irq_sysfs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) #else /* !CONFIG_SYSFS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) static struct kobj_type irq_kobj_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	.release	= irq_kobj_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) static void irq_sysfs_add(int irq, struct irq_desc *desc) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) static void irq_sysfs_del(struct irq_desc *desc) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) #endif /* CONFIG_SYSFS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) static RADIX_TREE(irq_desc_tree, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) static void irq_insert_desc(unsigned int irq, struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	radix_tree_insert(&irq_desc_tree, irq, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) struct irq_desc *irq_to_desc(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	return radix_tree_lookup(&irq_desc_tree, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) EXPORT_SYMBOL(irq_to_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) static void delete_irq_desc(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	radix_tree_delete(&irq_desc_tree, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) static void free_masks(struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) #ifdef CONFIG_GENERIC_PENDING_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	free_cpumask_var(desc->pending_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	free_cpumask_var(desc->irq_common_data.affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	free_cpumask_var(desc->irq_common_data.effective_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) static inline void free_masks(struct irq_desc *desc) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) void irq_lock_sparse(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	mutex_lock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) void irq_unlock_sparse(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	mutex_unlock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 				   const struct cpumask *affinity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 				   struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	desc = kzalloc_node(sizeof(*desc), GFP_KERNEL, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	if (!desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	/* allocate based on nr_cpu_ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	desc->kstat_irqs = alloc_percpu(unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	if (!desc->kstat_irqs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		goto err_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	if (alloc_masks(desc, node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		goto err_kstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	raw_spin_lock_init(&desc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	lockdep_set_class(&desc->lock, &irq_desc_lock_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	mutex_init(&desc->request_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	init_rcu_head(&desc->rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	desc_set_defaults(irq, desc, node, affinity, owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	irqd_set(&desc->irq_data, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	kobject_init(&desc->kobj, &irq_kobj_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	return desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) err_kstat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	free_percpu(desc->kstat_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) err_desc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	kfree(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) static void irq_kobj_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	free_masks(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	free_percpu(desc->kstat_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	kfree(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) static void delayed_free_desc(struct rcu_head *rhp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	struct irq_desc *desc = container_of(rhp, struct irq_desc, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	kobject_put(&desc->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) static void free_desc(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	irq_remove_debugfs_entry(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	unregister_irq_proc(irq, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	 * sparse_irq_lock protects also show_interrupts() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	 * kstat_irq_usr(). Once we deleted the descriptor from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	 * sparse tree we can free it. Access in proc will fail to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	 * lookup the descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	 * The sysfs entry must be serialized against a concurrent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	 * irq_sysfs_init() as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	irq_sysfs_del(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	delete_irq_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	 * We free the descriptor, masks and stat fields via RCU. That
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	 * allows demultiplex interrupts to do rcu based management of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	 * the child interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	 * This also allows us to use rcu in kstat_irqs_usr().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	call_rcu(&desc->rcu, delayed_free_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) static int alloc_descs(unsigned int start, unsigned int cnt, int node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		       const struct irq_affinity_desc *affinity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		       struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	/* Validate affinity mask(s) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	if (affinity) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		for (i = 0; i < cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			if (cpumask_empty(&affinity[i].mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	for (i = 0; i < cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		const struct cpumask *mask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		unsigned int flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		if (affinity) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			if (affinity->is_managed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 				flags = IRQD_AFFINITY_MANAGED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 					IRQD_MANAGED_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			mask = &affinity->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			node = cpu_to_node(cpumask_first(mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			affinity++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		desc = alloc_desc(start + i, node, flags, mask, owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		if (!desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		irq_insert_desc(start + i, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		irq_sysfs_add(start + i, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		irq_add_debugfs_entry(start + i, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	bitmap_set(allocated_irqs, start, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	return start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		free_desc(start + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) static int irq_expand_nr_irqs(unsigned int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	if (nr > IRQ_BITMAP_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	nr_irqs = nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) int __init early_irq_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	int i, initcnt, node = first_online_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	init_irq_default_affinity();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	/* Let arch update nr_irqs and return the nr of preallocated irqs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	initcnt = arch_probe_nr_irqs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	printk(KERN_INFO "NR_IRQS: %d, nr_irqs: %d, preallocated irqs: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	       NR_IRQS, nr_irqs, initcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	if (WARN_ON(nr_irqs > IRQ_BITMAP_BITS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		nr_irqs = IRQ_BITMAP_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	if (WARN_ON(initcnt > IRQ_BITMAP_BITS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		initcnt = IRQ_BITMAP_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	if (initcnt > nr_irqs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		nr_irqs = initcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	for (i = 0; i < initcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		desc = alloc_desc(i, node, 0, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		set_bit(i, allocated_irqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		irq_insert_desc(i, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	return arch_early_irq_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) #else /* !CONFIG_SPARSE_IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	[0 ... NR_IRQS-1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		.handle_irq	= handle_bad_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		.depth		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		.lock		= __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) int __init early_irq_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	int count, i, node = first_online_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	init_irq_default_affinity();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	printk(KERN_INFO "NR_IRQS: %d\n", NR_IRQS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	desc = irq_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	count = ARRAY_SIZE(irq_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		desc[i].kstat_irqs = alloc_percpu(unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		alloc_masks(&desc[i], node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		raw_spin_lock_init(&desc[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		mutex_init(&desc[i].request_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		desc_set_defaults(i, &desc[i], node, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	return arch_early_irq_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) struct irq_desc *irq_to_desc(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	return (irq < NR_IRQS) ? irq_desc + irq : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) EXPORT_SYMBOL(irq_to_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) static void free_desc(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	raw_spin_lock_irqsave(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	desc_set_defaults(irq, desc, irq_desc_get_node(desc), NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	raw_spin_unlock_irqrestore(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) static inline int alloc_descs(unsigned int start, unsigned int cnt, int node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			      const struct irq_affinity_desc *affinity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 			      struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	for (i = 0; i < cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		struct irq_desc *desc = irq_to_desc(start + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		desc->owner = owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	bitmap_set(allocated_irqs, start, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	return start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) static int irq_expand_nr_irqs(unsigned int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) void irq_mark_irq(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	mutex_lock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	bitmap_set(allocated_irqs, irq, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	mutex_unlock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) #ifdef CONFIG_GENERIC_IRQ_LEGACY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) void irq_init_desc(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	free_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) #endif /* !CONFIG_SPARSE_IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634)  * generic_handle_irq - Invoke the handler for a particular irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635)  * @irq:	The irq number to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) int generic_handle_irq(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	struct irq_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	if (!desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	data = irq_desc_get_irq_data(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	if (WARN_ON_ONCE(!in_irq() && handle_enforce_irqctx(data)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	generic_handle_irq_desc(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) EXPORT_SYMBOL_GPL(generic_handle_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) #ifdef CONFIG_HANDLE_DOMAIN_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657)  * __handle_domain_irq - Invoke the handler for a HW irq belonging to a domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658)  * @domain:	The domain where to perform the lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)  * @hwirq:	The HW irq number to convert to a logical one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660)  * @lookup:	Whether to perform the domain lookup or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661)  * @regs:	Register file coming from the low-level handling code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)  * Returns:	0 on success, or -EINVAL if conversion has failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) int __handle_domain_irq(struct irq_domain *domain, unsigned int hwirq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 			bool lookup, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	struct pt_regs *old_regs = set_irq_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	unsigned int irq = hwirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) #ifdef CONFIG_IRQ_DOMAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	if (lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		irq = irq_find_mapping(domain, hwirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	 * Some hardware gives randomly wrong interrupts.  Rather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	 * than crashing, do something sensible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	if (unlikely(!irq || irq >= nr_irqs || !(desc = irq_to_desc(irq)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		ack_bad_irq(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	if (IS_ENABLED(CONFIG_ARCH_WANTS_IRQ_RAW) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	    unlikely(irq_settings_is_raw(desc))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		generic_handle_irq_desc(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		irq_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		generic_handle_irq_desc(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		irq_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	set_irq_regs(old_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) #ifdef CONFIG_IRQ_DOMAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)  * handle_domain_nmi - Invoke the handler for a HW irq belonging to a domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)  * @domain:	The domain where to perform the lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)  * @hwirq:	The HW irq number to convert to a logical one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  * @regs:	Register file coming from the low-level handling code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)  *		This function must be called from an NMI context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)  * Returns:	0 on success, or -EINVAL if conversion has failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) int handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		      struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	struct pt_regs *old_regs = set_irq_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	unsigned int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	 * NMI context needs to be setup earlier in order to deal with tracing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	WARN_ON(!in_nmi());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	irq = irq_find_mapping(domain, hwirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	 * ack_bad_irq is not NMI-safe, just report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	 * an invalid interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	if (likely(irq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		generic_handle_irq(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	set_irq_regs(old_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) /* Dynamic interrupt handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745)  * irq_free_descs - free irq descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746)  * @from:	Start of descriptor range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)  * @cnt:	Number of consecutive irqs to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) void irq_free_descs(unsigned int from, unsigned int cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	if (from >= nr_irqs || (from + cnt) > nr_irqs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	mutex_lock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	for (i = 0; i < cnt; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		free_desc(from + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	bitmap_clear(allocated_irqs, from, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	mutex_unlock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) EXPORT_SYMBOL_GPL(irq_free_descs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)  * __irq_alloc_descs - allocate and initialize a range of irq descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)  * @irq:	Allocate for specific irq number if irq >= 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768)  * @from:	Start the search from this irq number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769)  * @cnt:	Number of consecutive irqs to allocate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770)  * @node:	Preferred node on which the irq descriptor should be allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771)  * @owner:	Owning module (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772)  * @affinity:	Optional pointer to an affinity mask array of size @cnt which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773)  *		hints where the irq descriptors should be allocated and which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774)  *		default affinities to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)  * Returns the first irq number or error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) int __ref
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		  struct module *owner, const struct irq_affinity_desc *affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	int start, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (!cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	if (irq >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		if (from > irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		from = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		 * For interrupts which are freely allocated the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		 * architecture can force a lower bound to the @from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		 * argument. x86 uses this to exclude the GSI space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		from = arch_dynirq_lower_bound(from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	mutex_lock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	start = bitmap_find_next_zero_area(allocated_irqs, IRQ_BITMAP_BITS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 					   from, cnt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	ret = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	if (irq >=0 && start != irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	if (start + cnt > nr_irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		ret = irq_expand_nr_irqs(start + cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 			goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	ret = alloc_descs(start, cnt, node, affinity, owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	mutex_unlock(&sparse_irq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) EXPORT_SYMBOL_GPL(__irq_alloc_descs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) #ifdef CONFIG_GENERIC_IRQ_LEGACY_ALLOC_HWIRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)  * irq_alloc_hwirqs - Allocate an irq descriptor and initialize the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823)  * @cnt:	number of interrupts to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  * @node:	node on which to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  * Returns an interrupt number > 0 or 0, if the allocation fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) unsigned int irq_alloc_hwirqs(int cnt, int node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	int i, irq = __irq_alloc_descs(-1, 0, cnt, node, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	for (i = irq; cnt > 0; i++, cnt--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		if (arch_setup_hwirq(i, node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		irq_clear_status_flags(i, _IRQ_NOREQUEST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	for (i--; i >= irq; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		irq_set_status_flags(i, _IRQ_NOREQUEST | _IRQ_NOPROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		arch_teardown_hwirq(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	irq_free_descs(irq, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) EXPORT_SYMBOL_GPL(irq_alloc_hwirqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853)  * irq_free_hwirqs - Free irq descriptor and cleanup the hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854)  * @from:	Free from irq number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855)  * @cnt:	number of interrupts to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) void irq_free_hwirqs(unsigned int from, int cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	for (i = from, j = cnt; j > 0; i++, j--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		irq_set_status_flags(i, _IRQ_NOREQUEST | _IRQ_NOPROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		arch_teardown_hwirq(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	irq_free_descs(from, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) EXPORT_SYMBOL_GPL(irq_free_hwirqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  * irq_get_next_irq - get next allocated irq number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873)  * @offset:	where to start the search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875)  * Returns next irq number after offset or nr_irqs if none is found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) unsigned int irq_get_next_irq(unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	return find_next_bit(allocated_irqs, nr_irqs, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) struct irq_desc *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		    unsigned int check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	if (desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		if (check & _IRQ_DESC_CHECK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 			if ((check & _IRQ_DESC_PERCPU) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 			    !irq_settings_is_per_cpu_devid(desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 			if (!(check & _IRQ_DESC_PERCPU) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 			    irq_settings_is_per_cpu_devid(desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		if (bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 			chip_bus_lock(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		raw_spin_lock_irqsave(&desc->lock, *flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	return desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	__releases(&desc->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	raw_spin_unlock_irqrestore(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	if (bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		chip_bus_sync_unlock(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) int irq_set_percpu_devid_partition(unsigned int irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 				   const struct cpumask *affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	if (!desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	if (desc->percpu_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	desc->percpu_enabled = kzalloc(sizeof(*desc->percpu_enabled), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (!desc->percpu_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	if (affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		desc->percpu_affinity = affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		desc->percpu_affinity = cpu_possible_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	irq_set_percpu_devid_flags(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) int irq_set_percpu_devid(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	return irq_set_percpu_devid_partition(irq, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (!desc || !desc->percpu_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	if (affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		cpumask_copy(affinity, desc->percpu_affinity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) EXPORT_SYMBOL_GPL(irq_get_percpu_devid_partition);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) void kstat_incr_irq_this_cpu(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	kstat_incr_irqs_this_cpu(irq_to_desc(irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964)  * kstat_irqs_cpu - Get the statistics for an interrupt on a cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965)  * @irq:	The interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966)  * @cpu:	The cpu number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)  * Returns the sum of interrupt counts on @cpu since boot for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969)  * @irq. The caller must ensure that the interrupt is not removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970)  * concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	return desc && desc->kstat_irqs ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			*per_cpu_ptr(desc->kstat_irqs, cpu) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) EXPORT_SYMBOL_GPL(kstat_irqs_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) static bool irq_is_nmi(struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	return desc->istate & IRQS_NMI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987)  * kstat_irqs - Get the statistics for an interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988)  * @irq:	The interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990)  * Returns the sum of interrupt counts on all cpus since boot for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991)  * @irq. The caller must ensure that the interrupt is not removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992)  * concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) unsigned int kstat_irqs(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	unsigned int sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	if (!desc || !desc->kstat_irqs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	if (!irq_settings_is_per_cpu_devid(desc) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	    !irq_settings_is_per_cpu(desc) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	    !irq_is_nmi(desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	    return desc->tot_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	for_each_possible_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		sum += *per_cpu_ptr(desc->kstat_irqs, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  * kstat_irqs_usr - Get the statistics for an interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  * @irq:	The interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)  * Returns the sum of interrupt counts on all cpus since boot for @irq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)  * Contrary to kstat_irqs() this can be called from any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)  * It uses rcu since a concurrent removal of an interrupt descriptor is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)  * observing an rcu grace period before delayed_free_desc()/irq_kobj_release().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) unsigned int kstat_irqs_usr(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	unsigned int sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	sum = kstat_irqs(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) EXPORT_SYMBOL_GPL(kstat_irqs_usr);