Skip to contentSkip to conversation

tests/kms_setmode: Add HDMI 2.0 clock limit for mode selection

PATCH Superseded Jeevan B 3 participants 5 messages Mar 31

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jeevan B

author
#0 lore raw

PATCH v2 1/1 tests/kms_setmode: Add HDMI 2.0 clock limit for mode selection

eDP modes with high clock rates were being forced on HDMI 2.0 displays, causing kernel to reject with EINVAL. Add clock validation to skip incompatible eDP modes and fall back to supported modes.

v2: Add HDMI 2.0 clock limit helper, drop crtc_supports_mode(),
and ensure per-connector compatibility to avoid invalid modes.

---
 tests/kms_setmode.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)
tests/kms_setmode.c +42 -2
index 1f2849bc2..f1c1afe45 100644
@@ -79,6 +79,9 @@
 /* restricted pipe count */
 #define CRTC_RESTRICT_CNT 2
 
+/* Clock limit for HDMI 2.0 */
+#define HDMI_2_0_MAX_CLOCK_KHZ 600000
+
 static int drm_fd;
 static drmModeRes *drm_resources;
 static int filter_test_id;
@@ -165,6 +168,16 @@ static bool connector_supports_mode(drmModeConnector *connector,
 	return false;
 }
 
+static bool hdmi_connector_mode_exceeds_hdmi20_limit(drmModeConnector *connector,
+						     drmModeModeInfo *mode)
+{
+	if (connector->connector_type != DRM_MODE_CONNECTOR_HDMIA &&
+	    connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)
+		return false;
+
+	return mode->clock > HDMI_2_0_MAX_CLOCK_KHZ;
+}
+
 static bool crtc_supports_mode(struct crtc_config *crtc, drmModeModeInfo *mode)
 {
 	int i;
@@ -270,8 +283,35 @@ static void get_mode_for_crtc(struct crtc_config *crtc,
 				if (conn->modes[j].clock < mode->clock)
 					mode = &conn->modes[j];
 			}
-			*mode_ret = *mode;
-			return;
+
+			/* Check HDMI 2.0 clock + per-connector compatibility */
+			{
+				int k;
+				bool compatible = true;
+
+				for (k = 0; k < crtc->connector_count; k++) {
+					drmModeConnector *other_conn =
+						crtc->cconfs[k].connector;
+
+					/* HDMI 2.0 clock constraint */
+					if (hdmi_connector_mode_exceeds_hdmi20_limit(other_conn,
+										     mode)) {
+						compatible = false;
+						break;
+					}
+
+					/* Ensure connector supports the mode */
+					if (!connector_supports_mode(other_conn, mode)) {
+						compatible = false;
+						break;
+					}
+				}
+
+				if (compatible) {
+					*mode_ret = *mode;
+					return;
+				}
+			}
 		}
 	}
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 68 lines · Jeevan B

eDP modes with high clock rates were being forced on HDMI 2.0 displays, causing kernel to reject with EINVAL. Add clock validation to skip incompatible eDP modes and fall back to supported modes.

v2: Add HDMI 2.0 clock limit helper, drop crtc_supports_mode(),
and ensure per-connector compatibility to avoid invalid modes.

---
 tests/kms_setmode.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)
tests/kms_setmode.c +32 -2
index 1f2849bc2..f1c1afe45 100644
@@ -79,6 +79,9 @@
 /* restricted pipe count */
 #define CRTC_RESTRICT_CNT 2
 
+/* Clock limit for HDMI 2.0 */
+#define HDMI_2_0_MAX_CLOCK_KHZ 600000
+
 static int drm_fd;
 static drmModeRes *drm_resources;
 static int filter_test_id;
@@ -165,6 +168,16 @@ static bool connector_supports_mode(drmModeConnector *connector,
 	return false;
 }
 
+static bool hdmi_connector_mode_exceeds_hdmi20_limit(drmModeConnector *connector,
+						     drmModeModeInfo *mode)
+{
+	if (connector->connector_type != DRM_MODE_CONNECTOR_HDMIA &&
+	    connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)
+		return false;
+
+	return mode->clock > HDMI_2_0_MAX_CLOCK_KHZ;
+}
+
 static bool crtc_supports_mode(struct crtc_config *crtc, drmModeModeInfo *mode)
 {
 	int i;
@@ -270,8 +283,35 @@ static void get_mode_for_crtc(struct crtc_config *crtc,
 				if (conn->modes[j].clock < mode->clock)
 					mode = &conn->modes[j];
 			}
-			*mode_ret = *mode;
-			return;
+
+			/* Check HDMI 2.0 clock + per-connector compatibility */
+			{
+				int k;
+				bool compatible = true;
+
+				for (k = 0; k < crtc->connector_count; k++) {
+					drmModeConnector *other_conn =
+						crtc->cconfs[k].connector;
+
+					/* HDMI 2.0 clock constraint */
+					if (hdmi_connector_mode_exceeds_hdmi20_limit(other_conn,
+										     mode)) {
+						compatible = false;
+						break;
+					}
+
+					/* Ensure connector supports the mode */
+					if (!connector_supports_mode(other_conn, mode)) {

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config *crtc, · line 314

Quoted 10 lines
tests/kms_setmode.c +10 -0
+						compatible = false;
+						break;
+					}
+				}
+
+				if (compatible) {
+					*mode_ret = *mode;
+					return;
+				}
+			}

Please abstract the whole thing into a function. Having those {} blocks inline is messy.

BR,
Jani.

Quoted 2 lines
tests/kms_setmode.c +0 -0
 		}
 	}
Signature · 1 line
Jani Nikula, Intel
#2 lore raw
In reply to Jeevan B
Quoted 28 lines · Jeevan B

eDP modes with high clock rates were being forced on HDMI 2.0 displays, causing kernel to reject with EINVAL. Add clock validation to skip incompatible eDP modes and fall back to supported modes.

v2: Add HDMI 2.0 clock limit helper, drop crtc_supports_mode(),
and ensure per-connector compatibility to avoid invalid modes.

---
 tests/kms_setmode.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)
tests/kms_setmode.c +3 -0
index 1f2849bc2..f1c1afe45 100644
@@ -79,6 +79,9 @@
 /* restricted pipe count */
 #define CRTC_RESTRICT_CNT 2
 
+/* Clock limit for HDMI 2.0 */
+#define HDMI_2_0_MAX_CLOCK_KHZ 600000
+
 static int drm_fd;
 static drmModeRes *drm_resources;
 static int filter_test_id;
@@ -165,6 +168,16 @@ static bool connector_supports_mode(drmModeConnector *connector,
 	return false;

tests/kms_setmode.c static bool connector_supports_mode(drmModeConnector *connector, · line 178

Quoted 10 lines
tests/kms_setmode.c +8 -0
 }
 
+static bool hdmi_connector_mode_exceeds_hdmi20_limit(drmModeConnector *connector,
+						     drmModeModeInfo *mode)
+{
+	if (connector->connector_type != DRM_MODE_CONNECTOR_HDMIA &&
+	    connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)
+		return false;
+
+	return mode->clock > HDMI_2_0_MAX_CLOCK_KHZ;

Starting to test all kinds of random thing here does not seem maintainable.

I think the one sensible option is to make the test skip rather than fail if it couldn't find a common mode between the connectors and the modeset subsequently failed.

As for the external vs. internal connector situation, the test should probably try to find a mode on the external connector(s) that has the same refresh rate as one of the modes on the internal connector, and has the same resolution (or less) than the internal panel. That way we can use pfit to upscale content on the internal panel instead of attempting to force the external connectors to use the internal panel's native mode.

Quoted 45 lines
tests/kms_setmode.c +31 -2
+}
+
 static bool crtc_supports_mode(struct crtc_config *crtc, drmModeModeInfo *mode)
 {
 	int i;
@@ -270,8 +283,35 @@ static void get_mode_for_crtc(struct crtc_config *crtc,
 				if (conn->modes[j].clock < mode->clock)
 					mode = &conn->modes[j];
 			}
-			*mode_ret = *mode;
-			return;
+
+			/* Check HDMI 2.0 clock + per-connector compatibility */
+			{
+				int k;
+				bool compatible = true;
+
+				for (k = 0; k < crtc->connector_count; k++) {
+					drmModeConnector *other_conn =
+						crtc->cconfs[k].connector;
+
+					/* HDMI 2.0 clock constraint */
+					if (hdmi_connector_mode_exceeds_hdmi20_limit(other_conn,
+										     mode)) {
+						compatible = false;
+						break;
+					}
+
+					/* Ensure connector supports the mode */
+					if (!connector_supports_mode(other_conn, mode)) {
+						compatible = false;
+						break;
+					}
+				}
+
+				if (compatible) {
+					*mode_ret = *mode;
+					return;
+				}
+			}
 		}
 	}
 
Signature · 1 line
2.43.0
Signature · 2 lines
Ville Syrjälä
Intel
author
#3 lore raw
Quoted 61 lines

-----Original Message-----
From: Ville Syrjälä <[email protected]>
Sent: Tuesday, March 31, 2026 6:36 PM
To: B, Jeevan <[email protected]>
Cc: [email protected]; Nautiyal, Ankit K <[email protected]>
Subject: Re: [PATCH i-g-t v2] tests/kms_setmode: Add HDMI 2.0 clock limit for mode selection

Quoted 10 lines · Jeevan B

eDP modes with high clock rates were being forced on HDMI 2.0 displays, causing kernel to reject with EINVAL. Add clock validation to skip incompatible eDP modes and fall back to supported modes.

v2: Add HDMI 2.0 clock limit helper, drop crtc_supports_mode(),
and ensure per-connector compatibility to avoid invalid modes.

---
 tests/kms_setmode.c | 44

++++++++++++++++++++++++++++++++++++++++++--

tests/kms_setmode.c static bool

Quoted 17 lines
 1 file changed, 42 insertions(+), 2 deletions(-)
tests/kms_setmode.c index renamed from tests/kms_setmode.c +0 -0

1f2849bc2..f1c1afe45 100644

tests/kms_setmode.c +3 -0
@@ -79,6 +79,9 @@
 /* restricted pipe count */
 #define CRTC_RESTRICT_CNT 2
 
+/* Clock limit for HDMI 2.0 */
+#define HDMI_2_0_MAX_CLOCK_KHZ 600000
+
 static int drm_fd;
 static drmModeRes *drm_resources;
 static int filter_test_id;
@@ -165,6 +168,16 @@ static bool

connector_supports_mode(drmModeConnector *connector,

tests/kms_setmode.c static bool connector_supports_mode(drmModeConnector *connector,

Quoted 4 lines
tests/kms_setmode.c +1 -0
 	return false;
 }
 
+static bool

hdmi_connector_mode_exceeds_hdmi20_limit(drmModeConnector *connector,

tests/kms_setmode.c static bool · line 172

Quoted 1 line
tests/kms_setmode.c +1 -0
+						     drmModeModeInfo

*mode)

tests/kms_setmode.c static bool · line 174

Quoted 2 lines
tests/kms_setmode.c +2 -0
+{
+	if (connector->connector_type != DRM_MODE_CONNECTOR_HDMIA

&&

tests/kms_setmode.c static bool connector_supports_mode(drmModeConnector *connector, · line 178

Quoted 4 lines
tests/kms_setmode.c +4 -0
+	    connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)
+		return false;
+
+	return mode->clock > HDMI_2_0_MAX_CLOCK_KHZ;

Starting to test all kinds of random thing here does not seem maintainable.

I think the one sensible option is to make the test skip rather than fail if it couldn't find a common mode between the connectors and the modeset subsequently failed.

Quoted 7 lines

As for the external vs. internal connector situation, the test should probably try to find a mode on the external connector(s) that has the same refresh rate as one of the modes on the internal connector, and has the same resolution (or less) than the internal panel. That way we can use pfit to upscale content on the internal panel instead of attempting to force the external connectors to use the internal panel's native mode.

Thanks, that makes sense.

This test iterates through a large set of valid and invalid crtc/connector combinations, so trying to enforce strict compatibility in mode selection is making the logic complex and hard to maintain.

It's also becoming harder with newer internal panels supporting high refresh rates, which often don't have matching modes on external connectors.

I agree it's better to keep the selection simple and skip when no common mode is found or the modeset fails, instead of adding more heuristics.

Longer term, it might be worth rethinking the mode selection strategy, but for now I'll keep this change minimal.

Thanks
Jeevan B

Quoted 55 lines

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config

Quoted 6 lines
tests/kms_setmode.c +2 -0
+}
+
 static bool crtc_supports_mode(struct crtc_config *crtc,
 drmModeModeInfo *mode)  {
 	int i;
@@ -270,8 +283,35 @@ static void get_mode_for_crtc(struct crtc_config

*crtc,

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config *crtc,

Quoted 7 lines
tests/kms_setmode.c +2 -2
 				if (conn->modes[j].clock < mode->clock)
 					mode = &conn->modes[j];
 			}
-			*mode_ret = *mode;
-			return;
+
+			/* Check HDMI 2.0 clock + per-connector compatibility

*/

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config *crtc,

Quoted 10 lines
tests/kms_setmode.c +10 -0
+			{
+				int k;
+				bool compatible = true;
+
+				for (k = 0; k < crtc->connector_count; k++) {
+					drmModeConnector *other_conn =
+						crtc->cconfs[k].connector;
+
+					/* HDMI 2.0 clock constraint */
+					if

(hdmi_connector_mode_exceeds_hdmi20_limit(other_conn,

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config · line 298

Quoted 1 line
tests/kms_setmode.c +1 -0
+
	     mode)) {

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config *crtc,

Quoted 5 lines
tests/kms_setmode.c +5 -0
+						compatible = false;
+						break;
+					}
+
+					/* Ensure connector supports the

mode */

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config · line 304

Quoted 1 line
tests/kms_setmode.c +1 -0
+					if

(!connector_supports_mode(other_conn, mode)) {

Quoted 14 lines
tests/kms_setmode.c +10 -1
+						compatible = false;
+						break;
+					}
+				}
+
+				if (compatible) {
+					*mode_ret = *mode;
+					return;
+				}
+			}
 		}
 	}
 
--
Quoted 1 line

2.43.0

--
Ville Syrjälä
Intel

#4 lore raw
Quoted 78 lines · Jeevan
Quoted 61 lines

-----Original Message-----
From: Ville Syrjälä <[email protected]>
Sent: Tuesday, March 31, 2026 6:36 PM
To: B, Jeevan <[email protected]>
Cc: [email protected]; Nautiyal, Ankit K <[email protected]>
Subject: Re: [PATCH i-g-t v2] tests/kms_setmode: Add HDMI 2.0 clock limit for mode selection

Quoted 10 lines · Jeevan B

eDP modes with high clock rates were being forced on HDMI 2.0 displays, causing kernel to reject with EINVAL. Add clock validation to skip incompatible eDP modes and fall back to supported modes.

v2: Add HDMI 2.0 clock limit helper, drop crtc_supports_mode(),
and ensure per-connector compatibility to avoid invalid modes.

---
 tests/kms_setmode.c | 44

++++++++++++++++++++++++++++++++++++++++++--

tests/kms_setmode.c static bool

Quoted 17 lines
 1 file changed, 42 insertions(+), 2 deletions(-)
tests/kms_setmode.c index renamed from tests/kms_setmode.c +0 -0

1f2849bc2..f1c1afe45 100644

tests/kms_setmode.c +3 -0
@@ -79,6 +79,9 @@
 /* restricted pipe count */
 #define CRTC_RESTRICT_CNT 2
 
+/* Clock limit for HDMI 2.0 */
+#define HDMI_2_0_MAX_CLOCK_KHZ 600000
+
 static int drm_fd;
 static drmModeRes *drm_resources;
 static int filter_test_id;
@@ -165,6 +168,16 @@ static bool

connector_supports_mode(drmModeConnector *connector,

tests/kms_setmode.c static bool connector_supports_mode(drmModeConnector *connector,

Quoted 4 lines
tests/kms_setmode.c +1 -0
 	return false;
 }
 
+static bool

hdmi_connector_mode_exceeds_hdmi20_limit(drmModeConnector *connector,

tests/kms_setmode.c static bool · line 172

Quoted 1 line
tests/kms_setmode.c +1 -0
+						     drmModeModeInfo

*mode)

tests/kms_setmode.c static bool · line 174

Quoted 2 lines
tests/kms_setmode.c +2 -0
+{
+	if (connector->connector_type != DRM_MODE_CONNECTOR_HDMIA

&&

tests/kms_setmode.c static bool connector_supports_mode(drmModeConnector *connector, · line 178

Quoted 4 lines
tests/kms_setmode.c +4 -0
+	    connector->connector_type != DRM_MODE_CONNECTOR_HDMIB)
+		return false;
+
+	return mode->clock > HDMI_2_0_MAX_CLOCK_KHZ;

Starting to test all kinds of random thing here does not seem maintainable.

I think the one sensible option is to make the test skip rather than fail if it couldn't find a common mode between the connectors and the modeset subsequently failed.

Quoted 7 lines

As for the external vs. internal connector situation, the test should probably try to find a mode on the external connector(s) that has the same refresh rate as one of the modes on the internal connector, and has the same resolution (or less) than the internal panel. That way we can use pfit to upscale content on the internal panel instead of attempting to force the external connectors to use the internal panel's native mode.

Thanks, that makes sense.

This test iterates through a large set of valid and invalid crtc/connector combinations, so trying to enforce strict compatibility in mode selection is making the logic complex and hard to maintain.

It's also becoming harder with newer internal panels supporting high refresh rates, which often don't have matching modes on external connectors.

Quoted 5 lines

I agree it's better to keep the selection simple and skip when no common mode is found or the modeset fails, instead of adding more heuristics.

Longer term, it might be worth rethinking the mode selection strategy, but for now I'll keep this change minimal.

I think long term the test would be easier to maintain if it were converted to igt_display_require() and igt_crtc_t and friends instead of hand-rolling everything.

BR,
Jani.

Quoted 58 lines

Thanks
Jeevan B

Quoted 55 lines

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config

Quoted 6 lines
tests/kms_setmode.c +2 -0
+}
+
 static bool crtc_supports_mode(struct crtc_config *crtc,
 drmModeModeInfo *mode)  {
 	int i;
@@ -270,8 +283,35 @@ static void get_mode_for_crtc(struct crtc_config

*crtc,

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config *crtc,

Quoted 7 lines
tests/kms_setmode.c +2 -2
 				if (conn->modes[j].clock < mode->clock)
 					mode = &conn->modes[j];
 			}
-			*mode_ret = *mode;
-			return;
+
+			/* Check HDMI 2.0 clock + per-connector compatibility

*/

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config *crtc,

Quoted 10 lines
tests/kms_setmode.c +10 -0
+			{
+				int k;
+				bool compatible = true;
+
+				for (k = 0; k < crtc->connector_count; k++) {
+					drmModeConnector *other_conn =
+						crtc->cconfs[k].connector;
+
+					/* HDMI 2.0 clock constraint */
+					if

(hdmi_connector_mode_exceeds_hdmi20_limit(other_conn,

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config · line 298

Quoted 1 line
tests/kms_setmode.c +1 -0
+
	     mode)) {

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config *crtc,

Quoted 5 lines
tests/kms_setmode.c +5 -0
+						compatible = false;
+						break;
+					}
+
+					/* Ensure connector supports the

mode */

tests/kms_setmode.c static void get_mode_for_crtc(struct crtc_config · line 304

Quoted 1 line
tests/kms_setmode.c +1 -0
+					if

(!connector_supports_mode(other_conn, mode)) {

Quoted 14 lines
tests/kms_setmode.c +10 -1
+						compatible = false;
+						break;
+					}
+				}
+
+				if (compatible) {
+					*mode_ret = *mode;
+					return;
+				}
+			}
 		}
 	}
 
--
Quoted 1 line

2.43.0

--
Ville Syrjälä
Intel

Signature · 1 line
Jani Nikula, Intel