From patchwork Tue Feb 1 18:16:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 523671 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p11INhtS003360 for ; Tue, 1 Feb 2011 18:24:03 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E30039E933 for ; Tue, 1 Feb 2011 10:23:42 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-yi0-f49.google.com (mail-yi0-f49.google.com [209.85.218.49]) by gabe.freedesktop.org (Postfix) with ESMTP id 6B72C9E764 for ; Tue, 1 Feb 2011 10:18:08 -0800 (PST) Received: by yib2 with SMTP id 2so2693109yib.36 for ; Tue, 01 Feb 2011 10:18:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=3opfALHIlqisCpZj9aW4hksXw8wf58VhxmbjBN+c7kI=; b=ENFVvvsfGjXXXlOmmmE8O1u29SkYAfSe+Clmdr+/W2IA62yzxTpjbdO0I8pBRVTelq Gzx9sX9Ahu+98Q0lZZxtRvef0r/OEcs6zqabLNh3OMn2u6e0U4l2gU7tSIWgFLQjeIMS urfwLeeo/ZS6N7kaaFBwlpUXGAjbXkq/5eDsk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=cdHAupB0Fq8zr0yaP/WxTOuFkKiPbzxx6F+AOXWI2+jxach5gRQip7n+m2n2jFiV7b flvLr5zjA8I8MgPg7VqtZrw+l2oPfeS6UnM4rRE+eArfBDZx8m/X0hjWP5w5CKyVArw0 mNPiNospJh2jbW9/391cI8kHCv9CQfBANGPig= Received: by 10.90.97.14 with SMTP id u14mr10953360agb.26.1296584287878; Tue, 01 Feb 2011 10:18:07 -0800 (PST) Received: from localhost.localdomain ([67.208.96.87]) by mx.google.com with ESMTPS id f10sm27543608anh.5.2011.02.01.10.18.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 01 Feb 2011 10:18:07 -0800 (PST) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Tue, 1 Feb 2011 10:16:26 -0800 Message-Id: <1296584186-20446-10-git-send-email-bwidawsk@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1296584186-20446-1-git-send-email-bwidawsk@gmail.com> References: <1296584186-20446-1-git-send-email-bwidawsk@gmail.com> Subject: [Intel-gfx] [PATCH 9/9] drm/i915/context: Insert MI_SET_CONTEXT in ringbuffer context switch X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 01 Feb 2011 18:24:03 +0000 (UTC) diff --git a/drivers/gpu/drm/i915/i915_context.c b/drivers/gpu/drm/i915/i915_context.c index 4f255fb..6674a9d 100644 --- a/drivers/gpu/drm/i915/i915_context.c +++ b/drivers/gpu/drm/i915/i915_context.c @@ -81,7 +81,7 @@ i915_context_validate(struct drm_device *dev, struct drm_file *file, struct drm_gem_object *obj; struct drm_i915_gem_object *obj_priv; struct drm_i915_gem_context *ctx; - int i, ret = 0; + int i; ctx = i915_context_lookup_id(dev, ctx_id); if (ctx == NULL) { @@ -261,21 +261,32 @@ static void i915_context_hw_init(struct drm_device *dev, mutex_unlock(&dev->struct_mutex); } -static void i915_context_hw_deinit(struct drm_device *dev, +static int i915_context_hw_deinit(struct drm_device *dev, struct drm_i915_gem_context *ctx, struct intel_ring_buffer *ring) { + int ret; + struct drm_i915_private *dev_priv = dev->dev_private; + /* XXX We can prevent restoring contexts, but not saving them * so if we're going to take away our backing context object * of the last context, we have to switch now. */ - struct drm_i915_private *dev_priv = dev->dev_private; + mutex_lock(&dev->struct_mutex); if (ring->last_context == ctx && ctx != dev_priv->default_context) { - mutex_lock(&dev->struct_mutex); - ring->context_switch(ring, dev_priv->default_context, - I915_CONTEXT_NORMAL_SWITCH); - mutex_unlock(&dev->struct_mutex); + DRM_DEBUG_DRIVER("Switching to default context\n"); + ret = ring->context_switch(ring, dev_priv->default_context, + I915_CONTEXT_NORMAL_SWITCH); + if (ret) { + DRM_ERROR("Couldn't switch back to default context\n"); + goto out; + } + ring->last_context = dev_priv->default_context; } + +out: + mutex_unlock(&dev->struct_mutex); + return ret; } static int @@ -428,7 +439,8 @@ void i915_context_init(struct drm_device *dev) dev_priv->ctx_disable = 1; idr_destroy(&dev_priv->i915_ctx_idr); } else { - DRM_DEBUG_DRIVER("Context support enabled\n", ret); + DRM_DEBUG_DRIVER("Default context = %p\n", + to_intel_bo(dev_priv->default_context->ctx_obj)->gtt_offset); } } diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index 9d022fb..c1d9a0a 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -990,7 +990,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, struct drm_i915_gem_object *batch_obj; struct drm_clip_rect *cliprects = NULL; struct intel_ring_buffer *ring; - struct drm_i915_gem_context *ctx; + struct drm_i915_gem_context *ctx = NULL; u32 exec_start, exec_len; u32 seqno; u32 ctx_id; @@ -1013,7 +1013,9 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, DRM_DEBUG_DRIVER("Context resubmission required\n"); return -EIO; } - } + } else + ctx = dev_priv->default_context; + #if WATCH_EXEC DRM_INFO("buffers_ptr %d buffer_count %d len %08x\n", (int) args->buffers_ptr, args->buffer_count, args->batch_len); @@ -1203,8 +1205,11 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, } } - if (!dev_priv->ctx_disable) - ring->context_switch(ring, ctx, I915_CONTEXT_NORMAL_SWITCH); + if (!dev_priv->ctx_disable) { + ret = ring->context_switch(ring, ctx, I915_CONTEXT_NORMAL_SWITCH); + if (ret) + goto err; + } exec_start = batch_obj->gtt_offset + args->batch_start_offset; exec_len = args->batch_len; diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c index 89adb9d..4381730 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -750,15 +750,55 @@ render_ring_dispatch_execbuffer(struct intel_ring_buffer *ring, return 0; } -static void +static int render_ring_ctx_switch(struct intel_ring_buffer *ring, struct drm_i915_gem_context *ctx, - uint32_t flags) + u32 flags) { + struct drm_device *dev = ring->dev; + struct drm_gem_object *obj; + uint32_t ctx_switch_flags; + int ret = 0; + if (ring->last_context == ctx) - return; + return 0; + + DRM_DEBUG_DRIVER("Context switch to %d\n", + ctx->ctx_id); ring->last_context = ctx; + obj = ctx->ctx_obj; + + if (flags == I915_CONTEXT_SAVE_ONLY) + ctx_switch_flags = MI_RESTORE_INHIBIT; + else + ctx_switch_flags = 0; + + ret = intel_ring_begin(ring, 4); + if (ret) + return ret; + + if (IS_IRONLAKE_D(dev) || IS_IRONLAKE_M(dev)) + intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); + else + intel_ring_emit(ring, MI_NOOP); + + intel_ring_emit(ring, MI_SET_CONTEXT); + intel_ring_emit(ring, to_intel_bo(obj)->gtt_offset | + MI_MM_SPACE_GTT | + MI_SAVE_EXT_STATE_EN | + MI_RESTORE_EXT_STATE_EN | + ctx_switch_flags); + + if (IS_IRONLAKE_D(dev) || IS_IRONLAKE_M(dev)) + intel_ring_emit(ring, MI_SUSPEND_FLUSH); + /* TODO: we may need a NOOP here */ + else + intel_ring_emit(ring, MI_NOOP); + + intel_ring_advance(ring); + + return 0; } static void cleanup_status_page(struct intel_ring_buffer *ring) diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index 61525ba..e8f8b6a 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -80,7 +80,7 @@ struct intel_ring_buffer { u32 offset, u32 length); void (*cleanup)(struct intel_ring_buffer *ring); struct drm_i915_gem_context *last_context; - void (*context_switch)(struct intel_ring_buffer *ring, + int (*context_switch)(struct intel_ring_buffer *ring, struct drm_i915_gem_context *ctx, u32 flags);