blob: 9de8eb4eaefb52a741fd090a9749edadad3475f3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
3 *
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
6 * for more details.
7 *
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
13 * architectures. /Jes
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
26 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/types.h>
30#include <linux/sched.h>
Andrew Morton6168a702007-02-17 21:22:39 -080031#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/kernel_stat.h>
33#include <linux/errno.h>
34#include <linux/init.h>
35
36#include <asm/setup.h>
37#include <asm/system.h>
38#include <asm/irq.h>
39#include <asm/traps.h>
40#include <asm/page.h>
41#include <asm/machdep.h>
Roman Zippel68387c42006-06-25 05:47:01 -070042#include <asm/cacheflush.h>
Al Viro2850bc22006-10-07 14:16:45 +010043#include <asm/irq_regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#ifdef CONFIG_Q40
46#include <asm/q40ints.h>
47#endif
48
Roman Zippel68387c42006-06-25 05:47:01 -070049extern u32 auto_irqhandler_fixup[];
50extern u32 user_irqhandler_fixup[];
51extern u16 user_irqvec_fixup[];
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/* table for system interrupt handlers */
Roman Zippel68387c42006-06-25 05:47:01 -070054static struct irq_node *irq_list[NR_IRQS];
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020055static struct irq_chip *irq_chip[NR_IRQS];
Roman Zippel68387c42006-06-25 05:47:01 -070056static int irq_depth[NR_IRQS];
57
58static int m68k_first_user_vec;
Roman Zippelb5dc7842006-06-25 05:47:00 -070059
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020060static struct irq_chip auto_irq_chip = {
Roman Zippelb5dc7842006-06-25 05:47:00 -070061 .name = "auto",
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020062 .irq_startup = m68k_irq_startup,
63 .irq_shutdown = m68k_irq_shutdown,
Roman Zippelb5dc7842006-06-25 05:47:00 -070064};
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020066static struct irq_chip user_irq_chip = {
Roman Zippel68387c42006-06-25 05:47:01 -070067 .name = "user",
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020068 .irq_startup = m68k_irq_startup,
69 .irq_shutdown = m68k_irq_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define NUM_IRQ_NODES 100
Geert Uytterhoeven0dde5952011-04-17 21:39:08 +020073static struct irq_node nodes[NUM_IRQ_NODES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
76 * void init_IRQ(void)
77 *
78 * Parameters: None
79 *
80 * Returns: Nothing
81 *
82 * This function should be called during kernel startup to initialize
83 * the IRQ handling routines.
84 */
85
86void __init init_IRQ(void)
87{
88 int i;
89
Roman Zippel6d2f16a2006-06-23 02:04:59 -070090 /* 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();
94 }
95
Roman Zippel68387c42006-06-25 05:47:01 -070096 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020097 irq_chip[i] = &auto_irq_chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Roman Zippel68387c42006-06-25 05:47:01 -070099 mach_init_IRQ();
100}
101
102/**
103 * m68k_setup_auto_interrupt
104 * @handler: called from auto vector interrupts
105 *
106 * setup the handler to be called from auto vector interrupts instead of the
Al Viro2850bc22006-10-07 14:16:45 +0100107 * standard __m68k_handle_int(), it will be called with irq numbers in the range
Roman Zippel68387c42006-06-25 05:47:01 -0700108 * from IRQ_AUTO_1 - IRQ_AUTO_7.
109 */
110void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
111{
112 if (handler)
113 *auto_irqhandler_fixup = (u32)handler;
114 flush_icache();
115}
116
117/**
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
122 *
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
Al Viro2850bc22006-10-07 14:16:45 +0100126 * to be called instead of the default __m68k_handle_int(), it will be called
Roman Zippel68387c42006-06-25 05:47:01 -0700127 * with irq numbers starting from IRQ_USER.
128 */
129void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
130 void (*handler)(unsigned int, struct pt_regs *))
131{
132 int i;
133
Geert Uytterhoeven27123cb2008-11-14 08:10:19 +0100134 BUG_ON(IRQ_USER + cnt > NR_IRQS);
Roman Zippel68387c42006-06-25 05:47:01 -0700135 m68k_first_user_vec = vec;
136 for (i = 0; i < cnt; i++)
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200137 irq_chip[IRQ_USER + i] = &user_irq_chip;
Roman Zippel68387c42006-06-25 05:47:01 -0700138 *user_irqvec_fixup = vec - IRQ_USER;
139 if (handler)
140 *user_irqhandler_fixup = (u32)handler;
141 flush_icache();
142}
143
144/**
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200145 * m68k_setup_irq_chip
Roman Zippel68387c42006-06-25 05:47:01 -0700146 * @contr: irq controller which controls specified irq
147 * @irq: first irq to be managed by the controller
148 *
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/
152 * m68k_irq_shutdown.
153 */
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200154void m68k_setup_irq_chip(struct irq_chip *contr, unsigned int irq,
Roman Zippel68387c42006-06-25 05:47:01 -0700155 unsigned int cnt)
156{
157 int i;
158
159 for (i = 0; i < cnt; i++)
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200160 irq_chip[irq + i] = contr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Geert Uytterhoeven0dde5952011-04-17 21:39:08 +0200163struct irq_node *new_irq_node(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Geert Uytterhoeven0dde5952011-04-17 21:39:08 +0200165 struct irq_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 short i;
167
Roman Zippelb5dc7842006-06-25 05:47:00 -0700168 for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
169 if (!node->handler) {
170 memset(node, 0, sizeof(*node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return node;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700172 }
173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 printk ("new_irq_node: out of nodes\n");
176 return NULL;
177}
178
Roman Zippelb5dc7842006-06-25 05:47:00 -0700179int setup_irq(unsigned int irq, struct irq_node *node)
180{
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200181 struct irq_chip *contr;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700182 struct irq_node **prev;
183 unsigned long flags;
184
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200185 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700186 printk("%s: Incorrect IRQ %d from %s\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700187 __func__, irq, node->devname);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700188 return -ENXIO;
189 }
190
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200191 local_irq_save(flags);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700192
193 prev = irq_list + irq;
194 if (*prev) {
195 /* Can't share interrupts unless both agree to */
Thomas Gleixnerb0b9fdc2006-07-01 19:29:19 -0700196 if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200197 local_irq_restore(flags);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700198 return -EBUSY;
199 }
200 while (*prev)
201 prev = &(*prev)->next;
202 }
203
204 if (!irq_list[irq]) {
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200205 if (contr->irq_startup)
206 contr->irq_startup(irq);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700207 else
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200208 contr->irq_enable(irq);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700209 }
210 node->next = NULL;
211 *prev = node;
212
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200213 local_irq_restore(flags);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700214
215 return 0;
216}
217
Roman Zippel68387c42006-06-25 05:47:01 -0700218int request_irq(unsigned int irq,
David Howells40220c12006-10-09 12:19:47 +0100219 irq_handler_t handler,
Roman Zippel68387c42006-06-25 05:47:01 -0700220 unsigned long flags, const char *devname, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700222 struct irq_node *node;
223 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Roman Zippelb5dc7842006-06-25 05:47:00 -0700225 node = new_irq_node();
226 if (!node)
227 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Roman Zippelb5dc7842006-06-25 05:47:00 -0700229 node->handler = handler;
230 node->flags = flags;
231 node->dev_id = dev_id;
232 node->devname = devname;
233
234 res = setup_irq(irq, node);
235 if (res)
236 node->handler = NULL;
237
238 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
240
Roman Zippel68387c42006-06-25 05:47:01 -0700241EXPORT_SYMBOL(request_irq);
242
243void free_irq(unsigned int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200245 struct irq_chip *contr;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700246 struct irq_node **p, *node;
247 unsigned long flags;
248
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200249 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700250 printk("%s: Incorrect IRQ %d\n", __func__, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return;
252 }
253
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200254 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Roman Zippelb5dc7842006-06-25 05:47:00 -0700256 p = irq_list + irq;
257 while ((node = *p)) {
258 if (node->dev_id == dev_id)
259 break;
260 p = &node->next;
261 }
262
263 if (node) {
264 *p = node->next;
265 node->handler = NULL;
266 } else
267 printk("%s: Removing probably wrong IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700268 __func__, irq);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700269
Roman Zippel68387c42006-06-25 05:47:01 -0700270 if (!irq_list[irq]) {
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200271 if (contr->irq_shutdown)
272 contr->irq_shutdown(irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700273 else
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200274 contr->irq_disable(irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700275 }
Roman Zippelb5dc7842006-06-25 05:47:00 -0700276
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200277 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
Roman Zippel68387c42006-06-25 05:47:01 -0700280EXPORT_SYMBOL(free_irq);
281
282void enable_irq(unsigned int irq)
283{
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200284 struct irq_chip *contr;
Roman Zippel68387c42006-06-25 05:47:01 -0700285 unsigned long flags;
286
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200287 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
Roman Zippel68387c42006-06-25 05:47:01 -0700288 printk("%s: Incorrect IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700289 __func__, irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700290 return;
291 }
292
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200293 local_irq_save(flags);
Roman Zippel68387c42006-06-25 05:47:01 -0700294 if (irq_depth[irq]) {
295 if (!--irq_depth[irq]) {
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200296 if (contr->irq_enable)
297 contr->irq_enable(irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700298 }
299 } else
300 WARN_ON(1);
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200301 local_irq_restore(flags);
Roman Zippel68387c42006-06-25 05:47:01 -0700302}
303
304EXPORT_SYMBOL(enable_irq);
305
306void disable_irq(unsigned int irq)
307{
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200308 struct irq_chip *contr;
Roman Zippel68387c42006-06-25 05:47:01 -0700309 unsigned long flags;
310
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200311 if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
Roman Zippel68387c42006-06-25 05:47:01 -0700312 printk("%s: Incorrect IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700313 __func__, irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700314 return;
315 }
316
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200317 local_irq_save(flags);
Roman Zippel68387c42006-06-25 05:47:01 -0700318 if (!irq_depth[irq]++) {
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200319 if (contr->irq_disable)
320 contr->irq_disable(irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700321 }
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200322 local_irq_restore(flags);
Roman Zippel68387c42006-06-25 05:47:01 -0700323}
324
325EXPORT_SYMBOL(disable_irq);
326
Al Viroe9ed7e72007-07-21 23:29:12 +0100327void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
328
329EXPORT_SYMBOL(disable_irq_nosync);
330
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200331unsigned int m68k_irq_startup(unsigned int irq)
Roman Zippelb5dc7842006-06-25 05:47:00 -0700332{
333 if (irq <= IRQ_AUTO_7)
334 vectors[VEC_SPUR + irq] = auto_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700335 else
336 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700337 return 0;
338}
339
340void m68k_irq_shutdown(unsigned int irq)
341{
342 if (irq <= IRQ_AUTO_7)
343 vectors[VEC_SPUR + irq] = bad_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700344 else
345 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700346}
347
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349/*
350 * Do we need these probe functions on the m68k?
351 *
352 * ... may be useful with ISA devices
353 */
354unsigned long probe_irq_on (void)
355{
356#ifdef CONFIG_Q40
357 if (MACH_IS_Q40)
358 return q40_probe_irq_on();
359#endif
360 return 0;
361}
362
363EXPORT_SYMBOL(probe_irq_on);
364
365int probe_irq_off (unsigned long irqs)
366{
367#ifdef CONFIG_Q40
368 if (MACH_IS_Q40)
369 return q40_probe_irq_off(irqs);
370#endif
371 return 0;
372}
373
374EXPORT_SYMBOL(probe_irq_off);
375
Roman Zippel68387c42006-06-25 05:47:01 -0700376unsigned int irq_canonicalize(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Roman Zippel68387c42006-06-25 05:47:01 -0700378#ifdef CONFIG_Q40
379 if (MACH_IS_Q40 && irq == 11)
380 irq = 10;
381#endif
382 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
Roman Zippel68387c42006-06-25 05:47:01 -0700385EXPORT_SYMBOL(irq_canonicalize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Al Viro2850bc22006-10-07 14:16:45 +0100387asmlinkage void m68k_handle_int(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700389 struct irq_node *node;
Roman Zippel92445eaa2006-06-25 05:46:58 -0700390 kstat_cpu(0).irqs[irq]++;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700391 node = irq_list[irq];
392 do {
Al Viro2850bc22006-10-07 14:16:45 +0100393 node->handler(irq, node->dev_id);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700394 node = node->next;
395 } while (node);
Roman Zippel92445eaa2006-06-25 05:46:58 -0700396}
397
Al Viro2850bc22006-10-07 14:16:45 +0100398asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
399{
400 struct pt_regs *old_regs;
401 old_regs = set_irq_regs(regs);
402 m68k_handle_int(irq);
403 set_irq_regs(old_regs);
404}
405
Roman Zippel92445eaa2006-06-25 05:46:58 -0700406asmlinkage void handle_badint(struct pt_regs *regs)
407{
408 kstat_cpu(0).irqs[0]++;
409 printk("unexpected interrupt from %u\n", regs->vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
412int show_interrupts(struct seq_file *p, void *v)
413{
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200414 struct irq_chip *contr;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700415 struct irq_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 int i = *(loff_t *) v;
417
418 /* autovector interrupts */
Roman Zippel68387c42006-06-25 05:47:01 -0700419 if (irq_list[i]) {
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200420 contr = irq_chip[i];
Roman Zippelb5dc7842006-06-25 05:47:00 -0700421 node = irq_list[i];
Roman Zippel68387c42006-06-25 05:47:01 -0700422 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700423 while ((node = node->next))
424 seq_printf(p, ", %s", node->devname);
425 seq_puts(p, "\n");
Roman Zippel68387c42006-06-25 05:47:01 -0700426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return 0;
428}
429
Geert Uytterhoevenda9870e2008-10-13 21:59:01 +0200430#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431void init_irq_proc(void)
432{
433 /* Insert /proc/irq driver here */
434}
Geert Uytterhoevenda9870e2008-10-13 21:59:01 +0200435#endif