1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "vmm.h"
23
24#include <nvif/ifb00d.h>
25#include <nvif/unpack.h>
26
27static void
28gm200_vmm_pgt_sparse(struct nvkm_vmm *vmm,
29 struct nvkm_mmu_pt *pt, u32 ptei, u32 ptes)
30{
31
32 VMM_FO064(pt, vmm, ptei * 8, BIT_ULL(32) , ptes);
33}
34
35static const struct nvkm_vmm_desc_func
36gm200_vmm_spt = {
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,
42};
43
44static const struct nvkm_vmm_desc_func
45gm200_vmm_lpt = {
46 .invalid = gk104_vmm_lpt_invalid,
47 .unmap = gf100_vmm_pgt_unmap,
48 .sparse = gm200_vmm_pgt_sparse,
49 .mem = gf100_vmm_pgt_mem,
50};
51
52static void
53gm200_vmm_pgd_sparse(struct nvkm_vmm *vmm,
54 struct nvkm_mmu_pt *pt, u32 pdei, u32 pdes)
55{
56
57 VMM_FO064(pt, vmm, pdei * 8, BIT_ULL(35) , pdes);
58}
59
60static const struct nvkm_vmm_desc_func
61gm200_vmm_pgd = {
62 .unmap = gf100_vmm_pgt_unmap,
63 .sparse = gm200_vmm_pgd_sparse,
64 .pde = gf100_vmm_pgd_pde,
65};
66
67const struct nvkm_vmm_desc
68gm200_vmm_desc_17_12[] = {
69 { SPT, 15, 8, 0x1000, &gm200_vmm_spt },
70 { PGD, 13, 8, 0x1000, &gm200_vmm_pgd },
71 {}
72};
73
74const struct nvkm_vmm_desc
75gm200_vmm_desc_17_17[] = {
76 { LPT, 10, 8, 0x1000, &gm200_vmm_lpt },
77 { PGD, 13, 8, 0x1000, &gm200_vmm_pgd },
78 {}
79};
80
81const struct nvkm_vmm_desc
82gm200_vmm_desc_16_12[] = {
83 { SPT, 14, 8, 0x1000, &gm200_vmm_spt },
84 { PGD, 14, 8, 0x1000, &gm200_vmm_pgd },
85 {}
86};
87
88const struct nvkm_vmm_desc
89gm200_vmm_desc_16_16[] = {
90 { LPT, 10, 8, 0x1000, &gm200_vmm_lpt },
91 { PGD, 14, 8, 0x1000, &gm200_vmm_pgd },
92 {}
93};
94
95int
96gm200_vmm_join_(struct nvkm_vmm *vmm, struct nvkm_memory *inst, u64 base)
97{
98 if (vmm->func->page[1].shift == 16)
99 base |= BIT_ULL(11);
100 return gf100_vmm_join_(vmm, inst, base);
101}
102
103int
104gm200_vmm_join(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
105{
106 return gm200_vmm_join_(vmm, inst, 0);
107}
108
109static const struct nvkm_vmm_func
110gm200_vmm_17 = {
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,
116 .page = {
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 },
120 {}
121 }
122};
123
124static const struct nvkm_vmm_func
125gm200_vmm_16 = {
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,
131 .page = {
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 },
135 {}
136 }
137};
138
139int
140gm200_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)
145{
146 const struct nvkm_vmm_func *func;
147 union {
148 struct gm200_vmm_vn vn;
149 struct gm200_vmm_v0 v0;
150 } *args = argv;
151 int ret = -ENOSYS;
152
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;
157 default:
158 return -EINVAL;
159 }
160 } else
161 if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
162 func = func_17;
163 } else
164 return ret;
165
166 return nvkm_vmm_new_(func, mmu, 0, addr, size, key, name, pvmm);
167}
168
169int
170gm200_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)
173{
174 return gm200_vmm_new_(&gm200_vmm_16, &gm200_vmm_17, mmu, addr,
175 size, argv, argc, key, name, pvmm);
176}
177
178int
179gm200_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)
182{
183 return gf100_vmm_new_(&gm200_vmm_16, &gm200_vmm_17, mmu, addr,
184 size, argv, argc, key, name, pvmm);
185}
186