xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgk104.c (revision 791d3ef2e11100449837dc0b6fe884e60ca3a484)
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 	.page = {
75 		{ 17, &gk104_vmm_desc_17_17[0], NVKM_VMM_PAGE_xVxC },
76 		{ 12, &gk104_vmm_desc_17_12[0], NVKM_VMM_PAGE_xVHx },
77 		{}
78 	}
79 };
80 
81 static const struct nvkm_vmm_func
82 gk104_vmm_16 = {
83 	.join = gf100_vmm_join,
84 	.part = gf100_vmm_part,
85 	.aper = gf100_vmm_aper,
86 	.valid = gf100_vmm_valid,
87 	.flush = gf100_vmm_flush,
88 	.page = {
89 		{ 16, &gk104_vmm_desc_16_16[0], NVKM_VMM_PAGE_xVxC },
90 		{ 12, &gk104_vmm_desc_16_12[0], NVKM_VMM_PAGE_xVHx },
91 		{}
92 	}
93 };
94 
95 int
96 gk104_vmm_new(struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
97 	      struct lock_class_key *key, const char *name,
98 	      struct nvkm_vmm **pvmm)
99 {
100 	return gf100_vmm_new_(&gk104_vmm_16, &gk104_vmm_17, mmu, addr,
101 			      size, argv, argc, key, name, pvmm);
102 }
103