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>
14 #include <linux/kernel_stat.h>
15 #include <linux/mutex.h>
17 #include "internals.h"
22 * procfs protects read/write of /proc/irq/N/ files against a
23 * concurrent free of the interrupt descriptor. remove_proc_entry()
24 * immediately prevents new read/writes to happen and waits for
25 * already running read/write functions to complete.
27 * We remove the proc entries first and then delete the interrupt
28 * descriptor from the radix tree and free it. So it is guaranteed
29 * that irq_to_desc(N) is valid as long as the read/writes are
30 * permitted by procfs.
32 * The read from /proc/interrupts is a different problem because there
33 * is no protection. So the lookup and the access to irqdesc
34 * information must be protected by sparse_irq_lock.
36 static struct proc_dir_entry *root_irq_dir;
40 static int show_irq_affinity(int type, struct seq_file *m, void *v)
42 struct irq_desc *desc = irq_to_desc((long)m->private);
43 const struct cpumask *mask = desc->irq_data.affinity;
45 #ifdef CONFIG_GENERIC_PENDING_IRQ
46 if (irqd_is_setaffinity_pending(&desc->irq_data))
47 mask = desc->pending_mask;
50 seq_cpumask_list(m, mask);
57 static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
59 struct irq_desc *desc = irq_to_desc((long)m->private);
63 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
66 raw_spin_lock_irqsave(&desc->lock, flags);
67 if (desc->affinity_hint)
68 cpumask_copy(mask, desc->affinity_hint);
69 raw_spin_unlock_irqrestore(&desc->lock, flags);
73 free_cpumask_var(mask);
78 #ifndef is_affinity_mask_valid
79 #define is_affinity_mask_valid(val) 1
83 static int irq_affinity_proc_show(struct seq_file *m, void *v)
85 return show_irq_affinity(0, m, v);
88 static int irq_affinity_list_proc_show(struct seq_file *m, void *v)
90 return show_irq_affinity(1, m, v);
94 static ssize_t write_irq_affinity(int type, struct file *file,
95 const char __user *buffer, size_t count, loff_t *pos)
97 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
98 cpumask_var_t new_value;
101 if (!irq_can_set_affinity(irq) || no_irq_affinity)
104 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
108 err = cpumask_parselist_user(buffer, count, new_value);
110 err = cpumask_parse_user(buffer, count, new_value);
114 if (!is_affinity_mask_valid(new_value)) {
120 * Do not allow disabling IRQs completely - it's a too easy
121 * way to make the system unusable accidentally :-) At least
122 * one online CPU still has to be targeted.
124 if (!cpumask_intersects(new_value, cpu_online_mask)) {
125 /* Special case for empty set - allow the architecture
126 code to set default SMP affinity. */
127 err = irq_select_affinity_usr(irq, new_value) ? -EINVAL : count;
129 irq_set_affinity(irq, new_value);
134 free_cpumask_var(new_value);
138 static ssize_t irq_affinity_proc_write(struct file *file,
139 const char __user *buffer, size_t count, loff_t *pos)
141 return write_irq_affinity(0, file, buffer, count, pos);
144 static ssize_t irq_affinity_list_proc_write(struct file *file,
145 const char __user *buffer, size_t count, loff_t *pos)
147 return write_irq_affinity(1, file, buffer, count, pos);
150 static int irq_affinity_proc_open(struct inode *inode, struct file *file)
152 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
155 static int irq_affinity_list_proc_open(struct inode *inode, struct file *file)
157 return single_open(file, irq_affinity_list_proc_show, PDE(inode)->data);
160 static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
162 return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data);
165 static const struct file_operations irq_affinity_proc_fops = {
166 .open = irq_affinity_proc_open,
169 .release = single_release,
170 .write = irq_affinity_proc_write,
173 static const struct file_operations irq_affinity_hint_proc_fops = {
174 .open = irq_affinity_hint_proc_open,
177 .release = single_release,
180 static const struct file_operations irq_affinity_list_proc_fops = {
181 .open = irq_affinity_list_proc_open,
184 .release = single_release,
185 .write = irq_affinity_list_proc_write,
188 static int default_affinity_show(struct seq_file *m, void *v)
190 seq_cpumask(m, irq_default_affinity);
195 static ssize_t default_affinity_write(struct file *file,
196 const char __user *buffer, size_t count, loff_t *ppos)
198 cpumask_var_t new_value;
201 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
204 err = cpumask_parse_user(buffer, count, new_value);
208 if (!is_affinity_mask_valid(new_value)) {
214 * Do not allow disabling IRQs completely - it's a too easy
215 * way to make the system unusable accidentally :-) At least
216 * one online CPU still has to be targeted.
218 if (!cpumask_intersects(new_value, cpu_online_mask)) {
223 cpumask_copy(irq_default_affinity, new_value);
227 free_cpumask_var(new_value);
231 static int default_affinity_open(struct inode *inode, struct file *file)
233 return single_open(file, default_affinity_show, PDE(inode)->data);
236 static const struct file_operations default_affinity_proc_fops = {
237 .open = default_affinity_open,
240 .release = single_release,
241 .write = default_affinity_write,
244 static int irq_node_proc_show(struct seq_file *m, void *v)
246 struct irq_desc *desc = irq_to_desc((long) m->private);
248 seq_printf(m, "%d\n", desc->irq_data.node);
252 static int irq_node_proc_open(struct inode *inode, struct file *file)
254 return single_open(file, irq_node_proc_show, PDE(inode)->data);
257 static const struct file_operations irq_node_proc_fops = {
258 .open = irq_node_proc_open,
261 .release = single_release,
265 static int irq_spurious_proc_show(struct seq_file *m, void *v)
267 struct irq_desc *desc = irq_to_desc((long) m->private);
269 seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
270 desc->irq_count, desc->irqs_unhandled,
271 jiffies_to_msecs(desc->last_unhandled));
275 static int irq_spurious_proc_open(struct inode *inode, struct file *file)
277 return single_open(file, irq_spurious_proc_show, PDE(inode)->data);
280 static const struct file_operations irq_spurious_proc_fops = {
281 .open = irq_spurious_proc_open,
284 .release = single_release,
287 #define MAX_NAMELEN 128
289 static int name_unique(unsigned int irq, struct irqaction *new_action)
291 struct irq_desc *desc = irq_to_desc(irq);
292 struct irqaction *action;
296 raw_spin_lock_irqsave(&desc->lock, flags);
297 for (action = desc->action ; action; action = action->next) {
298 if ((action != new_action) && action->name &&
299 !strcmp(new_action->name, action->name)) {
304 raw_spin_unlock_irqrestore(&desc->lock, flags);
308 void register_handler_proc(unsigned int irq, struct irqaction *action)
310 char name [MAX_NAMELEN];
311 struct irq_desc *desc = irq_to_desc(irq);
313 if (!desc->dir || action->dir || !action->name ||
314 !name_unique(irq, action))
317 memset(name, 0, MAX_NAMELEN);
318 snprintf(name, MAX_NAMELEN, "%s", action->name);
320 /* create /proc/irq/1234/handler/ */
321 action->dir = proc_mkdir(name, desc->dir);
326 #define MAX_NAMELEN 10
328 void register_irq_proc(unsigned int irq, struct irq_desc *desc)
330 static DEFINE_MUTEX(register_lock);
331 char name [MAX_NAMELEN];
333 if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip))
337 * irq directories are registered only when a handler is
338 * added, not when the descriptor is created, so multiple
339 * tasks might try to register at the same time.
341 mutex_lock(®ister_lock);
346 memset(name, 0, MAX_NAMELEN);
347 sprintf(name, "%d", irq);
349 /* create /proc/irq/1234 */
350 desc->dir = proc_mkdir(name, root_irq_dir);
355 /* create /proc/irq/<irq>/smp_affinity */
356 proc_create_data("smp_affinity", 0600, desc->dir,
357 &irq_affinity_proc_fops, (void *)(long)irq);
359 /* create /proc/irq/<irq>/affinity_hint */
360 proc_create_data("affinity_hint", 0400, desc->dir,
361 &irq_affinity_hint_proc_fops, (void *)(long)irq);
363 /* create /proc/irq/<irq>/smp_affinity_list */
364 proc_create_data("smp_affinity_list", 0600, desc->dir,
365 &irq_affinity_list_proc_fops, (void *)(long)irq);
367 proc_create_data("node", 0444, desc->dir,
368 &irq_node_proc_fops, (void *)(long)irq);
371 proc_create_data("spurious", 0444, desc->dir,
372 &irq_spurious_proc_fops, (void *)(long)irq);
375 mutex_unlock(®ister_lock);
378 void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
380 char name [MAX_NAMELEN];
382 if (!root_irq_dir || !desc->dir)
385 remove_proc_entry("smp_affinity", desc->dir);
386 remove_proc_entry("affinity_hint", desc->dir);
387 remove_proc_entry("smp_affinity_list", desc->dir);
388 remove_proc_entry("node", desc->dir);
390 remove_proc_entry("spurious", desc->dir);
392 memset(name, 0, MAX_NAMELEN);
393 sprintf(name, "%u", irq);
394 remove_proc_entry(name, root_irq_dir);
399 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
402 struct irq_desc *desc = irq_to_desc(irq);
404 remove_proc_entry(action->dir->name, desc->dir);
408 static void register_default_affinity_proc(void)
411 proc_create("irq/default_smp_affinity", 0600, NULL,
412 &default_affinity_proc_fops);
416 void init_irq_proc(void)
419 struct irq_desc *desc;
421 /* create /proc/irq */
422 root_irq_dir = proc_mkdir("irq", NULL);
426 register_default_affinity_proc();
429 * Create entries for all existing IRQs.
431 for_each_irq_desc(irq, desc) {
435 register_irq_proc(irq, desc);
439 #ifdef CONFIG_GENERIC_IRQ_SHOW
441 int __weak arch_show_interrupts(struct seq_file *p, int prec)
446 #ifndef ACTUAL_NR_IRQS
447 # define ACTUAL_NR_IRQS nr_irqs
450 int show_interrupts(struct seq_file *p, void *v)
454 unsigned long flags, any_count = 0;
455 int i = *(loff_t *) v, j;
456 struct irqaction *action;
457 struct irq_desc *desc;
459 if (i > ACTUAL_NR_IRQS)
462 if (i == ACTUAL_NR_IRQS)
463 return arch_show_interrupts(p, prec);
465 /* print header and calculate the width of the first column */
467 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
470 seq_printf(p, "%*s", prec + 8, "");
471 for_each_online_cpu(j)
472 seq_printf(p, "CPU%-8d", j);
477 desc = irq_to_desc(i);
481 raw_spin_lock_irqsave(&desc->lock, flags);
482 for_each_online_cpu(j)
483 any_count |= kstat_irqs_cpu(i, j);
484 action = desc->action;
485 if (!action && !any_count)
488 seq_printf(p, "%*d: ", prec, i);
489 for_each_online_cpu(j)
490 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
492 if (desc->irq_data.chip) {
493 if (desc->irq_data.chip->irq_print_chip)
494 desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
495 else if (desc->irq_data.chip->name)
496 seq_printf(p, " %8s", desc->irq_data.chip->name);
498 seq_printf(p, " %8s", "-");
500 seq_printf(p, " %8s", "None");
502 #ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL
503 seq_printf(p, " %-8s", irqd_is_level_type(&desc->irq_data) ? "Level" : "Edge");
506 seq_printf(p, "-%-8s", desc->name);
509 seq_printf(p, " %s", action->name);
510 while ((action = action->next) != NULL)
511 seq_printf(p, ", %s", action->name);
516 raw_spin_unlock_irqrestore(&desc->lock, flags);