blob: c7f6ee67fd5abc425815d49519c4fb3fe36b96c6 [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>
42
43#ifdef CONFIG_Q40
44#include <asm/q40ints.h>
45#endif
46
47/* table for system interrupt handlers */
Roman Zippelb5dc7842006-06-25 05:47:00 -070048static struct irq_node *irq_list[SYS_IRQS];
49static struct irq_controller *irq_controller[SYS_IRQS];
50
51static struct irq_controller auto_irq_controller = {
52 .name = "auto",
53 .lock = SPIN_LOCK_UNLOCKED,
54 .startup = m68k_irq_startup,
55 .shutdown = m68k_irq_shutdown,
56};
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static const char *default_names[SYS_IRQS] = {
59 [0] = "spurious int",
60 [1] = "int1 handler",
61 [2] = "int2 handler",
62 [3] = "int3 handler",
63 [4] = "int4 handler",
64 [5] = "int5 handler",
65 [6] = "int6 handler",
66 [7] = "int7 handler"
67};
68
69/* The number of spurious interrupts */
70volatile unsigned int num_spurious;
71
72#define NUM_IRQ_NODES 100
73static irq_node_t nodes[NUM_IRQ_NODES];
74
75static void dummy_enable_irq(unsigned int irq);
76static void dummy_disable_irq(unsigned int irq);
77static int dummy_request_irq(unsigned int irq,
78 irqreturn_t (*handler) (int, void *, struct pt_regs *),
79 unsigned long flags, const char *devname, void *dev_id);
80static void dummy_free_irq(unsigned int irq, void *dev_id);
81
82void (*enable_irq) (unsigned int) = dummy_enable_irq;
83void (*disable_irq) (unsigned int) = dummy_disable_irq;
84
85int (*mach_request_irq) (unsigned int, irqreturn_t (*)(int, void *, struct pt_regs *),
86 unsigned long, const char *, void *) = dummy_request_irq;
87void (*mach_free_irq) (unsigned int, void *) = dummy_free_irq;
88
89void init_irq_proc(void);
90
91/*
92 * void init_IRQ(void)
93 *
94 * Parameters: None
95 *
96 * Returns: Nothing
97 *
98 * This function should be called during kernel startup to initialize
99 * the IRQ handling routines.
100 */
101
102void __init init_IRQ(void)
103{
104 int i;
105
Roman Zippel6d2f16a2006-06-23 02:04:59 -0700106 /* assembly irq entry code relies on this... */
107 if (HARDIRQ_MASK != 0x00ff0000) {
108 extern void hardirq_mask_is_broken(void);
109 hardirq_mask_is_broken();
110 }
111
Roman Zippelb5dc7842006-06-25 05:47:00 -0700112 for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++) {
113 irq_controller[i] = &auto_irq_controller;
114 if (mach_default_handler && (*mach_default_handler)[i])
115 cpu_request_irq(i, (*mach_default_handler)[i],
116 0, default_names[i], NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 mach_init_IRQ ();
120}
121
122irq_node_t *new_irq_node(void)
123{
124 irq_node_t *node;
125 short i;
126
Roman Zippelb5dc7842006-06-25 05:47:00 -0700127 for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
128 if (!node->handler) {
129 memset(node, 0, sizeof(*node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return node;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700131 }
132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 printk ("new_irq_node: out of nodes\n");
135 return NULL;
136}
137
138/*
139 * We will keep these functions until I have convinced Linus to move
140 * the declaration of them from include/linux/sched.h to
141 * include/asm/irq.h.
142 */
143int request_irq(unsigned int irq,
144 irqreturn_t (*handler) (int, void *, struct pt_regs *),
145 unsigned long flags, const char *devname, void *dev_id)
146{
147 return mach_request_irq(irq, handler, flags, devname, dev_id);
148}
149
150EXPORT_SYMBOL(request_irq);
151
152void free_irq(unsigned int irq, void *dev_id)
153{
154 mach_free_irq(irq, dev_id);
155}
156
157EXPORT_SYMBOL(free_irq);
158
Roman Zippelb5dc7842006-06-25 05:47:00 -0700159int setup_irq(unsigned int irq, struct irq_node *node)
160{
161 struct irq_controller *contr;
162 struct irq_node **prev;
163 unsigned long flags;
164
165 if (irq >= SYS_IRQS || !(contr = irq_controller[irq])) {
166 printk("%s: Incorrect IRQ %d from %s\n",
167 __FUNCTION__, irq, node->devname);
168 return -ENXIO;
169 }
170
171 spin_lock_irqsave(&contr->lock, flags);
172
173 prev = irq_list + irq;
174 if (*prev) {
175 /* Can't share interrupts unless both agree to */
176 if (!((*prev)->flags & node->flags & SA_SHIRQ)) {
177 spin_unlock_irqrestore(&contr->lock, flags);
178 return -EBUSY;
179 }
180 while (*prev)
181 prev = &(*prev)->next;
182 }
183
184 if (!irq_list[irq]) {
185 if (contr->startup)
186 contr->startup(irq);
187 else
188 contr->enable(irq);
189 }
190 node->next = NULL;
191 *prev = node;
192
193 spin_unlock_irqrestore(&contr->lock, flags);
194
195 return 0;
196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198int cpu_request_irq(unsigned int irq,
199 irqreturn_t (*handler)(int, void *, struct pt_regs *),
200 unsigned long flags, const char *devname, void *dev_id)
201{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700202 struct irq_node *node;
203 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Roman Zippelb5dc7842006-06-25 05:47:00 -0700205 node = new_irq_node();
206 if (!node)
207 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Roman Zippelb5dc7842006-06-25 05:47:00 -0700209 node->handler = handler;
210 node->flags = flags;
211 node->dev_id = dev_id;
212 node->devname = devname;
213
214 res = setup_irq(irq, node);
215 if (res)
216 node->handler = NULL;
217
218 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
221void cpu_free_irq(unsigned int irq, void *dev_id)
222{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700223 struct irq_controller *contr;
224 struct irq_node **p, *node;
225 unsigned long flags;
226
227 if (irq >= SYS_IRQS || !(contr = irq_controller[irq])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
229 return;
230 }
231
Roman Zippelb5dc7842006-06-25 05:47:00 -0700232 spin_lock_irqsave(&contr->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Roman Zippelb5dc7842006-06-25 05:47:00 -0700234 p = irq_list + irq;
235 while ((node = *p)) {
236 if (node->dev_id == dev_id)
237 break;
238 p = &node->next;
239 }
240
241 if (node) {
242 *p = node->next;
243 node->handler = NULL;
244 } else
245 printk("%s: Removing probably wrong IRQ %d\n",
246 __FUNCTION__, irq);
247
248 if (!irq_list[irq])
249 contr->shutdown(irq);
250
251 spin_unlock_irqrestore(&contr->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
Roman Zippelb5dc7842006-06-25 05:47:00 -0700254int m68k_irq_startup(unsigned int irq)
255{
256 if (irq <= IRQ_AUTO_7)
257 vectors[VEC_SPUR + irq] = auto_inthandler;
258 return 0;
259}
260
261void m68k_irq_shutdown(unsigned int irq)
262{
263 if (irq <= IRQ_AUTO_7)
264 vectors[VEC_SPUR + irq] = bad_inthandler;
265}
266
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/*
269 * Do we need these probe functions on the m68k?
270 *
271 * ... may be useful with ISA devices
272 */
273unsigned long probe_irq_on (void)
274{
275#ifdef CONFIG_Q40
276 if (MACH_IS_Q40)
277 return q40_probe_irq_on();
278#endif
279 return 0;
280}
281
282EXPORT_SYMBOL(probe_irq_on);
283
284int probe_irq_off (unsigned long irqs)
285{
286#ifdef CONFIG_Q40
287 if (MACH_IS_Q40)
288 return q40_probe_irq_off(irqs);
289#endif
290 return 0;
291}
292
293EXPORT_SYMBOL(probe_irq_off);
294
295static void dummy_enable_irq(unsigned int irq)
296{
297 printk("calling uninitialized enable_irq()\n");
298}
299
300static void dummy_disable_irq(unsigned int irq)
301{
302 printk("calling uninitialized disable_irq()\n");
303}
304
305static int dummy_request_irq(unsigned int irq,
306 irqreturn_t (*handler) (int, void *, struct pt_regs *),
307 unsigned long flags, const char *devname, void *dev_id)
308{
309 printk("calling uninitialized request_irq()\n");
310 return 0;
311}
312
313static void dummy_free_irq(unsigned int irq, void *dev_id)
314{
315 printk("calling uninitialized disable_irq()\n");
316}
317
Roman Zippel92445ea2006-06-25 05:46:58 -0700318asmlinkage void m68k_handle_int(unsigned int irq, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700320 struct irq_node *node;
321
Roman Zippel92445ea2006-06-25 05:46:58 -0700322 kstat_cpu(0).irqs[irq]++;
Roman Zippelb5dc7842006-06-25 05:47:00 -0700323 node = irq_list[irq];
324 do {
325 node->handler(irq, node->dev_id, regs);
326 node = node->next;
327 } while (node);
Roman Zippel92445ea2006-06-25 05:46:58 -0700328}
329
330asmlinkage void handle_badint(struct pt_regs *regs)
331{
332 kstat_cpu(0).irqs[0]++;
333 printk("unexpected interrupt from %u\n", regs->vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334}
335
336int show_interrupts(struct seq_file *p, void *v)
337{
Roman Zippelb5dc7842006-06-25 05:47:00 -0700338 struct irq_controller *contr;
339 struct irq_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 int i = *(loff_t *) v;
341
342 /* autovector interrupts */
Roman Zippelb5dc7842006-06-25 05:47:00 -0700343 if (i < SYS_IRQS && irq_list[i]) {
344 contr = irq_controller[i];
345 node = irq_list[i];
346 seq_printf(p, "%s %u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
347 while ((node = node->next))
348 seq_printf(p, ", %s", node->devname);
349 seq_puts(p, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 } else if (i == SYS_IRQS)
351 mach_get_irq_list(p, v);
352 return 0;
353}
354
355void init_irq_proc(void)
356{
357 /* Insert /proc/irq driver here */
358}
359