drm/nouveau/gr/gk20a,gm200-: add terminators to method lists read from fw
authorBen Skeggs <bskeggs@redhat.com>
Thu, 9 Jan 2020 01:46:15 +0000 (11:46 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Feb 2020 07:34:47 +0000 (08:34 +0100)
[ Upstream commit 7adc77aa0e11f25b0e762859219c70852cd8d56f ]

Method init is typically ordered by class in the FW image as ThreeD,
TwoD, Compute.

Due to a bug in parsing the FW into our internal format, we've been
accidentally sending Twod + Compute methods to the ThreeD class, as
well as Compute methods to the TwoD class - oops.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/nouveau/nvkm/engine/gr/gk20a.c

index 500cb08..b57ab5c 100644 (file)
@@ -143,23 +143,24 @@ gk20a_gr_av_to_method(struct gf100_gr *gr, const char *fw_name,
 
        nent = (fuc.size / sizeof(struct gk20a_fw_av));
 
-       pack = vzalloc((sizeof(*pack) * max_classes) +
-                      (sizeof(*init) * (nent + 1)));
+       pack = vzalloc((sizeof(*pack) * (max_classes + 1)) +
+                      (sizeof(*init) * (nent + max_classes + 1)));
        if (!pack) {
                ret = -ENOMEM;
                goto end;
        }
 
-       init = (void *)(pack + max_classes);
+       init = (void *)(pack + max_classes + 1);
 
-       for (i = 0; i < nent; i++) {
-               struct gf100_gr_init *ent = &init[i];
+       for (i = 0; i < nent; i++, init++) {
                struct gk20a_fw_av *av = &((struct gk20a_fw_av *)fuc.data)[i];
                u32 class = av->addr & 0xffff;
                u32 addr = (av->addr & 0xffff0000) >> 14;
 
                if (prevclass != class) {
-                       pack[classidx].init = ent;
+                       if (prevclass) /* Add terminator to the method list. */
+                               init++;
+                       pack[classidx].init = init;
                        pack[classidx].type = class;
                        prevclass = class;
                        if (++classidx >= max_classes) {
@@ -169,10 +170,10 @@ gk20a_gr_av_to_method(struct gf100_gr *gr, const char *fw_name,
                        }
                }
 
-               ent->addr = addr;
-               ent->data = av->data;
-               ent->count = 1;
-               ent->pitch = 1;
+               init->addr = addr;
+               init->data = av->data;
+               init->count = 1;
+               init->pitch = 1;
        }
 
        *ppack = pack;