drm/i915: Move fiddling with engine->last_retired_context
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 17 May 2018 21:26:31 +0000 (22:26 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 18 May 2018 08:35:21 +0000 (09:35 +0100)
Move the knowledge about resetting the current context tracking on the
engine from inside i915_gem_context.c into intel_engine_cs.c

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180517212633.24934-2-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_gem_context.c
drivers/gpu/drm/i915/intel_engine_cs.c
drivers/gpu/drm/i915/intel_ringbuffer.h

index 4bf18b5..9e70f4d 100644 (file)
@@ -514,16 +514,8 @@ void i915_gem_contexts_lost(struct drm_i915_private *dev_priv)
 
        lockdep_assert_held(&dev_priv->drm.struct_mutex);
 
-       for_each_engine(engine, dev_priv, id) {
-               engine->legacy_active_context = NULL;
-               engine->legacy_active_ppgtt = NULL;
-
-               if (!engine->last_retired_context)
-                       continue;
-
-               intel_context_unpin(engine->last_retired_context, engine);
-               engine->last_retired_context = NULL;
-       }
+       for_each_engine(engine, dev_priv, id)
+               intel_engine_lost_context(engine);
 }
 
 void i915_gem_contexts_fini(struct drm_i915_private *i915)
index 7983b8a..9e618aa 100644 (file)
@@ -1096,6 +1096,29 @@ void intel_engines_unpark(struct drm_i915_private *i915)
        }
 }
 
+/**
+ * intel_engine_lost_context: called when the GPU is reset into unknown state
+ * @engine: the engine
+ *
+ * We have either reset the GPU or otherwise about to lose state tracking of
+ * the current GPU logical state (e.g. suspend). On next use, it is therefore
+ * imperative that we make no presumptions about the current state and load
+ * from scratch.
+ */
+void intel_engine_lost_context(struct intel_engine_cs *engine)
+{
+       struct i915_gem_context *ctx;
+
+       lockdep_assert_held(&engine->i915->drm.struct_mutex);
+
+       engine->legacy_active_context = NULL;
+       engine->legacy_active_ppgtt = NULL;
+
+       ctx = fetch_and_zero(&engine->last_retired_context);
+       if (ctx)
+               intel_context_unpin(ctx, engine);
+}
+
 bool intel_engine_can_store_dword(struct intel_engine_cs *engine)
 {
        switch (INTEL_GEN(engine->i915)) {
index 61f385a..2b16185 100644 (file)
@@ -1053,6 +1053,7 @@ bool intel_engine_is_idle(struct intel_engine_cs *engine);
 bool intel_engines_are_idle(struct drm_i915_private *dev_priv);
 
 bool intel_engine_has_kernel_context(const struct intel_engine_cs *engine);
+void intel_engine_lost_context(struct intel_engine_cs *engine);
 
 void intel_engines_park(struct drm_i915_private *i915);
 void intel_engines_unpark(struct drm_i915_private *i915);