]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/nouveau/dispnv50/base507c.c
80e020611bcb5c7ccafbf2310546ffa6604825f7
[linux.git] / drivers / gpu / drm / nouveau / dispnv50 / base507c.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 "base.h"
23
24 #include <nvif/cl507c.h>
25 #include <nvif/event.h>
26
27 #include <drm/drm_atomic_helper.h>
28 #include <drm/drm_fourcc.h>
29 #include <drm/drm_plane_helper.h>
30
31 #include "nouveau_bo.h"
32
33 void
34 base507c_update(struct nv50_wndw *wndw, u32 *interlock)
35 {
36         u32 *push;
37         if ((push = evo_wait(&wndw->wndw, 2))) {
38                 evo_mthd(push, 0x0080, 1);
39                 evo_data(push, interlock[NV50_DISP_INTERLOCK_CORE]);
40                 evo_kick(push, &wndw->wndw);
41         }
42 }
43
44 void
45 base507c_image_clr(struct nv50_wndw *wndw)
46 {
47         u32 *push;
48         if ((push = evo_wait(&wndw->wndw, 4))) {
49                 evo_mthd(push, 0x0084, 1);
50                 evo_data(push, 0x00000000);
51                 evo_mthd(push, 0x00c0, 1);
52                 evo_data(push, 0x00000000);
53                 evo_kick(push, &wndw->wndw);
54         }
55 }
56
57 static void
58 base507c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
59 {
60         u32 *push;
61         if ((push = evo_wait(&wndw->wndw, 10))) {
62                 evo_mthd(push, 0x0084, 1);
63                 evo_data(push, asyw->image.mode << 8 |
64                                asyw->image.interval << 4);
65                 evo_mthd(push, 0x00c0, 1);
66                 evo_data(push, asyw->image.handle[0]);
67                 evo_mthd(push, 0x0800, 5);
68                 evo_data(push, asyw->image.offset[0] >> 8);
69                 evo_data(push, 0x00000000);
70                 evo_data(push, asyw->image.h << 16 | asyw->image.w);
71                 evo_data(push, asyw->image.layout << 20 |
72                                (asyw->image.pitch[0] >> 8) << 8 |
73                                asyw->image.blocks[0] << 8 |
74                                asyw->image.blockh);
75                 evo_data(push, asyw->image.kind << 16 |
76                                asyw->image.format << 8);
77                 evo_kick(push, &wndw->wndw);
78         }
79 }
80
81 void
82 base507c_xlut_clr(struct nv50_wndw *wndw)
83 {
84         u32 *push;
85         if ((push = evo_wait(&wndw->wndw, 2))) {
86                 evo_mthd(push, 0x00e0, 1);
87                 evo_data(push, 0x00000000);
88                 evo_kick(push, &wndw->wndw);
89         }
90 }
91
92 void
93 base507c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
94 {
95         u32 *push;
96         if ((push = evo_wait(&wndw->wndw, 2))) {
97                 evo_mthd(push, 0x00e0, 1);
98                 evo_data(push, 0x40000000);
99                 evo_kick(push, &wndw->wndw);
100         }
101 }
102
103 int
104 base507c_ntfy_wait_begun(struct nouveau_bo *bo, u32 offset,
105                          struct nvif_device *device)
106 {
107         s64 time = nvif_msec(device, 2000ULL,
108                 u32 data = nouveau_bo_rd32(bo, offset / 4);
109                 if ((data & 0xc0000000) == 0x40000000)
110                         break;
111                 usleep_range(1, 2);
112         );
113         return time < 0 ? time : 0;
114 }
115
116 void
117 base507c_ntfy_clr(struct nv50_wndw *wndw)
118 {
119         u32 *push;
120         if ((push = evo_wait(&wndw->wndw, 2))) {
121                 evo_mthd(push, 0x00a4, 1);
122                 evo_data(push, 0x00000000);
123                 evo_kick(push, &wndw->wndw);
124         }
125 }
126
127 void
128 base507c_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
129 {
130         u32 *push;
131         if ((push = evo_wait(&wndw->wndw, 3))) {
132                 evo_mthd(push, 0x00a0, 2);
133                 evo_data(push, asyw->ntfy.awaken << 30 | asyw->ntfy.offset);
134                 evo_data(push, asyw->ntfy.handle);
135                 evo_kick(push, &wndw->wndw);
136         }
137 }
138
139 void
140 base507c_ntfy_reset(struct nouveau_bo *bo, u32 offset)
141 {
142         nouveau_bo_wr32(bo, offset / 4, 0x00000000);
143 }
144
145 void
146 base507c_sema_clr(struct nv50_wndw *wndw)
147 {
148         u32 *push;
149         if ((push = evo_wait(&wndw->wndw, 2))) {
150                 evo_mthd(push, 0x0094, 1);
151                 evo_data(push, 0x00000000);
152                 evo_kick(push, &wndw->wndw);
153         }
154 }
155
156 void
157 base507c_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
158 {
159         u32 *push;
160         if ((push = evo_wait(&wndw->wndw, 5))) {
161                 evo_mthd(push, 0x0088, 4);
162                 evo_data(push, asyw->sema.offset);
163                 evo_data(push, asyw->sema.acquire);
164                 evo_data(push, asyw->sema.release);
165                 evo_data(push, asyw->sema.handle);
166                 evo_kick(push, &wndw->wndw);
167         }
168 }
169
170 void
171 base507c_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
172                  struct nv50_head_atom *asyh)
173 {
174         asyh->base.cpp = 0;
175 }
176
177 int
178 base507c_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
179                  struct nv50_head_atom *asyh)
180 {
181         const struct drm_framebuffer *fb = asyw->state.fb;
182         int ret;
183
184         if (!fb->format->depth)
185                 return -EINVAL;
186
187         ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
188                                                   DRM_PLANE_HELPER_NO_SCALING,
189                                                   DRM_PLANE_HELPER_NO_SCALING,
190                                                   false, true);
191         if (ret)
192                 return ret;
193
194         if (!wndw->func->ilut) {
195                 if ((asyh->base.cpp != 1) ^ (fb->format->cpp[0] != 1))
196                         asyh->state.color_mgmt_changed = true;
197         }
198
199         asyh->base.depth = fb->format->depth;
200         asyh->base.cpp = fb->format->cpp[0];
201         asyh->base.x = asyw->state.src.x1 >> 16;
202         asyh->base.y = asyw->state.src.y1 >> 16;
203         asyh->base.w = asyw->state.fb->width;
204         asyh->base.h = asyw->state.fb->height;
205         return 0;
206 }
207
208 const u32
209 base507c_format[] = {
210         DRM_FORMAT_C8,
211         DRM_FORMAT_RGB565,
212         DRM_FORMAT_XRGB1555,
213         DRM_FORMAT_ARGB1555,
214         DRM_FORMAT_XRGB8888,
215         DRM_FORMAT_ARGB8888,
216         DRM_FORMAT_XBGR2101010,
217         DRM_FORMAT_ABGR2101010,
218         DRM_FORMAT_XBGR8888,
219         DRM_FORMAT_ABGR8888,
220         0
221 };
222
223 static const struct nv50_wndw_func
224 base507c = {
225         .acquire = base507c_acquire,
226         .release = base507c_release,
227         .sema_set = base507c_sema_set,
228         .sema_clr = base507c_sema_clr,
229         .ntfy_reset = base507c_ntfy_reset,
230         .ntfy_set = base507c_ntfy_set,
231         .ntfy_clr = base507c_ntfy_clr,
232         .ntfy_wait_begun = base507c_ntfy_wait_begun,
233         .olut_core = 1,
234         .xlut_set = base507c_xlut_set,
235         .xlut_clr = base507c_xlut_clr,
236         .image_set = base507c_image_set,
237         .image_clr = base507c_image_clr,
238         .update = base507c_update,
239 };
240
241 int
242 base507c_new_(const struct nv50_wndw_func *func, const u32 *format,
243               struct nouveau_drm *drm, int head, s32 oclass, u32 interlock_data,
244               struct nv50_wndw **pwndw)
245 {
246         struct nv50_disp_base_channel_dma_v0 args = {
247                 .head = head,
248         };
249         struct nv50_disp *disp = nv50_disp(drm->dev);
250         struct nv50_wndw *wndw;
251         int ret;
252
253         ret = nv50_wndw_new_(func, drm->dev, DRM_PLANE_TYPE_PRIMARY,
254                              "base", head, format, BIT(head),
255                              NV50_DISP_INTERLOCK_BASE, interlock_data, &wndw);
256         if (*pwndw = wndw, ret)
257                 return ret;
258
259         ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
260                                &oclass, head, &args, sizeof(args),
261                                disp->sync->bo.offset, &wndw->wndw);
262         if (ret) {
263                 NV_ERROR(drm, "base%04x allocation failed: %d\n", oclass, ret);
264                 return ret;
265         }
266
267         ret = nvif_notify_init(&wndw->wndw.base.user, wndw->notify.func,
268                                false, NV50_DISP_BASE_CHANNEL_DMA_V0_NTFY_UEVENT,
269                                &(struct nvif_notify_uevent_req) {},
270                                sizeof(struct nvif_notify_uevent_req),
271                                sizeof(struct nvif_notify_uevent_rep),
272                                &wndw->notify);
273         if (ret)
274                 return ret;
275
276         wndw->ntfy = NV50_DISP_BASE_NTFY(wndw->id);
277         wndw->sema = NV50_DISP_BASE_SEM0(wndw->id);
278         wndw->data = 0x00000000;
279         return 0;
280 }
281
282 int
283 base507c_new(struct nouveau_drm *drm, int head, s32 oclass,
284              struct nv50_wndw **pwndw)
285 {
286         return base507c_new_(&base507c, base507c_format, drm, head, oclass,
287                              0x00000002 << (head * 8), pwndw);
288 }