blob: 5a8344b935474a645b4ebe0e7612169df9ded3c2 [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
28#include <linux/config.h>
29#include <linux/module.h>
30#include <linux/types.h>
31#include <linux/sched.h>
32#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#ifdef CONFIG_Q40
45#include <asm/q40ints.h>
46#endif
47
Roman Zippel68387c42006-06-25 05:47:01 -070048extern u32 auto_irqhandler_fixup[];
49extern u32 user_irqhandler_fixup[];
50extern u16 user_irqvec_fixup[];
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* table for system interrupt handlers */
Roman Zippel68387c42006-06-25 05:47:01 -070053static struct irq_node *irq_list[NR_IRQS];
54static struct irq_controller *irq_controller[NR_IRQS];
55static int irq_depth[NR_IRQS];
56
57static int m68k_first_user_vec;
Roman Zippelb5dc7842006-06-25 05:47:00 -070058
59static struct irq_controller auto_irq_controller = {
60 .name = "auto",
61 .lock = SPIN_LOCK_UNLOCKED,
62 .startup = m68k_irq_startup,
63 .shutdown = m68k_irq_shutdown,
64};
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Roman Zippel68387c42006-06-25 05:47:01 -070066static struct irq_controller user_irq_controller = {
67 .name = "user",
68 .lock = SPIN_LOCK_UNLOCKED,
69 .startup = m68k_irq_startup,
70 .shutdown = m68k_irq_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define NUM_IRQ_NODES 100
74static irq_node_t nodes[NUM_IRQ_NODES];
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/*
77 * void init_IRQ(void)
78 *
79 * Parameters: None
80 *
81 * Returns: Nothing
82 *
83 * This function should be called during kernel startup to initialize
84 * the IRQ handling routines.
85 */
86
87void __init init_IRQ(void)
88{
89 int i;
90
Roman Zippel6d2f16a2006-06-23 02:04:59 -070091 /* 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();
95 }
96
Roman Zippel68387c42006-06-25 05:47:01 -070097 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
Roman Zippelb5dc7842006-06-25 05:47:00 -070098 irq_controller[i] = &auto_irq_controller;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Roman Zippel68387c42006-06-25 05:47:01 -0700100 mach_init_IRQ();
101}
102
103/**
104 * m68k_setup_auto_interrupt
105 * @handler: called from auto vector interrupts
106 *
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.
110 */
111void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
112{
113 if (handler)
114 *auto_irqhandler_fixup = (u32)handler;
115 flush_icache();
116}
117
118/**
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
123 *
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.
129 */
130void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
131 void (*handler)(unsigned int, struct pt_regs *))
132{
133 int i;
134
135 m68k_first_user_vec = vec;
136 for (i = 0; i < cnt; i++)
137 irq_controller[IRQ_USER + i] = &user_irq_controller;
138 *user_irqvec_fixup = vec - IRQ_USER;
139 if (handler)
140 *user_irqhandler_fixup = (u32)handler;
141 flush_icache();
142}
143
144/**
145 * m68k_setup_irq_controller
146 * @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 */
154void m68k_setup_irq_controller(struct irq_controller *contr, unsigned int irq,
155 unsigned int cnt)
156{
157 int i;
158
159 for (i = 0; i < cnt; i++)
160 irq_controller[irq + i] = contr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
163irq_node_t *new_irq_node(void)
164{
165 irq_node_t *node;
166 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{
181 struct irq_controller *contr;
182 struct irq_node **prev;
183 unsigned long flags;
184
Roman Zippel68387c42006-06-25 05:47:01 -0700185 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700186 printk("%s: Incorrect IRQ %d from %s\n",
187 __FUNCTION__, irq, node->devname);
188 return -ENXIO;
189 }
190
191 spin_lock_irqsave(&contr->lock, flags);
192
193 prev = irq_list + irq;
194 if (*prev) {
195 /* Can't share interrupts unless both agree to */
196 if (!((*prev)->flags & node->flags & SA_SHIRQ)) {
197 spin_unlock_irqrestore(&contr->lock, flags);
198 return -EBUSY;
199 }
200 while (*prev)
201 prev = &(*prev)->next;
202 }
203
204 if (!irq_list[irq]) {
205 if (contr->startup)
206 contr->startup(irq);
207 else
208 contr->enable(irq);
209 }
210 node->next = NULL;
211 *prev = node;
212
213 spin_unlock_irqrestore(&contr->lock, flags);
214
215 return 0;
216}
217
Roman Zippel68387c42006-06-25 05:47:01 -0700218int request_irq(unsigned int irq,
219 irqreturn_t (*handler) (int, void *, struct pt_regs *),
220 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{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700245 struct irq_controller *contr;
246 struct irq_node **p, *node;
247 unsigned long flags;
248
Roman Zippel68387c42006-06-25 05:47:01 -0700249 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
251 return;
252 }
253
Roman Zippelb5dc7842006-06-25 05:47:00 -0700254 spin_lock_irqsave(&contr->lock, 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",
268 __FUNCTION__, irq);
269
Roman Zippel68387c42006-06-25 05:47:01 -0700270 if (!irq_list[irq]) {
271 if (contr->shutdown)
272 contr->shutdown(irq);
273 else
274 contr->disable(irq);
275 }
Roman Zippelb5dc7842006-06-25 05:47:00 -0700276
277 spin_unlock_irqrestore(&contr->lock, 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{
284 struct irq_controller *contr;
285 unsigned long flags;
286
287 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
288 printk("%s: Incorrect IRQ %d\n",
289 __FUNCTION__, irq);
290 return;
291 }
292
293 spin_lock_irqsave(&contr->lock, flags);
294 if (irq_depth[irq]) {
295 if (!--irq_depth[irq]) {
296 if (contr->enable)
297 contr->enable(irq);
298 }
299 } else
300 WARN_ON(1);
301 spin_unlock_irqrestore(&contr->lock, flags);
302}
303
304EXPORT_SYMBOL(enable_irq);
305
306void disable_irq(unsigned int irq)
307{
308 struct irq_controller *contr;
309 unsigned long flags;
310
311 if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
312 printk("%s: Incorrect IRQ %d\n",
313 __FUNCTION__, irq);
314 return;
315 }
316
317 spin_lock_irqsave(&contr->lock, flags);
318 if (!irq_depth[irq]++) {
319 if (contr->disable)
320 contr->disable(irq);
321 }
322 spin_unlock_irqrestore(&contr->lock, flags);
323}
324
325EXPORT_SYMBOL(disable_irq);
326
Roman Zippelb5dc7842006-06-25 05:47:00 -0700327int m68k_irq_startup(unsigned int irq)
328{
329 if (irq <= IRQ_AUTO_7)
330 vectors[VEC_SPUR + irq] = auto_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700331 else
332 vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700333 return 0;
334}
335
336void m68k_irq_shutdown(unsigned int irq)
337{
338 if (irq <= IRQ_AUTO_7)
339 vectors[VEC_SPUR + irq] = bad_inthandler;
Roman Zippel68387c42006-06-25 05:47:01 -0700340 else
341 vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700342}
343
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345/*
346 * Do we need these probe functions on the m68k?
347 *
348 * ... may be useful with ISA devices
349 */
350unsigned long probe_irq_on (void)
351{
352#ifdef CONFIG_Q40
353 if (MACH_IS_Q40)
354 return q40_probe_irq_on();
355#endif
356 return 0;
357}
358
359EXPORT_SYMBOL(probe_irq_on);
360
361int probe_irq_off (unsigned long irqs)
362{
363#ifdef CONFIG_Q40
364 if (MACH_IS_Q40)
365 return q40_probe_irq_off(irqs);
366#endif
367 return 0;
368}
369
370EXPORT_SYMBOL(probe_irq_off);
371
Roman Zippel68387c42006-06-25 05:47:01 -0700372unsigned int irq_canonicalize(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Roman Zippel68387c42006-06-25 05:47:01 -0700374#ifdef CONFIG_Q40
375 if (MACH_IS_Q40 && irq == 11)
376 irq = 10;
377#endif
378 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
Roman Zippel68387c42006-06-25 05:47:01 -0700381EXPORT_SYMBOL(irq_canonicalize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Roman Zippel92445ea2006-06-25 05:46:58 -0700383asmlinkage void m68k_handle_int(unsigned int irq, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700385 struct irq_node *node;
386
Roman Zippel92445ea2006-06-25 05:46:58 -0700387 kstat_cpu(0).irqs[irq]++;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700388 node = irq_list[irq];
389 do {
390 node->handler(irq, node->dev_id, regs);
391 node = node->next;
392 } while (node);
Roman Zippel92445ea2006-06-25 05:46:58 -0700393}
394
395asmlinkage void handle_badint(struct pt_regs *regs)
396{
397 kstat_cpu(0).irqs[0]++;
398 printk("unexpected interrupt from %u\n", regs->vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
401int show_interrupts(struct seq_file *p, void *v)
402{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700403 struct irq_controller *contr;
404 struct irq_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 int i = *(loff_t *) v;
406
407 /* autovector interrupts */
Roman Zippel68387c42006-06-25 05:47:01 -0700408 if (irq_list[i]) {
Roman Zippelb5dc7842006-06-25 05:47:00 -0700409 contr = irq_controller[i];
410 node = irq_list[i];
Roman Zippel68387c42006-06-25 05:47:01 -0700411 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
Roman Zippelb5dc7842006-06-25 05:47:00 -0700412 while ((node = node->next))
413 seq_printf(p, ", %s", node->devname);
414 seq_puts(p, "\n");
Roman Zippel68387c42006-06-25 05:47:01 -0700415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 return 0;
417}
418
419void init_irq_proc(void)
420{
421 /* Insert /proc/irq driver here */
422}
423