@@ -1176,6 +1176,99 @@ int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id)
igt_assert(false);
}
+static inline uint32_t pipe_select(int pipe)
+{
+ if (pipe > 1)
+ return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
+ else if (pipe > 0)
+ return DRM_VBLANK_SECONDARY;
+ else
+ return 0;
+}
+
+unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags)
+{
+ union drm_wait_vblank vbl;
+
+ memset(&vbl, 0, sizeof(vbl));
+ vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe) | flags;
+ if (drmIoctl(fd, DRM_IOCTL_WAIT_VBLANK, &vbl))
+ return 0;
+
+ return vbl.reply.sequence;
+}
+
+static int parse_resolution(struct kmstest_resolution *resolution, char *info)
+{
+ char size[32];
+ int ret;
+
+ ret = sscanf(info + 4, "%d%*c %*s %*s %*s %s%*c",
+ &resolution->id, size);
+
+ if (ret != 2)
+ return -1;
+
+ ret = sscanf(size + 6, "%d%*c%d%*c",
+ &resolution->width, &resolution->height);
+
+ if (ret != 2)
+ return -1;
+
+ return ret + 1;
+}
+
+static bool get_visibility(FILE *fid, struct kmstest_resolution *resolution)
+{
+ char tmp[256];
+ struct kmstest_resolution plane;
+ int ret;
+
+ while (fgets(tmp, 256, fid) != NULL) {
+ if (strstr(tmp, "type=OVL") != NULL) {
+ ret = sscanf(tmp + 12, "%d%*c %*s %*s %d%*c%d%*c",
+ &plane.id, &plane.width, &plane.height);
+
+ igt_assert_eq(ret, 3);
+
+ if (plane.width > resolution->width)
+ return false;
+ else if (plane.height > resolution->height)
+ return false;
+ else
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool kmstest_plane_visible(void)
+{
+ char tmp[256];
+ FILE *fid;
+ bool visible = false;
+ struct kmstest_resolution resolution;
+ const char *mode = "r";
+ int ret;
+
+ fid = igt_debugfs_fopen("i915_display_info", mode);
+
+ igt_assert(fid != NULL);
+
+ while (fgets(tmp, 256, fid) != NULL) {
+ if (strstr(tmp, "active=yes") != NULL) {
+ ret = parse_resolution(&resolution, tmp);
+ igt_assert_eq(ret, 3);
+ visible = get_visibility(fid, &resolution);
+ }
+ }
+
+ fclose(fid);
+
+ return visible;
+}
+
/*
* A small modeset API
*/
@@ -132,6 +132,13 @@ struct kmstest_connector_config {
unsigned valid_crtc_idx_mask;
};
+struct kmstest_resolution {
+ int id;
+ int width;
+ int height;
+};
+
+
/**
* kmstest_force_connector_state:
* @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
@@ -177,6 +184,8 @@ uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
unsigned prot);
+unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
+bool kmstest_plane_visible(void);
/*
* A small modeset API
@@ -108,6 +108,7 @@ TESTS_progs_M = \
kms_pipe_color \
kms_pipe_crc_basic \
kms_plane \
+ kms_plane_lowres \
kms_properties \
kms_psr_sink_crc \
kms_render \
new file mode 100644
@@ -0,0 +1,394 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "igt.h"
+#include "drmtest.h"
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+IGT_TEST_DESCRIPTION("Test atomic mode setting with a plane by switching between high and low resolutions");
+
+#define MAX_CRCS 1
+#define SIZE 256
+#define LOOP_FOREVER -1
+
+typedef struct {
+ int drm_fd;
+ igt_display_t display;
+ igt_pipe_crc_t *pipe_crc;
+ igt_plane_t *plane[2];
+ struct igt_fb fb[2];
+} data_t;
+
+/* Command line parameters. */
+struct {
+ int iterations;
+} opt = {
+ .iterations = 64,
+};
+
+static drmModeModeInfo
+get_lowres_mode(int drmfd, drmModeModeInfo *mode_default)
+{
+ drmModeRes *mode_resources = drmModeGetResources(drmfd);
+ drmModeModeInfo mode;
+ drmModeModeInfo std_1024_mode = {
+ .clock = 65000,
+ .hdisplay = 1024,
+ .hsync_start = 1048,
+ .hsync_end = 1184,
+ .htotal = 1344,
+ .hskew = 0,
+ .vdisplay = 768,
+ .vsync_start = 771,
+ .vsync_end = 777,
+ .vtotal = 806,
+ .vscan = 0,
+ .vrefresh = 60,
+ .flags = 0xA,
+ .type = 0x40,
+ .name = "Custom 1024x768",
+ };
+ bool found;
+ int limit = mode_default->vdisplay-SIZE;
+ int i, j;
+
+ if (!mode_resources) {
+ igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
+ return std_1024_mode;
+ }
+
+ found = false;
+ for (i = 0; i < mode_resources->count_connectors; i++) {
+ drmModeConnector *connector;
+
+ connector = drmModeGetConnectorCurrent(drmfd,
+ mode_resources->connectors[i]);
+ if (!connector) {
+ igt_warn("could not get connector %i: %s\n",
+ mode_resources->connectors[i], strerror(errno));
+ continue;
+ }
+
+ if (!connector->count_modes)
+ continue;
+
+ igt_info("\nHigh resolution mode:\n");
+ igt_info(" name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot flags type clock\n");
+ kmstest_dump_mode(mode_default);
+
+ igt_info("\nLow resolution mode:\n");
+ igt_info(" name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot flags type clock\n");
+ for (j = 0; j < connector->count_modes; j++) {
+ mode = connector->modes[j];
+ if (mode.vdisplay < limit) {
+ kmstest_dump_mode(&connector->modes[j]);
+ found = true;
+ break;
+ }
+ }
+
+ drmModeFreeConnector(connector);
+ }
+
+ drmModeFreeResources(mode_resources);
+
+ if (!found)
+ return std_1024_mode;
+
+ return mode;
+}
+
+static void
+test_init(data_t *data, enum pipe pipe)
+{
+ data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
+}
+
+static void
+test_fini(data_t *data, igt_output_t *output)
+{
+ /* restore original mode */
+ igt_output_override_mode(output, NULL);
+
+ for (int i = 0; i < 2; i++)
+ igt_plane_set_fb(data->plane[i], NULL);
+
+ /* reset the constraint on the pipe */
+ igt_output_set_pipe(output, PIPE_ANY);
+
+ igt_pipe_crc_free(data->pipe_crc);
+}
+
+static int
+display_commit_mode(data_t *data, enum pipe pipe, int flags, igt_crc_t *crc)
+{
+ char buf[256];
+ struct drm_event *e = (void *)buf;
+ unsigned int vblank_start, vblank_stop;
+ int n, ret;
+
+ vblank_start = kmstest_get_vblank(data->display.drm_fd, pipe,
+ DRM_VBLANK_NEXTONMISS);
+
+ ret = igt_display_try_commit_atomic(&data->display,
+ flags,
+ NULL);
+ igt_skip_on(ret != 0);
+
+ igt_set_timeout(1, "Stuck on page flip");
+ ret = read(data->display.drm_fd, buf, sizeof(buf));
+ igt_assert(ret >= 0);
+
+ vblank_stop = kmstest_get_vblank(data->display.drm_fd, pipe, 0);
+ igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
+ igt_reset_timeout();
+
+ n = igt_pipe_crc_get_crcs(data->pipe_crc, vblank_stop - vblank_start,
+ &crc);
+ igt_assert_eq(n, vblank_stop - vblank_start);
+
+ return n;
+}
+
+static void
+check_mode(drmModeModeInfo *mode1, drmModeModeInfo *mode2)
+{
+ igt_assert_eq(mode1->hdisplay, mode2->hdisplay);
+ igt_assert_eq(mode1->vdisplay, mode2->vdisplay);
+ igt_assert_eq(mode1->vrefresh, mode2->vrefresh);
+}
+
+static drmModeModeInfo *
+test_setup(data_t *data, enum pipe pipe, uint64_t modifier, int flags,
+ igt_output_t *output)
+{
+ drmModeModeInfo *mode;
+ int x, y;
+
+ igt_output_set_pipe(output, pipe);
+
+ data->plane[0] = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
+ igt_skip_on(data->display.pipes[pipe].n_planes <= IGT_PLANE_PRIMARY);
+
+ data->plane[1] = igt_output_get_plane(output, IGT_PLANE_2);
+ igt_skip_on(data->display.pipes[pipe].n_planes <= IGT_PLANE_2);
+
+ mode = igt_output_get_mode(output);
+
+ x = 0;
+ y = mode->vdisplay - SIZE;
+
+ igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
+ DRM_FORMAT_XRGB8888,
+ modifier,
+ 0.0, 0.0, 1.0,
+ &data->fb[0]);
+
+ igt_plane_set_fb(data->plane[0], &data->fb[0]);
+
+ /* yellow sprite plane in lower left corner */
+ igt_create_color_fb(data->drm_fd,
+ SIZE, SIZE,
+ DRM_FORMAT_XRGB8888,
+ modifier,
+ 1.0, 1.0, 0.0,
+ &data->fb[1]);
+
+ igt_plane_set_position(data->plane[1], x, y);
+ igt_plane_set_fb(data->plane[1], &data->fb[1]);
+
+ return mode;
+}
+
+static void
+test_plane_position_with_output(data_t *data, enum pipe pipe,
+ igt_output_t *output, uint64_t modifier)
+{
+ igt_crc_t *crc_hires1, *crc_hires2;
+ igt_crc_t *crc_lowres;
+ drmModeModeInfo mode_lowres;
+ drmModeModeInfo *mode1, *mode2, *mode3;
+ int ret, i, n;
+ int iterations = opt.iterations < 1 ? 1 : opt.iterations;
+ bool loop_forever;
+ char info[256];
+ int flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_ALLOW_MODESET;
+
+ if (opt.iterations == LOOP_FOREVER) {
+ loop_forever = true;
+ sprintf(info, "forever");
+ } else {
+ loop_forever = false;
+ sprintf(info, "for %d %s",
+ iterations, iterations > 1 ? "iterations" : "iteration");
+ }
+
+ igt_info("Testing connector %s using pipe %s %s\n",
+ igt_output_name(output), kmstest_pipe_name(pipe), info);
+
+ test_init(data, pipe);
+
+ mode1 = test_setup(data, pipe, modifier, flags, output);
+
+ mode_lowres = get_lowres_mode(data->drm_fd, mode1);
+
+ igt_pipe_crc_start(data->pipe_crc);
+ ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
+ igt_skip_on(ret != 0);
+
+ n = igt_pipe_crc_get_crcs(data->pipe_crc, 1, &crc_hires1);
+ igt_assert_eq(1, n);
+
+ igt_assert_eq(kmstest_plane_visible(), true);
+
+ i = 0;
+ while (i < iterations || loop_forever) {
+ /* switch to lower resolution */
+ igt_output_override_mode(output, &mode_lowres);
+ igt_output_set_pipe(output, pipe);
+
+ mode2 = igt_output_get_mode(output);
+
+ check_mode(&mode_lowres, mode2);
+
+ display_commit_mode(data, pipe, flags, crc_lowres);
+ igt_assert_eq(kmstest_plane_visible(), false);
+
+ /* switch back to higher resolution */
+ igt_output_override_mode(output, NULL);
+ igt_output_set_pipe(output, pipe);
+
+ mode3 = igt_output_get_mode(output);
+
+ check_mode(mode1, mode3);
+
+ display_commit_mode(data, pipe, flags, crc_hires2);
+ igt_assert_eq(kmstest_plane_visible(), true);
+
+ i++;
+ }
+
+ igt_pipe_crc_stop(data->pipe_crc);
+
+ test_fini(data, output);
+}
+
+static void
+test_plane_position(data_t *data, enum pipe pipe, uint64_t modifier)
+{
+ igt_output_t *output;
+ int connected_outs;
+ int max_planes = 2;
+
+ igt_require(data->display.is_atomic);
+ igt_skip_on(pipe >= data->display.n_pipes);
+ igt_skip_on(max_planes >= data->display.pipes[pipe].n_planes);
+
+ connected_outs = 0;
+ for_each_connected_output(&data->display, output) {
+ test_plane_position_with_output(data, pipe, output, modifier);
+ connected_outs++;
+ }
+
+ igt_skip_on(connected_outs == 0);
+
+}
+
+static void
+run_tests_for_pipe(data_t *data, enum pipe pipe)
+{
+ igt_subtest_f("pipe-%s-tiling-none",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_DRM_FORMAT_MOD_NONE);
+
+ igt_subtest_f("pipe-%s-tiling-x",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_X_TILED);
+
+ igt_subtest_f("pipe-%s-tiling-y",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Y_TILED);
+
+ igt_subtest_f("pipe-%s-tiling-yf",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Yf_TILED);
+}
+
+static data_t data;
+
+static int opt_handler(int option, int option_index, void *input)
+{
+ switch (option) {
+ case 'i':
+ opt.iterations = strtol(optarg, NULL, 0);
+
+ if (opt.iterations < LOOP_FOREVER || opt.iterations == 0) {
+ igt_info("incorrect number of iterations\n");
+ igt_assert(false);
+ }
+ break;
+ default:
+ igt_assert(false);
+ }
+
+ return 0;
+}
+
+const char *help_str =
+ " --iterations Number of iterations for test coverage. -1 loop forever, default 64 iterations\n";
+
+int main(int argc, char *argv[])
+{
+ struct option long_options[] = {
+ { "iterations", required_argument, NULL, 'i'},
+ { 0, 0, 0, 0 }
+ };
+
+ igt_subtest_init_parse_opts(&argc, argv, "", long_options, help_str,
+ opt_handler, NULL);
+
+ igt_skip_on_simulation();
+
+ igt_fixture {
+ data.drm_fd = drm_open_driver_master(DRIVER_ANY);
+
+ kmstest_set_vt_graphics_mode();
+
+ igt_require_pipe_crc();
+ igt_display_init(&data.display, data.drm_fd);
+ }
+
+ for (int pipe = 0; pipe < I915_MAX_PIPES; pipe++)
+ run_tests_for_pipe(&data, pipe);
+
+ igt_fixture {
+ igt_display_fini(&data.display);
+ }
+
+ igt_exit();
+}
Testcase for plane visibility after atomic modesets. The idea of the test is the following: - draw a blue screen with high resolution - enable a yellow plane, visible, in lower-left corner - set a new lower resolution mode (1024x768) that makes plane invisible - check from debugfs 'i915_display_info' that the plane is invisible - switch back to higher resolution mode - check from debugfs 'i915_display_info' that the plane is visible again - repeat number of iterations, default 64 v2: allow test to be run on non-Intel drivers (Daniel) moved test for plane visibility to as helper function (Daniel) moved get_vblank() function to be part of helper functions (Daniel) rename 'tiling' parameter as 'modifier' (Daniel) select a mode from a list so that the plane should be invisible. use default 1024x768 mode only as a fallback if decent mode has not been found (Daniel) add tiling MODE_NONE (Daniel) Cc: Daniel Stone <daniel@fooishbar.org> Signed-off-by: Mika Kahola <mika.kahola@intel.com> --- lib/igt_kms.c | 93 +++++++++++ lib/igt_kms.h | 9 ++ tests/Makefile.sources | 1 + tests/kms_plane_lowres.c | 394 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 497 insertions(+) create mode 100644 tests/kms_plane_lowres.c