sched: Fix proc_sched_set_task()
[deliverable/linux.git] / kernel / irq / proc.c
CommitLineData
1da177e4
LT
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>
f18e439d 11#include <linux/seq_file.h>
1da177e4
LT
12#include <linux/interrupt.h>
13
97a41e26
AB
14#include "internals.h"
15
4a733ee1 16static struct proc_dir_entry *root_irq_dir;
1da177e4
LT
17
18#ifdef CONFIG_SMP
19
f18e439d 20static int irq_affinity_proc_show(struct seq_file *m, void *v)
1da177e4 21{
08678b08 22 struct irq_desc *desc = irq_to_desc((long)m->private);
7f7ace0c 23 const struct cpumask *mask = desc->affinity;
42ee2b74
AK
24
25#ifdef CONFIG_GENERIC_PENDING_IRQ
26 if (desc->status & IRQ_MOVE_PENDING)
7f7ace0c 27 mask = desc->pending_mask;
42ee2b74 28#endif
f18e439d
AD
29 seq_cpumask(m, mask);
30 seq_putc(m, '\n');
31 return 0;
1da177e4
LT
32}
33
25d61578
JK
34#ifndef is_affinity_mask_valid
35#define is_affinity_mask_valid(val) 1
36#endif
37
1da177e4 38int no_irq_affinity;
f18e439d
AD
39static ssize_t irq_affinity_proc_write(struct file *file,
40 const char __user *buffer, size_t count, loff_t *pos)
1da177e4 41{
f18e439d 42 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
0de26520 43 cpumask_var_t new_value;
f18e439d 44 int err;
1da177e4 45
08678b08 46 if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
950f4427 47 irq_balancing_disabled(irq))
1da177e4
LT
48 return -EIO;
49
0de26520
RR
50 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
51 return -ENOMEM;
52
53 err = cpumask_parse_user(buffer, count, new_value);
1da177e4 54 if (err)
0de26520 55 goto free_cpumask;
1da177e4 56
6bdf197b 57 if (!is_affinity_mask_valid(new_value)) {
0de26520
RR
58 err = -EINVAL;
59 goto free_cpumask;
60 }
25d61578 61
1da177e4
LT
62 /*
63 * Do not allow disabling IRQs completely - it's a too easy
64 * way to make the system unusable accidentally :-) At least
65 * one online CPU still has to be targeted.
66 */
0de26520 67 if (!cpumask_intersects(new_value, cpu_online_mask)) {
eee45269
IK
68 /* Special case for empty set - allow the architecture
69 code to set default SMP affinity. */
0de26520
RR
70 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
71 } else {
72 irq_set_affinity(irq, new_value);
73 err = count;
74 }
75
76free_cpumask:
77 free_cpumask_var(new_value);
78 return err;
1da177e4
LT
79}
80
f18e439d 81static int irq_affinity_proc_open(struct inode *inode, struct file *file)
18404756 82{
f18e439d 83 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
18404756
MK
84}
85
f18e439d
AD
86static const struct file_operations irq_affinity_proc_fops = {
87 .open = irq_affinity_proc_open,
88 .read = seq_read,
89 .llseek = seq_lseek,
90 .release = single_release,
91 .write = irq_affinity_proc_write,
92};
93
94static int default_affinity_show(struct seq_file *m, void *v)
95{
d036e67b 96 seq_cpumask(m, irq_default_affinity);
f18e439d
AD
97 seq_putc(m, '\n');
98 return 0;
99}
100
101static ssize_t default_affinity_write(struct file *file,
102 const char __user *buffer, size_t count, loff_t *ppos)
18404756 103{
d036e67b 104 cpumask_var_t new_value;
f18e439d 105 int err;
18404756 106
d036e67b
RR
107 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
108 return -ENOMEM;
109
110 err = cpumask_parse_user(buffer, count, new_value);
18404756 111 if (err)
d036e67b 112 goto out;
18404756 113
d036e67b
RR
114 if (!is_affinity_mask_valid(new_value)) {
115 err = -EINVAL;
116 goto out;
117 }
18404756
MK
118
119 /*
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.
123 */
d036e67b
RR
124 if (!cpumask_intersects(new_value, cpu_online_mask)) {
125 err = -EINVAL;
126 goto out;
127 }
18404756 128
d036e67b
RR
129 cpumask_copy(irq_default_affinity, new_value);
130 err = count;
18404756 131
d036e67b
RR
132out:
133 free_cpumask_var(new_value);
134 return err;
18404756 135}
f18e439d
AD
136
137static int default_affinity_open(struct inode *inode, struct file *file)
138{
34769945 139 return single_open(file, default_affinity_show, PDE(inode)->data);
f18e439d
AD
140}
141
142static const struct file_operations default_affinity_proc_fops = {
143 .open = default_affinity_open,
144 .read = seq_read,
145 .llseek = seq_lseek,
146 .release = single_release,
147 .write = default_affinity_write,
148};
1da177e4
LT
149#endif
150
a1afb637 151static int irq_spurious_proc_show(struct seq_file *m, void *v)
96d97cf0 152{
a1afb637
AD
153 struct irq_desc *desc = irq_to_desc((long) m->private);
154
155 seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
156 desc->irq_count, desc->irqs_unhandled,
157 jiffies_to_msecs(desc->last_unhandled));
158 return 0;
159}
160
161static int irq_spurious_proc_open(struct inode *inode, struct file *file)
162{
163 return single_open(file, irq_spurious_proc_show, NULL);
96d97cf0
AK
164}
165
a1afb637
AD
166static const struct file_operations irq_spurious_proc_fops = {
167 .open = irq_spurious_proc_open,
168 .read = seq_read,
169 .llseek = seq_lseek,
170 .release = single_release,
171};
172
1da177e4
LT
173#define MAX_NAMELEN 128
174
175static int name_unique(unsigned int irq, struct irqaction *new_action)
176{
08678b08 177 struct irq_desc *desc = irq_to_desc(irq);
1da177e4 178 struct irqaction *action;
d2d9433a
DA
179 unsigned long flags;
180 int ret = 1;
1da177e4 181
239007b8 182 raw_spin_lock_irqsave(&desc->lock, flags);
d2d9433a 183 for (action = desc->action ; action; action = action->next) {
1da177e4 184 if ((action != new_action) && action->name &&
d2d9433a
DA
185 !strcmp(new_action->name, action->name)) {
186 ret = 0;
187 break;
188 }
189 }
239007b8 190 raw_spin_unlock_irqrestore(&desc->lock, flags);
d2d9433a 191 return ret;
1da177e4
LT
192}
193
194void register_handler_proc(unsigned int irq, struct irqaction *action)
195{
196 char name [MAX_NAMELEN];
08678b08 197 struct irq_desc *desc = irq_to_desc(irq);
1da177e4 198
08678b08 199 if (!desc->dir || action->dir || !action->name ||
1da177e4
LT
200 !name_unique(irq, action))
201 return;
202
203 memset(name, 0, MAX_NAMELEN);
204 snprintf(name, MAX_NAMELEN, "%s", action->name);
205
206 /* create /proc/irq/1234/handler/ */
08678b08 207 action->dir = proc_mkdir(name, desc->dir);
1da177e4
LT
208}
209
210#undef MAX_NAMELEN
211
212#define MAX_NAMELEN 10
213
2c6927a3 214void register_irq_proc(unsigned int irq, struct irq_desc *desc)
1da177e4
LT
215{
216 char name [MAX_NAMELEN];
217
08678b08 218 if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
1da177e4
LT
219 return;
220
221 memset(name, 0, MAX_NAMELEN);
222 sprintf(name, "%d", irq);
223
224 /* create /proc/irq/1234 */
08678b08 225 desc->dir = proc_mkdir(name, root_irq_dir);
c82a43d4
CG
226 if (!desc->dir)
227 return;
1da177e4
LT
228
229#ifdef CONFIG_SMP
f18e439d 230 /* create /proc/irq/<irq>/smp_affinity */
08678b08 231 proc_create_data("smp_affinity", 0600, desc->dir,
f18e439d 232 &irq_affinity_proc_fops, (void *)(long)irq);
1da177e4 233#endif
96d97cf0 234
a1afb637
AD
235 proc_create_data("spurious", 0444, desc->dir,
236 &irq_spurious_proc_fops, (void *)(long)irq);
1da177e4
LT
237}
238
239#undef MAX_NAMELEN
240
241void unregister_handler_proc(unsigned int irq, struct irqaction *action)
242{
08678b08
YL
243 if (action->dir) {
244 struct irq_desc *desc = irq_to_desc(irq);
d3c60047 245
08678b08
YL
246 remove_proc_entry(action->dir->name, desc->dir);
247 }
1da177e4
LT
248}
249
3786fc71 250static void register_default_affinity_proc(void)
18404756
MK
251{
252#ifdef CONFIG_SMP
f18e439d
AD
253 proc_create("irq/default_smp_affinity", 0600, NULL,
254 &default_affinity_proc_fops);
18404756
MK
255#endif
256}
257
1da177e4
LT
258void init_irq_proc(void)
259{
2c6927a3
YL
260 unsigned int irq;
261 struct irq_desc *desc;
1da177e4
LT
262
263 /* create /proc/irq */
264 root_irq_dir = proc_mkdir("irq", NULL);
265 if (!root_irq_dir)
266 return;
267
18404756
MK
268 register_default_affinity_proc();
269
1da177e4
LT
270 /*
271 * Create entries for all existing IRQs.
272 */
0b8f1efa
YL
273 for_each_irq_desc(irq, desc) {
274 if (!desc)
275 continue;
276
2c6927a3 277 register_irq_proc(irq, desc);
0b8f1efa 278 }
1da177e4
LT
279}
280
This page took 0.450387 seconds and 5 git commands to generate.