1c011b254SBen Skeggs /*
2c011b254SBen Skeggs * Copyright 2018 Red Hat Inc.
3c011b254SBen Skeggs *
4c011b254SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c011b254SBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c011b254SBen Skeggs * to deal in the Software without restriction, including without limitation
7c011b254SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c011b254SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c011b254SBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c011b254SBen Skeggs *
11c011b254SBen Skeggs * The above copyright notice and this permission notice shall be included in
12c011b254SBen Skeggs * all copies or substantial portions of the Software.
13c011b254SBen Skeggs *
14c011b254SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c011b254SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c011b254SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c011b254SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c011b254SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c011b254SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c011b254SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c011b254SBen Skeggs */
22c011b254SBen Skeggs #include "vmm.h"
23c011b254SBen Skeggs
24c011b254SBen Skeggs #include <subdev/timer.h>
25c011b254SBen Skeggs
26c011b254SBen Skeggs static void
tu102_vmm_flush(struct nvkm_vmm * vmm,int depth)27c011b254SBen Skeggs tu102_vmm_flush(struct nvkm_vmm *vmm, int depth)
28c011b254SBen Skeggs {
295ec69c91SBen Skeggs struct nvkm_device *device = vmm->mmu->subdev.device;
30b9f327f1SBen Skeggs u32 type = (5 /* CACHE_LEVEL_UP_TO_PDE3 */ - depth) << 24;
31c011b254SBen Skeggs
32b9f327f1SBen Skeggs type |= 0x00000001; /* PAGE_ALL */
33c011b254SBen Skeggs if (atomic_read(&vmm->engref[NVKM_SUBDEV_BAR]))
34*fa60f8faSDave Airlie type |= 0x00000006; /* HUB_ONLY | ALL PDB (hack) */
35c011b254SBen Skeggs
365ec69c91SBen Skeggs mutex_lock(&vmm->mmu->mutex);
37c011b254SBen Skeggs
38c011b254SBen Skeggs nvkm_wr32(device, 0xb830a0, vmm->pd->pt[0]->addr >> 8);
39c011b254SBen Skeggs nvkm_wr32(device, 0xb830a4, 0x00000000);
40c011b254SBen Skeggs nvkm_wr32(device, 0x100e68, 0x00000000);
41c011b254SBen Skeggs nvkm_wr32(device, 0xb830b0, 0x80000000 | type);
42c011b254SBen Skeggs
43c011b254SBen Skeggs nvkm_msec(device, 2000,
44c011b254SBen Skeggs if (!(nvkm_rd32(device, 0xb830b0) & 0x80000000))
45c011b254SBen Skeggs break;
46c011b254SBen Skeggs );
47c011b254SBen Skeggs
485ec69c91SBen Skeggs mutex_unlock(&vmm->mmu->mutex);
49c011b254SBen Skeggs }
50c011b254SBen Skeggs
51c011b254SBen Skeggs static const struct nvkm_vmm_func
52c011b254SBen Skeggs tu102_vmm = {
53c011b254SBen Skeggs .join = gv100_vmm_join,
54c011b254SBen Skeggs .part = gf100_vmm_part,
55c011b254SBen Skeggs .aper = gf100_vmm_aper,
56c011b254SBen Skeggs .valid = gp100_vmm_valid,
57c011b254SBen Skeggs .flush = tu102_vmm_flush,
5871871aa6SBen Skeggs .mthd = gp100_vmm_mthd,
59c011b254SBen Skeggs .page = {
60c011b254SBen Skeggs { 47, &gp100_vmm_desc_16[4], NVKM_VMM_PAGE_Sxxx },
61c011b254SBen Skeggs { 38, &gp100_vmm_desc_16[3], NVKM_VMM_PAGE_Sxxx },
62c011b254SBen Skeggs { 29, &gp100_vmm_desc_16[2], NVKM_VMM_PAGE_Sxxx },
63c011b254SBen Skeggs { 21, &gp100_vmm_desc_16[1], NVKM_VMM_PAGE_SVxC },
64c011b254SBen Skeggs { 16, &gp100_vmm_desc_16[0], NVKM_VMM_PAGE_SVxC },
65c011b254SBen Skeggs { 12, &gp100_vmm_desc_12[0], NVKM_VMM_PAGE_SVHx },
66c011b254SBen Skeggs {}
67c011b254SBen Skeggs }
68c011b254SBen Skeggs };
69c011b254SBen Skeggs
70c011b254SBen Skeggs int
tu102_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)712606f291SBen Skeggs tu102_vmm_new(struct nvkm_mmu *mmu, bool managed, u64 addr, u64 size,
72c011b254SBen Skeggs void *argv, u32 argc, struct lock_class_key *key,
73c011b254SBen Skeggs const char *name, struct nvkm_vmm **pvmm)
74c011b254SBen Skeggs {
75ab2ee9ffSBen Skeggs return gp100_vmm_new_(&tu102_vmm, mmu, managed, addr, size,
76c011b254SBen Skeggs argv, argc, key, name, pvmm);
77c011b254SBen Skeggs }
78