[PATCH 054/156] drm/nouveau/nvkm: move umem list to mmu

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


This hack will be removed entirely later in the series, but for now we
need to move it out of client for upcoming changes.

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 .../gpu/drm/nouveau/include/nvkm/core/client.h |  3 ---
 .../gpu/drm/nouveau/include/nvkm/subdev/mmu.h  |  5 ++++-
 drivers/gpu/drm/nouveau/nvkm/core/client.c     |  2 --
 .../gpu/drm/nouveau/nvkm/engine/disp/chan.c    |  2 +-
 .../gpu/drm/nouveau/nvkm/engine/fifo/uchan.c   |  2 +-
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c |  2 ++
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c | 18 +++++++++---------
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c |  4 ++--
 8 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvkm/core/client.h b/drivers/gpu/drm/nouveau/include/nvkm/core/client.h
index 4045b9f5ef4e..f7f195d87838 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/core/client.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/core/client.h
@@ -14,9 +14,6 @@ struct nvkm_client {
 
 	void *data;
 	int (*event)(u64 token, void *argv, u32 argc);
-
-	struct list_head umem;
-	spinlock_t lock;
 };
 
 int  nvkm_client_new(const char *name, u64 device, const char *cfg, const char *dbg,
diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/mmu.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/mmu.h
index 935b1cacd528..f2d23bfdf29a 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/mmu.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/mmu.h
@@ -109,7 +109,7 @@ int nvkm_vmm_map(struct nvkm_vmm *, struct nvkm_vma *, void *argv, u32 argc,
 		 struct nvkm_vmm_map *);
 void nvkm_vmm_unmap(struct nvkm_vmm *, struct nvkm_vma *);
 
-struct nvkm_memory *nvkm_umem_search(struct nvkm_client *, u64);
+struct nvkm_memory *nvkm_umem_search(struct nvkm_mmu *, struct nvkm_client *, u64);
 struct nvkm_vmm *nvkm_uvmm_search(struct nvkm_client *, u64 handle);
 
 struct nvkm_mmu {
@@ -148,6 +148,9 @@ struct nvkm_mmu {
 	struct mutex mutex; /* serialises mmu invalidations */
 
 	struct nvkm_device_oclass user;
+
+	spinlock_t umem_lock;
+	struct list_head umem;
 };
 
 int nv04_mmu_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_mmu **);
diff --git a/drivers/gpu/drm/nouveau/nvkm/core/client.c b/drivers/gpu/drm/nouveau/nvkm/core/client.c
index b127676078b1..7dc425e67dd4 100644
--- a/drivers/gpu/drm/nouveau/nvkm/core/client.c
+++ b/drivers/gpu/drm/nouveau/nvkm/core/client.c
@@ -120,7 +120,5 @@ nvkm_client_new(const char *name, u64 device, const char *cfg, const char *dbg,
 	client->objroot = RB_ROOT;
 	spin_lock_init(&client->obj_lock);
 	client->event = event;
-	INIT_LIST_HEAD(&client->umem);
-	spin_lock_init(&client->lock);
 	return 0;
 }
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c
index b34615dcc8eb..d3c0537c08db 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/chan.c
@@ -234,7 +234,7 @@ nvkm_disp_chan_new_(struct nvkm_disp *disp, int nr, const struct nvkm_oclass *oc
 	*pobject = &uchan->object;
 
 	if (chan->func->push) {
-		chan->memory = nvkm_umem_search(uchan->object.client, args->v0.pushbuf);
+		chan->memory = nvkm_umem_search(disp->engine.subdev.device->mmu, uchan->object.client, args->v0.pushbuf);
 		if (IS_ERR(chan->memory))
 			return PTR_ERR(chan->memory);
 
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c
index 3dbc424869b3..23d992413442 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c
@@ -365,7 +365,7 @@ nvkm_uchan_new(struct nvkm_fifo *fifo, struct nvkm_cgrp *cgrp, const struct nvkm
 	}
 
 	if (args->v0.huserd) {
-		userd = nvkm_umem_search(oclass->client, args->v0.huserd);
+		userd = nvkm_umem_search(fifo->engine.subdev.device->mmu, oclass->client, args->v0.huserd);
 		if (IS_ERR(userd)) {
 			ret = PTR_ERR(userd);
 			userd = NULL;
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
index b67ace7ae93c..7b949a43c372 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/base.c
@@ -428,6 +428,8 @@ nvkm_mmu_ctor(const struct nvkm_mmu_func *func, struct nvkm_device *device,
 	mutex_init(&mmu->mutex);
 	mmu->user.ctor = nvkm_ummu_new;
 	mmu->user.base = func->mmu.user;
+	spin_lock_init(&mmu->umem_lock);
+	INIT_LIST_HEAD(&mmu->umem);
 }
 
 int
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c
index 45ab7e445d58..45f589eb5d78 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c
@@ -48,7 +48,7 @@ struct nvif_mem_priv {
 
 static const struct nvkm_object_func nvkm_umem;
 struct nvkm_memory *
-nvkm_umem_search(struct nvkm_client *client, u64 handle)
+nvkm_umem_search(struct nvkm_mmu *mmu, struct nvkm_client *client, u64 handle)
 {
 	struct nvkm_client *master = client->object.client;
 	struct nvkm_memory *memory = NULL;
@@ -58,14 +58,14 @@ nvkm_umem_search(struct nvkm_client *client, u64 handle)
 	object = nvkm_object_search(client, handle, &nvkm_umem);
 	if (IS_ERR(object)) {
 		if (client != master) {
-			spin_lock(&master->lock);
-			list_for_each_entry(umem, &master->umem, head) {
+			spin_lock(&mmu->umem_lock);
+			list_for_each_entry(umem, &mmu->umem, head) {
 				if (umem->object.object == handle) {
 					memory = nvkm_memory_ref(umem->memory);
 					break;
 				}
 			}
-			spin_unlock(&master->lock);
+			spin_unlock(&mmu->umem_lock);
 		}
 	} else {
 		umem = container_of(object, typeof(*umem), object);
@@ -141,9 +141,9 @@ nvkm_umem_dtor(struct nvkm_object *object)
 {
 	struct nvif_mem_priv *umem = container_of(object, typeof(*umem), object);
 
-	spin_lock(&umem->object.client->lock);
+	spin_lock(&umem->mmu->umem_lock);
 	list_del_init(&umem->head);
-	spin_unlock(&umem->object.client->lock);
+	spin_unlock(&umem->mmu->umem_lock);
 	nvkm_memory_unref(&umem->memory);
 	return umem;
 }
@@ -196,9 +196,9 @@ nvkm_umem_new(const struct nvkm_oclass *oclass, void *argv, u32 argc,
 	if (ret)
 		return ret;
 
-	spin_lock(&umem->object.client->lock);
-	list_add(&umem->head, &umem->object.client->umem);
-	spin_unlock(&umem->object.client->lock);
+	spin_lock(&mmu->umem_lock);
+	list_add(&umem->head, &mmu->umem);
+	spin_unlock(&mmu->umem_lock);
 
 	args->v0.page = nvkm_memory_page(umem->memory);
 	args->v0.addr = nvkm_memory_addr(umem->memory);
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
index 6f261f81a2ad..761a50047b42 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
@@ -178,7 +178,7 @@ nvkm_uvmm_mthd_map(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
 	if (nvkm_vmm_in_managed_range(vmm, addr, size) && vmm->managed.raw)
 		return -EINVAL;
 
-	memory = nvkm_umem_search(client, handle);
+	memory = nvkm_umem_search(vmm->mmu, client, handle);
 	if (IS_ERR(memory)) {
 		VMM_DEBUG(vmm, "memory %016llx %ld\n", handle, PTR_ERR(memory));
 		return PTR_ERR(memory);
@@ -421,7 +421,7 @@ nvkm_uvmm_mthd_raw_map(struct nvkm_uvmm *uvmm, struct nvif_vmm_raw_v0 *args)
 
 	vma.page = vma.refd = refd;
 
-	memory = nvkm_umem_search(client, args->memory);
+	memory = nvkm_umem_search(uvmm->vmm->mmu, client, args->memory);
 	if (IS_ERR(memory)) {
 		VMM_DEBUG(vmm, "memory %016llx %ld\n", handle, PTR_ERR(memory));
 		return PTR_ERR(memory);
-- 
2.41.0



More information about the Nouveau mailing list