Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kunal Joshi <kunal1.joshi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Kunal Joshi <kunal1.joshi@intel.com>, Sowmiya S <sowmiya.s@intel.com>
Subject: [PATCH i-g-t 01/13] lib/i915/i915_dp: add helpers for the allowed link configs debugfs
Date: Thu,  1 Oct 2026 13:06:51 +0530	[thread overview]
Message-ID: <20261001073703.5067-2-kunal1.joshi@intel.com> (raw)
In-Reply-To: <20261001073703.5067-1-kunal1.joshi@intel.com>

The existing helpers don't tell which link configs can actually be used.
i915_dp_get_max_supported_rate() parses i915_dp_force_link_rate, which
only lists the source rates, and the driver silently clamps a forced
rate the sink doesn't support.

The intel_dp_allowed_link_configs connector debugfs file lists the lane
count and link rate combos the driver picks from. Add
i915_dp_get_allowed_link_configs() to read them, and
i915_dp_has_allowed_link_configs_debugfs() to check the file exists.
We'll be adding a user in follow-up.

Assisted-by: GitHub_Copilot:claude-opus-5
Signed-off-by: Kunal Joshi <kunal1.joshi@intel.com>
Reviewed-by: Sowmiya S <sowmiya.s@intel.com>
---
 lib/i915/i915_dp.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/i915/i915_dp.h | 17 ++++++++++
 2 files changed, 98 insertions(+)

diff --git a/lib/i915/i915_dp.c b/lib/i915/i915_dp.c
index 3d570f7cc..aba6aa8d5 100644
--- a/lib/i915/i915_dp.c
+++ b/lib/i915/i915_dp.c
@@ -37,6 +37,12 @@
 #include "igt_core.h"
 #include "igt_kms.h"
 
+/*
+ * The driver allows at most 10 link rates over 3 lane counts, i.e. 30 entries
+ * of at most "4x2000000 ", so 1024 has plenty of room to spare.
+ */
+#define LINK_CONFIGS_BUF_SIZE	1024
+
 /**
  * i915_dp_parse_marked_value:
  * @buf: Buffer containing the content to parse
@@ -391,6 +397,81 @@ int i915_dp_get_max_supported_rate(int drm_fd, const igt_output_t *output)
 	return max_rate;
 }
 
+/**
+ * i915_dp_has_allowed_link_configs_debugfs:
+ * @drm_fd: A drm file descriptor
+ * @output: Target output
+ *
+ * Checks if the allowed link configs debugfs is available for a specific
+ * output.
+ *
+ * Returns: True if the debugfs is available, false otherwise
+ */
+bool i915_dp_has_allowed_link_configs_debugfs(int drm_fd, igt_output_t *output)
+{
+	char buf[LINK_CONFIGS_BUF_SIZE];
+
+	return igt_debugfs_read_connector_file(drm_fd, igt_output_name(output),
+					       "intel_dp_allowed_link_configs",
+					       buf, sizeof(buf)) == 0;
+}
+
+/**
+ * i915_dp_get_allowed_link_configs:
+ * @drm_fd: A drm file descriptor
+ * @output: Target output
+ * @configs: Array to store the allowed link configurations in
+ * @max_configs: Number of entries in @configs
+ *
+ * Read the link configurations the driver currently allows on @output, i.e.
+ * the intersection of the source rates, the rates the sink advertises and the
+ * current link limits.
+ *
+ * The driver lists them in the order it would pick them, which differs between
+ * SST and MST and depends on earlier link training results, so callers have to
+ * treat the result as an unordered set.
+ *
+ * Returns: The number of configurations stored in @configs
+ */
+int i915_dp_get_allowed_link_configs(int drm_fd, igt_output_t *output,
+				     struct i915_dp_link_config *configs,
+				     int max_configs)
+{
+	char buf[LINK_CONFIGS_BUF_SIZE];
+	char *token, *saveptr = NULL;
+	int count = 0;
+	int res;
+
+	res = igt_debugfs_read_connector_file(drm_fd, igt_output_name(output),
+					      "intel_dp_allowed_link_configs",
+					      buf, sizeof(buf));
+	igt_assert_f(res == 0, "Unable to read %s/intel_dp_allowed_link_configs\n",
+		     igt_output_name(output));
+
+	/* An empty set of allowed configurations reads back as a bare newline. */
+	buf[strcspn(buf, "\n")] = '\0';
+
+	for (token = strtok_r(buf, " ", &saveptr); token;
+	     token = strtok_r(NULL, " ", &saveptr)) {
+		int lane_count, link_rate;
+		char extra;
+
+		igt_assert_f(count < max_configs,
+			     "More than %d link configs on %s\n",
+			     max_configs, igt_output_name(output));
+		igt_assert_f(sscanf(token, "%dx%d%c", &lane_count, &link_rate,
+				    &extra) == 2 && lane_count > 0 &&
+			     link_rate > 0,
+			     "Failed to parse link config '%s'\n", token);
+
+		configs[count].lane_count = lane_count;
+		configs[count].link_rate = link_rate;
+		count++;
+	}
+
+	return count;
+}
+
 /**
  * i915_dp_get_next_lower_rate:
  * @drm_fd: A drm file descriptor
diff --git a/lib/i915/i915_dp.h b/lib/i915/i915_dp.h
index 5d17713e2..c818b3937 100644
--- a/lib/i915/i915_dp.h
+++ b/lib/i915/i915_dp.h
@@ -10,6 +10,19 @@
 /* DP link rates are in 10 kbit/s units; UHBR10 is 10 Gbps. */
 #define I915_DP_UHBR10_LINK_RATE	1000000
 
+/**
+ * struct i915_dp_link_config:
+ * @lane_count: Number of lanes
+ * @link_rate: Link rate in 10 kbit/s units
+ *
+ * A single link configuration, as listed by the intel_dp_allowed_link_configs
+ * connector debugfs file.
+ */
+struct i915_dp_link_config {
+	int lane_count;
+	int link_rate;
+};
+
 /**
  * i915_dp_is_uhbr_rate:
  * @link_rate: DP link rate in 10 kbit/s units, as reported by the
@@ -40,6 +53,10 @@ 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,
 			     const char *link_rate, const char *lane_count);
 int i915_dp_get_max_supported_rate(int drm_fd, const igt_output_t *output);
+bool i915_dp_has_allowed_link_configs_debugfs(int drm_fd, igt_output_t *output);
+int i915_dp_get_allowed_link_configs(int drm_fd, igt_output_t *output,
+				     struct i915_dp_link_config *configs,
+				     int max_configs);
 int i915_dp_get_next_lower_rate(int drm_fd, igt_output_t *output, int rate);
 
 #endif
-- 
2.25.1


  reply	other threads:[~2026-10-01  7:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01  7:36 [PATCH i-g-t 00/13] Expand kms_dp_link_training coverage Kunal Joshi
2026-10-01  7:36 ` Kunal Joshi [this message]
2026-10-01  7:36 ` [PATCH i-g-t 02/13] tests/intel/kms_dp_link_training: use i915_dp_is_uhbr_rate() Kunal Joshi
2026-10-01  7:36 ` [PATCH i-g-t 03/13] tests/intel/kms_dp_link_training: extract train_link_config() Kunal Joshi
2026-10-01  7:36 ` [PATCH i-g-t 04/13] tests/intel/kms_dp_link_training: detect links that failed training Kunal Joshi
2026-10-01  9:05   ` S, Sowmiya
2026-10-01  7:36 ` [PATCH i-g-t 05/13] tests/intel/kms_dp_link_training: use the lowest pixel clock mode Kunal Joshi
2026-10-01  7:36 ` [PATCH i-g-t 06/13] tests/intel/kms_dp_link_training: train all allowed link configs Kunal Joshi
2026-10-01  9:05   ` S, Sowmiya
2026-10-01  7:36 ` [PATCH i-g-t 07/13] lib/i915/i915_dp: add i915_dp_get_tc_mode() Kunal Joshi
2026-10-01  7:36 ` [PATCH i-g-t 08/13] tests/intel/kms_dp_link_training: log the DP link inventory Kunal Joshi
2026-10-01  7:36 ` [PATCH i-g-t 09/13] tests/intel/kms_dp_link_training: train each MST topology only once Kunal Joshi
2026-10-01  7:37 ` [PATCH i-g-t 10/13] tests/intel/kms_dp_link_training: add tbt-alt and direct link subtests Kunal Joshi
2026-10-01  7:37 ` [PATCH i-g-t 11/13] lib/igt_dp: add DPCD read helpers Kunal Joshi
2026-10-01  7:37 ` [PATCH i-g-t 12/13] lib/igt_dp: add DPCD link status and channel coding checks Kunal Joshi
2026-10-01  7:37 ` [PATCH i-g-t 13/13] tests/intel/kms_dp_link_training: check the link from the sink side Kunal Joshi
2026-10-01 13:13 ` ✓ i915.CI.BAT: success for Expand kms_dp_link_training coverage (rev2) Patchwork
2026-10-01 16:42 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-01 21:02 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-10-05 16:06   ` Joshi, Kunal1
2026-10-02 17:18 ` ✗ i915.CI.Full: " Patchwork
2026-10-05 16:04   ` Joshi, Kunal1
  -- strict thread matches above, loose matches on Subject: below --
2026-09-16  4:47 [PATCH i-g-t 00/13] Expand kms_dp_link_training coverage Kunal Joshi
2026-09-16  4:47 ` [PATCH i-g-t 01/13] lib/i915/i915_dp: Add helpers for the allowed link configs debugfs Kunal Joshi
2026-09-21  8:37   ` S, Sowmiya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261001073703.5067-2-kunal1.joshi@intel.com \
    --to=kunal1.joshi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=sowmiya.s@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox