All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Subject: [PATCH v3 21/21] drm/i915: Unify GPU resets upon shutdown
Date: Sun, 24 Apr 2016 19:10:19 +0100	[thread overview]
Message-ID: <1461521419-18086-21-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1461521419-18086-1-git-send-email-chris@chris-wilson.co.uk>

Both execlists and legacy need to reset the context (and mode) of the
GPU before we lose control of the system. By resetting the GPU, we
revert back to default settings. This simplifies the life of any
subsequent driver (in particular for virtualized setups) as it does not
then have to try and recover from an unknown condition. As both paths
need to reset for the same reason, move the reset to a common point.

This unifies the resets added in a647828afc (drm/i915: Also perform gpu
reset under execlist mode) and 8e96d9c4d9 (drm/i915: reset the GPU on
context fini).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
CC: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Cc: "Niu, Bing" <bing.niu@intel.com>
---
 drivers/gpu/drm/i915/i915_dma.c         | 41 ++++++++++++++++++++++++++-------
 drivers/gpu/drm/i915/i915_gem.c         |  8 -------
 drivers/gpu/drm/i915/i915_gem_context.c |  8 +------
 3 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 5c7615041b31..68c60f4fd44d 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -425,6 +425,37 @@ static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
 	.can_switch = i915_switcheroo_can_switch,
 };
 
+static void i915_gem_fini(struct drm_device *dev)
+{
+	int reset;
+
+	/*
+	 * Neither the BIOS, ourselves or any other kernel
+	 * expects the system to be in execlists mode on startup,
+	 * so we need to reset the GPU back to legacy mode. And the only
+	 * known way to disable logical contexts is through a GPU reset.
+	 *
+	 * So in order to leave the system in a known default configuration,
+	 * always reset the GPU upon unload. Afterwards we then clean up the
+	 * GEM state tracking, flushing off the requests and leaving the
+	 * system in a known idle state.
+	 *
+	 * Note that is of the upmost importance that the GPU is idle and
+	 * all stray writes are flushed *before* we dismantle the backing
+	 * storage for the pinned objects.
+	 */
+	reset = intel_gpu_reset(dev, ALL_ENGINES);
+	WARN_ON(reset && reset != -ENODEV);
+
+	mutex_lock(&dev->struct_mutex);
+	i915_gem_reset(dev);
+	i915_gem_cleanup_engines(dev);
+	i915_gem_context_fini(dev);
+	mutex_unlock(&dev->struct_mutex);
+
+	WARN_ON(!list_empty(&to_i915(dev)->context_list));
+}
+
 static int i915_load_modeset_init(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
@@ -506,10 +537,7 @@ static int i915_load_modeset_init(struct drm_device *dev)
 	return 0;
 
 cleanup_gem:
-	mutex_lock(&dev->struct_mutex);
-	i915_gem_cleanup_engines(dev);
-	i915_gem_context_fini(dev);
-	mutex_unlock(&dev->struct_mutex);
+	i915_gem_fini(dev);
 cleanup_irq:
 	intel_guc_ucode_fini(dev);
 	drm_irq_uninstall(dev);
@@ -1456,10 +1484,7 @@ int i915_driver_unload(struct drm_device *dev)
 	flush_workqueue(dev_priv->wq);
 
 	intel_guc_ucode_fini(dev);
-	mutex_lock(&dev->struct_mutex);
-	i915_gem_cleanup_engines(dev);
-	i915_gem_context_fini(dev);
-	mutex_unlock(&dev->struct_mutex);
+	i915_gem_fini(dev);
 	intel_fbc_cleanup_cfb(dev_priv);
 
 	intel_power_domains_fini(dev_priv);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index a88aa7f11a9c..82e41eeb36bb 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4970,14 +4970,6 @@ i915_gem_cleanup_engines(struct drm_device *dev)
 
 	for_each_engine(engine, dev_priv)
 		dev_priv->gt.cleanup_engine(engine);
-
-	if (i915.enable_execlists)
-		/*
-		 * Neither the BIOS, ourselves or any other kernel
-		 * expects the system to be in execlists mode on startup,
-		 * so we need to reset the GPU back to legacy mode.
-		 */
-		intel_gpu_reset(dev, ALL_ENGINES);
 }
 
 static void
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index fef33a3ce3b7..26122de365b2 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -452,14 +452,8 @@ void i915_gem_context_fini(struct drm_device *dev)
 
 	i915_gem_context_lost(dev_priv);
 
-	if (dctx->legacy_hw_ctx.rcs_state) {
-		/* The only known way to stop the gpu from accessing the hw context is
-		 * to reset it. Do this as the very last operation to avoid confusing
-		 * other code, leading to spurious errors. */
-		intel_gpu_reset(dev, ALL_ENGINES);
-
+	if (dctx->legacy_hw_ctx.rcs_state)
 		i915_gem_object_ggtt_unpin(dctx->legacy_hw_ctx.rcs_state);
-	}
 
 	i915_gem_context_unreference(dctx);
 	dev_priv->kernel_context = NULL;
-- 
2.8.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-04-24 18:11 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-24 18:09 [PATCH v3 01/21] drm/i915/fbdev: Call intel_unpin_fb_obj() on release Chris Wilson
2016-04-24 18:10 ` [PATCH v3 02/21] drm/i915/overlay: Replace i915_gem_obj_ggtt_offset() with the known flip_addr Chris Wilson
2016-04-24 18:10 ` [PATCH v3 03/21] io-mapping: Specify mapping size for io_mapping_map_wc() Chris Wilson
2016-04-24 18:10   ` Chris Wilson
2016-04-24 18:10   ` Chris Wilson
2016-04-24 18:10 ` [PATCH v3 04/21] drm/i915: Introduce i915_vm_to_ggtt() Chris Wilson
2016-04-24 18:10 ` [PATCH v3 05/21] drm/i915: Move ioremap_wc tracking onto VMA Chris Wilson
2016-04-24 18:10 ` [PATCH v3 06/21] drm/i915: Use i915_vma_pin_iomap on the ringbuffer object Chris Wilson
2016-04-24 18:10 ` [PATCH v3 07/21] drm/i915: Mark the current context as lost on suspend Chris Wilson
2016-04-24 18:10 ` [PATCH v3 08/21] drm/i915: L3 cache remapping is part of context switching Chris Wilson
2016-04-24 18:10 ` [PATCH v3 09/21] drm/i915: Consolidate L3 remapping LRI Chris Wilson
2016-04-24 18:10 ` [PATCH v3 10/21] drm/i915: Remove early l3-remap Chris Wilson
2016-04-24 18:10 ` [PATCH v3 11/21] drm/i915: Rearrange switch_context to load the aliasing ppgtt on first use Chris Wilson
2016-04-24 18:10 ` [PATCH v3 12/21] drm/i915: Assign every HW context a unique ID Chris Wilson
2016-04-24 18:10 ` [PATCH v3 13/21] drm/i915: Replace the pinned context address with its " Chris Wilson
2016-04-25 15:21   ` Dave Gordon
2016-04-25 15:48     ` Chris Wilson
2016-04-26  8:06       ` Dave Gordon
2016-04-26  8:40         ` Chris Wilson
2016-04-24 18:10 ` [PATCH v3 14/21] drm/i915: Refactor execlists default context pinning Chris Wilson
2016-04-24 18:10 ` [PATCH v3 15/21] drm/i915: Move context initialisation to first-use Chris Wilson
2016-04-24 18:10 ` [PATCH v3 16/21] drm/i915: Move the magical deferred context allocation into the request Chris Wilson
2016-04-24 18:10 ` [PATCH v3 17/21] drm/i915: Move releasing of the GEM request from free to retire/cancel Chris Wilson
2016-04-24 18:10 ` [PATCH v3 18/21] drm/i915: Track the previous pinned context inside the request Chris Wilson
2016-04-24 18:10 ` [PATCH v3 19/21] drm/i915: Store LRC hardware id in " Chris Wilson
2016-04-24 18:10 ` [PATCH v3 20/21] drm/i915: Stop tracking execlists retired requests Chris Wilson
2016-04-24 18:10 ` Chris Wilson [this message]
2016-04-25  9:42   ` [PATCH v3 21/21] drm/i915: Unify GPU resets upon shutdown Mika Kuoppala
2016-04-25 17:25   ` Ville Syrjälä
2016-04-25 17:45     ` Chris Wilson
2016-04-25 18:42       ` Ville Syrjälä
2016-04-25  8:20 ` ✗ Fi.CI.BAT: warning for series starting with [v3,01/21] drm/i915/fbdev: Call intel_unpin_fb_obj() on release Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461521419-18086-21-git-send-email-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mika.kuoppala@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.