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 nvkm_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 NVKM_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 nvkm_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 nvkm_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
)
98 const u32 mthd
= NV04_DISP_SCANOUTPOS
+ nouveau_crtc(crtc
)->index
;
99 struct nouveau_display
*disp
= nouveau_display(crtc
->dev
);
100 struct nv04_display_scanoutpos args
;
104 ret
= nvif_exec(&disp
->disp
, mthd
, &args
, sizeof(args
));
109 ret
|= DRM_SCANOUTPOS_ACCURATE
;
110 ret
|= DRM_SCANOUTPOS_VALID
;
114 if (retry
) ndelay(crtc
->linedur_ns
);
118 *vpos
= calc(args
.vblanks
, args
.vblanke
, args
.vtotal
, args
.vline
);
119 if (stime
) *stime
= ns_to_ktime(args
.time
[0]);
120 if (etime
) *etime
= ns_to_ktime(args
.time
[1]);
123 ret
|= DRM_SCANOUTPOS_INVBL
;
128 nouveau_display_scanoutpos(struct drm_device
*dev
, int head
, unsigned int flags
,
129 int *vpos
, int *hpos
, ktime_t
*stime
, ktime_t
*etime
)
131 struct drm_crtc
*crtc
;
133 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
134 if (nouveau_crtc(crtc
)->index
== head
) {
135 return nouveau_display_scanoutpos_head(crtc
, vpos
, hpos
,
144 nouveau_display_vblstamp(struct drm_device
*dev
, int head
, int *max_error
,
145 struct timeval
*time
, unsigned flags
)
147 struct drm_crtc
*crtc
;
149 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
150 if (nouveau_crtc(crtc
)->index
== head
) {
151 return drm_calc_vbltimestamp_from_scanoutpos(dev
,
152 head
, max_error
, time
, flags
, crtc
,
161 nouveau_display_vblank_fini(struct drm_device
*dev
)
163 struct drm_crtc
*crtc
;
165 drm_vblank_cleanup(dev
);
167 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
168 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
169 nvkm_notify_fini(&nv_crtc
->vblank
);
174 nouveau_display_vblank_init(struct drm_device
*dev
)
176 struct nouveau_drm
*drm
= nouveau_drm(dev
);
177 struct nouveau_disp
*pdisp
= nvkm_disp(&drm
->device
);
178 struct drm_crtc
*crtc
;
181 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
182 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
183 ret
= nvkm_notify_init(&pdisp
->vblank
,
184 nouveau_display_vblank_handler
, false,
185 &(struct nvif_notify_head_req_v0
) {
186 .head
= nv_crtc
->index
,
188 sizeof(struct nvif_notify_head_req_v0
),
189 sizeof(struct nvif_notify_head_rep_v0
),
192 nouveau_display_vblank_fini(dev
);
197 ret
= drm_vblank_init(dev
, dev
->mode_config
.num_crtc
);
199 nouveau_display_vblank_fini(dev
);
207 nouveau_user_framebuffer_destroy(struct drm_framebuffer
*drm_fb
)
209 struct nouveau_framebuffer
*fb
= nouveau_framebuffer(drm_fb
);
210 struct nouveau_display
*disp
= nouveau_display(drm_fb
->dev
);
213 disp
->fb_dtor(drm_fb
);
216 drm_gem_object_unreference_unlocked(&fb
->nvbo
->gem
);
218 drm_framebuffer_cleanup(drm_fb
);
223 nouveau_user_framebuffer_create_handle(struct drm_framebuffer
*drm_fb
,
224 struct drm_file
*file_priv
,
225 unsigned int *handle
)
227 struct nouveau_framebuffer
*fb
= nouveau_framebuffer(drm_fb
);
229 return drm_gem_handle_create(file_priv
, &fb
->nvbo
->gem
, handle
);
232 static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs
= {
233 .destroy
= nouveau_user_framebuffer_destroy
,
234 .create_handle
= nouveau_user_framebuffer_create_handle
,
238 nouveau_framebuffer_init(struct drm_device
*dev
,
239 struct nouveau_framebuffer
*nv_fb
,
240 struct drm_mode_fb_cmd2
*mode_cmd
,
241 struct nouveau_bo
*nvbo
)
243 struct nouveau_display
*disp
= nouveau_display(dev
);
244 struct drm_framebuffer
*fb
= &nv_fb
->base
;
247 drm_helper_mode_fill_fb_struct(fb
, mode_cmd
);
250 ret
= drm_framebuffer_init(dev
, fb
, &nouveau_framebuffer_funcs
);
255 ret
= disp
->fb_ctor(fb
);
263 static struct drm_framebuffer
*
264 nouveau_user_framebuffer_create(struct drm_device
*dev
,
265 struct drm_file
*file_priv
,
266 struct drm_mode_fb_cmd2
*mode_cmd
)
268 struct nouveau_framebuffer
*nouveau_fb
;
269 struct drm_gem_object
*gem
;
272 gem
= drm_gem_object_lookup(dev
, file_priv
, mode_cmd
->handles
[0]);
274 return ERR_PTR(-ENOENT
);
276 nouveau_fb
= kzalloc(sizeof(struct nouveau_framebuffer
), GFP_KERNEL
);
280 ret
= nouveau_framebuffer_init(dev
, nouveau_fb
, mode_cmd
, nouveau_gem_object(gem
));
284 return &nouveau_fb
->base
;
289 drm_gem_object_unreference(gem
);
293 static const struct drm_mode_config_funcs nouveau_mode_config_funcs
= {
294 .fb_create
= nouveau_user_framebuffer_create
,
295 .output_poll_changed
= nouveau_fbcon_output_poll_changed
,
299 struct nouveau_drm_prop_enum_list
{
305 static struct nouveau_drm_prop_enum_list underscan
[] = {
306 { 6, UNDERSCAN_AUTO
, "auto" },
307 { 6, UNDERSCAN_OFF
, "off" },
308 { 6, UNDERSCAN_ON
, "on" },
312 static struct nouveau_drm_prop_enum_list dither_mode
[] = {
313 { 7, DITHERING_MODE_AUTO
, "auto" },
314 { 7, DITHERING_MODE_OFF
, "off" },
315 { 1, DITHERING_MODE_ON
, "on" },
316 { 6, DITHERING_MODE_STATIC2X2
, "static 2x2" },
317 { 6, DITHERING_MODE_DYNAMIC2X2
, "dynamic 2x2" },
318 { 4, DITHERING_MODE_TEMPORAL
, "temporal" },
322 static struct nouveau_drm_prop_enum_list dither_depth
[] = {
323 { 6, DITHERING_DEPTH_AUTO
, "auto" },
324 { 6, DITHERING_DEPTH_6BPC
, "6 bpc" },
325 { 6, DITHERING_DEPTH_8BPC
, "8 bpc" },
329 #define PROP_ENUM(p,gen,n,list) do { \
330 struct nouveau_drm_prop_enum_list *l = (list); \
332 while (l->gen_mask) { \
333 if (l->gen_mask & (1 << (gen))) \
338 p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \
341 while (p && l->gen_mask) { \
342 if (l->gen_mask & (1 << (gen))) { \
343 drm_property_add_enum(p, c, l->type, l->name); \
352 nouveau_display_init(struct drm_device
*dev
)
354 struct nouveau_display
*disp
= nouveau_display(dev
);
355 struct drm_connector
*connector
;
358 ret
= disp
->init(dev
);
362 /* enable polling for external displays */
363 drm_kms_helper_poll_enable(dev
);
365 /* enable hotplug interrupts */
366 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
367 struct nouveau_connector
*conn
= nouveau_connector(connector
);
368 nvkm_notify_get(&conn
->hpd
);
375 nouveau_display_fini(struct drm_device
*dev
)
377 struct nouveau_display
*disp
= nouveau_display(dev
);
378 struct drm_connector
*connector
;
381 /* Make sure that drm and hw vblank irqs get properly disabled. */
382 for (head
= 0; head
< dev
->mode_config
.num_crtc
; head
++)
383 drm_vblank_off(dev
, head
);
385 /* disable hotplug interrupts */
386 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
387 struct nouveau_connector
*conn
= nouveau_connector(connector
);
388 nvkm_notify_put(&conn
->hpd
);
391 drm_kms_helper_poll_disable(dev
);
396 nouveau_display_create_properties(struct drm_device
*dev
)
398 struct nouveau_display
*disp
= nouveau_display(dev
);
401 if (disp
->disp
.oclass
< NV50_DISP_CLASS
)
404 if (disp
->disp
.oclass
< NVD0_DISP_CLASS
)
409 PROP_ENUM(disp
->dithering_mode
, gen
, "dithering mode", dither_mode
);
410 PROP_ENUM(disp
->dithering_depth
, gen
, "dithering depth", dither_depth
);
411 PROP_ENUM(disp
->underscan_property
, gen
, "underscan", underscan
);
413 disp
->underscan_hborder_property
=
414 drm_property_create_range(dev
, 0, "underscan hborder", 0, 128);
416 disp
->underscan_vborder_property
=
417 drm_property_create_range(dev
, 0, "underscan vborder", 0, 128);
423 disp
->vibrant_hue_property
=
424 drm_property_create_range(dev
, 0, "vibrant hue", 0, 180);
427 disp
->color_vibrance_property
=
428 drm_property_create_range(dev
, 0, "color vibrance", 0, 200);
432 nouveau_display_create(struct drm_device
*dev
)
434 struct nouveau_drm
*drm
= nouveau_drm(dev
);
435 struct nouveau_display
*disp
;
438 disp
= drm
->display
= kzalloc(sizeof(*disp
), GFP_KERNEL
);
442 drm_mode_config_init(dev
);
443 drm_mode_create_scaling_mode_property(dev
);
444 drm_mode_create_dvi_i_properties(dev
);
446 dev
->mode_config
.funcs
= &nouveau_mode_config_funcs
;
447 dev
->mode_config
.fb_base
= nv_device_resource_start(nvkm_device(&drm
->device
), 1);
449 dev
->mode_config
.min_width
= 0;
450 dev
->mode_config
.min_height
= 0;
451 if (drm
->device
.info
.family
< NV_DEVICE_INFO_V0_CELSIUS
) {
452 dev
->mode_config
.max_width
= 2048;
453 dev
->mode_config
.max_height
= 2048;
455 if (drm
->device
.info
.family
< NV_DEVICE_INFO_V0_TESLA
) {
456 dev
->mode_config
.max_width
= 4096;
457 dev
->mode_config
.max_height
= 4096;
459 dev
->mode_config
.max_width
= 8192;
460 dev
->mode_config
.max_height
= 8192;
463 dev
->mode_config
.preferred_depth
= 24;
464 dev
->mode_config
.prefer_shadow
= 1;
466 if (drm
->device
.info
.chipset
< 0x11)
467 dev
->mode_config
.async_page_flip
= false;
469 dev
->mode_config
.async_page_flip
= true;
471 drm_kms_helper_poll_init(dev
);
472 drm_kms_helper_poll_disable(dev
);
474 if (drm
->vbios
.dcb
.entries
) {
475 static const u16 oclass
[] = {
489 for (i
= 0, ret
= -ENODEV
; ret
&& i
< ARRAY_SIZE(oclass
); i
++) {
490 ret
= nvif_object_init(nvif_object(&drm
->device
), NULL
,
491 NVDRM_DISPLAY
, oclass
[i
],
492 NULL
, 0, &disp
->disp
);
496 nouveau_display_create_properties(dev
);
497 if (disp
->disp
.oclass
< NV50_DISP_CLASS
)
498 ret
= nv04_display_create(dev
);
500 ret
= nv50_display_create(dev
);
507 goto disp_create_err
;
509 if (dev
->mode_config
.num_crtc
) {
510 ret
= nouveau_display_vblank_init(dev
);
515 nouveau_backlight_init(dev
);
521 drm_kms_helper_poll_fini(dev
);
522 drm_mode_config_cleanup(dev
);
527 nouveau_display_destroy(struct drm_device
*dev
)
529 struct nouveau_display
*disp
= nouveau_display(dev
);
531 nouveau_backlight_exit(dev
);
532 nouveau_display_vblank_fini(dev
);
534 drm_kms_helper_poll_fini(dev
);
535 drm_mode_config_cleanup(dev
);
540 nvif_object_fini(&disp
->disp
);
542 nouveau_drm(dev
)->display
= NULL
;
547 nouveau_display_suspend(struct drm_device
*dev
)
549 struct nouveau_drm
*drm
= nouveau_drm(dev
);
550 struct drm_crtc
*crtc
;
552 nouveau_display_fini(dev
);
554 NV_INFO(drm
, "unpinning framebuffer(s)...\n");
555 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
556 struct nouveau_framebuffer
*nouveau_fb
;
558 nouveau_fb
= nouveau_framebuffer(crtc
->primary
->fb
);
559 if (!nouveau_fb
|| !nouveau_fb
->nvbo
)
562 nouveau_bo_unpin(nouveau_fb
->nvbo
);
565 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
566 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
568 nouveau_bo_unmap(nv_crtc
->cursor
.nvbo
);
569 nouveau_bo_unpin(nv_crtc
->cursor
.nvbo
);
576 nouveau_display_repin(struct drm_device
*dev
)
578 struct nouveau_drm
*drm
= nouveau_drm(dev
);
579 struct drm_crtc
*crtc
;
582 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
583 struct nouveau_framebuffer
*nouveau_fb
;
585 nouveau_fb
= nouveau_framebuffer(crtc
->primary
->fb
);
586 if (!nouveau_fb
|| !nouveau_fb
->nvbo
)
589 nouveau_bo_pin(nouveau_fb
->nvbo
, TTM_PL_FLAG_VRAM
);
592 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
593 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
595 ret
= nouveau_bo_pin(nv_crtc
->cursor
.nvbo
, TTM_PL_FLAG_VRAM
);
597 ret
= nouveau_bo_map(nv_crtc
->cursor
.nvbo
);
599 NV_ERROR(drm
, "Could not pin/map cursor.\n");
604 nouveau_display_resume(struct drm_device
*dev
)
606 struct drm_crtc
*crtc
;
609 nouveau_display_init(dev
);
611 /* Force CLUT to get re-loaded during modeset */
612 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
613 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
615 nv_crtc
->lut
.depth
= 0;
618 /* Make sure that drm and hw vblank irqs get resumed if needed. */
619 for (head
= 0; head
< dev
->mode_config
.num_crtc
; head
++)
620 drm_vblank_on(dev
, head
);
622 drm_helper_resume_force_mode(dev
);
624 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
625 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
626 u32 offset
= nv_crtc
->cursor
.nvbo
->bo
.offset
;
628 nv_crtc
->cursor
.set_offset(nv_crtc
, offset
);
629 nv_crtc
->cursor
.set_pos(nv_crtc
, nv_crtc
->cursor_saved_x
,
630 nv_crtc
->cursor_saved_y
);
635 nouveau_page_flip_emit(struct nouveau_channel
*chan
,
636 struct nouveau_bo
*old_bo
,
637 struct nouveau_bo
*new_bo
,
638 struct nouveau_page_flip_state
*s
,
639 struct nouveau_fence
**pfence
)
641 struct nouveau_fence_chan
*fctx
= chan
->fence
;
642 struct nouveau_drm
*drm
= chan
->drm
;
643 struct drm_device
*dev
= drm
->dev
;
647 /* Queue it to the pending list */
648 spin_lock_irqsave(&dev
->event_lock
, flags
);
649 list_add_tail(&s
->head
, &fctx
->flip
);
650 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
652 /* Synchronize with the old framebuffer */
653 ret
= nouveau_fence_sync(old_bo
->bo
.sync_obj
, chan
);
657 /* Emit the pageflip */
658 ret
= RING_SPACE(chan
, 2);
662 if (drm
->device
.info
.family
< NV_DEVICE_INFO_V0_FERMI
)
663 BEGIN_NV04(chan
, NvSubSw
, NV_SW_PAGE_FLIP
, 1);
665 BEGIN_NVC0(chan
, FermiSw
, NV_SW_PAGE_FLIP
, 1);
666 OUT_RING (chan
, 0x00000000);
669 ret
= nouveau_fence_new(chan
, false, pfence
);
675 spin_lock_irqsave(&dev
->event_lock
, flags
);
677 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
682 nouveau_crtc_page_flip(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
683 struct drm_pending_vblank_event
*event
, u32 flags
)
685 const int swap_interval
= (flags
& DRM_MODE_PAGE_FLIP_ASYNC
) ? 0 : 1;
686 struct drm_device
*dev
= crtc
->dev
;
687 struct nouveau_drm
*drm
= nouveau_drm(dev
);
688 struct nouveau_bo
*old_bo
= nouveau_framebuffer(crtc
->primary
->fb
)->nvbo
;
689 struct nouveau_bo
*new_bo
= nouveau_framebuffer(fb
)->nvbo
;
690 struct nouveau_page_flip_state
*s
;
691 struct nouveau_channel
*chan
;
692 struct nouveau_cli
*cli
;
693 struct nouveau_fence
*fence
;
699 cli
= (void *)nvif_client(&chan
->device
->base
);
701 s
= kzalloc(sizeof(*s
), GFP_KERNEL
);
705 if (new_bo
!= old_bo
) {
706 ret
= nouveau_bo_pin(new_bo
, TTM_PL_FLAG_VRAM
);
711 mutex_lock(&cli
->mutex
);
713 /* 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
);
718 nouveau_fence_unref(&fence
);
722 ret
= ttm_bo_reserve(&old_bo
->bo
, true, false, false, NULL
);
726 /* Initialize a page flip struct */
727 *s
= (struct nouveau_page_flip_state
)
728 { { }, event
, nouveau_crtc(crtc
)->index
,
729 fb
->bits_per_pixel
, fb
->pitches
[0], crtc
->x
, crtc
->y
,
732 /* Keep vblanks on during flip, for the target crtc of this flip */
733 drm_vblank_get(dev
, nouveau_crtc(crtc
)->index
);
735 /* Emit a page flip */
736 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_TESLA
) {
737 ret
= nv50_display_flip_next(crtc
, fb
, chan
, swap_interval
);
741 struct nv04_display
*dispnv04
= nv04_display(dev
);
742 int head
= nouveau_crtc(crtc
)->index
;
745 ret
= RING_SPACE(chan
, 8);
749 BEGIN_NV04(chan
, NvSubImageBlit
, 0x012c, 1);
751 BEGIN_NV04(chan
, NvSubImageBlit
, 0x0134, 1);
752 OUT_RING (chan
, head
);
753 BEGIN_NV04(chan
, NvSubImageBlit
, 0x0100, 1);
755 BEGIN_NV04(chan
, NvSubImageBlit
, 0x0130, 1);
759 nouveau_bo_ref(new_bo
, &dispnv04
->image
[head
]);
762 ret
= nouveau_page_flip_emit(chan
, old_bo
, new_bo
, s
, &fence
);
765 mutex_unlock(&cli
->mutex
);
767 /* Update the crtc struct and cleanup */
768 crtc
->primary
->fb
= fb
;
770 nouveau_bo_fence(old_bo
, fence
);
771 ttm_bo_unreserve(&old_bo
->bo
);
772 if (old_bo
!= new_bo
)
773 nouveau_bo_unpin(old_bo
);
774 nouveau_fence_unref(&fence
);
778 drm_vblank_put(dev
, nouveau_crtc(crtc
)->index
);
779 ttm_bo_unreserve(&old_bo
->bo
);
781 mutex_unlock(&cli
->mutex
);
782 if (old_bo
!= new_bo
)
783 nouveau_bo_unpin(new_bo
);
790 nouveau_finish_page_flip(struct nouveau_channel
*chan
,
791 struct nouveau_page_flip_state
*ps
)
793 struct nouveau_fence_chan
*fctx
= chan
->fence
;
794 struct nouveau_drm
*drm
= chan
->drm
;
795 struct drm_device
*dev
= drm
->dev
;
796 struct nouveau_page_flip_state
*s
;
800 spin_lock_irqsave(&dev
->event_lock
, flags
);
802 if (list_empty(&fctx
->flip
)) {
803 NV_ERROR(drm
, "unexpected pageflip\n");
804 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
808 s
= list_first_entry(&fctx
->flip
, struct nouveau_page_flip_state
, head
);
810 /* Vblank timestamps/counts are only correct on >= NV-50 */
811 if (drm
->device
.info
.family
>= NV_DEVICE_INFO_V0_TESLA
)
814 drm_send_vblank_event(dev
, crtcid
, s
->event
);
817 /* Give up ownership of vblank for page-flipped crtc */
818 drm_vblank_put(dev
, s
->crtc
);
825 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
830 nouveau_flip_complete(void *data
)
832 struct nouveau_channel
*chan
= data
;
833 struct nouveau_drm
*drm
= chan
->drm
;
834 struct nouveau_page_flip_state state
;
836 if (!nouveau_finish_page_flip(chan
, &state
)) {
837 if (drm
->device
.info
.family
< NV_DEVICE_INFO_V0_TESLA
) {
838 nv_set_crtc_base(drm
->dev
, state
.crtc
, state
.offset
+
839 state
.y
* state
.pitch
+
840 state
.x
* state
.bpp
/ 8);
848 nouveau_display_dumb_create(struct drm_file
*file_priv
, struct drm_device
*dev
,
849 struct drm_mode_create_dumb
*args
)
851 struct nouveau_bo
*bo
;
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
);
858 ret
= nouveau_gem_new(dev
, args
->size
, 0, NOUVEAU_GEM_DOMAIN_VRAM
, 0, 0, &bo
);
862 ret
= drm_gem_handle_create(file_priv
, &bo
->gem
, &args
->handle
);
863 drm_gem_object_unreference_unlocked(&bo
->gem
);
868 nouveau_display_dumb_map_offset(struct drm_file
*file_priv
,
869 struct drm_device
*dev
,
870 uint32_t handle
, uint64_t *poffset
)
872 struct drm_gem_object
*gem
;
874 gem
= drm_gem_object_lookup(dev
, file_priv
, handle
);
876 struct nouveau_bo
*bo
= nouveau_gem_object(gem
);
877 *poffset
= drm_vma_node_offset_addr(&bo
->bo
.vma_node
);
878 drm_gem_object_unreference_unlocked(gem
);