All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sagar Arun Kamble <sagar.a.kamble@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH v13 13/21] drm/i915/uc: Support resume from sleep w/ and w/o GuC/HuC reload
Date: Wed, 11 Oct 2017 14:24:08 +0530	[thread overview]
Message-ID: <1507712056-25030-14-git-send-email-sagar.a.kamble@intel.com> (raw)
In-Reply-To: <1507712056-25030-1-git-send-email-sagar.a.kamble@intel.com>

GuC/HuC resume operation depends on whether firmwares are available
in the WOPCM region. This is known through register WOPCM_SIZE BIT(0).

If it indicates WOPCM is locked (bit is set) we just need to send action
to GuC to resume and enable other related GuC functionality such as
communication, interrupts and submission.

If it indicates WOPCM is not locked then we need to first reload the
GuC/HuC and then do all resume tasks. Currently on resume from sleep,
GuC/HuC are not loaded as GPU is reset at the end of suspend/early resume.
So we will have to reload the firmware and send action to resume.
Resume will be done through uc_init_hw from gem_init_hw based on newly
introduced state "guc->suspended". During gem_init_hw firmware load will
be skipped based on resume status during intel_uc_resume.

Also updated the accesses to dev_priv->guc and dev_priv->huc structure by
reusing initial declared pointer.

Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_guc_reg.h |  1 +
 drivers/gpu/drm/i915/intel_guc.c    |  2 +
 drivers/gpu/drm/i915/intel_guc.h    |  3 ++
 drivers/gpu/drm/i915/intel_uc.c     | 99 +++++++++++++++++++++++++++++--------
 4 files changed, 85 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_guc_reg.h b/drivers/gpu/drm/i915/i915_guc_reg.h
index 35cf991..532296b 100644
--- a/drivers/gpu/drm/i915/i915_guc_reg.h
+++ b/drivers/gpu/drm/i915/i915_guc_reg.h
@@ -75,6 +75,7 @@
 
 /* Defines WOPCM space available to GuC firmware */
 #define GUC_WOPCM_SIZE			_MMIO(0xc050)
+#define   GUC_WOPCM_LOCKED		  BIT(0)
 /* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
 #define   GUC_WOPCM_TOP			  (0x80 << 12)	/* 512KB */
 #define   BXT_GUC_WOPCM_RC6_RESERVED	  (0x10 << 12)	/* 64KB  */
diff --git a/drivers/gpu/drm/i915/intel_guc.c b/drivers/gpu/drm/i915/intel_guc.c
index 55a0158..73be382 100644
--- a/drivers/gpu/drm/i915/intel_guc.c
+++ b/drivers/gpu/drm/i915/intel_guc.c
@@ -65,6 +65,8 @@ void intel_guc_init_early(struct intel_guc *guc)
 	mutex_init(&guc->send_mutex);
 	guc->send = intel_guc_send_nop;
 	guc->notify = gen8_guc_raise_irq;
+	guc->suspended = false;
+	guc->skip_load_on_resume = false;
 }
 
 int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len)
diff --git a/drivers/gpu/drm/i915/intel_guc.h b/drivers/gpu/drm/i915/intel_guc.h
index a587210..9f84033 100644
--- a/drivers/gpu/drm/i915/intel_guc.h
+++ b/drivers/gpu/drm/i915/intel_guc.h
@@ -38,6 +38,9 @@ struct intel_guc {
 	struct intel_guc_log log;
 	struct intel_guc_ct ct;
 
+	bool suspended;
+	bool skip_load_on_resume;
+
 	/* Log snapshot if GuC errors during load */
 	struct drm_i915_gem_object *load_err_log;
 
diff --git a/drivers/gpu/drm/i915/intel_uc.c b/drivers/gpu/drm/i915/intel_uc.c
index 1365724..f641872 100644
--- a/drivers/gpu/drm/i915/intel_uc.c
+++ b/drivers/gpu/drm/i915/intel_uc.c
@@ -152,14 +152,35 @@ static void guc_disable_communication(struct intel_guc *guc)
 	guc->send = intel_guc_send_nop;
 }
 
+static inline bool guc_wopcm_locked(struct intel_guc *guc)
+{
+	struct drm_i915_private *dev_priv = guc_to_i915(guc);
+
+	return I915_READ(GUC_WOPCM_SIZE) & GUC_WOPCM_LOCKED;
+}
+
 int intel_uc_init_hw(struct drm_i915_private *dev_priv)
 {
 	struct intel_guc *guc = &dev_priv->guc;
+	struct intel_huc *huc = &dev_priv->huc;
 	int ret, attempts;
 
 	if (!i915_modparams.enable_guc_loading)
 		return 0;
 
+	/*
+	 * If on resume from sleep GuC was available we resumed GuC during
+	 * i915_gem_resume. We need to skip load here. Reset skip_load_on_resume
+	 * to allow load during module reload/reset/next resume behavior.
+	 */
+	if (guc->skip_load_on_resume) {
+		guc->skip_load_on_resume = false;
+		return 0;
+	}
+
+	WARN_ON_ONCE(guc->fw.load_status == INTEL_UC_FIRMWARE_SUCCESS);
+	WARN_ON_ONCE(huc->fw.load_status == INTEL_UC_FIRMWARE_SUCCESS);
+
 	guc_disable_communication(guc);
 	gen9_reset_guc_interrupts(dev_priv);
 
@@ -197,8 +218,8 @@ int intel_uc_init_hw(struct drm_i915_private *dev_priv)
 		if (ret)
 			goto err_submission;
 
-		intel_huc_init_hw(&dev_priv->huc);
-		ret = intel_guc_init_hw(&dev_priv->guc);
+		intel_huc_init_hw(huc);
+		ret = intel_guc_init_hw(guc);
 		if (ret == 0 || ret != -EAGAIN)
 			break;
 
@@ -214,7 +235,21 @@ int intel_uc_init_hw(struct drm_i915_private *dev_priv)
 	if (ret)
 		goto err_log_capture;
 
-	intel_huc_auth(&dev_priv->huc);
+	/*
+	 * If WOPCM was not locked during resume from sleep, GuC/HuC need to
+	 * be reloaded. For this we are using intel_uc_init_hw path as we want
+	 * to handle HuC/GuC reload, GuC resume, HuC authentication and
+	 * submission enabling etc. all here.
+	 */
+	if (guc->suspended) {
+		ret = intel_guc_resume(guc);
+		if (ret)
+			DRM_ERROR("GuC resume failed (%d)."
+				  " GuC functions may not work\n", ret);
+		guc->suspended = false;
+	}
+
+	intel_huc_auth(huc);
 	if (i915_guc_submission_initialized(guc)) {
 		if (i915_modparams.guc_log_level >= 0)
 			gen9_enable_guc_interrupts(dev_priv);
@@ -305,6 +340,8 @@ int intel_uc_suspend(struct drm_i915_private *dev_priv)
 	gen9_disable_guc_interrupts(dev_priv);
 	guc_disable_communication(guc);
 
+	guc->suspended = true;
+
 	goto out;
 
 out_suspend:
@@ -326,28 +363,50 @@ int intel_uc_suspend(struct drm_i915_private *dev_priv)
 void intel_uc_resume(struct drm_i915_private *dev_priv)
 {
 	struct intel_guc *guc = &dev_priv->guc;
+	struct intel_huc *huc = &dev_priv->huc;
 	int ret;
 
-	if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
-		return;
-
-	ret = guc_enable_communication(guc);
-	if (ret) {
-		DRM_DEBUG_DRIVER("GuC communication enable failed (%d)\n", ret);
+	if (!guc->suspended)
 		return;
-	}
 
-	if (i915_modparams.guc_log_level >= 0)
-		gen9_enable_guc_interrupts(dev_priv);
+	/*
+	 * If WOPCM is locked then GuC and HuC are still loaded. We just
+	 * need to enable communication with GuC, enable interrupts,
+	 * invoke GuC action to resume from sleep and enable submission.
+	 * If WOPCM is not locked it is similar to fresh boot and we need
+	 * reload the GuC/HuC firmwares and enable other GuC related
+	 * mechanisms. Post reloading GuC we need to send action to resume
+	 * from sleep for GuC to restore its state prior to suspend.
+	 */
+	if (guc_wopcm_locked(guc)) {
+		huc->fw.load_status = INTEL_UC_FIRMWARE_SUCCESS;
+		guc->fw.load_status = INTEL_UC_FIRMWARE_SUCCESS;
 
-	ret = intel_guc_resume(guc);
-	if (ret)
-		DRM_ERROR("GuC resume failed (%d)."
-			  "GuC functions may not work\n", ret);
+		ret = guc_enable_communication(guc);
+		if (ret) {
+			DRM_DEBUG_DRIVER("GuC communication enable failed"
+					 " (%d)\n", ret);
+			return;
+		}
 
-	i915_guc_submission_enable(dev_priv);
+		if (i915_modparams.guc_log_level >= 0)
+			gen9_enable_guc_interrupts(dev_priv);
 
-	DRM_DEBUG_DRIVER("GuC submission %s\n",
-			 i915_guc_submission_enabled(guc) ?
-			 "enabled" : "disabled");
+		ret = intel_guc_resume(guc);
+		if (ret)
+			DRM_ERROR("GuC resume failed (%d)."
+				  " GuC functions may not work\n", ret);
+
+		i915_guc_submission_enable(dev_priv);
+
+		DRM_DEBUG_DRIVER("GuC submission %s\n",
+				 i915_guc_submission_enabled(guc) ?
+				 "enabled" : "disabled");
+		guc->suspended = false;
+		guc->skip_load_on_resume = true;
+	} else {
+		DRM_DEBUG_DRIVER("GuC not available. Resume will be done"
+				 " during i915_gem_init_hw\n");
+		guc->skip_load_on_resume = false;
+	}
 }
-- 
1.9.1

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

  parent reply	other threads:[~2017-10-11  8:51 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11  8:53 [PATCH v13 00/21] drm/i915: GEM/GuC Suspend/Resume/Reset fixes and restructuring Sagar Arun Kamble
2017-10-11  8:53 ` [PATCH v13 01/21] drm/i915/guc: Add GuC submission initialization/enable state variables Sagar Arun Kamble
2017-10-11  8:53 ` [PATCH v13 02/21] drm/i915/guc: Sanitize module parameter guc_log_level Sagar Arun Kamble
2017-10-11 14:51   ` Michal Wajdeczko
2017-10-12  5:48     ` Sagar Arun Kamble
2017-10-11  8:53 ` [PATCH v13 03/21] drm/i915/guc: Add status checks to enable/disable_guc_interrupts Sagar Arun Kamble
2017-10-11 15:20   ` Michal Wajdeczko
2017-10-12  5:50     ` Sagar Arun Kamble
2017-10-12  6:17       ` Sagar Arun Kamble
2017-10-13  8:09         ` Sagar Arun Kamble
2017-10-11  8:53 ` [PATCH v13 04/21] drm/i915/guc: Remove enable_guc_submission dependency for invoking GuC log functions Sagar Arun Kamble
2017-10-11 15:40   ` Michal Wajdeczko
2017-10-12  5:58     ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 05/21] drm/i915/guc: Update enable_guc_loading check in intel_uc_fini_hw Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 06/21] drm/i915/guc: Pass intel_guc struct parameter to intel_guc_suspend/resume Sagar Arun Kamble
2017-10-11 15:50   ` Michal Wajdeczko
2017-10-12  6:18     ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 07/21] drm/i915: Create GEM runtime resume helper and handle GEM runtime suspend error Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 08/21] drm/i915/guc: Update GEM suspend/resume flows with GuC suspend/resume functions Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 09/21] drm/i915/uc: Create uC suspend and resume functions Sagar Arun Kamble
2017-10-11 15:57   ` Michal Wajdeczko
2017-10-12  6:25     ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 10/21] drm/i915/guc: Update uC suspend/resume function separating Host/GuC tasks Sagar Arun Kamble
2017-10-11 16:19   ` Michal Wajdeczko
2017-10-12  6:38     ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 11/21] drm/i915/guc: Remove GuC submission disable from i915_driver_unload Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 12/21] drm/i915/guc: Fix GuC related state cleanup in unload path Sagar Arun Kamble
2017-10-11  8:54 ` Sagar Arun Kamble [this message]
2017-10-11 17:06   ` [PATCH v13 13/21] drm/i915/uc: Support resume from sleep w/ and w/o GuC/HuC reload Michal Wajdeczko
2017-10-12  6:48     ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 14/21] drm/i915/uc: Update GEM runtime resume with need for reload of GuC/HuC Sagar Arun Kamble
2017-10-11 17:19   ` Michal Wajdeczko
2017-10-12  6:50     ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 15/21] drm/i915/guc: Add comment about update needed in GuC submission enable/disable for RPM Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 16/21] drm/i915: Enable interrupts prior to GEM resume during i915_drm_resume Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 17/21] drm/i915: Split i915_gem_suspend into gem quiescing and HW suspend Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 18/21] drm/i915/uc: Introduce intel_uc_sanitize to initialize GuC/HuC reset state Sagar Arun Kamble
2017-10-11 17:30   ` Michal Wajdeczko
2017-10-11 17:46     ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 19/21] drm/i915/guc: Fix enable/disable of GuC GGTT invalidate functions Sagar Arun Kamble
2017-10-11 17:35   ` Michal Wajdeczko
2017-10-11 17:44     ` Sagar Arun Kamble
2017-10-11 17:58       ` Michal Wajdeczko
2017-10-11 18:09         ` Sagar Arun Kamble
2017-10-11 18:20           ` Michal Wajdeczko
2017-10-12  9:08             ` Joonas Lahtinen
2017-10-12 12:08               ` Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 20/21] drm/i915/guc: Disable GuC submission/interrupts/communication in intel_uc_sanitize Sagar Arun Kamble
2017-10-11  8:54 ` [PATCH v13 21/21] HAX enable GuC submission for CI Sagar Arun Kamble
2017-10-11  9:44 ` ✗ Fi.CI.BAT: failure for drm/i915: GEM/GuC Suspend/Resume/Reset fixes and restructuring 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=1507712056-25030-14-git-send-email-sagar.a.kamble@intel.com \
    --to=sagar.a.kamble@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /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.