blob: 7e8a0d394e6184cbf63a5fb257befa4082ce0148 [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];
55static struct irq_controller *irq_controller[NR_IRQS];
56static int irq_depth[NR_IRQS];
57
58static int m68k_first_user_vec;
Roman Zippelb5dc7842006-06-25 05:47:00 -070059
60static struct irq_controller auto_irq_controller = {
61 .name = "auto",
Milind Arun Choudhary241258d2007-05-06 14:50:54 -070062 .lock = __SPIN_LOCK_UNLOCKED(auto_irq_controller.lock),
Roman Zippelb5dc7842006-06-25 05:47:00 -070063 .startup = m68k_irq_startup,
64 .shutdown = m68k_irq_shutdown,
65};
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Roman Zippel68387c42006-06-25 05:47:01 -070067static struct irq_controller user_irq_controller = {
68 .name = "user",
Milind Arun Choudhary241258d2007-05-06 14:50:54 -070069 .lock = __SPIN_LOCK_UNLOCKED(user_irq_controller.lock),
Roman Zippel68387c42006-06-25 05:47:01 -070070 .startup = m68k_irq_startup,
71 .shutdown = m68k_irq_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072};
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#define NUM_IRQ_NODES 100
75static irq_node_t nodes[NUM_IRQ_NODES];
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/*
78 * void init_IRQ(void)
79 *
80 * Parameters: None
81 *
82 * Returns: Nothing
83 *
84 * This function should be called during kernel startup to initialize
85 * the IRQ handling routines.
86 */
87
88void __init init_IRQ(void)
89{
90 int i;
91
Roman Zippel6d2f16a2006-06-23 02:04:59 -070092 /* 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();
96 }
97
Roman Zippel68387c42006-06-25 05:47:01 -070098 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
Roman Zippelb5dc7842006-06-25 05:47:00 -070099 irq_controller[i] = &auto_irq_controller;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Roman Zippel68387c42006-06-25 05:47:01 -0700101 mach_init_IRQ();
102}
103
104/**
105 * m68k_setup_auto_interrupt
106 * @handler: called from auto vector interrupts
107 *
108 * setup the handler to be called from auto vector interrupts instead of the
Al Viro2850bc22006-10-07 14:16:45 +0100109 * standard __m68k_handle_int(), it will be called with irq numbers in the range
Roman Zippel68387c42006-06-25 05:47:01 -0700110 * from IRQ_AUTO_1 - IRQ_AUTO_7.
111 */
112void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
113{
114 if (handler)
115 *auto_irqhandler_fixup = (u32)handler;
116 flush_icache();
117}
118
119/**
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
124 *
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
Al Viro2850bc22006-10-07 14:16:45 +0100128 * to be called instead of the default __m68k_handle_int(), it will be called
Roman Zippel68387c42006-06-25 05:47:01 -0700129 * with irq numbers starting from IRQ_USER.
130 */
131void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
132 void (*handler)(unsigned int, struct pt_regs *))
133{
134 int i;
135
Geert Uytterhoeven69961c32006-10-09 22:23:31 +0200136 BUG_ON(IRQ_USER + cnt >= NR_IRQS);
Roman Zippel68387c42006-06-25 05:47:01 -0700137 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;
141 if (handler)
142 *user_irqhandler_fixup = (u32)handler;
143 flush_icache();
144}
145
146/**
147 * m68k_setup_irq_controller
148 * @contr: irq controller which controls specified irq
149 * @irq: first irq to be managed by the controller
150 *
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/
154 * m68k_irq_shutdown.
155 */
156void m68k_setup_irq_controller(struct irq_controller *contr, unsigned int irq,
157 unsigned int cnt)
158{
159 int i;
160
161 for (i = 0; i < cnt; i++)
162 irq_controller[irq + i] = contr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165irq_node_t *new_irq_node(void)
166{
167 irq_node_t *node;
168 short i;
169
Roman Zippelb5dc7842006-06-25 05:47:00 -0700170 for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
171 if (!node->handler) {
172 memset(node, 0, sizeof(*node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 return node;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700174 }
175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 printk ("new_irq_node: out of nodes\n");
178 return NULL;
179}
180
Roman Zippelb5dc7842006-06-25 05:47:00 -0700181int setup_irq(unsigned int irq, struct irq_node *node)
182{
183 struct irq_controller *contr;
184 struct irq_node **prev;
185 unsigned long flags;
186
Roman Zippel68387c42006-06-25 05:47:01 -0700187 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700188 printk("%s: Incorrect IRQ %d from %s\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700189 __func__, irq, node->devname);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700190 return -ENXIO;
191 }
192
193 spin_lock_irqsave(&contr->lock, flags);
194
195 prev = irq_list + irq;
196 if (*prev) {
197 /* Can't share interrupts unless both agree to */
Thomas Gleixnerb0b9fdc2006-07-01 19:29:19 -0700198 if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700199 spin_unlock_irqrestore(&contr->lock, flags);
200 return -EBUSY;
201 }
202 while (*prev)
203 prev = &(*prev)->next;
204 }
205
206 if (!irq_list[irq]) {
207 if (contr->startup)
208 contr->startup(irq);
209 else
210 contr->enable(irq);
211 }
212 node->next = NULL;
213 *prev = node;
214
215 spin_unlock_irqrestore(&contr->lock, flags);
216
217 return 0;
218}
219
Roman Zippel68387c42006-06-25 05:47:01 -0700220int request_irq(unsigned int irq,
David Howells40220c12006-10-09 12:19:47 +0100221 irq_handler_t handler,
Roman Zippel68387c42006-06-25 05:47:01 -0700222 unsigned long flags, const char *devname, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700224 struct irq_node *node;
225 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Roman Zippelb5dc7842006-06-25 05:47:00 -0700227 node = new_irq_node();
228 if (!node)
229 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Roman Zippelb5dc7842006-06-25 05:47:00 -0700231 node->handler = handler;
232 node->flags = flags;
233 node->dev_id = dev_id;
234 node->devname = devname;
235
236 res = setup_irq(irq, node);
237 if (res)
238 node->handler = NULL;
239
240 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
Roman Zippel68387c42006-06-25 05:47:01 -0700243EXPORT_SYMBOL(request_irq);
244
245void free_irq(unsigned int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700247 struct irq_controller *contr;
248 struct irq_node **p, *node;
249 unsigned long flags;
250
Roman Zippel68387c42006-06-25 05:47:01 -0700251 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700252 printk("%s: Incorrect IRQ %d\n", __func__, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return;
254 }
255
Roman Zippelb5dc7842006-06-25 05:47:00 -0700256 spin_lock_irqsave(&contr->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Roman Zippelb5dc7842006-06-25 05:47:00 -0700258 p = irq_list + irq;
259 while ((node = *p)) {
260 if (node->dev_id == dev_id)
261 break;
262 p = &node->next;
263 }
264
265 if (node) {
266 *p = node->next;
267 node->handler = NULL;
268 } else
269 printk("%s: Removing probably wrong IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700270 __func__, irq);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700271
Roman Zippel68387c42006-06-25 05:47:01 -0700272 if (!irq_list[irq]) {
273 if (contr->shutdown)
274 contr->shutdown(irq);
275 else
276 contr->disable(irq);
277 }
Roman Zippelb5dc7842006-06-25 05:47:00 -0700278
279 spin_unlock_irqrestore(&contr->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Roman Zippel68387c42006-06-25 05:47:01 -0700282EXPORT_SYMBOL(free_irq);
283
284void enable_irq(unsigned int irq)
285{
286 struct irq_controller *contr;
287 unsigned long flags;
288
289 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
290 printk("%s: Incorrect IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700291 __func__, irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700292 return;
293 }
294
295 spin_lock_irqsave(&contr->lock, flags);
296 if (irq_depth[irq]) {
297 if (!--irq_depth[irq]) {
298 if (contr->enable)
299 contr->enable(irq);
300 }
301 } else
302 WARN_ON(1);
303 spin_unlock_irqrestore(&contr->lock, flags);
304}
305
306EXPORT_SYMBOL(enable_irq);
307
308void disable_irq(unsigned int irq)
309{
310 struct irq_controller *contr;
311 unsigned long flags;
312
313 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
314 printk("%s: Incorrect IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700315 __func__, irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700316 return;
317 }
318
319 spin_lock_irqsave(&contr->lock, flags);
320 if (!irq_depth[irq]++) {
321 if (contr->disable)
322 contr->disable(irq);
323 }
324 spin_unlock_irqrestore(&contr->lock, flags);
325}
326
327EXPORT_SYMBOL(disable_irq);
328
Al Viroe9ed7e72007-07-21 23:29:12 +0100329void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
330
331EXPORT_SYMBOL(disable_irq_nosync);
332
Roman Zippelb5dc7842006-06-25 05:47:00 -0700333int m68k_irq_startup(unsigned int irq)
334{
335 if (irq <= IRQ_AUTO_7)
336 vectors[VEC_SPUR + irq] = auto_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700337 else
338 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700339 return 0;
340}
341
342void m68k_irq_shutdown(unsigned int irq)
343{
344 if (irq <= IRQ_AUTO_7)
345 vectors[VEC_SPUR + irq] = bad_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700346 else
347 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700348}
349
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/*
352 * Do we need these probe functions on the m68k?
353 *
354 * ... may be useful with ISA devices
355 */
356unsigned long probe_irq_on (void)
357{
358#ifdef CONFIG_Q40
359 if (MACH_IS_Q40)
360 return q40_probe_irq_on();
361#endif
362 return 0;
363}
364
365EXPORT_SYMBOL(probe_irq_on);
366
367int probe_irq_off (unsigned long irqs)
368{
369#ifdef CONFIG_Q40
370 if (MACH_IS_Q40)
371 return q40_probe_irq_off(irqs);
372#endif
373 return 0;
374}
375
376EXPORT_SYMBOL(probe_irq_off);
377
Roman Zippel68387c42006-06-25 05:47:01 -0700378unsigned int irq_canonicalize(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Roman Zippel68387c42006-06-25 05:47:01 -0700380#ifdef CONFIG_Q40
381 if (MACH_IS_Q40 && irq == 11)
382 irq = 10;
383#endif
384 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Roman Zippel68387c42006-06-25 05:47:01 -0700387EXPORT_SYMBOL(irq_canonicalize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Al Viro2850bc22006-10-07 14:16:45 +0100389asmlinkage void m68k_handle_int(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700391 struct irq_node *node;
Roman Zippel92445eaa2006-06-25 05:46:58 -0700392 kstat_cpu(0).irqs[irq]++;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700393 node = irq_list[irq];
394 do {
Al Viro2850bc22006-10-07 14:16:45 +0100395 node->handler(irq, node->dev_id);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700396 node = node->next;
397 } while (node);
Roman Zippel92445eaa2006-06-25 05:46:58 -0700398}
399
Al Viro2850bc22006-10-07 14:16:45 +0100400asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
401{
402 struct pt_regs *old_regs;
403 old_regs = set_irq_regs(regs);
404 m68k_handle_int(irq);
405 set_irq_regs(old_regs);
406}
407
Roman Zippel92445eaa2006-06-25 05:46:58 -0700408asmlinkage void handle_badint(struct pt_regs *regs)
409{
410 kstat_cpu(0).irqs[0]++;
411 printk("unexpected interrupt from %u\n", regs->vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414int show_interrupts(struct seq_file *p, void *v)
415{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700416 struct irq_controller *contr;
417 struct irq_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 int i = *(loff_t *) v;
419
420 /* autovector interrupts */
Roman Zippel68387c42006-06-25 05:47:01 -0700421 if (irq_list[i]) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700422 contr = irq_controller[i];
423 node = irq_list[i];
Roman Zippel68387c42006-06-25 05:47:01 -0700424 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700425 while ((node = node->next))
426 seq_printf(p, ", %s", node->devname);
427 seq_puts(p, "\n");
Roman Zippel68387c42006-06-25 05:47:01 -0700428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return 0;
430}
431
Geert Uytterhoevenda9870e2008-10-13 21:59:01 +0200432#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433void init_irq_proc(void)
434{
435 /* Insert /proc/irq driver here */
436}
Geert Uytterhoevenda9870e2008-10-13 21:59:01 +0200437#endif