[PATCH i-g-t v7 43/48] lib/igt_kms: Add helper to get a CRTC from an output

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

Grabbing a valid CRTC from a specific output is useful when testing
the output.

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

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 0c61ac6e2788..9f8e09008e19 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -7937,3 +7937,23 @@ int igt_get_crtc_index_from_connector_id(int drm_fd, int connector_id)
}
return 0;
}
+
+/*
+ * igt_get_crtc_for_output:
+ * @display: display to fetch the CRTC
+ * @output: output to use
+ *
+ * Get a valid CRTC for a specific output. The return value is the first valid CRTC for a
+ * specific output.
+ */
+igt_crtc_t *igt_get_crtc_for_output(igt_display_t *display,
+ igt_output_t *output)
+{
+ igt_crtc_t *crtc;
+
+ for_each_crtc(display, crtc)
+ if (igt_crtc_connector_valid(crtc, output))
+ return crtc;
+
+ return NULL;
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 4b5f6fcc929b..716d203a7c2e 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -1329,5 +1329,7 @@ get_list_diff(const uint32_t *list_a, int list_a_len, const uint32_t *list_b, in
uint32_t **diff);

int igt_get_crtc_index_from_connector_id(int drm_fd, int connector_id);
+igt_crtc_t *igt_get_crtc_for_output(igt_display_t *display,
+ igt_output_t *output);

#endif /* __IGT_KMS_H__ */

--
2.52.0