Merge /spare/repo/linux-2.6/
[linux-2.6] / 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 #ifdef CONFIG_GENERIC_PENDING_IRQ
23 void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val)
24 {
25         /*
26          * Save these away for later use. Re-progam when the
27          * interrupt is pending
28          */
29         set_pending_irq(irq, mask_val);
30 }
31 #else
32 void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val)
33 {
34         irq_affinity[irq] = mask_val;
35         irq_desc[irq].handler->set_affinity(irq, mask_val);
36 }
37 #endif
38
39 static int irq_affinity_read_proc(char *page, char **start, off_t off,
40                                   int count, int *eof, void *data)
41 {
42         int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
43
44         if (count - len < 2)
45                 return -EINVAL;
46         len += sprintf(page + len, "\n");
47         return len;
48 }
49
50 int no_irq_affinity;
51 static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
52                                    unsigned long count, void *data)
53 {
54         unsigned int irq = (int)(long)data, full_count = count, err;
55         cpumask_t new_value, tmp;
56
57         if (!irq_desc[irq].handler->set_affinity || no_irq_affinity)
58                 return -EIO;
59
60         err = cpumask_parse(buffer, count, new_value);
61         if (err)
62                 return err;
63
64         /*
65          * Do not allow disabling IRQs completely - it's a too easy
66          * way to make the system unusable accidentally :-) At least
67          * one online CPU still has to be targeted.
68          */
69         cpus_and(tmp, new_value, cpu_online_map);
70         if (cpus_empty(tmp))
71                 return -EINVAL;
72
73         proc_set_irq_affinity(irq, new_value);
74
75         return full_count;
76 }
77
78 #endif
79
80 #define MAX_NAMELEN 128
81
82 static int name_unique(unsigned int irq, struct irqaction *new_action)
83 {
84         struct irq_desc *desc = irq_desc + irq;
85         struct irqaction *action;
86
87         for (action = desc->action ; action; action = action->next)
88                 if ((action != new_action) && action->name &&
89                                 !strcmp(new_action->name, action->name))
90                         return 0;
91         return 1;
92 }
93
94 void register_handler_proc(unsigned int irq, struct irqaction *action)
95 {
96         char name [MAX_NAMELEN];
97
98         if (!irq_dir[irq] || action->dir || !action->name ||
99                                         !name_unique(irq, action))
100                 return;
101
102         memset(name, 0, MAX_NAMELEN);
103         snprintf(name, MAX_NAMELEN, "%s", action->name);
104
105         /* create /proc/irq/1234/handler/ */
106         action->dir = proc_mkdir(name, irq_dir[irq]);
107 }
108
109 #undef MAX_NAMELEN
110
111 #define MAX_NAMELEN 10
112
113 void register_irq_proc(unsigned int irq)
114 {
115         char name [MAX_NAMELEN];
116
117         if (!root_irq_dir ||
118                 (irq_desc[irq].handler == &no_irq_type) ||
119                         irq_dir[irq])
120                 return;
121
122         memset(name, 0, MAX_NAMELEN);
123         sprintf(name, "%d", irq);
124
125         /* create /proc/irq/1234 */
126         irq_dir[irq] = proc_mkdir(name, root_irq_dir);
127
128 #ifdef CONFIG_SMP
129         {
130                 struct proc_dir_entry *entry;
131
132                 /* create /proc/irq/<irq>/smp_affinity */
133                 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
134
135                 if (entry) {
136                         entry->nlink = 1;
137                         entry->data = (void *)(long)irq;
138                         entry->read_proc = irq_affinity_read_proc;
139                         entry->write_proc = irq_affinity_write_proc;
140                 }
141                 smp_affinity_entry[irq] = entry;
142         }
143 #endif
144 }
145
146 #undef MAX_NAMELEN
147
148 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
149 {
150         if (action->dir)
151                 remove_proc_entry(action->dir->name, irq_dir[irq]);
152 }
153
154 void init_irq_proc(void)
155 {
156         int i;
157
158         /* create /proc/irq */
159         root_irq_dir = proc_mkdir("irq", NULL);
160         if (!root_irq_dir)
161                 return;
162
163         /*
164          * Create entries for all existing IRQs.
165          */
166         for (i = 0; i < NR_IRQS; i++)
167                 register_irq_proc(i);
168 }
169