From patchwork Wed Apr 24 06:15:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 2482481 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id D1F73DF25A for ; Wed, 24 Apr 2013 06:19:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E2277E6303 for ; Tue, 23 Apr 2013 23:19:17 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from shiva.localdomain (unknown [209.20.75.48]) by gabe.freedesktop.org (Postfix) with ESMTP id 763E2E626F for ; Tue, 23 Apr 2013 23:13:24 -0700 (PDT) Received: by shiva.localdomain (Postfix, from userid 1005) id E7D4F88652; Wed, 24 Apr 2013 06:13:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on shiva.chad-versace.us X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable version=3.3.2 Received: from lundgren.kumite (c-24-21-100-90.hsd1.or.comcast.net [24.21.100.90]) by shiva.localdomain (Postfix) with ESMTPSA id 30FE48865D; Wed, 24 Apr 2013 06:13:20 +0000 (UTC) From: Ben Widawsky To: Intel GFX Date: Tue, 23 Apr 2013 23:15:37 -0700 Message-Id: <1366784140-2670-10-git-send-email-ben@bwidawsk.net> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1366784140-2670-1-git-send-email-ben@bwidawsk.net> References: <1366784140-2670-1-git-send-email-ben@bwidawsk.net> Cc: Ben Widawsky Subject: [Intel-gfx] [PATCH 09/12] drm/i915: Split context enabling from init X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 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 Context init should have only been called once, ever. The code was hackish because it predated some of the init cleanups. This patch refactors the code to leave the part which must be run more than once (reset, and thaw) as a distinct function. I need this for some of my future plans to more closely tie a context to a PPGTT. Since context_init comes before ring_init now, we also have to add the call to fini() if things go badly. Signed-off-by: Ben Widawsky --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem.c | 18 +++++++++++++++--- drivers/gpu/drm/i915/i915_gem_context.c | 18 +++++++++--------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 618845e..11cc159 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1699,6 +1699,7 @@ struct dma_buf *i915_gem_prime_export(struct drm_device *dev, /* i915_gem_context.c */ void i915_gem_context_init(struct drm_device *dev); void i915_gem_context_fini(struct drm_device *dev, bool reset); +int i915_gem_context_enable(struct drm_i915_private *dev_priv); void i915_gem_context_close(struct drm_device *dev, struct drm_file *file); int i915_switch_context(struct intel_ring_buffer *ring, struct drm_file *file, int to_id); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 9c5eaf0..fbd289d 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2151,6 +2151,8 @@ void i915_gem_reset(struct drm_device *dev) for_each_ring(ring, dev_priv, i) i915_gem_reset_ring_lists(dev_priv, ring); + i915_gem_context_fini(dev, false); + /* Move everything out of the GPU domains to ensure we do any * necessary invalidation upon reuse. */ @@ -4029,10 +4031,18 @@ i915_gem_init_hw(struct drm_device *dev) return ret; /* - * XXX: There was some w/a described somewhere suggesting loading - * contexts before PPGTT. + * XXX: Contexts should only be initialized once. Doing a switch to the + * default context switch however is something we'd like to do after + * reset or thaw (the latter may not actually be necessary for HW, but + * goes with our code better). Context switching requires rings (for + * the do_switch), but before enabling PPGTT. So don't move this. */ - i915_gem_context_init(dev); + if (!dev_priv->hw_contexts_disabled && + i915_gem_context_enable(dev_priv)) { + i915_gem_context_fini(dev, false); + dev_priv->hw_contexts_disabled = true; + } + if (dev_priv->mm.aliasing_ppgtt) { ret = dev_priv->mm.aliasing_ppgtt->enable(dev); if (ret) { @@ -4060,6 +4070,8 @@ int i915_gem_init(struct drm_device *dev) i915_gem_init_global_gtt(dev); + i915_gem_context_init(dev); + ret = i915_gem_init_hw(dev); mutex_unlock(&dev->struct_mutex); if (ret) { diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 6030d83..b2deddd 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -216,15 +216,10 @@ static int create_default_context(struct drm_i915_private *dev_priv) if (ret) goto err_destroy; - ret = do_switch(ctx); - if (ret) - goto err_unpin; + DRM_DEBUG_DRIVER("Default HW context created\n"); - DRM_DEBUG_DRIVER("Default HW context loaded\n"); return 0; -err_unpin: - i915_gem_object_unpin(ctx->obj); err_destroy: do_destroy(ctx); return ret; @@ -239,9 +234,8 @@ void i915_gem_context_init(struct drm_device *dev) 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 (WARN_ON(dev_priv->hw_contexts_disabled || + dev_priv->ring[RCS].default_context)) return; dev_priv->hw_context_size = round_up(get_context_size(dev), 4096); @@ -279,6 +273,12 @@ void i915_gem_context_fini(struct drm_device *dev, bool reset) dev_priv->ring[RCS].default_context = NULL; } +int i915_gem_context_enable(struct drm_i915_private *dev_priv) +{ + BUG_ON(!dev_priv->ring[RCS].default_context); + return do_switch(dev_priv->ring[RCS].default_context); +} + static int context_idr_cleanup(int id, void *p, void *data) { struct i915_hw_context *ctx = p;