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 %s\n", igt_output_name(output),
139 kmstest_pipe_name(pipe));
141 functional_test_init(&test, output, pipe);
144 * Make sure we have no more than one primary or cursor plane per crtc.
145 * If the kernel accidentally calls drm_plane_init() rather than
146 * drm_universal_plane_init(), the type enum can get interpreted as a
147 * boolean and show up in userspace as the wrong type.
149 for (i = 0; i < display->pipes[pipe].n_planes; i++)
150 if (display->pipes[pipe].planes[i].is_primary)
152 else if (display->pipes[pipe].planes[i].is_cursor)
155 igt_assert(num_primary == 1);
156 igt_assert(num_cursor <= 1);
158 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
159 sprite = igt_output_get_plane(output, IGT_PLANE_2);
161 functional_test_fini(&test, output);
162 igt_skip("No sprite plane available\n");
165 igt_plane_set_position(sprite, 100, 100);
167 /* Step 1: Legacy API's, black primary, red sprite (CRC 1) */
168 igt_plane_set_fb(primary, &test.black_fb);
169 igt_plane_set_fb(sprite, &test.red_fb);
170 igt_display_commit2(display, COMMIT_LEGACY);
171 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_1);
173 /* Step 2: Legacy API', blue primary, red sprite (CRC 2) */
174 igt_plane_set_fb(primary, &test.blue_fb);
175 igt_plane_set_fb(sprite, &test.red_fb);
176 igt_display_commit2(display, COMMIT_LEGACY);
177 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_2);
179 /* Step 3: Legacy API's, yellow primary (CRC 3) */
180 igt_plane_set_fb(primary, &test.yellow_fb);
181 igt_display_commit2(display, COMMIT_LEGACY);
182 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_3);
184 /* Step 4: Universal API's, blue primary, red sprite (CRC 4) */
185 igt_plane_set_fb(primary, &test.blue_fb);
186 igt_plane_set_fb(sprite, &test.red_fb);
187 igt_display_commit2(display, COMMIT_UNIVERSAL);
188 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_4);
190 /* Step 5: Universal API's, disable primary plane (CRC 5) */
191 igt_plane_set_fb(primary, NULL);
192 igt_display_commit2(display, COMMIT_UNIVERSAL);
193 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_5);
195 /* Step 6: Universal API's, re-enable primary with blue (CRC 6) */
196 igt_plane_set_fb(primary, &test.blue_fb);
197 igt_display_commit2(display, COMMIT_UNIVERSAL);
198 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_6);
200 /* Step 7: Legacy API's, yellow primary, no sprite */
201 igt_plane_set_fb(primary, &test.yellow_fb);
202 igt_plane_set_fb(sprite, NULL);
203 igt_display_commit2(display, COMMIT_LEGACY);
205 /* Step 8: Disable CRTC */
206 igt_plane_set_fb(primary, NULL);
207 igt_display_commit2(display, COMMIT_LEGACY);
209 /* Step 9: Universal API's with crtc off:
211 * - multiple primary fb's, ending in blue
213 igt_plane_set_fb(sprite, &test.red_fb);
214 igt_display_commit2(display, COMMIT_UNIVERSAL);
215 igt_plane_set_fb(primary, &test.yellow_fb);
216 igt_display_commit2(display, COMMIT_UNIVERSAL);
217 igt_plane_set_fb(primary, &test.black_fb);
218 igt_display_commit2(display, COMMIT_UNIVERSAL);
219 igt_plane_set_fb(primary, &test.blue_fb);
220 igt_display_commit2(display, COMMIT_UNIVERSAL);
222 /* Step 10: Enable crtc (fb = -1), take CRC (CRC 7) */
223 ret = drmModeSetCrtc(data->drm_fd, output->config.crtc->crtc_id, -1,
224 0, 0, &output->config.connector->connector_id,
226 igt_assert(ret == 0);
227 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_7);
229 /* Step 11: Disable primary plane */
230 igt_plane_set_fb(primary, NULL);
231 igt_display_commit2(display, COMMIT_UNIVERSAL);
233 /* Step 12: Legacy modeset to yellow FB (CRC 8) */
234 igt_plane_set_fb(primary, &test.yellow_fb);
235 igt_display_commit2(display, COMMIT_LEGACY);
236 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_8);
238 /* Step 13: Legacy API', blue primary, red sprite */
239 igt_plane_set_fb(primary, &test.blue_fb);
240 igt_plane_set_fb(sprite, &test.red_fb);
241 igt_display_commit2(display, COMMIT_LEGACY);
243 /* Step 14: Universal API, set primary completely offscreen (CRC 9) */
244 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
245 output->config.crtc->crtc_id,
246 test.blue_fb.fb_id, 0,
250 IGT_FIXED(0,0), IGT_FIXED(0,0),
251 IGT_FIXED(test.mode->hdisplay,0),
252 IGT_FIXED(test.mode->vdisplay,0));
253 igt_assert(ret == 0);
254 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_9);
257 * Step 15: Explicitly disable primary after it's already been
258 * implicitly disabled (CRC 10).
260 igt_plane_set_fb(primary, NULL);
261 igt_display_commit2(display, COMMIT_UNIVERSAL);
262 igt_pipe_crc_collect_crc(test.pipe_crc, &test.crc_10);
264 /* Step 16: Legacy API's, blue primary, red sprite */
265 igt_plane_set_fb(primary, &test.blue_fb);
266 igt_plane_set_fb(sprite, &test.red_fb);
267 igt_display_commit2(display, COMMIT_LEGACY);
269 /* Blue bg + red sprite should be same under both types of API's */
270 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_4));
272 /* Disabling primary plane should be same as black primary */
273 igt_assert(igt_crc_equal(&test.crc_1, &test.crc_5));
275 /* Re-enabling primary should return to blue properly */
276 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_6));
279 * We should be able to setup plane FB's while CRTC is disabled and
280 * then have them pop up correctly when the CRTC is re-enabled.
282 igt_assert(igt_crc_equal(&test.crc_2, &test.crc_7));
285 * We should be able to modeset with the primary plane off
288 igt_assert(igt_crc_equal(&test.crc_3, &test.crc_8));
291 * We should be able to move the primary plane completely offscreen
292 * and have it disable successfully.
294 igt_assert(igt_crc_equal(&test.crc_5, &test.crc_9));
297 * We should be able to explicitly disable an already
298 * implicitly-disabled primary plane
300 igt_assert(igt_crc_equal(&test.crc_5, &test.crc_10));
302 igt_plane_set_fb(primary, NULL);
303 igt_plane_set_fb(sprite, NULL);
305 functional_test_fini(&test, output);
309 sanity_test_init(sanity_test_t *test, igt_output_t *output, enum pipe pipe)
311 data_t *data = test->data;
312 drmModeModeInfo *mode;
314 igt_output_set_pipe(output, pipe);
316 mode = igt_output_get_mode(output);
317 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
322 igt_create_color_fb(data->drm_fd,
323 mode->hdisplay + 100, mode->vdisplay + 100,
327 &test->oversized_fb);
328 igt_create_color_fb(data->drm_fd,
329 mode->hdisplay - 100, mode->vdisplay - 100,
333 &test->undersized_fb);
335 test->moderes = drmModeGetResources(data->drm_fd);
339 sanity_test_fini(sanity_test_t *test, igt_output_t *output)
341 drmModeFreeResources(test->moderes);
343 igt_remove_fb(test->data->drm_fd, &test->oversized_fb);
344 igt_remove_fb(test->data->drm_fd, &test->undersized_fb);
345 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
347 igt_output_set_pipe(output, PIPE_ANY);
348 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
352 * Universal plane sanity testing.
353 * - Primary doesn't cover CRTC
354 * - Primary plane tries to scale down
355 * - Primary plane tries to scale up
358 sanity_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
360 sanity_test_t test = { .data = data };
361 igt_plane_t *primary;
362 drmModeModeInfo *mode;
365 igt_output_set_pipe(output, pipe);
366 mode = igt_output_get_mode(output);
368 sanity_test_init(&test, output, pipe);
370 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
372 /* Use legacy API to set a mode with a blue FB */
373 igt_plane_set_fb(primary, &test.blue_fb);
374 igt_display_commit2(&data->display, COMMIT_LEGACY);
377 * Try to use universal plane API to set primary plane that
378 * doesn't cover CRTC (should fail).
380 igt_plane_set_fb(primary, &test.undersized_fb);
381 ret = igt_display_try_commit2(&data->display, COMMIT_UNIVERSAL);
382 igt_assert(ret == -EINVAL);
384 /* Same as above, but different plane positioning. */
385 igt_plane_set_position(primary, 100, 100);
386 ret = igt_display_try_commit2(&data->display, COMMIT_UNIVERSAL);
387 igt_assert(ret == -EINVAL);
389 igt_plane_set_position(primary, 0, 0);
391 /* Try to use universal plane API to scale down (should fail) */
392 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
393 output->config.crtc->crtc_id,
394 test.oversized_fb.fb_id, 0,
396 mode->hdisplay + 100,
397 mode->vdisplay + 100,
398 IGT_FIXED(0,0), IGT_FIXED(0,0),
399 IGT_FIXED(mode->hdisplay,0),
400 IGT_FIXED(mode->vdisplay,0));
401 igt_assert(ret == -ERANGE);
403 /* Try to use universal plane API to scale up (should fail) */
404 ret = drmModeSetPlane(data->drm_fd, primary->drm_plane->plane_id,
405 output->config.crtc->crtc_id,
406 test.oversized_fb.fb_id, 0,
410 IGT_FIXED(0,0), IGT_FIXED(0,0),
411 IGT_FIXED(mode->hdisplay - 100,0),
412 IGT_FIXED(mode->vdisplay - 100,0));
413 igt_assert(ret == -ERANGE);
415 /* Find other crtcs and try to program our primary plane on them */
416 for (i = 0; i < test.moderes->count_crtcs; i++)
417 if (test.moderes->crtcs[i] != output->config.crtc->crtc_id) {
418 ret = drmModeSetPlane(data->drm_fd,
419 primary->drm_plane->plane_id,
420 test.moderes->crtcs[i],
421 test.blue_fb.fb_id, 0,
425 IGT_FIXED(0,0), IGT_FIXED(0,0),
426 IGT_FIXED(mode->hdisplay,0),
427 IGT_FIXED(mode->vdisplay,0));
428 igt_assert(ret == -EINVAL);
431 igt_plane_set_fb(primary, NULL);
432 sanity_test_fini(&test, output);
436 pageflip_test_init(pageflip_test_t *test, igt_output_t *output, enum pipe pipe)
438 data_t *data = test->data;
439 drmModeModeInfo *mode;
441 igt_output_set_pipe(output, pipe);
443 mode = igt_output_get_mode(output);
444 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
449 igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
457 pageflip_test_fini(pageflip_test_t *test, igt_output_t *output)
459 igt_remove_fb(test->data->drm_fd, &test->red_fb);
460 igt_remove_fb(test->data->drm_fd, &test->blue_fb);
462 igt_output_set_pipe(output, PIPE_ANY);
463 igt_display_commit2(&test->data->display, COMMIT_LEGACY);
467 pageflip_test_pipe(data_t *data, enum pipe pipe, igt_output_t *output)
469 pageflip_test_t test = { .data = data };
470 igt_plane_t *primary;
471 struct timeval timeout = { .tv_sec = 0, .tv_usec = 500 };
472 drmEventContext evctx = { .version = DRM_EVENT_CONTEXT_VERSION };
477 igt_output_set_pipe(output, pipe);
479 pageflip_test_init(&test, output, pipe);
481 primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
483 /* Use legacy API to set a mode with a blue FB */
484 igt_plane_set_fb(primary, &test.blue_fb);
485 igt_display_commit2(&data->display, COMMIT_LEGACY);
487 /* Disable the primary plane */
488 igt_plane_set_fb(primary, NULL);
489 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
492 * Issue a pageflip to red FB
494 * Note that crtc->primary->fb = NULL causes flip to return EBUSY for
495 * historical reasons...
497 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
498 test.red_fb.fb_id, 0, NULL);
499 igt_assert(ret == -EBUSY);
501 /* Turn primary plane back on */
502 igt_plane_set_fb(primary, &test.blue_fb);
503 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
506 * Issue a pageflip to red, then immediately try to disable the primary
507 * plane, hopefully before the pageflip has a chance to complete. The
508 * plane disable operation should wind up blocking while the pageflip
509 * completes, which we don't have a good way to specifically test for,
510 * but at least we can make sure that nothing blows up.
512 ret = drmModePageFlip(data->drm_fd, output->config.crtc->crtc_id,
513 test.red_fb.fb_id, DRM_MODE_PAGE_FLIP_EVENT,
515 igt_assert(ret == 0);
516 igt_plane_set_fb(primary, NULL);
517 igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
519 /* Wait for pageflip completion, then consume event on fd */
521 FD_SET(data->drm_fd, &fds);
523 ret = select(data->drm_fd + 1, &fds, NULL, NULL, &timeout);
524 } while (ret < 0 && errno == EINTR);
525 igt_assert(ret == 1);
526 ret = drmHandleEvent(data->drm_fd, &evctx);
527 igt_assert(ret == 0);
529 igt_plane_set_fb(primary, NULL);
530 pageflip_test_fini(&test, output);
534 run_tests_for_pipe(data_t *data, enum pipe pipe)
536 igt_output_t *output;
538 igt_subtest_f("universal-plane-pipe-%s-functional",
539 kmstest_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-%s-sanity",
544 kmstest_pipe_name(pipe))
545 for_each_connected_output(&data->display, output)
546 sanity_test_pipe(data, pipe, output);
548 igt_subtest_f("disable-primary-vs-flip-pipe-%s",
549 kmstest_pipe_name(pipe))
550 for_each_connected_output(&data->display, output)
551 pageflip_test_pipe(data, pipe, output);
559 igt_skip_on_simulation();
562 data.drm_fd = drm_open_any();
564 igt_set_vt_graphics_mode();
566 igt_require_pipe_crc();
567 igt_display_init(&data.display, data.drm_fd);
569 igt_require(data.display.has_universal_planes);
572 for (int pipe = 0; pipe < 3; pipe++)
573 run_tests_for_pipe(&data, pipe);
576 igt_display_fini(&data.display);