2 * Copyright © 2014 Intel Corporation
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:
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
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
30 #include "igt_debugfs.h"
35 igt_display_t display;
40 igt_pipe_crc_t *pipe_crc;
41 igt_crc_t crc_1, crc_2, crc_3, crc_4, crc_5, crc_6, crc_7, crc_8,
43 struct igt_fb red_fb, blue_fb, black_fb, yellow_fb;
44 drmModeModeInfo *mode;
49 drmModeResPtr moderes;
50 struct igt_fb blue_fb, oversized_fb, undersized_fb;
55 struct igt_fb red_fb, blue_fb;
59 functional_test_init(functional_test_t *test, igt_output_t *output, enum pipe pipe)
61 data_t *data = test->data;
62 drmModeModeInfo *mode;
64 test->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
66 igt_skip("auto crc not supported on this connector with pipe %i\n",
70 igt_output_set_pipe(output, pipe);
72 mode = igt_output_get_mode(output);
73 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
78 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
83 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
88 igt_create_color_fb(data->drm_fd, 100, 100,
98 functional_test_fini(functional_test_t *test, igt_output_t *output)
100 igt_pipe_crc_free(test->pipe_crc);
102 igt_remove_fb(test->data->drm_fd, &test->black_fb);
103 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
104 igt_remove_fb(test->data->drm_fd, &test->red_fb);
105 igt_remove_fb(test->data->drm_fd, &test->yellow_fb);
107 igt_output_set_pipe(output, PIPE_ANY);
108 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
112 * Universal plane functional testing.
113 * - Black primary plane via traditional interfaces, red sprite, grab CRC:1.
114 * - Blue primary plane via traditional interfaces, red sprite, grab CRC:2.
115 * - Yellow primary via traditional interfaces
116 * - Blue primary plane, red sprite via universal planes, grab CRC:3 and compare
117 * with CRC:2 (should be the same)
118 * - Disable primary plane, grab CRC:4 (should be same as CRC:1)
119 * - Reenable primary, grab CRC:5 (should be same as CRC:2 and CRC:3)
120 * - Yellow primary, no sprite
122 * - Program red sprite (while CRTC off)
123 * - Program blue primary (while CRTC off)
124 * - Enable CRTC, grab CRC:6 (should be same as CRC:2)
127 functional_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
129 functional_test_t test = { .data = data };
130 igt_display_t *display = &data->display;
131 igt_plane_t *primary, *sprite;
133 int num_primary = 0, num_cursor = 0;
136 igt_assert(data->display.has_universal_planes);
137 igt_skip_on(pipe >= display->n_pipes);
139 fprintf(stdout, "Testing connector %s using pipe %c\n",
140 igt_output_name(output), pipe_name(pipe));
142 functional_test_init(&test, output, pipe);
145 * Make sure we have no more than one primary or cursor plane per crtc.
146 * If the kernel accidentally calls drm_plane_init() rather than
147 * drm_universal_plane_init(), the type enum can get interpreted as a
148 * boolean and show up in userspace as the wrong type.
150 for (i = 0; i < display->pipes[pipe].n_planes; i++)
151 if (display->pipes[pipe].planes[i].is_primary)
153 else if (display->pipes[pipe].planes[i].is_cursor)
156 igt_assert(num_primary == 1);
157 igt_assert(num_cursor <= 1);
159 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
160 sprite = igt_output_get_plane(output, IGT_PLANE_2);
162 functional_test_fini(&test, output);
163 igt_skip("No sprite plane available\n");
166 igt_plane_set_position(sprite, 100, 100);
168 /* Step 1: Legacy API's, black primary, red sprite (CRC 1) */
169 igt_plane_set_fb(primary, &test.black_fb);
170 igt_plane_set_fb(sprite, &test.red_fb);
171 igt_display_commit2(display, COMMIT_LEGACY);
172 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_1);
174 /* Step 2: Legacy API', blue primary, red sprite (CRC 2) */
175 igt_plane_set_fb(primary, &test.blue_fb);
176 igt_plane_set_fb(sprite, &test.red_fb);
177 igt_display_commit2(display, COMMIT_LEGACY);
178 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_2);
180 /* Step 3: Legacy API's, yellow primary (CRC 3) */
181 igt_plane_set_fb(primary, &test.yellow_fb);
182 igt_display_commit2(display, COMMIT_LEGACY);
183 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_3);
185 /* Step 4: Universal API's, blue primary, red sprite (CRC 4) */
186 igt_plane_set_fb(primary, &test.blue_fb);
187 igt_plane_set_fb(sprite, &test.red_fb);
188 igt_display_commit2(display, COMMIT_UNIVERSAL);
189 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_4);
191 /* Step 5: Universal API's, disable primary plane (CRC 5) */
192 igt_plane_set_fb(primary, NULL);
193 igt_display_commit2(display, COMMIT_UNIVERSAL);
194 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_5);
196 /* Step 6: Universal API's, re-enable primary with blue (CRC 6) */
197 igt_plane_set_fb(primary, &test.blue_fb);
198 igt_display_commit2(display, COMMIT_UNIVERSAL);
199 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_6);
201 /* Step 7: Legacy API's, yellow primary, no sprite */
202 igt_plane_set_fb(primary, &test.yellow_fb);
203 igt_plane_set_fb(sprite, NULL);
204 igt_display_commit2(display, COMMIT_LEGACY);
206 /* Step 8: Disable CRTC */
207 igt_plane_set_fb(primary, NULL);
208 igt_display_commit2(display, COMMIT_LEGACY);
210 /* Step 9: Universal API's with crtc off:
212 * - multiple primary fb's, ending in blue
214 igt_plane_set_fb(sprite, &test.red_fb);
215 igt_display_commit2(display, COMMIT_UNIVERSAL);
216 igt_plane_set_fb(primary, &test.yellow_fb);
217 igt_display_commit2(display, COMMIT_UNIVERSAL);
218 igt_plane_set_fb(primary, &test.black_fb);
219 igt_display_commit2(display, COMMIT_UNIVERSAL);
220 igt_plane_set_fb(primary, &test.blue_fb);
221 igt_display_commit2(display, COMMIT_UNIVERSAL);
223 /* Step 10: Enable crtc (fb = -1), take CRC (CRC 7) */
224 ret = drmModeSetCrtc(data->drm_fd, output->config.crtc->crtc_id, -1,
225 0, 0, &output->config.connector->connector_id,
227 igt_assert(ret == 0);
228 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_7);
230 /* Step 11: Disable primary plane */
231 igt_plane_set_fb(primary, NULL);
232 igt_display_commit2(display, COMMIT_UNIVERSAL);
234 /* Step 12: Legacy modeset to yellow FB (CRC 8) */
235 igt_plane_set_fb(primary, &test.yellow_fb);
236 igt_display_commit2(display, COMMIT_LEGACY);
237 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_8);
239 /* Step 13: Legacy API', blue primary, red sprite */
240 igt_plane_set_fb(primary, &test.blue_fb);
241 igt_plane_set_fb(sprite, &test.red_fb);
242 igt_display_commit2(display, COMMIT_LEGACY);
244 /* Step 14: Universal API, set primary completely offscreen (CRC 9) */
245 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
246 output->config.crtc->crtc_id,
247 test.blue_fb.fb_id, 0,
251 IGT_FIXED(0,0), IGT_FIXED(0,0),
252 IGT_FIXED(test.mode->hdisplay,0),
253 IGT_FIXED(test.mode->vdisplay,0));
254 igt_assert(ret == 0);
255 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_9);
258 * Step 15: Explicitly disable primary after it's already been
259 * implicitly disabled (CRC 10).
261 igt_plane_set_fb(primary, NULL);
262 igt_display_commit2(display, COMMIT_UNIVERSAL);
263 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_10);
265 /* Step 16: Legacy API's, blue primary, red sprite */
266 igt_plane_set_fb(primary, &test.blue_fb);
267 igt_plane_set_fb(sprite, &test.red_fb);
268 igt_display_commit2(display, COMMIT_LEGACY);
270 /* Blue bg + red sprite should be same under both types of API's */
271 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_4));
273 /* Disabling primary plane should be same as black primary */
274 igt_assert(igt_crc_equal(&test.crc_1, &test.crc_5));
276 /* Re-enabling primary should return to blue properly */
277 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_6));
280 * We should be able to setup plane FB's while CRTC is disabled and
281 * then have them pop up correctly when the CRTC is re-enabled.
283 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_7));
286 * We should be able to modeset with the primary plane off
289 igt_assert(igt_crc_equal(&test.crc_3, &test.crc_8));
292 * We should be able to move the primary plane completely offscreen
293 * and have it disable successfully.
295 igt_assert(igt_crc_equal(&test.crc_5, &test.crc_9));
298 * We should be able to explicitly disable an already
299 * implicitly-disabled primary plane
301 igt_assert(igt_crc_equal(&test.crc_5, &test.crc_10));
303 igt_plane_set_fb(primary, NULL);
304 igt_plane_set_fb(sprite, NULL);
306 functional_test_fini(&test, output);
310 sanity_test_init(sanity_test_t *test, igt_output_t *output, enum pipe pipe)
312 data_t *data = test->data;
313 drmModeModeInfo *mode;
315 igt_output_set_pipe(output, pipe);
317 mode = igt_output_get_mode(output);
318 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
323 igt_create_color_fb(data->drm_fd,
324 mode->hdisplay + 100, mode->vdisplay + 100,
328 &test->oversized_fb);
329 igt_create_color_fb(data->drm_fd,
330 mode->hdisplay - 100, mode->vdisplay - 100,
334 &test->undersized_fb);
336 test->moderes = drmModeGetResources(data->drm_fd);
340 sanity_test_fini(sanity_test_t *test, igt_output_t *output)
342 drmModeFreeResources(test->moderes);
344 igt_remove_fb(test->data->drm_fd, &test->oversized_fb);
345 igt_remove_fb(test->data->drm_fd, &test->undersized_fb);
346 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
348 igt_output_set_pipe(output, PIPE_ANY);
349 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
353 * Universal plane sanity testing.
354 * - Primary doesn't cover CRTC
355 * - Primary plane tries to scale down
356 * - Primary plane tries to scale up
359 sanity_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
361 sanity_test_t test = { .data = data };
362 igt_plane_t *primary;
363 drmModeModeInfo *mode;
366 igt_output_set_pipe(output, pipe);
367 mode = igt_output_get_mode(output);
369 sanity_test_init(&test, output, pipe);
371 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
373 /* Use legacy API to set a mode with a blue FB */
374 igt_plane_set_fb(primary, &test.blue_fb);
375 igt_display_commit2(&data->display, COMMIT_LEGACY);
378 * Try to use universal plane API to set primary plane that
379 * doesn't cover CRTC (should fail).
381 igt_plane_set_fb(primary, &test.undersized_fb);
382 ret = igt_display_try_commit2(&data->display, COMMIT_UNIVERSAL);
383 igt_assert(ret == -EINVAL);
385 /* Same as above, but different plane positioning. */
386 igt_plane_set_position(primary, 100, 100);
387 ret = igt_display_try_commit2(&data->display, COMMIT_UNIVERSAL);
388 igt_assert(ret == -EINVAL);
390 igt_plane_set_position(primary, 0, 0);
392 /* Try to use universal plane API to scale down (should fail) */
393 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
394 output->config.crtc->crtc_id,
395 test.oversized_fb.fb_id, 0,
397 mode->hdisplay + 100,
398 mode->vdisplay + 100,
399 IGT_FIXED(0,0), IGT_FIXED(0,0),
400 IGT_FIXED(mode->hdisplay,0),
401 IGT_FIXED(mode->vdisplay,0));
402 igt_assert(ret == -ERANGE);
404 /* Try to use universal plane API to scale up (should fail) */
405 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
406 output->config.crtc->crtc_id,
407 test.oversized_fb.fb_id, 0,
411 IGT_FIXED(0,0), IGT_FIXED(0,0),
412 IGT_FIXED(mode->hdisplay - 100,0),
413 IGT_FIXED(mode->vdisplay - 100,0));
414 igt_assert(ret == -ERANGE);
416 /* Find other crtcs and try to program our primary plane on them */
417 for (i = 0; i < test.moderes->count_crtcs; i++)
418 if (test.moderes->crtcs[i] != output->config.crtc->crtc_id) {
419 ret = drmModeSetPlane(data->drm_fd,
420 primary->drm_plane->plane_id,
421 test.moderes->crtcs[i],
422 test.blue_fb.fb_id, 0,
426 IGT_FIXED(0,0), IGT_FIXED(0,0),
427 IGT_FIXED(mode->hdisplay,0),
428 IGT_FIXED(mode->vdisplay,0));
429 igt_assert(ret == -EINVAL);
432 igt_plane_set_fb(primary, NULL);
433 sanity_test_fini(&test, output);
437 pageflip_test_init(pageflip_test_t *test, igt_output_t *output, enum pipe pipe)
439 data_t *data = test->data;
440 drmModeModeInfo *mode;
442 igt_output_set_pipe(output, pipe);
444 mode = igt_output_get_mode(output);
445 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
450 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
458 pageflip_test_fini(pageflip_test_t *test, igt_output_t *output)
460 igt_remove_fb(test->data->drm_fd, &test->red_fb);
461 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
463 igt_output_set_pipe(output, PIPE_ANY);
464 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
468 pageflip_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
470 pageflip_test_t test = { .data = data };
471 igt_plane_t *primary;
472 struct timeval timeout = { .tv_sec = 0, .tv_usec = 500 };
473 drmEventContext evctx = { .version = DRM_EVENT_CONTEXT_VERSION };
478 igt_output_set_pipe(output, pipe);
480 pageflip_test_init(&test, output, pipe);
482 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
484 /* Use legacy API to set a mode with a blue FB */
485 igt_plane_set_fb(primary, &test.blue_fb);
486 igt_display_commit2(&data->display, COMMIT_LEGACY);
488 /* Disable the primary plane */
489 igt_plane_set_fb(primary, NULL);
490 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
493 * Issue a pageflip to red FB
495 * Note that crtc->primary->fb = NULL causes flip to return EBUSY for
496 * historical reasons...
498 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
499 test.red_fb.fb_id, 0, NULL);
500 igt_assert(ret == -EBUSY);
502 /* Turn primary plane back on */
503 igt_plane_set_fb(primary, &test.blue_fb);
504 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
507 * Issue a pageflip to red, then immediately try to disable the primary
508 * plane, hopefully before the pageflip has a chance to complete. The
509 * plane disable operation should wind up blocking while the pageflip
510 * completes, which we don't have a good way to specifically test for,
511 * but at least we can make sure that nothing blows up.
513 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
514 test.red_fb.fb_id, DRM_MODE_PAGE_FLIP_EVENT,
516 igt_assert(ret == 0);
517 igt_plane_set_fb(primary, NULL);
518 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
520 /* Wait for pageflip completion, then consume event on fd */
522 FD_SET(data->drm_fd, &fds);
524 ret = select(data->drm_fd + 1, &fds, NULL, NULL, &timeout);
525 } while (ret < 0 && errno == EINTR);
526 igt_assert(ret == 1);
527 ret = drmHandleEvent(data->drm_fd, &evctx);
528 igt_assert(ret == 0);
530 igt_plane_set_fb(primary, NULL);
531 pageflip_test_fini(&test, output);
535 run_tests_for_pipe(data_t *data, enum pipe pipe)
537 igt_output_t *output;
539 igt_subtest_f("universal-plane-pipe-%c-functional", pipe_name(pipe))
540 for_each_connected_output(&data->display, output)
541 functional_test_pipe(data, pipe, output);
543 igt_subtest_f("universal-plane-pipe-%c-sanity", pipe_name(pipe))
544 for_each_connected_output(&data->display, output)
545 sanity_test_pipe(data, pipe, output);
547 igt_subtest_f("disable-primary-vs-flip-pipe-%c", pipe_name(pipe))
548 for_each_connected_output(&data->display, output)
549 pageflip_test_pipe(data, pipe, output);
557 igt_skip_on_simulation();
560 data.drm_fd = drm_open_any();
562 igt_set_vt_graphics_mode();
564 igt_require_pipe_crc();
565 igt_display_init(&data.display, data.drm_fd);
567 igt_require(data.display.has_universal_planes);
570 for (int pipe = 0; pipe < 3; pipe++)
571 run_tests_for_pipe(&data, pipe);
574 igt_display_fini(&data.display);