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 int nr_irqs = NR_IRQS;
50 EXPORT_SYMBOL(nr_irqs);
52 extern u32 auto_irqhandler_fixup[];
53 extern u32 user_irqhandler_fixup[];
54 extern u16 user_irqvec_fixup[];
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];
61 static int m68k_first_user_vec;
63 static struct irq_controller auto_irq_controller = {
65 .lock = __SPIN_LOCK_UNLOCKED(auto_irq_controller.lock),
66 .startup = m68k_irq_startup,
67 .shutdown = m68k_irq_shutdown,
70 static struct irq_controller user_irq_controller = {
72 .lock = __SPIN_LOCK_UNLOCKED(user_irq_controller.lock),
73 .startup = m68k_irq_startup,
74 .shutdown = m68k_irq_shutdown,
77 #define NUM_IRQ_NODES 100
78 static irq_node_t nodes[NUM_IRQ_NODES];
87 * This function should be called during kernel startup to initialize
88 * the IRQ handling routines.
91 void __init init_IRQ(void)
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();
101 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
102 irq_controller[i] = &auto_irq_controller;
108 * m68k_setup_auto_interrupt
109 * @handler: called from auto vector interrupts
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.
115 void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
118 *auto_irqhandler_fixup = (u32)handler;
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
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.
134 void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
135 void (*handler)(unsigned int, struct pt_regs *))
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;
145 *user_irqhandler_fixup = (u32)handler;
150 * m68k_setup_irq_controller
151 * @contr: irq controller which controls specified irq
152 * @irq: first irq to be managed by the controller
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/
159 void m68k_setup_irq_controller(struct irq_controller *contr, unsigned int irq,
164 for (i = 0; i < cnt; i++)
165 irq_controller[irq + i] = contr;
168 irq_node_t *new_irq_node(void)
173 for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
174 if (!node->handler) {
175 memset(node, 0, sizeof(*node));
180 printk ("new_irq_node: out of nodes\n");
184 int setup_irq(unsigned int irq, struct irq_node *node)
186 struct irq_controller *contr;
187 struct irq_node **prev;
190 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
191 printk("%s: Incorrect IRQ %d from %s\n",
192 __func__, irq, node->devname);
196 spin_lock_irqsave(&contr->lock, flags);
198 prev = irq_list + irq;
200 /* Can't share interrupts unless both agree to */
201 if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
202 spin_unlock_irqrestore(&contr->lock, flags);
206 prev = &(*prev)->next;
209 if (!irq_list[irq]) {
218 spin_unlock_irqrestore(&contr->lock, flags);
223 int request_irq(unsigned int irq,
224 irq_handler_t handler,
225 unsigned long flags, const char *devname, void *dev_id)
227 struct irq_node *node;
230 node = new_irq_node();
234 node->handler = handler;
236 node->dev_id = dev_id;
237 node->devname = devname;
239 res = setup_irq(irq, node);
241 node->handler = NULL;
246 EXPORT_SYMBOL(request_irq);
248 void free_irq(unsigned int irq, void *dev_id)
250 struct irq_controller *contr;
251 struct irq_node **p, *node;
254 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
255 printk("%s: Incorrect IRQ %d\n", __func__, irq);
259 spin_lock_irqsave(&contr->lock, flags);
262 while ((node = *p)) {
263 if (node->dev_id == dev_id)
270 node->handler = NULL;
272 printk("%s: Removing probably wrong IRQ %d\n",
275 if (!irq_list[irq]) {
277 contr->shutdown(irq);
282 spin_unlock_irqrestore(&contr->lock, flags);
285 EXPORT_SYMBOL(free_irq);
287 void enable_irq(unsigned int irq)
289 struct irq_controller *contr;
292 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
293 printk("%s: Incorrect IRQ %d\n",
298 spin_lock_irqsave(&contr->lock, flags);
299 if (irq_depth[irq]) {
300 if (!--irq_depth[irq]) {
306 spin_unlock_irqrestore(&contr->lock, flags);
309 EXPORT_SYMBOL(enable_irq);
311 void disable_irq(unsigned int irq)
313 struct irq_controller *contr;
316 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
317 printk("%s: Incorrect IRQ %d\n",
322 spin_lock_irqsave(&contr->lock, flags);
323 if (!irq_depth[irq]++) {
327 spin_unlock_irqrestore(&contr->lock, flags);
330 EXPORT_SYMBOL(disable_irq);
332 void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
334 EXPORT_SYMBOL(disable_irq_nosync);
336 int m68k_irq_startup(unsigned int irq)
338 if (irq <= IRQ_AUTO_7)
339 vectors[VEC_SPUR + irq] = auto_inthandler;
341 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
345 void m68k_irq_shutdown(unsigned int irq)
347 if (irq <= IRQ_AUTO_7)
348 vectors[VEC_SPUR + irq] = bad_inthandler;
350 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
355 * Do we need these probe functions on the m68k?
357 * ... may be useful with ISA devices
359 unsigned long probe_irq_on (void)
363 return q40_probe_irq_on();
368 EXPORT_SYMBOL(probe_irq_on);
370 int probe_irq_off (unsigned long irqs)
374 return q40_probe_irq_off(irqs);
379 EXPORT_SYMBOL(probe_irq_off);
381 unsigned int irq_canonicalize(unsigned int irq)
384 if (MACH_IS_Q40 && irq == 11)
390 EXPORT_SYMBOL(irq_canonicalize);
392 asmlinkage void m68k_handle_int(unsigned int irq)
394 struct irq_node *node;
395 kstat_cpu(0).irqs[irq]++;
396 node = irq_list[irq];
398 node->handler(irq, node->dev_id);
403 asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
405 struct pt_regs *old_regs;
406 old_regs = set_irq_regs(regs);
407 m68k_handle_int(irq);
408 set_irq_regs(old_regs);
411 asmlinkage void handle_badint(struct pt_regs *regs)
413 kstat_cpu(0).irqs[0]++;
414 printk("unexpected interrupt from %u\n", regs->vector);
417 int show_interrupts(struct seq_file *p, void *v)
419 struct irq_controller *contr;
420 struct irq_node *node;
421 int i = *(loff_t *) v;
423 /* autovector interrupts */
425 contr = irq_controller[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);
435 #ifdef CONFIG_PROC_FS
436 void init_irq_proc(void)
438 /* Insert /proc/irq driver here */