xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_corec37d.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_dispnv50_corec37d.c,v 1.2 2021/12/18 23:45:32 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_dispnv50_corec37d.c,v 1.2 2021/12/18 23:45:32 riastradh Exp $");
26 
27 #include "core.h"
28 #include "head.h"
29 
30 #include <nouveau_bo.h>
31 
32 void
corec37d_wndw_owner(struct nv50_core * core)33 corec37d_wndw_owner(struct nv50_core *core)
34 {
35 	const u32 windows = 8; /*XXX*/
36 	u32 *push, i;
37 	if ((push = evo_wait(&core->chan, 2 * windows))) {
38 		for (i = 0; i < windows; i++) {
39 			evo_mthd(push, 0x1000 + (i * 0x080), 1);
40 			evo_data(push, i >> 1);
41 		}
42 		evo_kick(push, &core->chan);
43 	}
44 }
45 
46 void
corec37d_update(struct nv50_core * core,u32 * interlock,bool ntfy)47 corec37d_update(struct nv50_core *core, u32 *interlock, bool ntfy)
48 {
49 	u32 *push;
50 	if ((push = evo_wait(&core->chan, 9))) {
51 		if (ntfy) {
52 			evo_mthd(push, 0x020c, 1);
53 			evo_data(push, 0x00001000 | NV50_DISP_CORE_NTFY);
54 		}
55 
56 		evo_mthd(push, 0x0218, 2);
57 		evo_data(push, interlock[NV50_DISP_INTERLOCK_CURS]);
58 		evo_data(push, interlock[NV50_DISP_INTERLOCK_WNDW]);
59 		evo_mthd(push, 0x0200, 1);
60 		evo_data(push, 0x00000001);
61 
62 		if (ntfy) {
63 			evo_mthd(push, 0x020c, 1);
64 			evo_data(push, 0x00000000);
65 		}
66 		evo_kick(push, &core->chan);
67 	}
68 }
69 
70 int
corec37d_ntfy_wait_done(struct nouveau_bo * bo,u32 offset,struct nvif_device * device)71 corec37d_ntfy_wait_done(struct nouveau_bo *bo, u32 offset,
72 			struct nvif_device *device)
73 {
74 	u32 data;
75 	s64 time = nvif_msec(device, 2000ULL,
76 		data = nouveau_bo_rd32(bo, offset / 4 + 0);
77 		if ((data & 0xc0000000) == 0x80000000)
78 			break;
79 		usleep_range(1, 2);
80 	);
81 	return time < 0 ? time : 0;
82 }
83 
84 void
corec37d_ntfy_init(struct nouveau_bo * bo,u32 offset)85 corec37d_ntfy_init(struct nouveau_bo *bo, u32 offset)
86 {
87 	nouveau_bo_wr32(bo, offset / 4 + 0, 0x00000000);
88 	nouveau_bo_wr32(bo, offset / 4 + 1, 0x00000000);
89 	nouveau_bo_wr32(bo, offset / 4 + 2, 0x00000000);
90 	nouveau_bo_wr32(bo, offset / 4 + 3, 0x00000000);
91 }
92 
93 static void
corec37d_init(struct nv50_core * core)94 corec37d_init(struct nv50_core *core)
95 {
96 	const u32 windows = 8; /*XXX*/
97 	u32 *push, i;
98 	if ((push = evo_wait(&core->chan, 2 + 5 * windows))) {
99 		evo_mthd(push, 0x0208, 1);
100 		evo_data(push, core->chan.sync.handle);
101 		for (i = 0; i < windows; i++) {
102 			evo_mthd(push, 0x1004 + (i * 0x080), 2);
103 			evo_data(push, 0x0000001f);
104 			evo_data(push, 0x00000000);
105 			evo_mthd(push, 0x1010 + (i * 0x080), 1);
106 			evo_data(push, 0x00127fff);
107 		}
108 		evo_kick(push, &core->chan);
109 		core->assign_windows = true;
110 	}
111 }
112 
113 static const struct nv50_core_func
114 corec37d = {
115 	.init = corec37d_init,
116 	.ntfy_init = corec37d_ntfy_init,
117 	.ntfy_wait_done = corec37d_ntfy_wait_done,
118 	.update = corec37d_update,
119 	.wndw.owner = corec37d_wndw_owner,
120 	.head = &headc37d,
121 	.sor = &sorc37d,
122 };
123 
124 int
corec37d_new(struct nouveau_drm * drm,s32 oclass,struct nv50_core ** pcore)125 corec37d_new(struct nouveau_drm *drm, s32 oclass, struct nv50_core **pcore)
126 {
127 	return core507d_new_(&corec37d, drm, oclass, pcore);
128 }
129