blob: 0832145fea977546db87a1b69887c9b24a685b8c [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>
10#include <linux/proc_fs.h>
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070011#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/interrupt.h>
13
Adrian Bunk97a41e22006-01-08 01:02:17 -080014#include "internals.h"
15
Ingo Molnar4a733ee2006-06-29 02:24:42 -070016static struct proc_dir_entry *root_irq_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#ifdef CONFIG_SMP
19
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070020static int irq_affinity_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
Yinghai Lu08678b02008-08-19 20:50:05 -070022 struct irq_desc *desc = irq_to_desc((long)m->private);
Mike Travis7f7ace02009-01-10 21:58:08 -080023 const struct cpumask *mask = desc->affinity;
Andi Kleen42ee2b72007-07-21 17:09:54 +020024
25#ifdef CONFIG_GENERIC_PENDING_IRQ
26 if (desc->status & IRQ_MOVE_PENDING)
Mike Travis7f7ace02009-01-10 21:58:08 -080027 mask = desc->pending_mask;
Andi Kleen42ee2b72007-07-21 17:09:54 +020028#endif
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070029 seq_cpumask(m, mask);
30 seq_putc(m, '\n');
31 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032}
33
John Keller25d61572007-05-10 22:42:44 -070034#ifndef is_affinity_mask_valid
35#define is_affinity_mask_valid(val) 1
36#endif
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038int no_irq_affinity;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070039static ssize_t irq_affinity_proc_write(struct file *file,
40 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070042 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
Rusty Russell0de26522008-12-13 21:20:26 +103043 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070044 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Yinghai Lu08678b02008-08-19 20:50:05 -070046 if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
Thomas Gleixner950f4422007-02-16 01:27:24 -080047 irq_balancing_disabled(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return -EIO;
49
Rusty Russell0de26522008-12-13 21:20:26 +103050 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
51 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Rusty Russell0de26522008-12-13 21:20:26 +103053 err = cpumask_parse_user(buffer, count, new_value);
54 if (err)
55 goto free_cpumask;
56
Ingo Molnar6bdf1972009-01-03 12:50:46 +010057 if (!is_affinity_mask_valid(new_value)) {
Rusty Russell0de26522008-12-13 21:20:26 +103058 err = -EINVAL;
59 goto free_cpumask;
60 }
John Keller25d61572007-05-10 22:42:44 -070061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /*
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 */
Rusty Russell0de26522008-12-13 21:20:26 +103067 if (!cpumask_intersects(new_value, cpu_online_mask)) {
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080068 /* Special case for empty set - allow the architecture
69 code to set default SMP affinity. */
Rusty Russell0de26522008-12-13 21:20:26 +103070 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
71 } else {
72 irq_set_affinity(irq, new_value);
73 err = count;
74 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Rusty Russell0de26522008-12-13 21:20:26 +103076free_cpumask:
77 free_cpumask_var(new_value);
78 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070081static int irq_affinity_proc_open(struct inode *inode, struct file *file)
Max Krasnyansky18404752008-05-29 11:02:52 -070082{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070083 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
Max Krasnyansky18404752008-05-29 11:02:52 -070084}
85
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070086static 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)
Max Krasnyansky18404752008-05-29 11:02:52 -070095{
Rusty Russelld036e672009-01-01 10:12:26 +103096 seq_cpumask(m, irq_default_affinity);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070097 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)
103{
Rusty Russelld036e672009-01-01 10:12:26 +1030104 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700105 int err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700106
Rusty Russelld036e672009-01-01 10:12:26 +1030107 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
108 return -ENOMEM;
Max Krasnyansky18404752008-05-29 11:02:52 -0700109
Rusty Russelld036e672009-01-01 10:12:26 +1030110 err = cpumask_parse_user(buffer, count, new_value);
111 if (err)
112 goto out;
113
114 if (!is_affinity_mask_valid(new_value)) {
115 err = -EINVAL;
116 goto out;
117 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700118
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 */
Rusty Russelld036e672009-01-01 10:12:26 +1030124 if (!cpumask_intersects(new_value, cpu_online_mask)) {
125 err = -EINVAL;
126 goto out;
127 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700128
Rusty Russelld036e672009-01-01 10:12:26 +1030129 cpumask_copy(irq_default_affinity, new_value);
130 err = count;
Max Krasnyansky18404752008-05-29 11:02:52 -0700131
Rusty Russelld036e672009-01-01 10:12:26 +1030132out:
133 free_cpumask_var(new_value);
134 return err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700135}
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700136
137static int default_affinity_open(struct inode *inode, struct file *file)
138{
Thomas Gleixner34769942009-11-20 11:46:21 +0100139 return single_open(file, default_affinity_show, PDE(inode)->data);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700140}
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};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif
150
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400151static int irq_spurious_proc_show(struct seq_file *m, void *v)
Andi Kleen96d97cf2008-01-30 13:32:48 +0100152{
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400153 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;
Andi Kleen96d97cf2008-01-30 13:32:48 +0100159}
160
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400161static int irq_spurious_proc_open(struct inode *inode, struct file *file)
162{
163 return single_open(file, irq_spurious_proc_show, NULL);
164}
165
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#define MAX_NAMELEN 128
174
175static int name_unique(unsigned int irq, struct irqaction *new_action)
176{
Yinghai Lu08678b02008-08-19 20:50:05 -0700177 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 struct irqaction *action;
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700179 unsigned long flags;
180 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700182 spin_lock_irqsave(&desc->lock, flags);
183 for (action = desc->action ; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 if ((action != new_action) && action->name &&
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700185 !strcmp(new_action->name, action->name)) {
186 ret = 0;
187 break;
188 }
189 }
190 spin_unlock_irqrestore(&desc->lock, flags);
191 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
194void register_handler_proc(unsigned int irq, struct irqaction *action)
195{
196 char name [MAX_NAMELEN];
Yinghai Lu08678b02008-08-19 20:50:05 -0700197 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Yinghai Lu08678b02008-08-19 20:50:05 -0700199 if (!desc->dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 !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/ */
Yinghai Lu08678b02008-08-19 20:50:05 -0700207 action->dir = proc_mkdir(name, desc->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
209
210#undef MAX_NAMELEN
211
212#define MAX_NAMELEN 10
213
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700214void register_irq_proc(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 char name [MAX_NAMELEN];
217
Yinghai Lu08678b02008-08-19 20:50:05 -0700218 if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return;
220
221 memset(name, 0, MAX_NAMELEN);
222 sprintf(name, "%d", irq);
223
224 /* create /proc/irq/1234 */
Yinghai Lu08678b02008-08-19 20:50:05 -0700225 desc->dir = proc_mkdir(name, root_irq_dir);
Cyrill Gorcunovc82a43d2009-10-26 23:28:11 +0300226 if (!desc->dir)
227 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700230 /* create /proc/irq/<irq>/smp_affinity */
Yinghai Lu08678b02008-08-19 20:50:05 -0700231 proc_create_data("smp_affinity", 0600, desc->dir,
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700232 &irq_affinity_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#endif
Andi Kleen96d97cf2008-01-30 13:32:48 +0100234
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400235 proc_create_data("spurious", 0444, desc->dir,
236 &irq_spurious_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
239#undef MAX_NAMELEN
240
241void unregister_handler_proc(unsigned int irq, struct irqaction *action)
242{
Yinghai Lu08678b02008-08-19 20:50:05 -0700243 if (action->dir) {
244 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200245
Yinghai Lu08678b02008-08-19 20:50:05 -0700246 remove_proc_entry(action->dir->name, desc->dir);
247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
roel kluin3786fc72008-10-21 19:49:09 -0400250static void register_default_affinity_proc(void)
Max Krasnyansky18404752008-05-29 11:02:52 -0700251{
252#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700253 proc_create("irq/default_smp_affinity", 0600, NULL,
254 &default_affinity_proc_fops);
Max Krasnyansky18404752008-05-29 11:02:52 -0700255#endif
256}
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258void init_irq_proc(void)
259{
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700260 unsigned int irq;
261 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 /* create /proc/irq */
264 root_irq_dir = proc_mkdir("irq", NULL);
265 if (!root_irq_dir)
266 return;
267
Max Krasnyansky18404752008-05-29 11:02:52 -0700268 register_default_affinity_proc();
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 /*
271 * Create entries for all existing IRQs.
272 */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800273 for_each_irq_desc(irq, desc) {
274 if (!desc)
275 continue;
276
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700277 register_irq_proc(irq, desc);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280