Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add a new "fo_mmap" fileops method to allow use of arbitrary...



details:   https://anonhg.NetBSD.org/src/rev/85cfa86b5792
branches:  trunk
changeset: 334911:85cfa86b5792
user:      chs <chs%NetBSD.org@localhost>
date:      Sun Dec 14 23:48:58 2014 +0000

description:
add a new "fo_mmap" fileops method to allow use of arbitrary uvm_objects for
mappings of file objects.  move vnode-specific details of mmap()ing a vnode
from uvm_mmap() to the new vnode-specific vn_mmap().  add new uvm_mmap_dev()
and uvm_mmap_anon() convenience functions for mapping character devices
and anonymous memory, and replace all other calls to uvm_mmap() with those.
use the new fileop in drm2 so that libdrm can use mmap() to map things
like on other platforms (instead of the ioctl that we have used so far).

diffstat:

 common/lib/libprop/prop_kern.c                |   28 +-
 sys/arch/mac68k/dev/grf_compat.c              |   30 +-
 sys/arch/x68k/dev/grf.c                       |   26 +-
 sys/external/bsd/drm/dist/bsd-core/drm_bufs.c |   22 +-
 sys/external/bsd/drm2/drm/drm_drv.c           |   88 +-----
 sys/external/bsd/drm2/drm/drm_vm.c            |    6 +-
 sys/external/bsd/drm2/include/linux/mm.h      |   40 +--
 sys/kern/vfs_vnops.c                          |  226 +++++++++++++++++++-
 sys/rump/librump/rumpkern/vm.c                |   39 +-
 sys/sys/file.h                                |   20 +-
 sys/uvm/uvm_device.c                          |    7 +-
 sys/uvm/uvm_device.h                          |    4 +-
 sys/uvm/uvm_extern.h                          |    8 +-
 sys/uvm/uvm_mmap.c                            |  303 ++++++-------------------
 14 files changed, 396 insertions(+), 451 deletions(-)

diffs (truncated from 1426 to 300 lines):

diff -r e7820c523a0d -r 85cfa86b5792 common/lib/libprop/prop_kern.c
--- a/common/lib/libprop/prop_kern.c    Sun Dec 14 23:27:14 2014 +0000
+++ b/common/lib/libprop/prop_kern.c    Sun Dec 14 23:48:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_kern.c,v 1.17 2011/09/30 22:08:18 jym Exp $       */
+/*     $NetBSD: prop_kern.c,v 1.18 2014/12/14 23:48:58 chs Exp $       */
 
 /*-
  * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
@@ -380,7 +380,7 @@
 #include <sys/resource.h>
 #include <sys/pool.h>
 
-#include <uvm/uvm.h>
+#include <uvm/uvm_extern.h>
 
 #include "prop_object_impl.h"
 
@@ -507,9 +507,9 @@
        struct lwp *l = curlwp;         /* XXX */
        struct proc *p = l->l_proc;
        char *buf;
+       void *uaddr;
        size_t len, rlen;
        int error = 0;
-       vaddr_t uaddr;
 
        switch (prop_object_type(obj)) {
        case PROP_TYPE_ARRAY:
@@ -526,26 +526,12 @@
 
        len = strlen(buf) + 1;
        rlen = round_page(len);
-
-       /*
-        * See sys_mmap() in sys/uvm/uvm_mmap.c.
-        * Let's act as if we were calling mmap(0, ...)
-        */
-       uaddr = p->p_emul->e_vm_default_addr(p,
-           (vaddr_t)p->p_vmspace->vm_daddr, rlen);
-
-       error = uvm_mmap(&p->p_vmspace->vm_map,
-                        &uaddr, rlen,
-                        VM_PROT_READ|VM_PROT_WRITE,
-                        VM_PROT_READ|VM_PROT_WRITE,
-                        MAP_PRIVATE|MAP_ANON,
-                        NULL, 0,
-                        p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
-       
+       uaddr = NULL;
+       error = uvm_mmap_anon(p, &uaddr, rlen);
        if (error == 0) {
-               error = copyout(buf, (char *)uaddr, len);
+               error = copyout(buf, uaddr, len);
                if (error == 0) {
-                       pref->pref_plist = (char *)uaddr;
+                       pref->pref_plist = uaddr;
                        pref->pref_len   = len;
                }
        }
diff -r e7820c523a0d -r 85cfa86b5792 sys/arch/mac68k/dev/grf_compat.c
--- a/sys/arch/mac68k/dev/grf_compat.c  Sun Dec 14 23:27:14 2014 +0000
+++ b/sys/arch/mac68k/dev/grf_compat.c  Sun Dec 14 23:48:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: grf_compat.c,v 1.26 2014/07/25 08:10:33 dholland Exp $ */
+/*     $NetBSD: grf_compat.c,v 1.27 2014/12/14 23:48:58 chs Exp $      */
 
 /*
  * Copyright (C) 1999 Scott Reynolds
@@ -34,7 +34,7 @@
 #include "opt_grf_compat.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: grf_compat.c,v 1.26 2014/07/25 08:10:33 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: grf_compat.c,v 1.27 2014/12/14 23:48:58 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -43,12 +43,9 @@
 #include <sys/errno.h>
 #include <sys/ioctl.h>
 #include <sys/malloc.h>
-#include <sys/mman.h>
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
-#include <sys/vnode.h>
 
-#include <machine/autoconf.h>
 #include <machine/bus.h>
 #include <machine/grfioctl.h>
 
@@ -59,7 +56,6 @@
 #include <miscfs/specfs/specdev.h>
 
 #include <uvm/uvm_extern.h>
-#include <uvm/uvm_map.h>
 
 dev_type_open(grfopen);
 dev_type_close(grfclose);
@@ -320,24 +316,14 @@
 int
 grfmap(dev_t dev, struct macfb_softc *sc, void **addrp, struct proc *p)
 {
-       struct vnode vn;
-       u_long len;
-       int error, flags;
+       size_t len;
+       int error;
 
        len = m68k_round_page(sc->sc_dc->dc_offset + sc->sc_dc->dc_size);
-       *addrp = (void *)p->p_emul->e_vm_default_addr(p,
-           (vaddr_t)p->p_vmspace->vm_daddr, len);
-       flags = MAP_SHARED | MAP_FIXED;
-
-       vn.v_type = VCHR;               /* XXX */
-       vn.v_rdev = dev;                /* XXX */
-
-       error = uvm_mmap(&p->p_vmspace->vm_map, (vaddr_t *)addrp,
-           (vsize_t)len, VM_PROT_ALL, VM_PROT_ALL,
-           flags, (void *)&vn, 0, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
+       error = uvm_mmap_dev(p, addrp, len, dev, 0);
 
        /* Offset into page: */
-       *addrp = (char*)*addrp + sc->sc_dc->dc_offset;
+       *addrp = (char *)*addrp + sc->sc_dc->dc_offset;
 
        return (error);
 }
@@ -345,9 +331,9 @@
 int
 grfunmap(dev_t dev, struct macfb_softc *sc, void *addr, struct proc *p)
 {
-       vm_size_t size;
+       size_t size;
 
-       addr = (char*)addr - sc->sc_dc->dc_offset;
+       addr = (char *)addr - sc->sc_dc->dc_offset;
 
        if (addr <= 0)
                return (-1);
diff -r e7820c523a0d -r 85cfa86b5792 sys/arch/x68k/dev/grf.c
--- a/sys/arch/x68k/dev/grf.c   Sun Dec 14 23:27:14 2014 +0000
+++ b/sys/arch/x68k/dev/grf.c   Sun Dec 14 23:48:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: grf.c,v 1.44 2014/07/25 08:10:35 dholland Exp $        */
+/*     $NetBSD: grf.c,v 1.45 2014/12/14 23:48:58 chs Exp $     */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.44 2014/07/25 08:10:35 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.45 2014/12/14 23:48:58 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -53,10 +53,7 @@
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
 #include <sys/ioctl.h>
-#include <sys/file.h>
 #include <sys/malloc.h>
-#include <sys/vnode.h>
-#include <sys/mman.h>
 #include <sys/conf.h>
 
 #include <machine/cpu.h>
@@ -66,7 +63,6 @@
 #include <x68k/dev/itevar.h>
 
 #include <uvm/uvm_extern.h>
-#include <uvm/uvm_map.h>
 
 #include <miscfs/specfs/specdev.h>
 
@@ -266,9 +262,8 @@
 grfmap(dev_t dev, void **addrp, struct proc *p)
 {
        struct grf_softc *gp = device_lookup_private(&grf_cd, GRFUNIT(dev));
-       int len, error;
-       struct vnode vn;
-       int flags;
+       size_t len;
+       int error;
 
 #ifdef DEBUG
        if (grfdebug & GDB_MMAP)
@@ -276,19 +271,8 @@
 #endif
 
        len = gp->g_display.gd_regsize + gp->g_display.gd_fbsize;
-       flags = MAP_SHARED;
-       if (*addrp)
-               flags |= MAP_FIXED;
-       else
-               *addrp = (void *)p->p_emul->e_vm_default_addr(p, 
-                   (vaddr_t)p->p_vmspace->vm_daddr, len);
 
-       vn.v_type = VCHR;                       /* XXX */
-       vn.v_rdev = dev;                        /* XXX */
-       error = uvm_mmap(&p->p_vmspace->vm_map, (vaddr_t *)addrp,
-                        (vsize_t)len, VM_PROT_ALL, VM_PROT_ALL,
-                        flags, (void *)&vn, 0,
-                        p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
+       error = uvm_mmap_dev(p, addrp, len, dev, 0);
        if (error == 0)
                (void) (*gp->g_sw->gd_mode)(gp, GM_MAP, *addrp);
 
diff -r e7820c523a0d -r 85cfa86b5792 sys/external/bsd/drm/dist/bsd-core/drm_bufs.c
--- a/sys/external/bsd/drm/dist/bsd-core/drm_bufs.c     Sun Dec 14 23:27:14 2014 +0000
+++ b/sys/external/bsd/drm/dist/bsd-core/drm_bufs.c     Sun Dec 14 23:48:58 2014 +0000
@@ -1068,29 +1068,22 @@
        int retcode = 0;
        const int zero = 0;
        vm_offset_t address;
+#if defined(__FreeBSD__)
        struct vmspace *vms;
-#if defined(__FreeBSD__)
        vm_ooffset_t foff;
        vm_size_t size;
        vm_offset_t vaddr;
 #elif   defined(__NetBSD__)
-       struct vnode *vn;
        voff_t foff;
        vsize_t size, rsize;
+       void *addr;
        vaddr_t vaddr;
 #endif
        struct drm_buf_map *request = data;
        int i;
 
-#if defined(__NetBSD__)
-       if (!vfinddev(dev->kdev, VCHR, &vn))
-               return 0;       /* FIXME: Shouldn't this be EINVAL or something? */
-#endif /* __NetBSD__ || __OpenBSD */
-
 #if defined(__FreeBSD__)
        vms = DRM_CURPROC->td_proc->p_vmspace;
-#elif   defined(__NetBSD__)
-       vms = DRM_CURPROC->p_vmspace;
 #endif
 
        DRM_SPINLOCK(&dev->dma_lock);
@@ -1128,13 +1121,10 @@
 #endif
 #elif   defined(__NetBSD__)
        /* XXXNETBSD */
-       vaddr = curlwp->l_proc->p_emul->e_vm_default_addr(curlwp->l_proc,
-           (vaddr_t)vms->vm_daddr, size);
        rsize = round_page(size);
+       retcode = uvm_mmap_dev(curproc, &addr, rsize, dev->kdev, foff);
+       vaddr = (vaddr_t)addr;
        DRM_DEBUG("mmap %#lx/%#lx foff %#llx\n", vaddr, rsize, (long long)foff);
-       retcode = uvm_mmap(&vms->vm_map, &vaddr, rsize,
-           UVM_PROT_READ | UVM_PROT_WRITE, UVM_PROT_ALL, MAP_SHARED,
-           &vn->v_uobj, foff, curproc->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
 #endif
        if (retcode)
                goto done;
@@ -1167,10 +1157,6 @@
 
  done:
        request->count = dma->buf_count;
-#if defined(__NetBSD__)
-       vrele(vn);
-#endif
-
        DRM_DEBUG("%d buffers, retcode = %d\n", request->count, retcode);
 
        return retcode;
diff -r e7820c523a0d -r 85cfa86b5792 sys/external/bsd/drm2/drm/drm_drv.c
--- a/sys/external/bsd/drm2/drm/drm_drv.c       Sun Dec 14 23:27:14 2014 +0000
+++ b/sys/external/bsd/drm2/drm/drm_drv.c       Sun Dec 14 23:48:58 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_drv.c,v 1.11 2014/11/22 19:18:07 riastradh Exp $   */
+/*     $NetBSD: drm_drv.c,v 1.12 2014/12/14 23:48:58 chs Exp $ */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.11 2014/11/22 19:18:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.12 2014/12/14 23:48:58 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -72,11 +72,12 @@
 static int     drm_kqfilter(struct file *, struct knote *);
 static int     drm_stat(struct file *, struct stat *);
 static int     drm_ioctl(struct file *, unsigned long, void *);
+static int     drm_fop_mmap(struct file *, off_t *, size_t, int, int *, int *,
+                            struct uvm_object **, int *);
 static int     drm_version_string(char *, size_t *, const char *);
 static paddr_t drm_mmap(dev_t, off_t, int);
 
 static drm_ioctl_t     drm_version;



Home | Main Index | Thread Index | Old Index