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/proc_fs.h>
11 #include <linux/seq_file.h>
12 #include <linux/interrupt.h>
14 #include "internals.h"
16 static struct proc_dir_entry
*root_irq_dir
;
20 static int irq_affinity_proc_show(struct seq_file
*m
, void *v
)
22 struct irq_desc
*desc
= irq_to_desc((long)m
->private);
23 const struct cpumask
*mask
= desc
->affinity
;
25 #ifdef CONFIG_GENERIC_PENDING_IRQ
26 if (desc
->status
& IRQ_MOVE_PENDING
)
27 mask
= desc
->pending_mask
;
34 #ifndef is_affinity_mask_valid
35 #define is_affinity_mask_valid(val) 1
39 static ssize_t
irq_affinity_proc_write(struct file
*file
,
40 const char __user
*buffer
, size_t count
, loff_t
*pos
)
42 unsigned int irq
= (int)(long)PDE(file
->f_path
.dentry
->d_inode
)->data
;
43 cpumask_var_t new_value
;
46 if (!irq_to_desc(irq
)->chip
->set_affinity
|| no_irq_affinity
||
47 irq_balancing_disabled(irq
))
50 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
53 err
= cpumask_parse_user(buffer
, count
, new_value
);
57 if (!is_affinity_mask_valid(new_value
)) {
63 * Do not allow disabling IRQs completely - it's a too easy
64 * way to make the system unusable accidentally :-) At least
65 * one online CPU still has to be targeted.
67 if (!cpumask_intersects(new_value
, cpu_online_mask
)) {
68 /* Special case for empty set - allow the architecture
69 code to set default SMP affinity. */
70 err
= irq_select_affinity_usr(irq
) ? -EINVAL
: count
;
72 irq_set_affinity(irq
, new_value
);
77 free_cpumask_var(new_value
);
81 static int irq_affinity_proc_open(struct inode
*inode
, struct file
*file
)
83 return single_open(file
, irq_affinity_proc_show
, PDE(inode
)->data
);
86 static const struct file_operations irq_affinity_proc_fops
= {
87 .open
= irq_affinity_proc_open
,
90 .release
= single_release
,
91 .write
= irq_affinity_proc_write
,
94 static int default_affinity_show(struct seq_file
*m
, void *v
)
96 seq_cpumask(m
, irq_default_affinity
);
101 static ssize_t
default_affinity_write(struct file
*file
,
102 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
104 cpumask_var_t new_value
;
107 if (!alloc_cpumask_var(&new_value
, GFP_KERNEL
))
110 err
= cpumask_parse_user(buffer
, count
, new_value
);
114 if (!is_affinity_mask_valid(new_value
)) {
120 * Do not allow disabling IRQs completely - it's a too easy
121 * way to make the system unusable accidentally :-) At least
122 * one online CPU still has to be targeted.
124 if (!cpumask_intersects(new_value
, cpu_online_mask
)) {
129 cpumask_copy(irq_default_affinity
, new_value
);
133 free_cpumask_var(new_value
);
137 static int default_affinity_open(struct inode
*inode
, struct file
*file
)
139 return single_open(file
, default_affinity_show
, PDE(inode
)->data
);
142 static const struct file_operations default_affinity_proc_fops
= {
143 .open
= default_affinity_open
,
146 .release
= single_release
,
147 .write
= default_affinity_write
,
151 static int irq_spurious_proc_show(struct seq_file
*m
, void *v
)
153 struct irq_desc
*desc
= irq_to_desc((long) m
->private);
155 seq_printf(m
, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
156 desc
->irq_count
, desc
->irqs_unhandled
,
157 jiffies_to_msecs(desc
->last_unhandled
));
161 static int irq_spurious_proc_open(struct inode
*inode
, struct file
*file
)
163 return single_open(file
, irq_spurious_proc_show
, NULL
);
166 static const struct file_operations irq_spurious_proc_fops
= {
167 .open
= irq_spurious_proc_open
,
170 .release
= single_release
,
173 #define MAX_NAMELEN 128
175 static int name_unique(unsigned int irq
, struct irqaction
*new_action
)
177 struct irq_desc
*desc
= irq_to_desc(irq
);
178 struct irqaction
*action
;
182 raw_spin_lock_irqsave(&desc
->lock
, flags
);
183 for (action
= desc
->action
; action
; action
= action
->next
) {
184 if ((action
!= new_action
) && action
->name
&&
185 !strcmp(new_action
->name
, action
->name
)) {
190 raw_spin_unlock_irqrestore(&desc
->lock
, flags
);
194 void register_handler_proc(unsigned int irq
, struct irqaction
*action
)
196 char name
[MAX_NAMELEN
];
197 struct irq_desc
*desc
= irq_to_desc(irq
);
199 if (!desc
->dir
|| action
->dir
|| !action
->name
||
200 !name_unique(irq
, action
))
203 memset(name
, 0, MAX_NAMELEN
);
204 snprintf(name
, MAX_NAMELEN
, "%s", action
->name
);
206 /* create /proc/irq/1234/handler/ */
207 action
->dir
= proc_mkdir(name
, desc
->dir
);
212 #define MAX_NAMELEN 10
214 void register_irq_proc(unsigned int irq
, struct irq_desc
*desc
)
216 char name
[MAX_NAMELEN
];
218 if (!root_irq_dir
|| (desc
->chip
== &no_irq_chip
) || desc
->dir
)
221 memset(name
, 0, MAX_NAMELEN
);
222 sprintf(name
, "%d", irq
);
224 /* create /proc/irq/1234 */
225 desc
->dir
= proc_mkdir(name
, root_irq_dir
);
230 /* create /proc/irq/<irq>/smp_affinity */
231 proc_create_data("smp_affinity", 0600, desc
->dir
,
232 &irq_affinity_proc_fops
, (void *)(long)irq
);
235 proc_create_data("spurious", 0444, desc
->dir
,
236 &irq_spurious_proc_fops
, (void *)(long)irq
);
241 void unregister_handler_proc(unsigned int irq
, struct irqaction
*action
)
244 struct irq_desc
*desc
= irq_to_desc(irq
);
246 remove_proc_entry(action
->dir
->name
, desc
->dir
);
250 static void register_default_affinity_proc(void)
253 proc_create("irq/default_smp_affinity", 0600, NULL
,
254 &default_affinity_proc_fops
);
258 void init_irq_proc(void)
261 struct irq_desc
*desc
;
263 /* create /proc/irq */
264 root_irq_dir
= proc_mkdir("irq", NULL
);
268 register_default_affinity_proc();
271 * Create entries for all existing IRQs.
273 for_each_irq_desc(irq
, desc
) {
277 register_irq_proc(irq
, desc
);