blob: 01b1d3a88983f92c189e0c9b27f23ffe0e73f88f [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);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020024 const struct cpumask *mask = desc->irq_data.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
Peter P Waskiewicz Jr4308ad82010-05-05 13:56:42 -070041 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -070042 return -ENOMEM;
43
44 raw_spin_lock_irqsave(&desc->lock, flags);
45 if (desc->affinity_hint)
46 cpumask_copy(mask, desc->affinity_hint);
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -070047 raw_spin_unlock_irqrestore(&desc->lock, flags);
48
49 seq_cpumask(m, mask);
50 seq_putc(m, '\n');
51 free_cpumask_var(mask);
52
53 return 0;
54}
55
John Keller25d61572007-05-10 22:42:44 -070056#ifndef is_affinity_mask_valid
57#define is_affinity_mask_valid(val) 1
58#endif
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060int no_irq_affinity;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070061static ssize_t irq_affinity_proc_write(struct file *file,
62 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070064 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
Rusty Russell0de26522008-12-13 21:20:26 +103065 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070066 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Thomas Gleixnerc96b3b32010-09-27 12:45:41 +000068 if (!irq_to_desc(irq)->irq_data.chip->irq_set_affinity || no_irq_affinity ||
Thomas Gleixner950f4422007-02-16 01:27:24 -080069 irq_balancing_disabled(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return -EIO;
71
Rusty Russell0de26522008-12-13 21:20:26 +103072 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
73 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Rusty Russell0de26522008-12-13 21:20:26 +103075 err = cpumask_parse_user(buffer, count, new_value);
76 if (err)
77 goto free_cpumask;
78
Ingo Molnar6bdf1972009-01-03 12:50:46 +010079 if (!is_affinity_mask_valid(new_value)) {
Rusty Russell0de26522008-12-13 21:20:26 +103080 err = -EINVAL;
81 goto free_cpumask;
82 }
John Keller25d61572007-05-10 22:42:44 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 /*
85 * Do not allow disabling IRQs completely - it's a too easy
86 * way to make the system unusable accidentally :-) At least
87 * one online CPU still has to be targeted.
88 */
Rusty Russell0de26522008-12-13 21:20:26 +103089 if (!cpumask_intersects(new_value, cpu_online_mask)) {
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080090 /* Special case for empty set - allow the architecture
91 code to set default SMP affinity. */
Rusty Russell0de26522008-12-13 21:20:26 +103092 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
93 } else {
94 irq_set_affinity(irq, new_value);
95 err = count;
96 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Rusty Russell0de26522008-12-13 21:20:26 +103098free_cpumask:
99 free_cpumask_var(new_value);
100 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700103static int irq_affinity_proc_open(struct inode *inode, struct file *file)
Max Krasnyansky18404752008-05-29 11:02:52 -0700104{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700105 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
Max Krasnyansky18404752008-05-29 11:02:52 -0700106}
107
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700108static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
109{
110 return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data);
111}
112
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700113static const struct file_operations irq_affinity_proc_fops = {
114 .open = irq_affinity_proc_open,
115 .read = seq_read,
116 .llseek = seq_lseek,
117 .release = single_release,
118 .write = irq_affinity_proc_write,
119};
120
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700121static const struct file_operations irq_affinity_hint_proc_fops = {
122 .open = irq_affinity_hint_proc_open,
123 .read = seq_read,
124 .llseek = seq_lseek,
125 .release = single_release,
126};
127
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700128static int default_affinity_show(struct seq_file *m, void *v)
Max Krasnyansky18404752008-05-29 11:02:52 -0700129{
Rusty Russelld036e672009-01-01 10:12:26 +1030130 seq_cpumask(m, irq_default_affinity);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700131 seq_putc(m, '\n');
132 return 0;
133}
134
135static ssize_t default_affinity_write(struct file *file,
136 const char __user *buffer, size_t count, loff_t *ppos)
137{
Rusty Russelld036e672009-01-01 10:12:26 +1030138 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700139 int err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700140
Rusty Russelld036e672009-01-01 10:12:26 +1030141 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
142 return -ENOMEM;
Max Krasnyansky18404752008-05-29 11:02:52 -0700143
Rusty Russelld036e672009-01-01 10:12:26 +1030144 err = cpumask_parse_user(buffer, count, new_value);
145 if (err)
146 goto out;
147
148 if (!is_affinity_mask_valid(new_value)) {
149 err = -EINVAL;
150 goto out;
151 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700152
153 /*
154 * Do not allow disabling IRQs completely - it's a too easy
155 * way to make the system unusable accidentally :-) At least
156 * one online CPU still has to be targeted.
157 */
Rusty Russelld036e672009-01-01 10:12:26 +1030158 if (!cpumask_intersects(new_value, cpu_online_mask)) {
159 err = -EINVAL;
160 goto out;
161 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700162
Rusty Russelld036e672009-01-01 10:12:26 +1030163 cpumask_copy(irq_default_affinity, new_value);
164 err = count;
Max Krasnyansky18404752008-05-29 11:02:52 -0700165
Rusty Russelld036e672009-01-01 10:12:26 +1030166out:
167 free_cpumask_var(new_value);
168 return err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700169}
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700170
171static int default_affinity_open(struct inode *inode, struct file *file)
172{
Thomas Gleixner34769942009-11-20 11:46:21 +0100173 return single_open(file, default_affinity_show, PDE(inode)->data);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700174}
175
176static const struct file_operations default_affinity_proc_fops = {
177 .open = default_affinity_open,
178 .read = seq_read,
179 .llseek = seq_lseek,
180 .release = single_release,
181 .write = default_affinity_write,
182};
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800183
184static int irq_node_proc_show(struct seq_file *m, void *v)
185{
186 struct irq_desc *desc = irq_to_desc((long) m->private);
187
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200188 seq_printf(m, "%d\n", desc->irq_data.node);
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800189 return 0;
190}
191
192static int irq_node_proc_open(struct inode *inode, struct file *file)
193{
194 return single_open(file, irq_node_proc_show, PDE(inode)->data);
195}
196
197static const struct file_operations irq_node_proc_fops = {
198 .open = irq_node_proc_open,
199 .read = seq_read,
200 .llseek = seq_lseek,
201 .release = single_release,
202};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#endif
204
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400205static int irq_spurious_proc_show(struct seq_file *m, void *v)
Andi Kleen96d97cf2008-01-30 13:32:48 +0100206{
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400207 struct irq_desc *desc = irq_to_desc((long) m->private);
208
209 seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
210 desc->irq_count, desc->irqs_unhandled,
211 jiffies_to_msecs(desc->last_unhandled));
212 return 0;
Andi Kleen96d97cf2008-01-30 13:32:48 +0100213}
214
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400215static int irq_spurious_proc_open(struct inode *inode, struct file *file)
216{
217 return single_open(file, irq_spurious_proc_show, NULL);
218}
219
220static const struct file_operations irq_spurious_proc_fops = {
221 .open = irq_spurious_proc_open,
222 .read = seq_read,
223 .llseek = seq_lseek,
224 .release = single_release,
225};
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define MAX_NAMELEN 128
228
229static int name_unique(unsigned int irq, struct irqaction *new_action)
230{
Yinghai Lu08678b02008-08-19 20:50:05 -0700231 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 struct irqaction *action;
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700233 unsigned long flags;
234 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Thomas Gleixner239007b2009-11-17 16:46:45 +0100236 raw_spin_lock_irqsave(&desc->lock, flags);
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700237 for (action = desc->action ; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if ((action != new_action) && action->name &&
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700239 !strcmp(new_action->name, action->name)) {
240 ret = 0;
241 break;
242 }
243 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100244 raw_spin_unlock_irqrestore(&desc->lock, flags);
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700245 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
248void register_handler_proc(unsigned int irq, struct irqaction *action)
249{
250 char name [MAX_NAMELEN];
Yinghai Lu08678b02008-08-19 20:50:05 -0700251 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Yinghai Lu08678b02008-08-19 20:50:05 -0700253 if (!desc->dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 !name_unique(irq, action))
255 return;
256
257 memset(name, 0, MAX_NAMELEN);
258 snprintf(name, MAX_NAMELEN, "%s", action->name);
259
260 /* create /proc/irq/1234/handler/ */
Yinghai Lu08678b02008-08-19 20:50:05 -0700261 action->dir = proc_mkdir(name, desc->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
264#undef MAX_NAMELEN
265
266#define MAX_NAMELEN 10
267
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700268void register_irq_proc(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
270 char name [MAX_NAMELEN];
271
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200272 if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip) || desc->dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return;
274
275 memset(name, 0, MAX_NAMELEN);
276 sprintf(name, "%d", irq);
277
278 /* create /proc/irq/1234 */
Yinghai Lu08678b02008-08-19 20:50:05 -0700279 desc->dir = proc_mkdir(name, root_irq_dir);
Cyrill Gorcunovc82a43d2009-10-26 23:28:11 +0300280 if (!desc->dir)
281 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700284 /* create /proc/irq/<irq>/smp_affinity */
Yinghai Lu08678b02008-08-19 20:50:05 -0700285 proc_create_data("smp_affinity", 0600, desc->dir,
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700286 &irq_affinity_proc_fops, (void *)(long)irq);
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800287
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700288 /* create /proc/irq/<irq>/affinity_hint */
289 proc_create_data("affinity_hint", 0400, desc->dir,
290 &irq_affinity_hint_proc_fops, (void *)(long)irq);
291
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800292 proc_create_data("node", 0444, desc->dir,
293 &irq_node_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294#endif
Andi Kleen96d97cf2008-01-30 13:32:48 +0100295
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400296 proc_create_data("spurious", 0444, desc->dir,
297 &irq_spurious_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Thomas Gleixner13bfe992010-09-30 02:46:07 +0200300void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
301{
302 char name [MAX_NAMELEN];
303
304 if (!root_irq_dir || !desc->dir)
305 return;
306#ifdef CONFIG_SMP
307 remove_proc_entry("smp_affinity", desc->dir);
308 remove_proc_entry("affinity_hint", desc->dir);
309 remove_proc_entry("node", desc->dir);
310#endif
311 remove_proc_entry("spurious", desc->dir);
312
313 memset(name, 0, MAX_NAMELEN);
314 sprintf(name, "%u", irq);
315 remove_proc_entry(name, root_irq_dir);
316}
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#undef MAX_NAMELEN
319
320void unregister_handler_proc(unsigned int irq, struct irqaction *action)
321{
Yinghai Lu08678b02008-08-19 20:50:05 -0700322 if (action->dir) {
323 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200324
Yinghai Lu08678b02008-08-19 20:50:05 -0700325 remove_proc_entry(action->dir->name, desc->dir);
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
roel kluin3786fc72008-10-21 19:49:09 -0400329static void register_default_affinity_proc(void)
Max Krasnyansky18404752008-05-29 11:02:52 -0700330{
331#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700332 proc_create("irq/default_smp_affinity", 0600, NULL,
333 &default_affinity_proc_fops);
Max Krasnyansky18404752008-05-29 11:02:52 -0700334#endif
335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337void init_irq_proc(void)
338{
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700339 unsigned int irq;
340 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 /* create /proc/irq */
343 root_irq_dir = proc_mkdir("irq", NULL);
344 if (!root_irq_dir)
345 return;
346
Max Krasnyansky18404752008-05-29 11:02:52 -0700347 register_default_affinity_proc();
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 /*
350 * Create entries for all existing IRQs.
351 */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800352 for_each_irq_desc(irq, desc) {
353 if (!desc)
354 continue;
355
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700356 register_irq_proc(irq, desc);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359