Commit 2919d291 authored by Oscar Mateo's avatar Oscar Mateo Committed by Daniel Vetter

drm/i915: Extract ringbuffer destroy & generalize alloc to take a ringbuf

More prep work: with Execlists, we are going to start creating a lot
of extra ringbuffers soon, so these functions are handy.

No functional changes.

v2: rename allocate/destroy_ring_buffer to alloc/destroy_ringbuffer_obj
because the name is more meaningful and to mirror a similar function in
the context world: i915_gem_alloc_context_obj(). Change suggested by Brad
Volkin.
Reviewed-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: default avatarOscar Mateo <oscar.mateo@intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 31b7a88d
...@@ -1482,15 +1482,25 @@ static int init_phys_status_page(struct intel_engine_cs *ring) ...@@ -1482,15 +1482,25 @@ static int init_phys_status_page(struct intel_engine_cs *ring)
return 0; return 0;
} }
static int allocate_ring_buffer(struct intel_engine_cs *ring) static void intel_destroy_ringbuffer_obj(struct intel_ringbuffer *ringbuf)
{
if (!ringbuf->obj)
return;
iounmap(ringbuf->virtual_start);
i915_gem_object_ggtt_unpin(ringbuf->obj);
drm_gem_object_unreference(&ringbuf->obj->base);
ringbuf->obj = NULL;
}
static int intel_alloc_ringbuffer_obj(struct drm_device *dev,
struct intel_ringbuffer *ringbuf)
{ {
struct drm_device *dev = ring->dev;
struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_private *dev_priv = to_i915(dev);
struct intel_ringbuffer *ringbuf = ring->buffer;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
int ret; int ret;
if (intel_ring_initialized(ring)) if (ringbuf->obj)
return 0; return 0;
obj = NULL; obj = NULL;
...@@ -1562,7 +1572,7 @@ static int intel_init_ring_buffer(struct drm_device *dev, ...@@ -1562,7 +1572,7 @@ static int intel_init_ring_buffer(struct drm_device *dev,
goto error; goto error;
} }
ret = allocate_ring_buffer(ring); ret = intel_alloc_ringbuffer_obj(dev, ringbuf);
if (ret) { if (ret) {
DRM_ERROR("Failed to allocate ringbuffer %s: %d\n", ring->name, ret); DRM_ERROR("Failed to allocate ringbuffer %s: %d\n", ring->name, ret);
goto error; goto error;
...@@ -1603,11 +1613,7 @@ void intel_cleanup_ring_buffer(struct intel_engine_cs *ring) ...@@ -1603,11 +1613,7 @@ void intel_cleanup_ring_buffer(struct intel_engine_cs *ring)
intel_stop_ring_buffer(ring); intel_stop_ring_buffer(ring);
WARN_ON(!IS_GEN2(ring->dev) && (I915_READ_MODE(ring) & MODE_IDLE) == 0); WARN_ON(!IS_GEN2(ring->dev) && (I915_READ_MODE(ring) & MODE_IDLE) == 0);
iounmap(ringbuf->virtual_start); intel_destroy_ringbuffer_obj(ringbuf);
i915_gem_object_ggtt_unpin(ringbuf->obj);
drm_gem_object_unreference(&ringbuf->obj->base);
ringbuf->obj = NULL;
ring->preallocated_lazy_request = NULL; ring->preallocated_lazy_request = NULL;
ring->outstanding_lazy_seqno = 0; ring->outstanding_lazy_seqno = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment