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
,
116 .invalidate_pdb
= gf100_vmm_invalidate_pdb
,
118 { 27, &gm200_vmm_desc_17_17
[1], NVKM_VMM_PAGE_Sxxx
},
119 { 17, &gm200_vmm_desc_17_17
[0], NVKM_VMM_PAGE_SVxC
},
120 { 12, &gm200_vmm_desc_17_12
[0], NVKM_VMM_PAGE_SVHx
},
125 static const struct nvkm_vmm_func
127 .join
= gm200_vmm_join
,
128 .part
= gf100_vmm_part
,
129 .aper
= gf100_vmm_aper
,
130 .valid
= gf100_vmm_valid
,
131 .flush
= gf100_vmm_flush
,
132 .invalidate_pdb
= gf100_vmm_invalidate_pdb
,
134 { 27, &gm200_vmm_desc_16_16
[1], NVKM_VMM_PAGE_Sxxx
},
135 { 16, &gm200_vmm_desc_16_16
[0], NVKM_VMM_PAGE_SVxC
},
136 { 12, &gm200_vmm_desc_16_12
[0], NVKM_VMM_PAGE_SVHx
},
142 gm200_vmm_new_(const struct nvkm_vmm_func
*func_16
,
143 const struct nvkm_vmm_func
*func_17
,
144 struct nvkm_mmu
*mmu
, bool managed
, u64 addr
, u64 size
,
145 void *argv
, u32 argc
, struct lock_class_key
*key
,
146 const char *name
, struct nvkm_vmm
**pvmm
)
148 const struct nvkm_vmm_func
*func
;
150 struct gm200_vmm_vn vn
;
151 struct gm200_vmm_v0 v0
;
155 if (!(ret
= nvif_unpack(ret
, &argv
, &argc
, args
->v0
, 0, 0, false))) {
156 switch (args
->v0
.bigpage
) {
157 case 16: func
= func_16
; break;
158 case 17: func
= func_17
; break;
163 if (!(ret
= nvif_unvers(ret
, &argv
, &argc
, args
->vn
))) {
168 return nvkm_vmm_new_(func
, mmu
, 0, managed
, addr
, size
, key
, name
, pvmm
);
172 gm200_vmm_new(struct nvkm_mmu
*mmu
, bool managed
, u64 addr
, u64 size
,
173 void *argv
, u32 argc
, struct lock_class_key
*key
,
174 const char *name
, struct nvkm_vmm
**pvmm
)
176 return gm200_vmm_new_(&gm200_vmm_16
, &gm200_vmm_17
, mmu
, managed
, addr
,
177 size
, argv
, argc
, key
, name
, pvmm
);
181 gm200_vmm_new_fixed(struct nvkm_mmu
*mmu
, bool managed
, u64 addr
, u64 size
,
182 void *argv
, u32 argc
, struct lock_class_key
*key
,
183 const char *name
, struct nvkm_vmm
**pvmm
)
185 return gf100_vmm_new_(&gm200_vmm_16
, &gm200_vmm_17
, mmu
, managed
, addr
,
186 size
, argv
, argc
, key
, name
, pvmm
);