svn commit: r206593 - user/jmallett/octeon/sys/mips/mips

Juli Mallett jmallett at FreeBSD.org
Wed Apr 14 06:47:35 UTC 2010


Author: jmallett
Date: Wed Apr 14 06:47:34 2010
New Revision: 206593
URL: http://svn.freebsd.org/changeset/base/206593

Log:
  Try moving to the PowerPC mem.c, using uiomove_fromphys and pals.  This is
  probably wrong.

Modified:
  user/jmallett/octeon/sys/mips/mips/mem.c

Modified: user/jmallett/octeon/sys/mips/mips/mem.c
==============================================================================
--- user/jmallett/octeon/sys/mips/mips/mem.c	Wed Apr 14 06:46:43 2010	(r206592)
+++ user/jmallett/octeon/sys/mips/mips/mem.c	Wed Apr 14 06:47:34 2010	(r206593)
@@ -1,13 +1,12 @@
-/*	$OpenBSD: mem.c,v 1.2 1998/08/31 17:42:34 millert Exp $ */
-/*	$NetBSD: mem.c,v 1.6 1995/04/10 11:55:03 mycroft Exp $	*/
-/*
+/*-
  * Copyright (c) 1988 University of Utah.
- * Copyright (c) 1982, 1986, 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
- * Science Department and Ralph Campbell.
+ * Science Department, and code derived from software contributed to
+ * Berkeley by William Jolitz.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -33,142 +32,136 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	@(#)mem.c	8.3 (Berkeley) 1/12/94
- *	JNPR: mem.c,v 1.3 2007/08/09 11:23:32 katta Exp $
+ *	from: Utah $Hdr: mem.c 1.13 89/10/08$
+ *	from: @(#)mem.c	7.2 (Berkeley) 5/9/91
  */
 
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
 /*
  * Memory special file
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/param.h>
-#include <sys/kernel.h>
 #include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/memrange.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
 #include <sys/proc.h>
-#include <sys/signalvar.h>
-#include <vm/vm.h>
-#include <vm/vm_extern.h>
-#include <vm/pmap.h>
-#include <vm/vm_map.h>
-#include <sys/user.h>
 #include <sys/msgbuf.h>
 #include <sys/systm.h>
-#include <sys/systm.h>
-#include <sys/buf.h>
+#include <sys/signalvar.h>
 #include <sys/uio.h>
-#include <sys/sched.h>
-#include <sys/malloc.h>
-#include <machine/pte.h>
-#include <machine/cpu.h>
+
 #include <machine/md_var.h>
-#include <machine/atomic.h>
+#include <machine/vmparam.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <vm/vm_extern.h>
+#include <vm/vm_page.h>
+
 #include <machine/memdev.h>
 
-/*ARGSUSED*/
+struct mem_range_softc mem_range_softc;
+
+/* ARGSUSED */
 int
-memrw(dev, uio, flags)
-	struct cdev *dev;
-	struct uio *uio;
-	int flags;
+memrw(struct cdev *dev, struct uio *uio, int flags)
 {
-	register vm_offset_t v;
-	register int c;
-	register struct iovec *iov;
+	struct iovec *iov;
 	int error = 0;
+	vm_offset_t va, eva, off, v;
+	vm_prot_t prot;
+	struct vm_page m;
+	vm_page_t marr;
+	vm_size_t cnt;
+
+	cnt = 0;
+	error = 0;
+
+	GIANT_REQUIRED;
 
-	while (uio->uio_resid > 0 && error == 0) {
+	while (uio->uio_resid > 0 && !error) {
 		iov = uio->uio_iov;
 		if (iov->iov_len == 0) {
 			uio->uio_iov++;
 			uio->uio_iovcnt--;
 			if (uio->uio_iovcnt < 0)
-				panic("mmrw");
+				panic("memrw");
 			continue;
 		}
-
-		/* minor device 0 is physical memory */
 		if (dev2unit(dev) == CDEV_MINOR_MEM) {
 			v = uio->uio_offset;
-			c = iov->iov_len;
 
-#if defined(__mips_n64)
-			vm_offset_t va;
-			vm_paddr_t pa;
-			register int o;
-
-			if (is_cacheable_mem(v) &&
-			    is_cacheable_mem(v + c - 1)) {
-				pa = uio->uio_offset & ~PAGE_MASK;
-				va = MIPS_PHYS_TO_XKPHYS(MIPS_XKPHYS_CCA_CNC, pa);
-				o = (int)uio->uio_offset & PAGE_MASK;
-				c = (u_int)(PAGE_SIZE -
-					    ((uintptr_t)iov->iov_base & PAGE_MASK));
-				c = min(c, (u_int)(PAGE_SIZE - o));
-				c = min(c, (u_int)iov->iov_len);
-				error = uiomove((caddr_t)(va + o), (int)c, uio);
-			} else
-				return (EFAULT);
-#else
-			return (ENOTSUP);
-#endif
-			continue;
+			off = uio->uio_offset & PAGE_MASK;
+			cnt = PAGE_SIZE - ((vm_offset_t)iov->iov_base &
+			    PAGE_MASK);
+			cnt = min(cnt, PAGE_SIZE - off);
+			cnt = min(cnt, iov->iov_len);
+
+			m.phys_addr = trunc_page(v);
+			marr = &m;
+			error = uiomove_fromphys(&marr, off, cnt, uio);
 		}
-
-		/* minor device 1 is kernel memory */
 		else if (dev2unit(dev) == CDEV_MINOR_KMEM) {
-			v = uio->uio_offset;
-			c = min(iov->iov_len, MAXPHYS);
+			va = uio->uio_offset;
 
-			vm_offset_t addr, eaddr;
-
-			/*
-			 * Make sure that all of the pages are currently
-			 * resident so that we don't create any zero-fill pages.
+			va = trunc_page(uio->uio_offset);
+			eva = round_page(uio->uio_offset
+			    + iov->iov_len);
+
+			/* 
+			 * Make sure that all the pages are currently resident
+			 * so that we don't create any zero-fill pages.
 			 */
-			addr = trunc_page(uio->uio_offset);
-			eaddr = round_page(uio->uio_offset + c);
 
-			if (addr > (vm_offset_t) VM_MIN_KERNEL_ADDRESS) {
-				for (; addr < eaddr; addr += PAGE_SIZE) 
-					if (pmap_extract(kernel_pmap, addr) == 0)
-						return EFAULT;
-
-				if (!kernacc(
-				    (caddr_t)(uintptr_t)uio->uio_offset, c,
-				    uio->uio_rw == UIO_READ ?
-				    VM_PROT_READ : VM_PROT_WRITE))
-					return (EFAULT);
-			}
-			else if (MIPS_IS_KSEG0_ADDR(v)) {
-				if (MIPS_KSEG0_TO_PHYS(v + c) >= ctob(physmem))
-					return (EFAULT);
-			}
-			else if (MIPS_IS_KSEG1_ADDR(v)) {
-				if (MIPS_KSEG1_TO_PHYS(v + c) >= ctob(physmem))
+			for (; va < eva; va += PAGE_SIZE)
+				if (pmap_extract(kernel_pmap, va) == 0)
 					return (EFAULT);
-			}
-			else
+
+			prot = (uio->uio_rw == UIO_READ)
+			    ? VM_PROT_READ : VM_PROT_WRITE;
+
+			va = uio->uio_offset;
+			if (kernacc((void *) va, iov->iov_len, prot)
+			    == FALSE)
 				return (EFAULT);
 
+			error = uiomove((void *)va, iov->iov_len, uio);
 
-			error = uiomove((caddr_t)v, c, uio);
 			continue;
 		}
-
 	}
+
 	return (error);
 }
 
-/*ARGSUSED*/
+/*
+ * allow user processes to MMAP some memory sections
+ * instead of going through read/write
+ */
 int
-memmmap(struct cdev *dev, vm_ooffset_t off, vm_paddr_t *paddr,
+memmmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
     int prot, vm_memattr_t *memattr)
 {
+	/*
+	 * /dev/mem is the only one that makes sense through this
+	 * interface.  For /dev/kmem any physaddr we return here
+	 * could be transient and hence incorrect or invalid at
+	 * a later time.
+	 */
+	if (dev2unit(dev) != CDEV_MINOR_MEM)
+		return (-1);
+
+	*paddr = offset;
 
-	return (EOPNOTSUPP);
+	return (0);
 }
 
 void


More information about the svn-src-user mailing list