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/dist/drm/nouveau Kludge to pass bus_sp...



details:   https://anonhg.NetBSD.org/src/rev/cc8886e076d2
branches:  trunk
changeset: 992721:cc8886e076d2
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 07:35:56 2018 +0000

description:
Kludge to pass bus_space_tag through nvif mappings.

- New `ioctl' NVIF_IOCTL_V0_MAP_NETBSD returns bus_space_tag_t too.
  . Blocked from userland.  (Would only disclose a kernel virtual
    address, so not terribly serious.)
- struct nvif_driver::map function takes bus_sapce_tag, returns
  bus_space_handle in addition to kva pointer.
- struct nvif_driver::unmap function takes bus_space_tag and
  bus_space_handle rather than kva pointer.
- Teach various nvkm object types to return bus space tags too.
- Map them all with BUS_SPACE_MAP_LINEAR so the vaddr works.

XXX The fifo channel might need to be mapped with a subregion.
XXX What to do?

diffstat:

 sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/driver.h                                |   9 ++-
 sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/ioctl.h                                 |  16 +++++-
 sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/object.h                                |   6 +-
 sys/external/bsd/drm2/dist/drm/nouveau/include/nvkm/core/object.h                           |  10 ++-
 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nvif.c                                       |  29 +++++++++-
 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c                                       |   7 +-
 sys/external/bsd/drm2/dist/drm/nouveau/nvif/nouveau_nvif_object.c                           |  25 +++++++-
 sys/external/bsd/drm2/dist/drm/nouveau/nvkm/core/nouveau_nvkm_core_ioctl.c                  |  28 ++++++++-
 sys/external/bsd/drm2/dist/drm/nouveau/nvkm/core/nouveau_nvkm_core_object.c                 |   9 +-
 sys/external/bsd/drm2/dist/drm/nouveau/nvkm/core/nouveau_nvkm_core_oproxy.c                 |   9 +-
 sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/device/nouveau_nvkm_engine_device_user.c |   8 +-
 sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/disp/nouveau_nvkm_engine_disp_channv50.c |  10 ++-
 sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/fifo/nouveau_nvkm_engine_fifo_chan.c     |   9 ++-
 13 files changed, 142 insertions(+), 33 deletions(-)

diffs (truncated from 483 to 300 lines):

diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/driver.h
--- a/sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/driver.h      Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/driver.h      Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: driver.h,v 1.3 2018/08/27 07:32:59 riastradh Exp $     */
+/*     $NetBSD: driver.h,v 1.4 2018/08/27 07:35:56 riastradh Exp $     */
 
 #ifndef __NVIF_DRIVER_H__
 #define __NVIF_DRIVER_H__
@@ -16,8 +16,15 @@
        int (*suspend)(void *priv);
        int (*resume)(void *priv);
        int (*ioctl)(void *priv, bool super, void *data, u32 size, void **hack);
+#ifdef __NetBSD__
+       int (*map)(void *priv, bus_space_tag_t tag, u64 handle, u32 size,
+           bus_space_handle_t *handlep, void __iomem **ptrp);
+       void (*unmap)(void *priv, bus_space_tag_t tag,
+           bus_space_handle_t handle, u32 size);
+#else
        void __iomem *(*map)(void *priv, u64 handle, u32 size);
        void (*unmap)(void *priv, void __iomem *ptr, u32 size);
+#endif
        bool keep;
 };
 
diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/ioctl.h
--- a/sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/ioctl.h       Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/ioctl.h       Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ioctl.h,v 1.2 2018/08/27 04:58:30 riastradh Exp $      */
+/*     $NetBSD: ioctl.h,v 1.3 2018/08/27 07:35:56 riastradh Exp $      */
 
 #ifndef __NVIF_IOCTL_H__
 #define __NVIF_IOCTL_H__
@@ -20,6 +20,7 @@
 #define NVIF_IOCTL_V0_NTFY_DEL                                             0x0a
 #define NVIF_IOCTL_V0_NTFY_GET                                             0x0b
 #define NVIF_IOCTL_V0_NTFY_PUT                                             0x0c
+#define NVIF_IOCTL_V0_MAP_NETBSD                                          0x0d
        __u8  type;
        __u8  pad02[4];
 #define NVIF_IOCTL_V0_OWNER_NVIF                                           0x00
@@ -98,6 +99,19 @@
        __u64 handle;
 };
 
+#ifdef __NetBSD__
+/* XXX Kludge for NetBSD kernel-only use.  */
+#include <sys/bus.h>
+struct nvif_ioctl_map_netbsd_v0 {
+       /* nvif_ioctl ... */
+       __u8  version;
+       __u8  pad01[3];
+       bus_space_tag_t tag;
+       __u32 length;
+       __u64 handle;
+};
+#endif
+
 struct nvif_ioctl_unmap {
 };
 
diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/object.h
--- a/sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/object.h      Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/include/nvif/object.h      Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: object.h,v 1.3 2018/08/27 07:32:59 riastradh Exp $     */
+/*     $NetBSD: object.h,v 1.4 2018/08/27 07:35:56 riastradh Exp $     */
 
 #ifndef __NVIF_OBJECT_H__
 #define __NVIF_OBJECT_H__
@@ -67,6 +67,10 @@
        s32 oclass;
        void *priv; /*XXX: hack */
        struct {
+#ifdef __NetBSD__
+               bus_space_tag_t tag;
+               bus_space_handle_t handle;
+#endif
                void __iomem *ptr;
                u32 size;
        } map;
diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/include/nvkm/core/object.h
--- a/sys/external/bsd/drm2/dist/drm/nouveau/include/nvkm/core/object.h Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/include/nvkm/core/object.h Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: object.h,v 1.2 2018/08/27 04:58:30 riastradh Exp $     */
+/*     $NetBSD: object.h,v 1.3 2018/08/27 07:35:56 riastradh Exp $     */
 
 #ifndef __NVKM_OBJECT_H__
 #define __NVKM_OBJECT_H__
@@ -29,7 +29,12 @@
        int (*fini)(struct nvkm_object *, bool suspend);
        int (*mthd)(struct nvkm_object *, u32 mthd, void *data, u32 size);
        int (*ntfy)(struct nvkm_object *, u32 mthd, struct nvkm_event **);
+#ifdef __NetBSD__
+       int (*map)(struct nvkm_object *, bus_space_tag_t *tagp, u64 *addr,
+           u32 *size);
+#else
        int (*map)(struct nvkm_object *, u64 *addr, u32 *size);
+#endif
        int (*rd08)(struct nvkm_object *, u64 addr, u8 *data);
        int (*rd16)(struct nvkm_object *, u64 addr, u16 *data);
        int (*rd32)(struct nvkm_object *, u64 addr, u32 *data);
@@ -54,7 +59,8 @@
 int nvkm_object_fini(struct nvkm_object *, bool suspend);
 int nvkm_object_mthd(struct nvkm_object *, u32 mthd, void *data, u32 size);
 int nvkm_object_ntfy(struct nvkm_object *, u32 mthd, struct nvkm_event **);
-int nvkm_object_map(struct nvkm_object *, u64 *addr, u32 *size);
+int nvkm_object_map(struct nvkm_object *, bus_space_tag_t *, u64 *addr,
+    u32 *size);
 int nvkm_object_rd08(struct nvkm_object *, u64 addr, u8  *data);
 int nvkm_object_rd16(struct nvkm_object *, u64 addr, u16 *data);
 int nvkm_object_rd32(struct nvkm_object *, u64 addr, u32 *data);
diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nvif.c
--- a/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nvif.c     Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nvif.c     Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_nvif.c,v 1.2 2018/08/27 04:58:24 riastradh Exp $       */
+/*     $NetBSD: nouveau_nvif.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $       */
 
 /*
  * Copyright 2014 Red Hat Inc.
@@ -29,7 +29,7 @@
  ******************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_nvif.c,v 1.2 2018/08/27 04:58:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_nvif.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $");
 
 #include <core/client.h>
 #include <core/notify.h>
@@ -44,6 +44,30 @@
 #include "nouveau_drm.h"
 #include "nouveau_usif.h"
 
+#ifdef __NetBSD__
+#define        __iomem __nvif_iomem
+static int
+nvkm_client_map(void *priv, bus_space_tag_t tag, u64 busaddr, u32 size,
+    bus_space_handle_t *handlep, void __iomem **ptrp)
+{
+       int ret;
+
+       ret = -bus_space_map(tag, busaddr, size, BUS_SPACE_MAP_LINEAR,
+           handlep);
+       if (ret)
+               return ret;
+       *ptrp = bus_space_vaddr(tag, *handlep);
+       return 0;
+}
+
+static void
+nvkm_client_unmap(void *priv, bus_space_tag_t tag, bus_space_handle_t handle,
+    u32 size)
+{
+
+       bus_space_unmap(tag, handle, size);
+}
+#else
 static void
 nvkm_client_unmap(void *priv, void __iomem *ptr, u32 size)
 {
@@ -55,6 +79,7 @@
 {
        return ioremap(handle, size);
 }
+#endif
 
 static int
 nvkm_client_ioctl(void *priv, bool super, void *data, u32 size, void **hack)
diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c
--- a/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c     Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_usif.c     Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_usif.c,v 1.2 2018/08/27 04:58:24 riastradh Exp $       */
+/*     $NetBSD: nouveau_usif.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $       */
 
 /*
  * Copyright 2014 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_usif.c,v 1.2 2018/08/27 04:58:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_usif.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $");
 
 #include "nouveau_drm.h"
 #include "nouveau_usif.h"
@@ -355,6 +355,9 @@
        case NVIF_IOCTL_V0_NTFY_PUT:
                ret = usif_notify_put(filp, data, size, argv, argc);
                break;
+       case NVIF_IOCTL_V0_MAP_NETBSD:
+               /* Kernel-only kludge.  */
+               ret = -EINVAL;
        default:
                ret = nvif_client_ioctl(client, argv, argc);
                break;
diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/nvif/nouveau_nvif_object.c
--- a/sys/external/bsd/drm2/dist/drm/nouveau/nvif/nouveau_nvif_object.c Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/nvif/nouveau_nvif_object.c Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_nvif_object.c,v 1.2 2018/08/27 04:58:30 riastradh Exp $        */
+/*     $NetBSD: nouveau_nvif_object.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $        */
 
 /*
  * Copyright 2014 Red Hat Inc.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_nvif_object.c,v 1.2 2018/08/27 04:58:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_nvif_object.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $");
 
 #include <nvif/object.h>
 #include <nvif/client.h>
@@ -183,7 +183,8 @@
                };
 
                if (object->map.ptr) {
-                       client->driver->unmap(client, object->map.ptr,
+                       client->driver->unmap(client, object->map.tag,
+                                                     object->map.handle,
                                                      object->map.size);
                        object->map.ptr = NULL;
                }
@@ -199,18 +200,36 @@
        struct nvif_client *client = object->client;
        struct {
                struct nvif_ioctl_v0 ioctl;
+#ifdef __NetBSD__
+               struct nvif_ioctl_map_netbsd_v0 map;
+#else
                struct nvif_ioctl_map_v0 map;
+#endif
        } args = {
+#ifdef __NetBSD__
+               .ioctl.type = NVIF_IOCTL_V0_MAP_NETBSD,
+#else
                .ioctl.type = NVIF_IOCTL_V0_MAP,
+#endif
        };
        int ret = nvif_object_ioctl(object, &args, sizeof(args), NULL);
        if (ret == 0) {
                object->map.size = args.map.length;
+#ifdef __NetBSD__
+               ret = client->driver->map(client, args.map.tag,
+                   args.map.handle, object->map.size, &object->map.handle,
+                   &object->map.ptr);
+               if (ret) {
+                       nvif_object_unmap(object);
+                       return -ENOMEM;
+               }
+#else
                object->map.ptr = client->driver->map(client, args.map.handle,
                                                      object->map.size);
                if (ret = -ENOMEM, object->map.ptr)
                        return 0;
                nvif_object_unmap(object);
+#endif
        }
        return ret;
 }
diff -r e102bf55748b -r cc8886e076d2 sys/external/bsd/drm2/dist/drm/nouveau/nvkm/core/nouveau_nvkm_core_ioctl.c
--- a/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/core/nouveau_nvkm_core_ioctl.c        Mon Aug 27 07:35:41 2018 +0000
+++ b/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/core/nouveau_nvkm_core_ioctl.c        Mon Aug 27 07:35:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_nvkm_core_ioctl.c,v 1.2 2018/08/27 04:58:30 riastradh Exp $    */
+/*     $NetBSD: nouveau_nvkm_core_ioctl.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $    */
 
 /*
  * Copyright 2014 Red Hat Inc.
@@ -24,7 +24,7 @@
  * Authors: Ben Skeggs <bskeggs%redhat.com@localhost>
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_core_ioctl.c,v 1.2 2018/08/27 04:58:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_core_ioctl.c,v 1.3 2018/08/27 07:35:56 riastradh Exp $");
 
 #include <core/ioctl.h>
 #include <core/client.h>
@@ -260,8 +260,29 @@
 
        nvif_ioctl(object, "map size %d\n", size);
        if (nvif_unpack(args->v0, 0, 0, false)) {
+               bus_space_tag_t dummy __unused;
                nvif_ioctl(object, "map vers %d\n", args->v0.version);
-               ret = nvkm_object_map(object, &args->v0.handle,
+               ret = nvkm_object_map(object, &dummy,
+                                             &args->v0.handle,
+                                             &args->v0.length);
+       }
+
+       return ret;
+}
+
+static int
+nvkm_ioctl_map_netbsd(struct nvkm_object *object, void *data, u32 size)
+{



Home | Main Index | Thread Index | Old Index