blob: c2f2ccb0549a18a8552e0c8a018a198e4c70195e [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>
11#include <linux/interrupt.h>
12
Adrian Bunk97a41e22006-01-08 01:02:17 -080013#include "internals.h"
14
Ingo Molnar4a733ee2006-06-29 02:24:42 -070015static struct proc_dir_entry *root_irq_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#ifdef CONFIG_SMP
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019static int irq_affinity_read_proc(char *page, char **start, off_t off,
20 int count, int *eof, void *data)
21{
Andi Kleen42ee2b72007-07-21 17:09:54 +020022 struct irq_desc *desc = irq_desc + (long)data;
23 cpumask_t *mask = &desc->affinity;
24 int len;
25
26#ifdef CONFIG_GENERIC_PENDING_IRQ
27 if (desc->status & IRQ_MOVE_PENDING)
28 mask = &desc->pending_mask;
29#endif
30 len = cpumask_scnprintf(page, count, *mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32 if (count - len < 2)
33 return -EINVAL;
34 len += sprintf(page + len, "\n");
35 return len;
36}
37
John Keller25d61572007-05-10 22:42:44 -070038#ifndef is_affinity_mask_valid
39#define is_affinity_mask_valid(val) 1
40#endif
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042int no_irq_affinity;
43static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
44 unsigned long count, void *data)
45{
46 unsigned int irq = (int)(long)data, full_count = count, err;
47 cpumask_t new_value, tmp;
48
Hidetoshi Seto6e2ac662006-12-08 02:35:58 -080049 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
Thomas Gleixner950f4422007-02-16 01:27:24 -080050 irq_balancing_disabled(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 return -EIO;
52
Reinette Chatre01a3ee22006-10-11 01:21:55 -070053 err = cpumask_parse_user(buffer, count, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 if (err)
55 return err;
56
John Keller25d61572007-05-10 22:42:44 -070057 if (!is_affinity_mask_valid(new_value))
58 return -EINVAL;
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 /*
61 * Do not allow disabling IRQs completely - it's a too easy
62 * way to make the system unusable accidentally :-) At least
63 * one online CPU still has to be targeted.
64 */
65 cpus_and(tmp, new_value, cpu_online_map);
66 if (cpus_empty(tmp))
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080067 /* Special case for empty set - allow the architecture
68 code to set default SMP affinity. */
69 return select_smp_affinity(irq) ? -EINVAL : full_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Thomas Gleixner771ee3b2007-02-16 01:27:25 -080071 irq_set_affinity(irq, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 return full_count;
74}
75
76#endif
77
Andi Kleen96d97cf2008-01-30 13:32:48 +010078static int irq_spurious_read(char *page, char **start, off_t off,
79 int count, int *eof, void *data)
80{
81 struct irq_desc *d = &irq_desc[(long) data];
82 return sprintf(page, "count %u\n"
83 "unhandled %u\n"
84 "last_unhandled %u ms\n",
85 d->irq_count,
86 d->irqs_unhandled,
87 jiffies_to_msecs(d->last_unhandled));
88}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define MAX_NAMELEN 128
91
92static int name_unique(unsigned int irq, struct irqaction *new_action)
93{
94 struct irq_desc *desc = irq_desc + irq;
95 struct irqaction *action;
Dmitry Adamushkod2d94332007-05-08 00:27:31 -070096 unsigned long flags;
97 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Dmitry Adamushkod2d94332007-05-08 00:27:31 -070099 spin_lock_irqsave(&desc->lock, flags);
100 for (action = desc->action ; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 if ((action != new_action) && action->name &&
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700102 !strcmp(new_action->name, action->name)) {
103 ret = 0;
104 break;
105 }
106 }
107 spin_unlock_irqrestore(&desc->lock, flags);
108 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
111void register_handler_proc(unsigned int irq, struct irqaction *action)
112{
113 char name [MAX_NAMELEN];
114
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700115 if (!irq_desc[irq].dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 !name_unique(irq, action))
117 return;
118
119 memset(name, 0, MAX_NAMELEN);
120 snprintf(name, MAX_NAMELEN, "%s", action->name);
121
122 /* create /proc/irq/1234/handler/ */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700123 action->dir = proc_mkdir(name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
126#undef MAX_NAMELEN
127
128#define MAX_NAMELEN 10
129
130void register_irq_proc(unsigned int irq)
131{
132 char name [MAX_NAMELEN];
Andi Kleen96d97cf2008-01-30 13:32:48 +0100133 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 if (!root_irq_dir ||
Ingo Molnarf1c26622006-06-29 02:24:57 -0700136 (irq_desc[irq].chip == &no_irq_chip) ||
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700137 irq_desc[irq].dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return;
139
140 memset(name, 0, MAX_NAMELEN);
141 sprintf(name, "%d", irq);
142
143 /* create /proc/irq/1234 */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700144 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146#ifdef CONFIG_SMP
147 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /* create /proc/irq/<irq>/smp_affinity */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700149 entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 if (entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 entry->data = (void *)(long)irq;
153 entry->read_proc = irq_affinity_read_proc;
154 entry->write_proc = irq_affinity_write_proc;
155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157#endif
Andi Kleen96d97cf2008-01-30 13:32:48 +0100158
159 entry = create_proc_entry("spurious", 0444, irq_desc[irq].dir);
160 if (entry) {
161 entry->data = (void *)(long)irq;
162 entry->read_proc = irq_spurious_read;
163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
166#undef MAX_NAMELEN
167
168void unregister_handler_proc(unsigned int irq, struct irqaction *action)
169{
170 if (action->dir)
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700171 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
174void init_irq_proc(void)
175{
176 int i;
177
178 /* create /proc/irq */
179 root_irq_dir = proc_mkdir("irq", NULL);
180 if (!root_irq_dir)
181 return;
182
183 /*
184 * Create entries for all existing IRQs.
185 */
186 for (i = 0; i < NR_IRQS; i++)
187 register_irq_proc(i);
188}
189