From 042f8514e67315b74cccf3692d34e5b2d32a6c14 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sun, 26 May 2019 13:43:32 -0700 Subject: [PATCH] iris: Move fresh BO allocation into a helper function. There's enough going on here to warrant a helper. More cleaning coming. Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gallium/drivers/iris/iris_bufmgr.c | 56 ++++++++++++++------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 64dd73adaaa..e6c61a7a14c 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -360,6 +360,34 @@ bo_calloc(void) return bo; } +static struct iris_bo * +alloc_fresh_bo(struct iris_bufmgr *bufmgr, uint64_t bo_size) +{ + struct iris_bo *bo = bo_calloc(); + if (!bo) + return NULL; + + struct drm_i915_gem_create create = { .size = bo_size }; + + /* All new BOs we get from the kernel are zeroed, so we don't need to + * worry about that here. + */ + if (drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) { + free(bo); + return NULL; + } + + bo->gem_handle = create.handle; + bo->bufmgr = bufmgr; + bo->size = bo_size; + bo->idle = true; + bo->tiling_mode = I915_TILING_NONE; + bo->swizzle_mode = I915_BIT_6_SWIZZLE_NONE; + bo->stride = 0; + + return bo; +} + static struct iris_bo * bo_alloc_internal(struct iris_bufmgr *bufmgr, const char *name, @@ -371,7 +399,6 @@ bo_alloc_internal(struct iris_bufmgr *bufmgr, { struct iris_bo *bo; unsigned int page_size = getpagesize(); - int ret; struct bo_cache_bucket *bucket; bool alloc_from_cache; uint64_t bo_size; @@ -434,33 +461,10 @@ retry: bo->gtt_offset = 0ull; } } else { - bo = bo_calloc(); + alloc_pages = true; + bo = alloc_fresh_bo(bufmgr, bo_size); if (!bo) goto err; - - bo->size = bo_size; - bo->idle = true; - - struct drm_i915_gem_create create = { .size = bo_size }; - - /* All new BOs we get from the kernel are zeroed, so we don't need to - * worry about that here. - */ - ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CREATE, &create); - if (ret != 0) { - free(bo); - goto err; - } - - bo->gem_handle = create.handle; - - bo->bufmgr = bufmgr; - - bo->tiling_mode = I915_TILING_NONE; - bo->swizzle_mode = I915_BIT_6_SWIZZLE_NONE; - bo->stride = 0; - - alloc_pages = true; } bo->name = name; -- 2.30.2