2 * Copyright 2018 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <drm/drm_atomic_helper.h>
26 #include <drm/drm_plane_helper.h>
27 #include <nouveau_bo.h>
29 #include <nvif/clc37e.h>
32 wndwc37e_csc_clr(struct nv50_wndw *wndw)
37 wndwc37e_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
40 if ((push = evo_wait(&wndw->wndw, 13))) {
41 evo_mthd(push, 0x02bc, 12);
42 for (i = 0; i < 12; i++)
43 evo_data(push, asyw->csc.matrix[i]);
44 evo_kick(push, &wndw->wndw);
49 wndwc37e_ilut_clr(struct nv50_wndw *wndw)
52 if ((push = evo_wait(&wndw->wndw, 2))) {
53 evo_mthd(push, 0x02b8, 1);
54 evo_data(push, 0x00000000);
55 evo_kick(push, &wndw->wndw);
60 wndwc37e_ilut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
63 if ((push = evo_wait(&wndw->wndw, 4))) {
64 evo_mthd(push, 0x02b0, 3);
65 evo_data(push, asyw->xlut.i.output_mode << 8 |
66 asyw->xlut.i.range << 4 |
68 evo_data(push, asyw->xlut.i.offset >> 8);
69 evo_data(push, asyw->xlut.handle);
70 evo_kick(push, &wndw->wndw);
75 wndwc37e_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
77 asyw->xlut.i.mode = 2;
78 asyw->xlut.i.size = 0;
79 asyw->xlut.i.range = 0;
80 asyw->xlut.i.output_mode = 1;
81 asyw->xlut.i.load = head907d_olut_load;
85 wndwc37e_blend_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
88 if ((push = evo_wait(&wndw->wndw, 8))) {
89 evo_mthd(push, 0x02ec, 7);
90 evo_data(push, asyw->blend.depth << 4);
91 evo_data(push, asyw->blend.k1);
92 evo_data(push, 0x00007722);
93 evo_data(push, 0xffff0000);
94 evo_data(push, 0xffff0000);
95 evo_data(push, 0xffff0000);
96 evo_data(push, 0xffff0000);
97 evo_kick(push, &wndw->wndw);
102 wndwc37e_image_clr(struct nv50_wndw *wndw)
105 if ((push = evo_wait(&wndw->wndw, 4))) {
106 evo_mthd(push, 0x0308, 1);
107 evo_data(push, 0x00000000);
108 evo_mthd(push, 0x0240, 1);
109 evo_data(push, 0x00000000);
110 evo_kick(push, &wndw->wndw);
115 wndwc37e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
119 if (!(push = evo_wait(&wndw->wndw, 17)))
122 evo_mthd(push, 0x0308, 1);
123 evo_data(push, asyw->image.mode << 4 | asyw->image.interval);
124 evo_mthd(push, 0x0224, 4);
125 evo_data(push, asyw->image.h << 16 | asyw->image.w);
126 evo_data(push, asyw->image.layout << 4 | asyw->image.blockh);
127 evo_data(push, asyw->csc.valid << 17 |
128 asyw->image.colorspace << 8 |
130 evo_data(push, asyw->image.blocks[0] | (asyw->image.pitch[0] >> 6));
131 evo_mthd(push, 0x0240, 1);
132 evo_data(push, asyw->image.handle[0]);
133 evo_mthd(push, 0x0260, 1);
134 evo_data(push, asyw->image.offset[0] >> 8);
135 evo_mthd(push, 0x0290, 1);
136 evo_data(push, (asyw->state.src_y >> 16) << 16 |
137 (asyw->state.src_x >> 16));
138 evo_mthd(push, 0x0298, 1);
139 evo_data(push, (asyw->state.src_h >> 16) << 16 |
140 (asyw->state.src_w >> 16));
141 evo_mthd(push, 0x02a4, 1);
142 evo_data(push, asyw->state.crtc_h << 16 |
144 evo_kick(push, &wndw->wndw);
148 wndwc37e_ntfy_clr(struct nv50_wndw *wndw)
151 if ((push = evo_wait(&wndw->wndw, 2))) {
152 evo_mthd(push, 0x021c, 1);
153 evo_data(push, 0x00000000);
154 evo_kick(push, &wndw->wndw);
159 wndwc37e_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
162 if ((push = evo_wait(&wndw->wndw, 3))) {
163 evo_mthd(push, 0x021c, 2);
164 evo_data(push, asyw->ntfy.handle);
165 evo_data(push, asyw->ntfy.offset | asyw->ntfy.awaken);
166 evo_kick(push, &wndw->wndw);
171 wndwc37e_sema_clr(struct nv50_wndw *wndw)
174 if ((push = evo_wait(&wndw->wndw, 2))) {
175 evo_mthd(push, 0x0218, 1);
176 evo_data(push, 0x00000000);
177 evo_kick(push, &wndw->wndw);
182 wndwc37e_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
185 if ((push = evo_wait(&wndw->wndw, 5))) {
186 evo_mthd(push, 0x020c, 4);
187 evo_data(push, asyw->sema.offset);
188 evo_data(push, asyw->sema.acquire);
189 evo_data(push, asyw->sema.release);
190 evo_data(push, asyw->sema.handle);
191 evo_kick(push, &wndw->wndw);
196 wndwc37e_update(struct nv50_wndw *wndw, u32 *interlock)
199 if ((push = evo_wait(&wndw->wndw, 5))) {
200 evo_mthd(push, 0x0370, 2);
201 evo_data(push, interlock[NV50_DISP_INTERLOCK_CURS] << 1 |
202 interlock[NV50_DISP_INTERLOCK_CORE]);
203 evo_data(push, interlock[NV50_DISP_INTERLOCK_WNDW]);
204 evo_mthd(push, 0x0200, 1);
205 if (interlock[NV50_DISP_INTERLOCK_WIMM] & wndw->interlock.data)
206 evo_data(push, 0x00001001);
208 evo_data(push, 0x00000001);
209 evo_kick(push, &wndw->wndw);
214 wndwc37e_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
215 struct nv50_head_atom *asyh)
220 wndwc37e_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
221 struct nv50_head_atom *asyh)
223 return drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
224 DRM_PLANE_HELPER_NO_SCALING,
225 DRM_PLANE_HELPER_NO_SCALING,
230 wndwc37e_format[] = {
239 DRM_FORMAT_XBGR2101010,
240 DRM_FORMAT_ABGR2101010,
243 DRM_FORMAT_XRGB2101010,
244 DRM_FORMAT_ARGB2101010,
245 DRM_FORMAT_XBGR16161616F,
246 DRM_FORMAT_ABGR16161616F,
250 static const struct nv50_wndw_func
252 .acquire = wndwc37e_acquire,
253 .release = wndwc37e_release,
254 .sema_set = wndwc37e_sema_set,
255 .sema_clr = wndwc37e_sema_clr,
256 .ntfy_set = wndwc37e_ntfy_set,
257 .ntfy_clr = wndwc37e_ntfy_clr,
258 .ntfy_reset = corec37d_ntfy_init,
259 .ntfy_wait_begun = base507c_ntfy_wait_begun,
260 .ilut = wndwc37e_ilut,
261 .xlut_set = wndwc37e_ilut_set,
262 .xlut_clr = wndwc37e_ilut_clr,
264 .csc_set = wndwc37e_csc_set,
265 .csc_clr = wndwc37e_csc_clr,
266 .image_set = wndwc37e_image_set,
267 .image_clr = wndwc37e_image_clr,
268 .blend_set = wndwc37e_blend_set,
269 .update = wndwc37e_update,
273 wndwc37e_new_(const struct nv50_wndw_func *func, struct nouveau_drm *drm,
274 enum drm_plane_type type, int index, s32 oclass, u32 heads,
275 struct nv50_wndw **pwndw)
277 struct nvc37e_window_channel_dma_v0 args = {
278 .pushbuf = 0xb0007e00 | index,
281 struct nv50_disp *disp = nv50_disp(drm->dev);
282 struct nv50_wndw *wndw;
285 ret = nv50_wndw_new_(func, drm->dev, type, "wndw", index,
286 wndwc37e_format, heads, NV50_DISP_INTERLOCK_WNDW,
288 if (*pwndw = wndw, ret)
291 ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
292 &oclass, 0, &args, sizeof(args),
293 disp->sync->bo.offset, &wndw->wndw);
295 NV_ERROR(drm, "qndw%04x allocation failed: %d\n", oclass, ret);
299 wndw->ntfy = NV50_DISP_WNDW_NTFY(wndw->id);
300 wndw->sema = NV50_DISP_WNDW_SEM0(wndw->id);
301 wndw->data = 0x00000000;
306 wndwc37e_new(struct nouveau_drm *drm, enum drm_plane_type type, int index,
307 s32 oclass, struct nv50_wndw **pwndw)
309 return wndwc37e_new_(&wndwc37e, drm, type, index, oclass,
310 BIT(index >> 1), pwndw);