patch-2.0.21-2.1.0 linux/arch/m68k/amiga/amiints.c

Next file: linux/arch/m68k/amiga/amikeyb.c
Previous file: linux/arch/m68k/amiga/amifb.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file lx2.0/v2.0.21/linux/arch/m68k/amiga/amiints.c linux/arch/m68k/amiga/amiints.c
@@ -1,15 +1,30 @@
 /*
- * amiints.c -- Amiga Linux interrupt handling code
+ * linux/arch/m68k/amiga/amiints.c -- Amiga Linux interrupt handling code
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file COPYING in the main directory of this archive
  * for more details.
  *
+ * 11/07/96: rewritten interrupt handling, irq lists are exists now only for
+ *           this sources where it makes sense (VERTB/PORTS/EXTER) and you must
+ *           be careful that dev_id for this sources is unique since this the
+ *           only possibility to distinguish between different handlers for
+ *           free_irq. irq lists also have different irq flags:
+ *           - IRQ_FLG_FAST: handler is inserted at top of list (after other
+ *                           fast handlers)
+ *           - IRQ_FLG_SLOW: handler is inserted at bottom of list and before
+ *                           they're executed irq level is set to the previous
+ *                           one, but handlers don't need to be reentrant, if
+ *                           reentrance occured, slow handlers will be just
+ *                           called again.
+ *           The whole interrupt handling for CIAs is moved to cia.c
+ *           /Roman Zippel
  */
 
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
+#include <linux/kernel_stat.h>
 
 #include <asm/system.h>
 #include <asm/irq.h>
@@ -17,32 +32,33 @@
 #include <asm/amigahw.h>
 #include <asm/amigaints.h>
 
-/* isr node variables for amiga interrupt sources */
-static isr_node_t *ami_lists[NUM_AMIGA_SOURCES];
+extern int cia_request_irq(struct ciabase *base,int irq,
+                           void (*handler)(int, void *, struct pt_regs *),
+                           unsigned long flags, const char *devname, void *dev_id);
+extern void cia_free_irq(struct ciabase *base, unsigned int irq, void *dev_id);
+extern void cia_init_IRQ(struct ciabase *base);
+extern int cia_get_irq_list(struct ciabase *base, char *buf);
+
+/* irq node variables for amiga interrupt sources */
+static irq_node_t *ami_irq_list[AMI_STD_IRQS];
+
+unsigned short ami_intena_vals[AMI_STD_IRQS] = {
+	IF_VERTB, IF_COPER, IF_AUD0, IF_AUD1, IF_AUD2, IF_AUD3, IF_BLIT,
+	IF_DSKSYN, IF_DSKBLK, IF_RBF, IF_TBE, IF_SOFT, IF_PORTS, IF_EXTER
+};
+static const unsigned char ami_servers[AMI_STD_IRQS] = {
+	1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
+};
 
-static const ushort ami_intena_vals[NUM_AMIGA_SOURCES] = {
-    IF_VERTB, IF_COPER, IF_AUD0, IF_AUD1, IF_AUD2, IF_AUD3, IF_BLIT,
-    IF_DSKSYN, IF_DSKBLK, IF_RBF, IF_TBE, IF_PORTS, IF_PORTS, IF_PORTS,
-    IF_PORTS, IF_PORTS, IF_EXTER, IF_EXTER, IF_EXTER, IF_EXTER, IF_EXTER,
-    IF_SOFT, IF_PORTS, IF_EXTER
-    };
-
-struct ciadata
-{
-    volatile struct CIA *ciaptr;
-    unsigned long	baseirq;
-} ciadata[2];
+static short ami_ablecount[AMI_IRQS];
 
-/*
- * index into ami_lists for IRQs.  CIA IRQs are special, because
- * the same cia interrupt handler is used for both CIAs.
- */
-#define IRQ_IDX(source) (source & ~IRQ_MACHSPEC)
-#define CIA_IRQ_IDX(source) (IRQ_IDX(datap->baseirq) \
-			     +(source-IRQ_AMIGA_CIAA_TA))
+static void ami_badint(int irq, void *dev_id, struct pt_regs *fp)
+{
+	num_spurious += 1;
+}
 
 /*
- * void amiga_init_INTS (void)
+ * void amiga_init_IRQ(void)
  *
  * Parameters:	None
  *
@@ -52,405 +68,428 @@
  * the amiga IRQ handling routines.
  */
 
-static void
-    ami_int1(int irq, struct pt_regs *fp, void *data),
-    ami_int2(int irq, struct pt_regs *fp, void *data),
-    ami_int3(int irq, struct pt_regs *fp, void *data),
-    ami_int4(int irq, struct pt_regs *fp, void *data),
-    ami_int5(int irq, struct pt_regs *fp, void *data),
-    ami_int6(int irq, struct pt_regs *fp, void *data),
-    ami_int7(int irq, struct pt_regs *fp, void *data),
-    ami_intcia(int irq, struct pt_regs *fp, void *data);
-
-void amiga_init_INTS (void)
-{
-    int i;
-
-    /* initialize handlers */
-    for (i = 0; i < NUM_AMIGA_SOURCES; i++)
-	ami_lists[i] = NULL;
-
-    add_isr (IRQ1, ami_int1, 0, NULL, "int1 handler");
-    add_isr (IRQ2, ami_int2, 0, NULL, "int2 handler");
-    add_isr (IRQ3, ami_int3, 0, NULL, "int3 handler");
-    add_isr (IRQ4, ami_int4, 0, NULL, "int4 handler");
-    add_isr (IRQ5, ami_int5, 0, NULL, "int5 handler");
-    add_isr (IRQ6, ami_int6, 0, NULL, "int6 handler");
-    add_isr (IRQ7, ami_int7, 0, NULL, "int7 handler");
-
-    /* hook in the CIA interrupts */
-    ciadata[0].ciaptr = &ciaa;
-    ciadata[0].baseirq = IRQ_AMIGA_CIAA_TA;
-    add_isr (IRQ_AMIGA_PORTS, ami_intcia, 0, NULL, "Amiga CIAA");
-    ciadata[1].ciaptr = &ciab;
-    ciadata[1].baseirq = IRQ_AMIGA_CIAB_TA;
-    add_isr (IRQ_AMIGA_EXTER, ami_intcia, 0, NULL, "Amiga CIAB");
-
-    /* turn off all interrupts and enable the master interrupt bit */
-    custom.intena = 0x7fff;
-    custom.intreq = 0x7fff;
-    custom.intena = 0xc000;
-
-    /* turn off all CIA interrupts */
-    ciaa.icr = 0x7f;
-    ciab.icr = 0x7f;
-
-    /* clear any pending CIA interrupts */
-    i = ciaa.icr;
-    i = ciab.icr;
-}
-
-
-/*
- * The builtin Amiga hardware interrupt handlers.
- */
-
-static void ami_int1 (int irq, struct pt_regs *fp, void *data)
+void amiga_init_IRQ(void)
 {
-    ushort ints = custom.intreqr & custom.intenar;
-
-    /* if serial transmit buffer empty, interrupt */
-    if (ints & IF_TBE) {
-	if (ami_lists[IRQ_IDX(IRQ_AMIGA_TBE)]) {
-	    call_isr_list (IRQ_AMIGA_TBE,
-			   ami_lists[IRQ_IDX(IRQ_AMIGA_TBE)], fp);
-	    /* 
-	     * don't acknowledge.... 
-	     * allow serial code to turn off interrupts, but
-	     * leave it pending so that when interrupts are
-	     * turned on, transmission will resume
-	     */
-	} else
-	    /* acknowledge the interrupt */
-	    custom.intreq = IF_TBE;
-    }
+	int i;
 
-    /* if floppy disk transfer complete, interrupt */
-    if (ints & IF_DSKBLK) {
-	call_isr_list (IRQ_AMIGA_DSKBLK,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_DSKBLK)], fp);
-
-	/* acknowledge */
-	custom.intreq = IF_DSKBLK;
-    }
-
-    /* if software interrupt set, interrupt */
-    if (ints & IF_SOFT) {
-	call_isr_list (IRQ_AMIGA_SOFT,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_SOFT)], fp);
-
-	/* acknowledge */
-	custom.intreq = IF_SOFT;
-    }
-}
-
-static void ami_int2 (int irq, struct pt_regs *fp, void *data)
-{
-    ushort ints = custom.intreqr & custom.intenar;
+	/* initialize handlers */
+	for (i = 0; i < AMI_STD_IRQS; i++) {
+		if (ami_servers[i]) {
+			ami_irq_list[i] = NULL;
+		} else {
+			ami_irq_list[i] = new_irq_node();
+			ami_irq_list[i]->handler = ami_badint;
+			ami_irq_list[i]->flags   = IRQ_FLG_STD;
+			ami_irq_list[i]->dev_id  = NULL;
+			ami_irq_list[i]->devname = NULL;
+			ami_irq_list[i]->next    = NULL;
+		}
+	}
+	for (i = 0; i < AMI_IRQS; i++)
+		ami_ablecount[i] = 0;
 
-    if (ints & IF_PORTS) {
-	/* call routines which have hooked into the PORTS interrupt */
-	call_isr_list (IRQ_AMIGA_PORTS,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_PORTS)], fp);
+	/* turn off all interrupts and enable the master interrupt bit */
+	custom.intena = 0x7fff;
+	custom.intreq = 0x7fff;
+	custom.intena = IF_SETCLR | IF_INTEN;
 
-	/* acknowledge */
-	custom.intreq = IF_PORTS;
-    }
+	cia_init_IRQ(&ciaa_base);
+	cia_init_IRQ(&ciab_base);
 }
 
-static void ami_int3 (int irq, struct pt_regs *fp, void *data)
+void amiga_insert_irq(irq_node_t **list, irq_node_t *node)
 {
-    ushort ints = custom.intreqr & custom.intenar;
+	unsigned long flags;
+	irq_node_t *cur;
 
-    /* if a copper interrupt */
-    if (ints & IF_COPER) {
-	call_isr_list (IRQ_AMIGA_COPPER,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_COPPER)], fp);
+	if (!node->dev_id)
+		printk("%s: Warning: dev_id of %s is zero\n",
+		       __FUNCTION__, node->devname);
 
-	/* acknowledge */
-	custom.intreq = IF_COPER;
-    }
+	save_flags(flags);
+	cli();
 
-    /* if a vertical blank interrupt */
-    if (ints & IF_VERTB) {
-	call_isr_list (IRQ_AMIGA_VERTB,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_VERTB)], fp);
+	cur = *list;
 
-	/* acknowledge */
-	custom.intreq = IF_VERTB;
-    }
+	if (node->flags & IRQ_FLG_FAST) {
+		node->flags &= ~IRQ_FLG_SLOW;
+		while (cur && cur->flags & IRQ_FLG_FAST) {
+			list = &cur->next;
+			cur = cur->next;
+		}
+	} else if (node->flags & IRQ_FLG_SLOW) {
+		while (cur) {
+			list = &cur->next;
+			cur = cur->next;
+		}
+	} else {
+		while (cur && !(cur->flags & IRQ_FLG_SLOW)) {
+			list = &cur->next;
+			cur = cur->next;
+		}
+	}
 
-    /* if a blitter interrupt */
-    if (ints & IF_BLIT) {
-	call_isr_list (IRQ_AMIGA_BLIT,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_BLIT)], fp);
+	node->next = cur;
+	*list = node;
 
-	/* acknowledge */
-	custom.intreq = IF_BLIT;
-    }
+	restore_flags(flags);
 }
 
-static void ami_int4 (int irq, struct pt_regs *fp, void *data)
+void amiga_delete_irq(irq_node_t **list, void *dev_id)
 {
-    ushort ints = custom.intreqr & custom.intenar;
+	unsigned long flags;
+	irq_node_t *node;
 
-    /* if audio 0 interrupt */
-    if (ints & IF_AUD0) {
-	call_isr_list (IRQ_AMIGA_AUD0,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_AUD0)], fp);
+	save_flags(flags);
+	cli();
 
-	/* acknowledge */
-	custom.intreq = IF_AUD0;
-    }
+	for (node = *list; node; list = &node->next, node = *list) {
+		if (node->dev_id == dev_id) {
+			*list = node->next;
+			/* Mark it as free. */
+			node->handler = NULL;
+			restore_flags(flags);
+			return;
+		}
+	}
+	restore_flags(flags);
+	printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
+}
 
-    /* if audio 1 interrupt */
-    if (ints & IF_AUD1) {
-	call_isr_list (IRQ_AMIGA_AUD1,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_AUD1)], fp);
+/*
+ * amiga_request_irq : add an interrupt service routine for a particular
+ *                     machine specific interrupt source.
+ *                     If the addition was successful, it returns 0.
+ */
 
-	/* acknowledge */
-	custom.intreq = IF_AUD1;
-    }
+int amiga_request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
+                      unsigned long flags, const char *devname, void *dev_id)
+{
+	irq_node_t *node;
 
-    /* if audio 2 interrupt */
-    if (ints & IF_AUD2) {
-	call_isr_list (IRQ_AMIGA_AUD2,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_AUD2)], fp);
+	if (irq >= AMI_IRQS) {
+		printk ("%s: Unknown IRQ %d from %s\n", __FUNCTION__, irq, devname);
+		return -ENXIO;
+	}
 
-	/* acknowledge */
-	custom.intreq = IF_AUD2;
-    }
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAB))
+		return cia_request_irq(&ciab_base, irq - IRQ_IDX(IRQ_AMIGA_CIAB),
+		                       handler, flags, devname, dev_id);
+
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAA))
+		return cia_request_irq(&ciaa_base, irq - IRQ_IDX(IRQ_AMIGA_CIAA),
+		                       handler, flags, devname, dev_id);
+
+	if (ami_servers[irq]) {
+		if (!(node = new_irq_node()))
+			return -ENOMEM;
+		node->handler = handler;
+		node->flags   = flags;
+		node->dev_id  = dev_id;
+		node->devname = devname;
+		node->next    = NULL;
+		amiga_insert_irq(&ami_irq_list[irq], node);
+	} else {
+		if (!(ami_irq_list[irq]->flags & IRQ_FLG_STD)) {
+			if (ami_irq_list[irq]->flags & IRQ_FLG_LOCK) {
+				printk("%s: IRQ %d from %s is not replaceable\n",
+				       __FUNCTION__, irq, ami_irq_list[irq]->devname);
+				return -EBUSY;
+			}
+			if (flags & IRQ_FLG_REPLACE) {
+				printk("%s: %s can't replace IRQ %d from %s\n",
+				       __FUNCTION__, devname, irq, ami_irq_list[irq]->devname);
+				return -EBUSY;
+			}
+		}
+		ami_irq_list[irq]->handler = handler;
+		ami_irq_list[irq]->flags   = flags;
+		ami_irq_list[irq]->dev_id  = dev_id;
+		ami_irq_list[irq]->devname = devname;
+	}
 
-    /* if audio 3 interrupt */
-    if (ints & IF_AUD3) {
-	call_isr_list (IRQ_AMIGA_AUD3,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_AUD3)], fp);
+	/* enable the interrupt */
+	if (irq < IRQ_IDX(IRQ_AMIGA_PORTS)) 
+		custom.intena = IF_SETCLR | ami_intena_vals[irq];
 
-	/* acknowledge */
-	custom.intreq = IF_AUD3;
-    }
+	return 0;
 }
 
-static void ami_int5 (int irq, struct pt_regs *fp, void *data)
+void amiga_free_irq(unsigned int irq, void *dev_id)
 {
-    ushort ints = custom.intreqr & custom.intenar;
+	if (irq >= AMI_IRQS) {
+		printk ("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
+		return;
+	}
 
-    /* if serial receive buffer full interrupt */
-    if (ints & IF_RBF) {
-	if (ami_lists[IRQ_IDX(IRQ_AMIGA_RBF)]) {
-	    call_isr_list (IRQ_AMIGA_RBF,
-			   ami_lists[IRQ_IDX(IRQ_AMIGA_RBF)], fp);
-	    /* don't acknowledge ; leave that for the handler */
-        } else
-	    /* acknowledge the interrupt */
-	    custom.intreq = IF_RBF;
-    }
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAB)) {
+		cia_free_irq(&ciab_base, irq - IRQ_IDX(IRQ_AMIGA_CIAB), dev_id);
+		return;
+	}
 
-    /* if a disk sync interrupt */
-    if (ints & IF_DSKSYN) {
-	call_isr_list (IRQ_AMIGA_DSKSYN,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_DSKSYN)], fp);
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAA)) {
+		cia_free_irq(&ciaa_base, irq - IRQ_IDX(IRQ_AMIGA_CIAA), dev_id);
+		return;
+	}
 
-	/* acknowledge */
-	custom.intreq = IF_DSKSYN;
-    }
+	if (ami_servers[irq]) {
+		amiga_delete_irq(&ami_irq_list[irq], dev_id);
+		/* if server list empty, disable the interrupt */
+		if (!ami_irq_list[irq] && irq < IRQ_IDX(IRQ_AMIGA_PORTS))
+			custom.intena = ami_intena_vals[irq];
+	} else {
+		if (ami_irq_list[irq]->dev_id != dev_id)
+			printk("%s: removing probably wrong IRQ %d from %s\n",
+			       __FUNCTION__, irq, ami_irq_list[irq]->devname);
+		ami_irq_list[irq]->handler = ami_badint;
+		ami_irq_list[irq]->flags   = IRQ_FLG_STD;
+		ami_irq_list[irq]->dev_id  = NULL;
+		ami_irq_list[irq]->devname = NULL;
+		custom.intena = ami_intena_vals[irq];
+	}
 }
 
-static void ami_int6 (int irq, struct pt_regs *fp, void *data)
+/*
+ * Enable/disable a particular machine specific interrupt source.
+ * Note that this may affect other interrupts in case of a shared interrupt.
+ * This function should only be called for a _very_ short time to change some
+ * internal data, that may not be changed by the interrupt at the same time.
+ * ami_(enable|disable)_irq calls may also be nested.
+ */
+
+void amiga_enable_irq(unsigned int irq)
 {
-    ushort ints = custom.intreqr & custom.intenar;
+	if (irq >= AMI_IRQS) {
+		printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
+		return;
+	}
 
-    if (ints & IF_EXTER) {
-	/* call routines which have hooked into the EXTER interrupt */
-	call_isr_list (IRQ_AMIGA_EXTER,
-		       ami_lists[IRQ_IDX(IRQ_AMIGA_EXTER)], fp);
+	if (ami_ablecount[irq]++)
+		return;
 
-	/* acknowledge */
-	custom.intreq = IF_EXTER;
-    }
-}
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAB)) {
+		cia_able_irq(&ciab_base, CIA_ICR_SETCLR |
+		             (1 << (irq - IRQ_IDX(IRQ_AMIGA_CIAB))));
+		return;
+	}
 
-static void ami_int7 (int irq, struct pt_regs *fp, void *data)
-{
-    panic ("level 7 interrupt received\n");
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAA)) {
+		cia_able_irq(&ciaa_base, CIA_ICR_SETCLR |
+		             (1 << (irq - IRQ_IDX(IRQ_AMIGA_CIAA))));
+		return;
+	}
+
+	/* enable the interrupt */
+	custom.intena = IF_SETCLR | ami_intena_vals[irq];
 }
 
-static void ami_intcia (int irq, struct pt_regs *fp, void *data)
+void amiga_disable_irq(unsigned int irq)
 {
-    /* check CIA interrupts */
-    struct ciadata *datap;
-    u_char cia_ints;
+	if (irq >= AMI_IRQS) {
+		printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
+		return;
+	}
 
-    /* setup data correctly */
-    if (irq == IRQ_AMIGA_PORTS)
-	    datap = &ciadata[0];
-    else
-	    datap = &ciadata[1];
+	if (--ami_ablecount[irq])
+		return;
 
-    cia_ints = datap->ciaptr->icr;
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAB)) {
+		cia_able_irq(&ciab_base, 1 << (irq - IRQ_IDX(IRQ_AMIGA_CIAB)));
+		return;
+	}
 
-    /* if timer A interrupt */
-    if (cia_ints & CIA_ICR_TA)
-	call_isr_list (IRQ_AMIGA_CIAA_TA,
-		       ami_lists[CIA_IRQ_IDX(IRQ_AMIGA_CIAA_TA)], fp);
+	if (irq >= IRQ_IDX(IRQ_AMIGA_CIAA)) {
+		cia_able_irq(&ciaa_base, 1 << (irq - IRQ_IDX(IRQ_AMIGA_CIAA)));
+		return;
+	}
 
-    /* if timer B interrupt */
-    if (cia_ints & CIA_ICR_TB)
-	call_isr_list (IRQ_AMIGA_CIAA_TB,
-		       ami_lists[CIA_IRQ_IDX(IRQ_AMIGA_CIAA_TB)], fp);
+	/* disable the interrupt */
+	custom.intena = ami_intena_vals[irq];
+}
 
-    /* if the alarm interrupt */
-    if (cia_ints & CIA_ICR_ALRM)
-	call_isr_list (IRQ_AMIGA_CIAA_ALRM,
-		       ami_lists[CIA_IRQ_IDX(IRQ_AMIGA_CIAA_ALRM)], fp);
+inline void amiga_do_irq(int irq, struct pt_regs *fp)
+{
+	kstat.interrupts[SYS_IRQS + irq]++;
+	ami_irq_list[irq]->handler(irq | IRQ_MACHSPEC, ami_irq_list[irq]->dev_id, fp);
+}
 
-    /* if serial port interrupt (keyboard) */
-    if (cia_ints & CIA_ICR_SP)
-	call_isr_list (IRQ_AMIGA_CIAA_SP,
-		       ami_lists[CIA_IRQ_IDX(IRQ_AMIGA_CIAA_SP)], fp);
+void amiga_do_irq_list(int irq, struct pt_regs *fp, struct irq_server *server)
+{
+	irq_node_t *node, *slow_nodes;
+	int mach_irq = irq | IRQ_MACHSPEC;
+	unsigned short flags;
 
-    /* if flag interrupt (parallel port) */
-    if (cia_ints & CIA_ICR_FLG)
-	call_isr_list (IRQ_AMIGA_CIAA_FLG,
-		       ami_lists[CIA_IRQ_IDX(IRQ_AMIGA_CIAA_FLG)], fp);
+	kstat.interrupts[SYS_IRQS + irq]++;
+	if (server->count++)
+		server->reentrance = 1;
+	/* serve first fast and normal handlers */
+	for (node = ami_irq_list[irq];
+	     node && (!(node->flags & IRQ_FLG_SLOW));
+	     node = node->next)
+		node->handler(mach_irq, node->dev_id, fp);
+	custom.intreq = ami_intena_vals[irq];
+	if (!node) {
+		server->count--;
+		return;
+	}
+	save_flags(flags);
+	restore_flags((flags & ~0x0700) | (fp->sr & 0x0700));
+	/* if slow handlers exists, serve them now */
+	slow_nodes = node;
+	for (;;) {
+		for (; node; node = node->next)
+			node->handler(mach_irq, node->dev_id, fp);
+		/* if reentrance occured, serve slow handlers again */
+		custom.intena = ami_intena_vals[irq];
+		if (!server->reentrance) {
+			server->count--;
+			custom.intena = IF_SETCLR | ami_intena_vals[irq];
+			return;
+		}
+		server->reentrance = 0;
+		custom.intena = IF_SETCLR | ami_intena_vals[irq];
+		node = slow_nodes;
+	}
 }
 
 /*
- * amiga_add_isr : add an interrupt service routine for a particular
- *		   machine specific interrupt source.
- *		   If the addition was successful, it returns 1, otherwise
- *		   it returns 0.  It will fail if another routine is already
- *		   bound into the specified source.
- *   Note that the "pri" argument is currently unused.
+ * The builtin Amiga hardware interrupt handlers.
  */
 
-int amiga_add_isr (unsigned long source, isrfunc isr, int pri, void
-		   *data, char *name)
+static void ami_int1(int irq, void *dev_id, struct pt_regs *fp)
 {
-    unsigned long amiga_source = source & ~IRQ_MACHSPEC;
-    isr_node_t *p;
-
-    if (amiga_source > NUM_AMIGA_SOURCES) {
-	printk ("amiga_add_isr: Unknown interrupt source %ld\n", source);
-	return 0;
-    }
-
-    p = new_isr_node();
-    if (p == NULL)
-	return 0;
-    p->isr = isr;
-    p->pri = pri;
-    p->data = data;
-    p->name = name;
-    p->next = NULL;
-    insert_isr (&ami_lists[amiga_source], p);
-
-    /* enable the interrupt */
-    custom.intena = IF_SETCLR | ami_intena_vals[amiga_source];
+	unsigned short ints = custom.intreqr & custom.intenar;
 
-    /* if a CIAA interrupt, enable the appropriate CIA ICR bit */
-    if (source >= IRQ_AMIGA_CIAA_TA && source <= IRQ_AMIGA_CIAA_FLG)
-	ciaa.icr = 0x80 | (1 << (source - IRQ_AMIGA_CIAA_TA));
+	/* if serial transmit buffer empty, interrupt */
+	if (ints & IF_TBE) {
+		custom.intreq = IF_TBE;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_TBE), fp);
+	}
 
-    /* if a CIAB interrupt, enable the appropriate CIA ICR bit */
-    if (source >= IRQ_AMIGA_CIAB_TA && source <= IRQ_AMIGA_CIAB_FLG)
-	ciab.icr = 0x80 | (1 << (source - IRQ_AMIGA_CIAB_TA));
+	/* if floppy disk transfer complete, interrupt */
+	if (ints & IF_DSKBLK) {
+		custom.intreq = IF_DSKBLK;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_DSKBLK), fp);
+	}
 
-    return 1;
+	/* if software interrupt set, interrupt */
+	if (ints & IF_SOFT) {
+		custom.intreq = IF_SOFT;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_SOFT), fp);
+	}
 }
 
-int amiga_remove_isr (unsigned long source, isrfunc isr, void *data)
+static void ami_int3(int irq, void *dev_id, struct pt_regs *fp)
 {
-    unsigned long amiga_source = source & ~IRQ_MACHSPEC;
-
-    if (amiga_source > NUM_AMIGA_SOURCES) {
-	printk ("amiga_remove_isr: Unknown interrupt source %ld\n", source);
-	return 0;
-    }
-
-    delete_isr (&ami_lists[amiga_source], isr, data);
+	unsigned short ints = custom.intreqr & custom.intenar;
+	static struct irq_server server = {0, 0};
 
-    if (ami_lists[amiga_source] == NULL) {
-	/* disable the interrupt */
-	custom.intena = ami_intena_vals[amiga_source];
+	/* if a blitter interrupt */
+	if (ints & IF_BLIT) {
+		custom.intreq = IF_BLIT;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_BLIT), fp);
+	}
 
-	/* if a CIAA interrupt, disable the appropriate CIA ICR bit */
-	if (source >= IRQ_AMIGA_CIAA_TA && source <= IRQ_AMIGA_CIAA_FLG)
-	    ciaa.icr = 1 << (source - IRQ_AMIGA_CIAA_TA);
-
-	/* if a CIAB interrupt, disable the appropriate CIA ICR bit */
-	if (source >= IRQ_AMIGA_CIAB_TA && source <= IRQ_AMIGA_CIAB_FLG)
-	    ciab.icr = 1 << (source - IRQ_AMIGA_CIAB_TA);
-    }
+	/* if a copper interrupt */
+	if (ints & IF_COPER) {
+		custom.intreq = IF_COPER;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_COPPER), fp);
+	}
 
-    return 1;
+	/* if a vertical blank interrupt */
+	if (ints & IF_VERTB)
+		amiga_do_irq_list(IRQ_IDX(IRQ_AMIGA_VERTB), fp, &server);
 }
 
-
-/*
- * Enable/disable a particular machine specific interrupt source.
- * Note that this may affect other interrupts in case of a shared interrupt.
- */
-
-void amiga_enable_irq(unsigned int source)
+static void ami_int4(int irq, void *dev_id, struct pt_regs *fp)
 {
-    unsigned long amiga_source = source & ~IRQ_MACHSPEC;
+	unsigned short ints = custom.intreqr & custom.intenar;
 
-    if (amiga_source > NUM_AMIGA_SOURCES) {
-	printk("amiga_enable_irq: Unknown interrupt source %d\n", source);
-	return;
-    }
-
-    /* enable the interrupt */
-    custom.intena = IF_SETCLR | ami_intena_vals[amiga_source];
+	/* if audio 0 interrupt */
+	if (ints & IF_AUD0) {
+		custom.intreq = IF_AUD0;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_AUD0), fp);
+	}
 
-    /* if a CIAA interrupt, enable the appropriate CIA ICR bit */
-    if (source >= IRQ_AMIGA_CIAA_TA && source <= IRQ_AMIGA_CIAA_FLG)
-	ciaa.icr = 0x80 | (1 << (source - IRQ_AMIGA_CIAA_TA));
+	/* if audio 1 interrupt */
+	if (ints & IF_AUD1) {
+		custom.intreq = IF_AUD1;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_AUD1), fp);
+	}
 
-    /* if a CIAB interrupt, enable the appropriate CIA ICR bit */
-    if (source >= IRQ_AMIGA_CIAB_TA && source <= IRQ_AMIGA_CIAB_FLG)
-	ciab.icr = 0x80 | (1 << (source - IRQ_AMIGA_CIAB_TA));
+	/* if audio 2 interrupt */
+	if (ints & IF_AUD2) {
+		custom.intreq = IF_AUD2;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_AUD2), fp);
+	}
 
+	/* if audio 3 interrupt */
+	if (ints & IF_AUD3) {
+		custom.intreq = IF_AUD3;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_AUD3), fp);
+	}
 }
 
-void amiga_disable_irq(unsigned int source)
+static void ami_int5(int irq, void *dev_id, struct pt_regs *fp)
 {
-    unsigned long amiga_source = source & ~IRQ_MACHSPEC;
-
-    if (amiga_source > NUM_AMIGA_SOURCES) {
-	printk("amiga_disable_irq: Unknown interrupt source %d\n", source);
-	return;
-    }
+	unsigned short ints = custom.intreqr & custom.intenar;
 
-    /* disable the interrupt */
-    custom.intena = ami_intena_vals[amiga_source];
-
-    /* if a CIAA interrupt, disable the appropriate CIA ICR bit */
-    if (source >= IRQ_AMIGA_CIAA_TA && source <= IRQ_AMIGA_CIAA_FLG)
-	ciaa.icr = 1 << (source - IRQ_AMIGA_CIAA_TA);
+	/* if serial receive buffer full interrupt */
+	if (ints & IF_RBF) {
+		/* acknowledge of IF_RBF must be done by the serial interrupt */
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_RBF), fp);
+	}
 
-    /* if a CIAB interrupt, disable the appropriate CIA ICR bit */
-    if (source >= IRQ_AMIGA_CIAB_TA && source <= IRQ_AMIGA_CIAB_FLG)
-	ciab.icr = 1 << (source - IRQ_AMIGA_CIAB_TA);
+	/* if a disk sync interrupt */
+	if (ints & IF_DSKSYN) {
+		custom.intreq = IF_DSKSYN;
+		amiga_do_irq(IRQ_IDX(IRQ_AMIGA_DSKSYN), fp);
+	}
+}
 
+static void ami_int7(int irq, void *dev_id, struct pt_regs *fp)
+{
+	panic ("level 7 interrupt received\n");
 }
 
+void (*amiga_default_handler[SYS_IRQS])(int, void *, struct pt_regs *) = {
+	ami_badint, ami_int1, ami_badint, ami_int3,
+	ami_int4, ami_int5, ami_badint, ami_int7
+};
 
-int amiga_get_irq_list( char *buf, int len )
-{	int			i;
-    isr_node_t	*p;
+int amiga_get_irq_list(char *buf)
+{
+	int i, len = 0;
+	irq_node_t *node;
 
-	for( i = 0; i < NUM_AMIGA_SOURCES; ++i ) {
-		if (!ami_lists[i])
+	for (i = 0; i < AMI_STD_IRQS; i++) {
+		if (!(node = ami_irq_list[i]))
 			continue;
-		len += sprintf( buf+len, "ami  %2d: ???????? ", i );
-		for( p = ami_lists[i]; p; p = p->next ) {
-			len += sprintf( buf+len, "%s\n", p->name );
-			if (p->next)
-				len += sprintf( buf+len, "                  " );
-		}
+		if (node->flags & IRQ_FLG_STD)
+			continue;
+		len += sprintf(buf+len, "ami  %2d: %10u ", i,
+		               kstat.interrupts[SYS_IRQS + i]);
+		do {
+			if (ami_servers[i]) {
+				if (node->flags & IRQ_FLG_FAST)
+					len += sprintf(buf+len, "F ");
+				else if (node->flags & IRQ_FLG_SLOW)
+					len += sprintf(buf+len, "S ");
+				else
+					len += sprintf(buf+len, "  ");
+			} else {
+				if (node->flags & IRQ_FLG_LOCK)
+					len += sprintf(buf+len, "L ");
+				else
+					len += sprintf(buf+len, "  ");
+			}
+			len += sprintf(buf+len, "%s\n", node->devname);
+			if ((node = node->next))
+				len += sprintf(buf+len, "                    ");
+		} while (node);
 	}
-	
-	return( len );
+
+	len += cia_get_irq_list(&ciaa_base, buf+len);
+	len += cia_get_irq_list(&ciab_base, buf+len);
+	return len;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov