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_can_set_affinity(irq
) || no_irq_affinity
)
72 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
75 err
= cpumask_parse_user(buffer
, count
, new_value
);
79 if (!is_affinity_mask_valid(new_value
)) {
85 * Do not allow disabling IRQs completely - it's a too easy
86 * way to make the system unusable accidentally :-) At least
87 * one online CPU still has to be targeted.
89 if (!cpumask_intersects(new_value
, cpu_online_mask
)) {
90 /* Special case for empty set - allow the architecture
91 code to set default SMP affinity. */
92 err
= irq_select_affinity_usr(irq
, new_value
) ? -EINVAL
: count
;
94 irq_set_affinity(irq
, new_value
);
99 free_cpumask_var(new_value
);
103 static int irq_affinity_proc_open(struct inode
*inode
, struct file
*file
)
105 return single_open(file
, irq_affinity_proc_show
, PDE(inode
)->data
);
108 static int irq_affinity_hint_proc_open(struct inode
*inode
, struct file
*file
)
110 return single_open(file
, irq_affinity_hint_proc_show
, PDE(inode
)->data
);
113 static const struct file_operations irq_affinity_proc_fops
= {
114 .open
= irq_affinity_proc_open
,
117 .release
= single_release
,
118 .write
= irq_affinity_proc_write
,
121 static const struct file_operations irq_affinity_hint_proc_fops
= {
122 .open
= irq_affinity_hint_proc_open
,
125 .release
= single_release
,
128 static int default_affinity_show(struct seq_file
*m
, void *v
)
130 seq_cpumask(m
, irq_default_affinity
);
135 static ssize_t
default_affinity_write(struct file
*file
,
136 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
138 cpumask_var_t new_value
;
141 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
144 err
= cpumask_parse_user(buffer
, count
, new_value
);
148 if (!is_affinity_mask_valid(new_value
)) {
154 * Do not allow disabling IRQs completely - it's a too easy
155 * way to make the system unusable accidentally :-) At least
156 * one online CPU still has to be targeted.
158 if (!cpumask_intersects(new_value
, cpu_online_mask
)) {
163 cpumask_copy(irq_default_affinity
, new_value
);
167 free_cpumask_var(new_value
);
171 static int default_affinity_open(struct inode
*inode
, struct file
*file
)
173 return single_open(file
, default_affinity_show
, PDE(inode
)->data
);
176 static const struct file_operations default_affinity_proc_fops
= {
177 .open
= default_affinity_open
,
180 .release
= single_release
,
181 .write
= default_affinity_write
,
184 static int irq_node_proc_show(struct seq_file
*m
, void *v
)
186 struct irq_desc
*desc
= irq_to_desc((long) m
->private);
188 seq_printf(m
, "%d\n", desc
->irq_data
.node
);
192 static int irq_node_proc_open(struct inode
*inode
, struct file
*file
)
194 return single_open(file
, irq_node_proc_show
, PDE(inode
)->data
);
197 static const struct file_operations irq_node_proc_fops
= {
198 .open
= irq_node_proc_open
,
201 .release
= single_release
,
205 static int irq_spurious_proc_show(struct seq_file
*m
, void *v
)
207 struct irq_desc
*desc
= irq_to_desc((long) m
->private);
209 seq_printf(m
, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
210 desc
->irq_count
, desc
->irqs_unhandled
,
211 jiffies_to_msecs(desc
->last_unhandled
));
215 static int irq_spurious_proc_open(struct inode
*inode
, struct file
*file
)
217 return single_open(file
, irq_spurious_proc_show
, PDE(inode
)->data
);
220 static const struct file_operations irq_spurious_proc_fops
= {
221 .open
= irq_spurious_proc_open
,
224 .release
= single_release
,
227 #define MAX_NAMELEN 128
229 static int name_unique(unsigned int irq
, struct irqaction
*new_action
)
231 struct irq_desc
*desc
= irq_to_desc(irq
);
232 struct irqaction
*action
;
236 raw_spin_lock_irqsave(&desc
->lock
, flags
);
237 for (action
= desc
->action
; action
; action
= action
->next
) {
238 if ((action
!= new_action
) && action
->name
&&
239 !strcmp(new_action
->name
, action
->name
)) {
244 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
248 void register_handler_proc(unsigned int irq
, struct irqaction
*action
)
250 char name
[MAX_NAMELEN
];
251 struct irq_desc
*desc
= irq_to_desc(irq
);
253 if (!desc
->dir
|| action
->dir
|| !action
->name
||
254 !name_unique(irq
, action
))
257 memset(name
, 0, MAX_NAMELEN
);
258 snprintf(name
, MAX_NAMELEN
, "%s", action
->name
);
260 /* create /proc/irq/1234/handler/ */
261 action
->dir
= proc_mkdir(name
, desc
->dir
);
266 #define MAX_NAMELEN 10
268 void register_irq_proc(unsigned int irq
, struct irq_desc
*desc
)
270 char name
[MAX_NAMELEN
];
272 if (!root_irq_dir
|| (desc
->irq_data
.chip
== &no_irq_chip
) || desc
->dir
)
275 memset(name
, 0, MAX_NAMELEN
);
276 sprintf(name
, "%d", irq
);
278 /* create /proc/irq/1234 */
279 desc
->dir
= proc_mkdir(name
, root_irq_dir
);
284 /* create /proc/irq/<irq>/smp_affinity */
285 proc_create_data("smp_affinity", 0600, desc
->dir
,
286 &irq_affinity_proc_fops
, (void *)(long)irq
);
288 /* create /proc/irq/<irq>/affinity_hint */
289 proc_create_data("affinity_hint", 0400, desc
->dir
,
290 &irq_affinity_hint_proc_fops
, (void *)(long)irq
);
292 proc_create_data("node", 0444, desc
->dir
,
293 &irq_node_proc_fops
, (void *)(long)irq
);
296 proc_create_data("spurious", 0444, desc
->dir
,
297 &irq_spurious_proc_fops
, (void *)(long)irq
);
300 void unregister_irq_proc(unsigned int irq
, struct irq_desc
*desc
)
302 char name
[MAX_NAMELEN
];
304 if (!root_irq_dir
|| !desc
->dir
)
307 remove_proc_entry("smp_affinity", desc
->dir
);
308 remove_proc_entry("affinity_hint", desc
->dir
);
309 remove_proc_entry("node", desc
->dir
);
311 remove_proc_entry("spurious", desc
->dir
);
313 memset(name
, 0, MAX_NAMELEN
);
314 sprintf(name
, "%u", irq
);
315 remove_proc_entry(name
, root_irq_dir
);
320 void unregister_handler_proc(unsigned int irq
, struct irqaction
*action
)
323 struct irq_desc
*desc
= irq_to_desc(irq
);
325 remove_proc_entry(action
->dir
->name
, desc
->dir
);
329 static void register_default_affinity_proc(void)
332 proc_create("irq/default_smp_affinity", 0600, NULL
,
333 &default_affinity_proc_fops
);
337 void init_irq_proc(void)
340 struct irq_desc
*desc
;
342 /* create /proc/irq */
343 root_irq_dir
= proc_mkdir("irq", NULL
);
347 register_default_affinity_proc();
350 * Create entries for all existing IRQs.
352 for_each_irq_desc(irq
, desc
) {
356 register_irq_proc(irq
, desc
);
360 #ifdef CONFIG_GENERIC_IRQ_SHOW
362 int __weak
arch_show_interrupts(struct seq_file
*p
, int prec
)
367 #ifndef ACTUAL_NR_IRQS
368 # define ACTUAL_NR_IRQS nr_irqs
371 int show_interrupts(struct seq_file
*p
, void *v
)
375 unsigned long flags
, any_count
= 0;
376 int i
= *(loff_t
*) v
, j
;
377 struct irqaction
*action
;
378 struct irq_desc
*desc
;
380 if (i
> ACTUAL_NR_IRQS
)
383 if (i
== ACTUAL_NR_IRQS
)
384 return arch_show_interrupts(p
, prec
);
386 /* print header and calculate the width of the first column */
388 for (prec
= 3, j
= 1000; prec
< 10 && j
<= nr_irqs
; ++prec
)
391 seq_printf(p
, "%*s", prec
+ 8, "");
392 for_each_online_cpu(j
)
393 seq_printf(p
, "CPU%-8d", j
);
397 desc
= irq_to_desc(i
);
401 raw_spin_lock_irqsave(&desc
->lock
, flags
);
402 for_each_online_cpu(j
)
403 any_count
|= kstat_irqs_cpu(i
, j
);
404 action
= desc
->action
;
405 if (!action
&& !any_count
)
408 seq_printf(p
, "%*d: ", prec
, i
);
409 for_each_online_cpu(j
)
410 seq_printf(p
, "%10u ", kstat_irqs_cpu(i
, j
));
412 if (desc
->irq_data
.chip
) {
413 if (desc
->irq_data
.chip
->irq_print_chip
)
414 desc
->irq_data
.chip
->irq_print_chip(&desc
->irq_data
, p
);
415 else if (desc
->irq_data
.chip
->name
)
416 seq_printf(p
, " %8s", desc
->irq_data
.chip
->name
);
418 seq_printf(p
, " %8s", "-");
420 seq_printf(p
, " %8s", "None");
422 #ifdef CONFIG_GENIRC_IRQ_SHOW_LEVEL
423 seq_printf(p
, " %-8s", irqd_is_level_type(&desc
->irq_data
) ? "Level" : "Edge");
426 seq_printf(p
, "-%-8s", desc
->name
);
429 seq_printf(p
, " %s", action
->name
);
430 while ((action
= action
->next
) != NULL
)
431 seq_printf(p
, ", %s", action
->name
);
436 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);