blob: 99a3866efbc239020fc9d0d8fcb46bd6f6e6a26f [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 Skeggsfd478772016-07-09 10:41:01 +1000300 GP104_DISP_CORE_CHANNEL_DMA,
Ben Skeggsf9d5cbb2016-07-09 10:41:01 +1000301 GP100_DISP_CORE_CHANNEL_DMA,
Ben Skeggsdb1eb522016-02-11 08:35:32 +1000302 GM200_DISP_CORE_CHANNEL_DMA,
Ben Skeggs648d4df2014-08-10 04:10:27 +1000303 GM107_DISP_CORE_CHANNEL_DMA,
304 GK110_DISP_CORE_CHANNEL_DMA,
305 GK104_DISP_CORE_CHANNEL_DMA,
306 GF110_DISP_CORE_CHANNEL_DMA,
307 GT214_DISP_CORE_CHANNEL_DMA,
308 GT206_DISP_CORE_CHANNEL_DMA,
309 GT200_DISP_CORE_CHANNEL_DMA,
310 G82_DISP_CORE_CHANNEL_DMA,
311 NV50_DISP_CORE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000312 0
313 };
314
Ben Skeggsa01ca782015-08-20 14:54:15 +1000315 return nv50_dmac_create(device, disp, oclass, 0, &args, sizeof(args),
316 syncbuf, &core->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000317}
318
319/******************************************************************************
320 * Base
321 *****************************************************************************/
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000322
Ben Skeggse225f442012-11-21 14:40:21 +1000323struct nv50_sync {
324 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000325 u32 addr;
326 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000327};
328
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000329static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000330nv50_base_create(struct nvif_device *device, struct nvif_object *disp,
331 int head, u64 syncbuf, struct nv50_sync *base)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000332{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000333 struct nv50_disp_base_channel_dma_v0 args = {
334 .pushbuf = 0xb0007c00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000335 .head = head,
336 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000337 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000338 GK110_DISP_BASE_CHANNEL_DMA,
339 GK104_DISP_BASE_CHANNEL_DMA,
340 GF110_DISP_BASE_CHANNEL_DMA,
341 GT214_DISP_BASE_CHANNEL_DMA,
342 GT200_DISP_BASE_CHANNEL_DMA,
343 G82_DISP_BASE_CHANNEL_DMA,
344 NV50_DISP_BASE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000345 0
346 };
347
Ben Skeggsa01ca782015-08-20 14:54:15 +1000348 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000349 syncbuf, &base->base);
350}
351
352/******************************************************************************
353 * Overlay
354 *****************************************************************************/
355
Ben Skeggse225f442012-11-21 14:40:21 +1000356struct nv50_ovly {
357 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000358};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000359
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000360static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000361nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp,
362 int head, u64 syncbuf, struct nv50_ovly *ovly)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000363{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000364 struct nv50_disp_overlay_channel_dma_v0 args = {
365 .pushbuf = 0xb0007e00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000366 .head = head,
367 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000368 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000369 GK104_DISP_OVERLAY_CONTROL_DMA,
370 GF110_DISP_OVERLAY_CONTROL_DMA,
371 GT214_DISP_OVERLAY_CHANNEL_DMA,
372 GT200_DISP_OVERLAY_CHANNEL_DMA,
373 G82_DISP_OVERLAY_CHANNEL_DMA,
374 NV50_DISP_OVERLAY_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000375 0
376 };
377
Ben Skeggsa01ca782015-08-20 14:54:15 +1000378 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000379 syncbuf, &ovly->base);
380}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000381
Ben Skeggse225f442012-11-21 14:40:21 +1000382struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000383 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000384 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000385 struct nv50_curs curs;
386 struct nv50_sync sync;
387 struct nv50_ovly ovly;
388 struct nv50_oimm oimm;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000389};
390
Ben Skeggse225f442012-11-21 14:40:21 +1000391#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
392#define nv50_curs(c) (&nv50_head(c)->curs)
393#define nv50_sync(c) (&nv50_head(c)->sync)
394#define nv50_ovly(c) (&nv50_head(c)->ovly)
395#define nv50_oimm(c) (&nv50_head(c)->oimm)
396#define nv50_chan(c) (&(c)->base.base)
Ben Skeggs0ad72862014-08-10 04:10:22 +1000397#define nv50_vers(c) nv50_chan(c)->user.oclass
398
399struct nv50_fbdma {
400 struct list_head head;
401 struct nvif_object core;
402 struct nvif_object base[4];
403};
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000404
Ben Skeggse225f442012-11-21 14:40:21 +1000405struct nv50_disp {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000406 struct nvif_object *disp;
Ben Skeggse225f442012-11-21 14:40:21 +1000407 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000408
Ben Skeggs8a423642014-08-10 04:10:19 +1000409 struct list_head fbdma;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000410
411 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000412};
413
Ben Skeggse225f442012-11-21 14:40:21 +1000414static struct nv50_disp *
415nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000416{
Ben Skeggs77145f12012-07-31 16:16:21 +1000417 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000418}
419
Ben Skeggse225f442012-11-21 14:40:21 +1000420#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000421
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000422static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000423nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000424{
425 return nouveau_encoder(encoder)->crtc;
426}
427
428/******************************************************************************
429 * EVO channel helpers
430 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000431static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000432evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000433{
Ben Skeggse225f442012-11-21 14:40:21 +1000434 struct nv50_dmac *dmac = evoc;
Ben Skeggsa01ca782015-08-20 14:54:15 +1000435 struct nvif_device *device = dmac->base.device;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000436 u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000437
Daniel Vetter59ad1462012-12-02 14:49:44 +0100438 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000439 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000440 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000441
Ben Skeggs0ad72862014-08-10 04:10:22 +1000442 nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
Ben Skeggs54442042015-08-20 14:54:11 +1000443 if (nvif_msec(device, 2000,
444 if (!nvif_rd32(&dmac->base.user, 0x0004))
445 break;
446 ) < 0) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100447 mutex_unlock(&dmac->lock);
Ben Skeggs9ad97ed2015-08-20 14:54:13 +1000448 printk(KERN_ERR "nouveau: evo channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000449 return NULL;
450 }
451
452 put = 0;
453 }
454
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000455 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000456}
457
458static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000459evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000460{
Ben Skeggse225f442012-11-21 14:40:21 +1000461 struct nv50_dmac *dmac = evoc;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000462 nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100463 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000464}
465
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000466#if 1
Ben Skeggs51beb422011-07-05 10:33:08 +1000467#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
468#define evo_data(p,d) *((p)++) = (d)
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000469#else
470#define evo_mthd(p,m,s) do { \
471 const u32 _m = (m), _s = (s); \
472 printk(KERN_ERR "%04x %d %s\n", _m, _s, __func__); \
473 *((p)++) = ((_s << 18) | _m); \
474} while(0)
475#define evo_data(p,d) do { \
476 const u32 _d = (d); \
477 printk(KERN_ERR "\t%08x\n", _d); \
478 *((p)++) = _d; \
479} while(0)
480#endif
Ben Skeggs51beb422011-07-05 10:33:08 +1000481
Ben Skeggs3376ee32011-11-12 14:28:12 +1000482static bool
483evo_sync_wait(void *data)
484{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500485 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
486 return true;
487 usleep_range(1, 2);
488 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000489}
490
491static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000492evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000493{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000494 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggse225f442012-11-21 14:40:21 +1000495 struct nv50_disp *disp = nv50_disp(dev);
496 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000497 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000498 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000499 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000500 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000501 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000502 evo_mthd(push, 0x0080, 2);
503 evo_data(push, 0x00000000);
504 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000505 evo_kick(push, mast);
Ben Skeggs54442042015-08-20 14:54:11 +1000506 if (nvif_msec(device, 2000,
507 if (evo_sync_wait(disp->sync))
508 break;
509 ) >= 0)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000510 return 0;
511 }
512
513 return -EBUSY;
514}
515
516/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +1000517 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +1000518 *****************************************************************************/
519struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +1000520nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000521{
Ben Skeggse225f442012-11-21 14:40:21 +1000522 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000523}
524
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000525struct nv50_display_flip {
526 struct nv50_disp *disp;
527 struct nv50_sync *chan;
528};
529
530static bool
531nv50_display_flip_wait(void *data)
532{
533 struct nv50_display_flip *flip = data;
534 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
Calvin Owensb1ea3e62013-04-07 21:01:19 -0500535 flip->chan->data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000536 return true;
537 usleep_range(1, 2);
538 return false;
539}
540
Ben Skeggs3376ee32011-11-12 14:28:12 +1000541void
Ben Skeggse225f442012-11-21 14:40:21 +1000542nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000543{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000544 struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000545 struct nv50_display_flip flip = {
546 .disp = nv50_disp(crtc->dev),
547 .chan = nv50_sync(crtc),
548 };
Ben Skeggs3376ee32011-11-12 14:28:12 +1000549 u32 *push;
550
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000551 push = evo_wait(flip.chan, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000552 if (push) {
553 evo_mthd(push, 0x0084, 1);
554 evo_data(push, 0x00000000);
555 evo_mthd(push, 0x0094, 1);
556 evo_data(push, 0x00000000);
557 evo_mthd(push, 0x00c0, 1);
558 evo_data(push, 0x00000000);
559 evo_mthd(push, 0x0080, 1);
560 evo_data(push, 0x00000000);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000561 evo_kick(push, flip.chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000562 }
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000563
Ben Skeggs54442042015-08-20 14:54:11 +1000564 nvif_msec(device, 2000,
565 if (nv50_display_flip_wait(&flip))
566 break;
567 );
Ben Skeggs3376ee32011-11-12 14:28:12 +1000568}
569
570int
Ben Skeggse225f442012-11-21 14:40:21 +1000571nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +1000572 struct nouveau_channel *chan, u32 swap_interval)
573{
574 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000575 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000576 struct nv50_head *head = nv50_head(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000577 struct nv50_sync *sync = nv50_sync(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000578 u32 *push;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000579 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000580
Ben Skeggs9ba83102014-12-22 19:50:23 +1000581 if (crtc->primary->fb->width != fb->width ||
582 crtc->primary->fb->height != fb->height)
583 return -EINVAL;
584
Ben Skeggs3376ee32011-11-12 14:28:12 +1000585 swap_interval <<= 4;
586 if (swap_interval == 0)
587 swap_interval |= 0x100;
Ben Skeggsf60b6e72013-03-19 15:20:00 +1000588 if (chan == NULL)
589 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000590
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000591 push = evo_wait(sync, 128);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000592 if (unlikely(push == NULL))
593 return -EBUSY;
594
Ben Skeggsa01ca782015-08-20 14:54:15 +1000595 if (chan && chan->user.oclass < G82_CHANNEL_GPFIFO) {
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000596 ret = RING_SPACE(chan, 8);
597 if (ret)
598 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000599
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000600 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000601 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000602 OUT_RING (chan, sync->addr ^ 0x10);
603 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
604 OUT_RING (chan, sync->data + 1);
605 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
606 OUT_RING (chan, sync->addr);
607 OUT_RING (chan, sync->data);
608 } else
Ben Skeggsa01ca782015-08-20 14:54:15 +1000609 if (chan && chan->user.oclass < FERMI_CHANNEL_GPFIFO) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000610 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000611 ret = RING_SPACE(chan, 12);
612 if (ret)
613 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +1000614
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000615 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000616 OUT_RING (chan, chan->vram.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000617 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
618 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
619 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
620 OUT_RING (chan, sync->data + 1);
621 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
622 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
623 OUT_RING (chan, upper_32_bits(addr));
624 OUT_RING (chan, lower_32_bits(addr));
625 OUT_RING (chan, sync->data);
626 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
627 } else
628 if (chan) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000629 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000630 ret = RING_SPACE(chan, 10);
631 if (ret)
632 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000633
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000634 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
635 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
636 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
637 OUT_RING (chan, sync->data + 1);
638 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
639 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
640 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
641 OUT_RING (chan, upper_32_bits(addr));
642 OUT_RING (chan, lower_32_bits(addr));
643 OUT_RING (chan, sync->data);
644 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
645 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
646 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -0500647
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000648 if (chan) {
649 sync->addr ^= 0x10;
650 sync->data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000651 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000652 }
653
654 /* queue the flip */
655 evo_mthd(push, 0x0100, 1);
656 evo_data(push, 0xfffe0000);
657 evo_mthd(push, 0x0084, 1);
658 evo_data(push, swap_interval);
659 if (!(swap_interval & 0x00000100)) {
660 evo_mthd(push, 0x00e0, 1);
661 evo_data(push, 0x40000000);
662 }
663 evo_mthd(push, 0x0088, 4);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000664 evo_data(push, sync->addr);
665 evo_data(push, sync->data++);
666 evo_data(push, sync->data);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000667 evo_data(push, sync->base.sync.handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000668 evo_mthd(push, 0x00a0, 2);
669 evo_data(push, 0x00000000);
670 evo_data(push, 0x00000000);
671 evo_mthd(push, 0x00c0, 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000672 evo_data(push, nv_fb->r_handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000673 evo_mthd(push, 0x0110, 2);
674 evo_data(push, 0x00000000);
675 evo_data(push, 0x00000000);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000676 if (nv50_vers(sync) < GF110_DISP_BASE_CHANNEL_DMA) {
Ben Skeggsed5085a52012-11-16 13:16:51 +1000677 evo_mthd(push, 0x0800, 5);
678 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
679 evo_data(push, 0);
680 evo_data(push, (fb->height << 16) | fb->width);
681 evo_data(push, nv_fb->r_pitch);
682 evo_data(push, nv_fb->r_format);
683 } else {
684 evo_mthd(push, 0x0400, 5);
685 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
686 evo_data(push, 0);
687 evo_data(push, (fb->height << 16) | fb->width);
688 evo_data(push, nv_fb->r_pitch);
689 evo_data(push, nv_fb->r_format);
690 }
Ben Skeggs3376ee32011-11-12 14:28:12 +1000691 evo_mthd(push, 0x0080, 1);
692 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000693 evo_kick(push, sync);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000694
695 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000696 return 0;
697}
698
Ben Skeggs26f6d882011-07-04 16:25:18 +1000699/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000700 * CRTC
701 *****************************************************************************/
702static int
Ben Skeggse225f442012-11-21 14:40:21 +1000703nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000704{
Ben Skeggse225f442012-11-21 14:40:21 +1000705 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde691852011-10-17 12:23:41 +1000706 struct nouveau_connector *nv_connector;
707 struct drm_connector *connector;
708 u32 *push, mode = 0x00;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000709
Ben Skeggs488ff202011-10-17 10:38:10 +1000710 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +1000711 connector = &nv_connector->base;
712 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
Matt Roperf4510a22014-04-01 15:22:40 -0700713 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
Ben Skeggsde691852011-10-17 12:23:41 +1000714 mode = DITHERING_MODE_DYNAMIC2X2;
715 } else {
716 mode = nv_connector->dithering_mode;
717 }
718
719 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
720 if (connector->display_info.bpc >= 8)
721 mode |= DITHERING_DEPTH_8BPC;
722 } else {
723 mode |= nv_connector->dithering_depth;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000724 }
725
Ben Skeggsde8268c2012-11-16 10:24:31 +1000726 push = evo_wait(mast, 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000727 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000728 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000729 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
730 evo_data(push, mode);
731 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000732 if (nv50_vers(mast) < GK104_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000733 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
734 evo_data(push, mode);
735 } else {
736 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
737 evo_data(push, mode);
738 }
739
Ben Skeggs438d99e2011-07-05 16:48:06 +1000740 if (update) {
741 evo_mthd(push, 0x0080, 1);
742 evo_data(push, 0x00000000);
743 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000744 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000745 }
746
747 return 0;
748}
749
750static int
Ben Skeggse225f442012-11-21 14:40:21 +1000751nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000752{
Ben Skeggse225f442012-11-21 14:40:21 +1000753 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs92854622011-11-11 23:49:06 +1000754 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000755 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000756 struct nouveau_connector *nv_connector;
Ben Skeggs92854622011-11-11 23:49:06 +1000757 int mode = DRM_MODE_SCALE_NONE;
758 u32 oX, oY, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000759
Ben Skeggs92854622011-11-11 23:49:06 +1000760 /* start off at the resolution we programmed the crtc for, this
761 * effectively handles NONE/FULL scaling
762 */
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000763 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs576f7912014-12-22 17:19:26 +1000764 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs92854622011-11-11 23:49:06 +1000765 mode = nv_connector->scaling_mode;
Ben Skeggs576f7912014-12-22 17:19:26 +1000766 if (nv_connector->scaling_full) /* non-EDID LVDS/eDP mode */
767 mode = DRM_MODE_SCALE_FULLSCREEN;
768 }
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000769
Ben Skeggs92854622011-11-11 23:49:06 +1000770 if (mode != DRM_MODE_SCALE_NONE)
771 omode = nv_connector->native_mode;
772 else
773 omode = umode;
774
775 oX = omode->hdisplay;
776 oY = omode->vdisplay;
777 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
778 oY *= 2;
779
780 /* add overscan compensation if necessary, will keep the aspect
781 * ratio the same as the backend mode unless overridden by the
782 * user setting both hborder and vborder properties.
783 */
784 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
785 (nv_connector->underscan == UNDERSCAN_AUTO &&
Ben Skeggs92854622011-11-11 23:49:06 +1000786 drm_detect_hdmi_monitor(nv_connector->edid)))) {
787 u32 bX = nv_connector->underscan_hborder;
788 u32 bY = nv_connector->underscan_vborder;
789 u32 aspect = (oY << 19) / oX;
790
791 if (bX) {
792 oX -= (bX * 2);
793 if (bY) oY -= (bY * 2);
794 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
795 } else {
796 oX -= (oX >> 4) + 32;
797 if (bY) oY -= (bY * 2);
798 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000799 }
800 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000801
Ben Skeggs92854622011-11-11 23:49:06 +1000802 /* handle CENTER/ASPECT scaling, taking into account the areas
803 * removed already for overscan compensation
804 */
805 switch (mode) {
806 case DRM_MODE_SCALE_CENTER:
807 oX = min((u32)umode->hdisplay, oX);
808 oY = min((u32)umode->vdisplay, oY);
809 /* fall-through */
810 case DRM_MODE_SCALE_ASPECT:
811 if (oY < oX) {
812 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
813 oX = ((oY * aspect) + (aspect / 2)) >> 19;
814 } else {
815 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
816 oY = ((oX * aspect) + (aspect / 2)) >> 19;
817 }
818 break;
819 default:
820 break;
821 }
822
Ben Skeggsde8268c2012-11-16 10:24:31 +1000823 push = evo_wait(mast, 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000824 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000825 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000826 /*XXX: SCALE_CTRL_ACTIVE??? */
827 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
828 evo_data(push, (oY << 16) | oX);
829 evo_data(push, (oY << 16) | oX);
830 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
831 evo_data(push, 0x00000000);
832 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
833 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
834 } else {
835 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
836 evo_data(push, (oY << 16) | oX);
837 evo_data(push, (oY << 16) | oX);
838 evo_data(push, (oY << 16) | oX);
839 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
840 evo_data(push, 0x00000000);
841 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
842 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
843 }
844
845 evo_kick(push, mast);
846
Ben Skeggs3376ee32011-11-12 14:28:12 +1000847 if (update) {
Ben Skeggse225f442012-11-21 14:40:21 +1000848 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700849 nv50_display_flip_next(crtc, crtc->primary->fb,
850 NULL, 1);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000851 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000852 }
853
854 return 0;
855}
856
857static int
Roy Splieteae73822014-10-30 22:57:45 +0100858nv50_crtc_set_raster_vblank_dmi(struct nouveau_crtc *nv_crtc, u32 usec)
859{
860 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
861 u32 *push;
862
863 push = evo_wait(mast, 8);
864 if (!push)
865 return -ENOMEM;
866
867 evo_mthd(push, 0x0828 + (nv_crtc->index * 0x400), 1);
868 evo_data(push, usec);
869 evo_kick(push, mast);
870 return 0;
871}
872
873static int
Ben Skeggse225f442012-11-21 14:40:21 +1000874nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +1000875{
Ben Skeggse225f442012-11-21 14:40:21 +1000876 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsf9887d02012-11-21 13:03:42 +1000877 u32 *push, hue, vib;
878 int adj;
879
880 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
881 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
882 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
883
884 push = evo_wait(mast, 16);
885 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000886 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsf9887d02012-11-21 13:03:42 +1000887 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
888 evo_data(push, (hue << 20) | (vib << 8));
889 } else {
890 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
891 evo_data(push, (hue << 20) | (vib << 8));
892 }
893
894 if (update) {
895 evo_mthd(push, 0x0080, 1);
896 evo_data(push, 0x00000000);
897 }
898 evo_kick(push, mast);
899 }
900
901 return 0;
902}
903
904static int
Ben Skeggse225f442012-11-21 14:40:21 +1000905nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000906 int x, int y, bool update)
907{
908 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggse225f442012-11-21 14:40:21 +1000909 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000910 u32 *push;
911
Ben Skeggsde8268c2012-11-16 10:24:31 +1000912 push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000913 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000914 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000915 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
916 evo_data(push, nvfb->nvbo->bo.offset >> 8);
917 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
918 evo_data(push, (fb->height << 16) | fb->width);
919 evo_data(push, nvfb->r_pitch);
920 evo_data(push, nvfb->r_format);
921 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
922 evo_data(push, (y << 16) | x);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000923 if (nv50_vers(mast) > NV50_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000924 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000925 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000926 }
927 } else {
928 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
929 evo_data(push, nvfb->nvbo->bo.offset >> 8);
930 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
931 evo_data(push, (fb->height << 16) | fb->width);
932 evo_data(push, nvfb->r_pitch);
933 evo_data(push, nvfb->r_format);
Ben Skeggs8a423642014-08-10 04:10:19 +1000934 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000935 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
936 evo_data(push, (y << 16) | x);
937 }
938
Ben Skeggsa46232e2011-07-07 15:23:48 +1000939 if (update) {
940 evo_mthd(push, 0x0080, 1);
941 evo_data(push, 0x00000000);
942 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000943 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000944 }
945
Ben Skeggs8a423642014-08-10 04:10:19 +1000946 nv_crtc->fb.handle = nvfb->r_handle;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000947 return 0;
948}
949
950static void
Ben Skeggse225f442012-11-21 14:40:21 +1000951nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000952{
Ben Skeggse225f442012-11-21 14:40:21 +1000953 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000954 u32 *push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000955 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000956 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000957 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
958 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100959 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000960 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000961 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000962 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
963 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100964 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000965 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000966 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000967 } else {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000968 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
969 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100970 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000971 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000972 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000973 }
974 evo_kick(push, mast);
975 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100976 nv_crtc->cursor.visible = true;
Ben Skeggsde8268c2012-11-16 10:24:31 +1000977}
978
979static void
Ben Skeggse225f442012-11-21 14:40:21 +1000980nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000981{
Ben Skeggse225f442012-11-21 14:40:21 +1000982 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000983 u32 *push = evo_wait(mast, 16);
984 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000985 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000986 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
987 evo_data(push, 0x05000000);
988 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000989 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000990 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
991 evo_data(push, 0x05000000);
992 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
993 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000994 } else {
995 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
996 evo_data(push, 0x05000000);
997 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
998 evo_data(push, 0x00000000);
999 }
Ben Skeggsde8268c2012-11-16 10:24:31 +10001000 evo_kick(push, mast);
1001 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001002 nv_crtc->cursor.visible = false;
Ben Skeggsde8268c2012-11-16 10:24:31 +10001003}
Ben Skeggs438d99e2011-07-05 16:48:06 +10001004
Ben Skeggsde8268c2012-11-16 10:24:31 +10001005static void
Ben Skeggse225f442012-11-21 14:40:21 +10001006nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +10001007{
Ben Skeggse225f442012-11-21 14:40:21 +10001008 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001009
Ben Skeggs697bb722015-07-28 17:20:57 +10001010 if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled)
Ben Skeggse225f442012-11-21 14:40:21 +10001011 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001012 else
Ben Skeggse225f442012-11-21 14:40:21 +10001013 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001014
1015 if (update) {
1016 u32 *push = evo_wait(mast, 2);
1017 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001018 evo_mthd(push, 0x0080, 1);
1019 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001020 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001021 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001022 }
1023}
1024
1025static void
Ben Skeggse225f442012-11-21 14:40:21 +10001026nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001027{
1028}
1029
1030static void
Ben Skeggse225f442012-11-21 14:40:21 +10001031nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001032{
1033 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001034 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001035 u32 *push;
1036
Ben Skeggse225f442012-11-21 14:40:21 +10001037 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001038
Ben Skeggs56d237d2014-05-19 14:54:33 +10001039 push = evo_wait(mast, 6);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001040 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001041 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001042 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1043 evo_data(push, 0x00000000);
1044 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1045 evo_data(push, 0x40000000);
1046 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001047 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001048 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1049 evo_data(push, 0x00000000);
1050 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1051 evo_data(push, 0x40000000);
1052 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
1053 evo_data(push, 0x00000000);
1054 } else {
1055 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
1056 evo_data(push, 0x00000000);
1057 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
1058 evo_data(push, 0x03000000);
1059 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
1060 evo_data(push, 0x00000000);
1061 }
1062
1063 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001064 }
1065
Ben Skeggse225f442012-11-21 14:40:21 +10001066 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001067}
1068
1069static void
Ben Skeggse225f442012-11-21 14:40:21 +10001070nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001071{
1072 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001073 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001074 u32 *push;
1075
Ben Skeggsde8268c2012-11-16 10:24:31 +10001076 push = evo_wait(mast, 32);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001077 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001078 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001079 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001080 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001081 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1082 evo_data(push, 0xc0000000);
1083 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1084 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001085 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001086 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001087 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001088 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1089 evo_data(push, 0xc0000000);
1090 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1091 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001092 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001093 } else {
1094 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001095 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001096 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
1097 evo_data(push, 0x83000000);
1098 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1099 evo_data(push, 0x00000000);
1100 evo_data(push, 0x00000000);
1101 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001102 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001103 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
1104 evo_data(push, 0xffffff00);
1105 }
1106
1107 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001108 }
1109
Ben Skeggs5a560252014-11-10 15:52:02 +10001110 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Matt Roperf4510a22014-04-01 15:22:40 -07001111 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001112}
1113
1114static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001115nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001116 struct drm_display_mode *adjusted_mode)
1117{
Ben Skeggseb2e9682014-01-24 10:13:23 +10001118 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001119 return true;
1120}
1121
1122static int
Ben Skeggse225f442012-11-21 14:40:21 +10001123nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001124{
Matt Roperf4510a22014-04-01 15:22:40 -07001125 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001126 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001127 int ret;
1128
Ben Skeggs547ad072014-11-10 12:35:06 +10001129 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001130 if (ret == 0) {
1131 if (head->image)
1132 nouveau_bo_unpin(head->image);
1133 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001134 }
1135
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001136 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001137}
1138
1139static int
Ben Skeggse225f442012-11-21 14:40:21 +10001140nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001141 struct drm_display_mode *mode, int x, int y,
1142 struct drm_framebuffer *old_fb)
1143{
Ben Skeggse225f442012-11-21 14:40:21 +10001144 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001145 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1146 struct nouveau_connector *nv_connector;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001147 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
1148 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
1149 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
1150 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
Roy Spliet1dce6262014-09-12 18:00:13 +02001151 u32 vblan2e = 0, vblan2s = 1, vblankus = 0;
Ben Skeggs3488c572012-03-12 11:42:20 +10001152 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001153 int ret;
1154
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001155 hactive = mode->htotal;
1156 hsynce = mode->hsync_end - mode->hsync_start - 1;
1157 hbackp = mode->htotal - mode->hsync_end;
1158 hblanke = hsynce + hbackp;
1159 hfrontp = mode->hsync_start - mode->hdisplay;
1160 hblanks = mode->htotal - hfrontp - 1;
1161
1162 vactive = mode->vtotal * vscan / ilace;
1163 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
1164 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
1165 vblanke = vsynce + vbackp;
1166 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
1167 vblanks = vactive - vfrontp - 1;
Roy Spliet1dce6262014-09-12 18:00:13 +02001168 /* XXX: Safe underestimate, even "0" works */
1169 vblankus = (vactive - mode->vdisplay - 2) * hactive;
1170 vblankus *= 1000;
1171 vblankus /= mode->clock;
1172
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001173 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1174 vblan2e = vactive + vsynce + vbackp;
1175 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
1176 vactive = (vactive * 2) + 1;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001177 }
1178
Ben Skeggse225f442012-11-21 14:40:21 +10001179 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001180 if (ret)
1181 return ret;
1182
Ben Skeggsde8268c2012-11-16 10:24:31 +10001183 push = evo_wait(mast, 64);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001184 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001185 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001186 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1187 evo_data(push, 0x00800000 | mode->clock);
1188 evo_data(push, (ilace == 2) ? 2 : 0);
Roy Splieteae73822014-10-30 22:57:45 +01001189 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001190 evo_data(push, 0x00000000);
1191 evo_data(push, (vactive << 16) | hactive);
1192 evo_data(push, ( vsynce << 16) | hsynce);
1193 evo_data(push, (vblanke << 16) | hblanke);
1194 evo_data(push, (vblanks << 16) | hblanks);
1195 evo_data(push, (vblan2e << 16) | vblan2s);
Roy Splieteae73822014-10-30 22:57:45 +01001196 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001197 evo_data(push, 0x00000000);
1198 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1199 evo_data(push, 0x00000311);
1200 evo_data(push, 0x00000100);
1201 } else {
1202 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
1203 evo_data(push, 0x00000000);
1204 evo_data(push, (vactive << 16) | hactive);
1205 evo_data(push, ( vsynce << 16) | hsynce);
1206 evo_data(push, (vblanke << 16) | hblanke);
1207 evo_data(push, (vblanks << 16) | hblanks);
1208 evo_data(push, (vblan2e << 16) | vblan2s);
1209 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1210 evo_data(push, 0x00000000); /* ??? */
1211 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1212 evo_data(push, mode->clock * 1000);
1213 evo_data(push, 0x00200000); /* ??? */
1214 evo_data(push, mode->clock * 1000);
1215 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1216 evo_data(push, 0x00000311);
1217 evo_data(push, 0x00000100);
1218 }
1219
1220 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001221 }
1222
1223 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001224 nv50_crtc_set_dither(nv_crtc, false);
1225 nv50_crtc_set_scale(nv_crtc, false);
Roy Splieteae73822014-10-30 22:57:45 +01001226
1227 /* G94 only accepts this after setting scale */
1228 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA)
1229 nv50_crtc_set_raster_vblank_dmi(nv_crtc, vblankus);
1230
Ben Skeggse225f442012-11-21 14:40:21 +10001231 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07001232 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001233 return 0;
1234}
1235
1236static int
Ben Skeggse225f442012-11-21 14:40:21 +10001237nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001238 struct drm_framebuffer *old_fb)
1239{
Ben Skeggs77145f12012-07-31 16:16:21 +10001240 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001241 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1242 int ret;
1243
Matt Roperf4510a22014-04-01 15:22:40 -07001244 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10001245 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10001246 return 0;
1247 }
1248
Ben Skeggse225f442012-11-21 14:40:21 +10001249 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001250 if (ret)
1251 return ret;
1252
Ben Skeggse225f442012-11-21 14:40:21 +10001253 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07001254 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1255 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001256 return 0;
1257}
1258
1259static int
Ben Skeggse225f442012-11-21 14:40:21 +10001260nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001261 struct drm_framebuffer *fb, int x, int y,
1262 enum mode_set_atomic state)
1263{
1264 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001265 nv50_display_flip_stop(crtc);
1266 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001267 return 0;
1268}
1269
1270static void
Ben Skeggse225f442012-11-21 14:40:21 +10001271nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001272{
Ben Skeggse225f442012-11-21 14:40:21 +10001273 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001274 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1275 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1276 int i;
1277
1278 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001279 u16 r = nv_crtc->lut.r[i] >> 2;
1280 u16 g = nv_crtc->lut.g[i] >> 2;
1281 u16 b = nv_crtc->lut.b[i] >> 2;
1282
Ben Skeggs648d4df2014-08-10 04:10:27 +10001283 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001284 writew(r + 0x0000, lut + (i * 0x08) + 0);
1285 writew(g + 0x0000, lut + (i * 0x08) + 2);
1286 writew(b + 0x0000, lut + (i * 0x08) + 4);
1287 } else {
1288 writew(r + 0x6000, lut + (i * 0x20) + 0);
1289 writew(g + 0x6000, lut + (i * 0x20) + 2);
1290 writew(b + 0x6000, lut + (i * 0x20) + 4);
1291 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001292 }
1293}
1294
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001295static void
1296nv50_crtc_disable(struct drm_crtc *crtc)
1297{
1298 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10001299 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001300 if (head->image)
1301 nouveau_bo_unpin(head->image);
1302 nouveau_bo_ref(NULL, &head->image);
1303}
1304
Ben Skeggs438d99e2011-07-05 16:48:06 +10001305static int
Ben Skeggse225f442012-11-21 14:40:21 +10001306nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001307 uint32_t handle, uint32_t width, uint32_t height)
1308{
1309 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs5a560252014-11-10 15:52:02 +10001310 struct drm_gem_object *gem = NULL;
1311 struct nouveau_bo *nvbo = NULL;
1312 int ret = 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001313
Ben Skeggs5a560252014-11-10 15:52:02 +10001314 if (handle) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001315 if (width != 64 || height != 64)
1316 return -EINVAL;
1317
Chris Wilsona8ad0bd2016-05-09 11:04:54 +01001318 gem = drm_gem_object_lookup(file_priv, handle);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001319 if (unlikely(!gem))
1320 return -ENOENT;
1321 nvbo = nouveau_gem_object(gem);
1322
Ben Skeggs5a560252014-11-10 15:52:02 +10001323 ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001324 }
1325
Ben Skeggs5a560252014-11-10 15:52:02 +10001326 if (ret == 0) {
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001327 if (nv_crtc->cursor.nvbo)
1328 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1329 nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001330 }
Ben Skeggs5a560252014-11-10 15:52:02 +10001331 drm_gem_object_unreference_unlocked(gem);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001332
Ben Skeggs5a560252014-11-10 15:52:02 +10001333 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001334 return ret;
1335}
1336
1337static int
Ben Skeggse225f442012-11-21 14:40:21 +10001338nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001339{
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001340 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001341 struct nv50_curs *curs = nv50_curs(crtc);
1342 struct nv50_chan *chan = nv50_chan(curs);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001343 nvif_wr32(&chan->user, 0x0084, (y << 16) | (x & 0xffff));
1344 nvif_wr32(&chan->user, 0x0080, 0x00000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001345
1346 nv_crtc->cursor_saved_x = x;
1347 nv_crtc->cursor_saved_y = y;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001348 return 0;
1349}
1350
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001351static int
Ben Skeggse225f442012-11-21 14:40:21 +10001352nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001353 uint32_t size)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001354{
1355 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001356 u32 i;
1357
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001358 for (i = 0; i < size; i++) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001359 nv_crtc->lut.r[i] = r[i];
1360 nv_crtc->lut.g[i] = g[i];
1361 nv_crtc->lut.b[i] = b[i];
1362 }
1363
Ben Skeggse225f442012-11-21 14:40:21 +10001364 nv50_crtc_lut_load(crtc);
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001365
1366 return 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001367}
1368
1369static void
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001370nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y)
1371{
1372 nv50_crtc_cursor_move(&nv_crtc->base, x, y);
1373
1374 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
1375}
1376
1377static void
Ben Skeggse225f442012-11-21 14:40:21 +10001378nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001379{
1380 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001381 struct nv50_disp *disp = nv50_disp(crtc->dev);
1382 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001383 struct nv50_fbdma *fbdma;
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001384
Ben Skeggs0ad72862014-08-10 04:10:22 +10001385 list_for_each_entry(fbdma, &disp->fbdma, head) {
1386 nvif_object_fini(&fbdma->base[nv_crtc->index]);
1387 }
1388
1389 nv50_dmac_destroy(&head->ovly.base, disp->disp);
1390 nv50_pioc_destroy(&head->oimm.base);
1391 nv50_dmac_destroy(&head->sync.base, disp->disp);
1392 nv50_pioc_destroy(&head->curs.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001393
1394 /*XXX: this shouldn't be necessary, but the core doesn't call
1395 * disconnect() during the cleanup paths
1396 */
1397 if (head->image)
1398 nouveau_bo_unpin(head->image);
1399 nouveau_bo_ref(NULL, &head->image);
1400
Ben Skeggs5a560252014-11-10 15:52:02 +10001401 /*XXX: ditto */
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001402 if (nv_crtc->cursor.nvbo)
1403 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1404 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001405
Ben Skeggs438d99e2011-07-05 16:48:06 +10001406 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001407 if (nv_crtc->lut.nvbo)
1408 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001409 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001410
Ben Skeggs438d99e2011-07-05 16:48:06 +10001411 drm_crtc_cleanup(crtc);
1412 kfree(crtc);
1413}
1414
Ben Skeggse225f442012-11-21 14:40:21 +10001415static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1416 .dpms = nv50_crtc_dpms,
1417 .prepare = nv50_crtc_prepare,
1418 .commit = nv50_crtc_commit,
1419 .mode_fixup = nv50_crtc_mode_fixup,
1420 .mode_set = nv50_crtc_mode_set,
1421 .mode_set_base = nv50_crtc_mode_set_base,
1422 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1423 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001424 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001425};
1426
Ben Skeggse225f442012-11-21 14:40:21 +10001427static const struct drm_crtc_funcs nv50_crtc_func = {
1428 .cursor_set = nv50_crtc_cursor_set,
1429 .cursor_move = nv50_crtc_cursor_move,
1430 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10001431 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10001432 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001433 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001434};
1435
1436static int
Ben Skeggs0ad72862014-08-10 04:10:22 +10001437nv50_crtc_create(struct drm_device *dev, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001438{
Ben Skeggsa01ca782015-08-20 14:54:15 +10001439 struct nouveau_drm *drm = nouveau_drm(dev);
1440 struct nvif_device *device = &drm->device;
Ben Skeggse225f442012-11-21 14:40:21 +10001441 struct nv50_disp *disp = nv50_disp(dev);
1442 struct nv50_head *head;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001443 struct drm_crtc *crtc;
1444 int ret, i;
1445
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001446 head = kzalloc(sizeof(*head), GFP_KERNEL);
1447 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001448 return -ENOMEM;
1449
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001450 head->base.index = index;
Ben Skeggsf9887d02012-11-21 13:03:42 +10001451 head->base.color_vibrance = 50;
1452 head->base.vibrant_hue = 0;
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001453 head->base.cursor.set_pos = nv50_crtc_cursor_restore;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001454 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001455 head->base.lut.r[i] = i << 8;
1456 head->base.lut.g[i] = i << 8;
1457 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001458 }
1459
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001460 crtc = &head->base.base;
Ben Skeggse225f442012-11-21 14:40:21 +10001461 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1462 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001463 drm_mode_crtc_set_gamma_size(crtc, 256);
1464
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10001465 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01001466 0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001467 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10001468 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001469 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001470 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001471 if (ret)
1472 nouveau_bo_unpin(head->base.lut.nvbo);
1473 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001474 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001475 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001476 }
1477
1478 if (ret)
1479 goto out;
1480
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001481 /* allocate cursor resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001482 ret = nv50_curs_create(device, disp->disp, index, &head->curs);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001483 if (ret)
1484 goto out;
1485
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001486 /* allocate page flip / sync resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001487 ret = nv50_base_create(device, disp->disp, index, disp->sync->bo.offset,
1488 &head->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001489 if (ret)
1490 goto out;
1491
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001492 head->sync.addr = EVO_FLIP_SEM0(index);
1493 head->sync.data = 0x00000000;
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001494
1495 /* allocate overlay resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001496 ret = nv50_oimm_create(device, disp->disp, index, &head->oimm);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001497 if (ret)
1498 goto out;
1499
Ben Skeggsa01ca782015-08-20 14:54:15 +10001500 ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset,
1501 &head->ovly);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001502 if (ret)
1503 goto out;
1504
Ben Skeggs438d99e2011-07-05 16:48:06 +10001505out:
1506 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10001507 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001508 return ret;
1509}
1510
1511/******************************************************************************
Ben Skeggsa91d3222014-12-22 16:30:13 +10001512 * Encoder helpers
1513 *****************************************************************************/
1514static bool
1515nv50_encoder_mode_fixup(struct drm_encoder *encoder,
1516 const struct drm_display_mode *mode,
1517 struct drm_display_mode *adjusted_mode)
1518{
1519 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1520 struct nouveau_connector *nv_connector;
1521
1522 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1523 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs576f7912014-12-22 17:19:26 +10001524 nv_connector->scaling_full = false;
1525 if (nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) {
1526 switch (nv_connector->type) {
1527 case DCB_CONNECTOR_LVDS:
1528 case DCB_CONNECTOR_LVDS_SPWG:
1529 case DCB_CONNECTOR_eDP:
1530 /* force use of scaler for non-edid modes */
1531 if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
1532 return true;
1533 nv_connector->scaling_full = true;
1534 break;
1535 default:
1536 return true;
1537 }
1538 }
1539
1540 drm_mode_copy(adjusted_mode, nv_connector->native_mode);
Ben Skeggsa91d3222014-12-22 16:30:13 +10001541 }
1542
1543 return true;
1544}
1545
1546/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001547 * DAC
1548 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001549static void
Ben Skeggse225f442012-11-21 14:40:21 +10001550nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001551{
1552 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001553 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001554 struct {
1555 struct nv50_disp_mthd_v1 base;
1556 struct nv50_disp_dac_pwr_v0 pwr;
1557 } args = {
1558 .base.version = 1,
1559 .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
1560 .base.hasht = nv_encoder->dcb->hasht,
1561 .base.hashm = nv_encoder->dcb->hashm,
1562 .pwr.state = 1,
1563 .pwr.data = 1,
1564 .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
1565 mode != DRM_MODE_DPMS_OFF),
1566 .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
1567 mode != DRM_MODE_DPMS_OFF),
1568 };
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001569
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001570 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001571}
1572
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001573static void
Ben Skeggse225f442012-11-21 14:40:21 +10001574nv50_dac_commit(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001575{
1576}
1577
1578static void
Ben Skeggse225f442012-11-21 14:40:21 +10001579nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001580 struct drm_display_mode *adjusted_mode)
1581{
Ben Skeggse225f442012-11-21 14:40:21 +10001582 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001583 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1584 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001585 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001586
Ben Skeggse225f442012-11-21 14:40:21 +10001587 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001588
Ben Skeggs97b19b52012-11-16 11:21:37 +10001589 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001590 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001591 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001592 u32 syncs = 0x00000000;
1593
1594 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1595 syncs |= 0x00000001;
1596 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1597 syncs |= 0x00000002;
1598
1599 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1600 evo_data(push, 1 << nv_crtc->index);
1601 evo_data(push, syncs);
1602 } else {
1603 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1604 u32 syncs = 0x00000001;
1605
1606 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1607 syncs |= 0x00000008;
1608 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1609 syncs |= 0x00000010;
1610
1611 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1612 magic |= 0x00000001;
1613
1614 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1615 evo_data(push, syncs);
1616 evo_data(push, magic);
1617 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1618 evo_data(push, 1 << nv_crtc->index);
1619 }
1620
1621 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001622 }
1623
1624 nv_encoder->crtc = encoder->crtc;
1625}
1626
1627static void
Ben Skeggse225f442012-11-21 14:40:21 +10001628nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001629{
1630 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001631 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001632 const int or = nv_encoder->or;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001633 u32 *push;
1634
1635 if (nv_encoder->crtc) {
Ben Skeggse225f442012-11-21 14:40:21 +10001636 nv50_crtc_prepare(nv_encoder->crtc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001637
Ben Skeggs97b19b52012-11-16 11:21:37 +10001638 push = evo_wait(mast, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001639 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001640 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001641 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1642 evo_data(push, 0x00000000);
1643 } else {
1644 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1645 evo_data(push, 0x00000000);
1646 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001647 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001648 }
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001649 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001650
1651 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001652}
1653
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001654static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10001655nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001656{
Ben Skeggsc4abd312014-08-10 04:10:26 +10001657 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001658 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsc4abd312014-08-10 04:10:26 +10001659 struct {
1660 struct nv50_disp_mthd_v1 base;
1661 struct nv50_disp_dac_load_v0 load;
1662 } args = {
1663 .base.version = 1,
1664 .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
1665 .base.hasht = nv_encoder->dcb->hasht,
1666 .base.hashm = nv_encoder->dcb->hashm,
1667 };
1668 int ret;
Ben Skeggsb6819932011-07-08 11:14:50 +10001669
Ben Skeggsc4abd312014-08-10 04:10:26 +10001670 args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
1671 if (args.load.data == 0)
1672 args.load.data = 340;
1673
1674 ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
1675 if (ret || !args.load.load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10001676 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10001677
Ben Skeggs35b21d32012-11-08 12:08:55 +10001678 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001679}
1680
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001681static void
Ben Skeggse225f442012-11-21 14:40:21 +10001682nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001683{
1684 drm_encoder_cleanup(encoder);
1685 kfree(encoder);
1686}
1687
Ben Skeggse225f442012-11-21 14:40:21 +10001688static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1689 .dpms = nv50_dac_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10001690 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggse225f442012-11-21 14:40:21 +10001691 .prepare = nv50_dac_disconnect,
1692 .commit = nv50_dac_commit,
1693 .mode_set = nv50_dac_mode_set,
1694 .disable = nv50_dac_disconnect,
1695 .get_crtc = nv50_display_crtc_get,
1696 .detect = nv50_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001697};
1698
Ben Skeggse225f442012-11-21 14:40:21 +10001699static const struct drm_encoder_funcs nv50_dac_func = {
1700 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001701};
1702
1703static int
Ben Skeggse225f442012-11-21 14:40:21 +10001704nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001705{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001706 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10001707 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001708 struct nvkm_i2c_bus *bus;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001709 struct nouveau_encoder *nv_encoder;
1710 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001711 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001712
1713 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1714 if (!nv_encoder)
1715 return -ENOMEM;
1716 nv_encoder->dcb = dcbe;
1717 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001718
1719 bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
1720 if (bus)
1721 nv_encoder->i2c = &bus->i2c;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001722
1723 encoder = to_drm_encoder(nv_encoder);
1724 encoder->possible_crtcs = dcbe->heads;
1725 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02001726 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type, NULL);
Ben Skeggse225f442012-11-21 14:40:21 +10001727 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001728
1729 drm_mode_connector_attach_encoder(connector, encoder);
1730 return 0;
1731}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001732
1733/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10001734 * Audio
1735 *****************************************************************************/
1736static void
Ben Skeggse225f442012-11-21 14:40:21 +10001737nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001738{
1739 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001740 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs78951d22011-11-11 18:13:13 +10001741 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001742 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsd889c522014-09-15 21:11:51 +10001743 struct __packed {
1744 struct {
1745 struct nv50_disp_mthd_v1 mthd;
1746 struct nv50_disp_sor_hda_eld_v0 eld;
1747 } base;
Ben Skeggs120b0c32014-08-10 04:10:26 +10001748 u8 data[sizeof(nv_connector->base.eld)];
1749 } args = {
Ben Skeggsd889c522014-09-15 21:11:51 +10001750 .base.mthd.version = 1,
1751 .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1752 .base.mthd.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001753 .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1754 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001755 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001756
1757 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1758 if (!drm_detect_monitor_audio(nv_connector->edid))
1759 return;
1760
Ben Skeggs78951d22011-11-11 18:13:13 +10001761 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001762 memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001763
Jani Nikula938fd8a2014-10-28 16:20:48 +02001764 nvif_mthd(disp->disp, 0, &args,
1765 sizeof(args.base) + drm_eld_size(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001766}
1767
1768static void
Ben Skeggscc2a9072014-09-15 21:29:05 +10001769nv50_audio_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001770{
1771 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001772 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001773 struct {
1774 struct nv50_disp_mthd_v1 base;
1775 struct nv50_disp_sor_hda_eld_v0 eld;
1776 } args = {
1777 .base.version = 1,
1778 .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1779 .base.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001780 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1781 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001782 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001783
Ben Skeggs120b0c32014-08-10 04:10:26 +10001784 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001785}
1786
1787/******************************************************************************
1788 * HDMI
1789 *****************************************************************************/
1790static void
Ben Skeggse225f442012-11-21 14:40:21 +10001791nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001792{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001793 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1794 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001795 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001796 struct {
1797 struct nv50_disp_mthd_v1 base;
1798 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1799 } args = {
1800 .base.version = 1,
1801 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1802 .base.hasht = nv_encoder->dcb->hasht,
1803 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1804 (0x0100 << nv_crtc->index),
1805 .pwr.state = 1,
1806 .pwr.rekey = 56, /* binary driver, and tegra, constant */
1807 };
1808 struct nouveau_connector *nv_connector;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001809 u32 max_ac_packet;
1810
1811 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1812 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1813 return;
1814
1815 max_ac_packet = mode->htotal - mode->hdisplay;
Ben Skeggse00f2232014-08-10 04:10:26 +10001816 max_ac_packet -= args.pwr.rekey;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001817 max_ac_packet -= 18; /* constant from tegra */
Ben Skeggse00f2232014-08-10 04:10:26 +10001818 args.pwr.max_ac_packet = max_ac_packet / 32;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001819
Ben Skeggse00f2232014-08-10 04:10:26 +10001820 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggse225f442012-11-21 14:40:21 +10001821 nv50_audio_mode_set(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10001822}
1823
1824static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001825nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001826{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001827 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001828 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001829 struct {
1830 struct nv50_disp_mthd_v1 base;
1831 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1832 } args = {
1833 .base.version = 1,
1834 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1835 .base.hasht = nv_encoder->dcb->hasht,
1836 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1837 (0x0100 << nv_crtc->index),
1838 };
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001839
Ben Skeggse00f2232014-08-10 04:10:26 +10001840 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001841}
1842
1843/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001844 * SOR
1845 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001846static void
Ben Skeggse225f442012-11-21 14:40:21 +10001847nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001848{
1849 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001850 struct nv50_disp *disp = nv50_disp(encoder->dev);
1851 struct {
1852 struct nv50_disp_mthd_v1 base;
1853 struct nv50_disp_sor_pwr_v0 pwr;
1854 } args = {
1855 .base.version = 1,
1856 .base.method = NV50_DISP_MTHD_V1_SOR_PWR,
1857 .base.hasht = nv_encoder->dcb->hasht,
1858 .base.hashm = nv_encoder->dcb->hashm,
1859 .pwr.state = mode == DRM_MODE_DPMS_ON,
1860 };
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001861 struct {
1862 struct nv50_disp_mthd_v1 base;
1863 struct nv50_disp_sor_dp_pwr_v0 pwr;
1864 } link = {
1865 .base.version = 1,
1866 .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
1867 .base.hasht = nv_encoder->dcb->hasht,
1868 .base.hashm = nv_encoder->dcb->hashm,
1869 .pwr.state = mode == DRM_MODE_DPMS_ON,
1870 };
Ben Skeggs83fc0832011-07-05 13:08:40 +10001871 struct drm_device *dev = encoder->dev;
1872 struct drm_encoder *partner;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001873
1874 nv_encoder->last_dpms = mode;
1875
1876 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1877 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1878
1879 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1880 continue;
1881
1882 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10001883 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10001884 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1885 return;
1886 break;
1887 }
1888 }
1889
Ben Skeggs48743222014-05-31 01:48:06 +10001890 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001891 args.pwr.state = 1;
1892 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001893 nvif_mthd(disp->disp, 0, &link, sizeof(link));
Ben Skeggs48743222014-05-31 01:48:06 +10001894 } else {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001895 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs48743222014-05-31 01:48:06 +10001896 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001897}
1898
Ben Skeggs83fc0832011-07-05 13:08:40 +10001899static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001900nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1901{
1902 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1903 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1904 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001905 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10001906 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1907 evo_data(push, (nv_encoder->ctrl = temp));
1908 } else {
1909 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1910 evo_data(push, (nv_encoder->ctrl = temp));
1911 }
1912 evo_kick(push, mast);
1913 }
1914}
1915
1916static void
Ben Skeggse225f442012-11-21 14:40:21 +10001917nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001918{
1919 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001920 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001921
1922 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1923 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001924
1925 if (nv_crtc) {
1926 nv50_crtc_prepare(&nv_crtc->base);
1927 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001928 nv50_audio_disconnect(encoder, nv_crtc);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001929 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1930 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001931}
1932
1933static void
Ben Skeggse225f442012-11-21 14:40:21 +10001934nv50_sor_commit(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001935{
1936}
1937
1938static void
Ben Skeggse225f442012-11-21 14:40:21 +10001939nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001940 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001941{
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001942 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1943 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1944 struct {
1945 struct nv50_disp_mthd_v1 base;
1946 struct nv50_disp_sor_lvds_script_v0 lvds;
1947 } lvds = {
1948 .base.version = 1,
1949 .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
1950 .base.hasht = nv_encoder->dcb->hasht,
1951 .base.hashm = nv_encoder->dcb->hashm,
1952 };
Ben Skeggse225f442012-11-21 14:40:21 +10001953 struct nv50_disp *disp = nv50_disp(encoder->dev);
1954 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001955 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10001956 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001957 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10001958 struct nvbios *bios = &drm->vbios;
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001959 u32 mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001960 u8 owner = 1 << nv_crtc->index;
1961 u8 proto = 0xf;
1962 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001963
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001964 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001965 nv_encoder->crtc = encoder->crtc;
1966
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001967 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10001968 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001969 if (nv_encoder->dcb->sorconf.link & 1) {
Hauke Mehrtens16ef53a92015-11-03 21:00:10 -05001970 proto = 0x1;
1971 /* Only enable dual-link if:
1972 * - Need to (i.e. rate > 165MHz)
1973 * - DCB says we can
1974 * - Not an HDMI monitor, since there's no dual-link
1975 * on HDMI.
1976 */
1977 if (mode->clock >= 165000 &&
1978 nv_encoder->dcb->duallink_possible &&
1979 !drm_detect_hdmi_monitor(nv_connector->edid))
1980 proto |= 0x4;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001981 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001982 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001983 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001984
Ben Skeggse84a35a2014-06-05 10:59:55 +10001985 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001986 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001987 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001988 proto = 0x0;
1989
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001990 if (bios->fp_no_ddc) {
1991 if (bios->fp.dual_link)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001992 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001993 if (bios->fp.if_is_24bit)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001994 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001995 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10001996 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001997 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001998 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001999 } else
2000 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002001 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002002 }
2003
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002004 if (lvds.lvds.script & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002005 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002006 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002007 } else {
2008 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002009 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002010 }
2011
2012 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002013 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002014 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10002015
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002016 nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds));
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002017 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10002018 case DCB_OUTPUT_DP:
Ben Skeggs3488c572012-03-12 11:42:20 +10002019 if (nv_connector->base.display_info.bpc == 6) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002020 nv_encoder->dp.datarate = mode->clock * 18 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002021 depth = 0x2;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002022 } else
2023 if (nv_connector->base.display_info.bpc == 8) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002024 nv_encoder->dp.datarate = mode->clock * 24 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002025 depth = 0x5;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002026 } else {
2027 nv_encoder->dp.datarate = mode->clock * 30 / 8;
2028 depth = 0x6;
Ben Skeggs3488c572012-03-12 11:42:20 +10002029 }
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002030
2031 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002032 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002033 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002034 proto = 0x9;
Ben Skeggs3eee8642014-09-15 15:20:47 +10002035 nv50_audio_mode_set(encoder, mode);
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002036 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002037 default:
2038 BUG_ON(1);
2039 break;
2040 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10002041
Ben Skeggse84a35a2014-06-05 10:59:55 +10002042 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002043
Ben Skeggs648d4df2014-08-10 04:10:27 +10002044 if (nv50_vers(mast) >= GF110_DISP) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10002045 u32 *push = evo_wait(mast, 3);
2046 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002047 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
2048 u32 syncs = 0x00000001;
2049
2050 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2051 syncs |= 0x00000008;
2052 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2053 syncs |= 0x00000010;
2054
2055 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2056 magic |= 0x00000001;
2057
2058 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
2059 evo_data(push, syncs | (depth << 6));
2060 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10002061 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002062 }
2063
Ben Skeggse84a35a2014-06-05 10:59:55 +10002064 ctrl = proto << 8;
2065 mask = 0x00000f00;
2066 } else {
2067 ctrl = (depth << 16) | (proto << 8);
2068 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2069 ctrl |= 0x00001000;
2070 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2071 ctrl |= 0x00002000;
2072 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002073 }
2074
Ben Skeggse84a35a2014-06-05 10:59:55 +10002075 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002076}
2077
2078static void
Ben Skeggse225f442012-11-21 14:40:21 +10002079nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002080{
2081 drm_encoder_cleanup(encoder);
2082 kfree(encoder);
2083}
2084
Ben Skeggse225f442012-11-21 14:40:21 +10002085static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
2086 .dpms = nv50_sor_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10002087 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggs5a885f02013-02-20 14:34:18 +10002088 .prepare = nv50_sor_disconnect,
Ben Skeggse225f442012-11-21 14:40:21 +10002089 .commit = nv50_sor_commit,
2090 .mode_set = nv50_sor_mode_set,
2091 .disable = nv50_sor_disconnect,
2092 .get_crtc = nv50_display_crtc_get,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002093};
2094
Ben Skeggse225f442012-11-21 14:40:21 +10002095static const struct drm_encoder_funcs nv50_sor_func = {
2096 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002097};
2098
2099static int
Ben Skeggse225f442012-11-21 14:40:21 +10002100nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002101{
Ben Skeggs5ed50202013-02-11 20:15:03 +10002102 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002103 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002104 struct nouveau_encoder *nv_encoder;
2105 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10002106 int type;
2107
2108 switch (dcbe->type) {
2109 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
2110 case DCB_OUTPUT_TMDS:
2111 case DCB_OUTPUT_DP:
2112 default:
2113 type = DRM_MODE_ENCODER_TMDS;
2114 break;
2115 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10002116
2117 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2118 if (!nv_encoder)
2119 return -ENOMEM;
2120 nv_encoder->dcb = dcbe;
2121 nv_encoder->or = ffs(dcbe->or) - 1;
2122 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
2123
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002124 if (dcbe->type == DCB_OUTPUT_DP) {
2125 struct nvkm_i2c_aux *aux =
2126 nvkm_i2c_aux_find(i2c, dcbe->i2c_index);
2127 if (aux) {
2128 nv_encoder->i2c = &aux->i2c;
2129 nv_encoder->aux = aux;
2130 }
2131 } else {
2132 struct nvkm_i2c_bus *bus =
2133 nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
2134 if (bus)
2135 nv_encoder->i2c = &bus->i2c;
2136 }
2137
Ben Skeggs83fc0832011-07-05 13:08:40 +10002138 encoder = to_drm_encoder(nv_encoder);
2139 encoder->possible_crtcs = dcbe->heads;
2140 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002141 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type, NULL);
Ben Skeggse225f442012-11-21 14:40:21 +10002142 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002143
2144 drm_mode_connector_attach_encoder(connector, encoder);
2145 return 0;
2146}
Ben Skeggs26f6d882011-07-04 16:25:18 +10002147
2148/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10002149 * PIOR
2150 *****************************************************************************/
2151
2152static void
2153nv50_pior_dpms(struct drm_encoder *encoder, int mode)
2154{
2155 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2156 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs67cb49c2014-08-10 04:10:27 +10002157 struct {
2158 struct nv50_disp_mthd_v1 base;
2159 struct nv50_disp_pior_pwr_v0 pwr;
2160 } args = {
2161 .base.version = 1,
2162 .base.method = NV50_DISP_MTHD_V1_PIOR_PWR,
2163 .base.hasht = nv_encoder->dcb->hasht,
2164 .base.hashm = nv_encoder->dcb->hashm,
2165 .pwr.state = mode == DRM_MODE_DPMS_ON,
2166 .pwr.type = nv_encoder->dcb->type,
2167 };
2168
2169 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggseb6313a2013-02-11 09:52:58 +10002170}
2171
2172static bool
2173nv50_pior_mode_fixup(struct drm_encoder *encoder,
2174 const struct drm_display_mode *mode,
2175 struct drm_display_mode *adjusted_mode)
2176{
Ben Skeggsa91d3222014-12-22 16:30:13 +10002177 if (!nv50_encoder_mode_fixup(encoder, mode, adjusted_mode))
2178 return false;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002179 adjusted_mode->clock *= 2;
2180 return true;
2181}
2182
2183static void
2184nv50_pior_commit(struct drm_encoder *encoder)
2185{
2186}
2187
2188static void
2189nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
2190 struct drm_display_mode *adjusted_mode)
2191{
2192 struct nv50_mast *mast = nv50_mast(encoder->dev);
2193 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2194 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
2195 struct nouveau_connector *nv_connector;
2196 u8 owner = 1 << nv_crtc->index;
2197 u8 proto, depth;
2198 u32 *push;
2199
2200 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2201 switch (nv_connector->base.display_info.bpc) {
2202 case 10: depth = 0x6; break;
2203 case 8: depth = 0x5; break;
2204 case 6: depth = 0x2; break;
2205 default: depth = 0x0; break;
2206 }
2207
2208 switch (nv_encoder->dcb->type) {
2209 case DCB_OUTPUT_TMDS:
2210 case DCB_OUTPUT_DP:
2211 proto = 0x0;
2212 break;
2213 default:
2214 BUG_ON(1);
2215 break;
2216 }
2217
2218 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
2219
2220 push = evo_wait(mast, 8);
2221 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002222 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002223 u32 ctrl = (depth << 16) | (proto << 8) | owner;
2224 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2225 ctrl |= 0x00001000;
2226 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2227 ctrl |= 0x00002000;
2228 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
2229 evo_data(push, ctrl);
2230 }
2231
2232 evo_kick(push, mast);
2233 }
2234
2235 nv_encoder->crtc = encoder->crtc;
2236}
2237
2238static void
2239nv50_pior_disconnect(struct drm_encoder *encoder)
2240{
2241 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2242 struct nv50_mast *mast = nv50_mast(encoder->dev);
2243 const int or = nv_encoder->or;
2244 u32 *push;
2245
2246 if (nv_encoder->crtc) {
2247 nv50_crtc_prepare(nv_encoder->crtc);
2248
2249 push = evo_wait(mast, 4);
2250 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002251 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002252 evo_mthd(push, 0x0700 + (or * 0x040), 1);
2253 evo_data(push, 0x00000000);
2254 }
Ben Skeggseb6313a2013-02-11 09:52:58 +10002255 evo_kick(push, mast);
2256 }
2257 }
2258
2259 nv_encoder->crtc = NULL;
2260}
2261
2262static void
2263nv50_pior_destroy(struct drm_encoder *encoder)
2264{
2265 drm_encoder_cleanup(encoder);
2266 kfree(encoder);
2267}
2268
2269static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
2270 .dpms = nv50_pior_dpms,
2271 .mode_fixup = nv50_pior_mode_fixup,
2272 .prepare = nv50_pior_disconnect,
2273 .commit = nv50_pior_commit,
2274 .mode_set = nv50_pior_mode_set,
2275 .disable = nv50_pior_disconnect,
2276 .get_crtc = nv50_display_crtc_get,
2277};
2278
2279static const struct drm_encoder_funcs nv50_pior_func = {
2280 .destroy = nv50_pior_destroy,
2281};
2282
2283static int
2284nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2285{
2286 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002287 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002288 struct nvkm_i2c_bus *bus = NULL;
2289 struct nvkm_i2c_aux *aux = NULL;
2290 struct i2c_adapter *ddc;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002291 struct nouveau_encoder *nv_encoder;
2292 struct drm_encoder *encoder;
2293 int type;
2294
2295 switch (dcbe->type) {
2296 case DCB_OUTPUT_TMDS:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002297 bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev));
2298 ddc = bus ? &bus->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002299 type = DRM_MODE_ENCODER_TMDS;
2300 break;
2301 case DCB_OUTPUT_DP:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002302 aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev));
2303 ddc = aux ? &aux->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002304 type = DRM_MODE_ENCODER_TMDS;
2305 break;
2306 default:
2307 return -ENODEV;
2308 }
2309
2310 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2311 if (!nv_encoder)
2312 return -ENOMEM;
2313 nv_encoder->dcb = dcbe;
2314 nv_encoder->or = ffs(dcbe->or) - 1;
2315 nv_encoder->i2c = ddc;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002316 nv_encoder->aux = aux;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002317
2318 encoder = to_drm_encoder(nv_encoder);
2319 encoder->possible_crtcs = dcbe->heads;
2320 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002321 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type, NULL);
Ben Skeggseb6313a2013-02-11 09:52:58 +10002322 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2323
2324 drm_mode_connector_attach_encoder(connector, encoder);
2325 return 0;
2326}
2327
2328/******************************************************************************
Ben Skeggsab0af552014-08-10 04:10:19 +10002329 * Framebuffer
2330 *****************************************************************************/
2331
Ben Skeggs8a423642014-08-10 04:10:19 +10002332static void
Ben Skeggs0ad72862014-08-10 04:10:22 +10002333nv50_fbdma_fini(struct nv50_fbdma *fbdma)
Ben Skeggs8a423642014-08-10 04:10:19 +10002334{
Ben Skeggs0ad72862014-08-10 04:10:22 +10002335 int i;
2336 for (i = 0; i < ARRAY_SIZE(fbdma->base); i++)
2337 nvif_object_fini(&fbdma->base[i]);
2338 nvif_object_fini(&fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002339 list_del(&fbdma->head);
2340 kfree(fbdma);
2341}
2342
2343static int
2344nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind)
2345{
2346 struct nouveau_drm *drm = nouveau_drm(dev);
2347 struct nv50_disp *disp = nv50_disp(dev);
2348 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggs4acfd702014-08-10 04:10:24 +10002349 struct __attribute__ ((packed)) {
2350 struct nv_dma_v0 base;
2351 union {
2352 struct nv50_dma_v0 nv50;
2353 struct gf100_dma_v0 gf100;
Ben Skeggsbd70563f2015-08-20 14:54:21 +10002354 struct gf119_dma_v0 gf119;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002355 };
2356 } args = {};
Ben Skeggs8a423642014-08-10 04:10:19 +10002357 struct nv50_fbdma *fbdma;
2358 struct drm_crtc *crtc;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002359 u32 size = sizeof(args.base);
Ben Skeggs8a423642014-08-10 04:10:19 +10002360 int ret;
2361
2362 list_for_each_entry(fbdma, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002363 if (fbdma->core.handle == name)
Ben Skeggs8a423642014-08-10 04:10:19 +10002364 return 0;
2365 }
2366
2367 fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL);
2368 if (!fbdma)
2369 return -ENOMEM;
2370 list_add(&fbdma->head, &disp->fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002371
Ben Skeggs4acfd702014-08-10 04:10:24 +10002372 args.base.target = NV_DMA_V0_TARGET_VRAM;
2373 args.base.access = NV_DMA_V0_ACCESS_RDWR;
2374 args.base.start = offset;
2375 args.base.limit = offset + length - 1;
Ben Skeggs8a423642014-08-10 04:10:19 +10002376
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002377 if (drm->device.info.chipset < 0x80) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002378 args.nv50.part = NV50_DMA_V0_PART_256;
2379 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002380 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002381 if (drm->device.info.chipset < 0xc0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002382 args.nv50.part = NV50_DMA_V0_PART_256;
2383 args.nv50.kind = kind;
2384 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002385 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002386 if (drm->device.info.chipset < 0xd0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002387 args.gf100.kind = kind;
2388 size += sizeof(args.gf100);
Ben Skeggs8a423642014-08-10 04:10:19 +10002389 } else {
Ben Skeggsbd70563f2015-08-20 14:54:21 +10002390 args.gf119.page = GF119_DMA_V0_PAGE_LP;
2391 args.gf119.kind = kind;
2392 size += sizeof(args.gf119);
Ben Skeggs8a423642014-08-10 04:10:19 +10002393 }
2394
2395 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002396 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsa01ca782015-08-20 14:54:15 +10002397 int ret = nvif_object_init(&head->sync.base.base.user, name,
2398 NV_DMA_IN_MEMORY, &args, size,
Ben Skeggs0ad72862014-08-10 04:10:22 +10002399 &fbdma->base[head->base.index]);
Ben Skeggs8a423642014-08-10 04:10:19 +10002400 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002401 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002402 return ret;
2403 }
2404 }
2405
Ben Skeggsa01ca782015-08-20 14:54:15 +10002406 ret = nvif_object_init(&mast->base.base.user, name, NV_DMA_IN_MEMORY,
2407 &args, size, &fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002408 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002409 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002410 return ret;
2411 }
2412
2413 return 0;
2414}
2415
Ben Skeggsab0af552014-08-10 04:10:19 +10002416static void
2417nv50_fb_dtor(struct drm_framebuffer *fb)
2418{
2419}
2420
2421static int
2422nv50_fb_ctor(struct drm_framebuffer *fb)
2423{
2424 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
2425 struct nouveau_drm *drm = nouveau_drm(fb->dev);
2426 struct nouveau_bo *nvbo = nv_fb->nvbo;
Ben Skeggs8a423642014-08-10 04:10:19 +10002427 struct nv50_disp *disp = nv50_disp(fb->dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002428 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
2429 u8 tile = nvbo->tile_mode;
Ben Skeggsab0af552014-08-10 04:10:19 +10002430
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002431 if (drm->device.info.chipset >= 0xc0)
Ben Skeggs8a423642014-08-10 04:10:19 +10002432 tile >>= 4; /* yep.. */
2433
Ben Skeggsab0af552014-08-10 04:10:19 +10002434 switch (fb->depth) {
2435 case 8: nv_fb->r_format = 0x1e00; break;
2436 case 15: nv_fb->r_format = 0xe900; break;
2437 case 16: nv_fb->r_format = 0xe800; break;
2438 case 24:
2439 case 32: nv_fb->r_format = 0xcf00; break;
2440 case 30: nv_fb->r_format = 0xd100; break;
2441 default:
2442 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
2443 return -EINVAL;
2444 }
2445
Ben Skeggs648d4df2014-08-10 04:10:27 +10002446 if (disp->disp->oclass < G82_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002447 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2448 (fb->pitches[0] | 0x00100000);
2449 nv_fb->r_format |= kind << 16;
2450 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10002451 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002452 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2453 (fb->pitches[0] | 0x00100000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002454 } else {
Ben Skeggs8a423642014-08-10 04:10:19 +10002455 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2456 (fb->pitches[0] | 0x01000000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002457 }
Ben Skeggs8a423642014-08-10 04:10:19 +10002458 nv_fb->r_handle = 0xffff0000 | kind;
Ben Skeggsab0af552014-08-10 04:10:19 +10002459
Ben Skeggsf392ec42014-08-10 04:10:28 +10002460 return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0,
2461 drm->device.info.ram_user, kind);
Ben Skeggsab0af552014-08-10 04:10:19 +10002462}
2463
2464/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002465 * Init
2466 *****************************************************************************/
Ben Skeggsab0af552014-08-10 04:10:19 +10002467
Ben Skeggs2a44e492011-11-09 11:36:33 +10002468void
Ben Skeggse225f442012-11-21 14:40:21 +10002469nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002470{
Ben Skeggs26f6d882011-07-04 16:25:18 +10002471}
2472
2473int
Ben Skeggse225f442012-11-21 14:40:21 +10002474nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002475{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002476 struct nv50_disp *disp = nv50_disp(dev);
2477 struct drm_crtc *crtc;
2478 u32 *push;
2479
2480 push = evo_wait(nv50_mast(dev), 32);
2481 if (!push)
2482 return -EBUSY;
2483
2484 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2485 struct nv50_sync *sync = nv50_sync(crtc);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002486
2487 nv50_crtc_lut_load(crtc);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002488 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002489 }
2490
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002491 evo_mthd(push, 0x0088, 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10002492 evo_data(push, nv50_mast(dev)->base.sync.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002493 evo_kick(push, nv50_mast(dev));
2494 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002495}
2496
2497void
Ben Skeggse225f442012-11-21 14:40:21 +10002498nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002499{
Ben Skeggse225f442012-11-21 14:40:21 +10002500 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002501 struct nv50_fbdma *fbdma, *fbtmp;
2502
2503 list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002504 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002505 }
Ben Skeggs26f6d882011-07-04 16:25:18 +10002506
Ben Skeggs0ad72862014-08-10 04:10:22 +10002507 nv50_dmac_destroy(&disp->mast.base, disp->disp);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10002508
Ben Skeggs816af2f2011-11-16 15:48:48 +10002509 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002510 if (disp->sync)
2511 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10002512 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10002513
Ben Skeggs77145f12012-07-31 16:16:21 +10002514 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002515 kfree(disp);
2516}
2517
2518int
Ben Skeggse225f442012-11-21 14:40:21 +10002519nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002520{
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002521 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggs77145f12012-07-31 16:16:21 +10002522 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10002523 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002524 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10002525 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10002526 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002527 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002528
2529 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2530 if (!disp)
2531 return -ENOMEM;
Ben Skeggs8a423642014-08-10 04:10:19 +10002532 INIT_LIST_HEAD(&disp->fbdma);
Ben Skeggs77145f12012-07-31 16:16:21 +10002533
2534 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10002535 nouveau_display(dev)->dtor = nv50_display_destroy;
2536 nouveau_display(dev)->init = nv50_display_init;
2537 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggsab0af552014-08-10 04:10:19 +10002538 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
2539 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
Ben Skeggs0ad72862014-08-10 04:10:22 +10002540 disp->disp = &nouveau_display(dev)->disp;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002541
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002542 /* small shared memory area we use for notifiers and semaphores */
2543 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01002544 0, 0x0000, NULL, NULL, &disp->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002545 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10002546 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002547 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002548 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002549 if (ret)
2550 nouveau_bo_unpin(disp->sync);
2551 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002552 if (ret)
2553 nouveau_bo_ref(NULL, &disp->sync);
2554 }
2555
2556 if (ret)
2557 goto out;
2558
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002559 /* allocate master evo channel */
Ben Skeggsa01ca782015-08-20 14:54:15 +10002560 ret = nv50_core_create(device, disp->disp, disp->sync->bo.offset,
Ben Skeggs410f3ec2014-08-10 04:10:25 +10002561 &disp->mast);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002562 if (ret)
2563 goto out;
2564
Ben Skeggs438d99e2011-07-05 16:48:06 +10002565 /* create crtc objects to represent the hw heads */
Ben Skeggs648d4df2014-08-10 04:10:27 +10002566 if (disp->disp->oclass >= GF110_DISP)
Ben Skeggsa01ca782015-08-20 14:54:15 +10002567 crtcs = nvif_rd32(&device->object, 0x022448);
Ben Skeggs63718a02012-11-16 11:44:14 +10002568 else
2569 crtcs = 2;
2570
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002571 for (i = 0; i < crtcs; i++) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002572 ret = nv50_crtc_create(dev, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002573 if (ret)
2574 goto out;
2575 }
2576
Ben Skeggs83fc0832011-07-05 13:08:40 +10002577 /* create encoder/connector objects based on VBIOS DCB table */
2578 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2579 connector = nouveau_connector_create(dev, dcbe->connector);
2580 if (IS_ERR(connector))
2581 continue;
2582
Ben Skeggseb6313a2013-02-11 09:52:58 +10002583 if (dcbe->location == DCB_LOC_ON_CHIP) {
2584 switch (dcbe->type) {
2585 case DCB_OUTPUT_TMDS:
2586 case DCB_OUTPUT_LVDS:
2587 case DCB_OUTPUT_DP:
2588 ret = nv50_sor_create(connector, dcbe);
2589 break;
2590 case DCB_OUTPUT_ANALOG:
2591 ret = nv50_dac_create(connector, dcbe);
2592 break;
2593 default:
2594 ret = -ENODEV;
2595 break;
2596 }
2597 } else {
2598 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002599 }
2600
Ben Skeggseb6313a2013-02-11 09:52:58 +10002601 if (ret) {
2602 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2603 dcbe->location, dcbe->type,
2604 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10002605 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002606 }
2607 }
2608
2609 /* cull any connectors we created that don't have an encoder */
2610 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2611 if (connector->encoder_ids[0])
2612 continue;
2613
Ben Skeggs77145f12012-07-31 16:16:21 +10002614 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03002615 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002616 connector->funcs->destroy(connector);
2617 }
2618
Ben Skeggs26f6d882011-07-04 16:25:18 +10002619out:
2620 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002621 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002622 return ret;
2623}