Skip to contentSkip to conversation

drm/i915/dp: Fix the math in intel_dp_link_required

PATCH In review Adam Jackson 4 participants 9 messages Oct 14, 2011 – May 10, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/i915/dp: Fix the math in intel_dp_link_required

The previous code was confused about units, which is pretty reasonable given that the units themselves are confusing.

---
 drivers/gpu/drm/i915/intel_dp.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +21 -5
index 44fef5e..4e62ff2 100644
@@ -175,9 +175,25 @@ intel_dp_link_clock(uint8_t link_bw)
 		return 162000;
 }
 
-/* I think this is a fiction */
+/*
+ * The units on the numbers in the next two are... bizarre.  Examples will
+ * make it clearer; this one parallels an example in the eDP spec.
+ *
+ * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
+ *
+ *     270000 * 1 * 8 / 10 == 216000
+ *
+ * The actual data capacity of that configuration is 2.16Gbit/s, so the
+ * units are decakilobits.  ->clock in a drm_display_mode is in kilohertz -
+ * or equivalently, kilopixels per second - so for 1680x1050R it'd be
+ * 119000.  At 18bpp that's 2142000 kilobits per second.
+ *
+ * Thus the strange-looking division by 10 in intel_dp_link_required, to
+ * get the result in decakilobits instead of kilobits.
+ */
+
 static int
-intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock)
+intel_dp_link_required(struct intel_dp *intel_dp, int pixel_clock)
 {
 	struct drm_crtc *crtc = intel_dp->base.base.crtc;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
@@ -186,7 +202,7 @@ intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pi
 	if (intel_crtc)
 		bpp = intel_crtc->bpp;
 
-	return (pixel_clock * bpp + 7) / 8;
+	return (pixel_clock * bpp + 9) / 10;
 }
 
 static int
@@ -216,7 +232,7 @@ intel_dp_mode_valid(struct drm_connector *connector,
 	/* only refuse the mode on non eDP since we have seen some weird eDP panels
 	   which are outside spec tolerances but somehow work by magic */
 	if (!is_edp(intel_dp) &&
-	    (intel_dp_link_required(connector->dev, intel_dp, mode->clock)
+	    (intel_dp_link_required(intel_dp, mode->clock)
 	     > intel_dp_max_data_rate(max_link_clock, max_lanes)))
 		return MODE_CLOCK_HIGH;
 
@@ -620,7 +636,7 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
 		for (clock = 0; clock <= max_clock; clock++) {
 			int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
 
-			if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock)
+			if (intel_dp_link_required(intel_dp, mode->clock)
 					<= link_avail) {
 				intel_dp->link_bw = bws[clock];
 				intel_dp->lane_count = lane_count;
Signature · 1 line
1.7.6.4
#1 lore raw

PATCH 2/2 drm/i915/dp: Remove eDP special cases from bandwidth checks

These were just working around the math being wrong.

---
 drivers/gpu/drm/i915/intel_dp.c |   20 ++------------------
 1 files changed, 2 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +2 -18
index 4e62ff2..08c3f84 100644
@@ -229,11 +229,8 @@ intel_dp_mode_valid(struct drm_connector *connector,
 			return MODE_PANEL;
 	}
 
-	/* only refuse the mode on non eDP since we have seen some weird eDP panels
-	   which are outside spec tolerances but somehow work by magic */
-	if (!is_edp(intel_dp) &&
-	    (intel_dp_link_required(intel_dp, mode->clock)
-	     > intel_dp_max_data_rate(max_link_clock, max_lanes)))
+	if (intel_dp_link_required(intel_dp, mode->clock)
+	    > intel_dp_max_data_rate(max_link_clock, max_lanes))
 		return MODE_CLOCK_HIGH;
 
 	if (mode->clock < 10000)
@@ -650,19 +647,6 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
 		}
 	}
 
-	if (is_edp(intel_dp)) {
-		/* okay we failed just pick the highest */
-		intel_dp->lane_count = max_lane_count;
-		intel_dp->link_bw = bws[max_clock];
-		adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
-		DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
-			      "count %d clock %d\n",
-			      intel_dp->link_bw, intel_dp->lane_count,
-			      adjusted_mode->clock);
-
-		return true;
-	}
-
 	return false;
 }
 
Signature · 1 line
1.7.6.4
#2 lore raw

Re: [PATCH 2/2] drm/i915/dp: Remove eDP special cases from bandwidth checks

Quoted 1 line · Adam Jackson

These were just working around the math being wrong.

One wonders whether this might break some machines which are currently working. Should we emit an error or something if an eDP panel asks for the impossible?

Signature · 1 line
[email protected]

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

Re: [PATCH 2/2] drm/i915/dp: Remove eDP special cases from bandwidth checks

Quoted 7 lines · Keith Packard
Quoted 1 line · Adam Jackson

These were just working around the math being wrong.

One wonders whether this might break some machines which are currently working. Should we emit an error or something if an eDP panel asks for the impossible?

Probably, but I think in cases where that happens we should be considering the driver to be broken before the panel. No one's going to manufacture hardware that can't run Windows.

The patch adding that check - fe27d53e5c597ee5ba5d72a29d517091f244e974 - references bug #28070. Relevant attachments:

https://bugs.freedesktop.org/attachment.cgi?id=35584
[drm:drm_mode_debug_printmodeline], Modeline 25:"1920x1080" 60 137700 1920 1968 2000 2066 1080 1083 1088 1111 0x48 0xa [drm:intel_dp_mode_fixup], Display port link bw 06 lane count 2 clock 162000

https://bugs.freedesktop.org/attachment.cgi?id=35585
eDP block: type 6

	Power Sequence: T3 3000 T7 400 T9 2000 T10 500 T12 5000
	Panel color depth: 18bpp
	eDP sDRRs MSA timing delay: 0
	Link params:
		rate: 1.62G
		lanes: x1 mode
		pre-emphasis: none
		vswing: 0.4V

Old math: (137700 * 18 + 7) / 8 == 309825
New math: (137700 * 18 + 9) / 10 == 247860

I'm coming to believe that the eDP block's link parameters are nonsense and we should just trust DPCD. Which seems like a solid plan regardless. Sadly that dmesg doesn't include a DPCD dump, but, the threshold table looks like this:

Rate / Lanes 1 2 4
1.62GHz 129600 259200 518400
2.7GHZ 216000 432000 864000

Note that the corrected math gives us a data rate that fits in 2x1.62, but the old math requires either more lanes or a higher rate. So I suspect the machine wasn't broken in the first place.

- ajax

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw

Re: [PATCH 2/2] drm/i915/dp: Remove eDP special cases from bandwidth checks

Quoted 5 lines · Adam Jackson
Quoted 4 lines · Keith Packard
Quoted 1 line · Adam Jackson

These were just working around the math being wrong.

Quoted 7 lines
Quoted 3 lines

One wonders whether this might break some machines which are currently working. Should we emit an error or something if an eDP panel asks for the impossible?

Probably, but I think in cases where that happens we should be considering the driver to be broken before the panel. No one's going to manufacture hardware that can't run Windows.

Sigh, This patch did introduce a number of regressions, notably
https://bugs.freedesktop.org/show_bug.cgi?id=45801
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw

Re: [PATCH 2/2] drm/i915/dp: Remove eDP special cases from bandwidth checks

Quoted 10 lines · Chris Wilson
Quoted 9 lines · Adam Jackson
Quoted 7 lines · Keith Packard
Quoted 1 line · Adam Jackson

These were just working around the math being wrong.

One wonders whether this might break some machines which are currently working. Should we emit an error or something if an eDP panel asks for the impossible?

Quoted 6 lines
Quoted 3 lines

Probably, but I think in cases where that happens we should be considering the driver to be broken before the panel. No one's going to manufacture hardware that can't run Windows.

Sigh, This patch did introduce a number of regressions, notably
https://bugs.freedesktop.org/show_bug.cgi?id=45801

To clarify, the first patch (fix dp math) broke stuff, not the second one (rip out edp special case) for this reporter.
-Daniel

Signature · 3 lines
Daniel Vetter
Mail: [email protected]
Mobile: +41 (0)79 365 57 48
#6 lore raw
In reply to Adam Jackson
Quoted 2 lines · Adam Jackson

The previous code was confused about units, which is pretty reasonable given that the units themselves are confusing.

Thanks for actually figuring this out; the comment before that function should have indicated to any reader that I couldn't figure out what that computation should have been.

One question -- do you have an example of where the old computation failed and the new one works?

Signature · 1 line
[email protected]

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw
Quoted 11 lines · Keith Packard
Quoted 2 lines · Adam Jackson

The previous code was confused about units, which is pretty reasonable given that the units themselves are confusing.

Thanks for actually figuring this out; the comment before that function should have indicated to any reader that I couldn't figure out what that computation should have been.

One question -- do you have an example of where the old computation failed and the new one works?

If you want "failed" to mean "refused to light something legal" you'd have to go to something fairly extreme like 2560x1600R 30bpp:

wrong math: (268500 * 30 + 7) / 8 == 1006875
right math: (268500 * 30 + 9) / 10 == 805500

Remembering that the 4x2.7 limit is 864000. But there are more mundane cases where we'd just be wasting power by picking a higher link/lane combo. 1920x1200R 24bpp:

wrong math: (154000 * 24 + 7) / 8 == 462000
right math: (154000 * 24 + 9) / 10 == 369600

Here we'd pick 4x1.62 instead of 2x2.7. Which would work, assuming your sink has all four lanes wired, but. Unlike the first theoretical example, this one I've actually tested (GM45 machine, HP LP2480zx monitor):

[drm:drm_mode_debug_printmodeline], Modeline 28:"" 0 154000 1920 1968 2000 2080 1200 1203 1209 1235 0x0 0x9 [drm:intel_dp_mode_fixup], Display port link bw 0a lane count 2 clock 270000

---

The units end up being weird because of how we're choosing to encode the lane rate in adjusted_mode->clock (all the literal '270000' in intel_dp_link_clock() and friends). It might be prettier to fix those constants instead, but it's rather more invasive and doesn't really win you anything.

- ajax

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Acked-by
#8 lore raw
Quoted 3 lines · Adam Jackson

[drm:drm_mode_debug_printmodeline], Modeline 28:"" 0 154000 1920 1968 2000 2080 1200 1203 1209 1235 0x0 0x9 [drm:intel_dp_mode_fixup], Display port link bw 0a lane count 2 clock
270000

Ok, nice to see that you've actually tested a marginal case and had it work :-)

Signature · 1 line
[email protected]

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx