]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/m68k/kernel/ints.c
[PATCH] m68k: introduce irq controller
[linux-2.6-omap-h63xx.git] / arch / m68k / kernel / ints.c
1 /*
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 */
48 static struct irq_node *irq_list[SYS_IRQS];
49 static struct irq_controller *irq_controller[SYS_IRQS];
50
51 static 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 };
57
58 static 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 */
70 volatile unsigned int num_spurious;
71
72 #define NUM_IRQ_NODES 100
73 static irq_node_t nodes[NUM_IRQ_NODES];
74
75 static void dummy_enable_irq(unsigned int irq);
76 static void dummy_disable_irq(unsigned int irq);
77 static 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);
80 static void dummy_free_irq(unsigned int irq, void *dev_id);
81
82 void (*enable_irq) (unsigned int) = dummy_enable_irq;
83 void (*disable_irq) (unsigned int) = dummy_disable_irq;
84
85 int (*mach_request_irq) (unsigned int, irqreturn_t (*)(int, void *, struct pt_regs *),
86                       unsigned long, const char *, void *) = dummy_request_irq;
87 void (*mach_free_irq) (unsigned int, void *) = dummy_free_irq;
88
89 void 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
102 void __init init_IRQ(void)
103 {
104         int i;
105
106         /* 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
112         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);
117         }
118
119         mach_init_IRQ ();
120 }
121
122 irq_node_t *new_irq_node(void)
123 {
124         irq_node_t *node;
125         short i;
126
127         for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
128                 if (!node->handler) {
129                         memset(node, 0, sizeof(*node));
130                         return node;
131                 }
132         }
133
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  */
143 int 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
150 EXPORT_SYMBOL(request_irq);
151
152 void free_irq(unsigned int irq, void *dev_id)
153 {
154         mach_free_irq(irq, dev_id);
155 }
156
157 EXPORT_SYMBOL(free_irq);
158
159 int 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
198 int 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 {
202         struct irq_node *node;
203         int res;
204
205         node = new_irq_node();
206         if (!node)
207                 return -ENOMEM;
208
209         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;
219 }
220
221 void cpu_free_irq(unsigned int irq, void *dev_id)
222 {
223         struct irq_controller *contr;
224         struct irq_node **p, *node;
225         unsigned long flags;
226
227         if (irq >= SYS_IRQS || !(contr = irq_controller[irq])) {
228                 printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
229                 return;
230         }
231
232         spin_lock_irqsave(&contr->lock, flags);
233
234         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);
252 }
253
254 int 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
261 void m68k_irq_shutdown(unsigned int irq)
262 {
263         if (irq <= IRQ_AUTO_7)
264                 vectors[VEC_SPUR + irq] = bad_inthandler;
265 }
266
267
268 /*
269  * Do we need these probe functions on the m68k?
270  *
271  *  ... may be useful with ISA devices
272  */
273 unsigned 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
282 EXPORT_SYMBOL(probe_irq_on);
283
284 int 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
293 EXPORT_SYMBOL(probe_irq_off);
294
295 static void dummy_enable_irq(unsigned int irq)
296 {
297         printk("calling uninitialized enable_irq()\n");
298 }
299
300 static void dummy_disable_irq(unsigned int irq)
301 {
302         printk("calling uninitialized disable_irq()\n");
303 }
304
305 static 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
313 static void dummy_free_irq(unsigned int irq, void *dev_id)
314 {
315         printk("calling uninitialized disable_irq()\n");
316 }
317
318 asmlinkage void m68k_handle_int(unsigned int irq, struct pt_regs *regs)
319 {
320         struct irq_node *node;
321
322         kstat_cpu(0).irqs[irq]++;
323         node = irq_list[irq];
324         do {
325                 node->handler(irq, node->dev_id, regs);
326                 node = node->next;
327         } while (node);
328 }
329
330 asmlinkage void handle_badint(struct pt_regs *regs)
331 {
332         kstat_cpu(0).irqs[0]++;
333         printk("unexpected interrupt from %u\n", regs->vector);
334 }
335
336 int show_interrupts(struct seq_file *p, void *v)
337 {
338         struct irq_controller *contr;
339         struct irq_node *node;
340         int i = *(loff_t *) v;
341
342         /* autovector interrupts */
343         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");
350         } else if (i == SYS_IRQS)
351                 mach_get_irq_list(p, v);
352         return 0;
353 }
354
355 void init_irq_proc(void)
356 {
357         /* Insert /proc/irq driver here */
358 }
359