]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgf100.c
drm/nouveau/mmu/gf100: implement vmm on top of new base
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / nouveau / nvkm / subdev / mmu / vmmgf100.c
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 #include <subdev/fb.h>
25
26 const struct nvkm_vmm_desc_func
27 gf100_vmm_pgt = {
28 };
29
30 const struct nvkm_vmm_desc_func
31 gf100_vmm_pgd = {
32 };
33
34 static const struct nvkm_vmm_desc
35 gf100_vmm_desc_17_12[] = {
36 { SPT, 15, 8, 0x1000, &gf100_vmm_pgt },
37 { PGD, 13, 8, 0x1000, &gf100_vmm_pgd },
38 {}
39 };
40
41 static const struct nvkm_vmm_desc
42 gf100_vmm_desc_17_17[] = {
43 { LPT, 10, 8, 0x1000, &gf100_vmm_pgt },
44 { PGD, 13, 8, 0x1000, &gf100_vmm_pgd },
45 {}
46 };
47
48 static const struct nvkm_vmm_desc
49 gf100_vmm_desc_16_12[] = {
50 { SPT, 14, 8, 0x1000, &gf100_vmm_pgt },
51 { PGD, 14, 8, 0x1000, &gf100_vmm_pgd },
52 {}
53 };
54
55 static const struct nvkm_vmm_desc
56 gf100_vmm_desc_16_16[] = {
57 { LPT, 10, 8, 0x1000, &gf100_vmm_pgt },
58 { PGD, 14, 8, 0x1000, &gf100_vmm_pgd },
59 {}
60 };
61
62 void
63 gf100_vmm_part(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
64 {
65 nvkm_fo64(inst, 0x0200, 0x00000000, 2);
66 }
67
68 int
69 gf100_vmm_join_(struct nvkm_vmm *vmm, struct nvkm_memory *inst, u64 base)
70 {
71 struct nvkm_mmu_pt *pd = vmm->pd->pt[0];
72
73 switch (nvkm_memory_target(pd->memory)) {
74 case NVKM_MEM_TARGET_VRAM: base |= 0ULL << 0; break;
75 case NVKM_MEM_TARGET_HOST: base |= 2ULL << 0;
76 base |= BIT_ULL(2) /* VOL. */;
77 break;
78 case NVKM_MEM_TARGET_NCOH: base |= 3ULL << 0; break;
79 default:
80 WARN_ON(1);
81 return -EINVAL;
82 }
83 base |= pd->addr;
84
85 nvkm_kmap(inst);
86 nvkm_wo64(inst, 0x0200, base);
87 nvkm_wo64(inst, 0x0208, vmm->limit - 1);
88 nvkm_done(inst);
89 return 0;
90 }
91
92 int
93 gf100_vmm_join(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
94 {
95 return gf100_vmm_join_(vmm, inst, 0);
96 }
97
98 static const struct nvkm_vmm_func
99 gf100_vmm_17 = {
100 .join = gf100_vmm_join,
101 .part = gf100_vmm_part,
102 .page = {
103 { 17, &gf100_vmm_desc_17_17[0], NVKM_VMM_PAGE_xVxC },
104 { 12, &gf100_vmm_desc_17_12[0], NVKM_VMM_PAGE_xVHx },
105 {}
106 }
107 };
108
109 static const struct nvkm_vmm_func
110 gf100_vmm_16 = {
111 .join = gf100_vmm_join,
112 .part = gf100_vmm_part,
113 .page = {
114 { 16, &gf100_vmm_desc_16_16[0], NVKM_VMM_PAGE_xVxC },
115 { 12, &gf100_vmm_desc_16_12[0], NVKM_VMM_PAGE_xVHx },
116 {}
117 }
118 };
119
120 int
121 gf100_vmm_new_(const struct nvkm_vmm_func *func_16,
122 const struct nvkm_vmm_func *func_17,
123 struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
124 struct lock_class_key *key, const char *name,
125 struct nvkm_vmm **pvmm)
126 {
127 switch (mmu->subdev.device->fb->page) {
128 case 16: return nv04_vmm_new_(func_16, mmu, 0, addr, size,
129 argv, argc, key, name, pvmm);
130 case 17: return nv04_vmm_new_(func_17, mmu, 0, addr, size,
131 argv, argc, key, name, pvmm);
132 default:
133 WARN_ON(1);
134 return -EINVAL;
135 }
136 }
137
138 int
139 gf100_vmm_new(struct nvkm_mmu *mmu, u64 addr, u64 size, void *argv, u32 argc,
140 struct lock_class_key *key, const char *name,
141 struct nvkm_vmm **pvmm)
142 {
143 return gf100_vmm_new_(&gf100_vmm_16, &gf100_vmm_17, mmu, addr,
144 size, argv, argc, key, name, pvmm);
145 }