[PATCH i-g-t v7 38/48] lib/i915/dp: Add helper to get maximum supported rate

Louis Chauvet
2026-02-23T12:09:29Z

Some GPU can't reach all the DP rates. To avoid false positive during
testing with unigraf, add an helper to filter tests based on the maximum
supported rate of the current GPU.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/i915/i915_dp.c | 35 +++++++++++++++++++++++++++++++++++
lib/i915/i915_dp.h | 1 +
2 files changed, 36 insertions(+)

diff --git a/lib/i915/i915_dp.c b/lib/i915/i915_dp.c
index 48a69e9ff283..da3dd05c3293 100644
--- a/lib/i915/i915_dp.c
+++ b/lib/i915/i915_dp.c
@@ -28,7 +28,9 @@
*/

#include <ctype.h>
+#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>

#include "i915_dp.h"
@@ -344,3 +346,36 @@ void i915_dp_set_link_params(int drm_fd, igt_output_t *output,
temp = drmModeGetConnector(drm_fd, output->config.connector->connector_id);
drmModeFreeConnector(temp);
}
+
+/**
+ * i915_dp_get_max_supported_rate:
+ * @drm_fd: A drm file descriptor
+ * @output: Target output
+ *
+ * Returns: Max supported link rate available for output, else -1
+ */
+int i915_dp_get_max_supported_rate(int drm_fd, const igt_output_t *output)
+{
+ char buf[512];
+ int res, max_rate = -EINVAL;
+ char *token;
+
+ res = igt_debugfs_read_connector_file(drm_fd, igt_output_name(output),
+ "i915_dp_force_link_rate",
+ buf, sizeof(buf));
+ igt_assert_f(!res, "Unable to read %s/i915_dp_force_link_rate\n",
+ igt_output_name(output));
+
+ token = strtok(buf, " ");
+ while (token) {
+ int rate;
+
+ errno = 0;
+ rate = strtol(token, NULL, 0);
+ if (!errno && rate > max_rate)
+ max_rate = rate;
+ token = strtok(NULL, " ");
+ }
+
+ return max_rate;
+}
diff --git a/lib/i915/i915_dp.h b/lib/i915/i915_dp.h
index e4249d179543..b13629147804 100644
--- a/lib/i915/i915_dp.h
+++ b/lib/i915/i915_dp.h
@@ -18,5 +18,6 @@ int i915_dp_get_pending_retrain(int drm_fd, igt_output_t *output);
void i915_dp_reset_link_params(int drm_fd, igt_output_t *output);
void i915_dp_set_link_params(int drm_fd, igt_output_t *output,
char *link_rate, char *lane_count);
+int i915_dp_get_max_supported_rate(int drm_fd, const igt_output_t *output);

#endif

--
2.52.0