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/kernel_stat.h>
32 #include <linux/errno.h>
33 #include <linux/init.h>
35 #include <asm/setup.h>
36 #include <asm/system.h>
38 #include <asm/traps.h>
40 #include <asm/machdep.h>
41 #include <asm/cacheflush.h>
44 #include <asm/q40ints.h>
47 extern u32 auto_irqhandler_fixup[];
48 extern u32 user_irqhandler_fixup[];
49 extern u16 user_irqvec_fixup[];
51 /* table for system interrupt handlers */
52 static struct irq_node *irq_list[NR_IRQS];
53 static struct irq_controller *irq_controller[NR_IRQS];
54 static int irq_depth[NR_IRQS];
56 static int m68k_first_user_vec;
58 static struct irq_controller auto_irq_controller = {
60 .lock = SPIN_LOCK_UNLOCKED,
61 .startup = m68k_irq_startup,
62 .shutdown = m68k_irq_shutdown,
65 static struct irq_controller user_irq_controller = {
67 .lock = SPIN_LOCK_UNLOCKED,
68 .startup = m68k_irq_startup,
69 .shutdown = m68k_irq_shutdown,
72 #define NUM_IRQ_NODES 100
73 static irq_node_t nodes[NUM_IRQ_NODES];
82 * This function should be called during kernel startup to initialize
83 * the IRQ handling routines.
86 void __init init_IRQ(void)
90 /* assembly irq entry code relies on this... */
91 if (HARDIRQ_MASK != 0x00ff0000) {
92 extern void hardirq_mask_is_broken(void);
93 hardirq_mask_is_broken();
96 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
97 irq_controller[i] = &auto_irq_controller;
103 * m68k_setup_auto_interrupt
104 * @handler: called from auto vector interrupts
106 * setup the handler to be called from auto vector interrupts instead of the
107 * standard m68k_handle_int(), it will be called with irq numbers in the range
108 * from IRQ_AUTO_1 - IRQ_AUTO_7.
110 void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
113 *auto_irqhandler_fixup = (u32)handler;
118 * m68k_setup_user_interrupt
119 * @vec: first user vector interrupt to handle
120 * @cnt: number of active user vector interrupts
121 * @handler: called from user vector interrupts
123 * setup user vector interrupts, this includes activating the specified range
124 * of interrupts, only then these interrupts can be requested (note: this is
125 * different from auto vector interrupts). An optional handler can be installed
126 * to be called instead of the default m68k_handle_int(), it will be called
127 * with irq numbers starting from IRQ_USER.
129 void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
130 void (*handler)(unsigned int, struct pt_regs *))
134 m68k_first_user_vec = vec;
135 for (i = 0; i < cnt; i++)
136 irq_controller[IRQ_USER + i] = &user_irq_controller;
137 *user_irqvec_fixup = vec - IRQ_USER;
139 *user_irqhandler_fixup = (u32)handler;
144 * m68k_setup_irq_controller
145 * @contr: irq controller which controls specified irq
146 * @irq: first irq to be managed by the controller
148 * Change the controller for the specified range of irq, which will be used to
149 * manage these irq. auto/user irq already have a default controller, which can
150 * be changed as well, but the controller probably should use m68k_irq_startup/
153 void m68k_setup_irq_controller(struct irq_controller *contr, unsigned int irq,
158 for (i = 0; i < cnt; i++)
159 irq_controller[irq + i] = contr;
162 irq_node_t *new_irq_node(void)
167 for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
168 if (!node->handler) {
169 memset(node, 0, sizeof(*node));
174 printk ("new_irq_node: out of nodes\n");
178 int setup_irq(unsigned int irq, struct irq_node *node)
180 struct irq_controller *contr;
181 struct irq_node **prev;
184 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
185 printk("%s: Incorrect IRQ %d from %s\n",
186 __FUNCTION__, irq, node->devname);
190 spin_lock_irqsave(&contr->lock, flags);
192 prev = irq_list + irq;
194 /* Can't share interrupts unless both agree to */
195 if (!((*prev)->flags & node->flags & SA_SHIRQ)) {
196 spin_unlock_irqrestore(&contr->lock, flags);
200 prev = &(*prev)->next;
203 if (!irq_list[irq]) {
212 spin_unlock_irqrestore(&contr->lock, flags);
217 int request_irq(unsigned int irq,
218 irqreturn_t (*handler) (int, void *, struct pt_regs *),
219 unsigned long flags, const char *devname, void *dev_id)
221 struct irq_node *node;
224 node = new_irq_node();
228 node->handler = handler;
230 node->dev_id = dev_id;
231 node->devname = devname;
233 res = setup_irq(irq, node);
235 node->handler = NULL;
240 EXPORT_SYMBOL(request_irq);
242 void free_irq(unsigned int irq, void *dev_id)
244 struct irq_controller *contr;
245 struct irq_node **p, *node;
248 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
249 printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
253 spin_lock_irqsave(&contr->lock, flags);
256 while ((node = *p)) {
257 if (node->dev_id == dev_id)
264 node->handler = NULL;
266 printk("%s: Removing probably wrong IRQ %d\n",
269 if (!irq_list[irq]) {
271 contr->shutdown(irq);
276 spin_unlock_irqrestore(&contr->lock, flags);
279 EXPORT_SYMBOL(free_irq);
281 void enable_irq(unsigned int irq)
283 struct irq_controller *contr;
286 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
287 printk("%s: Incorrect IRQ %d\n",
292 spin_lock_irqsave(&contr->lock, flags);
293 if (irq_depth[irq]) {
294 if (!--irq_depth[irq]) {
300 spin_unlock_irqrestore(&contr->lock, flags);
303 EXPORT_SYMBOL(enable_irq);
305 void disable_irq(unsigned int irq)
307 struct irq_controller *contr;
310 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
311 printk("%s: Incorrect IRQ %d\n",
316 spin_lock_irqsave(&contr->lock, flags);
317 if (!irq_depth[irq]++) {
321 spin_unlock_irqrestore(&contr->lock, flags);
324 EXPORT_SYMBOL(disable_irq);
326 int m68k_irq_startup(unsigned int irq)
328 if (irq <= IRQ_AUTO_7)
329 vectors[VEC_SPUR + irq] = auto_inthandler;
331 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
335 void m68k_irq_shutdown(unsigned int irq)
337 if (irq <= IRQ_AUTO_7)
338 vectors[VEC_SPUR + irq] = bad_inthandler;
340 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
345 * Do we need these probe functions on the m68k?
347 * ... may be useful with ISA devices
349 unsigned long probe_irq_on (void)
353 return q40_probe_irq_on();
358 EXPORT_SYMBOL(probe_irq_on);
360 int probe_irq_off (unsigned long irqs)
364 return q40_probe_irq_off(irqs);
369 EXPORT_SYMBOL(probe_irq_off);
371 unsigned int irq_canonicalize(unsigned int irq)
374 if (MACH_IS_Q40 && irq == 11)
380 EXPORT_SYMBOL(irq_canonicalize);
382 asmlinkage void m68k_handle_int(unsigned int irq, struct pt_regs *regs)
384 struct irq_node *node;
386 kstat_cpu(0).irqs[irq]++;
387 node = irq_list[irq];
389 node->handler(irq, node->dev_id, regs);
394 asmlinkage void handle_badint(struct pt_regs *regs)
396 kstat_cpu(0).irqs[0]++;
397 printk("unexpected interrupt from %u\n", regs->vector);
400 int show_interrupts(struct seq_file *p, void *v)
402 struct irq_controller *contr;
403 struct irq_node *node;
404 int i = *(loff_t *) v;
406 /* autovector interrupts */
408 contr = irq_controller[i];
410 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
411 while ((node = node->next))
412 seq_printf(p, ", %s", node->devname);
418 void init_irq_proc(void)
420 /* Insert /proc/irq driver here */