- transition from "ioctl" interface Signed-off-by: Ben Skeggs <bskeggs@xxxxxxxxxx> --- .../gpu/drm/nouveau/include/nvif/driverif.h | 8 +++ drivers/gpu/drm/nouveau/include/nvif/mem.h | 4 +- drivers/gpu/drm/nouveau/include/nvif/mmu.h | 1 - drivers/gpu/drm/nouveau/include/nvif/vmm.h | 2 +- drivers/gpu/drm/nouveau/nouveau_bo.c | 10 ++-- drivers/gpu/drm/nouveau/nouveau_chan.c | 2 +- drivers/gpu/drm/nouveau/nouveau_drm.c | 54 ++++++++----------- drivers/gpu/drm/nouveau/nouveau_drv.h | 2 - drivers/gpu/drm/nouveau/nouveau_mem.c | 10 ++-- drivers/gpu/drm/nouveau/nouveau_svm.c | 3 +- drivers/gpu/drm/nouveau/nouveau_uvmm.c | 3 +- drivers/gpu/drm/nouveau/nouveau_vmm.c | 4 +- drivers/gpu/drm/nouveau/nouveau_vmm.h | 2 +- drivers/gpu/drm/nouveau/nvif/mem.c | 10 ++-- drivers/gpu/drm/nouveau/nvif/mmu.c | 11 ---- drivers/gpu/drm/nouveau/nvif/vmm.c | 4 +- .../gpu/drm/nouveau/nvkm/subdev/mmu/ummu.c | 4 ++ 17 files changed, 60 insertions(+), 74 deletions(-) diff --git a/drivers/gpu/drm/nouveau/include/nvif/driverif.h b/drivers/gpu/drm/nouveau/include/nvif/driverif.h index 7bba8c79d71e..a1b97bc5e933 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/driverif.h +++ b/drivers/gpu/drm/nouveau/include/nvif/driverif.h @@ -84,6 +84,14 @@ struct nvif_mmu_impl { u8 type_nr; u16 kind_nr; + + struct { + s32 oclass; + } mem; + + struct { + s32 oclass; + } vmm; }; struct nvif_device_impl { diff --git a/drivers/gpu/drm/nouveau/include/nvif/mem.h b/drivers/gpu/drm/nouveau/include/nvif/mem.h index 9e1071dd56a0..217d13126f13 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/mem.h +++ b/drivers/gpu/drm/nouveau/include/nvif/mem.h @@ -10,10 +10,10 @@ struct nvif_mem { u64 size; }; -int nvif_mem_ctor_type(struct nvif_mmu *mmu, const char *name, s32 oclass, +int nvif_mem_ctor_type(struct nvif_mmu *mmu, const char *name, int type, u8 page, u64 size, void *argv, u32 argc, struct nvif_mem *); -int nvif_mem_ctor(struct nvif_mmu *mmu, const char *name, s32 oclass, u8 type, +int nvif_mem_ctor(struct nvif_mmu *mmu, const char *name, u8 type, u8 page, u64 size, void *argv, u32 argc, struct nvif_mem *); void nvif_mem_dtor(struct nvif_mem *); diff --git a/drivers/gpu/drm/nouveau/include/nvif/mmu.h b/drivers/gpu/drm/nouveau/include/nvif/mmu.h index 414caaa2230a..ed5d011f4237 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/mmu.h +++ b/drivers/gpu/drm/nouveau/include/nvif/mmu.h @@ -12,7 +12,6 @@ struct nvif_mmu { u8 type_nr; u8 kind_inv; u16 kind_nr; - s32 mem; struct { u64 size; diff --git a/drivers/gpu/drm/nouveau/include/nvif/vmm.h b/drivers/gpu/drm/nouveau/include/nvif/vmm.h index 0ecedd0ee0a5..e8d8fbd56010 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/vmm.h +++ b/drivers/gpu/drm/nouveau/include/nvif/vmm.h @@ -36,7 +36,7 @@ struct nvif_vmm { int page_nr; }; -int nvif_vmm_ctor(struct nvif_mmu *, const char *name, s32 oclass, +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 *); diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index e1483fd5d283..cbb8f54db83f 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -1158,7 +1158,7 @@ nouveau_ttm_io_mem_free_locked(struct nouveau_drm *drm, { struct nouveau_mem *mem = nouveau_mem(reg); - if (drm->client.mem->oclass >= NVIF_CLASS_MEM_NV50) { + if (drm->mmu.impl->mem.oclass >= NVIF_CLASS_MEM_NV50) { switch (reg->mem_type) { case TTM_PL_TT: if (mem->kind) @@ -1179,7 +1179,7 @@ nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg) struct nouveau_drm *drm = nouveau_bdev(bdev); struct nvkm_device *device = nvxx_device(&drm->client.device); struct nouveau_mem *mem = nouveau_mem(reg); - struct nvif_mmu *mmu = &drm->client.mmu; + struct nvif_mmu *mmu = &drm->mmu; int ret; mutex_lock(&drm->ttm.io_reserve_mutex); @@ -1198,7 +1198,7 @@ nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg) reg->bus.caching = ttm_write_combined; } #endif - if (drm->client.mem->oclass < NVIF_CLASS_MEM_NV50 || + if (mmu->impl->mem.oclass < NVIF_CLASS_MEM_NV50 || !mem->kind) { /* untiled */ ret = 0; @@ -1217,7 +1217,7 @@ nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg) else reg->bus.caching = ttm_write_combined; - if (drm->client.mem->oclass >= NVIF_CLASS_MEM_NV50) { + if (mmu->impl->mem.oclass >= NVIF_CLASS_MEM_NV50) { union { struct nv50_mem_map_v0 nv50; struct gf100_mem_map_v0 gf100; @@ -1225,7 +1225,7 @@ nouveau_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource *reg) u64 handle, length; u32 argc = 0; - switch (mem->mem.object.oclass) { + switch (mmu->impl->mem.oclass) { case NVIF_CLASS_MEM_NV50: args.nv50.version = 0; args.nv50.ro = 0; diff --git a/drivers/gpu/drm/nouveau/nouveau_chan.c b/drivers/gpu/drm/nouveau/nouveau_chan.c index 636ca1f284f8..dd4f9915ccaf 100644 --- a/drivers/gpu/drm/nouveau/nouveau_chan.c +++ b/drivers/gpu/drm/nouveau/nouveau_chan.c @@ -328,7 +328,7 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, u64 runm, /* allocate userd */ if (oclass >= VOLTA_CHANNEL_GPFIFO_A) { - ret = nvif_mem_ctor(&cli->mmu, "abi16ChanUSERD", NVIF_CLASS_MEM_GF100, + ret = nvif_mem_ctor(&cli->mmu, "abi16ChanUSERD", NVIF_MEM_VRAM | NVIF_MEM_COHERENT | NVIF_MEM_MAPPABLE, 0, PAGE_SIZE, NULL, 0, &chan->mem_userd); if (ret) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index 1dba64a1e590..8ab6b9e03eb5 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -194,22 +194,6 @@ static int nouveau_cli_init(struct nouveau_drm *drm, const char *sname, struct nouveau_cli *cli) { - static const struct nvif_mclass - mems[] = { - { NVIF_CLASS_MEM_GF100, -1 }, - { NVIF_CLASS_MEM_NV50 , -1 }, - { NVIF_CLASS_MEM_NV04 , -1 }, - {} - }; - static const struct nvif_mclass - vmms[] = { - { NVIF_CLASS_VMM_GP100, -1 }, - { NVIF_CLASS_VMM_GM200, -1 }, - { NVIF_CLASS_VMM_GF100, -1 }, - { NVIF_CLASS_VMM_NV50 , -1 }, - { NVIF_CLASS_VMM_NV04 , -1 }, - {} - }; int ret; snprintf(cli->name, sizeof(cli->name), "%s", sname); @@ -242,26 +226,12 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname, goto done; } - ret = nvif_mclass(&cli->mmu.object, vmms); - if (ret < 0) { - NV_PRINTK(err, cli, "No supported VMM class\n"); - goto done; - } - - ret = nouveau_vmm_init(cli, vmms[ret].oclass, &cli->vmm); + ret = nouveau_vmm_init(cli, &cli->vmm); if (ret) { NV_PRINTK(err, cli, "VMM allocation failed: %d\n", ret); goto done; } - ret = nvif_mclass(&cli->mmu.object, mems); - if (ret < 0) { - NV_PRINTK(err, cli, "No supported MEM class\n"); - goto done; - } - - cli->mem = &mems[ret]; - /* Don't pass in the (shared) sched_wq in order to let * nouveau_sched_create() create a dedicated one for VM_BIND jobs. * @@ -574,6 +544,28 @@ nouveau_drm_device_init(struct drm_device *dev, struct nvkm_device *nvkm) goto fail_nvif; } + switch (drm->mmu.impl->mem.oclass) { + case NVIF_CLASS_MEM_GF100: + case NVIF_CLASS_MEM_NV50: + case NVIF_CLASS_MEM_NV04: + break; + default: + NV_ERROR(drm, "No supported MEM class (0x%04x)\n", drm->mmu.impl->mem.oclass); + goto fail_nvif; + } + + switch (drm->mmu.impl->vmm.oclass) { + case NVIF_CLASS_VMM_GP100: + case NVIF_CLASS_VMM_GM200: + case NVIF_CLASS_VMM_GF100: + case NVIF_CLASS_VMM_NV50: + case NVIF_CLASS_VMM_NV04: + break; + default: + NV_ERROR(drm, "No supported VMM class (0x%04x)\n", drm->mmu.impl->vmm.oclass); + goto fail_nvif; + } + drm->sched_wq = alloc_workqueue("nouveau_sched_wq_shared", 0, WQ_MAX_ACTIVE); if (!drm->sched_wq) { diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index 35dfc95b32ed..38d33a4d5c49 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -100,8 +100,6 @@ struct nouveau_cli { struct nouveau_sched *sched; - const struct nvif_mclass *mem; - struct list_head head; void *abi16; struct list_head objects; diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c index baea74899fcf..75abd545c92d 100644 --- a/drivers/gpu/drm/nouveau/nouveau_mem.c +++ b/drivers/gpu/drm/nouveau/nouveau_mem.c @@ -90,7 +90,6 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt) { struct nouveau_mem *mem = nouveau_mem(reg); struct nouveau_drm *drm = mem->drm; - struct nouveau_cli *cli = &drm->cli; struct nvif_mmu *mmu = &drm->mmu; struct nvif_mem_ram_v0 args = {}; u8 type; @@ -115,7 +114,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_tt *tt) args.dma = tt->dma_address; mutex_lock(&drm->client_mutex); - ret = nvif_mem_ctor_type(mmu, "ttmHostMem", cli->mem->oclass, type, PAGE_SHIFT, + ret = nvif_mem_ctor_type(mmu, "ttmHostMem", type, PAGE_SHIFT, reg->size, &args, sizeof(args), &mem->mem); mutex_unlock(&drm->client_mutex); @@ -127,15 +126,14 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page) { struct nouveau_mem *mem = nouveau_mem(reg); struct nouveau_drm *drm = mem->drm; - struct nouveau_cli *cli = &drm->cli; struct nvif_mmu *mmu = &drm->mmu; u64 size = ALIGN(reg->size, 1 << page); int ret; mutex_lock(&drm->client_mutex); - switch (cli->mem->oclass) { + switch (drm->mmu.impl->mem.oclass) { case NVIF_CLASS_MEM_GF100: - ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass, + ret = nvif_mem_ctor_type(mmu, "ttmVram", drm->ttm.type_vram, page, size, &(struct gf100_mem_v0) { .contig = contig, @@ -143,7 +141,7 @@ nouveau_mem_vram(struct ttm_resource *reg, bool contig, u8 page) &mem->mem); break; case NVIF_CLASS_MEM_NV50: - ret = nvif_mem_ctor_type(mmu, "ttmVram", cli->mem->oclass, + ret = nvif_mem_ctor_type(mmu, "ttmVram", drm->ttm.type_vram, page, size, &(struct nv50_mem_v0) { .bankswz = mmu->kind[mem->kind] == 2, diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index 477336672652..a478b5a9ed0a 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -346,8 +346,7 @@ nouveau_svmm_init(struct drm_device *dev, void *data, * All future channel/memory allocations will make use of this * VMM instead of the standard one. */ - ret = nvif_vmm_ctor(&cli->mmu, "svmVmm", - cli->vmm.vmm.object.oclass, MANAGED, + ret = nvif_vmm_ctor(&cli->mmu, "svmVmm", MANAGED, args->unmanaged_addr, args->unmanaged_size, &(struct gp100_vmm_v0) { .fault_replay = true, diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c b/drivers/gpu/drm/nouveau/nouveau_uvmm.c index 0a0a11dc9ec0..d35096071c1a 100644 --- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c +++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c @@ -1865,8 +1865,7 @@ nouveau_uvmm_ioctl_vm_init(struct drm_device *dev, /* GPUVM takes care from here on. */ drm_gem_object_put(r_obj); - ret = nvif_vmm_ctor(&cli->mmu, "uvmm", - cli->vmm.vmm.object.oclass, RAW, + ret = nvif_vmm_ctor(&cli->mmu, "uvmm", RAW, init->kernel_managed_addr, init->kernel_managed_size, NULL, 0, &uvmm->vmm.vmm); diff --git a/drivers/gpu/drm/nouveau/nouveau_vmm.c b/drivers/gpu/drm/nouveau/nouveau_vmm.c index 3dda885df5b2..93807d21ceff 100644 --- a/drivers/gpu/drm/nouveau/nouveau_vmm.c +++ b/drivers/gpu/drm/nouveau/nouveau_vmm.c @@ -129,9 +129,9 @@ nouveau_vmm_fini(struct nouveau_vmm *vmm) } int -nouveau_vmm_init(struct nouveau_cli *cli, s32 oclass, struct nouveau_vmm *vmm) +nouveau_vmm_init(struct nouveau_cli *cli, struct nouveau_vmm *vmm) { - int ret = nvif_vmm_ctor(&cli->mmu, "drmVmm", oclass, UNMANAGED, + int ret = nvif_vmm_ctor(&cli->mmu, "drmVmm", UNMANAGED, PAGE_SIZE, 0, NULL, 0, &vmm->vmm); if (ret) return ret; diff --git a/drivers/gpu/drm/nouveau/nouveau_vmm.h b/drivers/gpu/drm/nouveau/nouveau_vmm.h index 2b98d975f37e..196d8a819617 100644 --- a/drivers/gpu/drm/nouveau/nouveau_vmm.h +++ b/drivers/gpu/drm/nouveau/nouveau_vmm.h @@ -28,6 +28,6 @@ struct nouveau_vmm { struct nouveau_svmm *svmm; }; -int nouveau_vmm_init(struct nouveau_cli *, s32 oclass, struct nouveau_vmm *); +int nouveau_vmm_init(struct nouveau_cli *, struct nouveau_vmm *); void nouveau_vmm_fini(struct nouveau_vmm *); #endif diff --git a/drivers/gpu/drm/nouveau/nvif/mem.c b/drivers/gpu/drm/nouveau/nvif/mem.c index 0e1b7b4c2e91..0f0b4a7c5e80 100644 --- a/drivers/gpu/drm/nouveau/nvif/mem.c +++ b/drivers/gpu/drm/nouveau/nvif/mem.c @@ -28,7 +28,7 @@ int nvif_mem_ctor_map(struct nvif_mmu *mmu, const char *name, u8 type, u64 size, struct nvif_mem *mem) { - int ret = nvif_mem_ctor(mmu, name, mmu->mem, NVIF_MEM_MAPPABLE | type, + int ret = nvif_mem_ctor(mmu, name, NVIF_MEM_MAPPABLE | type, 0, size, NULL, 0, mem); if (ret == 0) { ret = nvif_object_map(&mem->object, NULL, 0); @@ -45,7 +45,7 @@ nvif_mem_dtor(struct nvif_mem *mem) } int -nvif_mem_ctor_type(struct nvif_mmu *mmu, const char *name, s32 oclass, +nvif_mem_ctor_type(struct nvif_mmu *mmu, const char *name, int type, u8 page, u64 size, void *argv, u32 argc, struct nvif_mem *mem) { @@ -69,7 +69,7 @@ nvif_mem_ctor_type(struct nvif_mmu *mmu, const char *name, s32 oclass, args->size = size; memcpy(args->data, argv, argc); - ret = nvif_object_ctor(&mmu->object, name ? name : "nvifMem", 0, oclass, + ret = nvif_object_ctor(&mmu->object, name ? name : "nvifMem", 0, mmu->impl->mem.oclass, args, sizeof(*args) + argc, &mem->object); if (ret == 0) { mem->type = mmu->type[type].type; @@ -85,7 +85,7 @@ nvif_mem_ctor_type(struct nvif_mmu *mmu, const char *name, s32 oclass, } int -nvif_mem_ctor(struct nvif_mmu *mmu, const char *name, s32 oclass, u8 type, +nvif_mem_ctor(struct nvif_mmu *mmu, const char *name, u8 type, u8 page, u64 size, void *argv, u32 argc, struct nvif_mem *mem) { int ret = -EINVAL, i; @@ -94,7 +94,7 @@ nvif_mem_ctor(struct nvif_mmu *mmu, const char *name, s32 oclass, u8 type, for (i = 0; ret && i < mmu->type_nr; i++) { if ((mmu->type[i].type & type) == type) { - ret = nvif_mem_ctor_type(mmu, name, oclass, i, page, + ret = nvif_mem_ctor_type(mmu, name, i, page, size, argv, argc, mem); } } diff --git a/drivers/gpu/drm/nouveau/nvif/mmu.c b/drivers/gpu/drm/nouveau/nvif/mmu.c index cc15cf99462c..7e592a6d8530 100644 --- a/drivers/gpu/drm/nouveau/nvif/mmu.c +++ b/drivers/gpu/drm/nouveau/nvif/mmu.c @@ -42,12 +42,6 @@ nvif_mmu_dtor(struct nvif_mmu *mmu) int nvif_mmu_ctor(struct nvif_device *device, const char *name, struct nvif_mmu *mmu) { - static const struct nvif_mclass mems[] = { - { NVIF_CLASS_MEM_GF100, -1 }, - { NVIF_CLASS_MEM_NV50 , -1 }, - { NVIF_CLASS_MEM_NV04 , -1 }, - {} - }; const s32 oclass = device->impl->mmu.oclass; int ret, i; @@ -68,11 +62,6 @@ nvif_mmu_ctor(struct nvif_device *device, const char *name, struct nvif_mmu *mmu mmu->type_nr = mmu->impl->type_nr; mmu->kind_nr = mmu->impl->kind_nr; - ret = nvif_mclass(&mmu->object, mems); - if (ret < 0) - goto done; - mmu->mem = mems[ret].oclass; - mmu->heap = kmalloc_array(mmu->heap_nr, sizeof(*mmu->heap), GFP_KERNEL); mmu->type = kmalloc_array(mmu->type_nr, sizeof(*mmu->type), diff --git a/drivers/gpu/drm/nouveau/nvif/vmm.c b/drivers/gpu/drm/nouveau/nvif/vmm.c index 99296f03371a..2738ea9229cc 100644 --- a/drivers/gpu/drm/nouveau/nvif/vmm.c +++ b/drivers/gpu/drm/nouveau/nvif/vmm.c @@ -196,7 +196,7 @@ nvif_vmm_dtor(struct nvif_vmm *vmm) } int -nvif_vmm_ctor(struct nvif_mmu *mmu, const char *name, s32 oclass, +nvif_vmm_ctor(struct nvif_mmu *mmu, const char *name, enum nvif_vmm_type type, u64 addr, u64 size, void *argv, u32 argc, struct nvif_vmm *vmm) { @@ -225,7 +225,7 @@ nvif_vmm_ctor(struct nvif_mmu *mmu, const char *name, s32 oclass, memcpy(args->data, argv, argc); ret = nvif_object_ctor(&mmu->object, name ? name : "nvifVmm", 0, - oclass, args, argn, &vmm->object); + mmu->impl->vmm.oclass, args, argn, &vmm->object); if (ret) goto done; diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/ummu.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/ummu.c index f97dec6c3309..9f44d469b4da 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/ummu.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/ummu.c @@ -186,6 +186,10 @@ nvkm_ummu_new(struct nvkm_device *device, const struct nvif_mmu_impl **pimpl, ummu->impl.type_nr = mmu->type_nr; ummu->impl.kind_nr = kinds; + ummu->impl.mem.oclass = mmu->func->mem.user.oclass; + + ummu->impl.vmm.oclass = mmu->func->vmm.user.oclass; + *pimpl = &ummu->impl; *ppriv = ummu; *pobject = &ummu->object; -- 2.41.0