drm/i915: Empty the ring before disabling
authorChris Wilson <chris@chris-wilson.co.uk>
Fri, 27 Oct 2017 09:43:11 +0000 (10:43 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 27 Oct 2017 11:09:29 +0000 (12:09 +0100)
An interesting snippet from Sandybridge's prm:

"Although a Ring Buffer can be enabled in the non-empty state, it must
not be disabled unless it is empty. Attempting to disable a Ring Buffer
in the non-empty state is UNDEFINED."

Let's avoid the undefined behaviour as we disable the rings prior to
reset and resume.

v2: Tell HEAD to catch up to TAIL (empty ring) first, then reset both to
0 (supposedly while stopped).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171027094311.30380-1-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/intel_ringbuffer.c
drivers/gpu/drm/i915/intel_uncore.c

index 05e01446b00b321bc92411751a74ba02d32c1de5..47fadf8da84e9e374b721bb56a88c7160e1413eb 100644 (file)
@@ -480,10 +480,14 @@ static bool stop_ring(struct intel_engine_cs *engine)
                }
        }
 
-       I915_WRITE_CTL(engine, 0);
+       I915_WRITE_HEAD(engine, I915_READ_TAIL(engine));
+
        I915_WRITE_HEAD(engine, 0);
        I915_WRITE_TAIL(engine, 0);
 
+       /* The ring must be empty before it is disabled */
+       I915_WRITE_CTL(engine, 0);
+
        return (I915_READ_HEAD(engine) & HEAD_ADDR) == 0;
 }
 
index 20e3c65c0999f88ee68c09c3aa13533bbe0b1a5c..96ee6b2754bed12500d2747772d5e24dab7cbac0 100644 (file)
@@ -1387,10 +1387,14 @@ static void gen3_stop_engine(struct intel_engine_cs *engine)
                DRM_DEBUG_DRIVER("%s: timed out on STOP_RING\n",
                                 engine->name);
 
-       I915_WRITE_FW(RING_CTL(base), 0);
+       I915_WRITE_FW(RING_HEAD(base), I915_READ_FW(RING_TAIL(base)));
+
        I915_WRITE_FW(RING_HEAD(base), 0);
        I915_WRITE_FW(RING_TAIL(base), 0);
 
+       /* The ring must be empty before it is disabled */
+       I915_WRITE_FW(RING_CTL(base), 0);
+
        /* Check acts as a post */
        if (I915_READ_FW(RING_HEAD(base)) != 0)
                DRM_DEBUG_DRIVER("%s: ring head not parked\n",