diff mbox

[1/2] intel: Split out bo allocation

Message ID 1408677155-1840-70-git-send-email-benjamin.widawsky@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Widawsky Aug. 22, 2014, 3:12 a.m. UTC
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
 intel/intel_bufmgr_gem.c | 69 ++++++++++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 29 deletions(-)
diff mbox

Patch

diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
index 0e1cb0d..d7d3769 100644
--- a/intel/intel_bufmgr_gem.c
+++ b/intel/intel_bufmgr_gem.c
@@ -636,6 +636,43 @@  drm_intel_gem_bo_cache_purge_bucket(drm_intel_bufmgr_gem *bufmgr_gem,
 	}
 }
 
+static drm_intel_bo_gem *
+__bo_alloc(drm_intel_bufmgr_gem *bufmgr_gem, unsigned long size)
+{
+	struct drm_i915_gem_create create;
+	drm_intel_bo_gem *bo_gem;
+	int ret;
+
+	bo_gem = calloc(1, sizeof(*bo_gem));
+	if (!bo_gem)
+		return NULL;
+
+	bo_gem->bo.size = size;
+
+	VG_CLEAR(create);
+	create.size = size;
+
+	ret = drmIoctl(bufmgr_gem->fd,
+		       DRM_IOCTL_I915_GEM_CREATE,
+		       &create);
+	bo_gem->gem_handle = create.handle;
+	bo_gem->bo.handle = bo_gem->gem_handle;
+	if (ret != 0) {
+		free(bo_gem);
+		return NULL;
+	}
+	bo_gem->bo.bufmgr = (drm_intel_bufmgr *)bufmgr_gem;
+
+	bo_gem->tiling_mode = I915_TILING_NONE;
+	bo_gem->swizzle_mode = I915_BIT_6_SWIZZLE_NONE;
+	bo_gem->stride = 0;
+
+	DRMINITLISTHEAD(&bo_gem->name_list);
+	DRMINITLISTHEAD(&bo_gem->vma_list);
+
+	return bo_gem;
+}
+
 static drm_intel_bo *
 drm_intel_gem_bo_alloc_internal(drm_intel_bufmgr *bufmgr,
 				const char *name,
@@ -647,7 +684,6 @@  drm_intel_gem_bo_alloc_internal(drm_intel_bufmgr *bufmgr,
 	drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bufmgr;
 	drm_intel_bo_gem *bo_gem;
 	unsigned int page_size = getpagesize();
-	int ret;
 	struct drm_intel_gem_bo_bucket *bucket;
 	bool alloc_from_cache;
 	unsigned long bo_size;
@@ -720,41 +756,16 @@  retry:
 	pthread_mutex_unlock(&bufmgr_gem->lock);
 
 	if (!alloc_from_cache) {
-		struct drm_i915_gem_create create;
-
-		bo_gem = calloc(1, sizeof(*bo_gem));
+		bo_gem = __bo_alloc(bufmgr_gem, bo_size);
 		if (!bo_gem)
 			return NULL;
 
-		bo_gem->bo.size = bo_size;
-
-		VG_CLEAR(create);
-		create.size = bo_size;
-
-		ret = drmIoctl(bufmgr_gem->fd,
-			       DRM_IOCTL_I915_GEM_CREATE,
-			       &create);
-		bo_gem->gem_handle = create.handle;
-		bo_gem->bo.handle = bo_gem->gem_handle;
-		if (ret != 0) {
-			free(bo_gem);
-			return NULL;
-		}
-		bo_gem->bo.bufmgr = bufmgr;
-
-		bo_gem->tiling_mode = I915_TILING_NONE;
-		bo_gem->swizzle_mode = I915_BIT_6_SWIZZLE_NONE;
-		bo_gem->stride = 0;
-
 		if (drm_intel_gem_bo_set_tiling_internal(&bo_gem->bo,
 							 tiling_mode,
 							 stride)) {
-		    drm_intel_gem_bo_free(&bo_gem->bo);
-		    return NULL;
+			drm_intel_gem_bo_free(&bo_gem->bo);
+			return NULL;
 		}
-
-		DRMINITLISTHEAD(&bo_gem->name_list);
-		DRMINITLISTHEAD(&bo_gem->vma_list);
 	}
 
 	bo_gem->name = name;