diff mbox series

[06/10] drm/i915: Stash away the original SSKPD latency values

Message ID 20201030165045.5000-7-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: ilk+ wm cleanups | expand

Commit Message

Ville Syrjala Oct. 30, 2020, 4:50 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

On ILK-IVB we must write the latency value read from SSKPD into
the latency field in the WM_LP registers. While bspec was never
clear on how the punit (or whatever) interprets these values
empirical evidence has shown that these are treated as a cookie
rather than as a literal latency value. That is, if we write a
value that we didn't get from SSKPD (just off by one is sufficient)
the system no longer appears to enter the corresponding power
saving state.

This was made much more obvious on HSW/BDW since there we longer
write the latency value into the WM_LP registers, and rather we
write the desired watermark level number (well, 2x the level
number).

Since we allow the user to adjust the latency values via debugfs,
and since we have some quirks where we adjust the values automagically,
we must stash away the originals read from SSKPD for later use
in the WM_LP registers.

v2: s/latency/cookie/ to make it clear what it is
    s/u16/u8/ since the reg can only hold 7 bits

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h |  6 ++++++
 drivers/gpu/drm/i915/intel_pm.c | 37 +++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 0d05f7586e19..533afb4da3c0 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1135,6 +1135,12 @@  struct drm_i915_private {
 		 * FIXME get rid of this.
 		 */
 		bool distrust_bios_wm;
+
+		/*
+		 * The values we must write to the LP watermark
+		 * registers' latency field on ILK-BDW.
+		 */
+		u8 ilk_wm_lp_cookie[5];
 	} wm;
 
 	struct dram_info {
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index 61bb36239930..5db20bf36302 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -3085,10 +3085,35 @@  static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv)
 	intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
 }
 
+/* The value we need to program into the WM_LPx latency field */
+static u16 ilk_wm_lp_cookie(struct drm_i915_private *dev_priv, int level)
+{
+	if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
+		return 2 * level;
+	else
+		return dev_priv->wm.pri_latency[level];
+}
+
+static void ilk_setup_wm_lp_cookie(struct drm_i915_private *dev_priv)
+{
+	int level, max_level = ilk_wm_max_level(dev_priv);
+
+	for (level = 1; level <= max_level; level++)
+		dev_priv->wm.ilk_wm_lp_cookie[level] =
+			ilk_wm_lp_cookie(dev_priv, level);
+}
+
 static void ilk_setup_wm_latency(struct drm_i915_private *dev_priv)
 {
 	intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency);
 
+	/*
+	 * On ILK-IVB the values written to the LP watermark register
+	 * latency field must match SSKPD 100%. So do this before any
+	 * adjustments are made to the latency values we got from SSKPD.
+	 */
+	ilk_setup_wm_lp_cookie(dev_priv);
+
 	memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency,
 	       sizeof(dev_priv->wm.pri_latency));
 	memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency,
@@ -3366,16 +3391,6 @@  static int ilk_wm_lp_to_level(int wm_lp, const struct ilk_wm_state *pipe_wm)
 	return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable);
 }
 
-/* The value we need to program into the WM_LPx latency field */
-static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv,
-				      int level)
-{
-	if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
-		return 2 * level;
-	else
-		return dev_priv->wm.pri_latency[level];
-}
-
 static void ilk_compute_wm_results(struct drm_i915_private *dev_priv,
 				   const struct ilk_wm_state *merged,
 				   enum ilk_ddb_partitioning partitioning,
@@ -3400,7 +3415,7 @@  static void ilk_compute_wm_results(struct drm_i915_private *dev_priv,
 		 * disabled. Doing otherwise could cause underruns.
 		 */
 		results->wm_lp[wm_lp - 1] =
-			(ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) |
+			(dev_priv->wm.ilk_wm_lp_cookie[level] << WM1_LP_LATENCY_SHIFT) |
 			(r->pri_val << WM1_LP_SR_SHIFT) |
 			r->cur_val;