x86, ioapic: Move nr_ioapic_registers calculation to mp_register_ioapic.
[linux/fpc-iii.git] / kernel / irq / proc.c
blob7a6eb04ef6b587b37ca97a127186adfcc812886d
1 /*
2 * linux/kernel/irq/proc.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the /proc/irq/ handling code.
7 */
9 #include <linux/irq.h>
10 #include <linux/gfp.h>
11 #include <linux/proc_fs.h>
12 #include <linux/seq_file.h>
13 #include <linux/interrupt.h>
15 #include "internals.h"
17 static struct proc_dir_entry *root_irq_dir;
19 #ifdef CONFIG_SMP
21 static int irq_affinity_proc_show(struct seq_file *m, void *v)
23 struct irq_desc *desc = irq_to_desc((long)m->private);
24 const struct cpumask *mask = desc->affinity;
26 #ifdef CONFIG_GENERIC_PENDING_IRQ
27 if (desc->status & IRQ_MOVE_PENDING)
28 mask = desc->pending_mask;
29 #endif
30 seq_cpumask(m, mask);
31 seq_putc(m, '\n');
32 return 0;
35 #ifndef is_affinity_mask_valid
36 #define is_affinity_mask_valid(val) 1
37 #endif
39 int no_irq_affinity;
40 static ssize_t irq_affinity_proc_write(struct file *file,
41 const char __user *buffer, size_t count, loff_t *pos)
43 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
44 cpumask_var_t new_value;
45 int err;
47 if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
48 irq_balancing_disabled(irq))
49 return -EIO;
51 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
52 return -ENOMEM;
54 err = cpumask_parse_user(buffer, count, new_value);
55 if (err)
56 goto free_cpumask;
58 if (!is_affinity_mask_valid(new_value)) {
59 err = -EINVAL;
60 goto free_cpumask;
64 * Do not allow disabling IRQs completely - it's a too easy
65 * way to make the system unusable accidentally :-) At least
66 * one online CPU still has to be targeted.
68 if (!cpumask_intersects(new_value, cpu_online_mask)) {
69 /* Special case for empty set - allow the architecture
70 code to set default SMP affinity. */
71 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
72 } else {
73 irq_set_affinity(irq, new_value);
74 err = count;
77 free_cpumask:
78 free_cpumask_var(new_value);
79 return err;
82 static int irq_affinity_proc_open(struct inode *inode, struct file *file)
84 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
87 static const struct file_operations irq_affinity_proc_fops = {
88 .open = irq_affinity_proc_open,
89 .read = seq_read,
90 .llseek = seq_lseek,
91 .release = single_release,
92 .write = irq_affinity_proc_write,
95 static int default_affinity_show(struct seq_file *m, void *v)
97 seq_cpumask(m, irq_default_affinity);
98 seq_putc(m, '\n');
99 return 0;
102 static ssize_t default_affinity_write(struct file *file,
103 const char __user *buffer, size_t count, loff_t *ppos)
105 cpumask_var_t new_value;
106 int err;
108 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
109 return -ENOMEM;
111 err = cpumask_parse_user(buffer, count, new_value);
112 if (err)
113 goto out;
115 if (!is_affinity_mask_valid(new_value)) {
116 err = -EINVAL;
117 goto out;
121 * Do not allow disabling IRQs completely - it's a too easy
122 * way to make the system unusable accidentally :-) At least
123 * one online CPU still has to be targeted.
125 if (!cpumask_intersects(new_value, cpu_online_mask)) {
126 err = -EINVAL;
127 goto out;
130 cpumask_copy(irq_default_affinity, new_value);
131 err = count;
133 out:
134 free_cpumask_var(new_value);
135 return err;
138 static int default_affinity_open(struct inode *inode, struct file *file)
140 return single_open(file, default_affinity_show, PDE(inode)->data);
143 static const struct file_operations default_affinity_proc_fops = {
144 .open = default_affinity_open,
145 .read = seq_read,
146 .llseek = seq_lseek,
147 .release = single_release,
148 .write = default_affinity_write,
150 #endif
152 static int irq_spurious_proc_show(struct seq_file *m, void *v)
154 struct irq_desc *desc = irq_to_desc((long) m->private);
156 seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
157 desc->irq_count, desc->irqs_unhandled,
158 jiffies_to_msecs(desc->last_unhandled));
159 return 0;
162 static int irq_spurious_proc_open(struct inode *inode, struct file *file)
164 return single_open(file, irq_spurious_proc_show, NULL);
167 static const struct file_operations irq_spurious_proc_fops = {
168 .open = irq_spurious_proc_open,
169 .read = seq_read,
170 .llseek = seq_lseek,
171 .release = single_release,
174 #define MAX_NAMELEN 128
176 static int name_unique(unsigned int irq, struct irqaction *new_action)
178 struct irq_desc *desc = irq_to_desc(irq);
179 struct irqaction *action;
180 unsigned long flags;
181 int ret = 1;
183 raw_spin_lock_irqsave(&desc->lock, flags);
184 for (action = desc->action ; action; action = action->next) {
185 if ((action != new_action) && action->name &&
186 !strcmp(new_action->name, action->name)) {
187 ret = 0;
188 break;
191 raw_spin_unlock_irqrestore(&desc->lock, flags);
192 return ret;
195 void register_handler_proc(unsigned int irq, struct irqaction *action)
197 char name [MAX_NAMELEN];
198 struct irq_desc *desc = irq_to_desc(irq);
200 if (!desc->dir || action->dir || !action->name ||
201 !name_unique(irq, action))
202 return;
204 memset(name, 0, MAX_NAMELEN);
205 snprintf(name, MAX_NAMELEN, "%s", action->name);
207 /* create /proc/irq/1234/handler/ */
208 action->dir = proc_mkdir(name, desc->dir);
211 #undef MAX_NAMELEN
213 #define MAX_NAMELEN 10
215 void register_irq_proc(unsigned int irq, struct irq_desc *desc)
217 char name [MAX_NAMELEN];
219 if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
220 return;
222 memset(name, 0, MAX_NAMELEN);
223 sprintf(name, "%d", irq);
225 /* create /proc/irq/1234 */
226 desc->dir = proc_mkdir(name, root_irq_dir);
227 if (!desc->dir)
228 return;
230 #ifdef CONFIG_SMP
231 /* create /proc/irq/<irq>/smp_affinity */
232 proc_create_data("smp_affinity", 0600, desc->dir,
233 &irq_affinity_proc_fops, (void *)(long)irq);
234 #endif
236 proc_create_data("spurious", 0444, desc->dir,
237 &irq_spurious_proc_fops, (void *)(long)irq);
240 #undef MAX_NAMELEN
242 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
244 if (action->dir) {
245 struct irq_desc *desc = irq_to_desc(irq);
247 remove_proc_entry(action->dir->name, desc->dir);
251 static void register_default_affinity_proc(void)
253 #ifdef CONFIG_SMP
254 proc_create("irq/default_smp_affinity", 0600, NULL,
255 &default_affinity_proc_fops);
256 #endif
259 void init_irq_proc(void)
261 unsigned int irq;
262 struct irq_desc *desc;
264 /* create /proc/irq */
265 root_irq_dir = proc_mkdir("irq", NULL);
266 if (!root_irq_dir)
267 return;
269 register_default_affinity_proc();
272 * Create entries for all existing IRQs.
274 for_each_irq_desc(irq, desc) {
275 if (!desc)
276 continue;
278 register_irq_proc(irq, desc);