intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math
@ 2016-11-14 21:42 Dhinakaran Pandiyan
  2016-11-14 21:42 ` [PATCH v2 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST Dhinakaran Pandiyan
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Dhinakaran Pandiyan @ 2016-11-14 21:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula, Dhinakaran Pandiyan

We store DP link rates as link clock frequencies in kHz, just like all
other clock values. But, DP link rates in the DP Spec. are expressed in
Gbps/lane, which seems to have led to some confusion.

E.g., for HBR2
Max. data rate = 5.4 Gbps/lane x 4 lane x 8/10 x 1/8 = 2160000 kBps
where, 8/10 is for channel encoding and 1/8 is for bit to Byte conversion

Using link clock frequency, like we do
Max. data rate = 540000 kHz * 4 lanes = 2160000 kSymbols/s
Because, each symbol has 8 bit of data, this is 2160000 kBps
and there is no need to account for channel encoding here.

But, currently we do 540000 kHz * 4 lanes * (8/10) = 1728000 kBps

Similarly, while computing the required link bandwidth for a mode,
there is a mysterious 1/10 term.
This should simply be pixel_clock kHz * (bpp/8) to give the final result in
kBps

v2: Changed to DIV_ROUND_UP() and comment changes (Ville)

Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
---
 drivers/gpu/drm/i915/intel_dp.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 8f313c1..0c5d4bd 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -161,33 +161,23 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
 	return min(source_max, sink_max);
 }
 
-/*
- * 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(int pixel_clock, int bpp)
 {
-	return (pixel_clock * bpp + 9) / 10;
+	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
+	return DIV_ROUND_UP(pixel_clk * bpp, 8);
 }
 
 static int
 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
 {
-	return (max_link_clock * max_lanes * 8) / 10;
+	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
+	 * link rate that is generally expressed in Gbps. Since, 8 bits of data
+	 * is transmitted every LS_Clk per lane, there is no need to account for
+	 * the channel encoding that is done in the PHY layer here.
+	 */
+
+	return max_link_clock * max_lanes;
 }
 
 static int
@@ -3573,7 +3563,12 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
 			if (val == 0)
 				break;
 
-			/* Value read is in kHz while drm clock is saved in deca-kHz */
+			/* Value read multiplied by 200kHz gives the per-lane
+			 * link rate in kHz. The source rates are, however,
+			 * stored in terms of LS_Clk kHz. The full conversion
+			 * back to symbols is
+			 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
+			 */
 			intel_dp->sink_rates[i] = (val * 200) / 10;
 		}
 		intel_dp->num_sink_rates = i;
-- 
2.7.4

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST
  2016-11-14 21:42 [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
@ 2016-11-14 21:42 ` Dhinakaran Pandiyan
  2016-11-15 20:59   ` [PATCH v3 " Dhinakaran Pandiyan
  2016-11-14 21:50 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Dhinakaran Pandiyan @ 2016-11-14 21:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula, Dhinakaran Pandiyan

Not validating the mode rate against max. link rate results in not pruning
invalid modes. For e.g, a HBR2 5.4 Gbps 2-lane configuration does not
support 4k@60Hz. But, we do not reject this mode.

So, make use of the helpers in intel_dp to validate mode data rate against
max. link data rate of a configuration.

v2: Renamed mode data rate local variable to be more explanatory.

Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
---
 drivers/gpu/drm/i915/intel_dp.c     |  4 ++--
 drivers/gpu/drm/i915/intel_dp_mst.c | 12 +++++++++++-
 drivers/gpu/drm/i915/intel_drv.h    |  2 ++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 0c5d4bd..a7393e8 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -161,14 +161,14 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
 	return min(source_max, sink_max);
 }
 
-static int
+int
 intel_dp_link_required(int pixel_clock, int bpp)
 {
 	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
 	return DIV_ROUND_UP(pixel_clk * bpp, 8);
 }
 
-static int
+int
 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
 {
 	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
index 3ffbd69..2c557d9 100644
--- a/drivers/gpu/drm/i915/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/intel_dp_mst.c
@@ -335,7 +335,17 @@ static enum drm_mode_status
 intel_dp_mst_mode_valid(struct drm_connector *connector,
 			struct drm_display_mode *mode)
 {
+	struct intel_connector *intel_connector = to_intel_connector(connector);
+	struct intel_dp *intel_dp = intel_connector->mst_port;
 	int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
+	int link_clock = intel_dp_max_link_rate(intel_dp);
+	int lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
+	int bpp = 24; /* MST uses fixed bpp */
+	int mode_data_rate;
+	int link_max_data_rate;
+
+	mode_data_rate = intel_dp_link_required(mode->clock, bpp);
+	link_max_data_rate = intel_dp_max_data_rate(link_clock, lane_count);
 
 	/* TODO - validate mode against available PBN for link */
 	if (mode->clock < 10000)
@@ -344,7 +354,7 @@ intel_dp_mst_mode_valid(struct drm_connector *connector,
 	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
 		return MODE_H_ILLEGAL;
 
-	if (mode->clock > max_dotclk)
+	if (mode_data_rate > link_max_data_rate || mode->clock > max_dotclk)
 		return MODE_CLOCK_HIGH;
 
 	return MODE_OK;
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index c2f3863..313419d 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1471,6 +1471,8 @@ bool intel_dp_read_dpcd(struct intel_dp *intel_dp);
 bool __intel_dp_read_desc(struct intel_dp *intel_dp,
 			  struct intel_dp_desc *desc);
 bool intel_dp_read_desc(struct intel_dp *intel_dp);
+int intel_dp_link_required(int pixel_clock, int bpp);
+int intel_dp_max_data_rate(int max_link_clock, int max_lanes);
 
 /* intel_dp_aux_backlight.c */
 int intel_dp_aux_init_backlight_funcs(struct intel_connector *intel_connector);
-- 
2.7.4

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math
  2016-11-14 21:42 [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
  2016-11-14 21:42 ` [PATCH v2 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST Dhinakaran Pandiyan
@ 2016-11-14 21:50 ` Dhinakaran Pandiyan
  2016-11-15  9:30   ` Jani Nikula
  2016-11-29 20:22   ` Ville Syrjälä
  2016-11-14 22:15 ` ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev2) Patchwork
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 12+ messages in thread
From: Dhinakaran Pandiyan @ 2016-11-14 21:50 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula, Dhinakaran Pandiyan

We store DP link rates as link clock frequencies in kHz, just like all
other clock values. But, DP link rates in the DP Spec. are expressed in
Gbps/lane, which seems to have led to some confusion.

E.g., for HBR2
Max. data rate = 5.4 Gbps/lane x 4 lane x 8/10 x 1/8 = 2160000 kBps
where, 8/10 is for channel encoding and 1/8 is for bit to Byte conversion

Using link clock frequency, like we do
Max. data rate = 540000 kHz * 4 lanes = 2160000 kSymbols/s
Because, each symbol has 8 bit of data, this is 2160000 kBps
and there is no need to account for channel encoding here.

But, currently we do 540000 kHz * 4 lanes * (8/10) = 1728000 kBps

Similarly, while computing the required link bandwidth for a mode,
there is a mysterious 1/10 term.
This should simply be pixel_clock kHz * (bpp/8) to give the final result in
kBps

v2: Changed to DIV_ROUND_UP() and comment changes (Ville)

Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
---
Fixed a typo that snuck in.

 drivers/gpu/drm/i915/intel_dp.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 8f313c1..bdef314 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -161,33 +161,23 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
 	return min(source_max, sink_max);
 }
 
-/*
- * 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(int pixel_clock, int bpp)
 {
-	return (pixel_clock * bpp + 9) / 10;
+	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
+	return DIV_ROUND_UP(pixel_clock * bpp, 8);
 }
 
 static int
 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
 {
-	return (max_link_clock * max_lanes * 8) / 10;
+	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
+	 * link rate that is generally expressed in Gbps. Since, 8 bits of data
+	 * is transmitted every LS_Clk per lane, there is no need to account for
+	 * the channel encoding that is done in the PHY layer here.
+	 */
+
+	return max_link_clock * max_lanes;
 }
 
 static int
@@ -3573,7 +3563,12 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
 			if (val == 0)
 				break;
 
-			/* Value read is in kHz while drm clock is saved in deca-kHz */
+			/* Value read multiplied by 200kHz gives the per-lane
+			 * link rate in kHz. The source rates are, however,
+			 * stored in terms of LS_Clk kHz. The full conversion
+			 * back to symbols is
+			 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
+			 */
 			intel_dp->sink_rates[i] = (val * 200) / 10;
 		}
 		intel_dp->num_sink_rates = i;
-- 
2.7.4

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev2)
  2016-11-14 21:42 [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
  2016-11-14 21:42 ` [PATCH v2 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST Dhinakaran Pandiyan
  2016-11-14 21:50 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
@ 2016-11-14 22:15 ` Patchwork
  2016-11-15  5:07 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math kbuild test robot
  2016-11-15 21:16 ` ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev3) Patchwork
  4 siblings, 0 replies; 12+ messages in thread
From: Patchwork @ 2016-11-14 22:15 UTC (permalink / raw)
  To: Pandiyan, Dhinakaran; +Cc: intel-gfx

== Series Details ==

Series: series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev2)
URL   : https://patchwork.freedesktop.org/series/15305/
State : success

== Summary ==

Series 15305v2 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/15305/revisions/2/mbox/


fi-bdw-5557u     total:244  pass:229  dwarn:0   dfail:0   fail:0   skip:15 
fi-bsw-n3050     total:244  pass:204  dwarn:0   dfail:0   fail:0   skip:40 
fi-bxt-t5700     total:244  pass:216  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-j1900     total:244  pass:216  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-n2820     total:244  pass:212  dwarn:0   dfail:0   fail:0   skip:32 
fi-hsw-4770      total:244  pass:224  dwarn:0   dfail:0   fail:0   skip:20 
fi-hsw-4770r     total:244  pass:224  dwarn:0   dfail:0   fail:0   skip:20 
fi-ilk-650       total:244  pass:191  dwarn:0   dfail:0   fail:0   skip:53 
fi-ivb-3520m     total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-ivb-3770      total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-kbl-7200u     total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-skl-6260u     total:244  pass:230  dwarn:0   dfail:0   fail:0   skip:14 
fi-skl-6700hq    total:244  pass:223  dwarn:0   dfail:0   fail:0   skip:21 
fi-snb-2520m     total:244  pass:212  dwarn:0   dfail:0   fail:0   skip:32 
fi-snb-2600      total:244  pass:211  dwarn:0   dfail:0   fail:0   skip:33 

2f21978cfd8984c79e4cbd77ce63d9f73fe226ef drm-intel-nightly: 2016y-11m-14d-21h-23m-10s UTC integration manifest
feb0aee drm/dp/i915: Fix DP link rate math

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_2990/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math
  2016-11-14 21:42 [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
                   ` (2 preceding siblings ...)
  2016-11-14 22:15 ` ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev2) Patchwork
@ 2016-11-15  5:07 ` kbuild test robot
  2016-11-15 21:16 ` ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev3) Patchwork
  4 siblings, 0 replies; 12+ messages in thread
From: kbuild test robot @ 2016-11-15  5:07 UTC (permalink / raw)
  Cc: jani.nikula, intel-gfx, kbuild-all, Dhinakaran Pandiyan

[-- Attachment #1: Type: text/plain, Size: 7847 bytes --]

Hi Dhinakaran,

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on v4.9-rc5 next-20161114]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Dhinakaran-Pandiyan/drm-dp-i915-Fix-DP-link-rate-math/20161115-055743
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-rhel (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   In file included from include/linux/cache.h:4:0,
                    from include/linux/printk.h:8,
                    from include/linux/kernel.h:13,
                    from include/linux/list.h:8,
                    from include/linux/kobject.h:20,
                    from include/linux/device.h:17,
                    from include/linux/i2c.h:30,
                    from drivers/gpu/drm/i915/intel_dp.c:28:
   drivers/gpu/drm/i915/intel_dp.c: In function 'intel_dp_link_required':
>> drivers/gpu/drm/i915/intel_dp.c:168:22: error: 'pixel_clk' undeclared (first use in this function)
     return DIV_ROUND_UP(pixel_clk * bpp, 8);
                         ^
   include/uapi/linux/kernel.h:12:40: note: in definition of macro '__KERNEL_DIV_ROUND_UP'
    #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
                                           ^
   drivers/gpu/drm/i915/intel_dp.c:168:9: note: in expansion of macro 'DIV_ROUND_UP'
     return DIV_ROUND_UP(pixel_clk * bpp, 8);
            ^~~~~~~~~~~~
   drivers/gpu/drm/i915/intel_dp.c:168:22: note: each undeclared identifier is reported only once for each function it appears in
     return DIV_ROUND_UP(pixel_clk * bpp, 8);
                         ^
   include/uapi/linux/kernel.h:12:40: note: in definition of macro '__KERNEL_DIV_ROUND_UP'
    #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
                                           ^
   drivers/gpu/drm/i915/intel_dp.c:168:9: note: in expansion of macro 'DIV_ROUND_UP'
     return DIV_ROUND_UP(pixel_clk * bpp, 8);
            ^~~~~~~~~~~~
   drivers/gpu/drm/i915/intel_dp.c:169:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^

vim +/pixel_clk +168 drivers/gpu/drm/i915/intel_dp.c

    22	 *
    23	 * Authors:
    24	 *    Keith Packard <keithp@keithp.com>
    25	 *
    26	 */
    27	
  > 28	#include <linux/i2c.h>
    29	#include <linux/slab.h>
    30	#include <linux/export.h>
    31	#include <linux/notifier.h>
    32	#include <linux/reboot.h>
    33	#include <drm/drmP.h>
    34	#include <drm/drm_atomic_helper.h>
    35	#include <drm/drm_crtc.h>
    36	#include <drm/drm_crtc_helper.h>
    37	#include <drm/drm_edid.h>
    38	#include "intel_drv.h"
    39	#include <drm/i915_drm.h>
    40	#include "i915_drv.h"
    41	
    42	#define DP_LINK_CHECK_TIMEOUT	(10 * 1000)
    43	
    44	/* Compliance test status bits  */
    45	#define INTEL_DP_RESOLUTION_SHIFT_MASK	0
    46	#define INTEL_DP_RESOLUTION_PREFERRED	(1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
    47	#define INTEL_DP_RESOLUTION_STANDARD	(2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
    48	#define INTEL_DP_RESOLUTION_FAILSAFE	(3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
    49	
    50	struct dp_link_dpll {
    51		int clock;
    52		struct dpll dpll;
    53	};
    54	
    55	static const struct dp_link_dpll gen4_dpll[] = {
    56		{ 162000,
    57			{ .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
    58		{ 270000,
    59			{ .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
    60	};
    61	
    62	static const struct dp_link_dpll pch_dpll[] = {
    63		{ 162000,
    64			{ .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
    65		{ 270000,
    66			{ .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
    67	};
    68	
    69	static const struct dp_link_dpll vlv_dpll[] = {
    70		{ 162000,
    71			{ .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
    72		{ 270000,
    73			{ .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
    74	};
    75	
    76	/*
    77	 * CHV supports eDP 1.4 that have  more link rates.
    78	 * Below only provides the fixed rate but exclude variable rate.
    79	 */
    80	static const struct dp_link_dpll chv_dpll[] = {
    81		/*
    82		 * CHV requires to program fractional division for m2.
    83		 * m2 is stored in fixed point format using formula below
    84		 * (m2_int << 22) | m2_fraction
    85		 */
    86		{ 162000,	/* m2_int = 32, m2_fraction = 1677722 */
    87			{ .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
    88		{ 270000,	/* m2_int = 27, m2_fraction = 0 */
    89			{ .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
    90		{ 540000,	/* m2_int = 27, m2_fraction = 0 */
    91			{ .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
    92	};
    93	
    94	static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
    95					  324000, 432000, 540000 };
    96	static const int skl_rates[] = { 162000, 216000, 270000,
    97					  324000, 432000, 540000 };
    98	static const int default_rates[] = { 162000, 270000, 540000 };
    99	
   100	/**
   101	 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
   102	 * @intel_dp: DP struct
   103	 *
   104	 * If a CPU or PCH DP output is attached to an eDP panel, this function
   105	 * will return true, and false otherwise.
   106	 */
   107	static bool is_edp(struct intel_dp *intel_dp)
   108	{
   109		struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
   110	
   111		return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
   112	}
   113	
   114	static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
   115	{
   116		struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
   117	
   118		return intel_dig_port->base.base.dev;
   119	}
   120	
   121	static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
   122	{
   123		return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
   124	}
   125	
   126	static void intel_dp_link_down(struct intel_dp *intel_dp);
   127	static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
   128	static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
   129	static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
   130	static void vlv_steal_power_sequencer(struct drm_device *dev,
   131					      enum pipe pipe);
   132	static void intel_dp_unset_edid(struct intel_dp *intel_dp);
   133	
   134	static int
   135	intel_dp_max_link_bw(struct intel_dp  *intel_dp)
   136	{
   137		int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
   138	
   139		switch (max_link_bw) {
   140		case DP_LINK_BW_1_62:
   141		case DP_LINK_BW_2_7:
   142		case DP_LINK_BW_5_4:
   143			break;
   144		default:
   145			WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
   146			     max_link_bw);
   147			max_link_bw = DP_LINK_BW_1_62;
   148			break;
   149		}
   150		return max_link_bw;
   151	}
   152	
   153	static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
   154	{
   155		struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
   156		u8 source_max, sink_max;
   157	
   158		source_max = intel_dig_port->max_lanes;
   159		sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
   160	
   161		return min(source_max, sink_max);
   162	}
   163	
   164	static int
   165	intel_dp_link_required(int pixel_clock, int bpp)
   166	{
   167		/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
 > 168		return DIV_ROUND_UP(pixel_clk * bpp, 8);
   169	}
   170	
   171	static int

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 37885 bytes --]

[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math
  2016-11-14 21:50 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
@ 2016-11-15  9:30   ` Jani Nikula
  2016-11-15 18:46     ` Pandiyan, Dhinakaran
  2016-11-29 20:22   ` Ville Syrjälä
  1 sibling, 1 reply; 12+ messages in thread
From: Jani Nikula @ 2016-11-15  9:30 UTC (permalink / raw)
  To: intel-gfx; +Cc: Dhinakaran Pandiyan

On Mon, 14 Nov 2016, Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com> wrote:
> We store DP link rates as link clock frequencies in kHz, just like all
> other clock values. But, DP link rates in the DP Spec. are expressed in
> Gbps/lane, which seems to have led to some confusion.
>
> E.g., for HBR2
> Max. data rate = 5.4 Gbps/lane x 4 lane x 8/10 x 1/8 = 2160000 kBps
> where, 8/10 is for channel encoding and 1/8 is for bit to Byte conversion
>
> Using link clock frequency, like we do
> Max. data rate = 540000 kHz * 4 lanes = 2160000 kSymbols/s
> Because, each symbol has 8 bit of data, this is 2160000 kBps
> and there is no need to account for channel encoding here.
>
> But, currently we do 540000 kHz * 4 lanes * (8/10) = 1728000 kBps
>
> Similarly, while computing the required link bandwidth for a mode,
> there is a mysterious 1/10 term.
> This should simply be pixel_clock kHz * (bpp/8) to give the final result in
> kBps
>
> v2: Changed to DIV_ROUND_UP() and comment changes (Ville)
>
> Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
> ---
> Fixed a typo that snuck in.

Trust me, you really don't want to lead us to believe you're sending
patches to the list without as much as compiling them first.

Sincerely,
Jani.

>
>  drivers/gpu/drm/i915/intel_dp.c | 35 +++++++++++++++--------------------
>  1 file changed, 15 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index 8f313c1..bdef314 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -161,33 +161,23 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
>  	return min(source_max, sink_max);
>  }
>  
> -/*
> - * 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(int pixel_clock, int bpp)
>  {
> -	return (pixel_clock * bpp + 9) / 10;
> +	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
> +	return DIV_ROUND_UP(pixel_clock * bpp, 8);
>  }
>  
>  static int
>  intel_dp_max_data_rate(int max_link_clock, int max_lanes)
>  {
> -	return (max_link_clock * max_lanes * 8) / 10;
> +	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
> +	 * link rate that is generally expressed in Gbps. Since, 8 bits of data
> +	 * is transmitted every LS_Clk per lane, there is no need to account for
> +	 * the channel encoding that is done in the PHY layer here.
> +	 */
> +
> +	return max_link_clock * max_lanes;
>  }
>  
>  static int
> @@ -3573,7 +3563,12 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
>  			if (val == 0)
>  				break;
>  
> -			/* Value read is in kHz while drm clock is saved in deca-kHz */
> +			/* Value read multiplied by 200kHz gives the per-lane
> +			 * link rate in kHz. The source rates are, however,
> +			 * stored in terms of LS_Clk kHz. The full conversion
> +			 * back to symbols is
> +			 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
> +			 */
>  			intel_dp->sink_rates[i] = (val * 200) / 10;
>  		}
>  		intel_dp->num_sink_rates = i;

-- 
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math
  2016-11-15  9:30   ` Jani Nikula
@ 2016-11-15 18:46     ` Pandiyan, Dhinakaran
  0 siblings, 0 replies; 12+ messages in thread
From: Pandiyan, Dhinakaran @ 2016-11-15 18:46 UTC (permalink / raw)
  To: Nikula, Jani; +Cc: intel-gfx@lists.freedesktop.org

On Tue, 2016-11-15 at 11:30 +0200, Jani Nikula wrote:
> On Mon, 14 Nov 2016, Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com> wrote:
> > We store DP link rates as link clock frequencies in kHz, just like all
> > other clock values. But, DP link rates in the DP Spec. are expressed in
> > Gbps/lane, which seems to have led to some confusion.
> >
> > E.g., for HBR2
> > Max. data rate = 5.4 Gbps/lane x 4 lane x 8/10 x 1/8 = 2160000 kBps
> > where, 8/10 is for channel encoding and 1/8 is for bit to Byte conversion
> >
> > Using link clock frequency, like we do
> > Max. data rate = 540000 kHz * 4 lanes = 2160000 kSymbols/s
> > Because, each symbol has 8 bit of data, this is 2160000 kBps
> > and there is no need to account for channel encoding here.
> >
> > But, currently we do 540000 kHz * 4 lanes * (8/10) = 1728000 kBps
> >
> > Similarly, while computing the required link bandwidth for a mode,
> > there is a mysterious 1/10 term.
> > This should simply be pixel_clock kHz * (bpp/8) to give the final result in
> > kBps
> >
> > v2: Changed to DIV_ROUND_UP() and comment changes (Ville)
> >
> > Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
> > ---
> > Fixed a typo that snuck in.
> 
> Trust me, you really don't want to lead us to believe you're sending
> patches to the list without as much as compiling them first.
> 
> Sincerely,
> Jani.
> 

I did compile, the typo fix did not get committed in the interactive
rebase I was doing.


> >
> >  drivers/gpu/drm/i915/intel_dp.c | 35 +++++++++++++++--------------------
> >  1 file changed, 15 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> > index 8f313c1..bdef314 100644
> > --- a/drivers/gpu/drm/i915/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > @@ -161,33 +161,23 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
> >  	return min(source_max, sink_max);
> >  }
> >  
> > -/*
> > - * 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(int pixel_clock, int bpp)
> >  {
> > -	return (pixel_clock * bpp + 9) / 10;
> > +	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
> > +	return DIV_ROUND_UP(pixel_clock * bpp, 8);
> >  }
> >  
> >  static int
> >  intel_dp_max_data_rate(int max_link_clock, int max_lanes)
> >  {
> > -	return (max_link_clock * max_lanes * 8) / 10;
> > +	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
> > +	 * link rate that is generally expressed in Gbps. Since, 8 bits of data
> > +	 * is transmitted every LS_Clk per lane, there is no need to account for
> > +	 * the channel encoding that is done in the PHY layer here.
> > +	 */
> > +
> > +	return max_link_clock * max_lanes;
> >  }
> >  
> >  static int
> > @@ -3573,7 +3563,12 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
> >  			if (val == 0)
> >  				break;
> >  
> > -			/* Value read is in kHz while drm clock is saved in deca-kHz */
> > +			/* Value read multiplied by 200kHz gives the per-lane
> > +			 * link rate in kHz. The source rates are, however,
> > +			 * stored in terms of LS_Clk kHz. The full conversion
> > +			 * back to symbols is
> > +			 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
> > +			 */
> >  			intel_dp->sink_rates[i] = (val * 200) / 10;
> >  		}
> >  		intel_dp->num_sink_rates = i;
> 

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST
  2016-11-14 21:42 ` [PATCH v2 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST Dhinakaran Pandiyan
@ 2016-11-15 20:59   ` Dhinakaran Pandiyan
  2016-11-29 20:24     ` Ville Syrjälä
  0 siblings, 1 reply; 12+ messages in thread
From: Dhinakaran Pandiyan @ 2016-11-15 20:59 UTC (permalink / raw)
  To: intel-gfx; +Cc: Dhinakaran Pandiyan

Not validating the mode rate against max. link rate results in not pruning
invalid modes. For e.g, a HBR2 5.4 Gbps 2-lane configuration does not
support 4k@60Hz. But, we do not reject this mode.

So, make use of the helpers in intel_dp to validate mode data rate against
max. link data rate of a configuration.

v3: Renamed local variables again for consistency (Manasi)
v2: Renamed mode data rate local variable to be more explanatory.

Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
---
 drivers/gpu/drm/i915/intel_dp.c     |  4 ++--
 drivers/gpu/drm/i915/intel_dp_mst.c | 12 +++++++++++-
 drivers/gpu/drm/i915/intel_drv.h    |  2 ++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index bdef314..8a0c909 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -161,14 +161,14 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
 	return min(source_max, sink_max);
 }
 
-static int
+int
 intel_dp_link_required(int pixel_clock, int bpp)
 {
 	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
 	return DIV_ROUND_UP(pixel_clock * bpp, 8);
 }
 
-static int
+int
 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
 {
 	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
index 3ffbd69..e21cf08 100644
--- a/drivers/gpu/drm/i915/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/intel_dp_mst.c
@@ -335,7 +335,17 @@ static enum drm_mode_status
 intel_dp_mst_mode_valid(struct drm_connector *connector,
 			struct drm_display_mode *mode)
 {
+	struct intel_connector *intel_connector = to_intel_connector(connector);
+	struct intel_dp *intel_dp = intel_connector->mst_port;
 	int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
+	int bpp = 24; /* MST uses fixed bpp */
+	int max_rate, mode_rate, max_lanes, max_link_clock;
+
+	max_link_clock = intel_dp_max_link_rate(intel_dp);
+	max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
+
+	max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
+	mode_rate = intel_dp_link_required(mode->clock, bpp);
 
 	/* TODO - validate mode against available PBN for link */
 	if (mode->clock < 10000)
@@ -344,7 +354,7 @@ intel_dp_mst_mode_valid(struct drm_connector *connector,
 	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
 		return MODE_H_ILLEGAL;
 
-	if (mode->clock > max_dotclk)
+	if (mode_rate > max_rate || mode->clock > max_dotclk)
 		return MODE_CLOCK_HIGH;
 
 	return MODE_OK;
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index c2f3863..313419d 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1471,6 +1471,8 @@ bool intel_dp_read_dpcd(struct intel_dp *intel_dp);
 bool __intel_dp_read_desc(struct intel_dp *intel_dp,
 			  struct intel_dp_desc *desc);
 bool intel_dp_read_desc(struct intel_dp *intel_dp);
+int intel_dp_link_required(int pixel_clock, int bpp);
+int intel_dp_max_data_rate(int max_link_clock, int max_lanes);
 
 /* intel_dp_aux_backlight.c */
 int intel_dp_aux_init_backlight_funcs(struct intel_connector *intel_connector);
-- 
2.7.4

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev3)
  2016-11-14 21:42 [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
                   ` (3 preceding siblings ...)
  2016-11-15  5:07 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math kbuild test robot
@ 2016-11-15 21:16 ` Patchwork
  4 siblings, 0 replies; 12+ messages in thread
From: Patchwork @ 2016-11-15 21:16 UTC (permalink / raw)
  To: Pandiyan, Dhinakaran; +Cc: intel-gfx

== Series Details ==

Series: series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev3)
URL   : https://patchwork.freedesktop.org/series/15305/
State : success

== Summary ==

Series 15305v3 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/15305/revisions/3/mbox/


fi-bdw-5557u     total:244  pass:229  dwarn:0   dfail:0   fail:0   skip:15 
fi-bsw-n3050     total:244  pass:204  dwarn:0   dfail:0   fail:0   skip:40 
fi-bxt-t5700     total:244  pass:216  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-j1900     total:244  pass:216  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-n2820     total:244  pass:212  dwarn:0   dfail:0   fail:0   skip:32 
fi-hsw-4770      total:244  pass:224  dwarn:0   dfail:0   fail:0   skip:20 
fi-hsw-4770r     total:244  pass:224  dwarn:0   dfail:0   fail:0   skip:20 
fi-ilk-650       total:244  pass:191  dwarn:0   dfail:0   fail:0   skip:53 
fi-ivb-3520m     total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-ivb-3770      total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-kbl-7200u     total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-skl-6260u     total:244  pass:230  dwarn:0   dfail:0   fail:0   skip:14 
fi-skl-6700hq    total:244  pass:223  dwarn:0   dfail:0   fail:0   skip:21 
fi-skl-6700k     total:244  pass:222  dwarn:1   dfail:0   fail:0   skip:21 
fi-skl-6770hq    total:244  pass:230  dwarn:0   dfail:0   fail:0   skip:14 
fi-snb-2520m     total:244  pass:212  dwarn:0   dfail:0   fail:0   skip:32 
fi-snb-2600      total:244  pass:211  dwarn:0   dfail:0   fail:0   skip:33 

04145fe15cf8c81c221e62fc9d65d93053f9bd1a drm-intel-nightly: 2016y-11m-15d-14h-47m-07s UTC integration manifest
7ce028d drm/i915/dp: Validate mode against max. link data rate for DP MST
8cc172a drm/dp/i915: Fix DP link rate math

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3007/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math
  2016-11-14 21:50 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
  2016-11-15  9:30   ` Jani Nikula
@ 2016-11-29 20:22   ` Ville Syrjälä
  1 sibling, 0 replies; 12+ messages in thread
From: Ville Syrjälä @ 2016-11-29 20:22 UTC (permalink / raw)
  To: Dhinakaran Pandiyan; +Cc: jani.nikula, intel-gfx

On Mon, Nov 14, 2016 at 01:50:20PM -0800, Dhinakaran Pandiyan wrote:
> We store DP link rates as link clock frequencies in kHz, just like all
> other clock values. But, DP link rates in the DP Spec. are expressed in
> Gbps/lane, which seems to have led to some confusion.
> 
> E.g., for HBR2
> Max. data rate = 5.4 Gbps/lane x 4 lane x 8/10 x 1/8 = 2160000 kBps
> where, 8/10 is for channel encoding and 1/8 is for bit to Byte conversion
> 
> Using link clock frequency, like we do
> Max. data rate = 540000 kHz * 4 lanes = 2160000 kSymbols/s
> Because, each symbol has 8 bit of data, this is 2160000 kBps
> and there is no need to account for channel encoding here.
> 
> But, currently we do 540000 kHz * 4 lanes * (8/10) = 1728000 kBps
> 
> Similarly, while computing the required link bandwidth for a mode,
> there is a mysterious 1/10 term.
> This should simply be pixel_clock kHz * (bpp/8) to give the final result in
> kBps
> 
> v2: Changed to DIV_ROUND_UP() and comment changes (Ville)
> 
> Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>

Math checks out.

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> ---
> Fixed a typo that snuck in.
> 
>  drivers/gpu/drm/i915/intel_dp.c | 35 +++++++++++++++--------------------
>  1 file changed, 15 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index 8f313c1..bdef314 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -161,33 +161,23 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
>  	return min(source_max, sink_max);
>  }
>  
> -/*
> - * 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(int pixel_clock, int bpp)
>  {
> -	return (pixel_clock * bpp + 9) / 10;
> +	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
> +	return DIV_ROUND_UP(pixel_clock * bpp, 8);
>  }
>  
>  static int
>  intel_dp_max_data_rate(int max_link_clock, int max_lanes)
>  {
> -	return (max_link_clock * max_lanes * 8) / 10;
> +	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
> +	 * link rate that is generally expressed in Gbps. Since, 8 bits of data
> +	 * is transmitted every LS_Clk per lane, there is no need to account for
> +	 * the channel encoding that is done in the PHY layer here.
> +	 */
> +
> +	return max_link_clock * max_lanes;
>  }
>  
>  static int
> @@ -3573,7 +3563,12 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
>  			if (val == 0)
>  				break;
>  
> -			/* Value read is in kHz while drm clock is saved in deca-kHz */
> +			/* Value read multiplied by 200kHz gives the per-lane
> +			 * link rate in kHz. The source rates are, however,
> +			 * stored in terms of LS_Clk kHz. The full conversion
> +			 * back to symbols is
> +			 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
> +			 */
>  			intel_dp->sink_rates[i] = (val * 200) / 10;
>  		}
>  		intel_dp->num_sink_rates = i;
> -- 
> 2.7.4

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST
  2016-11-15 20:59   ` [PATCH v3 " Dhinakaran Pandiyan
@ 2016-11-29 20:24     ` Ville Syrjälä
  2016-12-05 14:34       ` Ville Syrjälä
  0 siblings, 1 reply; 12+ messages in thread
From: Ville Syrjälä @ 2016-11-29 20:24 UTC (permalink / raw)
  To: Dhinakaran Pandiyan; +Cc: intel-gfx

On Tue, Nov 15, 2016 at 12:59:06PM -0800, Dhinakaran Pandiyan wrote:
> Not validating the mode rate against max. link rate results in not pruning
> invalid modes. For e.g, a HBR2 5.4 Gbps 2-lane configuration does not
> support 4k@60Hz. But, we do not reject this mode.
> 
> So, make use of the helpers in intel_dp to validate mode data rate against
> max. link data rate of a configuration.
> 
> v3: Renamed local variables again for consistency (Manasi)
> v2: Renamed mode data rate local variable to be more explanatory.
> 
> Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> ---
>  drivers/gpu/drm/i915/intel_dp.c     |  4 ++--
>  drivers/gpu/drm/i915/intel_dp_mst.c | 12 +++++++++++-
>  drivers/gpu/drm/i915/intel_drv.h    |  2 ++
>  3 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index bdef314..8a0c909 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -161,14 +161,14 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
>  	return min(source_max, sink_max);
>  }
>  
> -static int
> +int
>  intel_dp_link_required(int pixel_clock, int bpp)
>  {
>  	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
>  	return DIV_ROUND_UP(pixel_clock * bpp, 8);
>  }
>  
> -static int
> +int
>  intel_dp_max_data_rate(int max_link_clock, int max_lanes)
>  {
>  	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
> diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
> index 3ffbd69..e21cf08 100644
> --- a/drivers/gpu/drm/i915/intel_dp_mst.c
> +++ b/drivers/gpu/drm/i915/intel_dp_mst.c
> @@ -335,7 +335,17 @@ static enum drm_mode_status
>  intel_dp_mst_mode_valid(struct drm_connector *connector,
>  			struct drm_display_mode *mode)
>  {
> +	struct intel_connector *intel_connector = to_intel_connector(connector);
> +	struct intel_dp *intel_dp = intel_connector->mst_port;
>  	int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
> +	int bpp = 24; /* MST uses fixed bpp */
> +	int max_rate, mode_rate, max_lanes, max_link_clock;
> +
> +	max_link_clock = intel_dp_max_link_rate(intel_dp);
> +	max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
> +
> +	max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
> +	mode_rate = intel_dp_link_required(mode->clock, bpp);
>  
>  	/* TODO - validate mode against available PBN for link */
>  	if (mode->clock < 10000)
> @@ -344,7 +354,7 @@ intel_dp_mst_mode_valid(struct drm_connector *connector,
>  	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
>  		return MODE_H_ILLEGAL;
>  
> -	if (mode->clock > max_dotclk)
> +	if (mode_rate > max_rate || mode->clock > max_dotclk)
>  		return MODE_CLOCK_HIGH;
>  
>  	return MODE_OK;
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index c2f3863..313419d 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -1471,6 +1471,8 @@ bool intel_dp_read_dpcd(struct intel_dp *intel_dp);
>  bool __intel_dp_read_desc(struct intel_dp *intel_dp,
>  			  struct intel_dp_desc *desc);
>  bool intel_dp_read_desc(struct intel_dp *intel_dp);
> +int intel_dp_link_required(int pixel_clock, int bpp);
> +int intel_dp_max_data_rate(int max_link_clock, int max_lanes);
>  
>  /* intel_dp_aux_backlight.c */
>  int intel_dp_aux_init_backlight_funcs(struct intel_connector *intel_connector);
> -- 
> 2.7.4

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST
  2016-11-29 20:24     ` Ville Syrjälä
@ 2016-12-05 14:34       ` Ville Syrjälä
  0 siblings, 0 replies; 12+ messages in thread
From: Ville Syrjälä @ 2016-12-05 14:34 UTC (permalink / raw)
  To: Dhinakaran Pandiyan; +Cc: intel-gfx

On Tue, Nov 29, 2016 at 10:24:16PM +0200, Ville Syrjälä wrote:
> On Tue, Nov 15, 2016 at 12:59:06PM -0800, Dhinakaran Pandiyan wrote:
> > Not validating the mode rate against max. link rate results in not pruning
> > invalid modes. For e.g, a HBR2 5.4 Gbps 2-lane configuration does not
> > support 4k@60Hz. But, we do not reject this mode.
> > 
> > So, make use of the helpers in intel_dp to validate mode data rate against
> > max. link data rate of a configuration.
> > 
> > v3: Renamed local variables again for consistency (Manasi)
> > v2: Renamed mode data rate local variable to be more explanatory.
> > 
> > Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
> 
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

...and both patches pushed to dinq.

> 
> > ---
> >  drivers/gpu/drm/i915/intel_dp.c     |  4 ++--
> >  drivers/gpu/drm/i915/intel_dp_mst.c | 12 +++++++++++-
> >  drivers/gpu/drm/i915/intel_drv.h    |  2 ++
> >  3 files changed, 15 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> > index bdef314..8a0c909 100644
> > --- a/drivers/gpu/drm/i915/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > @@ -161,14 +161,14 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
> >  	return min(source_max, sink_max);
> >  }
> >  
> > -static int
> > +int
> >  intel_dp_link_required(int pixel_clock, int bpp)
> >  {
> >  	/* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
> >  	return DIV_ROUND_UP(pixel_clock * bpp, 8);
> >  }
> >  
> > -static int
> > +int
> >  intel_dp_max_data_rate(int max_link_clock, int max_lanes)
> >  {
> >  	/* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
> > diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
> > index 3ffbd69..e21cf08 100644
> > --- a/drivers/gpu/drm/i915/intel_dp_mst.c
> > +++ b/drivers/gpu/drm/i915/intel_dp_mst.c
> > @@ -335,7 +335,17 @@ static enum drm_mode_status
> >  intel_dp_mst_mode_valid(struct drm_connector *connector,
> >  			struct drm_display_mode *mode)
> >  {
> > +	struct intel_connector *intel_connector = to_intel_connector(connector);
> > +	struct intel_dp *intel_dp = intel_connector->mst_port;
> >  	int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
> > +	int bpp = 24; /* MST uses fixed bpp */
> > +	int max_rate, mode_rate, max_lanes, max_link_clock;
> > +
> > +	max_link_clock = intel_dp_max_link_rate(intel_dp);
> > +	max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);
> > +
> > +	max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
> > +	mode_rate = intel_dp_link_required(mode->clock, bpp);
> >  
> >  	/* TODO - validate mode against available PBN for link */
> >  	if (mode->clock < 10000)
> > @@ -344,7 +354,7 @@ intel_dp_mst_mode_valid(struct drm_connector *connector,
> >  	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
> >  		return MODE_H_ILLEGAL;
> >  
> > -	if (mode->clock > max_dotclk)
> > +	if (mode_rate > max_rate || mode->clock > max_dotclk)
> >  		return MODE_CLOCK_HIGH;
> >  
> >  	return MODE_OK;
> > diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> > index c2f3863..313419d 100644
> > --- a/drivers/gpu/drm/i915/intel_drv.h
> > +++ b/drivers/gpu/drm/i915/intel_drv.h
> > @@ -1471,6 +1471,8 @@ bool intel_dp_read_dpcd(struct intel_dp *intel_dp);
> >  bool __intel_dp_read_desc(struct intel_dp *intel_dp,
> >  			  struct intel_dp_desc *desc);
> >  bool intel_dp_read_desc(struct intel_dp *intel_dp);
> > +int intel_dp_link_required(int pixel_clock, int bpp);
> > +int intel_dp_max_data_rate(int max_link_clock, int max_lanes);
> >  
> >  /* intel_dp_aux_backlight.c */
> >  int intel_dp_aux_init_backlight_funcs(struct intel_connector *intel_connector);
> > -- 
> > 2.7.4
> 
> -- 
> Ville Syrjälä
> Intel OTC
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-12-05 14:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-14 21:42 [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
2016-11-14 21:42 ` [PATCH v2 2/2] drm/i915/dp: Validate mode against max. link data rate for DP MST Dhinakaran Pandiyan
2016-11-15 20:59   ` [PATCH v3 " Dhinakaran Pandiyan
2016-11-29 20:24     ` Ville Syrjälä
2016-12-05 14:34       ` Ville Syrjälä
2016-11-14 21:50 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math Dhinakaran Pandiyan
2016-11-15  9:30   ` Jani Nikula
2016-11-15 18:46     ` Pandiyan, Dhinakaran
2016-11-29 20:22   ` Ville Syrjälä
2016-11-14 22:15 ` ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev2) Patchwork
2016-11-15  5:07 ` [PATCH v2 1/2] drm/dp/i915: Fix DP link rate math kbuild test robot
2016-11-15 21:16 ` ✓ Fi.CI.BAT: success for series starting with [v2,1/2] drm/dp/i915: Fix DP link rate math (rev3) Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).