[PATCH i-g-t 1/5] lib/kms: add igt_next_crtc()

Jani Nikula
2026-03-06T13:24:13Z

Add a helper to get the next valid CRTC after a given CRTC, or the first
if NULL CRTC is given.

There are a number of tests that seem difficult to convert to
for_each_crtc(), as they have some other loops, but basically need a
helper for "give me another CRTC". This should fit the bill.

As most tests currently loop pipes, this also gives CRTCs in pipe order.

Open question is whether this should skip or not if there are no CRTCs
left.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
lib/igt_kms.c | 19 +++++++++++++++++++
lib/igt_kms.h | 1 +
2 files changed, 20 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 9ebf77b74d04..240200a98772 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -8021,3 +8021,22 @@ igt_crtc_t *igt_first_crtc_with_single_output(igt_display_t *display, igt_output

return NULL;
}
+
+/*
+ * igt_next_crtc:
+ * @display: pointer to igt_display_t
+ * @crtc: pointer to igt_crtc_t, or NULL for first
+ *
+ * Returns: The next CRTC on the device
+ */
+igt_crtc_t *igt_next_crtc(igt_display_t *display, igt_crtc_t *crtc)
+{
+ igt_crtc_t *next;
+
+ for_each_crtc(display, next) {
+ if (!crtc || next->pipe > crtc->pipe)
+ return next;
+ }
+
+ return NULL;
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index e91c6567757e..23169e87ff2d 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -585,6 +585,7 @@ static inline igt_crtc_t *igt_crtc_for_pipe(igt_display_t *display, enum pipe pi
igt_crtc_t *igt_crtc_for_crtc_id(igt_display_t *display, uint32_t crtc_id);
igt_crtc_t *igt_first_crtc(igt_display_t *display);
igt_crtc_t *igt_first_crtc_with_single_output(igt_display_t *display, igt_output_t **ret_output);
+igt_crtc_t *igt_next_crtc(igt_display_t *display, igt_crtc_t *crtc);

uint32_t igt_crtc_get_vbl_flag(igt_crtc_t *crtc);
unsigned int igt_crtc_get_vblank(igt_crtc_t *crtc, unsigned int flags);
--
2.47.3