Merge master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6-block.git] / kernel / irq / proc.c
CommitLineData
1da177e4
LT
1/*
2 * linux/kernel/irq/proc.c
3 *
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
5 *
6 * This file contains the /proc/irq/ handling code.
7 */
8
9#include <linux/irq.h>
10#include <linux/proc_fs.h>
11#include <linux/interrupt.h>
12
97a41e26
AB
13#include "internals.h"
14
4a733ee1 15static struct proc_dir_entry *root_irq_dir;
1da177e4
LT
16
17#ifdef CONFIG_SMP
18
54d5d424
AR
19#ifdef CONFIG_GENERIC_PENDING_IRQ
20void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val)
21{
1b61b910
ZY
22 set_balance_irq_affinity(irq, mask_val);
23
54d5d424
AR
24 /*
25 * Save these away for later use. Re-progam when the
26 * interrupt is pending
27 */
28 set_pending_irq(irq, mask_val);
29}
30#else
31void proc_set_irq_affinity(unsigned int irq, cpumask_t mask_val)
1da177e4 32{
1b61b910 33 set_balance_irq_affinity(irq, mask_val);
a53da52f 34 irq_desc[irq].affinity = mask_val;
d1bef4ed 35 irq_desc[irq].chip->set_affinity(irq, mask_val);
1da177e4 36}
54d5d424 37#endif
1da177e4
LT
38
39static int irq_affinity_read_proc(char *page, char **start, off_t off,
40 int count, int *eof, void *data)
41{
a53da52f 42 int len = cpumask_scnprintf(page, count, irq_desc[(long)data].affinity);
1da177e4
LT
43
44 if (count - len < 2)
45 return -EINVAL;
46 len += sprintf(page + len, "\n");
47 return len;
48}
49
50int no_irq_affinity;
51static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
52 unsigned long count, void *data)
53{
54 unsigned int irq = (int)(long)data, full_count = count, err;
55 cpumask_t new_value, tmp;
56
d1bef4ed 57 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity)
1da177e4
LT
58 return -EIO;
59
01a3ee2b 60 err = cpumask_parse_user(buffer, count, new_value);
1da177e4
LT
61 if (err)
62 return err;
63
64 /*
65 * Do not allow disabling IRQs completely - it's a too easy
66 * way to make the system unusable accidentally :-) At least
67 * one online CPU still has to be targeted.
68 */
69 cpus_and(tmp, new_value, cpu_online_map);
70 if (cpus_empty(tmp))
eee45269
IK
71 /* Special case for empty set - allow the architecture
72 code to set default SMP affinity. */
73 return select_smp_affinity(irq) ? -EINVAL : full_count;
1da177e4
LT
74
75 proc_set_irq_affinity(irq, new_value);
76
77 return full_count;
78}
79
80#endif
81
82#define MAX_NAMELEN 128
83
84static int name_unique(unsigned int irq, struct irqaction *new_action)
85{
86 struct irq_desc *desc = irq_desc + irq;
87 struct irqaction *action;
88
89 for (action = desc->action ; action; action = action->next)
90 if ((action != new_action) && action->name &&
91 !strcmp(new_action->name, action->name))
92 return 0;
93 return 1;
94}
95
96void register_handler_proc(unsigned int irq, struct irqaction *action)
97{
98 char name [MAX_NAMELEN];
99
4a733ee1 100 if (!irq_desc[irq].dir || action->dir || !action->name ||
1da177e4
LT
101 !name_unique(irq, action))
102 return;
103
104 memset(name, 0, MAX_NAMELEN);
105 snprintf(name, MAX_NAMELEN, "%s", action->name);
106
107 /* create /proc/irq/1234/handler/ */
4a733ee1 108 action->dir = proc_mkdir(name, irq_desc[irq].dir);
1da177e4
LT
109}
110
111#undef MAX_NAMELEN
112
113#define MAX_NAMELEN 10
114
115void register_irq_proc(unsigned int irq)
116{
117 char name [MAX_NAMELEN];
118
119 if (!root_irq_dir ||
f1c2662c 120 (irq_desc[irq].chip == &no_irq_chip) ||
4a733ee1 121 irq_desc[irq].dir)
1da177e4
LT
122 return;
123
124 memset(name, 0, MAX_NAMELEN);
125 sprintf(name, "%d", irq);
126
127 /* create /proc/irq/1234 */
4a733ee1 128 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
1da177e4
LT
129
130#ifdef CONFIG_SMP
131 {
132 struct proc_dir_entry *entry;
133
134 /* create /proc/irq/<irq>/smp_affinity */
4a733ee1 135 entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir);
1da177e4
LT
136
137 if (entry) {
138 entry->nlink = 1;
139 entry->data = (void *)(long)irq;
140 entry->read_proc = irq_affinity_read_proc;
141 entry->write_proc = irq_affinity_write_proc;
142 }
1da177e4
LT
143 }
144#endif
145}
146
147#undef MAX_NAMELEN
148
149void unregister_handler_proc(unsigned int irq, struct irqaction *action)
150{
151 if (action->dir)
4a733ee1 152 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
1da177e4
LT
153}
154
155void init_irq_proc(void)
156{
157 int i;
158
159 /* create /proc/irq */
160 root_irq_dir = proc_mkdir("irq", NULL);
161 if (!root_irq_dir)
162 return;
163
164 /*
165 * Create entries for all existing IRQs.
166 */
167 for (i = 0; i < NR_IRQS; i++)
168 register_irq_proc(i);
169}
170