1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
/*
* Copyright © 2014 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.
*
* Authors:
* Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
*/
/**
* TEST: kms flip tiling
* Category: Display
* Description: Test page flips and tiling scenarios
* Driver requirement: i915, xe
* Mega feature: General Display Features
*/
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "igt.h"
/**
* SUBTEST: flip-change-tiling
* Description: Check pageflip between modifiers
*/
IGT_TEST_DESCRIPTION("Test page flips and tiling scenarios");
typedef struct {
int drm_fd;
igt_display_t display;
int gen;
uint32_t testformat;
struct igt_fb fb[2];
struct igt_fb old_fb[2];
igt_pipe_crc_t *pipe_crc;
bool flipevent_in_queue; // if test fails may need to handle rogue event
} data_t;
static void pipe_crc_free(data_t *data)
{
if (!data->pipe_crc)
return;
igt_pipe_crc_stop(data->pipe_crc);
igt_pipe_crc_free(data->pipe_crc);
data->pipe_crc = NULL;
}
static void pipe_crc_new(data_t *data, int pipe)
{
if (data->pipe_crc)
return;
data->pipe_crc = igt_pipe_crc_new(data->drm_fd, pipe,
IGT_PIPE_CRC_SOURCE_AUTO);
igt_assert(data->pipe_crc);
igt_pipe_crc_start(data->pipe_crc);
}
static int try_commit(igt_display_t *display)
{
return igt_display_try_commit2(display, display->is_atomic ?
COMMIT_ATOMIC : COMMIT_LEGACY);
}
static uint64_t pageflip_timeout_us(drmModeModeInfo *mode)
{
uint64_t timeout_ns;
/* 1 frame for flip + 1 frame for vblank wait due to FBC. */
timeout_ns = igt_kms_frame_time_from_vrefresh(mode->vrefresh) * 2;
/* 20 msec scheduling overhead. */
timeout_ns += 20000000;
return DIV_ROUND_UP(timeout_ns, 1000);
}
static void
test_flip_tiling(data_t *data, enum pipe pipe, igt_output_t *output, uint64_t modifier[2])
{
drmModeModeInfo *mode;
igt_plane_t *primary;
igt_crc_t reference_crc, crc;
int fb_id, ret;
memcpy(&data->old_fb, &data->fb, sizeof(data->fb));
mode = igt_output_get_mode(output);
primary = igt_output_get_plane(output, 0);
fb_id = igt_create_pattern_fb(data->drm_fd,
mode->hdisplay, mode->vdisplay,
data->testformat, modifier[0],
&data->fb[0]);
igt_assert(fb_id);
/* Second fb has different background so CRC does not match. */
fb_id = igt_create_color_pattern_fb(data->drm_fd,
mode->hdisplay, mode->vdisplay,
data->testformat, modifier[1],
0.5, 0.5, 0.5, &data->fb[1]);
igt_assert(fb_id);
/* Set the crtc and generate a reference CRC. */
igt_plane_set_fb(primary, &data->fb[1]);
igt_require_f(try_commit(&data->display) == 0,
"commit failed with " IGT_MODIFIER_FMT "\n",
IGT_MODIFIER_ARGS(modifier[1]));
pipe_crc_new(data, pipe);
igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc, &reference_crc);
/* Commit the first fb. */
igt_plane_set_fb(primary, &data->fb[0]);
igt_require_f(try_commit(&data->display) == 0,
"commit failed with " IGT_MODIFIER_FMT "\n",
IGT_MODIFIER_ARGS(modifier[0]));
/* Flip to the second fb. */
ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
data->fb[1].fb_id, DRM_MODE_PAGE_FLIP_EVENT, NULL);
/*
* Page flip should work but some transitions may be temporarily
* on some kernels.
*/
igt_require(ret == 0);
data->flipevent_in_queue = true;
kmstest_wait_for_pageflip_timeout(data->drm_fd, pageflip_timeout_us(mode));
data->flipevent_in_queue = false;
/* Get a crc and compare with the reference. */
igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc, &crc);
igt_assert_crc_equal(&reference_crc, &crc);
igt_remove_fb(data->drm_fd, &data->old_fb[0]);
igt_remove_fb(data->drm_fd, &data->old_fb[1]);
}
static void test_cleanup(data_t *data, enum pipe pipe, igt_output_t *output)
{
igt_plane_t *primary;
primary = igt_output_get_plane(output, 0);
/* Clean up. */
igt_plane_set_fb(primary, NULL);
pipe_crc_free(data);
igt_output_set_pipe(output, PIPE_ANY);
igt_remove_fb(data->drm_fd, &data->fb[0]);
igt_remove_fb(data->drm_fd, &data->fb[1]);
}
static void handle_lost_event(data_t *data) {
// wait for max 5 seconds in case hit swapping or similar in progress.
drmEventContext evctx = { .version = 2 };
struct timeval timeout = { .tv_sec = 5};
fd_set fds;
int ret;
FD_ZERO(&fds);
FD_SET(data->drm_fd, &fds);
do {
errno = 0;
ret = select(data->drm_fd + 1, &fds, NULL, NULL, &timeout);
} while (ret < 0 && errno == EINTR);
// TODO: if still failed may need to reset/restart everything to
// avoid consecutive tests failing.
igt_assert(drmHandleEvent(data->drm_fd, &evctx) == 0);
data->flipevent_in_queue = false;
igt_remove_fb(data->drm_fd, &data->old_fb[0]);
igt_remove_fb(data->drm_fd, &data->old_fb[1]);
}
static data_t data = {};
igt_output_t *output;
igt_main
{
igt_fixture {
data.drm_fd = drm_open_driver_master(DRIVER_INTEL | DRIVER_XE);
data.gen = intel_display_ver(intel_get_drm_devid(data.drm_fd));
data.testformat = DRM_FORMAT_XRGB8888;
kmstest_set_vt_graphics_mode();
igt_require_pipe_crc(data.drm_fd);
igt_display_require(&data.display, data.drm_fd);
}
igt_describe("Check pageflip between modifiers");
igt_subtest_with_dynamic("flip-change-tiling") {
enum pipe pipe;
for_each_pipe_with_valid_output(&data.display, pipe, output) {
igt_plane_t *plane;
igt_display_reset(&data.display);
pipe_crc_free(&data);
igt_output_set_pipe(output, pipe);
if (!intel_pipe_output_combo_valid(&data.display))
continue;
plane = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
for (int i = 0; i < plane->format_mod_count; i++) {
if (plane->formats[i] != data.testformat)
continue;
for (int j = 0; j < plane->format_mod_count; j++) {
uint64_t modifier[2] = {
plane->modifiers[i],
plane->modifiers[j],
};
if (plane->formats[j] != data.testformat)
continue;
igt_dynamic_f("pipe-%s-%s-%s-to-%s",
kmstest_pipe_name(pipe),
igt_output_name(output),
igt_fb_modifier_name(modifier[0]),
igt_fb_modifier_name(modifier[1]))
test_flip_tiling(&data, pipe, output, modifier);
if (data.flipevent_in_queue)
handle_lost_event(&data);
}
}
test_cleanup(&data, pipe, output);
}
}
igt_fixture {
igt_display_fini(&data.display);
drm_close_driver(data.drm_fd);
}
}
|