Resent-Date: Tue, 5 Jan 1999 16:37:28 +0100 (MET)
Date: Tue, 5 Jan 1999 15:36:59 +0000
From: Richard Hirst <richard@sleepie.demon.co.uk>
To: Jes Sorensen <Jes.Sorensen@cern.ch>
Cc: linux-m68k@lists.linux-m68k.org
Subject: O_SYNC option for /dev/mem
Resent-From: linux-m68k@phil.uni-sb.de

Hi Jes,
  I sent a patch for 2.1.131 to add O_SYNC as an open() option to
/dev/mem, to replace the old /dev/memnc.  It didn't make it to the list
due to holidays, etc, but I think you should have got it.  Now 2.2 is
out, is it worth sending it against that, or is this a new feature which
should wait for 2.3?

Richard.


--- linux68k-2.1.131/drivers/char/mem.c	Sun Dec 20 21:34:27 1998
+++ linuxvme-2.1.131/drivers/char/mem.c	Sat Dec 26 08:38:01 1998
@@ -157,6 +157,34 @@
 	if (offset >= __pa(high_memory))
 		pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
 #endif
+	/* If O_SYNC, then make this a non-cached memory area */
+	if (file->f_flags & O_SYNC) {
+#if defined(__mc68000__)
+		if (CPU_IS_020_OR_030)
+			pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE030;
+		if (CPU_IS_040_OR_060) {
+			pgprot_val(vma->vm_page_prot) &= _CACHEMASK040;
+			/* Use no-cache mode, serialized */
+			pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE_S;
+		}
+#elif defined(__powerpc__)
+		pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
+#elif defined(__i386__)
+		if (boot_cpu_data.x86 > 3)
+			pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
+#elif defined(__mips__)
+		pgprot_val(vma->vm_page_prot) &= ~_CACHE_MASK;
+		pgprot_val(vma->vm_page_prot) |= _CACHE_UNCACHED;
+#else
+		printk(KERN_ALERT "/dev/mem: O_SYNC access unsupported\n");
+#endif
+		/*
+		 * Set VM_IO, as this is likely a non-cached access to an
+		 * I/O area, and we don't want to include that in a core
+		 * file.
+		 */
+		vma->vm_flags |= VM_IO;
+	}
 	if (remap_page_range(vma->vm_start, offset, vma->vm_end-vma->vm_start,
 			     vma->vm_page_prot))
 		return -EAGAIN;

