drm/nouveau/mmu/gm200,gm20b: implement vmm on top of new base
authorBen Skeggs <bskeggs@redhat.com>
Tue, 31 Oct 2017 17:56:19 +0000 (03:56 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Thu, 2 Nov 2017 03:32:26 +0000 (13:32 +1000)
Adds support for:
- Per-VMM selection of big page size.
- System-memory PDs.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvif/class.h
drivers/gpu/drm/nouveau/include/nvif/ifb00d.h [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/Kbuild
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/gm200.c
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/gm20b.c
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.h
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgm200.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgm20b.c [new file with mode: 0644]

index df8d6a32d2dc1d0a7b29fee8746498e9f3d4700f..76dff0697f63b49784fd3bffd8d4df124aeacf95 100644 (file)
@@ -18,6 +18,7 @@
 #define NVIF_CLASS_VMM_NV04                          /* if000d.h */  0x8000000d
 #define NVIF_CLASS_VMM_NV50                          /* if500d.h */  0x8000500d
 #define NVIF_CLASS_VMM_GF100                         /* if900d.h */  0x8000900d
+#define NVIF_CLASS_VMM_GM200                         /* ifb00d.h */  0x8000b00d
 
 /* the below match nvidia-assigned (either in hw, or sw) class numbers */
 #define NV_NULL_CLASS                                                0x00000030
diff --git a/drivers/gpu/drm/nouveau/include/nvif/ifb00d.h b/drivers/gpu/drm/nouveau/include/nvif/ifb00d.h
new file mode 100644 (file)
index 0000000..2e1e998
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __NVIF_IFB00D_H__
+#define __NVIF_IFB00D_H__
+#include "if000c.h"
+
+struct gm200_vmm_vn {
+       /* nvif_vmm_vX ... */
+};
+
+struct gm200_vmm_v0 {
+       /* nvif_vmm_vX ... */
+       __u8  version;
+       __u8  bigpage;
+};
+#endif
index e65daffff9bfd640bfca8a1d0a00e9298f102433..55963dc4dc41ca9dbd4f275c70b19cb001482d53 100644 (file)
@@ -20,3 +20,5 @@ nvkm-y += nvkm/subdev/mmu/vmmnv50.o
 nvkm-y += nvkm/subdev/mmu/vmmgf100.o
 nvkm-y += nvkm/subdev/mmu/vmmgk104.o
 nvkm-y += nvkm/subdev/mmu/vmmgk20a.o
+nvkm-y += nvkm/subdev/mmu/vmmgm200.o
+nvkm-y += nvkm/subdev/mmu/vmmgm20b.o
index 4bb342fa3d5406355acf8db2211aa29886f07c95..8d6be5b3e8e8403f71b09a5317320ad51b88f512 100644 (file)
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
-#include "priv.h"
+#include "vmm.h"
+
+#include <subdev/fb.h>
+
+#include <nvif/class.h>
 
 static const struct nvkm_mmu_func
 gm200_mmu = {
@@ -34,10 +38,29 @@ gm200_mmu = {
        .map_sg = gf100_vm_map_sg,
        .unmap = gf100_vm_unmap,
        .flush = gf100_vm_flush,
+       .vmm = {{ -1,  0, NVIF_CLASS_VMM_GM200}, gm200_vmm_new },
+};
+
+static const struct nvkm_mmu_func
+gm200_mmu_fixed = {
+       .limit = (1ULL << 40),
+       .dma_bits = 40,
+       .pgt_bits  = 27 - 12,
+       .spg_shift = 12,
+       .lpg_shift = 17,
+       .create = gf100_vm_create,
+       .map_pgt = gf100_vm_map_pgt,
+       .map = gf100_vm_map,
+       .map_sg = gf100_vm_map_sg,
+       .unmap = gf100_vm_unmap,
+       .flush = gf100_vm_flush,
+       .vmm = {{ -1, -1, NVIF_CLASS_VMM_GM200}, gm200_vmm_new_fixed },
 };
 
 int
 gm200_mmu_new(struct nvkm_device *device, int index, struct nvkm_mmu **pmmu)
 {
+       if (device->fb->page)
+               return nvkm_mmu_new_(&gm200_mmu_fixed, device, index, pmmu);
        return nvkm_mmu_new_(&gm200_mmu, device, index, pmmu);
 }
index 06e49a9c8a9f54e50bfffb87e084a3aeab98f752..2894c7cbcdbb1b0515e6bfc898f0b0cbfd443e95 100644 (file)
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
-#include "priv.h"
+#include "vmm.h"
+
+#include <subdev/fb.h>
+
+#include <nvif/class.h>
 
 static const struct nvkm_mmu_func
 gm20b_mmu = {
@@ -34,10 +38,29 @@ gm20b_mmu = {
        .map_sg = gf100_vm_map_sg,
        .unmap = gf100_vm_unmap,
        .flush = gf100_vm_flush,
+       .vmm = {{ -1,  0, NVIF_CLASS_VMM_GM200}, gm20b_vmm_new },
+};
+
+static const struct nvkm_mmu_func
+gm20b_mmu_fixed = {
+       .limit = (1ULL << 40),
+       .dma_bits = 40,
+       .pgt_bits  = 27 - 12,
+       .spg_shift = 12,
+       .lpg_shift = 17,
+       .create = gf100_vm_create,
+       .map_pgt = gf100_vm_map_pgt,
+       .map = gf100_vm_map,
+       .map_sg = gf100_vm_map_sg,
+       .unmap = gf100_vm_unmap,
+       .flush = gf100_vm_flush,
+       .vmm = {{ -1, -1, NVIF_CLASS_VMM_GM200}, gm20b_vmm_new_fixed },
 };
 
 int
 gm20b_mmu_new(struct nvkm_device *device, int index, struct nvkm_mmu **pmmu)
 {
+       if (device->fb->page)
+               return nvkm_mmu_new_(&gm20b_mmu_fixed, device, index, pmmu);
        return nvkm_mmu_new_(&gm20b_mmu, device, index, pmmu);
 }
index 914ae3f53cca8376ee9ea7e6616ce50a80525294..5cca1b449bdb5c54ffbf5dea1b8c6ee225b35ac5 100644 (file)
@@ -73,6 +73,11 @@ extern const struct nvkm_vmm_desc gk104_vmm_desc_16_16[];
 extern const struct nvkm_vmm_desc gk104_vmm_desc_17_12[];
 extern const struct nvkm_vmm_desc gk104_vmm_desc_17_17[];
 
+extern const struct nvkm_vmm_desc gm200_vmm_desc_16_12[];
+extern const struct nvkm_vmm_desc gm200_vmm_desc_16_16[];
+extern const struct nvkm_vmm_desc gm200_vmm_desc_17_12[];
+extern const struct nvkm_vmm_desc gm200_vmm_desc_17_17[];
+
 struct nvkm_vmm_page {
        u8 shift;
        const struct nvkm_vmm_desc *desc;
@@ -126,6 +131,12 @@ int gf100_vmm_join_(struct nvkm_vmm *, struct nvkm_memory *, u64 base);
 int gf100_vmm_join(struct nvkm_vmm *, struct nvkm_memory *);
 void gf100_vmm_part(struct nvkm_vmm *, struct nvkm_memory *);
 
+int gm200_vmm_new_(const struct nvkm_vmm_func *, const struct nvkm_vmm_func *,
+                  struct nvkm_mmu *, u64, u64, void *, u32,
+                  struct lock_class_key *, const char *, struct nvkm_vmm **);
+int gm200_vmm_join_(struct nvkm_vmm *, struct nvkm_memory *, u64 base);
+int gm200_vmm_join(struct nvkm_vmm *, struct nvkm_memory *);
+
 int nv04_vmm_new(struct nvkm_mmu *, u64, u64, void *, u32,
                 struct lock_class_key *, const char *, struct nvkm_vmm **);
 int nv41_vmm_new(struct nvkm_mmu *, u64, u64, void *, u32,
@@ -142,4 +153,16 @@ int gk104_vmm_new(struct nvkm_mmu *, u64, u64, void *, u32,
                  struct lock_class_key *, const char *, struct nvkm_vmm **);
 int gk20a_vmm_new(struct nvkm_mmu *, u64, u64, void *, u32,
                  struct lock_class_key *, const char *, struct nvkm_vmm **);
+int gm200_vmm_new_fixed(struct nvkm_mmu *, u64, u64, void *, u32,
+                       struct lock_class_key *, const char *,
+                       struct nvkm_vmm **);
+int gm200_vmm_new(struct nvkm_mmu *, u64, u64, void *, u32,
+                 struct lock_class_key *, const char *,
+                 struct nvkm_vmm **);
+int gm20b_vmm_new_fixed(struct nvkm_mmu *, u64, u64, void *, u32,
+                       struct lock_class_key *, const char *,
+                       struct nvkm_vmm **);
+int gm20b_vmm_new(struct nvkm_mmu *, u64, u64, void *, u32,
+                 struct lock_class_key *, const char *,
+                 struct nvkm_vmm **);
 #endif
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgm200.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgm200.c
new file mode 100644 (file)
index 0000000..4313856
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+#include "vmm.h"
+
+#include <nvif/ifb00d.h>
+#include <nvif/unpack.h>
+
+static const struct nvkm_vmm_desc_func
+gm200_vmm_spt = {
+};
+
+static const struct nvkm_vmm_desc_func
+gm200_vmm_lpt = {
+};
+
+static const struct nvkm_vmm_desc_func
+gm200_vmm_pgd = {
+};
+
+const struct nvkm_vmm_desc
+gm200_vmm_desc_17_12[] = {
+       { SPT, 15, 8, 0x1000, &gm200_vmm_spt },
+       { PGD, 13, 8, 0x1000, &gm200_vmm_pgd },
+       {}
+};
+
+const struct nvkm_vmm_desc
+gm200_vmm_desc_17_17[] = {
+       { LPT, 10, 8, 0x1000, &gm200_vmm_lpt },
+       { PGD, 13, 8, 0x1000, &gm200_vmm_pgd },
+       {}
+};
+
+const struct nvkm_vmm_desc
+gm200_vmm_desc_16_12[] = {
+       { SPT, 14, 8, 0x1000, &gm200_vmm_spt },
+       { PGD, 14, 8, 0x1000, &gm200_vmm_pgd },
+       {}
+};
+
+const struct nvkm_vmm_desc
+gm200_vmm_desc_16_16[] = {
+       { LPT, 10, 8, 0x1000, &gm200_vmm_lpt },
+       { PGD, 14, 8, 0x1000, &gm200_vmm_pgd },
+       {}
+};
+
+int
+gm200_vmm_join_(struct nvkm_vmm *vmm, struct nvkm_memory *inst, u64 base)
+{
+       if (vmm->func->page[1].shift == 16)
+               base |= BIT_ULL(11);
+       return gf100_vmm_join_(vmm, inst, base);
+}
+
+int
+gm200_vmm_join(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
+{
+       return gm200_vmm_join_(vmm, inst, 0);
+}
+
+static const struct nvkm_vmm_func
+gm200_vmm_17 = {
+       .join = gm200_vmm_join,
+       .part = gf100_vmm_part,
+       .page = {
+               { 27, &gm200_vmm_desc_17_17[1], NVKM_VMM_PAGE_Sxxx },
+               { 17, &gm200_vmm_desc_17_17[0], NVKM_VMM_PAGE_SVxC },
+               { 12, &gm200_vmm_desc_17_12[0], NVKM_VMM_PAGE_SVHx },
+               {}
+       }
+};
+
+static const struct nvkm_vmm_func
+gm200_vmm_16 = {
+       .join = gm200_vmm_join,
+       .part = gf100_vmm_part,
+       .page = {
+               { 27, &gm200_vmm_desc_16_16[1], NVKM_VMM_PAGE_Sxxx },
+               { 16, &gm200_vmm_desc_16_16[0], NVKM_VMM_PAGE_SVxC },
+               { 12, &gm200_vmm_desc_16_12[0], NVKM_VMM_PAGE_SVHx },
+               {}
+       }
+};
+
+int
+gm200_vmm_new_(const struct nvkm_vmm_func *func_16,
+              const struct nvkm_vmm_func *func_17,
+              struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
+              struct lock_class_key *key, const char *name,
+              struct nvkm_vmm **pvmm)
+{
+       const struct nvkm_vmm_func *func;
+       union {
+               struct gm200_vmm_vn vn;
+               struct gm200_vmm_v0 v0;
+       } *args = argv;
+       int ret = -ENOSYS;
+
+       if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
+               switch (args->v0.bigpage) {
+               case 16: func = func_16; break;
+               case 17: func = func_17; break;
+               default:
+                       return -EINVAL;
+               }
+       } else
+       if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
+               func = func_17;
+       } else
+               return ret;
+
+       return nvkm_vmm_new_(func, mmu, 0, addr, size, key, name, pvmm);
+}
+
+int
+gm200_vmm_new(struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
+             struct lock_class_key *key, const char *name,
+             struct nvkm_vmm **pvmm)
+{
+       return gm200_vmm_new_(&gm200_vmm_16, &gm200_vmm_17, mmu, addr,
+                             size, argv, argc, key, name, pvmm);
+}
+
+int
+gm200_vmm_new_fixed(struct nvkm_mmu *mmu, u64 addr, u64 size,
+                   void *argv, u32 argc, struct lock_class_key *key,
+                   const char *name, struct nvkm_vmm **pvmm)
+{
+       return gf100_vmm_new_(&gm200_vmm_16, &gm200_vmm_17, mmu, addr,
+                             size, argv, argc, key, name, pvmm);
+}
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgm20b.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgm20b.c
new file mode 100644 (file)
index 0000000..ec24c43
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+#include "vmm.h"
+
+static const struct nvkm_vmm_func
+gm20b_vmm_17 = {
+       .join = gm200_vmm_join,
+       .part = gf100_vmm_part,
+       .page = {
+               { 27, &gm200_vmm_desc_17_17[1], NVKM_VMM_PAGE_Sxxx },
+               { 17, &gm200_vmm_desc_17_17[0], NVKM_VMM_PAGE_SxHC },
+               { 12, &gm200_vmm_desc_17_12[0], NVKM_VMM_PAGE_SxHx },
+               {}
+       }
+};
+
+static const struct nvkm_vmm_func
+gm20b_vmm_16 = {
+       .join = gm200_vmm_join,
+       .part = gf100_vmm_part,
+       .page = {
+               { 27, &gm200_vmm_desc_16_16[1], NVKM_VMM_PAGE_Sxxx },
+               { 16, &gm200_vmm_desc_16_16[0], NVKM_VMM_PAGE_SxHC },
+               { 12, &gm200_vmm_desc_16_12[0], NVKM_VMM_PAGE_SxHx },
+               {}
+       }
+};
+
+int
+gm20b_vmm_new(struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
+             struct lock_class_key *key, const char *name,
+             struct nvkm_vmm **pvmm)
+{
+       return gm200_vmm_new_(&gm20b_vmm_16, &gm20b_vmm_17, mmu, addr,
+                             size, argv, argc, key, name, pvmm);
+}
+
+int
+gm20b_vmm_new_fixed(struct nvkm_mmu *mmu, u64 addr, u64 size,
+                   void *argv, u32 argc, struct lock_class_key *key,
+                   const char *name, struct nvkm_vmm **pvmm)
+{
+       return gf100_vmm_new_(&gm20b_vmm_16, &gm20b_vmm_17, mmu, addr,
+                             size, argv, argc, key, name, pvmm);
+}