[PATCH i-g-t v3 27/29] lib/unigraf: add unigraf_get_connector_by_stream
Louis Chauvet
louis.chauvet at bootlin.com
Sat Aug 23 02:11:47 UTC 2025
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 at bootlin.com>
---
lib/unigraf/unigraf.c | 37 +++++++++++++++++++++++++++++++++++++
lib/unigraf/unigraf.h | 7 +++++++
2 files changed, 44 insertions(+)
diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index e2a26f9bb199d83d9a1474ac2613a181450e0530..8de2c74affdda741b11933a1a55f1c2d2b1bb61b 100644
--- a/lib/unigraf/unigraf.c
+++ b/lib/unigraf/unigraf.c
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include <xf86drmMode.h>
#include "unigraf.h"
#include "TSI_types.h"
@@ -257,6 +258,42 @@ drmModeConnectorPtr unigraf_get_connector(int drm_fd)
return igt_get_connector_from_name(drm_fd, unigraf_connector_name);
}
+int unigraf_get_connector_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) {
+ if (memcmp(path_blob->data, mst_path, mst_path_len) == 0) {
+ drmModeFreeResources(res);
+ if (stream_id == 0) {
+ drmModeFreePropertyBlob(path_blob);
+ drmModeFreeResources(res);
+ drmModeFreeConnector(main_connector);
+ return res->connectors[i];
+ }
+ stream_id--;
+ }
+
+ drmModeFreePropertyBlob(path_blob);
+ }
+ }
+
+ drmModeFreeResources(res);
+ drmModeFreeConnector(main_connector);
+
+ return 0;
+}
+
bool unigraf_open_device(int drm_fd)
{
TSI_RESULT r;
diff --git a/lib/unigraf/unigraf.h b/lib/unigraf/unigraf.h
index e2013e8dd887389b573fbc3faddffb119f10c9b5..be958df5278b2997b031c38b89615eb6af51159e 100644
--- a/lib/unigraf/unigraf.h
+++ b/lib/unigraf/unigraf.h
@@ -172,4 +172,11 @@ void unigraf_read_crc(int stream, igt_crc_t *out);
*/
bool unigraf_use_crc(void);
+/**
+ * unigraf_get_connector_by_stream() - Get a connector id from a stream id
+ * @drm_fd: DRM device where the unigraf is attached
+ * @stream_id: Stream to grab the connector from
+ */
+int unigraf_get_connector_by_stream(int drm_fd, int stream_id);
+
#endif // UNIGRAF_H
--
2.50.1
More information about the igt-dev
mailing list