xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgk104.c (revision 26fbb4c8c7c3ee9a4c3b4de555a8587b5a19154e)
1 /*
2  * Copyright 2017 Red Hat Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  */
22 #include "vmm.h"
23 
24 void
25 gk104_vmm_lpt_invalid(struct nvkm_vmm *vmm,
26 		      struct nvkm_mmu_pt *pt, u32 ptei, u32 ptes)
27 {
28 	/* VALID_FALSE + PRIV tells the MMU to ignore corresponding SPTEs. */
29 	VMM_FO064(pt, vmm, ptei * 8, BIT_ULL(1) /* PRIV. */, ptes);
30 }
31 
32 static const struct nvkm_vmm_desc_func
33 gk104_vmm_lpt = {
34 	.invalid = gk104_vmm_lpt_invalid,
35 	.unmap = gf100_vmm_pgt_unmap,
36 	.mem = gf100_vmm_pgt_mem,
37 };
38 
39 const struct nvkm_vmm_desc
40 gk104_vmm_desc_17_12[] = {
41 	{ SPT, 15, 8, 0x1000, &gf100_vmm_pgt },
42 	{ PGD, 13, 8, 0x1000, &gf100_vmm_pgd },
43 	{}
44 };
45 
46 const struct nvkm_vmm_desc
47 gk104_vmm_desc_17_17[] = {
48 	{ LPT, 10, 8, 0x1000, &gk104_vmm_lpt },
49 	{ PGD, 13, 8, 0x1000, &gf100_vmm_pgd },
50 	{}
51 };
52 
53 const struct nvkm_vmm_desc
54 gk104_vmm_desc_16_12[] = {
55 	{ SPT, 14, 8, 0x1000, &gf100_vmm_pgt },
56 	{ PGD, 14, 8, 0x1000, &gf100_vmm_pgd },
57 	{}
58 };
59 
60 const struct nvkm_vmm_desc
61 gk104_vmm_desc_16_16[] = {
62 	{ LPT, 10, 8, 0x1000, &gk104_vmm_lpt },
63 	{ PGD, 14, 8, 0x1000, &gf100_vmm_pgd },
64 	{}
65 };
66 
67 static const struct nvkm_vmm_func
68 gk104_vmm_17 = {
69 	.join = gf100_vmm_join,
70 	.part = gf100_vmm_part,
71 	.aper = gf100_vmm_aper,
72 	.valid = gf100_vmm_valid,
73 	.flush = gf100_vmm_flush,
74 	.invalidate_pdb = gf100_vmm_invalidate_pdb,
75 	.page = {
76 		{ 17, &gk104_vmm_desc_17_17[0], NVKM_VMM_PAGE_xVxC },
77 		{ 12, &gk104_vmm_desc_17_12[0], NVKM_VMM_PAGE_xVHx },
78 		{}
79 	}
80 };
81 
82 static const struct nvkm_vmm_func
83 gk104_vmm_16 = {
84 	.join = gf100_vmm_join,
85 	.part = gf100_vmm_part,
86 	.aper = gf100_vmm_aper,
87 	.valid = gf100_vmm_valid,
88 	.flush = gf100_vmm_flush,
89 	.invalidate_pdb = gf100_vmm_invalidate_pdb,
90 	.page = {
91 		{ 16, &gk104_vmm_desc_16_16[0], NVKM_VMM_PAGE_xVxC },
92 		{ 12, &gk104_vmm_desc_16_12[0], NVKM_VMM_PAGE_xVHx },
93 		{}
94 	}
95 };
96 
97 int
98 gk104_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
99 	      void *argv, u32 argc, struct lock_class_key *key,
100 	      const char *name, struct nvkm_vmm **pvmm)
101 {
102 	return gf100_vmm_new_(&gk104_vmm_16, &gk104_vmm_17, mmu, managed, addr,
103 			      size, argv, argc, key, name, pvmm);
104 }
105