]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/m68k/kernel/ints.c
m68k/irq: Remove obsolete IRQ_FLG_* users
[linux-2.6.git] / arch / m68k / kernel / ints.c
1 /*
2  * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file COPYING in the main directory of this archive
6  * for more details.
7  */
8
9 #include <linux/module.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16
17 #include <asm/setup.h>
18 #include <asm/system.h>
19 #include <asm/irq.h>
20 #include <asm/traps.h>
21 #include <asm/page.h>
22 #include <asm/machdep.h>
23 #include <asm/cacheflush.h>
24 #include <asm/irq_regs.h>
25
26 #ifdef CONFIG_Q40
27 #include <asm/q40ints.h>
28 #endif
29
30 extern u32 auto_irqhandler_fixup[];
31 extern u32 user_irqhandler_fixup[];
32 extern u16 user_irqvec_fixup[];
33
34 /* table for system interrupt handlers */
35 static struct irq_data *irq_list[NR_IRQS];
36 static struct irq_chip *irq_chip[NR_IRQS];
37 static int irq_depth[NR_IRQS];
38
39 static inline int irq_set_chip(unsigned int irq, struct irq_chip *chip)
40 {
41         irq_chip[irq] = chip;
42         return 0;
43 }
44
45 static int m68k_first_user_vec;
46
47 static struct irq_chip auto_irq_chip = {
48         .name           = "auto",
49         .irq_startup    = m68k_irq_startup,
50         .irq_shutdown   = m68k_irq_shutdown,
51 };
52
53 static struct irq_chip user_irq_chip = {
54         .name           = "user",
55         .irq_startup    = m68k_irq_startup,
56         .irq_shutdown   = m68k_irq_shutdown,
57 };
58
59 #define NUM_IRQ_NODES 100
60 static struct irq_data nodes[NUM_IRQ_NODES];
61
62 /*
63  * void init_IRQ(void)
64  *
65  * Parameters:  None
66  *
67  * Returns:     Nothing
68  *
69  * This function should be called during kernel startup to initialize
70  * the IRQ handling routines.
71  */
72
73 void __init init_IRQ(void)
74 {
75         int i;
76
77         /* assembly irq entry code relies on this... */
78         if (HARDIRQ_MASK != 0x00ff0000) {
79                 extern void hardirq_mask_is_broken(void);
80                 hardirq_mask_is_broken();
81         }
82
83         for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
84                 irq_set_chip(i, &auto_irq_chip);
85
86         mach_init_IRQ();
87 }
88
89 /**
90  * m68k_setup_auto_interrupt
91  * @handler: called from auto vector interrupts
92  *
93  * setup the handler to be called from auto vector interrupts instead of the
94  * standard do_IRQ(), it will be called with irq numbers in the range
95  * from IRQ_AUTO_1 - IRQ_AUTO_7.
96  */
97 void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
98 {
99         if (handler)
100                 *auto_irqhandler_fixup = (u32)handler;
101         flush_icache();
102 }
103
104 /**
105  * m68k_setup_user_interrupt
106  * @vec: first user vector interrupt to handle
107  * @cnt: number of active user vector interrupts
108  * @handler: called from user vector interrupts
109  *
110  * setup user vector interrupts, this includes activating the specified range
111  * of interrupts, only then these interrupts can be requested (note: this is
112  * different from auto vector interrupts). An optional handler can be installed
113  * to be called instead of the default do_IRQ(), it will be called
114  * with irq numbers starting from IRQ_USER.
115  */
116 void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
117                                       void (*handler)(unsigned int, struct pt_regs *))
118 {
119         int i;
120
121         BUG_ON(IRQ_USER + cnt > NR_IRQS);
122         m68k_first_user_vec = vec;
123         for (i = 0; i < cnt; i++)
124                 irq_set_chip(IRQ_USER + i, &user_irq_chip);
125         *user_irqvec_fixup = vec - IRQ_USER;
126         if (handler)
127                 *user_irqhandler_fixup = (u32)handler;
128         flush_icache();
129 }
130
131 /**
132  * m68k_setup_irq_chip
133  * @contr: irq controller which controls specified irq
134  * @irq: first irq to be managed by the controller
135  *
136  * Change the controller for the specified range of irq, which will be used to
137  * manage these irq. auto/user irq already have a default controller, which can
138  * be changed as well, but the controller probably should use m68k_irq_startup/
139  * m68k_irq_shutdown.
140  */
141 void m68k_setup_irq_chip(struct irq_chip *contr, unsigned int irq,
142                                unsigned int cnt)
143 {
144         int i;
145
146         for (i = 0; i < cnt; i++)
147                 irq_set_chip(irq + i, contr);
148 }
149
150 struct irq_data *new_irq_node(void)
151 {
152         struct irq_data *node;
153         short i;
154
155         for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
156                 if (!node->handler) {
157                         memset(node, 0, sizeof(*node));
158                         return node;
159                 }
160         }
161
162         printk ("new_irq_node: out of nodes\n");
163         return NULL;
164 }
165
166 static int m68k_setup_irq(unsigned int irq, struct irq_data *node)
167 {
168         struct irq_chip *contr;
169         struct irq_data **prev;
170         unsigned long flags;
171
172         if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
173                 printk("%s: Incorrect IRQ %d from %s\n",
174                        __func__, irq, node->devname);
175                 return -ENXIO;
176         }
177
178         local_irq_save(flags);
179
180         prev = irq_list + irq;
181         if (*prev) {
182                 /* Can't share interrupts unless both agree to */
183                 if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
184                         local_irq_restore(flags);
185                         return -EBUSY;
186                 }
187                 while (*prev)
188                         prev = &(*prev)->next;
189         }
190
191         if (!irq_list[irq]) {
192                 if (contr->irq_startup)
193                         contr->irq_startup(node);
194                 else
195                         contr->irq_enable(node);
196         }
197         node->next = NULL;
198         *prev = node;
199
200         local_irq_restore(flags);
201
202         return 0;
203 }
204
205 int request_irq(unsigned int irq,
206                 irq_handler_t handler,
207                 unsigned long flags, const char *devname, void *dev_id)
208 {
209         struct irq_data *node;
210         int res;
211
212         node = new_irq_node();
213         if (!node)
214                 return -ENOMEM;
215
216         node->irq     = irq;
217         node->handler = handler;
218         node->flags   = flags;
219         node->dev_id  = dev_id;
220         node->devname = devname;
221
222         res = m68k_setup_irq(irq, node);
223         if (res)
224                 node->handler = NULL;
225
226         return res;
227 }
228
229 EXPORT_SYMBOL(request_irq);
230
231 void free_irq(unsigned int irq, void *dev_id)
232 {
233         struct irq_chip *contr;
234         struct irq_data **p, *node;
235         unsigned long flags;
236
237         if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
238                 printk("%s: Incorrect IRQ %d\n", __func__, irq);
239                 return;
240         }
241
242         local_irq_save(flags);
243
244         p = irq_list + irq;
245         while ((node = *p)) {
246                 if (node->dev_id == dev_id)
247                         break;
248                 p = &node->next;
249         }
250
251         if (node) {
252                 *p = node->next;
253                 node->handler = NULL;
254         } else
255                 printk("%s: Removing probably wrong IRQ %d\n",
256                        __func__, irq);
257
258         if (!irq_list[irq]) {
259                 if (contr->irq_shutdown)
260                         contr->irq_shutdown(node);
261                 else
262                         contr->irq_disable(node);
263         }
264
265         local_irq_restore(flags);
266 }
267
268 EXPORT_SYMBOL(free_irq);
269
270 void enable_irq(unsigned int irq)
271 {
272         struct irq_chip *contr;
273         unsigned long flags;
274
275         if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
276                 printk("%s: Incorrect IRQ %d\n",
277                        __func__, irq);
278                 return;
279         }
280
281         local_irq_save(flags);
282         if (irq_depth[irq]) {
283                 if (!--irq_depth[irq]) {
284                         if (contr->irq_enable)
285                                 contr->irq_enable(irq_list[irq]);
286                 }
287         } else
288                 WARN_ON(1);
289         local_irq_restore(flags);
290 }
291
292 EXPORT_SYMBOL(enable_irq);
293
294 void disable_irq(unsigned int irq)
295 {
296         struct irq_chip *contr;
297         unsigned long flags;
298
299         if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
300                 printk("%s: Incorrect IRQ %d\n",
301                        __func__, irq);
302                 return;
303         }
304
305         local_irq_save(flags);
306         if (!irq_depth[irq]++) {
307                 if (contr->irq_disable)
308                         contr->irq_disable(irq_list[irq]);
309         }
310         local_irq_restore(flags);
311 }
312
313 EXPORT_SYMBOL(disable_irq);
314
315 void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
316
317 EXPORT_SYMBOL(disable_irq_nosync);
318
319 unsigned int m68k_irq_startup_irq(unsigned int irq)
320 {
321         if (irq <= IRQ_AUTO_7)
322                 vectors[VEC_SPUR + irq] = auto_inthandler;
323         else
324                 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
325         return 0;
326 }
327
328 unsigned int m68k_irq_startup(struct irq_data *data)
329 {
330         return m68k_irq_startup_irq(data->irq);
331 }
332
333 void m68k_irq_shutdown(struct irq_data *data)
334 {
335         unsigned int irq = data->irq;
336
337         if (irq <= IRQ_AUTO_7)
338                 vectors[VEC_SPUR + irq] = bad_inthandler;
339         else
340                 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
341 }
342
343
344 /*
345  * Do we need these probe functions on the m68k?
346  *
347  *  ... may be useful with ISA devices
348  */
349 unsigned long probe_irq_on (void)
350 {
351 #ifdef CONFIG_Q40
352         if (MACH_IS_Q40)
353                 return q40_probe_irq_on();
354 #endif
355         return 0;
356 }
357
358 EXPORT_SYMBOL(probe_irq_on);
359
360 int probe_irq_off (unsigned long irqs)
361 {
362 #ifdef CONFIG_Q40
363         if (MACH_IS_Q40)
364                 return q40_probe_irq_off(irqs);
365 #endif
366         return 0;
367 }
368
369 EXPORT_SYMBOL(probe_irq_off);
370
371 unsigned int irq_canonicalize(unsigned int irq)
372 {
373 #ifdef CONFIG_Q40
374         if (MACH_IS_Q40 && irq == 11)
375                 irq = 10;
376 #endif
377         return irq;
378 }
379
380 EXPORT_SYMBOL(irq_canonicalize);
381
382 void generic_handle_irq(unsigned int irq)
383 {
384         struct irq_data *node;
385         kstat_cpu(0).irqs[irq]++;
386         node = irq_list[irq];
387         do {
388                 node->handler(irq, node->dev_id);
389                 node = node->next;
390         } while (node);
391 }
392
393 asmlinkage void do_IRQ(int irq, struct pt_regs *regs)
394 {
395         struct pt_regs *old_regs;
396         old_regs = set_irq_regs(regs);
397         generic_handle_irq(irq);
398         set_irq_regs(old_regs);
399 }
400
401 asmlinkage void handle_badint(struct pt_regs *regs)
402 {
403         kstat_cpu(0).irqs[0]++;
404         printk("unexpected interrupt from %u\n", regs->vector);
405 }
406
407 int show_interrupts(struct seq_file *p, void *v)
408 {
409         struct irq_chip *contr;
410         struct irq_data *node;
411         int i = *(loff_t *) v;
412
413         /* autovector interrupts */
414         if (irq_list[i]) {
415                 contr = irq_chip[i];
416                 node = irq_list[i];
417                 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
418                 while ((node = node->next))
419                         seq_printf(p, ", %s", node->devname);
420                 seq_puts(p, "\n");
421         }
422         return 0;
423 }
424
425 #ifdef CONFIG_PROC_FS
426 void init_irq_proc(void)
427 {
428         /* Insert /proc/irq driver here */
429 }
430 #endif