[PATCH i-g-t 04/12] lib/igt_kms: add function to force link retrain

Kunal Joshi kunal1.joshi at intel.com
Mon Aug 19 09:26:07 UTC 2024


add two helper one allows to set and restore to
specified default value on exit, while the second
only allows forcing link retrain without any restoration

Signed-off-by: Kunal Joshi <kunal1.joshi at intel.com>
---
 lib/igt_kms.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  3 +++
 2 files changed, 70 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 1115a0b93..05e115d9c 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -6772,6 +6772,51 @@ bool kmstest_force_connector_link_rate(int drm_fd, drmModeConnector *connector,
 	return true;
 }
 
+static bool force_connector_retrain(int drm_fd,
+					  drmModeConnector *connector,
+					  const char *value)
+{
+	return connector_attr_set_debugfs(drm_fd, connector,
+					  "i915_dp_force_link_retrain",
+					  value, "1");
+}
+
+/**
+ * kmstest_force_connector_force_retrain:
+ * @fd: drm file descriptor
+ * @connector: connector
+ * @retrain_count: number of time to retrain
+ *
+ * Force retraining on the specified connector
+ * and install exit handler for resetting
+ *
+ * Returns: True on success
+ */
+bool kmstest_force_connector_retrain(int drm_fd, drmModeConnector *connector, int retrain_count)
+{
+	char value[2];
+	drmModeConnector *temp;
+
+	if (!is_intel_device(drm_fd))
+		return false;
+
+	snprintf(value, sizeof(value), "%d", retrain_count);
+	if (!force_connector_retrain(drm_fd, connector, value))
+		return false;
+
+	dump_connector_attrs();
+	igt_install_exit_handler(reset_connectors_at_exit);
+
+	/*
+	 * To allow callers to always use GetConnectorCurrent we need to force a
+	 * redetection here.
+	 */
+	temp = drmModeGetConnector(drm_fd, connector->connector_id);
+	drmModeFreeConnector(temp);
+
+	return true;
+}
+
 /**
  * igt_get_dp_link_rate_set_for_output:
  * @drm_fd: A drm file descriptor
@@ -6887,3 +6932,25 @@ enum dp_lane_count igt_get_dp_max_lane_count(int drm_fd, igt_output_t *output)
 
 	return max_lane_count;
 }
+
+/**
+ * igt_force_link_retrain:
+ * @drm_fd: A drm file descriptor
+ * @output: Target output
+ * @retrain_count: number of retraining required
+ *
+ * Force retrain the link on given output
+ */
+void igt_force_link_retrain(int drm_fd, igt_output_t *output, int retrain_count)
+{
+	int dir;
+	char value[2];
+
+	snprintf(value, sizeof(value), "%d", retrain_count);
+	igt_require_f(output->name, "Invalid output");
+	dir = igt_debugfs_connector_dir(drm_fd, output->name, O_RDONLY);
+	igt_assert_f(dir >= 0, "Failed to open debugfs dir for connector %s\n",
+			       igt_output_name(output));
+	igt_sysfs_write(dir, "i915_dp_force_link_retrain", value, sizeof(value));
+	close(dir);
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index b65c478c9..4a90b5398 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -292,6 +292,8 @@ bool kmstest_force_connector_lane_count(int drm_fd, drmModeConnector *connector,
 					const char *lane);
 bool kmstest_force_connector_link_rate(int drm_fd, drmModeConnector *connector,
 				       const char *link);
+bool kmstest_force_connector_retrain(int drm_fd, drmModeConnector *connector,
+				     int retrain_count);
 
 bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
 					drmModeModeInfo *mode);
@@ -1255,5 +1257,6 @@ enum dp_link_rate igt_get_dp_link_rate_set_for_output(int drm_fd, igt_output_t *
 enum dp_lane_count igt_get_dp_lane_count_set_for_output(int drm_fd, igt_output_t *output);
 enum dp_link_rate igt_get_dp_max_link_rate(int drm_fd, igt_output_t *output);
 enum dp_lane_count igt_get_dp_max_lane_count(int drm_fd, igt_output_t *output);
+void igt_force_link_retrain(int drm_fd, igt_output_t *output, int retrain_count);
 
 #endif /* __IGT_KMS_H__ */
-- 
2.43.0



More information about the igt-dev mailing list