All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeevan B <jeevan.b@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: kunal1.joshi@intel.com, suraj.kandpal@intel.com,
	Jeevan B <jeevan.b@intel.com>
Subject: [PATCH i-g-t 5/6] lib/igt_kms: Add helper to get eDP/DP supported link rates
Date: Mon, 24 Nov 2025 23:57:55 +0530	[thread overview]
Message-ID: <20251124182804.2095722-6-jeevan.b@intel.com> (raw)
In-Reply-To: <20251124182804.2095722-1-jeevan.b@intel.com>

Add igt_get_supported_link_rates to parse debugfs and return available
eDP/DP link rates for a given connector.

Signed-off-by: Jeevan B <jeevan.b@intel.com>
---
 lib/igt_kms.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  2 ++
 2 files changed, 54 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index c03cfed09..4071aa00a 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -7632,3 +7632,55 @@ bool igt_has_lobf_debugfs(int drmfd, igt_output_t *output)
                                               buf, sizeof(buf));
         return res == 0;
 }
+
+/**
+ * igt_get_supported_link_rates:
+ * @drmfd: A drm file descriptor
+ * @connector_name: Name of the libdrm connector we're going to use
+ *
+ * Returns: All the link rates supported by the connector
+ */
+int igt_get_supported_link_rates(int drmfd, char *connector_name,
+		       int *rates, int max_rates)
+{
+	char buf[48];
+	int fd, res;
+	int count = 0;
+	char *token, *star;
+
+	if (!rates || max_rates <= 0) {
+		return -1;
+        }
+
+	fd = igt_debugfs_connector_dir(drmfd, connector_name, O_RDONLY);
+	igt_assert_lte(0, fd);
+
+	res = igt_debugfs_simple_read(fd, "i915_dp_force_link_rate", buf, sizeof(buf));
+	igt_require(res > 0);
+
+	igt_require_f(res > 0,
+		      "Unable to read i915_dp_force_link_rate for %s\n",
+		      connector_name);
+
+	buf[res] = '\0'; /* Null terminate */
+	token = strtok(buf, " \t\n");
+
+	while (token && count < max_rates) {
+		if (!strcmp(token, "[auto]")) {
+			token = strtok(NULL, " \t\n");
+			continue;
+		}
+
+		star = strchr(token, '*');
+		if (star)
+			*star = '\0';
+
+		if (isdigit(token[0])) {
+			rates[count++] = atoi(token);
+		}
+
+		token = strtok(NULL, " \t\n");
+	}
+
+	return count;
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index cd9f6840a..474a809ea 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -1303,6 +1303,8 @@ void igt_set_link_params(int drm_fd, igt_output_t *output,
 int igt_backlight_read(int *result, const char *fname, igt_backlight_context_t *context);
 int igt_backlight_write(int value, const char *fname, igt_backlight_context_t *context);
 uint32_t igt_get_connected_output_count(igt_display_t *display);
+int igt_get_supported_link_rates(int drmfd, char *connector_name, int *rates,
+				 int max_rates);
 
 drmModePropertyBlobRes *igt_get_writeback_formats_blob(igt_output_t *output);
 
-- 
2.43.0


  parent reply	other threads:[~2025-11-24 18:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24 18:27 [PATCH i-g-t 0/6] RFC: Add new test for eDP data override Jeevan B
2025-11-24 18:27 ` [PATCH i-g-t 1/6] tests/intel/kms_dp_link_training: rename to tests/intel/kms_link_training Jeevan B
2025-11-24 18:27 ` [PATCH i-g-t 2/6] tests/intel/kms_dp_linktrain_fallback: rename to tests/intel/kms_linktrain_fallback Jeevan B
2025-11-24 18:27 ` [PATCH i-g-t 3/6] lib/igt_kms: add helpers for connector type Jeevan B
2025-11-24 18:27 ` [PATCH i-g-t 4/6] tests/intel/kms_link_training: extend test for eDP connector Jeevan B
2025-11-24 18:27 ` Jeevan B [this message]
2025-11-24 18:27 ` [PATCH i-g-t 6/6] RFC: tests/intel/kms_link_training: Add edp-data-override subtest Jeevan B

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=20251124182804.2095722-6-jeevan.b@intel.com \
    --to=jeevan.b@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kunal1.joshi@intel.com \
    --cc=suraj.kandpal@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.