blob: 6e9892c9f811428fcec11251068f878899e00b8c [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
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
28#include <drm/drm_crtc_helper.h>
Ben Skeggs77145f12012-07-31 16:16:21 +100029
Ben Skeggs6ee73862009-12-11 19:24:15 +100030#include "nouveau_fbcon.h"
Ben Skeggs1a646342013-03-21 15:45:11 +100031#include "dispnv04/hw.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020032#include "nouveau_crtc.h"
33#include "nouveau_dma.h"
Ben Skeggs77145f12012-07-31 16:16:21 +100034#include "nouveau_gem.h"
Ben Skeggsde691852011-10-17 12:23:41 +100035#include "nouveau_connector.h"
Ben Skeggs45c4e0a2011-02-09 11:57:45 +100036#include "nv50_display.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100037
Ben Skeggsebb945a2012-07-20 08:17:34 +100038#include "nouveau_fence.h"
39
Ben Skeggs77145f12012-07-31 16:16:21 +100040#include <engine/disp.h>
Ben Skeggse0996ae2012-07-10 12:20:17 +100041
Ben Skeggs1d7c71a2013-01-31 09:23:34 +100042#include <core/class.h>
Ben Skeggs79ca2772014-08-10 04:10:20 +100043#include <nvif/event.h>
Ben Skeggs1d7c71a2013-01-31 09:23:34 +100044
Ben Skeggs51cb4b32013-10-03 07:02:29 +100045static int
Ben Skeggs79ca2772014-08-10 04:10:20 +100046nouveau_display_vblank_handler(struct nvkm_notify *notify)
Ben Skeggs51cb4b32013-10-03 07:02:29 +100047{
Ben Skeggs79ca2772014-08-10 04:10:20 +100048 struct nouveau_crtc *nv_crtc =
49 container_of(notify, typeof(*nv_crtc), vblank);
Ben Skeggsb12f0ae2014-08-10 04:10:19 +100050 drm_handle_vblank(nv_crtc->base.dev, nv_crtc->index);
Ben Skeggs79ca2772014-08-10 04:10:20 +100051 return NVKM_NOTIFY_KEEP;
Ben Skeggs51cb4b32013-10-03 07:02:29 +100052}
53
54int
55nouveau_display_vblank_enable(struct drm_device *dev, int head)
56{
Ben Skeggsb12f0ae2014-08-10 04:10:19 +100057 struct drm_crtc *crtc;
58 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
59 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
60 if (nv_crtc->index == head) {
Ben Skeggs79ca2772014-08-10 04:10:20 +100061 nvkm_notify_get(&nv_crtc->vblank);
Ben Skeggsb12f0ae2014-08-10 04:10:19 +100062 return 0;
63 }
Ben Skeggs51cb4b32013-10-03 07:02:29 +100064 }
Ben Skeggsb12f0ae2014-08-10 04:10:19 +100065 return -EINVAL;
Ben Skeggs51cb4b32013-10-03 07:02:29 +100066}
67
68void
69nouveau_display_vblank_disable(struct drm_device *dev, int head)
70{
Ben Skeggsb12f0ae2014-08-10 04:10:19 +100071 struct drm_crtc *crtc;
72 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
73 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
74 if (nv_crtc->index == head) {
Ben Skeggs79ca2772014-08-10 04:10:20 +100075 nvkm_notify_put(&nv_crtc->vblank);
Ben Skeggsb12f0ae2014-08-10 04:10:19 +100076 return;
77 }
78 }
Ben Skeggs51cb4b32013-10-03 07:02:29 +100079}
80
Ben Skeggsd83ef852013-11-14 13:37:49 +100081static inline int
82calc(int blanks, int blanke, int total, int line)
83{
84 if (blanke >= blanks) {
85 if (line >= blanks)
86 line -= total;
87 } else {
88 if (line >= blanks)
89 line -= total;
90 line -= blanke + 1;
91 }
92 return line;
93}
94
95int
96nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos,
97 ktime_t *stime, ktime_t *etime)
98{
99 const u32 mthd = NV04_DISP_SCANOUTPOS + nouveau_crtc(crtc)->index;
100 struct nouveau_display *disp = nouveau_display(crtc->dev);
101 struct nv04_display_scanoutpos args;
102 int ret, retry = 1;
103
104 do {
105 ret = nv_exec(disp->core, mthd, &args, sizeof(args));
106 if (ret != 0)
107 return 0;
108
109 if (args.vline) {
110 ret |= DRM_SCANOUTPOS_ACCURATE;
111 ret |= DRM_SCANOUTPOS_VALID;
112 break;
113 }
114
115 if (retry) ndelay(crtc->linedur_ns);
116 } while (retry--);
117
Mario Kleiner6c3252b2014-03-19 10:02:11 +0100118 *hpos = args.hline;
Ben Skeggsd83ef852013-11-14 13:37:49 +1000119 *vpos = calc(args.vblanks, args.vblanke, args.vtotal, args.vline);
120 if (stime) *stime = ns_to_ktime(args.time[0]);
121 if (etime) *etime = ns_to_ktime(args.time[1]);
122
123 if (*vpos < 0)
124 ret |= DRM_SCANOUTPOS_INVBL;
125 return ret;
126}
127
128int
129nouveau_display_scanoutpos(struct drm_device *dev, int head, unsigned int flags,
130 int *vpos, int *hpos, ktime_t *stime, ktime_t *etime)
131{
132 struct drm_crtc *crtc;
133
134 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
135 if (nouveau_crtc(crtc)->index == head) {
136 return nouveau_display_scanoutpos_head(crtc, vpos, hpos,
137 stime, etime);
138 }
139 }
140
141 return 0;
142}
143
144int
145nouveau_display_vblstamp(struct drm_device *dev, int head, int *max_error,
146 struct timeval *time, unsigned flags)
147{
148 struct drm_crtc *crtc;
149
150 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
151 if (nouveau_crtc(crtc)->index == head) {
152 return drm_calc_vbltimestamp_from_scanoutpos(dev,
153 head, max_error, time, flags, crtc,
154 &crtc->hwmode);
155 }
156 }
157
158 return -EINVAL;
159}
160
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000161static void
162nouveau_display_vblank_fini(struct drm_device *dev)
163{
Ben Skeggsb12f0ae2014-08-10 04:10:19 +1000164 struct drm_crtc *crtc;
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000165
Ben Skeggs1139ffb2014-01-23 10:49:47 +1000166 drm_vblank_cleanup(dev);
167
Ben Skeggsb12f0ae2014-08-10 04:10:19 +1000168 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
169 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs79ca2772014-08-10 04:10:20 +1000170 nvkm_notify_fini(&nv_crtc->vblank);
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000171 }
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000172}
173
174static int
175nouveau_display_vblank_init(struct drm_device *dev)
176{
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000177 struct nouveau_drm *drm = nouveau_drm(dev);
178 struct nouveau_disp *pdisp = nouveau_disp(drm->device);
Ben Skeggsb12f0ae2014-08-10 04:10:19 +1000179 struct drm_crtc *crtc;
180 int ret;
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000181
Ben Skeggsb12f0ae2014-08-10 04:10:19 +1000182 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
183 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs79ca2772014-08-10 04:10:20 +1000184 ret = nvkm_notify_init(&pdisp->vblank,
185 nouveau_display_vblank_handler, false,
186 &(struct nvif_notify_head_req_v0) {
187 .head = nv_crtc->index,
188 },
189 sizeof(struct nvif_notify_head_req_v0),
190 sizeof(struct nvif_notify_head_rep_v0),
191 &nv_crtc->vblank);
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000192 if (ret) {
193 nouveau_display_vblank_fini(dev);
194 return ret;
195 }
196 }
197
198 ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
199 if (ret) {
200 nouveau_display_vblank_fini(dev);
201 return ret;
202 }
203
204 return 0;
205}
206
Ben Skeggs6ee73862009-12-11 19:24:15 +1000207static void
208nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
209{
210 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
Ben Skeggsab0af552014-08-10 04:10:19 +1000211 struct nouveau_display *disp = nouveau_display(drm_fb->dev);
212
213 if (disp->fb_dtor)
214 disp->fb_dtor(drm_fb);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000215
Luca Barbieribc9025b2010-02-09 05:49:12 +0000216 if (fb->nvbo)
David Herrmann55fb74a2013-10-02 10:15:17 +0200217 drm_gem_object_unreference_unlocked(&fb->nvbo->gem);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000218
219 drm_framebuffer_cleanup(drm_fb);
220 kfree(fb);
221}
222
223static int
224nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
225 struct drm_file *file_priv,
226 unsigned int *handle)
227{
228 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
229
David Herrmann55fb74a2013-10-02 10:15:17 +0200230 return drm_gem_handle_create(file_priv, &fb->nvbo->gem, handle);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231}
232
233static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
234 .destroy = nouveau_user_framebuffer_destroy,
235 .create_handle = nouveau_user_framebuffer_create_handle,
236};
237
Dave Airlie38651672010-03-30 05:34:13 +0000238int
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000239nouveau_framebuffer_init(struct drm_device *dev,
240 struct nouveau_framebuffer *nv_fb,
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800241 struct drm_mode_fb_cmd2 *mode_cmd,
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000242 struct nouveau_bo *nvbo)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000243{
Ben Skeggsab0af552014-08-10 04:10:19 +1000244 struct nouveau_display *disp = nouveau_display(dev);
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000245 struct drm_framebuffer *fb = &nv_fb->base;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000246 int ret;
247
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000248 drm_helper_mode_fill_fb_struct(fb, mode_cmd);
249 nv_fb->nvbo = nvbo;
250
Daniel Vetterc7d73f62012-12-13 23:38:38 +0100251 ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs);
Ben Skeggsab0af552014-08-10 04:10:19 +1000252 if (ret)
Daniel Vetterc7d73f62012-12-13 23:38:38 +0100253 return ret;
Ben Skeggsab0af552014-08-10 04:10:19 +1000254
255 if (disp->fb_ctor) {
256 ret = disp->fb_ctor(fb);
257 if (ret)
258 disp->fb_dtor(fb);
Daniel Vetterc7d73f62012-12-13 23:38:38 +0100259 }
260
Ben Skeggsab0af552014-08-10 04:10:19 +1000261 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000262}
263
264static struct drm_framebuffer *
265nouveau_user_framebuffer_create(struct drm_device *dev,
266 struct drm_file *file_priv,
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800267 struct drm_mode_fb_cmd2 *mode_cmd)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000268{
Dave Airlie38651672010-03-30 05:34:13 +0000269 struct nouveau_framebuffer *nouveau_fb;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000270 struct drm_gem_object *gem;
Maarten Lankhorstfdfb8332013-07-08 14:50:54 +1000271 int ret = -ENOMEM;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000272
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800273 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000274 if (!gem)
Chris Wilsoncce13ff2010-08-08 13:36:38 +0100275 return ERR_PTR(-ENOENT);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000276
Dave Airlie38651672010-03-30 05:34:13 +0000277 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
278 if (!nouveau_fb)
Maarten Lankhorstfdfb8332013-07-08 14:50:54 +1000279 goto err_unref;
Dave Airlie38651672010-03-30 05:34:13 +0000280
281 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
Maarten Lankhorstfdfb8332013-07-08 14:50:54 +1000282 if (ret)
283 goto err;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000284
Dave Airlie38651672010-03-30 05:34:13 +0000285 return &nouveau_fb->base;
Maarten Lankhorstfdfb8332013-07-08 14:50:54 +1000286
287err:
288 kfree(nouveau_fb);
289err_unref:
290 drm_gem_object_unreference(gem);
291 return ERR_PTR(ret);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000292}
293
Ben Skeggs27d50302011-10-06 12:46:40 +1000294static const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000295 .fb_create = nouveau_user_framebuffer_create,
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000296 .output_poll_changed = nouveau_fbcon_output_poll_changed,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000297};
298
Ben Skeggsb29caa52011-10-06 13:29:05 +1000299
Sascha Hauer4a67d392012-02-06 10:58:17 +0100300struct nouveau_drm_prop_enum_list {
Ben Skeggsde691852011-10-17 12:23:41 +1000301 u8 gen_mask;
Ben Skeggsb29caa52011-10-06 13:29:05 +1000302 int type;
303 char *name;
304};
305
Sascha Hauer4a67d392012-02-06 10:58:17 +0100306static struct nouveau_drm_prop_enum_list underscan[] = {
Ben Skeggs92854622011-11-11 23:49:06 +1000307 { 6, UNDERSCAN_AUTO, "auto" },
308 { 6, UNDERSCAN_OFF, "off" },
309 { 6, UNDERSCAN_ON, "on" },
Ben Skeggsde691852011-10-17 12:23:41 +1000310 {}
Ben Skeggsb29caa52011-10-06 13:29:05 +1000311};
312
Sascha Hauer4a67d392012-02-06 10:58:17 +0100313static struct nouveau_drm_prop_enum_list dither_mode[] = {
Ben Skeggsde691852011-10-17 12:23:41 +1000314 { 7, DITHERING_MODE_AUTO, "auto" },
315 { 7, DITHERING_MODE_OFF, "off" },
316 { 1, DITHERING_MODE_ON, "on" },
317 { 6, DITHERING_MODE_STATIC2X2, "static 2x2" },
318 { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" },
319 { 4, DITHERING_MODE_TEMPORAL, "temporal" },
320 {}
321};
322
Sascha Hauer4a67d392012-02-06 10:58:17 +0100323static struct nouveau_drm_prop_enum_list dither_depth[] = {
Ben Skeggsde691852011-10-17 12:23:41 +1000324 { 6, DITHERING_DEPTH_AUTO, "auto" },
325 { 6, DITHERING_DEPTH_6BPC, "6 bpc" },
326 { 6, DITHERING_DEPTH_8BPC, "8 bpc" },
327 {}
328};
329
330#define PROP_ENUM(p,gen,n,list) do { \
Sascha Hauer4a67d392012-02-06 10:58:17 +0100331 struct nouveau_drm_prop_enum_list *l = (list); \
Ben Skeggsde691852011-10-17 12:23:41 +1000332 int c = 0; \
333 while (l->gen_mask) { \
334 if (l->gen_mask & (1 << (gen))) \
335 c++; \
336 l++; \
337 } \
338 if (c) { \
339 p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \
340 l = (list); \
341 c = 0; \
342 while (p && l->gen_mask) { \
343 if (l->gen_mask & (1 << (gen))) { \
344 drm_property_add_enum(p, c, l->type, l->name); \
345 c++; \
346 } \
347 l++; \
348 } \
349 } \
350} while(0)
351
Francisco Jerez042206c2010-10-21 18:19:29 +0200352int
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000353nouveau_display_init(struct drm_device *dev)
354{
Ben Skeggs77145f12012-07-31 16:16:21 +1000355 struct nouveau_display *disp = nouveau_display(dev);
Ben Skeggs52c4d762011-11-24 12:59:44 +1000356 struct drm_connector *connector;
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000357 int ret;
358
359 ret = disp->init(dev);
Ben Skeggs52c4d762011-11-24 12:59:44 +1000360 if (ret)
361 return ret;
362
Ben Skeggs7df898b2012-01-31 09:16:59 +1000363 /* enable polling for external displays */
Ben Skeggs52c4d762011-11-24 12:59:44 +1000364 drm_kms_helper_poll_enable(dev);
365
366 /* enable hotplug interrupts */
367 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
368 struct nouveau_connector *conn = nouveau_connector(connector);
Ben Skeggs79ca2772014-08-10 04:10:20 +1000369 nvkm_notify_get(&conn->hpd);
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000370 }
371
372 return ret;
373}
374
375void
376nouveau_display_fini(struct drm_device *dev)
377{
Ben Skeggs77145f12012-07-31 16:16:21 +1000378 struct nouveau_display *disp = nouveau_display(dev);
Ben Skeggs52c4d762011-11-24 12:59:44 +1000379 struct drm_connector *connector;
Mario Kleiner9cba5ef2014-07-29 02:36:44 +0200380 int head;
381
382 /* Make sure that drm and hw vblank irqs get properly disabled. */
383 for (head = 0; head < dev->mode_config.num_crtc; head++)
384 drm_vblank_off(dev, head);
Ben Skeggs52c4d762011-11-24 12:59:44 +1000385
386 /* disable hotplug interrupts */
387 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
388 struct nouveau_connector *conn = nouveau_connector(connector);
Ben Skeggs79ca2772014-08-10 04:10:20 +1000389 nvkm_notify_put(&conn->hpd);
Ben Skeggs52c4d762011-11-24 12:59:44 +1000390 }
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000391
392 drm_kms_helper_poll_disable(dev);
393 disp->fini(dev);
394}
395
Ben Skeggs9c210f32014-08-10 04:10:21 +1000396static void
397nouveau_display_create_properties(struct drm_device *dev)
Ben Skeggs27d50302011-10-06 12:46:40 +1000398{
Ben Skeggs9c210f32014-08-10 04:10:21 +1000399 struct nouveau_display *disp = nouveau_display(dev);
400 int gen;
Ben Skeggs27d50302011-10-06 12:46:40 +1000401
Ben Skeggs9c210f32014-08-10 04:10:21 +1000402 if (nv_mclass(disp->core) < NV50_DISP_CLASS)
Ben Skeggsde691852011-10-17 12:23:41 +1000403 gen = 0;
404 else
Ben Skeggs9c210f32014-08-10 04:10:21 +1000405 if (nv_mclass(disp->core) < NVD0_DISP_CLASS)
Ben Skeggsde691852011-10-17 12:23:41 +1000406 gen = 1;
407 else
408 gen = 2;
409
410 PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode);
411 PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth);
412 PROP_ENUM(disp->underscan_property, gen, "underscan", underscan);
Ben Skeggsb29caa52011-10-06 13:29:05 +1000413
414 disp->underscan_hborder_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100415 drm_property_create_range(dev, 0, "underscan hborder", 0, 128);
Ben Skeggsb29caa52011-10-06 13:29:05 +1000416
417 disp->underscan_vborder_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100418 drm_property_create_range(dev, 0, "underscan vborder", 0, 128);
Ben Skeggsb29caa52011-10-06 13:29:05 +1000419
Ben Skeggs9c210f32014-08-10 04:10:21 +1000420 if (gen < 1)
421 return;
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100422
Ben Skeggs9c210f32014-08-10 04:10:21 +1000423 /* -90..+90 */
424 disp->vibrant_hue_property =
425 drm_property_create_range(dev, 0, "vibrant hue", 0, 180);
426
427 /* -100..+100 */
428 disp->color_vibrance_property =
429 drm_property_create_range(dev, 0, "color vibrance", 0, 200);
430}
431
432int
433nouveau_display_create(struct drm_device *dev)
434{
435 struct nouveau_drm *drm = nouveau_drm(dev);
436 struct nouveau_device *device = nouveau_dev(dev);
437 struct nouveau_display *disp;
438 int ret;
439
440 disp = drm->display = kzalloc(sizeof(*disp), GFP_KERNEL);
441 if (!disp)
442 return -ENOMEM;
443
444 drm_mode_config_init(dev);
445 drm_mode_create_scaling_mode_property(dev);
446 drm_mode_create_dvi_i_properties(dev);
Christoph Bumillerdf26bc92012-01-21 23:13:26 +0100447
Laurent Pincharte6ecefa2012-05-17 13:27:23 +0200448 dev->mode_config.funcs = &nouveau_mode_config_funcs;
Alexandre Courbot420b9462014-02-17 15:17:26 +0900449 dev->mode_config.fb_base = nv_device_resource_start(device, 1);
Ben Skeggs27d50302011-10-06 12:46:40 +1000450
451 dev->mode_config.min_width = 0;
452 dev->mode_config.min_height = 0;
Ben Skeggs77145f12012-07-31 16:16:21 +1000453 if (nv_device(drm->device)->card_type < NV_10) {
Ben Skeggs27d50302011-10-06 12:46:40 +1000454 dev->mode_config.max_width = 2048;
455 dev->mode_config.max_height = 2048;
456 } else
Ben Skeggs77145f12012-07-31 16:16:21 +1000457 if (nv_device(drm->device)->card_type < NV_50) {
Ben Skeggs27d50302011-10-06 12:46:40 +1000458 dev->mode_config.max_width = 4096;
459 dev->mode_config.max_height = 4096;
460 } else {
461 dev->mode_config.max_width = 8192;
462 dev->mode_config.max_height = 8192;
463 }
464
Dave Airlief1377992012-02-20 14:39:11 +0000465 dev->mode_config.preferred_depth = 24;
466 dev->mode_config.prefer_shadow = 1;
467
Ben Skeggsb9d9dcd2013-11-11 13:59:40 +1000468 if (nv_device(drm->device)->chipset < 0x11)
469 dev->mode_config.async_page_flip = false;
470 else
471 dev->mode_config.async_page_flip = true;
472
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000473 drm_kms_helper_poll_init(dev);
474 drm_kms_helper_poll_disable(dev);
475
Ben Skeggsfc162082013-09-10 13:20:34 +1000476 if (drm->vbios.dcb.entries) {
Ben Skeggs2332b312014-01-22 12:58:12 +1000477 static const u16 oclass[] = {
Ben Skeggs0b681682014-02-24 14:29:55 +1000478 GM107_DISP_CLASS,
Ben Skeggs2332b312014-01-22 12:58:12 +1000479 NVF0_DISP_CLASS,
480 NVE0_DISP_CLASS,
481 NVD0_DISP_CLASS,
482 NVA3_DISP_CLASS,
483 NV94_DISP_CLASS,
484 NVA0_DISP_CLASS,
485 NV84_DISP_CLASS,
486 NV50_DISP_CLASS,
487 NV04_DISP_CLASS,
488 };
489 int i;
490
491 for (i = 0, ret = -ENODEV; ret && i < ARRAY_SIZE(oclass); i++) {
492 ret = nouveau_object_new(nv_object(drm), NVDRM_DEVICE,
493 NVDRM_DISPLAY, oclass[i],
494 NULL, 0, &disp->core);
495 }
496
497 if (ret == 0) {
Ben Skeggs9c210f32014-08-10 04:10:21 +1000498 nouveau_display_create_properties(dev);
Ben Skeggs2332b312014-01-22 12:58:12 +1000499 if (nv_mclass(disp->core) < NV50_DISP_CLASS)
500 ret = nv04_display_create(dev);
501 else
502 ret = nv50_display_create(dev);
503 }
Ben Skeggsfc162082013-09-10 13:20:34 +1000504 } else {
505 ret = 0;
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000506 }
507
Ben Skeggsfc162082013-09-10 13:20:34 +1000508 if (ret)
509 goto disp_create_err;
510
511 if (dev->mode_config.num_crtc) {
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000512 ret = nouveau_display_vblank_init(dev);
Ben Skeggsfc162082013-09-10 13:20:34 +1000513 if (ret)
514 goto vblank_err;
515 }
516
517 nouveau_backlight_init(dev);
Marcin Slusarz5ace2c92012-04-15 14:36:08 +0200518 return 0;
519
520vblank_err:
Ben Skeggs77145f12012-07-31 16:16:21 +1000521 disp->dtor(dev);
Marcin Slusarz5ace2c92012-04-15 14:36:08 +0200522disp_create_err:
523 drm_kms_helper_poll_fini(dev);
524 drm_mode_config_cleanup(dev);
Ben Skeggs2a44e492011-11-09 11:36:33 +1000525 return ret;
Ben Skeggs27d50302011-10-06 12:46:40 +1000526}
527
528void
529nouveau_display_destroy(struct drm_device *dev)
530{
Ben Skeggs77145f12012-07-31 16:16:21 +1000531 struct nouveau_display *disp = nouveau_display(dev);
Ben Skeggs2332b312014-01-22 12:58:12 +1000532 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs27d50302011-10-06 12:46:40 +1000533
Ben Skeggs77145f12012-07-31 16:16:21 +1000534 nouveau_backlight_exit(dev);
Ben Skeggs51cb4b32013-10-03 07:02:29 +1000535 nouveau_display_vblank_fini(dev);
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000536
Ben Skeggsd6bf2f32012-10-30 10:59:12 +1000537 drm_kms_helper_poll_fini(dev);
538 drm_mode_config_cleanup(dev);
539
Ben Skeggs94307382012-10-31 12:11:15 +1000540 if (disp->dtor)
541 disp->dtor(dev);
Ben Skeggsf62b27d2011-11-09 15:18:47 +1000542
Ben Skeggs2332b312014-01-22 12:58:12 +1000543 nouveau_object_del(nv_object(drm), NVDRM_DEVICE, NVDRM_DISPLAY);
544
Ben Skeggs77145f12012-07-31 16:16:21 +1000545 nouveau_drm(dev)->display = NULL;
546 kfree(disp);
547}
548
549int
550nouveau_display_suspend(struct drm_device *dev)
551{
552 struct nouveau_drm *drm = nouveau_drm(dev);
553 struct drm_crtc *crtc;
554
555 nouveau_display_fini(dev);
556
Ben Skeggsc52f4fa2013-11-08 14:38:40 +1000557 NV_INFO(drm, "unpinning framebuffer(s)...\n");
Ben Skeggs77145f12012-07-31 16:16:21 +1000558 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
559 struct nouveau_framebuffer *nouveau_fb;
560
Matt Roperf4510a22014-04-01 15:22:40 -0700561 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs77145f12012-07-31 16:16:21 +1000562 if (!nouveau_fb || !nouveau_fb->nvbo)
563 continue;
564
565 nouveau_bo_unpin(nouveau_fb->nvbo);
566 }
567
568 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
569 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
570
571 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
572 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
573 }
574
575 return 0;
576}
577
578void
Dave Airlie5addcf02012-09-10 14:20:51 +1000579nouveau_display_repin(struct drm_device *dev)
Ben Skeggs77145f12012-07-31 16:16:21 +1000580{
581 struct nouveau_drm *drm = nouveau_drm(dev);
582 struct drm_crtc *crtc;
583 int ret;
584
585 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
586 struct nouveau_framebuffer *nouveau_fb;
587
Matt Roperf4510a22014-04-01 15:22:40 -0700588 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs77145f12012-07-31 16:16:21 +1000589 if (!nouveau_fb || !nouveau_fb->nvbo)
590 continue;
591
592 nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM);
593 }
594
595 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
596 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
597
598 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
599 if (!ret)
600 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
601 if (ret)
602 NV_ERROR(drm, "Could not pin/map cursor.\n");
603 }
Dave Airlie5addcf02012-09-10 14:20:51 +1000604}
Ben Skeggs77145f12012-07-31 16:16:21 +1000605
Dave Airlie5addcf02012-09-10 14:20:51 +1000606void
607nouveau_display_resume(struct drm_device *dev)
608{
609 struct drm_crtc *crtc;
Mario Kleiner9cba5ef2014-07-29 02:36:44 +0200610 int head;
611
Ben Skeggs77145f12012-07-31 16:16:21 +1000612 nouveau_display_init(dev);
613
614 /* Force CLUT to get re-loaded during modeset */
615 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
616 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
617
618 nv_crtc->lut.depth = 0;
619 }
620
Mario Kleiner9cba5ef2014-07-29 02:36:44 +0200621 /* Make sure that drm and hw vblank irqs get resumed if needed. */
622 for (head = 0; head < dev->mode_config.num_crtc; head++)
623 drm_vblank_on(dev, head);
624
Ben Skeggs77145f12012-07-31 16:16:21 +1000625 drm_helper_resume_force_mode(dev);
626
627 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
628 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
629 u32 offset = nv_crtc->cursor.nvbo->bo.offset;
630
631 nv_crtc->cursor.set_offset(nv_crtc, offset);
632 nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
633 nv_crtc->cursor_saved_y);
634 }
Ben Skeggs27d50302011-10-06 12:46:40 +1000635}
636
Francisco Jerez332b2422010-10-20 23:35:40 +0200637static int
Francisco Jerez332b2422010-10-20 23:35:40 +0200638nouveau_page_flip_emit(struct nouveau_channel *chan,
639 struct nouveau_bo *old_bo,
640 struct nouveau_bo *new_bo,
641 struct nouveau_page_flip_state *s,
642 struct nouveau_fence **pfence)
643{
Ben Skeggsf589be82012-07-22 11:55:54 +1000644 struct nouveau_fence_chan *fctx = chan->fence;
Ben Skeggs77145f12012-07-31 16:16:21 +1000645 struct nouveau_drm *drm = chan->drm;
646 struct drm_device *dev = drm->dev;
Francisco Jerez332b2422010-10-20 23:35:40 +0200647 unsigned long flags;
648 int ret;
649
650 /* Queue it to the pending list */
651 spin_lock_irqsave(&dev->event_lock, flags);
Ben Skeggsf589be82012-07-22 11:55:54 +1000652 list_add_tail(&s->head, &fctx->flip);
Francisco Jerez332b2422010-10-20 23:35:40 +0200653 spin_unlock_irqrestore(&dev->event_lock, flags);
654
655 /* Synchronize with the old framebuffer */
656 ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan);
657 if (ret)
658 goto fail;
659
660 /* Emit the pageflip */
Ben Skeggs1e303c02013-11-13 10:49:46 +1000661 ret = RING_SPACE(chan, 2);
Francisco Jerez332b2422010-10-20 23:35:40 +0200662 if (ret)
663 goto fail;
664
Ben Skeggs1e303c02013-11-13 10:49:46 +1000665 if (nv_device(drm->device)->card_type < NV_C0)
Ben Skeggs6d597022012-04-01 21:09:13 +1000666 BEGIN_NV04(chan, NvSubSw, NV_SW_PAGE_FLIP, 1);
Ben Skeggs1e303c02013-11-13 10:49:46 +1000667 else
668 BEGIN_NVC0(chan, FermiSw, NV_SW_PAGE_FLIP, 1);
669 OUT_RING (chan, 0x00000000);
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000670 FIRE_RING (chan);
Francisco Jerez332b2422010-10-20 23:35:40 +0200671
Ben Skeggs264ce192013-02-14 13:43:21 +1000672 ret = nouveau_fence_new(chan, false, pfence);
Francisco Jerez332b2422010-10-20 23:35:40 +0200673 if (ret)
674 goto fail;
675
676 return 0;
677fail:
678 spin_lock_irqsave(&dev->event_lock, flags);
679 list_del(&s->head);
680 spin_unlock_irqrestore(&dev->event_lock, flags);
681 return ret;
682}
683
684int
685nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggsb9d9dcd2013-11-11 13:59:40 +1000686 struct drm_pending_vblank_event *event, u32 flags)
Francisco Jerez332b2422010-10-20 23:35:40 +0200687{
Ben Skeggsb9d9dcd2013-11-11 13:59:40 +1000688 const int swap_interval = (flags & DRM_MODE_PAGE_FLIP_ASYNC) ? 0 : 1;
Francisco Jerez332b2422010-10-20 23:35:40 +0200689 struct drm_device *dev = crtc->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +1000690 struct nouveau_drm *drm = nouveau_drm(dev);
Matt Roperf4510a22014-04-01 15:22:40 -0700691 struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->primary->fb)->nvbo;
Francisco Jerez332b2422010-10-20 23:35:40 +0200692 struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo;
693 struct nouveau_page_flip_state *s;
Ben Skeggseae389f2013-11-13 10:17:17 +1000694 struct nouveau_channel *chan = drm->channel;
Francisco Jerez332b2422010-10-20 23:35:40 +0200695 struct nouveau_fence *fence;
696 int ret;
697
Ben Skeggs77145f12012-07-31 16:16:21 +1000698 if (!drm->channel)
Francisco Jerez332b2422010-10-20 23:35:40 +0200699 return -ENODEV;
700
701 s = kzalloc(sizeof(*s), GFP_KERNEL);
702 if (!s)
703 return -ENOMEM;
704
Maarten Lankhorstd5c1e842014-01-14 16:48:58 +0100705 if (new_bo != old_bo) {
706 ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM);
707 if (ret)
708 goto fail_free;
709 }
710
711 mutex_lock(&chan->cli->mutex);
712
Ben Skeggseae389f2013-11-13 10:17:17 +1000713 /* synchronise rendering channel with the kernel's channel */
714 spin_lock(&new_bo->bo.bdev->fence_lock);
715 fence = nouveau_fence_ref(new_bo->bo.sync_obj);
716 spin_unlock(&new_bo->bo.bdev->fence_lock);
717 ret = nouveau_fence_sync(fence, chan);
Ben Skeggs2fd04c82013-11-21 14:22:39 +1000718 nouveau_fence_unref(&fence);
Ben Skeggseae389f2013-11-13 10:17:17 +1000719 if (ret)
Maarten Lankhorst09c3de12014-01-29 11:05:09 +0100720 goto fail_unpin;
Maarten Lankhorstb580c9e2013-06-27 13:48:18 +0200721
Ben Skeggs07ad6ca2013-11-13 10:00:32 +1000722 ret = ttm_bo_reserve(&old_bo->bo, true, false, false, NULL);
Ben Skeggs060810d2013-07-08 14:15:51 +1000723 if (ret)
724 goto fail_unpin;
Francisco Jerez332b2422010-10-20 23:35:40 +0200725
726 /* Initialize a page flip struct */
727 *s = (struct nouveau_page_flip_state)
Benjamin Franzke2503c6f2011-02-16 10:04:48 +0100728 { { }, event, nouveau_crtc(crtc)->index,
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200729 fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y,
Francisco Jerez332b2422010-10-20 23:35:40 +0200730 new_bo->bo.offset };
731
Mario Kleinerba124a42014-06-11 09:51:23 +0200732 /* Keep vblanks on during flip, for the target crtc of this flip */
733 drm_vblank_get(dev, nouveau_crtc(crtc)->index);
734
Francisco Jerez332b2422010-10-20 23:35:40 +0200735 /* Emit a page flip */
Ben Skeggs77145f12012-07-31 16:16:21 +1000736 if (nv_device(drm->device)->card_type >= NV_50) {
Ben Skeggsb9d9dcd2013-11-11 13:59:40 +1000737 ret = nv50_display_flip_next(crtc, fb, chan, swap_interval);
Ben Skeggs060810d2013-07-08 14:15:51 +1000738 if (ret)
Ben Skeggsd7117e02011-02-07 14:27:04 +1000739 goto fail_unreserve;
Ben Skeggs78ae0ad2013-08-21 11:30:36 +1000740 } else {
741 struct nv04_display *dispnv04 = nv04_display(dev);
Ben Skeggsb9d9dcd2013-11-11 13:59:40 +1000742 int head = nouveau_crtc(crtc)->index;
743
744 if (swap_interval) {
745 ret = RING_SPACE(chan, 8);
746 if (ret)
747 goto fail_unreserve;
748
749 BEGIN_NV04(chan, NvSubImageBlit, 0x012c, 1);
750 OUT_RING (chan, 0);
751 BEGIN_NV04(chan, NvSubImageBlit, 0x0134, 1);
752 OUT_RING (chan, head);
753 BEGIN_NV04(chan, NvSubImageBlit, 0x0100, 1);
754 OUT_RING (chan, 0);
755 BEGIN_NV04(chan, NvSubImageBlit, 0x0130, 1);
756 OUT_RING (chan, 0);
757 }
758
759 nouveau_bo_ref(new_bo, &dispnv04->image[head]);
Ben Skeggsd7117e02011-02-07 14:27:04 +1000760 }
761
Francisco Jerez332b2422010-10-20 23:35:40 +0200762 ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence);
Francisco Jerez332b2422010-10-20 23:35:40 +0200763 if (ret)
764 goto fail_unreserve;
Maarten Lankhorst806cbc52014-05-01 13:58:05 +0200765 mutex_unlock(&chan->cli->mutex);
Francisco Jerez332b2422010-10-20 23:35:40 +0200766
767 /* Update the crtc struct and cleanup */
Matt Roperf4510a22014-04-01 15:22:40 -0700768 crtc->primary->fb = fb;
Francisco Jerez332b2422010-10-20 23:35:40 +0200769
Ben Skeggs07ad6ca2013-11-13 10:00:32 +1000770 nouveau_bo_fence(old_bo, fence);
771 ttm_bo_unreserve(&old_bo->bo);
Ben Skeggs060810d2013-07-08 14:15:51 +1000772 if (old_bo != new_bo)
Maarten Lankhorstb580c9e2013-06-27 13:48:18 +0200773 nouveau_bo_unpin(old_bo);
Francisco Jerez332b2422010-10-20 23:35:40 +0200774 nouveau_fence_unref(&fence);
775 return 0;
776
777fail_unreserve:
Mario Kleinerba124a42014-06-11 09:51:23 +0200778 drm_vblank_put(dev, nouveau_crtc(crtc)->index);
Ben Skeggs07ad6ca2013-11-13 10:00:32 +1000779 ttm_bo_unreserve(&old_bo->bo);
Ben Skeggs060810d2013-07-08 14:15:51 +1000780fail_unpin:
781 mutex_unlock(&chan->cli->mutex);
782 if (old_bo != new_bo)
Maarten Lankhorstb580c9e2013-06-27 13:48:18 +0200783 nouveau_bo_unpin(new_bo);
Francisco Jerez332b2422010-10-20 23:35:40 +0200784fail_free:
785 kfree(s);
786 return ret;
787}
788
789int
790nouveau_finish_page_flip(struct nouveau_channel *chan,
791 struct nouveau_page_flip_state *ps)
792{
Ben Skeggsf589be82012-07-22 11:55:54 +1000793 struct nouveau_fence_chan *fctx = chan->fence;
Ben Skeggs77145f12012-07-31 16:16:21 +1000794 struct nouveau_drm *drm = chan->drm;
795 struct drm_device *dev = drm->dev;
Francisco Jerez332b2422010-10-20 23:35:40 +0200796 struct nouveau_page_flip_state *s;
797 unsigned long flags;
Mario Kleineraf4870e2014-05-13 00:42:08 +0200798 int crtcid = -1;
Francisco Jerez332b2422010-10-20 23:35:40 +0200799
800 spin_lock_irqsave(&dev->event_lock, flags);
801
Ben Skeggsf589be82012-07-22 11:55:54 +1000802 if (list_empty(&fctx->flip)) {
Ben Skeggs77145f12012-07-31 16:16:21 +1000803 NV_ERROR(drm, "unexpected pageflip\n");
Francisco Jerez332b2422010-10-20 23:35:40 +0200804 spin_unlock_irqrestore(&dev->event_lock, flags);
805 return -EINVAL;
806 }
807
Ben Skeggsf589be82012-07-22 11:55:54 +1000808 s = list_first_entry(&fctx->flip, struct nouveau_page_flip_state, head);
Mario Kleineraf4870e2014-05-13 00:42:08 +0200809 if (s->event) {
810 /* Vblank timestamps/counts are only correct on >= NV-50 */
811 if (nv_device(drm->device)->card_type >= NV_50)
812 crtcid = s->crtc;
813
814 drm_send_vblank_event(dev, crtcid, s->event);
815 }
Francisco Jerez332b2422010-10-20 23:35:40 +0200816
Mario Kleinerba124a42014-06-11 09:51:23 +0200817 /* Give up ownership of vblank for page-flipped crtc */
818 drm_vblank_put(dev, s->crtc);
819
Francisco Jerez332b2422010-10-20 23:35:40 +0200820 list_del(&s->head);
Ben Skeggsd7117e02011-02-07 14:27:04 +1000821 if (ps)
822 *ps = *s;
Francisco Jerez332b2422010-10-20 23:35:40 +0200823 kfree(s);
824
825 spin_unlock_irqrestore(&dev->event_lock, flags);
826 return 0;
827}
Ben Skeggs33dbc272011-09-30 08:55:50 +1000828
829int
Ben Skeggsf589be82012-07-22 11:55:54 +1000830nouveau_flip_complete(void *data)
831{
832 struct nouveau_channel *chan = data;
Ben Skeggs77145f12012-07-31 16:16:21 +1000833 struct nouveau_drm *drm = chan->drm;
Ben Skeggsf589be82012-07-22 11:55:54 +1000834 struct nouveau_page_flip_state state;
835
836 if (!nouveau_finish_page_flip(chan, &state)) {
Ben Skeggs77145f12012-07-31 16:16:21 +1000837 if (nv_device(drm->device)->card_type < NV_50) {
838 nv_set_crtc_base(drm->dev, state.crtc, state.offset +
Ben Skeggsf589be82012-07-22 11:55:54 +1000839 state.y * state.pitch +
840 state.x * state.bpp / 8);
841 }
842 }
843
844 return 0;
845}
846
847int
Ben Skeggs33dbc272011-09-30 08:55:50 +1000848nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
849 struct drm_mode_create_dumb *args)
850{
851 struct nouveau_bo *bo;
852 int ret;
853
854 args->pitch = roundup(args->width * (args->bpp / 8), 256);
855 args->size = args->pitch * args->height;
856 args->size = roundup(args->size, PAGE_SIZE);
857
Dave Airlie610bd7d2012-09-14 13:28:23 +1000858 ret = nouveau_gem_new(dev, args->size, 0, NOUVEAU_GEM_DOMAIN_VRAM, 0, 0, &bo);
Ben Skeggs33dbc272011-09-30 08:55:50 +1000859 if (ret)
860 return ret;
861
David Herrmann55fb74a2013-10-02 10:15:17 +0200862 ret = drm_gem_handle_create(file_priv, &bo->gem, &args->handle);
863 drm_gem_object_unreference_unlocked(&bo->gem);
Ben Skeggs33dbc272011-09-30 08:55:50 +1000864 return ret;
865}
866
867int
Ben Skeggs33dbc272011-09-30 08:55:50 +1000868nouveau_display_dumb_map_offset(struct drm_file *file_priv,
869 struct drm_device *dev,
870 uint32_t handle, uint64_t *poffset)
871{
872 struct drm_gem_object *gem;
873
874 gem = drm_gem_object_lookup(dev, file_priv, handle);
875 if (gem) {
David Herrmann55fb74a2013-10-02 10:15:17 +0200876 struct nouveau_bo *bo = nouveau_gem_object(gem);
David Herrmann72525b32013-07-24 21:08:53 +0200877 *poffset = drm_vma_node_offset_addr(&bo->bo.vma_node);
Ben Skeggs33dbc272011-09-30 08:55:50 +1000878 drm_gem_object_unreference_unlocked(gem);
879 return 0;
880 }
881
882 return -ENOENT;
883}