1540a1ddeSBen Skeggs /*
2540a1ddeSBen Skeggs * Copyright 2017 Red Hat Inc.
3540a1ddeSBen Skeggs *
4540a1ddeSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5540a1ddeSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6540a1ddeSBen Skeggs * to deal in the Software without restriction, including without limitation
7540a1ddeSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8540a1ddeSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9540a1ddeSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10540a1ddeSBen Skeggs *
11540a1ddeSBen Skeggs * The above copyright notice and this permission notice shall be included in
12540a1ddeSBen Skeggs * all copies or substantial portions of the Software.
13540a1ddeSBen Skeggs *
14540a1ddeSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15540a1ddeSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16540a1ddeSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17540a1ddeSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18540a1ddeSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19540a1ddeSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20540a1ddeSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21540a1ddeSBen Skeggs */
22540a1ddeSBen Skeggs #include "vmm.h"
23540a1ddeSBen Skeggs
24540a1ddeSBen Skeggs #include <subdev/fb.h>
25b77791daSBen Skeggs #include <subdev/ltc.h>
26b77791daSBen Skeggs #include <subdev/timer.h>
27b77791daSBen Skeggs
28b77791daSBen Skeggs #include <nvif/if900d.h>
29b77791daSBen Skeggs #include <nvif/unpack.h>
30b77791daSBen Skeggs
31b77791daSBen Skeggs static inline void
gf100_vmm_pgt_pte(struct nvkm_vmm * vmm,struct nvkm_mmu_pt * pt,u32 ptei,u32 ptes,struct nvkm_vmm_map * map,u64 addr)32b77791daSBen Skeggs gf100_vmm_pgt_pte(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
33b77791daSBen Skeggs u32 ptei, u32 ptes, struct nvkm_vmm_map *map, u64 addr)
34b77791daSBen Skeggs {
35b77791daSBen Skeggs u64 base = (addr >> 8) | map->type;
36b77791daSBen Skeggs u64 data = base;
37b77791daSBen Skeggs
38b77791daSBen Skeggs if (map->ctag && !(map->next & (1ULL << 44))) {
39b77791daSBen Skeggs while (ptes--) {
40b77791daSBen Skeggs data = base | ((map->ctag >> 1) << 44);
41b77791daSBen Skeggs if (!(map->ctag++ & 1))
42b77791daSBen Skeggs data |= BIT_ULL(60);
43b77791daSBen Skeggs
44b77791daSBen Skeggs VMM_WO064(pt, vmm, ptei++ * 8, data);
45b77791daSBen Skeggs base += map->next;
46b77791daSBen Skeggs }
47b77791daSBen Skeggs } else {
48b77791daSBen Skeggs map->type += ptes * map->ctag;
49b77791daSBen Skeggs
50b77791daSBen Skeggs while (ptes--) {
51b77791daSBen Skeggs VMM_WO064(pt, vmm, ptei++ * 8, data);
52b77791daSBen Skeggs data += map->next;
53b77791daSBen Skeggs }
54b77791daSBen Skeggs }
55b77791daSBen Skeggs }
56b77791daSBen Skeggs
57b77791daSBen Skeggs void
gf100_vmm_pgt_sgl(struct nvkm_vmm * vmm,struct nvkm_mmu_pt * pt,u32 ptei,u32 ptes,struct nvkm_vmm_map * map)58b77791daSBen Skeggs gf100_vmm_pgt_sgl(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
59b77791daSBen Skeggs u32 ptei, u32 ptes, struct nvkm_vmm_map *map)
60b77791daSBen Skeggs {
61b77791daSBen Skeggs VMM_MAP_ITER_SGL(vmm, pt, ptei, ptes, map, gf100_vmm_pgt_pte);
62b77791daSBen Skeggs }
63b77791daSBen Skeggs
64b77791daSBen Skeggs void
gf100_vmm_pgt_dma(struct nvkm_vmm * vmm,struct nvkm_mmu_pt * pt,u32 ptei,u32 ptes,struct nvkm_vmm_map * map)65b77791daSBen Skeggs gf100_vmm_pgt_dma(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
66b77791daSBen Skeggs u32 ptei, u32 ptes, struct nvkm_vmm_map *map)
67b77791daSBen Skeggs {
68b77791daSBen Skeggs if (map->page->shift == PAGE_SHIFT) {
69b77791daSBen Skeggs VMM_SPAM(vmm, "DMAA %08x %08x PTE(s)", ptei, ptes);
70b77791daSBen Skeggs nvkm_kmap(pt->memory);
71b77791daSBen Skeggs while (ptes--) {
72b77791daSBen Skeggs const u64 data = (*map->dma++ >> 8) | map->type;
73b77791daSBen Skeggs VMM_WO064(pt, vmm, ptei++ * 8, data);
74b77791daSBen Skeggs map->type += map->ctag;
75b77791daSBen Skeggs }
76b77791daSBen Skeggs nvkm_done(pt->memory);
77b77791daSBen Skeggs return;
78b77791daSBen Skeggs }
79b77791daSBen Skeggs
80b77791daSBen Skeggs VMM_MAP_ITER_DMA(vmm, pt, ptei, ptes, map, gf100_vmm_pgt_pte);
81b77791daSBen Skeggs }
82b77791daSBen Skeggs
83b77791daSBen Skeggs void
gf100_vmm_pgt_mem(struct nvkm_vmm * vmm,struct nvkm_mmu_pt * pt,u32 ptei,u32 ptes,struct nvkm_vmm_map * map)84b77791daSBen Skeggs gf100_vmm_pgt_mem(struct nvkm_vmm *vmm, struct nvkm_mmu_pt *pt,
85b77791daSBen Skeggs u32 ptei, u32 ptes, struct nvkm_vmm_map *map)
86b77791daSBen Skeggs {
87b77791daSBen Skeggs VMM_MAP_ITER_MEM(vmm, pt, ptei, ptes, map, gf100_vmm_pgt_pte);
88b77791daSBen Skeggs }
89b77791daSBen Skeggs
90b77791daSBen Skeggs void
gf100_vmm_pgt_unmap(struct nvkm_vmm * vmm,struct nvkm_mmu_pt * pt,u32 ptei,u32 ptes)91b77791daSBen Skeggs gf100_vmm_pgt_unmap(struct nvkm_vmm *vmm,
92b77791daSBen Skeggs struct nvkm_mmu_pt *pt, u32 ptei, u32 ptes)
93b77791daSBen Skeggs {
94b77791daSBen Skeggs VMM_FO064(pt, vmm, ptei * 8, 0ULL, ptes);
95b77791daSBen Skeggs }
96540a1ddeSBen Skeggs
97540a1ddeSBen Skeggs const struct nvkm_vmm_desc_func
98540a1ddeSBen Skeggs gf100_vmm_pgt = {
99b77791daSBen Skeggs .unmap = gf100_vmm_pgt_unmap,
100b77791daSBen Skeggs .mem = gf100_vmm_pgt_mem,
101b77791daSBen Skeggs .dma = gf100_vmm_pgt_dma,
102b77791daSBen Skeggs .sgl = gf100_vmm_pgt_sgl,
103540a1ddeSBen Skeggs };
104540a1ddeSBen Skeggs
105b77791daSBen Skeggs void
gf100_vmm_pgd_pde(struct nvkm_vmm * vmm,struct nvkm_vmm_pt * pgd,u32 pdei)106b77791daSBen Skeggs gf100_vmm_pgd_pde(struct nvkm_vmm *vmm, struct nvkm_vmm_pt *pgd, u32 pdei)
107b77791daSBen Skeggs {
108b77791daSBen Skeggs struct nvkm_vmm_pt *pgt = pgd->pde[pdei];
109b77791daSBen Skeggs struct nvkm_mmu_pt *pd = pgd->pt[0];
110b77791daSBen Skeggs struct nvkm_mmu_pt *pt;
111b77791daSBen Skeggs u64 data = 0;
112b77791daSBen Skeggs
113b77791daSBen Skeggs if ((pt = pgt->pt[0])) {
114b77791daSBen Skeggs switch (nvkm_memory_target(pt->memory)) {
115b77791daSBen Skeggs case NVKM_MEM_TARGET_VRAM: data |= 1ULL << 0; break;
116b77791daSBen Skeggs case NVKM_MEM_TARGET_HOST: data |= 2ULL << 0;
117b77791daSBen Skeggs data |= BIT_ULL(35); /* VOL */
118b77791daSBen Skeggs break;
119b77791daSBen Skeggs case NVKM_MEM_TARGET_NCOH: data |= 3ULL << 0; break;
120b77791daSBen Skeggs default:
121b77791daSBen Skeggs WARN_ON(1);
122b77791daSBen Skeggs return;
123b77791daSBen Skeggs }
124b77791daSBen Skeggs data |= pt->addr >> 8;
125b77791daSBen Skeggs }
126b77791daSBen Skeggs
127b77791daSBen Skeggs if ((pt = pgt->pt[1])) {
128b77791daSBen Skeggs switch (nvkm_memory_target(pt->memory)) {
129b77791daSBen Skeggs case NVKM_MEM_TARGET_VRAM: data |= 1ULL << 32; break;
130b77791daSBen Skeggs case NVKM_MEM_TARGET_HOST: data |= 2ULL << 32;
131b77791daSBen Skeggs data |= BIT_ULL(34); /* VOL */
132b77791daSBen Skeggs break;
133b77791daSBen Skeggs case NVKM_MEM_TARGET_NCOH: data |= 3ULL << 32; break;
134b77791daSBen Skeggs default:
135b77791daSBen Skeggs WARN_ON(1);
136b77791daSBen Skeggs return;
137b77791daSBen Skeggs }
138b77791daSBen Skeggs data |= pt->addr << 24;
139b77791daSBen Skeggs }
140b77791daSBen Skeggs
141b77791daSBen Skeggs nvkm_kmap(pd->memory);
142b77791daSBen Skeggs VMM_WO064(pd, vmm, pdei * 8, data);
143b77791daSBen Skeggs nvkm_done(pd->memory);
144b77791daSBen Skeggs }
145b77791daSBen Skeggs
146540a1ddeSBen Skeggs const struct nvkm_vmm_desc_func
147540a1ddeSBen Skeggs gf100_vmm_pgd = {
148b77791daSBen Skeggs .unmap = gf100_vmm_pgt_unmap,
149b77791daSBen Skeggs .pde = gf100_vmm_pgd_pde,
150540a1ddeSBen Skeggs };
151540a1ddeSBen Skeggs
152540a1ddeSBen Skeggs static const struct nvkm_vmm_desc
153540a1ddeSBen Skeggs gf100_vmm_desc_17_12[] = {
154540a1ddeSBen Skeggs { SPT, 15, 8, 0x1000, &gf100_vmm_pgt },
155540a1ddeSBen Skeggs { PGD, 13, 8, 0x1000, &gf100_vmm_pgd },
156540a1ddeSBen Skeggs {}
157540a1ddeSBen Skeggs };
158540a1ddeSBen Skeggs
159540a1ddeSBen Skeggs static const struct nvkm_vmm_desc
160540a1ddeSBen Skeggs gf100_vmm_desc_17_17[] = {
161540a1ddeSBen Skeggs { LPT, 10, 8, 0x1000, &gf100_vmm_pgt },
162540a1ddeSBen Skeggs { PGD, 13, 8, 0x1000, &gf100_vmm_pgd },
163540a1ddeSBen Skeggs {}
164540a1ddeSBen Skeggs };
165540a1ddeSBen Skeggs
166540a1ddeSBen Skeggs static const struct nvkm_vmm_desc
167540a1ddeSBen Skeggs gf100_vmm_desc_16_12[] = {
168540a1ddeSBen Skeggs { SPT, 14, 8, 0x1000, &gf100_vmm_pgt },
169540a1ddeSBen Skeggs { PGD, 14, 8, 0x1000, &gf100_vmm_pgd },
170540a1ddeSBen Skeggs {}
171540a1ddeSBen Skeggs };
172540a1ddeSBen Skeggs
173540a1ddeSBen Skeggs static const struct nvkm_vmm_desc
174540a1ddeSBen Skeggs gf100_vmm_desc_16_16[] = {
175540a1ddeSBen Skeggs { LPT, 10, 8, 0x1000, &gf100_vmm_pgt },
176540a1ddeSBen Skeggs { PGD, 14, 8, 0x1000, &gf100_vmm_pgd },
177540a1ddeSBen Skeggs {}
178540a1ddeSBen Skeggs };
179540a1ddeSBen Skeggs
180540a1ddeSBen Skeggs void
gf100_vmm_invalidate_pdb(struct nvkm_vmm * vmm,u64 addr)181d389fd4fSBen Skeggs gf100_vmm_invalidate_pdb(struct nvkm_vmm *vmm, u64 addr)
182d389fd4fSBen Skeggs {
183d389fd4fSBen Skeggs struct nvkm_device *device = vmm->mmu->subdev.device;
184d389fd4fSBen Skeggs nvkm_wr32(device, 0x100cb8, addr);
185d389fd4fSBen Skeggs }
186d389fd4fSBen Skeggs
187d389fd4fSBen Skeggs void
gf100_vmm_invalidate(struct nvkm_vmm * vmm,u32 type)188874c1b56SBen Skeggs gf100_vmm_invalidate(struct nvkm_vmm *vmm, u32 type)
189b77791daSBen Skeggs {
1905ec69c91SBen Skeggs struct nvkm_device *device = vmm->mmu->subdev.device;
191d389fd4fSBen Skeggs struct nvkm_mmu_pt *pd = vmm->pd->pt[0];
192d389fd4fSBen Skeggs u64 addr = 0;
193b77791daSBen Skeggs
1945ec69c91SBen Skeggs mutex_lock(&vmm->mmu->mutex);
195b77791daSBen Skeggs /* Looks like maybe a "free flush slots" counter, the
196b77791daSBen Skeggs * faster you write to 0x100cbc to more it decreases.
197b77791daSBen Skeggs */
198b77791daSBen Skeggs nvkm_msec(device, 2000,
199b77791daSBen Skeggs if (nvkm_rd32(device, 0x100c80) & 0x00ff0000)
200b77791daSBen Skeggs break;
201b77791daSBen Skeggs );
202b77791daSBen Skeggs
203d389fd4fSBen Skeggs if (!(type & 0x00000002) /* ALL_PDB. */) {
204d389fd4fSBen Skeggs switch (nvkm_memory_target(pd->memory)) {
205d389fd4fSBen Skeggs case NVKM_MEM_TARGET_VRAM: addr |= 0x00000000; break;
206d389fd4fSBen Skeggs case NVKM_MEM_TARGET_HOST: addr |= 0x00000002; break;
207d389fd4fSBen Skeggs case NVKM_MEM_TARGET_NCOH: addr |= 0x00000003; break;
208d389fd4fSBen Skeggs default:
209d389fd4fSBen Skeggs WARN_ON(1);
210d389fd4fSBen Skeggs break;
211d389fd4fSBen Skeggs }
212d389fd4fSBen Skeggs addr |= (vmm->pd->pt[0]->addr >> 12) << 4;
213d389fd4fSBen Skeggs
214d389fd4fSBen Skeggs vmm->func->invalidate_pdb(vmm, addr);
215d389fd4fSBen Skeggs }
216d389fd4fSBen Skeggs
217b77791daSBen Skeggs nvkm_wr32(device, 0x100cbc, 0x80000000 | type);
218b77791daSBen Skeggs
219b77791daSBen Skeggs /* Wait for flush to be queued? */
220b77791daSBen Skeggs nvkm_msec(device, 2000,
221b77791daSBen Skeggs if (nvkm_rd32(device, 0x100c80) & 0x00008000)
222b77791daSBen Skeggs break;
223b77791daSBen Skeggs );
2245ec69c91SBen Skeggs mutex_unlock(&vmm->mmu->mutex);
225b77791daSBen Skeggs }
226b77791daSBen Skeggs
227b77791daSBen Skeggs void
gf100_vmm_flush(struct nvkm_vmm * vmm,int depth)228b77791daSBen Skeggs gf100_vmm_flush(struct nvkm_vmm *vmm, int depth)
229b77791daSBen Skeggs {
230874c1b56SBen Skeggs u32 type = 0x00000001; /* PAGE_ALL */
231874c1b56SBen Skeggs if (atomic_read(&vmm->engref[NVKM_SUBDEV_BAR]))
232874c1b56SBen Skeggs type |= 0x00000004; /* HUB_ONLY */
233874c1b56SBen Skeggs gf100_vmm_invalidate(vmm, type);
234b77791daSBen Skeggs }
235b77791daSBen Skeggs
236b77791daSBen Skeggs int
gf100_vmm_valid(struct nvkm_vmm * vmm,void * argv,u32 argc,struct nvkm_vmm_map * map)237b77791daSBen Skeggs gf100_vmm_valid(struct nvkm_vmm *vmm, void *argv, u32 argc,
238b77791daSBen Skeggs struct nvkm_vmm_map *map)
239b77791daSBen Skeggs {
240b77791daSBen Skeggs const enum nvkm_memory_target target = nvkm_memory_target(map->memory);
241b77791daSBen Skeggs const struct nvkm_vmm_page *page = map->page;
242b77791daSBen Skeggs const bool gm20x = page->desc->func->sparse != NULL;
243b77791daSBen Skeggs union {
244b77791daSBen Skeggs struct gf100_vmm_map_vn vn;
245b77791daSBen Skeggs struct gf100_vmm_map_v0 v0;
246b77791daSBen Skeggs } *args = argv;
247b77791daSBen Skeggs struct nvkm_device *device = vmm->mmu->subdev.device;
248b77791daSBen Skeggs struct nvkm_memory *memory = map->memory;
249176ada03SJames Jones u8 kind, kind_inv, priv, ro, vol;
250b77791daSBen Skeggs int kindn, aper, ret = -ENOSYS;
251b77791daSBen Skeggs const u8 *kindm;
252b77791daSBen Skeggs
253b77791daSBen Skeggs map->next = (1 << page->shift) >> 8;
254b77791daSBen Skeggs map->type = map->ctag = 0;
255b77791daSBen Skeggs
256b77791daSBen Skeggs if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
257b77791daSBen Skeggs vol = !!args->v0.vol;
258b77791daSBen Skeggs ro = !!args->v0.ro;
259b77791daSBen Skeggs priv = !!args->v0.priv;
260b77791daSBen Skeggs kind = args->v0.kind;
261b77791daSBen Skeggs } else
262b77791daSBen Skeggs if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
263b77791daSBen Skeggs vol = target == NVKM_MEM_TARGET_HOST;
264b77791daSBen Skeggs ro = 0;
265b77791daSBen Skeggs priv = 0;
266b77791daSBen Skeggs kind = 0x00;
267b77791daSBen Skeggs } else {
268b77791daSBen Skeggs VMM_DEBUG(vmm, "args");
269b77791daSBen Skeggs return ret;
270b77791daSBen Skeggs }
271b77791daSBen Skeggs
272b77791daSBen Skeggs aper = vmm->func->aper(target);
273b77791daSBen Skeggs if (WARN_ON(aper < 0))
274b77791daSBen Skeggs return aper;
275b77791daSBen Skeggs
276176ada03SJames Jones kindm = vmm->mmu->func->kind(vmm->mmu, &kindn, &kind_inv);
277176ada03SJames Jones if (kind >= kindn || kindm[kind] == kind_inv) {
278b77791daSBen Skeggs VMM_DEBUG(vmm, "kind %02x", kind);
279b77791daSBen Skeggs return -EINVAL;
280b77791daSBen Skeggs }
281b77791daSBen Skeggs
282b77791daSBen Skeggs if (kindm[kind] != kind) {
283b77791daSBen Skeggs u32 comp = (page->shift == 16 && !gm20x) ? 16 : 17;
284b77791daSBen Skeggs u32 tags = ALIGN(nvkm_memory_size(memory), 1 << 17) >> comp;
285b77791daSBen Skeggs if (aper != 0 || !(page->type & NVKM_VMM_PAGE_COMP)) {
286b77791daSBen Skeggs VMM_DEBUG(vmm, "comp %d %02x", aper, page->type);
287b77791daSBen Skeggs return -EINVAL;
288b77791daSBen Skeggs }
289b77791daSBen Skeggs
290*6b252cf4SDanilo Krummrich if (!map->no_comp) {
291b77791daSBen Skeggs ret = nvkm_memory_tags_get(memory, device, tags,
292b77791daSBen Skeggs nvkm_ltc_tags_clear,
293b77791daSBen Skeggs &map->tags);
294b77791daSBen Skeggs if (ret) {
295b77791daSBen Skeggs VMM_DEBUG(vmm, "comp %d", ret);
296b77791daSBen Skeggs return ret;
297b77791daSBen Skeggs }
298*6b252cf4SDanilo Krummrich }
299b77791daSBen Skeggs
300*6b252cf4SDanilo Krummrich if (!map->no_comp && map->tags->mn) {
301b77791daSBen Skeggs u64 tags = map->tags->mn->offset + (map->offset >> 17);
302b77791daSBen Skeggs if (page->shift == 17 || !gm20x) {
303b77791daSBen Skeggs map->type |= tags << 44;
304b77791daSBen Skeggs map->ctag |= 1ULL << 44;
305b77791daSBen Skeggs map->next |= 1ULL << 44;
306b77791daSBen Skeggs } else {
307b77791daSBen Skeggs map->ctag |= tags << 1 | 1;
308b77791daSBen Skeggs }
309b77791daSBen Skeggs } else {
310b77791daSBen Skeggs kind = kindm[kind];
311b77791daSBen Skeggs }
312b77791daSBen Skeggs }
313b77791daSBen Skeggs
314b77791daSBen Skeggs map->type |= BIT(0);
315b77791daSBen Skeggs map->type |= (u64)priv << 1;
316b77791daSBen Skeggs map->type |= (u64) ro << 2;
317b77791daSBen Skeggs map->type |= (u64) vol << 32;
318b77791daSBen Skeggs map->type |= (u64)aper << 33;
319b77791daSBen Skeggs map->type |= (u64)kind << 36;
320b77791daSBen Skeggs return 0;
321b77791daSBen Skeggs }
322b77791daSBen Skeggs
323b77791daSBen Skeggs int
gf100_vmm_aper(enum nvkm_memory_target target)324b77791daSBen Skeggs gf100_vmm_aper(enum nvkm_memory_target target)
325b77791daSBen Skeggs {
326b77791daSBen Skeggs switch (target) {
327b77791daSBen Skeggs case NVKM_MEM_TARGET_VRAM: return 0;
328b77791daSBen Skeggs case NVKM_MEM_TARGET_HOST: return 2;
329b77791daSBen Skeggs case NVKM_MEM_TARGET_NCOH: return 3;
330b77791daSBen Skeggs default:
331b77791daSBen Skeggs return -EINVAL;
332b77791daSBen Skeggs }
333b77791daSBen Skeggs }
334b77791daSBen Skeggs
335b77791daSBen Skeggs void
gf100_vmm_part(struct nvkm_vmm * vmm,struct nvkm_memory * inst)336540a1ddeSBen Skeggs gf100_vmm_part(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
337540a1ddeSBen Skeggs {
338540a1ddeSBen Skeggs nvkm_fo64(inst, 0x0200, 0x00000000, 2);
339540a1ddeSBen Skeggs }
340540a1ddeSBen Skeggs
341540a1ddeSBen Skeggs int
gf100_vmm_join_(struct nvkm_vmm * vmm,struct nvkm_memory * inst,u64 base)342540a1ddeSBen Skeggs gf100_vmm_join_(struct nvkm_vmm *vmm, struct nvkm_memory *inst, u64 base)
343540a1ddeSBen Skeggs {
344540a1ddeSBen Skeggs struct nvkm_mmu_pt *pd = vmm->pd->pt[0];
345540a1ddeSBen Skeggs
346540a1ddeSBen Skeggs switch (nvkm_memory_target(pd->memory)) {
347540a1ddeSBen Skeggs case NVKM_MEM_TARGET_VRAM: base |= 0ULL << 0; break;
348540a1ddeSBen Skeggs case NVKM_MEM_TARGET_HOST: base |= 2ULL << 0;
349540a1ddeSBen Skeggs base |= BIT_ULL(2) /* VOL. */;
350540a1ddeSBen Skeggs break;
351540a1ddeSBen Skeggs case NVKM_MEM_TARGET_NCOH: base |= 3ULL << 0; break;
352540a1ddeSBen Skeggs default:
353540a1ddeSBen Skeggs WARN_ON(1);
354540a1ddeSBen Skeggs return -EINVAL;
355540a1ddeSBen Skeggs }
356540a1ddeSBen Skeggs base |= pd->addr;
357540a1ddeSBen Skeggs
358540a1ddeSBen Skeggs nvkm_kmap(inst);
359540a1ddeSBen Skeggs nvkm_wo64(inst, 0x0200, base);
360540a1ddeSBen Skeggs nvkm_wo64(inst, 0x0208, vmm->limit - 1);
361540a1ddeSBen Skeggs nvkm_done(inst);
362540a1ddeSBen Skeggs return 0;
363540a1ddeSBen Skeggs }
364540a1ddeSBen Skeggs
365540a1ddeSBen Skeggs int
gf100_vmm_join(struct nvkm_vmm * vmm,struct nvkm_memory * inst)366540a1ddeSBen Skeggs gf100_vmm_join(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
367540a1ddeSBen Skeggs {
368540a1ddeSBen Skeggs return gf100_vmm_join_(vmm, inst, 0);
369540a1ddeSBen Skeggs }
370540a1ddeSBen Skeggs
371540a1ddeSBen Skeggs static const struct nvkm_vmm_func
372540a1ddeSBen Skeggs gf100_vmm_17 = {
373540a1ddeSBen Skeggs .join = gf100_vmm_join,
374540a1ddeSBen Skeggs .part = gf100_vmm_part,
375b77791daSBen Skeggs .aper = gf100_vmm_aper,
376b77791daSBen Skeggs .valid = gf100_vmm_valid,
377b77791daSBen Skeggs .flush = gf100_vmm_flush,
378d389fd4fSBen Skeggs .invalidate_pdb = gf100_vmm_invalidate_pdb,
379540a1ddeSBen Skeggs .page = {
380540a1ddeSBen Skeggs { 17, &gf100_vmm_desc_17_17[0], NVKM_VMM_PAGE_xVxC },
381540a1ddeSBen Skeggs { 12, &gf100_vmm_desc_17_12[0], NVKM_VMM_PAGE_xVHx },
382540a1ddeSBen Skeggs {}
383540a1ddeSBen Skeggs }
384540a1ddeSBen Skeggs };
385540a1ddeSBen Skeggs
386540a1ddeSBen Skeggs static const struct nvkm_vmm_func
387540a1ddeSBen Skeggs gf100_vmm_16 = {
388540a1ddeSBen Skeggs .join = gf100_vmm_join,
389540a1ddeSBen Skeggs .part = gf100_vmm_part,
390b77791daSBen Skeggs .aper = gf100_vmm_aper,
391b77791daSBen Skeggs .valid = gf100_vmm_valid,
392b77791daSBen Skeggs .flush = gf100_vmm_flush,
393d389fd4fSBen Skeggs .invalidate_pdb = gf100_vmm_invalidate_pdb,
394540a1ddeSBen Skeggs .page = {
395540a1ddeSBen Skeggs { 16, &gf100_vmm_desc_16_16[0], NVKM_VMM_PAGE_xVxC },
396540a1ddeSBen Skeggs { 12, &gf100_vmm_desc_16_12[0], NVKM_VMM_PAGE_xVHx },
397540a1ddeSBen Skeggs {}
398540a1ddeSBen Skeggs }
399540a1ddeSBen Skeggs };
400540a1ddeSBen Skeggs
401540a1ddeSBen Skeggs int
gf100_vmm_new_(const struct nvkm_vmm_func * func_16,const struct nvkm_vmm_func * func_17,struct nvkm_mmu * mmu,bool managed,u64 addr,u64 size,void * argv,u32 argc,struct lock_class_key * key,const char * name,struct nvkm_vmm ** pvmm)402540a1ddeSBen Skeggs gf100_vmm_new_(const struct nvkm_vmm_func *func_16,
403540a1ddeSBen Skeggs const struct nvkm_vmm_func *func_17,
4042606f291SBen Skeggs struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
4052606f291SBen Skeggs void *argv, u32 argc, struct lock_class_key *key,
4062606f291SBen Skeggs const char *name, struct nvkm_vmm **pvmm)
407540a1ddeSBen Skeggs {
408540a1ddeSBen Skeggs switch (mmu->subdev.device->fb->page) {
4092606f291SBen Skeggs case 16: return nv04_vmm_new_(func_16, mmu, 0, managed, addr, size,
410540a1ddeSBen Skeggs argv, argc, key, name, pvmm);
4112606f291SBen Skeggs case 17: return nv04_vmm_new_(func_17, mmu, 0, managed, addr, size,
412540a1ddeSBen Skeggs argv, argc, key, name, pvmm);
413540a1ddeSBen Skeggs default:
414540a1ddeSBen Skeggs WARN_ON(1);
415540a1ddeSBen Skeggs return -EINVAL;
416540a1ddeSBen Skeggs }
417540a1ddeSBen Skeggs }
418540a1ddeSBen Skeggs
419540a1ddeSBen Skeggs int
gf100_vmm_new(struct nvkm_mmu * mmu,bool managed,u64 addr,u64 size,void * argv,u32 argc,struct lock_class_key * key,const char * name,struct nvkm_vmm ** pvmm)4202606f291SBen Skeggs gf100_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
4212606f291SBen Skeggs void *argv, u32 argc, struct lock_class_key *key,
4222606f291SBen Skeggs const char *name, struct nvkm_vmm **pvmm)
423540a1ddeSBen Skeggs {
4242606f291SBen Skeggs return gf100_vmm_new_(&gf100_vmm_16, &gf100_vmm_17, mmu, managed, addr,
425540a1ddeSBen Skeggs size, argv, argc, key, name, pvmm);
426540a1ddeSBen Skeggs }
427