2 * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
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
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
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
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>
36 #include <asm/setup.h>
37 #include <asm/system.h>
39 #include <asm/traps.h>
41 #include <asm/machdep.h>
42 #include <asm/cacheflush.h>
43 #include <asm/irq_regs.h>
46 #include <asm/q40ints.h>
49 extern u32 auto_irqhandler_fixup[];
50 extern u32 user_irqhandler_fixup[];
51 extern u16 user_irqvec_fixup[];
53 /* table for system interrupt handlers */
54 static struct irq_data *irq_list[NR_IRQS];
55 static struct irq_chip *irq_chip[NR_IRQS];
56 static int irq_depth[NR_IRQS];
58 static inline int irq_set_chip(unsigned int irq, struct irq_chip *chip)
64 static int m68k_first_user_vec;
66 static struct irq_chip auto_irq_chip = {
68 .irq_startup = m68k_irq_startup,
69 .irq_shutdown = m68k_irq_shutdown,
72 static struct irq_chip user_irq_chip = {
74 .irq_startup = m68k_irq_startup,
75 .irq_shutdown = m68k_irq_shutdown,
78 #define NUM_IRQ_NODES 100
79 static struct irq_data nodes[NUM_IRQ_NODES];
88 * This function should be called during kernel startup to initialize
89 * the IRQ handling routines.
92 void __init init_IRQ(void)
96 /* assembly irq entry code relies on this... */
97 if (HARDIRQ_MASK != 0x00ff0000) {
98 extern void hardirq_mask_is_broken(void);
99 hardirq_mask_is_broken();
102 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
103 irq_set_chip(i, &auto_irq_chip);
109 * m68k_setup_auto_interrupt
110 * @handler: called from auto vector interrupts
112 * setup the handler to be called from auto vector interrupts instead of the
113 * standard __m68k_handle_int(), it will be called with irq numbers in the range
114 * from IRQ_AUTO_1 - IRQ_AUTO_7.
116 void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
119 *auto_irqhandler_fixup = (u32)handler;
124 * m68k_setup_user_interrupt
125 * @vec: first user vector interrupt to handle
126 * @cnt: number of active user vector interrupts
127 * @handler: called from user vector interrupts
129 * setup user vector interrupts, this includes activating the specified range
130 * of interrupts, only then these interrupts can be requested (note: this is
131 * different from auto vector interrupts). An optional handler can be installed
132 * to be called instead of the default __m68k_handle_int(), it will be called
133 * with irq numbers starting from IRQ_USER.
135 void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
136 void (*handler)(unsigned int, struct pt_regs *))
140 BUG_ON(IRQ_USER + cnt > NR_IRQS);
141 m68k_first_user_vec = vec;
142 for (i = 0; i < cnt; i++)
143 irq_set_chip(IRQ_USER + i, &user_irq_chip);
144 *user_irqvec_fixup = vec - IRQ_USER;
146 *user_irqhandler_fixup = (u32)handler;
151 * m68k_setup_irq_chip
152 * @contr: irq controller which controls specified irq
153 * @irq: first irq to be managed by the controller
155 * Change the controller for the specified range of irq, which will be used to
156 * manage these irq. auto/user irq already have a default controller, which can
157 * be changed as well, but the controller probably should use m68k_irq_startup/
160 void m68k_setup_irq_chip(struct irq_chip *contr, unsigned int irq,
165 for (i = 0; i < cnt; i++)
166 irq_set_chip(irq + i, contr);
169 struct irq_data *new_irq_node(void)
171 struct irq_data *node;
174 for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
175 if (!node->handler) {
176 memset(node, 0, sizeof(*node));
181 printk ("new_irq_node: out of nodes\n");
185 static int m68k_setup_irq(unsigned int irq, struct irq_data *node)
187 struct irq_chip *contr;
188 struct irq_data **prev;
191 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
192 printk("%s: Incorrect IRQ %d from %s\n",
193 __func__, irq, node->devname);
197 local_irq_save(flags);
199 prev = irq_list + irq;
201 /* Can't share interrupts unless both agree to */
202 if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
203 local_irq_restore(flags);
207 prev = &(*prev)->next;
210 if (!irq_list[irq]) {
211 if (contr->irq_startup)
212 contr->irq_startup(node);
214 contr->irq_enable(node);
219 local_irq_restore(flags);
224 int request_irq(unsigned int irq,
225 irq_handler_t handler,
226 unsigned long flags, const char *devname, void *dev_id)
228 struct irq_data *node;
231 node = new_irq_node();
236 node->handler = handler;
238 node->dev_id = dev_id;
239 node->devname = devname;
241 res = m68k_setup_irq(irq, node);
243 node->handler = NULL;
248 EXPORT_SYMBOL(request_irq);
250 void free_irq(unsigned int irq, void *dev_id)
252 struct irq_chip *contr;
253 struct irq_data **p, *node;
256 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
257 printk("%s: Incorrect IRQ %d\n", __func__, irq);
261 local_irq_save(flags);
264 while ((node = *p)) {
265 if (node->dev_id == dev_id)
272 node->handler = NULL;
274 printk("%s: Removing probably wrong IRQ %d\n",
277 if (!irq_list[irq]) {
278 if (contr->irq_shutdown)
279 contr->irq_shutdown(node);
281 contr->irq_disable(node);
284 local_irq_restore(flags);
287 EXPORT_SYMBOL(free_irq);
289 void enable_irq(unsigned int irq)
291 struct irq_chip *contr;
294 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
295 printk("%s: Incorrect IRQ %d\n",
300 local_irq_save(flags);
301 if (irq_depth[irq]) {
302 if (!--irq_depth[irq]) {
303 if (contr->irq_enable)
304 contr->irq_enable(irq_list[irq]);
308 local_irq_restore(flags);
311 EXPORT_SYMBOL(enable_irq);
313 void disable_irq(unsigned int irq)
315 struct irq_chip *contr;
318 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
319 printk("%s: Incorrect IRQ %d\n",
324 local_irq_save(flags);
325 if (!irq_depth[irq]++) {
326 if (contr->irq_disable)
327 contr->irq_disable(irq_list[irq]);
329 local_irq_restore(flags);
332 EXPORT_SYMBOL(disable_irq);
334 void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
336 EXPORT_SYMBOL(disable_irq_nosync);
338 unsigned int m68k_irq_startup_irq(unsigned int irq)
340 if (irq <= IRQ_AUTO_7)
341 vectors[VEC_SPUR + irq] = auto_inthandler;
343 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
347 unsigned int m68k_irq_startup(struct irq_data *data)
349 return m68k_irq_startup_irq(data->irq);
352 void m68k_irq_shutdown(struct irq_data *data)
354 unsigned int irq = data->irq;
356 if (irq <= IRQ_AUTO_7)
357 vectors[VEC_SPUR + irq] = bad_inthandler;
359 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
364 * Do we need these probe functions on the m68k?
366 * ... may be useful with ISA devices
368 unsigned long probe_irq_on (void)
372 return q40_probe_irq_on();
377 EXPORT_SYMBOL(probe_irq_on);
379 int probe_irq_off (unsigned long irqs)
383 return q40_probe_irq_off(irqs);
388 EXPORT_SYMBOL(probe_irq_off);
390 unsigned int irq_canonicalize(unsigned int irq)
393 if (MACH_IS_Q40 && irq == 11)
399 EXPORT_SYMBOL(irq_canonicalize);
401 asmlinkage void m68k_handle_int(unsigned int irq)
403 struct irq_data *node;
404 kstat_cpu(0).irqs[irq]++;
405 node = irq_list[irq];
407 node->handler(irq, node->dev_id);
412 asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
414 struct pt_regs *old_regs;
415 old_regs = set_irq_regs(regs);
416 m68k_handle_int(irq);
417 set_irq_regs(old_regs);
420 asmlinkage void handle_badint(struct pt_regs *regs)
422 kstat_cpu(0).irqs[0]++;
423 printk("unexpected interrupt from %u\n", regs->vector);
426 int show_interrupts(struct seq_file *p, void *v)
428 struct irq_chip *contr;
429 struct irq_data *node;
430 int i = *(loff_t *) v;
432 /* autovector interrupts */
436 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
437 while ((node = node->next))
438 seq_printf(p, ", %s", node->devname);
444 #ifdef CONFIG_PROC_FS
445 void init_irq_proc(void)
447 /* Insert /proc/irq driver here */