From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
Date: Wed, 19 Feb 97 12:46:44 +0100
To: linux-m68k@phil.uni-sb.de
Subject: L68K: Linux 2.1.26
X-Yow: YOW!!  Now I understand advanced MICROBIOLOGY
 and th' new TAX REFORM laws!!
Sender: owner-linux-m68k@phil.uni-sb.de
Reply-To: schwab@issan.informatik.uni-dortmund.de

Hi!

As usual, here are my patches :-)

- arch/m68k/atari/joystick.c: *really* do the select->poll transition
- arch/m68k/boot/atari/bootstrap.c: better checking of available space for
  ramdisk
- arch/m68k/kernel/m68k_ksyms.c: add missing symbol
- arch/m68k/kernel/sys_m68k.c: fix error checking (copy_from_user does not
  return an error code)
- arch/m68k/lib/semaphore.S, include/asm-m68k/semaphore.h: fix
  down_interruptible, return value is in %d0
- drivers/char/atarimouse.c: modernize
- include/asm-m68k/pgtable.h: fix ATC flushing on 68030/68851: no need to
  mess mit sfc/dfc, instead use proper fc,mask combination
- include/asm-m68k/poll.h: remove nasty i-word from comment :-) and make
  it compatible with Linux/Sparc *and* GNU libc (what is iBCS anyway?)
- kernel/module.c: add missing cache flush
- drivers/block/acsi.c, drivers/net/atari_bionet.c,
  drivers/net/atari_pamsnet.c: modernize and fix module support (i didn't
  even try to compile them, but at least i did think about them)

Andreas.

----------------------------------------------------------------------
--- arch/m68k/atari/joystick.c.~1~	Wed Oct 30 17:45:53 1996
+++ arch/m68k/atari/joystick.c	Mon Feb  3 20:41:14 1997
@@ -10,6 +10,7 @@
 #include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/major.h>
+#include <linux/poll.h>
 
 #include <asm/atarikb.h>
 #include <asm/atari_joystick.h>
@@ -89,30 +90,28 @@
 			  char *buffer, unsigned long count)
 {
     int minor = DEVICE_NR(inode->i_rdev);
-    int i;
 
     if (count < 2)
 	return -EINVAL;
     if (!joystick[minor].ready)
 	return -EAGAIN;
-    put_user(joystick[minor].fire, buffer++);
-    put_user(joystick[minor].dir, buffer++);
-    for (i = 0; i < count; i++)
-	put_user(0, buffer++);
     joystick[minor].ready = 0;
-
-    return i;
+    if (put_user(joystick[minor].fire, buffer++) ||
+	put_user(joystick[minor].dir, buffer++))
+	return -EFAULT;
+    if (count > 2)
+	if (clear_user(buffer, count - 2))
+	    return -EFAULT;
+    return count;
 }
 
-static int joystick_select(struct inode *inode, struct file *file, int sel_type, select_table *wait)
+static unsigned int joystick_poll(struct file *file, poll_table *wait)
 {
-    int minor = DEVICE_NR(inode->i_rdev);
+    int minor = DEVICE_NR(file->f_inode->i_rdev);
 
-    if (sel_type != SEL_IN)
-	return 0;
+    poll_wait(&joystick[minor].wait, wait);
     if (joystick[minor].ready)
-	return 1;
-    select_wait(&joystick[minor].wait, wait);
+	return POLLIN | POLLRDNORM;
     return 0;
 }
 
@@ -121,7 +120,7 @@
 	read_joystick,
 	write_joystick,
 	NULL,		/* joystick_readdir */
-	joystick_select,
+	joystick_poll,
 	NULL,		/* joystick_ioctl */
 	NULL,		/* joystick_mmap */
 	open_joystick,
--- arch/m68k/boot/atari/bootstrap.c.~1~	Mon Feb 17 17:33:02 1997
+++ arch/m68k/boot/atari/bootstrap.c	Mon Feb 17 18:59:40 1997
@@ -883,18 +883,6 @@
     }
     else
 	bi.ramdisk.size = 0;
-
-    rd_size = bi.ramdisk.size;
-    if (mem_size - rd_size < MB && bi.num_memory > 1)
-      /* If running low on ST ram load ramdisk into alternate ram.  */
-      bi.ramdisk.addr = (u_long) bi.memory[1].addr + bi.memory[1].size - rd_size;
-    else
-      /* Else hopefully there is enough ST ram. */
-      bi.ramdisk.addr = (u_long)start_mem + mem_size - rd_size;
-
-    /* create the bootinfo structure */
-    if (!create_bootinfo())
-	boot_exit (EXIT_FAILURE);
  
     /* calculate the total required amount of memory */
     if (elf_kernel)
@@ -921,6 +909,19 @@
       }
     else
       kernel_size = kexec.a_text + kexec.a_data + kexec.a_bss;
+
+    rd_size = bi.ramdisk.size;
+    if (rd_size + kernel_size > mem_size - MB/2 && bi.num_memory > 1)
+      /* If running low on ST ram load ramdisk into alternate ram.  */
+      bi.ramdisk.addr = (u_long) bi.memory[1].addr + bi.memory[1].size - rd_size;
+    else
+      /* Else hopefully there is enough ST ram. */
+      bi.ramdisk.addr = (u_long)start_mem + mem_size - rd_size;
+
+    /* create the bootinfo structure */
+    if (!create_bootinfo())
+	boot_exit (EXIT_FAILURE);
+
     memreq = kernel_size + bi_size;
 #ifdef BOOTINFO_COMPAT_1_0
     if (sizeof(compat_bootinfo) > bi_size)
--- arch/m68k/kernel/m68k_ksyms.c.~1~	Mon Feb 17 17:33:09 1997
+++ arch/m68k/kernel/m68k_ksyms.c	Sun Jan 26 20:50:26 1997
@@ -47,4 +47,5 @@
 EXPORT_SYMBOL_NOVERS(memset);
 
 EXPORT_SYMBOL_NOVERS(__down_failed);
+EXPORT_SYMBOL_NOVERS(__down_failed_interruptible);
 EXPORT_SYMBOL_NOVERS(__up_wakeup);
--- arch/m68k/kernel/sys_m68k.c.~1~	Mon Feb 17 17:33:11 1997
+++ arch/m68k/kernel/sys_m68k.c	Mon Feb 17 19:39:34 1997
@@ -66,7 +66,8 @@
 	struct mmap_arg_struct a;
 
 	lock_kernel();
-	if ((error = copy_from_user(&a, arg, sizeof(a))))
+	error = -EFAULT;
+	if (copy_from_user(&a, arg, sizeof(a)))
 		goto out;
 
 	if (!(a.flags & MAP_ANONYMOUS)) {
@@ -197,8 +198,7 @@
 			ret = -EINVAL;
 			goto out;
 		}
-	else
-		ret = -EINVAL;
+	ret = -EINVAL;
 out:
 	unlock_kernel();
 	return ret;
--- arch/m68k/lib/semaphore.S.~1~	Mon Feb 17 17:33:13 1997
+++ arch/m68k/lib/semaphore.S	Mon Feb 17 19:08:32 1997
@@ -9,8 +9,10 @@
 #include <linux/linkage.h>
 
 /*
- * "down_failed" is called with the eventual return address
- * in %a0, and the address of the semaphore in %a1.
+ * The semaphore operations have a special calling sequence that
+ * allow us to do a simpler in-line version of them. These routines
+ * need to convert that sequence back into the C sequence when
+ * there is contention on the semaphore.
  */
 ENTRY(__down_failed)
 	moveml %a0/%d0/%d1,-(%sp)
@@ -22,11 +24,11 @@
 	rts
 
 ENTRY(__down_failed_interruptible)
-	moveml %a0/%d0/%d1,-(%sp)
+	movel %a0,-(%sp)
+	movel %d1,-(%sp)
 	movel %a1,-(%sp)
 	jbsr SYMBOL_NAME(__down_interruptible)
 	movel (%sp)+,%a1
-	movel (%sp)+,%d0
 	movel (%sp)+,%d1
 	rts
 
--- drivers/block/acsi.c.~1~	Mon Feb 17 17:34:09 1997
+++ drivers/block/acsi.c	Mon Feb 17 20:13:06 1997
@@ -1626,22 +1626,22 @@
 	return DEV_SUPPORTED;
 }
 
-	EXPORT_SYMBOL(acsi_delay_start),
-	EXPORT_SYMBOL(acsi_delay_end),
-	EXPORT_SYMBOL(acsi_wait_for_IRQ),
-	EXPORT_SYMBOL(acsi_wait_for_noIRQ),
-	EXPORT_SYMBOL(acsicmd_nodma),
-	EXPORT_SYMBOL(acsi_getstatus),
-	EXPORT_SYMBOL(acsi_buffer),
-	EXPORT_SYMBOL(phys_acsi_buffer),
+EXPORT_SYMBOL(acsi_delay_start);
+EXPORT_SYMBOL(acsi_delay_end);
+EXPORT_SYMBOL(acsi_wait_for_IRQ);
+EXPORT_SYMBOL(acsi_wait_for_noIRQ);
+EXPORT_SYMBOL(acsicmd_nodma);
+EXPORT_SYMBOL(acsi_getstatus);
+EXPORT_SYMBOL(acsi_buffer);
+EXPORT_SYMBOL(phys_acsi_buffer);
 
 #ifdef CONFIG_ATARI_SLM_MODULE
 void acsi_attach_SLMs( int (*attach_func)( int, int ) );
 
-	EXPORT_SYMBOL(acsi_extstatus),
-	EXPORT_SYMBOL(acsi_end_extstatus),
-	EXPORT_SYMBOL(acsi_extcmd),
-	EXPORT_SYMBOL(acsi_attach_SLMs),
+EXPORT_SYMBOL(acsi_extstatus);
+EXPORT_SYMBOL(acsi_end_extstatus);
+EXPORT_SYMBOL(acsi_extcmd);
+EXPORT_SYMBOL(acsi_attach_SLMs);
 
 /* to remember IDs of SLM devices, SLM module is loaded later
  * (index is target#, contents is lun#, -1 means "no SLM") */
--- drivers/char/atarimouse.c.~1~	Mon Feb 17 17:34:40 1997
+++ drivers/char/atarimouse.c	Mon Feb 17 19:10:54 1997
@@ -99,12 +99,9 @@
 		       char *buffer, unsigned long count)
 {
     int dx, dy, buttons;
-    int r;
 
     if (count < 3)
 	return -EINVAL;
-    if ((r = verify_area(VERIFY_WRITE, buffer, count)))
-	return r;
     if (!mouse.ready)
 	return -EAGAIN;
     /* ikbd_mouse_disable */
@@ -124,12 +121,14 @@
     if (mouse.dx == 0 && mouse.dy == 0)
       mouse.ready = 0;
     /* ikbd_mouse_rel_pos(); */
-    put_user(buttons | 0x80, buffer);
-    put_user((char) dx, buffer + 1);
-    put_user((char) dy, buffer + 2);
-    for (r = 3; r < count; r++)
-      put_user (0, buffer + r);
-    return r;
+    if (put_user(buttons | 0x80, buffer++) ||
+	put_user((char) dx, buffer++) ||
+	put_user((char) dy, buffer++))
+	return -EFAULT;
+    if (count > 3)
+	if (clear_user(buffer, count - 3))
+	    return -EFAULT;
+    return count;
 }
 
 static unsigned int mouse_poll(struct file *file, poll_table *wait)
--- drivers/net/atari_bionet.c.~1~	Mon Feb 17 17:35:15 1997
+++ drivers/net/atari_bionet.c	Mon Feb 17 20:07:33 1997
@@ -80,12 +80,7 @@
 static char *version =
 	"bionet.c:v1.0 06-feb-96 (c) Hartmut Laue.\n";
 
-#ifdef MODULE
 #include <linux/module.h>
-#else
-#define MOD_INC_USE_COUNT
-#define MOD_DEC_USE_COUNT
-#endif
 
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -603,21 +598,12 @@
 
 #ifdef MODULE
 
-#include <linux/version.h>
-
-/* We should include the kernel identification string in the module.
- */
-static char kernel_version[] = UTS_RELEASE;
-
-#undef	NEXT_DEV
-#define NEXT_DEV	(&bio_dev)
-
 static struct device bio_dev =
 	{
 		"        ",	/* filled in by register_netdev() */
 		0, 0, 0, 0,	/* memory */
 		0, 0,		/* base, irq */
-		0, 0, 0, NEXT_DEV, bionet_probe,
+		0, 0, 0, NULL, bionet_probe,
 	};
 
 int
--- drivers/net/atari_pamsnet.c.~1~	Mon Feb 17 17:35:15 1997
+++ drivers/net/atari_pamsnet.c	Mon Feb 17 20:08:30 1997
@@ -77,12 +77,7 @@
 static char *version =
 	"pamsnet.c:v0.2beta 30-mar-96 (c) Torsten Lang.\n";
 
-#ifdef MODULE
 #include <linux/module.h>
-#else
-#define MOD_INC_USE_COUNT
-#define MOD_DEC_USE_COUNT
-#endif
 
 #include <linux/kernel.h>
 #include <linux/sched.h>
@@ -875,21 +870,12 @@
 
 #ifdef MODULE
 
-#include <linux/version.h>
-
-/* We should include the kernel identification string in the module.
- */
-static char kernel_version[] = UTS_RELEASE;
-
-#undef	NEXT_DEV
-#define NEXT_DEV	(&pam_dev)
-
 static struct device pam_dev =
 	{
 		"        ",	/* filled in by register_netdev() */
 		0, 0, 0, 0,	/* memory */
 		0, 0,		/* base, irq */
-		0, 0, 0, NEXT_DEV, pamsnet_probe,
+		0, 0, 0, NULL, pamsnet_probe,
 	};
 
 int
--- include/asm-m68k/pgtable.h.~2~	Mon Feb 17 19:24:19 1997
+++ include/asm-m68k/pgtable.h	Tue Feb 18 00:05:20 1997
@@ -195,7 +195,7 @@
 				     ".chip 68k"
 				     : : "a" (addr));
 	} else
-		__asm__ __volatile__("pflush #0,#0,(%0)" : : "a" (addr));
+		__asm__ __volatile__("pflush #0,#4,(%0)" : : "a" (addr));
 }
 
 #define flush_tlb() __flush_tlb()
@@ -235,15 +235,16 @@
 
 extern inline void flush_tlb_kernel_page(unsigned long addr)
 {
-#ifndef CPU_M68020_OR_M68030_ONLY
-	int old_fs = get_fs();
-
-	set_fs(KERNEL_DS);
-#endif
-	__flush_tlb_one(addr);
-#ifndef CPU_M68020_OR_M68030_ONLY
-	set_fs(old_fs);
-#endif
+	if (CPU_IS_040_OR_060) {
+		unsigned long old_fs = get_fs();
+		set_fs(KERNEL_DS);
+		__asm__ __volatile__(".chip 68040\n\t"
+				     "pflush (%0)\n\t"
+				     ".chip 68k"
+				     : : "a" (addr));
+		set_fs(old_fs);
+	} else
+		__asm__ __volatile__("pflush #4,#4,(%0)" : : "a" (addr));
 }
 
 /* Certain architectures need to do special things when pte's
--- include/asm-m68k/poll.h.~1~	Mon Feb 17 17:38:19 1997
+++ include/asm-m68k/poll.h	Tue Jan 28 08:34:27 1997
@@ -1,20 +1,16 @@
 #ifndef __m68k_POLL_H
 #define __m68k_POLL_H
 
-/* These are specified by iBCS2 */
-#define POLLIN		0x0001
-#define POLLPRI		0x0002
-#define POLLOUT		0x0004
-#define POLLERR		0x0008
-#define POLLHUP		0x0010
-#define POLLNVAL	0x0020
-
-/* The rest seem to be more-or-less nonstandard. Check them! */
-#define POLLRDNORM	0x0040
-#define POLLRDBAND	0x0080
-#define POLLWRNORM	0x0100
-#define POLLWRBAND	0x0200
-#define POLLMSG		0x0400
+#define POLLIN		  1
+#define POLLPRI		  2
+#define POLLOUT		  4
+#define POLLERR		  8
+#define POLLHUP		 16
+#define POLLNVAL	 32
+#define POLLRDNORM	 64
+#define POLLWRNORM	POLLOUT
+#define POLLRDBAND	128
+#define POLLWRBAND	256
 
 struct pollfd {
 	int fd;
--- include/asm-m68k/semaphore.h.~1~	Mon Feb 17 17:38:21 1997
+++ include/asm-m68k/semaphore.h	Mon Feb 17 19:32:37 1997
@@ -53,18 +53,18 @@
  */
 extern inline int down_interruptible(struct semaphore * sem)
 {
-	register int ret __asm__ ("%a0");
+	register int ret __asm__ ("%d0");
 	register struct semaphore *sem1 __asm__ ("%a1") = sem;
 	__asm__ __volatile__(
-		"| atomic down operation\n\t"
+		"| atomic interruptible down operation\n\t"
 		"lea %%pc@(1f),%%a0\n\t"
 		"subql #1,%1@\n\t"
 		"jmi " SYMBOL_NAME_STR(__down_failed_interruptible) "\n\t"
-		"subl %%a0,%%a0\n"
+		"clrl %0\n"
 		"1:"
-		: "=a" (ret)
+		: "=d" (ret)
 		: "a" (sem1)
-		: "memory");
+		: "%d0", "%a0", "memory");
 	return ret;
 }
 
--- kernel/module.c.~1~	Mon Feb 17 17:39:13 1997
+++ kernel/module.c	Mon Jan 27 20:35:56 1997
@@ -5,6 +5,7 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/config.h>
+#include <asm/pgtable.h>
 #include <asm/uaccess.h>
 #include <linux/vmalloc.h>
 #include <linux/smp.h>
@@ -295,6 +296,9 @@
 		error = -EFAULT;
 		goto err3;
 	}
+
+	flush_pages_to_ram((unsigned long)mod,
+			   (mod->size + PAGE_SIZE - 1) / PAGE_SIZE);
 
 	/* Update module references.  */
 	mod->next = mod_tmp.next;
