[PATCH 051/156] drm/nouveau/nvkm: detach user handling from nvkm_disp_chan

Ben Skeggs bskeggs at nvidia.com
Tue Apr 16 23:38:17 UTC 2024


- preparation for upcoming patches
- open-code current nvkm_disp_chan() macro

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 .../gpu/drm/nouveau/nvkm/engine/disp/chan.c   | 63 +++++++++++++------
 .../gpu/drm/nouveau/nvkm/engine/disp/chan.h   | 11 ++--
 .../gpu/drm/nouveau/nvkm/engine/disp/nv50.c   |  7 +--
 .../gpu/drm/nouveau/nvkm/engine/disp/r535.c   | 20 +++---
 4 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c
index 25fe9946957f..b34615dcc8eb 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c
@@ -23,14 +23,20 @@
 
 #include <core/oproxy.h>
 #include <core/ramht.h>
+#include <subdev/mmu.h>
 
 #include <nvif/if0014.h>
 
+struct nvif_disp_chan_priv {
+	struct nvkm_object object;
+	struct nvkm_disp_chan chan;
+};
+
 static int
 nvkm_disp_chan_ntfy(struct nvkm_object *object, u32 type, struct nvkm_event **pevent)
 {
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
-	struct nvkm_disp *disp = chan->disp;
+	struct nvif_disp_chan_priv *uchan = container_of(object, typeof(*uchan), object);
+	struct nvkm_disp *disp = uchan->chan.disp;
 
 	switch (type) {
 	case 0:
@@ -47,7 +53,8 @@ static int
 nvkm_disp_chan_map(struct nvkm_object *object, void *argv, u32 argc,
 		   enum nvkm_object_map *type, u64 *addr, u64 *size)
 {
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
+	struct nvif_disp_chan_priv *uchan = container_of(object, typeof(*uchan), object);
+	struct nvkm_disp_chan *chan = &uchan->chan;
 	struct nvkm_device *device = chan->disp->engine.subdev.device;
 	const u64 base = device->func->resource_addr(device, 0);
 
@@ -79,7 +86,8 @@ static int
 nvkm_disp_chan_child_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 			 struct nvkm_object **pobject)
 {
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(oclass->parent);
+	struct nvif_disp_chan_priv *uchan = container_of(oclass->parent, typeof(*uchan), object);
+	struct nvkm_disp_chan *chan = &uchan->chan;
 	struct nvkm_disp *disp = chan->disp;
 	struct nvkm_device *device = disp->engine.subdev.device;
 	const struct nvkm_device_oclass *sclass = oclass->priv;
@@ -106,7 +114,8 @@ nvkm_disp_chan_child_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 static int
 nvkm_disp_chan_child_get(struct nvkm_object *object, int index, struct nvkm_oclass *sclass)
 {
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
+	struct nvif_disp_chan_priv *uchan = container_of(object, typeof(*uchan), object);
+	struct nvkm_disp_chan *chan = &uchan->chan;
 	struct nvkm_device *device = chan->disp->engine.subdev.device;
 	const struct nvkm_device_oclass *oclass = NULL;
 
@@ -130,7 +139,8 @@ nvkm_disp_chan_child_get(struct nvkm_object *object, int index, struct nvkm_ocla
 static int
 nvkm_disp_chan_fini(struct nvkm_object *object, bool suspend)
 {
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
+	struct nvif_disp_chan_priv *uchan = container_of(object, typeof(*uchan), object);
+	struct nvkm_disp_chan *chan = &uchan->chan;
 
 	chan->func->fini(chan);
 	chan->func->intr(chan, false);
@@ -140,7 +150,8 @@ nvkm_disp_chan_fini(struct nvkm_object *object, bool suspend)
 static int
 nvkm_disp_chan_init(struct nvkm_object *object)
 {
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
+	struct nvif_disp_chan_priv *uchan = container_of(object, typeof(*uchan), object);
+	struct nvkm_disp_chan *chan = &uchan->chan;
 
 	chan->func->intr(chan, true);
 	return chan->func->init(chan);
@@ -149,16 +160,17 @@ nvkm_disp_chan_init(struct nvkm_object *object)
 static void *
 nvkm_disp_chan_dtor(struct nvkm_object *object)
 {
-	struct nvkm_disp_chan *chan = nvkm_disp_chan(object);
+
+	struct nvif_disp_chan_priv *uchan = container_of(object, typeof(*uchan), object);
+	struct nvkm_disp_chan *chan = &uchan->chan;
 	struct nvkm_disp *disp = chan->disp;
 
 	spin_lock(&disp->user.lock);
-	if (disp->chan[chan->chid.user] == chan)
-		disp->chan[chan->chid.user] = NULL;
+	disp->chan[chan->chid.user] = NULL;
 	spin_unlock(&disp->user.lock);
 
 	nvkm_memory_unref(&chan->memory);
-	return chan;
+	return uchan;
 }
 
 static const struct nvkm_object_func
@@ -176,6 +188,7 @@ nvkm_disp_chan_new_(struct nvkm_disp *disp, int nr, const struct nvkm_oclass *oc
 		    void *argv, u32 argc, struct nvkm_object **pobject)
 {
 	const struct nvkm_disp_chan_user *user = NULL;
+	struct nvif_disp_chan_priv *uchan;
 	struct nvkm_disp_chan *chan;
 	union nvif_disp_chan_args *args = argv;
 	int ret, i;
@@ -195,11 +208,12 @@ nvkm_disp_chan_new_(struct nvkm_disp *disp, int nr, const struct nvkm_oclass *oc
 	if (args->v0.id >= nr || !args->v0.pushbuf != !user->func->push)
 		return -EINVAL;
 
-	if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
+	uchan = kzalloc(sizeof(*uchan), GFP_KERNEL);
+	if (!uchan)
 		return -ENOMEM;
-	*pobject = &chan->object;
+	chan = &uchan->chan;
 
-	nvkm_object_ctor(&nvkm_disp_chan, oclass, &chan->object);
+	nvkm_object_ctor(&nvkm_disp_chan, oclass, &uchan->object);
 	chan->func = user->func;
 	chan->mthd = user->mthd;
 	chan->disp = disp;
@@ -207,19 +221,28 @@ nvkm_disp_chan_new_(struct nvkm_disp *disp, int nr, const struct nvkm_oclass *oc
 	chan->chid.user = user->user + args->v0.id;
 	chan->head = args->v0.id;
 
-	if (chan->func->push) {
-		ret = chan->func->push(chan, args->v0.pushbuf);
-		if (ret)
-			return ret;
-	}
-
 	spin_lock(&disp->user.lock);
 	if (disp->chan[chan->chid.user]) {
 		spin_unlock(&disp->user.lock);
+		kfree(uchan);
 		return -EBUSY;
 	}
 	disp->chan[chan->chid.user] = chan;
+	chan->user.oclass = oclass->base.oclass;
 	spin_unlock(&disp->user.lock);
+
+	*pobject = &uchan->object;
+
+	if (chan->func->push) {
+		chan->memory = nvkm_umem_search(uchan->object.client, args->v0.pushbuf);
+		if (IS_ERR(chan->memory))
+			return PTR_ERR(chan->memory);
+
+		ret = chan->func->push(chan);
+		if (ret)
+			return ret;
+	}
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.h b/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.h
index 020290510157..8c212dde036f 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.h
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.h
@@ -1,7 +1,6 @@
 /* SPDX-License-Identifier: MIT */
 #ifndef __NVKM_DISP_CHAN_H__
 #define __NVKM_DISP_CHAN_H__
-#define nvkm_disp_chan(p) container_of((p), struct nvkm_disp_chan, object)
 #include <core/object.h>
 #include "priv.h"
 
@@ -16,8 +15,6 @@ struct nvkm_disp_chan {
 	} chid;
 	int head;
 
-	struct nvkm_object object;
-
 	struct nvkm_memory *memory;
 	u64 push;
 
@@ -26,6 +23,10 @@ struct nvkm_disp_chan {
 	struct {
 		struct nvkm_gsp_object object;
 	} rm;
+
+	struct {
+		s32 oclass;
+	} user;
 };
 
 int nvkm_disp_core_new(const struct nvkm_oclass *, void *, u32, struct nvkm_object **);
@@ -33,7 +34,7 @@ int nvkm_disp_chan_new(const struct nvkm_oclass *, void *, u32, struct nvkm_obje
 int nvkm_disp_wndw_new(const struct nvkm_oclass *, void *, u32, struct nvkm_object **);
 
 struct nvkm_disp_chan_func {
-	int (*push)(struct nvkm_disp_chan *, u64 object);
+	int (*push)(struct nvkm_disp_chan *);
 	int (*init)(struct nvkm_disp_chan *);
 	void (*fini)(struct nvkm_disp_chan *);
 	void (*intr)(struct nvkm_disp_chan *, bool en);
@@ -45,7 +46,7 @@ void nv50_disp_chan_intr(struct nvkm_disp_chan *, bool);
 u64 nv50_disp_chan_user(struct nvkm_disp_chan *, u64 *);
 extern const struct nvkm_disp_chan_func nv50_disp_pioc_func;
 extern const struct nvkm_disp_chan_func nv50_disp_dmac_func;
-int nv50_disp_dmac_push(struct nvkm_disp_chan *, u64);
+int nv50_disp_dmac_push(struct nvkm_disp_chan *);
 int nv50_disp_dmac_bind(struct nvkm_disp_chan *, struct nvkm_object *, u32);
 extern const struct nvkm_disp_chan_func nv50_disp_core_func;
 
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
index 03a5f88a4b99..682628fe5b20 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
@@ -37,7 +37,6 @@
 #include <subdev/bios/pll.h>
 #include <subdev/devinit.h>
 #include <subdev/i2c.h>
-#include <subdev/mmu.h>
 #include <subdev/timer.h>
 
 #include <nvif/class.h>
@@ -681,12 +680,8 @@ nv50_disp_dmac_init(struct nvkm_disp_chan *chan)
 }
 
 int
-nv50_disp_dmac_push(struct nvkm_disp_chan *chan, u64 object)
+nv50_disp_dmac_push(struct nvkm_disp_chan *chan)
 {
-	chan->memory = nvkm_umem_search(chan->object.client, object);
-	if (IS_ERR(chan->memory))
-		return PTR_ERR(chan->memory);
-
 	if (nvkm_memory_size(chan->memory) < 0x1000)
 		return -EINVAL;
 
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/r535.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/r535.c
index 027867c2a8c5..f94858bc64f9 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/r535.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/r535.c
@@ -53,7 +53,7 @@
 static u64
 r535_chan_user(struct nvkm_disp_chan *chan, u64 *psize)
 {
-	switch (chan->object.oclass & 0xff) {
+	switch (chan->user.oclass & 0xff) {
 	case 0x7d: *psize = 0x10000; return 0x680000;
 	case 0x7e: *psize = 0x01000; return 0x690000 + (chan->head * *psize);
 	case 0x7b: *psize = 0x01000; return 0x6b0000 + (chan->head * *psize);
@@ -111,9 +111,9 @@ r535_chan_push(struct nvkm_disp_chan *chan)
 		ctrl->limit = nvkm_memory_size(chan->memory) - 1;
 	}
 
-	ctrl->hclass = chan->object.oclass;
+	ctrl->hclass = chan->user.oclass;
 	ctrl->channelInstance = chan->head;
-	ctrl->valid = ((chan->object.oclass & 0xff) != 0x7a) ? 1 : 0;
+	ctrl->valid = ((chan->user.oclass & 0xff) != 0x7a) ? 1 : 0;
 
 	return nvkm_gsp_rm_ctrl_wr(&gsp->internal.device.subdevice, ctrl);
 }
@@ -129,8 +129,8 @@ r535_curs_init(struct nvkm_disp_chan *chan)
 		return ret;
 
 	args = nvkm_gsp_rm_alloc_get(&chan->disp->rm.object,
-				     (chan->object.oclass << 16) | chan->head,
-				     chan->object.oclass, sizeof(*args), &chan->rm.object);
+				     (chan->user.oclass << 16) | chan->head,
+				     chan->user.oclass, sizeof(*args), &chan->rm.object);
 	if (IS_ERR(args))
 		return PTR_ERR(args);
 
@@ -182,8 +182,8 @@ r535_dmac_init(struct nvkm_disp_chan *chan)
 		return ret;
 
 	args = nvkm_gsp_rm_alloc_get(&chan->disp->rm.object,
-				     (chan->object.oclass << 16) | chan->head,
-				     chan->object.oclass, sizeof(*args), &chan->rm.object);
+				     (chan->user.oclass << 16) | chan->head,
+				     chan->user.oclass, sizeof(*args), &chan->rm.object);
 	if (IS_ERR(args))
 		return PTR_ERR(args);
 
@@ -194,12 +194,8 @@ r535_dmac_init(struct nvkm_disp_chan *chan)
 }
 
 static int
-r535_dmac_push(struct nvkm_disp_chan *chan, u64 memory)
+r535_dmac_push(struct nvkm_disp_chan *chan)
 {
-	chan->memory = nvkm_umem_search(chan->object.client, memory);
-	if (IS_ERR(chan->memory))
-		return PTR_ERR(chan->memory);
-
 	return 0;
 }
 
-- 
2.41.0



More information about the Nouveau mailing list