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

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


- transition from "ioctl" interfaces

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 .../gpu/drm/nouveau/include/nvif/driverif.h   |  3 ++
 drivers/gpu/drm/nouveau/include/nvif/if000c.h |  2 -
 drivers/gpu/drm/nouveau/nvif/vmm.c            | 28 +------------
 .../gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c    | 39 +++++++------------
 4 files changed, 19 insertions(+), 53 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
index 65958649f08c..1cea0a07b2e8 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
@@ -139,6 +139,9 @@ struct nvif_vmm_impl {
 	struct {
 		int (*get)(struct nvif_vmm_priv *, u8 shift, u64 addr, u64 size);
 		int (*put)(struct nvif_vmm_priv *, u8 shift, u64 addr, u64 size);
+		int (*map)(struct nvif_vmm_priv *, u8 shift, u64 addr, u64 size, void *, u32,
+			   struct nvif_mem_priv *, u64 offset);
+		int (*unmap)(struct nvif_vmm_priv *, u8 shift, u64 addr, u64 size, bool sparse);
 	} raw;
 };
 
diff --git a/drivers/gpu/drm/nouveau/include/nvif/if000c.h b/drivers/gpu/drm/nouveau/include/nvif/if000c.h
index c81fae28395a..232cc1142798 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/if000c.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/if000c.h
@@ -6,8 +6,6 @@
 
 struct nvif_vmm_raw_v0 {
 	__u8 version;
-#define NVIF_VMM_RAW_V0_MAP	0x2
-#define NVIF_VMM_RAW_V0_UNMAP	0x3
 #define NVIF_VMM_RAW_V0_SPARSE	0x4
 	__u8  op;
 	__u8  sparse;
diff --git a/drivers/gpu/drm/nouveau/nvif/vmm.c b/drivers/gpu/drm/nouveau/nvif/vmm.c
index d7ca6afaeb04..16c6aaa81326 100644
--- a/drivers/gpu/drm/nouveau/nvif/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvif/vmm.c
@@ -81,38 +81,14 @@ int
 nvif_vmm_raw_map(struct nvif_vmm *vmm, u64 addr, u64 size, u8 shift,
 		 void *argv, u32 argc, struct nvif_mem *mem, u64 offset)
 {
-	struct nvif_vmm_raw_v0 args = {
-		.version = 0,
-		.op = NVIF_VMM_RAW_V0_MAP,
-		.addr = addr,
-		.size = size,
-		.shift = shift,
-		.memory = nvif_handle(&mem->object),
-		.offset = offset,
-		.argv = (u64)(uintptr_t)argv,
-		.argc = argc,
-	};
-
-
-	return nvif_object_mthd(&vmm->object, NVIF_VMM_V0_RAW,
-				&args, sizeof(args));
+	return vmm->impl->raw.map(vmm->priv, shift, addr, size, argv, argc, mem->priv, offset);
 }
 
 int
 nvif_vmm_raw_unmap(struct nvif_vmm *vmm, u64 addr, u64 size,
 		   u8 shift, bool sparse)
 {
-	struct nvif_vmm_raw_v0 args = {
-		.version = 0,
-		.op = NVIF_VMM_RAW_V0_UNMAP,
-		.addr = addr,
-		.size = size,
-		.shift = shift,
-		.sparse = sparse,
-	};
-
-	return nvif_object_mthd(&vmm->object, NVIF_VMM_V0_RAW,
-				&args, sizeof(args));
+	return vmm->impl->raw.unmap(vmm->priv, shift, addr, size, sparse);
 }
 
 int
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
index 51c7e0fd7876..7c8a7a5dc3f9 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
@@ -296,40 +296,33 @@ nvkm_uvmm_raw_put(struct nvif_vmm_priv *uvmm, u8 shift, u64 addr, u64 size)
 }
 
 static int
-nvkm_uvmm_mthd_raw_map(struct nvkm_uvmm *uvmm, struct nvif_vmm_raw_v0 *args)
+nvkm_uvmm_raw_map(struct nvif_vmm_priv *uvmm, u8 shift, u64 addr, u64 size, void *argv, u32 argc,
+		  struct nvif_mem_priv *umem, u64 offset)
 {
-	struct nvkm_client *client = uvmm->object.client;
 	struct nvkm_vmm *vmm = uvmm->vmm;
 	struct nvkm_vma vma = {
-		.addr = args->addr,
-		.size = args->size,
+		.addr = addr,
+		.size = size,
 		.used = true,
 		.mapref = false,
 		.no_comp = true,
 	};
 	struct nvkm_memory *memory;
-	void *argv = (void *)(uintptr_t)args->argv;
-	unsigned int argc = args->argc;
-	u64 handle = args->memory;
 	u8 refd;
 	int ret;
 
-	if (!nvkm_vmm_in_managed_range(vmm, args->addr, args->size))
+	if (!nvkm_vmm_in_managed_range(vmm, addr, size))
 		return -EINVAL;
 
-	ret = nvkm_uvmm_page_index(uvmm, args->size, args->shift, &refd);
+	ret = nvkm_uvmm_page_index(uvmm, size, shift, &refd);
 	if (ret)
 		return ret;
 
 	vma.page = vma.refd = refd;
 
-	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);
-	}
+	memory = nvkm_umem_ref(umem);
 
-	ret = nvkm_memory_map(memory, args->offset, vmm, &vma, argv, argc);
+	ret = nvkm_memory_map(memory, offset, vmm, &vma, argv, argc);
 
 	nvkm_memory_unref(&vma.memory);
 	nvkm_memory_unref(&memory);
@@ -337,22 +330,20 @@ nvkm_uvmm_mthd_raw_map(struct nvkm_uvmm *uvmm, struct nvif_vmm_raw_v0 *args)
 }
 
 static int
-nvkm_uvmm_mthd_raw_unmap(struct nvkm_uvmm *uvmm, struct nvif_vmm_raw_v0 *args)
+nvkm_uvmm_raw_unmap(struct nvif_vmm_priv *uvmm, u8 shift, u64 addr, u64 size, bool sparse)
 {
 	struct nvkm_vmm *vmm = uvmm->vmm;
 	u8 refd;
 	int ret;
 
-	if (!nvkm_vmm_in_managed_range(vmm, args->addr, args->size))
+	if (!nvkm_vmm_in_managed_range(vmm, addr, size))
 		return -EINVAL;
 
-	ret = nvkm_uvmm_page_index(uvmm, args->size, args->shift, &refd);
+	ret = nvkm_uvmm_page_index(uvmm, size, shift, &refd);
 	if (ret)
 		return ret;
 
-	nvkm_vmm_raw_unmap(vmm, args->addr, args->size,
-			   args->sparse, refd);
-
+	nvkm_vmm_raw_unmap(vmm, addr, size, sparse, refd);
 	return 0;
 }
 
@@ -382,10 +373,6 @@ nvkm_uvmm_mthd_raw(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
 		return ret;
 
 	switch (args->v0.op) {
-	case NVIF_VMM_RAW_V0_MAP:
-		return nvkm_uvmm_mthd_raw_map(uvmm, &args->v0);
-	case NVIF_VMM_RAW_V0_UNMAP:
-		return nvkm_uvmm_mthd_raw_unmap(uvmm, &args->v0);
 	case NVIF_VMM_RAW_V0_SPARSE:
 		return nvkm_uvmm_mthd_raw_sparse(uvmm, &args->v0);
 	default:
@@ -431,6 +418,8 @@ nvkm_uvmm_impl = {
 	.pfnclr = nvkm_uvmm_pfnclr,
 	.raw.get = nvkm_uvmm_raw_get,
 	.raw.put = nvkm_uvmm_raw_put,
+	.raw.map = nvkm_uvmm_raw_map,
+	.raw.unmap = nvkm_uvmm_raw_unmap,
 };
 
 static void *
-- 
2.41.0



More information about the Nouveau mailing list