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-2004 Linus Torvalds, Ingo Molnar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file contains the /proc/irq/ handling code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "internals.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Access rules:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * procfs protects read/write of /proc/irq/N/ files against a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * concurrent free of the interrupt descriptor. remove_proc_entry()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * immediately prevents new read/writes to happen and waits for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * already running read/write functions to complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * We remove the proc entries first and then delete the interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * descriptor from the radix tree and free it. So it is guaranteed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * that irq_to_desc(N) is valid as long as the read/writes are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * permitted by procfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * The read from /proc/interrupts is a different problem because there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * is no protection. So the lookup and the access to irqdesc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * information must be protected by sparse_irq_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static struct proc_dir_entry *root_irq_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	AFFINITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	AFFINITY_LIST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	EFFECTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	EFFECTIVE_LIST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static int show_irq_affinity(int type, struct seq_file *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct irq_desc *desc = irq_to_desc((long)m->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	const struct cpumask *mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	case AFFINITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	case AFFINITY_LIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		mask = desc->irq_common_data.affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #ifdef CONFIG_GENERIC_PENDING_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		if (irqd_is_setaffinity_pending(&desc->irq_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			mask = desc->pending_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	case EFFECTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	case EFFECTIVE_LIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		mask = irq_data_get_effective_affinity_mask(&desc->irq_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	case AFFINITY_LIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	case EFFECTIVE_LIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		seq_printf(m, "%*pbl\n", cpumask_pr_args(mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	case AFFINITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	case EFFECTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		seq_printf(m, "%*pb\n", cpumask_pr_args(mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct irq_desc *desc = irq_to_desc((long)m->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	cpumask_var_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	raw_spin_lock_irqsave(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (desc->affinity_hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		cpumask_copy(mask, desc->affinity_hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	raw_spin_unlock_irqrestore(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	seq_printf(m, "%*pb\n", cpumask_pr_args(mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	free_cpumask_var(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int no_irq_affinity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int irq_affinity_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return show_irq_affinity(AFFINITY, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int irq_affinity_list_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return show_irq_affinity(AFFINITY_LIST, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #ifndef CONFIG_AUTO_IRQ_AFFINITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static inline int irq_select_affinity_usr(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 * If the interrupt is started up already then this fails. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 * interrupt is assigned to an online CPU already. There is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * point to move it around randomly. Tell user space that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * selected mask is bogus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * If not then any change to the affinity is pointless because the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * startup code invokes irq_setup_affinity() which will select
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * a online CPU anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* ALPHA magic affinity auto selector. Keep it for historical reasons. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static inline int irq_select_affinity_usr(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return irq_select_affinity(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static ssize_t write_irq_affinity(int type, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		const char __user *buffer, size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	unsigned int irq = (int)(long)PDE_DATA(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	cpumask_var_t new_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!irq_can_set_affinity_usr(irq) || no_irq_affinity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		err = cpumask_parselist_user(buffer, count, new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		err = cpumask_parse_user(buffer, count, new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		goto free_cpumask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * Do not allow disabling IRQs completely - it's a too easy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * way to make the system unusable accidentally :-) At least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 * one active CPU still has to be targeted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (!cpumask_intersects(new_value, cpu_active_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		 * Special case for empty set - allow the architecture code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		 * to set default SMP affinity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		err = irq_select_affinity_usr(irq) ? -EINVAL : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		err = irq_set_affinity(irq, new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			err = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) free_cpumask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	free_cpumask_var(new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static ssize_t irq_affinity_proc_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		const char __user *buffer, size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return write_irq_affinity(0, file, buffer, count, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static ssize_t irq_affinity_list_proc_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		const char __user *buffer, size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	return write_irq_affinity(1, file, buffer, count, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static int irq_affinity_proc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return single_open(file, irq_affinity_proc_show, PDE_DATA(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int irq_affinity_list_proc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return single_open(file, irq_affinity_list_proc_show, PDE_DATA(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static const struct proc_ops irq_affinity_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.proc_open	= irq_affinity_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	.proc_read	= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	.proc_lseek	= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	.proc_release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	.proc_write	= irq_affinity_proc_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static const struct proc_ops irq_affinity_list_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	.proc_open	= irq_affinity_list_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	.proc_read	= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	.proc_lseek	= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	.proc_release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	.proc_write	= irq_affinity_list_proc_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int irq_effective_aff_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return show_irq_affinity(EFFECTIVE, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int irq_effective_aff_list_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return show_irq_affinity(EFFECTIVE_LIST, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int default_affinity_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	seq_printf(m, "%*pb\n", cpumask_pr_args(irq_default_affinity));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static ssize_t default_affinity_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		const char __user *buffer, size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	cpumask_var_t new_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	err = cpumask_parse_user(buffer, count, new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * Do not allow disabling IRQs completely - it's a too easy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 * way to make the system unusable accidentally :-) At least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	 * one online CPU still has to be targeted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (!cpumask_intersects(new_value, cpu_online_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	cpumask_copy(irq_default_affinity, new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	err = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	free_cpumask_var(new_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int default_affinity_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return single_open(file, default_affinity_show, PDE_DATA(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static const struct proc_ops default_affinity_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.proc_open	= default_affinity_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.proc_read	= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.proc_lseek	= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.proc_release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	.proc_write	= default_affinity_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int irq_node_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct irq_desc *desc = irq_to_desc((long) m->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	seq_printf(m, "%d\n", irq_desc_get_node(desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int irq_spurious_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct irq_desc *desc = irq_to_desc((long) m->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		   desc->irq_count, desc->irqs_unhandled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		   jiffies_to_msecs(desc->last_unhandled));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return 0;
^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) #define MAX_NAMELEN 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int name_unique(unsigned int irq, struct irqaction *new_action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct irqaction *action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	int ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	raw_spin_lock_irqsave(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	for_each_action_of_desc(desc, action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if ((action != new_action) && action->name &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 				!strcmp(new_action->name, action->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	raw_spin_unlock_irqrestore(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) void register_handler_proc(unsigned int irq, struct irqaction *action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	char name [MAX_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	struct irq_desc *desc = irq_to_desc(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (!desc->dir || action->dir || !action->name ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 					!name_unique(irq, action))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	snprintf(name, MAX_NAMELEN, "%s", action->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	/* create /proc/irq/1234/handler/ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	action->dir = proc_mkdir(name, desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #undef MAX_NAMELEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) #define MAX_NAMELEN 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) void register_irq_proc(unsigned int irq, struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	static DEFINE_MUTEX(register_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	void __maybe_unused *irqp = (void *)(unsigned long) irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	char name [MAX_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	 * irq directories are registered only when a handler is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 * added, not when the descriptor is created, so multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 * tasks might try to register at the same time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	mutex_lock(&register_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (desc->dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	sprintf(name, "%d", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	/* create /proc/irq/1234 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	desc->dir = proc_mkdir(name, root_irq_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	if (!desc->dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	/* create /proc/irq/<irq>/smp_affinity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	proc_create_data("smp_affinity", 0644, desc->dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			 &irq_affinity_proc_ops, irqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/* create /proc/irq/<irq>/affinity_hint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	proc_create_single_data("affinity_hint", 0444, desc->dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			irq_affinity_hint_proc_show, irqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/* create /proc/irq/<irq>/smp_affinity_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	proc_create_data("smp_affinity_list", 0644, desc->dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			 &irq_affinity_list_proc_ops, irqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			irqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) # ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	proc_create_single_data("effective_affinity", 0444, desc->dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			irq_effective_aff_proc_show, irqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	proc_create_single_data("effective_affinity_list", 0444, desc->dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			irq_effective_aff_list_proc_show, irqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	proc_create_single_data("spurious", 0444, desc->dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			irq_spurious_proc_show, (void *)(long)irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	mutex_unlock(&register_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	char name [MAX_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (!root_irq_dir || !desc->dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	remove_proc_entry("smp_affinity", desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	remove_proc_entry("affinity_hint", desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	remove_proc_entry("smp_affinity_list", desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	remove_proc_entry("node", desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) # ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	remove_proc_entry("effective_affinity", desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	remove_proc_entry("effective_affinity_list", desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	remove_proc_entry("spurious", desc->dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	sprintf(name, "%u", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	remove_proc_entry(name, root_irq_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) #undef MAX_NAMELEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) void unregister_handler_proc(unsigned int irq, struct irqaction *action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	proc_remove(action->dir);
^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 register_default_affinity_proc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	proc_create("irq/default_smp_affinity", 0644, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		    &default_affinity_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) void init_irq_proc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	unsigned int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	/* create /proc/irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	root_irq_dir = proc_mkdir("irq", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (!root_irq_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	register_default_affinity_proc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	 * Create entries for all existing IRQs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	for_each_irq_desc(irq, desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		register_irq_proc(irq, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #ifdef CONFIG_GENERIC_IRQ_SHOW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int __weak arch_show_interrupts(struct seq_file *p, int prec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #ifndef ACTUAL_NR_IRQS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) # define ACTUAL_NR_IRQS nr_irqs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) int show_interrupts(struct seq_file *p, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	static int prec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	unsigned long flags, any_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	int i = *(loff_t *) v, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct irqaction *action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct irq_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	if (i > ACTUAL_NR_IRQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (i == ACTUAL_NR_IRQS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return arch_show_interrupts(p, prec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	/* print header and calculate the width of the first column */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (i == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			j *= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		seq_printf(p, "%*s", prec + 8, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		for_each_online_cpu(j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			seq_printf(p, "CPU%-8d", j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		seq_putc(p, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	desc = irq_to_desc(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	if (!desc || irq_settings_is_hidden(desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		goto outsparse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	if (desc->kstat_irqs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		for_each_online_cpu(j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			any_count |= *per_cpu_ptr(desc->kstat_irqs, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	if ((!desc->action || irq_desc_is_chained(desc)) && !any_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		goto outsparse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	seq_printf(p, "%*d: ", prec, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	for_each_online_cpu(j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		seq_printf(p, "%10u ", desc->kstat_irqs ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 					*per_cpu_ptr(desc->kstat_irqs, j) : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	raw_spin_lock_irqsave(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	if (desc->irq_data.chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		if (desc->irq_data.chip->irq_print_chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		else if (desc->irq_data.chip->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			seq_printf(p, " %8s", desc->irq_data.chip->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			seq_printf(p, " %8s", "-");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		seq_printf(p, " %8s", "None");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	if (desc->irq_data.domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		seq_printf(p, " %*d", prec, (int) desc->irq_data.hwirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		seq_printf(p, " %*s", prec, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) #ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	seq_printf(p, " %-8s", irqd_is_level_type(&desc->irq_data) ? "Level" : "Edge");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	if (desc->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		seq_printf(p, "-%-8s", desc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	action = desc->action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	if (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		seq_printf(p, "  %s", action->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		while ((action = action->next) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			seq_printf(p, ", %s", action->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	seq_putc(p, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	raw_spin_unlock_irqrestore(&desc->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) outsparse:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) #endif