[PATCH 103/156] drm/nouveau/nvif: rework conn "new event" api

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


- transition from "ioctl" interface

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 drivers/gpu/drm/nouveau/include/nvif/conn.h   |  6 ---
 .../gpu/drm/nouveau/include/nvif/driverif.h   |  3 ++
 drivers/gpu/drm/nouveau/nvif/conn.c           | 22 ++++----
 .../gpu/drm/nouveau/nvkm/engine/disp/uconn.c  | 50 ++++++++-----------
 4 files changed, 35 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvif/conn.h b/drivers/gpu/drm/nouveau/include/nvif/conn.h
index 0f0ca002fe47..40c6424d82bf 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/conn.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/conn.h
@@ -17,12 +17,6 @@ struct nvif_conn {
 int nvif_conn_ctor(struct nvif_disp *, const char *name, int id, struct nvif_conn *);
 void nvif_conn_dtor(struct nvif_conn *);
 
-static inline int
-nvif_conn_id(struct nvif_conn *conn)
-{
-	return conn->object.handle;
-}
-
 int nvif_conn_event_ctor(struct nvif_conn *, const char *name, nvif_event_func, u8 types,
 			 struct nvif_event *);
 #endif
diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
index fb741c7293f6..489f50d6ee00 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
@@ -238,6 +238,9 @@ struct nvif_conn_impl {
 		NVIF_CONN_DP,
 		NVIF_CONN_EDP,
 	} type;
+
+	int (*event)(struct nvif_conn_priv *, u64 handle, u8 types,
+		     const struct nvif_event_impl **, struct nvif_event_priv **);
 };
 
 struct nvif_disp_impl {
diff --git a/drivers/gpu/drm/nouveau/nvif/conn.c b/drivers/gpu/drm/nouveau/nvif/conn.c
index 48927282a7ce..d4e9f0275d1e 100644
--- a/drivers/gpu/drm/nouveau/nvif/conn.c
+++ b/drivers/gpu/drm/nouveau/nvif/conn.c
@@ -23,25 +23,23 @@
 #include <nvif/disp.h>
 #include <nvif/printf.h>
 
-#include <nvif/if0011.h>
-
 int
 nvif_conn_event_ctor(struct nvif_conn *conn, const char *name, nvif_event_func func, u8 types,
 		     struct nvif_event *event)
 {
-	struct {
-		struct nvif_event_v0 base;
-		struct nvif_conn_event_v0 conn;
-	} args;
 	int ret;
 
-	args.conn.version = 0;
-	args.conn.types = types;
+	if (!conn->impl->event)
+		return -ENODEV;
 
-	ret = nvif_event_ctor_(&conn->object, name ?: "nvifConnHpd", nvif_conn_id(conn),
-			       func, true, &args.base, sizeof(args), false, event);
-	NVIF_DEBUG(&conn->object, "[NEW EVENT:HPD types:%02x]", types);
-	return ret;
+	ret = conn->impl->event(conn->priv, nvif_handle(&event->object), types,
+				&event->impl, &event->priv);
+	NVIF_ERRON(ret, &conn->object, "[NEW EVENT:HPD types:%02x]", types);
+	if (ret)
+		return ret;
+
+	nvif_event_ctor(&conn->object, name ?: "nvifConnHpd", conn->id, func, event);
+	return 0;
 }
 
 void
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/uconn.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/uconn.c
index 5f72db9276b8..9c7b83c99b80 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/uconn.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/uconn.c
@@ -98,24 +98,15 @@ nvkm_connector_is_dp_dms(u8 type)
 }
 
 static int
-nvkm_uconn_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm_uevent *uevent)
+nvkm_uconn_event(struct nvif_conn_priv *uconn, u64 handle, u8 types,
+		 const struct nvif_event_impl **pimpl, struct nvif_event_priv **ppriv)
 {
-	struct nvkm_conn *conn = container_of(object, struct nvif_conn_priv, object)->conn;
+	struct nvkm_conn *conn = uconn->conn;
 	struct nvkm_disp *disp = conn->disp;
 	struct nvkm_device *device = disp->engine.subdev.device;
 	struct nvkm_outp *outp;
-	union nvif_conn_event_args *args = argv;
 	u64 bits = 0;
 
-	if (!uevent) {
-		if (!disp->rm.client.gsp && conn->info.hpd == DCB_GPIO_UNUSED)
-			return -ENOSYS;
-		return 0;
-	}
-
-	if (argc != sizeof(args->v0) || args->v0.version != 0)
-		return -ENOSYS;
-
 	list_for_each_entry(outp, &conn->disp->outps, head) {
 		if (outp->info.connector == conn->index)
 			break;
@@ -125,33 +116,34 @@ nvkm_uconn_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm_
 		return -EINVAL;
 
 	if (disp->rm.client.gsp) {
-		if (args->v0.types & NVIF_CONN_EVENT_V0_PLUG  ) bits |= NVKM_DPYID_PLUG;
-		if (args->v0.types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_DPYID_UNPLUG;
-		if (args->v0.types & NVIF_CONN_EVENT_V0_IRQ   ) bits |= NVKM_DPYID_IRQ;
+		if (types & NVIF_CONN_EVENT_V0_PLUG  ) bits |= NVKM_DPYID_PLUG;
+		if (types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_DPYID_UNPLUG;
+		if (types & NVIF_CONN_EVENT_V0_IRQ   ) bits |= NVKM_DPYID_IRQ;
 
-		return nvkm_uevent_add(uevent, &disp->rm.event, outp->index, bits,
-				       nvkm_uconn_uevent_gsp);
+		return nvkm_uevent_new_(&uconn->object, handle, &disp->rm.event, true,
+					outp->index, bits, nvkm_uconn_uevent_gsp, pimpl, ppriv);
 	}
 
 	if (outp->dp.aux && !outp->info.location) {
-		if (args->v0.types & NVIF_CONN_EVENT_V0_PLUG  ) bits |= NVKM_I2C_PLUG;
-		if (args->v0.types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_I2C_UNPLUG;
-		if (args->v0.types & NVIF_CONN_EVENT_V0_IRQ   ) bits |= NVKM_I2C_IRQ;
+		if (types & NVIF_CONN_EVENT_V0_PLUG  ) bits |= NVKM_I2C_PLUG;
+		if (types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_I2C_UNPLUG;
+		if (types & NVIF_CONN_EVENT_V0_IRQ   ) bits |= NVKM_I2C_IRQ;
 
-		return nvkm_uevent_add(uevent, &device->i2c->event, outp->dp.aux->id, bits,
-				       nvkm_uconn_uevent_aux);
+		return nvkm_uevent_new_(&uconn->object, handle, &device->i2c->event, true,
+					outp->dp.aux->id, bits, nvkm_uconn_uevent_aux,
+					pimpl, ppriv);
 	}
 
-	if (args->v0.types & NVIF_CONN_EVENT_V0_PLUG  ) bits |= NVKM_GPIO_HI;
-	if (args->v0.types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_GPIO_LO;
-	if (args->v0.types & NVIF_CONN_EVENT_V0_IRQ) {
+	if (types & NVIF_CONN_EVENT_V0_PLUG  ) bits |= NVKM_GPIO_HI;
+	if (types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_GPIO_LO;
+	if (types & NVIF_CONN_EVENT_V0_IRQ) {
 		/* TODO: support DP IRQ on ANX9805 and remove this hack. */
 		if (!outp->info.location && !nvkm_connector_is_dp_dms(conn->info.type))
 			return -EINVAL;
 	}
 
-	return nvkm_uevent_add(uevent, &device->gpio->event, conn->info.hpd, bits,
-			       nvkm_uconn_uevent_gpio);
+	return nvkm_uevent_new_(&uconn->object, handle, &device->gpio->event, true,
+				conn->info.hpd, bits, nvkm_uconn_uevent_gpio, pimpl, ppriv);
 }
 
 static void
@@ -182,7 +174,6 @@ nvkm_uconn_dtor(struct nvkm_object *object)
 static const struct nvkm_object_func
 nvkm_uconn = {
 	.dtor = nvkm_uconn_dtor,
-	.uevent = nvkm_uconn_uevent,
 };
 
 int
@@ -244,6 +235,9 @@ nvkm_uconn_new(struct nvkm_disp *disp, u8 id, const struct nvif_conn_impl **pimp
 	nvkm_object_ctor(&nvkm_uconn, &(struct nvkm_oclass) {}, &uconn->object);
 	uconn->impl = nvkm_uconn_impl;
 	uconn->impl.type = type;
+	if (disp->rm.client.gsp || conn->info.hpd != DCB_GPIO_UNUSED)
+		uconn->impl.event = nvkm_uconn_event;
+
 	uconn->conn = conn;
 
 	*pimpl = &uconn->impl;
-- 
2.41.0



More information about the Nouveau mailing list