blob: 26449239bb46b04448834d0d71b16c459998b182 [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>
Thomas Gleixnerc78b9b62010-12-16 17:21:47 +010014#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Adrian Bunk97a41e22006-01-08 01:02:17 -080016#include "internals.h"
17
Ingo Molnar4a733ee2006-06-29 02:24:42 -070018static struct proc_dir_entry *root_irq_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#ifdef CONFIG_SMP
21
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070022static int irq_affinity_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
Yinghai Lu08678b02008-08-19 20:50:05 -070024 struct irq_desc *desc = irq_to_desc((long)m->private);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020025 const struct cpumask *mask = desc->irq_data.affinity;
Andi Kleen42ee2b72007-07-21 17:09:54 +020026
27#ifdef CONFIG_GENERIC_PENDING_IRQ
28 if (desc->status & IRQ_MOVE_PENDING)
Mike Travis7f7ace02009-01-10 21:58:08 -080029 mask = desc->pending_mask;
Andi Kleen42ee2b72007-07-21 17:09:54 +020030#endif
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070031 seq_cpumask(m, mask);
32 seq_putc(m, '\n');
33 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -070036static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
37{
38 struct irq_desc *desc = irq_to_desc((long)m->private);
39 unsigned long flags;
40 cpumask_var_t mask;
41
Peter P Waskiewicz Jr4308ad82010-05-05 13:56:42 -070042 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -070043 return -ENOMEM;
44
45 raw_spin_lock_irqsave(&desc->lock, flags);
46 if (desc->affinity_hint)
47 cpumask_copy(mask, desc->affinity_hint);
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -070048 raw_spin_unlock_irqrestore(&desc->lock, flags);
49
50 seq_cpumask(m, mask);
51 seq_putc(m, '\n');
52 free_cpumask_var(mask);
53
54 return 0;
55}
56
John Keller25d61572007-05-10 22:42:44 -070057#ifndef is_affinity_mask_valid
58#define is_affinity_mask_valid(val) 1
59#endif
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061int no_irq_affinity;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070062static ssize_t irq_affinity_proc_write(struct file *file,
63 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070065 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
Rusty Russell0de26522008-12-13 21:20:26 +103066 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070067 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Thomas Gleixnerc96b3b32010-09-27 12:45:41 +000069 if (!irq_to_desc(irq)->irq_data.chip->irq_set_affinity || no_irq_affinity ||
Thomas Gleixner950f4422007-02-16 01:27:24 -080070 irq_balancing_disabled(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 return -EIO;
72
Rusty Russell0de26522008-12-13 21:20:26 +103073 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
74 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Rusty Russell0de26522008-12-13 21:20:26 +103076 err = cpumask_parse_user(buffer, count, new_value);
77 if (err)
78 goto free_cpumask;
79
Ingo Molnar6bdf1972009-01-03 12:50:46 +010080 if (!is_affinity_mask_valid(new_value)) {
Rusty Russell0de26522008-12-13 21:20:26 +103081 err = -EINVAL;
82 goto free_cpumask;
83 }
John Keller25d61572007-05-10 22:42:44 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 /*
86 * Do not allow disabling IRQs completely - it's a too easy
87 * way to make the system unusable accidentally :-) At least
88 * one online CPU still has to be targeted.
89 */
Rusty Russell0de26522008-12-13 21:20:26 +103090 if (!cpumask_intersects(new_value, cpu_online_mask)) {
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080091 /* Special case for empty set - allow the architecture
92 code to set default SMP affinity. */
Thomas Gleixner3b8249e2011-02-07 16:02:20 +010093 err = irq_select_affinity_usr(irq, new_value) ? -EINVAL : count;
Rusty Russell0de26522008-12-13 21:20:26 +103094 } else {
95 irq_set_affinity(irq, new_value);
96 err = count;
97 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Rusty Russell0de26522008-12-13 21:20:26 +103099free_cpumask:
100 free_cpumask_var(new_value);
101 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700104static int irq_affinity_proc_open(struct inode *inode, struct file *file)
Max Krasnyansky18404752008-05-29 11:02:52 -0700105{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700106 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
Max Krasnyansky18404752008-05-29 11:02:52 -0700107}
108
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700109static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
110{
111 return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data);
112}
113
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700114static const struct file_operations irq_affinity_proc_fops = {
115 .open = irq_affinity_proc_open,
116 .read = seq_read,
117 .llseek = seq_lseek,
118 .release = single_release,
119 .write = irq_affinity_proc_write,
120};
121
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700122static const struct file_operations irq_affinity_hint_proc_fops = {
123 .open = irq_affinity_hint_proc_open,
124 .read = seq_read,
125 .llseek = seq_lseek,
126 .release = single_release,
127};
128
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700129static int default_affinity_show(struct seq_file *m, void *v)
Max Krasnyansky18404752008-05-29 11:02:52 -0700130{
Rusty Russelld036e672009-01-01 10:12:26 +1030131 seq_cpumask(m, irq_default_affinity);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700132 seq_putc(m, '\n');
133 return 0;
134}
135
136static ssize_t default_affinity_write(struct file *file,
137 const char __user *buffer, size_t count, loff_t *ppos)
138{
Rusty Russelld036e672009-01-01 10:12:26 +1030139 cpumask_var_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700140 int err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700141
Rusty Russelld036e672009-01-01 10:12:26 +1030142 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
143 return -ENOMEM;
Max Krasnyansky18404752008-05-29 11:02:52 -0700144
Rusty Russelld036e672009-01-01 10:12:26 +1030145 err = cpumask_parse_user(buffer, count, new_value);
146 if (err)
147 goto out;
148
149 if (!is_affinity_mask_valid(new_value)) {
150 err = -EINVAL;
151 goto out;
152 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700153
154 /*
155 * Do not allow disabling IRQs completely - it's a too easy
156 * way to make the system unusable accidentally :-) At least
157 * one online CPU still has to be targeted.
158 */
Rusty Russelld036e672009-01-01 10:12:26 +1030159 if (!cpumask_intersects(new_value, cpu_online_mask)) {
160 err = -EINVAL;
161 goto out;
162 }
Max Krasnyansky18404752008-05-29 11:02:52 -0700163
Rusty Russelld036e672009-01-01 10:12:26 +1030164 cpumask_copy(irq_default_affinity, new_value);
165 err = count;
Max Krasnyansky18404752008-05-29 11:02:52 -0700166
Rusty Russelld036e672009-01-01 10:12:26 +1030167out:
168 free_cpumask_var(new_value);
169 return err;
Max Krasnyansky18404752008-05-29 11:02:52 -0700170}
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700171
172static int default_affinity_open(struct inode *inode, struct file *file)
173{
Thomas Gleixner34769942009-11-20 11:46:21 +0100174 return single_open(file, default_affinity_show, PDE(inode)->data);
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700175}
176
177static const struct file_operations default_affinity_proc_fops = {
178 .open = default_affinity_open,
179 .read = seq_read,
180 .llseek = seq_lseek,
181 .release = single_release,
182 .write = default_affinity_write,
183};
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800184
185static int irq_node_proc_show(struct seq_file *m, void *v)
186{
187 struct irq_desc *desc = irq_to_desc((long) m->private);
188
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200189 seq_printf(m, "%d\n", desc->irq_data.node);
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800190 return 0;
191}
192
193static int irq_node_proc_open(struct inode *inode, struct file *file)
194{
195 return single_open(file, irq_node_proc_show, PDE(inode)->data);
196}
197
198static const struct file_operations irq_node_proc_fops = {
199 .open = irq_node_proc_open,
200 .read = seq_read,
201 .llseek = seq_lseek,
202 .release = single_release,
203};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#endif
205
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400206static int irq_spurious_proc_show(struct seq_file *m, void *v)
Andi Kleen96d97cf2008-01-30 13:32:48 +0100207{
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400208 struct irq_desc *desc = irq_to_desc((long) m->private);
209
210 seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
211 desc->irq_count, desc->irqs_unhandled,
212 jiffies_to_msecs(desc->last_unhandled));
213 return 0;
Andi Kleen96d97cf2008-01-30 13:32:48 +0100214}
215
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400216static int irq_spurious_proc_open(struct inode *inode, struct file *file)
217{
Kenji Kaneshige25c91702010-11-30 17:36:08 +0900218 return single_open(file, irq_spurious_proc_show, PDE(inode)->data);
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400219}
220
221static const struct file_operations irq_spurious_proc_fops = {
222 .open = irq_spurious_proc_open,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = single_release,
226};
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#define MAX_NAMELEN 128
229
230static int name_unique(unsigned int irq, struct irqaction *new_action)
231{
Yinghai Lu08678b02008-08-19 20:50:05 -0700232 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 struct irqaction *action;
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700234 unsigned long flags;
235 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Thomas Gleixner239007b2009-11-17 16:46:45 +0100237 raw_spin_lock_irqsave(&desc->lock, flags);
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700238 for (action = desc->action ; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if ((action != new_action) && action->name &&
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700240 !strcmp(new_action->name, action->name)) {
241 ret = 0;
242 break;
243 }
244 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100245 raw_spin_unlock_irqrestore(&desc->lock, flags);
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700246 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
249void register_handler_proc(unsigned int irq, struct irqaction *action)
250{
251 char name [MAX_NAMELEN];
Yinghai Lu08678b02008-08-19 20:50:05 -0700252 struct irq_desc *desc = irq_to_desc(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Yinghai Lu08678b02008-08-19 20:50:05 -0700254 if (!desc->dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 !name_unique(irq, action))
256 return;
257
258 memset(name, 0, MAX_NAMELEN);
259 snprintf(name, MAX_NAMELEN, "%s", action->name);
260
261 /* create /proc/irq/1234/handler/ */
Yinghai Lu08678b02008-08-19 20:50:05 -0700262 action->dir = proc_mkdir(name, desc->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
265#undef MAX_NAMELEN
266
267#define MAX_NAMELEN 10
268
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700269void register_irq_proc(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
271 char name [MAX_NAMELEN];
272
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200273 if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip) || desc->dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return;
275
276 memset(name, 0, MAX_NAMELEN);
277 sprintf(name, "%d", irq);
278
279 /* create /proc/irq/1234 */
Yinghai Lu08678b02008-08-19 20:50:05 -0700280 desc->dir = proc_mkdir(name, root_irq_dir);
Cyrill Gorcunovc82a43d2009-10-26 23:28:11 +0300281 if (!desc->dir)
282 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700285 /* create /proc/irq/<irq>/smp_affinity */
Yinghai Lu08678b02008-08-19 20:50:05 -0700286 proc_create_data("smp_affinity", 0600, desc->dir,
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700287 &irq_affinity_proc_fops, (void *)(long)irq);
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800288
Peter P Waskiewicz Jre7a297b2010-04-30 14:44:50 -0700289 /* create /proc/irq/<irq>/affinity_hint */
290 proc_create_data("affinity_hint", 0400, desc->dir,
291 &irq_affinity_hint_proc_fops, (void *)(long)irq);
292
Dimitri Sivanich92d6b712010-03-11 14:08:56 -0800293 proc_create_data("node", 0444, desc->dir,
294 &irq_node_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295#endif
Andi Kleen96d97cf2008-01-30 13:32:48 +0100296
Alexey Dobriyana1afb632009-08-28 22:19:33 +0400297 proc_create_data("spurious", 0444, desc->dir,
298 &irq_spurious_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Thomas Gleixner13bfe992010-09-30 02:46:07 +0200301void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
302{
303 char name [MAX_NAMELEN];
304
305 if (!root_irq_dir || !desc->dir)
306 return;
307#ifdef CONFIG_SMP
308 remove_proc_entry("smp_affinity", desc->dir);
309 remove_proc_entry("affinity_hint", desc->dir);
310 remove_proc_entry("node", desc->dir);
311#endif
312 remove_proc_entry("spurious", desc->dir);
313
314 memset(name, 0, MAX_NAMELEN);
315 sprintf(name, "%u", irq);
316 remove_proc_entry(name, root_irq_dir);
317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#undef MAX_NAMELEN
320
321void unregister_handler_proc(unsigned int irq, struct irqaction *action)
322{
Yinghai Lu08678b02008-08-19 20:50:05 -0700323 if (action->dir) {
324 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200325
Yinghai Lu08678b02008-08-19 20:50:05 -0700326 remove_proc_entry(action->dir->name, desc->dir);
327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
329
roel kluin3786fc72008-10-21 19:49:09 -0400330static void register_default_affinity_proc(void)
Max Krasnyansky18404752008-05-29 11:02:52 -0700331{
332#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700333 proc_create("irq/default_smp_affinity", 0600, NULL,
334 &default_affinity_proc_fops);
Max Krasnyansky18404752008-05-29 11:02:52 -0700335#endif
336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338void init_irq_proc(void)
339{
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700340 unsigned int irq;
341 struct irq_desc *desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /* create /proc/irq */
344 root_irq_dir = proc_mkdir("irq", NULL);
345 if (!root_irq_dir)
346 return;
347
Max Krasnyansky18404752008-05-29 11:02:52 -0700348 register_default_affinity_proc();
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 /*
351 * Create entries for all existing IRQs.
352 */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800353 for_each_irq_desc(irq, desc) {
354 if (!desc)
355 continue;
356
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700357 register_irq_proc(irq, desc);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Thomas Gleixnerc78b9b62010-12-16 17:21:47 +0100361#ifdef CONFIG_GENERIC_IRQ_SHOW
362
363int __weak arch_show_interrupts(struct seq_file *p, int prec)
364{
365 return 0;
366}
367
368int show_interrupts(struct seq_file *p, void *v)
369{
370 static int prec;
371
372 unsigned long flags, any_count = 0;
373 int i = *(loff_t *) v, j;
374 struct irqaction *action;
375 struct irq_desc *desc;
376
377 if (i > nr_irqs)
378 return 0;
379
380 if (i == nr_irqs)
381 return arch_show_interrupts(p, prec);
382
383 /* print header and calculate the width of the first column */
384 if (i == 0) {
385 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
386 j *= 10;
387
388 seq_printf(p, "%*s", prec + 8, "");
389 for_each_online_cpu(j)
390 seq_printf(p, "CPU%-8d", j);
391 seq_putc(p, '\n');
392 }
393
394 desc = irq_to_desc(i);
395 if (!desc)
396 return 0;
397
398 raw_spin_lock_irqsave(&desc->lock, flags);
399 for_each_online_cpu(j)
400 any_count |= kstat_irqs_cpu(i, j);
401 action = desc->action;
402 if (!action && !any_count)
403 goto out;
404
405 seq_printf(p, "%*d: ", prec, i);
406 for_each_online_cpu(j)
407 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
408 seq_printf(p, " %8s", desc->irq_data.chip->name);
409 seq_printf(p, "-%-8s", desc->name);
410
411 if (action) {
412 seq_printf(p, " %s", action->name);
413 while ((action = action->next) != NULL)
414 seq_printf(p, ", %s", action->name);
415 }
416
417 seq_putc(p, '\n');
418out:
419 raw_spin_unlock_irqrestore(&desc->lock, flags);
420 return 0;
421}
422#endif