This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / kernel / irq / proc.c
1 /*
2  * linux/kernel/irq/proc.c
3  *
4  * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
5  *
6  * This file contains the /proc/irq/ handling code.
7  */
8
9 #include <linux/irq.h>
10 #include <linux/proc_fs.h>
11 #include <linux/interrupt.h>
12
13 static struct proc_dir_entry *root_irq_dir, *irq_dir[NR_IRQS];
14
15 #ifdef CONFIG_SMP
16
17 /*
18  * The /proc/irq/<irq>/smp_affinity values:
19  */
20 static struct proc_dir_entry *smp_affinity_entry[NR_IRQS];
21
22 cpumask_t irq_affinity[NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
23
24 static int irq_affinity_read_proc(char *page, char **start, off_t off,
25                                   int count, int *eof, void *data)
26 {
27         int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
28
29         if (count - len < 2)
30                 return -EINVAL;
31         len += sprintf(page + len, "\n");
32         return len;
33 }
34
35 int no_irq_affinity;
36 static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
37                                    unsigned long count, void *data)
38 {
39         unsigned int irq = (int)(long)data, full_count = count, err;
40         cpumask_t new_value, tmp;
41
42         if (!irq_desc[irq].handler->set_affinity || no_irq_affinity)
43                 return -EIO;
44
45         err = cpumask_parse(buffer, count, new_value);
46         if (err)
47                 return err;
48
49         /*
50          * Do not allow disabling IRQs completely - it's a too easy
51          * way to make the system unusable accidentally :-) At least
52          * one online CPU still has to be targeted.
53          */
54         cpus_and(tmp, new_value, cpu_online_map);
55         if (cpus_empty(tmp))
56                 return -EINVAL;
57
58         irq_affinity[irq] = new_value;
59         irq_desc[irq].handler->set_affinity(irq, new_value);
60
61         return full_count;
62 }
63
64 #endif
65
66 #define MAX_NAMELEN 128
67
68 static int name_unique(unsigned int irq, struct irqaction *new_action)
69 {
70         struct irq_desc *desc = irq_desc + irq;
71         struct irqaction *action;
72
73         for (action = desc->action ; action; action = action->next)
74                 if ((action != new_action) && action->name &&
75                                 !strcmp(new_action->name, action->name))
76                         return 0;
77         return 1;
78 }
79
80 void register_handler_proc(unsigned int irq, struct irqaction *action)
81 {
82         char name [MAX_NAMELEN];
83
84         if (!irq_dir[irq] || action->dir || !action->name ||
85                                         !name_unique(irq, action))
86                 return;
87
88         memset(name, 0, MAX_NAMELEN);
89         snprintf(name, MAX_NAMELEN, "%s", action->name);
90
91         /* create /proc/irq/1234/handler/ */
92         action->dir = proc_mkdir(name, irq_dir[irq]);
93 }
94
95 #undef MAX_NAMELEN
96
97 #define MAX_NAMELEN 10
98
99 void register_irq_proc(unsigned int irq)
100 {
101         char name [MAX_NAMELEN];
102
103         if (!root_irq_dir ||
104                 (irq_desc[irq].handler == &no_irq_type) ||
105                         irq_dir[irq])
106                 return;
107
108         memset(name, 0, MAX_NAMELEN);
109         sprintf(name, "%d", irq);
110
111         /* create /proc/irq/1234 */
112         irq_dir[irq] = proc_mkdir(name, root_irq_dir);
113
114 #ifdef CONFIG_SMP
115         {
116                 struct proc_dir_entry *entry;
117
118                 /* create /proc/irq/<irq>/smp_affinity */
119                 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
120
121                 if (entry) {
122                         entry->nlink = 1;
123                         entry->data = (void *)(long)irq;
124                         entry->read_proc = irq_affinity_read_proc;
125                         entry->write_proc = irq_affinity_write_proc;
126                 }
127                 smp_affinity_entry[irq] = entry;
128         }
129 #endif
130 }
131
132 #undef MAX_NAMELEN
133
134 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
135 {
136         if (action->dir)
137                 remove_proc_entry(action->dir->name, irq_dir[irq]);
138 }
139
140 void init_irq_proc(void)
141 {
142         int i;
143
144         /* create /proc/irq */
145         root_irq_dir = proc_mkdir("irq", NULL);
146         if (!root_irq_dir)
147                 return;
148
149         /*
150          * Create entries for all existing IRQs.
151          */
152         for (i = 0; i < NR_IRQS; i++)
153                 register_irq_proc(i);
154 }
155