blob: a771e9067ebfb503e4180a600f85e4b395c4e6ef [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright (C) 2008 Maarten Maathuis.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27#include "drmP.h"
28#include "drm_mode.h"
29#include "drm_crtc_helper.h"
30
Ben Skeggs6ee73862009-12-11 19:24:15 +100031#include "nouveau_reg.h"
Ben Skeggs77145f12012-07-31 16:16:21 +100032#include "nouveau_drm.h"
33#include "nouveau_dma.h"
34#include "nouveau_gem.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100035#include "nouveau_hw.h"
36#include "nouveau_encoder.h"
37#include "nouveau_crtc.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100038#include "nouveau_connector.h"
39#include "nv50_display.h"
40
Ben Skeggs77145f12012-07-31 16:16:21 +100041#include <subdev/clock.h>
42
Ben Skeggs6ee73862009-12-11 19:24:15 +100043static void
44nv50_crtc_lut_load(struct drm_crtc *crtc)
45{
Ben Skeggs77145f12012-07-31 16:16:21 +100046 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +100047 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
48 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
49 int i;
50
Ben Skeggs77145f12012-07-31 16:16:21 +100051 NV_DEBUG(drm, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +100052
53 for (i = 0; i < 256; i++) {
54 writew(nv_crtc->lut.r[i] >> 2, lut + 8*i + 0);
55 writew(nv_crtc->lut.g[i] >> 2, lut + 8*i + 2);
56 writew(nv_crtc->lut.b[i] >> 2, lut + 8*i + 4);
57 }
58
59 if (nv_crtc->lut.depth == 30) {
60 writew(nv_crtc->lut.r[i - 1] >> 2, lut + 8*i + 0);
61 writew(nv_crtc->lut.g[i - 1] >> 2, lut + 8*i + 2);
62 writew(nv_crtc->lut.b[i - 1] >> 2, lut + 8*i + 4);
63 }
64}
65
66int
67nv50_crtc_blank(struct nouveau_crtc *nv_crtc, bool blanked)
68{
69 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggs77145f12012-07-31 16:16:21 +100070 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs59c0f572011-02-01 10:24:41 +100071 struct nouveau_channel *evo = nv50_display(dev)->master;
Ben Skeggs6ee73862009-12-11 19:24:15 +100072 int index = nv_crtc->index, ret;
73
Ben Skeggs77145f12012-07-31 16:16:21 +100074 NV_DEBUG(drm, "index %d\n", nv_crtc->index);
75 NV_DEBUG(drm, "%s\n", blanked ? "blanked" : "unblanked");
Ben Skeggs6ee73862009-12-11 19:24:15 +100076
77 if (blanked) {
78 nv_crtc->cursor.hide(nv_crtc, false);
79
Ben Skeggs77145f12012-07-31 16:16:21 +100080 ret = RING_SPACE(evo, nv_device(drm->device)->chipset != 0x50 ? 7 : 5);
Ben Skeggs6ee73862009-12-11 19:24:15 +100081 if (ret) {
Ben Skeggs77145f12012-07-31 16:16:21 +100082 NV_ERROR(drm, "no space while blanking crtc\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +100083 return ret;
84 }
Ben Skeggs6d597022012-04-01 21:09:13 +100085 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(index, CLUT_MODE), 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +100086 OUT_RING(evo, NV50_EVO_CRTC_CLUT_MODE_BLANK);
87 OUT_RING(evo, 0);
Ben Skeggs77145f12012-07-31 16:16:21 +100088 if (nv_device(drm->device)->chipset != 0x50) {
Ben Skeggs6d597022012-04-01 21:09:13 +100089 BEGIN_NV04(evo, 0, NV84_EVO_CRTC(index, CLUT_DMA), 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +100090 OUT_RING(evo, NV84_EVO_CRTC_CLUT_DMA_HANDLE_NONE);
91 }
92
Ben Skeggs6d597022012-04-01 21:09:13 +100093 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(index, FB_DMA), 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +100094 OUT_RING(evo, NV50_EVO_CRTC_FB_DMA_HANDLE_NONE);
95 } else {
96 if (nv_crtc->cursor.visible)
97 nv_crtc->cursor.show(nv_crtc, false);
98 else
99 nv_crtc->cursor.hide(nv_crtc, false);
100
Ben Skeggs77145f12012-07-31 16:16:21 +1000101 ret = RING_SPACE(evo, nv_device(drm->device)->chipset != 0x50 ? 10 : 8);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000102 if (ret) {
Ben Skeggs77145f12012-07-31 16:16:21 +1000103 NV_ERROR(drm, "no space while unblanking crtc\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000104 return ret;
105 }
Ben Skeggs6d597022012-04-01 21:09:13 +1000106 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(index, CLUT_MODE), 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000107 OUT_RING(evo, nv_crtc->lut.depth == 8 ?
108 NV50_EVO_CRTC_CLUT_MODE_OFF :
109 NV50_EVO_CRTC_CLUT_MODE_ON);
Ben Skeggs180cc302011-06-07 11:24:14 +1000110 OUT_RING(evo, nv_crtc->lut.nvbo->bo.offset >> 8);
Ben Skeggs77145f12012-07-31 16:16:21 +1000111 if (nv_device(drm->device)->chipset != 0x50) {
Ben Skeggs6d597022012-04-01 21:09:13 +1000112 BEGIN_NV04(evo, 0, NV84_EVO_CRTC(index, CLUT_DMA), 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000113 OUT_RING(evo, NvEvoVRAM);
114 }
115
Ben Skeggs6d597022012-04-01 21:09:13 +1000116 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(index, FB_OFFSET), 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000117 OUT_RING(evo, nv_crtc->fb.offset >> 8);
118 OUT_RING(evo, 0);
Ben Skeggs6d597022012-04-01 21:09:13 +1000119 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(index, FB_DMA), 1);
Ben Skeggs77145f12012-07-31 16:16:21 +1000120 if (nv_device(drm->device)->chipset != 0x50)
Ben Skeggs6d869512010-12-08 11:19:30 +1000121 if (nv_crtc->fb.tile_flags == 0x7a00 ||
122 nv_crtc->fb.tile_flags == 0xfe00)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000123 OUT_RING(evo, NvEvoFB32);
124 else
125 if (nv_crtc->fb.tile_flags == 0x7000)
126 OUT_RING(evo, NvEvoFB16);
127 else
Ben Skeggs6d869512010-12-08 11:19:30 +1000128 OUT_RING(evo, NvEvoVRAM_LP);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000129 else
Ben Skeggs6d869512010-12-08 11:19:30 +1000130 OUT_RING(evo, NvEvoVRAM_LP);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000131 }
132
133 nv_crtc->fb.blanked = blanked;
134 return 0;
135}
136
137static int
Ben Skeggs488ff202011-10-17 10:38:10 +1000138nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000139{
Ben Skeggsde691852011-10-17 12:23:41 +1000140 struct nouveau_channel *evo = nv50_display(nv_crtc->base.dev)->master;
141 struct nouveau_connector *nv_connector;
142 struct drm_connector *connector;
143 int head = nv_crtc->index, ret;
144 u32 mode = 0x00;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000145
Ben Skeggsde691852011-10-17 12:23:41 +1000146 nv_connector = nouveau_crtc_connector_get(nv_crtc);
147 connector = &nv_connector->base;
148 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
149 if (nv_crtc->base.fb->depth > connector->display_info.bpc * 3)
150 mode = DITHERING_MODE_DYNAMIC2X2;
151 } else {
152 mode = nv_connector->dithering_mode;
153 }
154
155 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
156 if (connector->display_info.bpc >= 8)
157 mode |= DITHERING_DEPTH_8BPC;
158 } else {
159 mode |= nv_connector->dithering_depth;
160 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000161
162 ret = RING_SPACE(evo, 2 + (update ? 2 : 0));
Ben Skeggsde691852011-10-17 12:23:41 +1000163 if (ret == 0) {
Ben Skeggs6d597022012-04-01 21:09:13 +1000164 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(head, DITHER_CTRL), 1);
Ben Skeggsde691852011-10-17 12:23:41 +1000165 OUT_RING (evo, mode);
166 if (update) {
Ben Skeggs6d597022012-04-01 21:09:13 +1000167 BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
Ben Skeggsde691852011-10-17 12:23:41 +1000168 OUT_RING (evo, 0);
169 FIRE_RING (evo);
170 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000171 }
172
Ben Skeggsde691852011-10-17 12:23:41 +1000173 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000174}
175
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100176static int
177nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
178{
179 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000180 struct nouveau_drm *drm = nouveau_drm(dev);
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100181 struct nouveau_channel *evo = nv50_display(dev)->master;
182 int ret;
183 int adj;
184 u32 hue, vib;
185
Ben Skeggs77145f12012-07-31 16:16:21 +1000186 NV_DEBUG(drm, "vibrance = %i, hue = %i\n",
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100187 nv_crtc->color_vibrance, nv_crtc->vibrant_hue);
188
189 ret = RING_SPACE(evo, 2 + (update ? 2 : 0));
190 if (ret) {
Ben Skeggs77145f12012-07-31 16:16:21 +1000191 NV_ERROR(drm, "no space while setting color vibrance\n");
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100192 return ret;
193 }
194
195 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
196 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
197
198 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
199
Ben Skeggs6d597022012-04-01 21:09:13 +1000200 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, COLOR_CTRL), 1);
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100201 OUT_RING (evo, (hue << 20) | (vib << 8));
202
203 if (update) {
Ben Skeggs6d597022012-04-01 21:09:13 +1000204 BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100205 OUT_RING (evo, 0);
206 FIRE_RING (evo);
207 }
208
209 return 0;
210}
211
Ben Skeggs6ee73862009-12-11 19:24:15 +1000212struct nouveau_connector *
213nouveau_crtc_connector_get(struct nouveau_crtc *nv_crtc)
214{
215 struct drm_device *dev = nv_crtc->base.dev;
216 struct drm_connector *connector;
217 struct drm_crtc *crtc = to_drm_crtc(nv_crtc);
218
219 /* The safest approach is to find an encoder with the right crtc, that
220 * is also linked to a connector. */
221 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
222 if (connector->encoder)
223 if (connector->encoder->crtc == crtc)
224 return nouveau_connector(connector);
225 }
226
227 return NULL;
228}
229
230static int
Ben Skeggs488ff202011-10-17 10:38:10 +1000231nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000232{
Ben Skeggsb29caa52011-10-06 13:29:05 +1000233 struct nouveau_connector *nv_connector;
Ben Skeggs549cd872011-10-06 11:51:45 +1000234 struct drm_crtc *crtc = &nv_crtc->base;
235 struct drm_device *dev = crtc->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000236 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs59c0f572011-02-01 10:24:41 +1000237 struct nouveau_channel *evo = nv50_display(dev)->master;
Ben Skeggs1cb94692011-10-25 16:29:13 +1000238 struct drm_display_mode *umode = &crtc->mode;
239 struct drm_display_mode *omode;
Ben Skeggs488ff202011-10-17 10:38:10 +1000240 int scaling_mode, ret;
Ben Skeggsb29caa52011-10-06 13:29:05 +1000241 u32 ctrl = 0, oX, oY;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000242
Ben Skeggs77145f12012-07-31 16:16:21 +1000243 NV_DEBUG(drm, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000244
Ben Skeggsb29caa52011-10-06 13:29:05 +1000245 nv_connector = nouveau_crtc_connector_get(nv_crtc);
246 if (!nv_connector || !nv_connector->native_mode) {
Ben Skeggs77145f12012-07-31 16:16:21 +1000247 NV_ERROR(drm, "no native mode, forcing panel scaling\n");
Ben Skeggsb29caa52011-10-06 13:29:05 +1000248 scaling_mode = DRM_MODE_SCALE_NONE;
Ben Skeggs488ff202011-10-17 10:38:10 +1000249 } else {
250 scaling_mode = nv_connector->scaling_mode;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000251 }
252
Ben Skeggsb29caa52011-10-06 13:29:05 +1000253 /* start off at the resolution we programmed the crtc for, this
254 * effectively handles NONE/FULL scaling
255 */
Ben Skeggs1cb94692011-10-25 16:29:13 +1000256 if (scaling_mode != DRM_MODE_SCALE_NONE)
257 omode = nv_connector->native_mode;
258 else
259 omode = umode;
260
261 oX = omode->hdisplay;
262 oY = omode->vdisplay;
263 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
264 oY *= 2;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000265
Ben Skeggsb29caa52011-10-06 13:29:05 +1000266 /* add overscan compensation if necessary, will keep the aspect
267 * ratio the same as the backend mode unless overridden by the
268 * user setting both hborder and vborder properties.
269 */
270 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
271 (nv_connector->underscan == UNDERSCAN_AUTO &&
272 nv_connector->edid &&
273 drm_detect_hdmi_monitor(nv_connector->edid)))) {
274 u32 bX = nv_connector->underscan_hborder;
275 u32 bY = nv_connector->underscan_vborder;
276 u32 aspect = (oY << 19) / oX;
277
278 if (bX) {
279 oX -= (bX * 2);
280 if (bY) oY -= (bY * 2);
281 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000282 } else {
Ben Skeggsb29caa52011-10-06 13:29:05 +1000283 oX -= (oX >> 4) + 32;
284 if (bY) oY -= (bY * 2);
285 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000286 }
Ben Skeggsb29caa52011-10-06 13:29:05 +1000287 }
288
289 /* handle CENTER/ASPECT scaling, taking into account the areas
290 * removed already for overscan compensation
291 */
292 switch (scaling_mode) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000293 case DRM_MODE_SCALE_CENTER:
Ben Skeggs1cb94692011-10-25 16:29:13 +1000294 oX = min((u32)umode->hdisplay, oX);
295 oY = min((u32)umode->vdisplay, oY);
Ben Skeggsb29caa52011-10-06 13:29:05 +1000296 /* fall-through */
297 case DRM_MODE_SCALE_ASPECT:
298 if (oY < oX) {
Ben Skeggs1cb94692011-10-25 16:29:13 +1000299 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
Ben Skeggsb29caa52011-10-06 13:29:05 +1000300 oX = ((oY * aspect) + (aspect / 2)) >> 19;
301 } else {
Ben Skeggs1cb94692011-10-25 16:29:13 +1000302 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
Ben Skeggsb29caa52011-10-06 13:29:05 +1000303 oY = ((oX * aspect) + (aspect / 2)) >> 19;
304 }
305 break;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000306 default:
Ben Skeggs6ee73862009-12-11 19:24:15 +1000307 break;
308 }
309
Ben Skeggs1cb94692011-10-25 16:29:13 +1000310 if (umode->hdisplay != oX || umode->vdisplay != oY ||
311 umode->flags & DRM_MODE_FLAG_INTERLACE ||
312 umode->flags & DRM_MODE_FLAG_DBLSCAN)
Ben Skeggsb29caa52011-10-06 13:29:05 +1000313 ctrl |= NV50_EVO_CRTC_SCALE_CTRL_ACTIVE;
314
Ben Skeggs549cd872011-10-06 11:51:45 +1000315 ret = RING_SPACE(evo, 5);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000316 if (ret)
317 return ret;
318
Ben Skeggs6d597022012-04-01 21:09:13 +1000319 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_CTRL), 1);
Ben Skeggsb29caa52011-10-06 13:29:05 +1000320 OUT_RING (evo, ctrl);
Ben Skeggs6d597022012-04-01 21:09:13 +1000321 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, SCALE_RES1), 2);
Ben Skeggsb29caa52011-10-06 13:29:05 +1000322 OUT_RING (evo, oY << 16 | oX);
323 OUT_RING (evo, oY << 16 | oX);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000324
325 if (update) {
Ben Skeggs549cd872011-10-06 11:51:45 +1000326 nv50_display_flip_stop(crtc);
Ben Skeggse6e039d2011-10-14 14:35:19 +1000327 nv50_display_sync(dev);
Ben Skeggs549cd872011-10-06 11:51:45 +1000328 nv50_display_flip_next(crtc, crtc->fb, NULL);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000329 }
330
331 return 0;
332}
333
334int
335nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk)
336{
Ben Skeggs77145f12012-07-31 16:16:21 +1000337 struct nouveau_device *device = nouveau_dev(dev);
338 struct nouveau_clock *clk = nouveau_clock(device);
339
340 return clk->pll_set(clk, PLL_VPLL0 + head, pclk);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000341}
342
343static void
344nv50_crtc_destroy(struct drm_crtc *crtc)
345{
Ben Skeggsa8f81832012-04-20 11:01:46 +1000346 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs77145f12012-07-31 16:16:21 +1000347 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000348
Ben Skeggs77145f12012-07-31 16:16:21 +1000349 NV_DEBUG(drm, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000350
Ben Skeggs9d59e8a2010-08-27 13:04:41 +1000351 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000352 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs9d59e8a2010-08-27 13:04:41 +1000353 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000354 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggsa8f81832012-04-20 11:01:46 +1000355 drm_crtc_cleanup(&nv_crtc->base);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000356 kfree(nv_crtc);
357}
358
359int
360nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
361 uint32_t buffer_handle, uint32_t width, uint32_t height)
362{
363 struct drm_device *dev = crtc->dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000364 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
365 struct nouveau_bo *cursor = NULL;
366 struct drm_gem_object *gem;
367 int ret = 0, i;
368
Ben Skeggs6ee73862009-12-11 19:24:15 +1000369 if (!buffer_handle) {
370 nv_crtc->cursor.hide(nv_crtc, true);
371 return 0;
372 }
373
Marcin Slusarzb4fa9d02011-05-01 23:49:04 +0200374 if (width != 64 || height != 64)
375 return -EINVAL;
376
Ben Skeggs6ee73862009-12-11 19:24:15 +1000377 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle);
378 if (!gem)
Chris Wilsonbf79cb92010-08-04 14:19:46 +0100379 return -ENOENT;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000380 cursor = nouveau_gem_object(gem);
381
382 ret = nouveau_bo_map(cursor);
383 if (ret)
384 goto out;
385
386 /* The simple will do for now. */
387 for (i = 0; i < 64 * 64; i++)
388 nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, nouveau_bo_rd32(cursor, i));
389
390 nouveau_bo_unmap(cursor);
391
Ben Skeggs180cc302011-06-07 11:24:14 +1000392 nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.nvbo->bo.offset);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000393 nv_crtc->cursor.show(nv_crtc, true);
394
395out:
Luca Barbieribc9025b2010-02-09 05:49:12 +0000396 drm_gem_object_unreference_unlocked(gem);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000397 return ret;
398}
399
400int
401nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
402{
403 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
404
405 nv_crtc->cursor.set_pos(nv_crtc, x, y);
406 return 0;
407}
408
409static void
410nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100411 uint32_t start, uint32_t size)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000412{
James Simmons72034252010-08-03 01:33:19 +0100413 int end = (start + size > 256) ? 256 : start + size, i;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000414 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000415
James Simmons72034252010-08-03 01:33:19 +0100416 for (i = start; i < end; i++) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000417 nv_crtc->lut.r[i] = r[i];
418 nv_crtc->lut.g[i] = g[i];
419 nv_crtc->lut.b[i] = b[i];
420 }
421
422 /* We need to know the depth before we upload, but it's possible to
423 * get called before a framebuffer is bound. If this is the case,
424 * mark the lut values as dirty by setting depth==0, and it'll be
425 * uploaded on the first mode_set_base()
426 */
427 if (!nv_crtc->base.fb) {
428 nv_crtc->lut.depth = 0;
429 return;
430 }
431
432 nv50_crtc_lut_load(crtc);
433}
434
435static void
436nv50_crtc_save(struct drm_crtc *crtc)
437{
Ben Skeggs77145f12012-07-31 16:16:21 +1000438 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
439 NV_ERROR(drm, "!!\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000440}
441
442static void
443nv50_crtc_restore(struct drm_crtc *crtc)
444{
Ben Skeggs77145f12012-07-31 16:16:21 +1000445 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
446 NV_ERROR(drm, "!!\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000447}
448
449static const struct drm_crtc_funcs nv50_crtc_funcs = {
450 .save = nv50_crtc_save,
451 .restore = nv50_crtc_restore,
452 .cursor_set = nv50_crtc_cursor_set,
453 .cursor_move = nv50_crtc_cursor_move,
454 .gamma_set = nv50_crtc_gamma_set,
455 .set_config = drm_crtc_helper_set_config,
Francisco Jerez332b2422010-10-20 23:35:40 +0200456 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000457 .destroy = nv50_crtc_destroy,
458};
459
460static void
461nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
462{
463}
464
465static void
466nv50_crtc_prepare(struct drm_crtc *crtc)
467{
468 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
469 struct drm_device *dev = crtc->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000470 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000471
Ben Skeggs77145f12012-07-31 16:16:21 +1000472 NV_DEBUG(drm, "index %d\n", nv_crtc->index);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000473
Ben Skeggs1d3fac02011-02-07 14:18:37 +1000474 nv50_display_flip_stop(crtc);
Francisco Jerez1c180fa2010-10-25 03:30:34 +0200475 drm_vblank_pre_modeset(dev, nv_crtc->index);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000476 nv50_crtc_blank(nv_crtc, true);
477}
478
479static void
480nv50_crtc_commit(struct drm_crtc *crtc)
481{
Ben Skeggs6ee73862009-12-11 19:24:15 +1000482 struct drm_device *dev = crtc->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000483 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000484 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000485
Ben Skeggs77145f12012-07-31 16:16:21 +1000486 NV_DEBUG(drm, "index %d\n", nv_crtc->index);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000487
488 nv50_crtc_blank(nv_crtc, false);
Francisco Jerez1c180fa2010-10-25 03:30:34 +0200489 drm_vblank_post_modeset(dev, nv_crtc->index);
Ben Skeggse6e039d2011-10-14 14:35:19 +1000490 nv50_display_sync(dev);
Ben Skeggs1d3fac02011-02-07 14:18:37 +1000491 nv50_display_flip_next(crtc, crtc->fb, NULL);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000492}
493
494static bool
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200495nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000496 struct drm_display_mode *adjusted_mode)
497{
498 return true;
499}
500
501static int
Chris Ballbe64c2bb2010-09-26 06:47:24 -0500502nv50_crtc_do_mode_set_base(struct drm_crtc *crtc,
503 struct drm_framebuffer *passed_fb,
Ben Skeggs60f60bf2011-02-03 15:46:14 +1000504 int x, int y, bool atomic)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000505{
506 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
507 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000508 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs59c0f572011-02-01 10:24:41 +1000509 struct nouveau_channel *evo = nv50_display(dev)->master;
Emil Velikovffbc5592011-08-21 22:48:12 +0100510 struct drm_framebuffer *drm_fb;
511 struct nouveau_framebuffer *fb;
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000512 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000513
Ben Skeggs77145f12012-07-31 16:16:21 +1000514 NV_DEBUG(drm, "index %d\n", nv_crtc->index);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000515
Emil Velikovffbc5592011-08-21 22:48:12 +0100516 /* no fb bound */
517 if (!atomic && !crtc->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +1000518 NV_DEBUG(drm, "No FB bound\n");
Emil Velikovffbc5592011-08-21 22:48:12 +0100519 return 0;
520 }
521
Chris Ballbe64c2bb2010-09-26 06:47:24 -0500522 /* If atomic, we want to switch to the fb we were passed, so
523 * now we update pointers to do that. (We don't pin; just
524 * assume we're already pinned and update the base address.)
525 */
526 if (atomic) {
527 drm_fb = passed_fb;
528 fb = nouveau_framebuffer(passed_fb);
Emil Velikovf9ec8f62011-03-19 23:31:53 +0000529 } else {
Emil Velikovffbc5592011-08-21 22:48:12 +0100530 drm_fb = crtc->fb;
531 fb = nouveau_framebuffer(crtc->fb);
Chris Ballbe64c2bb2010-09-26 06:47:24 -0500532 /* If not atomic, we can go ahead and pin, and unpin the
533 * old fb we were passed.
534 */
535 ret = nouveau_bo_pin(fb->nvbo, TTM_PL_FLAG_VRAM);
536 if (ret)
537 return ret;
538
539 if (passed_fb) {
540 struct nouveau_framebuffer *ofb = nouveau_framebuffer(passed_fb);
541 nouveau_bo_unpin(ofb->nvbo);
542 }
543 }
544
Ben Skeggs180cc302011-06-07 11:24:14 +1000545 nv_crtc->fb.offset = fb->nvbo->bo.offset;
Francisco Jerezf13b3262010-10-10 06:01:08 +0200546 nv_crtc->fb.tile_flags = nouveau_bo_tile_layout(fb->nvbo);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000547 nv_crtc->fb.cpp = drm_fb->bits_per_pixel / 8;
Ben Skeggs77145f12012-07-31 16:16:21 +1000548 if (!nv_crtc->fb.blanked && nv_device(drm->device)->chipset != 0x50) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000549 ret = RING_SPACE(evo, 2);
550 if (ret)
551 return ret;
552
Ben Skeggs6d597022012-04-01 21:09:13 +1000553 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_DMA), 1);
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000554 OUT_RING (evo, fb->r_dma);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000555 }
556
557 ret = RING_SPACE(evo, 12);
558 if (ret)
559 return ret;
560
Ben Skeggs6d597022012-04-01 21:09:13 +1000561 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_OFFSET), 5);
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000562 OUT_RING (evo, nv_crtc->fb.offset >> 8);
563 OUT_RING (evo, 0);
564 OUT_RING (evo, (drm_fb->height << 16) | drm_fb->width);
565 OUT_RING (evo, fb->r_pitch);
566 OUT_RING (evo, fb->r_format);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000567
Ben Skeggs6d597022012-04-01 21:09:13 +1000568 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CLUT_MODE), 1);
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000569 OUT_RING (evo, fb->base.depth == 8 ?
570 NV50_EVO_CRTC_CLUT_MODE_OFF : NV50_EVO_CRTC_CLUT_MODE_ON);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000571
Ben Skeggs6d597022012-04-01 21:09:13 +1000572 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, FB_POS), 1);
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000573 OUT_RING (evo, (y << 16) | x);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000574
575 if (nv_crtc->lut.depth != fb->base.depth) {
576 nv_crtc->lut.depth = fb->base.depth;
577 nv50_crtc_lut_load(crtc);
578 }
579
Ben Skeggs6ee73862009-12-11 19:24:15 +1000580 return 0;
581}
582
583static int
Ben Skeggs616a5f52011-10-20 15:00:22 +1000584nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
585 struct drm_display_mode *mode, int x, int y,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000586 struct drm_framebuffer *old_fb)
587{
588 struct drm_device *dev = crtc->dev;
Ben Skeggs59c0f572011-02-01 10:24:41 +1000589 struct nouveau_channel *evo = nv50_display(dev)->master;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000590 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs616a5f52011-10-20 15:00:22 +1000591 u32 head = nv_crtc->index * 0x400;
592 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
593 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
594 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
595 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
596 u32 vblan2e = 0, vblan2s = 1;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000597 int ret;
598
Ben Skeggs616a5f52011-10-20 15:00:22 +1000599 /* hw timing description looks like this:
600 *
601 * <sync> <back porch> <---------display---------> <front porch>
602 * ______
603 * |____________|---------------------------|____________|
604 *
605 * ^ synce ^ blanke ^ blanks ^ active
606 *
607 * interlaced modes also have 2 additional values pointing at the end
608 * and start of the next field's blanking period.
609 */
Ben Skeggs6ee73862009-12-11 19:24:15 +1000610
Ben Skeggs616a5f52011-10-20 15:00:22 +1000611 hactive = mode->htotal;
612 hsynce = mode->hsync_end - mode->hsync_start - 1;
613 hbackp = mode->htotal - mode->hsync_end;
614 hblanke = hsynce + hbackp;
615 hfrontp = mode->hsync_start - mode->hdisplay;
616 hblanks = mode->htotal - hfrontp - 1;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000617
Ben Skeggs616a5f52011-10-20 15:00:22 +1000618 vactive = mode->vtotal * vscan / ilace;
619 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
620 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
621 vblanke = vsynce + vbackp;
622 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
623 vblanks = vactive - vfrontp - 1;
624 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
625 vblan2e = vactive + vsynce + vbackp;
626 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
627 vactive = (vactive * 2) + 1;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000628 }
629
Ben Skeggs616a5f52011-10-20 15:00:22 +1000630 ret = RING_SPACE(evo, 18);
631 if (ret == 0) {
Ben Skeggs6d597022012-04-01 21:09:13 +1000632 BEGIN_NV04(evo, 0, 0x0804 + head, 2);
Ben Skeggs616a5f52011-10-20 15:00:22 +1000633 OUT_RING (evo, 0x00800000 | mode->clock);
634 OUT_RING (evo, (ilace == 2) ? 2 : 0);
Ben Skeggs6d597022012-04-01 21:09:13 +1000635 BEGIN_NV04(evo, 0, 0x0810 + head, 6);
Ben Skeggs616a5f52011-10-20 15:00:22 +1000636 OUT_RING (evo, 0x00000000); /* border colour */
637 OUT_RING (evo, (vactive << 16) | hactive);
638 OUT_RING (evo, ( vsynce << 16) | hsynce);
639 OUT_RING (evo, (vblanke << 16) | hblanke);
640 OUT_RING (evo, (vblanks << 16) | hblanks);
641 OUT_RING (evo, (vblan2e << 16) | vblan2s);
Ben Skeggs6d597022012-04-01 21:09:13 +1000642 BEGIN_NV04(evo, 0, 0x082c + head, 1);
Ben Skeggs616a5f52011-10-20 15:00:22 +1000643 OUT_RING (evo, 0x00000000);
Ben Skeggs6d597022012-04-01 21:09:13 +1000644 BEGIN_NV04(evo, 0, 0x0900 + head, 1);
Ben Skeggs616a5f52011-10-20 15:00:22 +1000645 OUT_RING (evo, 0x00000311); /* makes sync channel work */
Ben Skeggs6d597022012-04-01 21:09:13 +1000646 BEGIN_NV04(evo, 0, 0x08c8 + head, 1);
Ben Skeggs616a5f52011-10-20 15:00:22 +1000647 OUT_RING (evo, (umode->vdisplay << 16) | umode->hdisplay);
Ben Skeggs6d597022012-04-01 21:09:13 +1000648 BEGIN_NV04(evo, 0, 0x08d4 + head, 1);
Ben Skeggs616a5f52011-10-20 15:00:22 +1000649 OUT_RING (evo, 0x00000000); /* screen position */
Ben Skeggs6ee73862009-12-11 19:24:15 +1000650 }
651
Ben Skeggs488ff202011-10-17 10:38:10 +1000652 nv_crtc->set_dither(nv_crtc, false);
653 nv_crtc->set_scale(nv_crtc, false);
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100654 nv_crtc->set_color_vibrance(nv_crtc, false);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000655
Ben Skeggs60f60bf2011-02-03 15:46:14 +1000656 return nv50_crtc_do_mode_set_base(crtc, old_fb, x, y, false);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000657}
658
659static int
660nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
661 struct drm_framebuffer *old_fb)
662{
Ben Skeggs60f60bf2011-02-03 15:46:14 +1000663 int ret;
664
Ben Skeggs1d3fac02011-02-07 14:18:37 +1000665 nv50_display_flip_stop(crtc);
Ben Skeggs60f60bf2011-02-03 15:46:14 +1000666 ret = nv50_crtc_do_mode_set_base(crtc, old_fb, x, y, false);
667 if (ret)
668 return ret;
669
Ben Skeggse6e039d2011-10-14 14:35:19 +1000670 ret = nv50_display_sync(crtc->dev);
Ben Skeggs1d3fac02011-02-07 14:18:37 +1000671 if (ret)
672 return ret;
673
674 return nv50_display_flip_next(crtc, crtc->fb, NULL);
Chris Ballbe64c2bb2010-09-26 06:47:24 -0500675}
676
677static int
678nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
679 struct drm_framebuffer *fb,
Jason Wessel21c74a82010-10-13 14:09:44 -0500680 int x, int y, enum mode_set_atomic state)
Chris Ballbe64c2bb2010-09-26 06:47:24 -0500681{
Ben Skeggs60f60bf2011-02-03 15:46:14 +1000682 int ret;
683
Ben Skeggs1d3fac02011-02-07 14:18:37 +1000684 nv50_display_flip_stop(crtc);
Ben Skeggs60f60bf2011-02-03 15:46:14 +1000685 ret = nv50_crtc_do_mode_set_base(crtc, fb, x, y, true);
686 if (ret)
687 return ret;
688
Ben Skeggse6e039d2011-10-14 14:35:19 +1000689 return nv50_display_sync(crtc->dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000690}
691
692static const struct drm_crtc_helper_funcs nv50_crtc_helper_funcs = {
693 .dpms = nv50_crtc_dpms,
694 .prepare = nv50_crtc_prepare,
695 .commit = nv50_crtc_commit,
696 .mode_fixup = nv50_crtc_mode_fixup,
697 .mode_set = nv50_crtc_mode_set,
698 .mode_set_base = nv50_crtc_mode_set_base,
Chris Ballbe64c2bb2010-09-26 06:47:24 -0500699 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000700 .load_lut = nv50_crtc_lut_load,
701};
702
703int
704nv50_crtc_create(struct drm_device *dev, int index)
705{
Ben Skeggs77145f12012-07-31 16:16:21 +1000706 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000707 struct nouveau_crtc *nv_crtc = NULL;
708 int ret, i;
709
Ben Skeggs77145f12012-07-31 16:16:21 +1000710 NV_DEBUG(drm, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000711
712 nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL);
713 if (!nv_crtc)
714 return -ENOMEM;
715
Ben Skeggsa8f81832012-04-20 11:01:46 +1000716 nv_crtc->index = index;
717 nv_crtc->set_dither = nv50_crtc_set_dither;
718 nv_crtc->set_scale = nv50_crtc_set_scale;
719 nv_crtc->set_color_vibrance = nv50_crtc_set_color_vibrance;
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100720 nv_crtc->color_vibrance = 50;
721 nv_crtc->vibrant_hue = 0;
Ben Skeggsa8f81832012-04-20 11:01:46 +1000722 nv_crtc->lut.depth = 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000723 for (i = 0; i < 256; i++) {
724 nv_crtc->lut.r[i] = i << 8;
725 nv_crtc->lut.g[i] = i << 8;
726 nv_crtc->lut.b[i] = i << 8;
727 }
Ben Skeggsa8f81832012-04-20 11:01:46 +1000728
729 drm_crtc_init(dev, &nv_crtc->base, &nv50_crtc_funcs);
730 drm_crtc_helper_add(&nv_crtc->base, &nv50_crtc_helper_funcs);
731 drm_mode_crtc_set_gamma_size(&nv_crtc->base, 256);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000732
Ben Skeggs7375c952011-06-07 14:21:29 +1000733 ret = nouveau_bo_new(dev, 4096, 0x100, TTM_PL_FLAG_VRAM,
Dave Airlie22b33e82012-04-02 11:53:06 +0100734 0, 0x0000, NULL, &nv_crtc->lut.nvbo);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000735 if (!ret) {
736 ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM);
737 if (!ret)
738 ret = nouveau_bo_map(nv_crtc->lut.nvbo);
739 if (ret)
740 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
741 }
742
Ben Skeggsa8f81832012-04-20 11:01:46 +1000743 if (ret)
744 goto out;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000745
Ben Skeggs6ee73862009-12-11 19:24:15 +1000746
Ben Skeggs7375c952011-06-07 14:21:29 +1000747 ret = nouveau_bo_new(dev, 64*64*4, 0x100, TTM_PL_FLAG_VRAM,
Dave Airlie22b33e82012-04-02 11:53:06 +0100748 0, 0x0000, NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000749 if (!ret) {
750 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
751 if (!ret)
752 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
753 if (ret)
754 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
755 }
756
Ben Skeggsa8f81832012-04-20 11:01:46 +1000757 if (ret)
758 goto out;
759
Ben Skeggs6ee73862009-12-11 19:24:15 +1000760 nv50_cursor_init(nv_crtc);
Ben Skeggsa8f81832012-04-20 11:01:46 +1000761out:
762 if (ret)
763 nv50_crtc_destroy(&nv_crtc->base);
764 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000765}