blob: 7a7788212df76748c3395d5c5416e1baa4a94e15 [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 Skeggsdb1eb522016-02-11 08:35:32 +1000300 GM200_DISP_CORE_CHANNEL_DMA,
Ben Skeggs648d4df2014-08-10 04:10:27 +1000301 GM107_DISP_CORE_CHANNEL_DMA,
302 GK110_DISP_CORE_CHANNEL_DMA,
303 GK104_DISP_CORE_CHANNEL_DMA,
304 GF110_DISP_CORE_CHANNEL_DMA,
305 GT214_DISP_CORE_CHANNEL_DMA,
306 GT206_DISP_CORE_CHANNEL_DMA,
307 GT200_DISP_CORE_CHANNEL_DMA,
308 G82_DISP_CORE_CHANNEL_DMA,
309 NV50_DISP_CORE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000310 0
311 };
312
Ben Skeggsa01ca782015-08-20 14:54:15 +1000313 return nv50_dmac_create(device, disp, oclass, 0, &args, sizeof(args),
314 syncbuf, &core->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000315}
316
317/******************************************************************************
318 * Base
319 *****************************************************************************/
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000320
Ben Skeggse225f442012-11-21 14:40:21 +1000321struct nv50_sync {
322 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000323 u32 addr;
324 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000325};
326
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000327static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000328nv50_base_create(struct nvif_device *device, struct nvif_object *disp,
329 int head, u64 syncbuf, struct nv50_sync *base)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000330{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000331 struct nv50_disp_base_channel_dma_v0 args = {
332 .pushbuf = 0xb0007c00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000333 .head = head,
334 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000335 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000336 GK110_DISP_BASE_CHANNEL_DMA,
337 GK104_DISP_BASE_CHANNEL_DMA,
338 GF110_DISP_BASE_CHANNEL_DMA,
339 GT214_DISP_BASE_CHANNEL_DMA,
340 GT200_DISP_BASE_CHANNEL_DMA,
341 G82_DISP_BASE_CHANNEL_DMA,
342 NV50_DISP_BASE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000343 0
344 };
345
Ben Skeggsa01ca782015-08-20 14:54:15 +1000346 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000347 syncbuf, &base->base);
348}
349
350/******************************************************************************
351 * Overlay
352 *****************************************************************************/
353
Ben Skeggse225f442012-11-21 14:40:21 +1000354struct nv50_ovly {
355 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000356};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000357
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000358static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000359nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp,
360 int head, u64 syncbuf, struct nv50_ovly *ovly)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000361{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000362 struct nv50_disp_overlay_channel_dma_v0 args = {
363 .pushbuf = 0xb0007e00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000364 .head = head,
365 };
Ben Skeggs315a8b22015-08-20 14:54:16 +1000366 static const s32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000367 GK104_DISP_OVERLAY_CONTROL_DMA,
368 GF110_DISP_OVERLAY_CONTROL_DMA,
369 GT214_DISP_OVERLAY_CHANNEL_DMA,
370 GT200_DISP_OVERLAY_CHANNEL_DMA,
371 G82_DISP_OVERLAY_CHANNEL_DMA,
372 NV50_DISP_OVERLAY_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000373 0
374 };
375
Ben Skeggsa01ca782015-08-20 14:54:15 +1000376 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000377 syncbuf, &ovly->base);
378}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000379
Ben Skeggse225f442012-11-21 14:40:21 +1000380struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000381 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000382 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000383 struct nv50_curs curs;
384 struct nv50_sync sync;
385 struct nv50_ovly ovly;
386 struct nv50_oimm oimm;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000387};
388
Ben Skeggse225f442012-11-21 14:40:21 +1000389#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
390#define nv50_curs(c) (&nv50_head(c)->curs)
391#define nv50_sync(c) (&nv50_head(c)->sync)
392#define nv50_ovly(c) (&nv50_head(c)->ovly)
393#define nv50_oimm(c) (&nv50_head(c)->oimm)
394#define nv50_chan(c) (&(c)->base.base)
Ben Skeggs0ad72862014-08-10 04:10:22 +1000395#define nv50_vers(c) nv50_chan(c)->user.oclass
396
397struct nv50_fbdma {
398 struct list_head head;
399 struct nvif_object core;
400 struct nvif_object base[4];
401};
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000402
Ben Skeggse225f442012-11-21 14:40:21 +1000403struct nv50_disp {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000404 struct nvif_object *disp;
Ben Skeggse225f442012-11-21 14:40:21 +1000405 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000406
Ben Skeggs8a423642014-08-10 04:10:19 +1000407 struct list_head fbdma;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000408
409 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000410};
411
Ben Skeggse225f442012-11-21 14:40:21 +1000412static struct nv50_disp *
413nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000414{
Ben Skeggs77145f12012-07-31 16:16:21 +1000415 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000416}
417
Ben Skeggse225f442012-11-21 14:40:21 +1000418#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000419
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000420static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000421nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000422{
423 return nouveau_encoder(encoder)->crtc;
424}
425
426/******************************************************************************
427 * EVO channel helpers
428 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000429static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000430evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000431{
Ben Skeggse225f442012-11-21 14:40:21 +1000432 struct nv50_dmac *dmac = evoc;
Ben Skeggsa01ca782015-08-20 14:54:15 +1000433 struct nvif_device *device = dmac->base.device;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000434 u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000435
Daniel Vetter59ad1462012-12-02 14:49:44 +0100436 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000437 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000438 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000439
Ben Skeggs0ad72862014-08-10 04:10:22 +1000440 nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
Ben Skeggs54442042015-08-20 14:54:11 +1000441 if (nvif_msec(device, 2000,
442 if (!nvif_rd32(&dmac->base.user, 0x0004))
443 break;
444 ) < 0) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100445 mutex_unlock(&dmac->lock);
Ben Skeggs9ad97ed2015-08-20 14:54:13 +1000446 printk(KERN_ERR "nouveau: evo channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000447 return NULL;
448 }
449
450 put = 0;
451 }
452
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000453 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000454}
455
456static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000457evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000458{
Ben Skeggse225f442012-11-21 14:40:21 +1000459 struct nv50_dmac *dmac = evoc;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000460 nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100461 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000462}
463
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000464#if 1
Ben Skeggs51beb422011-07-05 10:33:08 +1000465#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
466#define evo_data(p,d) *((p)++) = (d)
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000467#else
468#define evo_mthd(p,m,s) do { \
469 const u32 _m = (m), _s = (s); \
470 printk(KERN_ERR "%04x %d %s\n", _m, _s, __func__); \
471 *((p)++) = ((_s << 18) | _m); \
472} while(0)
473#define evo_data(p,d) do { \
474 const u32 _d = (d); \
475 printk(KERN_ERR "\t%08x\n", _d); \
476 *((p)++) = _d; \
477} while(0)
478#endif
Ben Skeggs51beb422011-07-05 10:33:08 +1000479
Ben Skeggs3376ee32011-11-12 14:28:12 +1000480static bool
481evo_sync_wait(void *data)
482{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500483 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
484 return true;
485 usleep_range(1, 2);
486 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000487}
488
489static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000490evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000491{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000492 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggse225f442012-11-21 14:40:21 +1000493 struct nv50_disp *disp = nv50_disp(dev);
494 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000495 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000496 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000497 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000498 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000499 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000500 evo_mthd(push, 0x0080, 2);
501 evo_data(push, 0x00000000);
502 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000503 evo_kick(push, mast);
Ben Skeggs54442042015-08-20 14:54:11 +1000504 if (nvif_msec(device, 2000,
505 if (evo_sync_wait(disp->sync))
506 break;
507 ) >= 0)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000508 return 0;
509 }
510
511 return -EBUSY;
512}
513
514/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +1000515 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +1000516 *****************************************************************************/
517struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +1000518nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000519{
Ben Skeggse225f442012-11-21 14:40:21 +1000520 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000521}
522
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000523struct nv50_display_flip {
524 struct nv50_disp *disp;
525 struct nv50_sync *chan;
526};
527
528static bool
529nv50_display_flip_wait(void *data)
530{
531 struct nv50_display_flip *flip = data;
532 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
Calvin Owensb1ea3e62013-04-07 21:01:19 -0500533 flip->chan->data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000534 return true;
535 usleep_range(1, 2);
536 return false;
537}
538
Ben Skeggs3376ee32011-11-12 14:28:12 +1000539void
Ben Skeggse225f442012-11-21 14:40:21 +1000540nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000541{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000542 struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000543 struct nv50_display_flip flip = {
544 .disp = nv50_disp(crtc->dev),
545 .chan = nv50_sync(crtc),
546 };
Ben Skeggs3376ee32011-11-12 14:28:12 +1000547 u32 *push;
548
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000549 push = evo_wait(flip.chan, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000550 if (push) {
551 evo_mthd(push, 0x0084, 1);
552 evo_data(push, 0x00000000);
553 evo_mthd(push, 0x0094, 1);
554 evo_data(push, 0x00000000);
555 evo_mthd(push, 0x00c0, 1);
556 evo_data(push, 0x00000000);
557 evo_mthd(push, 0x0080, 1);
558 evo_data(push, 0x00000000);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000559 evo_kick(push, flip.chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000560 }
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000561
Ben Skeggs54442042015-08-20 14:54:11 +1000562 nvif_msec(device, 2000,
563 if (nv50_display_flip_wait(&flip))
564 break;
565 );
Ben Skeggs3376ee32011-11-12 14:28:12 +1000566}
567
568int
Ben Skeggse225f442012-11-21 14:40:21 +1000569nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +1000570 struct nouveau_channel *chan, u32 swap_interval)
571{
572 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000573 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000574 struct nv50_head *head = nv50_head(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000575 struct nv50_sync *sync = nv50_sync(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000576 u32 *push;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000577 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000578
Ben Skeggs9ba83102014-12-22 19:50:23 +1000579 if (crtc->primary->fb->width != fb->width ||
580 crtc->primary->fb->height != fb->height)
581 return -EINVAL;
582
Ben Skeggs3376ee32011-11-12 14:28:12 +1000583 swap_interval <<= 4;
584 if (swap_interval == 0)
585 swap_interval |= 0x100;
Ben Skeggsf60b6e72013-03-19 15:20:00 +1000586 if (chan == NULL)
587 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000588
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000589 push = evo_wait(sync, 128);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000590 if (unlikely(push == NULL))
591 return -EBUSY;
592
Ben Skeggsa01ca782015-08-20 14:54:15 +1000593 if (chan && chan->user.oclass < G82_CHANNEL_GPFIFO) {
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000594 ret = RING_SPACE(chan, 8);
595 if (ret)
596 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000597
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000598 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000599 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000600 OUT_RING (chan, sync->addr ^ 0x10);
601 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
602 OUT_RING (chan, sync->data + 1);
603 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
604 OUT_RING (chan, sync->addr);
605 OUT_RING (chan, sync->data);
606 } else
Ben Skeggsa01ca782015-08-20 14:54:15 +1000607 if (chan && chan->user.oclass < FERMI_CHANNEL_GPFIFO) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000608 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000609 ret = RING_SPACE(chan, 12);
610 if (ret)
611 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +1000612
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000613 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000614 OUT_RING (chan, chan->vram.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000615 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
616 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
617 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
618 OUT_RING (chan, sync->data + 1);
619 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
620 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
621 OUT_RING (chan, upper_32_bits(addr));
622 OUT_RING (chan, lower_32_bits(addr));
623 OUT_RING (chan, sync->data);
624 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
625 } else
626 if (chan) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000627 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000628 ret = RING_SPACE(chan, 10);
629 if (ret)
630 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000631
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000632 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
633 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
634 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
635 OUT_RING (chan, sync->data + 1);
636 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
637 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
638 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
639 OUT_RING (chan, upper_32_bits(addr));
640 OUT_RING (chan, lower_32_bits(addr));
641 OUT_RING (chan, sync->data);
642 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
643 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
644 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -0500645
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000646 if (chan) {
647 sync->addr ^= 0x10;
648 sync->data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000649 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000650 }
651
652 /* queue the flip */
653 evo_mthd(push, 0x0100, 1);
654 evo_data(push, 0xfffe0000);
655 evo_mthd(push, 0x0084, 1);
656 evo_data(push, swap_interval);
657 if (!(swap_interval & 0x00000100)) {
658 evo_mthd(push, 0x00e0, 1);
659 evo_data(push, 0x40000000);
660 }
661 evo_mthd(push, 0x0088, 4);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000662 evo_data(push, sync->addr);
663 evo_data(push, sync->data++);
664 evo_data(push, sync->data);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000665 evo_data(push, sync->base.sync.handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000666 evo_mthd(push, 0x00a0, 2);
667 evo_data(push, 0x00000000);
668 evo_data(push, 0x00000000);
669 evo_mthd(push, 0x00c0, 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000670 evo_data(push, nv_fb->r_handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000671 evo_mthd(push, 0x0110, 2);
672 evo_data(push, 0x00000000);
673 evo_data(push, 0x00000000);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000674 if (nv50_vers(sync) < GF110_DISP_BASE_CHANNEL_DMA) {
Ben Skeggsed5085a52012-11-16 13:16:51 +1000675 evo_mthd(push, 0x0800, 5);
676 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
677 evo_data(push, 0);
678 evo_data(push, (fb->height << 16) | fb->width);
679 evo_data(push, nv_fb->r_pitch);
680 evo_data(push, nv_fb->r_format);
681 } else {
682 evo_mthd(push, 0x0400, 5);
683 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
684 evo_data(push, 0);
685 evo_data(push, (fb->height << 16) | fb->width);
686 evo_data(push, nv_fb->r_pitch);
687 evo_data(push, nv_fb->r_format);
688 }
Ben Skeggs3376ee32011-11-12 14:28:12 +1000689 evo_mthd(push, 0x0080, 1);
690 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000691 evo_kick(push, sync);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000692
693 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000694 return 0;
695}
696
Ben Skeggs26f6d882011-07-04 16:25:18 +1000697/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000698 * CRTC
699 *****************************************************************************/
700static int
Ben Skeggse225f442012-11-21 14:40:21 +1000701nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000702{
Ben Skeggse225f442012-11-21 14:40:21 +1000703 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde691852011-10-17 12:23:41 +1000704 struct nouveau_connector *nv_connector;
705 struct drm_connector *connector;
706 u32 *push, mode = 0x00;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000707
Ben Skeggs488ff202011-10-17 10:38:10 +1000708 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +1000709 connector = &nv_connector->base;
710 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
Matt Roperf4510a22014-04-01 15:22:40 -0700711 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
Ben Skeggsde691852011-10-17 12:23:41 +1000712 mode = DITHERING_MODE_DYNAMIC2X2;
713 } else {
714 mode = nv_connector->dithering_mode;
715 }
716
717 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
718 if (connector->display_info.bpc >= 8)
719 mode |= DITHERING_DEPTH_8BPC;
720 } else {
721 mode |= nv_connector->dithering_depth;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000722 }
723
Ben Skeggsde8268c2012-11-16 10:24:31 +1000724 push = evo_wait(mast, 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000725 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000726 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000727 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
728 evo_data(push, mode);
729 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000730 if (nv50_vers(mast) < GK104_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000731 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
732 evo_data(push, mode);
733 } else {
734 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
735 evo_data(push, mode);
736 }
737
Ben Skeggs438d99e2011-07-05 16:48:06 +1000738 if (update) {
739 evo_mthd(push, 0x0080, 1);
740 evo_data(push, 0x00000000);
741 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000742 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000743 }
744
745 return 0;
746}
747
748static int
Ben Skeggse225f442012-11-21 14:40:21 +1000749nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000750{
Ben Skeggse225f442012-11-21 14:40:21 +1000751 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs92854622011-11-11 23:49:06 +1000752 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000753 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000754 struct nouveau_connector *nv_connector;
Ben Skeggs92854622011-11-11 23:49:06 +1000755 int mode = DRM_MODE_SCALE_NONE;
756 u32 oX, oY, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000757
Ben Skeggs92854622011-11-11 23:49:06 +1000758 /* start off at the resolution we programmed the crtc for, this
759 * effectively handles NONE/FULL scaling
760 */
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000761 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs576f7912014-12-22 17:19:26 +1000762 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs92854622011-11-11 23:49:06 +1000763 mode = nv_connector->scaling_mode;
Ben Skeggs576f7912014-12-22 17:19:26 +1000764 if (nv_connector->scaling_full) /* non-EDID LVDS/eDP mode */
765 mode = DRM_MODE_SCALE_FULLSCREEN;
766 }
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000767
Ben Skeggs92854622011-11-11 23:49:06 +1000768 if (mode != DRM_MODE_SCALE_NONE)
769 omode = nv_connector->native_mode;
770 else
771 omode = umode;
772
773 oX = omode->hdisplay;
774 oY = omode->vdisplay;
775 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
776 oY *= 2;
777
778 /* add overscan compensation if necessary, will keep the aspect
779 * ratio the same as the backend mode unless overridden by the
780 * user setting both hborder and vborder properties.
781 */
782 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
783 (nv_connector->underscan == UNDERSCAN_AUTO &&
Ben Skeggs92854622011-11-11 23:49:06 +1000784 drm_detect_hdmi_monitor(nv_connector->edid)))) {
785 u32 bX = nv_connector->underscan_hborder;
786 u32 bY = nv_connector->underscan_vborder;
787 u32 aspect = (oY << 19) / oX;
788
789 if (bX) {
790 oX -= (bX * 2);
791 if (bY) oY -= (bY * 2);
792 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
793 } else {
794 oX -= (oX >> 4) + 32;
795 if (bY) oY -= (bY * 2);
796 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000797 }
798 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000799
Ben Skeggs92854622011-11-11 23:49:06 +1000800 /* handle CENTER/ASPECT scaling, taking into account the areas
801 * removed already for overscan compensation
802 */
803 switch (mode) {
804 case DRM_MODE_SCALE_CENTER:
805 oX = min((u32)umode->hdisplay, oX);
806 oY = min((u32)umode->vdisplay, oY);
807 /* fall-through */
808 case DRM_MODE_SCALE_ASPECT:
809 if (oY < oX) {
810 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
811 oX = ((oY * aspect) + (aspect / 2)) >> 19;
812 } else {
813 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
814 oY = ((oX * aspect) + (aspect / 2)) >> 19;
815 }
816 break;
817 default:
818 break;
819 }
820
Ben Skeggsde8268c2012-11-16 10:24:31 +1000821 push = evo_wait(mast, 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000822 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000823 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000824 /*XXX: SCALE_CTRL_ACTIVE??? */
825 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
826 evo_data(push, (oY << 16) | oX);
827 evo_data(push, (oY << 16) | oX);
828 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
829 evo_data(push, 0x00000000);
830 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
831 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
832 } else {
833 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
834 evo_data(push, (oY << 16) | oX);
835 evo_data(push, (oY << 16) | oX);
836 evo_data(push, (oY << 16) | oX);
837 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
838 evo_data(push, 0x00000000);
839 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
840 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
841 }
842
843 evo_kick(push, mast);
844
Ben Skeggs3376ee32011-11-12 14:28:12 +1000845 if (update) {
Ben Skeggse225f442012-11-21 14:40:21 +1000846 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700847 nv50_display_flip_next(crtc, crtc->primary->fb,
848 NULL, 1);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000849 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000850 }
851
852 return 0;
853}
854
855static int
Roy Splieteae73822014-10-30 22:57:45 +0100856nv50_crtc_set_raster_vblank_dmi(struct nouveau_crtc *nv_crtc, u32 usec)
857{
858 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
859 u32 *push;
860
861 push = evo_wait(mast, 8);
862 if (!push)
863 return -ENOMEM;
864
865 evo_mthd(push, 0x0828 + (nv_crtc->index * 0x400), 1);
866 evo_data(push, usec);
867 evo_kick(push, mast);
868 return 0;
869}
870
871static int
Ben Skeggse225f442012-11-21 14:40:21 +1000872nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +1000873{
Ben Skeggse225f442012-11-21 14:40:21 +1000874 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsf9887d02012-11-21 13:03:42 +1000875 u32 *push, hue, vib;
876 int adj;
877
878 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
879 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
880 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
881
882 push = evo_wait(mast, 16);
883 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000884 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsf9887d02012-11-21 13:03:42 +1000885 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
886 evo_data(push, (hue << 20) | (vib << 8));
887 } else {
888 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
889 evo_data(push, (hue << 20) | (vib << 8));
890 }
891
892 if (update) {
893 evo_mthd(push, 0x0080, 1);
894 evo_data(push, 0x00000000);
895 }
896 evo_kick(push, mast);
897 }
898
899 return 0;
900}
901
902static int
Ben Skeggse225f442012-11-21 14:40:21 +1000903nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000904 int x, int y, bool update)
905{
906 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggse225f442012-11-21 14:40:21 +1000907 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000908 u32 *push;
909
Ben Skeggsde8268c2012-11-16 10:24:31 +1000910 push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000911 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000912 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000913 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
914 evo_data(push, nvfb->nvbo->bo.offset >> 8);
915 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
916 evo_data(push, (fb->height << 16) | fb->width);
917 evo_data(push, nvfb->r_pitch);
918 evo_data(push, nvfb->r_format);
919 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
920 evo_data(push, (y << 16) | x);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000921 if (nv50_vers(mast) > NV50_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000922 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000923 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000924 }
925 } else {
926 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
927 evo_data(push, nvfb->nvbo->bo.offset >> 8);
928 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
929 evo_data(push, (fb->height << 16) | fb->width);
930 evo_data(push, nvfb->r_pitch);
931 evo_data(push, nvfb->r_format);
Ben Skeggs8a423642014-08-10 04:10:19 +1000932 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000933 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
934 evo_data(push, (y << 16) | x);
935 }
936
Ben Skeggsa46232e2011-07-07 15:23:48 +1000937 if (update) {
938 evo_mthd(push, 0x0080, 1);
939 evo_data(push, 0x00000000);
940 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000941 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000942 }
943
Ben Skeggs8a423642014-08-10 04:10:19 +1000944 nv_crtc->fb.handle = nvfb->r_handle;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000945 return 0;
946}
947
948static void
Ben Skeggse225f442012-11-21 14:40:21 +1000949nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000950{
Ben Skeggse225f442012-11-21 14:40:21 +1000951 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000952 u32 *push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000953 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000954 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000955 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
956 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100957 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000958 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000959 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000960 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
961 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100962 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000963 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000964 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000965 } else {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000966 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
967 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100968 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000969 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000970 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000971 }
972 evo_kick(push, mast);
973 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100974 nv_crtc->cursor.visible = true;
Ben Skeggsde8268c2012-11-16 10:24:31 +1000975}
976
977static void
Ben Skeggse225f442012-11-21 14:40:21 +1000978nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000979{
Ben Skeggse225f442012-11-21 14:40:21 +1000980 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000981 u32 *push = evo_wait(mast, 16);
982 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000983 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000984 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
985 evo_data(push, 0x05000000);
986 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000987 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000988 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
989 evo_data(push, 0x05000000);
990 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
991 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000992 } else {
993 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
994 evo_data(push, 0x05000000);
995 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
996 evo_data(push, 0x00000000);
997 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000998 evo_kick(push, mast);
999 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001000 nv_crtc->cursor.visible = false;
Ben Skeggsde8268c2012-11-16 10:24:31 +10001001}
Ben Skeggs438d99e2011-07-05 16:48:06 +10001002
Ben Skeggsde8268c2012-11-16 10:24:31 +10001003static void
Ben Skeggse225f442012-11-21 14:40:21 +10001004nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +10001005{
Ben Skeggse225f442012-11-21 14:40:21 +10001006 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001007
Ben Skeggs697bb722015-07-28 17:20:57 +10001008 if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled)
Ben Skeggse225f442012-11-21 14:40:21 +10001009 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001010 else
Ben Skeggse225f442012-11-21 14:40:21 +10001011 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001012
1013 if (update) {
1014 u32 *push = evo_wait(mast, 2);
1015 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001016 evo_mthd(push, 0x0080, 1);
1017 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001018 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001019 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001020 }
1021}
1022
1023static void
Ben Skeggse225f442012-11-21 14:40:21 +10001024nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001025{
1026}
1027
1028static void
Ben Skeggse225f442012-11-21 14:40:21 +10001029nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001030{
1031 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001032 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001033 u32 *push;
1034
Ben Skeggse225f442012-11-21 14:40:21 +10001035 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001036
Ben Skeggs56d237d2014-05-19 14:54:33 +10001037 push = evo_wait(mast, 6);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001038 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001039 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001040 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1041 evo_data(push, 0x00000000);
1042 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1043 evo_data(push, 0x40000000);
1044 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001045 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001046 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1047 evo_data(push, 0x00000000);
1048 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1049 evo_data(push, 0x40000000);
1050 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
1051 evo_data(push, 0x00000000);
1052 } else {
1053 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
1054 evo_data(push, 0x00000000);
1055 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
1056 evo_data(push, 0x03000000);
1057 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
1058 evo_data(push, 0x00000000);
1059 }
1060
1061 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001062 }
1063
Ben Skeggse225f442012-11-21 14:40:21 +10001064 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001065}
1066
1067static void
Ben Skeggse225f442012-11-21 14:40:21 +10001068nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001069{
1070 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001071 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001072 u32 *push;
1073
Ben Skeggsde8268c2012-11-16 10:24:31 +10001074 push = evo_wait(mast, 32);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001075 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001076 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001077 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001078 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001079 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1080 evo_data(push, 0xc0000000);
1081 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1082 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001083 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001084 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001085 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001086 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1087 evo_data(push, 0xc0000000);
1088 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1089 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001090 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001091 } else {
1092 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001093 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001094 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
1095 evo_data(push, 0x83000000);
1096 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1097 evo_data(push, 0x00000000);
1098 evo_data(push, 0x00000000);
1099 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001100 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001101 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
1102 evo_data(push, 0xffffff00);
1103 }
1104
1105 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001106 }
1107
Ben Skeggs5a560252014-11-10 15:52:02 +10001108 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Matt Roperf4510a22014-04-01 15:22:40 -07001109 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001110}
1111
1112static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001113nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001114 struct drm_display_mode *adjusted_mode)
1115{
Ben Skeggseb2e9682014-01-24 10:13:23 +10001116 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001117 return true;
1118}
1119
1120static int
Ben Skeggse225f442012-11-21 14:40:21 +10001121nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001122{
Matt Roperf4510a22014-04-01 15:22:40 -07001123 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001124 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001125 int ret;
1126
Ben Skeggs547ad072014-11-10 12:35:06 +10001127 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001128 if (ret == 0) {
1129 if (head->image)
1130 nouveau_bo_unpin(head->image);
1131 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001132 }
1133
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001134 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001135}
1136
1137static int
Ben Skeggse225f442012-11-21 14:40:21 +10001138nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001139 struct drm_display_mode *mode, int x, int y,
1140 struct drm_framebuffer *old_fb)
1141{
Ben Skeggse225f442012-11-21 14:40:21 +10001142 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001143 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1144 struct nouveau_connector *nv_connector;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001145 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
1146 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
1147 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
1148 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
Roy Spliet1dce6262014-09-12 18:00:13 +02001149 u32 vblan2e = 0, vblan2s = 1, vblankus = 0;
Ben Skeggs3488c572012-03-12 11:42:20 +10001150 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001151 int ret;
1152
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001153 hactive = mode->htotal;
1154 hsynce = mode->hsync_end - mode->hsync_start - 1;
1155 hbackp = mode->htotal - mode->hsync_end;
1156 hblanke = hsynce + hbackp;
1157 hfrontp = mode->hsync_start - mode->hdisplay;
1158 hblanks = mode->htotal - hfrontp - 1;
1159
1160 vactive = mode->vtotal * vscan / ilace;
1161 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
1162 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
1163 vblanke = vsynce + vbackp;
1164 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
1165 vblanks = vactive - vfrontp - 1;
Roy Spliet1dce6262014-09-12 18:00:13 +02001166 /* XXX: Safe underestimate, even "0" works */
1167 vblankus = (vactive - mode->vdisplay - 2) * hactive;
1168 vblankus *= 1000;
1169 vblankus /= mode->clock;
1170
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001171 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1172 vblan2e = vactive + vsynce + vbackp;
1173 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
1174 vactive = (vactive * 2) + 1;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001175 }
1176
Ben Skeggse225f442012-11-21 14:40:21 +10001177 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001178 if (ret)
1179 return ret;
1180
Ben Skeggsde8268c2012-11-16 10:24:31 +10001181 push = evo_wait(mast, 64);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001182 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001183 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001184 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1185 evo_data(push, 0x00800000 | mode->clock);
1186 evo_data(push, (ilace == 2) ? 2 : 0);
Roy Splieteae73822014-10-30 22:57:45 +01001187 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001188 evo_data(push, 0x00000000);
1189 evo_data(push, (vactive << 16) | hactive);
1190 evo_data(push, ( vsynce << 16) | hsynce);
1191 evo_data(push, (vblanke << 16) | hblanke);
1192 evo_data(push, (vblanks << 16) | hblanks);
1193 evo_data(push, (vblan2e << 16) | vblan2s);
Roy Splieteae73822014-10-30 22:57:45 +01001194 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001195 evo_data(push, 0x00000000);
1196 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1197 evo_data(push, 0x00000311);
1198 evo_data(push, 0x00000100);
1199 } else {
1200 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
1201 evo_data(push, 0x00000000);
1202 evo_data(push, (vactive << 16) | hactive);
1203 evo_data(push, ( vsynce << 16) | hsynce);
1204 evo_data(push, (vblanke << 16) | hblanke);
1205 evo_data(push, (vblanks << 16) | hblanks);
1206 evo_data(push, (vblan2e << 16) | vblan2s);
1207 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1208 evo_data(push, 0x00000000); /* ??? */
1209 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1210 evo_data(push, mode->clock * 1000);
1211 evo_data(push, 0x00200000); /* ??? */
1212 evo_data(push, mode->clock * 1000);
1213 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1214 evo_data(push, 0x00000311);
1215 evo_data(push, 0x00000100);
1216 }
1217
1218 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001219 }
1220
1221 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001222 nv50_crtc_set_dither(nv_crtc, false);
1223 nv50_crtc_set_scale(nv_crtc, false);
Roy Splieteae73822014-10-30 22:57:45 +01001224
1225 /* G94 only accepts this after setting scale */
1226 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA)
1227 nv50_crtc_set_raster_vblank_dmi(nv_crtc, vblankus);
1228
Ben Skeggse225f442012-11-21 14:40:21 +10001229 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07001230 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001231 return 0;
1232}
1233
1234static int
Ben Skeggse225f442012-11-21 14:40:21 +10001235nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001236 struct drm_framebuffer *old_fb)
1237{
Ben Skeggs77145f12012-07-31 16:16:21 +10001238 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001239 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1240 int ret;
1241
Matt Roperf4510a22014-04-01 15:22:40 -07001242 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10001243 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10001244 return 0;
1245 }
1246
Ben Skeggse225f442012-11-21 14:40:21 +10001247 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001248 if (ret)
1249 return ret;
1250
Ben Skeggse225f442012-11-21 14:40:21 +10001251 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07001252 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1253 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001254 return 0;
1255}
1256
1257static int
Ben Skeggse225f442012-11-21 14:40:21 +10001258nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001259 struct drm_framebuffer *fb, int x, int y,
1260 enum mode_set_atomic state)
1261{
1262 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001263 nv50_display_flip_stop(crtc);
1264 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001265 return 0;
1266}
1267
1268static void
Ben Skeggse225f442012-11-21 14:40:21 +10001269nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001270{
Ben Skeggse225f442012-11-21 14:40:21 +10001271 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001272 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1273 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1274 int i;
1275
1276 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001277 u16 r = nv_crtc->lut.r[i] >> 2;
1278 u16 g = nv_crtc->lut.g[i] >> 2;
1279 u16 b = nv_crtc->lut.b[i] >> 2;
1280
Ben Skeggs648d4df2014-08-10 04:10:27 +10001281 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001282 writew(r + 0x0000, lut + (i * 0x08) + 0);
1283 writew(g + 0x0000, lut + (i * 0x08) + 2);
1284 writew(b + 0x0000, lut + (i * 0x08) + 4);
1285 } else {
1286 writew(r + 0x6000, lut + (i * 0x20) + 0);
1287 writew(g + 0x6000, lut + (i * 0x20) + 2);
1288 writew(b + 0x6000, lut + (i * 0x20) + 4);
1289 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001290 }
1291}
1292
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001293static void
1294nv50_crtc_disable(struct drm_crtc *crtc)
1295{
1296 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10001297 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001298 if (head->image)
1299 nouveau_bo_unpin(head->image);
1300 nouveau_bo_ref(NULL, &head->image);
1301}
1302
Ben Skeggs438d99e2011-07-05 16:48:06 +10001303static int
Ben Skeggse225f442012-11-21 14:40:21 +10001304nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001305 uint32_t handle, uint32_t width, uint32_t height)
1306{
1307 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs5a560252014-11-10 15:52:02 +10001308 struct drm_gem_object *gem = NULL;
1309 struct nouveau_bo *nvbo = NULL;
1310 int ret = 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001311
Ben Skeggs5a560252014-11-10 15:52:02 +10001312 if (handle) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001313 if (width != 64 || height != 64)
1314 return -EINVAL;
1315
Chris Wilsona8ad0bd2016-05-09 11:04:54 +01001316 gem = drm_gem_object_lookup(file_priv, handle);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001317 if (unlikely(!gem))
1318 return -ENOENT;
1319 nvbo = nouveau_gem_object(gem);
1320
Ben Skeggs5a560252014-11-10 15:52:02 +10001321 ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001322 }
1323
Ben Skeggs5a560252014-11-10 15:52:02 +10001324 if (ret == 0) {
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001325 if (nv_crtc->cursor.nvbo)
1326 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1327 nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001328 }
Ben Skeggs5a560252014-11-10 15:52:02 +10001329 drm_gem_object_unreference_unlocked(gem);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001330
Ben Skeggs5a560252014-11-10 15:52:02 +10001331 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001332 return ret;
1333}
1334
1335static int
Ben Skeggse225f442012-11-21 14:40:21 +10001336nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001337{
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001338 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001339 struct nv50_curs *curs = nv50_curs(crtc);
1340 struct nv50_chan *chan = nv50_chan(curs);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001341 nvif_wr32(&chan->user, 0x0084, (y << 16) | (x & 0xffff));
1342 nvif_wr32(&chan->user, 0x0080, 0x00000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001343
1344 nv_crtc->cursor_saved_x = x;
1345 nv_crtc->cursor_saved_y = y;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001346 return 0;
1347}
1348
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001349static int
Ben Skeggse225f442012-11-21 14:40:21 +10001350nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001351 uint32_t size)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001352{
1353 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001354 u32 i;
1355
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001356 for (i = 0; i < size; i++) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001357 nv_crtc->lut.r[i] = r[i];
1358 nv_crtc->lut.g[i] = g[i];
1359 nv_crtc->lut.b[i] = b[i];
1360 }
1361
Ben Skeggse225f442012-11-21 14:40:21 +10001362 nv50_crtc_lut_load(crtc);
Maarten Lankhorst7ea77282016-06-07 12:49:30 +02001363
1364 return 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001365}
1366
1367static void
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001368nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y)
1369{
1370 nv50_crtc_cursor_move(&nv_crtc->base, x, y);
1371
1372 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
1373}
1374
1375static void
Ben Skeggse225f442012-11-21 14:40:21 +10001376nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001377{
1378 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001379 struct nv50_disp *disp = nv50_disp(crtc->dev);
1380 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001381 struct nv50_fbdma *fbdma;
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001382
Ben Skeggs0ad72862014-08-10 04:10:22 +10001383 list_for_each_entry(fbdma, &disp->fbdma, head) {
1384 nvif_object_fini(&fbdma->base[nv_crtc->index]);
1385 }
1386
1387 nv50_dmac_destroy(&head->ovly.base, disp->disp);
1388 nv50_pioc_destroy(&head->oimm.base);
1389 nv50_dmac_destroy(&head->sync.base, disp->disp);
1390 nv50_pioc_destroy(&head->curs.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001391
1392 /*XXX: this shouldn't be necessary, but the core doesn't call
1393 * disconnect() during the cleanup paths
1394 */
1395 if (head->image)
1396 nouveau_bo_unpin(head->image);
1397 nouveau_bo_ref(NULL, &head->image);
1398
Ben Skeggs5a560252014-11-10 15:52:02 +10001399 /*XXX: ditto */
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001400 if (nv_crtc->cursor.nvbo)
1401 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1402 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001403
Ben Skeggs438d99e2011-07-05 16:48:06 +10001404 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001405 if (nv_crtc->lut.nvbo)
1406 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001407 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001408
Ben Skeggs438d99e2011-07-05 16:48:06 +10001409 drm_crtc_cleanup(crtc);
1410 kfree(crtc);
1411}
1412
Ben Skeggse225f442012-11-21 14:40:21 +10001413static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1414 .dpms = nv50_crtc_dpms,
1415 .prepare = nv50_crtc_prepare,
1416 .commit = nv50_crtc_commit,
1417 .mode_fixup = nv50_crtc_mode_fixup,
1418 .mode_set = nv50_crtc_mode_set,
1419 .mode_set_base = nv50_crtc_mode_set_base,
1420 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1421 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001422 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001423};
1424
Ben Skeggse225f442012-11-21 14:40:21 +10001425static const struct drm_crtc_funcs nv50_crtc_func = {
1426 .cursor_set = nv50_crtc_cursor_set,
1427 .cursor_move = nv50_crtc_cursor_move,
1428 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10001429 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10001430 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001431 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001432};
1433
1434static int
Ben Skeggs0ad72862014-08-10 04:10:22 +10001435nv50_crtc_create(struct drm_device *dev, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001436{
Ben Skeggsa01ca782015-08-20 14:54:15 +10001437 struct nouveau_drm *drm = nouveau_drm(dev);
1438 struct nvif_device *device = &drm->device;
Ben Skeggse225f442012-11-21 14:40:21 +10001439 struct nv50_disp *disp = nv50_disp(dev);
1440 struct nv50_head *head;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001441 struct drm_crtc *crtc;
1442 int ret, i;
1443
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001444 head = kzalloc(sizeof(*head), GFP_KERNEL);
1445 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001446 return -ENOMEM;
1447
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001448 head->base.index = index;
Ben Skeggse225f442012-11-21 14:40:21 +10001449 head->base.set_dither = nv50_crtc_set_dither;
1450 head->base.set_scale = nv50_crtc_set_scale;
1451 head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
Ben Skeggsf9887d02012-11-21 13:03:42 +10001452 head->base.color_vibrance = 50;
1453 head->base.vibrant_hue = 0;
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001454 head->base.cursor.set_pos = nv50_crtc_cursor_restore;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001455 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001456 head->base.lut.r[i] = i << 8;
1457 head->base.lut.g[i] = i << 8;
1458 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001459 }
1460
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001461 crtc = &head->base.base;
Ben Skeggse225f442012-11-21 14:40:21 +10001462 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1463 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001464 drm_mode_crtc_set_gamma_size(crtc, 256);
1465
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10001466 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01001467 0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001468 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10001469 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001470 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001471 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001472 if (ret)
1473 nouveau_bo_unpin(head->base.lut.nvbo);
1474 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001475 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001476 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001477 }
1478
1479 if (ret)
1480 goto out;
1481
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001482 /* allocate cursor resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001483 ret = nv50_curs_create(device, disp->disp, index, &head->curs);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001484 if (ret)
1485 goto out;
1486
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001487 /* allocate page flip / sync resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001488 ret = nv50_base_create(device, disp->disp, index, disp->sync->bo.offset,
1489 &head->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001490 if (ret)
1491 goto out;
1492
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001493 head->sync.addr = EVO_FLIP_SEM0(index);
1494 head->sync.data = 0x00000000;
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001495
1496 /* allocate overlay resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001497 ret = nv50_oimm_create(device, disp->disp, index, &head->oimm);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001498 if (ret)
1499 goto out;
1500
Ben Skeggsa01ca782015-08-20 14:54:15 +10001501 ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset,
1502 &head->ovly);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001503 if (ret)
1504 goto out;
1505
Ben Skeggs438d99e2011-07-05 16:48:06 +10001506out:
1507 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10001508 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001509 return ret;
1510}
1511
1512/******************************************************************************
Ben Skeggsa91d3222014-12-22 16:30:13 +10001513 * Encoder helpers
1514 *****************************************************************************/
1515static bool
1516nv50_encoder_mode_fixup(struct drm_encoder *encoder,
1517 const struct drm_display_mode *mode,
1518 struct drm_display_mode *adjusted_mode)
1519{
1520 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1521 struct nouveau_connector *nv_connector;
1522
1523 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1524 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs576f7912014-12-22 17:19:26 +10001525 nv_connector->scaling_full = false;
1526 if (nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) {
1527 switch (nv_connector->type) {
1528 case DCB_CONNECTOR_LVDS:
1529 case DCB_CONNECTOR_LVDS_SPWG:
1530 case DCB_CONNECTOR_eDP:
1531 /* force use of scaler for non-edid modes */
1532 if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
1533 return true;
1534 nv_connector->scaling_full = true;
1535 break;
1536 default:
1537 return true;
1538 }
1539 }
1540
1541 drm_mode_copy(adjusted_mode, nv_connector->native_mode);
Ben Skeggsa91d3222014-12-22 16:30:13 +10001542 }
1543
1544 return true;
1545}
1546
1547/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001548 * DAC
1549 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001550static void
Ben Skeggse225f442012-11-21 14:40:21 +10001551nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001552{
1553 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001554 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001555 struct {
1556 struct nv50_disp_mthd_v1 base;
1557 struct nv50_disp_dac_pwr_v0 pwr;
1558 } args = {
1559 .base.version = 1,
1560 .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
1561 .base.hasht = nv_encoder->dcb->hasht,
1562 .base.hashm = nv_encoder->dcb->hashm,
1563 .pwr.state = 1,
1564 .pwr.data = 1,
1565 .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
1566 mode != DRM_MODE_DPMS_OFF),
1567 .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
1568 mode != DRM_MODE_DPMS_OFF),
1569 };
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001570
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001571 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001572}
1573
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001574static void
Ben Skeggse225f442012-11-21 14:40:21 +10001575nv50_dac_commit(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001576{
1577}
1578
1579static void
Ben Skeggse225f442012-11-21 14:40:21 +10001580nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001581 struct drm_display_mode *adjusted_mode)
1582{
Ben Skeggse225f442012-11-21 14:40:21 +10001583 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001584 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1585 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001586 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001587
Ben Skeggse225f442012-11-21 14:40:21 +10001588 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001589
Ben Skeggs97b19b52012-11-16 11:21:37 +10001590 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001591 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001592 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001593 u32 syncs = 0x00000000;
1594
1595 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1596 syncs |= 0x00000001;
1597 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1598 syncs |= 0x00000002;
1599
1600 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1601 evo_data(push, 1 << nv_crtc->index);
1602 evo_data(push, syncs);
1603 } else {
1604 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1605 u32 syncs = 0x00000001;
1606
1607 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1608 syncs |= 0x00000008;
1609 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1610 syncs |= 0x00000010;
1611
1612 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1613 magic |= 0x00000001;
1614
1615 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1616 evo_data(push, syncs);
1617 evo_data(push, magic);
1618 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1619 evo_data(push, 1 << nv_crtc->index);
1620 }
1621
1622 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001623 }
1624
1625 nv_encoder->crtc = encoder->crtc;
1626}
1627
1628static void
Ben Skeggse225f442012-11-21 14:40:21 +10001629nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001630{
1631 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001632 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001633 const int or = nv_encoder->or;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001634 u32 *push;
1635
1636 if (nv_encoder->crtc) {
Ben Skeggse225f442012-11-21 14:40:21 +10001637 nv50_crtc_prepare(nv_encoder->crtc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001638
Ben Skeggs97b19b52012-11-16 11:21:37 +10001639 push = evo_wait(mast, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001640 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001641 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001642 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1643 evo_data(push, 0x00000000);
1644 } else {
1645 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1646 evo_data(push, 0x00000000);
1647 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001648 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001649 }
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001650 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001651
1652 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001653}
1654
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001655static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10001656nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001657{
Ben Skeggsc4abd312014-08-10 04:10:26 +10001658 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001659 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsc4abd312014-08-10 04:10:26 +10001660 struct {
1661 struct nv50_disp_mthd_v1 base;
1662 struct nv50_disp_dac_load_v0 load;
1663 } args = {
1664 .base.version = 1,
1665 .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
1666 .base.hasht = nv_encoder->dcb->hasht,
1667 .base.hashm = nv_encoder->dcb->hashm,
1668 };
1669 int ret;
Ben Skeggsb6819932011-07-08 11:14:50 +10001670
Ben Skeggsc4abd312014-08-10 04:10:26 +10001671 args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
1672 if (args.load.data == 0)
1673 args.load.data = 340;
1674
1675 ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
1676 if (ret || !args.load.load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10001677 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10001678
Ben Skeggs35b21d32012-11-08 12:08:55 +10001679 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001680}
1681
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001682static void
Ben Skeggse225f442012-11-21 14:40:21 +10001683nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001684{
1685 drm_encoder_cleanup(encoder);
1686 kfree(encoder);
1687}
1688
Ben Skeggse225f442012-11-21 14:40:21 +10001689static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1690 .dpms = nv50_dac_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10001691 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggse225f442012-11-21 14:40:21 +10001692 .prepare = nv50_dac_disconnect,
1693 .commit = nv50_dac_commit,
1694 .mode_set = nv50_dac_mode_set,
1695 .disable = nv50_dac_disconnect,
1696 .get_crtc = nv50_display_crtc_get,
1697 .detect = nv50_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001698};
1699
Ben Skeggse225f442012-11-21 14:40:21 +10001700static const struct drm_encoder_funcs nv50_dac_func = {
1701 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001702};
1703
1704static int
Ben Skeggse225f442012-11-21 14:40:21 +10001705nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001706{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001707 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10001708 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001709 struct nvkm_i2c_bus *bus;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001710 struct nouveau_encoder *nv_encoder;
1711 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001712 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001713
1714 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1715 if (!nv_encoder)
1716 return -ENOMEM;
1717 nv_encoder->dcb = dcbe;
1718 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001719
1720 bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
1721 if (bus)
1722 nv_encoder->i2c = &bus->i2c;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001723
1724 encoder = to_drm_encoder(nv_encoder);
1725 encoder->possible_crtcs = dcbe->heads;
1726 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02001727 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type, NULL);
Ben Skeggse225f442012-11-21 14:40:21 +10001728 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001729
1730 drm_mode_connector_attach_encoder(connector, encoder);
1731 return 0;
1732}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001733
1734/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10001735 * Audio
1736 *****************************************************************************/
1737static void
Ben Skeggse225f442012-11-21 14:40:21 +10001738nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001739{
1740 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001741 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs78951d22011-11-11 18:13:13 +10001742 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001743 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsd889c522014-09-15 21:11:51 +10001744 struct __packed {
1745 struct {
1746 struct nv50_disp_mthd_v1 mthd;
1747 struct nv50_disp_sor_hda_eld_v0 eld;
1748 } base;
Ben Skeggs120b0c32014-08-10 04:10:26 +10001749 u8 data[sizeof(nv_connector->base.eld)];
1750 } args = {
Ben Skeggsd889c522014-09-15 21:11:51 +10001751 .base.mthd.version = 1,
1752 .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1753 .base.mthd.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001754 .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1755 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001756 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001757
1758 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1759 if (!drm_detect_monitor_audio(nv_connector->edid))
1760 return;
1761
Ben Skeggs78951d22011-11-11 18:13:13 +10001762 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001763 memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001764
Jani Nikula938fd8a2014-10-28 16:20:48 +02001765 nvif_mthd(disp->disp, 0, &args,
1766 sizeof(args.base) + drm_eld_size(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001767}
1768
1769static void
Ben Skeggscc2a9072014-09-15 21:29:05 +10001770nv50_audio_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001771{
1772 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001773 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001774 struct {
1775 struct nv50_disp_mthd_v1 base;
1776 struct nv50_disp_sor_hda_eld_v0 eld;
1777 } args = {
1778 .base.version = 1,
1779 .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1780 .base.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001781 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1782 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001783 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001784
Ben Skeggs120b0c32014-08-10 04:10:26 +10001785 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001786}
1787
1788/******************************************************************************
1789 * HDMI
1790 *****************************************************************************/
1791static void
Ben Skeggse225f442012-11-21 14:40:21 +10001792nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001793{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001794 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1795 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001796 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001797 struct {
1798 struct nv50_disp_mthd_v1 base;
1799 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1800 } args = {
1801 .base.version = 1,
1802 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1803 .base.hasht = nv_encoder->dcb->hasht,
1804 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1805 (0x0100 << nv_crtc->index),
1806 .pwr.state = 1,
1807 .pwr.rekey = 56, /* binary driver, and tegra, constant */
1808 };
1809 struct nouveau_connector *nv_connector;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001810 u32 max_ac_packet;
1811
1812 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1813 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1814 return;
1815
1816 max_ac_packet = mode->htotal - mode->hdisplay;
Ben Skeggse00f2232014-08-10 04:10:26 +10001817 max_ac_packet -= args.pwr.rekey;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001818 max_ac_packet -= 18; /* constant from tegra */
Ben Skeggse00f2232014-08-10 04:10:26 +10001819 args.pwr.max_ac_packet = max_ac_packet / 32;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001820
Ben Skeggse00f2232014-08-10 04:10:26 +10001821 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggse225f442012-11-21 14:40:21 +10001822 nv50_audio_mode_set(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10001823}
1824
1825static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001826nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001827{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001828 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001829 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001830 struct {
1831 struct nv50_disp_mthd_v1 base;
1832 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1833 } args = {
1834 .base.version = 1,
1835 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1836 .base.hasht = nv_encoder->dcb->hasht,
1837 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1838 (0x0100 << nv_crtc->index),
1839 };
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001840
Ben Skeggse00f2232014-08-10 04:10:26 +10001841 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001842}
1843
1844/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001845 * SOR
1846 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001847static void
Ben Skeggse225f442012-11-21 14:40:21 +10001848nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001849{
1850 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001851 struct nv50_disp *disp = nv50_disp(encoder->dev);
1852 struct {
1853 struct nv50_disp_mthd_v1 base;
1854 struct nv50_disp_sor_pwr_v0 pwr;
1855 } args = {
1856 .base.version = 1,
1857 .base.method = NV50_DISP_MTHD_V1_SOR_PWR,
1858 .base.hasht = nv_encoder->dcb->hasht,
1859 .base.hashm = nv_encoder->dcb->hashm,
1860 .pwr.state = mode == DRM_MODE_DPMS_ON,
1861 };
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001862 struct {
1863 struct nv50_disp_mthd_v1 base;
1864 struct nv50_disp_sor_dp_pwr_v0 pwr;
1865 } link = {
1866 .base.version = 1,
1867 .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
1868 .base.hasht = nv_encoder->dcb->hasht,
1869 .base.hashm = nv_encoder->dcb->hashm,
1870 .pwr.state = mode == DRM_MODE_DPMS_ON,
1871 };
Ben Skeggs83fc0832011-07-05 13:08:40 +10001872 struct drm_device *dev = encoder->dev;
1873 struct drm_encoder *partner;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001874
1875 nv_encoder->last_dpms = mode;
1876
1877 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1878 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1879
1880 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1881 continue;
1882
1883 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10001884 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10001885 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1886 return;
1887 break;
1888 }
1889 }
1890
Ben Skeggs48743222014-05-31 01:48:06 +10001891 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001892 args.pwr.state = 1;
1893 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001894 nvif_mthd(disp->disp, 0, &link, sizeof(link));
Ben Skeggs48743222014-05-31 01:48:06 +10001895 } else {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001896 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs48743222014-05-31 01:48:06 +10001897 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001898}
1899
Ben Skeggs83fc0832011-07-05 13:08:40 +10001900static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001901nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1902{
1903 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1904 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1905 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001906 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10001907 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1908 evo_data(push, (nv_encoder->ctrl = temp));
1909 } else {
1910 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1911 evo_data(push, (nv_encoder->ctrl = temp));
1912 }
1913 evo_kick(push, mast);
1914 }
1915}
1916
1917static void
Ben Skeggse225f442012-11-21 14:40:21 +10001918nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001919{
1920 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001921 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001922
1923 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1924 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001925
1926 if (nv_crtc) {
1927 nv50_crtc_prepare(&nv_crtc->base);
1928 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001929 nv50_audio_disconnect(encoder, nv_crtc);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001930 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1931 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001932}
1933
1934static void
Ben Skeggse225f442012-11-21 14:40:21 +10001935nv50_sor_commit(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001936{
1937}
1938
1939static void
Ben Skeggse225f442012-11-21 14:40:21 +10001940nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001941 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001942{
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001943 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1944 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1945 struct {
1946 struct nv50_disp_mthd_v1 base;
1947 struct nv50_disp_sor_lvds_script_v0 lvds;
1948 } lvds = {
1949 .base.version = 1,
1950 .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
1951 .base.hasht = nv_encoder->dcb->hasht,
1952 .base.hashm = nv_encoder->dcb->hashm,
1953 };
Ben Skeggse225f442012-11-21 14:40:21 +10001954 struct nv50_disp *disp = nv50_disp(encoder->dev);
1955 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001956 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10001957 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001958 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10001959 struct nvbios *bios = &drm->vbios;
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001960 u32 mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001961 u8 owner = 1 << nv_crtc->index;
1962 u8 proto = 0xf;
1963 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001964
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001965 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001966 nv_encoder->crtc = encoder->crtc;
1967
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001968 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10001969 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001970 if (nv_encoder->dcb->sorconf.link & 1) {
Hauke Mehrtens16ef53a92015-11-03 21:00:10 -05001971 proto = 0x1;
1972 /* Only enable dual-link if:
1973 * - Need to (i.e. rate > 165MHz)
1974 * - DCB says we can
1975 * - Not an HDMI monitor, since there's no dual-link
1976 * on HDMI.
1977 */
1978 if (mode->clock >= 165000 &&
1979 nv_encoder->dcb->duallink_possible &&
1980 !drm_detect_hdmi_monitor(nv_connector->edid))
1981 proto |= 0x4;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001982 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001983 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001984 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001985
Ben Skeggse84a35a2014-06-05 10:59:55 +10001986 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001987 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001988 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001989 proto = 0x0;
1990
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001991 if (bios->fp_no_ddc) {
1992 if (bios->fp.dual_link)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001993 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001994 if (bios->fp.if_is_24bit)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001995 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001996 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10001997 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001998 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001999 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002000 } else
2001 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002002 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002003 }
2004
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002005 if (lvds.lvds.script & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002006 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002007 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002008 } else {
2009 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002010 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002011 }
2012
2013 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002014 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002015 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10002016
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002017 nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds));
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002018 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10002019 case DCB_OUTPUT_DP:
Ben Skeggs3488c572012-03-12 11:42:20 +10002020 if (nv_connector->base.display_info.bpc == 6) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002021 nv_encoder->dp.datarate = mode->clock * 18 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002022 depth = 0x2;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002023 } else
2024 if (nv_connector->base.display_info.bpc == 8) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002025 nv_encoder->dp.datarate = mode->clock * 24 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002026 depth = 0x5;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002027 } else {
2028 nv_encoder->dp.datarate = mode->clock * 30 / 8;
2029 depth = 0x6;
Ben Skeggs3488c572012-03-12 11:42:20 +10002030 }
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002031
2032 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002033 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002034 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002035 proto = 0x9;
Ben Skeggs3eee8642014-09-15 15:20:47 +10002036 nv50_audio_mode_set(encoder, mode);
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002037 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002038 default:
2039 BUG_ON(1);
2040 break;
2041 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10002042
Ben Skeggse84a35a2014-06-05 10:59:55 +10002043 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002044
Ben Skeggs648d4df2014-08-10 04:10:27 +10002045 if (nv50_vers(mast) >= GF110_DISP) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10002046 u32 *push = evo_wait(mast, 3);
2047 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002048 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
2049 u32 syncs = 0x00000001;
2050
2051 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2052 syncs |= 0x00000008;
2053 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2054 syncs |= 0x00000010;
2055
2056 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2057 magic |= 0x00000001;
2058
2059 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
2060 evo_data(push, syncs | (depth << 6));
2061 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10002062 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002063 }
2064
Ben Skeggse84a35a2014-06-05 10:59:55 +10002065 ctrl = proto << 8;
2066 mask = 0x00000f00;
2067 } else {
2068 ctrl = (depth << 16) | (proto << 8);
2069 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2070 ctrl |= 0x00001000;
2071 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2072 ctrl |= 0x00002000;
2073 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002074 }
2075
Ben Skeggse84a35a2014-06-05 10:59:55 +10002076 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002077}
2078
2079static void
Ben Skeggse225f442012-11-21 14:40:21 +10002080nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002081{
2082 drm_encoder_cleanup(encoder);
2083 kfree(encoder);
2084}
2085
Ben Skeggse225f442012-11-21 14:40:21 +10002086static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
2087 .dpms = nv50_sor_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10002088 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggs5a885f02013-02-20 14:34:18 +10002089 .prepare = nv50_sor_disconnect,
Ben Skeggse225f442012-11-21 14:40:21 +10002090 .commit = nv50_sor_commit,
2091 .mode_set = nv50_sor_mode_set,
2092 .disable = nv50_sor_disconnect,
2093 .get_crtc = nv50_display_crtc_get,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002094};
2095
Ben Skeggse225f442012-11-21 14:40:21 +10002096static const struct drm_encoder_funcs nv50_sor_func = {
2097 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002098};
2099
2100static int
Ben Skeggse225f442012-11-21 14:40:21 +10002101nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002102{
Ben Skeggs5ed50202013-02-11 20:15:03 +10002103 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002104 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002105 struct nouveau_encoder *nv_encoder;
2106 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10002107 int type;
2108
2109 switch (dcbe->type) {
2110 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
2111 case DCB_OUTPUT_TMDS:
2112 case DCB_OUTPUT_DP:
2113 default:
2114 type = DRM_MODE_ENCODER_TMDS;
2115 break;
2116 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10002117
2118 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2119 if (!nv_encoder)
2120 return -ENOMEM;
2121 nv_encoder->dcb = dcbe;
2122 nv_encoder->or = ffs(dcbe->or) - 1;
2123 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
2124
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002125 if (dcbe->type == DCB_OUTPUT_DP) {
2126 struct nvkm_i2c_aux *aux =
2127 nvkm_i2c_aux_find(i2c, dcbe->i2c_index);
2128 if (aux) {
2129 nv_encoder->i2c = &aux->i2c;
2130 nv_encoder->aux = aux;
2131 }
2132 } else {
2133 struct nvkm_i2c_bus *bus =
2134 nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
2135 if (bus)
2136 nv_encoder->i2c = &bus->i2c;
2137 }
2138
Ben Skeggs83fc0832011-07-05 13:08:40 +10002139 encoder = to_drm_encoder(nv_encoder);
2140 encoder->possible_crtcs = dcbe->heads;
2141 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002142 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type, NULL);
Ben Skeggse225f442012-11-21 14:40:21 +10002143 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002144
2145 drm_mode_connector_attach_encoder(connector, encoder);
2146 return 0;
2147}
Ben Skeggs26f6d882011-07-04 16:25:18 +10002148
2149/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10002150 * PIOR
2151 *****************************************************************************/
2152
2153static void
2154nv50_pior_dpms(struct drm_encoder *encoder, int mode)
2155{
2156 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2157 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs67cb49c2014-08-10 04:10:27 +10002158 struct {
2159 struct nv50_disp_mthd_v1 base;
2160 struct nv50_disp_pior_pwr_v0 pwr;
2161 } args = {
2162 .base.version = 1,
2163 .base.method = NV50_DISP_MTHD_V1_PIOR_PWR,
2164 .base.hasht = nv_encoder->dcb->hasht,
2165 .base.hashm = nv_encoder->dcb->hashm,
2166 .pwr.state = mode == DRM_MODE_DPMS_ON,
2167 .pwr.type = nv_encoder->dcb->type,
2168 };
2169
2170 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggseb6313a2013-02-11 09:52:58 +10002171}
2172
2173static bool
2174nv50_pior_mode_fixup(struct drm_encoder *encoder,
2175 const struct drm_display_mode *mode,
2176 struct drm_display_mode *adjusted_mode)
2177{
Ben Skeggsa91d3222014-12-22 16:30:13 +10002178 if (!nv50_encoder_mode_fixup(encoder, mode, adjusted_mode))
2179 return false;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002180 adjusted_mode->clock *= 2;
2181 return true;
2182}
2183
2184static void
2185nv50_pior_commit(struct drm_encoder *encoder)
2186{
2187}
2188
2189static void
2190nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
2191 struct drm_display_mode *adjusted_mode)
2192{
2193 struct nv50_mast *mast = nv50_mast(encoder->dev);
2194 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2195 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
2196 struct nouveau_connector *nv_connector;
2197 u8 owner = 1 << nv_crtc->index;
2198 u8 proto, depth;
2199 u32 *push;
2200
2201 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2202 switch (nv_connector->base.display_info.bpc) {
2203 case 10: depth = 0x6; break;
2204 case 8: depth = 0x5; break;
2205 case 6: depth = 0x2; break;
2206 default: depth = 0x0; break;
2207 }
2208
2209 switch (nv_encoder->dcb->type) {
2210 case DCB_OUTPUT_TMDS:
2211 case DCB_OUTPUT_DP:
2212 proto = 0x0;
2213 break;
2214 default:
2215 BUG_ON(1);
2216 break;
2217 }
2218
2219 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
2220
2221 push = evo_wait(mast, 8);
2222 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002223 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002224 u32 ctrl = (depth << 16) | (proto << 8) | owner;
2225 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2226 ctrl |= 0x00001000;
2227 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2228 ctrl |= 0x00002000;
2229 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
2230 evo_data(push, ctrl);
2231 }
2232
2233 evo_kick(push, mast);
2234 }
2235
2236 nv_encoder->crtc = encoder->crtc;
2237}
2238
2239static void
2240nv50_pior_disconnect(struct drm_encoder *encoder)
2241{
2242 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2243 struct nv50_mast *mast = nv50_mast(encoder->dev);
2244 const int or = nv_encoder->or;
2245 u32 *push;
2246
2247 if (nv_encoder->crtc) {
2248 nv50_crtc_prepare(nv_encoder->crtc);
2249
2250 push = evo_wait(mast, 4);
2251 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002252 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002253 evo_mthd(push, 0x0700 + (or * 0x040), 1);
2254 evo_data(push, 0x00000000);
2255 }
Ben Skeggseb6313a2013-02-11 09:52:58 +10002256 evo_kick(push, mast);
2257 }
2258 }
2259
2260 nv_encoder->crtc = NULL;
2261}
2262
2263static void
2264nv50_pior_destroy(struct drm_encoder *encoder)
2265{
2266 drm_encoder_cleanup(encoder);
2267 kfree(encoder);
2268}
2269
2270static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
2271 .dpms = nv50_pior_dpms,
2272 .mode_fixup = nv50_pior_mode_fixup,
2273 .prepare = nv50_pior_disconnect,
2274 .commit = nv50_pior_commit,
2275 .mode_set = nv50_pior_mode_set,
2276 .disable = nv50_pior_disconnect,
2277 .get_crtc = nv50_display_crtc_get,
2278};
2279
2280static const struct drm_encoder_funcs nv50_pior_func = {
2281 .destroy = nv50_pior_destroy,
2282};
2283
2284static int
2285nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2286{
2287 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002288 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002289 struct nvkm_i2c_bus *bus = NULL;
2290 struct nvkm_i2c_aux *aux = NULL;
2291 struct i2c_adapter *ddc;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002292 struct nouveau_encoder *nv_encoder;
2293 struct drm_encoder *encoder;
2294 int type;
2295
2296 switch (dcbe->type) {
2297 case DCB_OUTPUT_TMDS:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002298 bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev));
2299 ddc = bus ? &bus->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002300 type = DRM_MODE_ENCODER_TMDS;
2301 break;
2302 case DCB_OUTPUT_DP:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002303 aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev));
2304 ddc = aux ? &aux->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002305 type = DRM_MODE_ENCODER_TMDS;
2306 break;
2307 default:
2308 return -ENODEV;
2309 }
2310
2311 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2312 if (!nv_encoder)
2313 return -ENOMEM;
2314 nv_encoder->dcb = dcbe;
2315 nv_encoder->or = ffs(dcbe->or) - 1;
2316 nv_encoder->i2c = ddc;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002317 nv_encoder->aux = aux;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002318
2319 encoder = to_drm_encoder(nv_encoder);
2320 encoder->possible_crtcs = dcbe->heads;
2321 encoder->possible_clones = 0;
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002322 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type, NULL);
Ben Skeggseb6313a2013-02-11 09:52:58 +10002323 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2324
2325 drm_mode_connector_attach_encoder(connector, encoder);
2326 return 0;
2327}
2328
2329/******************************************************************************
Ben Skeggsab0af552014-08-10 04:10:19 +10002330 * Framebuffer
2331 *****************************************************************************/
2332
Ben Skeggs8a423642014-08-10 04:10:19 +10002333static void
Ben Skeggs0ad72862014-08-10 04:10:22 +10002334nv50_fbdma_fini(struct nv50_fbdma *fbdma)
Ben Skeggs8a423642014-08-10 04:10:19 +10002335{
Ben Skeggs0ad72862014-08-10 04:10:22 +10002336 int i;
2337 for (i = 0; i < ARRAY_SIZE(fbdma->base); i++)
2338 nvif_object_fini(&fbdma->base[i]);
2339 nvif_object_fini(&fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002340 list_del(&fbdma->head);
2341 kfree(fbdma);
2342}
2343
2344static int
2345nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind)
2346{
2347 struct nouveau_drm *drm = nouveau_drm(dev);
2348 struct nv50_disp *disp = nv50_disp(dev);
2349 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggs4acfd702014-08-10 04:10:24 +10002350 struct __attribute__ ((packed)) {
2351 struct nv_dma_v0 base;
2352 union {
2353 struct nv50_dma_v0 nv50;
2354 struct gf100_dma_v0 gf100;
Ben Skeggsbd70563f2015-08-20 14:54:21 +10002355 struct gf119_dma_v0 gf119;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002356 };
2357 } args = {};
Ben Skeggs8a423642014-08-10 04:10:19 +10002358 struct nv50_fbdma *fbdma;
2359 struct drm_crtc *crtc;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002360 u32 size = sizeof(args.base);
Ben Skeggs8a423642014-08-10 04:10:19 +10002361 int ret;
2362
2363 list_for_each_entry(fbdma, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002364 if (fbdma->core.handle == name)
Ben Skeggs8a423642014-08-10 04:10:19 +10002365 return 0;
2366 }
2367
2368 fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL);
2369 if (!fbdma)
2370 return -ENOMEM;
2371 list_add(&fbdma->head, &disp->fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002372
Ben Skeggs4acfd702014-08-10 04:10:24 +10002373 args.base.target = NV_DMA_V0_TARGET_VRAM;
2374 args.base.access = NV_DMA_V0_ACCESS_RDWR;
2375 args.base.start = offset;
2376 args.base.limit = offset + length - 1;
Ben Skeggs8a423642014-08-10 04:10:19 +10002377
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002378 if (drm->device.info.chipset < 0x80) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002379 args.nv50.part = NV50_DMA_V0_PART_256;
2380 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002381 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002382 if (drm->device.info.chipset < 0xc0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002383 args.nv50.part = NV50_DMA_V0_PART_256;
2384 args.nv50.kind = kind;
2385 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002386 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002387 if (drm->device.info.chipset < 0xd0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002388 args.gf100.kind = kind;
2389 size += sizeof(args.gf100);
Ben Skeggs8a423642014-08-10 04:10:19 +10002390 } else {
Ben Skeggsbd70563f2015-08-20 14:54:21 +10002391 args.gf119.page = GF119_DMA_V0_PAGE_LP;
2392 args.gf119.kind = kind;
2393 size += sizeof(args.gf119);
Ben Skeggs8a423642014-08-10 04:10:19 +10002394 }
2395
2396 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002397 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsa01ca782015-08-20 14:54:15 +10002398 int ret = nvif_object_init(&head->sync.base.base.user, name,
2399 NV_DMA_IN_MEMORY, &args, size,
Ben Skeggs0ad72862014-08-10 04:10:22 +10002400 &fbdma->base[head->base.index]);
Ben Skeggs8a423642014-08-10 04:10:19 +10002401 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002402 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002403 return ret;
2404 }
2405 }
2406
Ben Skeggsa01ca782015-08-20 14:54:15 +10002407 ret = nvif_object_init(&mast->base.base.user, name, NV_DMA_IN_MEMORY,
2408 &args, size, &fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002409 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002410 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002411 return ret;
2412 }
2413
2414 return 0;
2415}
2416
Ben Skeggsab0af552014-08-10 04:10:19 +10002417static void
2418nv50_fb_dtor(struct drm_framebuffer *fb)
2419{
2420}
2421
2422static int
2423nv50_fb_ctor(struct drm_framebuffer *fb)
2424{
2425 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
2426 struct nouveau_drm *drm = nouveau_drm(fb->dev);
2427 struct nouveau_bo *nvbo = nv_fb->nvbo;
Ben Skeggs8a423642014-08-10 04:10:19 +10002428 struct nv50_disp *disp = nv50_disp(fb->dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002429 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
2430 u8 tile = nvbo->tile_mode;
Ben Skeggsab0af552014-08-10 04:10:19 +10002431
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002432 if (drm->device.info.chipset >= 0xc0)
Ben Skeggs8a423642014-08-10 04:10:19 +10002433 tile >>= 4; /* yep.. */
2434
Ben Skeggsab0af552014-08-10 04:10:19 +10002435 switch (fb->depth) {
2436 case 8: nv_fb->r_format = 0x1e00; break;
2437 case 15: nv_fb->r_format = 0xe900; break;
2438 case 16: nv_fb->r_format = 0xe800; break;
2439 case 24:
2440 case 32: nv_fb->r_format = 0xcf00; break;
2441 case 30: nv_fb->r_format = 0xd100; break;
2442 default:
2443 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
2444 return -EINVAL;
2445 }
2446
Ben Skeggs648d4df2014-08-10 04:10:27 +10002447 if (disp->disp->oclass < G82_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002448 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2449 (fb->pitches[0] | 0x00100000);
2450 nv_fb->r_format |= kind << 16;
2451 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10002452 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002453 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2454 (fb->pitches[0] | 0x00100000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002455 } else {
Ben Skeggs8a423642014-08-10 04:10:19 +10002456 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2457 (fb->pitches[0] | 0x01000000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002458 }
Ben Skeggs8a423642014-08-10 04:10:19 +10002459 nv_fb->r_handle = 0xffff0000 | kind;
Ben Skeggsab0af552014-08-10 04:10:19 +10002460
Ben Skeggsf392ec42014-08-10 04:10:28 +10002461 return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0,
2462 drm->device.info.ram_user, kind);
Ben Skeggsab0af552014-08-10 04:10:19 +10002463}
2464
2465/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002466 * Init
2467 *****************************************************************************/
Ben Skeggsab0af552014-08-10 04:10:19 +10002468
Ben Skeggs2a44e492011-11-09 11:36:33 +10002469void
Ben Skeggse225f442012-11-21 14:40:21 +10002470nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002471{
Ben Skeggs26f6d882011-07-04 16:25:18 +10002472}
2473
2474int
Ben Skeggse225f442012-11-21 14:40:21 +10002475nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002476{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002477 struct nv50_disp *disp = nv50_disp(dev);
2478 struct drm_crtc *crtc;
2479 u32 *push;
2480
2481 push = evo_wait(nv50_mast(dev), 32);
2482 if (!push)
2483 return -EBUSY;
2484
2485 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2486 struct nv50_sync *sync = nv50_sync(crtc);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002487
2488 nv50_crtc_lut_load(crtc);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002489 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002490 }
2491
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002492 evo_mthd(push, 0x0088, 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10002493 evo_data(push, nv50_mast(dev)->base.sync.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002494 evo_kick(push, nv50_mast(dev));
2495 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002496}
2497
2498void
Ben Skeggse225f442012-11-21 14:40:21 +10002499nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002500{
Ben Skeggse225f442012-11-21 14:40:21 +10002501 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002502 struct nv50_fbdma *fbdma, *fbtmp;
2503
2504 list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002505 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002506 }
Ben Skeggs26f6d882011-07-04 16:25:18 +10002507
Ben Skeggs0ad72862014-08-10 04:10:22 +10002508 nv50_dmac_destroy(&disp->mast.base, disp->disp);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10002509
Ben Skeggs816af2f2011-11-16 15:48:48 +10002510 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002511 if (disp->sync)
2512 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10002513 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10002514
Ben Skeggs77145f12012-07-31 16:16:21 +10002515 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002516 kfree(disp);
2517}
2518
2519int
Ben Skeggse225f442012-11-21 14:40:21 +10002520nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002521{
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002522 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggs77145f12012-07-31 16:16:21 +10002523 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10002524 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002525 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10002526 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10002527 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002528 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002529
2530 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2531 if (!disp)
2532 return -ENOMEM;
Ben Skeggs8a423642014-08-10 04:10:19 +10002533 INIT_LIST_HEAD(&disp->fbdma);
Ben Skeggs77145f12012-07-31 16:16:21 +10002534
2535 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10002536 nouveau_display(dev)->dtor = nv50_display_destroy;
2537 nouveau_display(dev)->init = nv50_display_init;
2538 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggsab0af552014-08-10 04:10:19 +10002539 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
2540 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
Ben Skeggs0ad72862014-08-10 04:10:22 +10002541 disp->disp = &nouveau_display(dev)->disp;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002542
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002543 /* small shared memory area we use for notifiers and semaphores */
2544 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01002545 0, 0x0000, NULL, NULL, &disp->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002546 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10002547 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002548 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002549 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002550 if (ret)
2551 nouveau_bo_unpin(disp->sync);
2552 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002553 if (ret)
2554 nouveau_bo_ref(NULL, &disp->sync);
2555 }
2556
2557 if (ret)
2558 goto out;
2559
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002560 /* allocate master evo channel */
Ben Skeggsa01ca782015-08-20 14:54:15 +10002561 ret = nv50_core_create(device, disp->disp, disp->sync->bo.offset,
Ben Skeggs410f3ec2014-08-10 04:10:25 +10002562 &disp->mast);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002563 if (ret)
2564 goto out;
2565
Ben Skeggs438d99e2011-07-05 16:48:06 +10002566 /* create crtc objects to represent the hw heads */
Ben Skeggs648d4df2014-08-10 04:10:27 +10002567 if (disp->disp->oclass >= GF110_DISP)
Ben Skeggsa01ca782015-08-20 14:54:15 +10002568 crtcs = nvif_rd32(&device->object, 0x022448);
Ben Skeggs63718a02012-11-16 11:44:14 +10002569 else
2570 crtcs = 2;
2571
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002572 for (i = 0; i < crtcs; i++) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002573 ret = nv50_crtc_create(dev, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002574 if (ret)
2575 goto out;
2576 }
2577
Ben Skeggs83fc0832011-07-05 13:08:40 +10002578 /* create encoder/connector objects based on VBIOS DCB table */
2579 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2580 connector = nouveau_connector_create(dev, dcbe->connector);
2581 if (IS_ERR(connector))
2582 continue;
2583
Ben Skeggseb6313a2013-02-11 09:52:58 +10002584 if (dcbe->location == DCB_LOC_ON_CHIP) {
2585 switch (dcbe->type) {
2586 case DCB_OUTPUT_TMDS:
2587 case DCB_OUTPUT_LVDS:
2588 case DCB_OUTPUT_DP:
2589 ret = nv50_sor_create(connector, dcbe);
2590 break;
2591 case DCB_OUTPUT_ANALOG:
2592 ret = nv50_dac_create(connector, dcbe);
2593 break;
2594 default:
2595 ret = -ENODEV;
2596 break;
2597 }
2598 } else {
2599 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002600 }
2601
Ben Skeggseb6313a2013-02-11 09:52:58 +10002602 if (ret) {
2603 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2604 dcbe->location, dcbe->type,
2605 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10002606 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002607 }
2608 }
2609
2610 /* cull any connectors we created that don't have an encoder */
2611 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2612 if (connector->encoder_ids[0])
2613 continue;
2614
Ben Skeggs77145f12012-07-31 16:16:21 +10002615 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03002616 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002617 connector->funcs->destroy(connector);
2618 }
2619
Ben Skeggs26f6d882011-07-04 16:25:18 +10002620out:
2621 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002622 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002623 return ret;
2624}