Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/drm2/drm Expose nvif ioctl interface.



details:   https://anonhg.NetBSD.org/src/rev/439e13970e33
branches:  trunk
changeset: 995406:439e13970e33
user:      maya <maya%NetBSD.org@localhost>
date:      Fri Dec 21 07:51:17 2018 +0000

description:
Expose nvif ioctl interface.

nvif is a variable length (nested..) ioctl, so it doesn't match the
usual drm_ioctl interface. linux uses a shim to override the ioctl
function for nouveau to allow this, do the same.

fixes 3D acceleration with nouveau.

from riastradh.

diffstat:

 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c  |  37 +++++++++++++++++-
 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c |  16 +++++++-
 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h |   6 ++-
 sys/external/bsd/drm2/dist/include/drm/drmP.h         |   6 ++-
 sys/external/bsd/drm2/drm/drm_cdevsw.c                |  19 ++++++++-
 5 files changed, 74 insertions(+), 10 deletions(-)

diffs (231 lines):

diff -r b0b2e9374dc7 -r 439e13970e33 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c
--- a/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c      Fri Dec 21 07:13:30 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c      Fri Dec 21 07:51:17 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_drm.c,v 1.15 2018/08/27 15:22:54 riastradh Exp $       */
+/*     $NetBSD: nouveau_drm.c,v 1.16 2018/12/21 07:51:17 maya Exp $    */
 
 /*
  * Copyright 2012 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_drm.c,v 1.15 2018/08/27 15:22:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_drm.c,v 1.16 2018/12/21 07:51:17 maya Exp $");
 
 #include <linux/console.h>
 #include <linux/delay.h>
@@ -954,7 +954,35 @@
        DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_AUTH|DRM_RENDER_ALLOW),
 };
 
-#ifndef __NetBSD__             /* XXX nouveau pm */
+#ifdef __NetBSD__
+#include <sys/file.h>
+#include <sys/ioccom.h>
+static int                     /* XXX expose to ioc32 */
+nouveau_ioctl_override(struct file *fp, unsigned long cmd, void *data)
+{
+       struct drm_file *file = fp->f_data;
+       struct drm_device *dev = file->minor->dev;
+       int ret;
+
+       ret = pm_runtime_get_sync(dev->dev);
+       if (ret < 0 && ret != -EACCES)
+               return ret;
+
+       switch (DRM_IOCTL_NR(cmd) - DRM_COMMAND_BASE) {
+       case DRM_NOUVEAU_NVIF:
+               /* XXX errno NetBSD->Linux */
+               ret = -usif_ioctl(file, data, IOCPARM_LEN(cmd));
+               break;
+       default:
+               ret = drm_ioctl(fp, cmd, data);
+               break;
+       }
+
+       pm_runtime_mark_last_busy(dev->dev);
+       pm_runtime_put_autosuspend(dev->dev);
+       return ret;
+}
+#else
 long
 nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
@@ -979,7 +1007,9 @@
        pm_runtime_put_autosuspend(dev->dev);
        return ret;
 }
+#endif
 
+#ifndef __NetBSD__
 static const struct file_operations
 nouveau_driver_fops = {
        .owner = THIS_MODULE,
@@ -1026,6 +1056,7 @@
        .fops = NULL,
        .mmap_object = &nouveau_ttm_mmap_object,
        .gem_uvm_ops = &nouveau_gem_uvm_ops,
+       .ioctl_override = nouveau_ioctl_override,
 #else
        .fops = &nouveau_driver_fops,
 #endif
diff -r b0b2e9374dc7 -r 439e13970e33 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c
--- a/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c     Fri Dec 21 07:13:30 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c     Fri Dec 21 07:51:17 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_usif.c,v 1.5 2018/08/27 07:43:16 riastradh Exp $       */
+/*     $NetBSD: nouveau_usif.c,v 1.6 2018/12/21 07:51:17 maya Exp $    */
 
 /*
  * Copyright 2014 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_usif.c,v 1.5 2018/08/27 07:43:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_usif.c,v 1.6 2018/12/21 07:51:17 maya Exp $");
 
 #include "nouveau_drm.h"
 #include "nouveau_usif.h"
@@ -305,11 +305,17 @@
 }
 
 int
+#ifdef __NetBSD__
+usif_ioctl(struct drm_file *filp, void *data, u32 argc)
+#else
 usif_ioctl(struct drm_file *filp, void __user *user, u32 argc)
+#endif
 {
        struct nouveau_cli *cli = nouveau_cli(filp);
        struct nvif_client *client = &cli->base;
+#ifndef __NetBSD__
        void *data = kmalloc(argc, GFP_KERNEL);
+#endif
        u32   size = argc;
        union {
                struct nvif_ioctl_v0 v0;
@@ -318,10 +324,12 @@
        u8 owner;
        int ret;
 
+#ifndef __NetBSD__
        if (ret = -ENOMEM, !argv)
                goto done;
        if (ret = -EFAULT, copy_from_user(argv, user, size))
                goto done;
+#endif
 
        if (nvif_unpack(argv->v0, 0, 0, true)) {
                /* block access to objects not created via this interface */
@@ -385,10 +393,14 @@
        argv->v0.owner = owner;
        mutex_unlock(&cli->mutex);
 
+#ifndef __NetBSD__
        if (copy_to_user(user, argv, argc))
                ret = -EFAULT;
+#endif
 done:
+#ifndef __NetBSD__
        kfree(argv);
+#endif
        return ret;
 }
 
diff -r b0b2e9374dc7 -r 439e13970e33 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h
--- a/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h     Fri Dec 21 07:13:30 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h     Fri Dec 21 07:51:17 2018 +0000
@@ -1,11 +1,15 @@
-/*     $NetBSD: nouveau_usif.h,v 1.2 2018/08/27 04:58:24 riastradh Exp $       */
+/*     $NetBSD: nouveau_usif.h,v 1.3 2018/12/21 07:51:17 maya Exp $    */
 
 #ifndef __NOUVEAU_USIF_H__
 #define __NOUVEAU_USIF_H__
 
 void usif_client_init(struct nouveau_cli *);
 void usif_client_fini(struct nouveau_cli *);
+#ifdef __NetBSD__
+int  usif_ioctl(struct drm_file *, void *, u32);
+#else
 int  usif_ioctl(struct drm_file *, void __user *, u32);
+#endif
 int  usif_notify(const void *, u32, const void *, u32);
 
 #endif
diff -r b0b2e9374dc7 -r 439e13970e33 sys/external/bsd/drm2/dist/include/drm/drmP.h
--- a/sys/external/bsd/drm2/dist/include/drm/drmP.h     Fri Dec 21 07:13:30 2018 +0000
+++ b/sys/external/bsd/drm2/dist/include/drm/drmP.h     Fri Dec 21 07:51:17 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drmP.h,v 1.34 2018/08/28 03:41:39 riastradh Exp $      */
+/*     $NetBSD: drmP.h,v 1.35 2018/12/21 07:51:18 maya Exp $   */
 
 /*
  * Internal Header for the Direct Rendering Manager
@@ -710,6 +710,10 @@
        int num_ioctls;
        const struct file_operations *fops;
 
+#ifdef __NetBSD__
+       int (*ioctl_override)(struct file *, unsigned long, void *);
+#endif
+
        /* List of devices hanging off this driver with stealth attach. */
        struct list_head legacy_dev_list;
 };
diff -r b0b2e9374dc7 -r 439e13970e33 sys/external/bsd/drm2/drm/drm_cdevsw.c
--- a/sys/external/bsd/drm2/drm/drm_cdevsw.c    Fri Dec 21 07:13:30 2018 +0000
+++ b/sys/external/bsd/drm2/drm/drm_cdevsw.c    Fri Dec 21 07:51:17 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_cdevsw.c,v 1.12 2018/08/28 03:41:39 riastradh Exp $        */
+/*     $NetBSD: drm_cdevsw.c,v 1.13 2018/12/21 07:51:18 maya Exp $     */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.12 2018/08/28 03:41:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.13 2018/12/21 07:51:18 maya Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -70,6 +70,7 @@
                    int);
 static int     drm_dequeue_event(struct drm_file *, size_t,
                    struct drm_pending_event **, int);
+static int     drm_ioctl_shim(struct file *, unsigned long, void *);
 static int     drm_poll(struct file *, int);
 static int     drm_kqfilter(struct file *, struct knote *);
 static int     drm_stat(struct file *, struct stat *);
@@ -98,7 +99,7 @@
        .fo_name = "drm",
        .fo_read = drm_read,
        .fo_write = fbadop_write,
-       .fo_ioctl = drm_ioctl,
+       .fo_ioctl = drm_ioctl_shim,
        .fo_fcntl = fnullop_fcntl,
        .fo_poll = drm_poll,
        .fo_stat = drm_stat,
@@ -340,6 +341,18 @@
 }
 
 static int
+drm_ioctl_shim(struct file *fp, unsigned long cmd, void *data)
+{
+       struct drm_file *file = fp->f_data;
+       struct drm_driver *driver = file->minor->dev->driver;
+
+       if (driver->ioctl_override)
+               return driver->ioctl_override(fp, cmd, data);
+       else
+               return drm_ioctl(fp, cmd, data);
+}
+
+static int
 drm_poll(struct file *fp __unused, int events __unused)
 {
        struct drm_file *const file = fp->f_data;



Home | Main Index | Thread Index | Old Index