Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh...
[GitHub/mt8127/android_kernel_alcatel_ttab.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
1da177e4
LT
19static int irq_affinity_read_proc(char *page, char **start, off_t off,
20 int count, int *eof, void *data)
21{
42ee2b74
AK
22 struct irq_desc *desc = irq_desc + (long)data;
23 cpumask_t *mask = &desc->affinity;
24 int len;
25
26#ifdef CONFIG_GENERIC_PENDING_IRQ
27 if (desc->status & IRQ_MOVE_PENDING)
28 mask = &desc->pending_mask;
29#endif
30 len = cpumask_scnprintf(page, count, *mask);
1da177e4
LT
31
32 if (count - len < 2)
33 return -EINVAL;
34 len += sprintf(page + len, "\n");
35 return len;
36}
37
25d61578
JK
38#ifndef is_affinity_mask_valid
39#define is_affinity_mask_valid(val) 1
40#endif
41
1da177e4
LT
42int no_irq_affinity;
43static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
44 unsigned long count, void *data)
45{
46 unsigned int irq = (int)(long)data, full_count = count, err;
47 cpumask_t new_value, tmp;
48
6e2ac664 49 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
950f4427 50 irq_balancing_disabled(irq))
1da177e4
LT
51 return -EIO;
52
01a3ee2b 53 err = cpumask_parse_user(buffer, count, new_value);
1da177e4
LT
54 if (err)
55 return err;
56
25d61578
JK
57 if (!is_affinity_mask_valid(new_value))
58 return -EINVAL;
59
1da177e4
LT
60 /*
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.
64 */
65 cpus_and(tmp, new_value, cpu_online_map);
66 if (cpus_empty(tmp))
eee45269
IK
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;
1da177e4 70
771ee3b0 71 irq_set_affinity(irq, new_value);
1da177e4
LT
72
73 return full_count;
74}
75
76#endif
77
78#define MAX_NAMELEN 128
79
80static int name_unique(unsigned int irq, struct irqaction *new_action)
81{
82 struct irq_desc *desc = irq_desc + irq;
83 struct irqaction *action;
d2d9433a
DA
84 unsigned long flags;
85 int ret = 1;
1da177e4 86
d2d9433a
DA
87 spin_lock_irqsave(&desc->lock, flags);
88 for (action = desc->action ; action; action = action->next) {
1da177e4 89 if ((action != new_action) && action->name &&
d2d9433a
DA
90 !strcmp(new_action->name, action->name)) {
91 ret = 0;
92 break;
93 }
94 }
95 spin_unlock_irqrestore(&desc->lock, flags);
96 return ret;
1da177e4
LT
97}
98
99void register_handler_proc(unsigned int irq, struct irqaction *action)
100{
101 char name [MAX_NAMELEN];
102
4a733ee1 103 if (!irq_desc[irq].dir || action->dir || !action->name ||
1da177e4
LT
104 !name_unique(irq, action))
105 return;
106
107 memset(name, 0, MAX_NAMELEN);
108 snprintf(name, MAX_NAMELEN, "%s", action->name);
109
110 /* create /proc/irq/1234/handler/ */
4a733ee1 111 action->dir = proc_mkdir(name, irq_desc[irq].dir);
1da177e4
LT
112}
113
114#undef MAX_NAMELEN
115
116#define MAX_NAMELEN 10
117
118void register_irq_proc(unsigned int irq)
119{
120 char name [MAX_NAMELEN];
121
122 if (!root_irq_dir ||
f1c2662c 123 (irq_desc[irq].chip == &no_irq_chip) ||
4a733ee1 124 irq_desc[irq].dir)
1da177e4
LT
125 return;
126
127 memset(name, 0, MAX_NAMELEN);
128 sprintf(name, "%d", irq);
129
130 /* create /proc/irq/1234 */
4a733ee1 131 irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
1da177e4
LT
132
133#ifdef CONFIG_SMP
134 {
135 struct proc_dir_entry *entry;
136
137 /* create /proc/irq/<irq>/smp_affinity */
4a733ee1 138 entry = create_proc_entry("smp_affinity", 0600, irq_desc[irq].dir);
1da177e4
LT
139
140 if (entry) {
1da177e4
LT
141 entry->data = (void *)(long)irq;
142 entry->read_proc = irq_affinity_read_proc;
143 entry->write_proc = irq_affinity_write_proc;
144 }
1da177e4
LT
145 }
146#endif
147}
148
149#undef MAX_NAMELEN
150
151void unregister_handler_proc(unsigned int irq, struct irqaction *action)
152{
153 if (action->dir)
4a733ee1 154 remove_proc_entry(action->dir->name, irq_desc[irq].dir);
1da177e4
LT
155}
156
157void init_irq_proc(void)
158{
159 int i;
160
161 /* create /proc/irq */
162 root_irq_dir = proc_mkdir("irq", NULL);
163 if (!root_irq_dir)
164 return;
165
166 /*
167 * Create entries for all existing IRQs.
168 */
169 for (i = 0; i < NR_IRQS; i++)
170 register_irq_proc(i);
171}
172