Module Name:    src
Committed By:   maya
Date:           Fri Dec 21 07:51:18 UTC 2018

Modified Files:
        src/sys/external/bsd/drm2/dist/drm/nouveau: nouveau_drm.c
            nouveau_usif.c nouveau_usif.h
        src/sys/external/bsd/drm2/dist/include/drm: drmP.h
        src/sys/external/bsd/drm2/drm: drm_cdevsw.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c
cvs rdiff -u -r1.5 -r1.6 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c
cvs rdiff -u -r1.2 -r1.3 \
    src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h
cvs rdiff -u -r1.34 -r1.35 src/sys/external/bsd/drm2/dist/include/drm/drmP.h
cvs rdiff -u -r1.12 -r1.13 src/sys/external/bsd/drm2/drm/drm_cdevsw.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c:1.15 src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c:1.16
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c:1.15	Mon Aug 27 15:22:54 2018
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c	Fri Dec 21 07:51:17 2018
@@ -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 @@ nouveau_ioctls[] = {
 	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 @@ nouveau_drm_ioctl(struct file *file, uns
 	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 @@ driver_stub = {
 	.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

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c:1.5 src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c:1.6
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c:1.5	Mon Aug 27 07:43:16 2018
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c	Fri Dec 21 07:51:17 2018
@@ -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 @@ usif_object_new(struct drm_file *f, void
 }
 
 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 @@ usif_ioctl(struct drm_file *filp, void _
 	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 @@ usif_ioctl(struct drm_file *filp, void _
 	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;
 }
 

Index: src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h:1.2 src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h:1.3
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h:1.2	Mon Aug 27 04:58:24 2018
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.h	Fri Dec 21 07:51:17 2018
@@ -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

Index: src/sys/external/bsd/drm2/dist/include/drm/drmP.h
diff -u src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.34 src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.35
--- src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.34	Tue Aug 28 03:41:39 2018
+++ src/sys/external/bsd/drm2/dist/include/drm/drmP.h	Fri Dec 21 07:51:18 2018
@@ -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 @@ struct drm_driver {
 	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;
 };

Index: src/sys/external/bsd/drm2/drm/drm_cdevsw.c
diff -u src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.12 src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.13
--- src/sys/external/bsd/drm2/drm/drm_cdevsw.c:1.12	Tue Aug 28 03:41:39 2018
+++ src/sys/external/bsd/drm2/drm/drm_cdevsw.c	Fri Dec 21 07:51:18 2018
@@ -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 @@ static int	drm_read(struct file *, off_t
 		    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 @@ static const struct fileops drm_fileops 
 	.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 @@ out:	spin_unlock_irqrestore(&dev->event_
 }
 
 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;

Reply via email to