From patchwork Wed Feb 2 23:00:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 528031 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 p12N5pGx007525 for ; Wed, 2 Feb 2011 23:06:13 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A7789E96F for ; Wed, 2 Feb 2011 15:05:51 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-yw0-f49.google.com (mail-yw0-f49.google.com [209.85.213.49]) by gabe.freedesktop.org (Postfix) with ESMTP id 059599E9C3 for ; Wed, 2 Feb 2011 15:00:53 -0800 (PST) Received: by mail-yw0-f49.google.com with SMTP id 7so239314ywf.36 for ; Wed, 02 Feb 2011 15:00:53 -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=+v/sNRGk8rggXEuV+f0ESRToqDa30fGX+0fdQgMjKFY=; b=BCRh8UdWmLgsI5tnjvuxCmUigqExZAs19aJpDMNXcK7rwnrIAJ+1z2o6xfElwDqDiH +DS06BuiwlQQjrVJU1LIzMMCARbd8i8zlBtRNrAE9Yw2suwQT6CEVmTeDiTZb58ZqiC1 Ebih32TFIi3s6KVJ1tNJGIR62f6EL+83ir8Tg= 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=O9DKY/CzIPULGOFaDijuVNhG+JFy1S5HIx6imXH021N7p7f9bl6AuWry2UlRSPqnYO kh8KND0WoVIYh4YkxhHOHYP8AIiTe0KErEbnnsq0IIGiVhwJejcsvdojC+0/wWvZb9mx s7wc0cU9/bicc7Y0ws2hsofLsWHnr+G47F4JA= Received: by 10.236.108.145 with SMTP id q17mr3558678yhg.70.1296687653905; Wed, 02 Feb 2011 15:00:53 -0800 (PST) Received: from localhost.localdomain ([134.134.139.76]) by mx.google.com with ESMTPS id i10sm79654yhd.10.2011.02.02.15.00.52 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 02 Feb 2011 15:00:53 -0800 (PST) From: Ben Widawsky To: intel-gfx@lists.freedesktop.org Date: Wed, 2 Feb 2011 15:00:19 -0800 Message-Id: <1296687620-27019-8-git-send-email-bwidawsk@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1296687620-27019-1-git-send-email-bwidawsk@gmail.com> References: <1296687620-27019-1-git-send-email-bwidawsk@gmail.com> Subject: [Intel-gfx] [PATCH 7/8] 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]); Wed, 02 Feb 2011 23:06:55 +0000 (UTC) diff --git a/drivers/gpu/drm/i915/i915_context.c b/drivers/gpu/drm/i915/i915_context.c index 1085797..7f47563 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) { @@ -265,17 +265,28 @@ static int i915_context_hw_fini(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 b2313f0..91133f3 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);