blob: a09dd29c2fd748dea1dd83fd00b73751aa649316 [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{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070022 struct irq_desc *desc = irq_desc + (long)m->private;
Andi Kleen42ee2b72007-07-21 17:09:54 +020023 cpumask_t *mask = &desc->affinity;
Andi Kleen42ee2b72007-07-21 17:09:54 +020024
25#ifdef CONFIG_GENERIC_PENDING_IRQ
26 if (desc->status & IRQ_MOVE_PENDING)
27 mask = &desc->pending_mask;
28#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;
Max Krasnyansky18404752008-05-29 11:02:52 -070043 cpumask_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070044 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Hidetoshi Seto6e2ac662006-12-08 02:35:58 -080046 if (!irq_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
Reinette Chatre01a3ee22006-10-11 01:21:55 -070050 err = cpumask_parse_user(buffer, count, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 if (err)
52 return err;
53
John Keller25d61572007-05-10 22:42:44 -070054 if (!is_affinity_mask_valid(new_value))
55 return -EINVAL;
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 /*
58 * Do not allow disabling IRQs completely - it's a too easy
59 * way to make the system unusable accidentally :-) At least
60 * one online CPU still has to be targeted.
61 */
Max Krasnyansky18404752008-05-29 11:02:52 -070062 if (!cpus_intersects(new_value, cpu_online_map))
Ivan Kokshayskyeee45262006-01-06 00:12:21 -080063 /* Special case for empty set - allow the architecture
64 code to set default SMP affinity. */
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070065 return irq_select_affinity(irq) ? -EINVAL : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Thomas Gleixner771ee3b2007-02-16 01:27:25 -080067 irq_set_affinity(irq, new_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070069 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070072static int irq_affinity_proc_open(struct inode *inode, struct file *file)
Max Krasnyansky18404752008-05-29 11:02:52 -070073{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070074 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
Max Krasnyansky18404752008-05-29 11:02:52 -070075}
76
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070077static const struct file_operations irq_affinity_proc_fops = {
78 .open = irq_affinity_proc_open,
79 .read = seq_read,
80 .llseek = seq_lseek,
81 .release = single_release,
82 .write = irq_affinity_proc_write,
83};
84
85static int default_affinity_show(struct seq_file *m, void *v)
Max Krasnyansky18404752008-05-29 11:02:52 -070086{
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070087 seq_cpumask(m, &irq_default_affinity);
88 seq_putc(m, '\n');
89 return 0;
90}
91
92static ssize_t default_affinity_write(struct file *file,
93 const char __user *buffer, size_t count, loff_t *ppos)
94{
Max Krasnyansky18404752008-05-29 11:02:52 -070095 cpumask_t new_value;
Alexey Dobriyanf18e4392008-08-12 15:09:03 -070096 int err;
Max Krasnyansky18404752008-05-29 11:02:52 -070097
98 err = cpumask_parse_user(buffer, count, new_value);
99 if (err)
100 return err;
101
102 if (!is_affinity_mask_valid(new_value))
103 return -EINVAL;
104
105 /*
106 * Do not allow disabling IRQs completely - it's a too easy
107 * way to make the system unusable accidentally :-) At least
108 * one online CPU still has to be targeted.
109 */
110 if (!cpus_intersects(new_value, cpu_online_map))
111 return -EINVAL;
112
113 irq_default_affinity = new_value;
114
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700115 return count;
Max Krasnyansky18404752008-05-29 11:02:52 -0700116}
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700117
118static int default_affinity_open(struct inode *inode, struct file *file)
119{
120 return single_open(file, default_affinity_show, NULL);
121}
122
123static const struct file_operations default_affinity_proc_fops = {
124 .open = default_affinity_open,
125 .read = seq_read,
126 .llseek = seq_lseek,
127 .release = single_release,
128 .write = default_affinity_write,
129};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#endif
131
Andi Kleen96d97cf2008-01-30 13:32:48 +0100132static int irq_spurious_read(char *page, char **start, off_t off,
133 int count, int *eof, void *data)
134{
135 struct irq_desc *d = &irq_desc[(long) data];
136 return sprintf(page, "count %u\n"
137 "unhandled %u\n"
138 "last_unhandled %u ms\n",
139 d->irq_count,
140 d->irqs_unhandled,
141 jiffies_to_msecs(d->last_unhandled));
142}
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#define MAX_NAMELEN 128
145
146static int name_unique(unsigned int irq, struct irqaction *new_action)
147{
148 struct irq_desc *desc = irq_desc + irq;
149 struct irqaction *action;
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700150 unsigned long flags;
151 int ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700153 spin_lock_irqsave(&desc->lock, flags);
154 for (action = desc->action ; action; action = action->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if ((action != new_action) && action->name &&
Dmitry Adamushkod2d94332007-05-08 00:27:31 -0700156 !strcmp(new_action->name, action->name)) {
157 ret = 0;
158 break;
159 }
160 }
161 spin_unlock_irqrestore(&desc->lock, flags);
162 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165void register_handler_proc(unsigned int irq, struct irqaction *action)
166{
167 char name [MAX_NAMELEN];
168
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700169 if (!irq_desc[irq].dir || action->dir || !action->name ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 !name_unique(irq, action))
171 return;
172
173 memset(name, 0, MAX_NAMELEN);
174 snprintf(name, MAX_NAMELEN, "%s", action->name);
175
176 /* create /proc/irq/1234/handler/ */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700177 action->dir = proc_mkdir(name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
180#undef MAX_NAMELEN
181
182#define MAX_NAMELEN 10
183
184void register_irq_proc(unsigned int irq)
185{
186 char name [MAX_NAMELEN];
Andi Kleen96d97cf2008-01-30 13:32:48 +0100187 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 if (!root_irq_dir ||
Ingo Molnarf1c26622006-06-29 02:24:57 -0700190 (irq_desc[irq].chip == &no_irq_chip) ||
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700191 irq_desc[irq].dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return;
193
194 memset(name, 0, MAX_NAMELEN);
195 sprintf(name, "%d", irq);
196
197 /* create /proc/irq/1234 */
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700198 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700201 /* create /proc/irq/<irq>/smp_affinity */
202 proc_create_data("smp_affinity", 0600, irq_desc[irq].dir,
203 &irq_affinity_proc_fops, (void *)(long)irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#endif
Andi Kleen96d97cf2008-01-30 13:32:48 +0100205
206 entry = create_proc_entry("spurious", 0444, irq_desc[irq].dir);
207 if (entry) {
208 entry->data = (void *)(long)irq;
209 entry->read_proc = irq_spurious_read;
210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
213#undef MAX_NAMELEN
214
215void unregister_handler_proc(unsigned int irq, struct irqaction *action)
216{
217 if (action->dir)
Ingo Molnar4a733ee2006-06-29 02:24:42 -0700218 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
Max Krasnyansky18404752008-05-29 11:02:52 -0700221void register_default_affinity_proc(void)
222{
223#ifdef CONFIG_SMP
Alexey Dobriyanf18e4392008-08-12 15:09:03 -0700224 proc_create("irq/default_smp_affinity", 0600, NULL,
225 &default_affinity_proc_fops);
Max Krasnyansky18404752008-05-29 11:02:52 -0700226#endif
227}
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229void init_irq_proc(void)
230{
231 int i;
232
233 /* create /proc/irq */
234 root_irq_dir = proc_mkdir("irq", NULL);
235 if (!root_irq_dir)
236 return;
237
Max Krasnyansky18404752008-05-29 11:02:52 -0700238 register_default_affinity_proc();
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 /*
241 * Create entries for all existing IRQs.
242 */
243 for (i = 0; i < NR_IRQS; i++)
244 register_irq_proc(i);
245}
246