[PATCH 143/156] drm/nouveau/nvif: rework chan "new event" apis

Ben Skeggs bskeggs at nvidia.com
Tue Apr 16 23:39:49 UTC 2024


- transition from "ioctl" interfaces

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 drivers/gpu/drm/nouveau/include/nvif/chan.h   |  6 +++
 drivers/gpu/drm/nouveau/include/nvif/class.h  |  1 -
 .../gpu/drm/nouveau/include/nvif/driverif.h   |  7 +++
 drivers/gpu/drm/nouveau/include/nvif/if0020.h | 13 -----
 drivers/gpu/drm/nouveau/nouveau_chan.c        | 15 ++----
 drivers/gpu/drm/nouveau/nouveau_fence.c       | 17 ++----
 drivers/gpu/drm/nouveau/nvif/chan.c           | 17 ++++++
 .../gpu/drm/nouveau/nvkm/engine/fifo/chan.c   |  2 -
 .../gpu/drm/nouveau/nvkm/engine/fifo/uchan.c  | 53 +++++++++----------
 9 files changed, 60 insertions(+), 71 deletions(-)
 delete mode 100644 drivers/gpu/drm/nouveau/include/nvif/if0020.h

diff --git a/drivers/gpu/drm/nouveau/include/nvif/chan.h b/drivers/gpu/drm/nouveau/include/nvif/chan.h
index 80f7ea8c7268..45c82cef6b1d 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/chan.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/chan.h
@@ -3,6 +3,7 @@
 #define __NVIF_CHAN_H__
 #include <nvif/object.h>
 #include <nvif/driverif.h>
+#include <nvif/event.h>
 #include <nvif/push.h>
 struct nvif_cgrp;
 struct nvif_device;
@@ -22,4 +23,9 @@ struct nvif_chan {
 void nvif_chan_ctor(struct nvif_device *, struct nvif_cgrp *, const char *name, u8 runl, u8 runq,
 		    struct nvif_chan *);
 void nvif_chan_dtor(struct nvif_chan *);
+
+int nvif_chan_event_ctor(struct nvif_chan *, const char *name,
+			 int (*ctor)(struct nvif_chan_priv *, u64 token,
+				     const struct nvif_event_impl **, struct nvif_event_priv **),
+			 nvif_event_func, struct nvif_event *);
 #endif
diff --git a/drivers/gpu/drm/nouveau/include/nvif/class.h b/drivers/gpu/drm/nouveau/include/nvif/class.h
index 6174999eacd3..517bac332797 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/class.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/class.h
@@ -33,7 +33,6 @@
 #define NVIF_CLASS_HEAD                              /* if0013.h */  0x80000013
 #define NVIF_CLASS_DISP_CHAN                         /* if0014.h */  0x80000014
 
-#define NVIF_CLASS_CHAN                              /* if0020.h */  0x80000020
 #define NVIF_CLASS_CGRP                              /* if0021.h */  0x80000021
 
 /* the below match nvidia-assigned (either in hw, or sw) class numbers */
diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
index 75861e0327ac..6e109da67bbe 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
@@ -448,6 +448,13 @@ struct nvif_chan_impl {
 	} inst;
 
 	struct nvif_mapinfo map;
+
+	struct {
+		int (*killed)(struct nvif_chan_priv *, u64 token,
+			      const struct nvif_event_impl **, struct nvif_event_priv **);
+		int (*nonstall)(struct nvif_chan_priv *, u64 token,
+				const struct nvif_event_impl **, struct nvif_event_priv **);
+	} event;
 };
 
 struct nvif_cgrp_impl {
diff --git a/drivers/gpu/drm/nouveau/include/nvif/if0020.h b/drivers/gpu/drm/nouveau/include/nvif/if0020.h
deleted file mode 100644
index 1893b8aa0abb..000000000000
--- a/drivers/gpu/drm/nouveau/include/nvif/if0020.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-#ifndef __NVIF_IF0020_H__
-#define __NVIF_IF0020_H__
-
-union nvif_chan_event_args {
-	struct nvif_chan_event_v0 {
-		__u8 version;
-#define NVIF_CHAN_EVENT_V0_NON_STALL_INTR 0x00
-#define NVIF_CHAN_EVENT_V0_KILLED         0x01
-		__u8 type;
-	} v0;
-};
-#endif
diff --git a/drivers/gpu/drm/nouveau/nouveau_chan.c b/drivers/gpu/drm/nouveau/nouveau_chan.c
index 60be87d5fd59..7116d61535f8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_chan.c
+++ b/drivers/gpu/drm/nouveau/nouveau_chan.c
@@ -25,7 +25,6 @@
 
 #include <nvif/class.h>
 #include <nvif/cl0002.h>
-#include <nvif/if0020.h>
 
 #include "nouveau_drv.h"
 #include "nouveau_dma.h"
@@ -368,17 +367,9 @@ nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart)
 	}
 
 	if (chan->chan.object.oclass >= FERMI_CHANNEL_GPFIFO) {
-		struct {
-			struct nvif_event_v0 base;
-			struct nvif_chan_event_v0 host;
-		} args;
-
-		args.host.version = 0;
-		args.host.type = NVIF_CHAN_EVENT_V0_KILLED;
-
-		ret = nvif_event_ctor(&chan->chan.object, "abi16ChanKilled", chan->chid,
-				      nouveau_channel_killed, false,
-				      &args.base, sizeof(args), &chan->kill);
+		ret = nvif_chan_event_ctor(&chan->chan, "abi16ChanKilled",
+					   chan->chan.impl->event.killed,
+					   nouveau_channel_killed, &chan->kill);
 		if (ret == 0)
 			ret = nvif_event_allow(&chan->kill);
 		if (ret) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index ff31784effeb..9443cbaa8cff 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -29,8 +29,6 @@
 #include <linux/sched/signal.h>
 #include <trace/events/dma_fence.h>
 
-#include <nvif/if0020.h>
-
 #include "nouveau_drv.h"
 #include "nouveau_dma.h"
 #include "nouveau_fence.h"
@@ -184,10 +182,6 @@ nouveau_fence_context_new(struct nouveau_channel *chan, struct nouveau_fence_cha
 	struct nouveau_cli *cli = chan->cli;
 	struct nouveau_drm *drm = cli->drm;
 	struct nouveau_fence_priv *priv = (void*)drm->fence;
-	struct {
-		struct nvif_event_v0 base;
-		struct nvif_chan_event_v0 host;
-	} args;
 	int ret;
 
 	INIT_WORK(&fctx->uevent_work, nouveau_fence_uevent_work);
@@ -207,14 +201,9 @@ nouveau_fence_context_new(struct nouveau_channel *chan, struct nouveau_fence_cha
 	if (!priv->uevent)
 		return;
 
-	args.host.version = 0;
-	args.host.type = NVIF_CHAN_EVENT_V0_NON_STALL_INTR;
-
-	ret = nvif_event_ctor(&chan->chan.object, "fenceNonStallIntr",
-			      (chan->runlist << 16) | chan->chid,
-			      nouveau_fence_wait_uevent_handler, false,
-			      &args.base, sizeof(args), &fctx->event);
-
+	ret = nvif_chan_event_ctor(&chan->chan, "fenceNonStallIntr",
+				   chan->chan.impl->event.nonstall,
+				   nouveau_fence_wait_uevent_handler, &fctx->event);
 	WARN_ON(ret);
 }
 
diff --git a/drivers/gpu/drm/nouveau/nvif/chan.c b/drivers/gpu/drm/nouveau/nvif/chan.c
index cfca4dac5388..e8ade9a64d97 100644
--- a/drivers/gpu/drm/nouveau/nvif/chan.c
+++ b/drivers/gpu/drm/nouveau/nvif/chan.c
@@ -23,6 +23,23 @@
 #include <nvif/cgrp.h>
 #include <nvif/device.h>
 
+int
+nvif_chan_event_ctor(struct nvif_chan *chan, const char *name,
+		     int (*ctor)(struct nvif_chan_priv *, u64,
+				 const struct nvif_event_impl **, struct nvif_event_priv **),
+		     nvif_event_func func, struct nvif_event *event)
+{
+	int ret;
+
+	ret = ctor(chan->priv, nvif_handle(&event->object), &event->impl, &event->priv);
+	NVIF_ERRON(ret, &chan->object, "[NEW EVENT]");
+	if (ret)
+		return ret;
+
+	nvif_event_ctor(&chan->object, name ?: "nvifChanEvent", 0, func, event);
+	return 0;
+}
+
 void
 nvif_chan_dtor(struct nvif_chan *chan)
 {
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c
index 7d4716dcd512..920e012d169b 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c
@@ -31,8 +31,6 @@
 #include <subdev/mmu.h>
 #include <engine/dma.h>
 
-#include <nvif/if0020.h>
-
 const struct nvkm_event_func
 nvkm_chan_event = {
 };
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c
index e9279902c472..ed1e53b15be4 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c
@@ -32,8 +32,6 @@
 #include <subdev/mmu/umem.h>
 #include <engine/dma.h>
 
-#include <nvif/if0020.h>
-
 struct nvif_chan_priv {
 	struct nvkm_object object;
 	struct nvkm_chan *chan;
@@ -41,32 +39,6 @@ struct nvif_chan_priv {
 	struct nvif_chan_impl impl;
 };
 
-static int
-nvkm_uchan_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm_uevent *uevent)
-{
-	struct nvkm_chan *chan = container_of(object, struct nvif_chan_priv, object)->chan;
-	struct nvkm_runl *runl = chan->cgrp->runl;
-	union nvif_chan_event_args *args = argv;
-
-	if (!uevent)
-		return 0;
-	if (argc != sizeof(args->v0) || args->v0.version != 0)
-		return -ENOSYS;
-
-	switch (args->v0.type) {
-	case NVIF_CHAN_EVENT_V0_NON_STALL_INTR:
-		return nvkm_uevent_add(uevent, &runl->fifo->nonstall.event, runl->id,
-				       NVKM_FIFO_NONSTALL_EVENT, NULL);
-	case NVIF_CHAN_EVENT_V0_KILLED:
-		return nvkm_uevent_add(uevent, &runl->chid->event, chan->id,
-				       NVKM_CHAN_EVENT_ERRORED, NULL);
-	default:
-		break;
-	}
-
-	return -ENOSYS;
-}
-
 struct nvkm_uobj {
 	struct nvkm_oproxy oproxy;
 	struct nvkm_chan *chan;
@@ -254,6 +226,26 @@ nvkm_uchan_sclass(struct nvkm_object *object, int index, struct nvkm_oclass *ocl
 	return -EINVAL;
 }
 
+static int
+nvkm_uchan_event_nonstall(struct nvif_chan_priv *uchan, u64 token,
+			  const struct nvif_event_impl **pimpl, struct nvif_event_priv **ppriv)
+{
+	struct nvkm_runl *runl = uchan->chan->cgrp->runl;
+
+	return nvkm_uevent_new_(&uchan->object, token, &runl->fifo->nonstall.event, false,
+				runl->id, NVKM_FIFO_NONSTALL_EVENT, NULL, pimpl, ppriv);
+}
+
+static int
+nvkm_uchan_event_killed(struct nvif_chan_priv *uchan, u64 token,
+			const struct nvif_event_impl **pimpl, struct nvif_event_priv **ppriv)
+{
+	struct nvkm_runl *runl = uchan->chan->cgrp->runl;
+
+	return nvkm_uevent_new_(&uchan->object, token, &runl->chid->event, false,
+				uchan->chan->id, NVKM_CHAN_EVENT_ERRORED, NULL, pimpl, ppriv);
+}
+
 static void
 nvkm_uchan_del(struct nvif_chan_priv *uchan)
 {
@@ -266,6 +258,7 @@ nvkm_uchan_del(struct nvif_chan_priv *uchan)
 static const struct nvif_chan_impl
 nvkm_uchan_impl = {
 	.del = nvkm_uchan_del,
+	.event.killed = nvkm_uchan_event_killed,
 };
 
 static int
@@ -313,7 +306,6 @@ nvkm_uchan = {
 	.init = nvkm_uchan_init,
 	.fini = nvkm_uchan_fini,
 	.sclass = nvkm_uchan_sclass,
-	.uevent = nvkm_uchan_uevent,
 };
 
 struct nvkm_chan *
@@ -404,6 +396,9 @@ nvkm_uchan_new(struct nvkm_device *device, struct nvkm_cgrp *cgrp, u8 runi, u8 r
 		uchan->impl.map.length = chan->func->userd->size;
 	}
 
+	if (fifo->func->nonstall)
+		uchan->impl.event.nonstall = nvkm_uchan_event_nonstall;
+
 	*pimpl = &uchan->impl;
 	*ppriv = uchan;
 	*pobject = &uchan->object;
-- 
2.41.0



More information about the Nouveau mailing list