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_node
*irq_list
[NR_IRQS
];
55 static struct irq_controller
*irq_controller
[NR_IRQS
];
56 static int irq_depth
[NR_IRQS
];
58 static int m68k_first_user_vec
;
60 static struct irq_controller auto_irq_controller
= {
62 .lock
= __SPIN_LOCK_UNLOCKED(auto_irq_controller
.lock
),
63 .startup
= m68k_irq_startup
,
64 .shutdown
= m68k_irq_shutdown
,
67 static struct irq_controller user_irq_controller
= {
69 .lock
= __SPIN_LOCK_UNLOCKED(user_irq_controller
.lock
),
70 .startup
= m68k_irq_startup
,
71 .shutdown
= m68k_irq_shutdown
,
74 #define NUM_IRQ_NODES 100
75 static irq_node_t nodes
[NUM_IRQ_NODES
];
84 * This function should be called during kernel startup to initialize
85 * the IRQ handling routines.
88 void __init
init_IRQ(void)
92 /* assembly irq entry code relies on this... */
93 if (HARDIRQ_MASK
!= 0x00ff0000) {
94 extern void hardirq_mask_is_broken(void);
95 hardirq_mask_is_broken();
98 for (i
= IRQ_AUTO_1
; i
<= IRQ_AUTO_7
; i
++)
99 irq_controller
[i
] = &auto_irq_controller
;
105 * m68k_setup_auto_interrupt
106 * @handler: called from auto vector interrupts
108 * setup the handler to be called from auto vector interrupts instead of the
109 * standard __m68k_handle_int(), it will be called with irq numbers in the range
110 * from IRQ_AUTO_1 - IRQ_AUTO_7.
112 void __init
m68k_setup_auto_interrupt(void (*handler
)(unsigned int, struct pt_regs
*))
115 *auto_irqhandler_fixup
= (u32
)handler
;
120 * m68k_setup_user_interrupt
121 * @vec: first user vector interrupt to handle
122 * @cnt: number of active user vector interrupts
123 * @handler: called from user vector interrupts
125 * setup user vector interrupts, this includes activating the specified range
126 * of interrupts, only then these interrupts can be requested (note: this is
127 * different from auto vector interrupts). An optional handler can be installed
128 * to be called instead of the default __m68k_handle_int(), it will be called
129 * with irq numbers starting from IRQ_USER.
131 void __init
m68k_setup_user_interrupt(unsigned int vec
, unsigned int cnt
,
132 void (*handler
)(unsigned int, struct pt_regs
*))
136 BUG_ON(IRQ_USER
+ cnt
>= NR_IRQS
);
137 m68k_first_user_vec
= vec
;
138 for (i
= 0; i
< cnt
; i
++)
139 irq_controller
[IRQ_USER
+ i
] = &user_irq_controller
;
140 *user_irqvec_fixup
= vec
- IRQ_USER
;
142 *user_irqhandler_fixup
= (u32
)handler
;
147 * m68k_setup_irq_controller
148 * @contr: irq controller which controls specified irq
149 * @irq: first irq to be managed by the controller
151 * Change the controller for the specified range of irq, which will be used to
152 * manage these irq. auto/user irq already have a default controller, which can
153 * be changed as well, but the controller probably should use m68k_irq_startup/
156 void m68k_setup_irq_controller(struct irq_controller
*contr
, unsigned int irq
,
161 for (i
= 0; i
< cnt
; i
++)
162 irq_controller
[irq
+ i
] = contr
;
165 irq_node_t
*new_irq_node(void)
170 for (node
= nodes
, i
= NUM_IRQ_NODES
-1; i
>= 0; node
++, i
--) {
171 if (!node
->handler
) {
172 memset(node
, 0, sizeof(*node
));
177 printk ("new_irq_node: out of nodes\n");
181 int setup_irq(unsigned int irq
, struct irq_node
*node
)
183 struct irq_controller
*contr
;
184 struct irq_node
**prev
;
187 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
188 printk("%s: Incorrect IRQ %d from %s\n",
189 __func__
, irq
, node
->devname
);
193 spin_lock_irqsave(&contr
->lock
, flags
);
195 prev
= irq_list
+ irq
;
197 /* Can't share interrupts unless both agree to */
198 if (!((*prev
)->flags
& node
->flags
& IRQF_SHARED
)) {
199 spin_unlock_irqrestore(&contr
->lock
, flags
);
203 prev
= &(*prev
)->next
;
206 if (!irq_list
[irq
]) {
215 spin_unlock_irqrestore(&contr
->lock
, flags
);
220 int request_irq(unsigned int irq
,
221 irq_handler_t handler
,
222 unsigned long flags
, const char *devname
, void *dev_id
)
224 struct irq_node
*node
;
227 node
= new_irq_node();
231 node
->handler
= handler
;
233 node
->dev_id
= dev_id
;
234 node
->devname
= devname
;
236 res
= setup_irq(irq
, node
);
238 node
->handler
= NULL
;
243 EXPORT_SYMBOL(request_irq
);
245 void free_irq(unsigned int irq
, void *dev_id
)
247 struct irq_controller
*contr
;
248 struct irq_node
**p
, *node
;
251 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
252 printk("%s: Incorrect IRQ %d\n", __func__
, irq
);
256 spin_lock_irqsave(&contr
->lock
, flags
);
259 while ((node
= *p
)) {
260 if (node
->dev_id
== dev_id
)
267 node
->handler
= NULL
;
269 printk("%s: Removing probably wrong IRQ %d\n",
272 if (!irq_list
[irq
]) {
274 contr
->shutdown(irq
);
279 spin_unlock_irqrestore(&contr
->lock
, flags
);
282 EXPORT_SYMBOL(free_irq
);
284 void enable_irq(unsigned int irq
)
286 struct irq_controller
*contr
;
289 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
290 printk("%s: Incorrect IRQ %d\n",
295 spin_lock_irqsave(&contr
->lock
, flags
);
296 if (irq_depth
[irq
]) {
297 if (!--irq_depth
[irq
]) {
303 spin_unlock_irqrestore(&contr
->lock
, flags
);
306 EXPORT_SYMBOL(enable_irq
);
308 void disable_irq(unsigned int irq
)
310 struct irq_controller
*contr
;
313 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
314 printk("%s: Incorrect IRQ %d\n",
319 spin_lock_irqsave(&contr
->lock
, flags
);
320 if (!irq_depth
[irq
]++) {
324 spin_unlock_irqrestore(&contr
->lock
, flags
);
327 EXPORT_SYMBOL(disable_irq
);
329 void disable_irq_nosync(unsigned int irq
) __attribute__((alias("disable_irq")));
331 EXPORT_SYMBOL(disable_irq_nosync
);
333 int m68k_irq_startup(unsigned int irq
)
335 if (irq
<= IRQ_AUTO_7
)
336 vectors
[VEC_SPUR
+ irq
] = auto_inthandler
;
338 vectors
[m68k_first_user_vec
+ irq
- IRQ_USER
] = user_inthandler
;
342 void m68k_irq_shutdown(unsigned int irq
)
344 if (irq
<= IRQ_AUTO_7
)
345 vectors
[VEC_SPUR
+ irq
] = bad_inthandler
;
347 vectors
[m68k_first_user_vec
+ irq
- IRQ_USER
] = bad_inthandler
;
352 * Do we need these probe functions on the m68k?
354 * ... may be useful with ISA devices
356 unsigned long probe_irq_on (void)
360 return q40_probe_irq_on();
365 EXPORT_SYMBOL(probe_irq_on
);
367 int probe_irq_off (unsigned long irqs
)
371 return q40_probe_irq_off(irqs
);
376 EXPORT_SYMBOL(probe_irq_off
);
378 unsigned int irq_canonicalize(unsigned int irq
)
381 if (MACH_IS_Q40
&& irq
== 11)
387 EXPORT_SYMBOL(irq_canonicalize
);
389 asmlinkage
void m68k_handle_int(unsigned int irq
)
391 struct irq_node
*node
;
392 kstat_cpu(0).irqs
[irq
]++;
393 node
= irq_list
[irq
];
395 node
->handler(irq
, node
->dev_id
);
400 asmlinkage
void __m68k_handle_int(unsigned int irq
, struct pt_regs
*regs
)
402 struct pt_regs
*old_regs
;
403 old_regs
= set_irq_regs(regs
);
404 m68k_handle_int(irq
);
405 set_irq_regs(old_regs
);
408 asmlinkage
void handle_badint(struct pt_regs
*regs
)
410 kstat_cpu(0).irqs
[0]++;
411 printk("unexpected interrupt from %u\n", regs
->vector
);
414 int show_interrupts(struct seq_file
*p
, void *v
)
416 struct irq_controller
*contr
;
417 struct irq_node
*node
;
418 int i
= *(loff_t
*) v
;
420 /* autovector interrupts */
422 contr
= irq_controller
[i
];
424 seq_printf(p
, "%-8s %3u: %10u %s", contr
->name
, i
, kstat_cpu(0).irqs
[i
], node
->devname
);
425 while ((node
= node
->next
))
426 seq_printf(p
, ", %s", node
->devname
);
432 void init_irq_proc(void)
434 /* Insert /proc/irq driver here */