[PATCH i-g-t v7 33/48] lib/unigraf: add unigraf_get_connector_by_stream

Louis Chauvet
2026-02-23T12:09:41Z

As unigraf can emulate MST, we need a way to grab the corresponding DRM
connector from the stream id.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/unigraf/unigraf.c | 41 +++++++++++++++++++++++++++++++++++++++++
lib/unigraf/unigraf.h | 2 ++
2 files changed, 43 insertions(+)

diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index e9c9beb80c44..5d9edb8cd069 100644
--- a/lib/unigraf/unigraf.c
+++ b/lib/unigraf/unigraf.c
@@ -296,6 +296,47 @@ drmModeConnectorPtr unigraf_get_connector(int drm_fd)
return igt_get_connector_from_name(drm_fd, unigraf_connector_name);
}

+/**
+ * unigraf_get_connector_id_by_stream() - Get a connector id from a stream id
+ * @drm_fd: DRM device where the unigraf is attached
+ * @stream_id: Stream id in the MST streams
+ */
+int unigraf_get_connector_id_by_stream(int drm_fd, int stream_id)
+{
+ drmModeConnectorPtr main_connector = unigraf_get_connector(drm_fd);
+ drmModeResPtr res = drmModeGetResources(drm_fd);
+
+ char *mst_path;
+ int mst_path_len = asprintf(&mst_path, "mst:%d-", main_connector->connector_id);
+
+ igt_assert(mst_path_len >= 0);
+
+ for (int i = 0; i < res->count_connectors; i++) {
+ drmModePropertyBlobPtr path_blob = kmstest_get_path_blob(drm_fd,
+ res->connectors[i]);
+
+ if (!path_blob || path_blob->length < mst_path_len)
+ continue;
+
+ if (!memcmp(path_blob->data, mst_path, mst_path_len)) {
+ if (!stream_id) {
+ drmModeFreePropertyBlob(path_blob);
+ drmModeFreeResources(res);
+ drmModeFreeConnector(main_connector);
+ return res->connectors[i];
+ }
+ stream_id--;
+ }
+
+ drmModeFreePropertyBlob(path_blob);
+ }
+
+ drmModeFreeResources(res);
+ drmModeFreeConnector(main_connector);
+
+ return 0;
+}
+
/**
* unigraf_open_device() - Search and open a device.
* @drm_fd: File descriptor of the currently used drm device
diff --git a/lib/unigraf/unigraf.h b/lib/unigraf/unigraf.h
index f22f4c993622..0ed6d1eb2713 100644
--- a/lib/unigraf/unigraf.h
+++ b/lib/unigraf/unigraf.h
@@ -76,4 +76,6 @@ void unigraf_read_crc(int stream, igt_crc_t *out);

bool unigraf_use_crc(void);

+int unigraf_get_connector_id_by_stream(int drm_fd, int stream_id);
+
#endif // UNIGRAF_H

--
2.52.0