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/proc_fs.h>
11 #include <linux/interrupt.h>
13 #include "internals.h"
15 static struct proc_dir_entry *root_irq_dir;
19 static int irq_affinity_read_proc(char *page, char **start, off_t off,
20 int count, int *eof, void *data)
22 int len = cpumask_scnprintf(page, count, irq_desc[(long)data].affinity);
26 len += sprintf(page + len, "\n");
30 #ifndef is_affinity_mask_valid
31 #define is_affinity_mask_valid(val) 1
35 static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
36 unsigned long count, void *data)
38 unsigned int irq = (int)(long)data, full_count = count, err;
39 cpumask_t new_value, tmp;
41 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
42 irq_balancing_disabled(irq))
45 err = cpumask_parse_user(buffer, count, new_value);
49 if (!is_affinity_mask_valid(new_value))
53 * Do not allow disabling IRQs completely - it's a too easy
54 * way to make the system unusable accidentally :-) At least
55 * one online CPU still has to be targeted.
57 cpus_and(tmp, new_value, cpu_online_map);
59 /* Special case for empty set - allow the architecture
60 code to set default SMP affinity. */
61 return select_smp_affinity(irq) ? -EINVAL : full_count;
63 irq_set_affinity(irq, new_value);
70 #define MAX_NAMELEN 128
72 static int name_unique(unsigned int irq, struct irqaction *new_action)
74 struct irq_desc *desc = irq_desc + irq;
75 struct irqaction *action;
79 spin_lock_irqsave(&desc->lock, flags);
80 for (action = desc->action ; action; action = action->next) {
81 if ((action != new_action) && action->name &&
82 !strcmp(new_action->name, action->name)) {
87 spin_unlock_irqrestore(&desc->lock, flags);
91 void register_handler_proc(unsigned int irq, struct irqaction *action)
93 char name [MAX_NAMELEN];
95 if (!irq_desc[irq].dir || action->dir || !action->name ||
96 !name_unique(irq, action))
99 memset(name, 0, MAX_NAMELEN);
100 snprintf(name, MAX_NAMELEN, "%s", action->name);
102 /* create /proc/irq/1234/handler/ */
103 action->dir = proc_mkdir(name, irq_desc[irq].dir);
108 #define MAX_NAMELEN 10
110 void register_irq_proc(unsigned int irq)
112 char name [MAX_NAMELEN];
115 (irq_desc[irq].chip == &no_irq_chip) ||
119 memset(name, 0, MAX_NAMELEN);
120 sprintf(name, "%d", irq);
122 /* create /proc/irq/1234 */
123 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
127 struct proc_dir_entry *entry;
129 /* create /proc/irq/<irq>/smp_affinity */
130 entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir);
133 entry->data = (void *)(long)irq;
134 entry->read_proc = irq_affinity_read_proc;
135 entry->write_proc = irq_affinity_write_proc;
143 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
146 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
149 void init_irq_proc(void)
153 /* create /proc/irq */
154 root_irq_dir = proc_mkdir("irq", NULL);
159 * Create entries for all existing IRQs.
161 for (i = 0; i < NR_IRQS; i++)
162 register_irq_proc(i);