Skip to contentSkip to conversation

igt_kms refactoring and universal plane support

PATCH In review Matt Roper 2 participants 11 messages Jun 30, 2014 – Jul 4, 2014 Library code

lore
Share & tools
lore

Matt Roper

author
#0 lore raw

cover igt_kms refactoring and universal plane support

This patch set refactors the igt_kms library a bit to allow display state changes to be commited via different API's (with different "commit styles") and adds a new "universal" commit style that makes use of the universal plane API.

Some of the patches here were previously posted here:

        http://lists.freedesktop.org/archives/intel-gfx/2014-May/046276.html

Some of the key changes or additions from the previous patch series:
* igt_pipe no longer tracks the need to issue various ioctls upon commit. Instead we simply use the *_changed flags to indicate what has changed and make our own decisions about what ioctls to call at commit time. This will be important because some programming decisions (e.g., whether to wait for a vblank after updating a sprite) will differ between various commit styles (i.e., legacy vs universal plane vs atomic).
* The igt_display_use_universal_commits() function from the previous series is gone; it was too easy to make mistakes when writing tests that switch back and forth between API's and was somewhat difficult to follow the logic of those tests. Instead, we add a new commit function, igt_display_commit2() that takes an explicit "commit style" parameter indicating which type of API's should be used to perform the operation. Tests that are trying to exercise a specific API, or the interleaving of multiple API's should use this commit function. Other tests that simply want to get the hardware into a specific state, but don't care how to get there may continue to use igt_display_commit(), which will pick a default commit style ("legacy" style today, possibly configurable via an environment variable in the future?)
* igt_kms's internal plane list maintains the primary, overlays, cursor order as it has in the past, even if the universal plane API's return the planes in a different order.
* A few minor fixes to kms_cursor_crc

The expectation is that although we only have 'legacy' and 'universal' commit styles today, we'll also be adding 'atomic' in the near future and most of the infrastructure changes here should work well for that as well.

One remaining shortcoming of the igt_kms library is that crtc enable/disable is implicitly built into legacy commit style and doesn't have any direct API for tests to use yet. I.e.,

        igt_plane_set_fb(primary, NULL);
        igt_display_commit2(display, COMMIT_LEGACY);

will disable the CRTC (due to there being no distinction between primary planes and crtc's in the legacy KMS API), whereas

        igt_plane_set_fb(primary, NULL);
        igt_display_commit2(display, COMMIT_UNIVERSAL);

would leave the CRTC enabled (assuming it was already active) and just disable the primary plane.

A future patch set will need to address this by making CRTC enable/disable an explicit API distinct from plane fb updates.

Matt Roper (9):
lib/kms: Drop igt_pipe->need_set_{crtc,cursor} lib/kms: Track need for vblank wait locally lib/kms: Add igt_display_commit2()
lib/kms: Add igt_display_try_commit2() lib/kms: Add universal plane support (v2) lib/kms: Drop primary plane windowing test from
igt_plane_set_position()
tests/kms_universal_plane: Universal plane testing (v6) tests/kms_cursor_crc: Combine data_t and test_data_t tests/kms_cursor_crc: Call drmModeMoveCursor() directly

 lib/igt_kms.c               | 500 ++++++++++++++++++++++++++------------
 lib/igt_kms.h               |  13 +-
 tests/.gitignore            |   1 +
 tests/Makefile.sources      |   1 +
 tests/kms_cursor_crc.c      | 235 +++++++++---------
 tests/kms_universal_plane.c | 577 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1051 insertions(+), 276 deletions(-)
 create mode 100644 tests/kms_universal_plane.c
Signature · 1 line
1.8.5.1
author
#1 lore raw

PATCH 1/9 lib/kms: Drop igt_pipe->need_set_{crtc, cursor}

The "need" flags on igt_pipe simply mirror the fb_changed field of the primary/cursor planes. Drop them and just use fb_changed instead.

---
 lib/igt_kms.c | 18 ++++++------------
 lib/igt_kms.h |  2 --
 2 files changed, 6 insertions(+), 14 deletions(-)
lib/igt_kms.c +6 -12
index c0f4f6c..1e7b901 100644
@@ -837,11 +837,14 @@ static int igt_output_commit(igt_output_t *output)
 {
 	igt_display_t *display = output->display;
 	igt_pipe_t *pipe;
+	igt_plane_t *primary;
+	igt_plane_t *cursor;
 	int i;
 
 	pipe = igt_output_get_driving_pipe(output);
-	if (pipe->need_set_crtc) {
-		igt_plane_t *primary = &pipe->planes[0];
+	primary = igt_pipe_get_plane(pipe, IGT_PLANE_PRIMARY);
+	cursor = igt_pipe_get_plane(pipe, IGT_PLANE_CURSOR);
+	if (primary->fb_changed) {
 		drmModeModeInfo *mode;
 		uint32_t fb_id, crtc_id;
 		int ret;
@@ -887,16 +890,13 @@ static int igt_output_commit(igt_output_t *output)
 
 		igt_assert(ret == 0);
 
-		pipe->need_set_crtc = false;
 		primary->fb_changed = false;
 	}
 
-	if (pipe->need_set_cursor) {
-		igt_plane_t *cursor;
+	if (cursor->fb_changed) {
 		uint32_t gem_handle, crtc_id;
 		int ret;
 
-		cursor = igt_pipe_get_plane(pipe, IGT_PLANE_CURSOR);
 		crtc_id = output->config.crtc->crtc_id;
 		gem_handle = igt_plane_get_fb_gem_handle(cursor);
 
@@ -924,7 +924,6 @@ static int igt_output_commit(igt_output_t *output)
 
 		igt_assert(ret == 0);
 
-		pipe->need_set_cursor = false;
 		cursor->fb_changed = false;
 	}
 
@@ -1009,11 +1008,6 @@ void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb)
 
 	plane->fb = fb;
 
-	if (plane->is_primary)
-		pipe->need_set_crtc = true;
-	else if (plane->is_cursor)
-		pipe->need_set_cursor = true;
-
 	plane->fb_changed = true;
 }
 
lib/igt_kms.h +0 -2
index 7d015b4..88b695a 100644
@@ -120,8 +120,6 @@ typedef struct {
 struct igt_pipe {
 	igt_display_t *display;
 	enum pipe pipe;
-	unsigned int need_set_crtc        : 1;
-	unsigned int need_set_cursor      : 1;
 	unsigned int need_wait_for_vblank : 1;
 #define IGT_MAX_PLANES	4
 	int n_planes;
Signature · 1 line
1.8.5.1
author
#2 lore raw

PATCH 2/9 lib/kms: Track need for vblank wait locally

In reply to Matt Roper

The need to wait for a vblank after programming is due to the way we actually program the hardware. Move need_wait_for_vblank out of the pipe and into a local variable in preparation for future programming styles (e.g., atomic pageflip) that will need different logic.

---
 lib/igt_kms.c | 15 ++++++++++-----
 lib/igt_kms.h |  1 -
 2 files changed, 10 insertions(+), 6 deletions(-)
lib/igt_kms.c +10 -5
index 1e7b901..3f561e9 100644
@@ -759,13 +759,11 @@ static int igt_cursor_commit(igt_plane_t *plane, igt_output_t *output)
 static int igt_drm_plane_commit(igt_plane_t *plane, igt_output_t *output)
 {
 	igt_display_t *display = output->display;
-	igt_pipe_t *pipe;
 	uint32_t fb_id, crtc_id;
 	int ret;
 
 	fb_id = igt_plane_get_fb_id(plane);
 	crtc_id = output->config.crtc->crtc_id;
-	pipe = igt_output_get_driving_pipe(output);
 
 	if (plane->fb_changed && fb_id == 0) {
 		LOG(display,
@@ -814,7 +812,6 @@ static int igt_drm_plane_commit(igt_plane_t *plane, igt_output_t *output)
 
 		plane->fb_changed = false;
 		plane->position_changed = false;
-		pipe->need_wait_for_vblank = true;
 	}
 
 	return 0;
@@ -840,6 +837,7 @@ static int igt_output_commit(igt_output_t *output)
 	igt_plane_t *primary;
 	igt_plane_t *cursor;
 	int i;
+	bool need_wait_for_vblank = false;
 
 	pipe = igt_output_get_driving_pipe(output);
 	primary = igt_pipe_get_plane(pipe, IGT_PLANE_PRIMARY);
@@ -925,17 +923,24 @@ static int igt_output_commit(igt_output_t *output)
 		igt_assert(ret == 0);
 
 		cursor->fb_changed = false;
+		need_wait_for_vblank = true;
 	}
 
 	for (i = 0; i < pipe->n_planes; i++) {
 		igt_plane_t *plane = &pipe->planes[i];
 
+		if (plane->fb_changed || plane->position_changed)
+			need_wait_for_vblank = true;
+
 		igt_plane_commit(plane, output);
 	}
 
-	if (pipe->need_wait_for_vblank) {
+	/*
+	 * If the crtc is enabled, wait until the next vblank before returning
+	 * if we made changes to any of the planes.
+	 */
+	if (need_wait_for_vblank && igt_plane_get_fb_id(primary) != 0) {
 		igt_wait_for_vblank(display->drm_fd, pipe->pipe);
-		pipe->need_wait_for_vblank = false;
 	}
 
 	return 0;
lib/igt_kms.h +0 -1
index 88b695a..a9a4236 100644
@@ -120,7 +120,6 @@ typedef struct {
 struct igt_pipe {
 	igt_display_t *display;
 	enum pipe pipe;
-	unsigned int need_wait_for_vblank : 1;
 #define IGT_MAX_PLANES	4
 	int n_planes;
 	igt_plane_t planes[IGT_MAX_PLANES];
Signature · 1 line
1.8.5.1
author
#3 lore raw

PATCH 3/9 lib/kms: Add igt_display_commit2()

In reply to Matt Roper

Add a new commit interface, igt_display_commit2(), that allows tests to specify which programming API should be used to perform hardware updates. COMMIT_LEGACY is the only option for now, but universal and atomic interfaces will be added as additional options in the future.

igt_display_commit() remains unchanged for existing tests that wish to place the hardware in a specific state, but that don't care which API is used to achieve that state. The legacy API will be used by default for now, but in the future we may decide to make the default API configurable via an environment variable.

---
 lib/igt_kms.c | 32 +++++++++++++++++++++++++++++++-
 lib/igt_kms.h |  7 +++++++
 2 files changed, 38 insertions(+), 1 deletion(-)
lib/igt_kms.c +31 -1
index 3f561e9..064b741 100644
@@ -946,7 +946,21 @@ static int igt_output_commit(igt_output_t *output)
 	return 0;
 }
 
-int igt_display_commit(igt_display_t *display)
+/**
+ * igt_display_commit2:
+ * @display: DRM device handle
+ * @s: Commit style
+ *
+ * Commits framebuffer and positioning changes to all planes of each display
+ * pipe, using a specific API to perform the programming.  This function should
+ * be used to exercise a specific driver programming API; igt_display_commit
+ * should be used instead if the API used is unimportant to the test being run.
+ *
+ * Returns: 0 upon success.  This function will never return upon failure
+ * since igt_fail() at lower levels will longjmp out of it.
+ */
+int igt_display_commit2(igt_display_t *display,
+		       enum igt_commit_style s)
 {
 	int i;
 
@@ -971,6 +985,22 @@ int igt_display_commit(igt_display_t *display)
 	return 0;
 }
 
+/**
+ * igt_display_commit:
+ * @display: DRM device handle
+ * @s: Commit style
+ *
+ * Commits framebuffer and positioning changes to all planes of each display
+ * pipe.
+ *
+ * Returns: 0 upon success.  This function will never return upon failure
+ * since igt_fail() at lower levels will longjmp out of it.
+ */
+int igt_display_commit(igt_display_t *display)
+{
+	return igt_display_commit2(display, COMMIT_LEGACY);
+}
+
 const char *igt_output_name(igt_output_t *output)
 {
 	return output->name;
lib/igt_kms.h +7 -0
index a9a4236..62dc73c 100644
@@ -65,6 +65,12 @@ enum port {
 };
 #define port_name(p) ((p) + 'A')
 
+enum igt_commit_style {
+	COMMIT_LEGACY = 0,
+	COMMIT_UNIVERSAL,
+	/* We'll add atomic here eventually. */
+};
+
 #include "igt_fb.h"
 
 struct kmstest_connector_config {
@@ -150,6 +156,7 @@ void igt_set_vt_graphics_mode(void);
 
 void igt_display_init(igt_display_t *display, int drm_fd);
 void igt_display_fini(igt_display_t *display);
+int  igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
 int  igt_display_commit(igt_display_t *display);
 int  igt_display_get_n_pipes(igt_display_t *display);
 
Signature · 1 line
1.8.5.1
author
#4 lore raw

PATCH 4/9 lib/kms: Add igt_display_try_commit2()

In reply to Matt Roper

Add a new public API that will attempt a display commit, but will return an error code upon failure rather than failing the IGT test. This is intended to allow igt tests to verify that the expected error codes are returned to userspace when invalid requests are issued.

Note that with non-atomic programming, a single commit operation has several potential failure points internally; the first non-zero error code encountered will be returned immediately and no further programming will be performed by the commit. It is the caller's responsibility to return to a sane state.

---
 lib/igt_kms.c | 124 ++++++++++++++++++++++++++++++++++++++++++----------------
 lib/igt_kms.h |   1 +
 2 files changed, 92 insertions(+), 33 deletions(-)
lib/igt_kms.c +91 -33
index 064b741..9e1fca7 100644
@@ -730,7 +730,15 @@ static uint32_t igt_plane_get_fb_gem_handle(igt_plane_t *plane)
 		return 0;
 }
 
-static int igt_cursor_commit(igt_plane_t *plane, igt_output_t *output)
+#define CHECK_RETURN(r, fail) {	\
+	if (r && !fail)		\
+		return r;	\
+	igt_assert(r == 0);	\
+}
+
+static int igt_cursor_commit(igt_plane_t *plane,
+			     igt_output_t *output,
+			     bool fail_on_error)
 {
 	igt_display_t *display = output->display;
 	uint32_t crtc_id = output->config.crtc->crtc_id;
@@ -747,8 +755,7 @@ static int igt_cursor_commit(igt_plane_t *plane, igt_output_t *output)
 		    x, y);
 
 		ret = drmModeMoveCursor(display->drm_fd, crtc_id, x, y);
-
-		igt_assert(ret == 0);
+		CHECK_RETURN(ret, fail_on_error);
 
 		plane->position_changed = false;
 	}
@@ -756,7 +763,15 @@ static int igt_cursor_commit(igt_plane_t *plane, igt_output_t *output)
 	return 0;
 }
 
-static int igt_drm_plane_commit(igt_plane_t *plane, igt_output_t *output)
+/*
+ * Commit position and fb changes to a DRM plane via the SetPlane ioctl; if the
+ * DRM call to program the plane fails, we'll either fail immediately (for
+ * tests that expect the commit to succeed) or return the failure code (for
+ * tests that expect a specific error code).
+ */
+static int igt_drm_plane_commit(igt_plane_t *plane,
+				igt_output_t *output,
+				bool fail_on_error)
 {
 	igt_display_t *display = output->display;
 	uint32_t fb_id, crtc_id;
@@ -783,8 +798,7 @@ static int igt_drm_plane_commit(igt_plane_t *plane, igt_output_t *output)
 				      IGT_FIXED(0,0), /* src_y */
 				      IGT_FIXED(0,0), /* src_w */
 				      IGT_FIXED(0,0) /* src_h */);
-
-		igt_assert(ret == 0);
+		CHECK_RETURN(ret, fail_on_error);
 
 		plane->fb_changed = false;
 	} else if (plane->fb_changed || plane->position_changed) {
@@ -807,8 +821,7 @@ static int igt_drm_plane_commit(igt_plane_t *plane, igt_output_t *output)
 				      IGT_FIXED(0,0), /* src_y */
 				      IGT_FIXED(plane->fb->width,0), /* src_w */
 				      IGT_FIXED(plane->fb->height,0) /* src_h */);
-
-		igt_assert(ret == 0);
+		CHECK_RETURN(ret, fail_on_error);
 
 		plane->fb_changed = false;
 		plane->position_changed = false;
@@ -817,20 +830,22 @@ static int igt_drm_plane_commit(igt_plane_t *plane, igt_output_t *output)
 	return 0;
 }
 
-static int igt_plane_commit(igt_plane_t *plane, igt_output_t *output)
+static int igt_plane_commit(igt_plane_t *plane,
+			    igt_output_t *output,
+			    bool fail_on_error)
 {
 	if (plane->is_cursor) {
-		igt_cursor_commit(plane, output);
+		igt_cursor_commit(plane, output, fail_on_error);
 	} else if (plane->is_primary) {
 		/* state updated by SetCrtc */
 	} else {
-		igt_drm_plane_commit(plane, output);
+		igt_drm_plane_commit(plane, output, fail_on_error);
 	}
 
 	return 0;
 }
 
-static int igt_output_commit(igt_output_t *output)
+static int igt_output_commit(igt_output_t *output, bool fail_on_error)
 {
 	igt_display_t *display = output->display;
 	igt_pipe_t *pipe;
@@ -885,8 +900,7 @@ static int igt_output_commit(igt_output_t *output)
 					     0,    /* n_connectors */
 					     NULL  /* mode */);
 		}
-
-		igt_assert(ret == 0);
+		CHECK_RETURN(ret, fail_on_error);
 
 		primary->fb_changed = false;
 	}
@@ -919,8 +933,7 @@ static int igt_output_commit(igt_output_t *output)
 			ret = drmModeSetCursor(display->drm_fd, crtc_id,
 					       0, 0, 0);
 		}
-
-		igt_assert(ret == 0);
+		CHECK_RETURN(ret, fail_on_error);
 
 		cursor->fb_changed = false;
 		need_wait_for_vblank = true;
@@ -932,7 +945,7 @@ static int igt_output_commit(igt_output_t *output)
 		if (plane->fb_changed || plane->position_changed)
 			need_wait_for_vblank = true;
 
-		igt_plane_commit(plane, output);
+		igt_plane_commit(plane, output, fail_on_error);
 	}
 
 	/*
@@ -946,23 +959,20 @@ static int igt_output_commit(igt_output_t *output)
 	return 0;
 }
 
-/**
- * igt_display_commit2:
- * @display: DRM device handle
- * @s: Commit style
- *
- * Commits framebuffer and positioning changes to all planes of each display
- * pipe, using a specific API to perform the programming.  This function should
- * be used to exercise a specific driver programming API; igt_display_commit
- * should be used instead if the API used is unimportant to the test being run.
+/*
+ * Commit all plane changes across all outputs of the display.
  *
- * Returns: 0 upon success.  This function will never return upon failure
- * since igt_fail() at lower levels will longjmp out of it.
+ * If @fail_on_error is true, any failure to commit plane state will lead
+ * to subtest failure in the specific function where the failure occurs.
+ * Otherwise, the first error code encountered will be returned and no
+ * further programming will take place, which may result in some changes
+ * taking effect and others not taking effect.
  */
-int igt_display_commit2(igt_display_t *display,
-		       enum igt_commit_style s)
+static int do_display_commit(igt_display_t *display,
+			     enum igt_commit_style s,
+			     bool fail_on_error)
 {
-	int i;
+	int i, ret;
 
 	LOG_INDENT(display, "commit");
 
@@ -974,7 +984,8 @@ int igt_display_commit2(igt_display_t *display,
 		if (!output->valid)
 			continue;
 
-		igt_output_commit(output);
+		ret = igt_output_commit(output, fail_on_error);
+		CHECK_RETURN(ret, fail_on_error);
 	}
 
 	LOG_UNINDENT(display);
@@ -986,10 +997,57 @@ int igt_display_commit2(igt_display_t *display,
 }
 
 /**
- * igt_display_commit:
+ * igt_display_commit2:
+ * @display: DRM device handle
+ * @s: Commit style
+ *
+ * Commits framebuffer and positioning changes to all planes of each display
+ * pipe, using a specific API to perform the programming.  This function should
+ * be used to exercise a specific driver programming API; igt_display_commit
+ * should be used instead if the API used is unimportant to the test being run.
+ *
+ * This function should only be used to commit changes that are expected to
+ * succeed, since any failure during the commit process will cause the IGT
+ * subtest to fail.  To commit changes that are expected to fail, use
+ * @igt_try_display_commit2 instead.
+ *
+ * Returns: 0 upon success.  This function will never return upon failure
+ * since igt_fail() at lower levels will longjmp out of it.
+ */
+int igt_display_commit2(igt_display_t *display,
+		       enum igt_commit_style s)
+{
+	return do_display_commit(display, s, true);
+}
+
+/**
+ * igt_display_try_commit2:
  * @display: DRM device handle
  * @s: Commit style
  *
+ * Attempts to commit framebuffer and positioning changes to all planes of each
+ * display pipe.  This function should be used to commit changes that are
+ * expected to fail, so that the error code can be checked for correctness.
+ * For changes that are expected to succeed, use @igt_display_commit instead.
+ *
+ * Note that in non-atomic commit styles, no display programming will be
+ * performed after the first failure is encountered, so only some of the
+ * operations requested by a test may have been completed.  Tests that catch
+ * errors returned by this function should take care to restore the display to
+ * a sane state after a failure is detected.
+ *
+ * Returns: 0 upon success, otherwise the error code of the first error
+ * encountered.
+ */
+int igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s)
+{
+       return do_display_commit(display, s, false);
+}
+
+/**
+ * igt_display_commit:
+ * @display: DRM device handle
+ *
  * Commits framebuffer and positioning changes to all planes of each display
  * pipe.
  *
lib/igt_kms.h +1 -0
index 62dc73c..e238523 100644
@@ -158,6 +158,7 @@ void igt_display_init(igt_display_t *display, int drm_fd);
 void igt_display_fini(igt_display_t *display);
 int  igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
 int  igt_display_commit(igt_display_t *display);
+int  igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
 int  igt_display_get_n_pipes(igt_display_t *display);
 
 const char *igt_output_name(igt_output_t *output);
Signature · 1 line
1.8.5.1
author
#5 lore raw

PATCH 5/9 lib/kms: Add universal plane support (v2)

In reply to Matt Roper

Add support for universal planes. This involves revamping the existing plane handling a bit to allow primary & cursor planes to come from the DRM plane list, rather than always being manually added.

v2: Don't drop fixed ordering of internal plane list. Primary will
always be index 0, cursor will always be last in internal plane list.

---
 lib/igt_kms.c | 389 ++++++++++++++++++++++++++++++++++++++--------------------
 lib/igt_kms.h |   2 +
 2 files changed, 257 insertions(+), 134 deletions(-)
lib/igt_kms.c +255 -134
index 9e1fca7..313d4ae 100644
@@ -481,6 +481,39 @@ static void igt_output_refresh(igt_output_t *output)
 	display->pipes_in_use |= 1 << output->config.pipe;
 }
 
+/*
+ * Walk a plane's property list to determine its type.  If we don't
+ * find a type property, then the kernel doesn't support universal
+ * planes and we know the plane is an overlay/sprite.
+ */
+static int get_drm_plane_type(igt_display_t *display, uint32_t plane_id)
+{
+	drmModeObjectPropertiesPtr proplist;
+	drmModePropertyPtr prop = NULL;
+	int type = DRM_PLANE_TYPE_OVERLAY;
+	int i;
+
+	proplist = drmModeObjectGetProperties(display->drm_fd,
+					      plane_id,
+					      DRM_MODE_OBJECT_PLANE);
+	for (i = 0; i < proplist->count_props; i++) {
+		drmModeFreeProperty(prop);
+		prop = drmModeGetProperty(display->drm_fd, proplist->props[i]);
+		if (!prop)
+			continue;
+
+		if (strcmp(prop->name, "type") == 0) {
+			type = proplist->prop_values[i];
+			break;
+		}
+	}
+
+	drmModeFreeProperty(prop);
+	drmModeFreeObjectProperties(proplist);
+
+	return type;
+}
+
 void igt_display_init(igt_display_t *display, int drm_fd)
 {
 	drmModeRes *resources;
@@ -502,24 +535,19 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 	 */
 	display->n_pipes = resources->count_crtcs;
 
+	drmSetClientCap(drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
 	plane_resources = drmModeGetPlaneResources(display->drm_fd);
 	igt_assert(plane_resources);
 
 	for (i = 0; i < display->n_pipes; i++) {
 		igt_pipe_t *pipe = &display->pipes[i];
 		igt_plane_t *plane;
-		int p, j;
+		int p = IGT_PLANE_2;
+		int j, type;
 
 		pipe->display = display;
 		pipe->pipe = i;
 
-		/* primary plane */
-		p = IGT_PLANE_PRIMARY;
-		plane = &pipe->planes[p];
-		plane->pipe = pipe;
-		plane->index = p;
-		plane->is_primary = true;
-
 		/* add the planes that can be used with that pipe */
 		for (j = 0; j < plane_resources->count_planes; j++) {
 			drmModePlane *drm_plane;
@@ -533,21 +561,75 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 				continue;
 			}
 
-			p++;
-			plane = &pipe->planes[p];
+			type = get_drm_plane_type(display,
+						  plane_resources->planes[j]);
+			switch (type) {
+			case DRM_PLANE_TYPE_PRIMARY:
+				plane = &pipe->planes[IGT_PLANE_PRIMARY];
+				plane->is_primary = 1;
+				plane->index = IGT_PLANE_PRIMARY;
+				display->has_universal_planes = 1;
+				break;
+			case DRM_PLANE_TYPE_CURSOR:
+				/*
+				 * Cursor should be the highest index in our
+				 * internal list, but we don't know what that
+				 * is yet.  Just stick it in the last slot
+				 * for now and we'll move it later, if
+				 * necessary.
+				 */
+				plane = &pipe->planes[IGT_PLANE_CURSOR];
+				plane->is_cursor = 1;
+				plane->index = IGT_PLANE_CURSOR;
+				display->has_universal_planes = 1;
+				break;
+			default:
+				plane = &pipe->planes[p];
+				plane->index = p++;
+				break;
+			}
+
 			plane->pipe = pipe;
-			plane->index = p;
 			plane->drm_plane = drm_plane;
 		}
 
-		/* cursor plane */
-		p++;
-		plane = &pipe->planes[p];
-		plane->pipe = pipe;
-		plane->index = p;
-		plane->is_cursor = true;
+		if (display->has_universal_planes) {
+			/*
+			 * If we have universal planes, we should have both
+			 * primary and cursor planes setup now.
+			 */
+			igt_assert(pipe->planes[IGT_PLANE_PRIMARY].drm_plane &&
+				   pipe->planes[IGT_PLANE_CURSOR].drm_plane);
+
+			/*
+			 * Cursor was put in the last slot.  If we have 0 or
+			 * only 1 sprite, that's the wrong slot and we need to
+			 * move it down.
+			 */
+			if (p != IGT_PLANE_CURSOR) {
+				pipe->planes[p] = pipe->planes[IGT_PLANE_CURSOR];
+				pipe->planes[p].index = p;
+				memset(&pipe->planes[IGT_PLANE_CURSOR], 0,
+				       sizeof *plane);
+			}
+		} else {
+			/*
+			 * No universal plane support.  Add drm_plane-less
+			 * primary and cursor planes.
+			 */
+			plane = &pipe->planes[IGT_PLANE_PRIMARY];
+			plane->pipe = pipe;
+			plane->index = IGT_PLANE_PRIMARY;
+			plane->is_primary = true;
+
+			plane = &pipe->planes[p];
+			plane->pipe = pipe;
+			plane->index = p;
+			plane->is_cursor = true;
+		}
 
-		pipe->n_planes = ++p;
+		/* planes = 1 primary, (p-1) sprites, 1 cursor */
+		pipe->n_planes = p + 1;
 
 		/* make sure we don't overflow the plane array */
 		igt_assert(pipe->n_planes <= IGT_MAX_PLANES);
@@ -702,7 +784,7 @@ static igt_plane_t *igt_pipe_get_plane(igt_pipe_t *pipe, enum igt_plane plane)
 {
 	int idx;
 
-	/* Cursor plane is always the upper plane */
+	/* Cursor plane is always the highest index */
 	if (plane == IGT_PLANE_CURSOR)
 		idx = pipe->n_planes - 1;
 	else {
@@ -736,33 +818,6 @@ static uint32_t igt_plane_get_fb_gem_handle(igt_plane_t *plane)
 	igt_assert(r == 0);	\
 }
 
-static int igt_cursor_commit(igt_plane_t *plane,
-			     igt_output_t *output,
-			     bool fail_on_error)
-{
-	igt_display_t *display = output->display;
-	uint32_t crtc_id = output->config.crtc->crtc_id;
-	int ret;
-
-	if (plane->position_changed) {
-		int x = plane->crtc_x;
-		int y = plane->crtc_y;
-
-		LOG(display,
-		    "%s: MoveCursor pipe %c, (%d, %d)\n",
-		    igt_output_name(output),
-		    pipe_name(output->config.pipe),
-		    x, y);
-
-		ret = drmModeMoveCursor(display->drm_fd, crtc_id, x, y);
-		CHECK_RETURN(ret, fail_on_error);
-
-		plane->position_changed = false;
-	}
-
-	return 0;
-}
-
 /*
  * Commit position and fb changes to a DRM plane via the SetPlane ioctl; if the
  * DRM call to program the plane fails, we'll either fail immediately (for
@@ -777,6 +832,8 @@ static int igt_drm_plane_commit(igt_plane_t *plane,
 	uint32_t fb_id, crtc_id;
 	int ret;
 
+	igt_assert(plane->drm_plane);
+
 	fb_id = igt_plane_get_fb_id(plane);
 	crtc_id = output->config.crtc->crtc_id;
 
@@ -798,9 +855,8 @@ static int igt_drm_plane_commit(igt_plane_t *plane,
 				      IGT_FIXED(0,0), /* src_y */
 				      IGT_FIXED(0,0), /* src_w */
 				      IGT_FIXED(0,0) /* src_h */);
-		CHECK_RETURN(ret, fail_on_error);
 
-		plane->fb_changed = false;
+		CHECK_RETURN(ret, fail_on_error);
 	} else if (plane->fb_changed || plane->position_changed) {
 		LOG(display,
 		    "%s: SetPlane %c.%d, fb %u, position (%d, %d)\n",
@@ -821,96 +877,31 @@ static int igt_drm_plane_commit(igt_plane_t *plane,
 				      IGT_FIXED(0,0), /* src_y */
 				      IGT_FIXED(plane->fb->width,0), /* src_w */
 				      IGT_FIXED(plane->fb->height,0) /* src_h */);
-		CHECK_RETURN(ret, fail_on_error);
-
-		plane->fb_changed = false;
-		plane->position_changed = false;
-	}
 
-	return 0;
-}
-
-static int igt_plane_commit(igt_plane_t *plane,
-			    igt_output_t *output,
-			    bool fail_on_error)
-{
-	if (plane->is_cursor) {
-		igt_cursor_commit(plane, output, fail_on_error);
-	} else if (plane->is_primary) {
-		/* state updated by SetCrtc */
-	} else {
-		igt_drm_plane_commit(plane, output, fail_on_error);
+		CHECK_RETURN(ret, fail_on_error);
 	}
 
+	plane->fb_changed = false;
+	plane->position_changed = false;
 	return 0;
 }
 
-static int igt_output_commit(igt_output_t *output, bool fail_on_error)
+/*
+ * Commit position and fb changes to a cursor via legacy ioctl's.  If commit
+ * fails, we'll either fail immediately (for tests that expect the commit to
+ * succeed) or return the failure code (for tests that expect a specific error
+ * code).
+ */
+static int igt_cursor_commit_legacy(igt_plane_t *cursor,
+				    igt_output_t *output,
+				    bool fail_on_error)
 {
 	igt_display_t *display = output->display;
-	igt_pipe_t *pipe;
-	igt_plane_t *primary;
-	igt_plane_t *cursor;
-	int i;
-	bool need_wait_for_vblank = false;
-
-	pipe = igt_output_get_driving_pipe(output);
-	primary = igt_pipe_get_plane(pipe, IGT_PLANE_PRIMARY);
-	cursor = igt_pipe_get_plane(pipe, IGT_PLANE_CURSOR);
-	if (primary->fb_changed) {
-		drmModeModeInfo *mode;
-		uint32_t fb_id, crtc_id;
-		int ret;
-
-		crtc_id = output->config.crtc->crtc_id;
-		fb_id = igt_plane_get_fb_id(primary);
-		if (fb_id)
-			mode = igt_output_get_mode(output);
-		else
-			mode = NULL;
-
-		if (fb_id) {
-			LOG(display,
-			    "%s: SetCrtc pipe %c, fb %u, panning (%d, %d), "
-			    "mode %dx%d\n",
-			    igt_output_name(output),
-			    pipe_name(output->config.pipe),
-			    fb_id,
-			    0, 0,
-			    mode->hdisplay, mode->vdisplay);
-
-			ret = drmModeSetCrtc(display->drm_fd,
-					     crtc_id,
-					     fb_id,
-					     0, 0, /* x, y */
-					     &output->id,
-					     1,
-					     mode);
-		} else {
-			LOG(display,
-			    "%s: SetCrtc pipe %c, disabling\n",
-			    igt_output_name(output),
-			    pipe_name(output->config.pipe));
-
-			ret = drmModeSetCrtc(display->drm_fd,
-					     crtc_id,
-					     fb_id,
-					     0, 0, /* x, y */
-					     NULL, /* connectors */
-					     0,    /* n_connectors */
-					     NULL  /* mode */);
-		}
-		CHECK_RETURN(ret, fail_on_error);
-
-		primary->fb_changed = false;
-	}
+	uint32_t crtc_id = output->config.crtc->crtc_id;
+	int ret;
 
 	if (cursor->fb_changed) {
-		uint32_t gem_handle, crtc_id;
-		int ret;
-
-		crtc_id = output->config.crtc->crtc_id;
-		gem_handle = igt_plane_get_fb_gem_handle(cursor);
+		uint32_t gem_handle = igt_plane_get_fb_gem_handle(cursor);
 
 		if (gem_handle) {
 			LOG(display,
@@ -933,26 +924,154 @@ static int igt_output_commit(igt_output_t *output, bool fail_on_error)
 			ret = drmModeSetCursor(display->drm_fd, crtc_id,
 					       0, 0, 0);
 		}
+
 		CHECK_RETURN(ret, fail_on_error);
 
 		cursor->fb_changed = false;
-		need_wait_for_vblank = true;
 	}
 
+	if (cursor->position_changed) {
+		int x = cursor->crtc_x;
+		int y = cursor->crtc_y;
+
+		LOG(display,
+		    "%s: MoveCursor pipe %c, (%d, %d)\n",
+		    igt_output_name(output),
+		    pipe_name(output->config.pipe),
+		    x, y);
+
+		ret = drmModeMoveCursor(display->drm_fd, crtc_id, x, y);
+		CHECK_RETURN(ret, fail_on_error);
+
+		cursor->position_changed = false;
+	}
+
+	return 0;
+}
+
+/*
+ * Commit position and fb changes to a primary plane via the legacy interface
+ * (setmode).
+ */
+static int igt_primary_plane_commit_legacy(igt_plane_t *primary,
+					   igt_output_t *output,
+					   bool fail_on_error)
+{
+	struct igt_display *display = primary->pipe->display;
+	drmModeModeInfo *mode;
+	uint32_t fb_id, crtc_id;
+	int ret;
+
+	/* Primary planes can't be windowed when using a legacy commit */
+	igt_assert((primary->crtc_x == 0 && primary->crtc_y == 0));
+
+	if (!primary->fb_changed && !primary->position_changed)
+		return 0;
+
+	crtc_id = output->config.crtc->crtc_id;
+	fb_id = igt_plane_get_fb_id(primary);
+	if (fb_id)
+		mode = igt_output_get_mode(output);
+	else
+		mode = NULL;
+
+	if (fb_id) {
+		LOG(display,
+		    "%s: SetCrtc pipe %c, fb %u, panning (%d, %d), "
+		    "mode %dx%d\n",
+		    igt_output_name(output),
+		    pipe_name(output->config.pipe),
+		    fb_id,
+		    0, 0,
+		    mode->hdisplay, mode->vdisplay);
+
+		ret = drmModeSetCrtc(display->drm_fd,
+				     crtc_id,
+				     fb_id,
+				     0, 0, /* x, y */
+				     &output->id,
+				     1,
+				     mode);
+	} else {
+		LOG(display,
+		    "%s: SetCrtc pipe %c, disabling\n",
+		    igt_output_name(output),
+		    pipe_name(output->config.pipe));
+
+		ret = drmModeSetCrtc(display->drm_fd,
+				     crtc_id,
+				     fb_id,
+				     0, 0, /* x, y */
+				     NULL, /* connectors */
+				     0,    /* n_connectors */
+				     NULL  /* mode */);
+	}
+
+	CHECK_RETURN(ret, fail_on_error);
+
+	primary->pipe->enabled = (fb_id != 0);
+	primary->fb_changed = false;
+
+	return 0;
+}
+
+
+/*
+ * Commit position and fb changes to a plane.  The value of @s will determine
+ * which API is used to do the programming.
+ */
+static int igt_plane_commit(igt_plane_t *plane,
+			    igt_output_t *output,
+			    enum igt_commit_style s,
+			    bool fail_on_error)
+{
+	if (plane->is_cursor && s == COMMIT_LEGACY) {
+		return igt_cursor_commit_legacy(plane, output, fail_on_error);
+	} else if (plane->is_primary && s == COMMIT_LEGACY) {
+		return igt_primary_plane_commit_legacy(plane, output,
+						       fail_on_error);
+	} else {
+		return igt_drm_plane_commit(plane, output, fail_on_error);
+	}
+}
+
+/*
+ * Commit all plane changes to an output.  Note that if @s is COMMIT_LEGACY,
+ * enabling/disabling the primary plane will also enable/disable the CRTC.
+ *
+ * If @fail_on_error is true, any failure to commit plane state will lead
+ * to subtest failure in the specific function where the failure occurs.
+ * Otherwise, the first error code encountered will be returned and no
+ * further programming will take place, which may result in some changes
+ * taking effect and others not taking effect.
+ */
+static int igt_output_commit(igt_output_t *output,
+			     enum igt_commit_style s,
+			     bool fail_on_error)
+{
+	igt_display_t *display = output->display;
+	igt_pipe_t *pipe;
+	int i;
+	int ret;
+	bool need_wait_for_vblank = false;
+
+	pipe = igt_output_get_driving_pipe(output);
+
 	for (i = 0; i < pipe->n_planes; i++) {
 		igt_plane_t *plane = &pipe->planes[i];
 
 		if (plane->fb_changed || plane->position_changed)
 			need_wait_for_vblank = true;
 
-		igt_plane_commit(plane, output, fail_on_error);
+		ret = igt_plane_commit(plane, output, s, fail_on_error);
+		CHECK_RETURN(ret, fail_on_error);
 	}
 
 	/*
 	 * If the crtc is enabled, wait until the next vblank before returning
 	 * if we made changes to any of the planes.
 	 */
-	if (need_wait_for_vblank && igt_plane_get_fb_id(primary) != 0) {
+	if (need_wait_for_vblank && pipe->enabled) {
 		igt_wait_for_vblank(display->drm_fd, pipe->pipe);
 	}
 
@@ -984,7 +1103,7 @@ static int do_display_commit(igt_display_t *display,
 		if (!output->valid)
 			continue;
 
-		ret = igt_output_commit(output, fail_on_error);
+		ret = igt_output_commit(output, s, fail_on_error);
 		CHECK_RETURN(ret, fail_on_error);
 	}
 
@@ -1017,7 +1136,9 @@ static int do_display_commit(igt_display_t *display,
 int igt_display_commit2(igt_display_t *display,
 		       enum igt_commit_style s)
 {
-	return do_display_commit(display, s, true);
+	do_display_commit(display, s, true);
+
+	return 0;
 }
 
 /**
@@ -1041,7 +1162,7 @@ int igt_display_commit2(igt_display_t *display,
  */
 int igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s)
 {
-       return do_display_commit(display, s, false);
+	return do_display_commit(display, s, false);
 }
 
 /**
lib/igt_kms.h +2 -0
index e238523..95ba112 100644
@@ -126,6 +126,7 @@ typedef struct {
 struct igt_pipe {
 	igt_display_t *display;
 	enum pipe pipe;
+	bool enabled;
 #define IGT_MAX_PLANES	4
 	int n_planes;
 	igt_plane_t planes[IGT_MAX_PLANES];
@@ -149,6 +150,7 @@ struct igt_display {
 	unsigned long pipes_in_use;
 	igt_output_t *outputs;
 	igt_pipe_t pipes[I915_MAX_PIPES];
+	bool has_universal_planes;
 };
 
 /* set vt into graphics mode, required to prevent fbcon from interfering */
Signature · 1 line
1.8.5.1
author
#6 lore raw

PATCH 6/9 lib/kms: Drop primary plane windowing test from igt_plane_set_position()

In reply to Matt Roper

None of our hardware can support this today, but we'd like to be able to write tests that check that the kernel returns the proper error code when userspace tries it anyway.

---
 lib/igt_kms.c | 6 ------
 1 file changed, 6 deletions(-)
lib/igt_kms.c +0 -6
index 313d4ae..2442c4b 100644
@@ -1230,12 +1230,6 @@ void igt_plane_set_position(igt_plane_t *plane, int x, int y)
 	igt_pipe_t *pipe = plane->pipe;
 	igt_display_t *display = pipe->display;
 
-	/*
-	 * XXX: Some platforms don't need the primary plane to cover the
-	 * whole pipe. Of course this test becomes wrong when we support that.
-	 */
-	igt_assert(!plane->is_primary || (x == 0 && y == 0));
-
 	LOG(display, "%c.%d: plane_set_position(%d,%d)\n",
 	    pipe_name(pipe->pipe), plane->index, x, y);
 
Signature · 1 line
1.8.5.1
author
#7 lore raw

PATCH 7/9 tests/kms_universal_plane: Universal plane testing (v6)

In reply to Matt Roper

Add a simple test to exercise universal plane support.

v6:
- Update to new universal plane interface (commit parameter rather than state-changing function). It should now be a lot more explicit which steps are being taken with legacy API's vs universal API's now.
v5:
- Check that we don't have more than one primary or cursor. This will catch accidental calls to drm_plane_init() in the kernel where drm_universal_plane_init() was intended (these don't cause a compile warning due to type compatibility between enum and bool).
v4:
- Test disabling the primary plane explicitly when it has previously been implicitly disabled due to clipping.
- Skip test if igt_pipe_crc_new() fails
v3:
- For testing while crtc is off, switch between several different primary plane fb's before reenabling the crtc. This will help catch pin/unpin mistakes.
v2:
- Test that pageflips error out gracefully when the primary plane is disabled before the ioctl, or between ioctl and pageflip execution.
- Test that nothing blows up if we try to disable the primary plane immediately after a pageflip (presumably before the pageflip actually completes).
- Test that we can setup primary + sprite planes with the CRTC off and then have them show up properly when we enable the CRTC (drmModeSetCrtc with fb = -1).
- Test that we can modeset properly after having disabled the primary plane
- Test that proper error codes are returned for invalid plane programming attempts.

---
 tests/.gitignore            |   1 +
 tests/Makefile.sources      |   1 +
 tests/kms_universal_plane.c | 577 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 579 insertions(+)
 create mode 100644 tests/kms_universal_plane.c
tests/.gitignore +1 -0
index 1df2078..da9af6b 100644
@@ -128,6 +128,7 @@ kms_plane
 kms_render
 kms_setmode
 kms_sink_crc_basic
+kms_universal_plane
 multi-tests.txt
 pm_lpsp
 pm_psr
tests/Makefile.sources +1 -0
index 17c0ab9..1ebbac5 100644
@@ -72,6 +72,7 @@ TESTS_progs_M = \
 	kms_psr_sink_crc \
 	kms_render \
 	kms_setmode \
+	kms_universal_plane \
 	pm_lpsp \
 	pm_rpm \
 	pm_rps \
tests/kms_universal_plane.c new file +577 -0

577 lines not on this page · raw message

Signature · 6 lines
1.8.5.1

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

PATCH 8/9 tests/kms_cursor_crc: Combine data_t and test_data_t

In reply to Matt Roper

If a subtest fails, cleanup_crtc() never gets called and then the test_data_t structure for the test is lost, including the CRC file descriptor that we never got a chance to release; this causes all subsequent tests to fail with -EBUSY at igt_pipe_crc_new().

The split between permanent data_t and temporary test_data_t doesn't seem to serve a purpose, so just combine the fields from both into data_t. This will prevent us from losing the CRC filedescriptor so that we can properly close and reopen it after a failed test.

---
 tests/kms_cursor_crc.c | 229 +++++++++++++++++++++++--------------------------
 1 file changed, 108 insertions(+), 121 deletions(-)
tests/kms_cursor_crc.c +108 -121
index 1b8da26..d21fc99 100644
@@ -44,10 +44,6 @@ typedef struct {
 	igt_display_t display;
 	struct igt_fb primary_fb;
 	struct igt_fb fb;
-} data_t;
-
-typedef struct {
-	data_t *data;
 	igt_output_t *output;
 	enum pipe pipe;
 	igt_crc_t ref_crc;
@@ -56,7 +52,7 @@ typedef struct {
 	int curw, curh; /* cursor size */
 	int cursor_max_size;
 	igt_pipe_crc_t *pipe_crc;
-} test_data_t;
+} data_t;
 
 static void draw_cursor(cairo_t *cr, int x, int y, int w)
 {
@@ -72,11 +68,10 @@ static void draw_cursor(cairo_t *cr, int x, int y, int w)
 	igt_paint_color_alpha(cr, x + w, y + w, w, w, 0.5, 0.5, 0.5, 1.0);
 }
 
-static void cursor_enable(test_data_t *test_data)
+static void cursor_enable(data_t *data)
 {
-	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
-	igt_output_t *output = test_data->output;
+	igt_output_t *output = data->output;
 	igt_plane_t *cursor;
 
 	cursor = igt_output_get_plane(output, IGT_PLANE_CURSOR);
@@ -84,11 +79,10 @@ static void cursor_enable(test_data_t *test_data)
 	igt_display_commit(display);
 }
 
-static void cursor_disable(test_data_t *test_data)
+static void cursor_disable(data_t *data)
 {
-	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
-	igt_output_t *output = test_data->output;
+	igt_output_t *output = data->output;
 	igt_plane_t *cursor;
 
 	cursor = igt_output_get_plane(output, IGT_PLANE_CURSOR);
@@ -97,11 +91,10 @@ static void cursor_disable(test_data_t *test_data)
 }
 
 
-static void do_single_test(test_data_t *test_data, int x, int y)
+static void do_single_test(data_t *data, int x, int y)
 {
-	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
-	igt_pipe_crc_t *pipe_crc = test_data->pipe_crc;
+	igt_pipe_crc_t *pipe_crc = data->pipe_crc;
 	igt_crc_t crc, ref_crc;
 	igt_plane_t *cursor;
 	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
@@ -109,93 +102,93 @@ static void do_single_test(test_data_t *test_data, int x, int y)
 	igt_info("."); fflush(stdout);
 
 	/* Hardware test */
-	igt_paint_test_pattern(cr, test_data->screenw, test_data->screenh);
-	cursor_enable(test_data);
-	cursor = igt_output_get_plane(test_data->output, IGT_PLANE_CURSOR);
+	igt_paint_test_pattern(cr, data->screenw, data->screenh);
+	cursor_enable(data);
+	cursor = igt_output_get_plane(data->output, IGT_PLANE_CURSOR);
 	igt_plane_set_position(cursor, x, y);
 	igt_display_commit(display);
-	igt_wait_for_vblank(data->drm_fd, test_data->pipe);
+	igt_wait_for_vblank(data->drm_fd, data->pipe);
 	igt_pipe_crc_collect_crc(pipe_crc, &crc);
-	cursor_disable(test_data);
+	cursor_disable(data);
 
 	/* Now render the same in software and collect crc */
-	draw_cursor(cr, x, y, test_data->curw);
+	draw_cursor(cr, x, y, data->curw);
 	igt_display_commit(display);
-	igt_wait_for_vblank(data->drm_fd, test_data->pipe);
+	igt_wait_for_vblank(data->drm_fd, data->pipe);
 	igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
 	/* Clear screen afterwards */
-	igt_paint_color(cr, 0, 0, test_data->screenw, test_data->screenh,
-			    0.0, 0.0, 0.0);
+	igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
+			0.0, 0.0, 0.0);
 
 	igt_assert(igt_crc_equal(&crc, &ref_crc));
 }
 
-static void do_test(test_data_t *test_data,
+static void do_test(data_t *data,
 		    int left, int right, int top, int bottom)
 {
-	do_single_test(test_data, left, top);
-	do_single_test(test_data, right, top);
-	do_single_test(test_data, right, bottom);
-	do_single_test(test_data, left, bottom);
+	do_single_test(data, left, top);
+	do_single_test(data, right, top);
+	do_single_test(data, right, bottom);
+	do_single_test(data, left, bottom);
 }
 
-static void test_crc_onscreen(test_data_t *test_data)
+static void test_crc_onscreen(data_t *data)
 {
-	int left = test_data->left;
-	int right = test_data->right;
-	int top = test_data->top;
-	int bottom = test_data->bottom;
-	int cursor_w = test_data->curw;
-	int cursor_h = test_data->curh;
+	int left = data->left;
+	int right = data->right;
+	int top = data->top;
+	int bottom = data->bottom;
+	int cursor_w = data->curw;
+	int cursor_h = data->curh;
 
 	/* fully inside  */
-	do_test(test_data, left, right, top, bottom);
+	do_test(data, left, right, top, bottom);
 
 	/* 2 pixels inside */
-	do_test(test_data, left - (cursor_w-2), right + (cursor_w-2), top               , bottom               );
-	do_test(test_data, left               , right               , top - (cursor_h-2), bottom + (cursor_h-2));
-	do_test(test_data, left - (cursor_w-2), right + (cursor_w-2), top - (cursor_h-2), bottom + (cursor_h-2));
+	do_test(data, left - (cursor_w-2), right + (cursor_w-2), top               , bottom               );
+	do_test(data, left               , right               , top - (cursor_h-2), bottom + (cursor_h-2));
+	do_test(data, left - (cursor_w-2), right + (cursor_w-2), top - (cursor_h-2), bottom + (cursor_h-2));
 
 	/* 1 pixel inside */
-	do_test(test_data, left - (cursor_w-1), right + (cursor_w-1), top               , bottom               );
-	do_test(test_data, left               , right               , top - (cursor_h-1), bottom + (cursor_h-1));
-	do_test(test_data, left - (cursor_w-1), right + (cursor_w-1), top - (cursor_h-1), bottom + (cursor_h-1));
+	do_test(data, left - (cursor_w-1), right + (cursor_w-1), top               , bottom               );
+	do_test(data, left               , right               , top - (cursor_h-1), bottom + (cursor_h-1));
+	do_test(data, left - (cursor_w-1), right + (cursor_w-1), top - (cursor_h-1), bottom + (cursor_h-1));
 }
 
-static void test_crc_offscreen(test_data_t *test_data)
+static void test_crc_offscreen(data_t *data)
 {
-	int left = test_data->left;
-	int right = test_data->right;
-	int top = test_data->top;
-	int bottom = test_data->bottom;
-	int cursor_w = test_data->curw;
-	int cursor_h = test_data->curh;
+	int left = data->left;
+	int right = data->right;
+	int top = data->top;
+	int bottom = data->bottom;
+	int cursor_w = data->curw;
+	int cursor_h = data->curh;
 
 	/* fully outside */
-	do_test(test_data, left - (cursor_w), right + (cursor_w), top             , bottom             );
-	do_test(test_data, left             , right             , top - (cursor_h), bottom + (cursor_h));
-	do_test(test_data, left - (cursor_w), right + (cursor_w), top - (cursor_h), bottom + (cursor_h));
+	do_test(data, left - (cursor_w), right + (cursor_w), top             , bottom             );
+	do_test(data, left             , right             , top - (cursor_h), bottom + (cursor_h));
+	do_test(data, left - (cursor_w), right + (cursor_w), top - (cursor_h), bottom + (cursor_h));
 
 	/* fully outside by 1 extra pixels */
-	do_test(test_data, left - (cursor_w+1), right + (cursor_w+1), top               , bottom               );
-	do_test(test_data, left               , right               , top - (cursor_h+1), bottom + (cursor_h+1));
-	do_test(test_data, left - (cursor_w+1), right + (cursor_w+1), top - (cursor_h+1), bottom + (cursor_h+1));
+	do_test(data, left - (cursor_w+1), right + (cursor_w+1), top               , bottom               );
+	do_test(data, left               , right               , top - (cursor_h+1), bottom + (cursor_h+1));
+	do_test(data, left - (cursor_w+1), right + (cursor_w+1), top - (cursor_h+1), bottom + (cursor_h+1));
 
 	/* fully outside by 2 extra pixels */
-	do_test(test_data, left - (cursor_w+2), right + (cursor_w+2), top               , bottom               );
-	do_test(test_data, left               , right               , top - (cursor_h+2), bottom + (cursor_h+2));
-	do_test(test_data, left - (cursor_w+2), right + (cursor_w+2), top - (cursor_h+2), bottom + (cursor_h+2));
+	do_test(data, left - (cursor_w+2), right + (cursor_w+2), top               , bottom               );
+	do_test(data, left               , right               , top - (cursor_h+2), bottom + (cursor_h+2));
+	do_test(data, left - (cursor_w+2), right + (cursor_w+2), top - (cursor_h+2), bottom + (cursor_h+2));
 
 	/* fully outside by a lot of extra pixels */
-	do_test(test_data, left - (cursor_w+512), right + (cursor_w+512), top                 , bottom                 );
-	do_test(test_data, left                 , right                 , top - (cursor_h+512), bottom + (cursor_h+512));
-	do_test(test_data, left - (cursor_w+512), right + (cursor_w+512), top - (cursor_h+512), bottom + (cursor_h+512));
+	do_test(data, left - (cursor_w+512), right + (cursor_w+512), top                 , bottom                 );
+	do_test(data, left                 , right                 , top - (cursor_h+512), bottom + (cursor_h+512));
+	do_test(data, left - (cursor_w+512), right + (cursor_w+512), top - (cursor_h+512), bottom + (cursor_h+512));
 
 	/* go nuts */
-	do_test(test_data, INT_MIN, INT_MAX, INT_MIN, INT_MAX);
+	do_test(data, INT_MIN, INT_MAX, INT_MIN, INT_MAX);
 }
 
-static void test_crc_sliding(test_data_t *test_data)
+static void test_crc_sliding(data_t *data)
 {
 	int i;
 
@@ -203,34 +196,33 @@ static void test_crc_sliding(test_data_t *test_data)
 	 * no alignment issues. Horizontal, vertical and diagonal test.
 	 */
 	for (i = 0; i < 16; i++) {
-		do_single_test(test_data, i, 0);
-		do_single_test(test_data, 0, i);
-		do_single_test(test_data, i, i);
+		do_single_test(data, i, 0);
+		do_single_test(data, 0, i);
+		do_single_test(data, i, i);
 	}
 }
 
-static void test_crc_random(test_data_t *test_data)
+static void test_crc_random(data_t *data)
 {
 	int i;
 
 	/* Random cursor placement */
 	for (i = 0; i < 50; i++) {
-		int x = rand() % (test_data->screenw + test_data->curw * 2) - test_data->curw;
-		int y = rand() % (test_data->screenh + test_data->curh * 2) - test_data->curh;
-		do_single_test(test_data, x, y);
+		int x = rand() % (data->screenw + data->curw * 2) - data->curw;
+		int y = rand() % (data->screenh + data->curh * 2) - data->curh;
+		do_single_test(data, x, y);
 	}
 }
 
-static bool prepare_crtc(test_data_t *test_data, igt_output_t *output,
+static bool prepare_crtc(data_t *data, igt_output_t *output,
 			 int cursor_w, int cursor_h)
 {
 	drmModeModeInfo *mode;
-	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
 	igt_plane_t *primary;
 
 	/* select the pipe we want to use */
-	igt_output_set_pipe(output, test_data->pipe);
+	igt_output_set_pipe(output, data->pipe);
 	igt_display_commit(display);
 
 	if (!output->valid) {
@@ -242,10 +234,10 @@ static bool prepare_crtc(test_data_t *test_data, igt_output_t *output,
 	/* create and set the primary plane fb */
 	mode = igt_output_get_mode(output);
 	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
-				DRM_FORMAT_XRGB8888,
-				false, /* tiled */
-				0.0, 0.0, 0.0,
-				&data->primary_fb);
+			    DRM_FORMAT_XRGB8888,
+			    false, /* tiled */
+			    0.0, 0.0, 0.0,
+			    &data->primary_fb);
 
 	primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
 	igt_plane_set_fb(primary, &data->primary_fb);
@@ -253,46 +245,45 @@ static bool prepare_crtc(test_data_t *test_data, igt_output_t *output,
 	igt_display_commit(display);
 
 	/* create the pipe_crc object for this pipe */
-	if (test_data->pipe_crc)
-		igt_pipe_crc_free(test_data->pipe_crc);
+	if (data->pipe_crc)
+		igt_pipe_crc_free(data->pipe_crc);
 
-	test_data->pipe_crc = igt_pipe_crc_new(test_data->pipe,
-					       INTEL_PIPE_CRC_SOURCE_AUTO);
-	if (!test_data->pipe_crc) {
+	data->pipe_crc = igt_pipe_crc_new(data->pipe,
+					  INTEL_PIPE_CRC_SOURCE_AUTO);
+	if (!data->pipe_crc) {
 		igt_info("auto crc not supported on this connector with pipe %i\n",
-			 test_data->pipe);
+			 data->pipe);
 		return false;
 	}
 
 	/* x/y position where the cursor is still fully visible */
-	test_data->left = 0;
-	test_data->right = mode->hdisplay - cursor_w;
-	test_data->top = 0;
-	test_data->bottom = mode->vdisplay - cursor_h;
-	test_data->screenw = mode->hdisplay;
-	test_data->screenh = mode->vdisplay;
-	test_data->curw = cursor_w;
-	test_data->curh = cursor_h;
-	test_data->cursor_max_size = cursor_w;
+	data->left = 0;
+	data->right = mode->hdisplay - cursor_w;
+	data->top = 0;
+	data->bottom = mode->vdisplay - cursor_h;
+	data->screenw = mode->hdisplay;
+	data->screenh = mode->vdisplay;
+	data->curw = cursor_w;
+	data->curh = cursor_h;
+	data->cursor_max_size = cursor_w;
 
 	/* make sure cursor is disabled */
-	cursor_disable(test_data);
-	igt_wait_for_vblank(data->drm_fd, test_data->pipe);
+	cursor_disable(data);
+	igt_wait_for_vblank(data->drm_fd, data->pipe);
 
 	/* get reference crc w/o cursor */
-	igt_pipe_crc_collect_crc(test_data->pipe_crc, &test_data->ref_crc);
+	igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
 
 	return true;
 }
 
-static void cleanup_crtc(test_data_t *test_data, igt_output_t *output)
+static void cleanup_crtc(data_t *data, igt_output_t *output)
 {
-	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
 	igt_plane_t *primary;
 
-	igt_pipe_crc_free(test_data->pipe_crc);
-	test_data->pipe_crc = NULL;
+	igt_pipe_crc_free(data->pipe_crc);
+	data->pipe_crc = NULL;
 
 	igt_remove_fb(data->drm_fd, &data->primary_fb);
 
@@ -303,38 +294,35 @@ static void cleanup_crtc(test_data_t *test_data, igt_output_t *output)
 	igt_display_commit(display);
 }
 
-static void run_test(data_t *data, void (*testfunc)(test_data_t *), int cursor_w, int cursor_h)
+static void run_test(data_t *data, void (*testfunc)(data_t *), int cursor_w, int cursor_h)
 {
 	igt_display_t *display = &data->display;
 	igt_output_t *output;
 	enum pipe p;
-	test_data_t test_data = {
-		.data = data,
-	};
 	int valid_tests = 0;
 
 	for_each_connected_output(display, output) {
-		test_data.output = output;
+		data->output = output;
 		for (p = 0; p < igt_display_get_n_pipes(display); p++) {
-			test_data.pipe = p;
+			data->pipe = p;
 
-			if (!prepare_crtc(&test_data, output, cursor_w, cursor_h))
+			if (!prepare_crtc(data, output, cursor_w, cursor_h))
 				continue;
 
 			valid_tests++;
 
 			igt_info("Beginning %s on pipe %c, connector %s\n",
-				 igt_subtest_name(), pipe_name(test_data.pipe),
+				 igt_subtest_name(), pipe_name(data->pipe),
 				 igt_output_name(output));
 
-			testfunc(&test_data);
+			testfunc(data);
 
 			igt_info("\n%s on pipe %c, connector %s: PASSED\n\n",
-				 igt_subtest_name(), pipe_name(test_data.pipe),
+				 igt_subtest_name(), pipe_name(data->pipe),
 				 igt_output_name(output));
 
 			/* cleanup what prepare_crtc() has done */
-			cleanup_crtc(&test_data, output);
+			cleanup_crtc(data, output);
 		}
 	}
 
@@ -356,16 +344,15 @@ static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
 	igt_assert(cairo_status(cr) == 0);
 }
 
-static void test_cursor_size(test_data_t *test_data)
+static void test_cursor_size(data_t *data)
 {
-	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
-	igt_pipe_crc_t *pipe_crc = test_data->pipe_crc;
+	igt_pipe_crc_t *pipe_crc = data->pipe_crc;
 	igt_crc_t crc[10], ref_crc;
 	igt_plane_t *cursor;
 	cairo_t *cr;
 	uint32_t fb_id;
-	int i, size, cursor_max_size = test_data->cursor_max_size;
+	int i, size, cursor_max_size = data->cursor_max_size;
 
 	/* Create a maximum size cursor, then change the size in flight to
 	 * smaller ones to see that the size is applied correctly
@@ -379,28 +366,28 @@ static void test_cursor_size(test_data_t *test_data)
 	igt_paint_color_alpha(cr, 0, 0, cursor_max_size, cursor_max_size, 1.0, 1.0, 1.0, 1.0);
 
 	/* Hardware test loop */
-	cursor_enable(test_data);
-	cursor = igt_output_get_plane(test_data->output, IGT_PLANE_CURSOR);
+	cursor_enable(data);
+	cursor = igt_output_get_plane(data->output, IGT_PLANE_CURSOR);
 	igt_plane_set_position(cursor, 0, 0);
 	for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
 		/* Change size in flight: */
-		int ret = drmModeSetCursor(data->drm_fd, test_data->output->config.crtc->crtc_id,
+		int ret = drmModeSetCursor(data->drm_fd, data->output->config.crtc->crtc_id,
 					   data->fb.gem_handle, size, size);
 		igt_assert(ret == 0);
-		igt_wait_for_vblank(data->drm_fd, test_data->pipe);
+		igt_wait_for_vblank(data->drm_fd, data->pipe);
 		igt_pipe_crc_collect_crc(pipe_crc, &crc[i]);
 	}
-	cursor_disable(test_data);
+	cursor_disable(data);
 	/* Software test loop */
 	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 	for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
 		/* Now render the same in software and collect crc */
 		igt_paint_color_alpha(cr, 0, 0, size, size, 1.0, 1.0, 1.0, 1.0);
 		igt_display_commit(display);
-		igt_wait_for_vblank(data->drm_fd, test_data->pipe);
+		igt_wait_for_vblank(data->drm_fd, data->pipe);
 		igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
 		/* Clear screen afterwards */
-		igt_paint_color(cr, 0, 0, test_data->screenw, test_data->screenh,
+		igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
 				0.0, 0.0, 0.0);
 		igt_assert(igt_crc_equal(&crc[i], &ref_crc));
 	}
Signature · 1 line
1.8.5.1
author
#9 lore raw

PATCH 9/9 tests/kms_cursor_crc: Call drmModeMoveCursor() directly

In reply to Matt Roper

We're calling drmModeSetCursor() to change the cursor image and never actually doing a display commit (aside from when we display the cursor), so call the move ioctl directly rather than igt_plane_set_position() to ensure the changes actually take effect.

---
 tests/kms_cursor_crc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tests/kms_cursor_crc.c +5 -5
index d21fc99..82807b7 100644
@@ -349,10 +349,10 @@ static void test_cursor_size(data_t *data)
 	igt_display_t *display = &data->display;
 	igt_pipe_crc_t *pipe_crc = data->pipe_crc;
 	igt_crc_t crc[10], ref_crc;
-	igt_plane_t *cursor;
 	cairo_t *cr;
 	uint32_t fb_id;
 	int i, size, cursor_max_size = data->cursor_max_size;
+	int ret;
 
 	/* Create a maximum size cursor, then change the size in flight to
 	 * smaller ones to see that the size is applied correctly
@@ -367,12 +367,12 @@ static void test_cursor_size(data_t *data)
 
 	/* Hardware test loop */
 	cursor_enable(data);
-	cursor = igt_output_get_plane(data->output, IGT_PLANE_CURSOR);
-	igt_plane_set_position(cursor, 0, 0);
+	ret = drmModeMoveCursor(data->drm_fd, data->output->config.crtc->crtc_id, 0, 0);
+	igt_assert(ret == 0);
 	for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
 		/* Change size in flight: */
-		int ret = drmModeSetCursor(data->drm_fd, data->output->config.crtc->crtc_id,
-					   data->fb.gem_handle, size, size);
+		ret = drmModeSetCursor(data->drm_fd, data->output->config.crtc->crtc_id,
+				       data->fb.gem_handle, size, size);
 		igt_assert(ret == 0);
 		igt_wait_for_vblank(data->drm_fd, data->pipe);
 		igt_pipe_crc_collect_crc(pipe_crc, &crc[i]);
Signature · 1 line
1.8.5.1
#10 lore raw
In reply to Matt Roper
Quoted 3 lines · Matt Roper

This patch set refactors the igt_kms library a bit to allow display state changes to be commited via different API's (with different "commit styles") and adds a new "universal" commit style that makes use of the universal plane API.

Hi Matt,

Thanks for the patches, I pushed them all with a tiny fix on top of correctly list the sub=tests and don't fail, but skip, when the kernel doesn't have universal plane support.

Signature · 1 line
Damien