Skip to contentSkip to conversation

lib/igt_kms: add kmstest_get_crtc_idx

PATCH New Paulo Zanoni 1 participant 5 messages Feb 26, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 lib/igt_kms: add kmstest_get_crtc_idx

Move it from pm_rpm.c to lib/igt_kms and remove the hardcoded version from kms_frontbuffer_tracking. I'm also planning to add other callers.

---
 lib/igt_kms.c                    | 18 ++++++++++++++++++
 lib/igt_kms.h                    |  1 +
 tests/kms_frontbuffer_tracking.c | 10 +++-------
 tests/pm_rpm.c                   | 14 ++------------
 4 files changed, 24 insertions(+), 19 deletions(-)
lib/igt_kms.c +18 -0
index 90c8da7..285c1b6 100644
@@ -875,6 +875,24 @@ void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources)
 	}
 }
 
+/**
+ * kmstest_get_crtc_idx: get the CRTC index based on its ID
+ * @res: the libdrm resources
+ * @crtc_id: the CRTC id
+ *
+ * This is useful since a few places of libdrm deal with CRTC masks.
+ */
+int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id)
+{
+	int i;
+
+	for (i = 0; i < res->count_crtcs; i++)
+		if (res->crtcs[i] == crtc_id)
+			return i;
+
+	igt_assert(false);
+}
+
 /*
  * A small modeset API
  */
lib/igt_kms.h +1 -0
index 3f7add5..2cb7c1f 100644
@@ -150,6 +150,7 @@ bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type,
 			  const char *name, uint32_t *prop_id, uint64_t *value,
 			  drmModePropertyPtr *prop);
 void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources);
+int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id);
 
 /*
  * A small modeset API
tests/kms_frontbuffer_tracking.c +3 -7
index 26e12d0..88bf5a5 100644
@@ -2214,16 +2214,12 @@ static void wait_flip_event(void)
 
 static void set_prim_plane_for_params(struct modeset_params *params)
 {
-	int rc, i, crtc_index = -1;
+	int rc, i;
+	int crtc_idx = kmstest_get_crtc_idx(drm.res, params->crtc_id);
 	uint32_t plane_id = 0;
 
-	for (i = 0; i < drm.res->count_crtcs; i++)
-		if (drm.res->crtcs[i] == params->crtc_id)
-			crtc_index = i;
-	igt_assert(crtc_index >= 0);
-
 	for (i = 0; i < drm.plane_res->count_planes; i++)
-		if ((drm.planes[i]->possible_crtcs & (1 << crtc_index)) &&
+		if ((drm.planes[i]->possible_crtcs & (1 << crtc_idx)) &&
 		    drm.plane_types[i] == DRM_PLANE_TYPE_PRIMARY)
 			plane_id = drm.planes[i]->plane_id;
 	igt_assert(plane_id);
tests/pm_rpm.c +2 -12
index 2aa6c10..eeaf324 100644
@@ -1681,17 +1681,6 @@ static void test_one_plane(bool dpms, uint32_t plane_id,
 	igt_assert(wait_for_suspended());
 }
 
-static int get_crtc_idx(drmModeResPtr res, uint32_t crtc_id)
-{
-	int i;
-
-	for (i = 0; i < res->count_crtcs; i++)
-		if (res->crtcs[i] == crtc_id)
-			return i;
-
-	igt_assert(false);
-}
-
 /* This one also triggered WARNs on our driver at some point in time. */
 static void planes_subtest(bool universal, bool dpms)
 {
@@ -1699,7 +1688,8 @@ static void planes_subtest(bool universal, bool dpms)
 	drmModePlaneResPtr planes;
 
 	igt_require(default_mode_params);
-	crtc_idx = get_crtc_idx(ms_data.res, default_mode_params->crtc_id);
+	crtc_idx = kmstest_get_crtc_idx(ms_data.res,
+					default_mode_params->crtc_id);
 
 	if (universal) {
 		rc = drmSetClientCap(drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES,
Signature · 6 lines
2.7.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/5 kms_frontbuffer_tracking: don't pass the crtc idx to init_mode_params

We already pass the crtc id, so use the id to retrieve the index. We'll change the way we pass the crtc id in the next commits, so we'll have to call a function to calculate the index based on the id at that point. Do the change now in order to avoid big commits later.

---
 tests/kms_frontbuffer_tracking.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tests/kms_frontbuffer_tracking.c +5 -5
index 88bf5a5..d641cc7 100644
@@ -368,14 +368,14 @@ static void print_mode_info(const char *screen, struct modeset_params *params)
 }
 
 static void init_mode_params(struct modeset_params *params, uint32_t crtc_id,
-			     int crtc_index, uint32_t connector_id,
-			     drmModeModeInfoPtr mode)
+			     uint32_t connector_id, drmModeModeInfoPtr mode)
 {
 	uint32_t plane_id = 0;
+	int crtc_idx = kmstest_get_crtc_idx(drm.res, crtc_id);
 	int i;
 
 	for (i = 0; i < drm.plane_res->count_planes && plane_id == 0; i++)
-		if ((drm.planes[i]->possible_crtcs & (1 << crtc_index)) &&
+		if ((drm.planes[i]->possible_crtcs & (1 << crtc_idx)) &&
 		    drm.plane_types[i] == DRM_PLANE_TYPE_OVERLAY)
 			plane_id = drm.planes[i]->plane_id;
 
@@ -465,7 +465,7 @@ static bool init_modeset_cached_params(void)
 	if (!prim_connector_id)
 		return false;
 
-	init_mode_params(&prim_mode_params, drm.res->crtcs[0], 0,
+	init_mode_params(&prim_mode_params, drm.res->crtcs[0],
 			 prim_connector_id, prim_mode);
 	print_mode_info("Primary", &prim_mode_params);
 
@@ -475,7 +475,7 @@ static bool init_modeset_cached_params(void)
 	}
 
 	igt_assert(drm.res->count_crtcs >= 2);
-	init_mode_params(&scnd_mode_params, drm.res->crtcs[1], 1,
+	init_mode_params(&scnd_mode_params, drm.res->crtcs[1],
 			 scnd_connector_id, scnd_mode);
 	print_mode_info("Secondary", &scnd_mode_params);
 
Signature · 6 lines
2.7.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 3/5 kms_frontbuffer_tracking: extract find_connector function

In reply to Paulo Zanoni

We're going to make our search for connnectors a little more complicated, so extract the function since we're going to call it a few more times.

---
 tests/kms_frontbuffer_tracking.c | 70 ++++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 32 deletions(-)
tests/kms_frontbuffer_tracking.c +38 -32
index d641cc7..3b2ca8a 100644
@@ -368,7 +368,8 @@ static void print_mode_info(const char *screen, struct modeset_params *params)
 }
 
 static void init_mode_params(struct modeset_params *params, uint32_t crtc_id,
-			     uint32_t connector_id, drmModeModeInfoPtr mode)
+			     drmModeConnectorPtr connector,
+			     drmModeModeInfoPtr mode)
 {
 	uint32_t plane_id = 0;
 	int crtc_idx = kmstest_get_crtc_idx(drm.res, crtc_id);
@@ -382,7 +383,7 @@ static void init_mode_params(struct modeset_params *params, uint32_t crtc_id,
 	igt_assert(plane_id);
 
 	params->crtc_id = crtc_id;
-	params->connector_id = connector_id;
+	params->connector_id = connector->connector_id;
 	params->mode = mode;
 	params->sprite_id = plane_id;
 
@@ -427,56 +428,61 @@ static bool connector_get_mode(drmModeConnectorPtr c, drmModeModeInfoPtr *mode)
 	return true;
 }
 
-static bool init_modeset_cached_params(void)
+static bool find_connector(bool edp_only, uint32_t forbidden_id,
+			   drmModeConnectorPtr *ret_connector,
+			   drmModeModeInfoPtr *ret_mode)
 {
+	drmModeConnectorPtr c = NULL;
+	drmModeModeInfoPtr mode = NULL;
 	int i;
-	uint32_t prim_connector_id = 0, scnd_connector_id = 0;
-	drmModeModeInfoPtr prim_mode = NULL, scnd_mode = NULL;
-	drmModeModeInfoPtr tmp_mode;
 
-	/* First, try to find an eDP monitor since it's the only possible type
-	 * for PSR.  */
 	for (i = 0; i < drm.res->count_connectors; i++) {
-		if (drm.connectors[i]->connector_type != DRM_MODE_CONNECTOR_eDP)
-			continue;
+		c = drm.connectors[i];
 
-		if (connector_get_mode(drm.connectors[i], &tmp_mode)) {
-			prim_connector_id = drm.res->connectors[i];
-			prim_mode = tmp_mode;
-		}
-	}
-	for (i = 0; i < drm.res->count_connectors; i++) {
-		/* Don't pick again what we just selected on the above loop. */
-		if (drm.res->connectors[i] == prim_connector_id)
+		if (edp_only && c->connector_type != DRM_MODE_CONNECTOR_eDP)
+			continue;
+		if (c->connector_id == forbidden_id)
+			continue;
+		if (!connector_get_mode(c, &mode))
 			continue;
 
-		if (connector_get_mode(drm.connectors[i], &tmp_mode)) {
-			if (!prim_connector_id) {
-				prim_connector_id = drm.res->connectors[i];
-				prim_mode = tmp_mode;
-			} else if (!scnd_connector_id) {
-				scnd_connector_id = drm.res->connectors[i];
-				scnd_mode = tmp_mode;
-				break;
-			}
-		}
+		*ret_connector = c;
+		*ret_mode = mode;
+		return true;
 	}
 
-	if (!prim_connector_id)
+	return false;
+}
+
+static bool init_modeset_cached_params(void)
+{
+	drmModeConnectorPtr prim_connector = NULL, scnd_connector = NULL;
+	drmModeModeInfoPtr prim_mode = NULL, scnd_mode = NULL;
+
+	/* First, try to find an eDP monitor since it's the only possible type
+	 * for PSR.  */
+	find_connector(true, 0, &prim_connector, &prim_mode);
+	if (!prim_connector)
+		find_connector(false, 0, &prim_connector, &prim_mode);
+
+	if (!prim_connector)
 		return false;
 
+	find_connector(false, prim_connector->connector_id, &scnd_connector,
+		       &scnd_mode);
+
 	init_mode_params(&prim_mode_params, drm.res->crtcs[0],
-			 prim_connector_id, prim_mode);
+			 prim_connector, prim_mode);
 	print_mode_info("Primary", &prim_mode_params);
 
-	if (!scnd_connector_id) {
+	if (!scnd_connector) {
 		scnd_mode_params.connector_id = 0;
 		return true;
 	}
 
 	igt_assert(drm.res->count_crtcs >= 2);
 	init_mode_params(&scnd_mode_params, drm.res->crtcs[1],
-			 scnd_connector_id, scnd_mode);
+			 scnd_connector, scnd_mode);
 	print_mode_info("Secondary", &scnd_mode_params);
 
 	return true;
Signature · 6 lines
2.7.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 4/5 kms_frontbuffer_tracking: try harder to find suitable connectors

In reply to Paulo Zanoni

Instead of just giving preference to an eDP primary connector, give preference to one that's eDP and supports pipe A, then try lesser optimal combinations later.

We could try to make our test suite use different sets of connectors when testing FBC and PSR, but that would require some rework, and we would still be helpless when testing the combination of FBC+PSR.

Also notice that we still hardcode pipe A for the primary connector, regardless of whether it supports it. This will be solved in the next commits.

---
 tests/kms_frontbuffer_tracking.c | 69 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 62 insertions(+), 7 deletions(-)
tests/kms_frontbuffer_tracking.c +62 -7
index 3b2ca8a..47a37f4 100644
@@ -152,10 +152,12 @@ struct rect {
 
 #define MAX_CONNECTORS 32
 #define MAX_PLANES 32
+#define MAX_ENCODERS 32
 struct {
 	int fd;
 	drmModeResPtr res;
 	drmModeConnectorPtr connectors[MAX_CONNECTORS];
+	drmModeEncoderPtr encoders[MAX_ENCODERS];
 	drmModePlaneResPtr plane_res;
 	drmModePlanePtr planes[MAX_PLANES];
 	uint64_t plane_types[MAX_PLANES];
@@ -357,6 +359,17 @@ static drmModeConnectorPtr get_connector(uint32_t id)
 	igt_assert(false);
 }
 
+static drmModeEncoderPtr get_encoder(uint32_t id)
+{
+	int i;
+
+	for (i = 0; i < drm.res->count_encoders; i++)
+		if (drm.res->encoders[i] == id)
+			return drm.encoders[i];
+
+	igt_assert(false);
+}
+
 static void print_mode_info(const char *screen, struct modeset_params *params)
 {
 	drmModeConnectorPtr c = get_connector(params->connector_id);
@@ -428,7 +441,18 @@ static bool connector_get_mode(drmModeConnectorPtr c, drmModeModeInfoPtr *mode)
 	return true;
 }
 
-static bool find_connector(bool edp_only, uint32_t forbidden_id,
+static bool connector_supports_pipe_a(drmModeConnectorPtr connector)
+{
+	int i;
+
+	for (i = 0; i < connector->count_encoders; i++)
+		if (get_encoder(connector->encoders[i])->possible_crtcs & 1)
+			return true;
+
+	return false;
+}
+
+static bool find_connector(bool edp_only, bool pipe_a, uint32_t forbidden_id,
 			   drmModeConnectorPtr *ret_connector,
 			   drmModeModeInfoPtr *ret_mode)
 {
@@ -441,6 +465,8 @@ static bool find_connector(bool edp_only, uint32_t forbidden_id,
 
 		if (edp_only && c->connector_type != DRM_MODE_CONNECTOR_eDP)
 			continue;
+		if (pipe_a && !connector_supports_pipe_a(c))
+			continue;
 		if (c->connector_id == forbidden_id)
 			continue;
 		if (!connector_get_mode(c, &mode))
@@ -459,17 +485,27 @@ static bool init_modeset_cached_params(void)
 	drmModeConnectorPtr prim_connector = NULL, scnd_connector = NULL;
 	drmModeModeInfoPtr prim_mode = NULL, scnd_mode = NULL;
 
-	/* First, try to find an eDP monitor since it's the only possible type
-	 * for PSR.  */
-	find_connector(true, 0, &prim_connector, &prim_mode);
+	/*
+	 * We have this problem where PSR is only present on eDP monitors and
+	 * FBC is only present on pipe A for some platforms. So we search first
+	 * for the ideal case of eDP supporting pipe A, and try the less optimal
+	 * configs later, sacrificing  one of the features.
+	 * TODO: refactor the code in a way that allows us to have different
+	 * sets of prim/scnd structs for different features.
+	 */
+	find_connector(true, true, 0, &prim_connector, &prim_mode);
+	if (!prim_connector)
+		find_connector(true, false, 0, &prim_connector, &prim_mode);
 	if (!prim_connector)
-		find_connector(false, 0, &prim_connector, &prim_mode);
+		find_connector(false, true, 0, &prim_connector, &prim_mode);
+	if (!prim_connector)
+		find_connector(false, false, 0, &prim_connector, &prim_mode);
 
 	if (!prim_connector)
 		return false;
 
-	find_connector(false, prim_connector->connector_id, &scnd_connector,
-		       &scnd_mode);
+	find_connector(false, false, prim_connector->connector_id,
+		       &scnd_connector, &scnd_mode);
 
 	init_mode_params(&prim_mode_params, drm.res->crtcs[0],
 			 prim_connector, prim_mode);
@@ -1291,10 +1327,14 @@ static void setup_drm(void)
 
 	drm.res = drmModeGetResources(drm.fd);
 	igt_assert(drm.res->count_connectors <= MAX_CONNECTORS);
+	igt_assert(drm.res->count_encoders <= MAX_ENCODERS);
 
 	for (i = 0; i < drm.res->count_connectors; i++)
 		drm.connectors[i] = drmModeGetConnectorCurrent(drm.fd,
 						drm.res->connectors[i]);
+	for (i = 0; i < drm.res->count_encoders; i++)
+		drm.encoders[i] = drmModeGetEncoder(drm.fd,
+						    drm.res->encoders[i]);
 
 	rc = drmSetClientCap(drm.fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
 	igt_require(rc == 0);
@@ -1322,6 +1362,8 @@ static void teardown_drm(void)
 		drmModeFreePlane(drm.planes[i]);
 	drmModeFreePlaneResources(drm.plane_res);
 
+	for (i = 0; i < drm.res->count_encoders; i++)
+		drmModeFreeEncoder(drm.encoders[i]);
 	for (i = 0; i < drm.res->count_connectors; i++)
 		drmModeFreeConnector(drm.connectors[i]);
 
@@ -1456,10 +1498,23 @@ static bool fbc_supported_on_chipset(void)
 
 static void setup_fbc(void)
 {
+	drmModeConnectorPtr c = get_connector(prim_mode_params.connector_id);
+
 	if (!fbc_supported_on_chipset()) {
 		igt_info("Can't test FBC: not supported on this chipset\n");
 		return;
 	}
+
+	/*
+	 * While some platforms do allow FBC on pipes B/C, this test suite
+	 * is not prepared for that yet.
+	 * TODO: solve this.
+	 */
+	if (!connector_supports_pipe_a(c)) {
+		igt_info("Can't test FBC: primary connector doesn't support "
+			 "pipe A\n");
+		return;
+	}
 	fbc.can_test = true;
 
 	fbc_setup_last_action();
Signature · 6 lines
2.7.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH 5/5 tests: fix CRTC assignment for a few tests

In reply to Paulo Zanoni

All the tests I wrote always assumed that every connector supported CRTC 0. This is not the case for BSW and possibly others, so fix the tests before the CI reports more failures.

---
 lib/igt_kms.c                    | 32 ++++++++++++++++++++++++++++++++
 lib/igt_kms.h                    |  3 +++
 tests/kms_draw_crc.c             | 13 +++++++------
 tests/kms_fbcon_fbt.c            | 12 ++++++------
 tests/kms_frontbuffer_tracking.c | 23 ++++++++++++++++-------
 tests/pm_lpsp.c                  | 35 ++++++++++++++++++-----------------
 tests/pm_rpm.c                   | 24 ++----------------------
 tools/intel_residency.c          | 15 ++++++++-------
 8 files changed, 92 insertions(+), 65 deletions(-)
lib/igt_kms.c +32 -0
index 285c1b6..f771f29 100644
@@ -277,6 +277,38 @@ int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id)
 	return pfci.pipe;
 }
 
+/**
+ * kmstest_find_crtc_for_connector:
+ * @fd: DRM fd
+ * @res: libdrm resources pointer
+ * @connector: libdrm connector pointer
+ * @crtc_blacklist_idx_mask: a mask of CRTC indexes that we can't return
+ *
+ * Returns: the CRTC ID for a CRTC that fits the connector, otherwise it asserts
+ * false and never returns. The blacklist mask can be used in case you have
+ * CRTCs that are already in use by other connectors.
+ */
+uint32_t kmstest_find_crtc_for_connector(int fd, drmModeRes *res,
+					 drmModeConnector *connector,
+					 uint32_t crtc_blacklist_idx_mask)
+{
+	drmModeEncoder *e;
+	uint32_t possible_crtcs;
+	int i, j;
+
+	for (i = 0; i < connector->count_encoders; i++) {
+		e = drmModeGetEncoder(fd, connector->encoders[i]);
+		possible_crtcs = e->possible_crtcs & ~crtc_blacklist_idx_mask;
+		drmModeFreeEncoder(e);
+
+		for (j = 0; possible_crtcs >> j; j++)
+			if (possible_crtcs & (1 << j))
+				return res->crtcs[j];
+	}
+
+	igt_assert(false);
+}
+
 /*
  * Returns: the previous mode, or KD_GRAPHICS if no /dev/tty0 was
  * found and nothing was done.
lib/igt_kms.h +3 -0
index 2cb7c1f..5744ed0 100644
@@ -151,6 +151,9 @@ bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type,
 			  drmModePropertyPtr *prop);
 void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources);
 int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id);
+uint32_t kmstest_find_crtc_for_connector(int fd, drmModeRes *res,
+					 drmModeConnector *connector,
+					 uint32_t crtc_blacklist_idx_mask);
 
 /*
  * A small modeset API
tests/kms_draw_crc.c +7 -6
index 3f80174..9539fe4 100644
@@ -58,25 +58,26 @@ struct modeset_params ms;
 static void find_modeset_params(void)
 {
 	int i;
-	uint32_t connector_id = 0, crtc_id;
+	uint32_t crtc_id;
+	drmModeConnectorPtr connector = NULL;
 	drmModeModeInfoPtr mode = NULL;
 
 	for (i = 0; i < drm_res->count_connectors; i++) {
 		drmModeConnectorPtr c = drm_connectors[i];
 
 		if (c->count_modes) {
-			connector_id = c->connector_id;
+			connector = c;
 			mode = &c->modes[0];
 			break;
 		}
 	}
-	igt_require(connector_id);
+	igt_require(connector);
 
-	crtc_id = drm_res->crtcs[0];
-	igt_assert(crtc_id);
+	crtc_id = kmstest_find_crtc_for_connector(drm_fd, drm_res, connector,
+						  0);
 	igt_assert(mode);
 
-	ms.connector_id = connector_id;
+	ms.connector_id = connector->connector_id;
 	ms.crtc_id = crtc_id;
 	ms.mode = mode;
 
tests/kms_fbcon_fbt.c +6 -6
index 3c93378..586cdf5 100644
@@ -114,7 +114,7 @@ static void set_mode_for_one_screen(struct drm_info *drm, struct igt_fb *fb,
 				    connector_possible_fn connector_possible)
 {
 	int i, rc;
-	uint32_t connector_id = 0, crtc_id;
+	uint32_t crtc_id;
 	drmModeModeInfoPtr mode;
 	uint32_t buffer_id;
 	drmModeConnectorPtr c = NULL;
@@ -124,14 +124,14 @@ static void set_mode_for_one_screen(struct drm_info *drm, struct igt_fb *fb,
 
 		if (c->connection == DRM_MODE_CONNECTED && c->count_modes &&
 		    connector_possible(c)) {
-			connector_id = c->connector_id;
 			mode = &c->modes[0];
 			break;
 		}
 	}
-	igt_require_f(connector_id, "No connector available\n");
+	igt_require_f(i < drm->res->count_connectors,
+		      "No connector available\n");
 
-	crtc_id = drm->res->crtcs[0];
+	crtc_id = kmstest_find_crtc_for_connector(drm->fd, drm->res, c, 0);
 
 	buffer_id = igt_create_fb(drm->fd, mode->hdisplay, mode->vdisplay,
 				  DRM_FORMAT_XRGB8888,
@@ -142,8 +142,8 @@ static void set_mode_for_one_screen(struct drm_info *drm, struct igt_fb *fb,
 		 mode->hdisplay, mode->vdisplay,
 		 kmstest_connector_type_str(c->connector_type));
 
-	rc = drmModeSetCrtc(drm->fd, crtc_id, buffer_id, 0, 0, &connector_id, 1,
-			    mode);
+	rc = drmModeSetCrtc(drm->fd, crtc_id, buffer_id, 0, 0,
+			    &c->connector_id, 1, mode);
 	igt_assert_eq(rc, 0);
 }
 
tests/kms_frontbuffer_tracking.c +16 -7
index 47a37f4..b45b240 100644
@@ -374,10 +374,11 @@ static void print_mode_info(const char *screen, struct modeset_params *params)
 {
 	drmModeConnectorPtr c = get_connector(params->connector_id);
 
-	igt_info("%s screen: %s %s\n",
+	igt_info("%s screen: %s %s, crtc %d\n",
 		 screen,
 		 kmstest_connector_type_str(c->connector_type),
-		 params->mode->name);
+		 params->mode->name,
+		 params->crtc_id);
 }
 
 static void init_mode_params(struct modeset_params *params, uint32_t crtc_id,
@@ -484,6 +485,7 @@ static bool init_modeset_cached_params(void)
 {
 	drmModeConnectorPtr prim_connector = NULL, scnd_connector = NULL;
 	drmModeModeInfoPtr prim_mode = NULL, scnd_mode = NULL;
+	uint32_t prim_crtc_id, scnd_crtc_id;
 
 	/*
 	 * We have this problem where PSR is only present on eDP monitors and
@@ -507,7 +509,9 @@ static bool init_modeset_cached_params(void)
 	find_connector(false, false, prim_connector->connector_id,
 		       &scnd_connector, &scnd_mode);
 
-	init_mode_params(&prim_mode_params, drm.res->crtcs[0],
+	prim_crtc_id = kmstest_find_crtc_for_connector(drm.fd, drm.res,
+						       prim_connector, 0);
+	init_mode_params(&prim_mode_params, prim_crtc_id,
 			 prim_connector, prim_mode);
 	print_mode_info("Primary", &prim_mode_params);
 
@@ -517,7 +521,10 @@ static bool init_modeset_cached_params(void)
 	}
 
 	igt_assert(drm.res->count_crtcs >= 2);
-	init_mode_params(&scnd_mode_params, drm.res->crtcs[1],
+	scnd_crtc_id = kmstest_find_crtc_for_connector(drm.fd, drm.res,
+						      scnd_connector,
+			1 << kmstest_get_crtc_idx(drm.res, prim_crtc_id));
+	init_mode_params(&scnd_mode_params, scnd_crtc_id,
 			 scnd_connector, scnd_mode);
 	print_mode_info("Secondary", &scnd_mode_params);
 
@@ -2577,10 +2584,10 @@ static bool prim_plane_disabled(void)
 {
 	int i, rc;
 	bool disabled, found = false;
+	int crtc_idx = kmstest_get_crtc_idx(drm.res, prim_mode_params.crtc_id);
 
 	for (i = 0; i < drm.plane_res->count_planes; i++) {
-		/* We just pick the first CRTC for the primary plane. */
-		if ((drm.planes[i]->possible_crtcs & 0x1) &&
+		if ((drm.planes[i]->possible_crtcs & (1 << crtc_idx)) &&
 		    drm.plane_types[i] == DRM_PLANE_TYPE_PRIMARY) {
 			found = true;
 			disabled = (drm.planes[i]->crtc_id == 0);
@@ -2688,6 +2695,8 @@ static void scaledprimary_subtest(const struct test_mode *t)
 	struct modeset_params *params = pick_params(t);
 	int i, rc;
 	uint32_t plane_id;
+	int prim_crtc_idx = kmstest_get_crtc_idx(drm.res,
+						 prim_mode_params.crtc_id);
 
 	igt_require_f(intel_gen(intel_get_drm_devid(drm.fd)) >= 9,
 		      "Can't test primary plane scaling before gen 9\n");
@@ -2717,7 +2726,7 @@ static void scaledprimary_subtest(const struct test_mode *t)
 			 pick_color(&new_fb, COLOR_MAGENTA));
 
 	for (i = 0; i < drm.plane_res->count_planes; i++)
-		if ((drm.planes[i]->possible_crtcs & 1) &&
+		if ((drm.planes[i]->possible_crtcs & (1 << prim_crtc_idx)) &&
 		    drm.plane_types[i] == DRM_PLANE_TYPE_PRIMARY)
 			plane_id = drm.planes[i]->plane_id;
 
tests/pm_lpsp.c +18 -17
index 4cedeff..bfe5828 100644
@@ -65,7 +65,8 @@ static void edp_subtest(int drm_fd, drmModeResPtr drm_res,
 			bool use_panel_fitter)
 {
 	int i, rc;
-	uint32_t connector_id = 0, crtc_id = 0, buffer_id = 0;
+	uint32_t crtc_id = 0, buffer_id = 0;
+	drmModeConnectorPtr connector = NULL;
 	drmModeModeInfoPtr mode = NULL;
 	drmModeModeInfo std_1024_mode = {
 		.clock = 65000,
@@ -96,12 +97,12 @@ static void edp_subtest(int drm_fd, drmModeResPtr drm_res,
 			continue;
 
 		if (!use_panel_fitter && c->count_modes) {
-			connector_id = c->connector_id;
+			connector = c;
 			mode = &c->modes[0];
 			break;
 		}
 		if (use_panel_fitter) {
-			connector_id = c->connector_id;
+			connector = c;
 
 			/* This is one of the modes Xorg creates for panels, so
 			 * it should work just fine. Notice that Gens that
@@ -116,18 +117,18 @@ static void edp_subtest(int drm_fd, drmModeResPtr drm_res,
 			break;
 		}
 	}
-	igt_require(connector_id);
+	igt_require(connector);
 
-	crtc_id = drm_res->crtcs[0];
+	crtc_id = kmstest_find_crtc_for_connector(drm_fd, drm_res, connector,
+						  0);
 	buffer_id = create_fb(drm_fd, mode->hdisplay, mode->vdisplay);
 
-	igt_assert(crtc_id);
 	igt_assert(buffer_id);
-	igt_assert(connector_id);
+	igt_assert(connector);
 	igt_assert(mode);
 
-	rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0, &connector_id, 1,
-			    mode);
+	rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0,
+			    &connector->connector_id, 1, mode);
 	igt_assert_eq(rc, 0);
 
 	if (use_panel_fitter) {
@@ -144,7 +145,8 @@ static void non_edp_subtest(int drm_fd, drmModeResPtr drm_res,
 			    drmModeConnectorPtr *drm_connectors)
 {
 	int i, rc;
-	uint32_t connector_id = 0, crtc_id = 0, buffer_id = 0;
+	uint32_t crtc_id = 0, buffer_id = 0;
+	drmModeConnectorPtr connector = NULL;
 	drmModeModeInfoPtr mode = NULL;
 
 	kmstest_unset_all_crtcs(drm_fd, drm_res);
@@ -158,23 +160,22 @@ static void non_edp_subtest(int drm_fd, drmModeResPtr drm_res,
 			continue;
 
 		if (c->count_modes) {
-			connector_id = c->connector_id;
+			connector = c;
 			mode = &c->modes[0];
 			break;
 		}
 	}
-	igt_require(connector_id);
+	igt_require(connector);
 
-	crtc_id = drm_res->crtcs[0];
+	crtc_id = kmstest_find_crtc_for_connector(drm_fd, drm_res, connector,
+						  0);
 	buffer_id = create_fb(drm_fd, mode->hdisplay, mode->vdisplay);
 
-	igt_assert(crtc_id);
 	igt_assert(buffer_id);
-	igt_assert(connector_id);
 	igt_assert(mode);
 
-	rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0, &connector_id, 1,
-			    mode);
+	rc = drmModeSetCrtc(drm_fd, crtc_id, buffer_id, 0, 0,
+			    &connector->connector_id, 1, mode);
 	igt_assert_eq(rc, 0);
 
 	igt_assert(!lpsp_is_enabled(drm_fd));
tests/pm_rpm.c +2 -22
index eeaf324..0b9c6b7 100644
@@ -226,27 +226,6 @@ static void disable_or_dpms_all_screens(struct mode_set_data *data, bool dpms)
 	igt_assert(wait_for_suspended()); \
 } while (0)
 
-static uint32_t find_crtc_for_connector(drmModeResPtr res,
-					drmModeConnectorPtr connector)
-{
-	drmModeEncoderPtr e;
-	uint32_t crtc_id = 0;
-	int i, j;
-
-	for (i = 0; i < connector->count_encoders && !crtc_id; i++) {
-		e = drmModeGetEncoder(drm_fd, connector->encoders[i]);
-
-		for (j = 0; (e->possible_crtcs >> j) && !crtc_id; j++)
-			if (e->possible_crtcs & (1 << j))
-				crtc_id = res->crtcs[j];
-
-		drmModeFreeEncoder(e);
-	}
-
-	igt_assert(crtc_id);
-	return crtc_id;
-}
-
 static bool init_modeset_params_for_type(struct mode_set_data *data,
 					 struct modeset_params *params,
 					 enum screen_type type)
@@ -280,7 +259,8 @@ static bool init_modeset_params_for_type(struct mode_set_data *data,
 			      DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
 			      &params->fb);
 
-	params->crtc_id = find_crtc_for_connector(data->res, connector);
+	params->crtc_id = kmstest_find_crtc_for_connector(drm_fd, data->res,
+							  connector, 0);
 	params->connector_id = connector->connector_id;
 	params->mode = mode;
 
tools/intel_residency.c +8 -7
index 74074c5..116215a 100644
@@ -249,20 +249,21 @@ static void draw_rect(struct igt_fb *fb, enum igt_draw_method method,
 static void setup_modeset(void)
 {
 	int i;
+	drmModeConnectorPtr connector;
 
 	for (i = 0; i < drm.res->count_connectors; i++) {
-		drmModeConnectorPtr c = drm.connectors[i];
+		connector = drm.connectors[i];
 
-		if (c->connection == DRM_MODE_CONNECTED &&
-		    c->count_modes > 0) {
-			modeset.connector_id = c->connector_id;
-			modeset.mode = &c->modes[0];
+		if (connector->connection == DRM_MODE_CONNECTED &&
+		    connector->count_modes > 0)
 			break;
-		}
 	}
 	igt_assert(i < drm.res->count_connectors);
 
-	modeset.crtc_id = drm.res->crtcs[0];
+	modeset.connector_id = connector->connector_id;
+	modeset.mode = &connector->modes[0];
+	modeset.crtc_id = kmstest_find_crtc_for_connector(drm.fd, drm.res,
+							  connector, 0);
 
 	for (i = 0; i < 2; i++) {
 		igt_create_fb(drm.fd, modeset.mode->hdisplay,
Signature · 6 lines
2.7.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx