blob: 03a3e3fc84ab144d7e25bbfea1e8318c3730bdcb [file] [log] [blame]
Ben Skeggs56d237d2014-05-19 14:54:33 +10001/*
Ben Skeggs26f6d882011-07-04 16:25:18 +10002 * Copyright 2011 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 * Authors: Ben Skeggs
23 */
24
Ben Skeggs51beb422011-07-05 10:33:08 +100025#include <linux/dma-mapping.h>
Ben Skeggs83fc0832011-07-05 13:08:40 +100026
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
Ben Skeggsad633612016-11-04 17:20:36 +100028#include <drm/drm_atomic.h>
Ben Skeggs973f10c2016-11-04 17:20:36 +100029#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010030#include <drm/drm_crtc_helper.h>
Ben Skeggs48743222014-05-31 01:48:06 +100031#include <drm/drm_dp_helper.h>
Daniel Vetterb516a9e2015-12-04 09:45:43 +010032#include <drm/drm_fb_helper.h>
Ben Skeggsad633612016-11-04 17:20:36 +100033#include <drm/drm_plane_helper.h>
Ben Skeggs26f6d882011-07-04 16:25:18 +100034
Ben Skeggsfdb751e2014-08-10 04:10:23 +100035#include <nvif/class.h>
Ben Skeggs845f2722015-11-08 12:16:40 +100036#include <nvif/cl0002.h>
Ben Skeggs7568b102015-11-08 10:44:19 +100037#include <nvif/cl5070.h>
38#include <nvif/cl507a.h>
39#include <nvif/cl507b.h>
40#include <nvif/cl507c.h>
41#include <nvif/cl507d.h>
42#include <nvif/cl507e.h>
Ben Skeggs973f10c2016-11-04 17:20:36 +100043#include <nvif/event.h>
Ben Skeggsfdb751e2014-08-10 04:10:23 +100044
Ben Skeggs4dc28132016-05-20 09:22:55 +100045#include "nouveau_drv.h"
Ben Skeggs77145f12012-07-31 16:16:21 +100046#include "nouveau_dma.h"
47#include "nouveau_gem.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100048#include "nouveau_connector.h"
49#include "nouveau_encoder.h"
50#include "nouveau_crtc.h"
Ben Skeggsf589be82012-07-22 11:55:54 +100051#include "nouveau_fence.h"
Ben Skeggs3a89cd02011-07-07 10:47:10 +100052#include "nv50_display.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100053
Ben Skeggs8a464382011-11-12 23:52:07 +100054#define EVO_DMA_NR 9
55
Ben Skeggsbdb8c212011-11-12 01:30:24 +100056#define EVO_MASTER (0x00)
Ben Skeggsa63a97e2011-11-16 15:22:34 +100057#define EVO_FLIP(c) (0x01 + (c))
Ben Skeggs8a464382011-11-12 23:52:07 +100058#define EVO_OVLY(c) (0x05 + (c))
59#define EVO_OIMM(c) (0x09 + (c))
Ben Skeggsbdb8c212011-11-12 01:30:24 +100060#define EVO_CURS(c) (0x0d + (c))
61
Ben Skeggs816af2f2011-11-16 15:48:48 +100062/* offsets in shared sync bo of various structures */
63#define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +100064#define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
65#define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
66#define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
Ben Skeggs973f10c2016-11-04 17:20:36 +100067#define EVO_FLIP_NTFY0(c) EVO_SYNC((c) + 1, 0x20)
68#define EVO_FLIP_NTFY1(c) EVO_SYNC((c) + 1, 0x30)
Ben Skeggs816af2f2011-11-16 15:48:48 +100069
Ben Skeggsb5a794b2012-10-16 14:18:32 +100070/******************************************************************************
Ben Skeggs3dbd0362016-11-04 17:20:36 +100071 * Atomic state
72 *****************************************************************************/
73#define nv50_head_atom(p) container_of((p), struct nv50_head_atom, state)
74
75struct nv50_head_atom {
76 struct drm_crtc_state state;
77
Ben Skeggsc4e68122016-11-04 17:20:36 +100078 struct {
79 u16 iW;
80 u16 iH;
81 u16 oW;
82 u16 oH;
83 } view;
84
Ben Skeggs3dbd0362016-11-04 17:20:36 +100085 struct nv50_head_mode {
86 bool interlace;
87 u32 clock;
88 struct {
89 u16 active;
90 u16 synce;
91 u16 blanke;
92 u16 blanks;
93 } h;
94 struct {
95 u32 active;
96 u16 synce;
97 u16 blanke;
98 u16 blanks;
99 u16 blank2s;
100 u16 blank2e;
101 u16 blankus;
102 } v;
103 } mode;
104
Ben Skeggsad633612016-11-04 17:20:36 +1000105 struct {
Ben Skeggsa7ae1562016-11-04 17:20:36 +1000106 u32 handle;
107 u64 offset:40;
108 } lut;
109
110 struct {
Ben Skeggsad633612016-11-04 17:20:36 +1000111 bool visible;
112 u32 handle;
113 u64 offset:40;
114 u8 format;
115 u8 kind:7;
116 u8 layout:1;
117 u8 block:4;
118 u32 pitch:20;
119 u16 x;
120 u16 y;
121 u16 w;
122 u16 h;
123 } core;
124
125 struct {
Ben Skeggsea8ee392016-11-04 17:20:36 +1000126 bool visible;
127 u32 handle;
128 u64 offset:40;
129 u8 layout:1;
130 u8 format:1;
131 } curs;
132
133 struct {
Ben Skeggsad633612016-11-04 17:20:36 +1000134 u8 depth;
135 u8 cpp;
136 u16 x;
137 u16 y;
138 u16 w;
139 u16 h;
140 } base;
141
Ben Skeggs6bbab3b2016-11-04 17:20:36 +1000142 struct {
143 u8 cpp;
144 } ovly;
145
Ben Skeggs7e918332016-11-04 17:20:36 +1000146 struct {
147 bool enable:1;
148 u8 bits:2;
149 u8 mode:4;
150 } dither;
151
Ben Skeggs7e08d672016-11-04 17:20:36 +1000152 struct {
153 struct {
154 u16 cos:12;
155 u16 sin:12;
156 } sat;
157 } procamp;
158
Ben Skeggs3dbd0362016-11-04 17:20:36 +1000159 union {
160 struct {
Ben Skeggsad633612016-11-04 17:20:36 +1000161 bool core:1;
Ben Skeggsea8ee392016-11-04 17:20:36 +1000162 bool curs:1;
Ben Skeggsad633612016-11-04 17:20:36 +1000163 };
164 u8 mask;
165 } clr;
166
167 union {
168 struct {
169 bool core:1;
Ben Skeggsea8ee392016-11-04 17:20:36 +1000170 bool curs:1;
Ben Skeggsad633612016-11-04 17:20:36 +1000171 bool view:1;
Ben Skeggs3dbd0362016-11-04 17:20:36 +1000172 bool mode:1;
Ben Skeggs6bbab3b2016-11-04 17:20:36 +1000173 bool base:1;
174 bool ovly:1;
Ben Skeggs7e918332016-11-04 17:20:36 +1000175 bool dither:1;
Ben Skeggs7e08d672016-11-04 17:20:36 +1000176 bool procamp:1;
Ben Skeggs3dbd0362016-11-04 17:20:36 +1000177 };
178 u16 mask;
179 } set;
180};
181
Ben Skeggs973f10c2016-11-04 17:20:36 +1000182#define nv50_wndw_atom(p) container_of((p), struct nv50_wndw_atom, state)
183
184struct nv50_wndw_atom {
185 struct drm_plane_state state;
186 u8 interval;
187
188 struct drm_rect clip;
189
190 struct {
191 u32 handle;
192 u16 offset:12;
193 bool awaken:1;
194 } ntfy;
195
196 struct {
197 u32 handle;
198 u16 offset:12;
199 u32 acquire;
200 u32 release;
201 } sema;
202
203 struct {
204 u8 enable:2;
205 } lut;
206
207 struct {
208 u8 mode:2;
209 u8 interval:4;
210
211 u8 format;
212 u8 kind:7;
213 u8 layout:1;
214 u8 block:4;
215 u32 pitch:20;
216 u16 w;
217 u16 h;
218
219 u32 handle;
220 u64 offset;
221 } image;
222
223 struct {
224 u16 x;
225 u16 y;
226 } point;
227
228 union {
229 struct {
230 bool ntfy:1;
231 bool sema:1;
232 bool image:1;
233 };
234 u8 mask;
235 } clr;
236
237 union {
238 struct {
239 bool ntfy:1;
240 bool sema:1;
241 bool image:1;
242 bool lut:1;
243 bool point:1;
244 };
245 u8 mask;
246 } set;
247};
248
Ben Skeggs3dbd0362016-11-04 17:20:36 +1000249/******************************************************************************
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000250 * EVO channel
251 *****************************************************************************/
252
Ben Skeggse225f442012-11-21 14:40:21 +1000253struct nv50_chan {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000254 struct nvif_object user;
Ben Skeggsa01ca782015-08-20 14:54:15 +1000255 struct nvif_device *device;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000256};
257
258static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000259nv50_chan_create(struct nvif_device *device, struct nvif_object *disp,
Ben Skeggs315a8b22015-08-20 14:54:16 +1000260 const s32 *oclass, u8 head, void *data, u32 size,
Ben Skeggsa01ca782015-08-20 14:54:15 +1000261 struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000262{
Ben Skeggs41a63402015-08-20 14:54:16 +1000263 struct nvif_sclass *sclass;
264 int ret, i, n;
Ben Skeggs6af52892014-11-03 15:01:33 +1000265
Ben Skeggsa01ca782015-08-20 14:54:15 +1000266 chan->device = device;
267
Ben Skeggs41a63402015-08-20 14:54:16 +1000268 ret = n = nvif_object_sclass_get(disp, &sclass);
Ben Skeggs6af52892014-11-03 15:01:33 +1000269 if (ret < 0)
270 return ret;
271
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000272 while (oclass[0]) {
Ben Skeggs41a63402015-08-20 14:54:16 +1000273 for (i = 0; i < n; i++) {
274 if (sclass[i].oclass == oclass[0]) {
Ben Skeggsfcf3f912015-09-04 14:40:32 +1000275 ret = nvif_object_init(disp, 0, oclass[0],
Ben Skeggsa01ca782015-08-20 14:54:15 +1000276 data, size, &chan->user);
Ben Skeggs6af52892014-11-03 15:01:33 +1000277 if (ret == 0)
278 nvif_object_map(&chan->user);
Ben Skeggs41a63402015-08-20 14:54:16 +1000279 nvif_object_sclass_put(&sclass);
Ben Skeggs6af52892014-11-03 15:01:33 +1000280 return ret;
281 }
Ben Skeggsb76f1522014-08-10 04:10:28 +1000282 }
Ben Skeggs6af52892014-11-03 15:01:33 +1000283 oclass++;
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000284 }
Ben Skeggs6af52892014-11-03 15:01:33 +1000285
Ben Skeggs41a63402015-08-20 14:54:16 +1000286 nvif_object_sclass_put(&sclass);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000287 return -ENOSYS;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000288}
289
290static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000291nv50_chan_destroy(struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000292{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000293 nvif_object_fini(&chan->user);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000294}
295
296/******************************************************************************
297 * PIO EVO channel
298 *****************************************************************************/
299
Ben Skeggse225f442012-11-21 14:40:21 +1000300struct nv50_pioc {
301 struct nv50_chan base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000302};
303
304static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000305nv50_pioc_destroy(struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000306{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000307 nv50_chan_destroy(&pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000308}
309
310static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000311nv50_pioc_create(struct nvif_device *device, struct nvif_object *disp,
Ben Skeggs315a8b22015-08-20 14:54:16 +1000312 const s32 *oclass, u8 head, void *data, u32 size,
Ben Skeggsa01ca782015-08-20 14:54:15 +1000313 struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000314{
Ben Skeggsa01ca782015-08-20 14:54:15 +1000315 return nv50_chan_create(device, disp, oclass, head, data, size,
316 &pioc->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000317}
318
319/******************************************************************************
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000320 * Overlay Immediate
321 *****************************************************************************/
322
323struct nv50_oimm {
324 struct nv50_pioc base;
325};
326
327static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000328nv50_oimm_create(struct nvif_device *device, struct nvif_object *disp,
329 int head, struct nv50_oimm *oimm)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000330{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000331 struct nv50_disp_cursor_v0 args = {
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000332 .head = head,
333 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000334 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000335 GK104_DISP_OVERLAY,
336 GF110_DISP_OVERLAY,
337 GT214_DISP_OVERLAY,
338 G82_DISP_OVERLAY,
339 NV50_DISP_OVERLAY,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000340 0
341 };
342
Ben Skeggsa01ca782015-08-20 14:54:15 +1000343 return nv50_pioc_create(device, disp, oclass, head, &args, sizeof(args),
344 &oimm->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000345}
346
347/******************************************************************************
348 * DMA EVO channel
349 *****************************************************************************/
350
Ben Skeggsaccdea22016-11-04 17:20:36 +1000351struct nv50_dmac_ctxdma {
352 struct list_head head;
353 struct nvif_object object;
354};
355
Ben Skeggse225f442012-11-21 14:40:21 +1000356struct nv50_dmac {
357 struct nv50_chan base;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000358 dma_addr_t handle;
359 u32 *ptr;
Daniel Vetter59ad1462012-12-02 14:49:44 +0100360
Ben Skeggs0ad72862014-08-10 04:10:22 +1000361 struct nvif_object sync;
362 struct nvif_object vram;
Ben Skeggsaccdea22016-11-04 17:20:36 +1000363 struct list_head ctxdma;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000364
Daniel Vetter59ad1462012-12-02 14:49:44 +0100365 /* Protects against concurrent pushbuf access to this channel, lock is
366 * grabbed by evo_wait (if the pushbuf reservation is successful) and
367 * dropped again by evo_kick. */
368 struct mutex lock;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000369};
370
371static void
Ben Skeggsaccdea22016-11-04 17:20:36 +1000372nv50_dmac_ctxdma_del(struct nv50_dmac_ctxdma *ctxdma)
373{
374 nvif_object_fini(&ctxdma->object);
375 list_del(&ctxdma->head);
376 kfree(ctxdma);
377}
378
379static struct nv50_dmac_ctxdma *
380nv50_dmac_ctxdma_new(struct nv50_dmac *dmac, u32 handle,
381 struct nouveau_framebuffer *fb)
382{
383 struct nouveau_drm *drm = nouveau_drm(fb->base.dev);
384 struct nv50_dmac_ctxdma *ctxdma;
385 const u8 kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8;
386 struct {
387 struct nv_dma_v0 base;
388 union {
389 struct nv50_dma_v0 nv50;
390 struct gf100_dma_v0 gf100;
391 struct gf119_dma_v0 gf119;
392 };
393 } args = {};
394 u32 argc = sizeof(args.base);
395 int ret;
396
397 list_for_each_entry(ctxdma, &dmac->ctxdma, head) {
398 if (ctxdma->object.handle == handle)
399 return ctxdma;
400 }
401
402 if (!(ctxdma = kzalloc(sizeof(*ctxdma), GFP_KERNEL)))
403 return ERR_PTR(-ENOMEM);
404 list_add(&ctxdma->head, &dmac->ctxdma);
405
406 args.base.target = NV_DMA_V0_TARGET_VRAM;
407 args.base.access = NV_DMA_V0_ACCESS_RDWR;
408 args.base.start = 0;
409 args.base.limit = drm->device.info.ram_user - 1;
410
411 if (drm->device.info.chipset < 0x80) {
412 args.nv50.part = NV50_DMA_V0_PART_256;
413 argc += sizeof(args.nv50);
414 } else
415 if (drm->device.info.chipset < 0xc0) {
416 args.nv50.part = NV50_DMA_V0_PART_256;
417 args.nv50.kind = kind;
418 argc += sizeof(args.nv50);
419 } else
420 if (drm->device.info.chipset < 0xd0) {
421 args.gf100.kind = kind;
422 argc += sizeof(args.gf100);
423 } else {
424 args.gf119.page = GF119_DMA_V0_PAGE_LP;
425 args.gf119.kind = kind;
426 argc += sizeof(args.gf119);
427 }
428
429 ret = nvif_object_init(&dmac->base.user, handle, NV_DMA_IN_MEMORY,
430 &args, argc, &ctxdma->object);
431 if (ret) {
432 nv50_dmac_ctxdma_del(ctxdma);
433 return ERR_PTR(ret);
434 }
435
436 return ctxdma;
437}
438
439static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000440nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000441{
Ben Skeggsa01ca782015-08-20 14:54:15 +1000442 struct nvif_device *device = dmac->base.device;
Ben Skeggsaccdea22016-11-04 17:20:36 +1000443 struct nv50_dmac_ctxdma *ctxdma, *ctxtmp;
444
445 list_for_each_entry_safe(ctxdma, ctxtmp, &dmac->ctxdma, head) {
446 nv50_dmac_ctxdma_del(ctxdma);
447 }
Ben Skeggsa01ca782015-08-20 14:54:15 +1000448
Ben Skeggs0ad72862014-08-10 04:10:22 +1000449 nvif_object_fini(&dmac->vram);
450 nvif_object_fini(&dmac->sync);
451
452 nv50_chan_destroy(&dmac->base);
453
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000454 if (dmac->ptr) {
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000455 struct device *dev = nvxx_device(device)->dev;
456 dma_free_coherent(dev, PAGE_SIZE, dmac->ptr, dmac->handle);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000457 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000458}
459
460static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000461nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,
Ben Skeggs315a8b22015-08-20 14:54:16 +1000462 const s32 *oclass, u8 head, void *data, u32 size, u64 syncbuf,
Ben Skeggse225f442012-11-21 14:40:21 +1000463 struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000464{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000465 struct nv50_disp_core_channel_dma_v0 *args = data;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000466 struct nvif_object pushbuf;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000467 int ret;
468
Daniel Vetter59ad1462012-12-02 14:49:44 +0100469 mutex_init(&dmac->lock);
470
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000471 dmac->ptr = dma_alloc_coherent(nvxx_device(device)->dev, PAGE_SIZE,
472 &dmac->handle, GFP_KERNEL);
Ben Skeggs47057302012-11-16 13:58:48 +1000473 if (!dmac->ptr)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000474 return -ENOMEM;
475
Ben Skeggsfcf3f912015-09-04 14:40:32 +1000476 ret = nvif_object_init(&device->object, 0, NV_DMA_FROM_MEMORY,
477 &(struct nv_dma_v0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +1000478 .target = NV_DMA_V0_TARGET_PCI_US,
479 .access = NV_DMA_V0_ACCESS_RD,
Ben Skeggs47057302012-11-16 13:58:48 +1000480 .start = dmac->handle + 0x0000,
481 .limit = dmac->handle + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000482 }, sizeof(struct nv_dma_v0), &pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000483 if (ret)
484 return ret;
485
Ben Skeggsbf81df92015-08-20 14:54:16 +1000486 args->pushbuf = nvif_handle(&pushbuf);
487
Ben Skeggsa01ca782015-08-20 14:54:15 +1000488 ret = nv50_chan_create(device, disp, oclass, head, data, size,
489 &dmac->base);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000490 nvif_object_fini(&pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000491 if (ret)
492 return ret;
493
Ben Skeggsa01ca782015-08-20 14:54:15 +1000494 ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000495 &(struct nv_dma_v0) {
496 .target = NV_DMA_V0_TARGET_VRAM,
497 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000498 .start = syncbuf + 0x0000,
499 .limit = syncbuf + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000500 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000501 &dmac->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000502 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000503 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000504
Ben Skeggsa01ca782015-08-20 14:54:15 +1000505 ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000506 &(struct nv_dma_v0) {
507 .target = NV_DMA_V0_TARGET_VRAM,
508 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000509 .start = 0,
Ben Skeggsf392ec42014-08-10 04:10:28 +1000510 .limit = device->info.ram_user - 1,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000511 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000512 &dmac->vram);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000513 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000514 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000515
Ben Skeggsaccdea22016-11-04 17:20:36 +1000516 INIT_LIST_HEAD(&dmac->ctxdma);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000517 return ret;
518}
519
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000520/******************************************************************************
521 * Core
522 *****************************************************************************/
523
Ben Skeggse225f442012-11-21 14:40:21 +1000524struct nv50_mast {
525 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000526};
527
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000528static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000529nv50_core_create(struct nvif_device *device, struct nvif_object *disp,
530 u64 syncbuf, struct nv50_mast *core)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000531{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000532 struct nv50_disp_core_channel_dma_v0 args = {
533 .pushbuf = 0xb0007d00,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000534 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000535 static const s32 oclass[] = {
Ben Skeggsfd478772016-07-09 10:41:01 +1000536 GP104_DISP_CORE_CHANNEL_DMA,
Ben Skeggsf9d5cbb2016-07-09 10:41:01 +1000537 GP100_DISP_CORE_CHANNEL_DMA,
Ben Skeggsdb1eb522016-02-11 08:35:32 +1000538 GM200_DISP_CORE_CHANNEL_DMA,
Ben Skeggs648d4df2014-08-10 04:10:27 +1000539 GM107_DISP_CORE_CHANNEL_DMA,
540 GK110_DISP_CORE_CHANNEL_DMA,
541 GK104_DISP_CORE_CHANNEL_DMA,
542 GF110_DISP_CORE_CHANNEL_DMA,
543 GT214_DISP_CORE_CHANNEL_DMA,
544 GT206_DISP_CORE_CHANNEL_DMA,
545 GT200_DISP_CORE_CHANNEL_DMA,
546 G82_DISP_CORE_CHANNEL_DMA,
547 NV50_DISP_CORE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000548 0
549 };
550
Ben Skeggsa01ca782015-08-20 14:54:15 +1000551 return nv50_dmac_create(device, disp, oclass, 0, &args, sizeof(args),
552 syncbuf, &core->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000553}
554
555/******************************************************************************
556 * Base
557 *****************************************************************************/
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000558
Ben Skeggse225f442012-11-21 14:40:21 +1000559struct nv50_sync {
560 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000561 u32 addr;
562 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000563};
564
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000565static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000566nv50_base_create(struct nvif_device *device, struct nvif_object *disp,
567 int head, u64 syncbuf, struct nv50_sync *base)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000568{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000569 struct nv50_disp_base_channel_dma_v0 args = {
570 .pushbuf = 0xb0007c00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000571 .head = head,
572 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000573 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000574 GK110_DISP_BASE_CHANNEL_DMA,
575 GK104_DISP_BASE_CHANNEL_DMA,
576 GF110_DISP_BASE_CHANNEL_DMA,
577 GT214_DISP_BASE_CHANNEL_DMA,
578 GT200_DISP_BASE_CHANNEL_DMA,
579 G82_DISP_BASE_CHANNEL_DMA,
580 NV50_DISP_BASE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000581 0
582 };
583
Ben Skeggsa01ca782015-08-20 14:54:15 +1000584 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000585 syncbuf, &base->base);
586}
587
588/******************************************************************************
589 * Overlay
590 *****************************************************************************/
591
Ben Skeggse225f442012-11-21 14:40:21 +1000592struct nv50_ovly {
593 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000594};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000595
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000596static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000597nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp,
598 int head, u64 syncbuf, struct nv50_ovly *ovly)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000599{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000600 struct nv50_disp_overlay_channel_dma_v0 args = {
601 .pushbuf = 0xb0007e00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000602 .head = head,
603 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000604 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000605 GK104_DISP_OVERLAY_CONTROL_DMA,
606 GF110_DISP_OVERLAY_CONTROL_DMA,
607 GT214_DISP_OVERLAY_CHANNEL_DMA,
608 GT200_DISP_OVERLAY_CHANNEL_DMA,
609 G82_DISP_OVERLAY_CHANNEL_DMA,
610 NV50_DISP_OVERLAY_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000611 0
612 };
613
Ben Skeggsa01ca782015-08-20 14:54:15 +1000614 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000615 syncbuf, &ovly->base);
616}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000617
Ben Skeggse225f442012-11-21 14:40:21 +1000618struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000619 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000620 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000621 struct nv50_ovly ovly;
622 struct nv50_oimm oimm;
Ben Skeggs3dbd0362016-11-04 17:20:36 +1000623
624 struct nv50_head_atom arm;
625 struct nv50_head_atom asy;
Ben Skeggs973f10c2016-11-04 17:20:36 +1000626
627 struct nv50_base *_base;
Ben Skeggs22e927d2016-11-04 17:20:36 +1000628 struct nv50_curs *_curs;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000629};
630
Ben Skeggse225f442012-11-21 14:40:21 +1000631#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
Ben Skeggse225f442012-11-21 14:40:21 +1000632#define nv50_ovly(c) (&nv50_head(c)->ovly)
633#define nv50_oimm(c) (&nv50_head(c)->oimm)
634#define nv50_chan(c) (&(c)->base.base)
Ben Skeggs0ad72862014-08-10 04:10:22 +1000635#define nv50_vers(c) nv50_chan(c)->user.oclass
636
Ben Skeggse225f442012-11-21 14:40:21 +1000637struct nv50_disp {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000638 struct nvif_object *disp;
Ben Skeggse225f442012-11-21 14:40:21 +1000639 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000640
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000641 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000642};
643
Ben Skeggse225f442012-11-21 14:40:21 +1000644static struct nv50_disp *
645nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000646{
Ben Skeggs77145f12012-07-31 16:16:21 +1000647 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000648}
649
Ben Skeggse225f442012-11-21 14:40:21 +1000650#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000651
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000652static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000653nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000654{
655 return nouveau_encoder(encoder)->crtc;
656}
657
658/******************************************************************************
659 * EVO channel helpers
660 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000661static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000662evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000663{
Ben Skeggse225f442012-11-21 14:40:21 +1000664 struct nv50_dmac *dmac = evoc;
Ben Skeggsa01ca782015-08-20 14:54:15 +1000665 struct nvif_device *device = dmac->base.device;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000666 u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000667
Daniel Vetter59ad1462012-12-02 14:49:44 +0100668 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000669 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000670 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000671
Ben Skeggs0ad72862014-08-10 04:10:22 +1000672 nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
Ben Skeggs54442042015-08-20 14:54:11 +1000673 if (nvif_msec(device, 2000,
674 if (!nvif_rd32(&dmac->base.user, 0x0004))
675 break;
676 ) < 0) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100677 mutex_unlock(&dmac->lock);
Ben Skeggs9ad97ed2015-08-20 14:54:13 +1000678 printk(KERN_ERR "nouveau: evo channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000679 return NULL;
680 }
681
682 put = 0;
683 }
684
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000685 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000686}
687
688static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000689evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000690{
Ben Skeggse225f442012-11-21 14:40:21 +1000691 struct nv50_dmac *dmac = evoc;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000692 nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100693 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000694}
695
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000696#define evo_mthd(p,m,s) do { \
697 const u32 _m = (m), _s = (s); \
Ben Skeggs7f55a072016-11-04 17:20:36 +1000698 if (drm_debug & DRM_UT_KMS) \
699 printk(KERN_ERR "%04x %d %s\n", _m, _s, __func__); \
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000700 *((p)++) = ((_s << 18) | _m); \
701} while(0)
Ben Skeggs7f55a072016-11-04 17:20:36 +1000702
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000703#define evo_data(p,d) do { \
704 const u32 _d = (d); \
Ben Skeggs7f55a072016-11-04 17:20:36 +1000705 if (drm_debug & DRM_UT_KMS) \
706 printk(KERN_ERR "\t%08x\n", _d); \
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000707 *((p)++) = _d; \
708} while(0)
Ben Skeggs51beb422011-07-05 10:33:08 +1000709
Ben Skeggs3376ee32011-11-12 14:28:12 +1000710static bool
711evo_sync_wait(void *data)
712{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500713 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
714 return true;
715 usleep_range(1, 2);
716 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000717}
718
719static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000720evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000721{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000722 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggse225f442012-11-21 14:40:21 +1000723 struct nv50_disp *disp = nv50_disp(dev);
724 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000725 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000726 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000727 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000728 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000729 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000730 evo_mthd(push, 0x0080, 2);
731 evo_data(push, 0x00000000);
732 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000733 evo_kick(push, mast);
Ben Skeggs54442042015-08-20 14:54:11 +1000734 if (nvif_msec(device, 2000,
735 if (evo_sync_wait(disp->sync))
736 break;
737 ) >= 0)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000738 return 0;
739 }
740
741 return -EBUSY;
742}
743
744/******************************************************************************
Ben Skeggs973f10c2016-11-04 17:20:36 +1000745 * Plane
746 *****************************************************************************/
747#define nv50_wndw(p) container_of((p), struct nv50_wndw, plane)
748
749struct nv50_wndw {
750 const struct nv50_wndw_func *func;
751 struct nv50_dmac *dmac;
752
753 struct drm_plane plane;
754
755 struct nvif_notify notify;
756 u16 ntfy;
757 u16 sema;
758 u32 data;
759
760 struct nv50_wndw_atom arm;
761 struct nv50_wndw_atom asy;
762};
763
764struct nv50_wndw_func {
765 void *(*dtor)(struct nv50_wndw *);
766 int (*acquire)(struct nv50_wndw *, struct nv50_wndw_atom *asyw,
767 struct nv50_head_atom *asyh);
768 void (*release)(struct nv50_wndw *, struct nv50_wndw_atom *asyw,
769 struct nv50_head_atom *asyh);
770 void (*prepare)(struct nv50_wndw *, struct nv50_head_atom *asyh,
771 struct nv50_wndw_atom *asyw);
772
773 void (*sema_set)(struct nv50_wndw *, struct nv50_wndw_atom *);
774 void (*sema_clr)(struct nv50_wndw *);
775 void (*ntfy_set)(struct nv50_wndw *, struct nv50_wndw_atom *);
776 void (*ntfy_clr)(struct nv50_wndw *);
777 int (*ntfy_wait_begun)(struct nv50_wndw *, struct nv50_wndw_atom *);
778 void (*image_set)(struct nv50_wndw *, struct nv50_wndw_atom *);
779 void (*image_clr)(struct nv50_wndw *);
780 void (*lut)(struct nv50_wndw *, struct nv50_wndw_atom *);
781 void (*point)(struct nv50_wndw *, struct nv50_wndw_atom *);
782
783 u32 (*update)(struct nv50_wndw *, u32 interlock);
784};
785
786static int
787nv50_wndw_wait_armed(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
788{
789 if (asyw->set.ntfy)
790 return wndw->func->ntfy_wait_begun(wndw, asyw);
791 return 0;
792}
793
794static u32
795nv50_wndw_flush_clr(struct nv50_wndw *wndw, u32 interlock, bool flush,
796 struct nv50_wndw_atom *asyw)
797{
798 if (asyw->clr.sema && (!asyw->set.sema || flush))
799 wndw->func->sema_clr(wndw);
800 if (asyw->clr.ntfy && (!asyw->set.ntfy || flush))
801 wndw->func->ntfy_clr(wndw);
802 if (asyw->clr.image && (!asyw->set.image || flush))
803 wndw->func->image_clr(wndw);
804
805 return flush ? wndw->func->update(wndw, interlock) : 0;
806}
807
808static u32
809nv50_wndw_flush_set(struct nv50_wndw *wndw, u32 interlock,
810 struct nv50_wndw_atom *asyw)
811{
812 if (interlock) {
813 asyw->image.mode = 0;
814 asyw->image.interval = 1;
815 }
816
817 if (asyw->set.sema ) wndw->func->sema_set (wndw, asyw);
818 if (asyw->set.ntfy ) wndw->func->ntfy_set (wndw, asyw);
819 if (asyw->set.image) wndw->func->image_set(wndw, asyw);
820 if (asyw->set.lut ) wndw->func->lut (wndw, asyw);
821 if (asyw->set.point) wndw->func->point (wndw, asyw);
822
823 return wndw->func->update(wndw, interlock);
824}
825
826static void
827nv50_wndw_atomic_check_release(struct nv50_wndw *wndw,
828 struct nv50_wndw_atom *asyw,
829 struct nv50_head_atom *asyh)
830{
831 struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev);
832 NV_ATOMIC(drm, "%s release\n", wndw->plane.name);
833 wndw->func->release(wndw, asyw, asyh);
834 asyw->ntfy.handle = 0;
835 asyw->sema.handle = 0;
836}
837
838static int
839nv50_wndw_atomic_check_acquire(struct nv50_wndw *wndw,
840 struct nv50_wndw_atom *asyw,
841 struct nv50_head_atom *asyh)
842{
843 struct nouveau_framebuffer *fb = nouveau_framebuffer(asyw->state.fb);
844 struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev);
845 int ret;
846
847 NV_ATOMIC(drm, "%s acquire\n", wndw->plane.name);
848 asyw->clip.x1 = 0;
849 asyw->clip.y1 = 0;
850 asyw->clip.x2 = asyh->state.mode.hdisplay;
851 asyw->clip.y2 = asyh->state.mode.vdisplay;
852
853 asyw->image.w = fb->base.width;
854 asyw->image.h = fb->base.height;
855 asyw->image.kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8;
856 if (asyw->image.kind) {
857 asyw->image.layout = 0;
858 if (drm->device.info.chipset >= 0xc0)
859 asyw->image.block = fb->nvbo->tile_mode >> 4;
860 else
861 asyw->image.block = fb->nvbo->tile_mode;
862 asyw->image.pitch = (fb->base.pitches[0] / 4) << 4;
863 } else {
864 asyw->image.layout = 1;
865 asyw->image.block = 0;
866 asyw->image.pitch = fb->base.pitches[0];
867 }
868
869 ret = wndw->func->acquire(wndw, asyw, asyh);
870 if (ret)
871 return ret;
872
873 if (asyw->set.image) {
874 if (!(asyw->image.mode = asyw->interval ? 0 : 1))
875 asyw->image.interval = asyw->interval;
876 else
877 asyw->image.interval = 0;
878 }
879
880 return 0;
881}
882
883static int
884nv50_wndw_atomic_check(struct drm_plane *plane, struct drm_plane_state *state)
885{
886 struct nouveau_drm *drm = nouveau_drm(plane->dev);
887 struct nv50_wndw *wndw = nv50_wndw(plane);
888 struct nv50_wndw_atom *armw = &wndw->arm;
889 struct nv50_wndw_atom *asyw = &wndw->asy;
890 struct nv50_head_atom *harm = NULL, *asyh = NULL;
891 bool varm = false, asyv = false, asym = false;
892 int ret;
893
894 asyw->clr.mask = 0;
895 asyw->set.mask = 0;
896
897 NV_ATOMIC(drm, "%s atomic_check\n", plane->name);
898 if (asyw->state.crtc) {
899 asyh = &nv50_head(asyw->state.crtc)->asy;
900 if (IS_ERR(asyh))
901 return PTR_ERR(asyh);
902 asym = drm_atomic_crtc_needs_modeset(&asyh->state);
903 asyv = asyh->state.active;
904 }
905
906 if (armw->state.crtc) {
907 harm = &nv50_head(armw->state.crtc)->asy;
908 if (IS_ERR(harm))
909 return PTR_ERR(harm);
910 varm = nv50_head(harm->state.crtc)->arm.state.active;
911 }
912
913 if (asyv) {
914 asyw->point.x = asyw->state.crtc_x;
915 asyw->point.y = asyw->state.crtc_y;
916 if (memcmp(&armw->point, &asyw->point, sizeof(asyw->point)))
917 asyw->set.point = true;
918
919 if (!varm || asym || armw->state.fb != asyw->state.fb) {
920 ret = nv50_wndw_atomic_check_acquire(wndw, asyw, asyh);
921 if (ret)
922 return ret;
923 }
924 } else
925 if (varm) {
926 nv50_wndw_atomic_check_release(wndw, asyw, harm);
927 } else {
928 return 0;
929 }
930
931 if (!asyv || asym) {
932 asyw->clr.ntfy = armw->ntfy.handle != 0;
933 asyw->clr.sema = armw->sema.handle != 0;
934 if (wndw->func->image_clr)
935 asyw->clr.image = armw->image.handle != 0;
936 asyw->set.lut = wndw->func->lut && asyv;
937 }
938
939 memcpy(armw, asyw, sizeof(*asyw));
940 return 0;
941}
942
943static void
944nv50_wndw_atomic_destroy_state(struct drm_plane *plane,
945 struct drm_plane_state *state)
946{
947 struct nv50_wndw_atom *asyw = nv50_wndw_atom(state);
948 __drm_atomic_helper_plane_destroy_state(&asyw->state);
949 dma_fence_put(asyw->state.fence);
950 kfree(asyw);
951}
952
953static struct drm_plane_state *
954nv50_wndw_atomic_duplicate_state(struct drm_plane *plane)
955{
956 struct nv50_wndw_atom *armw = nv50_wndw_atom(plane->state);
957 struct nv50_wndw_atom *asyw;
958 if (!(asyw = kmalloc(sizeof(*asyw), GFP_KERNEL)))
959 return NULL;
960 __drm_atomic_helper_plane_duplicate_state(plane, &asyw->state);
961 asyw->state.fence = NULL;
962 asyw->interval = 1;
963 asyw->sema = armw->sema;
964 asyw->ntfy = armw->ntfy;
965 asyw->image = armw->image;
966 asyw->point = armw->point;
967 asyw->lut = armw->lut;
968 asyw->clr.mask = 0;
969 asyw->set.mask = 0;
970 return &asyw->state;
971}
972
973static void
974nv50_wndw_reset(struct drm_plane *plane)
975{
976 struct nv50_wndw_atom *asyw;
977
978 if (WARN_ON(!(asyw = kzalloc(sizeof(*asyw), GFP_KERNEL))))
979 return;
980
981 if (plane->state)
982 plane->funcs->atomic_destroy_state(plane, plane->state);
983 plane->state = &asyw->state;
984 plane->state->plane = plane;
985 plane->state->rotation = DRM_ROTATE_0;
986}
987
988static void
989nv50_wndw_destroy(struct drm_plane *plane)
990{
991 struct nv50_wndw *wndw = nv50_wndw(plane);
992 void *data;
993 nvif_notify_fini(&wndw->notify);
994 data = wndw->func->dtor(wndw);
995 drm_plane_cleanup(&wndw->plane);
996 kfree(data);
997}
998
999static const struct drm_plane_funcs
1000nv50_wndw = {
1001 .destroy = nv50_wndw_destroy,
1002 .reset = nv50_wndw_reset,
1003 .set_property = drm_atomic_helper_plane_set_property,
1004 .atomic_duplicate_state = nv50_wndw_atomic_duplicate_state,
1005 .atomic_destroy_state = nv50_wndw_atomic_destroy_state,
1006};
1007
1008static void
1009nv50_wndw_fini(struct nv50_wndw *wndw)
1010{
1011 nvif_notify_put(&wndw->notify);
1012}
1013
1014static void
1015nv50_wndw_init(struct nv50_wndw *wndw)
1016{
1017 nvif_notify_get(&wndw->notify);
1018}
1019
1020static int
1021nv50_wndw_ctor(const struct nv50_wndw_func *func, struct drm_device *dev,
1022 enum drm_plane_type type, const char *name, int index,
1023 struct nv50_dmac *dmac, const u32 *format, int nformat,
1024 struct nv50_wndw *wndw)
1025{
1026 int ret;
1027
1028 wndw->func = func;
1029 wndw->dmac = dmac;
1030
1031 ret = drm_universal_plane_init(dev, &wndw->plane, 0, &nv50_wndw, format,
1032 nformat, type, "%s-%d", name, index);
1033 if (ret)
1034 return ret;
1035
1036 return 0;
1037}
1038
1039/******************************************************************************
Ben Skeggs22e927d2016-11-04 17:20:36 +10001040 * Cursor plane
1041 *****************************************************************************/
1042#define nv50_curs(p) container_of((p), struct nv50_curs, wndw)
1043
1044struct nv50_curs {
1045 struct nv50_wndw wndw;
1046 struct nvif_object chan;
1047};
1048
1049static u32
1050nv50_curs_update(struct nv50_wndw *wndw, u32 interlock)
1051{
1052 struct nv50_curs *curs = nv50_curs(wndw);
1053 nvif_wr32(&curs->chan, 0x0080, 0x00000000);
1054 return 0;
1055}
1056
1057static void
1058nv50_curs_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
1059{
1060 struct nv50_curs *curs = nv50_curs(wndw);
1061 nvif_wr32(&curs->chan, 0x0084, (asyw->point.y << 16) | asyw->point.x);
1062}
1063
1064static void
1065nv50_curs_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh,
1066 struct nv50_wndw_atom *asyw)
1067{
1068 asyh->curs.handle = nv50_disp(wndw->plane.dev)->mast.base.vram.handle;
1069 asyh->curs.offset = asyw->image.offset;
1070 asyh->set.curs = asyh->curs.visible;
1071}
1072
1073static void
1074nv50_curs_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
1075 struct nv50_head_atom *asyh)
1076{
1077 asyh->curs.visible = false;
1078}
1079
1080static int
1081nv50_curs_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
1082 struct nv50_head_atom *asyh)
1083{
1084 int ret;
1085
1086 ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip,
1087 DRM_PLANE_HELPER_NO_SCALING,
1088 DRM_PLANE_HELPER_NO_SCALING,
1089 true, true);
1090 asyh->curs.visible = asyw->state.visible;
1091 if (ret || !asyh->curs.visible)
1092 return ret;
1093
1094 switch (asyw->state.fb->width) {
1095 case 32: asyh->curs.layout = 0; break;
1096 case 64: asyh->curs.layout = 1; break;
1097 default:
1098 return -EINVAL;
1099 }
1100
1101 if (asyw->state.fb->width != asyw->state.fb->height)
1102 return -EINVAL;
1103
1104 switch (asyw->state.fb->pixel_format) {
1105 case DRM_FORMAT_ARGB8888: asyh->curs.format = 1; break;
1106 default:
1107 WARN_ON(1);
1108 return -EINVAL;
1109 }
1110
1111 return 0;
1112}
1113
1114static void *
1115nv50_curs_dtor(struct nv50_wndw *wndw)
1116{
1117 struct nv50_curs *curs = nv50_curs(wndw);
1118 nvif_object_fini(&curs->chan);
1119 return curs;
1120}
1121
1122static const u32
1123nv50_curs_format[] = {
1124 DRM_FORMAT_ARGB8888,
1125};
1126
1127static const struct nv50_wndw_func
1128nv50_curs = {
1129 .dtor = nv50_curs_dtor,
1130 .acquire = nv50_curs_acquire,
1131 .release = nv50_curs_release,
1132 .prepare = nv50_curs_prepare,
1133 .point = nv50_curs_point,
1134 .update = nv50_curs_update,
1135};
1136
1137static int
1138nv50_curs_new(struct nouveau_drm *drm, struct nv50_head *head,
1139 struct nv50_curs **pcurs)
1140{
1141 static const struct nvif_mclass curses[] = {
1142 { GK104_DISP_CURSOR, 0 },
1143 { GF110_DISP_CURSOR, 0 },
1144 { GT214_DISP_CURSOR, 0 },
1145 { G82_DISP_CURSOR, 0 },
1146 { NV50_DISP_CURSOR, 0 },
1147 {}
1148 };
1149 struct nv50_disp_cursor_v0 args = {
1150 .head = head->base.index,
1151 };
1152 struct nv50_disp *disp = nv50_disp(drm->dev);
1153 struct nv50_curs *curs;
1154 int cid, ret;
1155
1156 cid = nvif_mclass(disp->disp, curses);
1157 if (cid < 0) {
1158 NV_ERROR(drm, "No supported cursor immediate class\n");
1159 return cid;
1160 }
1161
1162 if (!(curs = *pcurs = kzalloc(sizeof(*curs), GFP_KERNEL)))
1163 return -ENOMEM;
1164
1165 ret = nv50_wndw_ctor(&nv50_curs, drm->dev, DRM_PLANE_TYPE_CURSOR,
1166 "curs", head->base.index, &disp->mast.base,
1167 nv50_curs_format, ARRAY_SIZE(nv50_curs_format),
1168 &curs->wndw);
1169 if (ret) {
1170 kfree(curs);
1171 return ret;
1172 }
1173
1174 ret = nvif_object_init(disp->disp, 0, curses[cid].oclass, &args,
1175 sizeof(args), &curs->chan);
1176 if (ret) {
1177 NV_ERROR(drm, "curs%04x allocation failed: %d\n",
1178 curses[cid].oclass, ret);
1179 return ret;
1180 }
1181
1182 return 0;
1183}
1184
1185/******************************************************************************
Ben Skeggs973f10c2016-11-04 17:20:36 +10001186 * Primary plane
1187 *****************************************************************************/
1188#define nv50_base(p) container_of((p), struct nv50_base, wndw)
1189
1190struct nv50_base {
1191 struct nv50_wndw wndw;
1192 struct nv50_sync chan;
1193 int id;
1194};
1195
1196static int
1197nv50_base_notify(struct nvif_notify *notify)
1198{
1199 return NVIF_NOTIFY_KEEP;
1200}
1201
1202static void
1203nv50_base_lut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
1204{
1205 struct nv50_base *base = nv50_base(wndw);
1206 u32 *push;
1207 if ((push = evo_wait(&base->chan, 2))) {
1208 evo_mthd(push, 0x00e0, 1);
1209 evo_data(push, asyw->lut.enable << 30);
1210 evo_kick(push, &base->chan);
1211 }
1212}
1213
1214static void
1215nv50_base_image_clr(struct nv50_wndw *wndw)
1216{
1217 struct nv50_base *base = nv50_base(wndw);
1218 u32 *push;
1219 if ((push = evo_wait(&base->chan, 4))) {
1220 evo_mthd(push, 0x0084, 1);
1221 evo_data(push, 0x00000000);
1222 evo_mthd(push, 0x00c0, 1);
1223 evo_data(push, 0x00000000);
1224 evo_kick(push, &base->chan);
1225 }
1226}
1227
1228static void
1229nv50_base_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
1230{
1231 struct nv50_base *base = nv50_base(wndw);
1232 const s32 oclass = base->chan.base.base.user.oclass;
1233 u32 *push;
1234 if ((push = evo_wait(&base->chan, 10))) {
1235 evo_mthd(push, 0x0084, 1);
1236 evo_data(push, (asyw->image.mode << 8) |
1237 (asyw->image.interval << 4));
1238 evo_mthd(push, 0x00c0, 1);
1239 evo_data(push, asyw->image.handle);
1240 if (oclass < G82_DISP_BASE_CHANNEL_DMA) {
1241 evo_mthd(push, 0x0800, 5);
1242 evo_data(push, asyw->image.offset >> 8);
1243 evo_data(push, 0x00000000);
1244 evo_data(push, (asyw->image.h << 16) | asyw->image.w);
1245 evo_data(push, (asyw->image.layout << 20) |
1246 asyw->image.pitch |
1247 asyw->image.block);
1248 evo_data(push, (asyw->image.kind << 16) |
1249 (asyw->image.format << 8));
1250 } else
1251 if (oclass < GF110_DISP_BASE_CHANNEL_DMA) {
1252 evo_mthd(push, 0x0800, 5);
1253 evo_data(push, asyw->image.offset >> 8);
1254 evo_data(push, 0x00000000);
1255 evo_data(push, (asyw->image.h << 16) | asyw->image.w);
1256 evo_data(push, (asyw->image.layout << 20) |
1257 asyw->image.pitch |
1258 asyw->image.block);
1259 evo_data(push, asyw->image.format << 8);
1260 } else {
1261 evo_mthd(push, 0x0400, 5);
1262 evo_data(push, asyw->image.offset >> 8);
1263 evo_data(push, 0x00000000);
1264 evo_data(push, (asyw->image.h << 16) | asyw->image.w);
1265 evo_data(push, (asyw->image.layout << 24) |
1266 asyw->image.pitch |
1267 asyw->image.block);
1268 evo_data(push, asyw->image.format << 8);
1269 }
1270 evo_kick(push, &base->chan);
1271 }
1272}
1273
1274static void
1275nv50_base_ntfy_clr(struct nv50_wndw *wndw)
1276{
1277 struct nv50_base *base = nv50_base(wndw);
1278 u32 *push;
1279 if ((push = evo_wait(&base->chan, 2))) {
1280 evo_mthd(push, 0x00a4, 1);
1281 evo_data(push, 0x00000000);
1282 evo_kick(push, &base->chan);
1283 }
1284}
1285
1286static void
1287nv50_base_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
1288{
1289 struct nv50_base *base = nv50_base(wndw);
1290 u32 *push;
1291 if ((push = evo_wait(&base->chan, 3))) {
1292 evo_mthd(push, 0x00a0, 2);
1293 evo_data(push, (asyw->ntfy.awaken << 30) | asyw->ntfy.offset);
1294 evo_data(push, asyw->ntfy.handle);
1295 evo_kick(push, &base->chan);
1296 }
1297}
1298
1299static void
1300nv50_base_sema_clr(struct nv50_wndw *wndw)
1301{
1302 struct nv50_base *base = nv50_base(wndw);
1303 u32 *push;
1304 if ((push = evo_wait(&base->chan, 2))) {
1305 evo_mthd(push, 0x0094, 1);
1306 evo_data(push, 0x00000000);
1307 evo_kick(push, &base->chan);
1308 }
1309}
1310
1311static void
1312nv50_base_sema_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
1313{
1314 struct nv50_base *base = nv50_base(wndw);
1315 u32 *push;
1316 if ((push = evo_wait(&base->chan, 5))) {
1317 evo_mthd(push, 0x0088, 4);
1318 evo_data(push, asyw->sema.offset);
1319 evo_data(push, asyw->sema.acquire);
1320 evo_data(push, asyw->sema.release);
1321 evo_data(push, asyw->sema.handle);
1322 evo_kick(push, &base->chan);
1323 }
1324}
1325
1326static u32
1327nv50_base_update(struct nv50_wndw *wndw, u32 interlock)
1328{
1329 struct nv50_base *base = nv50_base(wndw);
1330 u32 *push;
1331
1332 if (!(push = evo_wait(&base->chan, 2)))
1333 return 0;
1334 evo_mthd(push, 0x0080, 1);
1335 evo_data(push, interlock);
1336 evo_kick(push, &base->chan);
1337
1338 if (base->chan.base.base.user.oclass < GF110_DISP_BASE_CHANNEL_DMA)
1339 return interlock ? 2 << (base->id * 8) : 0;
1340 return interlock ? 2 << (base->id * 4) : 0;
1341}
1342
1343static int
1344nv50_base_ntfy_wait_begun(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
1345{
1346 struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev);
1347 struct nv50_disp *disp = nv50_disp(wndw->plane.dev);
1348 if (nvif_msec(&drm->device, 2000ULL,
1349 u32 data = nouveau_bo_rd32(disp->sync, asyw->ntfy.offset / 4);
1350 if ((data & 0xc0000000) == 0x40000000)
1351 break;
1352 usleep_range(1, 2);
1353 ) < 0)
1354 return -ETIMEDOUT;
1355 return 0;
1356}
1357
1358static void
1359nv50_base_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
1360 struct nv50_head_atom *asyh)
1361{
1362 asyh->base.cpp = 0;
1363}
1364
1365static int
1366nv50_base_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
1367 struct nv50_head_atom *asyh)
1368{
1369 const u32 format = asyw->state.fb->pixel_format;
1370 const struct drm_format_info *info;
1371 int ret;
1372
1373 info = drm_format_info(format);
1374 if (!info || !info->depth)
1375 return -EINVAL;
1376
1377 ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip,
1378 DRM_PLANE_HELPER_NO_SCALING,
1379 DRM_PLANE_HELPER_NO_SCALING,
1380 false, true);
1381 if (ret)
1382 return ret;
1383
1384 asyh->base.depth = info->depth;
1385 asyh->base.cpp = info->cpp[0];
1386 asyh->base.x = asyw->state.src.x1 >> 16;
1387 asyh->base.y = asyw->state.src.y1 >> 16;
1388 asyh->base.w = asyw->state.fb->width;
1389 asyh->base.h = asyw->state.fb->height;
1390
1391 switch (format) {
1392 case DRM_FORMAT_C8 : asyw->image.format = 0x1e; break;
1393 case DRM_FORMAT_RGB565 : asyw->image.format = 0xe8; break;
1394 case DRM_FORMAT_XRGB1555 :
1395 case DRM_FORMAT_ARGB1555 : asyw->image.format = 0xe9; break;
1396 case DRM_FORMAT_XRGB8888 :
1397 case DRM_FORMAT_ARGB8888 : asyw->image.format = 0xcf; break;
1398 case DRM_FORMAT_XBGR2101010:
1399 case DRM_FORMAT_ABGR2101010: asyw->image.format = 0xd1; break;
1400 case DRM_FORMAT_XBGR8888 :
1401 case DRM_FORMAT_ABGR8888 : asyw->image.format = 0xd5; break;
1402 default:
1403 WARN_ON(1);
1404 return -EINVAL;
1405 }
1406
1407 asyw->lut.enable = 1;
1408 asyw->set.image = true;
1409 return 0;
1410}
1411
1412static void *
1413nv50_base_dtor(struct nv50_wndw *wndw)
1414{
1415 struct nv50_disp *disp = nv50_disp(wndw->plane.dev);
1416 struct nv50_base *base = nv50_base(wndw);
1417 nv50_dmac_destroy(&base->chan.base, disp->disp);
1418 return base;
1419}
1420
1421static const u32
1422nv50_base_format[] = {
1423 DRM_FORMAT_C8,
1424 DRM_FORMAT_RGB565,
1425 DRM_FORMAT_XRGB1555,
1426 DRM_FORMAT_ARGB1555,
1427 DRM_FORMAT_XRGB8888,
1428 DRM_FORMAT_ARGB8888,
1429 DRM_FORMAT_XBGR2101010,
1430 DRM_FORMAT_ABGR2101010,
1431 DRM_FORMAT_XBGR8888,
1432 DRM_FORMAT_ABGR8888,
1433};
1434
1435static const struct nv50_wndw_func
1436nv50_base = {
1437 .dtor = nv50_base_dtor,
1438 .acquire = nv50_base_acquire,
1439 .release = nv50_base_release,
1440 .sema_set = nv50_base_sema_set,
1441 .sema_clr = nv50_base_sema_clr,
1442 .ntfy_set = nv50_base_ntfy_set,
1443 .ntfy_clr = nv50_base_ntfy_clr,
1444 .ntfy_wait_begun = nv50_base_ntfy_wait_begun,
1445 .image_set = nv50_base_image_set,
1446 .image_clr = nv50_base_image_clr,
1447 .lut = nv50_base_lut,
1448 .update = nv50_base_update,
1449};
1450
1451static int
1452nv50_base_new(struct nouveau_drm *drm, struct nv50_head *head,
1453 struct nv50_base **pbase)
1454{
1455 struct nv50_disp *disp = nv50_disp(drm->dev);
1456 struct nv50_base *base;
1457 int ret;
1458
1459 if (!(base = *pbase = kzalloc(sizeof(*base), GFP_KERNEL)))
1460 return -ENOMEM;
1461 base->id = head->base.index;
1462 base->wndw.ntfy = EVO_FLIP_NTFY0(base->id);
1463 base->wndw.sema = EVO_FLIP_SEM0(base->id);
1464 base->wndw.data = 0x00000000;
1465
1466 ret = nv50_wndw_ctor(&nv50_base, drm->dev, DRM_PLANE_TYPE_PRIMARY,
1467 "base", base->id, &base->chan.base,
1468 nv50_base_format, ARRAY_SIZE(nv50_base_format),
1469 &base->wndw);
1470 if (ret) {
1471 kfree(base);
1472 return ret;
1473 }
1474
1475 ret = nv50_base_create(&drm->device, disp->disp, base->id,
1476 disp->sync->bo.offset, &base->chan);
1477 if (ret)
1478 return ret;
1479
1480 return nvif_notify_init(&base->chan.base.base.user, nv50_base_notify,
1481 false,
1482 NV50_DISP_BASE_CHANNEL_DMA_V0_NTFY_UEVENT,
1483 &(struct nvif_notify_uevent_req) {},
1484 sizeof(struct nvif_notify_uevent_req),
1485 sizeof(struct nvif_notify_uevent_rep),
1486 &base->wndw.notify);
1487}
1488
1489/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +10001490 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +10001491 *****************************************************************************/
1492struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +10001493nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +10001494{
Ben Skeggse225f442012-11-21 14:40:21 +10001495 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +10001496}
1497
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001498struct nv50_display_flip {
1499 struct nv50_disp *disp;
Ben Skeggs973f10c2016-11-04 17:20:36 +10001500 struct nv50_base *base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001501};
1502
1503static bool
1504nv50_display_flip_wait(void *data)
1505{
1506 struct nv50_display_flip *flip = data;
Ben Skeggs973f10c2016-11-04 17:20:36 +10001507 if (nouveau_bo_rd32(flip->disp->sync, flip->base->wndw.sema / 4) ==
1508 flip->base->wndw.data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001509 return true;
1510 usleep_range(1, 2);
1511 return false;
1512}
1513
Ben Skeggs3376ee32011-11-12 14:28:12 +10001514void
Ben Skeggse225f442012-11-21 14:40:21 +10001515nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +10001516{
Ben Skeggs967e7bd2014-08-10 04:10:22 +10001517 struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
Ben Skeggs973f10c2016-11-04 17:20:36 +10001518 struct nv50_base *base = nv50_head(crtc)->_base;
1519 struct nv50_wndw *wndw = &base->wndw;
1520 struct nv50_wndw_atom *asyw = &wndw->asy;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001521 struct nv50_display_flip flip = {
1522 .disp = nv50_disp(crtc->dev),
Ben Skeggs973f10c2016-11-04 17:20:36 +10001523 .base = base,
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001524 };
Ben Skeggs3376ee32011-11-12 14:28:12 +10001525
Ben Skeggs973f10c2016-11-04 17:20:36 +10001526 asyw->state.crtc = NULL;
1527 asyw->state.fb = NULL;
1528 nv50_wndw_atomic_check(&wndw->plane, &asyw->state);
1529 nv50_wndw_flush_clr(wndw, 0, true, asyw);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001530
Ben Skeggs54442042015-08-20 14:54:11 +10001531 nvif_msec(device, 2000,
1532 if (nv50_display_flip_wait(&flip))
1533 break;
1534 );
Ben Skeggs3376ee32011-11-12 14:28:12 +10001535}
1536
1537int
Ben Skeggse225f442012-11-21 14:40:21 +10001538nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001539 struct nouveau_channel *chan, u32 swap_interval)
1540{
1541 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001542 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001543 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs973f10c2016-11-04 17:20:36 +10001544 struct nv50_base *base = nv50_head(crtc)->_base;
1545 struct nv50_wndw *wndw = &base->wndw;
1546 struct nv50_wndw_atom *asyw = &wndw->asy;
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001547 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +10001548
Ben Skeggs9ba83102014-12-22 19:50:23 +10001549 if (crtc->primary->fb->width != fb->width ||
1550 crtc->primary->fb->height != fb->height)
1551 return -EINVAL;
1552
Ben Skeggsf60b6e72013-03-19 15:20:00 +10001553 if (chan == NULL)
1554 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001555
Ben Skeggsa01ca782015-08-20 14:54:15 +10001556 if (chan && chan->user.oclass < G82_CHANNEL_GPFIFO) {
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001557 ret = RING_SPACE(chan, 8);
1558 if (ret)
1559 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +10001560
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001561 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001562 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs973f10c2016-11-04 17:20:36 +10001563 OUT_RING (chan, base->wndw.sema ^ 0x10);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001564 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
Ben Skeggs973f10c2016-11-04 17:20:36 +10001565 OUT_RING (chan, base->wndw.data + 1);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001566 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
Ben Skeggs973f10c2016-11-04 17:20:36 +10001567 OUT_RING (chan, base->wndw.sema);
1568 OUT_RING (chan, base->wndw.data);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001569 } else
Ben Skeggsa01ca782015-08-20 14:54:15 +10001570 if (chan && chan->user.oclass < FERMI_CHANNEL_GPFIFO) {
Ben Skeggs973f10c2016-11-04 17:20:36 +10001571 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + base->wndw.sema;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001572 ret = RING_SPACE(chan, 12);
1573 if (ret)
1574 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +10001575
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001576 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001577 OUT_RING (chan, chan->vram.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001578 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
1579 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
1580 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
Ben Skeggs973f10c2016-11-04 17:20:36 +10001581 OUT_RING (chan, base->wndw.data + 1);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001582 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
1583 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
1584 OUT_RING (chan, upper_32_bits(addr));
1585 OUT_RING (chan, lower_32_bits(addr));
Ben Skeggs973f10c2016-11-04 17:20:36 +10001586 OUT_RING (chan, base->wndw.data);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001587 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
1588 } else
1589 if (chan) {
Ben Skeggs973f10c2016-11-04 17:20:36 +10001590 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + base->wndw.sema;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001591 ret = RING_SPACE(chan, 10);
1592 if (ret)
1593 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +10001594
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001595 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
1596 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
1597 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
Ben Skeggs973f10c2016-11-04 17:20:36 +10001598 OUT_RING (chan, base->wndw.data + 1);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001599 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
1600 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
1601 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
1602 OUT_RING (chan, upper_32_bits(addr));
1603 OUT_RING (chan, lower_32_bits(addr));
Ben Skeggs973f10c2016-11-04 17:20:36 +10001604 OUT_RING (chan, base->wndw.data);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001605 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
1606 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
1607 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -05001608
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001609 if (chan) {
Ben Skeggs973f10c2016-11-04 17:20:36 +10001610 base->wndw.sema ^= 0x10;
1611 base->wndw.data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +10001612 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001613 }
1614
1615 /* queue the flip */
Ben Skeggs973f10c2016-11-04 17:20:36 +10001616 asyw->state.crtc = &head->base.base;
1617 asyw->state.fb = fb;
1618 asyw->interval = swap_interval;
1619 asyw->image.handle = nv_fb->r_handle;
1620 asyw->image.offset = nv_fb->nvbo->bo.offset;
1621 asyw->sema.handle = base->chan.base.sync.handle;
1622 asyw->sema.offset = base->wndw.sema;
1623 asyw->sema.acquire = base->wndw.data++;
1624 asyw->sema.release = base->wndw.data;
1625 nv50_wndw_atomic_check(&wndw->plane, &asyw->state);
1626 asyw->set.sema = true;
1627 nv50_wndw_flush_set(wndw, 0, asyw);
1628 nv50_wndw_wait_armed(wndw, asyw);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001629
1630 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001631 return 0;
1632}
1633
Ben Skeggs26f6d882011-07-04 16:25:18 +10001634/******************************************************************************
Ben Skeggs3dbd0362016-11-04 17:20:36 +10001635 * Head
1636 *****************************************************************************/
Ben Skeggs3dbd0362016-11-04 17:20:36 +10001637static void
Ben Skeggs7e08d672016-11-04 17:20:36 +10001638nv50_head_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
1639{
1640 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1641 u32 *push;
1642 if ((push = evo_wait(core, 2))) {
1643 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA)
1644 evo_mthd(push, 0x08a8 + (head->base.index * 0x400), 1);
1645 else
1646 evo_mthd(push, 0x0498 + (head->base.index * 0x300), 1);
1647 evo_data(push, (asyh->procamp.sat.sin << 20) |
1648 (asyh->procamp.sat.cos << 8));
1649 evo_kick(push, core);
1650 }
1651}
1652
1653static void
Ben Skeggs7e918332016-11-04 17:20:36 +10001654nv50_head_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
1655{
1656 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1657 u32 *push;
1658 if ((push = evo_wait(core, 2))) {
1659 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA)
1660 evo_mthd(push, 0x08a0 + (head->base.index * 0x0400), 1);
1661 else
1662 if (core->base.user.oclass < GK104_DISP_CORE_CHANNEL_DMA)
1663 evo_mthd(push, 0x0490 + (head->base.index * 0x0300), 1);
1664 else
1665 evo_mthd(push, 0x04a0 + (head->base.index * 0x0300), 1);
1666 evo_data(push, (asyh->dither.mode << 3) |
1667 (asyh->dither.bits << 1) |
1668 asyh->dither.enable);
1669 evo_kick(push, core);
1670 }
1671}
1672
1673static void
Ben Skeggs6bbab3b2016-11-04 17:20:36 +10001674nv50_head_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
1675{
1676 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1677 u32 bounds = 0;
1678 u32 *push;
1679
1680 if (asyh->base.cpp) {
1681 switch (asyh->base.cpp) {
1682 case 8: bounds |= 0x00000500; break;
1683 case 4: bounds |= 0x00000300; break;
1684 case 2: bounds |= 0x00000100; break;
1685 default:
1686 WARN_ON(1);
1687 break;
1688 }
1689 bounds |= 0x00000001;
1690 }
1691
1692 if ((push = evo_wait(core, 2))) {
1693 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA)
1694 evo_mthd(push, 0x0904 + head->base.index * 0x400, 1);
1695 else
1696 evo_mthd(push, 0x04d4 + head->base.index * 0x300, 1);
1697 evo_data(push, bounds);
1698 evo_kick(push, core);
1699 }
1700}
1701
1702static void
1703nv50_head_base(struct nv50_head *head, struct nv50_head_atom *asyh)
1704{
1705 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1706 u32 bounds = 0;
1707 u32 *push;
1708
1709 if (asyh->base.cpp) {
1710 switch (asyh->base.cpp) {
1711 case 8: bounds |= 0x00000500; break;
1712 case 4: bounds |= 0x00000300; break;
1713 case 2: bounds |= 0x00000100; break;
1714 case 1: bounds |= 0x00000000; break;
1715 default:
1716 WARN_ON(1);
1717 break;
1718 }
1719 bounds |= 0x00000001;
1720 }
1721
1722 if ((push = evo_wait(core, 2))) {
1723 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA)
1724 evo_mthd(push, 0x0900 + head->base.index * 0x400, 1);
1725 else
1726 evo_mthd(push, 0x04d0 + head->base.index * 0x300, 1);
1727 evo_data(push, bounds);
1728 evo_kick(push, core);
1729 }
1730}
1731
1732static void
Ben Skeggsea8ee392016-11-04 17:20:36 +10001733nv50_head_curs_clr(struct nv50_head *head)
1734{
1735 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1736 u32 *push;
1737 if ((push = evo_wait(core, 4))) {
1738 if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) {
1739 evo_mthd(push, 0x0880 + head->base.index * 0x400, 1);
1740 evo_data(push, 0x05000000);
1741 } else
1742 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
1743 evo_mthd(push, 0x0880 + head->base.index * 0x400, 1);
1744 evo_data(push, 0x05000000);
1745 evo_mthd(push, 0x089c + head->base.index * 0x400, 1);
1746 evo_data(push, 0x00000000);
1747 } else {
1748 evo_mthd(push, 0x0480 + head->base.index * 0x300, 1);
1749 evo_data(push, 0x05000000);
1750 evo_mthd(push, 0x048c + head->base.index * 0x300, 1);
1751 evo_data(push, 0x00000000);
1752 }
1753 evo_kick(push, core);
1754 }
1755}
1756
1757static void
1758nv50_head_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
1759{
1760 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1761 u32 *push;
1762 if ((push = evo_wait(core, 5))) {
1763 if (core->base.user.oclass < G82_DISP_BASE_CHANNEL_DMA) {
1764 evo_mthd(push, 0x0880 + head->base.index * 0x400, 2);
1765 evo_data(push, 0x80000000 | (asyh->curs.layout << 26) |
1766 (asyh->curs.format << 24));
1767 evo_data(push, asyh->curs.offset >> 8);
1768 } else
1769 if (core->base.user.oclass < GF110_DISP_BASE_CHANNEL_DMA) {
1770 evo_mthd(push, 0x0880 + head->base.index * 0x400, 2);
1771 evo_data(push, 0x80000000 | (asyh->curs.layout << 26) |
1772 (asyh->curs.format << 24));
1773 evo_data(push, asyh->curs.offset >> 8);
1774 evo_mthd(push, 0x089c + head->base.index * 0x400, 1);
1775 evo_data(push, asyh->curs.handle);
1776 } else {
1777 evo_mthd(push, 0x0480 + head->base.index * 0x300, 2);
1778 evo_data(push, 0x80000000 | (asyh->curs.layout << 26) |
1779 (asyh->curs.format << 24));
1780 evo_data(push, asyh->curs.offset >> 8);
1781 evo_mthd(push, 0x048c + head->base.index * 0x300, 1);
1782 evo_data(push, asyh->curs.handle);
1783 }
1784 evo_kick(push, core);
1785 }
1786}
1787
1788static void
Ben Skeggsad633612016-11-04 17:20:36 +10001789nv50_head_core_clr(struct nv50_head *head)
1790{
1791 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1792 u32 *push;
1793 if ((push = evo_wait(core, 2))) {
1794 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA)
1795 evo_mthd(push, 0x0874 + head->base.index * 0x400, 1);
1796 else
1797 evo_mthd(push, 0x0474 + head->base.index * 0x300, 1);
1798 evo_data(push, 0x00000000);
1799 evo_kick(push, core);
1800 }
1801}
1802
1803static void
1804nv50_head_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
1805{
1806 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1807 u32 *push;
1808 if ((push = evo_wait(core, 9))) {
1809 if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) {
1810 evo_mthd(push, 0x0860 + head->base.index * 0x400, 1);
1811 evo_data(push, asyh->core.offset >> 8);
1812 evo_mthd(push, 0x0868 + head->base.index * 0x400, 4);
1813 evo_data(push, (asyh->core.h << 16) | asyh->core.w);
1814 evo_data(push, asyh->core.layout << 20 |
1815 (asyh->core.pitch >> 8) << 8 |
1816 asyh->core.block);
1817 evo_data(push, asyh->core.kind << 16 |
1818 asyh->core.format << 8);
1819 evo_data(push, asyh->core.handle);
1820 evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1);
1821 evo_data(push, (asyh->core.y << 16) | asyh->core.x);
1822 } else
1823 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
1824 evo_mthd(push, 0x0860 + head->base.index * 0x400, 1);
1825 evo_data(push, asyh->core.offset >> 8);
1826 evo_mthd(push, 0x0868 + head->base.index * 0x400, 4);
1827 evo_data(push, (asyh->core.h << 16) | asyh->core.w);
1828 evo_data(push, asyh->core.layout << 20 |
1829 (asyh->core.pitch >> 8) << 8 |
1830 asyh->core.block);
1831 evo_data(push, asyh->core.format << 8);
1832 evo_data(push, asyh->core.handle);
1833 evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1);
1834 evo_data(push, (asyh->core.y << 16) | asyh->core.x);
1835 } else {
1836 evo_mthd(push, 0x0460 + head->base.index * 0x300, 1);
1837 evo_data(push, asyh->core.offset >> 8);
1838 evo_mthd(push, 0x0468 + head->base.index * 0x300, 4);
1839 evo_data(push, (asyh->core.h << 16) | asyh->core.w);
1840 evo_data(push, asyh->core.layout << 24 |
1841 (asyh->core.pitch >> 8) << 8 |
1842 asyh->core.block);
1843 evo_data(push, asyh->core.format << 8);
1844 evo_data(push, asyh->core.handle);
1845 evo_mthd(push, 0x04b0 + head->base.index * 0x300, 1);
1846 evo_data(push, (asyh->core.y << 16) | asyh->core.x);
1847 }
1848 evo_kick(push, core);
1849 }
1850}
1851
1852static void
Ben Skeggsa7ae1562016-11-04 17:20:36 +10001853nv50_head_lut_clr(struct nv50_head *head)
1854{
1855 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1856 u32 *push;
1857 if ((push = evo_wait(core, 4))) {
1858 if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) {
1859 evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1);
1860 evo_data(push, 0x40000000);
1861 } else
1862 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
1863 evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1);
1864 evo_data(push, 0x40000000);
1865 evo_mthd(push, 0x085c + (head->base.index * 0x400), 1);
1866 evo_data(push, 0x00000000);
1867 } else {
1868 evo_mthd(push, 0x0440 + (head->base.index * 0x300), 1);
1869 evo_data(push, 0x03000000);
1870 evo_mthd(push, 0x045c + (head->base.index * 0x300), 1);
1871 evo_data(push, 0x00000000);
1872 }
1873 evo_kick(push, core);
1874 }
1875}
1876
1877static void
1878nv50_head_lut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
1879{
1880 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1881 u32 *push;
1882 if ((push = evo_wait(core, 7))) {
1883 if (core->base.user.oclass < G82_DISP_CORE_CHANNEL_DMA) {
1884 evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2);
1885 evo_data(push, 0xc0000000);
1886 evo_data(push, asyh->lut.offset >> 8);
1887 } else
1888 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
1889 evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2);
1890 evo_data(push, 0xc0000000);
1891 evo_data(push, asyh->lut.offset >> 8);
1892 evo_mthd(push, 0x085c + (head->base.index * 0x400), 1);
1893 evo_data(push, asyh->lut.handle);
1894 } else {
1895 evo_mthd(push, 0x0440 + (head->base.index * 0x300), 4);
1896 evo_data(push, 0x83000000);
1897 evo_data(push, asyh->lut.offset >> 8);
1898 evo_data(push, 0x00000000);
1899 evo_data(push, 0x00000000);
1900 evo_mthd(push, 0x045c + (head->base.index * 0x300), 1);
1901 evo_data(push, asyh->lut.handle);
1902 }
1903 evo_kick(push, core);
1904 }
1905}
1906
1907static void
Ben Skeggs3dbd0362016-11-04 17:20:36 +10001908nv50_head_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
1909{
1910 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1911 struct nv50_head_mode *m = &asyh->mode;
1912 u32 *push;
1913 if ((push = evo_wait(core, 14))) {
1914 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
1915 evo_mthd(push, 0x0804 + (head->base.index * 0x400), 2);
1916 evo_data(push, 0x00800000 | m->clock);
1917 evo_data(push, m->interlace ? 0x00000002 : 0x00000000);
Ben Skeggs06ab2822016-11-04 17:20:36 +10001918 evo_mthd(push, 0x0810 + (head->base.index * 0x400), 7);
Ben Skeggs3dbd0362016-11-04 17:20:36 +10001919 evo_data(push, 0x00000000);
1920 evo_data(push, (m->v.active << 16) | m->h.active );
1921 evo_data(push, (m->v.synce << 16) | m->h.synce );
1922 evo_data(push, (m->v.blanke << 16) | m->h.blanke );
1923 evo_data(push, (m->v.blanks << 16) | m->h.blanks );
1924 evo_data(push, (m->v.blank2e << 16) | m->v.blank2s);
Ben Skeggs06ab2822016-11-04 17:20:36 +10001925 evo_data(push, asyh->mode.v.blankus);
Ben Skeggs3dbd0362016-11-04 17:20:36 +10001926 evo_mthd(push, 0x082c + (head->base.index * 0x400), 1);
1927 evo_data(push, 0x00000000);
1928 } else {
1929 evo_mthd(push, 0x0410 + (head->base.index * 0x300), 6);
1930 evo_data(push, 0x00000000);
1931 evo_data(push, (m->v.active << 16) | m->h.active );
1932 evo_data(push, (m->v.synce << 16) | m->h.synce );
1933 evo_data(push, (m->v.blanke << 16) | m->h.blanke );
1934 evo_data(push, (m->v.blanks << 16) | m->h.blanks );
1935 evo_data(push, (m->v.blank2e << 16) | m->v.blank2s);
1936 evo_mthd(push, 0x042c + (head->base.index * 0x300), 2);
1937 evo_data(push, 0x00000000); /* ??? */
1938 evo_data(push, 0xffffff00);
1939 evo_mthd(push, 0x0450 + (head->base.index * 0x300), 3);
1940 evo_data(push, m->clock * 1000);
1941 evo_data(push, 0x00200000); /* ??? */
1942 evo_data(push, m->clock * 1000);
1943 }
1944 evo_kick(push, core);
1945 }
1946}
1947
1948static void
Ben Skeggsc4e68122016-11-04 17:20:36 +10001949nv50_head_view(struct nv50_head *head, struct nv50_head_atom *asyh)
1950{
1951 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->mast.base;
1952 u32 *push;
1953 if ((push = evo_wait(core, 10))) {
1954 if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
1955 evo_mthd(push, 0x08a4 + (head->base.index * 0x400), 1);
1956 evo_data(push, 0x00000000);
1957 evo_mthd(push, 0x08c8 + (head->base.index * 0x400), 1);
1958 evo_data(push, (asyh->view.iH << 16) | asyh->view.iW);
1959 evo_mthd(push, 0x08d8 + (head->base.index * 0x400), 2);
1960 evo_data(push, (asyh->view.oH << 16) | asyh->view.oW);
1961 evo_data(push, (asyh->view.oH << 16) | asyh->view.oW);
1962 } else {
1963 evo_mthd(push, 0x0494 + (head->base.index * 0x300), 1);
1964 evo_data(push, 0x00000000);
1965 evo_mthd(push, 0x04b8 + (head->base.index * 0x300), 1);
1966 evo_data(push, (asyh->view.iH << 16) | asyh->view.iW);
1967 evo_mthd(push, 0x04c0 + (head->base.index * 0x300), 3);
1968 evo_data(push, (asyh->view.oH << 16) | asyh->view.oW);
1969 evo_data(push, (asyh->view.oH << 16) | asyh->view.oW);
1970 evo_data(push, (asyh->view.oH << 16) | asyh->view.oW);
1971 }
1972 evo_kick(push, core);
1973 }
1974}
1975
1976static void
Ben Skeggsad633612016-11-04 17:20:36 +10001977nv50_head_flush_clr(struct nv50_head *head, struct nv50_head_atom *asyh, bool y)
1978{
1979 if (asyh->clr.core && (!asyh->set.core || y))
Ben Skeggsa7ae1562016-11-04 17:20:36 +10001980 nv50_head_lut_clr(head);
1981 if (asyh->clr.core && (!asyh->set.core || y))
Ben Skeggsad633612016-11-04 17:20:36 +10001982 nv50_head_core_clr(head);
Ben Skeggsea8ee392016-11-04 17:20:36 +10001983 if (asyh->clr.curs && (!asyh->set.curs || y))
1984 nv50_head_curs_clr(head);
Ben Skeggsad633612016-11-04 17:20:36 +10001985}
1986
1987static void
Ben Skeggs3dbd0362016-11-04 17:20:36 +10001988nv50_head_flush_set(struct nv50_head *head, struct nv50_head_atom *asyh)
1989{
Ben Skeggsc4e68122016-11-04 17:20:36 +10001990 if (asyh->set.view ) nv50_head_view (head, asyh);
Ben Skeggs3dbd0362016-11-04 17:20:36 +10001991 if (asyh->set.mode ) nv50_head_mode (head, asyh);
Ben Skeggsa7ae1562016-11-04 17:20:36 +10001992 if (asyh->set.core ) nv50_head_lut_set (head, asyh);
Ben Skeggsad633612016-11-04 17:20:36 +10001993 if (asyh->set.core ) nv50_head_core_set(head, asyh);
Ben Skeggsea8ee392016-11-04 17:20:36 +10001994 if (asyh->set.curs ) nv50_head_curs_set(head, asyh);
Ben Skeggs6bbab3b2016-11-04 17:20:36 +10001995 if (asyh->set.base ) nv50_head_base (head, asyh);
1996 if (asyh->set.ovly ) nv50_head_ovly (head, asyh);
Ben Skeggs7e918332016-11-04 17:20:36 +10001997 if (asyh->set.dither ) nv50_head_dither (head, asyh);
Ben Skeggs7e08d672016-11-04 17:20:36 +10001998 if (asyh->set.procamp) nv50_head_procamp (head, asyh);
1999}
2000
2001static void
2002nv50_head_atomic_check_procamp(struct nv50_head_atom *armh,
2003 struct nv50_head_atom *asyh,
2004 struct nouveau_conn_atom *asyc)
2005{
2006 const int vib = asyc->procamp.color_vibrance - 100;
2007 const int hue = asyc->procamp.vibrant_hue - 90;
2008 const int adj = (vib > 0) ? 50 : 0;
2009 asyh->procamp.sat.cos = ((vib * 2047 + adj) / 100) & 0xfff;
2010 asyh->procamp.sat.sin = ((hue * 2047) / 100) & 0xfff;
2011 asyh->set.procamp = true;
Ben Skeggs7e918332016-11-04 17:20:36 +10002012}
2013
2014static void
2015nv50_head_atomic_check_dither(struct nv50_head_atom *armh,
2016 struct nv50_head_atom *asyh,
2017 struct nouveau_conn_atom *asyc)
2018{
2019 struct drm_connector *connector = asyc->state.connector;
2020 u32 mode = 0x00;
2021
2022 if (asyc->dither.mode == DITHERING_MODE_AUTO) {
2023 if (asyh->base.depth > connector->display_info.bpc * 3)
2024 mode = DITHERING_MODE_DYNAMIC2X2;
2025 } else {
2026 mode = asyc->dither.mode;
2027 }
2028
2029 if (asyc->dither.depth == DITHERING_DEPTH_AUTO) {
2030 if (connector->display_info.bpc >= 8)
2031 mode |= DITHERING_DEPTH_8BPC;
2032 } else {
2033 mode |= asyc->dither.depth;
2034 }
2035
2036 asyh->dither.enable = mode;
2037 asyh->dither.bits = mode >> 1;
2038 asyh->dither.mode = mode >> 3;
2039 asyh->set.dither = true;
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002040}
2041
2042static void
Ben Skeggsc4e68122016-11-04 17:20:36 +10002043nv50_head_atomic_check_view(struct nv50_head_atom *armh,
2044 struct nv50_head_atom *asyh,
2045 struct nouveau_conn_atom *asyc)
2046{
2047 struct drm_connector *connector = asyc->state.connector;
2048 struct drm_display_mode *omode = &asyh->state.adjusted_mode;
2049 struct drm_display_mode *umode = &asyh->state.mode;
2050 int mode = asyc->scaler.mode;
2051 struct edid *edid;
2052
2053 if (connector->edid_blob_ptr)
2054 edid = (struct edid *)connector->edid_blob_ptr->data;
2055 else
2056 edid = NULL;
2057
2058 if (!asyc->scaler.full) {
2059 if (mode == DRM_MODE_SCALE_NONE)
2060 omode = umode;
2061 } else {
2062 /* Non-EDID LVDS/eDP mode. */
2063 mode = DRM_MODE_SCALE_FULLSCREEN;
2064 }
2065
2066 asyh->view.iW = umode->hdisplay;
2067 asyh->view.iH = umode->vdisplay;
2068 asyh->view.oW = omode->hdisplay;
2069 asyh->view.oH = omode->vdisplay;
2070 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
2071 asyh->view.oH *= 2;
2072
2073 /* Add overscan compensation if necessary, will keep the aspect
2074 * ratio the same as the backend mode unless overridden by the
2075 * user setting both hborder and vborder properties.
2076 */
2077 if ((asyc->scaler.underscan.mode == UNDERSCAN_ON ||
2078 (asyc->scaler.underscan.mode == UNDERSCAN_AUTO &&
2079 drm_detect_hdmi_monitor(edid)))) {
2080 u32 bX = asyc->scaler.underscan.hborder;
2081 u32 bY = asyc->scaler.underscan.vborder;
2082 u32 r = (asyh->view.oH << 19) / asyh->view.oW;
2083
2084 if (bX) {
2085 asyh->view.oW -= (bX * 2);
2086 if (bY) asyh->view.oH -= (bY * 2);
2087 else asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19;
2088 } else {
2089 asyh->view.oW -= (asyh->view.oW >> 4) + 32;
2090 if (bY) asyh->view.oH -= (bY * 2);
2091 else asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19;
2092 }
2093 }
2094
2095 /* Handle CENTER/ASPECT scaling, taking into account the areas
2096 * removed already for overscan compensation.
2097 */
2098 switch (mode) {
2099 case DRM_MODE_SCALE_CENTER:
2100 asyh->view.oW = min((u16)umode->hdisplay, asyh->view.oW);
2101 asyh->view.oH = min((u16)umode->vdisplay, asyh->view.oH);
2102 /* fall-through */
2103 case DRM_MODE_SCALE_ASPECT:
2104 if (asyh->view.oH < asyh->view.oW) {
2105 u32 r = (asyh->view.iW << 19) / asyh->view.iH;
2106 asyh->view.oW = ((asyh->view.oH * r) + (r / 2)) >> 19;
2107 } else {
2108 u32 r = (asyh->view.iH << 19) / asyh->view.iW;
2109 asyh->view.oH = ((asyh->view.oW * r) + (r / 2)) >> 19;
2110 }
2111 break;
2112 default:
2113 break;
2114 }
2115
2116 asyh->set.view = true;
2117}
2118
2119static void
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002120nv50_head_atomic_check_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
2121{
2122 struct drm_display_mode *mode = &asyh->state.adjusted_mode;
2123 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
2124 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
2125 u32 hbackp = mode->htotal - mode->hsync_end;
2126 u32 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
2127 u32 hfrontp = mode->hsync_start - mode->hdisplay;
2128 u32 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
2129 struct nv50_head_mode *m = &asyh->mode;
2130
2131 m->h.active = mode->htotal;
2132 m->h.synce = mode->hsync_end - mode->hsync_start - 1;
2133 m->h.blanke = m->h.synce + hbackp;
2134 m->h.blanks = mode->htotal - hfrontp - 1;
2135
2136 m->v.active = mode->vtotal * vscan / ilace;
2137 m->v.synce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
2138 m->v.blanke = m->v.synce + vbackp;
2139 m->v.blanks = m->v.active - vfrontp - 1;
2140
2141 /*XXX: Safe underestimate, even "0" works */
2142 m->v.blankus = (m->v.active - mode->vdisplay - 2) * m->h.active;
2143 m->v.blankus *= 1000;
2144 m->v.blankus /= mode->clock;
2145
2146 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
2147 m->v.blank2e = m->v.active + m->v.synce + vbackp;
2148 m->v.blank2s = m->v.blank2e + (mode->vdisplay * vscan / ilace);
2149 m->v.active = (m->v.active * 2) + 1;
2150 m->interlace = true;
2151 } else {
2152 m->v.blank2e = 0;
2153 m->v.blank2s = 1;
2154 m->interlace = false;
2155 }
2156 m->clock = mode->clock;
2157
2158 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
2159 asyh->set.mode = true;
2160}
2161
2162static int
2163nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state)
2164{
2165 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggsad633612016-11-04 17:20:36 +10002166 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002167 struct nv50_head *head = nv50_head(crtc);
2168 struct nv50_head_atom *armh = &head->arm;
2169 struct nv50_head_atom *asyh = nv50_head_atom(state);
2170
2171 NV_ATOMIC(drm, "%s atomic_check %d\n", crtc->name, asyh->state.active);
Ben Skeggsad633612016-11-04 17:20:36 +10002172 asyh->clr.mask = 0;
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002173 asyh->set.mask = 0;
2174
2175 if (asyh->state.active) {
2176 if (asyh->state.mode_changed)
2177 nv50_head_atomic_check_mode(head, asyh);
Ben Skeggsad633612016-11-04 17:20:36 +10002178
2179 if ((asyh->core.visible = (asyh->base.cpp != 0))) {
2180 asyh->core.x = asyh->base.x;
2181 asyh->core.y = asyh->base.y;
2182 asyh->core.w = asyh->base.w;
2183 asyh->core.h = asyh->base.h;
2184 } else
Ben Skeggsea8ee392016-11-04 17:20:36 +10002185 if ((asyh->core.visible = asyh->curs.visible)) {
Ben Skeggsad633612016-11-04 17:20:36 +10002186 /*XXX: We need to either find some way of having the
2187 * primary base layer appear black, while still
2188 * being able to display the other layers, or we
2189 * need to allocate a dummy black surface here.
2190 */
2191 asyh->core.x = 0;
2192 asyh->core.y = 0;
2193 asyh->core.w = asyh->state.mode.hdisplay;
2194 asyh->core.h = asyh->state.mode.vdisplay;
2195 }
2196 asyh->core.handle = disp->mast.base.vram.handle;
2197 asyh->core.offset = 0;
2198 asyh->core.format = 0xcf;
2199 asyh->core.kind = 0;
2200 asyh->core.layout = 1;
2201 asyh->core.block = 0;
2202 asyh->core.pitch = ALIGN(asyh->core.w, 64) * 4;
Ben Skeggsa7ae1562016-11-04 17:20:36 +10002203 asyh->lut.handle = disp->mast.base.vram.handle;
2204 asyh->lut.offset = head->base.lut.nvbo->bo.offset;
Ben Skeggs6bbab3b2016-11-04 17:20:36 +10002205 asyh->set.base = armh->base.cpp != asyh->base.cpp;
2206 asyh->set.ovly = armh->ovly.cpp != asyh->ovly.cpp;
Ben Skeggsad633612016-11-04 17:20:36 +10002207 } else {
2208 asyh->core.visible = false;
Ben Skeggsea8ee392016-11-04 17:20:36 +10002209 asyh->curs.visible = false;
Ben Skeggs6bbab3b2016-11-04 17:20:36 +10002210 asyh->base.cpp = 0;
2211 asyh->ovly.cpp = 0;
Ben Skeggsad633612016-11-04 17:20:36 +10002212 }
2213
2214 if (!drm_atomic_crtc_needs_modeset(&asyh->state)) {
2215 if (asyh->core.visible) {
2216 if (memcmp(&armh->core, &asyh->core, sizeof(asyh->core)))
2217 asyh->set.core = true;
2218 } else
2219 if (armh->core.visible) {
2220 asyh->clr.core = true;
2221 }
Ben Skeggsea8ee392016-11-04 17:20:36 +10002222
2223 if (asyh->curs.visible) {
2224 if (memcmp(&armh->curs, &asyh->curs, sizeof(asyh->curs)))
2225 asyh->set.curs = true;
2226 } else
2227 if (armh->curs.visible) {
2228 asyh->clr.curs = true;
2229 }
Ben Skeggsad633612016-11-04 17:20:36 +10002230 } else {
2231 asyh->clr.core = armh->core.visible;
Ben Skeggsea8ee392016-11-04 17:20:36 +10002232 asyh->clr.curs = armh->curs.visible;
Ben Skeggsad633612016-11-04 17:20:36 +10002233 asyh->set.core = asyh->core.visible;
Ben Skeggsea8ee392016-11-04 17:20:36 +10002234 asyh->set.curs = asyh->curs.visible;
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002235 }
2236
2237 memcpy(armh, asyh, sizeof(*asyh));
2238 asyh->state.mode_changed = 0;
2239 return 0;
2240}
2241
2242/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +10002243 * CRTC
2244 *****************************************************************************/
2245static int
Ben Skeggse225f442012-11-21 14:40:21 +10002246nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002247{
Ben Skeggse225f442012-11-21 14:40:21 +10002248 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs7e918332016-11-04 17:20:36 +10002249 struct nv50_head *head = nv50_head(&nv_crtc->base);
2250 struct nv50_head_atom *asyh = &head->asy;
Ben Skeggsde691852011-10-17 12:23:41 +10002251 struct nouveau_connector *nv_connector;
Ben Skeggs7e918332016-11-04 17:20:36 +10002252 struct nouveau_conn_atom asyc;
2253 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002254
Ben Skeggs488ff202011-10-17 10:38:10 +10002255 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +10002256
Ben Skeggs7e918332016-11-04 17:20:36 +10002257 asyc.state.connector = &nv_connector->base;
2258 asyc.dither.mode = nv_connector->dithering_mode;
2259 asyc.dither.depth = nv_connector->dithering_depth;
2260 asyh->state.crtc = &nv_crtc->base;
2261 nv50_head_atomic_check(&head->base.base, &asyh->state);
2262 nv50_head_atomic_check_dither(&head->arm, asyh, &asyc);
2263 nv50_head_flush_set(head, asyh);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002264
Ben Skeggs7e918332016-11-04 17:20:36 +10002265 if (update) {
2266 if ((push = evo_wait(mast, 2))) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10002267 evo_mthd(push, 0x0080, 1);
2268 evo_data(push, 0x00000000);
Ben Skeggs7e918332016-11-04 17:20:36 +10002269 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002270 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10002271 }
2272
2273 return 0;
2274}
2275
2276static int
Ben Skeggse225f442012-11-21 14:40:21 +10002277nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002278{
Ben Skeggsc4e68122016-11-04 17:20:36 +10002279 struct nv50_head *head = nv50_head(&nv_crtc->base);
2280 struct nv50_head_atom *asyh = &head->asy;
Ben Skeggs3376ee32011-11-12 14:28:12 +10002281 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +10002282 struct nouveau_connector *nv_connector;
Ben Skeggsc4e68122016-11-04 17:20:36 +10002283 struct nouveau_conn_atom asyc;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002284
Ben Skeggsf3fdc522011-07-07 16:01:57 +10002285 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsf3fdc522011-07-07 16:01:57 +10002286
Ben Skeggsc4e68122016-11-04 17:20:36 +10002287 asyc.state.connector = &nv_connector->base;
2288 asyc.scaler.mode = nv_connector->scaling_mode;
2289 asyc.scaler.full = nv_connector->scaling_full;
2290 asyc.scaler.underscan.mode = nv_connector->underscan;
2291 asyc.scaler.underscan.hborder = nv_connector->underscan_hborder;
2292 asyc.scaler.underscan.vborder = nv_connector->underscan_vborder;
2293 nv50_head_atomic_check(&head->base.base, &asyh->state);
2294 nv50_head_atomic_check_view(&head->arm, asyh, &asyc);
2295 nv50_head_flush_set(head, asyh);
Ben Skeggs92854622011-11-11 23:49:06 +10002296
Ben Skeggsc4e68122016-11-04 17:20:36 +10002297 if (update) {
2298 nv50_display_flip_stop(crtc);
2299 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002300 }
2301
2302 return 0;
2303}
2304
2305static int
Ben Skeggse225f442012-11-21 14:40:21 +10002306nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +10002307{
Ben Skeggse225f442012-11-21 14:40:21 +10002308 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs7e08d672016-11-04 17:20:36 +10002309 struct nv50_head *head = nv50_head(&nv_crtc->base);
2310 struct nv50_head_atom *asyh = &head->asy;
2311 struct nouveau_conn_atom asyc;
2312 u32 *push;
Ben Skeggsf9887d02012-11-21 13:03:42 +10002313
Ben Skeggs7e08d672016-11-04 17:20:36 +10002314 asyc.procamp.color_vibrance = nv_crtc->color_vibrance + 100;
2315 asyc.procamp.vibrant_hue = nv_crtc->vibrant_hue + 90;
2316 nv50_head_atomic_check(&head->base.base, &asyh->state);
2317 nv50_head_atomic_check_procamp(&head->arm, asyh, &asyc);
2318 nv50_head_flush_set(head, asyh);
Ben Skeggsf9887d02012-11-21 13:03:42 +10002319
Ben Skeggs7e08d672016-11-04 17:20:36 +10002320 if (update) {
2321 if ((push = evo_wait(mast, 2))) {
Ben Skeggsf9887d02012-11-21 13:03:42 +10002322 evo_mthd(push, 0x0080, 1);
2323 evo_data(push, 0x00000000);
Ben Skeggs7e08d672016-11-04 17:20:36 +10002324 evo_kick(push, mast);
Ben Skeggsf9887d02012-11-21 13:03:42 +10002325 }
Ben Skeggsf9887d02012-11-21 13:03:42 +10002326 }
2327
2328 return 0;
2329}
2330
2331static int
Ben Skeggse225f442012-11-21 14:40:21 +10002332nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002333 int x, int y, bool update)
2334{
2335 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggsad633612016-11-04 17:20:36 +10002336 struct nv50_head *head = nv50_head(&nv_crtc->base);
2337 struct nv50_head_atom *asyh = &head->asy;
Ben Skeggs973f10c2016-11-04 17:20:36 +10002338 struct nv50_wndw_atom *asyw = &head->_base->wndw.asy;
Ben Skeggsad633612016-11-04 17:20:36 +10002339 const struct drm_format_info *info;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002340
Ben Skeggsad633612016-11-04 17:20:36 +10002341 info = drm_format_info(nvfb->base.pixel_format);
2342 if (!info || !info->depth)
2343 return -EINVAL;
Ben Skeggsde8268c2012-11-16 10:24:31 +10002344
Ben Skeggsad633612016-11-04 17:20:36 +10002345 asyh->base.depth = info->depth;
2346 asyh->base.cpp = info->cpp[0];
2347 asyh->base.x = x;
2348 asyh->base.y = y;
2349 asyh->base.w = nvfb->base.width;
2350 asyh->base.h = nvfb->base.height;
Ben Skeggs973f10c2016-11-04 17:20:36 +10002351 asyw->state.src_x = x << 16;
2352 asyw->state.src_y = y << 16;
Ben Skeggsad633612016-11-04 17:20:36 +10002353 nv50_head_atomic_check(&head->base.base, &asyh->state);
2354 nv50_head_flush_set(head, asyh);
2355
2356 if (update) {
2357 struct nv50_mast *core = nv50_mast(nv_crtc->base.dev);
2358 u32 *push = evo_wait(core, 2);
2359 if (push) {
Ben Skeggsa46232e2011-07-07 15:23:48 +10002360 evo_mthd(push, 0x0080, 1);
2361 evo_data(push, 0x00000000);
Ben Skeggsad633612016-11-04 17:20:36 +10002362 evo_kick(push, core);
Ben Skeggsa46232e2011-07-07 15:23:48 +10002363 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10002364 }
2365
Ben Skeggs8a423642014-08-10 04:10:19 +10002366 nv_crtc->fb.handle = nvfb->r_handle;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002367 return 0;
2368}
2369
2370static void
Ben Skeggse225f442012-11-21 14:40:21 +10002371nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002372{
Ben Skeggse225f442012-11-21 14:40:21 +10002373 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsea8ee392016-11-04 17:20:36 +10002374 struct nv50_head *head = nv50_head(&nv_crtc->base);
2375 struct nv50_head_atom *asyh = &head->asy;
2376
2377 asyh->curs.visible = true;
2378 asyh->curs.handle = mast->base.vram.handle;
2379 asyh->curs.offset = nv_crtc->cursor.nvbo->bo.offset;
2380 asyh->curs.layout = 1;
2381 asyh->curs.format = 1;
2382 nv50_head_atomic_check(&head->base.base, &asyh->state);
2383 nv50_head_flush_set(head, asyh);
Ben Skeggsde8268c2012-11-16 10:24:31 +10002384}
2385
2386static void
Ben Skeggse225f442012-11-21 14:40:21 +10002387nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +10002388{
Ben Skeggsea8ee392016-11-04 17:20:36 +10002389 struct nv50_head *head = nv50_head(&nv_crtc->base);
2390 struct nv50_head_atom *asyh = &head->asy;
2391
2392 asyh->curs.visible = false;
2393 nv50_head_atomic_check(&head->base.base, &asyh->state);
2394 nv50_head_flush_clr(head, asyh, false);
Ben Skeggsde8268c2012-11-16 10:24:31 +10002395}
Ben Skeggs438d99e2011-07-05 16:48:06 +10002396
Ben Skeggsde8268c2012-11-16 10:24:31 +10002397static void
Ben Skeggse225f442012-11-21 14:40:21 +10002398nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +10002399{
Ben Skeggse225f442012-11-21 14:40:21 +10002400 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +10002401
Ben Skeggs697bb722015-07-28 17:20:57 +10002402 if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled)
Ben Skeggse225f442012-11-21 14:40:21 +10002403 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10002404 else
Ben Skeggse225f442012-11-21 14:40:21 +10002405 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10002406
2407 if (update) {
2408 u32 *push = evo_wait(mast, 2);
2409 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10002410 evo_mthd(push, 0x0080, 1);
2411 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +10002412 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002413 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10002414 }
2415}
2416
2417static void
Ben Skeggse225f442012-11-21 14:40:21 +10002418nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002419{
2420}
2421
2422static void
Ben Skeggse225f442012-11-21 14:40:21 +10002423nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002424{
Ben Skeggsad633612016-11-04 17:20:36 +10002425 struct nv50_head *head = nv50_head(crtc);
2426 struct nv50_head_atom *asyh = &head->asy;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002427
Ben Skeggse225f442012-11-21 14:40:21 +10002428 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +10002429
Ben Skeggsad633612016-11-04 17:20:36 +10002430 asyh->state.active = false;
2431 nv50_head_atomic_check(&head->base.base, &asyh->state);
2432 nv50_head_flush_clr(head, asyh, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002433}
2434
2435static void
Ben Skeggse225f442012-11-21 14:40:21 +10002436nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002437{
Ben Skeggsa7ae1562016-11-04 17:20:36 +10002438 struct nv50_head *head = nv50_head(crtc);
2439 struct nv50_head_atom *asyh = &head->asy;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002440
Ben Skeggsa7ae1562016-11-04 17:20:36 +10002441 asyh->state.active = true;
2442 nv50_head_atomic_check(&head->base.base, &asyh->state);
2443 nv50_head_flush_set(head, asyh);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002444
Matt Roperf4510a22014-04-01 15:22:40 -07002445 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002446}
2447
2448static bool
Ben Skeggse225f442012-11-21 14:40:21 +10002449nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002450 struct drm_display_mode *adjusted_mode)
2451{
Ben Skeggseb2e9682014-01-24 10:13:23 +10002452 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002453 return true;
2454}
2455
2456static int
Ben Skeggse225f442012-11-21 14:40:21 +10002457nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002458{
Matt Roperf4510a22014-04-01 15:22:40 -07002459 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002460 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002461 int ret;
2462
Ben Skeggs547ad072014-11-10 12:35:06 +10002463 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002464 if (ret == 0) {
2465 if (head->image)
2466 nouveau_bo_unpin(head->image);
2467 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002468 }
2469
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002470 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002471}
2472
2473static int
Ben Skeggse225f442012-11-21 14:40:21 +10002474nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002475 struct drm_display_mode *mode, int x, int y,
2476 struct drm_framebuffer *old_fb)
2477{
2478 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
2479 struct nouveau_connector *nv_connector;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002480 int ret;
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002481 struct nv50_head *head = nv50_head(crtc);
2482 struct nv50_head_atom *asyh = &head->asy;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002483
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002484 memcpy(&asyh->state.mode, umode, sizeof(*umode));
2485 memcpy(&asyh->state.adjusted_mode, mode, sizeof(*mode));
2486 asyh->state.active = true;
2487 asyh->state.mode_changed = true;
2488 nv50_head_atomic_check(&head->base.base, &asyh->state);
Ben Skeggs2d1d8982011-11-11 23:39:22 +10002489
Ben Skeggse225f442012-11-21 14:40:21 +10002490 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002491 if (ret)
2492 return ret;
2493
Ben Skeggs3dbd0362016-11-04 17:20:36 +10002494 nv50_head_flush_set(head, asyh);
2495
Ben Skeggs438d99e2011-07-05 16:48:06 +10002496 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10002497 nv50_crtc_set_dither(nv_crtc, false);
2498 nv50_crtc_set_scale(nv_crtc, false);
Roy Splieteae73822014-10-30 22:57:45 +01002499
Ben Skeggse225f442012-11-21 14:40:21 +10002500 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07002501 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002502 return 0;
2503}
2504
2505static int
Ben Skeggse225f442012-11-21 14:40:21 +10002506nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002507 struct drm_framebuffer *old_fb)
2508{
Ben Skeggs77145f12012-07-31 16:16:21 +10002509 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002510 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
2511 int ret;
2512
Matt Roperf4510a22014-04-01 15:22:40 -07002513 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10002514 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10002515 return 0;
2516 }
2517
Ben Skeggse225f442012-11-21 14:40:21 +10002518 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002519 if (ret)
2520 return ret;
2521
Ben Skeggse225f442012-11-21 14:40:21 +10002522 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07002523 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
2524 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002525 return 0;
2526}
2527
2528static int
Ben Skeggse225f442012-11-21 14:40:21 +10002529nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002530 struct drm_framebuffer *fb, int x, int y,
2531 enum mode_set_atomic state)
2532{
2533 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10002534 nv50_display_flip_stop(crtc);
2535 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002536 return 0;
2537}
2538
2539static void
Ben Skeggse225f442012-11-21 14:40:21 +10002540nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002541{
Ben Skeggse225f442012-11-21 14:40:21 +10002542 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002543 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
2544 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
2545 int i;
2546
2547 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10002548 u16 r = nv_crtc->lut.r[i] >> 2;
2549 u16 g = nv_crtc->lut.g[i] >> 2;
2550 u16 b = nv_crtc->lut.b[i] >> 2;
2551
Ben Skeggs648d4df2014-08-10 04:10:27 +10002552 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10002553 writew(r + 0x0000, lut + (i * 0x08) + 0);
2554 writew(g + 0x0000, lut + (i * 0x08) + 2);
2555 writew(b + 0x0000, lut + (i * 0x08) + 4);
2556 } else {
2557 writew(r + 0x6000, lut + (i * 0x20) + 0);
2558 writew(g + 0x6000, lut + (i * 0x20) + 2);
2559 writew(b + 0x6000, lut + (i * 0x20) + 4);
2560 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10002561 }
2562}
2563
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002564static void
2565nv50_crtc_disable(struct drm_crtc *crtc)
2566{
2567 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10002568 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002569 if (head->image)
2570 nouveau_bo_unpin(head->image);
2571 nouveau_bo_ref(NULL, &head->image);
2572}
2573
Ben Skeggs438d99e2011-07-05 16:48:06 +10002574static int
Ben Skeggse225f442012-11-21 14:40:21 +10002575nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002576 uint32_t handle, uint32_t width, uint32_t height)
2577{
2578 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs5a560252014-11-10 15:52:02 +10002579 struct drm_gem_object *gem = NULL;
2580 struct nouveau_bo *nvbo = NULL;
2581 int ret = 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002582
Ben Skeggs5a560252014-11-10 15:52:02 +10002583 if (handle) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10002584 if (width != 64 || height != 64)
2585 return -EINVAL;
2586
Chris Wilsona8ad0bd2016-05-09 11:04:54 +01002587 gem = drm_gem_object_lookup(file_priv, handle);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002588 if (unlikely(!gem))
2589 return -ENOENT;
2590 nvbo = nouveau_gem_object(gem);
2591
Ben Skeggs5a560252014-11-10 15:52:02 +10002592 ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002593 }
2594
Ben Skeggs5a560252014-11-10 15:52:02 +10002595 if (ret == 0) {
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002596 if (nv_crtc->cursor.nvbo)
2597 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
2598 nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002599 }
Ben Skeggs5a560252014-11-10 15:52:02 +10002600 drm_gem_object_unreference_unlocked(gem);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002601
Ben Skeggs5a560252014-11-10 15:52:02 +10002602 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002603 return ret;
2604}
2605
2606static int
Ben Skeggse225f442012-11-21 14:40:21 +10002607nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002608{
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002609 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs22e927d2016-11-04 17:20:36 +10002610 struct nv50_wndw *wndw = &nv50_head(crtc)->_curs->wndw;
2611 struct nv50_wndw_atom *asyw = &wndw->asy;
2612
2613 asyw->point.x = x;
2614 asyw->point.y = y;
2615 asyw->set.point = true;
2616 nv50_wndw_flush_set(wndw, 0, asyw);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002617
2618 nv_crtc->cursor_saved_x = x;
2619 nv_crtc->cursor_saved_y = y;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002620 return 0;
2621}
2622
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02002623static int
Ben Skeggse225f442012-11-21 14:40:21 +10002624nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02002625 uint32_t size)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002626{
2627 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002628 u32 i;
2629
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02002630 for (i = 0; i < size; i++) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10002631 nv_crtc->lut.r[i] = r[i];
2632 nv_crtc->lut.g[i] = g[i];
2633 nv_crtc->lut.b[i] = b[i];
2634 }
2635
Ben Skeggse225f442012-11-21 14:40:21 +10002636 nv50_crtc_lut_load(crtc);
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02002637
2638 return 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002639}
2640
2641static void
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002642nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y)
2643{
2644 nv50_crtc_cursor_move(&nv_crtc->base, x, y);
2645
2646 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
2647}
2648
2649static void
Ben Skeggse225f442012-11-21 14:40:21 +10002650nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002651{
2652 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10002653 struct nv50_disp *disp = nv50_disp(crtc->dev);
2654 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs0ad72862014-08-10 04:10:22 +10002655
2656 nv50_dmac_destroy(&head->ovly.base, disp->disp);
2657 nv50_pioc_destroy(&head->oimm.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002658
2659 /*XXX: this shouldn't be necessary, but the core doesn't call
2660 * disconnect() during the cleanup paths
2661 */
2662 if (head->image)
2663 nouveau_bo_unpin(head->image);
2664 nouveau_bo_ref(NULL, &head->image);
2665
Ben Skeggs5a560252014-11-10 15:52:02 +10002666 /*XXX: ditto */
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002667 if (nv_crtc->cursor.nvbo)
2668 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
2669 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002670
Ben Skeggs438d99e2011-07-05 16:48:06 +10002671 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002672 if (nv_crtc->lut.nvbo)
2673 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002674 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002675
Ben Skeggs438d99e2011-07-05 16:48:06 +10002676 drm_crtc_cleanup(crtc);
2677 kfree(crtc);
2678}
2679
Ben Skeggse225f442012-11-21 14:40:21 +10002680static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
2681 .dpms = nv50_crtc_dpms,
2682 .prepare = nv50_crtc_prepare,
2683 .commit = nv50_crtc_commit,
2684 .mode_fixup = nv50_crtc_mode_fixup,
2685 .mode_set = nv50_crtc_mode_set,
2686 .mode_set_base = nv50_crtc_mode_set_base,
2687 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
2688 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10002689 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002690};
2691
Ben Skeggse225f442012-11-21 14:40:21 +10002692static const struct drm_crtc_funcs nv50_crtc_func = {
2693 .cursor_set = nv50_crtc_cursor_set,
2694 .cursor_move = nv50_crtc_cursor_move,
2695 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10002696 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10002697 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10002698 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10002699};
2700
2701static int
Ben Skeggs0ad72862014-08-10 04:10:22 +10002702nv50_crtc_create(struct drm_device *dev, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002703{
Ben Skeggsa01ca782015-08-20 14:54:15 +10002704 struct nouveau_drm *drm = nouveau_drm(dev);
2705 struct nvif_device *device = &drm->device;
Ben Skeggse225f442012-11-21 14:40:21 +10002706 struct nv50_disp *disp = nv50_disp(dev);
2707 struct nv50_head *head;
Ben Skeggs973f10c2016-11-04 17:20:36 +10002708 struct nv50_base *base;
Ben Skeggs22e927d2016-11-04 17:20:36 +10002709 struct nv50_curs *curs;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002710 struct drm_crtc *crtc;
2711 int ret, i;
2712
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10002713 head = kzalloc(sizeof(*head), GFP_KERNEL);
2714 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10002715 return -ENOMEM;
2716
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10002717 head->base.index = index;
Ben Skeggsf9887d02012-11-21 13:03:42 +10002718 head->base.color_vibrance = 50;
2719 head->base.vibrant_hue = 0;
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002720 head->base.cursor.set_pos = nv50_crtc_cursor_restore;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002721 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10002722 head->base.lut.r[i] = i << 8;
2723 head->base.lut.g[i] = i << 8;
2724 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10002725 }
2726
Ben Skeggs973f10c2016-11-04 17:20:36 +10002727 ret = nv50_base_new(drm, head, &base);
Ben Skeggs22e927d2016-11-04 17:20:36 +10002728 if (ret == 0)
2729 ret = nv50_curs_new(drm, head, &curs);
Ben Skeggs973f10c2016-11-04 17:20:36 +10002730 if (ret) {
2731 kfree(head);
2732 return ret;
2733 }
2734
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10002735 crtc = &head->base.base;
Ben Skeggs973f10c2016-11-04 17:20:36 +10002736 head->_base = base;
Ben Skeggs22e927d2016-11-04 17:20:36 +10002737 head->_curs = curs;
Ben Skeggs973f10c2016-11-04 17:20:36 +10002738
Ben Skeggse225f442012-11-21 14:40:21 +10002739 drm_crtc_init(dev, crtc, &nv50_crtc_func);
2740 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002741 drm_mode_crtc_set_gamma_size(crtc, 256);
2742
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10002743 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01002744 0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002745 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10002746 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002747 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10002748 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002749 if (ret)
2750 nouveau_bo_unpin(head->base.lut.nvbo);
2751 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10002752 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10002753 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002754 }
2755
2756 if (ret)
2757 goto out;
2758
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002759 /* allocate overlay resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10002760 ret = nv50_oimm_create(device, disp->disp, index, &head->oimm);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002761 if (ret)
2762 goto out;
2763
Ben Skeggsa01ca782015-08-20 14:54:15 +10002764 ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset,
2765 &head->ovly);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002766 if (ret)
2767 goto out;
2768
Ben Skeggs438d99e2011-07-05 16:48:06 +10002769out:
2770 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002771 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002772 return ret;
2773}
2774
2775/******************************************************************************
Ben Skeggsd92c8ad2016-11-04 17:20:36 +10002776 * Output path helpers
Ben Skeggsa91d3222014-12-22 16:30:13 +10002777 *****************************************************************************/
Ben Skeggsd92c8ad2016-11-04 17:20:36 +10002778static int
2779nv50_outp_atomic_check_view(struct drm_encoder *encoder,
2780 struct drm_crtc_state *crtc_state,
2781 struct drm_connector_state *conn_state,
2782 struct drm_display_mode *native_mode)
2783{
2784 struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
2785 struct drm_display_mode *mode = &crtc_state->mode;
2786 struct drm_connector *connector = conn_state->connector;
2787 struct nouveau_conn_atom *asyc = nouveau_conn_atom(conn_state);
2788 struct nouveau_drm *drm = nouveau_drm(encoder->dev);
2789
2790 NV_ATOMIC(drm, "%s atomic_check\n", encoder->name);
2791 asyc->scaler.full = false;
2792 if (!native_mode)
2793 return 0;
2794
2795 if (asyc->scaler.mode == DRM_MODE_SCALE_NONE) {
2796 switch (connector->connector_type) {
2797 case DRM_MODE_CONNECTOR_LVDS:
2798 case DRM_MODE_CONNECTOR_eDP:
2799 /* Force use of scaler for non-EDID modes. */
2800 if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
2801 break;
2802 mode = native_mode;
2803 asyc->scaler.full = true;
2804 break;
2805 default:
2806 break;
2807 }
2808 } else {
2809 mode = native_mode;
2810 }
2811
2812 if (!drm_mode_equal(adjusted_mode, mode)) {
2813 drm_mode_copy(adjusted_mode, mode);
2814 crtc_state->mode_changed = true;
2815 }
2816
2817 return 0;
2818}
2819
Ben Skeggsa91d3222014-12-22 16:30:13 +10002820static bool
2821nv50_encoder_mode_fixup(struct drm_encoder *encoder,
2822 const struct drm_display_mode *mode,
2823 struct drm_display_mode *adjusted_mode)
2824{
2825 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2826 struct nouveau_connector *nv_connector;
2827
2828 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2829 if (nv_connector && nv_connector->native_mode) {
Ben Skeggsd92c8ad2016-11-04 17:20:36 +10002830 struct nouveau_conn_atom *asyc
2831 = nouveau_conn_atom(nv_connector->base.state);
2832 struct drm_crtc_state crtc_state = {
2833 .mode = *mode,
2834 .adjusted_mode = *adjusted_mode,
2835 };
Ben Skeggs576f7912014-12-22 17:19:26 +10002836
Ben Skeggsd92c8ad2016-11-04 17:20:36 +10002837 nv50_outp_atomic_check_view(encoder, &crtc_state, &asyc->state,
2838 nv_connector->native_mode);
2839 nv_connector->scaling_full = asyc->scaler.full;
2840 drm_mode_copy(adjusted_mode, &crtc_state.adjusted_mode);
Ben Skeggsa91d3222014-12-22 16:30:13 +10002841 }
2842
2843 return true;
2844}
2845
2846/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002847 * DAC
2848 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002849static void
Ben Skeggse225f442012-11-21 14:40:21 +10002850nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002851{
2852 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10002853 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsbf0eb892014-08-10 04:10:26 +10002854 struct {
2855 struct nv50_disp_mthd_v1 base;
2856 struct nv50_disp_dac_pwr_v0 pwr;
2857 } args = {
2858 .base.version = 1,
2859 .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
2860 .base.hasht = nv_encoder->dcb->hasht,
2861 .base.hashm = nv_encoder->dcb->hashm,
2862 .pwr.state = 1,
2863 .pwr.data = 1,
2864 .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
2865 mode != DRM_MODE_DPMS_OFF),
2866 .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
2867 mode != DRM_MODE_DPMS_OFF),
2868 };
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002869
Ben Skeggsbf0eb892014-08-10 04:10:26 +10002870 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002871}
2872
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002873static void
Ben Skeggsf20c6652016-11-04 17:20:36 +10002874nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002875{
Ben Skeggsf20c6652016-11-04 17:20:36 +10002876 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2877 struct nv50_mast *mast = nv50_mast(encoder->dev);
2878 const int or = nv_encoder->or;
2879 u32 *push;
2880
2881 if (nv_encoder->crtc) {
2882 nv50_crtc_prepare(nv_encoder->crtc);
2883
2884 push = evo_wait(mast, 4);
2885 if (push) {
2886 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
2887 evo_mthd(push, 0x0400 + (or * 0x080), 1);
2888 evo_data(push, 0x00000000);
2889 } else {
2890 evo_mthd(push, 0x0180 + (or * 0x020), 1);
2891 evo_data(push, 0x00000000);
2892 }
2893 evo_kick(push, mast);
2894 }
2895 }
2896
2897 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002898}
2899
2900static void
Ben Skeggse225f442012-11-21 14:40:21 +10002901nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002902 struct drm_display_mode *adjusted_mode)
2903{
Ben Skeggse225f442012-11-21 14:40:21 +10002904 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002905 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2906 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10002907 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002908
Ben Skeggse225f442012-11-21 14:40:21 +10002909 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002910
Ben Skeggs97b19b52012-11-16 11:21:37 +10002911 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002912 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002913 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10002914 u32 syncs = 0x00000000;
2915
2916 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2917 syncs |= 0x00000001;
2918 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2919 syncs |= 0x00000002;
2920
2921 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
2922 evo_data(push, 1 << nv_crtc->index);
2923 evo_data(push, syncs);
2924 } else {
2925 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
2926 u32 syncs = 0x00000001;
2927
2928 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2929 syncs |= 0x00000008;
2930 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2931 syncs |= 0x00000010;
2932
2933 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2934 magic |= 0x00000001;
2935
2936 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
2937 evo_data(push, syncs);
2938 evo_data(push, magic);
2939 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
2940 evo_data(push, 1 << nv_crtc->index);
2941 }
2942
2943 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002944 }
2945
2946 nv_encoder->crtc = encoder->crtc;
2947}
2948
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10002949static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10002950nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10002951{
Ben Skeggsc4abd312014-08-10 04:10:26 +10002952 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10002953 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsc4abd312014-08-10 04:10:26 +10002954 struct {
2955 struct nv50_disp_mthd_v1 base;
2956 struct nv50_disp_dac_load_v0 load;
2957 } args = {
2958 .base.version = 1,
2959 .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
2960 .base.hasht = nv_encoder->dcb->hasht,
2961 .base.hashm = nv_encoder->dcb->hashm,
2962 };
2963 int ret;
Ben Skeggsb6819932011-07-08 11:14:50 +10002964
Ben Skeggsc4abd312014-08-10 04:10:26 +10002965 args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
2966 if (args.load.data == 0)
2967 args.load.data = 340;
2968
2969 ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
2970 if (ret || !args.load.load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10002971 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10002972
Ben Skeggs35b21d32012-11-08 12:08:55 +10002973 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10002974}
2975
Ben Skeggsf20c6652016-11-04 17:20:36 +10002976static const struct drm_encoder_helper_funcs
2977nv50_dac_help = {
2978 .dpms = nv50_dac_dpms,
2979 .mode_fixup = nv50_encoder_mode_fixup,
2980 .prepare = nv50_dac_disconnect,
2981 .mode_set = nv50_dac_mode_set,
2982 .disable = nv50_dac_disconnect,
2983 .get_crtc = nv50_display_crtc_get,
2984 .detect = nv50_dac_detect
2985};
2986
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002987static void
Ben Skeggse225f442012-11-21 14:40:21 +10002988nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002989{
2990 drm_encoder_cleanup(encoder);
2991 kfree(encoder);
2992}
2993
Ben Skeggsf20c6652016-11-04 17:20:36 +10002994static const struct drm_encoder_funcs
2995nv50_dac_func = {
Ben Skeggse225f442012-11-21 14:40:21 +10002996 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10002997};
2998
2999static int
Ben Skeggse225f442012-11-21 14:40:21 +10003000nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10003001{
Ben Skeggs5ed50202013-02-11 20:15:03 +10003002 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10003003 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003004 struct nvkm_i2c_bus *bus;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10003005 struct nouveau_encoder *nv_encoder;
3006 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10003007 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10003008
3009 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
3010 if (!nv_encoder)
3011 return -ENOMEM;
3012 nv_encoder->dcb = dcbe;
3013 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003014
3015 bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
3016 if (bus)
3017 nv_encoder->i2c = &bus->i2c;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10003018
3019 encoder = to_drm_encoder(nv_encoder);
3020 encoder->possible_crtcs = dcbe->heads;
3021 encoder->possible_clones = 0;
Ben Skeggs5a223da2016-11-04 17:20:36 +10003022 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type,
3023 "dac-%04x-%04x", dcbe->hasht, dcbe->hashm);
Ben Skeggsf20c6652016-11-04 17:20:36 +10003024 drm_encoder_helper_add(encoder, &nv50_dac_help);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10003025
3026 drm_mode_connector_attach_encoder(connector, encoder);
3027 return 0;
3028}
Ben Skeggs26f6d882011-07-04 16:25:18 +10003029
3030/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10003031 * Audio
3032 *****************************************************************************/
3033static void
Ben Skeggsf20c6652016-11-04 17:20:36 +10003034nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
3035{
3036 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
3037 struct nv50_disp *disp = nv50_disp(encoder->dev);
3038 struct {
3039 struct nv50_disp_mthd_v1 base;
3040 struct nv50_disp_sor_hda_eld_v0 eld;
3041 } args = {
3042 .base.version = 1,
3043 .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
3044 .base.hasht = nv_encoder->dcb->hasht,
3045 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
3046 (0x0100 << nv_crtc->index),
3047 };
3048
3049 nvif_mthd(disp->disp, 0, &args, sizeof(args));
3050}
3051
3052static void
3053nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10003054{
3055 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggscc2a9072014-09-15 21:29:05 +10003056 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs78951d22011-11-11 18:13:13 +10003057 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10003058 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsd889c522014-09-15 21:11:51 +10003059 struct __packed {
3060 struct {
3061 struct nv50_disp_mthd_v1 mthd;
3062 struct nv50_disp_sor_hda_eld_v0 eld;
3063 } base;
Ben Skeggs120b0c32014-08-10 04:10:26 +10003064 u8 data[sizeof(nv_connector->base.eld)];
3065 } args = {
Ben Skeggsd889c522014-09-15 21:11:51 +10003066 .base.mthd.version = 1,
3067 .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
3068 .base.mthd.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10003069 .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
3070 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10003071 };
Ben Skeggs78951d22011-11-11 18:13:13 +10003072
3073 nv_connector = nouveau_encoder_connector_get(nv_encoder);
3074 if (!drm_detect_monitor_audio(nv_connector->edid))
3075 return;
3076
Ben Skeggs78951d22011-11-11 18:13:13 +10003077 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs120b0c32014-08-10 04:10:26 +10003078 memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10003079
Jani Nikula938fd8a2014-10-28 16:20:48 +02003080 nvif_mthd(disp->disp, 0, &args,
3081 sizeof(args.base) + drm_eld_size(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10003082}
3083
Ben Skeggsf20c6652016-11-04 17:20:36 +10003084/******************************************************************************
3085 * HDMI
3086 *****************************************************************************/
Ben Skeggs78951d22011-11-11 18:13:13 +10003087static void
Ben Skeggsf20c6652016-11-04 17:20:36 +10003088nv50_hdmi_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10003089{
3090 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10003091 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs120b0c32014-08-10 04:10:26 +10003092 struct {
3093 struct nv50_disp_mthd_v1 base;
Ben Skeggsf20c6652016-11-04 17:20:36 +10003094 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
Ben Skeggs120b0c32014-08-10 04:10:26 +10003095 } args = {
3096 .base.version = 1,
Ben Skeggsf20c6652016-11-04 17:20:36 +10003097 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
3098 .base.hasht = nv_encoder->dcb->hasht,
3099 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
3100 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10003101 };
Ben Skeggs78951d22011-11-11 18:13:13 +10003102
Ben Skeggs120b0c32014-08-10 04:10:26 +10003103 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10003104}
3105
Ben Skeggs78951d22011-11-11 18:13:13 +10003106static void
Ben Skeggsf20c6652016-11-04 17:20:36 +10003107nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10003108{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10003109 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
3110 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10003111 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10003112 struct {
3113 struct nv50_disp_mthd_v1 base;
3114 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
3115 } args = {
3116 .base.version = 1,
3117 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
3118 .base.hasht = nv_encoder->dcb->hasht,
3119 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
3120 (0x0100 << nv_crtc->index),
3121 .pwr.state = 1,
3122 .pwr.rekey = 56, /* binary driver, and tegra, constant */
3123 };
3124 struct nouveau_connector *nv_connector;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10003125 u32 max_ac_packet;
3126
3127 nv_connector = nouveau_encoder_connector_get(nv_encoder);
3128 if (!drm_detect_hdmi_monitor(nv_connector->edid))
3129 return;
3130
3131 max_ac_packet = mode->htotal - mode->hdisplay;
Ben Skeggse00f2232014-08-10 04:10:26 +10003132 max_ac_packet -= args.pwr.rekey;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10003133 max_ac_packet -= 18; /* constant from tegra */
Ben Skeggse00f2232014-08-10 04:10:26 +10003134 args.pwr.max_ac_packet = max_ac_packet / 32;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10003135
Ben Skeggse00f2232014-08-10 04:10:26 +10003136 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggsf20c6652016-11-04 17:20:36 +10003137 nv50_audio_enable(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10003138}
3139
3140/******************************************************************************
Ben Skeggs52aa30f2016-11-04 17:20:36 +10003141 * MST
3142 *****************************************************************************/
3143struct nv50_mstm {
3144 struct nouveau_encoder *outp;
3145
3146 struct drm_dp_mst_topology_mgr mgr;
3147};
3148
3149static int
3150nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state)
3151{
3152 struct nouveau_encoder *outp = mstm->outp;
3153 struct {
3154 struct nv50_disp_mthd_v1 base;
3155 struct nv50_disp_sor_dp_mst_link_v0 mst;
3156 } args = {
3157 .base.version = 1,
3158 .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_LINK,
3159 .base.hasht = outp->dcb->hasht,
3160 .base.hashm = outp->dcb->hashm,
3161 .mst.state = state,
3162 };
3163 struct nouveau_drm *drm = nouveau_drm(outp->base.base.dev);
3164 struct nvif_object *disp = &drm->display->disp;
3165 int ret;
3166
3167 if (dpcd >= 0x12) {
3168 ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CTRL, &dpcd);
3169 if (ret < 0)
3170 return ret;
3171
3172 dpcd &= ~DP_MST_EN;
3173 if (state)
3174 dpcd |= DP_MST_EN;
3175
3176 ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, dpcd);
3177 if (ret < 0)
3178 return ret;
3179 }
3180
3181 return nvif_mthd(disp, 0, &args, sizeof(args));
3182}
3183
3184int
3185nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow)
3186{
3187 int ret, state = 0;
3188
3189 if (!mstm)
3190 return 0;
3191
3192 if (dpcd[0] >= 0x12 && allow) {
3193 ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CAP, &dpcd[1]);
3194 if (ret < 0)
3195 return ret;
3196
3197 state = dpcd[1] & DP_MST_CAP;
3198 }
3199
3200 ret = nv50_mstm_enable(mstm, dpcd[0], state);
3201 if (ret)
3202 return ret;
3203
3204 ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, state);
3205 if (ret)
3206 return nv50_mstm_enable(mstm, dpcd[0], 0);
3207
3208 return mstm->mgr.mst_state;
3209}
3210
3211static void
3212nv50_mstm_del(struct nv50_mstm **pmstm)
3213{
3214 struct nv50_mstm *mstm = *pmstm;
3215 if (mstm) {
3216 kfree(*pmstm);
3217 *pmstm = NULL;
3218 }
3219}
3220
3221static int
3222nv50_mstm_new(struct nouveau_encoder *outp, struct drm_dp_aux *aux, int aux_max,
3223 int conn_base_id, struct nv50_mstm **pmstm)
3224{
3225 const int max_payloads = hweight8(outp->dcb->heads);
3226 struct drm_device *dev = outp->base.base.dev;
3227 struct nv50_mstm *mstm;
3228 int ret;
3229
3230 if (!(mstm = *pmstm = kzalloc(sizeof(*mstm), GFP_KERNEL)))
3231 return -ENOMEM;
3232 mstm->outp = outp;
3233
3234 ret = drm_dp_mst_topology_mgr_init(&mstm->mgr, dev->dev, aux, aux_max,
3235 max_payloads, conn_base_id);
3236 if (ret)
3237 return ret;
3238
3239 return 0;
3240}
3241
3242/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10003243 * SOR
3244 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10003245static void
Ben Skeggse225f442012-11-21 14:40:21 +10003246nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10003247{
3248 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggsd55b4af2014-08-10 04:10:26 +10003249 struct nv50_disp *disp = nv50_disp(encoder->dev);
3250 struct {
3251 struct nv50_disp_mthd_v1 base;
3252 struct nv50_disp_sor_pwr_v0 pwr;
3253 } args = {
3254 .base.version = 1,
3255 .base.method = NV50_DISP_MTHD_V1_SOR_PWR,
3256 .base.hasht = nv_encoder->dcb->hasht,
3257 .base.hashm = nv_encoder->dcb->hashm,
3258 .pwr.state = mode == DRM_MODE_DPMS_ON,
3259 };
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10003260 struct {
3261 struct nv50_disp_mthd_v1 base;
3262 struct nv50_disp_sor_dp_pwr_v0 pwr;
3263 } link = {
3264 .base.version = 1,
3265 .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
3266 .base.hasht = nv_encoder->dcb->hasht,
3267 .base.hashm = nv_encoder->dcb->hashm,
3268 .pwr.state = mode == DRM_MODE_DPMS_ON,
3269 };
Ben Skeggs83fc0832011-07-05 13:08:40 +10003270 struct drm_device *dev = encoder->dev;
3271 struct drm_encoder *partner;
Ben Skeggs83fc0832011-07-05 13:08:40 +10003272
3273 nv_encoder->last_dpms = mode;
3274
3275 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
3276 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
3277
3278 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
3279 continue;
3280
3281 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10003282 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10003283 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
3284 return;
3285 break;
3286 }
3287 }
3288
Ben Skeggs48743222014-05-31 01:48:06 +10003289 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10003290 args.pwr.state = 1;
3291 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10003292 nvif_mthd(disp->disp, 0, &link, sizeof(link));
Ben Skeggs48743222014-05-31 01:48:06 +10003293 } else {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10003294 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs48743222014-05-31 01:48:06 +10003295 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10003296}
3297
Ben Skeggs83fc0832011-07-05 13:08:40 +10003298static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10003299nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
3300{
3301 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
3302 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
3303 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10003304 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10003305 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
3306 evo_data(push, (nv_encoder->ctrl = temp));
3307 } else {
3308 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
3309 evo_data(push, (nv_encoder->ctrl = temp));
3310 }
3311 evo_kick(push, mast);
3312 }
3313}
3314
3315static void
Ben Skeggse225f442012-11-21 14:40:21 +10003316nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10003317{
3318 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10003319 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003320
3321 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
3322 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10003323
3324 if (nv_crtc) {
3325 nv50_crtc_prepare(&nv_crtc->base);
3326 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
Ben Skeggsf20c6652016-11-04 17:20:36 +10003327 nv50_audio_disable(encoder, nv_crtc);
3328 nv50_hdmi_disable(&nv_encoder->base.base, nv_crtc);
Ben Skeggse84a35a2014-06-05 10:59:55 +10003329 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10003330}
3331
3332static void
Ben Skeggse225f442012-11-21 14:40:21 +10003333nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003334 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10003335{
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003336 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
3337 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
3338 struct {
3339 struct nv50_disp_mthd_v1 base;
3340 struct nv50_disp_sor_lvds_script_v0 lvds;
3341 } lvds = {
3342 .base.version = 1,
3343 .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
3344 .base.hasht = nv_encoder->dcb->hasht,
3345 .base.hashm = nv_encoder->dcb->hashm,
3346 };
Ben Skeggse225f442012-11-21 14:40:21 +10003347 struct nv50_disp *disp = nv50_disp(encoder->dev);
3348 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10003349 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10003350 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003351 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10003352 struct nvbios *bios = &drm->vbios;
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003353 u32 mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003354 u8 owner = 1 << nv_crtc->index;
3355 u8 proto = 0xf;
3356 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10003357
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003358 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10003359 nv_encoder->crtc = encoder->crtc;
3360
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003361 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10003362 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003363 if (nv_encoder->dcb->sorconf.link & 1) {
Hauke Mehrtens16ef53a92015-11-03 21:00:10 -05003364 proto = 0x1;
3365 /* Only enable dual-link if:
3366 * - Need to (i.e. rate > 165MHz)
3367 * - DCB says we can
3368 * - Not an HDMI monitor, since there's no dual-link
3369 * on HDMI.
3370 */
3371 if (mode->clock >= 165000 &&
3372 nv_encoder->dcb->duallink_possible &&
3373 !drm_detect_hdmi_monitor(nv_connector->edid))
3374 proto |= 0x4;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003375 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003376 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003377 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10003378
Ben Skeggsf20c6652016-11-04 17:20:36 +10003379 nv50_hdmi_enable(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003380 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10003381 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003382 proto = 0x0;
3383
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003384 if (bios->fp_no_ddc) {
3385 if (bios->fp.dual_link)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003386 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003387 if (bios->fp.if_is_24bit)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003388 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003389 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10003390 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003391 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003392 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003393 } else
3394 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003395 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003396 }
3397
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003398 if (lvds.lvds.script & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003399 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003400 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003401 } else {
3402 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003403 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003404 }
3405
3406 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003407 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003408 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10003409
Ben Skeggsa3761fa2014-08-10 04:10:27 +10003410 nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds));
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003411 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10003412 case DCB_OUTPUT_DP:
Ben Skeggsf20c6652016-11-04 17:20:36 +10003413 if (nv_connector->base.display_info.bpc == 6)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003414 depth = 0x2;
Ben Skeggsf20c6652016-11-04 17:20:36 +10003415 else
3416 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003417 depth = 0x5;
Ben Skeggsf20c6652016-11-04 17:20:36 +10003418 else
Ben Skeggsbf2c8862012-11-21 14:49:54 +10003419 depth = 0x6;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10003420
3421 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003422 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10003423 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003424 proto = 0x9;
Ben Skeggsf20c6652016-11-04 17:20:36 +10003425
3426 nv50_audio_enable(encoder, mode);
Ben Skeggs6e83fda2012-03-11 01:28:48 +10003427 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10003428 default:
3429 BUG_ON(1);
3430 break;
3431 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10003432
Ben Skeggse84a35a2014-06-05 10:59:55 +10003433 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10003434
Ben Skeggs648d4df2014-08-10 04:10:27 +10003435 if (nv50_vers(mast) >= GF110_DISP) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10003436 u32 *push = evo_wait(mast, 3);
3437 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003438 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
3439 u32 syncs = 0x00000001;
3440
3441 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
3442 syncs |= 0x00000008;
3443 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
3444 syncs |= 0x00000010;
3445
3446 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
3447 magic |= 0x00000001;
3448
3449 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
3450 evo_data(push, syncs | (depth << 6));
3451 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10003452 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10003453 }
3454
Ben Skeggse84a35a2014-06-05 10:59:55 +10003455 ctrl = proto << 8;
3456 mask = 0x00000f00;
3457 } else {
3458 ctrl = (depth << 16) | (proto << 8);
3459 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
3460 ctrl |= 0x00001000;
3461 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
3462 ctrl |= 0x00002000;
3463 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10003464 }
3465
Ben Skeggse84a35a2014-06-05 10:59:55 +10003466 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10003467}
3468
Ben Skeggsf20c6652016-11-04 17:20:36 +10003469static const struct drm_encoder_helper_funcs
3470nv50_sor_help = {
3471 .dpms = nv50_sor_dpms,
3472 .mode_fixup = nv50_encoder_mode_fixup,
3473 .prepare = nv50_sor_disconnect,
3474 .mode_set = nv50_sor_mode_set,
3475 .disable = nv50_sor_disconnect,
3476 .get_crtc = nv50_display_crtc_get,
3477};
3478
Ben Skeggs83fc0832011-07-05 13:08:40 +10003479static void
Ben Skeggse225f442012-11-21 14:40:21 +10003480nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10003481{
Ben Skeggs52aa30f2016-11-04 17:20:36 +10003482 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
3483 nv50_mstm_del(&nv_encoder->dp.mstm);
Ben Skeggs83fc0832011-07-05 13:08:40 +10003484 drm_encoder_cleanup(encoder);
3485 kfree(encoder);
3486}
3487
Ben Skeggsf20c6652016-11-04 17:20:36 +10003488static const struct drm_encoder_funcs
3489nv50_sor_func = {
Ben Skeggse225f442012-11-21 14:40:21 +10003490 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10003491};
3492
3493static int
Ben Skeggse225f442012-11-21 14:40:21 +10003494nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10003495{
Ben Skeggs52aa30f2016-11-04 17:20:36 +10003496 struct nouveau_connector *nv_connector = nouveau_connector(connector);
Ben Skeggs5ed50202013-02-11 20:15:03 +10003497 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10003498 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10003499 struct nouveau_encoder *nv_encoder;
3500 struct drm_encoder *encoder;
Ben Skeggs52aa30f2016-11-04 17:20:36 +10003501 int type, ret;
Ben Skeggs5ed50202013-02-11 20:15:03 +10003502
3503 switch (dcbe->type) {
3504 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
3505 case DCB_OUTPUT_TMDS:
3506 case DCB_OUTPUT_DP:
3507 default:
3508 type = DRM_MODE_ENCODER_TMDS;
3509 break;
3510 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10003511
3512 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
3513 if (!nv_encoder)
3514 return -ENOMEM;
3515 nv_encoder->dcb = dcbe;
3516 nv_encoder->or = ffs(dcbe->or) - 1;
3517 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
3518
Ben Skeggs52aa30f2016-11-04 17:20:36 +10003519 encoder = to_drm_encoder(nv_encoder);
3520 encoder->possible_crtcs = dcbe->heads;
3521 encoder->possible_clones = 0;
Ben Skeggs5a223da2016-11-04 17:20:36 +10003522 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type,
3523 "sor-%04x-%04x", dcbe->hasht, dcbe->hashm);
Ben Skeggsf20c6652016-11-04 17:20:36 +10003524 drm_encoder_helper_add(encoder, &nv50_sor_help);
Ben Skeggs52aa30f2016-11-04 17:20:36 +10003525
3526 drm_mode_connector_attach_encoder(connector, encoder);
3527
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003528 if (dcbe->type == DCB_OUTPUT_DP) {
3529 struct nvkm_i2c_aux *aux =
3530 nvkm_i2c_aux_find(i2c, dcbe->i2c_index);
3531 if (aux) {
3532 nv_encoder->i2c = &aux->i2c;
3533 nv_encoder->aux = aux;
3534 }
Ben Skeggs52aa30f2016-11-04 17:20:36 +10003535
3536 /*TODO: Use DP Info Table to check for support. */
3537 if (nv50_disp(encoder->dev)->disp->oclass >= GF110_DISP) {
3538 ret = nv50_mstm_new(nv_encoder, &nv_connector->aux, 16,
3539 nv_connector->base.base.id,
3540 &nv_encoder->dp.mstm);
3541 if (ret)
3542 return ret;
3543 }
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003544 } else {
3545 struct nvkm_i2c_bus *bus =
3546 nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
3547 if (bus)
3548 nv_encoder->i2c = &bus->i2c;
3549 }
3550
Ben Skeggs83fc0832011-07-05 13:08:40 +10003551 return 0;
3552}
Ben Skeggs26f6d882011-07-04 16:25:18 +10003553
3554/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10003555 * PIOR
3556 *****************************************************************************/
Ben Skeggseb6313a2013-02-11 09:52:58 +10003557static void
3558nv50_pior_dpms(struct drm_encoder *encoder, int mode)
3559{
3560 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
3561 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs67cb49c2014-08-10 04:10:27 +10003562 struct {
3563 struct nv50_disp_mthd_v1 base;
3564 struct nv50_disp_pior_pwr_v0 pwr;
3565 } args = {
3566 .base.version = 1,
3567 .base.method = NV50_DISP_MTHD_V1_PIOR_PWR,
3568 .base.hasht = nv_encoder->dcb->hasht,
3569 .base.hashm = nv_encoder->dcb->hashm,
3570 .pwr.state = mode == DRM_MODE_DPMS_ON,
3571 .pwr.type = nv_encoder->dcb->type,
3572 };
3573
3574 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggseb6313a2013-02-11 09:52:58 +10003575}
3576
3577static bool
3578nv50_pior_mode_fixup(struct drm_encoder *encoder,
3579 const struct drm_display_mode *mode,
3580 struct drm_display_mode *adjusted_mode)
3581{
Ben Skeggsa91d3222014-12-22 16:30:13 +10003582 if (!nv50_encoder_mode_fixup(encoder, mode, adjusted_mode))
3583 return false;
Ben Skeggseb6313a2013-02-11 09:52:58 +10003584 adjusted_mode->clock *= 2;
3585 return true;
3586}
3587
3588static void
Ben Skeggsf20c6652016-11-04 17:20:36 +10003589nv50_pior_disconnect(struct drm_encoder *encoder)
Ben Skeggseb6313a2013-02-11 09:52:58 +10003590{
Ben Skeggsf20c6652016-11-04 17:20:36 +10003591 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
3592 struct nv50_mast *mast = nv50_mast(encoder->dev);
3593 const int or = nv_encoder->or;
3594 u32 *push;
3595
3596 if (nv_encoder->crtc) {
3597 nv50_crtc_prepare(nv_encoder->crtc);
3598
3599 push = evo_wait(mast, 4);
3600 if (push) {
3601 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
3602 evo_mthd(push, 0x0700 + (or * 0x040), 1);
3603 evo_data(push, 0x00000000);
3604 }
3605 evo_kick(push, mast);
3606 }
3607 }
3608
3609 nv_encoder->crtc = NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10003610}
3611
3612static void
3613nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
3614 struct drm_display_mode *adjusted_mode)
3615{
3616 struct nv50_mast *mast = nv50_mast(encoder->dev);
3617 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
3618 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
3619 struct nouveau_connector *nv_connector;
3620 u8 owner = 1 << nv_crtc->index;
3621 u8 proto, depth;
3622 u32 *push;
3623
3624 nv_connector = nouveau_encoder_connector_get(nv_encoder);
3625 switch (nv_connector->base.display_info.bpc) {
3626 case 10: depth = 0x6; break;
3627 case 8: depth = 0x5; break;
3628 case 6: depth = 0x2; break;
3629 default: depth = 0x0; break;
3630 }
3631
3632 switch (nv_encoder->dcb->type) {
3633 case DCB_OUTPUT_TMDS:
3634 case DCB_OUTPUT_DP:
3635 proto = 0x0;
3636 break;
3637 default:
3638 BUG_ON(1);
3639 break;
3640 }
3641
3642 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
3643
3644 push = evo_wait(mast, 8);
3645 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10003646 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10003647 u32 ctrl = (depth << 16) | (proto << 8) | owner;
3648 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
3649 ctrl |= 0x00001000;
3650 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
3651 ctrl |= 0x00002000;
3652 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
3653 evo_data(push, ctrl);
3654 }
3655
3656 evo_kick(push, mast);
3657 }
3658
3659 nv_encoder->crtc = encoder->crtc;
3660}
3661
Ben Skeggsf20c6652016-11-04 17:20:36 +10003662static const struct drm_encoder_helper_funcs
3663nv50_pior_help = {
3664 .dpms = nv50_pior_dpms,
3665 .mode_fixup = nv50_pior_mode_fixup,
3666 .prepare = nv50_pior_disconnect,
3667 .mode_set = nv50_pior_mode_set,
3668 .disable = nv50_pior_disconnect,
3669 .get_crtc = nv50_display_crtc_get,
3670};
Ben Skeggseb6313a2013-02-11 09:52:58 +10003671
3672static void
3673nv50_pior_destroy(struct drm_encoder *encoder)
3674{
3675 drm_encoder_cleanup(encoder);
3676 kfree(encoder);
3677}
3678
Ben Skeggsf20c6652016-11-04 17:20:36 +10003679static const struct drm_encoder_funcs
3680nv50_pior_func = {
Ben Skeggseb6313a2013-02-11 09:52:58 +10003681 .destroy = nv50_pior_destroy,
3682};
3683
3684static int
3685nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
3686{
3687 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10003688 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003689 struct nvkm_i2c_bus *bus = NULL;
3690 struct nvkm_i2c_aux *aux = NULL;
3691 struct i2c_adapter *ddc;
Ben Skeggseb6313a2013-02-11 09:52:58 +10003692 struct nouveau_encoder *nv_encoder;
3693 struct drm_encoder *encoder;
3694 int type;
3695
3696 switch (dcbe->type) {
3697 case DCB_OUTPUT_TMDS:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003698 bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev));
3699 ddc = bus ? &bus->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10003700 type = DRM_MODE_ENCODER_TMDS;
3701 break;
3702 case DCB_OUTPUT_DP:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003703 aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev));
3704 ddc = aux ? &aux->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10003705 type = DRM_MODE_ENCODER_TMDS;
3706 break;
3707 default:
3708 return -ENODEV;
3709 }
3710
3711 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
3712 if (!nv_encoder)
3713 return -ENOMEM;
3714 nv_encoder->dcb = dcbe;
3715 nv_encoder->or = ffs(dcbe->or) - 1;
3716 nv_encoder->i2c = ddc;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10003717 nv_encoder->aux = aux;
Ben Skeggseb6313a2013-02-11 09:52:58 +10003718
3719 encoder = to_drm_encoder(nv_encoder);
3720 encoder->possible_crtcs = dcbe->heads;
3721 encoder->possible_clones = 0;
Ben Skeggs5a223da2016-11-04 17:20:36 +10003722 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type,
3723 "pior-%04x-%04x", dcbe->hasht, dcbe->hashm);
Ben Skeggsf20c6652016-11-04 17:20:36 +10003724 drm_encoder_helper_add(encoder, &nv50_pior_help);
Ben Skeggseb6313a2013-02-11 09:52:58 +10003725
3726 drm_mode_connector_attach_encoder(connector, encoder);
3727 return 0;
3728}
3729
3730/******************************************************************************
Ben Skeggsab0af552014-08-10 04:10:19 +10003731 * Framebuffer
3732 *****************************************************************************/
3733
Ben Skeggs8a423642014-08-10 04:10:19 +10003734static void
Ben Skeggsab0af552014-08-10 04:10:19 +10003735nv50_fb_dtor(struct drm_framebuffer *fb)
3736{
3737}
3738
3739static int
3740nv50_fb_ctor(struct drm_framebuffer *fb)
3741{
3742 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
3743 struct nouveau_drm *drm = nouveau_drm(fb->dev);
3744 struct nouveau_bo *nvbo = nv_fb->nvbo;
Ben Skeggs8a423642014-08-10 04:10:19 +10003745 struct nv50_disp *disp = nv50_disp(fb->dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10003746 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
3747 u8 tile = nvbo->tile_mode;
Ben Skeggsaccdea22016-11-04 17:20:36 +10003748 struct drm_crtc *crtc;
Ben Skeggsab0af552014-08-10 04:10:19 +10003749
Ben Skeggs967e7bd2014-08-10 04:10:22 +10003750 if (drm->device.info.chipset >= 0xc0)
Ben Skeggs8a423642014-08-10 04:10:19 +10003751 tile >>= 4; /* yep.. */
3752
Ben Skeggsab0af552014-08-10 04:10:19 +10003753 switch (fb->depth) {
3754 case 8: nv_fb->r_format = 0x1e00; break;
3755 case 15: nv_fb->r_format = 0xe900; break;
3756 case 16: nv_fb->r_format = 0xe800; break;
3757 case 24:
3758 case 32: nv_fb->r_format = 0xcf00; break;
3759 case 30: nv_fb->r_format = 0xd100; break;
3760 default:
3761 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
3762 return -EINVAL;
3763 }
3764
Ben Skeggs648d4df2014-08-10 04:10:27 +10003765 if (disp->disp->oclass < G82_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10003766 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
3767 (fb->pitches[0] | 0x00100000);
3768 nv_fb->r_format |= kind << 16;
3769 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10003770 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10003771 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
3772 (fb->pitches[0] | 0x00100000);
Ben Skeggsab0af552014-08-10 04:10:19 +10003773 } else {
Ben Skeggs8a423642014-08-10 04:10:19 +10003774 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
3775 (fb->pitches[0] | 0x01000000);
Ben Skeggsab0af552014-08-10 04:10:19 +10003776 }
Ben Skeggs8a423642014-08-10 04:10:19 +10003777 nv_fb->r_handle = 0xffff0000 | kind;
Ben Skeggsab0af552014-08-10 04:10:19 +10003778
Ben Skeggsaccdea22016-11-04 17:20:36 +10003779 list_for_each_entry(crtc, &drm->dev->mode_config.crtc_list, head) {
3780 struct nv50_head *head = nv50_head(crtc);
3781 struct nv50_dmac_ctxdma *ctxdma;
3782
3783 ctxdma = nv50_dmac_ctxdma_new(&head->_base->chan.base,
3784 nv_fb->r_handle, nv_fb);
3785 if (IS_ERR(ctxdma))
3786 return PTR_ERR(ctxdma);
3787 }
3788
3789 return 0;
Ben Skeggsab0af552014-08-10 04:10:19 +10003790}
3791
3792/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10003793 * Init
3794 *****************************************************************************/
Ben Skeggsab0af552014-08-10 04:10:19 +10003795
Ben Skeggs2a44e492011-11-09 11:36:33 +10003796void
Ben Skeggse225f442012-11-21 14:40:21 +10003797nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10003798{
Ben Skeggs973f10c2016-11-04 17:20:36 +10003799 struct drm_plane *plane;
3800
3801 drm_for_each_plane(plane, dev) {
3802 struct nv50_wndw *wndw = nv50_wndw(plane);
3803 if (plane->funcs != &nv50_wndw)
3804 continue;
3805 nv50_wndw_fini(wndw);
3806 }
Ben Skeggs26f6d882011-07-04 16:25:18 +10003807}
3808
3809int
Ben Skeggse225f442012-11-21 14:40:21 +10003810nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10003811{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10003812 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs354d3502016-11-04 17:20:36 +10003813 struct drm_encoder *encoder;
Ben Skeggs973f10c2016-11-04 17:20:36 +10003814 struct drm_plane *plane;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10003815 struct drm_crtc *crtc;
3816 u32 *push;
3817
3818 push = evo_wait(nv50_mast(dev), 32);
3819 if (!push)
3820 return -EBUSY;
3821
3822 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Ben Skeggs973f10c2016-11-04 17:20:36 +10003823 struct nv50_wndw *wndw = &nv50_head(crtc)->_base->wndw;
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01003824
3825 nv50_crtc_lut_load(crtc);
Ben Skeggs973f10c2016-11-04 17:20:36 +10003826 nouveau_bo_wr32(disp->sync, wndw->sema / 4, wndw->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10003827 }
3828
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10003829 evo_mthd(push, 0x0088, 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10003830 evo_data(push, nv50_mast(dev)->base.sync.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10003831 evo_kick(push, nv50_mast(dev));
Ben Skeggs973f10c2016-11-04 17:20:36 +10003832
Ben Skeggs354d3502016-11-04 17:20:36 +10003833 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3834 if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
3835 const struct drm_encoder_helper_funcs *help;
3836 struct nouveau_encoder *nv_encoder;
3837
3838 nv_encoder = nouveau_encoder(encoder);
3839 if (nv_encoder->dcb->type == DCB_OUTPUT_DP)
3840 nv_encoder->dcb->type = DCB_OUTPUT_EOL;
3841
3842 help = encoder->helper_private;
3843 if (help && help->dpms)
3844 help->dpms(encoder, DRM_MODE_DPMS_ON);
3845
3846 if (nv_encoder->dcb->type == DCB_OUTPUT_EOL)
3847 nv_encoder->dcb->type = DCB_OUTPUT_DP;
3848 }
3849 }
3850
Ben Skeggs973f10c2016-11-04 17:20:36 +10003851 drm_for_each_plane(plane, dev) {
3852 struct nv50_wndw *wndw = nv50_wndw(plane);
3853 if (plane->funcs != &nv50_wndw)
3854 continue;
3855 nv50_wndw_init(wndw);
3856 }
3857
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10003858 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10003859}
3860
3861void
Ben Skeggse225f442012-11-21 14:40:21 +10003862nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10003863{
Ben Skeggse225f442012-11-21 14:40:21 +10003864 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10003865
Ben Skeggs0ad72862014-08-10 04:10:22 +10003866 nv50_dmac_destroy(&disp->mast.base, disp->disp);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10003867
Ben Skeggs816af2f2011-11-16 15:48:48 +10003868 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01003869 if (disp->sync)
3870 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10003871 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10003872
Ben Skeggs77145f12012-07-31 16:16:21 +10003873 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10003874 kfree(disp);
3875}
3876
3877int
Ben Skeggse225f442012-11-21 14:40:21 +10003878nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10003879{
Ben Skeggs967e7bd2014-08-10 04:10:22 +10003880 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggs77145f12012-07-31 16:16:21 +10003881 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10003882 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10003883 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10003884 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10003885 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10003886 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10003887
3888 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
3889 if (!disp)
3890 return -ENOMEM;
Ben Skeggs77145f12012-07-31 16:16:21 +10003891
3892 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10003893 nouveau_display(dev)->dtor = nv50_display_destroy;
3894 nouveau_display(dev)->init = nv50_display_init;
3895 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggsab0af552014-08-10 04:10:19 +10003896 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
3897 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
Ben Skeggs0ad72862014-08-10 04:10:22 +10003898 disp->disp = &nouveau_display(dev)->disp;
Ben Skeggs26f6d882011-07-04 16:25:18 +10003899
Ben Skeggsb5a794b2012-10-16 14:18:32 +10003900 /* small shared memory area we use for notifiers and semaphores */
3901 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01003902 0, 0x0000, NULL, NULL, &disp->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10003903 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10003904 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01003905 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10003906 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01003907 if (ret)
3908 nouveau_bo_unpin(disp->sync);
3909 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10003910 if (ret)
3911 nouveau_bo_ref(NULL, &disp->sync);
3912 }
3913
3914 if (ret)
3915 goto out;
3916
Ben Skeggsb5a794b2012-10-16 14:18:32 +10003917 /* allocate master evo channel */
Ben Skeggsa01ca782015-08-20 14:54:15 +10003918 ret = nv50_core_create(device, disp->disp, disp->sync->bo.offset,
Ben Skeggs410f3ec2014-08-10 04:10:25 +10003919 &disp->mast);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10003920 if (ret)
3921 goto out;
3922
Ben Skeggs438d99e2011-07-05 16:48:06 +10003923 /* create crtc objects to represent the hw heads */
Ben Skeggs648d4df2014-08-10 04:10:27 +10003924 if (disp->disp->oclass >= GF110_DISP)
Ben Skeggsa01ca782015-08-20 14:54:15 +10003925 crtcs = nvif_rd32(&device->object, 0x022448);
Ben Skeggs63718a02012-11-16 11:44:14 +10003926 else
3927 crtcs = 2;
3928
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10003929 for (i = 0; i < crtcs; i++) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10003930 ret = nv50_crtc_create(dev, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10003931 if (ret)
3932 goto out;
3933 }
3934
Ben Skeggs83fc0832011-07-05 13:08:40 +10003935 /* create encoder/connector objects based on VBIOS DCB table */
3936 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
3937 connector = nouveau_connector_create(dev, dcbe->connector);
3938 if (IS_ERR(connector))
3939 continue;
3940
Ben Skeggseb6313a2013-02-11 09:52:58 +10003941 if (dcbe->location == DCB_LOC_ON_CHIP) {
3942 switch (dcbe->type) {
3943 case DCB_OUTPUT_TMDS:
3944 case DCB_OUTPUT_LVDS:
3945 case DCB_OUTPUT_DP:
3946 ret = nv50_sor_create(connector, dcbe);
3947 break;
3948 case DCB_OUTPUT_ANALOG:
3949 ret = nv50_dac_create(connector, dcbe);
3950 break;
3951 default:
3952 ret = -ENODEV;
3953 break;
3954 }
3955 } else {
3956 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10003957 }
3958
Ben Skeggseb6313a2013-02-11 09:52:58 +10003959 if (ret) {
3960 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
3961 dcbe->location, dcbe->type,
3962 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10003963 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10003964 }
3965 }
3966
3967 /* cull any connectors we created that don't have an encoder */
3968 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
3969 if (connector->encoder_ids[0])
3970 continue;
3971
Ben Skeggs77145f12012-07-31 16:16:21 +10003972 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03003973 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10003974 connector->funcs->destroy(connector);
3975 }
3976
Ben Skeggs26f6d882011-07-04 16:25:18 +10003977out:
3978 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10003979 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10003980 return ret;
3981}