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