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_desc
+ (long)m
->private;
23 cpumask_t
*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
;
46 if (!irq_desc
[irq
].chip
->set_affinity
|| no_irq_affinity
||
47 irq_balancing_disabled(irq
))
50 err
= cpumask_parse_user(buffer
, count
, new_value
);
54 if (!is_affinity_mask_valid(new_value
))
58 * Do not allow disabling IRQs completely - it's a too easy
59 * way to make the system unusable accidentally :-) At least
60 * one online CPU still has to be targeted.
62 if (!cpus_intersects(new_value
, cpu_online_map
))
63 /* Special case for empty set - allow the architecture
64 code to set default SMP affinity. */
65 return irq_select_affinity(irq
) ? -EINVAL
: count
;
67 irq_set_affinity(irq
, new_value
);
72 static int irq_affinity_proc_open(struct inode
*inode
, struct file
*file
)
74 return single_open(file
, irq_affinity_proc_show
, PDE(inode
)->data
);
77 static const struct file_operations irq_affinity_proc_fops
= {
78 .open
= irq_affinity_proc_open
,
81 .release
= single_release
,
82 .write
= irq_affinity_proc_write
,
85 static int default_affinity_show(struct seq_file
*m
, void *v
)
87 seq_cpumask(m
, &irq_default_affinity
);
92 static ssize_t
default_affinity_write(struct file
*file
,
93 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
98 err
= cpumask_parse_user(buffer
, count
, new_value
);
102 if (!is_affinity_mask_valid(new_value
))
106 * Do not allow disabling IRQs completely - it's a too easy
107 * way to make the system unusable accidentally :-) At least
108 * one online CPU still has to be targeted.
110 if (!cpus_intersects(new_value
, cpu_online_map
))
113 irq_default_affinity
= new_value
;
118 static int default_affinity_open(struct inode
*inode
, struct file
*file
)
120 return single_open(file
, default_affinity_show
, NULL
);
123 static const struct file_operations default_affinity_proc_fops
= {
124 .open
= default_affinity_open
,
127 .release
= single_release
,
128 .write
= default_affinity_write
,
132 static int irq_spurious_read(char *page
, char **start
, off_t off
,
133 int count
, int *eof
, void *data
)
135 struct irq_desc
*d
= &irq_desc
[(long) data
];
136 return sprintf(page
, "count %u\n"
138 "last_unhandled %u ms\n",
141 jiffies_to_msecs(d
->last_unhandled
));
144 #define MAX_NAMELEN 128
146 static int name_unique(unsigned int irq
, struct irqaction
*new_action
)
148 struct irq_desc
*desc
= irq_desc
+ irq
;
149 struct irqaction
*action
;
153 spin_lock_irqsave(&desc
->lock
, flags
);
154 for (action
= desc
->action
; action
; action
= action
->next
) {
155 if ((action
!= new_action
) && action
->name
&&
156 !strcmp(new_action
->name
, action
->name
)) {
161 spin_unlock_irqrestore(&desc
->lock
, flags
);
165 void register_handler_proc(unsigned int irq
, struct irqaction
*action
)
167 char name
[MAX_NAMELEN
];
169 if (!irq_desc
[irq
].dir
|| action
->dir
|| !action
->name
||
170 !name_unique(irq
, action
))
173 memset(name
, 0, MAX_NAMELEN
);
174 snprintf(name
, MAX_NAMELEN
, "%s", action
->name
);
176 /* create /proc/irq/1234/handler/ */
177 action
->dir
= proc_mkdir(name
, irq_desc
[irq
].dir
);
182 #define MAX_NAMELEN 10
184 void register_irq_proc(unsigned int irq
)
186 char name
[MAX_NAMELEN
];
187 struct proc_dir_entry
*entry
;
190 (irq_desc
[irq
].chip
== &no_irq_chip
) ||
194 memset(name
, 0, MAX_NAMELEN
);
195 sprintf(name
, "%d", irq
);
197 /* create /proc/irq/1234 */
198 irq_desc
[irq
].dir
= proc_mkdir(name
, root_irq_dir
);
201 /* create /proc/irq/<irq>/smp_affinity */
202 proc_create_data("smp_affinity", 0600, irq_desc
[irq
].dir
,
203 &irq_affinity_proc_fops
, (void *)(long)irq
);
206 entry
= create_proc_entry("spurious", 0444, irq_desc
[irq
].dir
);
208 entry
->data
= (void *)(long)irq
;
209 entry
->read_proc
= irq_spurious_read
;
215 void unregister_handler_proc(unsigned int irq
, struct irqaction
*action
)
218 remove_proc_entry(action
->dir
->name
, irq_desc
[irq
].dir
);
221 void register_default_affinity_proc(void)
224 proc_create("irq/default_smp_affinity", 0600, NULL
,
225 &default_affinity_proc_fops
);
229 void init_irq_proc(void)
233 /* create /proc/irq */
234 root_irq_dir
= proc_mkdir("irq", NULL
);
238 register_default_affinity_proc();
241 * Create entries for all existing IRQs.
243 for (i
= 0; i
< NR_IRQS
; i
++)
244 register_irq_proc(i
);