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 int m68k_first_user_vec
;
60 static struct irq_chip auto_irq_chip
= {
62 .irq_startup
= m68k_irq_startup
,
63 .irq_shutdown
= m68k_irq_shutdown
,
66 static struct irq_chip user_irq_chip
= {
68 .irq_startup
= m68k_irq_startup
,
69 .irq_shutdown
= m68k_irq_shutdown
,
72 #define NUM_IRQ_NODES 100
73 static struct irq_data 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_chip
[i
] = &auto_irq_chip
;
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 BUG_ON(IRQ_USER
+ cnt
> NR_IRQS
);
135 m68k_first_user_vec
= vec
;
136 for (i
= 0; i
< cnt
; i
++)
137 irq_chip
[IRQ_USER
+ i
] = &user_irq_chip
;
138 *user_irqvec_fixup
= vec
- IRQ_USER
;
140 *user_irqhandler_fixup
= (u32
)handler
;
145 * m68k_setup_irq_chip
146 * @contr: irq controller which controls specified irq
147 * @irq: first irq to be managed by the controller
149 * Change the controller for the specified range of irq, which will be used to
150 * manage these irq. auto/user irq already have a default controller, which can
151 * be changed as well, but the controller probably should use m68k_irq_startup/
154 void m68k_setup_irq_chip(struct irq_chip
*contr
, unsigned int irq
,
159 for (i
= 0; i
< cnt
; i
++)
160 irq_chip
[irq
+ i
] = contr
;
163 struct irq_data
*new_irq_node(void)
165 struct irq_data
*node
;
168 for (node
= nodes
, i
= NUM_IRQ_NODES
-1; i
>= 0; node
++, i
--) {
169 if (!node
->handler
) {
170 memset(node
, 0, sizeof(*node
));
175 printk ("new_irq_node: out of nodes\n");
179 int setup_irq(unsigned int irq
, struct irq_data
*node
)
181 struct irq_chip
*contr
;
182 struct irq_data
**prev
;
185 if (irq
>= NR_IRQS
|| !(contr
= irq_chip
[irq
])) {
186 printk("%s: Incorrect IRQ %d from %s\n",
187 __func__
, irq
, node
->devname
);
191 local_irq_save(flags
);
193 prev
= irq_list
+ irq
;
195 /* Can't share interrupts unless both agree to */
196 if (!((*prev
)->flags
& node
->flags
& IRQF_SHARED
)) {
197 local_irq_restore(flags
);
201 prev
= &(*prev
)->next
;
204 if (!irq_list
[irq
]) {
205 if (contr
->irq_startup
)
206 contr
->irq_startup(node
);
208 contr
->irq_enable(node
);
213 local_irq_restore(flags
);
218 int request_irq(unsigned int irq
,
219 irq_handler_t handler
,
220 unsigned long flags
, const char *devname
, void *dev_id
)
222 struct irq_data
*node
;
225 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_chip
*contr
;
247 struct irq_data
**p
, *node
;
250 if (irq
>= NR_IRQS
|| !(contr
= irq_chip
[irq
])) {
251 printk("%s: Incorrect IRQ %d\n", __func__
, irq
);
255 local_irq_save(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
]) {
272 if (contr
->irq_shutdown
)
273 contr
->irq_shutdown(node
);
275 contr
->irq_disable(node
);
278 local_irq_restore(flags
);
281 EXPORT_SYMBOL(free_irq
);
283 void enable_irq(unsigned int irq
)
285 struct irq_chip
*contr
;
288 if (irq
>= NR_IRQS
|| !(contr
= irq_chip
[irq
])) {
289 printk("%s: Incorrect IRQ %d\n",
294 local_irq_save(flags
);
295 if (irq_depth
[irq
]) {
296 if (!--irq_depth
[irq
]) {
297 if (contr
->irq_enable
)
298 contr
->irq_enable(irq_list
[irq
]);
302 local_irq_restore(flags
);
305 EXPORT_SYMBOL(enable_irq
);
307 void disable_irq(unsigned int irq
)
309 struct irq_chip
*contr
;
312 if (irq
>= NR_IRQS
|| !(contr
= irq_chip
[irq
])) {
313 printk("%s: Incorrect IRQ %d\n",
318 local_irq_save(flags
);
319 if (!irq_depth
[irq
]++) {
320 if (contr
->irq_disable
)
321 contr
->irq_disable(irq_list
[irq
]);
323 local_irq_restore(flags
);
326 EXPORT_SYMBOL(disable_irq
);
328 void disable_irq_nosync(unsigned int irq
) __attribute__((alias("disable_irq")));
330 EXPORT_SYMBOL(disable_irq_nosync
);
332 unsigned int m68k_irq_startup_irq(unsigned int irq
)
334 if (irq
<= IRQ_AUTO_7
)
335 vectors
[VEC_SPUR
+ irq
] = auto_inthandler
;
337 vectors
[m68k_first_user_vec
+ irq
- IRQ_USER
] = user_inthandler
;
341 unsigned int m68k_irq_startup(struct irq_data
*data
)
343 return m68k_irq_startup_irq(data
->irq
);
346 void m68k_irq_shutdown(struct irq_data
*data
)
348 unsigned int irq
= data
->irq
;
350 if (irq
<= IRQ_AUTO_7
)
351 vectors
[VEC_SPUR
+ irq
] = bad_inthandler
;
353 vectors
[m68k_first_user_vec
+ irq
- IRQ_USER
] = bad_inthandler
;
358 * Do we need these probe functions on the m68k?
360 * ... may be useful with ISA devices
362 unsigned long probe_irq_on (void)
366 return q40_probe_irq_on();
371 EXPORT_SYMBOL(probe_irq_on
);
373 int probe_irq_off (unsigned long irqs
)
377 return q40_probe_irq_off(irqs
);
382 EXPORT_SYMBOL(probe_irq_off
);
384 unsigned int irq_canonicalize(unsigned int irq
)
387 if (MACH_IS_Q40
&& irq
== 11)
393 EXPORT_SYMBOL(irq_canonicalize
);
395 asmlinkage
void m68k_handle_int(unsigned int irq
)
397 struct irq_data
*node
;
398 kstat_cpu(0).irqs
[irq
]++;
399 node
= irq_list
[irq
];
401 node
->handler(irq
, node
->dev_id
);
406 asmlinkage
void __m68k_handle_int(unsigned int irq
, struct pt_regs
*regs
)
408 struct pt_regs
*old_regs
;
409 old_regs
= set_irq_regs(regs
);
410 m68k_handle_int(irq
);
411 set_irq_regs(old_regs
);
414 asmlinkage
void handle_badint(struct pt_regs
*regs
)
416 kstat_cpu(0).irqs
[0]++;
417 printk("unexpected interrupt from %u\n", regs
->vector
);
420 int show_interrupts(struct seq_file
*p
, void *v
)
422 struct irq_chip
*contr
;
423 struct irq_data
*node
;
424 int i
= *(loff_t
*) v
;
426 /* autovector interrupts */
430 seq_printf(p
, "%-8s %3u: %10u %s", contr
->name
, i
, kstat_cpu(0).irqs
[i
], node
->devname
);
431 while ((node
= node
->next
))
432 seq_printf(p
, ", %s", node
->devname
);
438 #ifdef CONFIG_PROC_FS
439 void init_irq_proc(void)
441 /* Insert /proc/irq driver here */