xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgv100.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1edf50395SBen Skeggs /*
2edf50395SBen Skeggs  * Copyright 2018 Red Hat Inc.
3edf50395SBen Skeggs  *
4edf50395SBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5edf50395SBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6edf50395SBen Skeggs  * to deal in the Software without restriction, including without limitation
7edf50395SBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8edf50395SBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9edf50395SBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10edf50395SBen Skeggs  *
11edf50395SBen Skeggs  * The above copyright notice and this permission notice shall be included in
12edf50395SBen Skeggs  * all copies or substantial portions of the Software.
13edf50395SBen Skeggs  *
14edf50395SBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15edf50395SBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16edf50395SBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17edf50395SBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18edf50395SBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19edf50395SBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20edf50395SBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21edf50395SBen Skeggs  */
22edf50395SBen Skeggs #include "vmm.h"
23edf50395SBen Skeggs 
24edf50395SBen Skeggs #include <subdev/fb.h>
25edf50395SBen Skeggs #include <subdev/ltc.h>
26edf50395SBen Skeggs 
27edf50395SBen Skeggs #include <nvif/ifc00d.h>
28edf50395SBen Skeggs #include <nvif/unpack.h>
29edf50395SBen Skeggs 
30edf50395SBen Skeggs int
gv100_vmm_join(struct nvkm_vmm * vmm,struct nvkm_memory * inst)31edf50395SBen Skeggs gv100_vmm_join(struct nvkm_vmm *vmm, struct nvkm_memory *inst)
32edf50395SBen Skeggs {
33edf50395SBen Skeggs 	u64 data[2], mask;
34edf50395SBen Skeggs 	int ret = gp100_vmm_join(vmm, inst), i;
35edf50395SBen Skeggs 	if (ret)
36edf50395SBen Skeggs 		return ret;
37edf50395SBen Skeggs 
38edf50395SBen Skeggs 	nvkm_kmap(inst);
39edf50395SBen Skeggs 	data[0] = nvkm_ro32(inst, 0x200);
40edf50395SBen Skeggs 	data[1] = nvkm_ro32(inst, 0x204);
41edf50395SBen Skeggs 	mask = BIT_ULL(0);
42edf50395SBen Skeggs 
43edf50395SBen Skeggs 	nvkm_wo32(inst, 0x21c, 0x00000000);
44edf50395SBen Skeggs 
45edf50395SBen Skeggs 	for (i = 0; i < 64; i++) {
46edf50395SBen Skeggs 		if (mask & BIT_ULL(i)) {
47edf50395SBen Skeggs 			nvkm_wo32(inst, 0x2a4 + (i * 0x10), data[1]);
48edf50395SBen Skeggs 			nvkm_wo32(inst, 0x2a0 + (i * 0x10), data[0]);
49edf50395SBen Skeggs 		} else {
50edf50395SBen Skeggs 			nvkm_wo32(inst, 0x2a4 + (i * 0x10), 0x00000001);
51edf50395SBen Skeggs 			nvkm_wo32(inst, 0x2a0 + (i * 0x10), 0x00000001);
52edf50395SBen Skeggs 		}
53edf50395SBen Skeggs 		nvkm_wo32(inst, 0x2a8 + (i * 0x10), 0x00000000);
54edf50395SBen Skeggs 	}
55edf50395SBen Skeggs 
56edf50395SBen Skeggs 	nvkm_wo32(inst, 0x298, lower_32_bits(mask));
57edf50395SBen Skeggs 	nvkm_wo32(inst, 0x29c, upper_32_bits(mask));
58edf50395SBen Skeggs 	nvkm_done(inst);
59edf50395SBen Skeggs 	return 0;
60edf50395SBen Skeggs }
61edf50395SBen Skeggs 
62edf50395SBen Skeggs static const struct nvkm_vmm_func
63edf50395SBen Skeggs gv100_vmm = {
64edf50395SBen Skeggs 	.join = gv100_vmm_join,
65edf50395SBen Skeggs 	.part = gf100_vmm_part,
66edf50395SBen Skeggs 	.aper = gf100_vmm_aper,
67edf50395SBen Skeggs 	.valid = gp100_vmm_valid,
68edf50395SBen Skeggs 	.flush = gp100_vmm_flush,
6971871aa6SBen Skeggs 	.mthd = gp100_vmm_mthd,
70d389fd4fSBen Skeggs 	.invalidate_pdb = gp100_vmm_invalidate_pdb,
71edf50395SBen Skeggs 	.page = {
72edf50395SBen Skeggs 		{ 47, &gp100_vmm_desc_16[4], NVKM_VMM_PAGE_Sxxx },
73edf50395SBen Skeggs 		{ 38, &gp100_vmm_desc_16[3], NVKM_VMM_PAGE_Sxxx },
74edf50395SBen Skeggs 		{ 29, &gp100_vmm_desc_16[2], NVKM_VMM_PAGE_Sxxx },
75edf50395SBen Skeggs 		{ 21, &gp100_vmm_desc_16[1], NVKM_VMM_PAGE_SVxC },
76edf50395SBen Skeggs 		{ 16, &gp100_vmm_desc_16[0], NVKM_VMM_PAGE_SVxC },
77edf50395SBen Skeggs 		{ 12, &gp100_vmm_desc_12[0], NVKM_VMM_PAGE_SVHx },
78edf50395SBen Skeggs 		{}
79edf50395SBen Skeggs 	}
80edf50395SBen Skeggs };
81edf50395SBen Skeggs 
82edf50395SBen Skeggs int
gv100_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)832606f291SBen Skeggs gv100_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
842606f291SBen Skeggs 	      void *argv, u32 argc, struct lock_class_key *key,
852606f291SBen Skeggs 	      const char *name, struct nvkm_vmm **pvmm)
86edf50395SBen Skeggs {
87*ab2ee9ffSBen Skeggs 	return gp100_vmm_new_(&gv100_vmm, mmu, managed, addr, size,
88edf50395SBen Skeggs 			      argv, argc, key, name, pvmm);
89edf50395SBen Skeggs }
90