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>
15 #include <linux/mutex.h>
17 #include "internals.h"
19 static struct proc_dir_entry
*root_irq_dir
;
23 static int show_irq_affinity(int type
, struct seq_file
*m
, void *v
)
25 struct irq_desc
*desc
= irq_to_desc((long)m
->private);
26 const struct cpumask
*mask
= desc
->irq_data
.affinity
;
28 #ifdef CONFIG_GENERIC_PENDING_IRQ
29 if (irqd_is_setaffinity_pending(&desc
->irq_data
))
30 mask
= desc
->pending_mask
;
33 seq_cpumask_list(m
, mask
);
40 static int irq_affinity_hint_proc_show(struct seq_file
*m
, void *v
)
42 struct irq_desc
*desc
= irq_to_desc((long)m
->private);
46 if (!zalloc_cpumask_var(&mask
, GFP_KERNEL
))
49 raw_spin_lock_irqsave(&desc
->lock
, flags
);
50 if (desc
->affinity_hint
)
51 cpumask_copy(mask
, desc
->affinity_hint
);
52 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
56 free_cpumask_var(mask
);
61 #ifndef is_affinity_mask_valid
62 #define is_affinity_mask_valid(val) 1
66 static int irq_affinity_proc_show(struct seq_file
*m
, void *v
)
68 return show_irq_affinity(0, m
, v
);
71 static int irq_affinity_list_proc_show(struct seq_file
*m
, void *v
)
73 return show_irq_affinity(1, m
, v
);
77 static ssize_t
write_irq_affinity(int type
, struct file
*file
,
78 const char __user
*buffer
, size_t count
, loff_t
*pos
)
80 unsigned int irq
= (int)(long)PDE_DATA(file_inode(file
));
81 cpumask_var_t new_value
;
84 if (!irq_can_set_affinity(irq
) || no_irq_affinity
)
87 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
91 err
= cpumask_parselist_user(buffer
, count
, new_value
);
93 err
= cpumask_parse_user(buffer
, count
, new_value
);
97 if (!is_affinity_mask_valid(new_value
)) {
103 * Do not allow disabling IRQs completely - it's a too easy
104 * way to make the system unusable accidentally :-) At least
105 * one online CPU still has to be targeted.
107 if (!cpumask_intersects(new_value
, cpu_online_mask
)) {
108 /* Special case for empty set - allow the architecture
109 code to set default SMP affinity. */
110 err
= irq_select_affinity_usr(irq
, new_value
) ? -EINVAL
: count
;
112 irq_set_affinity(irq
, new_value
);
117 free_cpumask_var(new_value
);
121 static ssize_t
irq_affinity_proc_write(struct file
*file
,
122 const char __user
*buffer
, size_t count
, loff_t
*pos
)
124 return write_irq_affinity(0, file
, buffer
, count
, pos
);
127 static ssize_t
irq_affinity_list_proc_write(struct file
*file
,
128 const char __user
*buffer
, size_t count
, loff_t
*pos
)
130 return write_irq_affinity(1, file
, buffer
, count
, pos
);
133 static int irq_affinity_proc_open(struct inode
*inode
, struct file
*file
)
135 return single_open(file
, irq_affinity_proc_show
, PDE_DATA(inode
));
138 static int irq_affinity_list_proc_open(struct inode
*inode
, struct file
*file
)
140 return single_open(file
, irq_affinity_list_proc_show
, PDE_DATA(inode
));
143 static int irq_affinity_hint_proc_open(struct inode
*inode
, struct file
*file
)
145 return single_open(file
, irq_affinity_hint_proc_show
, PDE_DATA(inode
));
148 static const struct file_operations irq_affinity_proc_fops
= {
149 .open
= irq_affinity_proc_open
,
152 .release
= single_release
,
153 .write
= irq_affinity_proc_write
,
156 static const struct file_operations irq_affinity_hint_proc_fops
= {
157 .open
= irq_affinity_hint_proc_open
,
160 .release
= single_release
,
163 static const struct file_operations irq_affinity_list_proc_fops
= {
164 .open
= irq_affinity_list_proc_open
,
167 .release
= single_release
,
168 .write
= irq_affinity_list_proc_write
,
171 static int default_affinity_show(struct seq_file
*m
, void *v
)
173 seq_cpumask(m
, irq_default_affinity
);
178 static ssize_t
default_affinity_write(struct file
*file
,
179 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
181 cpumask_var_t new_value
;
184 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
187 err
= cpumask_parse_user(buffer
, count
, new_value
);
191 if (!is_affinity_mask_valid(new_value
)) {
197 * Do not allow disabling IRQs completely - it's a too easy
198 * way to make the system unusable accidentally :-) At least
199 * one online CPU still has to be targeted.
201 if (!cpumask_intersects(new_value
, cpu_online_mask
)) {
206 cpumask_copy(irq_default_affinity
, new_value
);
210 free_cpumask_var(new_value
);
214 static int default_affinity_open(struct inode
*inode
, struct file
*file
)
216 return single_open(file
, default_affinity_show
, PDE_DATA(inode
));
219 static const struct file_operations default_affinity_proc_fops
= {
220 .open
= default_affinity_open
,
223 .release
= single_release
,
224 .write
= default_affinity_write
,
227 static int irq_node_proc_show(struct seq_file
*m
, void *v
)
229 struct irq_desc
*desc
= irq_to_desc((long) m
->private);
231 seq_printf(m
, "%d\n", desc
->irq_data
.node
);
235 static int irq_node_proc_open(struct inode
*inode
, struct file
*file
)
237 return single_open(file
, irq_node_proc_show
, PDE_DATA(inode
));
240 static const struct file_operations irq_node_proc_fops
= {
241 .open
= irq_node_proc_open
,
244 .release
= single_release
,
248 static int irq_spurious_proc_show(struct seq_file
*m
, void *v
)
250 struct irq_desc
*desc
= irq_to_desc((long) m
->private);
252 seq_printf(m
, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
253 desc
->irq_count
, desc
->irqs_unhandled
,
254 jiffies_to_msecs(desc
->last_unhandled
));
258 static int irq_spurious_proc_open(struct inode
*inode
, struct file
*file
)
260 return single_open(file
, irq_spurious_proc_show
, PDE_DATA(inode
));
263 static const struct file_operations irq_spurious_proc_fops
= {
264 .open
= irq_spurious_proc_open
,
267 .release
= single_release
,
270 #define MAX_NAMELEN 128
272 static int name_unique(unsigned int irq
, struct irqaction
*new_action
)
274 struct irq_desc
*desc
= irq_to_desc(irq
);
275 struct irqaction
*action
;
279 raw_spin_lock_irqsave(&desc
->lock
, flags
);
280 for (action
= desc
->action
; action
; action
= action
->next
) {
281 if ((action
!= new_action
) && action
->name
&&
282 !strcmp(new_action
->name
, action
->name
)) {
287 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
291 void register_handler_proc(unsigned int irq
, struct irqaction
*action
)
293 char name
[MAX_NAMELEN
];
294 struct irq_desc
*desc
= irq_to_desc(irq
);
296 if (!desc
->dir
|| action
->dir
|| !action
->name
||
297 !name_unique(irq
, action
))
300 memset(name
, 0, MAX_NAMELEN
);
301 snprintf(name
, MAX_NAMELEN
, "%s", action
->name
);
303 /* create /proc/irq/1234/handler/ */
304 action
->dir
= proc_mkdir(name
, desc
->dir
);
309 #define MAX_NAMELEN 10
311 void register_irq_proc(unsigned int irq
, struct irq_desc
*desc
)
313 static DEFINE_MUTEX(register_lock
);
314 char name
[MAX_NAMELEN
];
316 if (!root_irq_dir
|| (desc
->irq_data
.chip
== &no_irq_chip
))
320 * irq directories are registered only when a handler is
321 * added, not when the descriptor is created, so multiple
322 * tasks might try to register at the same time.
324 mutex_lock(®ister_lock
);
329 memset(name
, 0, MAX_NAMELEN
);
330 sprintf(name
, "%d", irq
);
332 /* create /proc/irq/1234 */
333 desc
->dir
= proc_mkdir(name
, root_irq_dir
);
338 /* create /proc/irq/<irq>/smp_affinity */
339 proc_create_data("smp_affinity", 0600, desc
->dir
,
340 &irq_affinity_proc_fops
, (void *)(long)irq
);
342 /* create /proc/irq/<irq>/affinity_hint */
343 proc_create_data("affinity_hint", 0400, desc
->dir
,
344 &irq_affinity_hint_proc_fops
, (void *)(long)irq
);
346 /* create /proc/irq/<irq>/smp_affinity_list */
347 proc_create_data("smp_affinity_list", 0600, desc
->dir
,
348 &irq_affinity_list_proc_fops
, (void *)(long)irq
);
350 proc_create_data("node", 0444, desc
->dir
,
351 &irq_node_proc_fops
, (void *)(long)irq
);
354 proc_create_data("spurious", 0444, desc
->dir
,
355 &irq_spurious_proc_fops
, (void *)(long)irq
);
358 mutex_unlock(®ister_lock
);
361 void unregister_irq_proc(unsigned int irq
, struct irq_desc
*desc
)
363 char name
[MAX_NAMELEN
];
365 if (!root_irq_dir
|| !desc
->dir
)
368 remove_proc_entry("smp_affinity", desc
->dir
);
369 remove_proc_entry("affinity_hint", desc
->dir
);
370 remove_proc_entry("smp_affinity_list", desc
->dir
);
371 remove_proc_entry("node", desc
->dir
);
373 remove_proc_entry("spurious", desc
->dir
);
375 memset(name
, 0, MAX_NAMELEN
);
376 sprintf(name
, "%u", irq
);
377 remove_proc_entry(name
, root_irq_dir
);
382 void unregister_handler_proc(unsigned int irq
, struct irqaction
*action
)
384 proc_remove(action
->dir
);
387 static void register_default_affinity_proc(void)
390 proc_create("irq/default_smp_affinity", 0600, NULL
,
391 &default_affinity_proc_fops
);
395 void init_irq_proc(void)
398 struct irq_desc
*desc
;
400 /* create /proc/irq */
401 root_irq_dir
= proc_mkdir("irq", NULL
);
405 register_default_affinity_proc();
408 * Create entries for all existing IRQs.
410 for_each_irq_desc(irq
, desc
) {
414 register_irq_proc(irq
, desc
);
418 #ifdef CONFIG_GENERIC_IRQ_SHOW
420 int __weak
arch_show_interrupts(struct seq_file
*p
, int prec
)
425 #ifndef ACTUAL_NR_IRQS
426 # define ACTUAL_NR_IRQS nr_irqs
429 int show_interrupts(struct seq_file
*p
, void *v
)
433 unsigned long flags
, any_count
= 0;
434 int i
= *(loff_t
*) v
, j
;
435 struct irqaction
*action
;
436 struct irq_desc
*desc
;
438 if (i
> ACTUAL_NR_IRQS
)
441 if (i
== ACTUAL_NR_IRQS
)
442 return arch_show_interrupts(p
, prec
);
444 /* print header and calculate the width of the first column */
446 for (prec
= 3, j
= 1000; prec
< 10 && j
<= nr_irqs
; ++prec
)
449 seq_printf(p
, "%*s", prec
+ 8, "");
450 for_each_online_cpu(j
)
451 seq_printf(p
, "CPU%-8d", j
);
455 desc
= irq_to_desc(i
);
459 raw_spin_lock_irqsave(&desc
->lock
, flags
);
460 for_each_online_cpu(j
)
461 any_count
|= kstat_irqs_cpu(i
, j
);
462 action
= desc
->action
;
463 if (!action
&& !any_count
)
466 seq_printf(p
, "%*d: ", prec
, i
);
467 for_each_online_cpu(j
)
468 seq_printf(p
, "%10u ", kstat_irqs_cpu(i
, j
));
470 if (desc
->irq_data
.chip
) {
471 if (desc
->irq_data
.chip
->irq_print_chip
)
472 desc
->irq_data
.chip
->irq_print_chip(&desc
->irq_data
, p
);
473 else if (desc
->irq_data
.chip
->name
)
474 seq_printf(p
, " %8s", desc
->irq_data
.chip
->name
);
476 seq_printf(p
, " %8s", "-");
478 seq_printf(p
, " %8s", "None");
480 #ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL
481 seq_printf(p
, " %-8s", irqd_is_level_type(&desc
->irq_data
) ? "Level" : "Edge");
484 seq_printf(p
, "-%-8s", desc
->name
);
487 seq_printf(p
, " %s", action
->name
);
488 while ((action
= action
->next
) != NULL
)
489 seq_printf(p
, ", %s", action
->name
);
494 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);