Skip to contentSkip to conversation

Modeset API for KMS tests

PATCH New Damien Lespiau 1 participant 30 messages Feb 7, 2014 – Feb 11, 2014 Library code

lore
Share & tools
lore
#0 lore raw

The goal of that series is to introduce a small mode setting API to write our KMS tests, port kms_pipe_crc_basic and kms_cursor_crc to it and introduce a new kms_plane test. To be more precise, the goals are:

- Fewer lines per test,
- Be able to switch between a "legacy" backend and an "atomic" one to help landing the latter (still has to be written).
- Have a convenience place to put common KMS facilities and testing

Here an example of the look and feel of the API:

igt_display_t display;
igt_output_t output;

igt_display_init(&display);

for_each_connected_output(&display, output) {
        drmModeModeInfo *mode;
	struct kmstest_fb green_fb;
        igt_plane_t *primary;

	/*
	 * Create a green fb and display it on the primary plane
	 */
	mode = igt_output_get_mode(output);
        kmstest_create_color_fb(drm_fd,
				mode->hdisplay, mode->vdisplay,
                                DRM_FORMAT_XRGB8888,
                                false, /* tiled */
                                0.0, 1.0, 0.0,
                                &green_fb);

	igt_output_set_pipe(output, PIPE_B);
        primary = igt_ouput_get_plane(output, 0);
        igt_plane_set_fb(primary, &green_fb);
}

/* commit the display configuration */
igt_display_commit(&display);

igt_display_fini(&display);

A few interesting things about that API:

- It exposes primary and cursor planes as igt_plane_t
- It's possible to grab a debug output by defining IGT_DISPLAY_VERBOSE. This gives something like:

display: A.0: plane_set_fb(32)
display: A.2: plane_set_fb(33)
display: A.2: plane_set_position(132,132)
display: commit {
display:     LVDS-1: Selecting pipe A
display:     LVDS-1: SetCrtc pipe A, fb 32, panning (0, 0), mode 1366x768
display:     LVDS-1: SetCursor pipe A, fb 2 64x64
display:     LVDS-1: MoveCursor pipe A, (132, 132)
display: }

- It's possible to stop at every commit() to inspect what is displayed, waiting for keypress with IGT_DISPLAY_WAIT_AT_COMMIT=1

For instance, one can run:

$ sudo IGT_DISPLAY_VERBOSE=1 IGT_DISPLAY_WAIT_AT_COMMIT=1 ./tests/kms_plane --run-subtest plane-position-hole-pipe-A-plane-2

HTH,

Signature · 1 line
Damien
#1 lore raw

PATCH 1/28 lib: Introduce a modeset API

The goals here are:
- Reduce duplicated code in each KMS test
- Provide an API that looks more like what we want for atomic modesets. The hope is then that it'll be easy to switch, at run-time, between the "legacy" path and atomic modesets, keeping the same API for tests.

---
 lib/igt_kms.c | 364 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  59 ++++++++++
 2 files changed, 423 insertions(+)
lib/igt_kms.c +364 -0
index 3960d24..dfa6b41 100644
@@ -24,6 +24,7 @@
 
 #define _GNU_SOURCE
 #include <stdio.h>
+#include <stdarg.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <string.h>
@@ -763,3 +764,366 @@ void kmstest_free_connector_config(struct kmstest_connector_config *config)
 	drmModeFreeConnector(config->connector);
 }
 
+/*
+ * A small modeset API
+ */
+
+#define LOG_SPACES		"    "
+#define LOG_N_SPACES		(sizeof(LOG_SPACES) - 1)
+
+#define LOG_INDENT(d, section)				\
+	do {						\
+		igt_display_log(d, "%s {\n", section);	\
+		igt_display_log_shift(d, 1);		\
+	} while (0)
+#define LOG_UNINDENT(d)					\
+	do {						\
+		igt_display_log_shift(d, -1);		\
+		igt_display_log(d, "}\n");		\
+	} while (0)
+#define LOG(d, fmt, ...)	igt_display_log(d, fmt, ## __VA_ARGS__)
+
+static int  __attribute__((format(printf, 2, 3)))
+igt_display_log(igt_display_t *display, const char *fmt, ...)
+{
+	va_list args;
+	int n, i;
+
+	if (!display->verbose)
+		return 0;
+
+	va_start(args, fmt);
+	n = printf("display: ");
+	for (i = 0; i < display->log_shift; i++)
+		n += printf("%s", LOG_SPACES);
+	n += vprintf(fmt, args);
+	va_end(args);
+
+	return n;
+}
+
+static void igt_display_log_shift(igt_display_t *display, int shift)
+{
+	display->log_shift += shift;
+	igt_assert(display->log_shift >= 0);
+}
+
+static void igt_output_refresh(igt_output_t *output)
+{
+	igt_display_t *display = output->display;
+	int ret;
+	unsigned long crtc_idx_mask;
+
+	/* we mask out the pipes already in use */
+	crtc_idx_mask = output->pending_crtc_idx_mask & ~display->pipes_in_use;
+
+	if (output->valid)
+		kmstest_free_connector_config(&output->config);
+	ret = kmstest_get_connector_config(display->drm_fd,
+					   output->id,
+					   crtc_idx_mask,
+					   &output->config);
+	if (ret == 0)
+		output->valid = true;
+	else
+		output->valid = false;
+
+	if (!output->valid)
+		return;
+
+	if (!output->name) {
+		drmModeConnector *c = output->config.connector;
+
+		asprintf(&output->name, "%s-%d",
+			 kmstest_connector_type_str(c->connector_type),
+			 c->connector_type_id);
+	}
+
+	LOG(display, "%s: Selecting pipe %c\n", output->name,
+	    pipe_name(output->config.pipe));
+
+	display->pipes_in_use |= 1 << output->config.pipe;
+}
+
+void igt_display_init(igt_display_t *display, int drm_fd)
+{
+	drmModeRes *resources;
+	bool verbose;
+	int i;
+
+	/*
+	 * It's valid to set verbose before the init so we can get debugging
+	 * output for the init() itself.
+	 */
+	verbose = display->verbose;
+	memset(display, 0, sizeof(igt_display_t));
+	display->verbose = verbose;
+
+	LOG_INDENT(display, "init");
+
+	display->drm_fd = drm_fd;
+
+	resources = drmModeGetResources(display->drm_fd);
+	igt_assert(resources);
+
+	/*
+	 * We cache the number of pipes, that number is a physical limit of the
+	 * hardware and cannot change of time (for now, at least).
+	 */
+	display->n_pipes = resources->count_crtcs;
+
+	for (i = 0; i < display->n_pipes; i++) {
+		igt_pipe_t *pipe = &display->pipes[i];
+		igt_plane_t *plane;
+
+		pipe->display = display;
+		pipe->pipe = i;
+		pipe->n_planes = 1;
+
+		/* primary plane */
+		plane = &pipe->planes[0];
+		plane->pipe = pipe;
+		plane->index = 0;
+		plane->is_primary = true;
+	}
+
+	/*
+	 * The number of connectors is set, so we just initialize the outputs
+	 * array in _init(). This may change when we need dynamic connectors
+	 * (say DisplayPort MST).
+	 */
+	display->n_outputs = resources->count_connectors;
+	display->outputs = calloc(display->n_outputs, sizeof(igt_output_t));
+	igt_assert(display->outputs);
+
+	for (i = 0; i < display->n_outputs; i++) {
+		igt_output_t *output = &display->outputs[i];
+
+		/*
+		 * We're free to select any pipe to drive that output until
+		 * a constraint is set with igt_output_set_pipe().
+		 */
+		output->pending_crtc_idx_mask = -1UL;
+		output->id = resources->connectors[i];
+		output->display = display;
+
+		igt_output_refresh(output);
+	}
+
+	drmModeFreeResources(resources);
+
+	LOG_UNINDENT(display);
+}
+
+void igt_display_set_verbose(igt_display_t *display, bool verbose)
+{
+	display->verbose = verbose;
+}
+
+static void igt_output_fini(igt_output_t *output)
+{
+	if (output->valid)
+		kmstest_free_connector_config(&output->config);
+	free(output->name);
+}
+
+void igt_display_fini(igt_display_t *display)
+{
+	int i;
+
+	for (i = 0; i < display->n_outputs; i++)
+		igt_output_fini(&display->outputs[i]);
+	free(display->outputs);
+	display->outputs = NULL;
+}
+
+static void igt_display_refresh(igt_display_t *display)
+{
+	int i;
+
+	display->pipes_in_use = 0;
+
+	/*
+	 * The pipe allocation has to be done in two phases:
+	 *   - first, try to satisfy the outputs where a pipe has been specified
+	 *   - then, allocate the outputs with PIPE_ANY
+	 */
+	for (i = 0; i < display->n_outputs; i++) {
+		igt_output_t *output = &display->outputs[i];
+
+		if (output->pending_crtc_idx_mask == -1UL)
+			continue;
+
+		igt_output_refresh(output);
+	}
+	for (i = 0; i < display->n_outputs; i++) {
+		igt_output_t *output = &display->outputs[i];
+
+		if (output->pending_crtc_idx_mask != -1UL)
+			continue;
+
+		igt_output_refresh(output);
+	}
+}
+
+static igt_pipe_t *igt_output_get_driving_pipe(igt_output_t *output)
+{
+	igt_display_t *display = output->display;
+	enum pipe pipe;
+
+	if (output->pending_crtc_idx_mask == -1UL) {
+		/*
+		 * The user hasn't specified a pipe to use, take the one
+		 * configured by the last refresh()
+		 */
+		pipe = output->config.pipe;
+	} else {
+		/*
+		 * Otherwise, return the pending pipe (ie the pipe that should
+		 * drive this output after the commit()
+		 */
+		pipe = ffs(output->pending_crtc_idx_mask) - 1;
+	}
+
+	igt_assert(pipe >= 0 && pipe < display->n_pipes);
+
+	return &display->pipes[pipe];
+}
+
+static uint32_t igt_plane_get_fd_id(igt_plane_t *plane)
+{
+	if (plane->fb)
+		return plane->fb->fb_id;
+	else
+		return 0;
+}
+
+static int igt_output_commit(igt_output_t *output)
+{
+	igt_display_t *display = output->display;
+	igt_pipe_t *pipe;
+
+	pipe = igt_output_get_driving_pipe(output);
+	if (pipe->need_set_crtc) {
+		igt_plane_t *primary = &pipe->planes[0];
+		drmModeModeInfo *mode;
+		uint32_t fb_id, crtc_id;
+		int ret;
+
+		crtc_id = output->config.crtc->crtc_id;
+		fb_id = igt_plane_get_fd_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, fb %u\n",
+			    igt_output_name(output),
+			    pipe_name(output->config.pipe),
+			    fb_id);
+
+			ret = drmModeSetCrtc(display->drm_fd,
+					     crtc_id,
+					     fb_id,
+					     0, 0, /* x, y */
+					     NULL, /* connectors */
+					     0,    /* n_connectors */
+					     NULL  /* mode */);
+		}
+
+		igt_assert(ret == 0);
+
+		pipe->need_set_crtc = false;
+	}
+
+	return 0;
+}
+
+int igt_display_commit(igt_display_t *display)
+{
+	int i;
+
+	LOG_INDENT(display, "commit");
+
+	igt_display_refresh(display);
+
+	for (i = 0; i < display->n_outputs; i++) {
+		igt_output_t *output = &display->outputs[i];
+
+		if (!output->valid)
+			continue;
+
+		igt_output_commit(output);
+	}
+
+	LOG_UNINDENT(display);
+
+	return 0;
+}
+
+const char *igt_output_name(igt_output_t *output)
+{
+	return output->name;
+}
+
+drmModeModeInfo *igt_output_get_mode(igt_output_t *output)
+{
+	return &output->config.default_mode;
+}
+
+void igt_output_set_pipe(igt_output_t *output, enum pipe pipe)
+{
+	igt_display_t *display = output->display;
+
+	LOG(display, "%s: set_pipe(%c)\n", igt_output_name(output),
+	    pipe_name(pipe));
+
+	output->pending_crtc_idx_mask = 1 << pipe;
+}
+
+static igt_plane_t *igt_pipe_get_plane(igt_pipe_t *pipe, int index)
+{
+	igt_assert(index >= 0 && index < pipe->n_planes);
+	return &pipe->planes[index];
+}
+
+igt_plane_t *igt_ouput_get_plane(igt_output_t *output, int index)
+{
+	igt_pipe_t *pipe;
+
+	pipe = igt_output_get_driving_pipe(output);
+	return igt_pipe_get_plane(pipe, 0);
+}
+
+void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb)
+{
+	igt_pipe_t *pipe = plane->pipe;
+	igt_display_t *display = pipe->display;
+
+	LOG(display, "%c.%d: plane_set_fb(%p)\n", pipe_name(pipe->pipe),
+	    plane->index, fb);
+
+	plane->fb = fb;
+
+	if (plane->is_primary)
+		pipe->need_set_crtc = true;
+}
lib/igt_kms.h +59 -0

72 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/28 kms_pipe_crc_basic: Port to the new modeset API

In reply to Damien Lespiau
---
 tests/kms_pipe_crc_basic.c | 126 +++++++++++----------------------------------
 1 file changed, 29 insertions(+), 97 deletions(-)
tests/kms_pipe_crc_basic.c +29 -97
index f4a97eb..fdec077 100644
@@ -34,17 +34,10 @@
 #include "igt_kms.h"
 
 typedef struct {
-	struct kmstest_connector_config config;
-	struct kmstest_fb fb;
-	bool valid;
-} connector_t;
-
-typedef struct {
 	int drm_fd;
 	igt_debugfs_t debugfs;
-	drmModeRes *resources;
-	int n_connectors;
-	connector_t *connectors;
+	igt_display_t display;
+	struct kmstest_fb fb;
 } data_t;
 
 static void test_bad_command(data_t *data, const char *cmd)
@@ -62,120 +55,58 @@ static void test_bad_command(data_t *data, const char *cmd)
 	fclose(ctl);
 }
 
-static void connector_init(data_t *data, connector_t *connector,
-			   uint32_t id, uint32_t crtc_id_mask)
-{
-	int ret;
-
-	ret = kmstest_get_connector_config(data->drm_fd, id, crtc_id_mask,
-					   &connector->config);
-	if (ret == 0)
-		connector->valid = true;
-	else
-		connector->valid = false;
-
-}
-
-static void connector_fini(connector_t *connector)
+static void create_fb_for_mode(data_t *data, drmModeModeInfo *mode)
 {
-	kmstest_free_connector_config(&connector->config);
-}
-
-static bool
-connector_set_mode(data_t *data, connector_t *connector, drmModeModeInfo *mode)
-{
-	struct kmstest_connector_config *config = &connector->config;
 	unsigned int fb_id;
 	cairo_t *cr;
-	int ret;
 
 	fb_id = kmstest_create_fb(data->drm_fd,
 				  mode->hdisplay, mode->vdisplay,
 				  32 /* bpp */, 24 /* depth */,
 				  false /* tiling */,
-				  &connector->fb);
+				  &data->fb);
 	igt_assert(fb_id);
 
-	cr = kmstest_get_cairo_ctx(data->drm_fd, &connector->fb);
+	cr = kmstest_get_cairo_ctx(data->drm_fd, &data->fb);
 	kmstest_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
 			    0.0, 1.0, 0.0);
 	igt_assert(cairo_status(cr) == 0);
 	cairo_destroy(cr);
-
-#if 0
-	fprintf(stdout, "Using pipe %c, %dx%d\n", pipe_name(config->pipe),
-		mode->hdisplay, mode->vdisplay);
-#endif
-
-	ret = drmModeSetCrtc(data->drm_fd,
-			     config->crtc->crtc_id,
-			     connector->fb.fb_id,
-			     0, 0, /* x, y */
-			     &config->connector->connector_id,
-			     1,
-			     mode);
-	igt_assert(ret == 0);
-
-	return 0;
-}
-
-static void display_init(data_t *data)
-{
-	data->resources = drmModeGetResources(data->drm_fd);
-	igt_assert(data->resources);
-
-	data->n_connectors = data->resources->count_connectors;
-	data->connectors = calloc(data->n_connectors, sizeof(connector_t));
-	igt_assert(data->connectors);
-}
-
-static void connectors_init(data_t *data, uint32_t crtc_id_mask)
-{
-	int i;
-
-	for (i = 0; i < data->n_connectors; i++) {
-		uint32_t id = data->resources->connectors[i];
-
-		connector_init(data, &data->connectors[i], id, crtc_id_mask);
-	}
-}
-
-static void display_fini(data_t *data)
-{
-	int i;
-
-	for (i = 0; i < data->n_connectors; i++)
-		connector_fini(&data->connectors[i]);
-	free(data->connectors);
-
-	drmModeFreeResources(data->resources);
 }
 
 #define TEST_SEQUENCE (1<<0)
 
 static void test_read_crc(data_t *data, int pipe, unsigned flags)
 {
-	connector_t *connector;
+	igt_display_t *display = &data->display;
 	igt_pipe_crc_t *pipe_crc;
 	igt_crc_t *crcs = NULL;
 	int valid_connectors = 0, i;
 
-	connectors_init(data, 1 << pipe);
+	for (i = 0;  i < display->n_outputs; i++) {
+		igt_output_t *output = &display->outputs[i];
+		igt_plane_t *primary;
+		drmModeModeInfo *mode;
 
-	for (i = 0;  i < data->n_connectors; i++) {
-		connector = &data->connectors[i];
-
-		if (!connector->valid)
+		if (!output->valid)
 			continue;
 
-		fprintf(stdout, "%s: Testing connector %u\n",
-			igt_subtest_name(), connector->config.connector->connector_id);
+		igt_output_set_pipe(output, pipe);
+
+		fprintf(stdout, "%s: Testing connector %s using pipe %c\n",
+			igt_subtest_name(), igt_output_name(output),
+			pipe_name(pipe));
 
-		connector_set_mode(data, connector, &connector->config.default_mode);
+		mode = igt_output_get_mode(output);
+		create_fb_for_mode(data, mode);
+
+		primary = igt_ouput_get_plane(output, 0);
+		igt_plane_set_fb(primary, &data->fb);
+
+		igt_display_commit(display);
 
 		pipe_crc = igt_pipe_crc_new(&data->debugfs, data->drm_fd,
-					    connector->config.pipe,
-					    INTEL_PIPE_CRC_SOURCE_AUTO);
+					    pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
 
 		if (!pipe_crc)
 			continue;
@@ -204,7 +135,8 @@ static void test_read_crc(data_t *data, int pipe, unsigned flags)
 
 		free(crcs);
 		igt_pipe_crc_free(pipe_crc);
-		kmstest_remove_fb(data->drm_fd, &connector->fb);
+		kmstest_remove_fb(data->drm_fd, &data->fb);
+		igt_plane_set_fb(primary, NULL);
 	}
 
 	igt_require_f(valid_connectors, "No connector found for pipe %i\n", pipe);
@@ -222,10 +154,10 @@ igt_main
 
 		igt_set_vt_graphics_mode();
 
-		display_init(&data);
-
 		igt_debugfs_init(&data.debugfs);
 		igt_pipe_crc_check(&data.debugfs);
+
+		igt_display_init(&data.display, data.drm_fd);
 	}
 
 	igt_subtest("bad-pipe")
@@ -249,6 +181,6 @@ igt_main
 	}
 
 	igt_fixture {
-		display_fini(&data);
+		igt_display_fini(&data.display);
 	}
 }
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/28 lib: Introduce symbolic names for display planes

In reply to Damien Lespiau

It'd be nice to have symbolic names for planes instead of using an index in igt_output_get_plane().

We also namespace the enum to not conflict with anyone.

---
 lib/igt_display.h | 18 +++++++++---------
 lib/igt_kms.c     | 18 ++++++++++++++++--
 lib/igt_kms.h     |  2 +-
 3 files changed, 26 insertions(+), 12 deletions(-)
lib/igt_display.h +9 -9
index 84638b2..77a75a7 100644
@@ -33,16 +33,16 @@ enum pipe {
 };
 #define pipe_name(p) ((p) + 'A')
 
-/* FIXME: i915_drm.h on Android pollutes the general namespace. */
-#undef PLANE_A
-#undef PLANE_B
-
-enum plane {
-        PLANE_A = 0,
-        PLANE_B,
-        PLANE_C,
+/* We namespace this enum to not conflict with the Android i915_drm.h */
+enum igt_plane {
+        IGT_PLANE_1 = 0,
+        IGT_PLANE_PRIMARY = IGT_PLANE_1,
+        IGT_PLANE_2,
+        IGT_PLANE_3,
+        IGT_PLANE_CURSOR,
 };
-#define plane_name(p) ((p) + 'A')
+
+const char *plane_name(enum igt_plane p);
 
 #define sprite_name(p, s) ((p) * dev_priv->num_plane + (s) + 'A')
 
lib/igt_kms.c +16 -2
index dfa6b41..e3e902a 100644
@@ -764,6 +764,20 @@ void kmstest_free_connector_config(struct kmstest_connector_config *config)
 	drmModeFreeConnector(config->connector);
 }
 
+const char *plane_name(enum igt_plane p)
+{
+	static const char *names[] = {
+		[IGT_PLANE_1] = "plane1",
+		[IGT_PLANE_2] = "plane2",
+		[IGT_PLANE_3] = "plane3",
+		[IGT_PLANE_CURSOR] = "cursor",
+	};
+
+	igt_assert(p < ARRAY_SIZE(names) && names[p]);
+
+	return names[p];
+}
+
 /*
  * A small modeset API
  */
@@ -1106,12 +1120,12 @@ static igt_plane_t *igt_pipe_get_plane(igt_pipe_t *pipe, int index)
 	return &pipe->planes[index];
 }
 
-igt_plane_t *igt_ouput_get_plane(igt_output_t *output, int index)
+igt_plane_t *igt_ouput_get_plane(igt_output_t *output, enum igt_plane plane)
 {
 	igt_pipe_t *pipe;
 
 	pipe = igt_output_get_driving_pipe(output);
-	return igt_pipe_get_plane(pipe, 0);
+	return igt_pipe_get_plane(pipe, plane);
 }
 
 void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb)
lib/igt_kms.h +1 -1
index 901fc1a..80cdfb6 100644
@@ -154,7 +154,7 @@ void igt_display_set_verbose(igt_display_t *display, bool verbose);
 const char *igt_output_name(igt_output_t *output);
 drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
 void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
-igt_plane_t *igt_ouput_get_plane(igt_output_t *output, int index);
+igt_plane_t *igt_ouput_get_plane(igt_output_t *output, enum igt_plane plane);
 
 void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb);
 
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/28 lib: Introduce a for_each_connected_output() macro

In reply to Damien Lespiau

So we can easily cycle through them in tests without knowing too many internal details about how igt_display_t organize its data.

---
 lib/igt_kms.h | 4 ++++
 1 file changed, 4 insertions(+)
lib/igt_kms.h +4 -0
index 80cdfb6..1d06767 100644
@@ -158,5 +158,9 @@ igt_plane_t *igt_ouput_get_plane(igt_output_t *output, enum igt_plane plane);
 
 void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb);
 
+#define for_each_connected_output(display, output)		\
+	for (int i__ = 0;  i__ < (display)->n_outputs; i__++)	\
+		if ((output = &(display)->outputs[i__]), output->valid)
+
 #endif /* __IGT_KMS_H__ */
 
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/28 kms_pipe_crc_basic: Use for_each_connected_output()

In reply to Damien Lespiau
---
 tests/kms_pipe_crc_basic.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tests/kms_pipe_crc_basic.c +3 -6
index fdec077..7d48ca6 100644
@@ -81,16 +81,13 @@ static void test_read_crc(data_t *data, int pipe, unsigned flags)
 	igt_display_t *display = &data->display;
 	igt_pipe_crc_t *pipe_crc;
 	igt_crc_t *crcs = NULL;
-	int valid_connectors = 0, i;
+	int valid_connectors = 0;
+	igt_output_t *output;
 
-	for (i = 0;  i < display->n_outputs; i++) {
-		igt_output_t *output = &display->outputs[i];
+	for_each_connected_output(display, output) {
 		igt_plane_t *primary;
 		drmModeModeInfo *mode;
 
-		if (!output->valid)
-			continue;
-
 		igt_output_set_pipe(output, pipe);
 
 		fprintf(stdout, "%s: Testing connector %s using pipe %c\n",
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 6/28 lib/display: Add an accessor to retrieve the number of pipes

In reply to Damien Lespiau
---
 lib/igt_kms.c | 5 +++++
 lib/igt_kms.h | 1 +
 2 files changed, 6 insertions(+)
lib/igt_kms.c +5 -0
index e3e902a..38ee82b 100644
@@ -934,6 +934,11 @@ void igt_display_set_verbose(igt_display_t *display, bool verbose)
 	display->verbose = verbose;
 }
 
+int igt_display_get_n_pipes(igt_display_t *display)
+{
+	return display->n_pipes;
+}
+
 static void igt_output_fini(igt_output_t *output)
 {
 	if (output->valid)
lib/igt_kms.h +1 -0
index 1d06767..bb74fc4 100644
@@ -150,6 +150,7 @@ void igt_display_init(igt_display_t *display, int drm_fd);
 void igt_display_fini(igt_display_t *display);
 int  igt_display_commit(igt_display_t *display);
 void igt_display_set_verbose(igt_display_t *display, bool verbose);
+int  igt_display_get_n_pipes(igt_display_t *display);
 
 const char *igt_output_name(igt_output_t *output);
 drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 7/28 kms_pipe_crc_basic: Use igt_display_get_n_pipes() instead of hardcoding 3

In reply to Damien Lespiau
---
 tests/kms_pipe_crc_basic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/kms_pipe_crc_basic.c +1 -1
index 7d48ca6..f4de64f 100644
@@ -169,7 +169,7 @@ igt_main
 	igt_subtest("bad-nb-words-3")
 		test_bad_command(&data, "pipe A none option");
 
-	for (int i = 0; i < 3; i++) {
+	for (int i = 0; i < igt_display_get_n_pipes(&data.display); i++) {
 		igt_subtest_f("read-crc-pipe-%c", 'A'+i)
 			test_read_crc(&data, i, 0);
 
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 8/28 tests/kms_cursor_crc: Move the array of cursor fb_ids to the stack

In reply to Damien Lespiau

This array is not used outside ouf create_cursor_fb(). A stack allocated array is enough.

---
 tests/kms_cursor_crc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tests/kms_cursor_crc.c +5 -5
index 38aa1ab..9ddee06 100644
@@ -52,7 +52,6 @@ typedef struct {
 	int drm_fd;
 	igt_debugfs_t debugfs;
 	drmModeRes *resources;
-	uint32_t fb_id[NUM_CURSOR_TYPES];
 	struct kmstest_fb fb[NUM_CURSOR_TYPES];
 	igt_pipe_crc_t **pipe_crc;
 } data_t;
@@ -313,11 +312,12 @@ static void create_cursor_fb(data_t *data,
 			     double r, double g, double b, double a)
 {
 	cairo_t *cr;
+	uint32_t fb_id[NUM_CURSOR_TYPES];
 
-	data->fb_id[cursor_type] = kmstest_create_fb2(data->drm_fd, 64, 64,
-						      DRM_FORMAT_ARGB8888, false,
-						      &data->fb[cursor_type]);
-	igt_assert(data->fb_id[cursor_type]);
+	fb_id[cursor_type] = kmstest_create_fb2(data->drm_fd, 64, 64,
+						DRM_FORMAT_ARGB8888, false,
+						&data->fb[cursor_type]);
+	igt_assert(fb_id[cursor_type]);
 
 	cr = kmstest_get_cairo_ctx(data->drm_fd,
 				   &data->fb[cursor_type]);
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 9/28 lib/display: Fix the SetCrtc disabling log message

In reply to Damien Lespiau

We were displaying the value of fb_id (0), when the actual interesting thing about this call it that it'll just down the pipe.

---
 lib/igt_kms.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/igt_kms.c +2 -3
index 38ee82b..64fb39a 100644
@@ -1055,10 +1055,9 @@ static int igt_output_commit(igt_output_t *output)
 					     mode);
 		} else {
 			LOG(display,
-			    "%s: SetCrtc pipe %c, fb %u\n",
+			    "%s: SetCrtc pipe %c, disabling\n",
 			    igt_output_name(output),
-			    pipe_name(output->config.pipe),
-			    fb_id);
+			    pipe_name(output->config.pipe));
 
 			ret = drmModeSetCrtc(display->drm_fd,
 					     crtc_id,
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 10/28 lib/display: Add support for the cursor plane

In reply to Damien Lespiau
---
 lib/igt_kms.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 lib/igt_kms.h |  13 +++++-
 2 files changed, 150 insertions(+), 11 deletions(-)
lib/igt_kms.c +139 -9
index 64fb39a..3b75478 100644
@@ -889,16 +889,29 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 	for (i = 0; i < display->n_pipes; i++) {
 		igt_pipe_t *pipe = &display->pipes[i];
 		igt_plane_t *plane;
+		int p;
 
 		pipe->display = display;
 		pipe->pipe = i;
-		pipe->n_planes = 1;
 
 		/* primary plane */
-		plane = &pipe->planes[0];
+		p = IGT_PLANE_PRIMARY;
+		plane = &pipe->planes[p];
 		plane->pipe = pipe;
-		plane->index = 0;
+		plane->index = p;
 		plane->is_primary = true;
+
+		/* cursor plane */
+		p++;
+		plane = &pipe->planes[p];
+		plane->pipe = pipe;
+		plane->index = p;
+		plane->is_cursor = true;
+
+		pipe->n_planes = ++p;
+
+		/* make sure we don't overflow the plane array */
+		igt_assert(pipe->n_planes <= IGT_MAX_PLANES);
 	}
 
 	/*
@@ -1009,6 +1022,22 @@ static igt_pipe_t *igt_output_get_driving_pipe(igt_output_t *output)
 	return &display->pipes[pipe];
 }
 
+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 */
+	if (plane == IGT_PLANE_CURSOR)
+		idx = pipe->n_planes - 1;
+	else {
+		igt_assert_f(plane >= 0 && plane < (pipe->n_planes - 1),
+			     "plane=%d\n", plane);
+		idx = plane;
+	}
+
+	return &pipe->planes[idx];
+}
+
 static uint32_t igt_plane_get_fd_id(igt_plane_t *plane)
 {
 	if (plane->fb)
@@ -1017,10 +1046,53 @@ static uint32_t igt_plane_get_fd_id(igt_plane_t *plane)
 		return 0;
 }
 
+static uint32_t igt_plane_get_fb_gem_handle(igt_plane_t *plane)
+{
+	if (plane->fb)
+		return plane->fb->gem_handle;
+	else
+		return 0;
+}
+
+static int igt_cursor_commit(igt_plane_t *plane, igt_output_t *output)
+{
+	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);
+
+		igt_assert(ret == 0);
+
+		plane->position_changed = false;
+	}
+
+	return 0;
+}
+
+static int igt_plane_commit(igt_plane_t *plane, igt_output_t *output)
+{
+	if (plane->is_cursor)
+		igt_cursor_commit(plane, output);
+
+	return 0;
+}
+
 static int igt_output_commit(igt_output_t *output)
 {
 	igt_display_t *display = output->display;
 	igt_pipe_t *pipe;
+	int i;
 
 	pipe = igt_output_get_driving_pipe(output);
 	if (pipe->need_set_crtc) {
@@ -1073,6 +1145,48 @@ static int igt_output_commit(igt_output_t *output)
 		pipe->need_set_crtc = false;
 	}
 
+	if (pipe->need_set_cursor) {
+		igt_plane_t *cursor;
+		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);
+
+		if (gem_handle) {
+			LOG(display,
+			    "%s: SetCursor pipe %c, fb %u %dx%d\n",
+			    igt_output_name(output),
+			    pipe_name(output->config.pipe),
+			    gem_handle,
+			    cursor->fb->width, cursor->fb->height);
+
+			ret = drmModeSetCursor(display->drm_fd, crtc_id,
+					       gem_handle,
+					       cursor->fb->width,
+					       cursor->fb->height);
+		} else {
+			LOG(display,
+			    "%s: SetCursor pipe %c, disabling\n",
+			    igt_output_name(output),
+			    pipe_name(output->config.pipe));
+
+			ret = drmModeSetCursor(display->drm_fd, crtc_id,
+					       0, 0, 0);
+		}
+
+		igt_assert(ret == 0);
+
+		pipe->need_set_cursor = false;
+	}
+
+	for (i = 0; i < pipe->n_planes; i++) {
+		igt_plane_t *plane = &pipe->planes[i];
+
+		igt_plane_commit(plane, output);
+	}
+
 	return 0;
 }
 
@@ -1118,12 +1232,6 @@ void igt_output_set_pipe(igt_output_t *output, enum pipe pipe)
 	output->pending_crtc_idx_mask = 1 << pipe;
 }
 
-static igt_plane_t *igt_pipe_get_plane(igt_pipe_t *pipe, int index)
-{
-	igt_assert(index >= 0 && index < pipe->n_planes);
-	return &pipe->planes[index];
-}
-
 igt_plane_t *igt_ouput_get_plane(igt_output_t *output, enum igt_plane plane)
 {
 	igt_pipe_t *pipe;
@@ -1144,4 +1252,26 @@ void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb)
 
 	if (plane->is_primary)
 		pipe->need_set_crtc = true;
+	else if (plane->is_cursor)
+		pipe->need_set_cursor = true;
+}
+
+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);
+
+	plane->crtc_x = x;
+	plane->crtc_y = y;
+
+	plane->position_changed = true;
 }
lib/igt_kms.h +11 -2
index bb74fc4..e86cff4 100644
@@ -109,18 +109,24 @@ uint32_t drm_format_to_bpp(uint32_t drm_format);
 
 typedef struct igt_display igt_display_t;
 typedef struct igt_pipe igt_pipe_t;
+typedef uint32_t igt_fixed_t;			/* 16.16 fixed point */
 
 typedef struct {
 	igt_pipe_t *pipe;
 	int index;
-	unsigned int is_primary : 1;
+	unsigned int is_primary       : 1;
+	unsigned int is_cursor        : 1;
+	unsigned int position_changed : 1;
 	struct kmstest_fb *fb;
+	/* position within pipe_src_w x pipe_src_h */
+	int crtc_x, crtc_y;
 } igt_plane_t;
 
 struct igt_pipe {
 	igt_display_t *display;
 	enum pipe pipe;
-	unsigned int need_set_crtc : 1;
+	unsigned int need_set_crtc   : 1;
+	unsigned int need_set_cursor : 1;
 #define IGT_MAX_PLANES	4
 	int n_planes;
 	igt_plane_t planes[IGT_MAX_PLANES];
@@ -158,10 +164,13 @@ void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
 igt_plane_t *igt_ouput_get_plane(igt_output_t *output, enum igt_plane plane);
 
 void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb);
+void igt_plane_set_position(igt_plane_t *plane, int x, int y);
 
 #define for_each_connected_output(display, output)		\
 	for (int i__ = 0;  i__ < (display)->n_outputs; i__++)	\
 		if ((output = &(display)->outputs[i__]), output->valid)
 
+#define IGT_FIXED(i,f)	((i) << 16 | (f))
+
 #endif /* __IGT_KMS_H__ */
 
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH 11/28 lib/display: Add a way to specify we don't care about the pipe to use

In reply to Damien Lespiau
---
 lib/igt_kms.c | 12 ++++++++----
 lib/igt_kms.h |  6 ++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
lib/igt_kms.c +8 -4
index 3b75478..e2413e5 100644
@@ -1226,10 +1226,14 @@ void igt_output_set_pipe(igt_output_t *output, enum pipe pipe)
 {
 	igt_display_t *display = output->display;
 
-	LOG(display, "%s: set_pipe(%c)\n", igt_output_name(output),
-	    pipe_name(pipe));
-
-	output->pending_crtc_idx_mask = 1 << pipe;
+	if (pipe == PIPE_ANY) {
+		LOG(display, "%s: set_pipe(any)\n", igt_output_name(output));
+		output->pending_crtc_idx_mask = -1UL;
+	} else {
+		LOG(display, "%s: set_pipe(%c)\n", igt_output_name(output),
+		    pipe_name(pipe));
+		output->pending_crtc_idx_mask = 1 << pipe;
+	}
 }
 
 igt_plane_t *igt_ouput_get_plane(igt_output_t *output, enum igt_plane plane)
lib/igt_kms.h +6 -0
index e86cff4..07cf8a2 100644
@@ -170,6 +170,12 @@ void igt_plane_set_position(igt_plane_t *plane, int x, int y);
 	for (int i__ = 0;  i__ < (display)->n_outputs; i__++)	\
 		if ((output = &(display)->outputs[i__]), output->valid)
 
+/*
+ * Can be used with igt_output_set_pipe() to mean we don't care about the pipe
+ * that should drive this output
+ */
+#define PIPE_ANY	(-1)
+
 #define IGT_FIXED(i,f)	((i) << 16 | (f))
 
 #endif /* __IGT_KMS_H__ */
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 12/28 kms_cursor_crc: Port the test to the new modeset API

In reply to Damien Lespiau
---
 tests/kms_cursor_crc.c | 201 ++++++++++++++++++++++++++-----------------------
 1 file changed, 106 insertions(+), 95 deletions(-)
tests/kms_cursor_crc.c +106 -95
index 9ddee06..76e2845 100644
@@ -43,101 +43,66 @@ enum cursor_type {
 };
 
 typedef struct {
-	struct kmstest_connector_config config;
-	drmModeModeInfo mode;
-	struct kmstest_fb fb;
-} connector_t;
-
-typedef struct {
 	int drm_fd;
 	igt_debugfs_t debugfs;
-	drmModeRes *resources;
+	igt_display_t display;
+	struct kmstest_fb primary_fb;
 	struct kmstest_fb fb[NUM_CURSOR_TYPES];
 	igt_pipe_crc_t **pipe_crc;
 } data_t;
 
 typedef struct {
 	data_t *data;
-	uint32_t crtc_id;
-	int crtc_idx;
+	igt_output_t *output;
+	enum pipe pipe;
 	igt_crc_t ref_crc;
 	bool crc_must_match;
 	int left, right, top, bottom;
 } test_data_t;
 
 
-static bool
-connector_set_mode(data_t *data, connector_t *connector, drmModeModeInfo *mode)
+static void create_fb_for_mode(data_t *data, drmModeModeInfo *mode)
 {
-	struct kmstest_connector_config *config = &connector->config;
 	unsigned int fb_id;
 	cairo_t *cr;
-	int ret;
 
 	fb_id = kmstest_create_fb2(data->drm_fd,
 				   mode->hdisplay, mode->vdisplay,
 				   DRM_FORMAT_XRGB8888,
-				   false, &connector->fb);
+				   false, &data->primary_fb);
 	igt_assert(fb_id);
 
 	/* black */
-	cr = kmstest_get_cairo_ctx(data->drm_fd, &connector->fb);
+	cr = kmstest_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 	kmstest_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
 			    0.0, 0.0, 0.0);
 	igt_assert(cairo_status(cr) == 0);
 	cairo_destroy(cr);
-
-#if 0
-	fprintf(stdout, "Using pipe %c, %dx%d\n", pipe_name(config->pipe),
-		mode->hdisplay, mode->vdisplay);
-#endif
-
-	ret = drmModeSetCrtc(data->drm_fd,
-			     config->crtc->crtc_id,
-			     connector->fb.fb_id,
-			     0, 0, /* x, y */
-			     &config->connector->connector_id,
-			     1,
-			     mode);
-	igt_assert(ret == 0);
-
-	return 0;
 }
 
-static igt_pipe_crc_t *create_crc(data_t *data, int crtc_idx)
+static igt_pipe_crc_t *create_crc(data_t *data, enum pipe pipe)
 {
 	igt_pipe_crc_t *crc;
 
-	crc = igt_pipe_crc_new(&data->debugfs, data->drm_fd, crtc_idx,
+	crc = igt_pipe_crc_new(&data->debugfs, data->drm_fd, pipe,
 			       INTEL_PIPE_CRC_SOURCE_AUTO);
 	return crc;
 }
 
-static void display_init(data_t *data)
-{
-	data->resources = drmModeGetResources(data->drm_fd);
-	igt_assert(data->resources);
-
-	data->pipe_crc = calloc(data->resources->count_crtcs, sizeof(data->pipe_crc[0]));
-}
-
-static void display_fini(data_t *data)
-{
-	free(data->pipe_crc);
-
-	drmModeFreeResources(data->resources);
-}
-
 static void do_single_test(test_data_t *test_data, int x, int y)
 {
 	data_t *data = test_data->data;
-	igt_pipe_crc_t *pipe_crc = data->pipe_crc[test_data->crtc_idx];
+	igt_display_t *display = &data->display;
+	igt_pipe_crc_t *pipe_crc = data->pipe_crc[test_data->pipe];
 	igt_crc_t *crcs = NULL;
+	igt_plane_t *cursor;
 
 	printf("."); fflush(stdout);
 
-	igt_assert(drmModeMoveCursor(data->drm_fd, test_data->crtc_id, x, y) == 0);
-	igt_wait_for_vblank(data->drm_fd, test_data->crtc_idx);
+	cursor = igt_ouput_get_plane(test_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_pipe_crc_start(pipe_crc);
 	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
@@ -158,18 +123,39 @@ static void do_test(test_data_t *test_data,
 	do_single_test(test_data, left, bottom);
 }
 
+static void cursor_enable(test_data_t *test_data, enum cursor_type cursor_type)
+{
+	data_t *data = test_data->data;
+	igt_display_t *display = &data->display;
+	igt_output_t *output = test_data->output;
+	igt_plane_t *cursor;
+
+	cursor = igt_ouput_get_plane(output, IGT_PLANE_CURSOR);
+	igt_plane_set_fb(cursor, &data->fb[cursor_type]);
+	igt_display_commit(display);
+}
+
+static void cursor_disable(test_data_t *test_data)
+{
+	data_t *data = test_data->data;
+	igt_display_t *display = &data->display;
+	igt_output_t *output = test_data->output;
+	igt_plane_t *cursor;
+
+	cursor = igt_ouput_get_plane(output, IGT_PLANE_CURSOR);
+	igt_plane_set_fb(cursor, NULL);
+	igt_display_commit(display);
+}
+
 static void test_crc(test_data_t *test_data, enum cursor_type cursor_type,
 		     bool onscreen)
 {
-	data_t *data = test_data->data;
 	int left = test_data->left;
 	int right = test_data->right;
 	int top = test_data->top;
 	int bottom = test_data->bottom;
 
-	/* enable cursor */
-	igt_assert(drmModeSetCursor(data->drm_fd, test_data->crtc_id,
-				    data->fb[cursor_type].gem_handle, 64, 64) == 0);
+	cursor_enable(test_data, cursor_type);
 
 	if (onscreen) {
 		/* cursor onscreen, crc should match, except when white visible cursor is used */
@@ -215,48 +201,52 @@ static void test_crc(test_data_t *test_data, enum cursor_type cursor_type,
 		do_test(test_data, INT_MIN, INT_MAX, INT_MIN, INT_MAX);
 	}
 
-	/* disable cursor again */
-	igt_assert(drmModeSetCursor(data->drm_fd, test_data->crtc_id, 0, 0, 0) == 0);
+	cursor_disable(test_data);
 }
 
-static bool prepare_crtc(test_data_t *test_data, uint32_t connector_id)
+static bool prepare_crtc(test_data_t *test_data, igt_output_t *output)
 {
-	connector_t connector;
+	drmModeModeInfo *mode;
 	igt_crc_t *crcs = NULL;
 	data_t *data = test_data->data;
+	igt_display_t *display = &data->display;
 	igt_pipe_crc_t *pipe_crc;
-	int ret;
+	igt_plane_t *primary;
 
-	ret = kmstest_get_connector_config(data->drm_fd,
-					   connector_id,
-					   1 << test_data->crtc_idx,
-					   &connector.config);
-	if (ret)
-		return false;
+	/* select the pipe we want to use */
+	igt_output_set_pipe(output, test_data->pipe);
 
-	connector_set_mode(data, &connector, &connector.config.default_mode);
+	/* create and set the primary plane fb */
+	mode = igt_output_get_mode(output);
+	create_fb_for_mode(data, mode);
 
-	igt_pipe_crc_free(data->pipe_crc[test_data->crtc_idx]);
-	data->pipe_crc[test_data->crtc_idx] = NULL;
+	primary = igt_ouput_get_plane(output, IGT_PLANE_PRIMARY);
+	igt_plane_set_fb(primary, &data->primary_fb);
 
-	pipe_crc = create_crc(data, test_data->crtc_idx);
+	igt_display_commit(display);
+
+	/* create the pipe_crc object for this pipe */
+	igt_pipe_crc_free(data->pipe_crc[test_data->pipe]);
+	data->pipe_crc[test_data->pipe] = NULL;
+
+	pipe_crc = create_crc(data, test_data->pipe);
 	if (!pipe_crc) {
-		printf("auto crc not supported on this connector with crtc %i\n",
-		       test_data->crtc_idx);
+		printf("auto crc not supported on this connector with pipe %i\n",
+		       test_data->pipe);
 		return false;
 	}
 
-	data->pipe_crc[test_data->crtc_idx] = pipe_crc;
+	data->pipe_crc[test_data->pipe] = pipe_crc;
 
 	/* x/y position where the cursor is still fully visible */
 	test_data->left = 0;
-	test_data->right = connector.config.default_mode.hdisplay - 64;
+	test_data->right = mode->hdisplay - 64;
 	test_data->top = 0;
-	test_data->bottom = connector.config.default_mode.vdisplay - 64;
+	test_data->bottom = mode->vdisplay - 64;
 
 	/* make sure cursor is disabled */
-	igt_assert(drmModeSetCursor(data->drm_fd, test_data->crtc_id, 0, 0, 0) == 0);
-	igt_wait_for_vblank(data->drm_fd, test_data->crtc_idx);
+	cursor_disable(test_data);
+	igt_wait_for_vblank(data->drm_fd, test_data->pipe);
 
 	/* get reference crc w/o cursor */
 	igt_pipe_crc_start(pipe_crc);
@@ -265,42 +255,59 @@ static bool prepare_crtc(test_data_t *test_data, uint32_t connector_id)
 	igt_pipe_crc_stop(pipe_crc);
 	free(crcs);
 
-	kmstest_free_connector_config(&connector.config);
-
 	return true;
 }
 
+static void cleanup_crtc(test_data_t *test_data, igt_output_t *output)
+{
+	data_t *data = test_data->data;
+	igt_plane_t *primary;
+
+	igt_pipe_crc_free(data->pipe_crc[test_data->pipe]);
+	data->pipe_crc[test_data->pipe] = NULL;
+
+	kmstest_remove_fb(data->drm_fd, &data->primary_fb);
+
+	primary = igt_ouput_get_plane(output, IGT_PLANE_PRIMARY);
+	igt_plane_set_fb(primary, NULL);
+
+	igt_output_set_pipe(output, PIPE_ANY);
+}
+
 static void run_test(data_t *data, enum cursor_type cursor_type, bool onscreen)
 {
+	igt_display_t *display = &data->display;
+	igt_output_t *output;
+	enum pipe p;
 	test_data_t test_data = {
 		.data = data,
 	};
-	int i, n;
 	int valid_tests = 0;
 
-	for (i = 0; i < data->resources->count_connectors; i++) {
-		uint32_t connector_id = data->resources->connectors[i];
 
-		for (n = 0; n < data->resources->count_crtcs; n++) {
-			test_data.crtc_idx = n;
-			test_data.crtc_id = data->resources->crtcs[n];
+	for_each_connected_output(display, output) {
+		test_data.output = output;
+		for (p = 0; p < igt_display_get_n_pipes(display); p++) {
+			test_data.pipe = p;
 
-			if (!prepare_crtc(&test_data, connector_id))
+			if (!prepare_crtc(&test_data, output))
 				continue;
 
 			valid_tests++;
 
-			fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
-				igt_subtest_name(), test_data.crtc_id, connector_id);
+			fprintf(stdout, "Beginning %s on pipe %c, connector %s\n",
+				igt_subtest_name(), pipe_name(test_data.pipe),
+				igt_output_name(output));
 
 			test_crc(&test_data, cursor_type, onscreen);
 
 
-			fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
-				igt_subtest_name(), test_data.crtc_id, connector_id);
+			fprintf(stdout, "\n%s on pipe %c, connector %s: PASSED\n\n",
+				igt_subtest_name(), pipe_name(test_data.pipe),
+				igt_output_name(output));
 
-			igt_pipe_crc_free(data->pipe_crc[test_data.crtc_idx]);
-			data->pipe_crc[test_data.crtc_idx] = NULL;
+			/* cleanup what prepare_crtc() has done */
+			cleanup_crtc(&test_data, output);
 		}
 	}
 
@@ -339,7 +346,9 @@ igt_main
 		igt_debugfs_init(&data.debugfs);
 		igt_pipe_crc_check(&data.debugfs);
 
-		display_init(&data);
+		igt_display_init(&data.display, data.drm_fd);
+		data.pipe_crc = calloc(igt_display_get_n_pipes(&data.display),
+				       sizeof(data.pipe_crc[0]));
 
 		create_cursor_fb(&data, WHITE_VISIBLE, 1.0, 1.0, 1.0, 1.0);
 		create_cursor_fb(&data, WHITE_INVISIBLE, 1.0, 1.0, 1.0, 0.0);
@@ -364,6 +373,8 @@ igt_main
 	igt_subtest("cursor-black-invisible-offscreen")
 		run_test(&data, BLACK_INVISIBLE, false);
 
-	igt_fixture
-		display_fini(&data);
+	igt_fixture {
+		free(data.pipe_crc);
+		igt_display_fini(&data.display);
+	}
 }
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH 13/28 lib/display: Allow to override the display verbosity with an env variale

In reply to Damien Lespiau
---
 lib/igt_kms.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/igt_kms.c +6 -0
index e2413e5..c503ebb 100644
@@ -863,6 +863,7 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 {
 	drmModeRes *resources;
 	bool verbose;
+	char *env;
 	int i;
 
 	/*
@@ -873,6 +874,11 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 	memset(display, 0, sizeof(igt_display_t));
 	display->verbose = verbose;
 
+	/* allow a verbose override from an env variable */
+	env = getenv("IGT_DISPLAY_VERBOSE");
+	if (env)
+		display->verbose = atoi(env) != 0;
+
 	LOG_INDENT(display, "init");
 
 	display->drm_fd = drm_fd;
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH 14/28 lib/display: Check if we're trying to use the same pipe on 2 outputs

In reply to Damien Lespiau
---
 lib/igt_kms.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
lib/igt_kms.c +25 -1
index c503ebb..1933fa6 100644
@@ -977,10 +977,34 @@ void igt_display_fini(igt_display_t *display)
 
 static void igt_display_refresh(igt_display_t *display)
 {
-	int i;
+	int i, j;
 
 	display->pipes_in_use = 0;
 
+       /* Check that two outputs aren't trying to use the same pipe */
+        for (i = 0; i < display->n_outputs; i++) {
+                igt_output_t *a = &display->outputs[i];
+
+                if (a->pending_crtc_idx_mask == -1UL)
+                        continue;
+
+                for (j = 0; j < display->n_outputs; j++) {
+                        igt_output_t *b = &display->outputs[j];
+
+                        if (i == j)
+                                continue;
+
+                        if (b->pending_crtc_idx_mask == -1UL)
+                                continue;
+
+                        igt_assert_f(a->pending_crtc_idx_mask !=
+                                     b->pending_crtc_idx_mask,
+                                     "%s and %s are both trying to use pipe %c\n",
+                                     igt_output_name(a), igt_output_name(b),
+                                     pipe_name(ffs(a->pending_crtc_idx_mask) - 1));
+                }
+        }
+
 	/*
 	 * The pipe allocation has to be done in two phases:
 	 *   - first, try to satisfy the outputs where a pipe has been specified
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH 15/28 lib/crc: Factor out reading a single CRC value

In reply to Damien Lespiau
---
 lib/igt_debugfs.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
lib/igt_debugfs.c +16 -7
index 4b96521..a0d84bf 100644
@@ -301,6 +301,21 @@ static bool pipe_crc_init_from_string(igt_crc_t *crc, const char *line)
 	return n == 6;
 }
 
+static bool read_one_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out)
+{
+	ssize_t bytes_read;
+	char buf[pipe_crc->buffer_len];
+
+	bytes_read = read(pipe_crc->crc_fd, &buf, pipe_crc->line_len);
+	igt_assert_cmpint(bytes_read, ==, pipe_crc->line_len);
+	buf[bytes_read] = '\0';
+
+	if (!pipe_crc_init_from_string(out, buf))
+		return false;
+
+	return true;
+}
+
 /*
  * Read @n_crcs from the @pipe_crc. This function blocks until @n_crcs are
  * retrieved.
@@ -309,9 +324,7 @@ void
 igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
 		      igt_crc_t **out_crcs)
 {
-	ssize_t bytes_read;
 	igt_crc_t *crcs;
-	char buf[pipe_crc->buffer_len];
 	int n = 0;
 
 	crcs = calloc(n_crcs, sizeof(igt_crc_t));
@@ -319,11 +332,7 @@ igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
 	do {
 		igt_crc_t *crc = &crcs[n];
 
-		bytes_read = read(pipe_crc->crc_fd, &buf, pipe_crc->line_len);
-		igt_assert_cmpint(bytes_read, ==, pipe_crc->line_len);
-		buf[bytes_read] = '\0';
-
-		if (!pipe_crc_init_from_string(crc, buf))
+		if (!read_one_crc(pipe_crc, crc))
 			continue;
 
 		n++;
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH 16/28 lib/crc: Add a helper to read a single CRC value

In reply to Damien Lespiau

In this case, we also take care of starting/stopping the CRC collection.

---
 lib/igt_debugfs.c | 14 ++++++++++++++
 lib/igt_debugfs.h |  1 +
 2 files changed, 15 insertions(+)
lib/igt_debugfs.c +14 -0
index a0d84bf..4a4a4dd 100644
@@ -342,6 +342,20 @@ igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
 }
 
 /*
+ * Read 1 CRC from @pipe_crc. This function blocks until the CRC is retrieved.
+ * @out_crc must be allocated by the caller.
+ *
+ * This function takes care of the pipe_crc book-keeping, it will start/stop
+ * the collection of the CRC.
+ */
+void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc)
+{
+	igt_pipe_crc_start(pipe_crc);
+	read_one_crc(pipe_crc, out_crc);
+	igt_pipe_crc_stop(pipe_crc);
+}
+
+/*
  * Drop caches
  */
 
lib/igt_debugfs.h +1 -0
index 075e446..6b7e623 100644
@@ -79,6 +79,7 @@ void igt_pipe_crc_start(igt_pipe_crc_t *pipe_crc);
 void igt_pipe_crc_stop(igt_pipe_crc_t *pipe_crc);
 void igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
 			   igt_crc_t **out_crcs);
+void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);
 
 /*
  * Drop caches
Signature · 1 line
1.8.3.1
#17 lore raw

PATCH 17/28 tests/kms_cursor_crc: Use igt_pipe_crc_collect_crc()

In reply to Damien Lespiau
---
 tests/kms_cursor_crc.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
tests/kms_cursor_crc.c +5 -13
index 76e2845..a386ad9 100644
@@ -94,7 +94,7 @@ static void do_single_test(test_data_t *test_data, int x, int y)
 	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
 	igt_pipe_crc_t *pipe_crc = data->pipe_crc[test_data->pipe];
-	igt_crc_t *crcs = NULL;
+	igt_crc_t crc;
 	igt_plane_t *cursor;
 
 	printf("."); fflush(stdout);
@@ -104,14 +104,11 @@ static void do_single_test(test_data_t *test_data, int x, int y)
 	igt_display_commit(display);
 	igt_wait_for_vblank(data->drm_fd, test_data->pipe);
 
-	igt_pipe_crc_start(pipe_crc);
-	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
-	igt_pipe_crc_stop(pipe_crc);
+	igt_pipe_crc_collect_crc(pipe_crc, &crc);
 	if (test_data->crc_must_match)
-		igt_assert(igt_crc_equal(&crcs[0], &test_data->ref_crc));
+		igt_assert(igt_crc_equal(&crc, &test_data->ref_crc));
 	else
-		igt_assert(!igt_crc_equal(&crcs[0], &test_data->ref_crc));
-	free(crcs);
+		igt_assert(!igt_crc_equal(&crc, &test_data->ref_crc));
 }
 
 static void do_test(test_data_t *test_data,
@@ -207,7 +204,6 @@ static void test_crc(test_data_t *test_data, enum cursor_type cursor_type,
 static bool prepare_crtc(test_data_t *test_data, igt_output_t *output)
 {
 	drmModeModeInfo *mode;
-	igt_crc_t *crcs = NULL;
 	data_t *data = test_data->data;
 	igt_display_t *display = &data->display;
 	igt_pipe_crc_t *pipe_crc;
@@ -249,11 +245,7 @@ static bool prepare_crtc(test_data_t *test_data, igt_output_t *output)
 	igt_wait_for_vblank(data->drm_fd, test_data->pipe);
 
 	/* get reference crc w/o cursor */
-	igt_pipe_crc_start(pipe_crc);
-	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
-	test_data->ref_crc = crcs[0];
-	igt_pipe_crc_stop(pipe_crc);
-	free(crcs);
+	igt_pipe_crc_collect_crc(pipe_crc, &test_data->ref_crc);
 
 	return true;
 }
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH 18/28 lib/display: Add support for DRM planes

In reply to Damien Lespiau

We can now extend our plane support beyond primary and cursor planes.

---
 lib/igt_kms.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/igt_kms.h |   6 +++
 2 files changed, 120 insertions(+), 2 deletions(-)
lib/igt_kms.c +114 -2
index 1933fa6..23a7318 100644
@@ -862,6 +862,7 @@ static void igt_output_refresh(igt_output_t *output)
 void igt_display_init(igt_display_t *display, int drm_fd)
 {
 	drmModeRes *resources;
+	drmModePlaneRes *plane_resources;
 	bool verbose;
 	char *env;
 	int i;
@@ -892,10 +893,13 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 	 */
 	display->n_pipes = resources->count_crtcs;
 
+	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;
+		int p, j;
 
 		pipe->display = display;
 		pipe->pipe = i;
@@ -907,6 +911,26 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 		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;
+
+			drm_plane = drmModeGetPlane(display->drm_fd,
+						    plane_resources->planes[j]);
+			igt_assert(drm_plane);
+
+			if (!(drm_plane->possible_crtcs & (1 << i))) {
+				drmModeFreePlane(drm_plane);
+				continue;
+			}
+
+			p++;
+			plane = &pipe->planes[p];
+			plane->pipe = pipe;
+			plane->index = p;
+			plane->drm_plane = drm_plane;
+		}
+
 		/* cursor plane */
 		p++;
 		plane = &pipe->planes[p];
@@ -943,6 +967,7 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 		igt_output_refresh(output);
 	}
 
+	drmModeFreePlaneResources(plane_resources);
 	drmModeFreeResources(resources);
 
 	LOG_UNINDENT(display);
@@ -958,6 +983,20 @@ int igt_display_get_n_pipes(igt_display_t *display)
 	return display->n_pipes;
 }
 
+static void igt_pipe_fini(igt_pipe_t *pipe)
+{
+	int i;
+
+	for (i = 0; i < pipe->n_planes; i++) {
+		igt_plane_t *plane = &pipe->planes[i];
+
+		if (plane->drm_plane) {
+			drmModeFreePlane(plane->drm_plane);
+			plane->drm_plane = NULL;
+		}
+	}
+}
+
 static void igt_output_fini(igt_output_t *output)
 {
 	if (output->valid)
@@ -969,6 +1008,9 @@ void igt_display_fini(igt_display_t *display)
 {
 	int i;
 
+	for (i = 0; i < display->n_pipes; i++)
+		igt_pipe_fini(&display->pipes[i]);
+
 	for (i = 0; i < display->n_outputs; i++)
 		igt_output_fini(&display->outputs[i]);
 	free(display->outputs);
@@ -1110,10 +1152,76 @@ 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)
+{
+	igt_display_t *display = output->display;
+	uint32_t fb_id, crtc_id;
+	int ret;
+
+	fb_id = igt_plane_get_fd_id(plane);
+	crtc_id = output->config.crtc->crtc_id;
+
+	if (plane->fb_changed && fb_id == 0) {
+		LOG(display,
+		    "%s: SetPlane pipe %c, plane %d, disabling\n",
+		    igt_output_name(output),
+		    pipe_name(output->config.pipe),
+		    plane->index);
+
+		ret = drmModeSetPlane(display->drm_fd,
+				      plane->drm_plane->plane_id,
+				      crtc_id,
+				      fb_id,
+				      0,    /* flags */
+				      0, 0, /* crtc_x, crtc_y */
+				      0, 0, /* crtc_w, crtc_h */
+				      IGT_FIXED(0,0), /* src_x */
+				      IGT_FIXED(0,0), /* src_y */
+				      IGT_FIXED(0,0), /* src_w */
+				      IGT_FIXED(0,0) /* src_h */);
+
+		igt_assert(ret == 0);
+
+		plane->fb_changed = false;
+	} else if (plane->fb_changed || plane->position_changed) {
+		LOG(display,
+		    "%s: SetPlane %c.%d, fb %u, position (%d, %d)\n",
+		    igt_output_name(output),
+		    pipe_name(output->config.pipe),
+		    plane->index,
+		    fb_id,
+		    plane->crtc_x, plane->crtc_y);
+
+		ret = drmModeSetPlane(display->drm_fd,
+				      plane->drm_plane->plane_id,
+				      crtc_id,
+				      fb_id,
+				      0,    /* flags */
+				      plane->crtc_x, plane->crtc_y,
+				      plane->fb->width, plane->fb->height,
+				      IGT_FIXED(0,0), /* src_x */
+				      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);
+
+		plane->fb_changed = false;
+		plane->position_changed = false;
+	}
+
+	return 0;
+}
+
 static int igt_plane_commit(igt_plane_t *plane, igt_output_t *output)
 {
-	if (plane->is_cursor)
+	if (plane->is_cursor) {
 		igt_cursor_commit(plane, output);
+	} else if (plane->is_primary) {
+		/* state updated by SetCrtc */
+	} else {
+		igt_drm_plane_commit(plane, output);
+	}
 
 	return 0;
 }
@@ -1173,6 +1281,7 @@ 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) {
@@ -1209,6 +1318,7 @@ static int igt_output_commit(igt_output_t *output)
 		igt_assert(ret == 0);
 
 		pipe->need_set_cursor = false;
+		cursor->fb_changed = false;
 	}
 
 	for (i = 0; i < pipe->n_planes; i++) {
@@ -1288,6 +1398,8 @@ void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb)
 		pipe->need_set_crtc = true;
 	else if (plane->is_cursor)
 		pipe->need_set_cursor = true;
+
+	plane->fb_changed = true;
 }
 
 void igt_plane_set_position(igt_plane_t *plane, int x, int y)
lib/igt_kms.h +6 -0
index 07cf8a2..a37f6b9 100644
@@ -116,7 +116,13 @@ typedef struct {
 	int index;
 	unsigned int is_primary       : 1;
 	unsigned int is_cursor        : 1;
+	unsigned int fb_changed       : 1;
 	unsigned int position_changed : 1;
+	/*
+	 * drm_plane can be NULL for primary and cursor planes (when not
+	 * using the atomic modeset API)
+	 */
+	drmModePlane *drm_plane;
 	struct kmstest_fb *fb;
 	/* position within pipe_src_w x pipe_src_h */
 	int crtc_x, crtc_y;
Signature · 1 line
1.8.3.1
#19 lore raw

PATCH 19/28 lib: Introduce a new helper kmstest_create_color_fb()

In reply to Damien Lespiau

We need to create fbs of a single color in a few places. Time to abstract that out to a helper function.

---
 lib/igt_kms.c | 19 +++++++++++++++++++
 lib/igt_kms.h |  4 ++++
 2 files changed, 23 insertions(+)
lib/igt_kms.c +19 -0
index 23a7318..74e52b6 100644
@@ -358,6 +358,25 @@ unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
 	return fb_id;
 }
 
+unsigned int kmstest_create_color_fb(int fd, int width, int height,
+				     uint32_t format, bool tiled,
+				     double r, double g, double b,
+				     struct kmstest_fb *fb /* out */)
+{
+	unsigned int fb_id;
+	cairo_t *cr;
+
+	fb_id = kmstest_create_fb2(fd, width, height, format, tiled, fb);
+	igt_assert(fb_id);
+
+	cr = kmstest_get_cairo_ctx(fd, fb);
+	kmstest_paint_color(cr, 0, 0, width, height, r, g, b);
+	igt_assert(cairo_status(cr) == 0);
+	cairo_destroy(cr);
+
+	return fb_id;
+}
+
 static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 {
 	struct format_desc_struct *f;
lib/igt_kms.h +4 -0
index a37f6b9..8110dad 100644
@@ -79,6 +79,10 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 			       struct kmstest_fb *fb_info);
 unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
 			        bool tiled, struct kmstest_fb *fb);
+unsigned int kmstest_create_color_fb(int fd, int width, int height,
+				     uint32_t format, bool tiled,
+				     double r, double g, double b,
+				     struct kmstest_fb *fb /* out */);
 void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
 cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
 cairo_surface_t *kmstest_get_cairo_surface(int fd, struct kmstest_fb *fb);
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH 20/28 kms_cursor_crc: Use kmstest_create_color_fb()

In reply to Damien Lespiau
---
 tests/kms_cursor_crc.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)
tests/kms_cursor_crc.c +5 -20
index a386ad9..6cdb785 100644
@@ -61,25 +61,6 @@ typedef struct {
 } test_data_t;
 
 
-static void create_fb_for_mode(data_t *data, drmModeModeInfo *mode)
-{
-	unsigned int fb_id;
-	cairo_t *cr;
-
-	fb_id = kmstest_create_fb2(data->drm_fd,
-				   mode->hdisplay, mode->vdisplay,
-				   DRM_FORMAT_XRGB8888,
-				   false, &data->primary_fb);
-	igt_assert(fb_id);
-
-	/* black */
-	cr = kmstest_get_cairo_ctx(data->drm_fd, &data->primary_fb);
-	kmstest_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
-			    0.0, 0.0, 0.0);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
-}
-
 static igt_pipe_crc_t *create_crc(data_t *data, enum pipe pipe)
 {
 	igt_pipe_crc_t *crc;
@@ -214,7 +195,11 @@ 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);
-	create_fb_for_mode(data, mode);
+	kmstest_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
+				DRM_FORMAT_XRGB8888,
+				false, /* tiled */
+				0.0, 0.0, 0.0,
+				&data->primary_fb);
 
 	primary = igt_ouput_get_plane(output, IGT_PLANE_PRIMARY);
 	igt_plane_set_fb(primary, &data->primary_fb);
Signature · 1 line
1.8.3.1
#21 lore raw

PATCH 21/28 lib: Include drm_fourcc.h from igt_kms.h

In reply to Damien Lespiau

This include is needed for the DRM_FORMAT* defines used in the fb creation helpers.

---
 lib/igt_kms.h          | 1 +
 tests/kms_cursor_crc.c | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)
lib/igt_kms.h +1 -0
index 8110dad..96dd9e4 100644
@@ -27,6 +27,7 @@
 
 #include <stdbool.h>
 
+#include <drm/drm_fourcc.h>
 #include <cairo.h>
 
 #include <igt_display.h>
tests/kms_cursor_crc.c +0 -2
index 6cdb785..e8c923f 100644
@@ -28,8 +28,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "drm_fourcc.h"
-
 #include "drmtest.h"
 #include "igt_debugfs.h"
 #include "igt_kms.h"
Signature · 1 line
1.8.3.1
#22 lore raw

PATCH 22/28 kms_pipe_crc_basic: Use kmstest_create_color_fb()

In reply to Damien Lespiau

Reducing again the per-test number of lines.

---
 tests/kms_pipe_crc_basic.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
tests/kms_pipe_crc_basic.c +6 -20
index f4de64f..8a45c5b 100644
@@ -55,25 +55,6 @@ static void test_bad_command(data_t *data, const char *cmd)
 	fclose(ctl);
 }
 
-static void create_fb_for_mode(data_t *data, drmModeModeInfo *mode)
-{
-	unsigned int fb_id;
-	cairo_t *cr;
-
-	fb_id = kmstest_create_fb(data->drm_fd,
-				  mode->hdisplay, mode->vdisplay,
-				  32 /* bpp */, 24 /* depth */,
-				  false /* tiling */,
-				  &data->fb);
-	igt_assert(fb_id);
-
-	cr = kmstest_get_cairo_ctx(data->drm_fd, &data->fb);
-	kmstest_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
-			    0.0, 1.0, 0.0);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
-}
-
 #define TEST_SEQUENCE (1<<0)
 
 static void test_read_crc(data_t *data, int pipe, unsigned flags)
@@ -95,7 +76,12 @@ static void test_read_crc(data_t *data, int pipe, unsigned flags)
 			pipe_name(pipe));
 
 		mode = igt_output_get_mode(output);
-		create_fb_for_mode(data, mode);
+		kmstest_create_color_fb(data->drm_fd,
+					mode->hdisplay, mode->vdisplay,
+					DRM_FORMAT_XRGB8888,
+					false, /* tiled */
+					0.0, 1.0, 0.0,
+					&data->fb);
 
 		primary = igt_ouput_get_plane(output, 0);
 		igt_plane_set_fb(primary, &data->fb);
Signature · 1 line
1.8.3.1
#23 lore raw

PATCH 23/28 lib: Add a helper to wait for a keypress

In reply to Damien Lespiau
---
 lib/drmtest.c | 13 +++++++++++++
 lib/drmtest.h |  2 ++
 2 files changed, 15 insertions(+)
lib/drmtest.c +13 -0
index f7262d7..f0635d3 100644
@@ -46,6 +46,7 @@
 #include <sys/types.h>
 #include <sys/syscall.h>
 #include <sys/utsname.h>
+#include <termios.h>
 
 #include "drmtest.h"
 #include "i915_drm.h"
@@ -1687,3 +1688,15 @@ void igt_drop_root(void)
 	igt_assert(getgid() == 2);
 	igt_assert(getuid() == 2);
 }
+
+void igt_wait_for_keypress(void)
+{
+	struct termios oldt, newt;
+
+	tcgetattr ( STDIN_FILENO, &oldt );
+	newt = oldt;
+	newt.c_lflag &= ~( ICANON | ECHO );
+	tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
+	getchar();
+	tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
+}
lib/drmtest.h +2 -0
index d42a6f7..af68ee8 100644
@@ -361,4 +361,6 @@ void igt_system_suspend_autoresume(void);
 /* dropping priviledges */
 void igt_drop_root(void);
 
+void igt_wait_for_keypress(void);
+
 #endif /* DRMTEST_H */
Signature · 1 line
1.8.3.1
#24 lore raw

PATCH 24/28 lib/display: Add a way to wait at every commit for inspection

In reply to Damien Lespiau
---
 lib/igt_kms.c | 3 +++
 1 file changed, 3 insertions(+)
lib/igt_kms.c +3 -0
index 74e52b6..fbbf6aa 100644
@@ -1368,6 +1368,9 @@ int igt_display_commit(igt_display_t *display)
 
 	LOG_UNINDENT(display);
 
+	if (getenv("IGT_DISPLAY_WAIT_AT_COMMIT"))
+		igt_wait_for_keypress();
+
 	return 0;
 }
 
Signature · 1 line
1.8.3.1
#25 lore raw

PATCH 25/28 lib/display: Print the fb id, not its pointer in the set_fb() log message

In reply to Damien Lespiau
---
 lib/igt_kms.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/igt_kms.c +2 -2
index fbbf6aa..7d74bf8 100644
@@ -1411,8 +1411,8 @@ void igt_plane_set_fb(igt_plane_t *plane, struct kmstest_fb *fb)
 	igt_pipe_t *pipe = plane->pipe;
 	igt_display_t *display = pipe->display;
 
-	LOG(display, "%c.%d: plane_set_fb(%p)\n", pipe_name(pipe->pipe),
-	    plane->index, fb);
+	LOG(display, "%c.%d: plane_set_fb(%d)\n", pipe_name(pipe->pipe),
+	    plane->index, fb ? fb->fb_id : 0);
 
 	plane->fb = fb;
 
Signature · 1 line
1.8.3.1
#26 lore raw

PATCH 26/28 lib/display: Wait for a vblank after SetPlane()

In reply to Damien Lespiau

Let's be testing friendly and gently wait for the next vblank before returning from commit() when needed.

After igt_display_commit() one can safely look at the CRC.

---
 lib/igt_kms.c | 8 ++++++++
 lib/igt_kms.h | 5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)
lib/igt_kms.c +8 -0
index 7d74bf8..862d8ba 100644
@@ -1174,11 +1174,13 @@ 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_fd_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,
@@ -1227,6 +1229,7 @@ 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;
@@ -1346,6 +1349,11 @@ static int igt_output_commit(igt_output_t *output)
 		igt_plane_commit(plane, output);
 	}
 
+	if (pipe->need_wait_for_vblank) {
+		igt_wait_for_vblank(display->drm_fd, pipe->pipe);
+		pipe->need_wait_for_vblank = false;
+	}
+
 	return 0;
 }
 
lib/igt_kms.h +3 -2
index 96dd9e4..8c1c0a7 100644
@@ -136,8 +136,9 @@ 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_set_crtc        : 1;
+	unsigned int need_set_cursor      : 1;
+	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.3.1
#27 lore raw

PATCH 27/28 lib/display: Fix assertion in set_plane()

In reply to Damien Lespiau

When cycling throuth planes, we still want to reach the cursor plane. We have to special case IGT_PLANE_CURSOR as a shorthand to select the cursor plane (the last plane on the pipe).

---
 lib/igt_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_kms.c +1 -1
index 862d8ba..2e5a8cb 100644
@@ -1121,7 +1121,7 @@ static igt_plane_t *igt_pipe_get_plane(igt_pipe_t *pipe, enum igt_plane plane)
 	if (plane == IGT_PLANE_CURSOR)
 		idx = pipe->n_planes - 1;
 	else {
-		igt_assert_f(plane >= 0 && plane < (pipe->n_planes - 1),
+		igt_assert_f(plane >= 0 && plane < (pipe->n_planes),
 			     "plane=%d\n", plane);
 		idx = plane;
 	}
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH 28/28 kms_plane: Start a basic display plane test

In reply to Damien Lespiau

We test the sprite plane positionning in there, for now.

---
 tests/.gitignore       |   1 +
 tests/Makefile.sources |   1 +
 tests/kms_plane.c      | 247 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 249 insertions(+)
 create mode 100644 tests/kms_plane.c
tests/.gitignore +1 -0
index bce8a42..6bb92e3 100644
@@ -110,6 +110,7 @@ kms_cursor_crc
 kms_fbc_crc
 kms_flip
 kms_pipe_crc_basic
+kms_plane
 kms_render
 kms_setmode
 pm_lpsp
tests/Makefile.sources +1 -0
index cb96b09..f9f6686 100644
@@ -58,6 +58,7 @@ TESTS_progs_M = \
 	kms_fbc_crc \
 	kms_flip \
 	kms_pipe_crc_basic \
+	kms_plane \
 	kms_render \
 	kms_setmode \
 	pm_lpsp \
tests/kms_plane.c new file +247 -0

247 lines not on this page · raw message

Signature · 1 line
1.8.3.1

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

#29 lore raw
In reply to Damien Lespiau
Quoted 3 lines · Damien Lespiau

The goal of that series is to introduce a small mode setting API to write our KMS tests, port kms_pipe_crc_basic and kms_cursor_crc to it and introduce a new kms_plane test.

So, I've pushed that series, nobdy seemed opposed to having more tests. I sprinkled a few fixes on top, including Chris' isatty() IRC comment for igt_wait_for_keypress().

Signature · 1 line
Damien