blob: e871a554398cab4c87128d44e6a4297e590209aa [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>
Daniel Vetterb516a9e2015-12-04 09:45:43 +010031#include <drm/drm_fb_helper.h>
Ben Skeggs26f6d882011-07-04 16:25:18 +100032
Ben Skeggsfdb751e2014-08-10 04:10:23 +100033#include <nvif/class.h>
Ben Skeggs845f2722015-11-08 12:16:40 +100034#include <nvif/cl0002.h>
Ben Skeggs7568b102015-11-08 10:44:19 +100035#include <nvif/cl5070.h>
36#include <nvif/cl507a.h>
37#include <nvif/cl507b.h>
38#include <nvif/cl507c.h>
39#include <nvif/cl507d.h>
40#include <nvif/cl507e.h>
Ben Skeggsfdb751e2014-08-10 04:10:23 +100041
Ben Skeggs4dc28132016-05-20 09:22:55 +100042#include "nouveau_drv.h"
Ben Skeggs77145f12012-07-31 16:16:21 +100043#include "nouveau_dma.h"
44#include "nouveau_gem.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100045#include "nouveau_connector.h"
46#include "nouveau_encoder.h"
47#include "nouveau_crtc.h"
Ben Skeggsf589be82012-07-22 11:55:54 +100048#include "nouveau_fence.h"
Ben Skeggs3a89cd02011-07-07 10:47:10 +100049#include "nv50_display.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100050
Ben Skeggs8a464382011-11-12 23:52:07 +100051#define EVO_DMA_NR 9
52
Ben Skeggsbdb8c212011-11-12 01:30:24 +100053#define EVO_MASTER (0x00)
Ben Skeggsa63a97e2011-11-16 15:22:34 +100054#define EVO_FLIP(c) (0x01 + (c))
Ben Skeggs8a464382011-11-12 23:52:07 +100055#define EVO_OVLY(c) (0x05 + (c))
56#define EVO_OIMM(c) (0x09 + (c))
Ben Skeggsbdb8c212011-11-12 01:30:24 +100057#define EVO_CURS(c) (0x0d + (c))
58
Ben Skeggs816af2f2011-11-16 15:48:48 +100059/* offsets in shared sync bo of various structures */
60#define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +100061#define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
62#define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
63#define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
Ben Skeggs816af2f2011-11-16 15:48:48 +100064
Ben Skeggsb5a794b2012-10-16 14:18:32 +100065/******************************************************************************
66 * EVO channel
67 *****************************************************************************/
68
Ben Skeggse225f442012-11-21 14:40:21 +100069struct nv50_chan {
Ben Skeggs0ad72862014-08-10 04:10:22 +100070 struct nvif_object user;
Ben Skeggsa01ca782015-08-20 14:54:15 +100071 struct nvif_device *device;
Ben Skeggsb5a794b2012-10-16 14:18:32 +100072};
73
74static int
Ben Skeggsa01ca782015-08-20 14:54:15 +100075nv50_chan_create(struct nvif_device *device, struct nvif_object *disp,
Ben Skeggs315a8b22015-08-20 14:54:16 +100076 const s32 *oclass, u8 head, void *data, u32 size,
Ben Skeggsa01ca782015-08-20 14:54:15 +100077 struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100078{
Ben Skeggs41a63402015-08-20 14:54:16 +100079 struct nvif_sclass *sclass;
80 int ret, i, n;
Ben Skeggs6af52892014-11-03 15:01:33 +100081
Ben Skeggsa01ca782015-08-20 14:54:15 +100082 chan->device = device;
83
Ben Skeggs41a63402015-08-20 14:54:16 +100084 ret = n = nvif_object_sclass_get(disp, &sclass);
Ben Skeggs6af52892014-11-03 15:01:33 +100085 if (ret < 0)
86 return ret;
87
Ben Skeggs410f3ec2014-08-10 04:10:25 +100088 while (oclass[0]) {
Ben Skeggs41a63402015-08-20 14:54:16 +100089 for (i = 0; i < n; i++) {
90 if (sclass[i].oclass == oclass[0]) {
Ben Skeggsfcf3f912015-09-04 14:40:32 +100091 ret = nvif_object_init(disp, 0, oclass[0],
Ben Skeggsa01ca782015-08-20 14:54:15 +100092 data, size, &chan->user);
Ben Skeggs6af52892014-11-03 15:01:33 +100093 if (ret == 0)
94 nvif_object_map(&chan->user);
Ben Skeggs41a63402015-08-20 14:54:16 +100095 nvif_object_sclass_put(&sclass);
Ben Skeggs6af52892014-11-03 15:01:33 +100096 return ret;
97 }
Ben Skeggsb76f1522014-08-10 04:10:28 +100098 }
Ben Skeggs6af52892014-11-03 15:01:33 +100099 oclass++;
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000100 }
Ben Skeggs6af52892014-11-03 15:01:33 +1000101
Ben Skeggs41a63402015-08-20 14:54:16 +1000102 nvif_object_sclass_put(&sclass);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000103 return -ENOSYS;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000104}
105
106static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000107nv50_chan_destroy(struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000108{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000109 nvif_object_fini(&chan->user);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000110}
111
112/******************************************************************************
113 * PIO EVO channel
114 *****************************************************************************/
115
Ben Skeggse225f442012-11-21 14:40:21 +1000116struct nv50_pioc {
117 struct nv50_chan base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000118};
119
120static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000121nv50_pioc_destroy(struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000122{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000123 nv50_chan_destroy(&pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000124}
125
126static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000127nv50_pioc_create(struct nvif_device *device, struct nvif_object *disp,
Ben Skeggs315a8b22015-08-20 14:54:16 +1000128 const s32 *oclass, u8 head, void *data, u32 size,
Ben Skeggsa01ca782015-08-20 14:54:15 +1000129 struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000130{
Ben Skeggsa01ca782015-08-20 14:54:15 +1000131 return nv50_chan_create(device, disp, oclass, head, data, size,
132 &pioc->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000133}
134
135/******************************************************************************
136 * Cursor Immediate
137 *****************************************************************************/
138
139struct nv50_curs {
140 struct nv50_pioc base;
141};
142
143static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000144nv50_curs_create(struct nvif_device *device, struct nvif_object *disp,
145 int head, struct nv50_curs *curs)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000146{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000147 struct nv50_disp_cursor_v0 args = {
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000148 .head = head,
149 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000150 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000151 GK104_DISP_CURSOR,
152 GF110_DISP_CURSOR,
153 GT214_DISP_CURSOR,
154 G82_DISP_CURSOR,
155 NV50_DISP_CURSOR,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000156 0
157 };
158
Ben Skeggsa01ca782015-08-20 14:54:15 +1000159 return nv50_pioc_create(device, disp, oclass, head, &args, sizeof(args),
160 &curs->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000161}
162
163/******************************************************************************
164 * Overlay Immediate
165 *****************************************************************************/
166
167struct nv50_oimm {
168 struct nv50_pioc base;
169};
170
171static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000172nv50_oimm_create(struct nvif_device *device, struct nvif_object *disp,
173 int head, struct nv50_oimm *oimm)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000174{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000175 struct nv50_disp_cursor_v0 args = {
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000176 .head = head,
177 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000178 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000179 GK104_DISP_OVERLAY,
180 GF110_DISP_OVERLAY,
181 GT214_DISP_OVERLAY,
182 G82_DISP_OVERLAY,
183 NV50_DISP_OVERLAY,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000184 0
185 };
186
Ben Skeggsa01ca782015-08-20 14:54:15 +1000187 return nv50_pioc_create(device, disp, oclass, head, &args, sizeof(args),
188 &oimm->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000189}
190
191/******************************************************************************
192 * DMA EVO channel
193 *****************************************************************************/
194
Ben Skeggse225f442012-11-21 14:40:21 +1000195struct nv50_dmac {
196 struct nv50_chan base;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000197 dma_addr_t handle;
198 u32 *ptr;
Daniel Vetter59ad1462012-12-02 14:49:44 +0100199
Ben Skeggs0ad72862014-08-10 04:10:22 +1000200 struct nvif_object sync;
201 struct nvif_object vram;
202
Daniel Vetter59ad1462012-12-02 14:49:44 +0100203 /* Protects against concurrent pushbuf access to this channel, lock is
204 * grabbed by evo_wait (if the pushbuf reservation is successful) and
205 * dropped again by evo_kick. */
206 struct mutex lock;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000207};
208
209static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000210nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000211{
Ben Skeggsa01ca782015-08-20 14:54:15 +1000212 struct nvif_device *device = dmac->base.device;
213
Ben Skeggs0ad72862014-08-10 04:10:22 +1000214 nvif_object_fini(&dmac->vram);
215 nvif_object_fini(&dmac->sync);
216
217 nv50_chan_destroy(&dmac->base);
218
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000219 if (dmac->ptr) {
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000220 struct device *dev = nvxx_device(device)->dev;
221 dma_free_coherent(dev, PAGE_SIZE, dmac->ptr, dmac->handle);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000222 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000223}
224
225static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000226nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,
Ben Skeggs315a8b22015-08-20 14:54:16 +1000227 const s32 *oclass, u8 head, void *data, u32 size, u64 syncbuf,
Ben Skeggse225f442012-11-21 14:40:21 +1000228 struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000229{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000230 struct nv50_disp_core_channel_dma_v0 *args = data;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000231 struct nvif_object pushbuf;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000232 int ret;
233
Daniel Vetter59ad1462012-12-02 14:49:44 +0100234 mutex_init(&dmac->lock);
235
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000236 dmac->ptr = dma_alloc_coherent(nvxx_device(device)->dev, PAGE_SIZE,
237 &dmac->handle, GFP_KERNEL);
Ben Skeggs47057302012-11-16 13:58:48 +1000238 if (!dmac->ptr)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000239 return -ENOMEM;
240
Ben Skeggsfcf3f912015-09-04 14:40:32 +1000241 ret = nvif_object_init(&device->object, 0, NV_DMA_FROM_MEMORY,
242 &(struct nv_dma_v0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +1000243 .target = NV_DMA_V0_TARGET_PCI_US,
244 .access = NV_DMA_V0_ACCESS_RD,
Ben Skeggs47057302012-11-16 13:58:48 +1000245 .start = dmac->handle + 0x0000,
246 .limit = dmac->handle + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000247 }, sizeof(struct nv_dma_v0), &pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000248 if (ret)
249 return ret;
250
Ben Skeggsbf81df92015-08-20 14:54:16 +1000251 args->pushbuf = nvif_handle(&pushbuf);
252
Ben Skeggsa01ca782015-08-20 14:54:15 +1000253 ret = nv50_chan_create(device, disp, oclass, head, data, size,
254 &dmac->base);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000255 nvif_object_fini(&pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000256 if (ret)
257 return ret;
258
Ben Skeggsa01ca782015-08-20 14:54:15 +1000259 ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000260 &(struct nv_dma_v0) {
261 .target = NV_DMA_V0_TARGET_VRAM,
262 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000263 .start = syncbuf + 0x0000,
264 .limit = syncbuf + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000265 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000266 &dmac->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000267 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000268 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000269
Ben Skeggsa01ca782015-08-20 14:54:15 +1000270 ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000271 &(struct nv_dma_v0) {
272 .target = NV_DMA_V0_TARGET_VRAM,
273 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000274 .start = 0,
Ben Skeggsf392ec42014-08-10 04:10:28 +1000275 .limit = device->info.ram_user - 1,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000276 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000277 &dmac->vram);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000278 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000279 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000280
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000281 return ret;
282}
283
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000284/******************************************************************************
285 * Core
286 *****************************************************************************/
287
Ben Skeggse225f442012-11-21 14:40:21 +1000288struct nv50_mast {
289 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000290};
291
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000292static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000293nv50_core_create(struct nvif_device *device, struct nvif_object *disp,
294 u64 syncbuf, struct nv50_mast *core)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000295{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000296 struct nv50_disp_core_channel_dma_v0 args = {
297 .pushbuf = 0xb0007d00,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000298 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000299 static const s32 oclass[] = {
Ben Skeggsf9d5cbb2016-07-09 10:41:01 +1000300 GP100_DISP_CORE_CHANNEL_DMA,
Ben Skeggsdb1eb522016-02-11 08:35:32 +1000301 GM200_DISP_CORE_CHANNEL_DMA,
Ben Skeggs648d4df2014-08-10 04:10:27 +1000302 GM107_DISP_CORE_CHANNEL_DMA,
303 GK110_DISP_CORE_CHANNEL_DMA,
304 GK104_DISP_CORE_CHANNEL_DMA,
305 GF110_DISP_CORE_CHANNEL_DMA,
306 GT214_DISP_CORE_CHANNEL_DMA,
307 GT206_DISP_CORE_CHANNEL_DMA,
308 GT200_DISP_CORE_CHANNEL_DMA,
309 G82_DISP_CORE_CHANNEL_DMA,
310 NV50_DISP_CORE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000311 0
312 };
313
Ben Skeggsa01ca782015-08-20 14:54:15 +1000314 return nv50_dmac_create(device, disp, oclass, 0, &args, sizeof(args),
315 syncbuf, &core->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000316}
317
318/******************************************************************************
319 * Base
320 *****************************************************************************/
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000321
Ben Skeggse225f442012-11-21 14:40:21 +1000322struct nv50_sync {
323 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000324 u32 addr;
325 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000326};
327
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000328static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000329nv50_base_create(struct nvif_device *device, struct nvif_object *disp,
330 int head, u64 syncbuf, struct nv50_sync *base)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000331{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000332 struct nv50_disp_base_channel_dma_v0 args = {
333 .pushbuf = 0xb0007c00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000334 .head = head,
335 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000336 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000337 GK110_DISP_BASE_CHANNEL_DMA,
338 GK104_DISP_BASE_CHANNEL_DMA,
339 GF110_DISP_BASE_CHANNEL_DMA,
340 GT214_DISP_BASE_CHANNEL_DMA,
341 GT200_DISP_BASE_CHANNEL_DMA,
342 G82_DISP_BASE_CHANNEL_DMA,
343 NV50_DISP_BASE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000344 0
345 };
346
Ben Skeggsa01ca782015-08-20 14:54:15 +1000347 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000348 syncbuf, &base->base);
349}
350
351/******************************************************************************
352 * Overlay
353 *****************************************************************************/
354
Ben Skeggse225f442012-11-21 14:40:21 +1000355struct nv50_ovly {
356 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000357};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000358
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000359static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000360nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp,
361 int head, u64 syncbuf, struct nv50_ovly *ovly)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000362{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000363 struct nv50_disp_overlay_channel_dma_v0 args = {
364 .pushbuf = 0xb0007e00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000365 .head = head,
366 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000367 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000368 GK104_DISP_OVERLAY_CONTROL_DMA,
369 GF110_DISP_OVERLAY_CONTROL_DMA,
370 GT214_DISP_OVERLAY_CHANNEL_DMA,
371 GT200_DISP_OVERLAY_CHANNEL_DMA,
372 G82_DISP_OVERLAY_CHANNEL_DMA,
373 NV50_DISP_OVERLAY_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000374 0
375 };
376
Ben Skeggsa01ca782015-08-20 14:54:15 +1000377 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000378 syncbuf, &ovly->base);
379}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000380
Ben Skeggse225f442012-11-21 14:40:21 +1000381struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000382 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000383 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000384 struct nv50_curs curs;
385 struct nv50_sync sync;
386 struct nv50_ovly ovly;
387 struct nv50_oimm oimm;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000388};
389
Ben Skeggse225f442012-11-21 14:40:21 +1000390#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
391#define nv50_curs(c) (&nv50_head(c)->curs)
392#define nv50_sync(c) (&nv50_head(c)->sync)
393#define nv50_ovly(c) (&nv50_head(c)->ovly)
394#define nv50_oimm(c) (&nv50_head(c)->oimm)
395#define nv50_chan(c) (&(c)->base.base)
Ben Skeggs0ad72862014-08-10 04:10:22 +1000396#define nv50_vers(c) nv50_chan(c)->user.oclass
397
398struct nv50_fbdma {
399 struct list_head head;
400 struct nvif_object core;
401 struct nvif_object base[4];
402};
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000403
Ben Skeggse225f442012-11-21 14:40:21 +1000404struct nv50_disp {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000405 struct nvif_object *disp;
Ben Skeggse225f442012-11-21 14:40:21 +1000406 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000407
Ben Skeggs8a423642014-08-10 04:10:19 +1000408 struct list_head fbdma;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000409
410 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000411};
412
Ben Skeggse225f442012-11-21 14:40:21 +1000413static struct nv50_disp *
414nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000415{
Ben Skeggs77145f12012-07-31 16:16:21 +1000416 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000417}
418
Ben Skeggse225f442012-11-21 14:40:21 +1000419#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000420
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000421static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000422nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000423{
424 return nouveau_encoder(encoder)->crtc;
425}
426
427/******************************************************************************
428 * EVO channel helpers
429 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000430static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000431evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000432{
Ben Skeggse225f442012-11-21 14:40:21 +1000433 struct nv50_dmac *dmac = evoc;
Ben Skeggsa01ca782015-08-20 14:54:15 +1000434 struct nvif_device *device = dmac->base.device;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000435 u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000436
Daniel Vetter59ad1462012-12-02 14:49:44 +0100437 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000438 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000439 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000440
Ben Skeggs0ad72862014-08-10 04:10:22 +1000441 nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
Ben Skeggs54442042015-08-20 14:54:11 +1000442 if (nvif_msec(device, 2000,
443 if (!nvif_rd32(&dmac->base.user, 0x0004))
444 break;
445 ) < 0) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100446 mutex_unlock(&dmac->lock);
Ben Skeggs9ad97ed2015-08-20 14:54:13 +1000447 printk(KERN_ERR "nouveau: evo channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000448 return NULL;
449 }
450
451 put = 0;
452 }
453
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000454 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000455}
456
457static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000458evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000459{
Ben Skeggse225f442012-11-21 14:40:21 +1000460 struct nv50_dmac *dmac = evoc;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000461 nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100462 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000463}
464
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000465#if 1
Ben Skeggs51beb422011-07-05 10:33:08 +1000466#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
467#define evo_data(p,d) *((p)++) = (d)
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000468#else
469#define evo_mthd(p,m,s) do { \
470 const u32 _m = (m), _s = (s); \
471 printk(KERN_ERR "%04x %d %s\n", _m, _s, __func__); \
472 *((p)++) = ((_s << 18) | _m); \
473} while(0)
474#define evo_data(p,d) do { \
475 const u32 _d = (d); \
476 printk(KERN_ERR "\t%08x\n", _d); \
477 *((p)++) = _d; \
478} while(0)
479#endif
Ben Skeggs51beb422011-07-05 10:33:08 +1000480
Ben Skeggs3376ee32011-11-12 14:28:12 +1000481static bool
482evo_sync_wait(void *data)
483{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500484 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
485 return true;
486 usleep_range(1, 2);
487 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000488}
489
490static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000491evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000492{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000493 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggse225f442012-11-21 14:40:21 +1000494 struct nv50_disp *disp = nv50_disp(dev);
495 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000496 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000497 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000498 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000499 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000500 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000501 evo_mthd(push, 0x0080, 2);
502 evo_data(push, 0x00000000);
503 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000504 evo_kick(push, mast);
Ben Skeggs54442042015-08-20 14:54:11 +1000505 if (nvif_msec(device, 2000,
506 if (evo_sync_wait(disp->sync))
507 break;
508 ) >= 0)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000509 return 0;
510 }
511
512 return -EBUSY;
513}
514
515/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +1000516 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +1000517 *****************************************************************************/
518struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +1000519nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000520{
Ben Skeggse225f442012-11-21 14:40:21 +1000521 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000522}
523
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000524struct nv50_display_flip {
525 struct nv50_disp *disp;
526 struct nv50_sync *chan;
527};
528
529static bool
530nv50_display_flip_wait(void *data)
531{
532 struct nv50_display_flip *flip = data;
533 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
Calvin Owensb1ea3e62013-04-07 21:01:19 -0500534 flip->chan->data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000535 return true;
536 usleep_range(1, 2);
537 return false;
538}
539
Ben Skeggs3376ee32011-11-12 14:28:12 +1000540void
Ben Skeggse225f442012-11-21 14:40:21 +1000541nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000542{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000543 struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000544 struct nv50_display_flip flip = {
545 .disp = nv50_disp(crtc->dev),
546 .chan = nv50_sync(crtc),
547 };
Ben Skeggs3376ee32011-11-12 14:28:12 +1000548 u32 *push;
549
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000550 push = evo_wait(flip.chan, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000551 if (push) {
552 evo_mthd(push, 0x0084, 1);
553 evo_data(push, 0x00000000);
554 evo_mthd(push, 0x0094, 1);
555 evo_data(push, 0x00000000);
556 evo_mthd(push, 0x00c0, 1);
557 evo_data(push, 0x00000000);
558 evo_mthd(push, 0x0080, 1);
559 evo_data(push, 0x00000000);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000560 evo_kick(push, flip.chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000561 }
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000562
Ben Skeggs54442042015-08-20 14:54:11 +1000563 nvif_msec(device, 2000,
564 if (nv50_display_flip_wait(&flip))
565 break;
566 );
Ben Skeggs3376ee32011-11-12 14:28:12 +1000567}
568
569int
Ben Skeggse225f442012-11-21 14:40:21 +1000570nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +1000571 struct nouveau_channel *chan, u32 swap_interval)
572{
573 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000574 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000575 struct nv50_head *head = nv50_head(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000576 struct nv50_sync *sync = nv50_sync(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000577 u32 *push;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000578 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000579
Ben Skeggs9ba83102014-12-22 19:50:23 +1000580 if (crtc->primary->fb->width != fb->width ||
581 crtc->primary->fb->height != fb->height)
582 return -EINVAL;
583
Ben Skeggs3376ee32011-11-12 14:28:12 +1000584 swap_interval <<= 4;
585 if (swap_interval == 0)
586 swap_interval |= 0x100;
Ben Skeggsf60b6e72013-03-19 15:20:00 +1000587 if (chan == NULL)
588 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000589
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000590 push = evo_wait(sync, 128);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000591 if (unlikely(push == NULL))
592 return -EBUSY;
593
Ben Skeggsa01ca782015-08-20 14:54:15 +1000594 if (chan && chan->user.oclass < G82_CHANNEL_GPFIFO) {
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000595 ret = RING_SPACE(chan, 8);
596 if (ret)
597 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000598
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000599 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000600 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000601 OUT_RING (chan, sync->addr ^ 0x10);
602 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
603 OUT_RING (chan, sync->data + 1);
604 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
605 OUT_RING (chan, sync->addr);
606 OUT_RING (chan, sync->data);
607 } else
Ben Skeggsa01ca782015-08-20 14:54:15 +1000608 if (chan && chan->user.oclass < FERMI_CHANNEL_GPFIFO) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000609 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000610 ret = RING_SPACE(chan, 12);
611 if (ret)
612 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +1000613
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000614 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000615 OUT_RING (chan, chan->vram.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000616 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
617 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
618 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
619 OUT_RING (chan, sync->data + 1);
620 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
621 BEGIN_NV04(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 } else
627 if (chan) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000628 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000629 ret = RING_SPACE(chan, 10);
630 if (ret)
631 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000632
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000633 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
634 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
635 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
636 OUT_RING (chan, sync->data + 1);
637 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
638 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
639 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
640 OUT_RING (chan, upper_32_bits(addr));
641 OUT_RING (chan, lower_32_bits(addr));
642 OUT_RING (chan, sync->data);
643 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
644 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
645 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -0500646
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000647 if (chan) {
648 sync->addr ^= 0x10;
649 sync->data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000650 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000651 }
652
653 /* queue the flip */
654 evo_mthd(push, 0x0100, 1);
655 evo_data(push, 0xfffe0000);
656 evo_mthd(push, 0x0084, 1);
657 evo_data(push, swap_interval);
658 if (!(swap_interval & 0x00000100)) {
659 evo_mthd(push, 0x00e0, 1);
660 evo_data(push, 0x40000000);
661 }
662 evo_mthd(push, 0x0088, 4);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000663 evo_data(push, sync->addr);
664 evo_data(push, sync->data++);
665 evo_data(push, sync->data);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000666 evo_data(push, sync->base.sync.handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000667 evo_mthd(push, 0x00a0, 2);
668 evo_data(push, 0x00000000);
669 evo_data(push, 0x00000000);
670 evo_mthd(push, 0x00c0, 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000671 evo_data(push, nv_fb->r_handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000672 evo_mthd(push, 0x0110, 2);
673 evo_data(push, 0x00000000);
674 evo_data(push, 0x00000000);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000675 if (nv50_vers(sync) < GF110_DISP_BASE_CHANNEL_DMA) {
Ben Skeggsed5085a52012-11-16 13:16:51 +1000676 evo_mthd(push, 0x0800, 5);
677 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
678 evo_data(push, 0);
679 evo_data(push, (fb->height << 16) | fb->width);
680 evo_data(push, nv_fb->r_pitch);
681 evo_data(push, nv_fb->r_format);
682 } else {
683 evo_mthd(push, 0x0400, 5);
684 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
685 evo_data(push, 0);
686 evo_data(push, (fb->height << 16) | fb->width);
687 evo_data(push, nv_fb->r_pitch);
688 evo_data(push, nv_fb->r_format);
689 }
Ben Skeggs3376ee32011-11-12 14:28:12 +1000690 evo_mthd(push, 0x0080, 1);
691 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000692 evo_kick(push, sync);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000693
694 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000695 return 0;
696}
697
Ben Skeggs26f6d882011-07-04 16:25:18 +1000698/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000699 * CRTC
700 *****************************************************************************/
701static int
Ben Skeggse225f442012-11-21 14:40:21 +1000702nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000703{
Ben Skeggse225f442012-11-21 14:40:21 +1000704 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde691852011-10-17 12:23:41 +1000705 struct nouveau_connector *nv_connector;
706 struct drm_connector *connector;
707 u32 *push, mode = 0x00;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000708
Ben Skeggs488ff202011-10-17 10:38:10 +1000709 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +1000710 connector = &nv_connector->base;
711 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
Matt Roperf4510a22014-04-01 15:22:40 -0700712 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
Ben Skeggsde691852011-10-17 12:23:41 +1000713 mode = DITHERING_MODE_DYNAMIC2X2;
714 } else {
715 mode = nv_connector->dithering_mode;
716 }
717
718 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
719 if (connector->display_info.bpc >= 8)
720 mode |= DITHERING_DEPTH_8BPC;
721 } else {
722 mode |= nv_connector->dithering_depth;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000723 }
724
Ben Skeggsde8268c2012-11-16 10:24:31 +1000725 push = evo_wait(mast, 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000726 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000727 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000728 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
729 evo_data(push, mode);
730 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000731 if (nv50_vers(mast) < GK104_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000732 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
733 evo_data(push, mode);
734 } else {
735 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
736 evo_data(push, mode);
737 }
738
Ben Skeggs438d99e2011-07-05 16:48:06 +1000739 if (update) {
740 evo_mthd(push, 0x0080, 1);
741 evo_data(push, 0x00000000);
742 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000743 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000744 }
745
746 return 0;
747}
748
749static int
Ben Skeggse225f442012-11-21 14:40:21 +1000750nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000751{
Ben Skeggse225f442012-11-21 14:40:21 +1000752 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs92854622011-11-11 23:49:06 +1000753 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000754 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000755 struct nouveau_connector *nv_connector;
Ben Skeggs92854622011-11-11 23:49:06 +1000756 int mode = DRM_MODE_SCALE_NONE;
757 u32 oX, oY, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000758
Ben Skeggs92854622011-11-11 23:49:06 +1000759 /* start off at the resolution we programmed the crtc for, this
760 * effectively handles NONE/FULL scaling
761 */
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000762 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs576f7912014-12-22 17:19:26 +1000763 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs92854622011-11-11 23:49:06 +1000764 mode = nv_connector->scaling_mode;
Ben Skeggs576f7912014-12-22 17:19:26 +1000765 if (nv_connector->scaling_full) /* non-EDID LVDS/eDP mode */
766 mode = DRM_MODE_SCALE_FULLSCREEN;
767 }
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000768
Ben Skeggs92854622011-11-11 23:49:06 +1000769 if (mode != DRM_MODE_SCALE_NONE)
770 omode = nv_connector->native_mode;
771 else
772 omode = umode;
773
774 oX = omode->hdisplay;
775 oY = omode->vdisplay;
776 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
777 oY *= 2;
778
779 /* add overscan compensation if necessary, will keep the aspect
780 * ratio the same as the backend mode unless overridden by the
781 * user setting both hborder and vborder properties.
782 */
783 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
784 (nv_connector->underscan == UNDERSCAN_AUTO &&
Ben Skeggs92854622011-11-11 23:49:06 +1000785 drm_detect_hdmi_monitor(nv_connector->edid)))) {
786 u32 bX = nv_connector->underscan_hborder;
787 u32 bY = nv_connector->underscan_vborder;
788 u32 aspect = (oY << 19) / oX;
789
790 if (bX) {
791 oX -= (bX * 2);
792 if (bY) oY -= (bY * 2);
793 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
794 } else {
795 oX -= (oX >> 4) + 32;
796 if (bY) oY -= (bY * 2);
797 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000798 }
799 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000800
Ben Skeggs92854622011-11-11 23:49:06 +1000801 /* handle CENTER/ASPECT scaling, taking into account the areas
802 * removed already for overscan compensation
803 */
804 switch (mode) {
805 case DRM_MODE_SCALE_CENTER:
806 oX = min((u32)umode->hdisplay, oX);
807 oY = min((u32)umode->vdisplay, oY);
808 /* fall-through */
809 case DRM_MODE_SCALE_ASPECT:
810 if (oY < oX) {
811 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
812 oX = ((oY * aspect) + (aspect / 2)) >> 19;
813 } else {
814 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
815 oY = ((oX * aspect) + (aspect / 2)) >> 19;
816 }
817 break;
818 default:
819 break;
820 }
821
Ben Skeggsde8268c2012-11-16 10:24:31 +1000822 push = evo_wait(mast, 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000823 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000824 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000825 /*XXX: SCALE_CTRL_ACTIVE??? */
826 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
827 evo_data(push, (oY << 16) | oX);
828 evo_data(push, (oY << 16) | oX);
829 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
830 evo_data(push, 0x00000000);
831 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
832 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
833 } else {
834 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
835 evo_data(push, (oY << 16) | oX);
836 evo_data(push, (oY << 16) | oX);
837 evo_data(push, (oY << 16) | oX);
838 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
839 evo_data(push, 0x00000000);
840 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
841 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
842 }
843
844 evo_kick(push, mast);
845
Ben Skeggs3376ee32011-11-12 14:28:12 +1000846 if (update) {
Ben Skeggse225f442012-11-21 14:40:21 +1000847 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700848 nv50_display_flip_next(crtc, crtc->primary->fb,
849 NULL, 1);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000850 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000851 }
852
853 return 0;
854}
855
856static int
Roy Splieteae73822014-10-30 22:57:45 +0100857nv50_crtc_set_raster_vblank_dmi(struct nouveau_crtc *nv_crtc, u32 usec)
858{
859 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
860 u32 *push;
861
862 push = evo_wait(mast, 8);
863 if (!push)
864 return -ENOMEM;
865
866 evo_mthd(push, 0x0828 + (nv_crtc->index * 0x400), 1);
867 evo_data(push, usec);
868 evo_kick(push, mast);
869 return 0;
870}
871
872static int
Ben Skeggse225f442012-11-21 14:40:21 +1000873nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +1000874{
Ben Skeggse225f442012-11-21 14:40:21 +1000875 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsf9887d02012-11-21 13:03:42 +1000876 u32 *push, hue, vib;
877 int adj;
878
879 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
880 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
881 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
882
883 push = evo_wait(mast, 16);
884 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000885 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsf9887d02012-11-21 13:03:42 +1000886 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
887 evo_data(push, (hue << 20) | (vib << 8));
888 } else {
889 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
890 evo_data(push, (hue << 20) | (vib << 8));
891 }
892
893 if (update) {
894 evo_mthd(push, 0x0080, 1);
895 evo_data(push, 0x00000000);
896 }
897 evo_kick(push, mast);
898 }
899
900 return 0;
901}
902
903static int
Ben Skeggse225f442012-11-21 14:40:21 +1000904nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000905 int x, int y, bool update)
906{
907 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggse225f442012-11-21 14:40:21 +1000908 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000909 u32 *push;
910
Ben Skeggsde8268c2012-11-16 10:24:31 +1000911 push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000912 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000913 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000914 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
915 evo_data(push, nvfb->nvbo->bo.offset >> 8);
916 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
917 evo_data(push, (fb->height << 16) | fb->width);
918 evo_data(push, nvfb->r_pitch);
919 evo_data(push, nvfb->r_format);
920 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
921 evo_data(push, (y << 16) | x);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000922 if (nv50_vers(mast) > NV50_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000923 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000924 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000925 }
926 } else {
927 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
928 evo_data(push, nvfb->nvbo->bo.offset >> 8);
929 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
930 evo_data(push, (fb->height << 16) | fb->width);
931 evo_data(push, nvfb->r_pitch);
932 evo_data(push, nvfb->r_format);
Ben Skeggs8a423642014-08-10 04:10:19 +1000933 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000934 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
935 evo_data(push, (y << 16) | x);
936 }
937
Ben Skeggsa46232e2011-07-07 15:23:48 +1000938 if (update) {
939 evo_mthd(push, 0x0080, 1);
940 evo_data(push, 0x00000000);
941 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000942 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000943 }
944
Ben Skeggs8a423642014-08-10 04:10:19 +1000945 nv_crtc->fb.handle = nvfb->r_handle;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000946 return 0;
947}
948
949static void
Ben Skeggse225f442012-11-21 14:40:21 +1000950nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000951{
Ben Skeggse225f442012-11-21 14:40:21 +1000952 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000953 u32 *push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000954 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000955 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000956 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
957 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100958 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000959 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000960 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000961 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
962 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100963 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000964 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000965 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000966 } else {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000967 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
968 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100969 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000970 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000971 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000972 }
973 evo_kick(push, mast);
974 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100975 nv_crtc->cursor.visible = true;
Ben Skeggsde8268c2012-11-16 10:24:31 +1000976}
977
978static void
Ben Skeggse225f442012-11-21 14:40:21 +1000979nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000980{
Ben Skeggse225f442012-11-21 14:40:21 +1000981 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000982 u32 *push = evo_wait(mast, 16);
983 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000984 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000985 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
986 evo_data(push, 0x05000000);
987 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000988 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000989 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
990 evo_data(push, 0x05000000);
991 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
992 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000993 } else {
994 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
995 evo_data(push, 0x05000000);
996 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
997 evo_data(push, 0x00000000);
998 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000999 evo_kick(push, mast);
1000 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001001 nv_crtc->cursor.visible = false;
Ben Skeggsde8268c2012-11-16 10:24:31 +10001002}
Ben Skeggs438d99e2011-07-05 16:48:06 +10001003
Ben Skeggsde8268c2012-11-16 10:24:31 +10001004static void
Ben Skeggse225f442012-11-21 14:40:21 +10001005nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +10001006{
Ben Skeggse225f442012-11-21 14:40:21 +10001007 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001008
Ben Skeggs697bb722015-07-28 17:20:57 +10001009 if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled)
Ben Skeggse225f442012-11-21 14:40:21 +10001010 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001011 else
Ben Skeggse225f442012-11-21 14:40:21 +10001012 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001013
1014 if (update) {
1015 u32 *push = evo_wait(mast, 2);
1016 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001017 evo_mthd(push, 0x0080, 1);
1018 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001019 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001020 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001021 }
1022}
1023
1024static void
Ben Skeggse225f442012-11-21 14:40:21 +10001025nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001026{
1027}
1028
1029static void
Ben Skeggse225f442012-11-21 14:40:21 +10001030nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001031{
1032 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001033 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001034 u32 *push;
1035
Ben Skeggse225f442012-11-21 14:40:21 +10001036 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001037
Ben Skeggs56d237d2014-05-19 14:54:33 +10001038 push = evo_wait(mast, 6);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001039 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001040 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001041 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1042 evo_data(push, 0x00000000);
1043 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1044 evo_data(push, 0x40000000);
1045 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001046 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001047 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1048 evo_data(push, 0x00000000);
1049 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1050 evo_data(push, 0x40000000);
1051 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
1052 evo_data(push, 0x00000000);
1053 } else {
1054 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
1055 evo_data(push, 0x00000000);
1056 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
1057 evo_data(push, 0x03000000);
1058 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
1059 evo_data(push, 0x00000000);
1060 }
1061
1062 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001063 }
1064
Ben Skeggse225f442012-11-21 14:40:21 +10001065 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001066}
1067
1068static void
Ben Skeggse225f442012-11-21 14:40:21 +10001069nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001070{
1071 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001072 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001073 u32 *push;
1074
Ben Skeggsde8268c2012-11-16 10:24:31 +10001075 push = evo_wait(mast, 32);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001076 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001077 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001078 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001079 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001080 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1081 evo_data(push, 0xc0000000);
1082 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1083 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001084 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001085 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001086 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001087 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1088 evo_data(push, 0xc0000000);
1089 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1090 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001091 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001092 } else {
1093 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001094 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001095 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
1096 evo_data(push, 0x83000000);
1097 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1098 evo_data(push, 0x00000000);
1099 evo_data(push, 0x00000000);
1100 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001101 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001102 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
1103 evo_data(push, 0xffffff00);
1104 }
1105
1106 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001107 }
1108
Ben Skeggs5a560252014-11-10 15:52:02 +10001109 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Matt Roperf4510a22014-04-01 15:22:40 -07001110 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001111}
1112
1113static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001114nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001115 struct drm_display_mode *adjusted_mode)
1116{
Ben Skeggseb2e9682014-01-24 10:13:23 +10001117 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001118 return true;
1119}
1120
1121static int
Ben Skeggse225f442012-11-21 14:40:21 +10001122nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001123{
Matt Roperf4510a22014-04-01 15:22:40 -07001124 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001125 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001126 int ret;
1127
Ben Skeggs547ad072014-11-10 12:35:06 +10001128 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001129 if (ret == 0) {
1130 if (head->image)
1131 nouveau_bo_unpin(head->image);
1132 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001133 }
1134
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001135 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001136}
1137
1138static int
Ben Skeggse225f442012-11-21 14:40:21 +10001139nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001140 struct drm_display_mode *mode, int x, int y,
1141 struct drm_framebuffer *old_fb)
1142{
Ben Skeggse225f442012-11-21 14:40:21 +10001143 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001144 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1145 struct nouveau_connector *nv_connector;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001146 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
1147 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
1148 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
1149 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
Roy Spliet1dce6262014-09-12 18:00:13 +02001150 u32 vblan2e = 0, vblan2s = 1, vblankus = 0;
Ben Skeggs3488c572012-03-12 11:42:20 +10001151 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001152 int ret;
1153
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001154 hactive = mode->htotal;
1155 hsynce = mode->hsync_end - mode->hsync_start - 1;
1156 hbackp = mode->htotal - mode->hsync_end;
1157 hblanke = hsynce + hbackp;
1158 hfrontp = mode->hsync_start - mode->hdisplay;
1159 hblanks = mode->htotal - hfrontp - 1;
1160
1161 vactive = mode->vtotal * vscan / ilace;
1162 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
1163 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
1164 vblanke = vsynce + vbackp;
1165 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
1166 vblanks = vactive - vfrontp - 1;
Roy Spliet1dce6262014-09-12 18:00:13 +02001167 /* XXX: Safe underestimate, even "0" works */
1168 vblankus = (vactive - mode->vdisplay - 2) * hactive;
1169 vblankus *= 1000;
1170 vblankus /= mode->clock;
1171
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001172 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1173 vblan2e = vactive + vsynce + vbackp;
1174 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
1175 vactive = (vactive * 2) + 1;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001176 }
1177
Ben Skeggse225f442012-11-21 14:40:21 +10001178 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001179 if (ret)
1180 return ret;
1181
Ben Skeggsde8268c2012-11-16 10:24:31 +10001182 push = evo_wait(mast, 64);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001183 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001184 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001185 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1186 evo_data(push, 0x00800000 | mode->clock);
1187 evo_data(push, (ilace == 2) ? 2 : 0);
Roy Splieteae73822014-10-30 22:57:45 +01001188 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001189 evo_data(push, 0x00000000);
1190 evo_data(push, (vactive << 16) | hactive);
1191 evo_data(push, ( vsynce << 16) | hsynce);
1192 evo_data(push, (vblanke << 16) | hblanke);
1193 evo_data(push, (vblanks << 16) | hblanks);
1194 evo_data(push, (vblan2e << 16) | vblan2s);
Roy Splieteae73822014-10-30 22:57:45 +01001195 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001196 evo_data(push, 0x00000000);
1197 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1198 evo_data(push, 0x00000311);
1199 evo_data(push, 0x00000100);
1200 } else {
1201 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
1202 evo_data(push, 0x00000000);
1203 evo_data(push, (vactive << 16) | hactive);
1204 evo_data(push, ( vsynce << 16) | hsynce);
1205 evo_data(push, (vblanke << 16) | hblanke);
1206 evo_data(push, (vblanks << 16) | hblanks);
1207 evo_data(push, (vblan2e << 16) | vblan2s);
1208 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1209 evo_data(push, 0x00000000); /* ??? */
1210 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1211 evo_data(push, mode->clock * 1000);
1212 evo_data(push, 0x00200000); /* ??? */
1213 evo_data(push, mode->clock * 1000);
1214 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1215 evo_data(push, 0x00000311);
1216 evo_data(push, 0x00000100);
1217 }
1218
1219 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001220 }
1221
1222 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001223 nv50_crtc_set_dither(nv_crtc, false);
1224 nv50_crtc_set_scale(nv_crtc, false);
Roy Splieteae73822014-10-30 22:57:45 +01001225
1226 /* G94 only accepts this after setting scale */
1227 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA)
1228 nv50_crtc_set_raster_vblank_dmi(nv_crtc, vblankus);
1229
Ben Skeggse225f442012-11-21 14:40:21 +10001230 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07001231 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001232 return 0;
1233}
1234
1235static int
Ben Skeggse225f442012-11-21 14:40:21 +10001236nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001237 struct drm_framebuffer *old_fb)
1238{
Ben Skeggs77145f12012-07-31 16:16:21 +10001239 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001240 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1241 int ret;
1242
Matt Roperf4510a22014-04-01 15:22:40 -07001243 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10001244 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10001245 return 0;
1246 }
1247
Ben Skeggse225f442012-11-21 14:40:21 +10001248 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001249 if (ret)
1250 return ret;
1251
Ben Skeggse225f442012-11-21 14:40:21 +10001252 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07001253 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1254 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001255 return 0;
1256}
1257
1258static int
Ben Skeggse225f442012-11-21 14:40:21 +10001259nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001260 struct drm_framebuffer *fb, int x, int y,
1261 enum mode_set_atomic state)
1262{
1263 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001264 nv50_display_flip_stop(crtc);
1265 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001266 return 0;
1267}
1268
1269static void
Ben Skeggse225f442012-11-21 14:40:21 +10001270nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001271{
Ben Skeggse225f442012-11-21 14:40:21 +10001272 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001273 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1274 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1275 int i;
1276
1277 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001278 u16 r = nv_crtc->lut.r[i] >> 2;
1279 u16 g = nv_crtc->lut.g[i] >> 2;
1280 u16 b = nv_crtc->lut.b[i] >> 2;
1281
Ben Skeggs648d4df2014-08-10 04:10:27 +10001282 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001283 writew(r + 0x0000, lut + (i * 0x08) + 0);
1284 writew(g + 0x0000, lut + (i * 0x08) + 2);
1285 writew(b + 0x0000, lut + (i * 0x08) + 4);
1286 } else {
1287 writew(r + 0x6000, lut + (i * 0x20) + 0);
1288 writew(g + 0x6000, lut + (i * 0x20) + 2);
1289 writew(b + 0x6000, lut + (i * 0x20) + 4);
1290 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001291 }
1292}
1293
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001294static void
1295nv50_crtc_disable(struct drm_crtc *crtc)
1296{
1297 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10001298 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001299 if (head->image)
1300 nouveau_bo_unpin(head->image);
1301 nouveau_bo_ref(NULL, &head->image);
1302}
1303
Ben Skeggs438d99e2011-07-05 16:48:06 +10001304static int
Ben Skeggse225f442012-11-21 14:40:21 +10001305nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001306 uint32_t handle, uint32_t width, uint32_t height)
1307{
1308 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs5a560252014-11-10 15:52:02 +10001309 struct drm_gem_object *gem = NULL;
1310 struct nouveau_bo *nvbo = NULL;
1311 int ret = 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001312
Ben Skeggs5a560252014-11-10 15:52:02 +10001313 if (handle) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001314 if (width != 64 || height != 64)
1315 return -EINVAL;
1316
Chris Wilsona8ad0bd2016-05-09 11:04:54 +01001317 gem = drm_gem_object_lookup(file_priv, handle);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001318 if (unlikely(!gem))
1319 return -ENOENT;
1320 nvbo = nouveau_gem_object(gem);
1321
Ben Skeggs5a560252014-11-10 15:52:02 +10001322 ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001323 }
1324
Ben Skeggs5a560252014-11-10 15:52:02 +10001325 if (ret == 0) {
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001326 if (nv_crtc->cursor.nvbo)
1327 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1328 nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001329 }
Ben Skeggs5a560252014-11-10 15:52:02 +10001330 drm_gem_object_unreference_unlocked(gem);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001331
Ben Skeggs5a560252014-11-10 15:52:02 +10001332 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001333 return ret;
1334}
1335
1336static int
Ben Skeggse225f442012-11-21 14:40:21 +10001337nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001338{
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001339 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001340 struct nv50_curs *curs = nv50_curs(crtc);
1341 struct nv50_chan *chan = nv50_chan(curs);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001342 nvif_wr32(&chan->user, 0x0084, (y << 16) | (x & 0xffff));
1343 nvif_wr32(&chan->user, 0x0080, 0x00000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001344
1345 nv_crtc->cursor_saved_x = x;
1346 nv_crtc->cursor_saved_y = y;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001347 return 0;
1348}
1349
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001350static int
Ben Skeggse225f442012-11-21 14:40:21 +10001351nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001352 uint32_t size)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001353{
1354 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001355 u32 i;
1356
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001357 for (i = 0; i < size; i++) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001358 nv_crtc->lut.r[i] = r[i];
1359 nv_crtc->lut.g[i] = g[i];
1360 nv_crtc->lut.b[i] = b[i];
1361 }
1362
Ben Skeggse225f442012-11-21 14:40:21 +10001363 nv50_crtc_lut_load(crtc);
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001364
1365 return 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001366}
1367
1368static void
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001369nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y)
1370{
1371 nv50_crtc_cursor_move(&nv_crtc->base, x, y);
1372
1373 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
1374}
1375
1376static void
Ben Skeggse225f442012-11-21 14:40:21 +10001377nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001378{
1379 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001380 struct nv50_disp *disp = nv50_disp(crtc->dev);
1381 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001382 struct nv50_fbdma *fbdma;
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001383
Ben Skeggs0ad72862014-08-10 04:10:22 +10001384 list_for_each_entry(fbdma, &disp->fbdma, head) {
1385 nvif_object_fini(&fbdma->base[nv_crtc->index]);
1386 }
1387
1388 nv50_dmac_destroy(&head->ovly.base, disp->disp);
1389 nv50_pioc_destroy(&head->oimm.base);
1390 nv50_dmac_destroy(&head->sync.base, disp->disp);
1391 nv50_pioc_destroy(&head->curs.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001392
1393 /*XXX: this shouldn't be necessary, but the core doesn't call
1394 * disconnect() during the cleanup paths
1395 */
1396 if (head->image)
1397 nouveau_bo_unpin(head->image);
1398 nouveau_bo_ref(NULL, &head->image);
1399
Ben Skeggs5a560252014-11-10 15:52:02 +10001400 /*XXX: ditto */
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001401 if (nv_crtc->cursor.nvbo)
1402 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1403 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001404
Ben Skeggs438d99e2011-07-05 16:48:06 +10001405 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001406 if (nv_crtc->lut.nvbo)
1407 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001408 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001409
Ben Skeggs438d99e2011-07-05 16:48:06 +10001410 drm_crtc_cleanup(crtc);
1411 kfree(crtc);
1412}
1413
Ben Skeggse225f442012-11-21 14:40:21 +10001414static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1415 .dpms = nv50_crtc_dpms,
1416 .prepare = nv50_crtc_prepare,
1417 .commit = nv50_crtc_commit,
1418 .mode_fixup = nv50_crtc_mode_fixup,
1419 .mode_set = nv50_crtc_mode_set,
1420 .mode_set_base = nv50_crtc_mode_set_base,
1421 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1422 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001423 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001424};
1425
Ben Skeggse225f442012-11-21 14:40:21 +10001426static const struct drm_crtc_funcs nv50_crtc_func = {
1427 .cursor_set = nv50_crtc_cursor_set,
1428 .cursor_move = nv50_crtc_cursor_move,
1429 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10001430 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10001431 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001432 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001433};
1434
1435static int
Ben Skeggs0ad72862014-08-10 04:10:22 +10001436nv50_crtc_create(struct drm_device *dev, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001437{
Ben Skeggsa01ca782015-08-20 14:54:15 +10001438 struct nouveau_drm *drm = nouveau_drm(dev);
1439 struct nvif_device *device = &drm->device;
Ben Skeggse225f442012-11-21 14:40:21 +10001440 struct nv50_disp *disp = nv50_disp(dev);
1441 struct nv50_head *head;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001442 struct drm_crtc *crtc;
1443 int ret, i;
1444
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001445 head = kzalloc(sizeof(*head), GFP_KERNEL);
1446 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001447 return -ENOMEM;
1448
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001449 head->base.index = index;
Ben Skeggse225f442012-11-21 14:40:21 +10001450 head->base.set_dither = nv50_crtc_set_dither;
1451 head->base.set_scale = nv50_crtc_set_scale;
1452 head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
Ben Skeggsf9887d02012-11-21 13:03:42 +10001453 head->base.color_vibrance = 50;
1454 head->base.vibrant_hue = 0;
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001455 head->base.cursor.set_pos = nv50_crtc_cursor_restore;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001456 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001457 head->base.lut.r[i] = i << 8;
1458 head->base.lut.g[i] = i << 8;
1459 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001460 }
1461
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001462 crtc = &head->base.base;
Ben Skeggse225f442012-11-21 14:40:21 +10001463 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1464 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001465 drm_mode_crtc_set_gamma_size(crtc, 256);
1466
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10001467 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01001468 0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001469 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10001470 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001471 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001472 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001473 if (ret)
1474 nouveau_bo_unpin(head->base.lut.nvbo);
1475 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001476 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001477 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001478 }
1479
1480 if (ret)
1481 goto out;
1482
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001483 /* allocate cursor resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001484 ret = nv50_curs_create(device, disp->disp, index, &head->curs);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001485 if (ret)
1486 goto out;
1487
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001488 /* allocate page flip / sync resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001489 ret = nv50_base_create(device, disp->disp, index, disp->sync->bo.offset,
1490 &head->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001491 if (ret)
1492 goto out;
1493
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001494 head->sync.addr = EVO_FLIP_SEM0(index);
1495 head->sync.data = 0x00000000;
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001496
1497 /* allocate overlay resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001498 ret = nv50_oimm_create(device, disp->disp, index, &head->oimm);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001499 if (ret)
1500 goto out;
1501
Ben Skeggsa01ca782015-08-20 14:54:15 +10001502 ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset,
1503 &head->ovly);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001504 if (ret)
1505 goto out;
1506
Ben Skeggs438d99e2011-07-05 16:48:06 +10001507out:
1508 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10001509 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001510 return ret;
1511}
1512
1513/******************************************************************************
Ben Skeggsa91d3222014-12-22 16:30:13 +10001514 * Encoder helpers
1515 *****************************************************************************/
1516static bool
1517nv50_encoder_mode_fixup(struct drm_encoder *encoder,
1518 const struct drm_display_mode *mode,
1519 struct drm_display_mode *adjusted_mode)
1520{
1521 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1522 struct nouveau_connector *nv_connector;
1523
1524 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1525 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs576f7912014-12-22 17:19:26 +10001526 nv_connector->scaling_full = false;
1527 if (nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) {
1528 switch (nv_connector->type) {
1529 case DCB_CONNECTOR_LVDS:
1530 case DCB_CONNECTOR_LVDS_SPWG:
1531 case DCB_CONNECTOR_eDP:
1532 /* force use of scaler for non-edid modes */
1533 if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
1534 return true;
1535 nv_connector->scaling_full = true;
1536 break;
1537 default:
1538 return true;
1539 }
1540 }
1541
1542 drm_mode_copy(adjusted_mode, nv_connector->native_mode);
Ben Skeggsa91d3222014-12-22 16:30:13 +10001543 }
1544
1545 return true;
1546}
1547
1548/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001549 * DAC
1550 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001551static void
Ben Skeggse225f442012-11-21 14:40:21 +10001552nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001553{
1554 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001555 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001556 struct {
1557 struct nv50_disp_mthd_v1 base;
1558 struct nv50_disp_dac_pwr_v0 pwr;
1559 } args = {
1560 .base.version = 1,
1561 .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
1562 .base.hasht = nv_encoder->dcb->hasht,
1563 .base.hashm = nv_encoder->dcb->hashm,
1564 .pwr.state = 1,
1565 .pwr.data = 1,
1566 .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
1567 mode != DRM_MODE_DPMS_OFF),
1568 .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
1569 mode != DRM_MODE_DPMS_OFF),
1570 };
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001571
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001572 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001573}
1574
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001575static void
Ben Skeggse225f442012-11-21 14:40:21 +10001576nv50_dac_commit(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001577{
1578}
1579
1580static void
Ben Skeggse225f442012-11-21 14:40:21 +10001581nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001582 struct drm_display_mode *adjusted_mode)
1583{
Ben Skeggse225f442012-11-21 14:40:21 +10001584 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001585 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1586 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001587 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001588
Ben Skeggse225f442012-11-21 14:40:21 +10001589 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001590
Ben Skeggs97b19b52012-11-16 11:21:37 +10001591 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001592 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001593 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001594 u32 syncs = 0x00000000;
1595
1596 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1597 syncs |= 0x00000001;
1598 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1599 syncs |= 0x00000002;
1600
1601 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1602 evo_data(push, 1 << nv_crtc->index);
1603 evo_data(push, syncs);
1604 } else {
1605 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1606 u32 syncs = 0x00000001;
1607
1608 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1609 syncs |= 0x00000008;
1610 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1611 syncs |= 0x00000010;
1612
1613 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1614 magic |= 0x00000001;
1615
1616 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1617 evo_data(push, syncs);
1618 evo_data(push, magic);
1619 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1620 evo_data(push, 1 << nv_crtc->index);
1621 }
1622
1623 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001624 }
1625
1626 nv_encoder->crtc = encoder->crtc;
1627}
1628
1629static void
Ben Skeggse225f442012-11-21 14:40:21 +10001630nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001631{
1632 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001633 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001634 const int or = nv_encoder->or;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001635 u32 *push;
1636
1637 if (nv_encoder->crtc) {
Ben Skeggse225f442012-11-21 14:40:21 +10001638 nv50_crtc_prepare(nv_encoder->crtc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001639
Ben Skeggs97b19b52012-11-16 11:21:37 +10001640 push = evo_wait(mast, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001641 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001642 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001643 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1644 evo_data(push, 0x00000000);
1645 } else {
1646 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1647 evo_data(push, 0x00000000);
1648 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001649 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001650 }
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001651 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001652
1653 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001654}
1655
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001656static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10001657nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001658{
Ben Skeggsc4abd312014-08-10 04:10:26 +10001659 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001660 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsc4abd312014-08-10 04:10:26 +10001661 struct {
1662 struct nv50_disp_mthd_v1 base;
1663 struct nv50_disp_dac_load_v0 load;
1664 } args = {
1665 .base.version = 1,
1666 .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
1667 .base.hasht = nv_encoder->dcb->hasht,
1668 .base.hashm = nv_encoder->dcb->hashm,
1669 };
1670 int ret;
Ben Skeggsb6819932011-07-08 11:14:50 +10001671
Ben Skeggsc4abd312014-08-10 04:10:26 +10001672 args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
1673 if (args.load.data == 0)
1674 args.load.data = 340;
1675
1676 ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
1677 if (ret || !args.load.load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10001678 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10001679
Ben Skeggs35b21d32012-11-08 12:08:55 +10001680 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001681}
1682
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001683static void
Ben Skeggse225f442012-11-21 14:40:21 +10001684nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001685{
1686 drm_encoder_cleanup(encoder);
1687 kfree(encoder);
1688}
1689
Ben Skeggse225f442012-11-21 14:40:21 +10001690static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1691 .dpms = nv50_dac_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10001692 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggse225f442012-11-21 14:40:21 +10001693 .prepare = nv50_dac_disconnect,
1694 .commit = nv50_dac_commit,
1695 .mode_set = nv50_dac_mode_set,
1696 .disable = nv50_dac_disconnect,
1697 .get_crtc = nv50_display_crtc_get,
1698 .detect = nv50_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001699};
1700
Ben Skeggse225f442012-11-21 14:40:21 +10001701static const struct drm_encoder_funcs nv50_dac_func = {
1702 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001703};
1704
1705static int
Ben Skeggse225f442012-11-21 14:40:21 +10001706nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001707{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001708 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10001709 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001710 struct nvkm_i2c_bus *bus;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001711 struct nouveau_encoder *nv_encoder;
1712 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001713 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001714
1715 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1716 if (!nv_encoder)
1717 return -ENOMEM;
1718 nv_encoder->dcb = dcbe;
1719 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001720
1721 bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
1722 if (bus)
1723 nv_encoder->i2c = &bus->i2c;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001724
1725 encoder = to_drm_encoder(nv_encoder);
1726 encoder->possible_crtcs = dcbe->heads;
1727 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02001728 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type, NULL);
Ben Skeggse225f442012-11-21 14:40:21 +10001729 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001730
1731 drm_mode_connector_attach_encoder(connector, encoder);
1732 return 0;
1733}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001734
1735/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10001736 * Audio
1737 *****************************************************************************/
1738static void
Ben Skeggse225f442012-11-21 14:40:21 +10001739nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001740{
1741 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001742 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs78951d22011-11-11 18:13:13 +10001743 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001744 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsd889c522014-09-15 21:11:51 +10001745 struct __packed {
1746 struct {
1747 struct nv50_disp_mthd_v1 mthd;
1748 struct nv50_disp_sor_hda_eld_v0 eld;
1749 } base;
Ben Skeggs120b0c32014-08-10 04:10:26 +10001750 u8 data[sizeof(nv_connector->base.eld)];
1751 } args = {
Ben Skeggsd889c522014-09-15 21:11:51 +10001752 .base.mthd.version = 1,
1753 .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1754 .base.mthd.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001755 .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1756 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001757 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001758
1759 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1760 if (!drm_detect_monitor_audio(nv_connector->edid))
1761 return;
1762
Ben Skeggs78951d22011-11-11 18:13:13 +10001763 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001764 memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001765
Jani Nikula938fd8a2014-10-28 16:20:48 +02001766 nvif_mthd(disp->disp, 0, &args,
1767 sizeof(args.base) + drm_eld_size(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001768}
1769
1770static void
Ben Skeggscc2a9072014-09-15 21:29:05 +10001771nv50_audio_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001772{
1773 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001774 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001775 struct {
1776 struct nv50_disp_mthd_v1 base;
1777 struct nv50_disp_sor_hda_eld_v0 eld;
1778 } args = {
1779 .base.version = 1,
1780 .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1781 .base.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001782 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1783 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001784 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001785
Ben Skeggs120b0c32014-08-10 04:10:26 +10001786 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001787}
1788
1789/******************************************************************************
1790 * HDMI
1791 *****************************************************************************/
1792static void
Ben Skeggse225f442012-11-21 14:40:21 +10001793nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001794{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001795 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1796 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001797 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001798 struct {
1799 struct nv50_disp_mthd_v1 base;
1800 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1801 } args = {
1802 .base.version = 1,
1803 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1804 .base.hasht = nv_encoder->dcb->hasht,
1805 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1806 (0x0100 << nv_crtc->index),
1807 .pwr.state = 1,
1808 .pwr.rekey = 56, /* binary driver, and tegra, constant */
1809 };
1810 struct nouveau_connector *nv_connector;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001811 u32 max_ac_packet;
1812
1813 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1814 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1815 return;
1816
1817 max_ac_packet = mode->htotal - mode->hdisplay;
Ben Skeggse00f2232014-08-10 04:10:26 +10001818 max_ac_packet -= args.pwr.rekey;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001819 max_ac_packet -= 18; /* constant from tegra */
Ben Skeggse00f2232014-08-10 04:10:26 +10001820 args.pwr.max_ac_packet = max_ac_packet / 32;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001821
Ben Skeggse00f2232014-08-10 04:10:26 +10001822 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggse225f442012-11-21 14:40:21 +10001823 nv50_audio_mode_set(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10001824}
1825
1826static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001827nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001828{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001829 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001830 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001831 struct {
1832 struct nv50_disp_mthd_v1 base;
1833 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1834 } args = {
1835 .base.version = 1,
1836 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1837 .base.hasht = nv_encoder->dcb->hasht,
1838 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1839 (0x0100 << nv_crtc->index),
1840 };
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001841
Ben Skeggse00f2232014-08-10 04:10:26 +10001842 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001843}
1844
1845/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001846 * SOR
1847 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001848static void
Ben Skeggse225f442012-11-21 14:40:21 +10001849nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001850{
1851 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001852 struct nv50_disp *disp = nv50_disp(encoder->dev);
1853 struct {
1854 struct nv50_disp_mthd_v1 base;
1855 struct nv50_disp_sor_pwr_v0 pwr;
1856 } args = {
1857 .base.version = 1,
1858 .base.method = NV50_DISP_MTHD_V1_SOR_PWR,
1859 .base.hasht = nv_encoder->dcb->hasht,
1860 .base.hashm = nv_encoder->dcb->hashm,
1861 .pwr.state = mode == DRM_MODE_DPMS_ON,
1862 };
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001863 struct {
1864 struct nv50_disp_mthd_v1 base;
1865 struct nv50_disp_sor_dp_pwr_v0 pwr;
1866 } link = {
1867 .base.version = 1,
1868 .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
1869 .base.hasht = nv_encoder->dcb->hasht,
1870 .base.hashm = nv_encoder->dcb->hashm,
1871 .pwr.state = mode == DRM_MODE_DPMS_ON,
1872 };
Ben Skeggs83fc0832011-07-05 13:08:40 +10001873 struct drm_device *dev = encoder->dev;
1874 struct drm_encoder *partner;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001875
1876 nv_encoder->last_dpms = mode;
1877
1878 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1879 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1880
1881 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1882 continue;
1883
1884 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10001885 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10001886 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1887 return;
1888 break;
1889 }
1890 }
1891
Ben Skeggs48743222014-05-31 01:48:06 +10001892 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001893 args.pwr.state = 1;
1894 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001895 nvif_mthd(disp->disp, 0, &link, sizeof(link));
Ben Skeggs48743222014-05-31 01:48:06 +10001896 } else {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001897 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs48743222014-05-31 01:48:06 +10001898 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001899}
1900
Ben Skeggs83fc0832011-07-05 13:08:40 +10001901static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001902nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1903{
1904 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1905 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1906 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001907 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10001908 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1909 evo_data(push, (nv_encoder->ctrl = temp));
1910 } else {
1911 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1912 evo_data(push, (nv_encoder->ctrl = temp));
1913 }
1914 evo_kick(push, mast);
1915 }
1916}
1917
1918static void
Ben Skeggse225f442012-11-21 14:40:21 +10001919nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001920{
1921 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001922 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001923
1924 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1925 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001926
1927 if (nv_crtc) {
1928 nv50_crtc_prepare(&nv_crtc->base);
1929 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001930 nv50_audio_disconnect(encoder, nv_crtc);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001931 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1932 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001933}
1934
1935static void
Ben Skeggse225f442012-11-21 14:40:21 +10001936nv50_sor_commit(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001937{
1938}
1939
1940static void
Ben Skeggse225f442012-11-21 14:40:21 +10001941nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001942 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001943{
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001944 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1945 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1946 struct {
1947 struct nv50_disp_mthd_v1 base;
1948 struct nv50_disp_sor_lvds_script_v0 lvds;
1949 } lvds = {
1950 .base.version = 1,
1951 .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
1952 .base.hasht = nv_encoder->dcb->hasht,
1953 .base.hashm = nv_encoder->dcb->hashm,
1954 };
Ben Skeggse225f442012-11-21 14:40:21 +10001955 struct nv50_disp *disp = nv50_disp(encoder->dev);
1956 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001957 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10001958 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001959 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10001960 struct nvbios *bios = &drm->vbios;
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001961 u32 mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001962 u8 owner = 1 << nv_crtc->index;
1963 u8 proto = 0xf;
1964 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001965
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001966 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001967 nv_encoder->crtc = encoder->crtc;
1968
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001969 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10001970 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001971 if (nv_encoder->dcb->sorconf.link & 1) {
Hauke Mehrtens16ef53a92015-11-03 21:00:10 -05001972 proto = 0x1;
1973 /* Only enable dual-link if:
1974 * - Need to (i.e. rate > 165MHz)
1975 * - DCB says we can
1976 * - Not an HDMI monitor, since there's no dual-link
1977 * on HDMI.
1978 */
1979 if (mode->clock >= 165000 &&
1980 nv_encoder->dcb->duallink_possible &&
1981 !drm_detect_hdmi_monitor(nv_connector->edid))
1982 proto |= 0x4;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001983 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001984 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001985 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001986
Ben Skeggse84a35a2014-06-05 10:59:55 +10001987 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001988 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001989 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001990 proto = 0x0;
1991
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001992 if (bios->fp_no_ddc) {
1993 if (bios->fp.dual_link)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001994 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001995 if (bios->fp.if_is_24bit)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001996 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001997 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10001998 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001999 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002000 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002001 } else
2002 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002003 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002004 }
2005
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002006 if (lvds.lvds.script & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002007 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002008 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002009 } else {
2010 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002011 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002012 }
2013
2014 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002015 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002016 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10002017
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002018 nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds));
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002019 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10002020 case DCB_OUTPUT_DP:
Ben Skeggs3488c572012-03-12 11:42:20 +10002021 if (nv_connector->base.display_info.bpc == 6) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002022 nv_encoder->dp.datarate = mode->clock * 18 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002023 depth = 0x2;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002024 } else
2025 if (nv_connector->base.display_info.bpc == 8) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002026 nv_encoder->dp.datarate = mode->clock * 24 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002027 depth = 0x5;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002028 } else {
2029 nv_encoder->dp.datarate = mode->clock * 30 / 8;
2030 depth = 0x6;
Ben Skeggs3488c572012-03-12 11:42:20 +10002031 }
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002032
2033 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002034 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002035 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002036 proto = 0x9;
Ben Skeggs3eee8642014-09-15 15:20:47 +10002037 nv50_audio_mode_set(encoder, mode);
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002038 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002039 default:
2040 BUG_ON(1);
2041 break;
2042 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10002043
Ben Skeggse84a35a2014-06-05 10:59:55 +10002044 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002045
Ben Skeggs648d4df2014-08-10 04:10:27 +10002046 if (nv50_vers(mast) >= GF110_DISP) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10002047 u32 *push = evo_wait(mast, 3);
2048 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002049 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
2050 u32 syncs = 0x00000001;
2051
2052 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2053 syncs |= 0x00000008;
2054 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2055 syncs |= 0x00000010;
2056
2057 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2058 magic |= 0x00000001;
2059
2060 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
2061 evo_data(push, syncs | (depth << 6));
2062 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10002063 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002064 }
2065
Ben Skeggse84a35a2014-06-05 10:59:55 +10002066 ctrl = proto << 8;
2067 mask = 0x00000f00;
2068 } else {
2069 ctrl = (depth << 16) | (proto << 8);
2070 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2071 ctrl |= 0x00001000;
2072 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2073 ctrl |= 0x00002000;
2074 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002075 }
2076
Ben Skeggse84a35a2014-06-05 10:59:55 +10002077 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002078}
2079
2080static void
Ben Skeggse225f442012-11-21 14:40:21 +10002081nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002082{
2083 drm_encoder_cleanup(encoder);
2084 kfree(encoder);
2085}
2086
Ben Skeggse225f442012-11-21 14:40:21 +10002087static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
2088 .dpms = nv50_sor_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10002089 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggs5a885f02013-02-20 14:34:18 +10002090 .prepare = nv50_sor_disconnect,
Ben Skeggse225f442012-11-21 14:40:21 +10002091 .commit = nv50_sor_commit,
2092 .mode_set = nv50_sor_mode_set,
2093 .disable = nv50_sor_disconnect,
2094 .get_crtc = nv50_display_crtc_get,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002095};
2096
Ben Skeggse225f442012-11-21 14:40:21 +10002097static const struct drm_encoder_funcs nv50_sor_func = {
2098 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002099};
2100
2101static int
Ben Skeggse225f442012-11-21 14:40:21 +10002102nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002103{
Ben Skeggs5ed50202013-02-11 20:15:03 +10002104 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002105 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002106 struct nouveau_encoder *nv_encoder;
2107 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10002108 int type;
2109
2110 switch (dcbe->type) {
2111 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
2112 case DCB_OUTPUT_TMDS:
2113 case DCB_OUTPUT_DP:
2114 default:
2115 type = DRM_MODE_ENCODER_TMDS;
2116 break;
2117 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10002118
2119 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2120 if (!nv_encoder)
2121 return -ENOMEM;
2122 nv_encoder->dcb = dcbe;
2123 nv_encoder->or = ffs(dcbe->or) - 1;
2124 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
2125
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002126 if (dcbe->type == DCB_OUTPUT_DP) {
2127 struct nvkm_i2c_aux *aux =
2128 nvkm_i2c_aux_find(i2c, dcbe->i2c_index);
2129 if (aux) {
2130 nv_encoder->i2c = &aux->i2c;
2131 nv_encoder->aux = aux;
2132 }
2133 } else {
2134 struct nvkm_i2c_bus *bus =
2135 nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
2136 if (bus)
2137 nv_encoder->i2c = &bus->i2c;
2138 }
2139
Ben Skeggs83fc0832011-07-05 13:08:40 +10002140 encoder = to_drm_encoder(nv_encoder);
2141 encoder->possible_crtcs = dcbe->heads;
2142 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002143 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type, NULL);
Ben Skeggse225f442012-11-21 14:40:21 +10002144 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002145
2146 drm_mode_connector_attach_encoder(connector, encoder);
2147 return 0;
2148}
Ben Skeggs26f6d882011-07-04 16:25:18 +10002149
2150/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10002151 * PIOR
2152 *****************************************************************************/
2153
2154static void
2155nv50_pior_dpms(struct drm_encoder *encoder, int mode)
2156{
2157 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2158 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs67cb49c2014-08-10 04:10:27 +10002159 struct {
2160 struct nv50_disp_mthd_v1 base;
2161 struct nv50_disp_pior_pwr_v0 pwr;
2162 } args = {
2163 .base.version = 1,
2164 .base.method = NV50_DISP_MTHD_V1_PIOR_PWR,
2165 .base.hasht = nv_encoder->dcb->hasht,
2166 .base.hashm = nv_encoder->dcb->hashm,
2167 .pwr.state = mode == DRM_MODE_DPMS_ON,
2168 .pwr.type = nv_encoder->dcb->type,
2169 };
2170
2171 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggseb6313a2013-02-11 09:52:58 +10002172}
2173
2174static bool
2175nv50_pior_mode_fixup(struct drm_encoder *encoder,
2176 const struct drm_display_mode *mode,
2177 struct drm_display_mode *adjusted_mode)
2178{
Ben Skeggsa91d3222014-12-22 16:30:13 +10002179 if (!nv50_encoder_mode_fixup(encoder, mode, adjusted_mode))
2180 return false;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002181 adjusted_mode->clock *= 2;
2182 return true;
2183}
2184
2185static void
2186nv50_pior_commit(struct drm_encoder *encoder)
2187{
2188}
2189
2190static void
2191nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
2192 struct drm_display_mode *adjusted_mode)
2193{
2194 struct nv50_mast *mast = nv50_mast(encoder->dev);
2195 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2196 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
2197 struct nouveau_connector *nv_connector;
2198 u8 owner = 1 << nv_crtc->index;
2199 u8 proto, depth;
2200 u32 *push;
2201
2202 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2203 switch (nv_connector->base.display_info.bpc) {
2204 case 10: depth = 0x6; break;
2205 case 8: depth = 0x5; break;
2206 case 6: depth = 0x2; break;
2207 default: depth = 0x0; break;
2208 }
2209
2210 switch (nv_encoder->dcb->type) {
2211 case DCB_OUTPUT_TMDS:
2212 case DCB_OUTPUT_DP:
2213 proto = 0x0;
2214 break;
2215 default:
2216 BUG_ON(1);
2217 break;
2218 }
2219
2220 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
2221
2222 push = evo_wait(mast, 8);
2223 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002224 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002225 u32 ctrl = (depth << 16) | (proto << 8) | owner;
2226 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2227 ctrl |= 0x00001000;
2228 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2229 ctrl |= 0x00002000;
2230 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
2231 evo_data(push, ctrl);
2232 }
2233
2234 evo_kick(push, mast);
2235 }
2236
2237 nv_encoder->crtc = encoder->crtc;
2238}
2239
2240static void
2241nv50_pior_disconnect(struct drm_encoder *encoder)
2242{
2243 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2244 struct nv50_mast *mast = nv50_mast(encoder->dev);
2245 const int or = nv_encoder->or;
2246 u32 *push;
2247
2248 if (nv_encoder->crtc) {
2249 nv50_crtc_prepare(nv_encoder->crtc);
2250
2251 push = evo_wait(mast, 4);
2252 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002253 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002254 evo_mthd(push, 0x0700 + (or * 0x040), 1);
2255 evo_data(push, 0x00000000);
2256 }
Ben Skeggseb6313a2013-02-11 09:52:58 +10002257 evo_kick(push, mast);
2258 }
2259 }
2260
2261 nv_encoder->crtc = NULL;
2262}
2263
2264static void
2265nv50_pior_destroy(struct drm_encoder *encoder)
2266{
2267 drm_encoder_cleanup(encoder);
2268 kfree(encoder);
2269}
2270
2271static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
2272 .dpms = nv50_pior_dpms,
2273 .mode_fixup = nv50_pior_mode_fixup,
2274 .prepare = nv50_pior_disconnect,
2275 .commit = nv50_pior_commit,
2276 .mode_set = nv50_pior_mode_set,
2277 .disable = nv50_pior_disconnect,
2278 .get_crtc = nv50_display_crtc_get,
2279};
2280
2281static const struct drm_encoder_funcs nv50_pior_func = {
2282 .destroy = nv50_pior_destroy,
2283};
2284
2285static int
2286nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2287{
2288 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002289 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002290 struct nvkm_i2c_bus *bus = NULL;
2291 struct nvkm_i2c_aux *aux = NULL;
2292 struct i2c_adapter *ddc;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002293 struct nouveau_encoder *nv_encoder;
2294 struct drm_encoder *encoder;
2295 int type;
2296
2297 switch (dcbe->type) {
2298 case DCB_OUTPUT_TMDS:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002299 bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev));
2300 ddc = bus ? &bus->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002301 type = DRM_MODE_ENCODER_TMDS;
2302 break;
2303 case DCB_OUTPUT_DP:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002304 aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev));
2305 ddc = aux ? &aux->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002306 type = DRM_MODE_ENCODER_TMDS;
2307 break;
2308 default:
2309 return -ENODEV;
2310 }
2311
2312 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2313 if (!nv_encoder)
2314 return -ENOMEM;
2315 nv_encoder->dcb = dcbe;
2316 nv_encoder->or = ffs(dcbe->or) - 1;
2317 nv_encoder->i2c = ddc;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002318 nv_encoder->aux = aux;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002319
2320 encoder = to_drm_encoder(nv_encoder);
2321 encoder->possible_crtcs = dcbe->heads;
2322 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002323 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type, NULL);
Ben Skeggseb6313a2013-02-11 09:52:58 +10002324 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2325
2326 drm_mode_connector_attach_encoder(connector, encoder);
2327 return 0;
2328}
2329
2330/******************************************************************************
Ben Skeggsab0af552014-08-10 04:10:19 +10002331 * Framebuffer
2332 *****************************************************************************/
2333
Ben Skeggs8a423642014-08-10 04:10:19 +10002334static void
Ben Skeggs0ad72862014-08-10 04:10:22 +10002335nv50_fbdma_fini(struct nv50_fbdma *fbdma)
Ben Skeggs8a423642014-08-10 04:10:19 +10002336{
Ben Skeggs0ad72862014-08-10 04:10:22 +10002337 int i;
2338 for (i = 0; i < ARRAY_SIZE(fbdma->base); i++)
2339 nvif_object_fini(&fbdma->base[i]);
2340 nvif_object_fini(&fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002341 list_del(&fbdma->head);
2342 kfree(fbdma);
2343}
2344
2345static int
2346nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind)
2347{
2348 struct nouveau_drm *drm = nouveau_drm(dev);
2349 struct nv50_disp *disp = nv50_disp(dev);
2350 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggs4acfd702014-08-10 04:10:24 +10002351 struct __attribute__ ((packed)) {
2352 struct nv_dma_v0 base;
2353 union {
2354 struct nv50_dma_v0 nv50;
2355 struct gf100_dma_v0 gf100;
Ben Skeggsbd70563f2015-08-20 14:54:21 +10002356 struct gf119_dma_v0 gf119;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002357 };
2358 } args = {};
Ben Skeggs8a423642014-08-10 04:10:19 +10002359 struct nv50_fbdma *fbdma;
2360 struct drm_crtc *crtc;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002361 u32 size = sizeof(args.base);
Ben Skeggs8a423642014-08-10 04:10:19 +10002362 int ret;
2363
2364 list_for_each_entry(fbdma, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002365 if (fbdma->core.handle == name)
Ben Skeggs8a423642014-08-10 04:10:19 +10002366 return 0;
2367 }
2368
2369 fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL);
2370 if (!fbdma)
2371 return -ENOMEM;
2372 list_add(&fbdma->head, &disp->fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002373
Ben Skeggs4acfd702014-08-10 04:10:24 +10002374 args.base.target = NV_DMA_V0_TARGET_VRAM;
2375 args.base.access = NV_DMA_V0_ACCESS_RDWR;
2376 args.base.start = offset;
2377 args.base.limit = offset + length - 1;
Ben Skeggs8a423642014-08-10 04:10:19 +10002378
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002379 if (drm->device.info.chipset < 0x80) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002380 args.nv50.part = NV50_DMA_V0_PART_256;
2381 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002382 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002383 if (drm->device.info.chipset < 0xc0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002384 args.nv50.part = NV50_DMA_V0_PART_256;
2385 args.nv50.kind = kind;
2386 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002387 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002388 if (drm->device.info.chipset < 0xd0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002389 args.gf100.kind = kind;
2390 size += sizeof(args.gf100);
Ben Skeggs8a423642014-08-10 04:10:19 +10002391 } else {
Ben Skeggsbd70563f2015-08-20 14:54:21 +10002392 args.gf119.page = GF119_DMA_V0_PAGE_LP;
2393 args.gf119.kind = kind;
2394 size += sizeof(args.gf119);
Ben Skeggs8a423642014-08-10 04:10:19 +10002395 }
2396
2397 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002398 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsa01ca782015-08-20 14:54:15 +10002399 int ret = nvif_object_init(&head->sync.base.base.user, name,
2400 NV_DMA_IN_MEMORY, &args, size,
Ben Skeggs0ad72862014-08-10 04:10:22 +10002401 &fbdma->base[head->base.index]);
Ben Skeggs8a423642014-08-10 04:10:19 +10002402 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002403 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002404 return ret;
2405 }
2406 }
2407
Ben Skeggsa01ca782015-08-20 14:54:15 +10002408 ret = nvif_object_init(&mast->base.base.user, name, NV_DMA_IN_MEMORY,
2409 &args, size, &fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002410 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002411 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002412 return ret;
2413 }
2414
2415 return 0;
2416}
2417
Ben Skeggsab0af552014-08-10 04:10:19 +10002418static void
2419nv50_fb_dtor(struct drm_framebuffer *fb)
2420{
2421}
2422
2423static int
2424nv50_fb_ctor(struct drm_framebuffer *fb)
2425{
2426 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
2427 struct nouveau_drm *drm = nouveau_drm(fb->dev);
2428 struct nouveau_bo *nvbo = nv_fb->nvbo;
Ben Skeggs8a423642014-08-10 04:10:19 +10002429 struct nv50_disp *disp = nv50_disp(fb->dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002430 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
2431 u8 tile = nvbo->tile_mode;
Ben Skeggsab0af552014-08-10 04:10:19 +10002432
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002433 if (drm->device.info.chipset >= 0xc0)
Ben Skeggs8a423642014-08-10 04:10:19 +10002434 tile >>= 4; /* yep.. */
2435
Ben Skeggsab0af552014-08-10 04:10:19 +10002436 switch (fb->depth) {
2437 case 8: nv_fb->r_format = 0x1e00; break;
2438 case 15: nv_fb->r_format = 0xe900; break;
2439 case 16: nv_fb->r_format = 0xe800; break;
2440 case 24:
2441 case 32: nv_fb->r_format = 0xcf00; break;
2442 case 30: nv_fb->r_format = 0xd100; break;
2443 default:
2444 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
2445 return -EINVAL;
2446 }
2447
Ben Skeggs648d4df2014-08-10 04:10:27 +10002448 if (disp->disp->oclass < G82_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002449 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2450 (fb->pitches[0] | 0x00100000);
2451 nv_fb->r_format |= kind << 16;
2452 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10002453 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002454 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2455 (fb->pitches[0] | 0x00100000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002456 } else {
Ben Skeggs8a423642014-08-10 04:10:19 +10002457 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2458 (fb->pitches[0] | 0x01000000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002459 }
Ben Skeggs8a423642014-08-10 04:10:19 +10002460 nv_fb->r_handle = 0xffff0000 | kind;
Ben Skeggsab0af552014-08-10 04:10:19 +10002461
Ben Skeggsf392ec42014-08-10 04:10:28 +10002462 return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0,
2463 drm->device.info.ram_user, kind);
Ben Skeggsab0af552014-08-10 04:10:19 +10002464}
2465
2466/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002467 * Init
2468 *****************************************************************************/
Ben Skeggsab0af552014-08-10 04:10:19 +10002469
Ben Skeggs2a44e492011-11-09 11:36:33 +10002470void
Ben Skeggse225f442012-11-21 14:40:21 +10002471nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002472{
Ben Skeggs26f6d882011-07-04 16:25:18 +10002473}
2474
2475int
Ben Skeggse225f442012-11-21 14:40:21 +10002476nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002477{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002478 struct nv50_disp *disp = nv50_disp(dev);
2479 struct drm_crtc *crtc;
2480 u32 *push;
2481
2482 push = evo_wait(nv50_mast(dev), 32);
2483 if (!push)
2484 return -EBUSY;
2485
2486 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2487 struct nv50_sync *sync = nv50_sync(crtc);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002488
2489 nv50_crtc_lut_load(crtc);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002490 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002491 }
2492
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002493 evo_mthd(push, 0x0088, 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10002494 evo_data(push, nv50_mast(dev)->base.sync.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002495 evo_kick(push, nv50_mast(dev));
2496 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002497}
2498
2499void
Ben Skeggse225f442012-11-21 14:40:21 +10002500nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002501{
Ben Skeggse225f442012-11-21 14:40:21 +10002502 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002503 struct nv50_fbdma *fbdma, *fbtmp;
2504
2505 list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002506 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002507 }
Ben Skeggs26f6d882011-07-04 16:25:18 +10002508
Ben Skeggs0ad72862014-08-10 04:10:22 +10002509 nv50_dmac_destroy(&disp->mast.base, disp->disp);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10002510
Ben Skeggs816af2f2011-11-16 15:48:48 +10002511 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002512 if (disp->sync)
2513 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10002514 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10002515
Ben Skeggs77145f12012-07-31 16:16:21 +10002516 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002517 kfree(disp);
2518}
2519
2520int
Ben Skeggse225f442012-11-21 14:40:21 +10002521nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002522{
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002523 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggs77145f12012-07-31 16:16:21 +10002524 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10002525 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002526 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10002527 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10002528 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002529 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002530
2531 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2532 if (!disp)
2533 return -ENOMEM;
Ben Skeggs8a423642014-08-10 04:10:19 +10002534 INIT_LIST_HEAD(&disp->fbdma);
Ben Skeggs77145f12012-07-31 16:16:21 +10002535
2536 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10002537 nouveau_display(dev)->dtor = nv50_display_destroy;
2538 nouveau_display(dev)->init = nv50_display_init;
2539 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggsab0af552014-08-10 04:10:19 +10002540 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
2541 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
Ben Skeggs0ad72862014-08-10 04:10:22 +10002542 disp->disp = &nouveau_display(dev)->disp;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002543
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002544 /* small shared memory area we use for notifiers and semaphores */
2545 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01002546 0, 0x0000, NULL, NULL, &disp->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002547 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10002548 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002549 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002550 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002551 if (ret)
2552 nouveau_bo_unpin(disp->sync);
2553 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002554 if (ret)
2555 nouveau_bo_ref(NULL, &disp->sync);
2556 }
2557
2558 if (ret)
2559 goto out;
2560
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002561 /* allocate master evo channel */
Ben Skeggsa01ca782015-08-20 14:54:15 +10002562 ret = nv50_core_create(device, disp->disp, disp->sync->bo.offset,
Ben Skeggs410f3ec2014-08-10 04:10:25 +10002563 &disp->mast);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002564 if (ret)
2565 goto out;
2566
Ben Skeggs438d99e2011-07-05 16:48:06 +10002567 /* create crtc objects to represent the hw heads */
Ben Skeggs648d4df2014-08-10 04:10:27 +10002568 if (disp->disp->oclass >= GF110_DISP)
Ben Skeggsa01ca782015-08-20 14:54:15 +10002569 crtcs = nvif_rd32(&device->object, 0x022448);
Ben Skeggs63718a02012-11-16 11:44:14 +10002570 else
2571 crtcs = 2;
2572
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002573 for (i = 0; i < crtcs; i++) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002574 ret = nv50_crtc_create(dev, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002575 if (ret)
2576 goto out;
2577 }
2578
Ben Skeggs83fc0832011-07-05 13:08:40 +10002579 /* create encoder/connector objects based on VBIOS DCB table */
2580 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2581 connector = nouveau_connector_create(dev, dcbe->connector);
2582 if (IS_ERR(connector))
2583 continue;
2584
Ben Skeggseb6313a2013-02-11 09:52:58 +10002585 if (dcbe->location == DCB_LOC_ON_CHIP) {
2586 switch (dcbe->type) {
2587 case DCB_OUTPUT_TMDS:
2588 case DCB_OUTPUT_LVDS:
2589 case DCB_OUTPUT_DP:
2590 ret = nv50_sor_create(connector, dcbe);
2591 break;
2592 case DCB_OUTPUT_ANALOG:
2593 ret = nv50_dac_create(connector, dcbe);
2594 break;
2595 default:
2596 ret = -ENODEV;
2597 break;
2598 }
2599 } else {
2600 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002601 }
2602
Ben Skeggseb6313a2013-02-11 09:52:58 +10002603 if (ret) {
2604 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2605 dcbe->location, dcbe->type,
2606 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10002607 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002608 }
2609 }
2610
2611 /* cull any connectors we created that don't have an encoder */
2612 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2613 if (connector->encoder_ids[0])
2614 continue;
2615
Ben Skeggs77145f12012-07-31 16:16:21 +10002616 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03002617 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002618 connector->funcs->destroy(connector);
2619 }
2620
Ben Skeggs26f6d882011-07-04 16:25:18 +10002621out:
2622 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002623 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002624 return ret;
2625}