Date: Mon, 13 Jul 1998 10:03:36 +0100
From: Jesper Skov <jskov@cygnus.co.uk>
To: linux-m68k@lists.linux-m68k.org
Subject: L68K: 2.1.108 APUS patches
Sender: owner-linux-m68k@phil.uni-sb.de

diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.108/arch/m68k/amiga/amiints.c ./arch/m68k/amiga/amiints.c
--- /home/jskov/kernel/dist/linux-2.1.108/arch/m68k/amiga/amiints.c	Sat Jan 24 19:09:30 1998
+++ ./arch/m68k/amiga/amiints.c	Sat Jul 11 19:18:03 1998
@@ -33,6 +33,10 @@
 #include <asm/amigahw.h>
 #include <asm/amigaints.h>
 
+#ifdef CONFIG_APUS
+#include <asm/amigappc.h>
+#endif
+
 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);
@@ -89,9 +93,16 @@
 	for (i = 0; i < AMI_IRQS; i++)
 		ami_ablecount[i] = 0;
 
-	/* turn off all interrupts and enable the master interrupt bit */
+	/* turn off all interrupts... */
 	custom.intena = 0x7fff;
 	custom.intreq = 0x7fff;
+
+#ifdef CONFIG_APUS
+	APUS_WRITE(APUS_REG_INT, REGINT_INTMASTER | REGINT_ENABLEIPL);
+	APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT);
+	APUS_WRITE(APUS_IPL_EMU, IPLEMU_SETRESET | IPLEMU_IPLMASK);
+#endif
+	/* ... and enable the master interrupt bit */
 	custom.intena = IF_SETCLR | IF_INTEN;
 
 	cia_init_IRQ(&ciaa_base);
@@ -353,8 +364,16 @@
 		server->count--;
 		return;
 	}
+#ifdef CONFIG_APUS
+	APUS_WRITE(APUS_IPL_EMU, IPLEMU_SETRESET | IPLEMU_DISABLEINT);
+	APUS_WRITE(APUS_IPL_EMU, IPLEMU_IPLMASK);
+	APUS_WRITE(APUS_IPL_EMU, (IPLEMU_SETRESET
+				  | (~(fp->mq) & IPLEMU_IPLMASK)));
+	APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT);
+#else
 	save_flags(flags);
 	restore_flags((flags & ~0x0700) | (fp->sr & 0x0700));
+#endif
 	/* if slow handlers exists, serve them now */
 	slow_nodes = node;
 	for (;;) {
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.108/arch/m68k/amiga/config.c ./arch/m68k/amiga/config.c
--- /home/jskov/kernel/dist/linux-2.1.108/arch/m68k/amiga/config.c	Thu Jul  9 09:40:23 1998
+++ ./arch/m68k/amiga/config.c	Sat Jul 11 19:18:03 1998
@@ -343,10 +343,12 @@
   mach_kbdrate         = amiga_kbdrate;
   mach_init_IRQ        = amiga_init_IRQ;
   mach_default_handler = &amiga_default_handler;
+#ifndef CONFIG_APUS
   mach_request_irq     = amiga_request_irq;
   mach_free_irq        = amiga_free_irq;
   enable_irq           = amiga_enable_irq;
   disable_irq          = amiga_disable_irq;
+#endif
   mach_get_model       = amiga_get_model;
   mach_get_hardware_list = amiga_get_hardware_list;
   mach_get_irq_list    = amiga_get_irq_list;
@@ -687,6 +689,7 @@
 
 static void amiga_reset (void)
 {
+#ifdef __mc68000__
   unsigned long jmp_addr040 = VTOP(&&jmp_addr_label040);
   unsigned long jmp_addr = VTOP(&&jmp_addr_label);
 
@@ -744,9 +747,9 @@
      "1:\n\t"
      "reset\n\t"
      "jmp   %/a0@" : /* Just that gcc scans it for % escapes */ );
+#endif  
   
   for (;;);
-
 }
 
 
@@ -789,9 +792,17 @@
 
 static void amiga_serial_putc(char c)
 {
-    custom.serdat = (unsigned char)c | 0x100;
-    while (!(custom.serdatr & 0x2000))
-	;
+	custom.serdat = (unsigned char)c | 0x100;
+
+#ifdef CONFIG_APUS
+	/* I'm sure this should not be necessary since the address is
+	   marked non-cachable and coherent. Still, without it the
+	   serial output is not usable. -jskov */
+	eieio ();
+#endif
+
+	while (!(custom.serdatr & 0x2000))
+		;
 }
 
 void amiga_serial_console_write(struct console *co, const char *s,
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.108/include/asm-m68k/ide.h ./include/asm-m68k/ide.h
--- /home/jskov/kernel/dist/linux-2.1.108/include/asm-m68k/ide.h	Mon Jun  8 17:57:15 1998
+++ ./include/asm-m68k/ide.h	Sat Jul 11 20:54:57 1998
@@ -134,6 +134,7 @@
 #undef HD_DATA
 #define HD_DATA NULL
 
+#ifndef CONFIG_APUS
 #define insl(data_reg, buffer, wcount) insw(data_reg, buffer, (wcount)<<1)
 #define outsl(data_reg, buffer, wcount) outsw(data_reg, buffer, (wcount)<<1)
 
@@ -214,6 +215,7 @@
 		: "a" (_port), "0" (_buf),		\
 		  "1" (_tmp));				\
 })
+#endif /* !CONFIG_APUS */
 
 #ifdef CONFIG_ATARI
 #define insl_swapw(data_reg, buffer, wcount) \
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.108/drivers/char/amiga_ser.c ./drivers/char/amiga_ser.c
--- /home/jskov/kernel/dist/linux-2.1.108/drivers/char/amiga_ser.c	Thu Jun 18 13:07:15 1998
+++ ./drivers/char/amiga_ser.c	Sat Jul 11 19:31:29 1998
@@ -454,6 +454,31 @@
        return (custom.serdatr & SDR_TSRE);
 }
 
+#ifdef CONFIG_KGDB
+int amiga_ser_out( unsigned char c )
+
+{
+	custom.serdat = c | 0x100;
+	while (!(custom.serdatr & 0x2000))
+		barrier();
+	return( 1 );
+}
+
+unsigned char amiga_ser_in( void )
+
+{
+	unsigned char c;
+	
+	/* XXX: is that ok?? derived from amiga_ser.c... */
+	while( !(custom.intreqr & IF_RBF) )
+		barrier();
+	c = custom.serdatr;
+	/* clear the interrupt, so that another character can be read */
+	custom.intreq = IF_RBF;
+	return( 0 );
+}
+#endif
+
 #ifdef MODULE
 int init_module(void)
 {
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.108/include/linux/serial.h ./include/linux/serial.h
--- /home/jskov/kernel/dist/linux-2.1.108/include/linux/serial.h	Wed Apr 29 17:45:25 1998
+++ ./include/linux/serial.h	Sat Jul 11 19:41:00 1998
@@ -10,7 +10,7 @@
 #ifndef _LINUX_SERIAL_H
 #define _LINUX_SERIAL_H
 
-#ifdef __mc68000__
+#if defined(__mc68000__) || defined(CONFIG_APUS)
 #include <asm/serial.h>
 #else
 
