Resent-Date: Thu, 12 Nov 1998 20:40:14 +0100 (MET)
Date: Thu, 12 Nov 1998 19:40:53 GMT
From: Jesper Skov <jskov@cygnus.co.uk>
To: linux-m68k@lists.linux-m68k.org, Jes.Sorensen@cern.ch
Subject: More (APUS) patches
Resent-From: linux-m68k@phil.uni-sb.de

I've been on the reduce-apus/m68k-diff-size-rampage. Here's a few
(APUS related) changes.

Adding iobarrier() allows drivers to be used on both m68k and PPC
without any aditional hackery. Someone with lots of time should go
through the existing Amiga drivers and add iobarrier() calls where the
PPC might otherwise reorder/collapse memory access [that was for you
elitist m68k linux hackers's information only; an APUS hacker should
do the work ;) ]

Jes, I think I've posted the CONFIG_APUS patches before. If you don't
want to include them, please let me know (why ;)

Jesper


o ide.c:       added missing declaration.
o amiga_ser.c: added iobarrier calls for PPC.
o tty_ioctl.c: fixed ambiguous else warning.
o 53c7xx.c:    fixed compiler warnings.
o amiga7xx.c:  fixed compiler warnings. (include setup.h for MACH_IS_AMIGA)
o fastlane.c:  added iobarrier calls for PPC.
o scsi.h:      added CONFIG_APUS condition.
o dmasound.c:  added CONFIG_APUS conditions.
o io.h:        added dummy m68k iobarrier.
o serial.h:    added CONFIG_APUS condition.

diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/block/ide.c ./drivers/block/ide.c
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/block/ide.c	Thu Nov 12 17:33:58 1998
+++ ./drivers/block/ide.c	Thu Nov 12 17:37:51 1998
@@ -2383,6 +2385,8 @@
 
 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
 	if (!strcmp(s, "ide=doubler")) {
+		extern int ide_doubler;
+
 		printk("ide: Enabled support for IDE doublers\n");
 		ide_doubler = 1;
 		return;


diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/char/amiga_ser.c ./drivers/char/amiga_ser.c
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/char/amiga_ser.c	Wed Aug  5 16:01:49 1998
+++ ./drivers/char/amiga_ser.c	Sun Oct  4 20:18:32 1998
@@ -43,6 +42,8 @@
 #include <asm/irq.h>
 #include <asm/atomic.h>
 
+#include <asm/io.h>
+
 /* some serial hardware definitions */
 #define SDR_OVRUN   (1<<15)
 #define SDR_RBF     (1<<14)
@@ -200,9 +201,14 @@
      * set the appropriate directions for the modem control flags,
      * and clear RTS and DTR
      */
-    ciab.ddra |= (SER_DTR | SER_RTS);   /* outputs */
-    ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR);  /* inputs */
-    
+    {
+	    unsigned short v = ciab.ddra;
+	    v |= (SER_DTR | SER_RTS);   /* outputs */
+	    v &= ~(SER_DCD | SER_CTS | SER_DSR);  /* inputs */
+	    iobarrier ();
+	    ciab.ddra = v;
+    }
+
     info->sw   = &amiga_ser_switch;
 
     return 0;
@@ -210,20 +216,24 @@
 
 static void ser_rx_int(int irq, void *data, struct pt_regs *fp)
 {
-      struct m68k_async_struct *info = data;
-      int ch, err;
+      int ch;
 
       ch = custom.serdatr;
+      iobarrier ();
 
-      custom.intreq = IF_RBF;
-
-      if ((ch & 0x1ff) == 0)
-	  err = TTY_BREAK;
-      else if (ch & SDR_OVRUN)
-	  err = TTY_OVERRUN;
-      else
-	  err = 0;
-      rs_receive_char(info, ch & 0xff, err);
+      {
+	      struct m68k_async_struct *info = data;
+	      int err;
+
+	      custom.intreq = IF_RBF;
+	      if ((ch & 0x1ff) == 0)
+		      err = TTY_BREAK;
+	      else if (ch & SDR_OVRUN)
+		      err = TTY_OVERRUN;
+	      else
+		      err = 0;
+	      rs_receive_char(info, ch & 0xff, err);
+      }
 }
 
 static void ser_tx_int( int irq, void *data, struct pt_regs *fp)
@@ -456,9 +495,9 @@
 
 #ifdef CONFIG_KGDB
 int amiga_ser_out( unsigned char c )
-
 {
 	custom.serdat = c | 0x100;
+	iobarrier ();
 	while (!(custom.serdatr & 0x2000))
 		barrier();
 	return( 1 );
@@ -468,30 +507,34 @@
 
 {
 	unsigned char c;
-	
+
 	/* XXX: is that ok?? derived from amiga_ser.c... */
 	while( !(custom.intreqr & IF_RBF) )
 		barrier();
-	c = custom.serdatr;
+
+	iobarrier ();
+	c = (unsigned char) (custom.serdatr & 0x00ff);
+	iobarrier ();
+
 	/* clear the interrupt, so that another character can be read */
 	custom.intreq = IF_RBF;
-	return( 0 );
+	return c;
 }
 #endif
 
 #ifdef MODULE
 int init_module(void)
 {
-return amiga_serinit();
+	return amiga_serinit();
 }
 
 void cleanup_module(void)
 {
-unregister_serial(line);
-custom.intena = IF_RBF | IF_TBE; /* forbid interrupts */
-custom.intreq = IF_RBF | IF_TBE; /* clear pending interrupts */
-free_irq(IRQ_AMIGA_TBE, amiga_info);
-free_irq(IRQ_AMIGA_RBF, amiga_info);
+	unregister_serial(line);
+	custom.intena = IF_RBF | IF_TBE; /* forbid interrupts */
+	custom.intreq = IF_RBF | IF_TBE; /* clear pending interrupts */
+	free_irq(IRQ_AMIGA_TBE, amiga_info);
+	free_irq(IRQ_AMIGA_RBF, amiga_info);
 }
 #endif
 
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/char/tty_ioctl.c ./drivers/char/tty_ioctl.c
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/char/tty_ioctl.c	Thu Nov 12 17:34:00 1998
+++ ./drivers/char/tty_ioctl.c	Thu Nov 12 17:37:55 1998
@@ -210,11 +210,12 @@
 {
 	int flags = 0;
 
-	if (!(tty->termios->c_lflag & ICANON))
+	if (!(tty->termios->c_lflag & ICANON)) {
 		if (tty->termios->c_lflag & ISIG)
 			flags |= 0x02;		/* cbreak */
 		else
 			flags |= 0x20;		/* raw */
+	}
 	if (tty->termios->c_lflag & ECHO)
 		flags |= 0x08;			/* echo */
 	if (tty->termios->c_oflag & OPOST)
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/53c7xx.c ./drivers/scsi/53c7xx.c
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/53c7xx.c	Fri Oct  9 19:36:35 1998
+++ ./drivers/scsi/53c7xx.c	Sun Oct 18 23:04:24 1998
@@ -298,6 +298,10 @@
  */
 #undef inb
 #undef outb
+#undef inw
+#undef outw
+#undef inl
+#undef outl
 #define inb(x)          1
 #define inw(x)          1
 #define inl(x)          1
@@ -1899,7 +1903,7 @@
     if (left < 0) 
 	printk("scsi%d: loop detected in ncr reconncect list\n",
 	    host->host_no);
-    else if (ncr_search) 
+    else if (ncr_search) {
 	if (found)
 	    printk("scsi%d: scsi %ld in ncr issue array and reconnect lists\n",
 		host->host_no, c->pid);
@@ -1910,6 +1914,7 @@
 /* If we're at the tail end of the issue queue, update that pointer too. */
 	    found = 1;
 	}
+    }
 
     /*
      * Traverse the host running list until we find this command or discover
@@ -5947,11 +5952,12 @@
 	    	}
     	    }
 	}
-	if (!(istat & (ISTAT_SIP|ISTAT_DIP))) 
+	if (!(istat & (ISTAT_SIP|ISTAT_DIP))) {
 	    if (stage == 0)
 	    	++stage;
 	    else if (stage == 3)
 		break;
+	}
     }
     hostdata->state = STATE_HALTED;
     restore_flags(flags);
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/amiga7xx.c ./drivers/scsi/amiga7xx.c
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/amiga7xx.c	Sat Aug 29 09:21:34 1998
+++ ./drivers/scsi/amiga7xx.c	Sun Oct 11 09:49:04 1998
@@ -15,6 +15,7 @@
 #include <linux/config.h>
 #include <linux/zorro.h>
 
+#include <asm/setup.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include <asm/amigaints.h>
@@ -33,9 +34,9 @@
     S_IFDIR | S_IRUGO | S_IXUGO, 2
 };
 
-extern ncr53c7xx_init (Scsi_Host_Template *tpnt, int board, int chip, 
-		       u32 base, int io_port, int irq, int dma,
-		       long long options, int clock);
+extern int ncr53c7xx_init (Scsi_Host_Template *tpnt, int board, int chip, 
+			   u32 base, int io_port, int irq, int dma,
+			   long long options, int clock);
 
 int amiga7xx_detect(Scsi_Host_Template *tpnt)
 {
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/fastlane.c ./drivers/scsi/fastlane.c
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/fastlane.c	Thu Nov 12 17:34:08 1998
+++ ./drivers/scsi/fastlane.c	Thu Nov 12 17:38:01 1998
@@ -38,6 +38,7 @@
 
 #include <linux/zorro.h>
 #include <asm/irq.h>
+#include <asm/io.h>		/* iobarrier, virt_to_bus */
 #include <asm/amigaints.h>
 #include <asm/amigahw.h>
 
@@ -163,7 +164,7 @@
 		
 		/* Set the command buffer */
 		esp->esp_command = (volatile unsigned char*) cmd_buffer;
-		esp->esp_command_dvma = virt_to_bus((unsigned long) cmd_buffer);
+		esp->esp_command_dvma = virt_to_bus((void*) cmd_buffer);
 
 		esp->irq = IRQ_AMIGA_PORTS;
 		request_irq(IRQ_AMIGA_PORTS, esp_intr, 0, 
@@ -230,7 +231,9 @@
 	t = (unsigned long *)((addr & 0x00ffffff) + esp->edev);
 
 	dregs->clear_strobe = 0;
+	iobarrier ();
 	*t = addr;
+	iobarrier ();
 
 	ctrl_data = (ctrl_data & FASTLANE_DMA_MASK) | FASTLANE_DMA_ENABLE;
 	dregs->ctrl_reg = ctrl_data;
@@ -249,7 +252,9 @@
 	t = (unsigned long *)((addr & 0x00ffffff) + (esp->edev));
 
 	dregs->clear_strobe = 0;
+	iobarrier ();
 	*t = addr;
+	iobarrier ();
 
 	ctrl_data = ((ctrl_data & FASTLANE_DMA_MASK) | 
 		     FASTLANE_DMA_ENABLE |
@@ -269,7 +274,9 @@
 	t = (unsigned long *)(esp->edev);
 
 	dregs->clear_strobe = 0;
+	iobarrier ();
 	*t = 0 ;
+	iobarrier ();
 }
 
 
@@ -292,6 +299,7 @@
 #ifdef __mc68000__
 	nop();
 #endif
+	iobarrier ();
 	dregs->ctrl_reg = ctrl_data;
 }
 
@@ -305,6 +313,9 @@
 
 	if(dma_status & FASTLANE_DMA_IACT)
 		return 0;	/* not our IRQ */
+
+	iobarrier ();		/* Make sure PPC doesn't touch eregs */
+				/* prematurely. */
 
 	/* Return non-zero if ESP requested IRQ */
 	return (
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/scsi.h ./drivers/scsi/scsi.h
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/scsi/scsi.h	Thu Nov 12 17:34:09 1998
+++ ./drivers/scsi/scsi.h	Thu Nov 12 19:07:36 1998
@@ -319,7 +319,7 @@
 #define ASKED_FOR_SENSE 0x20
 
 
-#ifdef __mc68000__
+#if defined(__mc68000__) || defined(CONFIG_APUS)
 #include <asm/pgtable.h>
 #define CONTIGUOUS_BUFFERS(X,Y) \
 	(virt_to_phys((X)->b_data+(X)->b_size-1)+1==virt_to_phys((Y)->b_data))
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/drivers/sound/dmasound.c ./drivers/sound/dmasound.c
--- /home/jskov/kernel/dist/linux-2.1.127/drivers/sound/dmasound.c	Thu Nov 12 17:34:09 1998
+++ ./drivers/sound/dmasound.c	Thu Nov 12 17:38:02 1998
@@ -90,7 +90,7 @@
 #include <linux/sound.h>
 #include <linux/init.h>
 
-#ifdef __mc68000__
+#if defined(__mc68000__) || defined(CONFIG_APUS)
 #include <asm/setup.h>
 #endif
 #include <asm/system.h>
@@ -4442,7 +4442,7 @@
 	struct device_node *np;
 #endif
 
-#ifdef __mc68000__
+#if defined(__mc68000__) || defined(CONFIG_APUS)
 	switch (m68k_machtype) {
 #ifdef CONFIG_ATARI
 	case MACH_ATARI:
@@ -4470,7 +4470,7 @@
 		break;
 #endif /* CONFIG_AMIGA */
 	}
-#endif /* __mc68000__ */
+#endif /* __mc68000__||CONFIG_APUS */
 
 #ifdef CONFIG_PMAC
 	awacs_subframe = 0;
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/include/asm-m68k/io.h ./include/asm-m68k/io.h
--- /home/jskov/kernel/dist/linux-2.1.127/include/asm-m68k/io.h	Mon Sep  7 21:04:12 1998
+++ ./include/asm-m68k/io.h	Sun Oct  4 10:04:13 1998
@@ -13,6 +13,8 @@
 
 #include <asm/virtconvert.h>
 
+#define iobarrier() do {} while (0)
+
 /*
  * readX/writeX() are used to access memory mapped devices. On some
  * architectures the memory mapped IO stuff needs to be accessed
diff -u --recursive -B --exclude-from=/home/jskov/lib/diff-excludes -P /home/jskov/kernel/dist/linux-2.1.127/include/linux/serial.h ./include/linux/serial.h
--- /home/jskov/kernel/dist/linux-2.1.127/include/linux/serial.h	Thu Nov 12 17:34:19 1998
+++ ./include/linux/serial.h	Thu Nov 12 18:46:31 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
 

