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>
42 #include <asm/irq_regs.h>
45 #include <asm/q40ints.h>
48 extern u32 auto_irqhandler_fixup
[];
49 extern u32 user_irqhandler_fixup
[];
50 extern u16 user_irqvec_fixup
[];
52 /* table for system interrupt handlers */
53 static struct irq_node
*irq_list
[NR_IRQS
];
54 static struct irq_controller
*irq_controller
[NR_IRQS
];
55 static int irq_depth
[NR_IRQS
];
57 static int m68k_first_user_vec
;
59 static struct irq_controller auto_irq_controller
= {
61 .lock
= SPIN_LOCK_UNLOCKED
,
62 .startup
= m68k_irq_startup
,
63 .shutdown
= m68k_irq_shutdown
,
66 static struct irq_controller user_irq_controller
= {
68 .lock
= SPIN_LOCK_UNLOCKED
,
69 .startup
= m68k_irq_startup
,
70 .shutdown
= m68k_irq_shutdown
,
73 #define NUM_IRQ_NODES 100
74 static irq_node_t nodes
[NUM_IRQ_NODES
];
83 * This function should be called during kernel startup to initialize
84 * the IRQ handling routines.
87 void __init
init_IRQ(void)
91 /* assembly irq entry code relies on this... */
92 if (HARDIRQ_MASK
!= 0x00ff0000) {
93 extern void hardirq_mask_is_broken(void);
94 hardirq_mask_is_broken();
97 for (i
= IRQ_AUTO_1
; i
<= IRQ_AUTO_7
; i
++)
98 irq_controller
[i
] = &auto_irq_controller
;
104 * m68k_setup_auto_interrupt
105 * @handler: called from auto vector interrupts
107 * setup the handler to be called from auto vector interrupts instead of the
108 * standard __m68k_handle_int(), it will be called with irq numbers in the range
109 * from IRQ_AUTO_1 - IRQ_AUTO_7.
111 void __init
m68k_setup_auto_interrupt(void (*handler
)(unsigned int, struct pt_regs
*))
114 *auto_irqhandler_fixup
= (u32
)handler
;
119 * m68k_setup_user_interrupt
120 * @vec: first user vector interrupt to handle
121 * @cnt: number of active user vector interrupts
122 * @handler: called from user vector interrupts
124 * setup user vector interrupts, this includes activating the specified range
125 * of interrupts, only then these interrupts can be requested (note: this is
126 * different from auto vector interrupts). An optional handler can be installed
127 * to be called instead of the default __m68k_handle_int(), it will be called
128 * with irq numbers starting from IRQ_USER.
130 void __init
m68k_setup_user_interrupt(unsigned int vec
, unsigned int cnt
,
131 void (*handler
)(unsigned int, struct pt_regs
*))
135 BUG_ON(IRQ_USER
+ cnt
>= NR_IRQS
);
136 m68k_first_user_vec
= vec
;
137 for (i
= 0; i
< cnt
; i
++)
138 irq_controller
[IRQ_USER
+ i
] = &user_irq_controller
;
139 *user_irqvec_fixup
= vec
- IRQ_USER
;
141 *user_irqhandler_fixup
= (u32
)handler
;
146 * m68k_setup_irq_controller
147 * @contr: irq controller which controls specified irq
148 * @irq: first irq to be managed by the controller
150 * Change the controller for the specified range of irq, which will be used to
151 * manage these irq. auto/user irq already have a default controller, which can
152 * be changed as well, but the controller probably should use m68k_irq_startup/
155 void m68k_setup_irq_controller(struct irq_controller
*contr
, unsigned int irq
,
160 for (i
= 0; i
< cnt
; i
++)
161 irq_controller
[irq
+ i
] = contr
;
164 irq_node_t
*new_irq_node(void)
169 for (node
= nodes
, i
= NUM_IRQ_NODES
-1; i
>= 0; node
++, i
--) {
170 if (!node
->handler
) {
171 memset(node
, 0, sizeof(*node
));
176 printk ("new_irq_node: out of nodes\n");
180 int setup_irq(unsigned int irq
, struct irq_node
*node
)
182 struct irq_controller
*contr
;
183 struct irq_node
**prev
;
186 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
187 printk("%s: Incorrect IRQ %d from %s\n",
188 __FUNCTION__
, irq
, node
->devname
);
192 spin_lock_irqsave(&contr
->lock
, flags
);
194 prev
= irq_list
+ irq
;
196 /* Can't share interrupts unless both agree to */
197 if (!((*prev
)->flags
& node
->flags
& IRQF_SHARED
)) {
198 spin_unlock_irqrestore(&contr
->lock
, flags
);
202 prev
= &(*prev
)->next
;
205 if (!irq_list
[irq
]) {
214 spin_unlock_irqrestore(&contr
->lock
, flags
);
219 int request_irq(unsigned int irq
,
220 irq_handler_t handler
,
221 unsigned long flags
, const char *devname
, void *dev_id
)
223 struct irq_node
*node
;
226 node
= new_irq_node();
230 node
->handler
= handler
;
232 node
->dev_id
= dev_id
;
233 node
->devname
= devname
;
235 res
= setup_irq(irq
, node
);
237 node
->handler
= NULL
;
242 EXPORT_SYMBOL(request_irq
);
244 void free_irq(unsigned int irq
, void *dev_id
)
246 struct irq_controller
*contr
;
247 struct irq_node
**p
, *node
;
250 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
251 printk("%s: Incorrect IRQ %d\n", __FUNCTION__
, irq
);
255 spin_lock_irqsave(&contr
->lock
, flags
);
258 while ((node
= *p
)) {
259 if (node
->dev_id
== dev_id
)
266 node
->handler
= NULL
;
268 printk("%s: Removing probably wrong IRQ %d\n",
271 if (!irq_list
[irq
]) {
273 contr
->shutdown(irq
);
278 spin_unlock_irqrestore(&contr
->lock
, flags
);
281 EXPORT_SYMBOL(free_irq
);
283 void enable_irq(unsigned int irq
)
285 struct irq_controller
*contr
;
288 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
289 printk("%s: Incorrect IRQ %d\n",
294 spin_lock_irqsave(&contr
->lock
, flags
);
295 if (irq_depth
[irq
]) {
296 if (!--irq_depth
[irq
]) {
302 spin_unlock_irqrestore(&contr
->lock
, flags
);
305 EXPORT_SYMBOL(enable_irq
);
307 void disable_irq(unsigned int irq
)
309 struct irq_controller
*contr
;
312 if (irq
>= NR_IRQS
|| !(contr
= irq_controller
[irq
])) {
313 printk("%s: Incorrect IRQ %d\n",
318 spin_lock_irqsave(&contr
->lock
, flags
);
319 if (!irq_depth
[irq
]++) {
323 spin_unlock_irqrestore(&contr
->lock
, flags
);
326 EXPORT_SYMBOL(disable_irq
);
328 int m68k_irq_startup(unsigned int irq
)
330 if (irq
<= IRQ_AUTO_7
)
331 vectors
[VEC_SPUR
+ irq
] = auto_inthandler
;
333 vectors
[m68k_first_user_vec
+ irq
- IRQ_USER
] = user_inthandler
;
337 void m68k_irq_shutdown(unsigned int irq
)
339 if (irq
<= IRQ_AUTO_7
)
340 vectors
[VEC_SPUR
+ irq
] = bad_inthandler
;
342 vectors
[m68k_first_user_vec
+ irq
- IRQ_USER
] = bad_inthandler
;
347 * Do we need these probe functions on the m68k?
349 * ... may be useful with ISA devices
351 unsigned long probe_irq_on (void)
355 return q40_probe_irq_on();
360 EXPORT_SYMBOL(probe_irq_on
);
362 int probe_irq_off (unsigned long irqs
)
366 return q40_probe_irq_off(irqs
);
371 EXPORT_SYMBOL(probe_irq_off
);
373 unsigned int irq_canonicalize(unsigned int irq
)
376 if (MACH_IS_Q40
&& irq
== 11)
382 EXPORT_SYMBOL(irq_canonicalize
);
384 asmlinkage
void m68k_handle_int(unsigned int irq
)
386 struct irq_node
*node
;
387 kstat_cpu(0).irqs
[irq
]++;
388 node
= irq_list
[irq
];
390 node
->handler(irq
, node
->dev_id
);
395 asmlinkage
void __m68k_handle_int(unsigned int irq
, struct pt_regs
*regs
)
397 struct pt_regs
*old_regs
;
398 old_regs
= set_irq_regs(regs
);
399 m68k_handle_int(irq
);
400 set_irq_regs(old_regs
);
403 asmlinkage
void handle_badint(struct pt_regs
*regs
)
405 kstat_cpu(0).irqs
[0]++;
406 printk("unexpected interrupt from %u\n", regs
->vector
);
409 int show_interrupts(struct seq_file
*p
, void *v
)
411 struct irq_controller
*contr
;
412 struct irq_node
*node
;
413 int i
= *(loff_t
*) v
;
415 /* autovector interrupts */
417 contr
= irq_controller
[i
];
419 seq_printf(p
, "%-8s %3u: %10u %s", contr
->name
, i
, kstat_cpu(0).irqs
[i
], node
->devname
);
420 while ((node
= node
->next
))
421 seq_printf(p
, ", %s", node
->devname
);
427 void init_irq_proc(void)
429 /* Insert /proc/irq driver here */