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, unsigned int pipe)
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 == pipe) {
60 nvif_notify_get(&nv_crtc->vblank);
68 nouveau_display_vblank_disable(struct drm_device *dev, unsigned int pipe)
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 == pipe) {
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);
106 struct drm_vblank_crtc *vblank = &crtc->dev->vblank[drm_crtc_index(crtc)];
110 ret = nvif_mthd(&disp->disp, 0, &args, sizeof(args));
114 if (args.scan.vline) {
115 ret |= DRM_SCANOUTPOS_ACCURATE;
116 ret |= DRM_SCANOUTPOS_VALID;
120 if (retry) ndelay(vblank->linedur_ns);
123 *hpos = args.scan.hline;
124 *vpos = calc(args.scan.vblanks, args.scan.vblanke,
125 args.scan.vtotal, args.scan.vline);
126 if (stime) *stime = ns_to_ktime(args.scan.time[0]);
127 if (etime) *etime = ns_to_ktime(args.scan.time[1]);
130 ret |= DRM_SCANOUTPOS_IN_VBLANK;
135 nouveau_display_scanoutpos(struct drm_device *dev, unsigned int pipe,
136 unsigned int flags, int *vpos, int *hpos,
137 ktime_t *stime, ktime_t *etime,
138 const struct drm_display_mode *mode)
140 struct drm_crtc *crtc;
142 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
143 if (nouveau_crtc(crtc)->index == pipe) {
144 return nouveau_display_scanoutpos_head(crtc, vpos, hpos,
153 nouveau_display_vblstamp(struct drm_device *dev, unsigned int pipe,
154 int *max_error, struct timeval *time, unsigned flags)
156 struct drm_crtc *crtc;
158 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
159 if (nouveau_crtc(crtc)->index == pipe) {
160 return drm_calc_vbltimestamp_from_scanoutpos(dev,
161 pipe, max_error, time, flags,
170 nouveau_display_vblank_fini(struct drm_device *dev)
172 struct drm_crtc *crtc;
174 drm_vblank_cleanup(dev);
176 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
177 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
178 nvif_notify_fini(&nv_crtc->vblank);
183 nouveau_display_vblank_init(struct drm_device *dev)
185 struct nouveau_display *disp = nouveau_display(dev);
186 struct drm_crtc *crtc;
189 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
190 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
191 ret = nvif_notify_init(&disp->disp,
192 nouveau_display_vblank_handler, false,
193 NV04_DISP_NTFY_VBLANK,
194 &(struct nvif_notify_head_req_v0) {
195 .head = nv_crtc->index,
197 sizeof(struct nvif_notify_head_req_v0),
198 sizeof(struct nvif_notify_head_rep_v0),
201 nouveau_display_vblank_fini(dev);
206 ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
208 nouveau_display_vblank_fini(dev);
216 nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
218 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
219 struct nouveau_display *disp = nouveau_display(drm_fb->dev);
222 disp->fb_dtor(drm_fb);
225 drm_gem_object_unreference_unlocked(&fb->nvbo->gem);
227 drm_framebuffer_cleanup(drm_fb);
232 nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
233 struct drm_file *file_priv,
234 unsigned int *handle)
236 struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb);
238 return drm_gem_handle_create(file_priv, &fb->nvbo->gem, handle);
241 static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
242 .destroy = nouveau_user_framebuffer_destroy,
243 .create_handle = nouveau_user_framebuffer_create_handle,
247 nouveau_framebuffer_init(struct drm_device *dev,
248 struct nouveau_framebuffer *nv_fb,
249 struct drm_mode_fb_cmd2 *mode_cmd,
250 struct nouveau_bo *nvbo)
252 struct nouveau_display *disp = nouveau_display(dev);
253 struct drm_framebuffer *fb = &nv_fb->base;
256 drm_helper_mode_fill_fb_struct(fb, mode_cmd);
259 ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs);
264 ret = disp->fb_ctor(fb);
272 static struct drm_framebuffer *
273 nouveau_user_framebuffer_create(struct drm_device *dev,
274 struct drm_file *file_priv,
275 struct drm_mode_fb_cmd2 *mode_cmd)
277 struct nouveau_framebuffer *nouveau_fb;
278 struct drm_gem_object *gem;
281 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]);
283 return ERR_PTR(-ENOENT);
285 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
289 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
293 return &nouveau_fb->base;
298 drm_gem_object_unreference(gem);
302 static const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
303 .fb_create = nouveau_user_framebuffer_create,
304 .output_poll_changed = nouveau_fbcon_output_poll_changed,
308 struct nouveau_drm_prop_enum_list {
314 static struct nouveau_drm_prop_enum_list underscan[] = {
315 { 6, UNDERSCAN_AUTO, "auto" },
316 { 6, UNDERSCAN_OFF, "off" },
317 { 6, UNDERSCAN_ON, "on" },
321 static struct nouveau_drm_prop_enum_list dither_mode[] = {
322 { 7, DITHERING_MODE_AUTO, "auto" },
323 { 7, DITHERING_MODE_OFF, "off" },
324 { 1, DITHERING_MODE_ON, "on" },
325 { 6, DITHERING_MODE_STATIC2X2, "static 2x2" },
326 { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" },
327 { 4, DITHERING_MODE_TEMPORAL, "temporal" },
331 static struct nouveau_drm_prop_enum_list dither_depth[] = {
332 { 6, DITHERING_DEPTH_AUTO, "auto" },
333 { 6, DITHERING_DEPTH_6BPC, "6 bpc" },
334 { 6, DITHERING_DEPTH_8BPC, "8 bpc" },
338 #define PROP_ENUM(p,gen,n,list) do { \
339 struct nouveau_drm_prop_enum_list *l = (list); \
341 while (l->gen_mask) { \
342 if (l->gen_mask & (1 << (gen))) \
347 p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \
350 while (p && l->gen_mask) { \
351 if (l->gen_mask & (1 << (gen))) { \
352 drm_property_add_enum(p, c, l->type, l->name); \
361 nouveau_display_init(struct drm_device *dev)
363 struct nouveau_display *disp = nouveau_display(dev);
364 struct nouveau_drm *drm = nouveau_drm(dev);
365 struct drm_connector *connector;
368 ret = disp->init(dev);
372 /* enable polling for external displays */
373 drm_kms_helper_poll_enable(dev);
375 /* enable hotplug interrupts */
376 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
377 struct nouveau_connector *conn = nouveau_connector(connector);
378 nvif_notify_get(&conn->hpd);
381 /* enable flip completion events */
382 nvif_notify_get(&drm->flip);
387 nouveau_display_fini(struct drm_device *dev)
389 struct nouveau_display *disp = nouveau_display(dev);
390 struct nouveau_drm *drm = nouveau_drm(dev);
391 struct drm_connector *connector;
394 /* Make sure that drm and hw vblank irqs get properly disabled. */
395 for (head = 0; head < dev->mode_config.num_crtc; head++)
396 drm_vblank_off(dev, head);
398 /* disable flip completion events */
399 nvif_notify_put(&drm->flip);
401 /* disable hotplug interrupts */
402 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
403 struct nouveau_connector *conn = nouveau_connector(connector);
404 nvif_notify_put(&conn->hpd);
407 drm_kms_helper_poll_disable(dev);
412 nouveau_display_create_properties(struct drm_device *dev)
414 struct nouveau_display *disp = nouveau_display(dev);
417 if (disp->disp.oclass < NV50_DISP)
420 if (disp->disp.oclass < GF110_DISP)
425 PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode);
426 PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth);
427 PROP_ENUM(disp->underscan_property, gen, "underscan", underscan);
429 disp->underscan_hborder_property =
430 drm_property_create_range(dev, 0, "underscan hborder", 0, 128);
432 disp->underscan_vborder_property =
433 drm_property_create_range(dev, 0, "underscan vborder", 0, 128);
439 disp->vibrant_hue_property =
440 drm_property_create_range(dev, 0, "vibrant hue", 0, 180);
443 disp->color_vibrance_property =
444 drm_property_create_range(dev, 0, "color vibrance", 0, 200);
448 nouveau_display_create(struct drm_device *dev)
450 struct nouveau_drm *drm = nouveau_drm(dev);
451 struct nvkm_device *device = nvxx_device(&drm->device);
452 struct nouveau_display *disp;
455 disp = drm->display = kzalloc(sizeof(*disp), GFP_KERNEL);
459 drm_mode_config_init(dev);
460 drm_mode_create_scaling_mode_property(dev);
461 drm_mode_create_dvi_i_properties(dev);
463 dev->mode_config.funcs = &nouveau_mode_config_funcs;
464 dev->mode_config.fb_base = device->func->resource_addr(device, 1);
466 dev->mode_config.min_width = 0;
467 dev->mode_config.min_height = 0;
468 if (drm->device.info.family < NV_DEVICE_INFO_V0_CELSIUS) {
469 dev->mode_config.max_width = 2048;
470 dev->mode_config.max_height = 2048;
472 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
473 dev->mode_config.max_width = 4096;
474 dev->mode_config.max_height = 4096;
476 if (drm->device.info.family < NV_DEVICE_INFO_V0_FERMI) {
477 dev->mode_config.max_width = 8192;
478 dev->mode_config.max_height = 8192;
480 dev->mode_config.max_width = 16384;
481 dev->mode_config.max_height = 16384;
484 dev->mode_config.preferred_depth = 24;
485 dev->mode_config.prefer_shadow = 1;
487 if (drm->device.info.chipset < 0x11)
488 dev->mode_config.async_page_flip = false;
490 dev->mode_config.async_page_flip = true;
492 drm_kms_helper_poll_init(dev);
493 drm_kms_helper_poll_disable(dev);
495 if (nouveau_modeset != 2 && drm->vbios.dcb.entries) {
496 static const u16 oclass[] = {
511 for (i = 0, ret = -ENODEV; ret && i < ARRAY_SIZE(oclass); i++) {
512 ret = nvif_object_init(&drm->device.object, 0,
513 oclass[i], NULL, 0, &disp->disp);
517 nouveau_display_create_properties(dev);
518 if (disp->disp.oclass < NV50_DISP)
519 ret = nv04_display_create(dev);
521 ret = nv50_display_create(dev);
528 goto disp_create_err;
530 if (dev->mode_config.num_crtc) {
531 ret = nouveau_display_vblank_init(dev);
536 nouveau_backlight_init(dev);
542 drm_kms_helper_poll_fini(dev);
543 drm_mode_config_cleanup(dev);
548 nouveau_display_destroy(struct drm_device *dev)
550 struct nouveau_display *disp = nouveau_display(dev);
552 nouveau_backlight_exit(dev);
553 nouveau_display_vblank_fini(dev);
555 drm_kms_helper_poll_fini(dev);
556 drm_mode_config_cleanup(dev);
561 nvif_object_fini(&disp->disp);
563 nouveau_drm(dev)->display = NULL;
568 nouveau_display_suspend(struct drm_device *dev, bool runtime)
570 struct drm_crtc *crtc;
572 nouveau_display_fini(dev);
574 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
575 struct nouveau_framebuffer *nouveau_fb;
577 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
578 if (!nouveau_fb || !nouveau_fb->nvbo)
581 nouveau_bo_unpin(nouveau_fb->nvbo);
584 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
585 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
586 if (nv_crtc->cursor.nvbo) {
587 if (nv_crtc->cursor.set_offset)
588 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
589 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
597 nouveau_display_resume(struct drm_device *dev, bool runtime)
599 struct nouveau_drm *drm = nouveau_drm(dev);
600 struct drm_crtc *crtc;
603 /* re-pin fb/cursors */
604 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
605 struct nouveau_framebuffer *nouveau_fb;
607 nouveau_fb = nouveau_framebuffer(crtc->primary->fb);
608 if (!nouveau_fb || !nouveau_fb->nvbo)
611 ret = nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM, true);
613 NV_ERROR(drm, "Could not pin framebuffer\n");
616 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
617 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
618 if (!nv_crtc->cursor.nvbo)
621 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM, true);
622 if (!ret && nv_crtc->cursor.set_offset)
623 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
625 NV_ERROR(drm, "Could not pin/map cursor.\n");
628 nouveau_display_init(dev);
630 /* Force CLUT to get re-loaded during modeset */
631 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
632 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
634 nv_crtc->lut.depth = 0;
637 /* Make sure that drm and hw vblank irqs get resumed if needed. */
638 for (head = 0; head < dev->mode_config.num_crtc; head++)
639 drm_vblank_on(dev, head);
641 /* This should ensure we don't hit a locking problem when someone
642 * wakes us up via a connector. We should never go into suspend
643 * while the display is on anyways.
648 drm_helper_resume_force_mode(dev);
650 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
651 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
653 if (!nv_crtc->cursor.nvbo)
656 if (nv_crtc->cursor.set_offset)
657 nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.nvbo->bo.offset);
658 nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
659 nv_crtc->cursor_saved_y);
664 nouveau_page_flip_emit(struct nouveau_channel *chan,
665 struct nouveau_bo *old_bo,
666 struct nouveau_bo *new_bo,
667 struct nouveau_page_flip_state *s,
668 struct nouveau_fence **pfence)
670 struct nouveau_fence_chan *fctx = chan->fence;
671 struct nouveau_drm *drm = chan->drm;
672 struct drm_device *dev = drm->dev;
676 /* Queue it to the pending list */
677 spin_lock_irqsave(&dev->event_lock, flags);
678 list_add_tail(&s->head, &fctx->flip);
679 spin_unlock_irqrestore(&dev->event_lock, flags);
681 /* Synchronize with the old framebuffer */
682 ret = nouveau_fence_sync(old_bo, chan, false, false);
686 /* Emit the pageflip */
687 ret = RING_SPACE(chan, 2);
691 if (drm->device.info.family < NV_DEVICE_INFO_V0_FERMI)
692 BEGIN_NV04(chan, NvSubSw, NV_SW_PAGE_FLIP, 1);
694 BEGIN_NVC0(chan, FermiSw, NV_SW_PAGE_FLIP, 1);
695 OUT_RING (chan, 0x00000000);
698 ret = nouveau_fence_new(chan, false, pfence);
704 spin_lock_irqsave(&dev->event_lock, flags);
706 spin_unlock_irqrestore(&dev->event_lock, flags);
711 nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
712 struct drm_pending_vblank_event *event, u32 flags)
714 const int swap_interval = (flags & DRM_MODE_PAGE_FLIP_ASYNC) ? 0 : 1;
715 struct drm_device *dev = crtc->dev;
716 struct nouveau_drm *drm = nouveau_drm(dev);
717 struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->primary->fb)->nvbo;
718 struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo;
719 struct nouveau_page_flip_state *s;
720 struct nouveau_channel *chan;
721 struct nouveau_cli *cli;
722 struct nouveau_fence *fence;
728 cli = (void *)chan->user.client;
730 s = kzalloc(sizeof(*s), GFP_KERNEL);
734 if (new_bo != old_bo) {
735 ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM, true);
740 mutex_lock(&cli->mutex);
741 ret = ttm_bo_reserve(&new_bo->bo, true, false, false, NULL);
745 /* synchronise rendering channel with the kernel's channel */
746 ret = nouveau_fence_sync(new_bo, chan, false, true);
748 ttm_bo_unreserve(&new_bo->bo);
752 if (new_bo != old_bo) {
753 ttm_bo_unreserve(&new_bo->bo);
755 ret = ttm_bo_reserve(&old_bo->bo, true, false, false, NULL);
760 /* Initialize a page flip struct */
761 *s = (struct nouveau_page_flip_state)
762 { { }, event, nouveau_crtc(crtc)->index,
763 fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y,
766 /* Keep vblanks on during flip, for the target crtc of this flip */
767 drm_vblank_get(dev, nouveau_crtc(crtc)->index);
769 /* Emit a page flip */
770 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
771 ret = nv50_display_flip_next(crtc, fb, chan, swap_interval);
775 struct nv04_display *dispnv04 = nv04_display(dev);
776 int head = nouveau_crtc(crtc)->index;
779 ret = RING_SPACE(chan, 8);
783 BEGIN_NV04(chan, NvSubImageBlit, 0x012c, 1);
785 BEGIN_NV04(chan, NvSubImageBlit, 0x0134, 1);
786 OUT_RING (chan, head);
787 BEGIN_NV04(chan, NvSubImageBlit, 0x0100, 1);
789 BEGIN_NV04(chan, NvSubImageBlit, 0x0130, 1);
793 nouveau_bo_ref(new_bo, &dispnv04->image[head]);
796 ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence);
799 mutex_unlock(&cli->mutex);
801 /* Update the crtc struct and cleanup */
802 crtc->primary->fb = fb;
804 nouveau_bo_fence(old_bo, fence, false);
805 ttm_bo_unreserve(&old_bo->bo);
806 if (old_bo != new_bo)
807 nouveau_bo_unpin(old_bo);
808 nouveau_fence_unref(&fence);
812 drm_vblank_put(dev, nouveau_crtc(crtc)->index);
813 ttm_bo_unreserve(&old_bo->bo);
815 mutex_unlock(&cli->mutex);
816 if (old_bo != new_bo)
817 nouveau_bo_unpin(new_bo);
824 nouveau_finish_page_flip(struct nouveau_channel *chan,
825 struct nouveau_page_flip_state *ps)
827 struct nouveau_fence_chan *fctx = chan->fence;
828 struct nouveau_drm *drm = chan->drm;
829 struct drm_device *dev = drm->dev;
830 struct nouveau_page_flip_state *s;
834 spin_lock_irqsave(&dev->event_lock, flags);
836 if (list_empty(&fctx->flip)) {
837 NV_ERROR(drm, "unexpected pageflip\n");
838 spin_unlock_irqrestore(&dev->event_lock, flags);
842 s = list_first_entry(&fctx->flip, struct nouveau_page_flip_state, head);
844 /* Vblank timestamps/counts are only correct on >= NV-50 */
845 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
848 drm_send_vblank_event(dev, crtcid, s->event);
851 /* Give up ownership of vblank for page-flipped crtc */
852 drm_vblank_put(dev, s->crtc);
859 spin_unlock_irqrestore(&dev->event_lock, flags);
864 nouveau_flip_complete(struct nvif_notify *notify)
866 struct nouveau_drm *drm = container_of(notify, typeof(*drm), flip);
867 struct nouveau_channel *chan = drm->channel;
868 struct nouveau_page_flip_state state;
870 if (!nouveau_finish_page_flip(chan, &state)) {
871 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
872 nv_set_crtc_base(drm->dev, state.crtc, state.offset +
873 state.y * state.pitch +
874 state.x * state.bpp / 8);
878 return NVIF_NOTIFY_KEEP;
882 nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
883 struct drm_mode_create_dumb *args)
885 struct nouveau_bo *bo;
889 args->pitch = roundup(args->width * (args->bpp / 8), 256);
890 args->size = args->pitch * args->height;
891 args->size = roundup(args->size, PAGE_SIZE);
893 /* Use VRAM if there is any ; otherwise fallback to system memory */
894 if (nouveau_drm(dev)->device.info.ram_size != 0)
895 domain = NOUVEAU_GEM_DOMAIN_VRAM;
897 domain = NOUVEAU_GEM_DOMAIN_GART;
899 ret = nouveau_gem_new(dev, args->size, 0, domain, 0, 0, &bo);
903 ret = drm_gem_handle_create(file_priv, &bo->gem, &args->handle);
904 drm_gem_object_unreference_unlocked(&bo->gem);
909 nouveau_display_dumb_map_offset(struct drm_file *file_priv,
910 struct drm_device *dev,
911 uint32_t handle, uint64_t *poffset)
913 struct drm_gem_object *gem;
915 gem = drm_gem_object_lookup(dev, file_priv, handle);
917 struct nouveau_bo *bo = nouveau_gem_object(gem);
918 *poffset = drm_vma_node_offset_addr(&bo->bo.vma_node);
919 drm_gem_object_unreference_unlocked(gem);