[PATCH i-g-t v2 21/26] lib/unigraf: Add connector autodetection

Louis Chauvet louis.chauvet at bootlin.com
Thu Jul 17 18:46:41 UTC 2025


In order to avoid writing custom configuration for each DUT, add a simple
autodetection algorithm.
---
 lib/unigraf/unigraf.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index b59a3627af30642899fcf3e4c9e5b53fb4e54eeb..10f8c5ab671d0e8ccf27d333f6ea66c8219b0892 100644
--- a/lib/unigraf/unigraf.c
+++ b/lib/unigraf/unigraf.c
@@ -165,8 +165,58 @@ static int unigraf_find_input(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 chamelium\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);
 }
 

-- 
2.50.0



More information about the igt-dev mailing list