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);
65 igt_skip_on_f(!test->pipe_crc,
66 "auto crc not supported on this connector with pipe %i\n", pipe);
69 igt_output_set_pipe(output, pipe);
71 mode = igt_output_get_mode(output);
72 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
77 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
82 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
87 igt_create_color_fb(data->drm_fd, 100, 100,
97 functional_test_fini(functional_test_t *test, igt_output_t *output)
99 igt_pipe_crc_free(test->pipe_crc);
101 igt_remove_fb(test->data->drm_fd, &test->black_fb);
102 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
103 igt_remove_fb(test->data->drm_fd, &test->red_fb);
104 igt_remove_fb(test->data->drm_fd, &test->yellow_fb);
106 igt_output_set_pipe(output, PIPE_ANY);
107 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
111 * Universal plane functional testing.
112 * - Black primary plane via traditional interfaces, red sprite, grab CRC:1.
113 * - Blue primary plane via traditional interfaces, red sprite, grab CRC:2.
114 * - Yellow primary via traditional interfaces
115 * - Blue primary plane, red sprite via universal planes, grab CRC:3 and compare
116 * with CRC:2 (should be the same)
117 * - Disable primary plane, grab CRC:4 (should be same as CRC:1)
118 * - Reenable primary, grab CRC:5 (should be same as CRC:2 and CRC:3)
119 * - Yellow primary, no sprite
121 * - Program red sprite (while CRTC off)
122 * - Program blue primary (while CRTC off)
123 * - Enable CRTC, grab CRC:6 (should be same as CRC:2)
126 functional_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
128 functional_test_t test = { .data = data };
129 igt_display_t *display = &data->display;
130 igt_plane_t *primary, *sprite;
132 int num_primary = 0, num_cursor = 0;
135 igt_assert(data->display.has_universal_planes);
136 igt_skip_on(pipe >= display->n_pipes);
138 igt_info("Testing connector %s using pipe %c\n", igt_output_name(output), pipe_name(pipe));
140 functional_test_init(&test, output, pipe);
143 * Make sure we have no more than one primary or cursor plane per crtc.
144 * If the kernel accidentally calls drm_plane_init() rather than
145 * drm_universal_plane_init(), the type enum can get interpreted as a
146 * boolean and show up in userspace as the wrong type.
148 for (i = 0; i < display->pipes[pipe].n_planes; i++)
149 if (display->pipes[pipe].planes[i].is_primary)
151 else if (display->pipes[pipe].planes[i].is_cursor)
154 igt_assert(num_primary == 1);
155 igt_assert(num_cursor <= 1);
157 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
158 sprite = igt_output_get_plane(output, IGT_PLANE_2);
160 functional_test_fini(&test, output);
161 igt_skip("No sprite plane available\n");
164 igt_plane_set_position(sprite, 100, 100);
166 /* Step 1: Legacy API's, black primary, red sprite (CRC 1) */
167 igt_plane_set_fb(primary, &test.black_fb);
168 igt_plane_set_fb(sprite, &test.red_fb);
169 igt_display_commit2(display, COMMIT_LEGACY);
170 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_1);
172 /* Step 2: Legacy API', blue primary, red sprite (CRC 2) */
173 igt_plane_set_fb(primary, &test.blue_fb);
174 igt_plane_set_fb(sprite, &test.red_fb);
175 igt_display_commit2(display, COMMIT_LEGACY);
176 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_2);
178 /* Step 3: Legacy API's, yellow primary (CRC 3) */
179 igt_plane_set_fb(primary, &test.yellow_fb);
180 igt_display_commit2(display, COMMIT_LEGACY);
181 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_3);
183 /* Step 4: Universal API's, blue primary, red sprite (CRC 4) */
184 igt_plane_set_fb(primary, &test.blue_fb);
185 igt_plane_set_fb(sprite, &test.red_fb);
186 igt_display_commit2(display, COMMIT_UNIVERSAL);
187 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_4);
189 /* Step 5: Universal API's, disable primary plane (CRC 5) */
190 igt_plane_set_fb(primary, NULL);
191 igt_display_commit2(display, COMMIT_UNIVERSAL);
192 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_5);
194 /* Step 6: Universal API's, re-enable primary with blue (CRC 6) */
195 igt_plane_set_fb(primary, &test.blue_fb);
196 igt_display_commit2(display, COMMIT_UNIVERSAL);
197 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_6);
199 /* Step 7: Legacy API's, yellow primary, no sprite */
200 igt_plane_set_fb(primary, &test.yellow_fb);
201 igt_plane_set_fb(sprite, NULL);
202 igt_display_commit2(display, COMMIT_LEGACY);
204 /* Step 8: Disable CRTC */
205 igt_plane_set_fb(primary, NULL);
206 igt_display_commit2(display, COMMIT_LEGACY);
208 /* Step 9: Universal API's with crtc off:
210 * - multiple primary fb's, ending in blue
212 igt_plane_set_fb(sprite, &test.red_fb);
213 igt_display_commit2(display, COMMIT_UNIVERSAL);
214 igt_plane_set_fb(primary, &test.yellow_fb);
215 igt_display_commit2(display, COMMIT_UNIVERSAL);
216 igt_plane_set_fb(primary, &test.black_fb);
217 igt_display_commit2(display, COMMIT_UNIVERSAL);
218 igt_plane_set_fb(primary, &test.blue_fb);
219 igt_display_commit2(display, COMMIT_UNIVERSAL);
221 /* Step 10: Enable crtc (fb = -1), take CRC (CRC 7) */
222 ret = drmModeSetCrtc(data->drm_fd, output->config.crtc->crtc_id, -1,
223 0, 0, &output->config.connector->connector_id,
225 igt_assert(ret == 0);
226 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_7);
228 /* Step 11: Disable primary plane */
229 igt_plane_set_fb(primary, NULL);
230 igt_display_commit2(display, COMMIT_UNIVERSAL);
232 /* Step 12: Legacy modeset to yellow FB (CRC 8) */
233 igt_plane_set_fb(primary, &test.yellow_fb);
234 igt_display_commit2(display, COMMIT_LEGACY);
235 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_8);
237 /* Step 13: Legacy API', blue primary, red sprite */
238 igt_plane_set_fb(primary, &test.blue_fb);
239 igt_plane_set_fb(sprite, &test.red_fb);
240 igt_display_commit2(display, COMMIT_LEGACY);
242 /* Step 14: Universal API, set primary completely offscreen (CRC 9) */
243 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
244 output->config.crtc->crtc_id,
245 test.blue_fb.fb_id, 0,
249 IGT_FIXED(0,0), IGT_FIXED(0,0),
250 IGT_FIXED(test.mode->hdisplay,0),
251 IGT_FIXED(test.mode->vdisplay,0));
252 igt_assert(ret == 0);
253 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_9);
256 * Step 15: Explicitly disable primary after it's already been
257 * implicitly disabled (CRC 10).
259 igt_plane_set_fb(primary, NULL);
260 igt_display_commit2(display, COMMIT_UNIVERSAL);
261 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_10);
263 /* Step 16: Legacy API's, blue primary, red sprite */
264 igt_plane_set_fb(primary, &test.blue_fb);
265 igt_plane_set_fb(sprite, &test.red_fb);
266 igt_display_commit2(display, COMMIT_LEGACY);
268 /* Blue bg + red sprite should be same under both types of API's */
269 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_4));
271 /* Disabling primary plane should be same as black primary */
272 igt_assert(igt_crc_equal(&test.crc_1, &test.crc_5));
274 /* Re-enabling primary should return to blue properly */
275 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_6));
278 * We should be able to setup plane FB's while CRTC is disabled and
279 * then have them pop up correctly when the CRTC is re-enabled.
281 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_7));
284 * We should be able to modeset with the primary plane off
287 igt_assert(igt_crc_equal(&test.crc_3, &test.crc_8));
290 * We should be able to move the primary plane completely offscreen
291 * and have it disable successfully.
293 igt_assert(igt_crc_equal(&test.crc_5, &test.crc_9));
296 * We should be able to explicitly disable an already
297 * implicitly-disabled primary plane
299 igt_assert(igt_crc_equal(&test.crc_5, &test.crc_10));
301 igt_plane_set_fb(primary, NULL);
302 igt_plane_set_fb(sprite, NULL);
304 functional_test_fini(&test, output);
308 sanity_test_init(sanity_test_t *test, igt_output_t *output, enum pipe pipe)
310 data_t *data = test->data;
311 drmModeModeInfo *mode;
313 igt_output_set_pipe(output, pipe);
315 mode = igt_output_get_mode(output);
316 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
321 igt_create_color_fb(data->drm_fd,
322 mode->hdisplay + 100, mode->vdisplay + 100,
326 &test->oversized_fb);
327 igt_create_color_fb(data->drm_fd,
328 mode->hdisplay - 100, mode->vdisplay - 100,
332 &test->undersized_fb);
334 test->moderes = drmModeGetResources(data->drm_fd);
338 sanity_test_fini(sanity_test_t *test, igt_output_t *output)
340 drmModeFreeResources(test->moderes);
342 igt_remove_fb(test->data->drm_fd, &test->oversized_fb);
343 igt_remove_fb(test->data->drm_fd, &test->undersized_fb);
344 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
346 igt_output_set_pipe(output, PIPE_ANY);
347 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
351 * Universal plane sanity testing.
352 * - Primary doesn't cover CRTC
353 * - Primary plane tries to scale down
354 * - Primary plane tries to scale up
357 sanity_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
359 sanity_test_t test = { .data = data };
360 igt_plane_t *primary;
361 drmModeModeInfo *mode;
364 igt_output_set_pipe(output, pipe);
365 mode = igt_output_get_mode(output);
367 sanity_test_init(&test, output, pipe);
369 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
371 /* Use legacy API to set a mode with a blue FB */
372 igt_plane_set_fb(primary, &test.blue_fb);
373 igt_display_commit2(&data->display, COMMIT_LEGACY);
376 * Try to use universal plane API to set primary plane that
377 * doesn't cover CRTC (should fail).
379 igt_plane_set_fb(primary, &test.undersized_fb);
380 ret = igt_display_try_commit2(&data->display, COMMIT_UNIVERSAL);
381 igt_assert(ret == -EINVAL);
383 /* Same as above, but different plane positioning. */
384 igt_plane_set_position(primary, 100, 100);
385 ret = igt_display_try_commit2(&data->display, COMMIT_UNIVERSAL);
386 igt_assert(ret == -EINVAL);
388 igt_plane_set_position(primary, 0, 0);
390 /* Try to use universal plane API to scale down (should fail) */
391 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
392 output->config.crtc->crtc_id,
393 test.oversized_fb.fb_id, 0,
395 mode->hdisplay + 100,
396 mode->vdisplay + 100,
397 IGT_FIXED(0,0), IGT_FIXED(0,0),
398 IGT_FIXED(mode->hdisplay,0),
399 IGT_FIXED(mode->vdisplay,0));
400 igt_assert(ret == -ERANGE);
402 /* Try to use universal plane API to scale up (should fail) */
403 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
404 output->config.crtc->crtc_id,
405 test.oversized_fb.fb_id, 0,
409 IGT_FIXED(0,0), IGT_FIXED(0,0),
410 IGT_FIXED(mode->hdisplay - 100,0),
411 IGT_FIXED(mode->vdisplay - 100,0));
412 igt_assert(ret == -ERANGE);
414 /* Find other crtcs and try to program our primary plane on them */
415 for (i = 0; i < test.moderes->count_crtcs; i++)
416 if (test.moderes->crtcs[i] != output->config.crtc->crtc_id) {
417 ret = drmModeSetPlane(data->drm_fd,
418 primary->drm_plane->plane_id,
419 test.moderes->crtcs[i],
420 test.blue_fb.fb_id, 0,
424 IGT_FIXED(0,0), IGT_FIXED(0,0),
425 IGT_FIXED(mode->hdisplay,0),
426 IGT_FIXED(mode->vdisplay,0));
427 igt_assert(ret == -EINVAL);
430 igt_plane_set_fb(primary, NULL);
431 sanity_test_fini(&test, output);
435 pageflip_test_init(pageflip_test_t *test, igt_output_t *output, enum pipe pipe)
437 data_t *data = test->data;
438 drmModeModeInfo *mode;
440 igt_output_set_pipe(output, pipe);
442 mode = igt_output_get_mode(output);
443 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
448 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
456 pageflip_test_fini(pageflip_test_t *test, igt_output_t *output)
458 igt_remove_fb(test->data->drm_fd, &test->red_fb);
459 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
461 igt_output_set_pipe(output, PIPE_ANY);
462 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
466 pageflip_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
468 pageflip_test_t test = { .data = data };
469 igt_plane_t *primary;
470 struct timeval timeout = { .tv_sec = 0, .tv_usec = 500 };
471 drmEventContext evctx = { .version = DRM_EVENT_CONTEXT_VERSION };
476 igt_output_set_pipe(output, pipe);
478 pageflip_test_init(&test, output, pipe);
480 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
482 /* Use legacy API to set a mode with a blue FB */
483 igt_plane_set_fb(primary, &test.blue_fb);
484 igt_display_commit2(&data->display, COMMIT_LEGACY);
486 /* Disable the primary plane */
487 igt_plane_set_fb(primary, NULL);
488 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
491 * Issue a pageflip to red FB
493 * Note that crtc->primary->fb = NULL causes flip to return EBUSY for
494 * historical reasons...
496 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
497 test.red_fb.fb_id, 0, NULL);
498 igt_assert(ret == -EBUSY);
500 /* Turn primary plane back on */
501 igt_plane_set_fb(primary, &test.blue_fb);
502 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
505 * Issue a pageflip to red, then immediately try to disable the primary
506 * plane, hopefully before the pageflip has a chance to complete. The
507 * plane disable operation should wind up blocking while the pageflip
508 * completes, which we don't have a good way to specifically test for,
509 * but at least we can make sure that nothing blows up.
511 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
512 test.red_fb.fb_id, DRM_MODE_PAGE_FLIP_EVENT,
514 igt_assert(ret == 0);
515 igt_plane_set_fb(primary, NULL);
516 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
518 /* Wait for pageflip completion, then consume event on fd */
520 FD_SET(data->drm_fd, &fds);
522 ret = select(data->drm_fd + 1, &fds, NULL, NULL, &timeout);
523 } while (ret < 0 && errno == EINTR);
524 igt_assert(ret == 1);
525 ret = drmHandleEvent(data->drm_fd, &evctx);
526 igt_assert(ret == 0);
528 igt_plane_set_fb(primary, NULL);
529 pageflip_test_fini(&test, output);
533 run_tests_for_pipe(data_t *data, enum pipe pipe)
535 igt_output_t *output;
537 igt_subtest_f("universal-plane-pipe-%c-functional", pipe_name(pipe))
538 for_each_connected_output(&data->display, output)
539 functional_test_pipe(data, pipe, output);
541 igt_subtest_f("universal-plane-pipe-%c-sanity", pipe_name(pipe))
542 for_each_connected_output(&data->display, output)
543 sanity_test_pipe(data, pipe, output);
545 igt_subtest_f("disable-primary-vs-flip-pipe-%c", pipe_name(pipe))
546 for_each_connected_output(&data->display, output)
547 pageflip_test_pipe(data, pipe, output);
555 igt_skip_on_simulation();
558 data.drm_fd = drm_open_any();
560 igt_set_vt_graphics_mode();
562 igt_require_pipe_crc();
563 igt_display_init(&data.display, data.drm_fd);
565 igt_require(data.display.has_universal_planes);
568 for (int pipe = 0; pipe < 3; pipe++)
569 run_tests_for_pipe(&data, pipe);
572 igt_display_fini(&data.display);