[PATCH 04/10] drm/amdgpu: abstract amdgpu_bo_create_shadow

Chunming Zhou David1.Zhou at amd.com
Tue Aug 2 08:00:34 UTC 2016


Change-Id: Id0e89f350a05f8668ea00e3fff8c0bd6f3049cec
Signed-off-by: Chunming Zhou <David1.Zhou at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 40 ++++++++++++++++++++----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  3 +++
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index e6ecf16..c1111c9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -380,6 +380,32 @@ fail_free:
 	return r;
 }
 
+int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
+			    unsigned long size, int byte_align,
+			    struct amdgpu_bo *bo)
+{
+	struct ttm_placement placement = {0};
+	struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
+
+	if (bo->shadow)
+		return 0;
+
+	bo->flags |= AMDGPU_GEM_CREATE_SHADOW;
+	memset(&placements, 0,
+	       (AMDGPU_GEM_DOMAIN_MAX + 1) * sizeof(struct ttm_place));
+
+	amdgpu_ttm_placement_init(adev, &placement,
+				  placements, AMDGPU_GEM_DOMAIN_GTT,
+				  AMDGPU_GEM_CREATE_CPU_GTT_USWC);
+
+	return amdgpu_bo_create_restricted(adev, size, byte_align, true,
+					   AMDGPU_GEM_DOMAIN_GTT,
+					   AMDGPU_GEM_CREATE_CPU_GTT_USWC,
+					   NULL, &placement,
+					   bo->tbo.resv,
+					   &bo->shadow);
+}
+
 int amdgpu_bo_create(struct amdgpu_device *adev,
 		     unsigned long size, int byte_align,
 		     bool kernel, u32 domain, u64 flags,
@@ -404,19 +430,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 		return r;
 
 	if (flags & AMDGPU_GEM_CREATE_SHADOW) {
-		memset(&placements, 0,
-		       (AMDGPU_GEM_DOMAIN_MAX + 1) * sizeof(struct ttm_place));
-
-		amdgpu_ttm_placement_init(adev, &placement,
-					  placements, AMDGPU_GEM_DOMAIN_GTT,
-					  AMDGPU_GEM_CREATE_CPU_GTT_USWC);
-
-		r = amdgpu_bo_create_restricted(adev, size, byte_align, kernel,
-						AMDGPU_GEM_DOMAIN_GTT,
-						AMDGPU_GEM_CREATE_CPU_GTT_USWC,
-						NULL, &placement,
-						(*bo_ptr)->tbo.resv,
-						&(*bo_ptr)->shadow);
+		r = amdgpu_bo_create_shadow(adev, size, byte_align, (*bo_ptr));
 		if (r)
 			amdgpu_bo_unref(bo_ptr);
 	} else
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index d650b42..b994fd4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -117,6 +117,9 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 			    struct sg_table *sg,
 			    struct reservation_object *resv,
 			    struct amdgpu_bo **bo_ptr);
+int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
+			    unsigned long size, int byte_align,
+			    struct amdgpu_bo *bo);
 int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 				unsigned long size, int byte_align,
 				bool kernel, u32 domain, u64 flags,
-- 
1.9.1



More information about the amd-gfx mailing list