[i-g-t,v4,2/5] lib/igt_kms: Add helper to wait for a specific status on a connector
Joshi, Kunal1
kunal1.joshi at intel.com
Wed Mar 19 08:46:32 UTC 2025
Hello Louis,
Can we have all connector related at one place (kms_connector_helper or
igt_connector),
igt_kms is already crowded and also will be easy to find all connector
helpers at one place.
Thanks and Regards
Kunal Joshi
On 10-01-2025 23:12, Louis Chauvet wrote:
> During testing with chamelium, it is frequent to wait for a specific
> connector status. This new helper is polling the DRM API to wait for this
> status. This allows detecting it without notifier systems which can fail
> if hot plug detection is not working properly on the device under test.
>
> Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
> ---
> lib/igt_kms.c | 39 +++++++++++++++++++++++++++++++++++++++
> lib/igt_kms.h | 3 +++
> 2 files changed, 42 insertions(+)
>
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index b3373435b252c9f8c5d5854f738f7f4bbc468964..d0b6c70f135754d0a413f73a0f8e5b24a208a2b3 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -7245,3 +7245,42 @@ double igt_default_display_detect_timeout(void)
>
> return timeout;
> }
> +
> +/**
> + * igt_wait_for_connector_status:
> + * @drm_fd: drm file descriptor
> + * @connector_id: connector to monitor
> + * @timeout: maximum duration to wait, in second. Use -1.0 to set the timeout
> + * to igt_default_detect_timeout().
> + * @drm_mode: mode to wait for, see enum drmModeConnection
> + *
> + * Wait for at most @timeout that the connector @connector_id status
> + * become @drm_mode
> + * Returns: true when the status is reached, false if there is a timeout
> + */
> +bool igt_wait_for_connector_status(int drm_fd, unsigned int connector_id, double timeout,
> + int drm_mode)
> +{
> + drmModeConnector *connector;
> + struct timespec start, end;
> +
> + if (timeout == -1.0)
> + timeout = igt_default_display_detect_timeout();
> +
> + clock_gettime(CLOCK_MONOTONIC, &start);
> + end = start;
> +
> + while (igt_time_elapsed(&start, &end) <= timeout) {
> + connector = drmModeGetConnector(drm_fd, connector_id);
> + if (connector && connector->connection == drm_mode) {
> + free(connector);
> + return true;
> + }
> + free(connector);
> + clock_gettime(CLOCK_MONOTONIC, &end);
> + }
> +
> + igt_debug("Timeout waiting for connection status %d on connector %d\n", drm_mode,
> + connector_id);
> + return false;
> +}
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 91a26f2070efd26f9d107841ae3083b281d5e4c6..6d5582290f61d1a4151dd8e8448fc26c660a1536 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -1279,4 +1279,7 @@ int igt_backlight_write(int value, const char *fname, igt_backlight_context_t *c
>
> double igt_default_display_detect_timeout(void);
>
> +bool igt_wait_for_connector_status(int drm_fd, unsigned int connector_id, double timeout,
> + int drm_mode);
> +
> #endif /* __IGT_KMS_H__ */
More information about the igt-dev
mailing list