blob: c56775f5aff39490c1cbd2c1e48f12207bca3fef [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>
28#include <drm/drm_crtc_helper.h>
Daniel Vetter3cb9ae42014-10-29 10:03:57 +010029#include <drm/drm_plane_helper.h>
Ben Skeggs48743222014-05-31 01:48:06 +100030#include <drm/drm_dp_helper.h>
Ben Skeggs26f6d882011-07-04 16:25:18 +100031
Ben Skeggsfdb751e2014-08-10 04:10:23 +100032#include <nvif/class.h>
33
Ben Skeggs77145f12012-07-31 16:16:21 +100034#include "nouveau_drm.h"
35#include "nouveau_dma.h"
36#include "nouveau_gem.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100037#include "nouveau_connector.h"
38#include "nouveau_encoder.h"
39#include "nouveau_crtc.h"
Ben Skeggsf589be82012-07-22 11:55:54 +100040#include "nouveau_fence.h"
Ben Skeggs3a89cd02011-07-07 10:47:10 +100041#include "nv50_display.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100042
Ben Skeggs8a464382011-11-12 23:52:07 +100043#define EVO_DMA_NR 9
44
Ben Skeggsbdb8c212011-11-12 01:30:24 +100045#define EVO_MASTER (0x00)
Ben Skeggsa63a97e2011-11-16 15:22:34 +100046#define EVO_FLIP(c) (0x01 + (c))
Ben Skeggs8a464382011-11-12 23:52:07 +100047#define EVO_OVLY(c) (0x05 + (c))
48#define EVO_OIMM(c) (0x09 + (c))
Ben Skeggsbdb8c212011-11-12 01:30:24 +100049#define EVO_CURS(c) (0x0d + (c))
50
Ben Skeggs816af2f2011-11-16 15:48:48 +100051/* offsets in shared sync bo of various structures */
52#define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +100053#define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
54#define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
55#define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
Ben Skeggs816af2f2011-11-16 15:48:48 +100056
Ben Skeggsb5a794b2012-10-16 14:18:32 +100057/******************************************************************************
58 * EVO channel
59 *****************************************************************************/
60
Ben Skeggse225f442012-11-21 14:40:21 +100061struct nv50_chan {
Ben Skeggs0ad72862014-08-10 04:10:22 +100062 struct nvif_object user;
Ben Skeggsb5a794b2012-10-16 14:18:32 +100063};
64
65static int
Ben Skeggs410f3ec2014-08-10 04:10:25 +100066nv50_chan_create(struct nvif_object *disp, const u32 *oclass, u8 head,
Ben Skeggse225f442012-11-21 14:40:21 +100067 void *data, u32 size, struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100068{
Ben Skeggs6af52892014-11-03 15:01:33 +100069 const u32 handle = (oclass[0] << 16) | head;
70 u32 sclass[8];
71 int ret, i;
72
73 ret = nvif_object_sclass(disp, sclass, ARRAY_SIZE(sclass));
74 WARN_ON(ret > ARRAY_SIZE(sclass));
75 if (ret < 0)
76 return ret;
77
Ben Skeggs410f3ec2014-08-10 04:10:25 +100078 while (oclass[0]) {
Ben Skeggs6af52892014-11-03 15:01:33 +100079 for (i = 0; i < ARRAY_SIZE(sclass); i++) {
80 if (sclass[i] == oclass[0]) {
81 ret = nvif_object_init(disp, NULL, handle,
82 oclass[0], data, size,
83 &chan->user);
84 if (ret == 0)
85 nvif_object_map(&chan->user);
86 return ret;
87 }
Ben Skeggsb76f1522014-08-10 04:10:28 +100088 }
Ben Skeggs6af52892014-11-03 15:01:33 +100089 oclass++;
Ben Skeggs410f3ec2014-08-10 04:10:25 +100090 }
Ben Skeggs6af52892014-11-03 15:01:33 +100091
Ben Skeggs410f3ec2014-08-10 04:10:25 +100092 return -ENOSYS;
Ben Skeggsb5a794b2012-10-16 14:18:32 +100093}
94
95static void
Ben Skeggs0ad72862014-08-10 04:10:22 +100096nv50_chan_destroy(struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100097{
Ben Skeggs0ad72862014-08-10 04:10:22 +100098 nvif_object_fini(&chan->user);
Ben Skeggsb5a794b2012-10-16 14:18:32 +100099}
100
101/******************************************************************************
102 * PIO EVO channel
103 *****************************************************************************/
104
Ben Skeggse225f442012-11-21 14:40:21 +1000105struct nv50_pioc {
106 struct nv50_chan base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000107};
108
109static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000110nv50_pioc_destroy(struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000111{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000112 nv50_chan_destroy(&pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000113}
114
115static int
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000116nv50_pioc_create(struct nvif_object *disp, const u32 *oclass, u8 head,
Ben Skeggse225f442012-11-21 14:40:21 +1000117 void *data, u32 size, struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000118{
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000119 return nv50_chan_create(disp, oclass, head, data, size, &pioc->base);
120}
121
122/******************************************************************************
123 * Cursor Immediate
124 *****************************************************************************/
125
126struct nv50_curs {
127 struct nv50_pioc base;
128};
129
130static int
131nv50_curs_create(struct nvif_object *disp, int head, struct nv50_curs *curs)
132{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000133 struct nv50_disp_cursor_v0 args = {
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000134 .head = head,
135 };
136 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000137 GK104_DISP_CURSOR,
138 GF110_DISP_CURSOR,
139 GT214_DISP_CURSOR,
140 G82_DISP_CURSOR,
141 NV50_DISP_CURSOR,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000142 0
143 };
144
145 return nv50_pioc_create(disp, oclass, head, &args, sizeof(args),
146 &curs->base);
147}
148
149/******************************************************************************
150 * Overlay Immediate
151 *****************************************************************************/
152
153struct nv50_oimm {
154 struct nv50_pioc base;
155};
156
157static int
158nv50_oimm_create(struct nvif_object *disp, int head, struct nv50_oimm *oimm)
159{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000160 struct nv50_disp_cursor_v0 args = {
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000161 .head = head,
162 };
163 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000164 GK104_DISP_OVERLAY,
165 GF110_DISP_OVERLAY,
166 GT214_DISP_OVERLAY,
167 G82_DISP_OVERLAY,
168 NV50_DISP_OVERLAY,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000169 0
170 };
171
172 return nv50_pioc_create(disp, oclass, head, &args, sizeof(args),
173 &oimm->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000174}
175
176/******************************************************************************
177 * DMA EVO channel
178 *****************************************************************************/
179
Ben Skeggse225f442012-11-21 14:40:21 +1000180struct nv50_dmac {
181 struct nv50_chan base;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000182 dma_addr_t handle;
183 u32 *ptr;
Daniel Vetter59ad1462012-12-02 14:49:44 +0100184
Ben Skeggs0ad72862014-08-10 04:10:22 +1000185 struct nvif_object sync;
186 struct nvif_object vram;
187
Daniel Vetter59ad1462012-12-02 14:49:44 +0100188 /* Protects against concurrent pushbuf access to this channel, lock is
189 * grabbed by evo_wait (if the pushbuf reservation is successful) and
190 * dropped again by evo_kick. */
191 struct mutex lock;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000192};
193
194static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000195nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000196{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000197 nvif_object_fini(&dmac->vram);
198 nvif_object_fini(&dmac->sync);
199
200 nv50_chan_destroy(&dmac->base);
201
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000202 if (dmac->ptr) {
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000203 struct pci_dev *pdev = nvxx_device(nvif_device(disp))->pdev;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000204 pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle);
205 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000206}
207
208static int
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000209nv50_dmac_create(struct nvif_object *disp, const u32 *oclass, u8 head,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000210 void *data, u32 size, u64 syncbuf,
Ben Skeggse225f442012-11-21 14:40:21 +1000211 struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000212{
Ben Skeggsf392ec42014-08-10 04:10:28 +1000213 struct nvif_device *device = nvif_device(disp);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000214 struct nv50_disp_core_channel_dma_v0 *args = data;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000215 struct nvif_object pushbuf;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000216 int ret;
217
Daniel Vetter59ad1462012-12-02 14:49:44 +0100218 mutex_init(&dmac->lock);
219
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000220 dmac->ptr = pci_alloc_consistent(nvxx_device(device)->pdev,
Ben Skeggs0ad72862014-08-10 04:10:22 +1000221 PAGE_SIZE, &dmac->handle);
Ben Skeggs47057302012-11-16 13:58:48 +1000222 if (!dmac->ptr)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000223 return -ENOMEM;
224
Ben Skeggsf392ec42014-08-10 04:10:28 +1000225 ret = nvif_object_init(nvif_object(device), NULL,
Ben Skeggs648d4df2014-08-10 04:10:27 +1000226 args->pushbuf, NV_DMA_FROM_MEMORY,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000227 &(struct nv_dma_v0) {
228 .target = NV_DMA_V0_TARGET_PCI_US,
229 .access = NV_DMA_V0_ACCESS_RD,
Ben Skeggs47057302012-11-16 13:58:48 +1000230 .start = dmac->handle + 0x0000,
231 .limit = dmac->handle + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000232 }, sizeof(struct nv_dma_v0), &pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000233 if (ret)
234 return ret;
235
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000236 ret = nv50_chan_create(disp, oclass, head, data, size, &dmac->base);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000237 nvif_object_fini(&pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000238 if (ret)
239 return ret;
240
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000241 ret = nvif_object_init(&dmac->base.user, NULL, 0xf0000000,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000242 NV_DMA_IN_MEMORY,
243 &(struct nv_dma_v0) {
244 .target = NV_DMA_V0_TARGET_VRAM,
245 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000246 .start = syncbuf + 0x0000,
247 .limit = syncbuf + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000248 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000249 &dmac->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000250 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000251 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000252
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000253 ret = nvif_object_init(&dmac->base.user, NULL, 0xf0000001,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000254 NV_DMA_IN_MEMORY,
255 &(struct nv_dma_v0) {
256 .target = NV_DMA_V0_TARGET_VRAM,
257 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000258 .start = 0,
Ben Skeggsf392ec42014-08-10 04:10:28 +1000259 .limit = device->info.ram_user - 1,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000260 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000261 &dmac->vram);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000262 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000263 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000264
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000265 return ret;
266}
267
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000268/******************************************************************************
269 * Core
270 *****************************************************************************/
271
Ben Skeggse225f442012-11-21 14:40:21 +1000272struct nv50_mast {
273 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000274};
275
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000276static int
277nv50_core_create(struct nvif_object *disp, u64 syncbuf, struct nv50_mast *core)
278{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000279 struct nv50_disp_core_channel_dma_v0 args = {
280 .pushbuf = 0xb0007d00,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000281 };
282 static const u32 oclass[] = {
Ben Skeggsdbbd6bc2014-08-19 10:23:47 +1000283 GM204_DISP_CORE_CHANNEL_DMA,
Ben Skeggs648d4df2014-08-10 04:10:27 +1000284 GM107_DISP_CORE_CHANNEL_DMA,
285 GK110_DISP_CORE_CHANNEL_DMA,
286 GK104_DISP_CORE_CHANNEL_DMA,
287 GF110_DISP_CORE_CHANNEL_DMA,
288 GT214_DISP_CORE_CHANNEL_DMA,
289 GT206_DISP_CORE_CHANNEL_DMA,
290 GT200_DISP_CORE_CHANNEL_DMA,
291 G82_DISP_CORE_CHANNEL_DMA,
292 NV50_DISP_CORE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000293 0
294 };
295
296 return nv50_dmac_create(disp, oclass, 0, &args, sizeof(args), syncbuf,
297 &core->base);
298}
299
300/******************************************************************************
301 * Base
302 *****************************************************************************/
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000303
Ben Skeggse225f442012-11-21 14:40:21 +1000304struct nv50_sync {
305 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000306 u32 addr;
307 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000308};
309
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000310static int
311nv50_base_create(struct nvif_object *disp, int head, u64 syncbuf,
312 struct nv50_sync *base)
313{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000314 struct nv50_disp_base_channel_dma_v0 args = {
315 .pushbuf = 0xb0007c00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000316 .head = head,
317 };
318 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000319 GK110_DISP_BASE_CHANNEL_DMA,
320 GK104_DISP_BASE_CHANNEL_DMA,
321 GF110_DISP_BASE_CHANNEL_DMA,
322 GT214_DISP_BASE_CHANNEL_DMA,
323 GT200_DISP_BASE_CHANNEL_DMA,
324 G82_DISP_BASE_CHANNEL_DMA,
325 NV50_DISP_BASE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000326 0
327 };
328
329 return nv50_dmac_create(disp, oclass, head, &args, sizeof(args),
330 syncbuf, &base->base);
331}
332
333/******************************************************************************
334 * Overlay
335 *****************************************************************************/
336
Ben Skeggse225f442012-11-21 14:40:21 +1000337struct nv50_ovly {
338 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000339};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000340
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000341static int
342nv50_ovly_create(struct nvif_object *disp, int head, u64 syncbuf,
343 struct nv50_ovly *ovly)
344{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000345 struct nv50_disp_overlay_channel_dma_v0 args = {
346 .pushbuf = 0xb0007e00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000347 .head = head,
348 };
349 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000350 GK104_DISP_OVERLAY_CONTROL_DMA,
351 GF110_DISP_OVERLAY_CONTROL_DMA,
352 GT214_DISP_OVERLAY_CHANNEL_DMA,
353 GT200_DISP_OVERLAY_CHANNEL_DMA,
354 G82_DISP_OVERLAY_CHANNEL_DMA,
355 NV50_DISP_OVERLAY_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000356 0
357 };
358
359 return nv50_dmac_create(disp, oclass, head, &args, sizeof(args),
360 syncbuf, &ovly->base);
361}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000362
Ben Skeggse225f442012-11-21 14:40:21 +1000363struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000364 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000365 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000366 struct nv50_curs curs;
367 struct nv50_sync sync;
368 struct nv50_ovly ovly;
369 struct nv50_oimm oimm;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000370};
371
Ben Skeggse225f442012-11-21 14:40:21 +1000372#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
373#define nv50_curs(c) (&nv50_head(c)->curs)
374#define nv50_sync(c) (&nv50_head(c)->sync)
375#define nv50_ovly(c) (&nv50_head(c)->ovly)
376#define nv50_oimm(c) (&nv50_head(c)->oimm)
377#define nv50_chan(c) (&(c)->base.base)
Ben Skeggs0ad72862014-08-10 04:10:22 +1000378#define nv50_vers(c) nv50_chan(c)->user.oclass
379
380struct nv50_fbdma {
381 struct list_head head;
382 struct nvif_object core;
383 struct nvif_object base[4];
384};
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000385
Ben Skeggse225f442012-11-21 14:40:21 +1000386struct nv50_disp {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000387 struct nvif_object *disp;
Ben Skeggse225f442012-11-21 14:40:21 +1000388 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000389
Ben Skeggs8a423642014-08-10 04:10:19 +1000390 struct list_head fbdma;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000391
392 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000393};
394
Ben Skeggse225f442012-11-21 14:40:21 +1000395static struct nv50_disp *
396nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000397{
Ben Skeggs77145f12012-07-31 16:16:21 +1000398 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000399}
400
Ben Skeggse225f442012-11-21 14:40:21 +1000401#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000402
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000403static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000404nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000405{
406 return nouveau_encoder(encoder)->crtc;
407}
408
409/******************************************************************************
410 * EVO channel helpers
411 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000412static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000413evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000414{
Ben Skeggse225f442012-11-21 14:40:21 +1000415 struct nv50_dmac *dmac = evoc;
Ben Skeggs54442042015-08-20 14:54:11 +1000416 struct nvif_device *device = nvif_device(&dmac->base.user);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000417 u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000418
Daniel Vetter59ad1462012-12-02 14:49:44 +0100419 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000420 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000421 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000422
Ben Skeggs0ad72862014-08-10 04:10:22 +1000423 nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
Ben Skeggs54442042015-08-20 14:54:11 +1000424 if (nvif_msec(device, 2000,
425 if (!nvif_rd32(&dmac->base.user, 0x0004))
426 break;
427 ) < 0) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100428 mutex_unlock(&dmac->lock);
Ben Skeggs9ad97ed2015-08-20 14:54:13 +1000429 printk(KERN_ERR "nouveau: evo channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000430 return NULL;
431 }
432
433 put = 0;
434 }
435
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000436 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000437}
438
439static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000440evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000441{
Ben Skeggse225f442012-11-21 14:40:21 +1000442 struct nv50_dmac *dmac = evoc;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000443 nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100444 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000445}
446
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000447#if 1
Ben Skeggs51beb422011-07-05 10:33:08 +1000448#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
449#define evo_data(p,d) *((p)++) = (d)
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000450#else
451#define evo_mthd(p,m,s) do { \
452 const u32 _m = (m), _s = (s); \
453 printk(KERN_ERR "%04x %d %s\n", _m, _s, __func__); \
454 *((p)++) = ((_s << 18) | _m); \
455} while(0)
456#define evo_data(p,d) do { \
457 const u32 _d = (d); \
458 printk(KERN_ERR "\t%08x\n", _d); \
459 *((p)++) = _d; \
460} while(0)
461#endif
Ben Skeggs51beb422011-07-05 10:33:08 +1000462
Ben Skeggs3376ee32011-11-12 14:28:12 +1000463static bool
464evo_sync_wait(void *data)
465{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500466 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
467 return true;
468 usleep_range(1, 2);
469 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000470}
471
472static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000473evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000474{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000475 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggse225f442012-11-21 14:40:21 +1000476 struct nv50_disp *disp = nv50_disp(dev);
477 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000478 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000479 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000480 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000481 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000482 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000483 evo_mthd(push, 0x0080, 2);
484 evo_data(push, 0x00000000);
485 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000486 evo_kick(push, mast);
Ben Skeggs54442042015-08-20 14:54:11 +1000487 if (nvif_msec(device, 2000,
488 if (evo_sync_wait(disp->sync))
489 break;
490 ) >= 0)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000491 return 0;
492 }
493
494 return -EBUSY;
495}
496
497/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +1000498 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +1000499 *****************************************************************************/
500struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +1000501nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000502{
Ben Skeggse225f442012-11-21 14:40:21 +1000503 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000504}
505
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000506struct nv50_display_flip {
507 struct nv50_disp *disp;
508 struct nv50_sync *chan;
509};
510
511static bool
512nv50_display_flip_wait(void *data)
513{
514 struct nv50_display_flip *flip = data;
515 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
Calvin Owensb1ea3e62013-04-07 21:01:19 -0500516 flip->chan->data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000517 return true;
518 usleep_range(1, 2);
519 return false;
520}
521
Ben Skeggs3376ee32011-11-12 14:28:12 +1000522void
Ben Skeggse225f442012-11-21 14:40:21 +1000523nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000524{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000525 struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000526 struct nv50_display_flip flip = {
527 .disp = nv50_disp(crtc->dev),
528 .chan = nv50_sync(crtc),
529 };
Ben Skeggs3376ee32011-11-12 14:28:12 +1000530 u32 *push;
531
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000532 push = evo_wait(flip.chan, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000533 if (push) {
534 evo_mthd(push, 0x0084, 1);
535 evo_data(push, 0x00000000);
536 evo_mthd(push, 0x0094, 1);
537 evo_data(push, 0x00000000);
538 evo_mthd(push, 0x00c0, 1);
539 evo_data(push, 0x00000000);
540 evo_mthd(push, 0x0080, 1);
541 evo_data(push, 0x00000000);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000542 evo_kick(push, flip.chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000543 }
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000544
Ben Skeggs54442042015-08-20 14:54:11 +1000545 nvif_msec(device, 2000,
546 if (nv50_display_flip_wait(&flip))
547 break;
548 );
Ben Skeggs3376ee32011-11-12 14:28:12 +1000549}
550
551int
Ben Skeggse225f442012-11-21 14:40:21 +1000552nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +1000553 struct nouveau_channel *chan, u32 swap_interval)
554{
555 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000556 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000557 struct nv50_head *head = nv50_head(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000558 struct nv50_sync *sync = nv50_sync(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000559 u32 *push;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000560 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000561
Ben Skeggs9ba83102014-12-22 19:50:23 +1000562 if (crtc->primary->fb->width != fb->width ||
563 crtc->primary->fb->height != fb->height)
564 return -EINVAL;
565
Ben Skeggs3376ee32011-11-12 14:28:12 +1000566 swap_interval <<= 4;
567 if (swap_interval == 0)
568 swap_interval |= 0x100;
Ben Skeggsf60b6e72013-03-19 15:20:00 +1000569 if (chan == NULL)
570 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000571
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000572 push = evo_wait(sync, 128);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000573 if (unlikely(push == NULL))
574 return -EBUSY;
575
Ben Skeggsbbf89062014-08-10 04:10:25 +1000576 if (chan && chan->object->oclass < G82_CHANNEL_GPFIFO) {
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000577 ret = RING_SPACE(chan, 8);
578 if (ret)
579 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000580
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000581 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000582 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000583 OUT_RING (chan, sync->addr ^ 0x10);
584 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
585 OUT_RING (chan, sync->data + 1);
586 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
587 OUT_RING (chan, sync->addr);
588 OUT_RING (chan, sync->data);
589 } else
Ben Skeggsbbf89062014-08-10 04:10:25 +1000590 if (chan && chan->object->oclass < FERMI_CHANNEL_GPFIFO) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000591 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000592 ret = RING_SPACE(chan, 12);
593 if (ret)
594 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +1000595
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000596 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000597 OUT_RING (chan, chan->vram.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000598 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
599 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
600 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
601 OUT_RING (chan, sync->data + 1);
602 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
603 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
604 OUT_RING (chan, upper_32_bits(addr));
605 OUT_RING (chan, lower_32_bits(addr));
606 OUT_RING (chan, sync->data);
607 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
608 } else
609 if (chan) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000610 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000611 ret = RING_SPACE(chan, 10);
612 if (ret)
613 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000614
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000615 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
616 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
617 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
618 OUT_RING (chan, sync->data + 1);
619 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
620 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
621 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
622 OUT_RING (chan, upper_32_bits(addr));
623 OUT_RING (chan, lower_32_bits(addr));
624 OUT_RING (chan, sync->data);
625 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
626 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
627 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -0500628
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000629 if (chan) {
630 sync->addr ^= 0x10;
631 sync->data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000632 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000633 }
634
635 /* queue the flip */
636 evo_mthd(push, 0x0100, 1);
637 evo_data(push, 0xfffe0000);
638 evo_mthd(push, 0x0084, 1);
639 evo_data(push, swap_interval);
640 if (!(swap_interval & 0x00000100)) {
641 evo_mthd(push, 0x00e0, 1);
642 evo_data(push, 0x40000000);
643 }
644 evo_mthd(push, 0x0088, 4);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000645 evo_data(push, sync->addr);
646 evo_data(push, sync->data++);
647 evo_data(push, sync->data);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000648 evo_data(push, sync->base.sync.handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000649 evo_mthd(push, 0x00a0, 2);
650 evo_data(push, 0x00000000);
651 evo_data(push, 0x00000000);
652 evo_mthd(push, 0x00c0, 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000653 evo_data(push, nv_fb->r_handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000654 evo_mthd(push, 0x0110, 2);
655 evo_data(push, 0x00000000);
656 evo_data(push, 0x00000000);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000657 if (nv50_vers(sync) < GF110_DISP_BASE_CHANNEL_DMA) {
Ben Skeggsed5085a52012-11-16 13:16:51 +1000658 evo_mthd(push, 0x0800, 5);
659 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
660 evo_data(push, 0);
661 evo_data(push, (fb->height << 16) | fb->width);
662 evo_data(push, nv_fb->r_pitch);
663 evo_data(push, nv_fb->r_format);
664 } else {
665 evo_mthd(push, 0x0400, 5);
666 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
667 evo_data(push, 0);
668 evo_data(push, (fb->height << 16) | fb->width);
669 evo_data(push, nv_fb->r_pitch);
670 evo_data(push, nv_fb->r_format);
671 }
Ben Skeggs3376ee32011-11-12 14:28:12 +1000672 evo_mthd(push, 0x0080, 1);
673 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000674 evo_kick(push, sync);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000675
676 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000677 return 0;
678}
679
Ben Skeggs26f6d882011-07-04 16:25:18 +1000680/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000681 * CRTC
682 *****************************************************************************/
683static int
Ben Skeggse225f442012-11-21 14:40:21 +1000684nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000685{
Ben Skeggse225f442012-11-21 14:40:21 +1000686 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde691852011-10-17 12:23:41 +1000687 struct nouveau_connector *nv_connector;
688 struct drm_connector *connector;
689 u32 *push, mode = 0x00;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000690
Ben Skeggs488ff202011-10-17 10:38:10 +1000691 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +1000692 connector = &nv_connector->base;
693 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
Matt Roperf4510a22014-04-01 15:22:40 -0700694 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
Ben Skeggsde691852011-10-17 12:23:41 +1000695 mode = DITHERING_MODE_DYNAMIC2X2;
696 } else {
697 mode = nv_connector->dithering_mode;
698 }
699
700 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
701 if (connector->display_info.bpc >= 8)
702 mode |= DITHERING_DEPTH_8BPC;
703 } else {
704 mode |= nv_connector->dithering_depth;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000705 }
706
Ben Skeggsde8268c2012-11-16 10:24:31 +1000707 push = evo_wait(mast, 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000708 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000709 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000710 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
711 evo_data(push, mode);
712 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000713 if (nv50_vers(mast) < GK104_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000714 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
715 evo_data(push, mode);
716 } else {
717 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
718 evo_data(push, mode);
719 }
720
Ben Skeggs438d99e2011-07-05 16:48:06 +1000721 if (update) {
722 evo_mthd(push, 0x0080, 1);
723 evo_data(push, 0x00000000);
724 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000725 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000726 }
727
728 return 0;
729}
730
731static int
Ben Skeggse225f442012-11-21 14:40:21 +1000732nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000733{
Ben Skeggse225f442012-11-21 14:40:21 +1000734 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs92854622011-11-11 23:49:06 +1000735 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000736 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000737 struct nouveau_connector *nv_connector;
Ben Skeggs92854622011-11-11 23:49:06 +1000738 int mode = DRM_MODE_SCALE_NONE;
739 u32 oX, oY, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000740
Ben Skeggs92854622011-11-11 23:49:06 +1000741 /* start off at the resolution we programmed the crtc for, this
742 * effectively handles NONE/FULL scaling
743 */
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000744 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs576f7912014-12-22 17:19:26 +1000745 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs92854622011-11-11 23:49:06 +1000746 mode = nv_connector->scaling_mode;
Ben Skeggs576f7912014-12-22 17:19:26 +1000747 if (nv_connector->scaling_full) /* non-EDID LVDS/eDP mode */
748 mode = DRM_MODE_SCALE_FULLSCREEN;
749 }
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000750
Ben Skeggs92854622011-11-11 23:49:06 +1000751 if (mode != DRM_MODE_SCALE_NONE)
752 omode = nv_connector->native_mode;
753 else
754 omode = umode;
755
756 oX = omode->hdisplay;
757 oY = omode->vdisplay;
758 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
759 oY *= 2;
760
761 /* add overscan compensation if necessary, will keep the aspect
762 * ratio the same as the backend mode unless overridden by the
763 * user setting both hborder and vborder properties.
764 */
765 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
766 (nv_connector->underscan == UNDERSCAN_AUTO &&
767 nv_connector->edid &&
768 drm_detect_hdmi_monitor(nv_connector->edid)))) {
769 u32 bX = nv_connector->underscan_hborder;
770 u32 bY = nv_connector->underscan_vborder;
771 u32 aspect = (oY << 19) / oX;
772
773 if (bX) {
774 oX -= (bX * 2);
775 if (bY) oY -= (bY * 2);
776 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
777 } else {
778 oX -= (oX >> 4) + 32;
779 if (bY) oY -= (bY * 2);
780 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000781 }
782 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000783
Ben Skeggs92854622011-11-11 23:49:06 +1000784 /* handle CENTER/ASPECT scaling, taking into account the areas
785 * removed already for overscan compensation
786 */
787 switch (mode) {
788 case DRM_MODE_SCALE_CENTER:
789 oX = min((u32)umode->hdisplay, oX);
790 oY = min((u32)umode->vdisplay, oY);
791 /* fall-through */
792 case DRM_MODE_SCALE_ASPECT:
793 if (oY < oX) {
794 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
795 oX = ((oY * aspect) + (aspect / 2)) >> 19;
796 } else {
797 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
798 oY = ((oX * aspect) + (aspect / 2)) >> 19;
799 }
800 break;
801 default:
802 break;
803 }
804
Ben Skeggsde8268c2012-11-16 10:24:31 +1000805 push = evo_wait(mast, 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000806 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000807 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000808 /*XXX: SCALE_CTRL_ACTIVE??? */
809 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
810 evo_data(push, (oY << 16) | oX);
811 evo_data(push, (oY << 16) | oX);
812 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
813 evo_data(push, 0x00000000);
814 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
815 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
816 } else {
817 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
818 evo_data(push, (oY << 16) | oX);
819 evo_data(push, (oY << 16) | oX);
820 evo_data(push, (oY << 16) | oX);
821 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
822 evo_data(push, 0x00000000);
823 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
824 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
825 }
826
827 evo_kick(push, mast);
828
Ben Skeggs3376ee32011-11-12 14:28:12 +1000829 if (update) {
Ben Skeggse225f442012-11-21 14:40:21 +1000830 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700831 nv50_display_flip_next(crtc, crtc->primary->fb,
832 NULL, 1);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000833 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000834 }
835
836 return 0;
837}
838
839static int
Roy Splieteae73822014-10-30 22:57:45 +0100840nv50_crtc_set_raster_vblank_dmi(struct nouveau_crtc *nv_crtc, u32 usec)
841{
842 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
843 u32 *push;
844
845 push = evo_wait(mast, 8);
846 if (!push)
847 return -ENOMEM;
848
849 evo_mthd(push, 0x0828 + (nv_crtc->index * 0x400), 1);
850 evo_data(push, usec);
851 evo_kick(push, mast);
852 return 0;
853}
854
855static int
Ben Skeggse225f442012-11-21 14:40:21 +1000856nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +1000857{
Ben Skeggse225f442012-11-21 14:40:21 +1000858 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsf9887d02012-11-21 13:03:42 +1000859 u32 *push, hue, vib;
860 int adj;
861
862 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
863 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
864 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
865
866 push = evo_wait(mast, 16);
867 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000868 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsf9887d02012-11-21 13:03:42 +1000869 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
870 evo_data(push, (hue << 20) | (vib << 8));
871 } else {
872 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
873 evo_data(push, (hue << 20) | (vib << 8));
874 }
875
876 if (update) {
877 evo_mthd(push, 0x0080, 1);
878 evo_data(push, 0x00000000);
879 }
880 evo_kick(push, mast);
881 }
882
883 return 0;
884}
885
886static int
Ben Skeggse225f442012-11-21 14:40:21 +1000887nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000888 int x, int y, bool update)
889{
890 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggse225f442012-11-21 14:40:21 +1000891 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000892 u32 *push;
893
Ben Skeggsde8268c2012-11-16 10:24:31 +1000894 push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000895 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000896 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000897 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
898 evo_data(push, nvfb->nvbo->bo.offset >> 8);
899 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
900 evo_data(push, (fb->height << 16) | fb->width);
901 evo_data(push, nvfb->r_pitch);
902 evo_data(push, nvfb->r_format);
903 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
904 evo_data(push, (y << 16) | x);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000905 if (nv50_vers(mast) > NV50_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000906 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000907 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000908 }
909 } else {
910 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
911 evo_data(push, nvfb->nvbo->bo.offset >> 8);
912 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
913 evo_data(push, (fb->height << 16) | fb->width);
914 evo_data(push, nvfb->r_pitch);
915 evo_data(push, nvfb->r_format);
Ben Skeggs8a423642014-08-10 04:10:19 +1000916 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000917 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
918 evo_data(push, (y << 16) | x);
919 }
920
Ben Skeggsa46232e2011-07-07 15:23:48 +1000921 if (update) {
922 evo_mthd(push, 0x0080, 1);
923 evo_data(push, 0x00000000);
924 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000925 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000926 }
927
Ben Skeggs8a423642014-08-10 04:10:19 +1000928 nv_crtc->fb.handle = nvfb->r_handle;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000929 return 0;
930}
931
932static void
Ben Skeggse225f442012-11-21 14:40:21 +1000933nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000934{
Ben Skeggse225f442012-11-21 14:40:21 +1000935 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000936 u32 *push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000937 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000938 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000939 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
940 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100941 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000942 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000943 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000944 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
945 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100946 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000947 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000948 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000949 } else {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000950 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
951 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100952 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000953 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000954 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000955 }
956 evo_kick(push, mast);
957 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100958 nv_crtc->cursor.visible = true;
Ben Skeggsde8268c2012-11-16 10:24:31 +1000959}
960
961static void
Ben Skeggse225f442012-11-21 14:40:21 +1000962nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000963{
Ben Skeggse225f442012-11-21 14:40:21 +1000964 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000965 u32 *push = evo_wait(mast, 16);
966 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000967 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000968 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
969 evo_data(push, 0x05000000);
970 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000971 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000972 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
973 evo_data(push, 0x05000000);
974 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
975 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000976 } else {
977 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
978 evo_data(push, 0x05000000);
979 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
980 evo_data(push, 0x00000000);
981 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000982 evo_kick(push, mast);
983 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100984 nv_crtc->cursor.visible = false;
Ben Skeggsde8268c2012-11-16 10:24:31 +1000985}
Ben Skeggs438d99e2011-07-05 16:48:06 +1000986
Ben Skeggsde8268c2012-11-16 10:24:31 +1000987static void
Ben Skeggse225f442012-11-21 14:40:21 +1000988nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000989{
Ben Skeggse225f442012-11-21 14:40:21 +1000990 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000991
Ben Skeggs697bb722015-07-28 17:20:57 +1000992 if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled)
Ben Skeggse225f442012-11-21 14:40:21 +1000993 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000994 else
Ben Skeggse225f442012-11-21 14:40:21 +1000995 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000996
997 if (update) {
998 u32 *push = evo_wait(mast, 2);
999 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001000 evo_mthd(push, 0x0080, 1);
1001 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001002 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001003 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001004 }
1005}
1006
1007static void
Ben Skeggse225f442012-11-21 14:40:21 +10001008nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001009{
1010}
1011
1012static void
Ben Skeggse225f442012-11-21 14:40:21 +10001013nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001014{
1015 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001016 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001017 u32 *push;
1018
Ben Skeggse225f442012-11-21 14:40:21 +10001019 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001020
Ben Skeggs56d237d2014-05-19 14:54:33 +10001021 push = evo_wait(mast, 6);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001022 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001023 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001024 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1025 evo_data(push, 0x00000000);
1026 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1027 evo_data(push, 0x40000000);
1028 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001029 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001030 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1031 evo_data(push, 0x00000000);
1032 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1033 evo_data(push, 0x40000000);
1034 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
1035 evo_data(push, 0x00000000);
1036 } else {
1037 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
1038 evo_data(push, 0x00000000);
1039 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
1040 evo_data(push, 0x03000000);
1041 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
1042 evo_data(push, 0x00000000);
1043 }
1044
1045 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001046 }
1047
Ben Skeggse225f442012-11-21 14:40:21 +10001048 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001049}
1050
1051static void
Ben Skeggse225f442012-11-21 14:40:21 +10001052nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001053{
1054 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001055 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001056 u32 *push;
1057
Ben Skeggsde8268c2012-11-16 10:24:31 +10001058 push = evo_wait(mast, 32);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001059 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001060 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001061 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001062 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001063 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1064 evo_data(push, 0xc0000000);
1065 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1066 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001067 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001068 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001069 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001070 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1071 evo_data(push, 0xc0000000);
1072 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1073 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001074 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001075 } else {
1076 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001077 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001078 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
1079 evo_data(push, 0x83000000);
1080 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1081 evo_data(push, 0x00000000);
1082 evo_data(push, 0x00000000);
1083 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001084 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001085 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
1086 evo_data(push, 0xffffff00);
1087 }
1088
1089 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001090 }
1091
Ben Skeggs5a560252014-11-10 15:52:02 +10001092 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Matt Roperf4510a22014-04-01 15:22:40 -07001093 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001094}
1095
1096static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001097nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001098 struct drm_display_mode *adjusted_mode)
1099{
Ben Skeggseb2e9682014-01-24 10:13:23 +10001100 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001101 return true;
1102}
1103
1104static int
Ben Skeggse225f442012-11-21 14:40:21 +10001105nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001106{
Matt Roperf4510a22014-04-01 15:22:40 -07001107 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001108 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001109 int ret;
1110
Ben Skeggs547ad072014-11-10 12:35:06 +10001111 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001112 if (ret == 0) {
1113 if (head->image)
1114 nouveau_bo_unpin(head->image);
1115 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001116 }
1117
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001118 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001119}
1120
1121static int
Ben Skeggse225f442012-11-21 14:40:21 +10001122nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001123 struct drm_display_mode *mode, int x, int y,
1124 struct drm_framebuffer *old_fb)
1125{
Ben Skeggse225f442012-11-21 14:40:21 +10001126 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001127 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1128 struct nouveau_connector *nv_connector;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001129 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
1130 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
1131 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
1132 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
Roy Spliet1dce6262014-09-12 18:00:13 +02001133 u32 vblan2e = 0, vblan2s = 1, vblankus = 0;
Ben Skeggs3488c572012-03-12 11:42:20 +10001134 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001135 int ret;
1136
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001137 hactive = mode->htotal;
1138 hsynce = mode->hsync_end - mode->hsync_start - 1;
1139 hbackp = mode->htotal - mode->hsync_end;
1140 hblanke = hsynce + hbackp;
1141 hfrontp = mode->hsync_start - mode->hdisplay;
1142 hblanks = mode->htotal - hfrontp - 1;
1143
1144 vactive = mode->vtotal * vscan / ilace;
1145 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
1146 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
1147 vblanke = vsynce + vbackp;
1148 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
1149 vblanks = vactive - vfrontp - 1;
Roy Spliet1dce6262014-09-12 18:00:13 +02001150 /* XXX: Safe underestimate, even "0" works */
1151 vblankus = (vactive - mode->vdisplay - 2) * hactive;
1152 vblankus *= 1000;
1153 vblankus /= mode->clock;
1154
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001155 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1156 vblan2e = vactive + vsynce + vbackp;
1157 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
1158 vactive = (vactive * 2) + 1;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001159 }
1160
Ben Skeggse225f442012-11-21 14:40:21 +10001161 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001162 if (ret)
1163 return ret;
1164
Ben Skeggsde8268c2012-11-16 10:24:31 +10001165 push = evo_wait(mast, 64);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001166 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001167 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001168 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1169 evo_data(push, 0x00800000 | mode->clock);
1170 evo_data(push, (ilace == 2) ? 2 : 0);
Roy Splieteae73822014-10-30 22:57:45 +01001171 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001172 evo_data(push, 0x00000000);
1173 evo_data(push, (vactive << 16) | hactive);
1174 evo_data(push, ( vsynce << 16) | hsynce);
1175 evo_data(push, (vblanke << 16) | hblanke);
1176 evo_data(push, (vblanks << 16) | hblanks);
1177 evo_data(push, (vblan2e << 16) | vblan2s);
Roy Splieteae73822014-10-30 22:57:45 +01001178 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001179 evo_data(push, 0x00000000);
1180 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1181 evo_data(push, 0x00000311);
1182 evo_data(push, 0x00000100);
1183 } else {
1184 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
1185 evo_data(push, 0x00000000);
1186 evo_data(push, (vactive << 16) | hactive);
1187 evo_data(push, ( vsynce << 16) | hsynce);
1188 evo_data(push, (vblanke << 16) | hblanke);
1189 evo_data(push, (vblanks << 16) | hblanks);
1190 evo_data(push, (vblan2e << 16) | vblan2s);
1191 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1192 evo_data(push, 0x00000000); /* ??? */
1193 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1194 evo_data(push, mode->clock * 1000);
1195 evo_data(push, 0x00200000); /* ??? */
1196 evo_data(push, mode->clock * 1000);
1197 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1198 evo_data(push, 0x00000311);
1199 evo_data(push, 0x00000100);
1200 }
1201
1202 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001203 }
1204
1205 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001206 nv50_crtc_set_dither(nv_crtc, false);
1207 nv50_crtc_set_scale(nv_crtc, false);
Roy Splieteae73822014-10-30 22:57:45 +01001208
1209 /* G94 only accepts this after setting scale */
1210 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA)
1211 nv50_crtc_set_raster_vblank_dmi(nv_crtc, vblankus);
1212
Ben Skeggse225f442012-11-21 14:40:21 +10001213 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07001214 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001215 return 0;
1216}
1217
1218static int
Ben Skeggse225f442012-11-21 14:40:21 +10001219nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001220 struct drm_framebuffer *old_fb)
1221{
Ben Skeggs77145f12012-07-31 16:16:21 +10001222 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001223 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1224 int ret;
1225
Matt Roperf4510a22014-04-01 15:22:40 -07001226 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10001227 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10001228 return 0;
1229 }
1230
Ben Skeggse225f442012-11-21 14:40:21 +10001231 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001232 if (ret)
1233 return ret;
1234
Ben Skeggse225f442012-11-21 14:40:21 +10001235 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07001236 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1237 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001238 return 0;
1239}
1240
1241static int
Ben Skeggse225f442012-11-21 14:40:21 +10001242nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001243 struct drm_framebuffer *fb, int x, int y,
1244 enum mode_set_atomic state)
1245{
1246 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001247 nv50_display_flip_stop(crtc);
1248 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001249 return 0;
1250}
1251
1252static void
Ben Skeggse225f442012-11-21 14:40:21 +10001253nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001254{
Ben Skeggse225f442012-11-21 14:40:21 +10001255 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001256 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1257 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1258 int i;
1259
1260 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001261 u16 r = nv_crtc->lut.r[i] >> 2;
1262 u16 g = nv_crtc->lut.g[i] >> 2;
1263 u16 b = nv_crtc->lut.b[i] >> 2;
1264
Ben Skeggs648d4df2014-08-10 04:10:27 +10001265 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001266 writew(r + 0x0000, lut + (i * 0x08) + 0);
1267 writew(g + 0x0000, lut + (i * 0x08) + 2);
1268 writew(b + 0x0000, lut + (i * 0x08) + 4);
1269 } else {
1270 writew(r + 0x6000, lut + (i * 0x20) + 0);
1271 writew(g + 0x6000, lut + (i * 0x20) + 2);
1272 writew(b + 0x6000, lut + (i * 0x20) + 4);
1273 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001274 }
1275}
1276
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001277static void
1278nv50_crtc_disable(struct drm_crtc *crtc)
1279{
1280 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10001281 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001282 if (head->image)
1283 nouveau_bo_unpin(head->image);
1284 nouveau_bo_ref(NULL, &head->image);
1285}
1286
Ben Skeggs438d99e2011-07-05 16:48:06 +10001287static int
Ben Skeggse225f442012-11-21 14:40:21 +10001288nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001289 uint32_t handle, uint32_t width, uint32_t height)
1290{
1291 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1292 struct drm_device *dev = crtc->dev;
Ben Skeggs5a560252014-11-10 15:52:02 +10001293 struct drm_gem_object *gem = NULL;
1294 struct nouveau_bo *nvbo = NULL;
1295 int ret = 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001296
Ben Skeggs5a560252014-11-10 15:52:02 +10001297 if (handle) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001298 if (width != 64 || height != 64)
1299 return -EINVAL;
1300
1301 gem = drm_gem_object_lookup(dev, file_priv, handle);
1302 if (unlikely(!gem))
1303 return -ENOENT;
1304 nvbo = nouveau_gem_object(gem);
1305
Ben Skeggs5a560252014-11-10 15:52:02 +10001306 ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001307 }
1308
Ben Skeggs5a560252014-11-10 15:52:02 +10001309 if (ret == 0) {
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001310 if (nv_crtc->cursor.nvbo)
1311 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1312 nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001313 }
Ben Skeggs5a560252014-11-10 15:52:02 +10001314 drm_gem_object_unreference_unlocked(gem);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001315
Ben Skeggs5a560252014-11-10 15:52:02 +10001316 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001317 return ret;
1318}
1319
1320static int
Ben Skeggse225f442012-11-21 14:40:21 +10001321nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001322{
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001323 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001324 struct nv50_curs *curs = nv50_curs(crtc);
1325 struct nv50_chan *chan = nv50_chan(curs);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001326 nvif_wr32(&chan->user, 0x0084, (y << 16) | (x & 0xffff));
1327 nvif_wr32(&chan->user, 0x0080, 0x00000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001328
1329 nv_crtc->cursor_saved_x = x;
1330 nv_crtc->cursor_saved_y = y;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001331 return 0;
1332}
1333
1334static void
Ben Skeggse225f442012-11-21 14:40:21 +10001335nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001336 uint32_t start, uint32_t size)
1337{
1338 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Dan Carpenterbdefc8c2013-11-28 01:18:47 +03001339 u32 end = min_t(u32, start + size, 256);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001340 u32 i;
1341
1342 for (i = start; i < end; i++) {
1343 nv_crtc->lut.r[i] = r[i];
1344 nv_crtc->lut.g[i] = g[i];
1345 nv_crtc->lut.b[i] = b[i];
1346 }
1347
Ben Skeggse225f442012-11-21 14:40:21 +10001348 nv50_crtc_lut_load(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001349}
1350
1351static void
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001352nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y)
1353{
1354 nv50_crtc_cursor_move(&nv_crtc->base, x, y);
1355
1356 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
1357}
1358
1359static void
Ben Skeggse225f442012-11-21 14:40:21 +10001360nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001361{
1362 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001363 struct nv50_disp *disp = nv50_disp(crtc->dev);
1364 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001365 struct nv50_fbdma *fbdma;
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001366
Ben Skeggs0ad72862014-08-10 04:10:22 +10001367 list_for_each_entry(fbdma, &disp->fbdma, head) {
1368 nvif_object_fini(&fbdma->base[nv_crtc->index]);
1369 }
1370
1371 nv50_dmac_destroy(&head->ovly.base, disp->disp);
1372 nv50_pioc_destroy(&head->oimm.base);
1373 nv50_dmac_destroy(&head->sync.base, disp->disp);
1374 nv50_pioc_destroy(&head->curs.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001375
1376 /*XXX: this shouldn't be necessary, but the core doesn't call
1377 * disconnect() during the cleanup paths
1378 */
1379 if (head->image)
1380 nouveau_bo_unpin(head->image);
1381 nouveau_bo_ref(NULL, &head->image);
1382
Ben Skeggs5a560252014-11-10 15:52:02 +10001383 /*XXX: ditto */
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001384 if (nv_crtc->cursor.nvbo)
1385 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1386 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001387
Ben Skeggs438d99e2011-07-05 16:48:06 +10001388 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001389 if (nv_crtc->lut.nvbo)
1390 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001391 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001392
Ben Skeggs438d99e2011-07-05 16:48:06 +10001393 drm_crtc_cleanup(crtc);
1394 kfree(crtc);
1395}
1396
Ben Skeggse225f442012-11-21 14:40:21 +10001397static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1398 .dpms = nv50_crtc_dpms,
1399 .prepare = nv50_crtc_prepare,
1400 .commit = nv50_crtc_commit,
1401 .mode_fixup = nv50_crtc_mode_fixup,
1402 .mode_set = nv50_crtc_mode_set,
1403 .mode_set_base = nv50_crtc_mode_set_base,
1404 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1405 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001406 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001407};
1408
Ben Skeggse225f442012-11-21 14:40:21 +10001409static const struct drm_crtc_funcs nv50_crtc_func = {
1410 .cursor_set = nv50_crtc_cursor_set,
1411 .cursor_move = nv50_crtc_cursor_move,
1412 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10001413 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10001414 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001415 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001416};
1417
1418static int
Ben Skeggs0ad72862014-08-10 04:10:22 +10001419nv50_crtc_create(struct drm_device *dev, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001420{
Ben Skeggse225f442012-11-21 14:40:21 +10001421 struct nv50_disp *disp = nv50_disp(dev);
1422 struct nv50_head *head;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001423 struct drm_crtc *crtc;
1424 int ret, i;
1425
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001426 head = kzalloc(sizeof(*head), GFP_KERNEL);
1427 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001428 return -ENOMEM;
1429
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001430 head->base.index = index;
Ben Skeggse225f442012-11-21 14:40:21 +10001431 head->base.set_dither = nv50_crtc_set_dither;
1432 head->base.set_scale = nv50_crtc_set_scale;
1433 head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
Ben Skeggsf9887d02012-11-21 13:03:42 +10001434 head->base.color_vibrance = 50;
1435 head->base.vibrant_hue = 0;
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001436 head->base.cursor.set_pos = nv50_crtc_cursor_restore;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001437 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001438 head->base.lut.r[i] = i << 8;
1439 head->base.lut.g[i] = i << 8;
1440 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001441 }
1442
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001443 crtc = &head->base.base;
Ben Skeggse225f442012-11-21 14:40:21 +10001444 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1445 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001446 drm_mode_crtc_set_gamma_size(crtc, 256);
1447
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10001448 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01001449 0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001450 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10001451 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001452 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001453 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001454 if (ret)
1455 nouveau_bo_unpin(head->base.lut.nvbo);
1456 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001457 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001458 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001459 }
1460
1461 if (ret)
1462 goto out;
1463
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001464 /* allocate cursor resources */
Ben Skeggs410f3ec2014-08-10 04:10:25 +10001465 ret = nv50_curs_create(disp->disp, index, &head->curs);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001466 if (ret)
1467 goto out;
1468
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001469 /* allocate page flip / sync resources */
Ben Skeggs410f3ec2014-08-10 04:10:25 +10001470 ret = nv50_base_create(disp->disp, index, disp->sync->bo.offset,
1471 &head->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001472 if (ret)
1473 goto out;
1474
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001475 head->sync.addr = EVO_FLIP_SEM0(index);
1476 head->sync.data = 0x00000000;
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001477
1478 /* allocate overlay resources */
Ben Skeggs410f3ec2014-08-10 04:10:25 +10001479 ret = nv50_oimm_create(disp->disp, index, &head->oimm);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001480 if (ret)
1481 goto out;
1482
Ben Skeggs410f3ec2014-08-10 04:10:25 +10001483 ret = nv50_ovly_create(disp->disp, index, disp->sync->bo.offset,
1484 &head->ovly);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001485 if (ret)
1486 goto out;
1487
Ben Skeggs438d99e2011-07-05 16:48:06 +10001488out:
1489 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10001490 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001491 return ret;
1492}
1493
1494/******************************************************************************
Ben Skeggsa91d3222014-12-22 16:30:13 +10001495 * Encoder helpers
1496 *****************************************************************************/
1497static bool
1498nv50_encoder_mode_fixup(struct drm_encoder *encoder,
1499 const struct drm_display_mode *mode,
1500 struct drm_display_mode *adjusted_mode)
1501{
1502 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1503 struct nouveau_connector *nv_connector;
1504
1505 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1506 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs576f7912014-12-22 17:19:26 +10001507 nv_connector->scaling_full = false;
1508 if (nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) {
1509 switch (nv_connector->type) {
1510 case DCB_CONNECTOR_LVDS:
1511 case DCB_CONNECTOR_LVDS_SPWG:
1512 case DCB_CONNECTOR_eDP:
1513 /* force use of scaler for non-edid modes */
1514 if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
1515 return true;
1516 nv_connector->scaling_full = true;
1517 break;
1518 default:
1519 return true;
1520 }
1521 }
1522
1523 drm_mode_copy(adjusted_mode, nv_connector->native_mode);
Ben Skeggsa91d3222014-12-22 16:30:13 +10001524 }
1525
1526 return true;
1527}
1528
1529/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001530 * DAC
1531 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001532static void
Ben Skeggse225f442012-11-21 14:40:21 +10001533nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001534{
1535 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001536 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001537 struct {
1538 struct nv50_disp_mthd_v1 base;
1539 struct nv50_disp_dac_pwr_v0 pwr;
1540 } args = {
1541 .base.version = 1,
1542 .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
1543 .base.hasht = nv_encoder->dcb->hasht,
1544 .base.hashm = nv_encoder->dcb->hashm,
1545 .pwr.state = 1,
1546 .pwr.data = 1,
1547 .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
1548 mode != DRM_MODE_DPMS_OFF),
1549 .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
1550 mode != DRM_MODE_DPMS_OFF),
1551 };
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001552
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001553 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001554}
1555
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001556static void
Ben Skeggse225f442012-11-21 14:40:21 +10001557nv50_dac_commit(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001558{
1559}
1560
1561static void
Ben Skeggse225f442012-11-21 14:40:21 +10001562nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001563 struct drm_display_mode *adjusted_mode)
1564{
Ben Skeggse225f442012-11-21 14:40:21 +10001565 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001566 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1567 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001568 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001569
Ben Skeggse225f442012-11-21 14:40:21 +10001570 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001571
Ben Skeggs97b19b52012-11-16 11:21:37 +10001572 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001573 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001574 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001575 u32 syncs = 0x00000000;
1576
1577 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1578 syncs |= 0x00000001;
1579 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1580 syncs |= 0x00000002;
1581
1582 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1583 evo_data(push, 1 << nv_crtc->index);
1584 evo_data(push, syncs);
1585 } else {
1586 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1587 u32 syncs = 0x00000001;
1588
1589 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1590 syncs |= 0x00000008;
1591 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1592 syncs |= 0x00000010;
1593
1594 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1595 magic |= 0x00000001;
1596
1597 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1598 evo_data(push, syncs);
1599 evo_data(push, magic);
1600 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1601 evo_data(push, 1 << nv_crtc->index);
1602 }
1603
1604 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001605 }
1606
1607 nv_encoder->crtc = encoder->crtc;
1608}
1609
1610static void
Ben Skeggse225f442012-11-21 14:40:21 +10001611nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001612{
1613 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001614 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001615 const int or = nv_encoder->or;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001616 u32 *push;
1617
1618 if (nv_encoder->crtc) {
Ben Skeggse225f442012-11-21 14:40:21 +10001619 nv50_crtc_prepare(nv_encoder->crtc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001620
Ben Skeggs97b19b52012-11-16 11:21:37 +10001621 push = evo_wait(mast, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001622 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001623 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001624 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1625 evo_data(push, 0x00000000);
1626 } else {
1627 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1628 evo_data(push, 0x00000000);
1629 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001630 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001631 }
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001632 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001633
1634 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001635}
1636
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001637static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10001638nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001639{
Ben Skeggsc4abd312014-08-10 04:10:26 +10001640 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001641 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsc4abd312014-08-10 04:10:26 +10001642 struct {
1643 struct nv50_disp_mthd_v1 base;
1644 struct nv50_disp_dac_load_v0 load;
1645 } args = {
1646 .base.version = 1,
1647 .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
1648 .base.hasht = nv_encoder->dcb->hasht,
1649 .base.hashm = nv_encoder->dcb->hashm,
1650 };
1651 int ret;
Ben Skeggsb6819932011-07-08 11:14:50 +10001652
Ben Skeggsc4abd312014-08-10 04:10:26 +10001653 args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
1654 if (args.load.data == 0)
1655 args.load.data = 340;
1656
1657 ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
1658 if (ret || !args.load.load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10001659 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10001660
Ben Skeggs35b21d32012-11-08 12:08:55 +10001661 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001662}
1663
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001664static void
Ben Skeggse225f442012-11-21 14:40:21 +10001665nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001666{
1667 drm_encoder_cleanup(encoder);
1668 kfree(encoder);
1669}
1670
Ben Skeggse225f442012-11-21 14:40:21 +10001671static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1672 .dpms = nv50_dac_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10001673 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggse225f442012-11-21 14:40:21 +10001674 .prepare = nv50_dac_disconnect,
1675 .commit = nv50_dac_commit,
1676 .mode_set = nv50_dac_mode_set,
1677 .disable = nv50_dac_disconnect,
1678 .get_crtc = nv50_display_crtc_get,
1679 .detect = nv50_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001680};
1681
Ben Skeggse225f442012-11-21 14:40:21 +10001682static const struct drm_encoder_funcs nv50_dac_func = {
1683 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001684};
1685
1686static int
Ben Skeggse225f442012-11-21 14:40:21 +10001687nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001688{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001689 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10001690 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001691 struct nvkm_i2c_bus *bus;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001692 struct nouveau_encoder *nv_encoder;
1693 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001694 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001695
1696 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1697 if (!nv_encoder)
1698 return -ENOMEM;
1699 nv_encoder->dcb = dcbe;
1700 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001701
1702 bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
1703 if (bus)
1704 nv_encoder->i2c = &bus->i2c;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001705
1706 encoder = to_drm_encoder(nv_encoder);
1707 encoder->possible_crtcs = dcbe->heads;
1708 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001709 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10001710 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001711
1712 drm_mode_connector_attach_encoder(connector, encoder);
1713 return 0;
1714}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001715
1716/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10001717 * Audio
1718 *****************************************************************************/
1719static void
Ben Skeggse225f442012-11-21 14:40:21 +10001720nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001721{
1722 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001723 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs78951d22011-11-11 18:13:13 +10001724 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001725 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsd889c522014-09-15 21:11:51 +10001726 struct __packed {
1727 struct {
1728 struct nv50_disp_mthd_v1 mthd;
1729 struct nv50_disp_sor_hda_eld_v0 eld;
1730 } base;
Ben Skeggs120b0c32014-08-10 04:10:26 +10001731 u8 data[sizeof(nv_connector->base.eld)];
1732 } args = {
Ben Skeggsd889c522014-09-15 21:11:51 +10001733 .base.mthd.version = 1,
1734 .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1735 .base.mthd.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001736 .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1737 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001738 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001739
1740 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1741 if (!drm_detect_monitor_audio(nv_connector->edid))
1742 return;
1743
Ben Skeggs78951d22011-11-11 18:13:13 +10001744 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001745 memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001746
Jani Nikula938fd8a2014-10-28 16:20:48 +02001747 nvif_mthd(disp->disp, 0, &args,
1748 sizeof(args.base) + drm_eld_size(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001749}
1750
1751static void
Ben Skeggscc2a9072014-09-15 21:29:05 +10001752nv50_audio_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001753{
1754 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001755 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001756 struct {
1757 struct nv50_disp_mthd_v1 base;
1758 struct nv50_disp_sor_hda_eld_v0 eld;
1759 } args = {
1760 .base.version = 1,
1761 .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1762 .base.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001763 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1764 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001765 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001766
Ben Skeggs120b0c32014-08-10 04:10:26 +10001767 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001768}
1769
1770/******************************************************************************
1771 * HDMI
1772 *****************************************************************************/
1773static void
Ben Skeggse225f442012-11-21 14:40:21 +10001774nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001775{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001776 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1777 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001778 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001779 struct {
1780 struct nv50_disp_mthd_v1 base;
1781 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1782 } args = {
1783 .base.version = 1,
1784 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1785 .base.hasht = nv_encoder->dcb->hasht,
1786 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1787 (0x0100 << nv_crtc->index),
1788 .pwr.state = 1,
1789 .pwr.rekey = 56, /* binary driver, and tegra, constant */
1790 };
1791 struct nouveau_connector *nv_connector;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001792 u32 max_ac_packet;
1793
1794 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1795 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1796 return;
1797
1798 max_ac_packet = mode->htotal - mode->hdisplay;
Ben Skeggse00f2232014-08-10 04:10:26 +10001799 max_ac_packet -= args.pwr.rekey;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001800 max_ac_packet -= 18; /* constant from tegra */
Ben Skeggse00f2232014-08-10 04:10:26 +10001801 args.pwr.max_ac_packet = max_ac_packet / 32;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001802
Ben Skeggse00f2232014-08-10 04:10:26 +10001803 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggse225f442012-11-21 14:40:21 +10001804 nv50_audio_mode_set(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10001805}
1806
1807static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001808nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001809{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001810 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001811 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001812 struct {
1813 struct nv50_disp_mthd_v1 base;
1814 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1815 } args = {
1816 .base.version = 1,
1817 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1818 .base.hasht = nv_encoder->dcb->hasht,
1819 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1820 (0x0100 << nv_crtc->index),
1821 };
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001822
Ben Skeggse00f2232014-08-10 04:10:26 +10001823 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001824}
1825
1826/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001827 * SOR
1828 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001829static void
Ben Skeggse225f442012-11-21 14:40:21 +10001830nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001831{
1832 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001833 struct nv50_disp *disp = nv50_disp(encoder->dev);
1834 struct {
1835 struct nv50_disp_mthd_v1 base;
1836 struct nv50_disp_sor_pwr_v0 pwr;
1837 } args = {
1838 .base.version = 1,
1839 .base.method = NV50_DISP_MTHD_V1_SOR_PWR,
1840 .base.hasht = nv_encoder->dcb->hasht,
1841 .base.hashm = nv_encoder->dcb->hashm,
1842 .pwr.state = mode == DRM_MODE_DPMS_ON,
1843 };
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001844 struct {
1845 struct nv50_disp_mthd_v1 base;
1846 struct nv50_disp_sor_dp_pwr_v0 pwr;
1847 } link = {
1848 .base.version = 1,
1849 .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
1850 .base.hasht = nv_encoder->dcb->hasht,
1851 .base.hashm = nv_encoder->dcb->hashm,
1852 .pwr.state = mode == DRM_MODE_DPMS_ON,
1853 };
Ben Skeggs83fc0832011-07-05 13:08:40 +10001854 struct drm_device *dev = encoder->dev;
1855 struct drm_encoder *partner;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001856
1857 nv_encoder->last_dpms = mode;
1858
1859 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1860 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1861
1862 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1863 continue;
1864
1865 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10001866 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10001867 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1868 return;
1869 break;
1870 }
1871 }
1872
Ben Skeggs48743222014-05-31 01:48:06 +10001873 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001874 args.pwr.state = 1;
1875 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001876 nvif_mthd(disp->disp, 0, &link, sizeof(link));
Ben Skeggs48743222014-05-31 01:48:06 +10001877 } else {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001878 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs48743222014-05-31 01:48:06 +10001879 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001880}
1881
Ben Skeggs83fc0832011-07-05 13:08:40 +10001882static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001883nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1884{
1885 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1886 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1887 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001888 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10001889 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1890 evo_data(push, (nv_encoder->ctrl = temp));
1891 } else {
1892 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1893 evo_data(push, (nv_encoder->ctrl = temp));
1894 }
1895 evo_kick(push, mast);
1896 }
1897}
1898
1899static void
Ben Skeggse225f442012-11-21 14:40:21 +10001900nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001901{
1902 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001903 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001904
1905 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1906 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001907
1908 if (nv_crtc) {
1909 nv50_crtc_prepare(&nv_crtc->base);
1910 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001911 nv50_audio_disconnect(encoder, nv_crtc);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001912 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1913 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001914}
1915
1916static void
Ben Skeggse225f442012-11-21 14:40:21 +10001917nv50_sor_commit(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001918{
1919}
1920
1921static void
Ben Skeggse225f442012-11-21 14:40:21 +10001922nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001923 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001924{
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001925 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1926 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1927 struct {
1928 struct nv50_disp_mthd_v1 base;
1929 struct nv50_disp_sor_lvds_script_v0 lvds;
1930 } lvds = {
1931 .base.version = 1,
1932 .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
1933 .base.hasht = nv_encoder->dcb->hasht,
1934 .base.hashm = nv_encoder->dcb->hashm,
1935 };
Ben Skeggse225f442012-11-21 14:40:21 +10001936 struct nv50_disp *disp = nv50_disp(encoder->dev);
1937 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001938 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10001939 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001940 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10001941 struct nvbios *bios = &drm->vbios;
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001942 u32 mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001943 u8 owner = 1 << nv_crtc->index;
1944 u8 proto = 0xf;
1945 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001946
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001947 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001948 nv_encoder->crtc = encoder->crtc;
1949
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001950 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10001951 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001952 if (nv_encoder->dcb->sorconf.link & 1) {
1953 if (mode->clock < 165000)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001954 proto = 0x1;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001955 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001956 proto = 0x5;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001957 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001958 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001959 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001960
Ben Skeggse84a35a2014-06-05 10:59:55 +10001961 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001962 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001963 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001964 proto = 0x0;
1965
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001966 if (bios->fp_no_ddc) {
1967 if (bios->fp.dual_link)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001968 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001969 if (bios->fp.if_is_24bit)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001970 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001971 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10001972 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001973 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001974 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001975 } else
1976 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001977 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001978 }
1979
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001980 if (lvds.lvds.script & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001981 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001982 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001983 } else {
1984 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001985 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001986 }
1987
1988 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001989 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001990 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10001991
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001992 nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds));
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001993 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001994 case DCB_OUTPUT_DP:
Ben Skeggs3488c572012-03-12 11:42:20 +10001995 if (nv_connector->base.display_info.bpc == 6) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001996 nv_encoder->dp.datarate = mode->clock * 18 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001997 depth = 0x2;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10001998 } else
1999 if (nv_connector->base.display_info.bpc == 8) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002000 nv_encoder->dp.datarate = mode->clock * 24 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002001 depth = 0x5;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002002 } else {
2003 nv_encoder->dp.datarate = mode->clock * 30 / 8;
2004 depth = 0x6;
Ben Skeggs3488c572012-03-12 11:42:20 +10002005 }
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002006
2007 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002008 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002009 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002010 proto = 0x9;
Ben Skeggs3eee8642014-09-15 15:20:47 +10002011 nv50_audio_mode_set(encoder, mode);
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002012 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002013 default:
2014 BUG_ON(1);
2015 break;
2016 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10002017
Ben Skeggse84a35a2014-06-05 10:59:55 +10002018 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002019
Ben Skeggs648d4df2014-08-10 04:10:27 +10002020 if (nv50_vers(mast) >= GF110_DISP) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10002021 u32 *push = evo_wait(mast, 3);
2022 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002023 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
2024 u32 syncs = 0x00000001;
2025
2026 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2027 syncs |= 0x00000008;
2028 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2029 syncs |= 0x00000010;
2030
2031 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2032 magic |= 0x00000001;
2033
2034 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
2035 evo_data(push, syncs | (depth << 6));
2036 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10002037 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002038 }
2039
Ben Skeggse84a35a2014-06-05 10:59:55 +10002040 ctrl = proto << 8;
2041 mask = 0x00000f00;
2042 } else {
2043 ctrl = (depth << 16) | (proto << 8);
2044 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2045 ctrl |= 0x00001000;
2046 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2047 ctrl |= 0x00002000;
2048 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002049 }
2050
Ben Skeggse84a35a2014-06-05 10:59:55 +10002051 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002052}
2053
2054static void
Ben Skeggse225f442012-11-21 14:40:21 +10002055nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002056{
2057 drm_encoder_cleanup(encoder);
2058 kfree(encoder);
2059}
2060
Ben Skeggse225f442012-11-21 14:40:21 +10002061static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
2062 .dpms = nv50_sor_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10002063 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggs5a885f02013-02-20 14:34:18 +10002064 .prepare = nv50_sor_disconnect,
Ben Skeggse225f442012-11-21 14:40:21 +10002065 .commit = nv50_sor_commit,
2066 .mode_set = nv50_sor_mode_set,
2067 .disable = nv50_sor_disconnect,
2068 .get_crtc = nv50_display_crtc_get,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002069};
2070
Ben Skeggse225f442012-11-21 14:40:21 +10002071static const struct drm_encoder_funcs nv50_sor_func = {
2072 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002073};
2074
2075static int
Ben Skeggse225f442012-11-21 14:40:21 +10002076nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002077{
Ben Skeggs5ed50202013-02-11 20:15:03 +10002078 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002079 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002080 struct nouveau_encoder *nv_encoder;
2081 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10002082 int type;
2083
2084 switch (dcbe->type) {
2085 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
2086 case DCB_OUTPUT_TMDS:
2087 case DCB_OUTPUT_DP:
2088 default:
2089 type = DRM_MODE_ENCODER_TMDS;
2090 break;
2091 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10002092
2093 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2094 if (!nv_encoder)
2095 return -ENOMEM;
2096 nv_encoder->dcb = dcbe;
2097 nv_encoder->or = ffs(dcbe->or) - 1;
2098 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
2099
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002100 if (dcbe->type == DCB_OUTPUT_DP) {
2101 struct nvkm_i2c_aux *aux =
2102 nvkm_i2c_aux_find(i2c, dcbe->i2c_index);
2103 if (aux) {
2104 nv_encoder->i2c = &aux->i2c;
2105 nv_encoder->aux = aux;
2106 }
2107 } else {
2108 struct nvkm_i2c_bus *bus =
2109 nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
2110 if (bus)
2111 nv_encoder->i2c = &bus->i2c;
2112 }
2113
Ben Skeggs83fc0832011-07-05 13:08:40 +10002114 encoder = to_drm_encoder(nv_encoder);
2115 encoder->possible_crtcs = dcbe->heads;
2116 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10002117 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10002118 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002119
2120 drm_mode_connector_attach_encoder(connector, encoder);
2121 return 0;
2122}
Ben Skeggs26f6d882011-07-04 16:25:18 +10002123
2124/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10002125 * PIOR
2126 *****************************************************************************/
2127
2128static void
2129nv50_pior_dpms(struct drm_encoder *encoder, int mode)
2130{
2131 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2132 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs67cb49c2014-08-10 04:10:27 +10002133 struct {
2134 struct nv50_disp_mthd_v1 base;
2135 struct nv50_disp_pior_pwr_v0 pwr;
2136 } args = {
2137 .base.version = 1,
2138 .base.method = NV50_DISP_MTHD_V1_PIOR_PWR,
2139 .base.hasht = nv_encoder->dcb->hasht,
2140 .base.hashm = nv_encoder->dcb->hashm,
2141 .pwr.state = mode == DRM_MODE_DPMS_ON,
2142 .pwr.type = nv_encoder->dcb->type,
2143 };
2144
2145 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggseb6313a2013-02-11 09:52:58 +10002146}
2147
2148static bool
2149nv50_pior_mode_fixup(struct drm_encoder *encoder,
2150 const struct drm_display_mode *mode,
2151 struct drm_display_mode *adjusted_mode)
2152{
Ben Skeggsa91d3222014-12-22 16:30:13 +10002153 if (!nv50_encoder_mode_fixup(encoder, mode, adjusted_mode))
2154 return false;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002155 adjusted_mode->clock *= 2;
2156 return true;
2157}
2158
2159static void
2160nv50_pior_commit(struct drm_encoder *encoder)
2161{
2162}
2163
2164static void
2165nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
2166 struct drm_display_mode *adjusted_mode)
2167{
2168 struct nv50_mast *mast = nv50_mast(encoder->dev);
2169 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2170 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
2171 struct nouveau_connector *nv_connector;
2172 u8 owner = 1 << nv_crtc->index;
2173 u8 proto, depth;
2174 u32 *push;
2175
2176 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2177 switch (nv_connector->base.display_info.bpc) {
2178 case 10: depth = 0x6; break;
2179 case 8: depth = 0x5; break;
2180 case 6: depth = 0x2; break;
2181 default: depth = 0x0; break;
2182 }
2183
2184 switch (nv_encoder->dcb->type) {
2185 case DCB_OUTPUT_TMDS:
2186 case DCB_OUTPUT_DP:
2187 proto = 0x0;
2188 break;
2189 default:
2190 BUG_ON(1);
2191 break;
2192 }
2193
2194 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
2195
2196 push = evo_wait(mast, 8);
2197 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002198 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002199 u32 ctrl = (depth << 16) | (proto << 8) | owner;
2200 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2201 ctrl |= 0x00001000;
2202 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2203 ctrl |= 0x00002000;
2204 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
2205 evo_data(push, ctrl);
2206 }
2207
2208 evo_kick(push, mast);
2209 }
2210
2211 nv_encoder->crtc = encoder->crtc;
2212}
2213
2214static void
2215nv50_pior_disconnect(struct drm_encoder *encoder)
2216{
2217 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2218 struct nv50_mast *mast = nv50_mast(encoder->dev);
2219 const int or = nv_encoder->or;
2220 u32 *push;
2221
2222 if (nv_encoder->crtc) {
2223 nv50_crtc_prepare(nv_encoder->crtc);
2224
2225 push = evo_wait(mast, 4);
2226 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002227 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002228 evo_mthd(push, 0x0700 + (or * 0x040), 1);
2229 evo_data(push, 0x00000000);
2230 }
Ben Skeggseb6313a2013-02-11 09:52:58 +10002231 evo_kick(push, mast);
2232 }
2233 }
2234
2235 nv_encoder->crtc = NULL;
2236}
2237
2238static void
2239nv50_pior_destroy(struct drm_encoder *encoder)
2240{
2241 drm_encoder_cleanup(encoder);
2242 kfree(encoder);
2243}
2244
2245static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
2246 .dpms = nv50_pior_dpms,
2247 .mode_fixup = nv50_pior_mode_fixup,
2248 .prepare = nv50_pior_disconnect,
2249 .commit = nv50_pior_commit,
2250 .mode_set = nv50_pior_mode_set,
2251 .disable = nv50_pior_disconnect,
2252 .get_crtc = nv50_display_crtc_get,
2253};
2254
2255static const struct drm_encoder_funcs nv50_pior_func = {
2256 .destroy = nv50_pior_destroy,
2257};
2258
2259static int
2260nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2261{
2262 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002263 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002264 struct nvkm_i2c_bus *bus = NULL;
2265 struct nvkm_i2c_aux *aux = NULL;
2266 struct i2c_adapter *ddc;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002267 struct nouveau_encoder *nv_encoder;
2268 struct drm_encoder *encoder;
2269 int type;
2270
2271 switch (dcbe->type) {
2272 case DCB_OUTPUT_TMDS:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002273 bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev));
2274 ddc = bus ? &bus->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002275 type = DRM_MODE_ENCODER_TMDS;
2276 break;
2277 case DCB_OUTPUT_DP:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002278 aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev));
2279 ddc = aux ? &aux->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002280 type = DRM_MODE_ENCODER_TMDS;
2281 break;
2282 default:
2283 return -ENODEV;
2284 }
2285
2286 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2287 if (!nv_encoder)
2288 return -ENOMEM;
2289 nv_encoder->dcb = dcbe;
2290 nv_encoder->or = ffs(dcbe->or) - 1;
2291 nv_encoder->i2c = ddc;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002292 nv_encoder->aux = aux;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002293
2294 encoder = to_drm_encoder(nv_encoder);
2295 encoder->possible_crtcs = dcbe->heads;
2296 encoder->possible_clones = 0;
2297 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type);
2298 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2299
2300 drm_mode_connector_attach_encoder(connector, encoder);
2301 return 0;
2302}
2303
2304/******************************************************************************
Ben Skeggsab0af552014-08-10 04:10:19 +10002305 * Framebuffer
2306 *****************************************************************************/
2307
Ben Skeggs8a423642014-08-10 04:10:19 +10002308static void
Ben Skeggs0ad72862014-08-10 04:10:22 +10002309nv50_fbdma_fini(struct nv50_fbdma *fbdma)
Ben Skeggs8a423642014-08-10 04:10:19 +10002310{
Ben Skeggs0ad72862014-08-10 04:10:22 +10002311 int i;
2312 for (i = 0; i < ARRAY_SIZE(fbdma->base); i++)
2313 nvif_object_fini(&fbdma->base[i]);
2314 nvif_object_fini(&fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002315 list_del(&fbdma->head);
2316 kfree(fbdma);
2317}
2318
2319static int
2320nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind)
2321{
2322 struct nouveau_drm *drm = nouveau_drm(dev);
2323 struct nv50_disp *disp = nv50_disp(dev);
2324 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggs4acfd702014-08-10 04:10:24 +10002325 struct __attribute__ ((packed)) {
2326 struct nv_dma_v0 base;
2327 union {
2328 struct nv50_dma_v0 nv50;
2329 struct gf100_dma_v0 gf100;
2330 struct gf110_dma_v0 gf110;
2331 };
2332 } args = {};
Ben Skeggs8a423642014-08-10 04:10:19 +10002333 struct nv50_fbdma *fbdma;
2334 struct drm_crtc *crtc;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002335 u32 size = sizeof(args.base);
Ben Skeggs8a423642014-08-10 04:10:19 +10002336 int ret;
2337
2338 list_for_each_entry(fbdma, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002339 if (fbdma->core.handle == name)
Ben Skeggs8a423642014-08-10 04:10:19 +10002340 return 0;
2341 }
2342
2343 fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL);
2344 if (!fbdma)
2345 return -ENOMEM;
2346 list_add(&fbdma->head, &disp->fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002347
Ben Skeggs4acfd702014-08-10 04:10:24 +10002348 args.base.target = NV_DMA_V0_TARGET_VRAM;
2349 args.base.access = NV_DMA_V0_ACCESS_RDWR;
2350 args.base.start = offset;
2351 args.base.limit = offset + length - 1;
Ben Skeggs8a423642014-08-10 04:10:19 +10002352
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002353 if (drm->device.info.chipset < 0x80) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002354 args.nv50.part = NV50_DMA_V0_PART_256;
2355 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002356 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002357 if (drm->device.info.chipset < 0xc0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002358 args.nv50.part = NV50_DMA_V0_PART_256;
2359 args.nv50.kind = kind;
2360 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002361 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002362 if (drm->device.info.chipset < 0xd0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002363 args.gf100.kind = kind;
2364 size += sizeof(args.gf100);
Ben Skeggs8a423642014-08-10 04:10:19 +10002365 } else {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002366 args.gf110.page = GF110_DMA_V0_PAGE_LP;
2367 args.gf110.kind = kind;
2368 size += sizeof(args.gf110);
Ben Skeggs8a423642014-08-10 04:10:19 +10002369 }
2370
2371 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002372 struct nv50_head *head = nv50_head(crtc);
2373 int ret = nvif_object_init(&head->sync.base.base.user, NULL,
Ben Skeggs4acfd702014-08-10 04:10:24 +10002374 name, NV_DMA_IN_MEMORY, &args, size,
Ben Skeggs0ad72862014-08-10 04:10:22 +10002375 &fbdma->base[head->base.index]);
Ben Skeggs8a423642014-08-10 04:10:19 +10002376 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002377 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002378 return ret;
2379 }
2380 }
2381
Ben Skeggs0ad72862014-08-10 04:10:22 +10002382 ret = nvif_object_init(&mast->base.base.user, NULL, name,
Ben Skeggs4acfd702014-08-10 04:10:24 +10002383 NV_DMA_IN_MEMORY, &args, size,
Ben Skeggs0ad72862014-08-10 04:10:22 +10002384 &fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002385 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002386 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002387 return ret;
2388 }
2389
2390 return 0;
2391}
2392
Ben Skeggsab0af552014-08-10 04:10:19 +10002393static void
2394nv50_fb_dtor(struct drm_framebuffer *fb)
2395{
2396}
2397
2398static int
2399nv50_fb_ctor(struct drm_framebuffer *fb)
2400{
2401 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
2402 struct nouveau_drm *drm = nouveau_drm(fb->dev);
2403 struct nouveau_bo *nvbo = nv_fb->nvbo;
Ben Skeggs8a423642014-08-10 04:10:19 +10002404 struct nv50_disp *disp = nv50_disp(fb->dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002405 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
2406 u8 tile = nvbo->tile_mode;
Ben Skeggsab0af552014-08-10 04:10:19 +10002407
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002408 if (drm->device.info.chipset >= 0xc0)
Ben Skeggs8a423642014-08-10 04:10:19 +10002409 tile >>= 4; /* yep.. */
2410
Ben Skeggsab0af552014-08-10 04:10:19 +10002411 switch (fb->depth) {
2412 case 8: nv_fb->r_format = 0x1e00; break;
2413 case 15: nv_fb->r_format = 0xe900; break;
2414 case 16: nv_fb->r_format = 0xe800; break;
2415 case 24:
2416 case 32: nv_fb->r_format = 0xcf00; break;
2417 case 30: nv_fb->r_format = 0xd100; break;
2418 default:
2419 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
2420 return -EINVAL;
2421 }
2422
Ben Skeggs648d4df2014-08-10 04:10:27 +10002423 if (disp->disp->oclass < G82_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002424 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2425 (fb->pitches[0] | 0x00100000);
2426 nv_fb->r_format |= kind << 16;
2427 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10002428 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002429 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2430 (fb->pitches[0] | 0x00100000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002431 } else {
Ben Skeggs8a423642014-08-10 04:10:19 +10002432 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2433 (fb->pitches[0] | 0x01000000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002434 }
Ben Skeggs8a423642014-08-10 04:10:19 +10002435 nv_fb->r_handle = 0xffff0000 | kind;
Ben Skeggsab0af552014-08-10 04:10:19 +10002436
Ben Skeggsf392ec42014-08-10 04:10:28 +10002437 return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0,
2438 drm->device.info.ram_user, kind);
Ben Skeggsab0af552014-08-10 04:10:19 +10002439}
2440
2441/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002442 * Init
2443 *****************************************************************************/
Ben Skeggsab0af552014-08-10 04:10:19 +10002444
Ben Skeggs2a44e492011-11-09 11:36:33 +10002445void
Ben Skeggse225f442012-11-21 14:40:21 +10002446nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002447{
Ben Skeggs26f6d882011-07-04 16:25:18 +10002448}
2449
2450int
Ben Skeggse225f442012-11-21 14:40:21 +10002451nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002452{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002453 struct nv50_disp *disp = nv50_disp(dev);
2454 struct drm_crtc *crtc;
2455 u32 *push;
2456
2457 push = evo_wait(nv50_mast(dev), 32);
2458 if (!push)
2459 return -EBUSY;
2460
2461 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2462 struct nv50_sync *sync = nv50_sync(crtc);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002463
2464 nv50_crtc_lut_load(crtc);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002465 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002466 }
2467
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002468 evo_mthd(push, 0x0088, 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10002469 evo_data(push, nv50_mast(dev)->base.sync.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002470 evo_kick(push, nv50_mast(dev));
2471 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002472}
2473
2474void
Ben Skeggse225f442012-11-21 14:40:21 +10002475nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002476{
Ben Skeggse225f442012-11-21 14:40:21 +10002477 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002478 struct nv50_fbdma *fbdma, *fbtmp;
2479
2480 list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002481 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002482 }
Ben Skeggs26f6d882011-07-04 16:25:18 +10002483
Ben Skeggs0ad72862014-08-10 04:10:22 +10002484 nv50_dmac_destroy(&disp->mast.base, disp->disp);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10002485
Ben Skeggs816af2f2011-11-16 15:48:48 +10002486 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002487 if (disp->sync)
2488 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10002489 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10002490
Ben Skeggs77145f12012-07-31 16:16:21 +10002491 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002492 kfree(disp);
2493}
2494
2495int
Ben Skeggse225f442012-11-21 14:40:21 +10002496nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002497{
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002498 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggs77145f12012-07-31 16:16:21 +10002499 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10002500 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002501 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10002502 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10002503 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002504 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002505
2506 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2507 if (!disp)
2508 return -ENOMEM;
Ben Skeggs8a423642014-08-10 04:10:19 +10002509 INIT_LIST_HEAD(&disp->fbdma);
Ben Skeggs77145f12012-07-31 16:16:21 +10002510
2511 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10002512 nouveau_display(dev)->dtor = nv50_display_destroy;
2513 nouveau_display(dev)->init = nv50_display_init;
2514 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggsab0af552014-08-10 04:10:19 +10002515 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
2516 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
Ben Skeggs0ad72862014-08-10 04:10:22 +10002517 disp->disp = &nouveau_display(dev)->disp;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002518
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002519 /* small shared memory area we use for notifiers and semaphores */
2520 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01002521 0, 0x0000, NULL, NULL, &disp->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002522 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10002523 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002524 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002525 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002526 if (ret)
2527 nouveau_bo_unpin(disp->sync);
2528 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002529 if (ret)
2530 nouveau_bo_ref(NULL, &disp->sync);
2531 }
2532
2533 if (ret)
2534 goto out;
2535
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002536 /* allocate master evo channel */
Ben Skeggs410f3ec2014-08-10 04:10:25 +10002537 ret = nv50_core_create(disp->disp, disp->sync->bo.offset,
2538 &disp->mast);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002539 if (ret)
2540 goto out;
2541
Ben Skeggs438d99e2011-07-05 16:48:06 +10002542 /* create crtc objects to represent the hw heads */
Ben Skeggs648d4df2014-08-10 04:10:27 +10002543 if (disp->disp->oclass >= GF110_DISP)
Ben Skeggsdb2bec12014-08-10 04:10:22 +10002544 crtcs = nvif_rd32(device, 0x022448);
Ben Skeggs63718a02012-11-16 11:44:14 +10002545 else
2546 crtcs = 2;
2547
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002548 for (i = 0; i < crtcs; i++) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002549 ret = nv50_crtc_create(dev, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002550 if (ret)
2551 goto out;
2552 }
2553
Ben Skeggs83fc0832011-07-05 13:08:40 +10002554 /* create encoder/connector objects based on VBIOS DCB table */
2555 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2556 connector = nouveau_connector_create(dev, dcbe->connector);
2557 if (IS_ERR(connector))
2558 continue;
2559
Ben Skeggseb6313a2013-02-11 09:52:58 +10002560 if (dcbe->location == DCB_LOC_ON_CHIP) {
2561 switch (dcbe->type) {
2562 case DCB_OUTPUT_TMDS:
2563 case DCB_OUTPUT_LVDS:
2564 case DCB_OUTPUT_DP:
2565 ret = nv50_sor_create(connector, dcbe);
2566 break;
2567 case DCB_OUTPUT_ANALOG:
2568 ret = nv50_dac_create(connector, dcbe);
2569 break;
2570 default:
2571 ret = -ENODEV;
2572 break;
2573 }
2574 } else {
2575 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002576 }
2577
Ben Skeggseb6313a2013-02-11 09:52:58 +10002578 if (ret) {
2579 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2580 dcbe->location, dcbe->type,
2581 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10002582 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002583 }
2584 }
2585
2586 /* cull any connectors we created that don't have an encoder */
2587 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2588 if (connector->encoder_ids[0])
2589 continue;
2590
Ben Skeggs77145f12012-07-31 16:16:21 +10002591 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03002592 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002593 connector->funcs->destroy(connector);
2594 }
2595
Ben Skeggs26f6d882011-07-04 16:25:18 +10002596out:
2597 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002598 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002599 return ret;
2600}