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