drm/nouveau/fb/gp100: initial support
authorBen Skeggs <bskeggs@redhat.com>
Sat, 9 Jul 2016 00:41:01 +0000 (10:41 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Thu, 14 Jul 2016 01:53:25 +0000 (11:53 +1000)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvkm/subdev/fb.h
drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
drivers/gpu/drm/nouveau/nvkm/subdev/fb/Kbuild
drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c
drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.c
drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp100.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/subdev/fb/priv.h
drivers/gpu/drm/nouveau/nvkm/subdev/fb/ram.h
drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgp100.c [new file with mode: 0644]

index c2c002d18f55972cff4eddc7ccf2981cc26348f0..c6c3c1ec3ae1a25460081b5cd36bc8b435130511 100644 (file)
@@ -93,6 +93,7 @@ int gk104_fb_new(struct nvkm_device *, int, struct nvkm_fb **);
 int gk20a_fb_new(struct nvkm_device *, int, struct nvkm_fb **);
 int gm107_fb_new(struct nvkm_device *, int, struct nvkm_fb **);
 int gm200_fb_new(struct nvkm_device *, int, struct nvkm_fb **);
+int gp100_fb_new(struct nvkm_device *, int, struct nvkm_fb **);
 
 #include <subdev/bios.h>
 #include <subdev/bios/ramcfg.h>
index b1465c13e48b0c032a95f8d13939ca56c562d966..b09818507946f75ffb5a4fa81414bd0db87fa541 100644 (file)
@@ -2153,6 +2153,7 @@ nv130_chipset = {
        .name = "GP100",
        .bios = nvkm_bios_new,
        .devinit = gm200_devinit_new,
+       .fb = gp100_fb_new,
        .imem = nv50_instmem_new,
        .mc = gp100_mc_new,
        .pci = gp100_pci_new,
index 842d5de96d73169be05fc86d2462fb1e27ebdcf9..1ca005d3ac62c96751106fdbd6314a441a2b3853 100644 (file)
@@ -24,6 +24,7 @@ nvkm-y += nvkm/subdev/fb/gk104.o
 nvkm-y += nvkm/subdev/fb/gk20a.o
 nvkm-y += nvkm/subdev/fb/gm107.o
 nvkm-y += nvkm/subdev/fb/gm200.o
+nvkm-y += nvkm/subdev/fb/gp100.o
 
 nvkm-y += nvkm/subdev/fb/ram.o
 nvkm-y += nvkm/subdev/fb/ramnv04.o
@@ -41,6 +42,7 @@ nvkm-y += nvkm/subdev/fb/rammcp77.o
 nvkm-y += nvkm/subdev/fb/ramgf100.o
 nvkm-y += nvkm/subdev/fb/ramgk104.o
 nvkm-y += nvkm/subdev/fb/ramgm107.o
+nvkm-y += nvkm/subdev/fb/ramgp100.o
 nvkm-y += nvkm/subdev/fb/sddr2.o
 nvkm-y += nvkm/subdev/fb/sddr3.o
 nvkm-y += nvkm/subdev/fb/gddr3.o
index 4742e5ee37ac501e1c434c00454b134d3112265f..a7049c041594b6511f52b33331a73e2bc8e3582d 100644 (file)
@@ -137,6 +137,8 @@ nvkm_fb_init(struct nvkm_subdev *subdev)
                fb->func->init(fb);
        if (fb->func->init_page)
                fb->func->init_page(fb);
+       if (fb->func->init_unkn)
+               fb->func->init_unkn(fb);
        return 0;
 }
 
index 6af3b724f07ba8d6d2b4aec2ec0b427b107a5470..62f653240be3103a76d58e506b8ab44acf2d8739 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <core/memory.h>
 
-static void
+void
 gm200_fb_init_page(struct nvkm_fb *fb)
 {
        struct nvkm_device *device = fb->subdev.device;
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp100.c
new file mode 100644 (file)
index 0000000..1620067
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2016 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 "gf100.h"
+#include "ram.h"
+
+#include <core/memory.h>
+
+static void
+gp100_fb_init_unkn(struct nvkm_fb *base)
+{
+       struct nvkm_device *device = gf100_fb(base)->base.subdev.device;
+       nvkm_wr32(device, 0x1fac80, nvkm_rd32(device, 0x100c80));
+       nvkm_wr32(device, 0x1facc4, nvkm_rd32(device, 0x100cc4));
+       nvkm_wr32(device, 0x1facc8, nvkm_rd32(device, 0x100cc8));
+       nvkm_wr32(device, 0x1faccc, nvkm_rd32(device, 0x100ccc));
+}
+
+static void
+gp100_fb_init(struct nvkm_fb *base)
+{
+       struct gf100_fb *fb = gf100_fb(base);
+       struct nvkm_device *device = fb->base.subdev.device;
+
+       if (fb->r100c10_page)
+               nvkm_wr32(device, 0x100c10, fb->r100c10 >> 8);
+
+       nvkm_wr32(device, 0x100cc8, nvkm_memory_addr(fb->base.mmu_wr) >> 8);
+       nvkm_wr32(device, 0x100ccc, nvkm_memory_addr(fb->base.mmu_rd) >> 8);
+       nvkm_mask(device, 0x100cc4, 0x00060000,
+                 max(nvkm_memory_size(fb->base.mmu_rd) >> 16, (u64)2) << 17);
+}
+
+static const struct nvkm_fb_func
+gp100_fb = {
+       .dtor = gf100_fb_dtor,
+       .oneinit = gf100_fb_oneinit,
+       .init = gp100_fb_init,
+       .init_page = gm200_fb_init_page,
+       .init_unkn = gp100_fb_init_unkn,
+       .ram_new = gp100_ram_new,
+       .memtype_valid = gf100_fb_memtype_valid,
+};
+
+int
+gp100_fb_new(struct nvkm_device *device, int index, struct nvkm_fb **pfb)
+{
+       return gf100_fb_new_(&gp100_fb, device, index, pfb);
+}
index c93926c573103281a9ca79c8ed19e40897ff4ede..e905d44fa1d59a88bf349e8bbcd467f49d7a7a00 100644 (file)
@@ -9,6 +9,7 @@ struct nvkm_fb_func {
        int (*oneinit)(struct nvkm_fb *);
        void (*init)(struct nvkm_fb *);
        void (*init_page)(struct nvkm_fb *);
+       void (*init_unkn)(struct nvkm_fb *);
        void (*intr)(struct nvkm_fb *);
 
        struct {
@@ -63,4 +64,6 @@ void nv46_fb_tile_init(struct nvkm_fb *, int i, u32 addr, u32 size,
 int gf100_fb_oneinit(struct nvkm_fb *);
 void gf100_fb_init_page(struct nvkm_fb *);
 bool gf100_fb_memtype_valid(struct nvkm_fb *, u32);
+
+void gm200_fb_init_page(struct nvkm_fb *);
 #endif
index f816cbf2ced32f02a310b112cee757024acb1ab3..b9ec0ae6723ad1c71b93802c50236d27d0bc12bc 100644 (file)
@@ -47,4 +47,5 @@ int mcp77_ram_new(struct nvkm_fb *, struct nvkm_ram **);
 int gf100_ram_new(struct nvkm_fb *, struct nvkm_ram **);
 int gk104_ram_new(struct nvkm_fb *, struct nvkm_ram **);
 int gm107_ram_new(struct nvkm_fb *, struct nvkm_ram **);
+int gp100_ram_new(struct nvkm_fb *, struct nvkm_ram **);
 #endif
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgp100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgp100.c
new file mode 100644 (file)
index 0000000..f3be408
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2013 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
+ */
+#include "ram.h"
+
+#include <subdev/bios.h>
+#include <subdev/bios/init.h>
+#include <subdev/bios/rammap.h>
+
+static int
+gp100_ram_init(struct nvkm_ram *ram)
+{
+       struct nvkm_subdev *subdev = &ram->fb->subdev;
+       struct nvkm_device *device = subdev->device;
+       struct nvkm_bios *bios = device->bios;
+       u8  ver, hdr, cnt, len, snr, ssz;
+       u32 data;
+       int i;
+
+       /* run a bunch of tables from rammap table.  there's actually
+        * individual pointers for each rammap entry too, but, nvidia
+        * seem to just run the last two entries' scripts early on in
+        * their init, and never again.. we'll just run 'em all once
+        * for now.
+        *
+        * i strongly suspect that each script is for a separate mode
+        * (likely selected by 0x9a065c's lower bits?), and the
+        * binary driver skips the one that's already been setup by
+        * the init tables.
+        */
+       data = nvbios_rammapTe(bios, &ver, &hdr, &cnt, &len, &snr, &ssz);
+       if (!data || hdr < 0x15)
+               return -EINVAL;
+
+       cnt  = nvbios_rd08(bios, data + 0x14); /* guess at count */
+       data = nvbios_rd32(bios, data + 0x10); /* guess u32... */
+       if (cnt) {
+               u32 save = nvkm_rd32(device, 0x9a065c) & 0x000000f0;
+               for (i = 0; i < cnt; i++, data += 4) {
+                       if (i != save >> 4) {
+                               nvkm_mask(device, 0x9a065c, 0x000000f0, i << 4);
+                               nvbios_exec(&(struct nvbios_init) {
+                                               .subdev = subdev,
+                                               .bios = bios,
+                                               .offset = nvbios_rd32(bios, data),
+                                               .execute = 1,
+                                           });
+                       }
+               }
+               nvkm_mask(device, 0x9a065c, 0x000000f0, save);
+       }
+
+       nvkm_mask(device, 0x9a0584, 0x11000000, 0x00000000);
+       nvkm_wr32(device, 0x10ecc0, 0xffffffff);
+       nvkm_mask(device, 0x9a0160, 0x00000010, 0x00000010);
+       return 0;
+}
+
+static const struct nvkm_ram_func
+gp100_ram_func = {
+       .init = gp100_ram_init,
+       .get = gf100_ram_get,
+       .put = gf100_ram_put,
+};
+
+int
+gp100_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
+{
+       struct nvkm_ram *ram;
+       struct nvkm_subdev *subdev = &fb->subdev;
+       struct nvkm_device *device = subdev->device;
+       enum nvkm_ram_type type = nvkm_fb_bios_memtype(device->bios);
+       const u32 rsvd_head = ( 256 * 1024); /* vga memory */
+       const u32 rsvd_tail = (1024 * 1024); /* vbios etc */
+       u32 fbpa_num = nvkm_rd32(device, 0x022438), fbpa;
+       u32 fbio_opt = nvkm_rd32(device, 0x021c14);
+       u64 part, size = 0, comm = ~0ULL;
+       bool mixed = false;
+       int ret;
+
+       nvkm_debug(subdev, "022438: %08x\n", fbpa_num);
+       nvkm_debug(subdev, "021c14: %08x\n", fbio_opt);
+       for (fbpa = 0; fbpa < fbpa_num; fbpa++) {
+               if (!(fbio_opt & (1 << fbpa))) {
+                       part = nvkm_rd32(device, 0x90020c + (fbpa * 0x4000));
+                       nvkm_debug(subdev, "fbpa %02x: %lld MiB\n", fbpa, part);
+                       part = part << 20;
+                       if (part != comm) {
+                               if (comm != ~0ULL)
+                                       mixed = true;
+                               comm = min(comm, part);
+                       }
+                       size = size + part;
+               }
+       }
+
+       ret = nvkm_ram_new_(&gp100_ram_func, fb, type, size, 0, &ram);
+       *pram = ram;
+       if (ret)
+               return ret;
+
+       nvkm_mm_fini(&ram->vram);
+
+       if (mixed) {
+               ret = nvkm_mm_init(&ram->vram, rsvd_head >> NVKM_RAM_MM_SHIFT,
+                                  ((comm * fbpa_num) - rsvd_head) >>
+                                  NVKM_RAM_MM_SHIFT, 1);
+               if (ret)
+                       return ret;
+
+               ret = nvkm_mm_init(&ram->vram, (0x1000000000ULL + comm) >>
+                                  NVKM_RAM_MM_SHIFT,
+                                  (size - (comm * fbpa_num) - rsvd_tail) >>
+                                  NVKM_RAM_MM_SHIFT, 1);
+               if (ret)
+                       return ret;
+       } else {
+               ret = nvkm_mm_init(&ram->vram, rsvd_head >> NVKM_RAM_MM_SHIFT,
+                                  (size - rsvd_head - rsvd_tail) >>
+                                  NVKM_RAM_MM_SHIFT, 1);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}