[PATCH 089/156] drm/nouveau/nvif: rework vmm "map"/"unmap" apis

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


- transition from "ioctl" interfaces

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 .../gpu/drm/nouveau/include/nvif/driverif.h   |  4 ++
 drivers/gpu/drm/nouveau/include/nvif/if000c.h | 18 --------
 drivers/gpu/drm/nouveau/nvif/vmm.c            | 28 +------------
 .../gpu/drm/nouveau/nvkm/subdev/mmu/umem.c    |  9 ++++
 .../gpu/drm/nouveau/nvkm/subdev/mmu/umem.h    |  1 +
 .../gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c    | 41 ++++---------------
 6 files changed, 24 insertions(+), 77 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
index 673969d46b66..94d0fb23ed2f 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
@@ -119,6 +119,10 @@ struct nvif_vmm_impl {
 	int (*get)(struct nvif_vmm_priv *, enum nvif_vmm_get_type, bool sparse, u8 page,
 		   u8 align, u64 size, u64 *addr);
 	int (*put)(struct nvif_vmm_priv *, u64 addr);
+
+	int (*map)(struct nvif_vmm_priv *, u64 addr, u64 size, void *, u32,
+		   struct nvif_mem_priv *, u64 offset);
+	int (*unmap)(struct nvif_vmm_priv *, u64 addr);
 };
 
 struct nvif_mmu_impl {
diff --git a/drivers/gpu/drm/nouveau/include/nvif/if000c.h b/drivers/gpu/drm/nouveau/include/nvif/if000c.h
index 50a834d5eb19..9b979fa5c7ac 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/if000c.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/if000c.h
@@ -1,29 +1,11 @@
 #ifndef __NVIF_IF000C_H__
 #define __NVIF_IF000C_H__
 
-#define NVIF_VMM_V0_MAP                                                    0x03
-#define NVIF_VMM_V0_UNMAP                                                  0x04
 #define NVIF_VMM_V0_PFNMAP                                                 0x05
 #define NVIF_VMM_V0_PFNCLR                                                 0x06
 #define NVIF_VMM_V0_RAW                                                    0x07
 #define NVIF_VMM_V0_MTHD(i)                                         ((i) + 0x80)
 
-struct nvif_vmm_map_v0 {
-	__u8  version;
-	__u8  pad01[7];
-	__u64 addr;
-	__u64 size;
-	__u64 memory;
-	__u64 offset;
-	__u8  data[];
-};
-
-struct nvif_vmm_unmap_v0 {
-	__u8  version;
-	__u8  pad01[7];
-	__u64 addr;
-};
-
 struct nvif_vmm_raw_v0 {
 	__u8 version;
 #define NVIF_VMM_RAW_V0_GET	0x0
diff --git a/drivers/gpu/drm/nouveau/nvif/vmm.c b/drivers/gpu/drm/nouveau/nvif/vmm.c
index cf00e7af6063..6821d8657e12 100644
--- a/drivers/gpu/drm/nouveau/nvif/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvif/vmm.c
@@ -29,38 +29,14 @@
 int
 nvif_vmm_unmap(struct nvif_vmm *vmm, u64 addr)
 {
-	return nvif_object_mthd(&vmm->object, NVIF_VMM_V0_UNMAP,
-				&(struct nvif_vmm_unmap_v0) { .addr = addr },
-				sizeof(struct nvif_vmm_unmap_v0));
+	return vmm->impl->unmap(vmm->priv, addr);
 }
 
 int
 nvif_vmm_map(struct nvif_vmm *vmm, u64 addr, u64 size, void *argv, u32 argc,
 	     struct nvif_mem *mem, u64 offset)
 {
-	struct nvif_vmm_map_v0 *args;
-	u8 stack[48];
-	int ret;
-
-	if (sizeof(*args) + argc > sizeof(stack)) {
-		if (!(args = kmalloc(sizeof(*args) + argc, GFP_KERNEL)))
-			return -ENOMEM;
-	} else {
-		args = (void *)stack;
-	}
-
-	args->version = 0;
-	args->addr = addr;
-	args->size = size;
-	args->memory = nvif_handle(&mem->object);
-	args->offset = offset;
-	memcpy(args->data, argv, argc);
-
-	ret = nvif_object_mthd(&vmm->object, NVIF_VMM_V0_MAP,
-			       args, sizeof(*args) + argc);
-	if (args != (void *)stack)
-		kfree(args);
-	return ret;
+	return vmm->impl->map(vmm->priv, addr, size, argv, argc, mem->priv, offset);
 }
 
 void
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c
index 6756e3e207d9..0676615093bb 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.c
@@ -48,6 +48,15 @@ struct nvif_mem_priv {
 	struct nvif_mem_impl impl;
 };
 
+struct nvkm_memory *
+nvkm_umem_ref(struct nvif_mem_priv *umem)
+{
+	if (umem)
+		return nvkm_memory_ref(umem->memory);
+
+	return NULL;
+}
+
 static const struct nvkm_object_func nvkm_umem;
 struct nvkm_memory *
 nvkm_umem_search(struct nvkm_mmu *mmu, struct nvkm_client *client, u64 handle)
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.h b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.h
index df7017eb98f4..a548a578758f 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/umem.h
@@ -5,4 +5,5 @@
 
 int nvkm_umem_new(struct nvkm_mmu *, u8 type, u8 page, u64 size, void *, u32,
 		  const struct nvif_mem_impl **, struct nvif_mem_priv **, struct nvkm_object **);
+struct nvkm_memory *nvkm_umem_ref(struct nvif_mem_priv *);
 #endif
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
index 066e068589eb..dae965fe2977 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
@@ -113,20 +113,11 @@ nvkm_uvmm_mthd_pfnmap(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
 }
 
 static int
-nvkm_uvmm_mthd_unmap(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
+nvkm_uvmm_unmap(struct nvif_vmm_priv *uvmm, u64 addr)
 {
-	union {
-		struct nvif_vmm_unmap_v0 v0;
-	} *args = argv;
 	struct nvkm_vmm *vmm = uvmm->vmm;
 	struct nvkm_vma *vma;
-	int ret = -ENOSYS;
-	u64 addr;
-
-	if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
-		addr = args->v0.addr;
-	} else
-		return ret;
+	int ret;
 
 	if (nvkm_vmm_in_managed_range(vmm, addr, 0) && vmm->managed.raw)
 		return -EINVAL;
@@ -157,34 +148,18 @@ nvkm_uvmm_mthd_unmap(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
 }
 
 static int
-nvkm_uvmm_mthd_map(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
+nvkm_uvmm_map(struct nvif_vmm_priv *uvmm, u64 addr, u64 size, void *argv, u32 argc,
+	      struct nvif_mem_priv *mem, u64 offset)
 {
-	struct nvkm_client *client = uvmm->object.client;
-	union {
-		struct nvif_vmm_map_v0 v0;
-	} *args = argv;
-	u64 addr, size, handle, offset;
 	struct nvkm_vmm *vmm = uvmm->vmm;
 	struct nvkm_vma *vma;
 	struct nvkm_memory *memory;
-	int ret = -ENOSYS;
-
-	if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, true))) {
-		addr = args->v0.addr;
-		size = args->v0.size;
-		handle = args->v0.memory;
-		offset = args->v0.offset;
-	} else
-		return ret;
+	int ret;
 
 	if (nvkm_vmm_in_managed_range(vmm, addr, size) && vmm->managed.raw)
 		return -EINVAL;
 
-	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);
-	}
+	memory = nvkm_umem_ref(mem);
 
 	mutex_lock(&vmm->mutex.vmm);
 	if (ret = -ENOENT, !(vma = nvkm_vmm_node_search(vmm, addr))) {
@@ -452,8 +427,6 @@ nvkm_uvmm_mthd(struct nvkm_object *object, u32 mthd, void *argv, u32 argc)
 {
 	struct nvif_vmm_priv *uvmm = container_of(object, typeof(*uvmm), object);
 	switch (mthd) {
-	case NVIF_VMM_V0_MAP   : return nvkm_uvmm_mthd_map   (uvmm, argv, argc);
-	case NVIF_VMM_V0_UNMAP : return nvkm_uvmm_mthd_unmap (uvmm, argv, argc);
 	case NVIF_VMM_V0_PFNMAP: return nvkm_uvmm_mthd_pfnmap(uvmm, argv, argc);
 	case NVIF_VMM_V0_PFNCLR: return nvkm_uvmm_mthd_pfnclr(uvmm, argv, argc);
 	case NVIF_VMM_V0_RAW   : return nvkm_uvmm_mthd_raw   (uvmm, argv, argc);
@@ -483,6 +456,8 @@ nvkm_uvmm_impl = {
 	.del = nvkm_uvmm_del,
 	.get = nvkm_uvmm_get,
 	.put = nvkm_uvmm_put,
+	.map = nvkm_uvmm_map,
+	.unmap = nvkm_uvmm_unmap,
 };
 
 static void *
-- 
2.41.0



More information about the Nouveau mailing list