aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2013-08-20 21:30:36 -0400
committerBen Skeggs <bskeggs@redhat.com>2013-08-20 21:36:21 -0400
commit78ae0ad403daf11cf63da86923d2b5dbeda3af8f (patch)
tree599c3e121747d8074473c1f86558914e5bc677df
parent6ff8c76a566f823d796359a6c1d76b7668f1e34d (diff)
drm/nv04/disp: fix framebuffer pin refcounting
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r--drivers/gpu/drm/nouveau/dispnv04/crtc.c58
-rw-r--r--drivers/gpu/drm/nouveau/dispnv04/disp.h1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.c3
3 files changed, 47 insertions, 15 deletions
diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
index 0782bd2f1e04..6a13ffb53bdb 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c
@@ -606,6 +606,24 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct drm_display_mode * mode)
606 regp->ramdac_a34 = 0x1; 606 regp->ramdac_a34 = 0x1;
607} 607}
608 608
609static int
610nv_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
611{
612 struct nv04_display *disp = nv04_display(crtc->dev);
613 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb);
614 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
615 int ret;
616
617 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
618 if (ret == 0) {
619 if (disp->image[nv_crtc->index])
620 nouveau_bo_unpin(disp->image[nv_crtc->index]);
621 nouveau_bo_ref(nvfb->nvbo, &disp->image[nv_crtc->index]);
622 }
623
624 return ret;
625}
626
609/** 627/**
610 * Sets up registers for the given mode/adjusted_mode pair. 628 * Sets up registers for the given mode/adjusted_mode pair.
611 * 629 *
@@ -622,10 +640,15 @@ nv_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
622 struct drm_device *dev = crtc->dev; 640 struct drm_device *dev = crtc->dev;
623 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); 641 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
624 struct nouveau_drm *drm = nouveau_drm(dev); 642 struct nouveau_drm *drm = nouveau_drm(dev);
643 int ret;
625 644
626 NV_DEBUG(drm, "CTRC mode on CRTC %d:\n", nv_crtc->index); 645 NV_DEBUG(drm, "CTRC mode on CRTC %d:\n", nv_crtc->index);
627 drm_mode_debug_printmodeline(adjusted_mode); 646 drm_mode_debug_printmodeline(adjusted_mode);
628 647
648 ret = nv_crtc_swap_fbs(crtc, old_fb);
649 if (ret)
650 return ret;
651
629 /* unlock must come after turning off FP_TG_CONTROL in output_prepare */ 652 /* unlock must come after turning off FP_TG_CONTROL in output_prepare */
630 nv_lock_vga_crtc_shadow(dev, nv_crtc->index, -1); 653 nv_lock_vga_crtc_shadow(dev, nv_crtc->index, -1);
631 654
@@ -722,6 +745,7 @@ static void nv_crtc_commit(struct drm_crtc *crtc)
722 745
723static void nv_crtc_destroy(struct drm_crtc *crtc) 746static void nv_crtc_destroy(struct drm_crtc *crtc)
724{ 747{
748 struct nv04_display *disp = nv04_display(crtc->dev);
725 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); 749 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
726 750
727 if (!nv_crtc) 751 if (!nv_crtc)
@@ -729,6 +753,10 @@ static void nv_crtc_destroy(struct drm_crtc *crtc)
729 753
730 drm_crtc_cleanup(crtc); 754 drm_crtc_cleanup(crtc);
731 755
756 if (disp->image[nv_crtc->index])
757 nouveau_bo_unpin(disp->image[nv_crtc->index]);
758 nouveau_bo_ref(NULL, &disp->image[nv_crtc->index]);
759
732 nouveau_bo_unmap(nv_crtc->cursor.nvbo); 760 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
733 nouveau_bo_unpin(nv_crtc->cursor.nvbo); 761 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
734 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); 762 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
@@ -754,6 +782,16 @@ nv_crtc_gamma_load(struct drm_crtc *crtc)
754} 782}
755 783
756static void 784static void
785nv_crtc_disable(struct drm_crtc *crtc)
786{
787 struct nv04_display *disp = nv04_display(crtc->dev);
788 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
789 if (disp->image[nv_crtc->index])
790 nouveau_bo_unpin(disp->image[nv_crtc->index]);
791 nouveau_bo_ref(NULL, &disp->image[nv_crtc->index]);
792}
793
794static void
757nv_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, uint32_t start, 795nv_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, uint32_t start,
758 uint32_t size) 796 uint32_t size)
759{ 797{
@@ -791,7 +829,6 @@ nv04_crtc_do_mode_set_base(struct drm_crtc *crtc,
791 struct drm_framebuffer *drm_fb; 829 struct drm_framebuffer *drm_fb;
792 struct nouveau_framebuffer *fb; 830 struct nouveau_framebuffer *fb;
793 int arb_burst, arb_lwm; 831 int arb_burst, arb_lwm;
794 int ret;
795 832
796 NV_DEBUG(drm, "index %d\n", nv_crtc->index); 833 NV_DEBUG(drm, "index %d\n", nv_crtc->index);
797 834
@@ -801,10 +838,8 @@ nv04_crtc_do_mode_set_base(struct drm_crtc *crtc,
801 return 0; 838 return 0;
802 } 839 }
803 840
804
805 /* If atomic, we want to switch to the fb we were passed, so 841 /* If atomic, we want to switch to the fb we were passed, so
806 * now we update pointers to do that. (We don't pin; just 842 * now we update pointers to do that.
807 * assume we're already pinned and update the base address.)
808 */ 843 */
809 if (atomic) { 844 if (atomic) {
810 drm_fb = passed_fb; 845 drm_fb = passed_fb;
@@ -812,17 +847,6 @@ nv04_crtc_do_mode_set_base(struct drm_crtc *crtc,
812 } else { 847 } else {
813 drm_fb = crtc->fb; 848 drm_fb = crtc->fb;
814 fb = nouveau_framebuffer(crtc->fb); 849 fb = nouveau_framebuffer(crtc->fb);
815 /* If not atomic, we can go ahead and pin, and unpin the
816 * old fb we were passed.
817 */
818 ret = nouveau_bo_pin(fb->nvbo, TTM_PL_FLAG_VRAM);
819 if (ret)
820 return ret;
821
822 if (passed_fb) {
823 struct nouveau_framebuffer *ofb = nouveau_framebuffer(passed_fb);
824 nouveau_bo_unpin(ofb->nvbo);
825 }
826 } 850 }
827 851
828 nv_crtc->fb.offset = fb->nvbo->bo.offset; 852 nv_crtc->fb.offset = fb->nvbo->bo.offset;
@@ -877,6 +901,9 @@ static int
877nv04_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 901nv04_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
878 struct drm_framebuffer *old_fb) 902 struct drm_framebuffer *old_fb)
879{ 903{
904 int ret = nv_crtc_swap_fbs(crtc, old_fb);
905 if (ret)
906 return ret;
880 return nv04_crtc_do_mode_set_base(crtc, old_fb, x, y, false); 907 return nv04_crtc_do_mode_set_base(crtc, old_fb, x, y, false);
881} 908}
882 909
@@ -1027,6 +1054,7 @@ static const struct drm_crtc_helper_funcs nv04_crtc_helper_funcs = {
1027 .mode_set_base = nv04_crtc_mode_set_base, 1054 .mode_set_base = nv04_crtc_mode_set_base,
1028 .mode_set_base_atomic = nv04_crtc_mode_set_base_atomic, 1055 .mode_set_base_atomic = nv04_crtc_mode_set_base_atomic,
1029 .load_lut = nv_crtc_gamma_load, 1056 .load_lut = nv_crtc_gamma_load,
1057 .disable = nv_crtc_disable,
1030}; 1058};
1031 1059
1032int 1060int
diff --git a/drivers/gpu/drm/nouveau/dispnv04/disp.h b/drivers/gpu/drm/nouveau/dispnv04/disp.h
index a0a031dad13f..9928187f0a7d 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/disp.h
+++ b/drivers/gpu/drm/nouveau/dispnv04/disp.h
@@ -81,6 +81,7 @@ struct nv04_display {
81 uint32_t saved_vga_font[4][16384]; 81 uint32_t saved_vga_font[4][16384];
82 uint32_t dac_users[4]; 82 uint32_t dac_users[4];
83 struct nouveau_object *core; 83 struct nouveau_object *core;
84 struct nouveau_bo *image[2];
84}; 85};
85 86
86static inline struct nv04_display * 87static inline struct nv04_display *
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c
index 907d20ef6d4d..a03e75deacaf 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -577,6 +577,9 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
577 ret = nv50_display_flip_next(crtc, fb, chan, 0); 577 ret = nv50_display_flip_next(crtc, fb, chan, 0);
578 if (ret) 578 if (ret)
579 goto fail_unreserve; 579 goto fail_unreserve;
580 } else {
581 struct nv04_display *dispnv04 = nv04_display(dev);
582 nouveau_bo_ref(new_bo, &dispnv04->image[nouveau_crtc(crtc)->index]);
580 } 583 }
581 584
582 ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence); 585 ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence);