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