965807f8b635316900ade5d3d1cb8ffbcb4bdab3
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / dispnv50 / wndwc37e.c
1 /*
2  * Copyright 2018 Red Hat Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  */
22 #include "wndw.h"
23 #include "atom.h"
24
25 #include <drm/drm_atomic_helper.h>
26 #include <drm/drm_plane_helper.h>
27 #include <nouveau_bo.h>
28
29 #include <nvif/clc37e.h>
30 #include <nvif/pushc37b.h>
31
32 static void
33 wndwc37e_csc_clr(struct nv50_wndw *wndw)
34 {
35 }
36
37 static void
38 wndwc37e_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
39 {
40         u32 *push, i;
41         if ((push = evo_wait(&wndw->wndw, 13))) {
42                  evo_mthd(push, 0x02bc, 12);
43                  for (i = 0; i < 12; i++)
44                           evo_data(push, asyw->csc.matrix[i]);
45                  evo_kick(push, &wndw->wndw);
46         }
47 }
48
49 static void
50 wndwc37e_ilut_clr(struct nv50_wndw *wndw)
51 {
52         u32 *push;
53         if ((push = evo_wait(&wndw->wndw, 2))) {
54                 evo_mthd(push, 0x02b8, 1);
55                 evo_data(push, 0x00000000);
56                 evo_kick(push, &wndw->wndw);
57         }
58 }
59
60 static void
61 wndwc37e_ilut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
62 {
63         u32 *push;
64         if ((push = evo_wait(&wndw->wndw, 4))) {
65                 evo_mthd(push, 0x02b0, 3);
66                 evo_data(push, asyw->xlut.i.output_mode << 8 |
67                                asyw->xlut.i.range << 4 |
68                                asyw->xlut.i.size);
69                 evo_data(push, asyw->xlut.i.offset >> 8);
70                 evo_data(push, asyw->xlut.handle);
71                 evo_kick(push, &wndw->wndw);
72         }
73 }
74
75 static bool
76 wndwc37e_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size)
77 {
78         if (size != 256 && size != 1024)
79                 return false;
80
81         asyw->xlut.i.mode = 2;
82         asyw->xlut.i.size = size == 1024 ? 2 : 0;
83         asyw->xlut.i.range = 0;
84         asyw->xlut.i.output_mode = 1;
85         asyw->xlut.i.load = head907d_olut_load;
86         return true;
87 }
88
89 void
90 wndwc37e_blend_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
91 {
92         u32 *push;
93         if ((push = evo_wait(&wndw->wndw, 8))) {
94                 evo_mthd(push, 0x02ec, 7);
95                 evo_data(push, asyw->blend.depth << 4);
96                 evo_data(push, asyw->blend.k1);
97                 evo_data(push, asyw->blend.dst_color << 12 |
98                                asyw->blend.dst_color << 8 |
99                                asyw->blend.src_color << 4 |
100                                asyw->blend.src_color);
101                 evo_data(push, 0xffff0000);
102                 evo_data(push, 0xffff0000);
103                 evo_data(push, 0xffff0000);
104                 evo_data(push, 0xffff0000);
105                 evo_kick(push, &wndw->wndw);
106         }
107 }
108
109 void
110 wndwc37e_image_clr(struct nv50_wndw *wndw)
111 {
112         u32 *push;
113         if ((push = evo_wait(&wndw->wndw, 4))) {
114                 evo_mthd(push, 0x0308, 1);
115                 evo_data(push, 0x00000000);
116                 evo_mthd(push, 0x0240, 1);
117                 evo_data(push, 0x00000000);
118                 evo_kick(push, &wndw->wndw);
119         }
120 }
121
122 static void
123 wndwc37e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
124 {
125         u32 *push;
126
127         if (!(push = evo_wait(&wndw->wndw, 17)))
128                 return;
129
130         evo_mthd(push, 0x0308, 1);
131         evo_data(push, asyw->image.mode << 4 | asyw->image.interval);
132         evo_mthd(push, 0x0224, 4);
133         evo_data(push, asyw->image.h << 16 | asyw->image.w);
134         evo_data(push, asyw->image.layout << 4 | asyw->image.blockh);
135         evo_data(push, asyw->csc.valid << 17 |
136                        asyw->image.colorspace << 8 |
137                        asyw->image.format);
138         evo_data(push, asyw->image.blocks[0] | (asyw->image.pitch[0] >> 6));
139         evo_mthd(push, 0x0240, 1);
140         evo_data(push, asyw->image.handle[0]);
141         evo_mthd(push, 0x0260, 1);
142         evo_data(push, asyw->image.offset[0] >> 8);
143         evo_mthd(push, 0x0290, 1);
144         evo_data(push, (asyw->state.src_y >> 16) << 16 |
145                        (asyw->state.src_x >> 16));
146         evo_mthd(push, 0x0298, 1);
147         evo_data(push, (asyw->state.src_h >> 16) << 16 |
148                        (asyw->state.src_w >> 16));
149         evo_mthd(push, 0x02a4, 1);
150         evo_data(push, asyw->state.crtc_h << 16 |
151                        asyw->state.crtc_w);
152         evo_kick(push, &wndw->wndw);
153 }
154
155 void
156 wndwc37e_ntfy_clr(struct nv50_wndw *wndw)
157 {
158         u32 *push;
159         if ((push = evo_wait(&wndw->wndw, 2))) {
160                 evo_mthd(push, 0x021c, 1);
161                 evo_data(push, 0x00000000);
162                 evo_kick(push, &wndw->wndw);
163         }
164 }
165
166 void
167 wndwc37e_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
168 {
169         u32 *push;
170         if ((push = evo_wait(&wndw->wndw, 3))) {
171                 evo_mthd(push, 0x021c, 2);
172                 evo_data(push, asyw->ntfy.handle);
173                 evo_data(push, asyw->ntfy.offset | asyw->ntfy.awaken);
174                 evo_kick(push, &wndw->wndw);
175         }
176 }
177
178 int
179 wndwc37e_sema_clr(struct nv50_wndw *wndw)
180 {
181         struct nvif_push *push = wndw->wndw.push;
182         int ret;
183
184         if ((ret = PUSH_WAIT(push, 2)))
185                 return ret;
186
187         PUSH_NVSQ(push, NVC37E, 0x0218, 0x00000000);
188         return 0;
189 }
190
191 int
192 wndwc37e_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
193 {
194         struct nvif_push *push = wndw->wndw.push;
195         int ret;
196
197         if ((ret = PUSH_WAIT(push, 5)))
198                 return ret;
199
200         PUSH_NVSQ(push, NVC37E, 0x020c, asyw->sema.offset,
201                                 0x0210, asyw->sema.acquire,
202                                 0x0214, asyw->sema.release,
203                                 0x0218, asyw->sema.handle);
204         return 0;
205 }
206
207 void
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
226 wndwc37e_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
227                  struct nv50_head_atom *asyh)
228 {
229 }
230
231 int
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
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->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
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 }