2 * Copyright 2017 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <nvif/ifb00d.h>
25 #include <nvif/unpack.h>
28 gm200_vmm_pgt_sparse(struct nvkm_vmm *vmm,
29 struct nvkm_mmu_pt *pt, u32 ptei, u32 ptes)
31 /* VALID_FALSE + VOL tells the MMU to treat the PTE as sparse. */
32 VMM_FO064(pt, vmm, ptei * 8, BIT_ULL(32) /* VOL. */, ptes);
35 static const struct nvkm_vmm_desc_func
37 .unmap = gf100_vmm_pgt_unmap,
38 .sparse = gm200_vmm_pgt_sparse,
39 .mem = gf100_vmm_pgt_mem,
40 .dma = gf100_vmm_pgt_dma,
41 .sgl = gf100_vmm_pgt_sgl,
44 static const struct nvkm_vmm_desc_func
46 .invalid = gk104_vmm_lpt_invalid,
47 .unmap = gf100_vmm_pgt_unmap,
48 .sparse = gm200_vmm_pgt_sparse,
49 .mem = gf100_vmm_pgt_mem,
53 gm200_vmm_pgd_sparse(struct nvkm_vmm *vmm,
54 struct nvkm_mmu_pt *pt, u32 pdei, u32 pdes)
56 /* VALID_FALSE + VOL_BIG tells the MMU to treat the PDE as sparse. */
57 VMM_FO064(pt, vmm, pdei * 8, BIT_ULL(35) /* VOL_BIG. */, pdes);
60 static const struct nvkm_vmm_desc_func
62 .unmap = gf100_vmm_pgt_unmap,
63 .sparse = gm200_vmm_pgd_sparse,
64 .pde = gf100_vmm_pgd_pde,
67 const struct nvkm_vmm_desc
68 gm200_vmm_desc_17_12[] = {
69 { SPT, 15, 8, 0x1000, &gm200_vmm_spt },
70 { PGD, 13, 8, 0x1000, &gm200_vmm_pgd },
74 const struct nvkm_vmm_desc
75 gm200_vmm_desc_17_17[] = {
76 { LPT, 10, 8, 0x1000, &gm200_vmm_lpt },
77 { PGD, 13, 8, 0x1000, &gm200_vmm_pgd },
81 const struct nvkm_vmm_desc
82 gm200_vmm_desc_16_12[] = {
83 { SPT, 14, 8, 0x1000, &gm200_vmm_spt },
84 { PGD, 14, 8, 0x1000, &gm200_vmm_pgd },
88 const struct nvkm_vmm_desc
89 gm200_vmm_desc_16_16[] = {
90 { LPT, 10, 8, 0x1000, &gm200_vmm_lpt },
91 { PGD, 14, 8, 0x1000, &gm200_vmm_pgd },
96 gm200_vmm_join_(struct nvkm_vmm *vmm, struct nvkm_memory *inst, u64 base)
98 if (vmm->func->page[1].shift == 16)
100 return gf100_vmm_join_(vmm, inst, base);
104 gm200_vmm_join(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
106 return gm200_vmm_join_(vmm, inst, 0);
109 static const struct nvkm_vmm_func
111 .join = gm200_vmm_join,
112 .part = gf100_vmm_part,
113 .aper = gf100_vmm_aper,
114 .valid = gf100_vmm_valid,
115 .flush = gf100_vmm_flush,
117 { 27, &gm200_vmm_desc_17_17[1], NVKM_VMM_PAGE_Sxxx },
118 { 17, &gm200_vmm_desc_17_17[0], NVKM_VMM_PAGE_SVxC },
119 { 12, &gm200_vmm_desc_17_12[0], NVKM_VMM_PAGE_SVHx },
124 static const struct nvkm_vmm_func
126 .join = gm200_vmm_join,
127 .part = gf100_vmm_part,
128 .aper = gf100_vmm_aper,
129 .valid = gf100_vmm_valid,
130 .flush = gf100_vmm_flush,
132 { 27, &gm200_vmm_desc_16_16[1], NVKM_VMM_PAGE_Sxxx },
133 { 16, &gm200_vmm_desc_16_16[0], NVKM_VMM_PAGE_SVxC },
134 { 12, &gm200_vmm_desc_16_12[0], NVKM_VMM_PAGE_SVHx },
140 gm200_vmm_new_(const struct nvkm_vmm_func *func_16,
141 const struct nvkm_vmm_func *func_17,
142 struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
143 struct lock_class_key *key, const char *name,
144 struct nvkm_vmm **pvmm)
146 const struct nvkm_vmm_func *func;
148 struct gm200_vmm_vn vn;
149 struct gm200_vmm_v0 v0;
153 if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
154 switch (args->v0.bigpage) {
155 case 16: func = func_16; break;
156 case 17: func = func_17; break;
161 if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
166 return nvkm_vmm_new_(func, mmu, 0, addr, size, key, name, pvmm);
170 gm200_vmm_new(struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
171 struct lock_class_key *key, const char *name,
172 struct nvkm_vmm **pvmm)
174 return gm200_vmm_new_(&gm200_vmm_16, &gm200_vmm_17, mmu, addr,
175 size, argv, argc, key, name, pvmm);
179 gm200_vmm_new_fixed(struct nvkm_mmu *mmu, u64 addr, u64 size,
180 void *argv, u32 argc, struct lock_class_key *key,
181 const char *name, struct nvkm_vmm **pvmm)
183 return gf100_vmm_new_(&gm200_vmm_16, &gm200_vmm_17, mmu, addr,
184 size, argv, argc, key, name, pvmm);