xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_wndwc37e.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_dispnv50_wndwc37e.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_wndwc37e.c,v 1.2 2021/12/18 23:45:32 riastradh Exp $");
26 
27 #include "wndw.h"
28 #include "atom.h"
29 
30 #include <drm/drm_atomic_helper.h>
31 #include <drm/drm_plane_helper.h>
32 #include <nouveau_bo.h>
33 
34 #include <nvif/clc37e.h>
35 
36 static void
wndwc37e_csc_clr(struct nv50_wndw * wndw)37 wndwc37e_csc_clr(struct nv50_wndw *wndw)
38 {
39 }
40 
41 static void
wndwc37e_csc_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)42 wndwc37e_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
43 {
44 	u32 *push, i;
45 	if ((push = evo_wait(&wndw->wndw, 13))) {
46 		 evo_mthd(push, 0x02bc, 12);
47 		 for (i = 0; i < 12; i++)
48 			  evo_data(push, asyw->csc.matrix[i]);
49 		 evo_kick(push, &wndw->wndw);
50 	}
51 }
52 
53 static void
wndwc37e_ilut_clr(struct nv50_wndw * wndw)54 wndwc37e_ilut_clr(struct nv50_wndw *wndw)
55 {
56 	u32 *push;
57 	if ((push = evo_wait(&wndw->wndw, 2))) {
58 		evo_mthd(push, 0x02b8, 1);
59 		evo_data(push, 0x00000000);
60 		evo_kick(push, &wndw->wndw);
61 	}
62 }
63 
64 static void
wndwc37e_ilut_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)65 wndwc37e_ilut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
66 {
67 	u32 *push;
68 	if ((push = evo_wait(&wndw->wndw, 4))) {
69 		evo_mthd(push, 0x02b0, 3);
70 		evo_data(push, asyw->xlut.i.output_mode << 8 |
71 			       asyw->xlut.i.range << 4 |
72 			       asyw->xlut.i.size);
73 		evo_data(push, asyw->xlut.i.offset >> 8);
74 		evo_data(push, asyw->xlut.handle);
75 		evo_kick(push, &wndw->wndw);
76 	}
77 }
78 
79 static bool
wndwc37e_ilut(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw,int size)80 wndwc37e_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size)
81 {
82 	if (size != 256 && size != 1024)
83 		return false;
84 
85 	asyw->xlut.i.mode = 2;
86 	asyw->xlut.i.size = size == 1024 ? 2 : 0;
87 	asyw->xlut.i.range = 0;
88 	asyw->xlut.i.output_mode = 1;
89 	asyw->xlut.i.load = head907d_olut_load;
90 	return true;
91 }
92 
93 void
wndwc37e_blend_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)94 wndwc37e_blend_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
95 {
96 	u32 *push;
97 	if ((push = evo_wait(&wndw->wndw, 8))) {
98 		evo_mthd(push, 0x02ec, 7);
99 		evo_data(push, asyw->blend.depth << 4);
100 		evo_data(push, asyw->blend.k1);
101 		evo_data(push, asyw->blend.dst_color << 12 |
102 			       asyw->blend.dst_color << 8 |
103 			       asyw->blend.src_color << 4 |
104 			       asyw->blend.src_color);
105 		evo_data(push, 0xffff0000);
106 		evo_data(push, 0xffff0000);
107 		evo_data(push, 0xffff0000);
108 		evo_data(push, 0xffff0000);
109 		evo_kick(push, &wndw->wndw);
110 	}
111 }
112 
113 void
wndwc37e_image_clr(struct nv50_wndw * wndw)114 wndwc37e_image_clr(struct nv50_wndw *wndw)
115 {
116 	u32 *push;
117 	if ((push = evo_wait(&wndw->wndw, 4))) {
118 		evo_mthd(push, 0x0308, 1);
119 		evo_data(push, 0x00000000);
120 		evo_mthd(push, 0x0240, 1);
121 		evo_data(push, 0x00000000);
122 		evo_kick(push, &wndw->wndw);
123 	}
124 }
125 
126 static void
wndwc37e_image_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)127 wndwc37e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
128 {
129 	u32 *push;
130 
131 	if (!(push = evo_wait(&wndw->wndw, 17)))
132 		return;
133 
134 	evo_mthd(push, 0x0308, 1);
135 	evo_data(push, asyw->image.mode << 4 | asyw->image.interval);
136 	evo_mthd(push, 0x0224, 4);
137 	evo_data(push, asyw->image.h << 16 | asyw->image.w);
138 	evo_data(push, asyw->image.layout << 4 | asyw->image.blockh);
139 	evo_data(push, asyw->csc.valid << 17 |
140 		       asyw->image.colorspace << 8 |
141 		       asyw->image.format);
142 	evo_data(push, asyw->image.blocks[0] | (asyw->image.pitch[0] >> 6));
143 	evo_mthd(push, 0x0240, 1);
144 	evo_data(push, asyw->image.handle[0]);
145 	evo_mthd(push, 0x0260, 1);
146 	evo_data(push, asyw->image.offset[0] >> 8);
147 	evo_mthd(push, 0x0290, 1);
148 	evo_data(push, (asyw->state.src_y >> 16) << 16 |
149 		       (asyw->state.src_x >> 16));
150 	evo_mthd(push, 0x0298, 1);
151 	evo_data(push, (asyw->state.src_h >> 16) << 16 |
152 		       (asyw->state.src_w >> 16));
153 	evo_mthd(push, 0x02a4, 1);
154 	evo_data(push, asyw->state.crtc_h << 16 |
155 		       asyw->state.crtc_w);
156 	evo_kick(push, &wndw->wndw);
157 }
158 
159 void
wndwc37e_ntfy_clr(struct nv50_wndw * wndw)160 wndwc37e_ntfy_clr(struct nv50_wndw *wndw)
161 {
162 	u32 *push;
163 	if ((push = evo_wait(&wndw->wndw, 2))) {
164 		evo_mthd(push, 0x021c, 1);
165 		evo_data(push, 0x00000000);
166 		evo_kick(push, &wndw->wndw);
167 	}
168 }
169 
170 void
wndwc37e_ntfy_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)171 wndwc37e_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
172 {
173 	u32 *push;
174 	if ((push = evo_wait(&wndw->wndw, 3))) {
175 		evo_mthd(push, 0x021c, 2);
176 		evo_data(push, asyw->ntfy.handle);
177 		evo_data(push, asyw->ntfy.offset | asyw->ntfy.awaken);
178 		evo_kick(push, &wndw->wndw);
179 	}
180 }
181 
182 void
wndwc37e_sema_clr(struct nv50_wndw * wndw)183 wndwc37e_sema_clr(struct nv50_wndw *wndw)
184 {
185 	u32 *push;
186 	if ((push = evo_wait(&wndw->wndw, 2))) {
187 		evo_mthd(push, 0x0218, 1);
188 		evo_data(push, 0x00000000);
189 		evo_kick(push, &wndw->wndw);
190 	}
191 }
192 
193 void
wndwc37e_sema_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)194 wndwc37e_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
195 {
196 	u32 *push;
197 	if ((push = evo_wait(&wndw->wndw, 5))) {
198 		evo_mthd(push, 0x020c, 4);
199 		evo_data(push, asyw->sema.offset);
200 		evo_data(push, asyw->sema.acquire);
201 		evo_data(push, asyw->sema.release);
202 		evo_data(push, asyw->sema.handle);
203 		evo_kick(push, &wndw->wndw);
204 	}
205 }
206 
207 void
wndwc37e_update(struct nv50_wndw * wndw,u32 * interlock)208 wndwc37e_update(struct nv50_wndw *wndw, u32 *interlock)
209 {
210 	u32 *push;
211 	if ((push = evo_wait(&wndw->wndw, 5))) {
212 		evo_mthd(push, 0x0370, 2);
213 		evo_data(push, interlock[NV50_DISP_INTERLOCK_CURS] << 1 |
214 			       interlock[NV50_DISP_INTERLOCK_CORE]);
215 		evo_data(push, interlock[NV50_DISP_INTERLOCK_WNDW]);
216 		evo_mthd(push, 0x0200, 1);
217 		if (interlock[NV50_DISP_INTERLOCK_WIMM] & wndw->interlock.data)
218 			evo_data(push, 0x00001001);
219 		else
220 			evo_data(push, 0x00000001);
221 		evo_kick(push, &wndw->wndw);
222 	}
223 }
224 
225 void
wndwc37e_release(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw,struct nv50_head_atom * asyh)226 wndwc37e_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
227 		 struct nv50_head_atom *asyh)
228 {
229 }
230 
231 int
wndwc37e_acquire(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw,struct nv50_head_atom * asyh)232 wndwc37e_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
233 		 struct nv50_head_atom *asyh)
234 {
235 	return drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
236 						   DRM_PLANE_HELPER_NO_SCALING,
237 						   DRM_PLANE_HELPER_NO_SCALING,
238 						   true, true);
239 }
240 
241 static const u32
242 wndwc37e_format[] = {
243 	DRM_FORMAT_C8,
244 	DRM_FORMAT_YUYV,
245 	DRM_FORMAT_UYVY,
246 	DRM_FORMAT_XRGB8888,
247 	DRM_FORMAT_ARGB8888,
248 	DRM_FORMAT_RGB565,
249 	DRM_FORMAT_XRGB1555,
250 	DRM_FORMAT_ARGB1555,
251 	DRM_FORMAT_XBGR2101010,
252 	DRM_FORMAT_ABGR2101010,
253 	DRM_FORMAT_XBGR8888,
254 	DRM_FORMAT_ABGR8888,
255 	DRM_FORMAT_XRGB2101010,
256 	DRM_FORMAT_ARGB2101010,
257 	DRM_FORMAT_XBGR16161616F,
258 	DRM_FORMAT_ABGR16161616F,
259 	0
260 };
261 
262 static const struct nv50_wndw_func
263 wndwc37e = {
264 	.acquire = wndwc37e_acquire,
265 	.release = wndwc37e_release,
266 	.sema_set = wndwc37e_sema_set,
267 	.sema_clr = wndwc37e_sema_clr,
268 	.ntfy_set = wndwc37e_ntfy_set,
269 	.ntfy_clr = wndwc37e_ntfy_clr,
270 	.ntfy_reset = corec37d_ntfy_init,
271 	.ntfy_wait_begun = base507c_ntfy_wait_begun,
272 	.ilut = wndwc37e_ilut,
273 	.ilut_size = 1024,
274 	.xlut_set = wndwc37e_ilut_set,
275 	.xlut_clr = wndwc37e_ilut_clr,
276 	.csc = base907c_csc,
277 	.csc_set = wndwc37e_csc_set,
278 	.csc_clr = wndwc37e_csc_clr,
279 	.image_set = wndwc37e_image_set,
280 	.image_clr = wndwc37e_image_clr,
281 	.blend_set = wndwc37e_blend_set,
282 	.update = wndwc37e_update,
283 };
284 
285 int
wndwc37e_new_(const struct nv50_wndw_func * func,struct nouveau_drm * drm,enum drm_plane_type type,int index,s32 oclass,u32 heads,struct nv50_wndw ** pwndw)286 wndwc37e_new_(const struct nv50_wndw_func *func, struct nouveau_drm *drm,
287 	      enum drm_plane_type type, int index, s32 oclass, u32 heads,
288 	      struct nv50_wndw **pwndw)
289 {
290 	struct nvc37e_window_channel_dma_v0 args = {
291 		.pushbuf = 0xb0007e00 | index,
292 		.index = index,
293 	};
294 	struct nv50_disp *disp = nv50_disp(drm->dev);
295 	struct nv50_wndw *wndw;
296 	int ret;
297 
298 	ret = nv50_wndw_new_(func, drm->dev, type, "wndw", index,
299 			     wndwc37e_format, heads, NV50_DISP_INTERLOCK_WNDW,
300 			     BIT(index), &wndw);
301 	if (*pwndw = wndw, ret)
302 		return ret;
303 
304 	ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
305 			       &oclass, 0, &args, sizeof(args),
306 			       disp->sync->bo.offset, &wndw->wndw);
307 	if (ret) {
308 		NV_ERROR(drm, "qndw%04x allocation failed: %d\n", oclass, ret);
309 		return ret;
310 	}
311 
312 	wndw->ntfy = NV50_DISP_WNDW_NTFY(wndw->id);
313 	wndw->sema = NV50_DISP_WNDW_SEM0(wndw->id);
314 	wndw->data = 0x00000000;
315 	return 0;
316 }
317 
318 int
wndwc37e_new(struct nouveau_drm * drm,enum drm_plane_type type,int index,s32 oclass,struct nv50_wndw ** pwndw)319 wndwc37e_new(struct nouveau_drm *drm, enum drm_plane_type type, int index,
320 	     s32 oclass, struct nv50_wndw **pwndw)
321 {
322 	return wndwc37e_new_(&wndwc37e, drm, type, index, oclass,
323 			     BIT(index >> 1), pwndw);
324 }
325