[PATCH i-g-t v7 06/48] lib/igt_kms: Add helper to get a pipe from a connector

Louis Chauvet
2026-02-23T12:08:55Z

Currently there is no way to get a pipe from the connector. Add this tiny
helper that will try to get the currently used pipe for a specific
connector.

Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/igt_kms.c | 41 +++++++++++++++++++++++++++++++++++++++++
lib/igt_kms.h | 3 +++
2 files changed, 44 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 514d905fe1fe..1c03542c87d7 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -8266,3 +8266,44 @@ int kms_wait_for_new_connectors(uint32_t **newly_connected,

return newly_connected_count;
}
+
+/**
+ * igt_get_crtc_index_from_connector_id() - Get a pipe from the connector id
+ * @drm_fd: drm file descriptor to which the connector belongs
+ * @connector_id: connector to inspect
+ *
+ * Returns 0 if the connector is not connected to any pipe
+ */
+int igt_get_crtc_index_from_connector_id(int drm_fd, int connector_id)
+{
+ drmModeObjectPropertiesPtr proplist;
+ drmModePropertyPtr crtc_id_prop;
+ drmModePropertyPtr prop;
+ enum pipe crtc_index;
+ uint32_t crtc_id;
+ int i;
+
+ proplist = drmModeObjectGetProperties(drm_fd, connector_id, DRM_MODE_OBJECT_CONNECTOR);
+ crtc_id_prop = NULL;
+
+ for (i = 0; i < proplist->count_props; i++) {
+ prop = drmModeGetProperty(drm_fd, proplist->props[i]);
+
+ if (strcmp(prop->name, "CRTC_ID") == 0) {
+ crtc_id_prop = prop;
+ break;
+ }
+ drmModeFreeProperty(prop);
+ }
+
+ igt_assert(crtc_id_prop);
+ igt_assert((crtc_id_prop->flags & DRM_MODE_PROP_EXTENDED_TYPE) == DRM_MODE_PROP_OBJECT);
+ crtc_id = proplist->prop_values[i];
+ drmModeFreeProperty(crtc_id_prop);
+ drmModeFreeObjectProperties(proplist);
+ if (crtc_id != 0) {
+ crtc_index = kmstest_get_crtc_index_from_id(drm_fd, crtc_id);
+ return crtc_index;
+ }
+ return 0;
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index a0b36efd8ebb..86bdb4d5031c 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -1332,4 +1332,7 @@ int kms_wait_for_new_connectors(uint32_t **newly_connected,
int
get_list_diff(const uint32_t *list_a, int list_a_len, const uint32_t *list_b, int list_b_len,
uint32_t **diff);
+
+int igt_get_crtc_index_from_connector_id(int drm_fd, int connector_id);
+
#endif /* __IGT_KMS_H__ */

--
2.52.0