[PATCH 088/156] drm/nouveau/nvif: rework vmm "get"/"put" apis

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


- transition from "ioctl" interfaces

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 .../gpu/drm/nouveau/include/nvif/driverif.h   | 10 ++++
 drivers/gpu/drm/nouveau/include/nvif/if000c.h | 22 ---------
 drivers/gpu/drm/nouveau/include/nvif/vmm.h    | 10 +---
 drivers/gpu/drm/nouveau/nouveau_bo.c          |  4 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c         |  2 +-
 drivers/gpu/drm/nouveau/nouveau_vmm.c         |  4 +-
 drivers/gpu/drm/nouveau/nvif/vmm.c            | 38 ++++-----------
 .../gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c    | 46 +++++--------------
 8 files changed, 39 insertions(+), 97 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
index 7540fe4d02c0..673969d46b66 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
@@ -95,6 +95,12 @@ enum nvif_vmm_type {
 	NVIF_VMM_TYPE_RAW,
 };
 
+enum nvif_vmm_get_type {
+	NVIF_VMM_GET_ADDR,
+	NVIF_VMM_GET_PTES,
+	NVIF_VMM_GET_LAZY,
+};
+
 struct nvif_vmm_impl {
 	void (*del)(struct nvif_vmm_priv *);
 
@@ -109,6 +115,10 @@ struct nvif_vmm_impl {
 		bool host;
 		bool comp;
 	} page[8];
+
+	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);
 };
 
 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 f554062469c3..50a834d5eb19 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/if000c.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/if000c.h
@@ -1,8 +1,6 @@
 #ifndef __NVIF_IF000C_H__
 #define __NVIF_IF000C_H__
 
-#define NVIF_VMM_V0_GET                                                    0x01
-#define NVIF_VMM_V0_PUT                                                    0x02
 #define NVIF_VMM_V0_MAP                                                    0x03
 #define NVIF_VMM_V0_UNMAP                                                  0x04
 #define NVIF_VMM_V0_PFNMAP                                                 0x05
@@ -10,26 +8,6 @@
 #define NVIF_VMM_V0_RAW                                                    0x07
 #define NVIF_VMM_V0_MTHD(i)                                         ((i) + 0x80)
 
-struct nvif_vmm_get_v0 {
-	__u8  version;
-#define NVIF_VMM_GET_V0_ADDR                                               0x00
-#define NVIF_VMM_GET_V0_PTES                                               0x01
-#define NVIF_VMM_GET_V0_LAZY	                                           0x02
-	__u8  type;
-	__u8  sparse;
-	__u8  page;
-	__u8  align;
-	__u8  pad05[3];
-	__u64 size;
-	__u64 addr;
-};
-
-struct nvif_vmm_put_v0 {
-	__u8  version;
-	__u8  pad01[7];
-	__u64 addr;
-};
-
 struct nvif_vmm_map_v0 {
 	__u8  version;
 	__u8  pad01[7];
diff --git a/drivers/gpu/drm/nouveau/include/nvif/vmm.h b/drivers/gpu/drm/nouveau/include/nvif/vmm.h
index 3019ddc98782..375d19345482 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/vmm.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/vmm.h
@@ -1,16 +1,10 @@
 #ifndef __NVIF_VMM_H__
 #define __NVIF_VMM_H__
 #include <nvif/object.h>
-#include <nvif/driverif.h> /* NVIF_VMM_TYPE */
+#include <nvif/driverif.h> /* NVIF_VMM_TYPE_*, NVIF_VMM_GET_* */
 struct nvif_mem;
 struct nvif_mmu;
 
-enum nvif_vmm_get {
-	ADDR,
-	PTES,
-	LAZY
-};
-
 struct nvif_vma {
 	u64 addr;
 	u64 size;
@@ -26,7 +20,7 @@ int nvif_vmm_ctor(struct nvif_mmu *, const char *name,
 		  enum nvif_vmm_type, u64 addr, u64 size, void *argv, u32 argc,
 		  struct nvif_vmm *);
 void nvif_vmm_dtor(struct nvif_vmm *);
-int nvif_vmm_get(struct nvif_vmm *, enum nvif_vmm_get, bool sparse,
+int nvif_vmm_get(struct nvif_vmm *, enum nvif_vmm_get_type, bool sparse,
 		 u8 page, u8 align, u64 size, struct nvif_vma *);
 void nvif_vmm_put(struct nvif_vmm *, struct nvif_vma *);
 int nvif_vmm_map(struct nvif_vmm *, u64 addr, u64 size, void *argv, u32 argc,
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index ed81872e2dba..7db05d6699d8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -835,12 +835,12 @@ nouveau_bo_move_prep(struct nouveau_drm *drm, struct ttm_buffer_object *bo,
 	struct nvif_vmm *vmm = &drm->client.vmm.vmm;
 	int ret;
 
-	ret = nvif_vmm_get(vmm, LAZY, false, old_mem->mem.impl->page, 0,
+	ret = nvif_vmm_get(vmm, NVIF_VMM_GET_LAZY, false, old_mem->mem.impl->page, 0,
 			   old_mem->mem.impl->size, &old_mem->vma[0]);
 	if (ret)
 		return ret;
 
-	ret = nvif_vmm_get(vmm, LAZY, false, new_mem->mem.impl->page, 0,
+	ret = nvif_vmm_get(vmm, NVIF_VMM_GET_LAZY, false, new_mem->mem.impl->page, 0,
 			   new_mem->mem.impl->size, &old_mem->vma[1]);
 	if (ret)
 		goto done;
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 2d6f1c97db1c..fc1d6fd94480 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -138,7 +138,7 @@ nv04_gart_manager_new(struct ttm_resource_manager *man,
 
 	mem = nouveau_mem(*res);
 	ttm_resource_init(bo, place, *res);
-	ret = nvif_vmm_get(&drm->cli.vmm.vmm, PTES, false, 12, 0,
+	ret = nvif_vmm_get(&drm->cli.vmm.vmm, NVIF_VMM_GET_PTES, false, 12, 0,
 			   (long)(*res)->size, &mem->vma[0]);
 	if (ret) {
 		nouveau_mem_del(man, *res);
diff --git a/drivers/gpu/drm/nouveau/nouveau_vmm.c b/drivers/gpu/drm/nouveau/nouveau_vmm.c
index 353c1a3f9714..94dd0bf547dc 100644
--- a/drivers/gpu/drm/nouveau/nouveau_vmm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_vmm.c
@@ -98,7 +98,7 @@ nouveau_vma_new(struct nouveau_bo *nvbo, struct nouveau_vmm *vmm,
 
 	if (nvbo->bo.resource->mem_type != TTM_PL_SYSTEM &&
 	    mem->mem.impl->page == nvbo->page) {
-		ret = nvif_vmm_get(&vmm->vmm, LAZY, false, mem->mem.impl->page, 0,
+		ret = nvif_vmm_get(&vmm->vmm, NVIF_VMM_GET_LAZY, false, mem->mem.impl->page, 0,
 				   mem->mem.impl->size, &tmp);
 		if (ret)
 			goto done;
@@ -106,7 +106,7 @@ nouveau_vma_new(struct nouveau_bo *nvbo, struct nouveau_vmm *vmm,
 		vma->addr = tmp.addr;
 		ret = nouveau_vma_map(vma, mem);
 	} else {
-		ret = nvif_vmm_get(&vmm->vmm, PTES, false, mem->mem.impl->page, 0,
+		ret = nvif_vmm_get(&vmm->vmm, NVIF_VMM_GET_PTES, false, mem->mem.impl->page, 0,
 				   mem->mem.impl->size, &tmp);
 		if (ret)
 			goto done;
diff --git a/drivers/gpu/drm/nouveau/nvif/vmm.c b/drivers/gpu/drm/nouveau/nvif/vmm.c
index 73c63bfd1e38..cf00e7af6063 100644
--- a/drivers/gpu/drm/nouveau/nvif/vmm.c
+++ b/drivers/gpu/drm/nouveau/nvif/vmm.c
@@ -66,44 +66,26 @@ nvif_vmm_map(struct nvif_vmm *vmm, u64 addr, u64 size, void *argv, u32 argc,
 void
 nvif_vmm_put(struct nvif_vmm *vmm, struct nvif_vma *vma)
 {
-	if (vma->size) {
-		WARN_ON(nvif_object_mthd(&vmm->object, NVIF_VMM_V0_PUT,
-					 &(struct nvif_vmm_put_v0) {
-						.addr = vma->addr,
-					 }, sizeof(struct nvif_vmm_put_v0)));
+	if (vmm && vma->size) {
+		WARN_ON(vmm->impl->put(vmm->priv, vma->addr));
 		vma->size = 0;
 	}
 }
 
 int
-nvif_vmm_get(struct nvif_vmm *vmm, enum nvif_vmm_get type, bool sparse,
+nvif_vmm_get(struct nvif_vmm *vmm, enum nvif_vmm_get_type type, bool sparse,
 	     u8 page, u8 align, u64 size, struct nvif_vma *vma)
 {
-	struct nvif_vmm_get_v0 args;
 	int ret;
 
-	args.version = vma->size = 0;
-	args.sparse = sparse;
-	args.page = page;
-	args.align = align;
-	args.size = size;
-
-	switch (type) {
-	case ADDR: args.type = NVIF_VMM_GET_V0_ADDR; break;
-	case PTES: args.type = NVIF_VMM_GET_V0_PTES; break;
-	case LAZY: args.type = NVIF_VMM_GET_V0_LAZY; break;
-	default:
-		WARN_ON(1);
-		return -EINVAL;
-	}
+	vma->size = 0;
 
-	ret = nvif_object_mthd(&vmm->object, NVIF_VMM_V0_GET,
-			       &args, sizeof(args));
-	if (ret == 0) {
-		vma->addr = args.addr;
-		vma->size = args.size;
-	}
-	return ret;
+	ret = vmm->impl->get(vmm->priv, type, sparse, page, align, size, &vma->addr);
+	if (ret)
+		return ret;
+
+	vma->size = size;
+	return 0;
 }
 
 int
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
index 15aa6a37060b..066e068589eb 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c
@@ -238,23 +238,14 @@ nvkm_uvmm_mthd_map(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
 }
 
 static int
-nvkm_uvmm_mthd_put(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
+nvkm_uvmm_put(struct nvif_vmm_priv *uvmm, u64 addr)
 {
-	union {
-		struct nvif_vmm_put_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;
 
 	mutex_lock(&vmm->mutex.vmm);
-	vma = nvkm_vmm_node_search(vmm, args->v0.addr);
+	vma = nvkm_vmm_node_search(vmm, addr);
 	if (ret = -ENOENT, !vma || vma->addr != addr || vma->part) {
 		VMM_DEBUG(vmm, "lookup %016llx: %016llx %d", addr,
 			  vma ? vma->addr : ~0ULL, vma ? vma->part : 0);
@@ -274,27 +265,14 @@ nvkm_uvmm_mthd_put(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
 }
 
 static int
-nvkm_uvmm_mthd_get(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
+nvkm_uvmm_get(struct nvif_vmm_priv *uvmm, enum nvif_vmm_get_type type, bool sparse,
+	      u8 page, u8 align, u64 size, u64 *addr)
 {
-	union {
-		struct nvif_vmm_get_v0 v0;
-	} *args = argv;
 	struct nvkm_vmm *vmm = uvmm->vmm;
 	struct nvkm_vma *vma;
-	int ret = -ENOSYS;
-	bool getref, mapref, sparse;
-	u8 page, align;
-	u64 size;
-
-	if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
-		getref = args->v0.type == NVIF_VMM_GET_V0_PTES;
-		mapref = args->v0.type == NVIF_VMM_GET_V0_ADDR;
-		sparse = args->v0.sparse;
-		page = args->v0.page;
-		align = args->v0.align;
-		size = args->v0.size;
-	} else
-		return ret;
+	bool getref = type == NVIF_VMM_GET_PTES;
+	bool mapref = type == NVIF_VMM_GET_ADDR;
+	int ret;
 
 	mutex_lock(&vmm->mutex.vmm);
 	ret = nvkm_vmm_get_locked(vmm, getref, mapref, sparse,
@@ -303,8 +281,8 @@ nvkm_uvmm_mthd_get(struct nvkm_uvmm *uvmm, void *argv, u32 argc)
 	if (ret)
 		return ret;
 
-	args->v0.addr = vma->addr;
-	return ret;
+	*addr = vma->addr;
+	return 0;
 }
 
 static inline int
@@ -474,8 +452,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_GET   : return nvkm_uvmm_mthd_get   (uvmm, argv, argc);
-	case NVIF_VMM_V0_PUT   : return nvkm_uvmm_mthd_put   (uvmm, argv, argc);
 	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);
@@ -505,6 +481,8 @@ nvkm_uvmm_del(struct nvif_vmm_priv *uvmm)
 static const struct nvif_vmm_impl
 nvkm_uvmm_impl = {
 	.del = nvkm_uvmm_del,
+	.get = nvkm_uvmm_get,
+	.put = nvkm_uvmm_put,
 };
 
 static void *
-- 
2.41.0



More information about the Nouveau mailing list