blob: 803248d467fbe72b5772c51fb279f19e28a07bdb [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_crtc_helper.h"
29#include "nouveau_drv.h"
30#include "nouveau_fb.h"
31#include "nouveau_fbcon.h"
Francisco Jerez042206c2010-10-21 18:19:29 +020032#include "nouveau_hw.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020033#include "nouveau_crtc.h"
34#include "nouveau_dma.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
38static void
39nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
40{
41 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
Ben Skeggs6ee73862009-12-11 19:24:15 +100042
Luca Barbieribc9025b2010-02-09 05:49:12 +000043 if (fb->nvbo)
44 drm_gem_object_unreference_unlocked(fb->nvbo->gem);
Ben Skeggs6ee73862009-12-11 19:24:15 +100045
46 drm_framebuffer_cleanup(drm_fb);
47 kfree(fb);
48}
49
50static int
51nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
52 struct drm_file *file_priv,
53 unsigned int *handle)
54{
55 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
56
57 return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle);
58}
59
60static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
61 .destroy = nouveau_user_framebuffer_destroy,
62 .create_handle = nouveau_user_framebuffer_create_handle,
63};
64
Dave Airlie38651672010-03-30 05:34:13 +000065int
Ben Skeggs45c4e0a2011-02-09 11:57:45 +100066nouveau_framebuffer_init(struct drm_device *dev,
67 struct nouveau_framebuffer *nv_fb,
Jesse Barnes308e5bc2011-11-14 14:51:28 -080068 struct drm_mode_fb_cmd2 *mode_cmd,
Ben Skeggs45c4e0a2011-02-09 11:57:45 +100069 struct nouveau_bo *nvbo)
Ben Skeggs6ee73862009-12-11 19:24:15 +100070{
Ben Skeggs45c4e0a2011-02-09 11:57:45 +100071 struct drm_nouveau_private *dev_priv = dev->dev_private;
72 struct drm_framebuffer *fb = &nv_fb->base;
Ben Skeggs6ee73862009-12-11 19:24:15 +100073 int ret;
74
Ben Skeggs45c4e0a2011-02-09 11:57:45 +100075 ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs);
Ben Skeggs6ee73862009-12-11 19:24:15 +100076 if (ret) {
Dave Airlie38651672010-03-30 05:34:13 +000077 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +100078 }
79
Ben Skeggs45c4e0a2011-02-09 11:57:45 +100080 drm_helper_mode_fill_fb_struct(fb, mode_cmd);
81 nv_fb->nvbo = nvbo;
82
83 if (dev_priv->card_type >= NV_50) {
84 u32 tile_flags = nouveau_bo_tile_layout(nvbo);
85 if (tile_flags == 0x7a00 ||
86 tile_flags == 0xfe00)
87 nv_fb->r_dma = NvEvoFB32;
88 else
89 if (tile_flags == 0x7000)
90 nv_fb->r_dma = NvEvoFB16;
91 else
92 nv_fb->r_dma = NvEvoVRAM_LP;
93
94 switch (fb->depth) {
95 case 8: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_8; break;
96 case 15: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_15; break;
97 case 16: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_16; break;
98 case 24:
99 case 32: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_24; break;
100 case 30: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_30; break;
101 default:
102 NV_ERROR(dev, "unknown depth %d\n", fb->depth);
103 return -EINVAL;
104 }
105
106 if (dev_priv->chipset == 0x50)
107 nv_fb->r_format |= (tile_flags << 8);
108
Ben Skeggs2fad3d52011-07-06 09:59:40 +1000109 if (!tile_flags) {
110 if (dev_priv->card_type < NV_D0)
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200111 nv_fb->r_pitch = 0x00100000 | fb->pitches[0];
Ben Skeggs2fad3d52011-07-06 09:59:40 +1000112 else
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200113 nv_fb->r_pitch = 0x01000000 | fb->pitches[0];
Ben Skeggs2fad3d52011-07-06 09:59:40 +1000114 } else {
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000115 u32 mode = nvbo->tile_mode;
116 if (dev_priv->card_type >= NV_C0)
117 mode >>= 4;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200118 nv_fb->r_pitch = ((fb->pitches[0] / 4) << 4) | mode;
Ben Skeggs45c4e0a2011-02-09 11:57:45 +1000119 }
120 }
121
Dave Airlie38651672010-03-30 05:34:13 +0000122 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000123}
124
125static struct drm_framebuffer *
126nouveau_user_framebuffer_create(struct drm_device *dev,
127 struct drm_file *file_priv,
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800128 struct drm_mode_fb_cmd2 *mode_cmd)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000129{
Dave Airlie38651672010-03-30 05:34:13 +0000130 struct nouveau_framebuffer *nouveau_fb;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000131 struct drm_gem_object *gem;
Dave Airlie38651672010-03-30 05:34:13 +0000132 int ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000133
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800134 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000135 if (!gem)
Chris Wilsoncce13ff2010-08-08 13:36:38 +0100136 return ERR_PTR(-ENOENT);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000137
Dave Airlie38651672010-03-30 05:34:13 +0000138 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
139 if (!nouveau_fb)
Chris Wilsoncce13ff2010-08-08 13:36:38 +0100140 return ERR_PTR(-ENOMEM);
Dave Airlie38651672010-03-30 05:34:13 +0000141
142 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
143 if (ret) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000144 drm_gem_object_unreference(gem);
Chris Wilsoncce13ff2010-08-08 13:36:38 +0100145 return ERR_PTR(ret);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000146 }
147
Dave Airlie38651672010-03-30 05:34:13 +0000148 return &nouveau_fb->base;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000149}
150
Ben Skeggs27d50302011-10-06 12:46:40 +1000151static const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152 .fb_create = nouveau_user_framebuffer_create,
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000153 .output_poll_changed = nouveau_fbcon_output_poll_changed,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000154};
155
Ben Skeggsb29caa52011-10-06 13:29:05 +1000156
157struct drm_prop_enum_list {
Ben Skeggsde691852011-10-17 12:23:41 +1000158 u8 gen_mask;
Ben Skeggsb29caa52011-10-06 13:29:05 +1000159 int type;
160 char *name;
161};
162
Ben Skeggsde691852011-10-17 12:23:41 +1000163static struct drm_prop_enum_list underscan[] = {
164 { 2, UNDERSCAN_AUTO, "auto" },
165 { 2, UNDERSCAN_OFF, "off" },
166 { 2, UNDERSCAN_ON, "on" },
167 {}
Ben Skeggsb29caa52011-10-06 13:29:05 +1000168};
169
Ben Skeggsde691852011-10-17 12:23:41 +1000170static struct drm_prop_enum_list dither_mode[] = {
171 { 7, DITHERING_MODE_AUTO, "auto" },
172 { 7, DITHERING_MODE_OFF, "off" },
173 { 1, DITHERING_MODE_ON, "on" },
174 { 6, DITHERING_MODE_STATIC2X2, "static 2x2" },
175 { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" },
176 { 4, DITHERING_MODE_TEMPORAL, "temporal" },
177 {}
178};
179
180static struct drm_prop_enum_list dither_depth[] = {
181 { 6, DITHERING_DEPTH_AUTO, "auto" },
182 { 6, DITHERING_DEPTH_6BPC, "6 bpc" },
183 { 6, DITHERING_DEPTH_8BPC, "8 bpc" },
184 {}
185};
186
187#define PROP_ENUM(p,gen,n,list) do { \
188 struct drm_prop_enum_list *l = (list); \
189 int c = 0; \
190 while (l->gen_mask) { \
191 if (l->gen_mask & (1 << (gen))) \
192 c++; \
193 l++; \
194 } \
195 if (c) { \
196 p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \
197 l = (list); \
198 c = 0; \
199 while (p && l->gen_mask) { \
200 if (l->gen_mask & (1 << (gen))) { \
201 drm_property_add_enum(p, c, l->type, l->name); \
202 c++; \
203 } \
204 l++; \
205 } \
206 } \
207} while(0)
208
Francisco Jerez042206c2010-10-21 18:19:29 +0200209int
Ben Skeggs27d50302011-10-06 12:46:40 +1000210nouveau_display_create(struct drm_device *dev)
211{
212 struct drm_nouveau_private *dev_priv = dev->dev_private;
213 struct nouveau_display_engine *disp = &dev_priv->engine.display;
Ben Skeggsde691852011-10-17 12:23:41 +1000214 int ret, gen;
Ben Skeggs27d50302011-10-06 12:46:40 +1000215
216 drm_mode_config_init(dev);
217 drm_mode_create_scaling_mode_property(dev);
Ben Skeggs4ceca5f2011-10-14 23:55:47 +1000218 drm_mode_create_dvi_i_properties(dev);
Ben Skeggs27d50302011-10-06 12:46:40 +1000219
Ben Skeggsde691852011-10-17 12:23:41 +1000220 if (dev_priv->card_type < NV_50)
221 gen = 0;
222 else
223 if (dev_priv->card_type < NV_D0)
224 gen = 1;
225 else
226 gen = 2;
227
228 PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode);
229 PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth);
230 PROP_ENUM(disp->underscan_property, gen, "underscan", underscan);
Ben Skeggsb29caa52011-10-06 13:29:05 +1000231
232 disp->underscan_hborder_property =
233 drm_property_create(dev, DRM_MODE_PROP_RANGE,
234 "underscan hborder", 2);
235 disp->underscan_hborder_property->values[0] = 0;
236 disp->underscan_hborder_property->values[1] = 128;
237
238 disp->underscan_vborder_property =
239 drm_property_create(dev, DRM_MODE_PROP_RANGE,
240 "underscan vborder", 2);
241 disp->underscan_vborder_property->values[0] = 0;
242 disp->underscan_vborder_property->values[1] = 128;
243
Ben Skeggs27d50302011-10-06 12:46:40 +1000244 dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
245 dev->mode_config.fb_base = pci_resource_start(dev->pdev, 1);
246
247 dev->mode_config.min_width = 0;
248 dev->mode_config.min_height = 0;
249 if (dev_priv->card_type < NV_10) {
250 dev->mode_config.max_width = 2048;
251 dev->mode_config.max_height = 2048;
252 } else
253 if (dev_priv->card_type < NV_50) {
254 dev->mode_config.max_width = 4096;
255 dev->mode_config.max_height = 4096;
256 } else {
257 dev->mode_config.max_width = 8192;
258 dev->mode_config.max_height = 8192;
259 }
260
261 ret = disp->create(dev);
262 if (ret)
263 return ret;
264
Ben Skeggs2a44e492011-11-09 11:36:33 +1000265 ret = disp->init(dev);
266 if (ret)
267 disp->destroy(dev);
268 return ret;
Ben Skeggs27d50302011-10-06 12:46:40 +1000269}
270
271void
272nouveau_display_destroy(struct drm_device *dev)
273{
274 struct drm_nouveau_private *dev_priv = dev->dev_private;
275 struct nouveau_display_engine *disp = &dev_priv->engine.display;
276
Ben Skeggs2a44e492011-11-09 11:36:33 +1000277 disp->fini(dev);
Ben Skeggs27d50302011-10-06 12:46:40 +1000278 disp->destroy(dev);
279 drm_mode_config_cleanup(dev);
280}
281
282int
Francisco Jerez042206c2010-10-21 18:19:29 +0200283nouveau_vblank_enable(struct drm_device *dev, int crtc)
284{
285 struct drm_nouveau_private *dev_priv = dev->dev_private;
286
287 if (dev_priv->card_type >= NV_50)
288 nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 0,
289 NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc));
290 else
291 NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0,
292 NV_PCRTC_INTR_0_VBLANK);
293
294 return 0;
295}
296
297void
298nouveau_vblank_disable(struct drm_device *dev, int crtc)
299{
300 struct drm_nouveau_private *dev_priv = dev->dev_private;
301
302 if (dev_priv->card_type >= NV_50)
303 nv_mask(dev, NV50_PDISPLAY_INTR_EN_1,
304 NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc), 0);
305 else
306 NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 0);
307}
Francisco Jerez332b2422010-10-20 23:35:40 +0200308
309static int
310nouveau_page_flip_reserve(struct nouveau_bo *old_bo,
311 struct nouveau_bo *new_bo)
312{
313 int ret;
314
315 ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM);
316 if (ret)
317 return ret;
318
319 ret = ttm_bo_reserve(&new_bo->bo, false, false, false, 0);
320 if (ret)
321 goto fail;
322
323 ret = ttm_bo_reserve(&old_bo->bo, false, false, false, 0);
324 if (ret)
325 goto fail_unreserve;
326
327 return 0;
328
329fail_unreserve:
330 ttm_bo_unreserve(&new_bo->bo);
331fail:
332 nouveau_bo_unpin(new_bo);
333 return ret;
334}
335
336static void
337nouveau_page_flip_unreserve(struct nouveau_bo *old_bo,
338 struct nouveau_bo *new_bo,
339 struct nouveau_fence *fence)
340{
341 nouveau_bo_fence(new_bo, fence);
342 ttm_bo_unreserve(&new_bo->bo);
343
344 nouveau_bo_fence(old_bo, fence);
345 ttm_bo_unreserve(&old_bo->bo);
346
347 nouveau_bo_unpin(old_bo);
348}
349
350static int
351nouveau_page_flip_emit(struct nouveau_channel *chan,
352 struct nouveau_bo *old_bo,
353 struct nouveau_bo *new_bo,
354 struct nouveau_page_flip_state *s,
355 struct nouveau_fence **pfence)
356{
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000357 struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
Francisco Jerez332b2422010-10-20 23:35:40 +0200358 struct drm_device *dev = chan->dev;
359 unsigned long flags;
360 int ret;
361
362 /* Queue it to the pending list */
363 spin_lock_irqsave(&dev->event_lock, flags);
364 list_add_tail(&s->head, &chan->nvsw.flip);
365 spin_unlock_irqrestore(&dev->event_lock, flags);
366
367 /* Synchronize with the old framebuffer */
368 ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan);
369 if (ret)
370 goto fail;
371
372 /* Emit the pageflip */
373 ret = RING_SPACE(chan, 2);
374 if (ret)
375 goto fail;
376
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000377 if (dev_priv->card_type < NV_C0)
378 BEGIN_RING(chan, NvSubSw, NV_SW_PAGE_FLIP, 1);
379 else
380 BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0500, 1);
381 OUT_RING (chan, 0);
382 FIRE_RING (chan);
Francisco Jerez332b2422010-10-20 23:35:40 +0200383
384 ret = nouveau_fence_new(chan, pfence, true);
385 if (ret)
386 goto fail;
387
388 return 0;
389fail:
390 spin_lock_irqsave(&dev->event_lock, flags);
391 list_del(&s->head);
392 spin_unlock_irqrestore(&dev->event_lock, flags);
393 return ret;
394}
395
396int
397nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
398 struct drm_pending_vblank_event *event)
399{
400 struct drm_device *dev = crtc->dev;
401 struct drm_nouveau_private *dev_priv = dev->dev_private;
402 struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->fb)->nvbo;
403 struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo;
404 struct nouveau_page_flip_state *s;
405 struct nouveau_channel *chan;
406 struct nouveau_fence *fence;
407 int ret;
408
Ben Skeggsa82dd492011-04-01 13:56:05 +1000409 if (!dev_priv->channel)
Francisco Jerez332b2422010-10-20 23:35:40 +0200410 return -ENODEV;
411
412 s = kzalloc(sizeof(*s), GFP_KERNEL);
413 if (!s)
414 return -ENOMEM;
415
416 /* Don't let the buffers go away while we flip */
417 ret = nouveau_page_flip_reserve(old_bo, new_bo);
418 if (ret)
419 goto fail_free;
420
421 /* Initialize a page flip struct */
422 *s = (struct nouveau_page_flip_state)
Benjamin Franzke2503c6f2011-02-16 10:04:48 +0100423 { { }, event, nouveau_crtc(crtc)->index,
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200424 fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y,
Francisco Jerez332b2422010-10-20 23:35:40 +0200425 new_bo->bo.offset };
426
427 /* Choose the channel the flip will be handled in */
428 chan = nouveau_fence_channel(new_bo->bo.sync_obj);
429 if (!chan)
430 chan = nouveau_channel_get_unlocked(dev_priv->channel);
431 mutex_lock(&chan->mutex);
432
433 /* Emit a page flip */
Ben Skeggsd7117e02011-02-07 14:27:04 +1000434 if (dev_priv->card_type >= NV_50) {
435 ret = nv50_display_flip_next(crtc, fb, chan);
436 if (ret) {
437 nouveau_channel_put(&chan);
438 goto fail_unreserve;
439 }
440 }
441
Francisco Jerez332b2422010-10-20 23:35:40 +0200442 ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence);
443 nouveau_channel_put(&chan);
444 if (ret)
445 goto fail_unreserve;
446
447 /* Update the crtc struct and cleanup */
448 crtc->fb = fb;
449
450 nouveau_page_flip_unreserve(old_bo, new_bo, fence);
451 nouveau_fence_unref(&fence);
452 return 0;
453
454fail_unreserve:
455 nouveau_page_flip_unreserve(old_bo, new_bo, NULL);
456fail_free:
457 kfree(s);
458 return ret;
459}
460
461int
462nouveau_finish_page_flip(struct nouveau_channel *chan,
463 struct nouveau_page_flip_state *ps)
464{
465 struct drm_device *dev = chan->dev;
466 struct nouveau_page_flip_state *s;
467 unsigned long flags;
468
469 spin_lock_irqsave(&dev->event_lock, flags);
470
471 if (list_empty(&chan->nvsw.flip)) {
472 NV_ERROR(dev, "Unexpected pageflip in channel %d.\n", chan->id);
473 spin_unlock_irqrestore(&dev->event_lock, flags);
474 return -EINVAL;
475 }
476
477 s = list_first_entry(&chan->nvsw.flip,
478 struct nouveau_page_flip_state, head);
479 if (s->event) {
480 struct drm_pending_vblank_event *e = s->event;
481 struct timeval now;
482
483 do_gettimeofday(&now);
484 e->event.sequence = 0;
485 e->event.tv_sec = now.tv_sec;
486 e->event.tv_usec = now.tv_usec;
487 list_add_tail(&e->base.link, &e->base.file_priv->event_list);
488 wake_up_interruptible(&e->base.file_priv->event_wait);
489 }
490
491 list_del(&s->head);
Ben Skeggsd7117e02011-02-07 14:27:04 +1000492 if (ps)
493 *ps = *s;
Francisco Jerez332b2422010-10-20 23:35:40 +0200494 kfree(s);
495
496 spin_unlock_irqrestore(&dev->event_lock, flags);
497 return 0;
498}
Ben Skeggs33dbc272011-09-30 08:55:50 +1000499
500int
501nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
502 struct drm_mode_create_dumb *args)
503{
504 struct nouveau_bo *bo;
505 int ret;
506
507 args->pitch = roundup(args->width * (args->bpp / 8), 256);
508 args->size = args->pitch * args->height;
509 args->size = roundup(args->size, PAGE_SIZE);
510
511 ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo);
512 if (ret)
513 return ret;
514
515 ret = drm_gem_handle_create(file_priv, bo->gem, &args->handle);
516 drm_gem_object_unreference_unlocked(bo->gem);
517 return ret;
518}
519
520int
521nouveau_display_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev,
522 uint32_t handle)
523{
524 return drm_gem_handle_delete(file_priv, handle);
525}
526
527int
528nouveau_display_dumb_map_offset(struct drm_file *file_priv,
529 struct drm_device *dev,
530 uint32_t handle, uint64_t *poffset)
531{
532 struct drm_gem_object *gem;
533
534 gem = drm_gem_object_lookup(dev, file_priv, handle);
535 if (gem) {
536 struct nouveau_bo *bo = gem->driver_private;
537 *poffset = bo->bo.addr_space_offset;
538 drm_gem_object_unreference_unlocked(gem);
539 return 0;
540 }
541
542 return -ENOENT;
543}