blob: 4f9427a30e141c816091b4b797f790fcf1815746 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/proc_fs.h>
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070012#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/interrupt.h>
14
Adrian Bunk97a41e22006-01-08 01:02:17 -080015#include "internals.h"
16
Ingo Molnar4a733ee2006-06-29 02:24:42 -070017static struct proc_dir_entry *root_irq_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#ifdef CONFIG_SMP
20
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070021static int irq_affinity_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
Yinghai Lu08678b02008-08-19 20:50:05 -070023 struct irq_desc *desc = irq_to_desc((long)m->private);
Mike Travis7f7ace02009-01-10 21:58:08 -080024 const struct cpumask *mask = desc->affinity;
Andi Kleen42ee2b72007-07-21 17:09:54 +020025
26#ifdef CONFIG_GENERIC_PENDING_IRQ
27 if (desc->status & IRQ_MOVE_PENDING)
Mike Travis7f7ace02009-01-10 21:58:08 -080028 mask = desc->pending_mask;
Andi Kleen42ee2b72007-07-21 17:09:54 +020029#endif
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070030 seq_cpumask(m, mask);
31 seq_putc(m, '\n');
32 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033}
34
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -070035static 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
John Keller25d61572007-05-10 22:42:44 -070058#ifndef is_affinity_mask_valid
59#define is_affinity_mask_valid(val) 1
60#endif
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062int no_irq_affinity;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070063static ssize_t irq_affinity_proc_write(struct file *file,
64 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070066 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
Rusty Russell0de26522008-12-13 21:20:26 +103067 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070068 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Yinghai Lu08678b02008-08-19 20:50:05 -070070 if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
Thomas Gleixner950f4422007-02-16 01:27:24 -080071 irq_balancing_disabled(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 return -EIO;
73
Rusty Russell0de26522008-12-13 21:20:26 +103074 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
75 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Rusty Russell0de26522008-12-13 21:20:26 +103077 err = cpumask_parse_user(buffer, count, new_value);
78 if (err)
79 goto free_cpumask;
80
Ingo Molnar6bdf1972009-01-03 12:50:46 +010081 if (!is_affinity_mask_valid(new_value)) {
Rusty Russell0de26522008-12-13 21:20:26 +103082 err = -EINVAL;
83 goto free_cpumask;
84 }
John Keller25d61572007-05-10 22:42:44 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 /*
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 */
Rusty Russell0de26522008-12-13 21:20:26 +103091 if (!cpumask_intersects(new_value, cpu_online_mask)) {
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080092 /* Special case for empty set - allow the architecture
93 code to set default SMP affinity. */
Rusty Russell0de26522008-12-13 21:20:26 +103094 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
95 } else {
96 irq_set_affinity(irq, new_value);
97 err = count;
98 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Rusty Russell0de26522008-12-13 21:20:26 +1030100free_cpumask:
101 free_cpumask_var(new_value);
102 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700105static int irq_affinity_proc_open(struct inode *inode, struct file *file)
Max Krasnyansky18404752008-05-29 11:02:52 -0700106{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700107 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
Max Krasnyansky18404752008-05-29 11:02:52 -0700108}
109
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700110static 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
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700115static 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
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700123static 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
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700130static int default_affinity_show(struct seq_file *m, void *v)
Max Krasnyansky18404752008-05-29 11:02:52 -0700131{
Rusty Russelld036e672009-01-01 10:12:26 +1030132 seq_cpumask(m, irq_default_affinity);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700133 seq_putc(m, '\n');
134 return 0;
135}
136
137static ssize_t default_affinity_write(struct file *file,
138 const char __user *buffer, size_t count, loff_t *ppos)
139{
Rusty Russelld036e672009-01-01 10:12:26 +1030140 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700141 int err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700142
Rusty Russelld036e672009-01-01 10:12:26 +1030143 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
144 return -ENOMEM;
Max Krasnyansky18404752008-05-29 11:02:52 -0700145
Rusty Russelld036e672009-01-01 10:12:26 +1030146 err = cpumask_parse_user(buffer, count, new_value);
147 if (err)
148 goto out;
149
150 if (!is_affinity_mask_valid(new_value)) {
151 err = -EINVAL;
152 goto out;
153 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700154
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 */
Rusty Russelld036e672009-01-01 10:12:26 +1030160 if (!cpumask_intersects(new_value, cpu_online_mask)) {
161 err = -EINVAL;
162 goto out;
163 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700164
Rusty Russelld036e672009-01-01 10:12:26 +1030165 cpumask_copy(irq_default_affinity, new_value);
166 err = count;
Max Krasnyansky18404752008-05-29 11:02:52 -0700167
Rusty Russelld036e672009-01-01 10:12:26 +1030168out:
169 free_cpumask_var(new_value);
170 return err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700171}
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700172
173static int default_affinity_open(struct inode *inode, struct file *file)
174{
Thomas Gleixner34769942009-11-20 11:46:21 +0100175 return single_open(file, default_affinity_show, PDE(inode)->data);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700176}
177
178static 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};
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800185
186static 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
194static 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
199static 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};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#endif
206
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400207static int irq_spurious_proc_show(struct seq_file *m, void *v)
Andi Kleen96d97cf2008-01-30 13:32:48 +0100208{
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400209 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;
Andi Kleen96d97cf2008-01-30 13:32:48 +0100215}
216
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400217static int irq_spurious_proc_open(struct inode *inode, struct file *file)
218{
219 return single_open(file, irq_spurious_proc_show, NULL);
220}
221
222static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#define MAX_NAMELEN 128
230
231static int name_unique(unsigned int irq, struct irqaction *new_action)
232{
Yinghai Lu08678b02008-08-19 20:50:05 -0700233 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 struct irqaction *action;
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700235 unsigned long flags;
236 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Thomas Gleixner239007b2009-11-17 16:46:45 +0100238 raw_spin_lock_irqsave(&desc->lock, flags);
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700239 for (action = desc->action ; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if ((action != new_action) && action->name &&
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700241 !strcmp(new_action->name, action->name)) {
242 ret = 0;
243 break;
244 }
245 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100246 raw_spin_unlock_irqrestore(&desc->lock, flags);
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700247 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
250void register_handler_proc(unsigned int irq, struct irqaction *action)
251{
252 char name [MAX_NAMELEN];
Yinghai Lu08678b02008-08-19 20:50:05 -0700253 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Yinghai Lu08678b02008-08-19 20:50:05 -0700255 if (!desc->dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 !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/ */
Yinghai Lu08678b02008-08-19 20:50:05 -0700263 action->dir = proc_mkdir(name, desc->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
266#undef MAX_NAMELEN
267
268#define MAX_NAMELEN 10
269
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700270void register_irq_proc(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 char name [MAX_NAMELEN];
273
Yinghai Lu08678b02008-08-19 20:50:05 -0700274 if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return;
276
277 memset(name, 0, MAX_NAMELEN);
278 sprintf(name, "%d", irq);
279
280 /* create /proc/irq/1234 */
Yinghai Lu08678b02008-08-19 20:50:05 -0700281 desc->dir = proc_mkdir(name, root_irq_dir);
Cyrill Gorcunovc82a43d2009-10-26 23:28:11 +0300282 if (!desc->dir)
283 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700286 /* create /proc/irq/<irq>/smp_affinity */
Yinghai Lu08678b02008-08-19 20:50:05 -0700287 proc_create_data("smp_affinity", 0600, desc->dir,
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700288 &irq_affinity_proc_fops, (void *)(long)irq);
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800289
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700290 /* 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
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800294 proc_create_data("node", 0444, desc->dir,
295 &irq_node_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#endif
Andi Kleen96d97cf2008-01-30 13:32:48 +0100297
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400298 proc_create_data("spurious", 0444, desc->dir,
299 &irq_spurious_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
301
302#undef MAX_NAMELEN
303
304void unregister_handler_proc(unsigned int irq, struct irqaction *action)
305{
Yinghai Lu08678b02008-08-19 20:50:05 -0700306 if (action->dir) {
307 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200308
Yinghai Lu08678b02008-08-19 20:50:05 -0700309 remove_proc_entry(action->dir->name, desc->dir);
310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
roel kluin3786fc72008-10-21 19:49:09 -0400313static void register_default_affinity_proc(void)
Max Krasnyansky18404752008-05-29 11:02:52 -0700314{
315#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700316 proc_create("irq/default_smp_affinity", 0600, NULL,
317 &default_affinity_proc_fops);
Max Krasnyansky18404752008-05-29 11:02:52 -0700318#endif
319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321void init_irq_proc(void)
322{
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700323 unsigned int irq;
324 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 /* create /proc/irq */
327 root_irq_dir = proc_mkdir("irq", NULL);
328 if (!root_irq_dir)
329 return;
330
Max Krasnyansky18404752008-05-29 11:02:52 -0700331 register_default_affinity_proc();
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /*
334 * Create entries for all existing IRQs.
335 */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800336 for_each_irq_desc(irq, desc) {
337 if (!desc)
338 continue;
339
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700340 register_irq_proc(irq, desc);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343