diff mbox

[3/5] drm/i915/contexts: Switch to default on resume

Message ID 1344980117-1993-4-git-send-email-ben@bwidawsk.net (mailing list archive)
State Deferred
Headers show

Commit Message

Ben Widawsky Aug. 14, 2012, 9:35 p.m. UTC
In order to make the HW state CCID match with what we think it should
be, we must order a switch to the default context.

The really sad thing here is that the switch can potentially fail, and
as such we have to assume contexts no longer work. There is likely room
for improvement but until we actually start seeing the case occur, I
think it should be fine.

This was accidentally left this out of the first series, noticed by
Chris Wilson.

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
 drivers/gpu/drm/i915/i915_gem_context.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Chris Wilson Aug. 15, 2012, 9:18 a.m. UTC | #1
On Tue, 14 Aug 2012 14:35:15 -0700, Ben Widawsky <ben@bwidawsk.net> wrote:
> In order to make the HW state CCID match with what we think it should
> be, we must order a switch to the default context.
> 
> The really sad thing here is that the switch can potentially fail, and
> as such we have to assume contexts no longer work. There is likely room
> for improvement but until we actually start seeing the case occur, I
> think it should be fine.
> 
> This was accidentally left this out of the first series, noticed by
> Chris Wilson.

However that do_switch() is a no-op as it spots that the
ring->last_ctx_obj is the DEFAULT_CONTEXT (saved across s&r) and we exit
early.

The only clean way I could see was to extract the actual set_switch
portion of do_switch() (i.e. discard the initial checks and pre-/post-op
pinning). Which brings you nicely into the next few patches...
-Chris
Ben Widawsky Aug. 15, 2012, 3:58 p.m. UTC | #2
On 2012-08-15 02:18, Chris Wilson wrote:
> On Tue, 14 Aug 2012 14:35:15 -0700, Ben Widawsky <ben@bwidawsk.net> 
> wrote:
>> In order to make the HW state CCID match with what we think it 
>> should
>> be, we must order a switch to the default context.
>>
>> The really sad thing here is that the switch can potentially fail, 
>> and
>> as such we have to assume contexts no longer work. There is likely 
>> room
>> for improvement but until we actually start seeing the case occur, I
>> think it should be fine.
>>
>> This was accidentally left this out of the first series, noticed by
>> Chris Wilson.
>
> However that do_switch() is a no-op as it spots that the
> ring->last_ctx_obj is the DEFAULT_CONTEXT (saved across s&r) and we 
> exit
> early.
>
> The only clean way I could see was to extract the actual set_switch
> portion of do_switch() (i.e. discard the initial checks and 
> pre-/post-op
> pinning). Which brings you nicely into the next few patches...
> -Chris

Agreed, I was thinking re-ordering the series would just magically 
solve all such issues :-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 5c2d354..3e884dc 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -244,15 +244,26 @@  void i915_gem_context_init(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	uint32_t ctx_size;
 
+	if (dev_priv->hw_contexts_disabled)
+		return;
+
 	if (!HAS_HW_CONTEXTS(dev)) {
 		dev_priv->hw_contexts_disabled = true;
 		return;
 	}
 
-	/* If called from reset, or thaw... we've been here already */
-	if (dev_priv->hw_contexts_disabled ||
-	    dev_priv->ring[RCS].default_context)
+	/* If called from reset, or thaw we want to switch back to the default
+	 * context so our HW CCID matches what we think it should be in software.
+	 */
+	if (dev_priv->ring[RCS].default_context) {
+		int ret = do_switch(dev_priv->ring[RCS].default_context);
+		if (ret) {
+			DRM_ERROR("HW contexts were broken after resume\n");
+			i915_gem_context_fini(dev);
+			dev_priv->hw_contexts_disabled = true;
+		}
 		return;
+	}
 
 	ctx_size = get_context_size(dev);
 	dev_priv->hw_context_size = get_context_size(dev);