[PATCH i-g-t 1/6] lib/igt_kms: add DP link management helper functions
Joshi, Kunal1
kunal1.joshi at intel.com
Thu Sep 12 11:15:46 UTC 2024
Hello,
> -----Original Message-----
> From: Joshi, Kunal1 <kunal1.joshi at intel.com>
> Sent: Thursday, September 12, 2024 11:59 AM
> To: igt-dev at lists.freedesktop.org
> Cc: Deak, Imre <imre.deak at intel.com>; Joshi, Kunal1
> <kunal1.joshi at intel.com>
> Subject: [PATCH i-g-t 1/6] lib/igt_kms: add DP link management helper
> functions
>
> Added helper functions for below
> - read current/max link_rate/lane_count
> - forcing link retraining
> - forcing link training failures
> - read pending retrain
> - read pending link training failures
> - checking output supports forcing lt failures
> - force link_rate/lane_count
>
> v2: combine all link training debugfs in one patch (Imre)
> remove unwanted valid output check (Imre)
> return link_rate/lane_count marked with '*' or an error (Imre)
>
> Signed-off-by: Kunal Joshi <kunal1.joshi at intel.com>
> ---
> lib/igt_kms.c | 210
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> lib/igt_kms.h | 10 +++
> 2 files changed, 220 insertions(+)
>
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c index dd530dbab..f0ac1e5dc 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -61,6 +61,7 @@
> #include "sw_sync.h"
> #ifdef HAVE_CHAMELIUM
> #include "igt_chamelium.h"
> +#include <ctype.h>
There are some warnings seen in pipeline
Will fix this in next revision.
Thanks and Regards
Kunal Joshi
> #endif
>
> /**
> @@ -6705,3 +6706,212 @@ int get_num_scalers(igt_display_t *display, enum
> pipe pipe)
>
> return num_scalers;
> }
> +
> +/**
> + * igt_get_dp_link_param_set_for_output:
> + * @drm_fd: A drm file descriptor
> + * @output: Target output
> + * @link_param: 0 for lane count, 1 for link rate
> + *
> + * Returns: link_rate / lane_count if set for output else -1 */ int
> +igt_get_dp_link_param_set_for_output(int drm_fd, igt_output_t *output,
> +int link_param) {
> + char *star_ptr, *param_ptr;
> + char buf[512];
> + int dir, res;
> + int ret;
> +
> + ret = -1;
> + 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));
> + res = igt_debugfs_simple_read(dir, link_param ?
> "i915_dp_force_link_rate" :
> + "i915_dp_force_lane_count", buf,
> sizeof(buf));
> + close(dir);
> + igt_require(res >= 0);
> +
> + /*
> + * Check we have a mode enabled for the output
> + * If so we will have current active link rate
> + * marked with a *
> + */
> + star_ptr = strstr(buf, "*");
> +
> + if (star_ptr) {
> + param_ptr = star_ptr - 1;
> + while (param_ptr > buf && isdigit(*param_ptr))
> + param_ptr--;
> +
> + param_ptr++;
> + igt_assert(sscanf(param_ptr, "%d", &ret) == 1);
> + }
> + return ret;
> +}
> +
> +/**
> + * igt_get_dp_max_link_param:
> + * @drm_fd: A drm file descriptor
> + * @output: The output to query
> + * @link_param: 0 for lane count, 1 for link rate
> + *
> + * Get the max link_rate / lane_count supported by the sink.
> + *
> + * Returns: max link_rate / lane_count supported by the sink.
> + */
> +int igt_get_dp_max_link_param(int drm_fd, igt_output_t *output, int
> +link_param) {
> + char buf[512];
> + int dir, res;
> + int max_link_param;
> +
> + dir = igt_debugfs_connector_dir(drm_fd, output->name,
> O_DIRECTORY);
> + igt_assert_f(dir >= 0, "Failed to open debugfs dir for connector %s\n",
> + igt_output_name(output));
> + res = igt_debugfs_simple_read(dir, link_param ?
> "i915_dp_max_link_rate" :
> + "i915_dp_max_lane_count", buf,
> sizeof(buf));
> + close(dir);
> + igt_require_f(res >= 0, "Couldn't read i915_dp_max_link_rate");
> +
> + igt_assert(sscanf(buf, "%d", &max_link_param) == 1);
> +
> + return max_link_param;
> +}
> +
> +/**
> + * igt_force_link_retrain:
> + * @drm_fd: A drm file descriptor
> + * @output: Target output
> + * @retrain_count: number of retraining required
> + *
> + * Force link retrain on the 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);
> + 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);
> +}
> +
> +/**
> + * igt_force_lt_failure:
> + * @drm_fd: A drm file descriptor
> + * @output: Target output
> + * @failure_count: 1 for same link param and
> + * 2 for reduced link params
> + *
> + * Force link training failure on the output.
> + * @failure_count: 1 for retraining with same link params
> + * 2 for retraining with reduced link params
> + */
> +void igt_force_lt_failure(int drm_fd, igt_output_t *output, int
> +failure_count) {
> + int dir;
> + char value[2];
> +
> + snprintf(value, sizeof(value), "%d", failure_count);
> + 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_training_failure",
> + value, sizeof(value));
> + close(dir);
> +}
> +
> +/**
> + * igt_get_dp_link_retrain_disabled:
> + * @drm_fd: A drm file descriptor
> + * @output: Target output
> + *
> + * Returns: True if link retrain disabled, false otherwise */ bool
> +igt_get_dp_link_retrain_disabled(int drm_fd, igt_output_t *output) {
> + int dir, res;
> + char buf[512];
> +
> + 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));
> + res = igt_debugfs_simple_read(dir,
> + "i915_dp_link_retrain_disabled",
> + buf, sizeof(buf));
> + close(dir);
> + igt_require(res >= 0);
> + return strstr(buf, "yes");
> +}
> +
> +/**
> + * Checks if the force link training failure debugfs
> + * is available for a specific output.
> + *
> + * @drmfd: file descriptor of the DRM device.
> + * @output: output to check.
> + * Returns:
> + * true if the debugfs is available, false otherwise.
> + */
> +bool igt_has_force_link_training_failure_debugfs(int drmfd,
> +igt_output_t *output) {
> + int debugfs_fd, ret;
> + char buf[512];
> +
> + igt_assert_f(output->name, "Invalid output\n");
> + debugfs_fd = igt_debugfs_connector_dir(drmfd, output->name,
> O_RDONLY);
> + if (debugfs_fd < 0)
> + return false;
> + ret = igt_debugfs_simple_read(debugfs_fd,
> + "i915_dp_force_link_training_failure",
> + buf, sizeof(buf));
> + close(debugfs_fd);
> + return ret >= 0;
> +}
> +
> +/**
> + * igt_get_dp_pending_lt_failures:
> + * @drm_fd: A drm file descriptor
> + * @output: Target output
> + *
> + * Returns: Number of pending link training failures.
> + */
> +int igt_get_dp_pending_lt_failures(int drm_fd, igt_output_t *output) {
> + int dir, res, ret;
> + char buf[512];
> +
> + 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));
> + res = igt_debugfs_simple_read(dir,
> "i915_dp_force_link_training_failure", buf, sizeof(buf));
> + close(dir);
> + igt_require(res >= 0);
> + sscanf(buf, "%d", &ret);
> + return ret;
> +}
> +
> +/**
> + * igt_dp_pending_retrain:
> + * @drm_fd: A drm file descriptor
> + * @output: Target output
> + *
> + * Returns: Number of pending link retrains.
> + */
> +int igt_get_dp_pending_retrain(int drm_fd, igt_output_t *output) {
> + int dir, res, ret;
> + char buf[512];
> +
> + 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));
> + res = igt_debugfs_simple_read(dir, "i915_dp_force_link_retrain", buf,
> sizeof(buf));
> + close(dir);
> + igt_require(res >= 0);
> + sscanf(buf, "%d", &ret);
> + return ret;
> +}
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h index 25ba50916..895bc9d04 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -1224,5 +1224,15 @@ bool
> intel_pipe_output_combo_valid(igt_display_t *display); bool
> igt_check_output_is_dp_mst(igt_output_t *output); int
> igt_get_dp_mst_connector_id(igt_output_t *output); int
> get_num_scalers(igt_display_t *display, enum pipe pipe);
> +int igt_get_dp_link_param_set_for_output(int drm_fd, igt_output_t *output,
> + int link_param);
> +int igt_get_dp_max_link_param(int drm_fd, igt_output_t *output,
> + int link_param);
> +void igt_force_link_retrain(int drm_fd, igt_output_t *output, int
> +retrain_count); void igt_force_lt_failure(int drm_fd, igt_output_t
> +*output, int failure_count); bool igt_get_dp_link_retrain_disabled(int
> +drm_fd, igt_output_t *output); bool
> +igt_has_force_link_training_failure_debugfs(int drmfd, igt_output_t
> +*output); int igt_get_dp_pending_lt_failures(int drm_fd, igt_output_t
> +*output); int igt_get_dp_pending_retrain(int drm_fd, igt_output_t
> +*output);
>
> #endif /* __IGT_KMS_H__ */
> --
> 2.43.0
More information about the igt-dev
mailing list