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.
10 #include <linux/gfp.h>
11 #include <linux/proc_fs.h>
12 #include <linux/seq_file.h>
13 #include <linux/interrupt.h>
14 #include <linux/kernel_stat.h>
16 #include "internals.h"
18 static struct proc_dir_entry *root_irq_dir;
22 static int irq_affinity_proc_show(struct seq_file *m, void *v)
24 struct irq_desc *desc = irq_to_desc((long)m->private);
25 const struct cpumask *mask = desc->irq_data.affinity;
27 #ifdef CONFIG_GENERIC_PENDING_IRQ
28 if (irqd_is_setaffinity_pending(&desc->irq_data))
29 mask = desc->pending_mask;
36 static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
38 struct irq_desc *desc = irq_to_desc((long)m->private);
42 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
45 raw_spin_lock_irqsave(&desc->lock, flags);
46 if (desc->affinity_hint)
47 cpumask_copy(mask, desc->affinity_hint);
48 raw_spin_unlock_irqrestore(&desc->lock, flags);
52 free_cpumask_var(mask);
57 #ifndef is_affinity_mask_valid
58 #define is_affinity_mask_valid(val) 1
62 static ssize_t irq_affinity_proc_write(struct file *file,
63 const char __user *buffer, size_t count, loff_t *pos)
65 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
66 cpumask_var_t new_value;
69 if (!irq_to_desc(irq)->irq_data.chip->irq_set_affinity || no_irq_affinity ||
70 irq_balancing_disabled(irq))
73 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
76 err = cpumask_parse_user(buffer, count, new_value);
80 if (!is_affinity_mask_valid(new_value)) {
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.
90 if (!cpumask_intersects(new_value, cpu_online_mask)) {
91 /* Special case for empty set - allow the architecture
92 code to set default SMP affinity. */
93 err = irq_select_affinity_usr(irq, new_value) ? -EINVAL : count;
95 irq_set_affinity(irq, new_value);
100 free_cpumask_var(new_value);
104 static int irq_affinity_proc_open(struct inode *inode, struct file *file)
106 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
109 static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
111 return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data);
114 static const struct file_operations irq_affinity_proc_fops = {
115 .open = irq_affinity_proc_open,
118 .release = single_release,
119 .write = irq_affinity_proc_write,
122 static const struct file_operations irq_affinity_hint_proc_fops = {
123 .open = irq_affinity_hint_proc_open,
126 .release = single_release,
129 static int default_affinity_show(struct seq_file *m, void *v)
131 seq_cpumask(m, irq_default_affinity);
136 static ssize_t default_affinity_write(struct file *file,
137 const char __user *buffer, size_t count, loff_t *ppos)
139 cpumask_var_t new_value;
142 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
145 err = cpumask_parse_user(buffer, count, new_value);
149 if (!is_affinity_mask_valid(new_value)) {
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.
159 if (!cpumask_intersects(new_value, cpu_online_mask)) {
164 cpumask_copy(irq_default_affinity, new_value);
168 free_cpumask_var(new_value);
172 static int default_affinity_open(struct inode *inode, struct file *file)
174 return single_open(file, default_affinity_show, PDE(inode)->data);
177 static const struct file_operations default_affinity_proc_fops = {
178 .open = default_affinity_open,
181 .release = single_release,
182 .write = default_affinity_write,
185 static int irq_node_proc_show(struct seq_file *m, void *v)
187 struct irq_desc *desc = irq_to_desc((long) m->private);
189 seq_printf(m, "%d\n", desc->irq_data.node);
193 static int irq_node_proc_open(struct inode *inode, struct file *file)
195 return single_open(file, irq_node_proc_show, PDE(inode)->data);
198 static const struct file_operations irq_node_proc_fops = {
199 .open = irq_node_proc_open,
202 .release = single_release,
206 static int irq_spurious_proc_show(struct seq_file *m, void *v)
208 struct irq_desc *desc = irq_to_desc((long) m->private);
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));
216 static int irq_spurious_proc_open(struct inode *inode, struct file *file)
218 return single_open(file, irq_spurious_proc_show, PDE(inode)->data);
221 static const struct file_operations irq_spurious_proc_fops = {
222 .open = irq_spurious_proc_open,
225 .release = single_release,
228 #define MAX_NAMELEN 128
230 static int name_unique(unsigned int irq, struct irqaction *new_action)
232 struct irq_desc *desc = irq_to_desc(irq);
233 struct irqaction *action;
237 raw_spin_lock_irqsave(&desc->lock, flags);
238 for (action = desc->action ; action; action = action->next) {
239 if ((action != new_action) && action->name &&
240 !strcmp(new_action->name, action->name)) {
245 raw_spin_unlock_irqrestore(&desc->lock, flags);
249 void register_handler_proc(unsigned int irq, struct irqaction *action)
251 char name [MAX_NAMELEN];
252 struct irq_desc *desc = irq_to_desc(irq);
254 if (!desc->dir || action->dir || !action->name ||
255 !name_unique(irq, action))
258 memset(name, 0, MAX_NAMELEN);
259 snprintf(name, MAX_NAMELEN, "%s", action->name);
261 /* create /proc/irq/1234/handler/ */
262 action->dir = proc_mkdir(name, desc->dir);
267 #define MAX_NAMELEN 10
269 void register_irq_proc(unsigned int irq, struct irq_desc *desc)
271 char name [MAX_NAMELEN];
273 if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip) || desc->dir)
276 memset(name, 0, MAX_NAMELEN);
277 sprintf(name, "%d", irq);
279 /* create /proc/irq/1234 */
280 desc->dir = proc_mkdir(name, root_irq_dir);
285 /* create /proc/irq/<irq>/smp_affinity */
286 proc_create_data("smp_affinity", 0600, desc->dir,
287 &irq_affinity_proc_fops, (void *)(long)irq);
289 /* create /proc/irq/<irq>/affinity_hint */
290 proc_create_data("affinity_hint", 0400, desc->dir,
291 &irq_affinity_hint_proc_fops, (void *)(long)irq);
293 proc_create_data("node", 0444, desc->dir,
294 &irq_node_proc_fops, (void *)(long)irq);
297 proc_create_data("spurious", 0444, desc->dir,
298 &irq_spurious_proc_fops, (void *)(long)irq);
301 void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
303 char name [MAX_NAMELEN];
305 if (!root_irq_dir || !desc->dir)
308 remove_proc_entry("smp_affinity", desc->dir);
309 remove_proc_entry("affinity_hint", desc->dir);
310 remove_proc_entry("node", desc->dir);
312 remove_proc_entry("spurious", desc->dir);
314 memset(name, 0, MAX_NAMELEN);
315 sprintf(name, "%u", irq);
316 remove_proc_entry(name, root_irq_dir);
321 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
324 struct irq_desc *desc = irq_to_desc(irq);
326 remove_proc_entry(action->dir->name, desc->dir);
330 static void register_default_affinity_proc(void)
333 proc_create("irq/default_smp_affinity", 0600, NULL,
334 &default_affinity_proc_fops);
338 void init_irq_proc(void)
341 struct irq_desc *desc;
343 /* create /proc/irq */
344 root_irq_dir = proc_mkdir("irq", NULL);
348 register_default_affinity_proc();
351 * Create entries for all existing IRQs.
353 for_each_irq_desc(irq, desc) {
357 register_irq_proc(irq, desc);
361 #ifdef CONFIG_GENERIC_IRQ_SHOW
363 int __weak arch_show_interrupts(struct seq_file *p, int prec)
368 int show_interrupts(struct seq_file *p, void *v)
372 unsigned long flags, any_count = 0;
373 int i = *(loff_t *) v, j;
374 struct irqaction *action;
375 struct irq_desc *desc;
381 return arch_show_interrupts(p, prec);
383 /* print header and calculate the width of the first column */
385 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
388 seq_printf(p, "%*s", prec + 8, "");
389 for_each_online_cpu(j)
390 seq_printf(p, "CPU%-8d", j);
394 desc = irq_to_desc(i);
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)
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);
412 seq_printf(p, " %s", action->name);
413 while ((action = action->next) != NULL)
414 seq_printf(p, ", %s", action->name);
419 raw_spin_unlock_irqrestore(&desc->lock, flags);