[PATCH i-g-t v3 22/29] lib/unigraf: Add connector autodetection
Louis Chauvet
louis.chauvet at bootlin.com
Sat Aug 23 02:11:42 UTC 2025
In order to avoid writing custom configuration for each DUT, add a simple
autodetection algorithm.
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
lib/unigraf/unigraf.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 64 insertions(+), 2 deletions(-)
diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index 41c1015aa942ccaf9c93890656d403997b19e661..b90025425d232bd5269adfe9f17f2813eac7754d 100644
--- a/lib/unigraf/unigraf.c
+++ b/lib/unigraf/unigraf.c
@@ -176,8 +176,58 @@ static int unigraf_find_input(const char *request)
return chosen_input;
}
+static void unigraf_autodetect_connector(int drm_fd)
+{
+ int newly_connected_count, already_connected_count, diff_len;
+ uint32_t *newly_connected = NULL, *already_connected = NULL;
+ drmModeConnectorPtr connector;
+ uint32_t *diff = NULL;
+
+ igt_assert(drm_fd);
+ unigraf_set_sst();
+ unigraf_hpd_deassert();
+
+ /*
+ * Hard sleep is required here as we don't know how long it will take for the device under
+ * test to properly detect the port disconnection.
+ */
+ sleep(igt_default_display_detect_timeout());
+
+ already_connected_count = igt_get_connected_connectors(drm_fd, &already_connected);
+
+ unigraf_hpd_assert();
+
+ newly_connected_count = kms_wait_for_new_connectors(&newly_connected,
+ already_connected,
+ already_connected_count,
+ drm_fd);
+
+ diff_len = get_list_diff(newly_connected, newly_connected_count,
+ already_connected, already_connected_count, &diff);
+
+ if (diff_len == 0) {
+ unigraf_debug("No newly connected connector, assuming that the unigraf is not connected.\n");
+ } else if (diff_len > 1) {
+ unigraf_debug("More than one new connectors connected, this is not supported by autodetection.\n");
+ } else {
+ unigraf_debug("Found one connector (%d) connected to the Unigraf\n", diff[0]);
+ connector = drmModeGetConnector(drm_fd, diff[0]);
+ igt_assert(connector);
+ igt_assert(asprintf(&unigraf_connector_name, "%s-%u",
+ kmstest_connector_type_str(connector->connector_type),
+ connector->connector_type_id) != -1);
+ drmModeFreeConnector(connector);
+ }
+
+ free(already_connected);
+ free(newly_connected);
+ free(diff);
+}
+
drmModeConnectorPtr unigraf_get_connector(int drm_fd)
{
+ if (!unigraf_connector_name)
+ unigraf_autodetect_connector(drm_fd);
return igt_get_connector_from_name(drm_fd, unigraf_connector_name);
}
@@ -197,7 +247,7 @@ bool unigraf_open_device(int drm_fd)
assert(igt_can_fail());
if (unigraf_device)
- return true;
+ return unigraf_connector_name != NULL;
unigraf_init();
@@ -316,7 +366,19 @@ bool unigraf_open_device(int drm_fd)
unigraf_assert(TSIX_VIN_Select(unigraf_device, chosen_input));
unigraf_assert(TSIX_VIN_Enable(unigraf_device, chosen_input));
- return true;
+ if (!unigraf_connector_name) {
+ unigraf_hpd_deassert();
+ unigraf_set_sst();
+ unigraf_hpd_assert();
+ sleep(1);
+ unigraf_autodetect_connector(drm_fd);
+ }
+
+ unigraf_hpd_deassert();
+ unigraf_set_sst();
+ unigraf_hpd_assert();
+ sleep(1);
+ return unigraf_connector_name != NULL;
}
void unigraf_require_device(int drm_fd)
--
2.50.1
More information about the igt-dev
mailing list