[PATCH 01/14] drm/cirrus: split out bo unpinning from cirrus_bo_push_sysram

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Varad Gautam <varad.gautam@xxxxxxxxxxxxx>

add a cirrus_bo_unpin call, and move bo_{reserve,unreserve} operations
to bo_{pin,unpin} to ensure correct pinning/unpinning and simplify the call
sequence.

Signed-off-by: Varad Gautam <varad.gautam@xxxxxxxxxxxxx>
---
 drivers/gpu/drm/cirrus/cirrus_drv.h  |  1 +
 drivers/gpu/drm/cirrus/cirrus_mode.c | 14 ++-------
 drivers/gpu/drm/cirrus/cirrus_ttm.c  | 55 +++++++++++++++++++++++++++++-------
 3 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h
index 8690352d96f7..8cdf6b0db4a7 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.h
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.h
@@ -262,6 +262,7 @@ static inline void cirrus_bo_unreserve(struct cirrus_bo *bo)
 
 int cirrus_bo_push_sysram(struct cirrus_bo *bo);
 int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
+int cirrus_bo_unpin(struct cirrus_bo *bo);
 
 extern int cirrus_bpp;
 
diff --git a/drivers/gpu/drm/cirrus/cirrus_mode.c b/drivers/gpu/drm/cirrus/cirrus_mode.c
index 53f6f0f84206..21d75e7e4abc 100644
--- a/drivers/gpu/drm/cirrus/cirrus_mode.c
+++ b/drivers/gpu/drm/cirrus/cirrus_mode.c
@@ -131,26 +131,17 @@ static int cirrus_crtc_do_set_base(struct drm_crtc *crtc,
 		cirrus_fb = to_cirrus_framebuffer(fb);
 		obj = cirrus_fb->obj;
 		bo = gem_to_cirrus_bo(obj);
-		ret = cirrus_bo_reserve(bo, false);
-		if (ret)
-			return ret;
+		cirrus_bo_unpin(bo);
 		cirrus_bo_push_sysram(bo);
-		cirrus_bo_unreserve(bo);
 	}
 
 	cirrus_fb = to_cirrus_framebuffer(crtc->primary->fb);
 	obj = cirrus_fb->obj;
 	bo = gem_to_cirrus_bo(obj);
 
-	ret = cirrus_bo_reserve(bo, false);
-	if (ret)
-		return ret;
-
 	ret = cirrus_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
-	if (ret) {
-		cirrus_bo_unreserve(bo);
+	if (ret)
 		return ret;
-	}
 
 	if (&cdev->mode_info.gfbdev->gfb == cirrus_fb) {
 		/* if pushing console in kmap it */
@@ -158,7 +149,6 @@ static int cirrus_crtc_do_set_base(struct drm_crtc *crtc,
 		if (ret)
 			DRM_ERROR("failed to kmap fbcon\n");
 	}
-	cirrus_bo_unreserve(bo);
 
 	cirrus_set_start_address(crtc, (u32)gpu_addr);
 	return 0;
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index 1ff1838c0d44..a91d31da90ba 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -358,12 +358,17 @@ static inline u64 cirrus_bo_gpu_offset(struct cirrus_bo *bo)
 
 int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr)
 {
-	int i, ret;
+	int i, ret = 0;
+
+	ret = cirrus_bo_reserve(bo, false);
+	if (ret)
+		return ret;
 
 	if (bo->pin_count) {
 		bo->pin_count++;
 		if (gpu_addr)
 			*gpu_addr = cirrus_bo_gpu_offset(bo);
+		goto out;
 	}
 
 	cirrus_ttm_placement(bo, pl_flag);
@@ -371,24 +376,51 @@ int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr)
 		bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
 	ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
 	if (ret)
-		return ret;
+		goto out;
 
 	bo->pin_count = 1;
 	if (gpu_addr)
 		*gpu_addr = cirrus_bo_gpu_offset(bo);
-	return 0;
+
+out:
+	cirrus_bo_unreserve(bo);
+	return ret;
+}
+
+int cirrus_bo_unpin(struct cirrus_bo *bo)
+{
+	int i, ret = 0;
+
+	ret = cirrus_bo_reserve(bo, false);
+	if (ret)
+		return ret;
+
+	if (!bo->pin_count || --bo->pin_count)
+		goto out;
+
+	for (i = 0; i < bo->placement.num_placement; i++)
+		bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
+	ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
+	if (ret)
+		goto out;
+
+out:
+	cirrus_bo_unreserve(bo);
+	return ret;
 }
 
 int cirrus_bo_push_sysram(struct cirrus_bo *bo)
 {
 	int i, ret;
-	if (!bo->pin_count) {
+
+	ret = cirrus_bo_reserve(bo, false);
+	if (ret)
+		return ret;
+
+	if (bo->pin_count) {
 		DRM_ERROR("unpin bad %p\n", bo);
-		return 0;
+		goto out;
 	}
-	bo->pin_count--;
-	if (bo->pin_count)
-		return 0;
 
 	if (bo->kmap.virtual)
 		ttm_bo_kunmap(&bo->kmap);
@@ -400,9 +432,12 @@ int cirrus_bo_push_sysram(struct cirrus_bo *bo)
 	ret = ttm_bo_validate(&bo->bo, &bo->placement, false, false);
 	if (ret) {
 		DRM_ERROR("pushing to VRAM failed\n");
-		return ret;
+		goto out;
 	}
-	return 0;
+
+out:
+	cirrus_bo_unreserve(bo);
+	return ret;
 }
 
 int cirrus_mmap(struct file *filp, struct vm_area_struct *vma)
-- 
2.13.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux