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>
15 #include "internals.h"
17 static struct proc_dir_entry
*root_irq_dir
;
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
;
35 #ifndef is_affinity_mask_valid
36 #define is_affinity_mask_valid(val) 1
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
;
47 if (!irq_to_desc(irq
)->chip
->set_affinity
|| no_irq_affinity
||
48 irq_balancing_disabled(irq
))
51 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
54 err
= cpumask_parse_user(buffer
, count
, new_value
);
58 if (!is_affinity_mask_valid(new_value
)) {
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
;
73 irq_set_affinity(irq
, new_value
);
78 free_cpumask_var(new_value
);
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
,
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
);
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
;
108 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
111 err
= cpumask_parse_user(buffer
, count
, new_value
);
115 if (!is_affinity_mask_valid(new_value
)) {
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
)) {
130 cpumask_copy(irq_default_affinity
, new_value
);
134 free_cpumask_var(new_value
);
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
,
147 .release
= single_release
,
148 .write
= default_affinity_write
,
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
));
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
,
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
;
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
)) {
191 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
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
))
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
);
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
)
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
);
231 /* create /proc/irq/<irq>/smp_affinity */
232 proc_create_data("smp_affinity", 0600, desc
->dir
,
233 &irq_affinity_proc_fops
, (void *)(long)irq
);
236 proc_create_data("spurious", 0444, desc
->dir
,
237 &irq_spurious_proc_fops
, (void *)(long)irq
);
242 void unregister_handler_proc(unsigned int irq
, struct irqaction
*action
)
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)
254 proc_create("irq/default_smp_affinity", 0600, NULL
,
255 &default_affinity_proc_fops
);
259 void init_irq_proc(void)
262 struct irq_desc
*desc
;
264 /* create /proc/irq */
265 root_irq_dir
= proc_mkdir("irq", NULL
);
269 register_default_affinity_proc();
272 * Create entries for all existing IRQs.
274 for_each_irq_desc(irq
, desc
) {
278 register_irq_proc(irq
, desc
);