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