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/interrupt.h>
13 #include "internals.h"
15 static struct proc_dir_entry
*root_irq_dir
;
19 static int irq_affinity_read_proc(char *page
, char **start
, off_t off
,
20 int count
, int *eof
, void *data
)
22 struct irq_desc
*desc
= irq_desc
+ (long)data
;
23 cpumask_t
*mask
= &desc
->affinity
;
26 #ifdef CONFIG_GENERIC_PENDING_IRQ
27 if (desc
->status
& IRQ_MOVE_PENDING
)
28 mask
= &desc
->pending_mask
;
30 len
= cpumask_scnprintf(page
, count
, *mask
);
34 len
+= sprintf(page
+ len
, "\n");
38 #ifndef is_affinity_mask_valid
39 #define is_affinity_mask_valid(val) 1
43 static int irq_affinity_write_proc(struct file
*file
, const char __user
*buffer
,
44 unsigned long count
, void *data
)
46 unsigned int irq
= (int)(long)data
, full_count
= count
, err
;
47 cpumask_t new_value
, tmp
;
49 if (!irq_desc
[irq
].chip
->set_affinity
|| no_irq_affinity
||
50 irq_balancing_disabled(irq
))
53 err
= cpumask_parse_user(buffer
, count
, new_value
);
57 if (!is_affinity_mask_valid(new_value
))
61 * Do not allow disabling IRQs completely - it's a too easy
62 * way to make the system unusable accidentally :-) At least
63 * one online CPU still has to be targeted.
65 cpus_and(tmp
, new_value
, cpu_online_map
);
67 /* Special case for empty set - allow the architecture
68 code to set default SMP affinity. */
69 return select_smp_affinity(irq
) ? -EINVAL
: full_count
;
71 irq_set_affinity(irq
, new_value
);
78 static int irq_spurious_read(char *page
, char **start
, off_t off
,
79 int count
, int *eof
, void *data
)
81 struct irq_desc
*d
= &irq_desc
[(long) data
];
82 return sprintf(page
, "count %u\n"
84 "last_unhandled %u ms\n",
87 jiffies_to_msecs(d
->last_unhandled
));
90 #define MAX_NAMELEN 128
92 static int name_unique(unsigned int irq
, struct irqaction
*new_action
)
94 struct irq_desc
*desc
= irq_desc
+ irq
;
95 struct irqaction
*action
;
99 spin_lock_irqsave(&desc
->lock
, flags
);
100 for (action
= desc
->action
; action
; action
= action
->next
) {
101 if ((action
!= new_action
) && action
->name
&&
102 !strcmp(new_action
->name
, action
->name
)) {
107 spin_unlock_irqrestore(&desc
->lock
, flags
);
111 void register_handler_proc(unsigned int irq
, struct irqaction
*action
)
113 char name
[MAX_NAMELEN
];
115 if (!irq_desc
[irq
].dir
|| action
->dir
|| !action
->name
||
116 !name_unique(irq
, action
))
119 memset(name
, 0, MAX_NAMELEN
);
120 snprintf(name
, MAX_NAMELEN
, "%s", action
->name
);
122 /* create /proc/irq/1234/handler/ */
123 action
->dir
= proc_mkdir(name
, irq_desc
[irq
].dir
);
128 #define MAX_NAMELEN 10
130 void register_irq_proc(unsigned int irq
)
132 char name
[MAX_NAMELEN
];
133 struct proc_dir_entry
*entry
;
136 (irq_desc
[irq
].chip
== &no_irq_chip
) ||
140 memset(name
, 0, MAX_NAMELEN
);
141 sprintf(name
, "%d", irq
);
143 /* create /proc/irq/1234 */
144 irq_desc
[irq
].dir
= proc_mkdir(name
, root_irq_dir
);
148 /* create /proc/irq/<irq>/smp_affinity */
149 entry
= create_proc_entry("smp_affinity", 0600, irq_desc
[irq
].dir
);
152 entry
->data
= (void *)(long)irq
;
153 entry
->read_proc
= irq_affinity_read_proc
;
154 entry
->write_proc
= irq_affinity_write_proc
;
159 entry
= create_proc_entry("spurious", 0444, irq_desc
[irq
].dir
);
161 entry
->data
= (void *)(long)irq
;
162 entry
->read_proc
= irq_spurious_read
;
168 void unregister_handler_proc(unsigned int irq
, struct irqaction
*action
)
171 remove_proc_entry(action
->dir
->name
, irq_desc
[irq
].dir
);
174 void init_irq_proc(void)
178 /* create /proc/irq */
179 root_irq_dir
= proc_mkdir("irq", NULL
);
184 * Create entries for all existing IRQs.
186 for (i
= 0; i
< NR_IRQS
; i
++)
187 register_irq_proc(i
);