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