[PATCH 3/8] drm/amdgpu: sync bo and shadow V2

Chunming Zhou David1.Zhou at amd.com
Wed Aug 17 06:05:14 UTC 2016


Use shadow flag to judge which direction to sync.
V2:
Don't need bo pin, so remove it.

Change-Id: I9b540970d3a24c6aebeaa94c99f66a89134c663d
Signed-off-by: Chunming Zhou <David1.Zhou at amd.com>
Reviewed-by: Christian König <christian.koenig at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 43 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  5 ++++
 2 files changed, 48 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 2b3aec3..3ba0448 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -443,6 +443,49 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 	return r;
 }
 
+int amdgpu_bo_backup_shadow(struct amdgpu_device *adev,
+			    struct amdgpu_ring *ring,
+			    struct amdgpu_bo *bo,
+			    struct reservation_object *resv,
+			    struct fence **fence,
+			    bool direct)
+
+{
+	struct amdgpu_bo *shadow = bo->shadow;
+	uint64_t bo_addr, shadow_addr;
+	int r;
+
+	if (!shadow)
+		return -EINVAL;
+
+	if (bo->backup_shadow == AMDGPU_BO_SHADOW_TO_NONE) {
+		DRM_INFO("No need to backup bo and shadow\n");
+		return 0;
+	}
+	bo_addr = amdgpu_bo_gpu_offset(bo);
+	shadow_addr = amdgpu_bo_gpu_offset(bo->shadow);
+
+	r = reservation_object_reserve_shared(bo->tbo.resv);
+	if (r)
+		goto err;
+
+	if (bo->backup_shadow & AMDGPU_BO_SHADOW_TO_PARENT)
+		r = amdgpu_copy_buffer(ring, shadow_addr, bo_addr,
+				       amdgpu_bo_size(bo), resv, fence,
+				       direct);
+	else
+		r = amdgpu_copy_buffer(ring, bo_addr, shadow_addr,
+				       amdgpu_bo_size(bo), resv, fence,
+				       direct);
+	if (!r) {
+		amdgpu_bo_fence(bo, *fence, true);
+		bo->backup_shadow = AMDGPU_BO_SHADOW_TO_NONE;
+	}
+err:
+
+	return r;
+}
+
 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)
 {
 	bool is_iomem;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index d650b42..bb076d0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -155,6 +155,11 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
 void amdgpu_bo_fence(struct amdgpu_bo *bo, struct fence *fence,
 		     bool shared);
 u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo);
+int amdgpu_bo_backup_shadow(struct amdgpu_device *adev,
+			    struct amdgpu_ring *ring,
+			    struct amdgpu_bo *bo,
+			    struct reservation_object *resv,
+			    struct fence **fence, bool direct);
 
 /*
  * sub allocation
-- 
1.9.1



More information about the amd-gfx mailing list