[PATCH 142/156] drm/nouveau/nvif: rework chan "sclass" api
Ben Skeggs
bskeggs at nvidia.com
Tue Apr 16 23:39:48 UTC 2024
- transition from "ioctl" interfaces
Signed-off-by: Ben Skeggs <bskeggs at nvidia.com>
---
drivers/gpu/drm/nouveau/include/nvif/fifo.h | 2 +
drivers/gpu/drm/nouveau/include/nvif/object.h | 8 --
drivers/gpu/drm/nouveau/nouveau_abi16.c | 91 +++++--------------
drivers/gpu/drm/nouveau/nvif/fifo.c | 13 +++
drivers/gpu/drm/nouveau/nvif/object.c | 51 -----------
drivers/gpu/drm/nouveau/nvkm/core/ioctl.c | 27 +-----
6 files changed, 40 insertions(+), 152 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/include/nvif/fifo.h b/drivers/gpu/drm/nouveau/include/nvif/fifo.h
index 4e9663848291..1a47cf96509f 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/fifo.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/fifo.h
@@ -16,4 +16,6 @@ nvif_fifo_runlist_ce(struct nvif_device *device)
runmce = runmgr;
return runmce;
}
+
+s32 nvif_fifo_engine_oclass(struct nvif_device *, enum nvif_engine_type);
#endif
diff --git a/drivers/gpu/drm/nouveau/include/nvif/object.h b/drivers/gpu/drm/nouveau/include/nvif/object.h
index d52d59d9805d..56308333ef86 100644
--- a/drivers/gpu/drm/nouveau/include/nvif/object.h
+++ b/drivers/gpu/drm/nouveau/include/nvif/object.h
@@ -3,12 +3,6 @@
#define __NVIF_OBJECT_H__
#include <nvif/os.h>
-struct nvif_sclass {
- s32 oclass;
- int minver;
- int maxver;
-};
-
struct nvif_object {
struct nvif_parent *parent;
struct nvif_client *client;
@@ -46,8 +40,6 @@ void nvif_object_ctor_1(struct nvif_object *parent, const char *name, u32 handle
void nvif_object_dtor(struct nvif_object *);
int nvif_object_ioctl(struct nvif_object *, void *, u32, void **);
-int nvif_object_sclass_get(struct nvif_object *, struct nvif_sclass **);
-void nvif_object_sclass_put(struct nvif_sclass **);
int nvif_object_mthd(struct nvif_object *, u32, void *, u32);
int nvif_object_map_cpu(struct nvif_object *, const struct nvif_mapinfo *, struct nvif_map *);
int nvif_object_unmap_cpu(struct nvif_map *);
diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouveau/nouveau_abi16.c
index d7db5c0eeaea..36cf7b035973 100644
--- a/drivers/gpu/drm/nouveau/nouveau_abi16.c
+++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c
@@ -131,25 +131,7 @@ nouveau_abi16_obj_new(struct nouveau_abi16 *abi16, enum nouveau_abi16_obj_type t
s32
nouveau_abi16_swclass(struct nouveau_drm *drm)
{
- switch (drm->client.device.info.family) {
- case NV_DEVICE_INFO_V0_TNT:
- return NVIF_CLASS_SW_NV04;
- case NV_DEVICE_INFO_V0_CELSIUS:
- case NV_DEVICE_INFO_V0_KELVIN:
- case NV_DEVICE_INFO_V0_RANKINE:
- case NV_DEVICE_INFO_V0_CURIE:
- return NVIF_CLASS_SW_NV10;
- case NV_DEVICE_INFO_V0_TESLA:
- return NVIF_CLASS_SW_NV50;
- case NV_DEVICE_INFO_V0_FERMI:
- case NV_DEVICE_INFO_V0_KEPLER:
- case NV_DEVICE_INFO_V0_MAXWELL:
- case NV_DEVICE_INFO_V0_PASCAL:
- case NV_DEVICE_INFO_V0_VOLTA:
- return NVIF_CLASS_SW_GF100;
- }
-
- return 0x0000;
+ return nvif_fifo_engine_oclass(&drm->device, NVIF_ENGINE_SW);
}
static void
@@ -510,9 +492,8 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
struct nouveau_abi16_chan *chan;
struct nouveau_abi16_ntfy *ntfy;
- struct nvif_sclass *sclass;
s32 oclass = 0;
- int ret, i;
+ int ret;
if (unlikely(!abi16))
return -ENOMEM;
@@ -524,56 +505,25 @@ nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS)
if (!chan)
return nouveau_abi16_put(abi16, -ENOENT);
- ret = nvif_object_sclass_get(&chan->chan->chan.object, &sclass);
- if (ret < 0)
- return nouveau_abi16_put(abi16, ret);
-
if ((init->class & 0x00ff) == 0x006e) {
/* nvsw: compatibility with older 0x*6e class identifier */
- for (i = 0; !oclass && i < ret; i++) {
- switch (sclass[i].oclass) {
- case NVIF_CLASS_SW_NV04:
- case NVIF_CLASS_SW_NV10:
- case NVIF_CLASS_SW_NV50:
- case NVIF_CLASS_SW_GF100:
- oclass = sclass[i].oclass;
- break;
- default:
- break;
- }
- }
+ oclass = nvif_fifo_engine_oclass(&abi16->cli->drm->device, NVIF_ENGINE_SW);
} else
if ((init->class & 0x00ff) == 0x00b1) {
/* msvld: compatibility with incorrect version exposure */
- for (i = 0; i < ret; i++) {
- if ((sclass[i].oclass & 0x00ff) == 0x00b1) {
- oclass = sclass[i].oclass;
- break;
- }
- }
+ oclass = nvif_fifo_engine_oclass(&abi16->cli->drm->device, NVIF_ENGINE_MSVLD);
} else
if ((init->class & 0x00ff) == 0x00b2) { /* mspdec */
/* mspdec: compatibility with incorrect version exposure */
- for (i = 0; i < ret; i++) {
- if ((sclass[i].oclass & 0x00ff) == 0x00b2) {
- oclass = sclass[i].oclass;
- break;
- }
- }
+ oclass = nvif_fifo_engine_oclass(&abi16->cli->drm->device, NVIF_ENGINE_MSPDEC);
} else
if ((init->class & 0x00ff) == 0x00b3) { /* msppp */
/* msppp: compatibility with incorrect version exposure */
- for (i = 0; i < ret; i++) {
- if ((sclass[i].oclass & 0x00ff) == 0x00b3) {
- oclass = sclass[i].oclass;
- break;
- }
- }
+ oclass = nvif_fifo_engine_oclass(&abi16->cli->drm->device, NVIF_ENGINE_MSPPP);
} else {
oclass = init->class;
}
- nvif_object_sclass_put(&sclass);
if (!oclass)
return nouveau_abi16_put(abi16, -EINVAL);
@@ -779,10 +729,11 @@ nouveau_abi16_ioctl_new(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl
static int
nouveau_abi16_ioctl_sclass(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *ioctl, u32 argc)
{
+ const struct nvif_device_impl_fifo *fifo;
+ const struct nvif_device_impl_runl *runl;
struct nvif_ioctl_sclass_v0 *args;
struct nouveau_abi16_chan *chan;
- struct nvif_sclass *sclass;
- int ret;
+ int cnt = 0;
if (!ioctl->route || argc < sizeof(*args))
return -EINVAL;
@@ -796,18 +747,24 @@ nouveau_abi16_ioctl_sclass(struct nouveau_abi16 *abi16, struct nvif_ioctl_v0 *io
if (!chan)
return -EINVAL;
- ret = nvif_object_sclass_get(&chan->chan->chan.object, &sclass);
- if (ret < 0)
- return ret;
+ fifo = &chan->chan->cli->drm->device.impl->fifo;
+ runl = &fifo->runl[chan->chan->chan.runl];
+
+ for (int engi = 0; engi < runl->engn_nr; engi++) {
+ const struct nvif_device_impl_engine *engine =
+ &fifo->engine[runl->engn[engi].engine];
- for (int i = 0; i < min_t(u8, args->count, ret); i++) {
- args->oclass[i].oclass = sclass[i].oclass;
- args->oclass[i].minver = sclass[i].minver;
- args->oclass[i].maxver = sclass[i].maxver;
+ for (int clsi = 0; clsi < engine->oclass_nr; clsi++) {
+ if (cnt < args->count) {
+ args->oclass[cnt].oclass = engine->oclass[clsi];
+ args->oclass[cnt].minver = -1;
+ args->oclass[cnt].maxver = -1;
+ }
+ cnt++;
+ }
}
- args->count = ret;
- nvif_object_sclass_put(&sclass);
+ args->count = cnt;
return 0;
}
diff --git a/drivers/gpu/drm/nouveau/nvif/fifo.c b/drivers/gpu/drm/nouveau/nvif/fifo.c
index 34e6fec0f0a3..6bf2c663583f 100644
--- a/drivers/gpu/drm/nouveau/nvif/fifo.c
+++ b/drivers/gpu/drm/nouveau/nvif/fifo.c
@@ -21,6 +21,19 @@
*/
#include <nvif/fifo.h>
+s32
+nvif_fifo_engine_oclass(struct nvif_device *device, enum nvif_engine_type type)
+{
+ const struct nvif_device_impl_fifo *impl = &device->impl->fifo;
+
+ for (int i = 0; i < impl->engine_nr; i++) {
+ if (impl->engine[i].type == type)
+ return impl->engine[i].oclass[0];
+ }
+
+ return 0;
+}
+
u64
nvif_fifo_runlist(struct nvif_device *device, enum nvif_engine_type type)
{
diff --git a/drivers/gpu/drm/nouveau/nvif/object.c b/drivers/gpu/drm/nouveau/nvif/object.c
index 371a3605f537..9887241c5200 100644
--- a/drivers/gpu/drm/nouveau/nvif/object.c
+++ b/drivers/gpu/drm/nouveau/nvif/object.c
@@ -46,57 +46,6 @@ nvif_object_ioctl(struct nvif_object *object, void *data, u32 size, void **hack)
return client->driver->ioctl(client->object.priv, data, size, hack);
}
-void
-nvif_object_sclass_put(struct nvif_sclass **psclass)
-{
- kfree(*psclass);
- *psclass = NULL;
-}
-
-int
-nvif_object_sclass_get(struct nvif_object *object, struct nvif_sclass **psclass)
-{
- struct {
- struct nvif_ioctl_v0 ioctl;
- struct nvif_ioctl_sclass_v0 sclass;
- } *args = NULL;
- int ret, cnt = 0, i;
- u32 size;
-
- while (1) {
- size = sizeof(*args) + cnt * sizeof(args->sclass.oclass[0]);
- if (!(args = kmalloc(size, GFP_KERNEL)))
- return -ENOMEM;
- args->ioctl.version = 0;
- args->ioctl.type = NVIF_IOCTL_V0_SCLASS;
- args->sclass.version = 0;
- args->sclass.count = cnt;
-
- ret = nvif_object_ioctl(object, args, size, NULL);
- if (ret == 0 && args->sclass.count <= cnt)
- break;
- cnt = args->sclass.count;
- kfree(args);
- if (ret != 0)
- return ret;
- }
-
- *psclass = kcalloc(args->sclass.count, sizeof(**psclass), GFP_KERNEL);
- if (*psclass) {
- for (i = 0; i < args->sclass.count; i++) {
- (*psclass)[i].oclass = args->sclass.oclass[i].oclass;
- (*psclass)[i].minver = args->sclass.oclass[i].minver;
- (*psclass)[i].maxver = args->sclass.oclass[i].maxver;
- }
- ret = args->sclass.count;
- } else {
- ret = -ENOMEM;
- }
-
- kfree(args);
- return ret;
-}
-
int
nvif_object_mthd(struct nvif_object *object, u32 mthd, void *data, u32 size)
{
diff --git a/drivers/gpu/drm/nouveau/nvkm/core/ioctl.c b/drivers/gpu/drm/nouveau/nvkm/core/ioctl.c
index 66f843cac37d..b34ed158aa63 100644
--- a/drivers/gpu/drm/nouveau/nvkm/core/ioctl.c
+++ b/drivers/gpu/drm/nouveau/nvkm/core/ioctl.c
@@ -60,32 +60,7 @@ static int
nvkm_ioctl_sclass(struct nvkm_client *client,
struct nvkm_object *object, void *data, u32 size)
{
- union {
- struct nvif_ioctl_sclass_v0 v0;
- } *args = data;
- struct nvkm_oclass oclass = { .client = client };
- int ret = -ENOSYS, i = 0;
-
- nvif_ioctl(object, "sclass size %d\n", size);
- if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
- nvif_ioctl(object, "sclass vers %d count %d\n",
- args->v0.version, args->v0.count);
- if (size != args->v0.count * sizeof(args->v0.oclass[0]))
- return -EINVAL;
-
- while (nvkm_ioctl_sclass_(object, i, &oclass) >= 0) {
- if (i < args->v0.count) {
- args->v0.oclass[i].oclass = oclass.base.oclass;
- args->v0.oclass[i].minver = oclass.base.minver;
- args->v0.oclass[i].maxver = oclass.base.maxver;
- }
- i++;
- }
-
- args->v0.count = i;
- }
-
- return ret;
+ return -ENODEV;
}
static int
--
2.41.0
More information about the Nouveau
mailing list