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