[PATCH 09/49] drm/i915: Extract ringbuffer obj alloc & destroy

oscar.mateo
2014-03-27T17:12:18Z

From: Ben Widawsky <benjamin.widawsky@intel.com>

There should be no functional changes.

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>

v2: Multiple rebases.

Signed-off-by: Oscar Mateo <oscar.mateo@intel.com>
---
drivers/gpu/drm/i915/intel_ringbuffer.c | 73 +++++++++++++++++++++------------
1 file changed, 46 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index 659fed0..f734c9d 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1332,6 +1332,45 @@ static int init_phys_status_page(struct intel_ring_buffer *ring)
return 0;
}

+static void destroy_ring_buffer(struct intel_ring_buffer *ring)
+{
+ i915_gem_object_ggtt_unpin(ring->obj);
+ drm_gem_object_unreference(&ring->obj->base);
+ ring->obj = NULL;
+}
+
+static int alloc_ring_buffer(struct intel_ring_buffer *ring)
+{
+ struct drm_device *dev = ring->dev;
+ struct drm_i915_gem_object *obj = NULL;
+ int ret;
+
+ if (!HAS_LLC(dev))
+ obj = i915_gem_object_create_stolen(dev, ring->size);
+ if (obj == NULL)
+ obj = i915_gem_alloc_object(dev, ring->size);
+ if (obj == NULL) {
+ DRM_ERROR("Failed to allocate ringbuffer\n");
+ return -ENOMEM;
+ }
+
+ ret = i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, PIN_MAPPABLE);
+ if (ret) {
+ drm_gem_object_unreference(&obj->base);
+ return ret;
+ }
+
+ ret = i915_gem_object_set_to_gtt_domain(obj, true);
+ if (ret) {
+ destroy_ring_buffer(ring);
+ return ret;
+ }
+
+ ring->obj = obj;
+
+ return 0;
+}
+
static int intel_init_ring_buffer(struct drm_device *dev,
struct intel_ring_buffer *ring)
{
@@ -1358,26 +1397,11 @@ static int intel_init_ring_buffer(struct drm_device *dev,
return ret;
}

- obj = NULL;
- if (!HAS_LLC(dev))
- obj = i915_gem_object_create_stolen(dev, ring->size);
- if (obj == NULL)
- obj = i915_gem_alloc_object(dev, ring->size);
- if (obj == NULL) {
- DRM_ERROR("Failed to allocate ringbuffer\n");
- ret = -ENOMEM;
- goto err_hws;
- }
-
- ring->obj = obj;
-
- ret = i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, PIN_MAPPABLE);
+ ret = alloc_ring_buffer(ring);
if (ret)
- goto err_unref;
+ goto err_hws;

- ret = i915_gem_object_set_to_gtt_domain(obj, true);
- if (ret)
- goto err_unpin;
+ obj = ring->obj;

ring->virtual_start =
ioremap_wc(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj),
@@ -1385,7 +1409,7 @@ static int intel_init_ring_buffer(struct drm_device *dev,
if (ring->virtual_start == NULL) {
DRM_ERROR("Failed to map ringbuffer.\n");
ret = -EINVAL;
- goto err_unpin;
+ goto destroy_ring;
}

ret = ring->init(ring);
@@ -1406,11 +1430,8 @@ static int intel_init_ring_buffer(struct drm_device *dev,

err_unmap:
iounmap(ring->virtual_start);
-err_unpin:
- i915_gem_object_ggtt_unpin(obj);
-err_unref:
- drm_gem_object_unreference(&obj->base);
- ring->obj = NULL;
+destroy_ring:
+ destroy_ring_buffer(ring);
err_hws:
cleanup_status_page(ring);
return ret;
@@ -1435,9 +1456,7 @@ void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring)

iounmap(ring->virtual_start);

- i915_gem_object_ggtt_unpin(ring->obj);
- drm_gem_object_unreference(&ring->obj->base);
- ring->obj = NULL;
+ destroy_ring_buffer(ring);
ring->preallocated_lazy_request = NULL;
ring->outstanding_lazy_seqno = 0;

--
1.9.0