From patchwork Tue Jul 1 18:17:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 4461151 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E4E5BBEECB for ; Tue, 1 Jul 2014 18:18:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A4262037B for ; Tue, 1 Jul 2014 18:18:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1E5102035C for ; Tue, 1 Jul 2014 18:18:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43E5A6E216; Tue, 1 Jul 2014 11:18:09 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 7434F6E197 for ; Tue, 1 Jul 2014 11:18:08 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 01 Jul 2014 11:18:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,583,1400050800"; d="scan'208";a="537317944" Received: from ironside.jf.intel.com ([10.7.197.210]) by orsmga001.jf.intel.com with ESMTP; 01 Jul 2014 11:17:53 -0700 From: Ben Widawsky To: Intel GFX Date: Tue, 1 Jul 2014 11:17:36 -0700 Message-Id: <1404238671-18760-2-git-send-email-benjamin.widawsky@intel.com> X-Mailer: git-send-email 2.0.1 In-Reply-To: <1404238671-18760-1-git-send-email-benjamin.widawsky@intel.com> References: <1404238671-18760-1-git-send-email-benjamin.widawsky@intel.com> Cc: Ben Widawsky , Ben Widawsky Subject: [Intel-gfx] [PATCH 01/16] drm/i915: Split up do_switch X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are two important reasons for this patch. It should make the existing code a lot more readable. It also makes the next patch much easier to understand in my opinion. There are 2 main variables that effect this function, leaving 4 permutations: ring: RCS vs !RCS PPGTT: full or not I didn't find extracting the full PPGTT usage to be very beneficial at this point, but it may be in the future. This was originally recommended by Daniel Vetter, and in this case, I agree. There was no intentional behavioral change. v2: Change the pin assertion to be GGTT only. This is more accurate. Signed-off-by: Ben Widawsky --- drivers/gpu/drm/i915/i915_gem_context.c | 78 +++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 0d2c75b..6dbe3e7 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -591,31 +591,57 @@ mi_set_context(struct intel_engine_cs *ring, return ret; } -static int do_switch(struct intel_engine_cs *ring, - struct intel_context *to) +static void do_switch_fini_common(struct intel_engine_cs *ring, + struct intel_context *from, + struct intel_context *to) +{ + if (likely(from)) + i915_gem_context_unreference(from); + i915_gem_context_reference(to); + ring->last_context = to; +} + +static int do_switch_xcs(struct intel_engine_cs *ring, + struct intel_context *from, + struct intel_context *to) +{ + struct drm_device *dev = ring->dev; + struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(to); + int ret; + + BUG_ON(from && from->obj != NULL); + + if (USES_FULL_PPGTT(dev)) { + ret = ppgtt->switch_mm(ppgtt, ring, false); + if (ret) + return ret; + } + + if (from) + do_switch_fini_common(ring, from, to); + + return 0; +} + +static int do_switch_rcs(struct intel_engine_cs *ring, + struct intel_context *from, + struct intel_context *to) { struct drm_i915_private *dev_priv = ring->dev->dev_private; - struct intel_context *from = ring->last_context; struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(to); u32 hw_flags = 0; bool uninitialized = false; int ret, i; - if (from != NULL && ring == &dev_priv->ring[RCS]) { + if (from != NULL) { BUG_ON(from->obj == NULL); - BUG_ON(!i915_gem_obj_is_pinned(from->obj)); + BUG_ON(!i915_gem_obj_ggtt_bound(from->obj)); } - if (from == to && !to->remap_slice) - return 0; - /* Trying to pin first makes error handling easier. */ - if (ring == &dev_priv->ring[RCS]) { - ret = i915_gem_obj_ggtt_pin(to->obj, - get_context_alignment(ring->dev), 0); - if (ret) - return ret; - } + ret = i915_gem_obj_ggtt_pin(to->obj, get_context_alignment(ring->dev), 0); + if (ret) + return ret; /* * Pin can switch back to the default context if we end up calling into @@ -630,12 +656,6 @@ static int do_switch(struct intel_engine_cs *ring, goto unpin_out; } - if (ring != &dev_priv->ring[RCS]) { - if (from) - i915_gem_context_unreference(from); - goto done; - } - /* * Clear this page out of any CPU caches for coherent swap-in/out. Note * that thanks to write = false in this call and us not setting any gpu @@ -694,15 +714,11 @@ static int do_switch(struct intel_engine_cs *ring, /* obj is kept alive until the next request by its active ref */ i915_gem_object_ggtt_unpin(from->obj); - i915_gem_context_unreference(from); } uninitialized = !to->is_initialized && from == NULL; to->is_initialized = true; - -done: - i915_gem_context_reference(to); - ring->last_context = to; + do_switch_fini_common(ring, from, to); if (uninitialized) { ret = i915_gem_render_state_init(ring); @@ -713,8 +729,7 @@ done: return 0; unpin_out: - if (ring->id == RCS) - i915_gem_object_ggtt_unpin(to->obj); + i915_gem_object_ggtt_unpin(to->obj); return ret; } @@ -732,6 +747,7 @@ int i915_switch_context(struct intel_engine_cs *ring, struct intel_context *to) { struct drm_i915_private *dev_priv = ring->dev->dev_private; + struct intel_context *from = ring->last_context; WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex)); @@ -745,7 +761,13 @@ int i915_switch_context(struct intel_engine_cs *ring, return 0; } - return do_switch(ring, to); + if (from == to && !to->remap_slice) + return 0; + + if (ring->id == RCS) + return do_switch_rcs(ring, from, to); + else + return do_switch_xcs(ring, from, to); } static bool hw_context_enabled(struct drm_device *dev)