drm/i915: Pull out some more common engine init code
authorTvrtko Ursulin <tvrtko.ursulin@intel.com>
Wed, 13 Jul 2016 15:03:41 +0000 (16:03 +0100)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Thu, 14 Jul 2016 10:17:24 +0000 (11:17 +0100)
Created two common helpers for engine setup and engine init phases
respectively to help with code sharing.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1468422221-12132-1-git-send-email-tvrtko.ursulin@linux.intel.com
Reviewed-by: Chris Wilson <chris-wilson.co.uk>
drivers/gpu/drm/i915/intel_engine_cs.c
drivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/intel_ringbuffer.c
drivers/gpu/drm/i915/intel_ringbuffer.h

index 80117b4990243c9788b76e1a7da58bc4957024ff..e3c9f04ea51ed2315bb139b3d0b5820e6994aa39 100644 (file)
@@ -160,3 +160,50 @@ cleanup:
        return ret;
 }
 
+void intel_engine_init_hangcheck(struct intel_engine_cs *engine)
+{
+       memset(&engine->hangcheck, 0, sizeof(engine->hangcheck));
+}
+
+/**
+ * intel_engines_setup_common - setup engine state not requiring hw access
+ * @engine: Engine to setup.
+ *
+ * Initializes @engine@ structure members shared between legacy and execlists
+ * submission modes which do not require hardware access.
+ *
+ * Typically done early in the submission mode specific engine setup stage.
+ */
+void intel_engine_setup_common(struct intel_engine_cs *engine)
+{
+       INIT_LIST_HEAD(&engine->active_list);
+       INIT_LIST_HEAD(&engine->request_list);
+       INIT_LIST_HEAD(&engine->buffers);
+       INIT_LIST_HEAD(&engine->execlist_queue);
+       spin_lock_init(&engine->execlist_lock);
+
+       intel_engine_init_hangcheck(engine);
+       i915_gem_batch_pool_init(&engine->i915->drm, &engine->batch_pool);
+}
+
+/**
+ * intel_engines_init_common - initialize cengine state which might require hw access
+ * @engine: Engine to initialize.
+ *
+ * Initializes @engine@ structure members shared between legacy and execlists
+ * submission modes which do require hardware access.
+ *
+ * Typcally done at later stages of submission mode specific engine setup.
+ *
+ * Returns zero on success or an error code on failure.
+ */
+int intel_engine_init_common(struct intel_engine_cs *engine)
+{
+       int ret;
+
+       ret = intel_engine_init_breadcrumbs(engine);
+       if (ret)
+               return ret;
+
+       return i915_cmd_parser_init_ring(engine);
+}
index 6e88d9af93282270ef19116e92dab7b2085bbd04..b6af635e3a0fc4f0f52054baef2dae0aa2ec52d3 100644 (file)
@@ -2009,6 +2009,8 @@ logical_ring_setup(struct intel_engine_cs *engine)
        struct drm_i915_private *dev_priv = engine->i915;
        enum forcewake_domains fw_domains;
 
+       intel_engine_setup_common(engine);
+
        /* Intentionally left blank. */
        engine->buffer = NULL;
 
@@ -2026,21 +2028,12 @@ logical_ring_setup(struct intel_engine_cs *engine)
 
        engine->fw_domains = fw_domains;
 
-       INIT_LIST_HEAD(&engine->active_list);
-       INIT_LIST_HEAD(&engine->request_list);
-       INIT_LIST_HEAD(&engine->buffers);
-       INIT_LIST_HEAD(&engine->execlist_queue);
-       spin_lock_init(&engine->execlist_lock);
-
        tasklet_init(&engine->irq_tasklet,
                     intel_lrc_irq_handler, (unsigned long)engine);
 
        logical_ring_init_platform_invariants(engine);
        logical_ring_default_vfuncs(engine);
        logical_ring_default_irqs(engine);
-
-       intel_engine_init_hangcheck(engine);
-       i915_gem_batch_pool_init(&dev_priv->drm, &engine->batch_pool);
 }
 
 static int
@@ -2049,11 +2042,7 @@ logical_ring_init(struct intel_engine_cs *engine)
        struct i915_gem_context *dctx = engine->i915->kernel_context;
        int ret;
 
-       ret = intel_engine_init_breadcrumbs(engine);
-       if (ret)
-               goto error;
-
-       ret = i915_cmd_parser_init_ring(engine);
+       ret = intel_engine_init_common(engine);
        if (ret)
                goto error;
 
index 3a8df752ceae326a889a37c9f120aa0365eb73ae..94c8ef461721b8a9860529a91e18d81c06724464 100644 (file)
@@ -549,11 +549,6 @@ static bool stop_ring(struct intel_engine_cs *engine)
        return (I915_READ_HEAD(engine) & HEAD_ADDR) == 0;
 }
 
-void intel_engine_init_hangcheck(struct intel_engine_cs *engine)
-{
-       memset(&engine->hangcheck, 0, sizeof(engine->hangcheck));
-}
-
 static int init_ring_common(struct intel_engine_cs *engine)
 {
        struct drm_i915_private *dev_priv = engine->i915;
@@ -2176,15 +2171,12 @@ static int intel_init_ring_buffer(struct intel_engine_cs *engine)
 
        WARN_ON(engine->buffer);
 
-       INIT_LIST_HEAD(&engine->active_list);
-       INIT_LIST_HEAD(&engine->request_list);
-       INIT_LIST_HEAD(&engine->execlist_queue);
-       INIT_LIST_HEAD(&engine->buffers);
-       i915_gem_batch_pool_init(&dev_priv->drm, &engine->batch_pool);
+       intel_engine_setup_common(engine);
+
        memset(engine->semaphore.sync_seqno, 0,
               sizeof(engine->semaphore.sync_seqno));
 
-       ret = intel_engine_init_breadcrumbs(engine);
+       ret = intel_engine_init_common(engine);
        if (ret)
                goto error;
 
@@ -2225,10 +2217,6 @@ static int intel_init_ring_buffer(struct intel_engine_cs *engine)
                goto error;
        }
 
-       ret = i915_cmd_parser_init_ring(engine);
-       if (ret)
-               goto error;
-
        return 0;
 
 error:
index db7613e8d585ee97e64d5fcef227ece433d00a40..df7587ab1ba78f288c918f69694553792297fc74 100644 (file)
@@ -480,6 +480,9 @@ int intel_ring_invalidate_all_caches(struct drm_i915_gem_request *req);
 int intel_init_pipe_control(struct intel_engine_cs *engine, int size);
 void intel_fini_pipe_control(struct intel_engine_cs *engine);
 
+void intel_engine_setup_common(struct intel_engine_cs *engine);
+int intel_engine_init_common(struct intel_engine_cs *engine);
+
 int intel_init_render_ring_buffer(struct intel_engine_cs *engine);
 int intel_init_bsd_ring_buffer(struct intel_engine_cs *engine);
 int intel_init_bsd2_ring_buffer(struct intel_engine_cs *engine);