2 * Copyright (C) 2008 Maarten Maathuis.
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:
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.
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.
28 #include <drm/drm_crtc_helper.h>
30 #include <nvif/class.h>
32 #include "nouveau_fbcon.h"
33 #include "dispnv04/hw.h"
34 #include "nouveau_crtc.h"
35 #include "nouveau_dma.h"
36 #include "nouveau_gem.h"
37 #include "nouveau_connector.h"
38 #include "nv50_display.h"
40 #include "nouveau_fence.h"
42 #include <nvif/event.h>
45 nouveau_display_vblank_handler(struct nvif_notify *notify)
47 struct nouveau_crtc *nv_crtc =
48 container_of(notify, typeof(*nv_crtc), vblank);
49 drm_handle_vblank(nv_crtc->base.dev, nv_crtc->index);
50 return NVIF_NOTIFY_KEEP;
54 nouveau_display_vblank_enable(struct drm_device *dev, int head)
56 struct drm_crtc *crtc;
57 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
58 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
59 if (nv_crtc->index == head) {
60 nvif_notify_get(&nv_crtc->vblank);
68 nouveau_display_vblank_disable(struct drm_device *dev, int head)
70 struct drm_crtc *crtc;
71 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
72 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
73 if (nv_crtc->index == head) {
74 nvif_notify_put(&nv_crtc->vblank);
81 calc(int blanks, int blanke, int total, int line)
83 if (blanke >= blanks) {
95 nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos,
96 ktime_t *stime, ktime_t *etime)
99 struct nv04_disp_mthd_v0 base;
100 struct nv04_disp_scanoutpos_v0 scan;
102 .base.method = NV04_DISP_SCANOUTPOS,
103 .base.head = nouveau_crtc(crtc)->index,
105 struct nouveau_display *disp = nouveau_display(crtc->dev);
109 ret = nvif_mthd(&disp->disp, 0, &args, sizeof(args));
113 if (args.scan.vline) {
114 ret |= DRM_SCANOUTPOS_ACCURATE;
115 ret |= DRM_SCANOUTPOS_VALID;
119 if (retry) ndelay(crtc->linedur_ns);
122 *hpos = args.scan.hline;
123 *vpos = calc(args.scan.vblanks, args.scan.vblanke,
124 args.scan.vtotal, args.scan.vline);
125 if (stime) *stime = ns_to_ktime(args.scan.time[0]);
126 if (etime) *etime = ns_to_ktime(args.scan.time[1]);
129 ret |= DRM_SCANOUTPOS_IN_VBLANK;
134 nouveau_display_scanoutpos(struct drm_device *dev, int head, unsigned int flags,
135 int *vpos, int *hpos, ktime_t *stime, ktime_t *etime)
137 struct drm_crtc *crtc;
139 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
140 if (nouveau_crtc(crtc)->index == head) {
141 return nouveau_display_scanoutpos_head(crtc, vpos, hpos,
150 nouveau_display_vblstamp(struct drm_device *dev, int head, int *max_error,
151 struct timeval *time, unsigned flags)
153 struct drm_crtc *crtc;
155 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
156 if (nouveau_crtc(crtc)->index == head) {
157 return drm_calc_vbltimestamp_from_scanoutpos(dev,
158 head, max_error, time, flags, crtc,
167 nouveau_display_vblank_fini(struct drm_device *dev)
169 struct drm_crtc *crtc;
171 drm_vblank_cleanup(dev);
173 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
174 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
175 nvif_notify_fini(&nv_crtc->vblank);
180 nouveau_display_vblank_init(struct drm_device *dev)
182 struct nouveau_display *disp = nouveau_display(dev);
183 struct drm_crtc *crtc;
186 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
187 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
188 ret = nvif_notify_init(&disp->disp,
189 nouveau_display_vblank_handler, false,
190 NV04_DISP_NTFY_VBLANK,
191 &(struct nvif_notify_head_req_v0) {
192 .head = nv_crtc->index,
194 sizeof(struct nvif_notify_head_req_v0),
195 sizeof(struct nvif_notify_head_rep_v0),
198 nouveau_display_vblank_fini(dev);
203 ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
205 nouveau_display_vblank_fini(dev);
213 nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
215 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
216 struct nouveau_display *disp = nouveau_display(drm_fb->dev);
219 disp->fb_dtor(drm_fb);
222 drm_gem_object_unreference_unlocked(&fb->nvbo->gem);
224 drm_framebuffer_cleanup(drm_fb);
229 nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
230 struct drm_file *file_priv,
231 unsigned int *handle)
233 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
235 return drm_gem_handle_create(file_priv, &fb->nvbo->gem, handle);
238 static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
239 .destroy = nouveau_user_framebuffer_destroy,
240 .create_handle = nouveau_user_framebuffer_create_handle,
244 nouveau_framebuffer_init(struct drm_device *dev,
245 struct nouveau_framebuffer *nv_fb,
246 struct drm_mode_fb_cmd2 *mode_cmd,
247 struct nouveau_bo *nvbo)
249 struct nouveau_display *disp = nouveau_display(dev);
250 struct drm_framebuffer *fb = &nv_fb->base;
253 drm_helper_mode_fill_fb_struct(fb, mode_cmd);
256 ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs);
261 ret = disp->fb_ctor(fb);
269 static struct drm_framebuffer *
270 nouveau_user_framebuffer_create(struct drm_device *dev,
271 struct drm_file *file_priv,
272 struct drm_mode_fb_cmd2 *mode_cmd)
274 struct nouveau_framebuffer *nouveau_fb;
275 struct drm_gem_object *gem;
278 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]);
280 return ERR_PTR(-ENOENT);
282 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
286 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
290 return &nouveau_fb->base;
295 drm_gem_object_unreference(gem);
299 static const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
300 .fb_create = nouveau_user_framebuffer_create,
301 .output_poll_changed = nouveau_fbcon_output_poll_changed,
305 struct nouveau_drm_prop_enum_list {
311 static struct nouveau_drm_prop_enum_list underscan[] = {
312 { 6, UNDERSCAN_AUTO, "auto" },
313 { 6, UNDERSCAN_OFF, "off" },
314 { 6, UNDERSCAN_ON, "on" },
318 static struct nouveau_drm_prop_enum_list dither_mode[] = {
319 { 7, DITHERING_MODE_AUTO, "auto" },
320 { 7, DITHERING_MODE_OFF, "off" },
321 { 1, DITHERING_MODE_ON, "on" },
322 { 6, DITHERING_MODE_STATIC2X2, "static 2x2" },
323 { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" },
324 { 4, DITHERING_MODE_TEMPORAL, "temporal" },
328 static struct nouveau_drm_prop_enum_list dither_depth[] = {
329 { 6, DITHERING_DEPTH_AUTO, "auto" },
330 { 6, DITHERING_DEPTH_6BPC, "6 bpc" },
331 { 6, DITHERING_DEPTH_8BPC, "8 bpc" },
335 #define PROP_ENUM(p,gen,n,list) do { \
336 struct nouveau_drm_prop_enum_list *l = (list); \
338 while (l->gen_mask) { \
339 if (l->gen_mask & (1 << (gen))) \
344 p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \
347 while (p && l->gen_mask) { \
348 if (l->gen_mask & (1 << (gen))) { \
349 drm_property_add_enum(p, c, l->type, l->name); \
358 nouveau_display_init(struct drm_device *dev)
360 struct nouveau_display *disp = nouveau_display(dev);
361 struct nouveau_drm *drm = nouveau_drm(dev);
362 struct drm_connector *connector;
365 ret = disp->init(dev);
369 /* enable polling for external displays */
370 drm_kms_helper_poll_enable(dev);
372 /* enable hotplug interrupts */
373 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
374 struct nouveau_connector *conn = nouveau_connector(connector);
375 nvif_notify_get(&conn->hpd);
378 /* enable flip completion events */
379 nvif_notify_get(&drm->flip);
384 nouveau_display_fini(struct drm_device *dev)
386 struct nouveau_display *disp = nouveau_display(dev);
387 struct nouveau_drm *drm = nouveau_drm(dev);
388 struct drm_connector *connector;
391 /* Make sure that drm and hw vblank irqs get properly disabled. */
392 for (head = 0; head < dev->mode_config.num_crtc; head++)
393 drm_vblank_off(dev, head);
395 /* disable flip completion events */
396 nvif_notify_put(&drm->flip);
398 /* disable hotplug interrupts */
399 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
400 struct nouveau_connector *conn = nouveau_connector(connector);
401 nvif_notify_put(&conn->hpd);
404 drm_kms_helper_poll_disable(dev);
409 nouveau_display_create_properties(struct drm_device *dev)
411 struct nouveau_display *disp = nouveau_display(dev);
414 if (disp->disp.oclass < NV50_DISP)
417 if (disp->disp.oclass < GF110_DISP)
422 PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode);
423 PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth);
424 PROP_ENUM(disp->underscan_property, gen, "underscan", underscan);
426 disp->underscan_hborder_property =
427 drm_property_create_range(dev, 0, "underscan hborder", 0, 128);
429 disp->underscan_vborder_property =
430 drm_property_create_range(dev, 0, "underscan vborder", 0, 128);
436 disp->vibrant_hue_property =
437 drm_property_create_range(dev, 0, "vibrant hue", 0, 180);
440 disp->color_vibrance_property =
441 drm_property_create_range(dev, 0, "color vibrance", 0, 200);
445 nouveau_display_create(struct drm_device *dev)
447 struct nouveau_drm *drm = nouveau_drm(dev);
448 struct nvkm_device *device = nvxx_device(&drm->device);
449 struct nouveau_display *disp;
452 disp = drm->display = kzalloc(sizeof(*disp), GFP_KERNEL);
456 drm_mode_config_init(dev);
457 drm_mode_create_scaling_mode_property(dev);
458 drm_mode_create_dvi_i_properties(dev);
460 dev->mode_config.funcs = &nouveau_mode_config_funcs;
461 dev->mode_config.fb_base = device->func->resource_addr(device, 1);
463 dev->mode_config.min_width = 0;
464 dev->mode_config.min_height = 0;
465 if (drm->device.info.family < NV_DEVICE_INFO_V0_CELSIUS) {
466 dev->mode_config.max_width = 2048;
467 dev->mode_config.max_height = 2048;
469 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
470 dev->mode_config.max_width = 4096;
471 dev->mode_config.max_height = 4096;
473 dev->mode_config.max_width = 8192;
474 dev->mode_config.max_height = 8192;
477 dev->mode_config.preferred_depth = 24;
478 dev->mode_config.prefer_shadow = 1;
480 if (drm->device.info.chipset < 0x11)
481 dev->mode_config.async_page_flip = false;
483 dev->mode_config.async_page_flip = true;
485 drm_kms_helper_poll_init(dev);
486 drm_kms_helper_poll_disable(dev);
488 if (nouveau_modeset != 2 && drm->vbios.dcb.entries) {
489 static const u16 oclass[] = {
504 for (i = 0, ret = -ENODEV; ret && i < ARRAY_SIZE(oclass); i++) {
505 ret = nvif_object_init(&drm->device.object,
506 NVDRM_DISPLAY, oclass[i],
507 NULL, 0, &disp->disp);
511 nouveau_display_create_properties(dev);
512 if (disp->disp.oclass < NV50_DISP)
513 ret = nv04_display_create(dev);
515 ret = nv50_display_create(dev);
522 goto disp_create_err;
524 if (dev->mode_config.num_crtc) {
525 ret = nouveau_display_vblank_init(dev);
530 nouveau_backlight_init(dev);
536 drm_kms_helper_poll_fini(dev);
537 drm_mode_config_cleanup(dev);
542 nouveau_display_destroy(struct drm_device *dev)
544 struct nouveau_display *disp = nouveau_display(dev);
546 nouveau_backlight_exit(dev);
547 nouveau_display_vblank_fini(dev);
549 drm_kms_helper_poll_fini(dev);
550 drm_mode_config_cleanup(dev);
555 nvif_object_fini(&disp->disp);
557 nouveau_drm(dev)->display = NULL;
562 nouveau_display_suspend(struct drm_device *dev, bool runtime)
564 struct drm_crtc *crtc;
566 nouveau_display_fini(dev);
568 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
569 struct nouveau_framebuffer *nouveau_fb;
571 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
572 if (!nouveau_fb || !nouveau_fb->nvbo)
575 nouveau_bo_unpin(nouveau_fb->nvbo);
578 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
579 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
580 if (nv_crtc->cursor.nvbo) {
581 if (nv_crtc->cursor.set_offset)
582 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
583 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
591 nouveau_display_resume(struct drm_device *dev, bool runtime)
593 struct nouveau_drm *drm = nouveau_drm(dev);
594 struct drm_crtc *crtc;
597 /* re-pin fb/cursors */
598 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
599 struct nouveau_framebuffer *nouveau_fb;
601 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
602 if (!nouveau_fb || !nouveau_fb->nvbo)
605 ret = nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM, true);
607 NV_ERROR(drm, "Could not pin framebuffer\n");
610 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
611 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
612 if (!nv_crtc->cursor.nvbo)
615 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM, true);
616 if (!ret && nv_crtc->cursor.set_offset)
617 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
619 NV_ERROR(drm, "Could not pin/map cursor.\n");
622 nouveau_display_init(dev);
624 /* Force CLUT to get re-loaded during modeset */
625 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
626 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
628 nv_crtc->lut.depth = 0;
631 /* Make sure that drm and hw vblank irqs get resumed if needed. */
632 for (head = 0; head < dev->mode_config.num_crtc; head++)
633 drm_vblank_on(dev, head);
635 /* This should ensure we don't hit a locking problem when someone
636 * wakes us up via a connector. We should never go into suspend
637 * while the display is on anyways.
642 drm_helper_resume_force_mode(dev);
644 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
645 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
647 if (!nv_crtc->cursor.nvbo)
650 if (nv_crtc->cursor.set_offset)
651 nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.nvbo->bo.offset);
652 nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
653 nv_crtc->cursor_saved_y);
658 nouveau_page_flip_emit(struct nouveau_channel *chan,
659 struct nouveau_bo *old_bo,
660 struct nouveau_bo *new_bo,
661 struct nouveau_page_flip_state *s,
662 struct nouveau_fence **pfence)
664 struct nouveau_fence_chan *fctx = chan->fence;
665 struct nouveau_drm *drm = chan->drm;
666 struct drm_device *dev = drm->dev;
670 /* Queue it to the pending list */
671 spin_lock_irqsave(&dev->event_lock, flags);
672 list_add_tail(&s->head, &fctx->flip);
673 spin_unlock_irqrestore(&dev->event_lock, flags);
675 /* Synchronize with the old framebuffer */
676 ret = nouveau_fence_sync(old_bo, chan, false, false);
680 /* Emit the pageflip */
681 ret = RING_SPACE(chan, 2);
685 if (drm->device.info.family < NV_DEVICE_INFO_V0_FERMI)
686 BEGIN_NV04(chan, NvSubSw, NV_SW_PAGE_FLIP, 1);
688 BEGIN_NVC0(chan, FermiSw, NV_SW_PAGE_FLIP, 1);
689 OUT_RING (chan, 0x00000000);
692 ret = nouveau_fence_new(chan, false, pfence);
698 spin_lock_irqsave(&dev->event_lock, flags);
700 spin_unlock_irqrestore(&dev->event_lock, flags);
705 nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
706 struct drm_pending_vblank_event *event, u32 flags)
708 const int swap_interval = (flags & DRM_MODE_PAGE_FLIP_ASYNC) ? 0 : 1;
709 struct drm_device *dev = crtc->dev;
710 struct nouveau_drm *drm = nouveau_drm(dev);
711 struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->primary->fb)->nvbo;
712 struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo;
713 struct nouveau_page_flip_state *s;
714 struct nouveau_channel *chan;
715 struct nouveau_cli *cli;
716 struct nouveau_fence *fence;
722 cli = (void *)chan->user.client;
724 s = kzalloc(sizeof(*s), GFP_KERNEL);
728 if (new_bo != old_bo) {
729 ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM, true);
734 mutex_lock(&cli->mutex);
735 ret = ttm_bo_reserve(&new_bo->bo, true, false, false, NULL);
739 /* synchronise rendering channel with the kernel's channel */
740 ret = nouveau_fence_sync(new_bo, chan, false, true);
742 ttm_bo_unreserve(&new_bo->bo);
746 if (new_bo != old_bo) {
747 ttm_bo_unreserve(&new_bo->bo);
749 ret = ttm_bo_reserve(&old_bo->bo, true, false, false, NULL);
754 /* Initialize a page flip struct */
755 *s = (struct nouveau_page_flip_state)
756 { { }, event, nouveau_crtc(crtc)->index,
757 fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y,
760 /* Keep vblanks on during flip, for the target crtc of this flip */
761 drm_vblank_get(dev, nouveau_crtc(crtc)->index);
763 /* Emit a page flip */
764 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
765 ret = nv50_display_flip_next(crtc, fb, chan, swap_interval);
769 struct nv04_display *dispnv04 = nv04_display(dev);
770 int head = nouveau_crtc(crtc)->index;
773 ret = RING_SPACE(chan, 8);
777 BEGIN_NV04(chan, NvSubImageBlit, 0x012c, 1);
779 BEGIN_NV04(chan, NvSubImageBlit, 0x0134, 1);
780 OUT_RING (chan, head);
781 BEGIN_NV04(chan, NvSubImageBlit, 0x0100, 1);
783 BEGIN_NV04(chan, NvSubImageBlit, 0x0130, 1);
787 nouveau_bo_ref(new_bo, &dispnv04->image[head]);
790 ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence);
793 mutex_unlock(&cli->mutex);
795 /* Update the crtc struct and cleanup */
796 crtc->primary->fb = fb;
798 nouveau_bo_fence(old_bo, fence, false);
799 ttm_bo_unreserve(&old_bo->bo);
800 if (old_bo != new_bo)
801 nouveau_bo_unpin(old_bo);
802 nouveau_fence_unref(&fence);
806 drm_vblank_put(dev, nouveau_crtc(crtc)->index);
807 ttm_bo_unreserve(&old_bo->bo);
809 mutex_unlock(&cli->mutex);
810 if (old_bo != new_bo)
811 nouveau_bo_unpin(new_bo);
818 nouveau_finish_page_flip(struct nouveau_channel *chan,
819 struct nouveau_page_flip_state *ps)
821 struct nouveau_fence_chan *fctx = chan->fence;
822 struct nouveau_drm *drm = chan->drm;
823 struct drm_device *dev = drm->dev;
824 struct nouveau_page_flip_state *s;
828 spin_lock_irqsave(&dev->event_lock, flags);
830 if (list_empty(&fctx->flip)) {
831 NV_ERROR(drm, "unexpected pageflip\n");
832 spin_unlock_irqrestore(&dev->event_lock, flags);
836 s = list_first_entry(&fctx->flip, struct nouveau_page_flip_state, head);
838 /* Vblank timestamps/counts are only correct on >= NV-50 */
839 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
842 drm_send_vblank_event(dev, crtcid, s->event);
845 /* Give up ownership of vblank for page-flipped crtc */
846 drm_vblank_put(dev, s->crtc);
853 spin_unlock_irqrestore(&dev->event_lock, flags);
858 nouveau_flip_complete(struct nvif_notify *notify)
860 struct nouveau_drm *drm = container_of(notify, typeof(*drm), flip);
861 struct nouveau_channel *chan = drm->channel;
862 struct nouveau_page_flip_state state;
864 if (!nouveau_finish_page_flip(chan, &state)) {
865 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
866 nv_set_crtc_base(drm->dev, state.crtc, state.offset +
867 state.y * state.pitch +
868 state.x * state.bpp / 8);
872 return NVIF_NOTIFY_KEEP;
876 nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
877 struct drm_mode_create_dumb *args)
879 struct nouveau_bo *bo;
883 args->pitch = roundup(args->width * (args->bpp / 8), 256);
884 args->size = args->pitch * args->height;
885 args->size = roundup(args->size, PAGE_SIZE);
887 /* Use VRAM if there is any ; otherwise fallback to system memory */
888 if (nouveau_drm(dev)->device.info.ram_size != 0)
889 domain = NOUVEAU_GEM_DOMAIN_VRAM;
891 domain = NOUVEAU_GEM_DOMAIN_GART;
893 ret = nouveau_gem_new(dev, args->size, 0, domain, 0, 0, &bo);
897 ret = drm_gem_handle_create(file_priv, &bo->gem, &args->handle);
898 drm_gem_object_unreference_unlocked(&bo->gem);
903 nouveau_display_dumb_map_offset(struct drm_file *file_priv,
904 struct drm_device *dev,
905 uint32_t handle, uint64_t *poffset)
907 struct drm_gem_object *gem;
909 gem = drm_gem_object_lookup(dev, file_priv, handle);
911 struct nouveau_bo *bo = nouveau_gem_object(gem);
912 *poffset = drm_vma_node_offset_addr(&bo->bo.vma_node);
913 drm_gem_object_unreference_unlocked(gem);