blob: 1bcf8469088efa4ed8d6044c1382d48dddb8f9e1 [file] [log] [blame]
Ville Syrjäläa7882a32015-12-18 14:21:27 +02001/*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24
25#include "igt.h"
26#include <errno.h>
27#include <limits.h>
28#include <stdbool.h>
29#include <stdio.h>
30#include <string.h>
31
32IGT_TEST_DESCRIPTION("Exercise CHV pipe C cursor fail");
33
34#ifndef DRM_CAP_CURSOR_WIDTH
35#define DRM_CAP_CURSOR_WIDTH 0x8
36#endif
37#ifndef DRM_CAP_CURSOR_HEIGHT
38#define DRM_CAP_CURSOR_HEIGHT 0x9
39#endif
40
41typedef struct {
42 int drm_fd;
43 igt_display_t display;
44 struct igt_fb primary_fb;
45 struct igt_fb fb;
46 igt_output_t *output;
47 enum pipe pipe;
48 igt_crc_t ref_crc;
49 int curw, curh; /* cursor size */
50 igt_pipe_crc_t *pipe_crc;
51 uint32_t devid;
52 bool colored, jump, disable;
53 int jump_x, jump_y;
54} data_t;
55
56enum {
57 EDGE_LEFT = 0x1,
58 EDGE_RIGHT = 0x2,
59 EDGE_TOP = 0x4,
60 EDGE_BOTTOM = 0x8,
61};
62
63static void cursor_disable(data_t *data)
64{
65 igt_output_t *output = data->output;
66 igt_plane_t *cursor;
67
Robert Foss6933e4d2017-01-10 18:41:57 -050068 cursor = igt_output_get_plane_type(output, DRM_PLANE_TYPE_CURSOR);
Ville Syrjäläa7882a32015-12-18 14:21:27 +020069 igt_plane_set_fb(cursor, NULL);
70}
71
72static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
73{
74 cairo_t *cr;
75 uint32_t fb_id;
76
77 fb_id = igt_create_fb(data->drm_fd, cur_w, cur_h,
78 DRM_FORMAT_ARGB8888,
79 LOCAL_DRM_FORMAT_MOD_NONE,
80 &data->fb);
81 igt_assert(fb_id);
82
83 cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
84 if (data->colored)
85 igt_paint_color_alpha(cr, 0, 0, data->fb.width, data->fb.height,
86 1.0, 0.0, 0.0, 1.0);
87 else
88 igt_paint_color_alpha(cr, 0, 0, data->fb.width, data->fb.height,
89 0.0, 0.0, 0.0, 0.0);
Maarten Lankhorstbe2f6fc2018-02-01 12:48:45 +010090 igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
Ville Syrjäläa7882a32015-12-18 14:21:27 +020091}
92
93static void cursor_move(data_t *data, int x, int y, int i)
94{
95 int crtc_id = data->output->config.crtc->crtc_id;
96
97 igt_debug("[%d] x=%d, y=%d\n", i, x, y);
98
99 /*
100 * The "fixed" kernel will refuse the ioctl when pipe C cursor
101 * would straddle the left screen edge (which is when the hw
102 * fails). So let's accept a failure from the ioctl in that case.
103 */
104 igt_assert(drmModeMoveCursor(data->drm_fd, crtc_id, x, y) == 0 ||
105 (IS_CHERRYVIEW(data->devid) && data->pipe == PIPE_C &&
106 x < 0 && x > -data->curw));
107 igt_wait_for_vblank(data->drm_fd, data->pipe);
108}
109
110#define XSTEP 8
Maarten Lankhorst39164652016-06-08 13:23:27 +0200111#define YSTEP 8
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200112#define NCRC 128
113
114static void test_edge_pos(data_t *data, int sx, int ex, int y, bool swap_axis)
115{
116 igt_crc_t *crc = NULL;
Maarten Lankhorst39164652016-06-08 13:23:27 +0200117 int i, n, x, xdir, dx;
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200118
119 if (sx > ex)
120 xdir = -1;
121 else
122 xdir = 1;
123
Maarten Lankhorst39164652016-06-08 13:23:27 +0200124 dx = (ex - sx)/XSTEP;
125
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200126 igt_pipe_crc_start(data->pipe_crc);
127
128 i = 0;
Maarten Lankhorst39164652016-06-08 13:23:27 +0200129
130 for (x = sx; xdir * (x - ex) <= 0; x += dx) {
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200131 int xx, yy;
132
133 if (swap_axis) {
134 xx = y;
135 yy = x;
136 } else {
137 xx = x;
138 yy = y;
139 }
140
141 if (data->jump) {
142 cursor_move(data, data->jump_x, data->jump_y, i++);
143 }
144 if (data->disable) {
145 cursor_move(data, -data->curw, -data->curh, i++);
146 }
147 cursor_move(data, xx, yy, i++);
148 if (data->jump) {
149 cursor_move(data, data->jump_x, data->jump_y, i++);
150 }
151 if (data->disable) {
152 cursor_move(data, -data->curw, -data->curh, i++);
153 }
154 }
155
156 n = igt_pipe_crc_get_crcs(data->pipe_crc, NCRC, &crc);
157 igt_pipe_crc_stop(data->pipe_crc);
158
159 if (!data->colored) {
160 igt_debug("Checking CRCs: ");
161 for (i = 0; i < n; i++) {
162 igt_debug("[%d] ", i);
163 igt_assert_crc_equal(&data->ref_crc, &crc[i]);
164 }
165 igt_debug("\n");
166 }
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200167}
168
169static void test_edge(data_t *data, int sy, int ey, int sx, int ex, bool swap_axis)
170{
171 int crtc_id = data->output->config.crtc->crtc_id;
Maarten Lankhorst39164652016-06-08 13:23:27 +0200172 int y, ydir, dy;
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200173
174 if (sy > ey)
175 ydir = -1;
176 else
177 ydir = 1;
178
Maarten Lankhorst39164652016-06-08 13:23:27 +0200179 dy = (ey - sy) / YSTEP;
180
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200181 igt_assert_eq(drmModeMoveCursor(data->drm_fd, crtc_id, -data->curw, -data->curh), 0);
182 igt_assert_eq(drmModeSetCursor(data->drm_fd, crtc_id, data->fb.gem_handle, data->curw, data->curh), 0);
183
184 for (y = sy; ydir * (y - ey) <= 0; ) {
185 test_edge_pos(data, sx, ex, y, swap_axis);
Maarten Lankhorst39164652016-06-08 13:23:27 +0200186 y += dy;
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200187 test_edge_pos(data, ex, sx, y, swap_axis);
Maarten Lankhorst39164652016-06-08 13:23:27 +0200188 y += dy;
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200189 }
190
191 igt_assert_eq(drmModeMoveCursor(data->drm_fd, crtc_id, -data->curw, -data->curh), 0);
192 igt_assert_eq(drmModeSetCursor(data->drm_fd, crtc_id, 0, data->curw, data->curh), 0);
193}
194
195static void test_edges(data_t *data, unsigned int edges)
196{
197 drmModeModeInfo *mode = igt_output_get_mode(data->output);
198
199 if (edges & EDGE_LEFT) {
200 test_edge(data, mode->vdisplay, -data->curh,
201 -data->curw, 0, false);
202 test_edge(data, -data->curh, mode->vdisplay,
203 -data->curw, 0, false);
204 }
205
206 if (edges & EDGE_RIGHT) {
207 test_edge(data, mode->vdisplay, -data->curh,
208 mode->hdisplay - data->curw, mode->hdisplay, false);
209 test_edge(data, -data->curh, mode->vdisplay,
210 mode->hdisplay - data->curw, mode->hdisplay, false);
211 }
212
213 if (edges & EDGE_TOP) {
214 test_edge(data, mode->hdisplay, -data->curw,
215 -data->curh, 0, true);
216 test_edge(data, -data->curw, mode->hdisplay,
217 -data->curh, 0, true);
218 }
219
220 if (edges & EDGE_BOTTOM) {
221 test_edge(data, mode->hdisplay, -data->curw,
222 mode->vdisplay - data->curh, mode->vdisplay, true);
223 test_edge(data, -data->curw, mode->hdisplay,
224 mode->vdisplay - data->curh, mode->vdisplay, true);
225 }
226}
227
Maarten Lankhorst9688fdb2017-01-05 14:10:49 +0100228static void prepare_crtc(data_t *data)
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200229{
230 drmModeModeInfo *mode;
231 igt_display_t *display = &data->display;
232 igt_plane_t *primary;
233
234 /* select the pipe we want to use */
235 igt_output_set_pipe(data->output, data->pipe);
236 cursor_disable(data);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200237
238 mode = igt_output_get_mode(data->output);
239 igt_create_pattern_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
240 DRM_FORMAT_XRGB8888,
241 LOCAL_DRM_FORMAT_MOD_NONE,
242 &data->primary_fb);
243
Robert Foss6933e4d2017-01-10 18:41:57 -0500244 primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200245 igt_plane_set_fb(primary, &data->primary_fb);
246
247 igt_display_commit(display);
248
249 data->jump_x = (mode->hdisplay - data->curw) / 2;
250 data->jump_y = (mode->vdisplay - data->curh) / 2;
251
252 /* create the pipe_crc object for this pipe */
253 if (data->pipe_crc)
254 igt_pipe_crc_free(data->pipe_crc);
255
Chris Wilson83884e92017-03-21 17:16:03 +0000256 data->pipe_crc = igt_pipe_crc_new_nonblock(data->drm_fd, data->pipe,
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200257 INTEL_PIPE_CRC_SOURCE_AUTO);
258
259 /* make sure cursor is disabled */
260 cursor_disable(data);
261 igt_wait_for_vblank(data->drm_fd, data->pipe);
262
263 /* get reference crc w/o cursor */
264 igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
265 igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
266 igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200267}
268
269static void cleanup_crtc(data_t *data)
270{
271 igt_display_t *display = &data->display;
272 igt_plane_t *primary;
273
274 igt_pipe_crc_free(data->pipe_crc);
275 data->pipe_crc = NULL;
276
277 igt_remove_fb(data->drm_fd, &data->primary_fb);
278
Robert Foss6933e4d2017-01-10 18:41:57 -0500279 primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200280 igt_plane_set_fb(primary, NULL);
281
282 igt_output_set_pipe(data->output, PIPE_ANY);
283 igt_display_commit(display);
284}
285
286static void test_crtc(data_t *data, unsigned int edges)
287{
288 igt_display_t *display = &data->display;
289 int valid_tests = 0;
290
291 create_cursor_fb(data, data->curw, data->curh);
292
Maarten Lankhorst9688fdb2017-01-05 14:10:49 +0100293 for_each_valid_output_on_pipe(display, data->pipe, data->output) {
294 prepare_crtc(data);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200295
296 valid_tests++;
297
298 igt_info("Beginning %s on pipe %s, connector %s\n",
299 igt_subtest_name(),
300 kmstest_pipe_name(data->pipe),
301 igt_output_name(data->output));
302
303 test_edges(data, edges);
304
305 igt_info("\n%s on pipe %s, connector %s: PASSED\n\n",
306 igt_subtest_name(),
307 kmstest_pipe_name(data->pipe),
308 igt_output_name(data->output));
309
310 /* cleanup what prepare_crtc() has done */
311 cleanup_crtc(data);
312 }
313
314 igt_remove_fb(data->drm_fd, &data->fb);
315
316 igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
317}
318
319static int opt_handler(int opt, int opt_index, void *_data)
320{
321 data_t *data = _data;
322
323 switch (opt) {
324 case 'c':
325 data->colored = true;
326 break;
327 case 'd':
328 data->disable = true;
329 break;
330 case 'j':
331 data->jump = true;
332 break;
333 default:
334 break;
335 }
336
337 return 0;
338}
339
340static data_t data;
341static uint64_t max_curw = 64, max_curh = 64;
342
343int main(int argc, char **argv)
344{
345 static const struct option long_opts[] = {
346 { .name = "colored", .val = 'c' },
347 { .name = "disable", .val = 'd'},
348 { .name = "jump", .val = 'j' },
349 {}
350 };
351 static const char *help_str =
352 " --colored\t\tUse a colored cursor (disables CRC checks)\n"
353 " --disable\t\tDisable the cursor between each step\n"
354 " --jump\t\tJump the cursor to middle of the screen between each step)\n";
355
356 igt_subtest_init_parse_opts(&argc, argv, "", long_opts, help_str,
357 opt_handler, &data);
358
359 igt_skip_on_simulation();
360
361 igt_fixture {
362 int ret;
363
364 data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
365
366 data.devid = intel_get_drm_devid(data.drm_fd);
367
368 ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_WIDTH, &max_curw);
369 igt_assert(ret == 0 || errno == EINVAL);
370 /* Not making use of cursor_height since it is same as width, still reading */
371 ret = drmGetCap(data.drm_fd, DRM_CAP_CURSOR_HEIGHT, &max_curh);
372 igt_assert(ret == 0 || errno == EINVAL);
373
374 kmstest_set_vt_graphics_mode();
375
Chris Wilson83884e92017-03-21 17:16:03 +0000376 igt_require_pipe_crc(data.drm_fd);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200377
378 igt_display_init(&data.display, data.drm_fd);
379 }
380
381 for (data.curw = 64; data.curw <= 256; data.curw *= 2) {
382 data.curh = data.curw;
383 for (data.pipe = PIPE_A; data.pipe <= PIPE_C; data.pipe++) {
384 igt_subtest_f("pipe-%s-%dx%d-left-edge",
385 kmstest_pipe_name(data.pipe),
386 data.curw, data.curh) {
Ville Syrjälä065d7362016-01-08 20:37:51 +0200387 igt_require(data.pipe < data.display.n_pipes);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200388 igt_require(data.curw <= max_curw && data.curh <= max_curh);
389 test_crtc(&data, EDGE_LEFT);
390 }
391 igt_subtest_f("pipe-%s-%dx%d-right-edge",
392 kmstest_pipe_name(data.pipe),
393 data.curw, data.curh) {
Ville Syrjälä065d7362016-01-08 20:37:51 +0200394 igt_require(data.pipe < data.display.n_pipes);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200395 igt_require(data.curw <= max_curw && data.curh <= max_curh);
396 test_crtc(&data, EDGE_RIGHT);
397 }
398 igt_subtest_f("pipe-%s-%dx%d-top-edge",
399 kmstest_pipe_name(data.pipe),
400 data.curw, data.curh) {
Ville Syrjälä065d7362016-01-08 20:37:51 +0200401 igt_require(data.pipe < data.display.n_pipes);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200402 igt_require(data.curw <= max_curw && data.curh <= max_curh);
403 test_crtc(&data, EDGE_TOP);
404 }
405 igt_subtest_f("pipe-%s-%dx%d-bottom-edge",
406 kmstest_pipe_name(data.pipe),
407 data.curw, data.curh) {
Ville Syrjälä065d7362016-01-08 20:37:51 +0200408 igt_require(data.pipe < data.display.n_pipes);
Ville Syrjäläa7882a32015-12-18 14:21:27 +0200409 igt_require(data.curw <= max_curw && data.curh <= max_curh);
410 test_crtc(&data, EDGE_BOTTOM);
411 }
412 }
413 }
414
415 igt_fixture
416 igt_display_fini(&data.display);
417
418 igt_exit();
419}