[PATCH 096/156] drm/nouveau/nvif: rework fault buffer "map" api

Ben Skeggs bskeggs at nvidia.com
Tue Apr 16 23:39:02 UTC 2024


- transition from "ioctl" interface

Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
 .../gpu/drm/nouveau/include/nvif/driverif.h   |  1 +
 drivers/gpu/drm/nouveau/nouveau_svm.c         | 26 +++++++++++--------
 .../gpu/drm/nouveau/nvkm/subdev/fault/user.c  | 16 +++---------
 3 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
index a1aab5735146..ba987233ec74 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h
@@ -198,6 +198,7 @@ struct nvif_mmu_impl {
 struct nvif_faultbuf_impl {
 	void (*del)(struct nvif_faultbuf_priv *);
 
+	struct nvif_mapinfo map;
 	u32 entries;
 	u32 get;
 	u32 put;
diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c
index 83702a86da1d..43218da5d0f3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_svm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_svm.c
@@ -47,6 +47,7 @@ struct nouveau_svm {
 		const struct nvif_faultbuf_impl *impl;
 		struct nvif_faultbuf_priv *priv;
 		struct nvif_object object;
+		struct nvif_map map;
 
 		int id;
 		u32 entries;
@@ -449,15 +450,14 @@ static void
 nouveau_svm_fault_cache(struct nouveau_svm *svm,
 			struct nouveau_svm_fault_buffer *buffer, u32 offset)
 {
-	struct nvif_object *memory = &buffer->object;
-	const u32 instlo = nvif_rd32(memory, offset + 0x00);
-	const u32 insthi = nvif_rd32(memory, offset + 0x04);
-	const u32 addrlo = nvif_rd32(memory, offset + 0x08);
-	const u32 addrhi = nvif_rd32(memory, offset + 0x0c);
-	const u32 timelo = nvif_rd32(memory, offset + 0x10);
-	const u32 timehi = nvif_rd32(memory, offset + 0x14);
-	const u32 engine = nvif_rd32(memory, offset + 0x18);
-	const u32   info = nvif_rd32(memory, offset + 0x1c);
+	const u32 instlo = nvif_rd32(buffer, offset + 0x00);
+	const u32 insthi = nvif_rd32(buffer, offset + 0x04);
+	const u32 addrlo = nvif_rd32(buffer, offset + 0x08);
+	const u32 addrhi = nvif_rd32(buffer, offset + 0x0c);
+	const u32 timelo = nvif_rd32(buffer, offset + 0x10);
+	const u32 timehi = nvif_rd32(buffer, offset + 0x14);
+	const u32 engine = nvif_rd32(buffer, offset + 0x18);
+	const u32   info = nvif_rd32(buffer, offset + 0x1c);
 	const u64   inst = (u64)insthi << 32 | instlo;
 	const u8     gpc = (info & 0x1f000000) >> 24;
 	const u8     hub = (info & 0x00100000) >> 20;
@@ -468,7 +468,7 @@ nouveau_svm_fault_cache(struct nouveau_svm *svm,
 	if (WARN_ON(!(info & 0x80000000)))
 		return;
 
-	nvif_mask(memory, offset + 0x1c, 0x80000000, 0x00000000);
+	nvif_mask(buffer, offset + 0x1c, 0x80000000, 0x00000000);
 
 	if (!buffer->fault[buffer->fault_nr]) {
 		fault = kmalloc(sizeof(*fault), GFP_KERNEL);
@@ -965,6 +965,7 @@ nouveau_svm_fault_buffer_dtor(struct nouveau_svm *svm, int id)
 	nvif_event_dtor(&buffer->notify);
 
 	if (buffer->impl) {
+		nvif_object_unmap_cpu(&buffer->map);
 		buffer->impl->del(buffer->priv);
 		buffer->impl = NULL;
 	}
@@ -991,7 +992,10 @@ nouveau_svm_fault_buffer_ctor(struct nouveau_svm *svm, s32 oclass, int id)
 	buffer->getaddr = buffer->impl->get;
 	buffer->putaddr = buffer->impl->put;
 
-	nvif_object_map(&buffer->object, NULL, 0);
+	ret = nvif_object_map_cpu(&buffer->object, &buffer->impl->map, &buffer->map);
+	if (ret)
+		return ret;
+
 	INIT_WORK(&buffer->work, nouveau_svm_fault);
 
 	ret = nvif_event_ctor(&buffer->object, "svmFault", id, nouveau_svm_event, true, NULL, 0,
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fault/user.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fault/user.c
index e6eb6df1f982..de7a79607eff 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/fault/user.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fault/user.c
@@ -51,18 +51,6 @@ nvkm_ufault_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm
 			       NVKM_FAULT_BUFFER_EVENT_PENDING, NULL);
 }
 
-static int
-nvkm_ufault_map(struct nvkm_object *object, void *argv, u32 argc,
-		enum nvkm_object_map *type, u64 *addr, u64 *size)
-{
-	struct nvkm_fault_buffer *buffer = container_of(object, struct nvif_faultbuf_priv, object)->buffer;
-	struct nvkm_device *device = buffer->fault->subdev.device;
-	*type = NVKM_OBJECT_MAP_IO;
-	*addr = device->func->resource_addr(device, 3) + buffer->addr;
-	*size = nvkm_memory_size(buffer->mem);
-	return 0;
-}
-
 static void
 nvkm_ufault_del(struct nvif_faultbuf_priv *ufault)
 {
@@ -108,7 +96,6 @@ nvkm_ufault = {
 	.dtor = nvkm_ufault_dtor,
 	.init = nvkm_ufault_init,
 	.fini = nvkm_ufault_fini,
-	.map = nvkm_ufault_map,
 	.uevent = nvkm_ufault_uevent,
 };
 
@@ -134,6 +121,9 @@ nvkm_ufault_new(struct nvkm_device *device, const struct nvif_faultbuf_impl **pi
 	}
 
 	ufault->impl = nvkm_ufault_impl;
+	ufault->impl.map.type = NVIF_MAP_IO;
+	ufault->impl.map.handle = device->func->resource_addr(device, 3) + ufault->buffer->addr;
+	ufault->impl.map.length = nvkm_memory_size(ufault->buffer->mem);
 	ufault->impl.entries = ufault->buffer->entries;
 	ufault->impl.get = ufault->buffer->get;
 	ufault->impl.put = ufault->buffer->put;
-- 
2.41.0



More information about the Nouveau mailing list