- Peter Anvin: more P4 configuration parsing
[davej-history.git] / arch / m68k / amiga / amiints.c
blob0902518f9bad9014eacbeb384f4e0658155be050
1 /*
2 * linux/arch/m68k/amiga/amiints.c -- Amiga Linux interrupt handling code
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.
8 * 11/07/96: rewritten interrupt handling, irq lists are exists now only for
9 * this sources where it makes sense (VERTB/PORTS/EXTER) and you must
10 * be careful that dev_id for this sources is unique since this the
11 * only possibility to distinguish between different handlers for
12 * free_irq. irq lists also have different irq flags:
13 * - IRQ_FLG_FAST: handler is inserted at top of list (after other
14 * fast handlers)
15 * - IRQ_FLG_SLOW: handler is inserted at bottom of list and before
16 * they're executed irq level is set to the previous
17 * one, but handlers don't need to be reentrant, if
18 * reentrance occurred, slow handlers will be just
19 * called again.
20 * The whole interrupt handling for CIAs is moved to cia.c
21 * /Roman Zippel
23 * 07/08/99: rewamp of the interrupt handling - we now have two types of
24 * interrupts, normal and fast handlers, fast handlers being
25 * marked with SA_INTERRUPT and runs with all other interrupts
26 * disabled. Normal interrupts disable their own source but
27 * run with all other interrupt sources enabled.
28 * PORTS and EXTER interrupts are always shared even if the
29 * drivers do not explicitly mark this when calling
30 * request_irq which they really should do.
31 * This is similar to the way interrupts are handled on all
32 * other architectures and makes a ton of sense besides
33 * having the advantage of making it easier to share
34 * drivers.
35 * /Jes
38 #include <linux/types.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/kernel_stat.h>
42 #include <linux/init.h>
44 #include <asm/system.h>
45 #include <asm/irq.h>
46 #include <asm/traps.h>
47 #include <asm/amigahw.h>
48 #include <asm/amigaints.h>
49 #include <asm/amipcmcia.h>
51 extern int cia_request_irq(struct ciabase *base,int irq,
52 void (*handler)(int, void *, struct pt_regs *),
53 unsigned long flags, const char *devname, void *dev_id);
54 extern void cia_free_irq(struct ciabase *base, unsigned int irq, void *dev_id);
55 extern void cia_init_IRQ(struct ciabase *base);
56 extern int cia_get_irq_list(struct ciabase *base, char *buf);
58 /* irq node variables for amiga interrupt sources */
59 static irq_node_t *ami_irq_list[AMI_STD_IRQS];
61 static unsigned short amiga_intena_vals[AMI_STD_IRQS] = {
62 IF_VERTB, IF_COPER, IF_AUD0, IF_AUD1, IF_AUD2, IF_AUD3, IF_BLIT,
63 IF_DSKSYN, IF_DSKBLK, IF_RBF, IF_TBE, IF_SOFT, IF_PORTS, IF_EXTER
65 static const unsigned char ami_servers[AMI_STD_IRQS] = {
66 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
69 static short ami_ablecount[AMI_IRQS];
71 static void ami_badint(int irq, void *dev_id, struct pt_regs *fp)
73 num_spurious += 1;
77 * void amiga_init_IRQ(void)
79 * Parameters: None
81 * Returns: Nothing
83 * This function should be called during kernel startup to initialize
84 * the amiga IRQ handling routines.
87 void __init amiga_init_IRQ(void)
89 int i;
91 /* initialize handlers */
92 for (i = 0; i < AMI_STD_IRQS; i++) {
93 if (ami_servers[i]) {
94 ami_irq_list[i] = NULL;
95 } else {
96 ami_irq_list[i] = new_irq_node();
97 ami_irq_list[i]->handler = ami_badint;
98 ami_irq_list[i]->flags = 0;
99 ami_irq_list[i]->dev_id = NULL;
100 ami_irq_list[i]->devname = NULL;
101 ami_irq_list[i]->next = NULL;
104 for (i = 0; i < AMI_IRQS; i++)
105 ami_ablecount[i] = 0;
107 /* turn off PCMCIA interrupts */
108 if (AMIGAHW_PRESENT(PCMCIA))
109 gayle.inten = GAYLE_IRQ_IDE;
111 /* turn off all interrupts and enable the master interrupt bit */
112 custom.intena = 0x7fff;
113 custom.intreq = 0x7fff;
114 custom.intena = IF_SETCLR | IF_INTEN;
116 cia_init_IRQ(&ciaa_base);
117 cia_init_IRQ(&ciab_base);
120 static inline int amiga_insert_irq(irq_node_t **list, irq_node_t *node)
122 unsigned long flags;
123 irq_node_t *cur;
125 if (!node->dev_id)
126 printk("%s: Warning: dev_id of %s is zero\n",
127 __FUNCTION__, node->devname);
129 save_flags(flags);
130 cli();
132 cur = *list;
134 if (node->flags & SA_INTERRUPT) {
135 if (node->flags & SA_SHIRQ)
136 return -EBUSY;
138 * There should never be more than one
140 while (cur && cur->flags & SA_INTERRUPT) {
141 list = &cur->next;
142 cur = cur->next;
144 } else {
145 while (cur) {
146 list = &cur->next;
147 cur = cur->next;
151 node->next = cur;
152 *list = node;
154 restore_flags(flags);
155 return 0;
158 static inline void amiga_delete_irq(irq_node_t **list, void *dev_id)
160 unsigned long flags;
161 irq_node_t *node;
163 save_flags(flags);
164 cli();
166 for (node = *list; node; list = &node->next, node = *list) {
167 if (node->dev_id == dev_id) {
168 *list = node->next;
169 /* Mark it as free. */
170 node->handler = NULL;
171 restore_flags(flags);
172 return;
175 restore_flags(flags);
176 printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
180 * amiga_request_irq : add an interrupt service routine for a particular
181 * machine specific interrupt source.
182 * If the addition was successful, it returns 0.
185 int amiga_request_irq(unsigned int irq,
186 void (*handler)(int, void *, struct pt_regs *),
187 unsigned long flags, const char *devname, void *dev_id)
189 irq_node_t *node;
190 int error = 0;
192 if (irq >= AMI_IRQS) {
193 printk ("%s: Unknown IRQ %d from %s\n", __FUNCTION__,
194 irq, devname);
195 return -ENXIO;
198 if (irq >= IRQ_AMIGA_AUTO)
199 return sys_request_irq(irq - IRQ_AMIGA_AUTO, handler,
200 flags, devname, dev_id);
202 if (irq >= IRQ_AMIGA_CIAB)
203 return cia_request_irq(&ciab_base, irq - IRQ_AMIGA_CIAB,
204 handler, flags, devname, dev_id);
206 if (irq >= IRQ_AMIGA_CIAA)
207 return cia_request_irq(&ciaa_base, irq - IRQ_AMIGA_CIAA,
208 handler, flags, devname, dev_id);
211 * IRQ_AMIGA_PORTS & IRQ_AMIGA_EXTER defaults to shared,
212 * we could add a check here for the SA_SHIRQ flag but all drivers
213 * should be aware of sharing anyway.
215 if (ami_servers[irq]) {
216 if (!(node = new_irq_node()))
217 return -ENOMEM;
218 node->handler = handler;
219 node->flags = flags;
220 node->dev_id = dev_id;
221 node->devname = devname;
222 node->next = NULL;
223 error = amiga_insert_irq(&ami_irq_list[irq], node);
224 } else {
225 ami_irq_list[irq]->handler = handler;
226 ami_irq_list[irq]->flags = flags;
227 ami_irq_list[irq]->dev_id = dev_id;
228 ami_irq_list[irq]->devname = devname;
231 /* enable the interrupt */
232 if (irq < IRQ_AMIGA_PORTS && !ami_ablecount[irq])
233 custom.intena = IF_SETCLR | amiga_intena_vals[irq];
235 return error;
238 void amiga_free_irq(unsigned int irq, void *dev_id)
240 if (irq >= AMI_IRQS) {
241 printk ("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
242 return;
245 if (irq >= IRQ_AMIGA_AUTO)
246 sys_free_irq(irq - IRQ_AMIGA_AUTO, dev_id);
248 if (irq >= IRQ_AMIGA_CIAB) {
249 cia_free_irq(&ciab_base, irq - IRQ_AMIGA_CIAB, dev_id);
250 return;
253 if (irq >= IRQ_AMIGA_CIAA) {
254 cia_free_irq(&ciaa_base, irq - IRQ_AMIGA_CIAA, dev_id);
255 return;
258 if (ami_servers[irq]) {
259 amiga_delete_irq(&ami_irq_list[irq], dev_id);
260 /* if server list empty, disable the interrupt */
261 if (!ami_irq_list[irq] && irq < IRQ_AMIGA_PORTS)
262 custom.intena = amiga_intena_vals[irq];
263 } else {
264 if (ami_irq_list[irq]->dev_id != dev_id)
265 printk("%s: removing probably wrong IRQ %d from %s\n",
266 __FUNCTION__, irq, ami_irq_list[irq]->devname);
267 ami_irq_list[irq]->handler = ami_badint;
268 ami_irq_list[irq]->flags = 0;
269 ami_irq_list[irq]->dev_id = NULL;
270 ami_irq_list[irq]->devname = NULL;
271 custom.intena = amiga_intena_vals[irq];
276 * Enable/disable a particular machine specific interrupt source.
277 * Note that this may affect other interrupts in case of a shared interrupt.
278 * This function should only be called for a _very_ short time to change some
279 * internal data, that may not be changed by the interrupt at the same time.
280 * ami_(enable|disable)_irq calls may also be nested.
283 void amiga_enable_irq(unsigned int irq)
285 if (irq >= AMI_IRQS) {
286 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
287 return;
290 if (--ami_ablecount[irq])
291 return;
293 /* No action for auto-vector interrupts */
294 if (irq >= IRQ_AMIGA_AUTO){
295 printk("%s: Trying to enable auto-vector IRQ %i\n",
296 __FUNCTION__, irq - IRQ_AMIGA_AUTO);
297 return;
300 if (irq >= IRQ_AMIGA_CIAB) {
301 cia_set_irq(&ciab_base, (1 << (irq - IRQ_AMIGA_CIAB)));
302 cia_able_irq(&ciab_base, CIA_ICR_SETCLR |
303 (1 << (irq - IRQ_AMIGA_CIAB)));
304 return;
307 if (irq >= IRQ_AMIGA_CIAA) {
308 cia_set_irq(&ciaa_base, (1 << (irq - IRQ_AMIGA_CIAA)));
309 cia_able_irq(&ciaa_base, CIA_ICR_SETCLR |
310 (1 << (irq - IRQ_AMIGA_CIAA)));
311 return;
314 /* enable the interrupt */
315 custom.intena = IF_SETCLR | amiga_intena_vals[irq];
318 void amiga_disable_irq(unsigned int irq)
320 if (irq >= AMI_IRQS) {
321 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
322 return;
325 if (ami_ablecount[irq]++)
326 return;
328 /* No action for auto-vector interrupts */
329 if (irq >= IRQ_AMIGA_AUTO) {
330 printk("%s: Trying to disable auto-vector IRQ %i\n",
331 __FUNCTION__, irq - IRQ_AMIGA_AUTO);
332 return;
335 if (irq >= IRQ_AMIGA_CIAB) {
336 cia_able_irq(&ciab_base, 1 << (irq - IRQ_AMIGA_CIAB));
337 return;
340 if (irq >= IRQ_AMIGA_CIAA) {
341 cia_able_irq(&ciaa_base, 1 << (irq - IRQ_AMIGA_CIAA));
342 return;
345 /* disable the interrupt */
346 custom.intena = amiga_intena_vals[irq];
349 inline void amiga_do_irq(int irq, struct pt_regs *fp)
351 kstat.irqs[0][SYS_IRQS + irq]++;
352 ami_irq_list[irq]->handler(irq, ami_irq_list[irq]->dev_id, fp);
355 void amiga_do_irq_list(int irq, struct pt_regs *fp)
357 irq_node_t *node;
359 kstat.irqs[0][SYS_IRQS + irq]++;
361 custom.intreq = amiga_intena_vals[irq];
363 for (node = ami_irq_list[irq]; node; node = node->next)
364 node->handler(irq, node->dev_id, fp);
368 * The builtin Amiga hardware interrupt handlers.
371 static void ami_int1(int irq, void *dev_id, struct pt_regs *fp)
373 unsigned short ints = custom.intreqr & custom.intenar;
375 /* if serial transmit buffer empty, interrupt */
376 if (ints & IF_TBE) {
377 custom.intreq = IF_TBE;
378 amiga_do_irq(IRQ_AMIGA_TBE, fp);
381 /* if floppy disk transfer complete, interrupt */
382 if (ints & IF_DSKBLK) {
383 custom.intreq = IF_DSKBLK;
384 amiga_do_irq(IRQ_AMIGA_DSKBLK, fp);
387 /* if software interrupt set, interrupt */
388 if (ints & IF_SOFT) {
389 custom.intreq = IF_SOFT;
390 amiga_do_irq(IRQ_AMIGA_SOFT, fp);
394 static void ami_int3(int irq, void *dev_id, struct pt_regs *fp)
396 unsigned short ints = custom.intreqr & custom.intenar;
398 /* if a blitter interrupt */
399 if (ints & IF_BLIT) {
400 custom.intreq = IF_BLIT;
401 amiga_do_irq(IRQ_AMIGA_BLIT, fp);
404 /* if a copper interrupt */
405 if (ints & IF_COPER) {
406 custom.intreq = IF_COPER;
407 amiga_do_irq(IRQ_AMIGA_COPPER, fp);
410 /* if a vertical blank interrupt */
411 if (ints & IF_VERTB)
412 amiga_do_irq_list(IRQ_AMIGA_VERTB, fp);
415 static void ami_int4(int irq, void *dev_id, struct pt_regs *fp)
417 unsigned short ints = custom.intreqr & custom.intenar;
419 /* if audio 0 interrupt */
420 if (ints & IF_AUD0) {
421 custom.intreq = IF_AUD0;
422 amiga_do_irq(IRQ_AMIGA_AUD0, fp);
425 /* if audio 1 interrupt */
426 if (ints & IF_AUD1) {
427 custom.intreq = IF_AUD1;
428 amiga_do_irq(IRQ_AMIGA_AUD1, fp);
431 /* if audio 2 interrupt */
432 if (ints & IF_AUD2) {
433 custom.intreq = IF_AUD2;
434 amiga_do_irq(IRQ_AMIGA_AUD2, fp);
437 /* if audio 3 interrupt */
438 if (ints & IF_AUD3) {
439 custom.intreq = IF_AUD3;
440 amiga_do_irq(IRQ_AMIGA_AUD3, fp);
444 static void ami_int5(int irq, void *dev_id, struct pt_regs *fp)
446 unsigned short ints = custom.intreqr & custom.intenar;
448 /* if serial receive buffer full interrupt */
449 if (ints & IF_RBF) {
450 /* acknowledge of IF_RBF must be done by the serial interrupt */
451 amiga_do_irq(IRQ_AMIGA_RBF, fp);
454 /* if a disk sync interrupt */
455 if (ints & IF_DSKSYN) {
456 custom.intreq = IF_DSKSYN;
457 amiga_do_irq(IRQ_AMIGA_DSKSYN, fp);
461 static void ami_int7(int irq, void *dev_id, struct pt_regs *fp)
463 panic ("level 7 interrupt received\n");
466 void (*amiga_default_handler[SYS_IRQS])(int, void *, struct pt_regs *) = {
467 ami_badint, ami_int1, ami_badint, ami_int3,
468 ami_int4, ami_int5, ami_badint, ami_int7
471 int amiga_get_irq_list(char *buf)
473 int i, len = 0;
474 irq_node_t *node;
476 for (i = 0; i < AMI_STD_IRQS; i++) {
477 if (!(node = ami_irq_list[i]))
478 continue;
479 len += sprintf(buf+len, "ami %2d: %10u ", i,
480 kstat.irqs[0][SYS_IRQS + i]);
481 do {
482 if (node->flags & SA_INTERRUPT)
483 len += sprintf(buf+len, "F ");
484 else
485 len += sprintf(buf+len, " ");
486 len += sprintf(buf+len, "%s\n", node->devname);
487 if ((node = node->next))
488 len += sprintf(buf+len, " ");
489 } while (node);
492 len += cia_get_irq_list(&ciaa_base, buf+len);
493 len += cia_get_irq_list(&ciab_base, buf+len);
494 return len;