7d2c2f2
From 7207eecfcb3095442bce30227b551003edc7b908 Mon Sep 17 00:00:00 2001
7d2c2f2
From: Matt Roper <matthew.d.roper@intel.com>
7d2c2f2
Date: Thu, 12 May 2016 07:06:02 -0700
7d2c2f2
Subject: [PATCH 08/17] drm/i915: Add distrust_bios_wm flag to dev_priv (v2)
7d2c2f2
7d2c2f2
SKL-style platforms can't fully trust the watermark/DDB settings
7d2c2f2
programmed by the BIOS and need to do extra sanitization on their first
7d2c2f2
atomic update.  Add a flag to dev_priv that is set during hardware
7d2c2f2
readout and cleared at the end of the first commit.
7d2c2f2
7d2c2f2
Note that for the somewhat common case where everything is turned off
7d2c2f2
when the driver starts up, we don't need to bother with a recompute...we
7d2c2f2
know exactly what the DDB should be (all zero's) so just setup the DDB
7d2c2f2
directly in that case.
7d2c2f2
7d2c2f2
v2:
7d2c2f2
 - Move clearing of distrust_bios_wm up below the swap_state call since
7d2c2f2
   it's a more natural / self-explanatory location.  (Maarten)
7d2c2f2
 - Use dev_priv->active_crtcs to test whether any CRTC's are turned on
7d2c2f2
   during HW WM readout rather than trying to count the active CRTC's
7d2c2f2
   again ourselves.  (Maarten)
7d2c2f2
7d2c2f2
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
7d2c2f2
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
7d2c2f2
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
7d2c2f2
Link: http://patchwork.freedesktop.org/patch/msgid/1463061971-19638-9-git-send-email-matthew.d.roper@intel.com
7d2c2f2
---
7d2c2f2
 drivers/gpu/drm/i915/i915_drv.h      | 7 +++++++
7d2c2f2
 drivers/gpu/drm/i915/intel_display.c | 1 +
7d2c2f2
 drivers/gpu/drm/i915/intel_pm.c      | 8 ++++++++
7d2c2f2
 3 files changed, 16 insertions(+)
7d2c2f2
7d2c2f2
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
7d2c2f2
index 611c128..e21960d 100644
7d2c2f2
--- a/drivers/gpu/drm/i915/i915_drv.h
7d2c2f2
+++ b/drivers/gpu/drm/i915/i915_drv.h
7d2c2f2
@@ -1981,6 +1981,13 @@ struct drm_i915_private {
7d2c2f2
 		 * cstate->wm.need_postvbl_update.
7d2c2f2
 		 */
7d2c2f2
 		struct mutex wm_mutex;
7d2c2f2
+
7d2c2f2
+		/*
7d2c2f2
+		 * Set during HW readout of watermarks/DDB.  Some platforms
7d2c2f2
+		 * need to know when we're still using BIOS-provided values
7d2c2f2
+		 * (which we don't fully trust).
7d2c2f2
+		 */
7d2c2f2
+		bool distrust_bios_wm;
7d2c2f2
 	} wm;
7d2c2f2
 
7d2c2f2
 	struct i915_runtime_pm pm;
7d2c2f2
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
7d2c2f2
index f26d1c5..a9d2e30 100644
7d2c2f2
--- a/drivers/gpu/drm/i915/intel_display.c
7d2c2f2
+++ b/drivers/gpu/drm/i915/intel_display.c
7d2c2f2
@@ -13621,6 +13621,7 @@ static int intel_atomic_commit(struct drm_device *dev,
7d2c2f2
 
7d2c2f2
 	drm_atomic_helper_swap_state(dev, state);
7d2c2f2
 	dev_priv->wm.config = intel_state->wm_config;
7d2c2f2
+	dev_priv->wm.distrust_bios_wm = false;
7d2c2f2
 	intel_shared_dpll_commit(state);
7d2c2f2
 
7d2c2f2
 	if (intel_state->modeset) {
7d2c2f2
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
7d2c2f2
index f009d43..a49faa7 100644
7d2c2f2
--- a/drivers/gpu/drm/i915/intel_pm.c
7d2c2f2
+++ b/drivers/gpu/drm/i915/intel_pm.c
7d2c2f2
@@ -4026,6 +4026,14 @@ void skl_wm_get_hw_state(struct drm_device *dev)
7d2c2f2
 	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
7d2c2f2
 		skl_pipe_wm_get_hw_state(crtc);
7d2c2f2
 
7d2c2f2
+	if (dev_priv->active_crtcs) {
7d2c2f2
+		/* Fully recompute DDB on first atomic commit */
7d2c2f2
+		dev_priv->wm.distrust_bios_wm = true;
7d2c2f2
+	} else {
7d2c2f2
+		/* Easy/common case; just sanitize DDB now if everything off */
7d2c2f2
+		memset(ddb, 0, sizeof(*ddb));
7d2c2f2
+	}
7d2c2f2
+
7d2c2f2
 	/* Calculate plane data rates */
7d2c2f2
 	for_each_intel_crtc(dev, intel_crtc) {
7d2c2f2
 		struct intel_crtc_state *cstate = intel_crtc->config;
7d2c2f2
-- 
7d2c2f2
2.7.4
7d2c2f2