2 * linux/kernel/irq/proc.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the /proc/irq/ handling code.
10 #include <linux/gfp.h>
11 #include <linux/proc_fs.h>
12 #include <linux/seq_file.h>
13 #include <linux/interrupt.h>
15 #include "internals.h"
17 static struct proc_dir_entry *root_irq_dir;
21 static int irq_affinity_proc_show(struct seq_file *m, void *v)
23 struct irq_desc *desc = irq_to_desc((long)m->private);
24 const struct cpumask *mask = desc->affinity;
26 #ifdef CONFIG_GENERIC_PENDING_IRQ
27 if (desc->status & IRQ_MOVE_PENDING)
28 mask = desc->pending_mask;
35 #ifndef is_affinity_mask_valid
36 #define is_affinity_mask_valid(val) 1
40 static ssize_t irq_affinity_proc_write(struct file *file,
41 const char __user *buffer, size_t count, loff_t *pos)
43 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
44 cpumask_var_t new_value;
47 if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
48 irq_balancing_disabled(irq))
51 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
54 err = cpumask_parse_user(buffer, count, new_value);
58 if (!is_affinity_mask_valid(new_value)) {
64 * Do not allow disabling IRQs completely - it's a too easy
65 * way to make the system unusable accidentally :-) At least
66 * one online CPU still has to be targeted.
68 if (!cpumask_intersects(new_value, cpu_online_mask)) {
69 /* Special case for empty set - allow the architecture
70 code to set default SMP affinity. */
71 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
73 irq_set_affinity(irq, new_value);
78 free_cpumask_var(new_value);
82 static int irq_affinity_proc_open(struct inode *inode, struct file *file)
84 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
87 static const struct file_operations irq_affinity_proc_fops = {
88 .open = irq_affinity_proc_open,
91 .release = single_release,
92 .write = irq_affinity_proc_write,
95 static int default_affinity_show(struct seq_file *m, void *v)
97 seq_cpumask(m, irq_default_affinity);
102 static ssize_t default_affinity_write(struct file *file,
103 const char __user *buffer, size_t count, loff_t *ppos)
105 cpumask_var_t new_value;
108 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
111 err = cpumask_parse_user(buffer, count, new_value);
115 if (!is_affinity_mask_valid(new_value)) {
121 * Do not allow disabling IRQs completely - it's a too easy
122 * way to make the system unusable accidentally :-) At least
123 * one online CPU still has to be targeted.
125 if (!cpumask_intersects(new_value, cpu_online_mask)) {
130 cpumask_copy(irq_default_affinity, new_value);
134 free_cpumask_var(new_value);
138 static int default_affinity_open(struct inode *inode, struct file *file)
140 return single_open(file, default_affinity_show, PDE(inode)->data);
143 static const struct file_operations default_affinity_proc_fops = {
144 .open = default_affinity_open,
147 .release = single_release,
148 .write = default_affinity_write,
151 static int irq_node_proc_show(struct seq_file *m, void *v)
153 struct irq_desc *desc = irq_to_desc((long) m->private);
155 seq_printf(m, "%d\n", desc->node);
159 static int irq_node_proc_open(struct inode *inode, struct file *file)
161 return single_open(file, irq_node_proc_show, PDE(inode)->data);
164 static const struct file_operations irq_node_proc_fops = {
165 .open = irq_node_proc_open,
168 .release = single_release,
172 static int irq_spurious_proc_show(struct seq_file *m, void *v)
174 struct irq_desc *desc = irq_to_desc((long) m->private);
176 seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
177 desc->irq_count, desc->irqs_unhandled,
178 jiffies_to_msecs(desc->last_unhandled));
182 static int irq_spurious_proc_open(struct inode *inode, struct file *file)
184 return single_open(file, irq_spurious_proc_show, NULL);
187 static const struct file_operations irq_spurious_proc_fops = {
188 .open = irq_spurious_proc_open,
191 .release = single_release,
194 #define MAX_NAMELEN 128
196 static int name_unique(unsigned int irq, struct irqaction *new_action)
198 struct irq_desc *desc = irq_to_desc(irq);
199 struct irqaction *action;
203 raw_spin_lock_irqsave(&desc->lock, flags);
204 for (action = desc->action ; action; action = action->next) {
205 if ((action != new_action) && action->name &&
206 !strcmp(new_action->name, action->name)) {
211 raw_spin_unlock_irqrestore(&desc->lock, flags);
215 void register_handler_proc(unsigned int irq, struct irqaction *action)
217 char name [MAX_NAMELEN];
218 struct irq_desc *desc = irq_to_desc(irq);
220 if (!desc->dir || action->dir || !action->name ||
221 !name_unique(irq, action))
224 memset(name, 0, MAX_NAMELEN);
225 snprintf(name, MAX_NAMELEN, "%s", action->name);
227 /* create /proc/irq/1234/handler/ */
228 action->dir = proc_mkdir(name, desc->dir);
233 #define MAX_NAMELEN 10
235 void register_irq_proc(unsigned int irq, struct irq_desc *desc)
237 char name [MAX_NAMELEN];
239 if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
242 memset(name, 0, MAX_NAMELEN);
243 sprintf(name, "%d", irq);
245 /* create /proc/irq/1234 */
246 desc->dir = proc_mkdir(name, root_irq_dir);
251 /* create /proc/irq/<irq>/smp_affinity */
252 proc_create_data("smp_affinity", 0600, desc->dir,
253 &irq_affinity_proc_fops, (void *)(long)irq);
255 proc_create_data("node", 0444, desc->dir,
256 &irq_node_proc_fops, (void *)(long)irq);
259 proc_create_data("spurious", 0444, desc->dir,
260 &irq_spurious_proc_fops, (void *)(long)irq);
265 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
268 struct irq_desc *desc = irq_to_desc(irq);
270 remove_proc_entry(action->dir->name, desc->dir);
274 static void register_default_affinity_proc(void)
277 proc_create("irq/default_smp_affinity", 0600, NULL,
278 &default_affinity_proc_fops);
282 void init_irq_proc(void)
285 struct irq_desc *desc;
287 /* create /proc/irq */
288 root_irq_dir = proc_mkdir("irq", NULL);
292 register_default_affinity_proc();
295 * Create entries for all existing IRQs.
297 for_each_irq_desc(irq, desc) {
301 register_irq_proc(irq, desc);