]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
drm/nouveau/disp: introduce object to track per-head functions/state
authorBen Skeggs <bskeggs@redhat.com>
Fri, 19 May 2017 13:59:34 +0000 (23:59 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 16 Jun 2017 04:04:48 +0000 (14:04 +1000)
Primarily intended as a way to pass per-head state around during
supervisor handling, and share logic between NV50/GF119.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
29 files changed:
drivers/gpu/drm/nouveau/include/nvkm/engine/disp.h
drivers/gpu/drm/nouveau/nvkm/engine/disp/Kbuild
drivers/gpu/drm/nouveau/nvkm/engine/disp/base.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/basenv50.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/cursnv50.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/g84.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/g94.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gf119.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gk104.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gk110.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gm107.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gm200.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gp100.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gp102.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gt200.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gt215.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/head.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/engine/disp/head.h [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/engine/disp/headgf119.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/engine/disp/headnv04.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/engine/disp/headnv50.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/engine/disp/nv04.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.h
drivers/gpu/drm/nouveau/nvkm/engine/disp/oimmnv50.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/ovlynv50.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/priv.h
drivers/gpu/drm/nouveau/nvkm/engine/disp/rootgf119.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/rootnv50.c

index f17200ed3c72600b1d67cf634e65d5794bc9366b..a0892d6d9841d3109ad2ed949a0b33f2815c229c 100644 (file)
@@ -8,10 +8,7 @@ struct nvkm_disp {
        const struct nvkm_disp_func *func;
        struct nvkm_engine engine;
 
-       struct {
-               int nr;
-       } head;
-
+       struct list_head head;
        struct list_head outp;
        struct list_head conn;
 
index cbc7f673a5def6b9dcdd4d398cf24db525f32025..7062929260bc92dd83f9abdbadd259c105ee293a 100644 (file)
@@ -14,6 +14,11 @@ nvkm-y += nvkm/engine/disp/gp100.o
 nvkm-y += nvkm/engine/disp/gp102.o
 nvkm-y += nvkm/engine/disp/vga.o
 
+nvkm-y += nvkm/engine/disp/head.o
+nvkm-y += nvkm/engine/disp/headnv04.o
+nvkm-y += nvkm/engine/disp/headnv50.o
+nvkm-y += nvkm/engine/disp/headgf119.o
+
 nvkm-y += nvkm/engine/disp/dacnv50.o
 nvkm-y += nvkm/engine/disp/piornv50.o
 nvkm-y += nvkm/engine/disp/sornv50.o
index 3e02a94c3072294e6e36e86ebc943da959b0327f..8489d0246cb322f96a31a57b3ed679c0f31a69b4 100644 (file)
@@ -23,6 +23,7 @@
  */
 #include "priv.h"
 #include "conn.h"
+#include "head.h"
 #include "outp.h"
 
 #include <core/client.h>
@@ -249,6 +250,7 @@ nvkm_disp_oneinit(struct nvkm_engine *engine)
        struct nvkm_bios *bios = disp->engine.subdev.device->bios;
        struct nvkm_outp *outp, *outt, *pair;
        struct nvkm_conn *conn;
+       struct nvkm_head *head;
        struct nvbios_connE connE;
        struct dcb_output dcbE;
        u8  hpd = 0, ver, hdr;
@@ -375,8 +377,11 @@ nvkm_disp_oneinit(struct nvkm_engine *engine)
        if (ret)
                return ret;
 
-       return nvkm_event_init(&nvkm_disp_vblank_func, 1,
-                              disp->head.nr, &disp->vblank);
+       i = 0;
+       list_for_each_entry(head, &disp->head, head)
+               i = max(i, head->id + 1);
+
+       return nvkm_event_init(&nvkm_disp_vblank_func, 1, i, &disp->vblank);
 }
 
 static void *
@@ -405,6 +410,12 @@ nvkm_disp_dtor(struct nvkm_engine *engine)
                nvkm_outp_del(&outp);
        }
 
+       while (!list_empty(&disp->head)) {
+               struct nvkm_head *head =
+                       list_first_entry(&disp->head, typeof(*head), head);
+               nvkm_head_del(&head);
+       }
+
        return data;
 }
 
@@ -420,10 +431,10 @@ nvkm_disp = {
 
 int
 nvkm_disp_ctor(const struct nvkm_disp_func *func, struct nvkm_device *device,
-              int index, int heads, struct nvkm_disp *disp)
+              int index, struct nvkm_disp *disp)
 {
        disp->func = func;
-       disp->head.nr = heads;
+       INIT_LIST_HEAD(&disp->head);
        INIT_LIST_HEAD(&disp->outp);
        INIT_LIST_HEAD(&disp->conn);
        return nvkm_engine_ctor(&nvkm_disp, device, index, true, &disp->engine);
@@ -431,9 +442,9 @@ nvkm_disp_ctor(const struct nvkm_disp_func *func, struct nvkm_device *device,
 
 int
 nvkm_disp_new_(const struct nvkm_disp_func *func, struct nvkm_device *device,
-              int index, int heads, struct nvkm_disp **pdisp)
+              int index, struct nvkm_disp **pdisp)
 {
        if (!(*pdisp = kzalloc(sizeof(**pdisp), GFP_KERNEL)))
                return -ENOMEM;
-       return nvkm_disp_ctor(func, device, index, heads, *pdisp);
+       return nvkm_disp_ctor(func, device, index, *pdisp);
 }
index 83f152300ec016166e3f6709b9e18ef30212187a..f1d6b820d48249ec808b777c02852b7416ab0423 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "dmacnv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 #include <core/client.h>
@@ -50,7 +51,7 @@ nv50_disp_base_new(const struct nv50_disp_dmac_func *func,
                nvif_ioctl(parent, "create disp base channel dma vers %d "
                                   "pushbuf %016llx head %d\n",
                           args->v0.version, args->v0.pushbuf, args->v0.head);
-               if (args->v0.head > disp->base.head.nr)
+               if (!nvkm_head_find(&disp->base, args->v0.head))
                        return -EINVAL;
                push = args->v0.pushbuf;
                head = args->v0.head;
index 82ff82d8c1abcc423da4cf814a087bd45461dc7c..ab51121b7982d5bdd379b3cf5b380c1f9a136f05 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "channv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 #include <core/client.h>
@@ -48,7 +49,7 @@ nv50_disp_curs_new(const struct nv50_disp_chan_func *func,
        if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
                nvif_ioctl(parent, "create disp cursor vers %d head %d\n",
                           args->v0.version, args->v0.head);
-               if (args->v0.head > disp->base.head.nr)
+               if (!nvkm_head_find(&disp->base, args->v0.head))
                        return -EINVAL;
                head = args->v0.head;
        } else
index 0db964764cedd5337523d91b1a93704e81333396..0de04221da4814ee99f05650eaaa1c86ce092afa 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -30,6 +31,7 @@ g84_disp = {
        .uevent = &nv50_disp_chan_uevent,
        .super = nv50_disp_super,
        .root = &g84_disp_root_oclass,
+       .head.new = nv50_head_new,
        .head.vblank_init = nv50_disp_vblank_init,
        .head.vblank_fini = nv50_disp_vblank_fini,
        .head.scanoutpos = nv50_disp_root_scanoutpos,
index 3f3cdbc3363a32449b7af34f226d3ddc9cfe0bd4..8010d381bc7d2966a075c5d2bd9f749cebb92a8e 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -30,6 +31,7 @@ g94_disp = {
        .uevent = &nv50_disp_chan_uevent,
        .super = nv50_disp_super,
        .root = &g94_disp_root_oclass,
+       .head.new = nv50_head_new,
        .head.vblank_init = nv50_disp_vblank_init,
        .head.vblank_fini = nv50_disp_vblank_fini,
        .head.scanoutpos = nv50_disp_root_scanoutpos,
index 8d1e535af208c7410e21f01949b888268fc1f38b..59bf3f950eeafeb33c3c999df84f5e7c850f88ab 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 #include <subdev/bios.h>
@@ -364,55 +365,55 @@ gf119_disp_super(struct work_struct *work)
                container_of(work, struct nv50_disp, supervisor);
        struct nvkm_subdev *subdev = &disp->base.engine.subdev;
        struct nvkm_device *device = subdev->device;
+       struct nvkm_head *head;
        u32 mask[4];
-       int head;
 
        nvkm_debug(subdev, "supervisor %d\n", ffs(disp->super));
-       for (head = 0; head < disp->base.head.nr; head++) {
-               mask[head] = nvkm_rd32(device, 0x6101d4 + (head * 0x800));
-               nvkm_debug(subdev, "head %d: %08x\n", head, mask[head]);
+       list_for_each_entry(head, &disp->base.head, head) {
+               mask[head->id] = nvkm_rd32(device, 0x6101d4 + (head->id * 0x800));
+               HEAD_DBG(head, "%08x", mask[head->id]);
        }
 
        if (disp->super & 0x00000001) {
                nv50_disp_chan_mthd(disp->chan[0], NV_DBG_DEBUG);
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(mask[head] & 0x00001000))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(mask[head->id] & 0x00001000))
                                continue;
-                       nvkm_debug(subdev, "supervisor 1.0 - head %d\n", head);
-                       gf119_disp_intr_unk1_0(disp, head);
+                       nvkm_debug(subdev, "supervisor 1.0 - head %d\n", head->id);
+                       gf119_disp_intr_unk1_0(disp, head->id);
                }
        } else
        if (disp->super & 0x00000002) {
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(mask[head] & 0x00001000))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(mask[head->id] & 0x00001000))
                                continue;
-                       nvkm_debug(subdev, "supervisor 2.0 - head %d\n", head);
-                       gf119_disp_intr_unk2_0(disp, head);
+                       nvkm_debug(subdev, "supervisor 2.0 - head %d\n", head->id);
+                       gf119_disp_intr_unk2_0(disp, head->id);
                }
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(mask[head] & 0x00010000))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(mask[head->id] & 0x00010000))
                                continue;
-                       nvkm_debug(subdev, "supervisor 2.1 - head %d\n", head);
-                       gf119_disp_intr_unk2_1(disp, head);
+                       nvkm_debug(subdev, "supervisor 2.1 - head %d\n", head->id);
+                       gf119_disp_intr_unk2_1(disp, head->id);
                }
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(mask[head] & 0x00001000))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(mask[head->id] & 0x00001000))
                                continue;
-                       nvkm_debug(subdev, "supervisor 2.2 - head %d\n", head);
-                       gf119_disp_intr_unk2_2(disp, head);
+                       nvkm_debug(subdev, "supervisor 2.2 - head %d\n", head->id);
+                       gf119_disp_intr_unk2_2(disp, head->id);
                }
        } else
        if (disp->super & 0x00000004) {
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(mask[head] & 0x00001000))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(mask[head->id] & 0x00001000))
                                continue;
-                       nvkm_debug(subdev, "supervisor 3.0 - head %d\n", head);
-                       gf119_disp_intr_unk4_0(disp, head);
+                       nvkm_debug(subdev, "supervisor 3.0 - head %d\n", head->id);
+                       gf119_disp_intr_unk4_0(disp, head->id);
                }
        }
 
-       for (head = 0; head < disp->base.head.nr; head++)
-               nvkm_wr32(device, 0x6101d4 + (head * 0x800), 0x00000000);
+       list_for_each_entry(head, &disp->base.head, head)
+               nvkm_wr32(device, 0x6101d4 + (head->id * 0x800), 0x00000000);
        nvkm_wr32(device, 0x6101d0, 0x80000000);
 }
 
@@ -447,8 +448,8 @@ gf119_disp_intr(struct nv50_disp *disp)
 {
        struct nvkm_subdev *subdev = &disp->base.engine.subdev;
        struct nvkm_device *device = subdev->device;
+       struct nvkm_head *head;
        u32 intr = nvkm_rd32(device, 0x610088);
-       int i;
 
        if (intr & 0x00000001) {
                u32 stat = nvkm_rd32(device, 0x61008c);
@@ -485,14 +486,15 @@ gf119_disp_intr(struct nv50_disp *disp)
                intr &= ~0x00100000;
        }
 
-       for (i = 0; i < disp->base.head.nr; i++) {
-               u32 mask = 0x01000000 << i;
+       list_for_each_entry(head, &disp->base.head, head) {
+               const u32 hoff = head->id * 0x800;
+               u32 mask = 0x01000000 << head->id;
                if (mask & intr) {
-                       u32 stat = nvkm_rd32(device, 0x6100bc + (i * 0x800));
+                       u32 stat = nvkm_rd32(device, 0x6100bc + hoff);
                        if (stat & 0x00000001)
-                               nvkm_disp_vblank(&disp->base, i);
-                       nvkm_mask(device, 0x6100bc + (i * 0x800), 0, 0);
-                       nvkm_rd32(device, 0x6100c0 + (i * 0x800));
+                               nvkm_disp_vblank(&disp->base, head->id);
+                       nvkm_mask(device, 0x6100bc + hoff, 0, 0);
+                       nvkm_rd32(device, 0x6100c0 + hoff);
                }
        }
 }
@@ -512,6 +514,7 @@ gf119_disp = {
        .uevent = &gf119_disp_chan_uevent,
        .super = gf119_disp_super,
        .root = &gf119_disp_root_oclass,
+       .head.new = gf119_head_new,
        .head.vblank_init = gf119_disp_vblank_init,
        .head.vblank_fini = gf119_disp_vblank_fini,
        .head.scanoutpos = gf119_disp_root_scanoutpos,
index ec14cef92de5ddc847330032005d0006b743d782..89561496570bf65b07ebd0b14042a01be42612f6 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -31,6 +32,7 @@ gk104_disp = {
        .uevent = &gf119_disp_chan_uevent,
        .super = gf119_disp_super,
        .root = &gk104_disp_root_oclass,
+       .head.new = gf119_head_new,
        .head.vblank_init = gf119_disp_vblank_init,
        .head.vblank_fini = gf119_disp_vblank_fini,
        .head.scanoutpos = gf119_disp_root_scanoutpos,
index 88f977660e416053a8f2490c78cd73471f5fbb69..9400d2ad79b9d04a7b03e96aa22798e6b81c50a3 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -31,6 +32,7 @@ gk110_disp = {
        .uevent = &gf119_disp_chan_uevent,
        .super = gf119_disp_super,
        .root = &gk110_disp_root_oclass,
+       .head.new = gf119_head_new,
        .head.vblank_init = gf119_disp_vblank_init,
        .head.vblank_fini = gf119_disp_vblank_fini,
        .head.scanoutpos = gf119_disp_root_scanoutpos,
index 5d7a2f42a4f063245496eba3576ea6d651a90e2e..b7570fb0fb1f3f3de214b2c703dc19cb32db6311 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -31,6 +32,7 @@ gm107_disp = {
        .uevent = &gf119_disp_chan_uevent,
        .super = gf119_disp_super,
        .root = &gm107_disp_root_oclass,
+       .head.new = gf119_head_new,
        .head.vblank_init = gf119_disp_vblank_init,
        .head.vblank_fini = gf119_disp_vblank_fini,
        .head.scanoutpos = gf119_disp_root_scanoutpos,
index 54fa9ebe346bfe6732be169478e5dbe7a725689b..b3e52080d4b712629a614c727d592f3ff3978dad 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -31,6 +32,7 @@ gm200_disp = {
        .uevent = &gf119_disp_chan_uevent,
        .super = gf119_disp_super,
        .root = &gm200_disp_root_oclass,
+       .head.new = gf119_head_new,
        .head.vblank_init = gf119_disp_vblank_init,
        .head.vblank_fini = gf119_disp_vblank_fini,
        .head.scanoutpos = gf119_disp_root_scanoutpos,
index 6f4e56d82421406bb411c73abd6c10a88534557b..3d1c65ff5620762aad3b26b7f2b89ba327249c15 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs <bskeggs@redhat.com>
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -31,6 +32,7 @@ gp100_disp = {
        .uevent = &gf119_disp_chan_uevent,
        .super = gf119_disp_super,
        .root = &gp100_disp_root_oclass,
+       .head.new = gf119_head_new,
        .head.vblank_init = gf119_disp_vblank_init,
        .head.vblank_fini = gf119_disp_vblank_fini,
        .head.scanoutpos = gf119_disp_root_scanoutpos,
index 54b97e1dce0bef9604ea449aad630c5f7af82502..fac8e88fd2d14e0dafbc777f3fcca75aa0584a7f 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs <bskeggs@redhat.com>
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static void
@@ -57,6 +58,7 @@ gp102_disp = {
        .uevent = &gf119_disp_chan_uevent,
        .super = gf119_disp_super,
        .root = &gp102_disp_root_oclass,
+       .head.new = gf119_head_new,
        .head.vblank_init = gf119_disp_vblank_init,
        .head.vblank_fini = gf119_disp_vblank_fini,
        .head.scanoutpos = gf119_disp_root_scanoutpos,
index da6c395050de69bca0eb2f579074476ee780f316..a0e7c3c78e971a86919d97c8df688f76cb704227 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -30,6 +31,7 @@ gt200_disp = {
        .uevent = &nv50_disp_chan_uevent,
        .super = nv50_disp_super,
        .root = &gt200_disp_root_oclass,
+       .head.new = nv50_head_new,
        .head.vblank_init = nv50_disp_vblank_init,
        .head.vblank_fini = nv50_disp_vblank_fini,
        .head.scanoutpos = nv50_disp_root_scanoutpos,
index 1f475cf284e310a3cc8868f8865b35ca159e7c56..5f8a8d85567304d64edf3e12650fe09f8ac2dbd7 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 static const struct nv50_disp_func
@@ -30,6 +31,7 @@ gt215_disp = {
        .uevent = &nv50_disp_chan_uevent,
        .super = nv50_disp_super,
        .root = &gt215_disp_root_oclass,
+       .head.new = nv50_head_new,
        .head.vblank_init = nv50_disp_vblank_init,
        .head.vblank_fini = nv50_disp_vblank_fini,
        .head.scanoutpos = nv50_disp_root_scanoutpos,
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/head.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/head.c
new file mode 100644 (file)
index 0000000..6702093
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017 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.
+ *
+ * Authors: Ben Skeggs <bskeggs@redhat.com>
+ */
+#include "head.h"
+
+struct nvkm_head *
+nvkm_head_find(struct nvkm_disp *disp, int id)
+{
+       struct nvkm_head *head;
+       list_for_each_entry(head, &disp->head, head) {
+               if (head->id == id)
+                       return head;
+       }
+       return NULL;
+}
+
+void
+nvkm_head_del(struct nvkm_head **phead)
+{
+       struct nvkm_head *head = *phead;
+       if (head) {
+               HEAD_DBG(head, "dtor");
+               list_del(&head->head);
+               kfree(*phead);
+               *phead = NULL;
+       }
+}
+
+int
+nvkm_head_new_(const struct nvkm_head_func *func,
+              struct nvkm_disp *disp, int id)
+{
+       struct nvkm_head *head;
+       if (!(head = kzalloc(sizeof(*head), GFP_KERNEL)))
+               return -ENOMEM;
+       head->func = func;
+       head->disp = disp;
+       head->id = id;
+       list_add_tail(&head->head, &disp->head);
+       HEAD_DBG(head, "ctor");
+       return 0;
+}
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/head.h b/drivers/gpu/drm/nouveau/nvkm/engine/disp/head.h
new file mode 100644 (file)
index 0000000..a8ae6cb
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef __NVKM_DISP_HEAD_H__
+#define __NVKM_DISP_HEAD_H__
+#include "priv.h"
+
+struct nvkm_head {
+       const struct nvkm_head_func *func;
+       struct nvkm_disp *disp;
+       int id;
+
+       struct list_head head;
+};
+
+int nvkm_head_new_(const struct nvkm_head_func *, struct nvkm_disp *, int id);
+void nvkm_head_del(struct nvkm_head **);
+struct nvkm_head *nvkm_head_find(struct nvkm_disp *, int id);
+
+struct nvkm_head_func {
+};
+
+#define HEAD_MSG(h,l,f,a...) do {                                              \
+       struct nvkm_head *_h = (h);                                            \
+       nvkm_##l(&_h->disp->engine.subdev, "head-%d: "f"\n", _h->id, ##a);     \
+} while(0)
+#define HEAD_WARN(h,f,a...) HEAD_MSG((h), warn, f, ##a)
+#define HEAD_DBG(h,f,a...) HEAD_MSG((h), debug, f, ##a)
+
+int nv04_head_new(struct nvkm_disp *, int id);
+int nv50_head_new(struct nvkm_disp *, int id);
+int gf119_head_new(struct nvkm_disp *, int id);
+#endif
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/headgf119.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/headgf119.c
new file mode 100644 (file)
index 0000000..062fa07
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 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.
+ *
+ * Authors: Ben Skeggs <bskeggs@redhat.com>
+ */
+#include "head.h"
+
+static const struct nvkm_head_func
+gf119_head = {
+};
+
+int
+gf119_head_new(struct nvkm_disp *disp, int id)
+{
+       return nvkm_head_new_(&gf119_head, disp, id);
+}
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/headnv04.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/headnv04.c
new file mode 100644 (file)
index 0000000..f581327
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 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.
+ *
+ * Authors: Ben Skeggs <bskeggs@redhat.com>
+ */
+#include "head.h"
+
+static const struct nvkm_head_func
+nv04_head = {
+};
+
+int
+nv04_head_new(struct nvkm_disp *disp, int id)
+{
+       return nvkm_head_new_(&nv04_head, disp, id);
+}
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/headnv50.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/headnv50.c
new file mode 100644 (file)
index 0000000..e48865c
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 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.
+ *
+ * Authors: Ben Skeggs <bskeggs@redhat.com>
+ */
+#include "head.h"
+
+static const struct nvkm_head_func
+nv50_head = {
+};
+
+int
+nv50_head_new(struct nvkm_disp *disp, int id)
+{
+       return nvkm_head_new_(&nv50_head, disp, id);
+}
index 67254ce6f83f64f04c65886b84023103203f65c8..978e3ad488d9e742b557a3bc1fafb0cf48ea77ae 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "priv.h"
+#include "head.h"
 
 static const struct nvkm_disp_oclass *
 nv04_disp_root(struct nvkm_disp *disp)
@@ -81,5 +82,17 @@ nv04_disp = {
 int
 nv04_disp_new(struct nvkm_device *device, int index, struct nvkm_disp **pdisp)
 {
-       return nvkm_disp_new_(&nv04_disp, device, index, 2, pdisp);
+       int ret, i;
+
+       ret = nvkm_disp_new_(&nv04_disp, device, index, pdisp);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < 2; i++) {
+               ret = nv04_head_new(*pdisp, i);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
 }
index 025cc0d7feb3464696a8a366f761755f46184aa8..9787a4cc4cce815140a374d738f22fa46c2f7562 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "nv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 #include <core/client.h>
@@ -146,7 +147,7 @@ nv50_disp_new_(const struct nv50_disp_func *func, struct nvkm_device *device,
               int index, int heads, struct nvkm_disp **pdisp)
 {
        struct nv50_disp *disp;
-       int ret;
+       int ret, i;
 
        if (!(disp = kzalloc(sizeof(*disp), GFP_KERNEL)))
                return -ENOMEM;
@@ -154,10 +155,16 @@ nv50_disp_new_(const struct nv50_disp_func *func, struct nvkm_device *device,
        disp->func = func;
        *pdisp = &disp->base;
 
-       ret = nvkm_disp_ctor(&nv50_disp_, device, index, heads, &disp->base);
+       ret = nvkm_disp_ctor(&nv50_disp_, device, index, &disp->base);
        if (ret)
                return ret;
 
+       for (i = 0; func->head.new && i < heads; i++) {
+               ret = func->head.new(&disp->base, i);
+               if (ret)
+                       return ret;
+       }
+
        return nvkm_event_init(func->uevent, 1, 1 + (heads * 4), &disp->uevent);
 }
 
@@ -684,43 +691,43 @@ nv50_disp_super(struct work_struct *work)
                container_of(work, struct nv50_disp, supervisor);
        struct nvkm_subdev *subdev = &disp->base.engine.subdev;
        struct nvkm_device *device = subdev->device;
+       struct nvkm_head *head;
        u32 super = nvkm_rd32(device, 0x610030);
-       int head;
 
        nvkm_debug(subdev, "supervisor %08x %08x\n", disp->super, super);
 
        if (disp->super & 0x00000010) {
                nv50_disp_chan_mthd(disp->chan[0], NV_DBG_DEBUG);
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(super & (0x00000020 << head)))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(super & (0x00000020 << head->id)))
                                continue;
-                       if (!(super & (0x00000080 << head)))
+                       if (!(super & (0x00000080 << head->id)))
                                continue;
-                       nv50_disp_intr_unk10_0(disp, head);
+                       nv50_disp_intr_unk10_0(disp, head->id);
                }
        } else
        if (disp->super & 0x00000020) {
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(super & (0x00000080 << head)))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(super & (0x00000080 << head->id)))
                                continue;
-                       nv50_disp_intr_unk20_0(disp, head);
+                       nv50_disp_intr_unk20_0(disp, head->id);
                }
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(super & (0x00000200 << head)))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(super & (0x00000200 << head->id)))
                                continue;
-                       nv50_disp_intr_unk20_1(disp, head);
+                       nv50_disp_intr_unk20_1(disp, head->id);
                }
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(super & (0x00000080 << head)))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(super & (0x00000080 << head->id)))
                                continue;
-                       nv50_disp_intr_unk20_2(disp, head);
+                       nv50_disp_intr_unk20_2(disp, head->id);
                }
        } else
        if (disp->super & 0x00000040) {
-               for (head = 0; head < disp->base.head.nr; head++) {
-                       if (!(super & (0x00000080 << head)))
+               list_for_each_entry(head, &disp->base.head, head) {
+                       if (!(super & (0x00000080 << head->id)))
                                continue;
-                       nv50_disp_intr_unk40_0(disp, head);
+                       nv50_disp_intr_unk40_0(disp, head->id);
                }
                nv50_disp_update_sppll1(disp);
        }
@@ -819,6 +826,7 @@ nv50_disp = {
        .uevent = &nv50_disp_chan_uevent,
        .super = nv50_disp_super,
        .root = &nv50_disp_root_oclass,
+       .head.new = nv50_head_new,
        .head.vblank_init = nv50_disp_vblank_init,
        .head.vblank_fini = nv50_disp_vblank_fini,
        .head.scanoutpos = nv50_disp_root_scanoutpos,
index 4fa82f48429b0f1083d709b2f3c8d7a7fb21f8fa..0361f0c2ba1aba16230e7907f22f216b883f9755 100644 (file)
@@ -75,6 +75,7 @@ struct nv50_disp_func {
        const struct nvkm_disp_oclass *root;
 
        struct {
+               int (*new)(struct nvkm_disp *, int id);
                void (*vblank_init)(struct nv50_disp *, int head);
                void (*vblank_fini)(struct nv50_disp *, int head);
                int (*scanoutpos)(NV50_DISP_MTHD_V0);
index 07540f3d32dc3256f005a4d630c73e4fe1e9d087..f3b0fa2c592441a1001d02da8ad51dc4ef2ba771 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "channv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 #include <core/client.h>
@@ -48,7 +49,7 @@ nv50_disp_oimm_new(const struct nv50_disp_chan_func *func,
        if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
                nvif_ioctl(parent, "create disp overlay vers %d head %d\n",
                           args->v0.version, args->v0.head);
-               if (args->v0.head > disp->base.head.nr)
+               if (!nvkm_head_find(&disp->base, args->v0.head))
                        return -EINVAL;
                head = args->v0.head;
        } else
index 2a49c46425cd0bba3b476203ee398b53f172677c..9ebaaa6e9e336ce391bc91e80ed6791cd9f86f5f 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "dmacnv50.h"
+#include "head.h"
 #include "rootnv50.h"
 
 #include <core/client.h>
@@ -50,7 +51,7 @@ nv50_disp_ovly_new(const struct nv50_disp_dmac_func *func,
                nvif_ioctl(parent, "create disp overlay channel dma vers %d "
                                   "pushbuf %016llx head %d\n",
                           args->v0.version, args->v0.pushbuf, args->v0.head);
-               if (args->v0.head > disp->base.head.nr)
+               if (!nvkm_head_find(&disp->base, args->v0.head))
                        return -EINVAL;
                push = args->v0.pushbuf;
                head = args->v0.head;
index e143fc7bc15fd0383821a4099a49dd0a290816c2..4bb05a09a60be5aba6859873ca3c7ef33a188852 100644 (file)
@@ -4,9 +4,9 @@
 #include "outp.h"
 
 int nvkm_disp_ctor(const struct nvkm_disp_func *, struct nvkm_device *,
-                  int index, int heads, struct nvkm_disp *);
+                  int index, struct nvkm_disp *);
 int nvkm_disp_new_(const struct nvkm_disp_func *, struct nvkm_device *,
-                  int index, int heads, struct nvkm_disp **);
+                  int index, struct nvkm_disp **);
 void nvkm_disp_vblank(struct nvkm_disp *, int head);
 
 struct nvkm_disp_func_outp {
index 335d88823c22d12d7aef3cfb26e48a6a96f5b0eb..f1159dd4db87ac1602973e60b457927d1f941c05 100644 (file)
@@ -22,6 +22,7 @@
  * Authors: Ben Skeggs
  */
 #include "rootnv50.h"
+#include "head.h"
 #include "dmacnv50.h"
 
 #include <core/client.h>
@@ -78,6 +79,7 @@ int
 gf119_disp_root_init(struct nv50_disp_root *root)
 {
        struct nv50_disp *disp = root->disp;
+       struct nvkm_head *head;
        struct nvkm_device *device = disp->base.engine.subdev.device;
        u32 tmp;
        int i;
@@ -88,13 +90,14 @@ gf119_disp_root_init(struct nv50_disp_root *root)
         */
 
        /* ... CRTC caps */
-       for (i = 0; i < disp->base.head.nr; i++) {
-               tmp = nvkm_rd32(device, 0x616104 + (i * 0x800));
-               nvkm_wr32(device, 0x6101b4 + (i * 0x800), tmp);
-               tmp = nvkm_rd32(device, 0x616108 + (i * 0x800));
-               nvkm_wr32(device, 0x6101b8 + (i * 0x800), tmp);
-               tmp = nvkm_rd32(device, 0x61610c + (i * 0x800));
-               nvkm_wr32(device, 0x6101bc + (i * 0x800), tmp);
+       list_for_each_entry(head, &disp->base.head, head) {
+               const u32 hoff = head->id * 0x800;
+               tmp = nvkm_rd32(device, 0x616104 + hoff);
+               nvkm_wr32(device, 0x6101b4 + hoff, tmp);
+               tmp = nvkm_rd32(device, 0x616108 + hoff);
+               nvkm_wr32(device, 0x6101b8 + hoff, tmp);
+               tmp = nvkm_rd32(device, 0x61610c + hoff);
+               nvkm_wr32(device, 0x6101bc + hoff, tmp);
        }
 
        /* ... DAC caps */
@@ -134,8 +137,10 @@ gf119_disp_root_init(struct nv50_disp_root *root)
         *
         * ftp://download.nvidia.com/open-gpu-doc/gk104-disable-underflow-reporting/1/gk104-disable-underflow-reporting.txt
         */
-       for (i = 0; i < disp->base.head.nr; i++)
-               nvkm_mask(device, 0x616308 + (i * 0x800), 0x00000111, 0x00000010);
+       list_for_each_entry(head, &disp->base.head, head) {
+               const u32 hoff = head->id * 0x800;
+               nvkm_mask(device, 0x616308 + hoff, 0x00000111, 0x00000010);
+       }
 
        return 0;
 }
index 2e73aeb86070d0e5df7a7fcaff0f4d0344fc5da1..b5df4e8ddbfd206f227412d871eabc5582375553 100644 (file)
@@ -23,6 +23,7 @@
  */
 #include "rootnv50.h"
 #include "dmacnv50.h"
+#include "head.h"
 
 #include <core/client.h>
 #include <core/ramht.h>
@@ -102,7 +103,7 @@ nv50_disp_root_mthd_(struct nvkm_object *object, u32 mthd, void *data, u32 size)
        } else
                return ret;
 
-       if (head < 0 || head >= disp->base.head.nr)
+       if (!nvkm_head_find(&disp->base, head))
                return -ENXIO;
 
        if (mask) {
@@ -351,6 +352,7 @@ int
 nv50_disp_root_init(struct nv50_disp_root *root)
 {
        struct nv50_disp *disp = root->disp;
+       struct nvkm_head *head;
        struct nvkm_device *device = disp->base.engine.subdev.device;
        u32 tmp;
        int i;
@@ -363,15 +365,15 @@ nv50_disp_root_init(struct nv50_disp_root *root)
        nvkm_wr32(device, 0x610184, tmp);
 
        /* ... CRTC caps */
-       for (i = 0; i < disp->base.head.nr; i++) {
-               tmp = nvkm_rd32(device, 0x616100 + (i * 0x800));
-               nvkm_wr32(device, 0x610190 + (i * 0x10), tmp);
-               tmp = nvkm_rd32(device, 0x616104 + (i * 0x800));
-               nvkm_wr32(device, 0x610194 + (i * 0x10), tmp);
-               tmp = nvkm_rd32(device, 0x616108 + (i * 0x800));
-               nvkm_wr32(device, 0x610198 + (i * 0x10), tmp);
-               tmp = nvkm_rd32(device, 0x61610c + (i * 0x800));
-               nvkm_wr32(device, 0x61019c + (i * 0x10), tmp);
+       list_for_each_entry(head, &disp->base.head, head) {
+               tmp = nvkm_rd32(device, 0x616100 + (head->id * 0x800));
+               nvkm_wr32(device, 0x610190 + (head->id * 0x10), tmp);
+               tmp = nvkm_rd32(device, 0x616104 + (head->id * 0x800));
+               nvkm_wr32(device, 0x610194 + (head->id * 0x10), tmp);
+               tmp = nvkm_rd32(device, 0x616108 + (head->id * 0x800));
+               nvkm_wr32(device, 0x610198 + (head->id * 0x10), tmp);
+               tmp = nvkm_rd32(device, 0x61610c + (head->id * 0x800));
+               nvkm_wr32(device, 0x61019c + (head->id * 0x10), tmp);
        }
 
        /* ... DAC caps */