drm/nouveau/fifo/gk104-: support querying engines available on each runlist
authorBen Skeggs <bskeggs@redhat.com>
Tue, 8 May 2018 10:39:46 +0000 (20:39 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 18 May 2018 05:01:21 +0000 (15:01 +1000)
Will be used to improve channel runlist selection.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvif/cl0080.h
drivers/gpu/drm/nouveau/include/nvif/device.h
drivers/gpu/drm/nouveau/include/nvif/fifo.h [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvif/Kbuild
drivers/gpu/drm/nouveau/nvif/device.c
drivers/gpu/drm/nouveau/nvif/fifo.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/engine/fifo/base.c
drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c
drivers/gpu/drm/nouveau/nvkm/engine/fifo/priv.h

index 5af610ea260e89d79e3948a1960bc71d73e8548a..49c1c90d2bde0f12bbc1bf2715ae824c51b9a3c5 100644 (file)
@@ -83,4 +83,11 @@ struct nv_device_time_v0 {
 
 /* Returns the number of available channels. */
 #define NV_DEVICE_FIFO_CHANNELS                      NV_DEVICE_FIFO(0x00000000)
+
+/* Returns a mask of available runlists. */
+#define NV_DEVICE_FIFO_RUNLISTS                      NV_DEVICE_FIFO(0x00000001)
+
+/* These return a mask of engines available on a particular runlist. */
+#define NV_DEVICE_FIFO_RUNLIST_ENGINES(n)     ((n) + NV_DEVICE_FIFO(0x00000010))
+#define NV_DEVICE_FIFO_RUNLIST_ENGINES__SIZE                                64
 #endif
index 216dbd9fa616825ae55777186f726130abf6e4fb..76fe21e395de4729ba87675eeb9c4538b1254c65 100644 (file)
@@ -8,6 +8,11 @@
 struct nvif_device {
        struct nvif_object object;
        struct nv_device_info_v0 info;
+
+       struct nvif_fifo_runlist {
+               u64 engines;
+       } *runlist;
+       int runlists;
 };
 
 int  nvif_device_init(struct nvif_object *, u32 handle, s32 oclass, void *, u32,
diff --git a/drivers/gpu/drm/nouveau/include/nvif/fifo.h b/drivers/gpu/drm/nouveau/include/nvif/fifo.h
new file mode 100644 (file)
index 0000000..e9468c9
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __NVIF_FIFO_H__
+#define __NVIF_FIFO_H__
+#include <nvif/device.h>
+
+/* Returns mask of runlists that support a NV_DEVICE_INFO_ENGINE_* type. */
+u64 nvif_fifo_runlist(struct nvif_device *, u64 engine);
+
+/* CE-supporting runlists (excluding GRCE, if others exist). */
+static inline u64
+nvif_fifo_runlist_ce(struct nvif_device *device)
+{
+       u64 runmgr = nvif_fifo_runlist(device, NV_DEVICE_INFO_ENGINE_GR);
+       u64 runmce = nvif_fifo_runlist(device, NV_DEVICE_INFO_ENGINE_CE);
+       if (runmce && !(runmce &= ~runmgr))
+               runmce = runmgr;
+       return runmce;
+}
+#endif
index f1675a4ab6fa5179fe44fe4caa5cc6664d8946fe..c817b02b7acf293c0766f0eca7db5fc37059b4a5 100644 (file)
@@ -2,6 +2,7 @@ nvif-y := nvif/object.o
 nvif-y += nvif/client.o
 nvif-y += nvif/device.o
 nvif-y += nvif/driver.o
+nvif-y += nvif/fifo.o
 nvif-y += nvif/mem.o
 nvif-y += nvif/mmu.o
 nvif-y += nvif/notify.o
index 252d8c33215bb44591add83fd05d5f65c325aa9e..ca5eb3dde70a02be25c8903bc514c4dba17d1ff9 100644 (file)
@@ -37,6 +37,8 @@ nvif_device_time(struct nvif_device *device)
 void
 nvif_device_fini(struct nvif_device *device)
 {
+       kfree(device->runlist);
+       device->runlist = NULL;
        nvif_object_fini(&device->object);
 }
 
@@ -46,6 +48,7 @@ nvif_device_init(struct nvif_object *parent, u32 handle, s32 oclass,
 {
        int ret = nvif_object_init(parent, handle, oclass, data, size,
                                   &device->object);
+       device->runlist = NULL;
        if (ret == 0) {
                device->info.version = 0;
                ret = nvif_object_mthd(&device->object, NV_DEVICE_V0_INFO,
diff --git a/drivers/gpu/drm/nouveau/nvif/fifo.c b/drivers/gpu/drm/nouveau/nvif/fifo.c
new file mode 100644 (file)
index 0000000..99d4fd1
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2018 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <nvif/fifo.h>
+
+static int
+nvif_fifo_runlists(struct nvif_device *device)
+{
+       struct nvif_object *object = &device->object;
+       struct {
+               struct nv_device_info_v1 m;
+               struct {
+                       struct nv_device_info_v1_data runlists;
+                       struct nv_device_info_v1_data runlist[64];
+               } v;
+       } *a;
+       int ret, i;
+
+       if (device->runlist)
+               return 0;
+
+       if (!(a = kmalloc(sizeof(*a), GFP_KERNEL)))
+               return -ENOMEM;
+       a->m.version = 1;
+       a->m.count = sizeof(a->v) / sizeof(a->v.runlists);
+       a->v.runlists.mthd = NV_DEVICE_FIFO_RUNLISTS;
+       for (i = 0; i < ARRAY_SIZE(a->v.runlist); i++)
+               a->v.runlist[i].mthd = NV_DEVICE_FIFO_RUNLIST_ENGINES(i);
+
+       ret = nvif_object_mthd(object, NV_DEVICE_V0_INFO, a, sizeof(*a));
+       if (ret)
+               goto done;
+
+       device->runlists = fls64(a->v.runlists.data);
+       device->runlist = kzalloc(sizeof(*device->runlist) *
+                                 device->runlists, GFP_KERNEL);
+       if (!device->runlist) {
+               ret = -ENOMEM;
+               goto done;
+       }
+
+       for (i = 0; i < device->runlists; i++) {
+               if (a->v.runlists.data & BIT_ULL(i))
+                       device->runlist[i].engines = a->v.runlist[i].data;
+       }
+
+done:
+       kfree(a);
+       return ret;
+}
+
+u64
+nvif_fifo_runlist(struct nvif_device *device, u64 engine)
+{
+       struct nvif_object *object = &device->object;
+       struct {
+               struct nv_device_info_v1 m;
+               struct {
+                       struct nv_device_info_v1_data engine;
+               } v;
+       } a = {
+               .m.version = 1,
+               .m.count = sizeof(a.v) / sizeof(a.v.engine),
+               .v.engine.mthd = engine,
+       };
+       u64 runm = 0;
+       int ret, i;
+
+       if ((ret = nvif_fifo_runlists(device)))
+               return runm;
+
+       ret = nvif_object_mthd(object, NV_DEVICE_V0_INFO, &a, sizeof(a));
+       if (ret == 0) {
+               for (i = 0; i < device->runlists; i++) {
+                       if (device->runlist[i].engines & a.v.engine.data)
+                               runm |= BIT_ULL(i);
+               }
+       }
+
+       return runm;
+}
index ed56087b4abe28e366d2d778bb773649d7f44c18..1642d8ea68f1ceaa98fbfd8296639e848aeba432 100644 (file)
@@ -284,6 +284,8 @@ nvkm_fifo_info(struct nvkm_engine *engine, u64 mthd, u64 *data)
        switch (mthd) {
        case NV_DEVICE_FIFO_CHANNELS: *data = fifo->nr; return 0;
        default:
+               if (fifo->func->info)
+                       return fifo->func->info(fifo, mthd, data);
                break;
        }
        return -ENOSYS;
index b5706b15a64d926dc312f553537d8a72f95d0cf1..b6c23cf43f832b90e33834baa501062c6050c384 100644 (file)
@@ -33,6 +33,7 @@
 #include <engine/sw.h>
 
 #include <nvif/class.h>
+#include <nvif/cl0080.h>
 
 struct gk104_fifo_engine_status {
        bool busy;
@@ -783,6 +784,34 @@ gk104_fifo_fini(struct nvkm_fifo *base)
        nvkm_mask(device, 0x002140, 0x10000000, 0x10000000);
 }
 
+static int
+gk104_fifo_info(struct nvkm_fifo *base, u64 mthd, u64 *data)
+{
+       struct gk104_fifo *fifo = gk104_fifo(base);
+       switch (mthd) {
+       case NV_DEVICE_FIFO_RUNLISTS:
+               *data = (1ULL << fifo->runlist_nr) - 1;
+               return 0;
+       case NV_DEVICE_FIFO_RUNLIST_ENGINES(0)...
+            NV_DEVICE_FIFO_RUNLIST_ENGINES(63): {
+               int runl = mthd - NV_DEVICE_FIFO_RUNLIST_ENGINES(0), engn;
+               if (runl < fifo->runlist_nr) {
+                       unsigned long engm = fifo->runlist[runl].engm;
+                       struct nvkm_engine *engine;
+                       *data = 0;
+                       for_each_set_bit(engn, &engm, fifo->engine_nr) {
+                               if ((engine = fifo->engine[engn].engine))
+                                       *data |= BIT_ULL(engine->subdev.index);
+                       }
+                       return 0;
+               }
+       }
+               return -EINVAL;
+       default:
+               return -EINVAL;
+       }
+}
+
 static int
 gk104_fifo_oneinit(struct nvkm_fifo *base)
 {
@@ -912,6 +941,7 @@ static const struct nvkm_fifo_func
 gk104_fifo_ = {
        .dtor = gk104_fifo_dtor,
        .oneinit = gk104_fifo_oneinit,
+       .info = gk104_fifo_info,
        .init = gk104_fifo_init,
        .fini = gk104_fifo_fini,
        .intr = gk104_fifo_intr,
index df74b54773b912244b72c2c5466c986f60b6aa7e..f9b4e9d2c08ab1a88100cb20258c9c2a0c0a1903 100644 (file)
@@ -18,6 +18,7 @@ struct nvkm_fifo_chan_oclass;
 struct nvkm_fifo_func {
        void *(*dtor)(struct nvkm_fifo *);
        int (*oneinit)(struct nvkm_fifo *);
+       int (*info)(struct nvkm_fifo *, u64 mthd, u64 *data);
        void (*init)(struct nvkm_fifo *);
        void (*fini)(struct nvkm_fifo *);
        void (*intr)(struct nvkm_fifo *);