xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/bar/nouveau_nvkm_subdev_bar_tu102.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_nvkm_subdev_bar_tu102.c,v 1.2 2021/12/18 23:45:38 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_bar_tu102.c,v 1.2 2021/12/18 23:45:38 riastradh Exp $");
26 
27 #include "gf100.h"
28 
29 #include <core/memory.h>
30 #include <subdev/timer.h>
31 
32 static void
tu102_bar_bar2_wait(struct nvkm_bar * bar)33 tu102_bar_bar2_wait(struct nvkm_bar *bar)
34 {
35 	struct nvkm_device *device = bar->subdev.device;
36 	nvkm_msec(device, 2000,
37 		if (!(nvkm_rd32(device, 0xb80f50) & 0x0000000c))
38 			break;
39 	);
40 }
41 
42 static void
tu102_bar_bar2_fini(struct nvkm_bar * bar)43 tu102_bar_bar2_fini(struct nvkm_bar *bar)
44 {
45 	nvkm_mask(bar->subdev.device, 0xb80f48, 0x80000000, 0x00000000);
46 }
47 
48 static void
tu102_bar_bar2_init(struct nvkm_bar * base)49 tu102_bar_bar2_init(struct nvkm_bar *base)
50 {
51 	struct nvkm_device *device = base->subdev.device;
52 	struct gf100_bar *bar = gf100_bar(base);
53 	u32 addr = nvkm_memory_addr(bar->bar[0].inst) >> 12;
54 	if (bar->bar2_halve)
55 		addr |= 0x40000000;
56 	nvkm_wr32(device, 0xb80f48, 0x80000000 | addr);
57 }
58 
59 static void
tu102_bar_bar1_wait(struct nvkm_bar * bar)60 tu102_bar_bar1_wait(struct nvkm_bar *bar)
61 {
62 	struct nvkm_device *device = bar->subdev.device;
63 	nvkm_msec(device, 2000,
64 		if (!(nvkm_rd32(device, 0xb80f50) & 0x00000003))
65 			break;
66 	);
67 }
68 
69 static void
tu102_bar_bar1_fini(struct nvkm_bar * bar)70 tu102_bar_bar1_fini(struct nvkm_bar *bar)
71 {
72 	nvkm_mask(bar->subdev.device, 0xb80f40, 0x80000000, 0x00000000);
73 }
74 
75 static void
tu102_bar_bar1_init(struct nvkm_bar * base)76 tu102_bar_bar1_init(struct nvkm_bar *base)
77 {
78 	struct nvkm_device *device = base->subdev.device;
79 	struct gf100_bar *bar = gf100_bar(base);
80 	const u32 addr = nvkm_memory_addr(bar->bar[1].inst) >> 12;
81 	nvkm_wr32(device, 0xb80f40, 0x80000000 | addr);
82 }
83 
84 static const struct nvkm_bar_func
85 tu102_bar = {
86 	.dtor = gf100_bar_dtor,
87 	.oneinit = gf100_bar_oneinit,
88 	.bar1.init = tu102_bar_bar1_init,
89 	.bar1.fini = tu102_bar_bar1_fini,
90 	.bar1.wait = tu102_bar_bar1_wait,
91 	.bar1.vmm = gf100_bar_bar1_vmm,
92 	.bar2.init = tu102_bar_bar2_init,
93 	.bar2.fini = tu102_bar_bar2_fini,
94 	.bar2.wait = tu102_bar_bar2_wait,
95 	.bar2.vmm = gf100_bar_bar2_vmm,
96 	.flush = g84_bar_flush,
97 };
98 
99 int
tu102_bar_new(struct nvkm_device * device,int index,struct nvkm_bar ** pbar)100 tu102_bar_new(struct nvkm_device *device, int index, struct nvkm_bar **pbar)
101 {
102 	return gf100_bar_new_(&tu102_bar, device, index, pbar);
103 }
104