blob: 44169e4cd91dd536f4a6088cdb49dbe572bc5b37 [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
Yinghai Lu85c0f902008-08-19 20:49:47 -070049int nr_irqs = NR_IRQS;
Ingo Molnarc59d85a2008-08-28 08:56:33 +020050EXPORT_SYMBOL(nr_irqs);
Yinghai Lu85c0f902008-08-19 20:49:47 -070051
Roman Zippel68387c42006-06-25 05:47:01 -070052extern u32 auto_irqhandler_fixup[];
53extern u32 user_irqhandler_fixup[];
54extern u16 user_irqvec_fixup[];
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* table for system interrupt handlers */
Roman Zippel68387c42006-06-25 05:47:01 -070057static struct irq_node *irq_list[NR_IRQS];
58static struct irq_controller *irq_controller[NR_IRQS];
59static int irq_depth[NR_IRQS];
60
61static int m68k_first_user_vec;
Roman Zippelb5dc7842006-06-25 05:47:00 -070062
63static struct irq_controller auto_irq_controller = {
64 .name = "auto",
Milind Arun Choudhary241258d2007-05-06 14:50:54 -070065 .lock = __SPIN_LOCK_UNLOCKED(auto_irq_controller.lock),
Roman Zippelb5dc7842006-06-25 05:47:00 -070066 .startup = m68k_irq_startup,
67 .shutdown = m68k_irq_shutdown,
68};
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Roman Zippel68387c42006-06-25 05:47:01 -070070static struct irq_controller user_irq_controller = {
71 .name = "user",
Milind Arun Choudhary241258d2007-05-06 14:50:54 -070072 .lock = __SPIN_LOCK_UNLOCKED(user_irq_controller.lock),
Roman Zippel68387c42006-06-25 05:47:01 -070073 .startup = m68k_irq_startup,
74 .shutdown = m68k_irq_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define NUM_IRQ_NODES 100
78static irq_node_t nodes[NUM_IRQ_NODES];
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080/*
81 * void init_IRQ(void)
82 *
83 * Parameters: None
84 *
85 * Returns: Nothing
86 *
87 * This function should be called during kernel startup to initialize
88 * the IRQ handling routines.
89 */
90
91void __init init_IRQ(void)
92{
93 int i;
94
Roman Zippel6d2f16a2006-06-23 02:04:59 -070095 /* assembly irq entry code relies on this... */
96 if (HARDIRQ_MASK != 0x00ff0000) {
97 extern void hardirq_mask_is_broken(void);
98 hardirq_mask_is_broken();
99 }
100
Roman Zippel68387c42006-06-25 05:47:01 -0700101 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
Roman Zippelb5dc7842006-06-25 05:47:00 -0700102 irq_controller[i] = &auto_irq_controller;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Roman Zippel68387c42006-06-25 05:47:01 -0700104 mach_init_IRQ();
105}
106
107/**
108 * m68k_setup_auto_interrupt
109 * @handler: called from auto vector interrupts
110 *
111 * setup the handler to be called from auto vector interrupts instead of the
Al Viro2850bc22006-10-07 14:16:45 +0100112 * standard __m68k_handle_int(), it will be called with irq numbers in the range
Roman Zippel68387c42006-06-25 05:47:01 -0700113 * from IRQ_AUTO_1 - IRQ_AUTO_7.
114 */
115void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
116{
117 if (handler)
118 *auto_irqhandler_fixup = (u32)handler;
119 flush_icache();
120}
121
122/**
123 * m68k_setup_user_interrupt
124 * @vec: first user vector interrupt to handle
125 * @cnt: number of active user vector interrupts
126 * @handler: called from user vector interrupts
127 *
128 * setup user vector interrupts, this includes activating the specified range
129 * of interrupts, only then these interrupts can be requested (note: this is
130 * different from auto vector interrupts). An optional handler can be installed
Al Viro2850bc22006-10-07 14:16:45 +0100131 * to be called instead of the default __m68k_handle_int(), it will be called
Roman Zippel68387c42006-06-25 05:47:01 -0700132 * with irq numbers starting from IRQ_USER.
133 */
134void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
135 void (*handler)(unsigned int, struct pt_regs *))
136{
137 int i;
138
Geert Uytterhoeven69961c32006-10-09 22:23:31 +0200139 BUG_ON(IRQ_USER + cnt >= NR_IRQS);
Roman Zippel68387c42006-06-25 05:47:01 -0700140 m68k_first_user_vec = vec;
141 for (i = 0; i < cnt; i++)
142 irq_controller[IRQ_USER + i] = &user_irq_controller;
143 *user_irqvec_fixup = vec - IRQ_USER;
144 if (handler)
145 *user_irqhandler_fixup = (u32)handler;
146 flush_icache();
147}
148
149/**
150 * m68k_setup_irq_controller
151 * @contr: irq controller which controls specified irq
152 * @irq: first irq to be managed by the controller
153 *
154 * Change the controller for the specified range of irq, which will be used to
155 * manage these irq. auto/user irq already have a default controller, which can
156 * be changed as well, but the controller probably should use m68k_irq_startup/
157 * m68k_irq_shutdown.
158 */
159void m68k_setup_irq_controller(struct irq_controller *contr, unsigned int irq,
160 unsigned int cnt)
161{
162 int i;
163
164 for (i = 0; i < cnt; i++)
165 irq_controller[irq + i] = contr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
168irq_node_t *new_irq_node(void)
169{
170 irq_node_t *node;
171 short i;
172
Roman Zippelb5dc7842006-06-25 05:47:00 -0700173 for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
174 if (!node->handler) {
175 memset(node, 0, sizeof(*node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return node;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700177 }
178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 printk ("new_irq_node: out of nodes\n");
181 return NULL;
182}
183
Roman Zippelb5dc7842006-06-25 05:47:00 -0700184int setup_irq(unsigned int irq, struct irq_node *node)
185{
186 struct irq_controller *contr;
187 struct irq_node **prev;
188 unsigned long flags;
189
Roman Zippel68387c42006-06-25 05:47:01 -0700190 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700191 printk("%s: Incorrect IRQ %d from %s\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700192 __func__, irq, node->devname);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700193 return -ENXIO;
194 }
195
196 spin_lock_irqsave(&contr->lock, flags);
197
198 prev = irq_list + irq;
199 if (*prev) {
200 /* Can't share interrupts unless both agree to */
Thomas Gleixnerb0b9fdc2006-07-01 19:29:19 -0700201 if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700202 spin_unlock_irqrestore(&contr->lock, flags);
203 return -EBUSY;
204 }
205 while (*prev)
206 prev = &(*prev)->next;
207 }
208
209 if (!irq_list[irq]) {
210 if (contr->startup)
211 contr->startup(irq);
212 else
213 contr->enable(irq);
214 }
215 node->next = NULL;
216 *prev = node;
217
218 spin_unlock_irqrestore(&contr->lock, flags);
219
220 return 0;
221}
222
Roman Zippel68387c42006-06-25 05:47:01 -0700223int request_irq(unsigned int irq,
David Howells40220c12006-10-09 12:19:47 +0100224 irq_handler_t handler,
Roman Zippel68387c42006-06-25 05:47:01 -0700225 unsigned long flags, const char *devname, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700227 struct irq_node *node;
228 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Roman Zippelb5dc7842006-06-25 05:47:00 -0700230 node = new_irq_node();
231 if (!node)
232 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Roman Zippelb5dc7842006-06-25 05:47:00 -0700234 node->handler = handler;
235 node->flags = flags;
236 node->dev_id = dev_id;
237 node->devname = devname;
238
239 res = setup_irq(irq, node);
240 if (res)
241 node->handler = NULL;
242
243 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Roman Zippel68387c42006-06-25 05:47:01 -0700246EXPORT_SYMBOL(request_irq);
247
248void free_irq(unsigned int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700250 struct irq_controller *contr;
251 struct irq_node **p, *node;
252 unsigned long flags;
253
Roman Zippel68387c42006-06-25 05:47:01 -0700254 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700255 printk("%s: Incorrect IRQ %d\n", __func__, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return;
257 }
258
Roman Zippelb5dc7842006-06-25 05:47:00 -0700259 spin_lock_irqsave(&contr->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Roman Zippelb5dc7842006-06-25 05:47:00 -0700261 p = irq_list + irq;
262 while ((node = *p)) {
263 if (node->dev_id == dev_id)
264 break;
265 p = &node->next;
266 }
267
268 if (node) {
269 *p = node->next;
270 node->handler = NULL;
271 } else
272 printk("%s: Removing probably wrong IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700273 __func__, irq);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700274
Roman Zippel68387c42006-06-25 05:47:01 -0700275 if (!irq_list[irq]) {
276 if (contr->shutdown)
277 contr->shutdown(irq);
278 else
279 contr->disable(irq);
280 }
Roman Zippelb5dc7842006-06-25 05:47:00 -0700281
282 spin_unlock_irqrestore(&contr->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Roman Zippel68387c42006-06-25 05:47:01 -0700285EXPORT_SYMBOL(free_irq);
286
287void enable_irq(unsigned int irq)
288{
289 struct irq_controller *contr;
290 unsigned long flags;
291
292 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
293 printk("%s: Incorrect IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700294 __func__, irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700295 return;
296 }
297
298 spin_lock_irqsave(&contr->lock, flags);
299 if (irq_depth[irq]) {
300 if (!--irq_depth[irq]) {
301 if (contr->enable)
302 contr->enable(irq);
303 }
304 } else
305 WARN_ON(1);
306 spin_unlock_irqrestore(&contr->lock, flags);
307}
308
309EXPORT_SYMBOL(enable_irq);
310
311void disable_irq(unsigned int irq)
312{
313 struct irq_controller *contr;
314 unsigned long flags;
315
316 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
317 printk("%s: Incorrect IRQ %d\n",
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700318 __func__, irq);
Roman Zippel68387c42006-06-25 05:47:01 -0700319 return;
320 }
321
322 spin_lock_irqsave(&contr->lock, flags);
323 if (!irq_depth[irq]++) {
324 if (contr->disable)
325 contr->disable(irq);
326 }
327 spin_unlock_irqrestore(&contr->lock, flags);
328}
329
330EXPORT_SYMBOL(disable_irq);
331
Al Viroe9ed7e72007-07-21 23:29:12 +0100332void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
333
334EXPORT_SYMBOL(disable_irq_nosync);
335
Roman Zippelb5dc7842006-06-25 05:47:00 -0700336int m68k_irq_startup(unsigned int irq)
337{
338 if (irq <= IRQ_AUTO_7)
339 vectors[VEC_SPUR + irq] = auto_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700340 else
341 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700342 return 0;
343}
344
345void m68k_irq_shutdown(unsigned int irq)
346{
347 if (irq <= IRQ_AUTO_7)
348 vectors[VEC_SPUR + irq] = bad_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700349 else
350 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700351}
352
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354/*
355 * Do we need these probe functions on the m68k?
356 *
357 * ... may be useful with ISA devices
358 */
359unsigned long probe_irq_on (void)
360{
361#ifdef CONFIG_Q40
362 if (MACH_IS_Q40)
363 return q40_probe_irq_on();
364#endif
365 return 0;
366}
367
368EXPORT_SYMBOL(probe_irq_on);
369
370int probe_irq_off (unsigned long irqs)
371{
372#ifdef CONFIG_Q40
373 if (MACH_IS_Q40)
374 return q40_probe_irq_off(irqs);
375#endif
376 return 0;
377}
378
379EXPORT_SYMBOL(probe_irq_off);
380
Roman Zippel68387c42006-06-25 05:47:01 -0700381unsigned int irq_canonicalize(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Roman Zippel68387c42006-06-25 05:47:01 -0700383#ifdef CONFIG_Q40
384 if (MACH_IS_Q40 && irq == 11)
385 irq = 10;
386#endif
387 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388}
389
Roman Zippel68387c42006-06-25 05:47:01 -0700390EXPORT_SYMBOL(irq_canonicalize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Al Viro2850bc22006-10-07 14:16:45 +0100392asmlinkage void m68k_handle_int(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700394 struct irq_node *node;
Roman Zippel92445ea2006-06-25 05:46:58 -0700395 kstat_cpu(0).irqs[irq]++;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700396 node = irq_list[irq];
397 do {
Al Viro2850bc22006-10-07 14:16:45 +0100398 node->handler(irq, node->dev_id);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700399 node = node->next;
400 } while (node);
Roman Zippel92445ea2006-06-25 05:46:58 -0700401}
402
Al Viro2850bc22006-10-07 14:16:45 +0100403asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
404{
405 struct pt_regs *old_regs;
406 old_regs = set_irq_regs(regs);
407 m68k_handle_int(irq);
408 set_irq_regs(old_regs);
409}
410
Roman Zippel92445ea2006-06-25 05:46:58 -0700411asmlinkage void handle_badint(struct pt_regs *regs)
412{
413 kstat_cpu(0).irqs[0]++;
414 printk("unexpected interrupt from %u\n", regs->vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
417int show_interrupts(struct seq_file *p, void *v)
418{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700419 struct irq_controller *contr;
420 struct irq_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 int i = *(loff_t *) v;
422
423 /* autovector interrupts */
Roman Zippel68387c42006-06-25 05:47:01 -0700424 if (irq_list[i]) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700425 contr = irq_controller[i];
426 node = irq_list[i];
Roman Zippel68387c42006-06-25 05:47:01 -0700427 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700428 while ((node = node->next))
429 seq_printf(p, ", %s", node->devname);
430 seq_puts(p, "\n");
Roman Zippel68387c42006-06-25 05:47:01 -0700431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return 0;
433}
434
Geert Uytterhoevenda9870e2008-10-13 21:59:01 +0200435#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436void init_irq_proc(void)
437{
438 /* Insert /proc/irq driver here */
439}
Geert Uytterhoevenda9870e2008-10-13 21:59:01 +0200440#endif