93f8d22
From a75a3c793e2cd3e7648597f2c77d87453f520f31 Mon Sep 17 00:00:00 2001
93f8d22
From: Fedora Kernel Team <kernel-team@fedoraproject.org>
93f8d22
Date: Mon, 20 Jun 2016 11:13:23 +0200
93f8d22
Subject: [PATCH 04/17] drm/i915/gen9: Allow calculation of data rate for
93f8d22
 in-flight state (v2)
93f8d22
93f8d22
Upstream: since drm-intel-next-2016-05-22
93f8d22
commit 9c74d82621c553f0da1f41bd5d90f5eab5659fdb
93f8d22
93f8d22
Author:     Matt Roper <matthew.d.roper@intel.com>
93f8d22
AuthorDate: Thu May 12 07:05:58 2016 -0700
93f8d22
Commit:     Matt Roper <matthew.d.roper@intel.com>
93f8d22
CommitDate: Fri May 13 07:32:49 2016 -0700
93f8d22
93f8d22
    drm/i915/gen9: Allow calculation of data rate for in-flight state (v2)
93f8d22
93f8d22
    Our skl_get_total_relative_data_rate() function gets passed a crtc state
93f8d22
    object to calculate the data rate for, but it currently always looks
93f8d22
    up the committed plane states that correspond to that CRTC.  Let's
93f8d22
    check whether the CRTC state is an in-flight state (meaning
93f8d22
    cstate->state is non-NULL) and if so, use the corresponding in-flight
93f8d22
    plane states.
93f8d22
93f8d22
    We'll soon be using this function exclusively for in-flight states; at
93f8d22
    that time we'll be able to simplify the function a bit, but for now we
93f8d22
    allow it to be used in either mode.
93f8d22
93f8d22
    v2:
93f8d22
     - Rebase on top of changes to cache plane data rates.
93f8d22
93f8d22
    Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
93f8d22
    Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
93f8d22
    Link: http://patchwork.freedesktop.org/patch/msgid/1463061971-19638-5-git-send-email-matthew.d.roper@intel.com
93f8d22
---
93f8d22
 drivers/gpu/drm/i915/intel_pm.c | 74 +++++++++++++++++++++++++++++++++--------
93f8d22
 1 file changed, 60 insertions(+), 14 deletions(-)
93f8d22
93f8d22
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
93f8d22
index 854f0a4..b863bfc 100644
93f8d22
--- a/drivers/gpu/drm/i915/intel_pm.c
93f8d22
+++ b/drivers/gpu/drm/i915/intel_pm.c
93f8d22
@@ -2914,25 +2914,69 @@ skl_plane_relative_data_rate(const struct intel_crtc_state *cstate,
93f8d22
  *   3 * 4096 * 8192  * 4 < 2^32
93f8d22
  */
93f8d22
 static unsigned int
93f8d22
-skl_get_total_relative_data_rate(struct intel_crtc_state *cstate)
93f8d22
+skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate)
93f8d22
 {
93f8d22
-	struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc);
93f8d22
-	struct drm_device *dev = intel_crtc->base.dev;
93f8d22
+	struct drm_crtc_state *cstate = &intel_cstate->base;
93f8d22
+	struct drm_atomic_state *state = cstate->state;
93f8d22
+	struct drm_crtc *crtc = cstate->crtc;
93f8d22
+	struct drm_device *dev = crtc->dev;
93f8d22
+	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
93f8d22
 	const struct intel_plane *intel_plane;
93f8d22
 	unsigned int rate, total_data_rate = 0;
93f8d22
+	int id;
93f8d22
 
93f8d22
 	/* Calculate and cache data rate for each plane */
93f8d22
-	for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
93f8d22
-		const struct drm_plane_state *pstate = intel_plane->base.state;
93f8d22
-		int id = skl_wm_plane_id(intel_plane);
93f8d22
+	/*
93f8d22
+	 * FIXME: At the moment this function can be called on either an
93f8d22
+	 * in-flight or a committed state object.  If it's in-flight then we
93f8d22
+	 * only want to re-calculate the plane data rate for planes that are
93f8d22
+	 * part of the transaction (i.e., we don't want to grab any additional
93f8d22
+	 * plane states if we don't have to).  If we're operating on committed
93f8d22
+	 * state, we'll just go ahead and recalculate the plane data rate for
93f8d22
+	 * all planes.
93f8d22
+	 *
93f8d22
+	 * Once we finish moving our DDB allocation to the atomic check phase,
93f8d22
+	 * we'll only be calling this function on in-flight state objects, so
93f8d22
+	 * the 'else' branch here will go away.
93f8d22
+	 */
93f8d22
+	if (state) {
93f8d22
+		struct drm_plane *plane;
93f8d22
+		struct drm_plane_state *pstate;
93f8d22
+		int i;
93f8d22
+
93f8d22
+		for_each_plane_in_state(state, plane, pstate, i) {
93f8d22
+			intel_plane = to_intel_plane(plane);
93f8d22
+			id = skl_wm_plane_id(intel_plane);
93f8d22
+
93f8d22
+			if (intel_plane->pipe != intel_crtc->pipe)
93f8d22
+				continue;
93f8d22
+
93f8d22
+			/* packed/uv */
93f8d22
+			rate = skl_plane_relative_data_rate(intel_cstate,
93f8d22
+							    pstate, 0);
93f8d22
+			intel_cstate->wm.skl.plane_data_rate[id] = rate;
93f8d22
+
93f8d22
+			/* y-plane */
93f8d22
+			rate = skl_plane_relative_data_rate(intel_cstate,
93f8d22
+							    pstate, 1);
93f8d22
+			intel_cstate->wm.skl.plane_y_data_rate[id] = rate;
93f8d22
+		}
93f8d22
+	} else {
93f8d22
+		for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
93f8d22
+			const struct drm_plane_state *pstate =
93f8d22
+				intel_plane->base.state;
93f8d22
+			int id = skl_wm_plane_id(intel_plane);
93f8d22
 
93f8d22
-		/* packed/uv */
93f8d22
-		rate = skl_plane_relative_data_rate(cstate, pstate, 0);
93f8d22
-		cstate->wm.skl.plane_data_rate[id] = rate;
93f8d22
+			/* packed/uv */
93f8d22
+			rate = skl_plane_relative_data_rate(intel_cstate,
93f8d22
+							    pstate, 0);
93f8d22
+			intel_cstate->wm.skl.plane_data_rate[id] = rate;
93f8d22
 
93f8d22
-		/* y-plane */
93f8d22
-		rate = skl_plane_relative_data_rate(cstate, pstate, 1);
93f8d22
-		cstate->wm.skl.plane_y_data_rate[id] = rate;
93f8d22
+			/* y-plane */
93f8d22
+			rate = skl_plane_relative_data_rate(intel_cstate,
93f8d22
+							    pstate, 1);
93f8d22
+			intel_cstate->wm.skl.plane_y_data_rate[id] = rate;
93f8d22
+		}
93f8d22
 	}
93f8d22
 
93f8d22
 	/* Calculate CRTC's total data rate from cached values */
93f8d22
@@ -2940,10 +2984,12 @@ skl_get_total_relative_data_rate(struct intel_crtc_state *cstate)
93f8d22
 		int id = skl_wm_plane_id(intel_plane);
93f8d22
 
93f8d22
 		/* packed/uv */
93f8d22
-		total_data_rate += cstate->wm.skl.plane_data_rate[id];
93f8d22
-		total_data_rate += cstate->wm.skl.plane_y_data_rate[id];
93f8d22
+		total_data_rate += intel_cstate->wm.skl.plane_data_rate[id];
93f8d22
+		total_data_rate += intel_cstate->wm.skl.plane_y_data_rate[id];
93f8d22
 	}
93f8d22
 
93f8d22
+	WARN_ON(cstate->plane_mask && total_data_rate == 0);
93f8d22
+
93f8d22
 	return total_data_rate;
93f8d22
 }
93f8d22
 
93f8d22
-- 
93f8d22
2.7.4
93f8d22