blob: 94d74ecab4dc548f03699cfb5e8ffe8449940365 [file] [log] [blame]
Rodrigo Vivi27d37a12014-03-19 22:43:51 -03001/*
2 * Copyright © 2013 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 <errno.h>
26#include <stdbool.h>
27#include <stdio.h>
28#include <string.h>
29
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030030#include "ioctl_wrappers.h"
31#include "drmtest.h"
32#include "intel_bufmgr.h"
33#include "intel_batchbuffer.h"
34#include "intel_chipset.h"
35#include "igt_debugfs.h"
36#include "igt_kms.h"
Rodrigo Vivi1ab04452014-08-29 17:58:31 -040037#include "igt_aux.h"
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030038
Rodrigo Vivi99efdc02014-09-09 17:58:45 -040039bool running_with_psr_disabled;
40
Rodrigo Vivi25aa69d2014-09-09 13:10:51 -040041#define CRC_BLACK "000000000000"
42
Rodrigo Vivi99efdc02014-09-09 17:58:45 -040043enum planes {
44 PRIMARY,
45 SPRITE,
46 CURSOR,
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030047};
48
Rodrigo Vivi99efdc02014-09-09 17:58:45 -040049enum operations {
50 PAGE_FLIP,
51 MMAP_GTT,
52 MMAP_GTT_WAITING,
53 MMAP_CPU,
54 BLT,
55 RENDER,
56 PLANE_MOVE,
57 PLANE_ONOFF,
58};
59
60static const char *op_str(enum operations op)
61{
62 static const char * const name[] = {
63 [PAGE_FLIP] = "page_flip",
64 [MMAP_GTT] = "mmap_gtt",
65 [MMAP_GTT_WAITING] = "mmap_gtt_waiting",
66 [MMAP_CPU] = "mmap_cpu",
67 [BLT] = "blt",
68 [RENDER] = "render",
69 [PLANE_MOVE] = "plane_move",
70 [PLANE_ONOFF] = "plane_onoff",
71 };
72
73 return name[op];
74}
Rodrigo Vivi1ab04452014-08-29 17:58:31 -040075
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030076typedef struct {
77 int drm_fd;
Rodrigo Vivi99efdc02014-09-09 17:58:45 -040078 enum planes test_plane;
79 enum operations op;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030080 uint32_t devid;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030081 uint32_t crtc_id;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030082 igt_display_t display;
Rodrigo Vivid4e6a512014-08-29 19:12:54 -040083 drm_intel_bufmgr *bufmgr;
84 struct igt_fb fb_green, fb_white;
85 igt_plane_t *primary, *sprite, *cursor;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030086} data_t;
87
Rodrigo Vivid4e6a512014-08-29 19:12:54 -040088static void create_cursor_fb(data_t *data)
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030089{
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030090 cairo_t *cr;
Rodrigo Vivid4e6a512014-08-29 19:12:54 -040091 uint32_t fb_id;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030092
Rodrigo Vivid4e6a512014-08-29 19:12:54 -040093 fb_id = igt_create_fb(data->drm_fd, 64, 64,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +000094 DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
Rodrigo Vivid4e6a512014-08-29 19:12:54 -040095 &data->fb_white);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030096 igt_assert(fb_id);
97
Rodrigo Vivid4e6a512014-08-29 19:12:54 -040098 cr = igt_get_cairo_ctx(data->drm_fd, &data->fb_white);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -030099 igt_paint_color_alpha(cr, 0, 0, 64, 64, 1.0, 1.0, 1.0, 1.0);
100 igt_assert(cairo_status(cr) == 0);
101}
102
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300103static void display_init(data_t *data)
104{
105 igt_display_init(&data->display, data->drm_fd);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300106}
107
108static void display_fini(data_t *data)
109{
110 igt_display_fini(&data->display);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300111}
112
113static void fill_blt(data_t *data, uint32_t handle, unsigned char color)
114{
115 drm_intel_bo *dst = gem_handle_to_libdrm_bo(data->bufmgr,
116 data->drm_fd,
117 "", handle);
118 struct intel_batchbuffer *batch;
119
120 batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
121 igt_assert(batch);
122
Chris Wilson10552b52014-08-30 11:44:51 +0100123 COLOR_BLIT_COPY_BATCH_START(0);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300124 OUT_BATCH((1 << 24) | (0xf0 << 16) | 0);
Rodrigo Vivi1447d832014-09-03 18:18:15 -0400125 OUT_BATCH(0);
Rodrigo Vivi3cb21242014-12-05 19:43:34 -0500126 OUT_BATCH(0xfff << 16 | 0xfff);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300127 OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
128 OUT_BATCH(color);
129 ADVANCE_BATCH();
130
131 intel_batchbuffer_flush(batch);
132 intel_batchbuffer_free(batch);
133
134 gem_bo_busy(data->drm_fd, handle);
135}
136
137static void scratch_buf_init(struct igt_buf *buf, drm_intel_bo *bo)
138{
139 buf->bo = bo;
140 buf->stride = 4096;
141 buf->tiling = I915_TILING_X;
Rodrigo Vivif20690d2014-12-05 19:45:37 -0500142 buf->size = 64 * 4096;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300143}
144
Rodrigo Vivifb004a62014-09-03 17:53:35 -0400145static void fill_render(data_t *data, uint32_t handle, unsigned char color)
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300146{
147 drm_intel_bo *src, *dst;
148 struct intel_batchbuffer *batch;
149 struct igt_buf src_buf, dst_buf;
150 const uint8_t buf[4] = { color, color, color, color };
151 igt_render_copyfunc_t rendercopy = igt_get_render_copyfunc(data->devid);
152
153 igt_skip_on(!rendercopy);
154
155 dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
156 igt_assert(dst);
157
Rodrigo Vivif20690d2014-12-05 19:45:37 -0500158 src = drm_intel_bo_alloc(data->bufmgr, "", 64 * 4096, 4096);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300159 igt_assert(src);
160
161 gem_write(data->drm_fd, src->handle, 0, buf, 4);
162
163 scratch_buf_init(&src_buf, src);
164 scratch_buf_init(&dst_buf, dst);
165
166 batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
167 igt_assert(batch);
168
Rodrigo Vivifb004a62014-09-03 17:53:35 -0400169 rendercopy(batch, NULL,
Rodrigo Vivif20690d2014-12-05 19:45:37 -0500170 &src_buf, 0, 0, 0xff, 0xff,
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300171 &dst_buf, 0, 0);
172
173 intel_batchbuffer_free(batch);
174
175 gem_bo_busy(data->drm_fd, handle);
176}
177
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300178static bool psr_enabled(data_t *data)
179{
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300180 FILE *file;
Chris Wilsonf59935c2015-03-11 08:40:23 +0000181 char buf[4096];
182 int ret;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300183
Rodrigo Vivi1ab04452014-08-29 17:58:31 -0400184 if (running_with_psr_disabled)
185 return true;
186
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300187 file = igt_debugfs_fopen("i915_edp_psr_status", "r");
188 igt_require(file);
189
Chris Wilsonf59935c2015-03-11 08:40:23 +0000190 /* First dump the entire file into the debug log for later analysis
191 * if required.
192 */
193 ret = fread(buf, 1, 4095, file);
194 igt_require(ret > 0);
195 buf[ret] = '\0';
196 igt_debug("i915_edp_psr_status:\n%s", buf);
197 fseek(file, 0, SEEK_SET);
198
199 /* Now check that we have all the preconditions required for PSR */
200 ret = fscanf(file, "Sink_Support: %s\n", buf);
201 igt_require_f(ret == 1 && strcmp(buf, "yes") == 0,
202 "Sink_Support: %s\n", buf);
203
204 ret = fscanf(file, "Source_OK: %s\n", buf);
205 igt_require_f(ret == 1 && strcmp(buf, "yes") == 0,
206 "Source_OK: %s\n", buf);
207
208 ret = fscanf(file, "Enabled: %s\n", buf);
209 igt_require_f(ret == 1 && strcmp(buf, "yes") == 0,
210 "Enabled: %s\n", buf);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300211
212 fclose(file);
Chris Wilsonf59935c2015-03-11 08:40:23 +0000213 return true;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300214}
215
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700216static bool psr_active(data_t *data)
217{
218 int ret;
219 FILE *file;
220 char str[4];
221
Rodrigo Vivi1ab04452014-08-29 17:58:31 -0400222 if (running_with_psr_disabled)
223 return true;
224
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700225 file = igt_debugfs_fopen("i915_edp_psr_status", "r");
226 igt_require(file);
227
228 ret = fscanf(file, "Sink_Support: %s\n", str);
Matt Roper07be8fe2015-03-05 15:01:00 -0800229 igt_assert_neq(ret, 0);
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700230 ret = fscanf(file, "Source_OK: %s\n", str);
Matt Roper07be8fe2015-03-05 15:01:00 -0800231 igt_assert_neq(ret, 0);
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700232 ret = fscanf(file, "Enabled: %s\n", str);
Matt Roper07be8fe2015-03-05 15:01:00 -0800233 igt_assert_neq(ret, 0);
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700234 ret = fscanf(file, "Active: %s\n", str);
Matt Roper07be8fe2015-03-05 15:01:00 -0800235 igt_assert_neq(ret, 0);
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700236 ret = fscanf(file, "Busy frontbuffer bits: %s\n", str);
Matt Roper07be8fe2015-03-05 15:01:00 -0800237 igt_assert_neq(ret, 0);
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700238 ret = fscanf(file, "Re-enable work scheduled: %s\n", str);
Matt Roper07be8fe2015-03-05 15:01:00 -0800239 igt_assert_neq(ret, 0);
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700240 ret = fscanf(file, "HW Enabled & Active bit: %s\n", str);
Matt Roper07be8fe2015-03-05 15:01:00 -0800241 igt_assert_neq(ret, 0);
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700242
243 fclose(file);
244 return strcmp(str, "yes") == 0;
245}
246
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300247static bool wait_psr_entry(data_t *data, int timeout)
248{
249 while (timeout--) {
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700250 if (psr_active(data))
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300251 return true;
252 sleep(1);
253 }
254 return false;
255}
256
257static void get_sink_crc(data_t *data, char *crc) {
258 int ret;
259 FILE *file;
260
261 file = igt_debugfs_fopen("i915_sink_crc_eDP1", "r");
262 igt_require(file);
263
264 ret = fscanf(file, "%s\n", crc);
265 igt_require(ret > 0);
266
267 fclose(file);
Rodrigo Vivi1ab04452014-08-29 17:58:31 -0400268
269 igt_debug("%s\n", crc);
270 igt_debug_wait_for_keypress("crc");
271
272 /* The important value was already taken.
273 * Now give a time for human eyes
274 */
275 usleep(300000);
Rodrigo Vivi25aa69d2014-09-09 13:10:51 -0400276
277 /* Black screen is always invalid */
278 igt_assert(strcmp(crc, CRC_BLACK) != 0);
279}
280
281static bool is_green(char *crc)
282{
283 char color_mask[5] = "FFFF\0";
284 char rs[5], gs[5], bs[5];
285 unsigned int rh, gh, bh, mask;
286 int ret;
287
288 sscanf(color_mask, "%4x", &mask);
289
290 memcpy(rs, &crc[0], 4);
291 rs[4] = '\0';
292 ret = sscanf(rs, "%4x", &rh);
293 igt_require(ret > 0);
294
295 memcpy(gs, &crc[4], 4);
296 gs[4] = '\0';
297 ret = sscanf(gs, "%4x", &gh);
298 igt_require(ret > 0);
299
300 memcpy(bs, &crc[8], 4);
301 bs[4] = '\0';
302 ret = sscanf(bs, "%4x", &bh);
303 igt_require(ret > 0);
304
305 return ((rh & mask) == 0 &&
306 (gh & mask) != 0 &&
307 (bh & mask) == 0);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300308}
309
310static void test_crc(data_t *data)
311{
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400312 uint32_t handle = data->fb_white.gem_handle;
313 igt_plane_t *test_plane;
314 void *ptr;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300315 char ref_crc[12];
316 char crc[12];
317
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400318 igt_plane_set_fb(data->primary, &data->fb_green);
319 igt_display_commit(&data->display);
320
Rodrigo Vivi25aa69d2014-09-09 13:10:51 -0400321 /* Confirm that screen became Green */
322 get_sink_crc(data, ref_crc);
323 igt_assert(is_green(ref_crc));
324
325 /* Confirm screen stays Green after PSR got active */
326 igt_assert(wait_psr_entry(data, 10));
327 get_sink_crc(data, ref_crc);
328 igt_assert(is_green(ref_crc));
329
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400330 /* Setting a secondary fb/plane */
331 switch (data->test_plane) {
332 case PRIMARY: default: test_plane = data->primary; break;
333 case SPRITE: test_plane = data->sprite; break;
334 case CURSOR: test_plane = data->cursor; break;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300335 }
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400336 igt_plane_set_fb(test_plane, &data->fb_white);
337 igt_display_commit(&data->display);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300338
Rodrigo Vivi25aa69d2014-09-09 13:10:51 -0400339 /* Confirm it is not Green anymore */
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300340 igt_assert(wait_psr_entry(data, 10));
341 get_sink_crc(data, ref_crc);
Rodrigo Vivi25aa69d2014-09-09 13:10:51 -0400342 igt_assert(!is_green(ref_crc));
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300343
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400344 switch (data->op) {
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400345 case PAGE_FLIP:
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400346 /* Only in use when testing primary plane */
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300347 igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400348 data->fb_green.fb_id, 0, NULL) == 0);
Rodrigo Vivi25aa69d2014-09-09 13:10:51 -0400349 get_sink_crc(data, crc);
350 igt_assert(is_green(crc));
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400351 break;
352 case MMAP_GTT:
353 ptr = gem_mmap__gtt(data->drm_fd, handle, 4096, PROT_WRITE);
354 gem_set_domain(data->drm_fd, handle,
355 I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
356 memset(ptr, 0, 4);
357 munmap(ptr, 4096);
358 break;
359 case MMAP_GTT_WAITING:
360 ptr = gem_mmap__gtt(data->drm_fd, handle, 4096, PROT_WRITE);
361 gem_set_domain(data->drm_fd, handle,
362 I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
363
364 /* Printing white on white so the screen shouldn't change */
365 memset(ptr, 0xff, 4);
366 get_sink_crc(data, crc);
367 igt_assert(strcmp(ref_crc, crc) == 0);
368
Daniel Vetter8b556f72014-10-23 17:54:44 +0200369 igt_info("Waiting 10s...\n");
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400370 sleep(10);
371
372 /* Now lets print black to change the screen */
373 memset(ptr, 0, 4);
374 munmap(ptr, 4096);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300375 break;
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400376 case MMAP_CPU:
Chris Wilson6fff1f82014-11-04 12:06:17 +0000377 ptr = gem_mmap__cpu(data->drm_fd, handle, 0, 4096, PROT_WRITE);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300378 gem_set_domain(data->drm_fd, handle,
379 I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300380 memset(ptr, 0, 4);
381 munmap(ptr, 4096);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300382 gem_sw_finish(data->drm_fd, handle);
383 break;
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400384 case BLT:
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400385 fill_blt(data, handle, 0);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300386 break;
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400387 case RENDER:
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400388 fill_render(data, handle, 0);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300389 break;
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400390 case PLANE_MOVE:
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400391 /* Only in use when testing Sprite and Cursor */
392 igt_plane_set_position(test_plane, 1, 1);
393 igt_display_commit(&data->display);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300394 break;
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400395 case PLANE_ONOFF:
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400396 /* Only in use when testing Sprite and Cursor */
397 igt_plane_set_fb(test_plane, NULL);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300398 igt_display_commit(&data->display);
399 break;
400 }
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300401 get_sink_crc(data, crc);
402 igt_assert(strcmp(ref_crc, crc) != 0);
403}
404
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400405static void test_cleanup(data_t *data) {
406 igt_plane_set_fb(data->primary, NULL);
407 if (data->test_plane == SPRITE)
408 igt_plane_set_fb(data->sprite, NULL);
409 if (data->test_plane == CURSOR)
410 igt_plane_set_fb(data->cursor, NULL);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300411
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400412 igt_display_commit(&data->display);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300413
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400414 igt_remove_fb(data->drm_fd, &data->fb_green);
415 igt_remove_fb(data->drm_fd, &data->fb_white);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300416}
417
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400418static void run_test(data_t *data)
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300419{
420 igt_display_t *display = &data->display;
421 igt_output_t *output;
422 drmModeModeInfo *mode;
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400423 uint32_t white_h, white_v;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300424
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300425 for_each_connected_output(display, output) {
426 drmModeConnectorPtr c = output->config.connector;
427
428 if (c->connector_type != DRM_MODE_CONNECTOR_eDP ||
429 c->connection != DRM_MODE_CONNECTED)
430 continue;
431
Rodrigo Vivi9c8ee512014-10-10 08:14:32 -0700432 igt_output_set_pipe(output, PIPE_ANY);
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400433 data->crtc_id = output->config.crtc->crtc_id;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300434
435 mode = igt_output_get_mode(output);
436
437 igt_create_color_fb(data->drm_fd,
438 mode->hdisplay, mode->vdisplay,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000439 DRM_FORMAT_XRGB8888,
440 LOCAL_I915_FORMAT_MOD_X_TILED,
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300441 0.0, 1.0, 0.0,
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400442 &data->fb_green);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300443
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400444 data->primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
445 igt_plane_set_fb(data->primary, NULL);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300446
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400447 white_h = mode->hdisplay;
448 white_v = mode->vdisplay;
449
450 switch (data->test_plane) {
451 case SPRITE:
452 data->sprite = igt_output_get_plane(output,
453 IGT_PLANE_2);
454 igt_plane_set_fb(data->sprite, NULL);
455 /* To make it different for human eyes let's make
456 * sprite visible in only one quarter of the primary
457 */
458 white_h = white_h/2;
459 white_v = white_v/2;
460 case PRIMARY:
461 igt_create_color_fb(data->drm_fd,
462 white_h, white_v,
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000463 DRM_FORMAT_XRGB8888,
464 LOCAL_I915_FORMAT_MOD_X_TILED,
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400465 1.0, 1.0, 1.0,
466 &data->fb_white);
467 break;
468 case CURSOR:
469 data->cursor = igt_output_get_plane(output,
470 IGT_PLANE_CURSOR);
471 igt_plane_set_fb(data->cursor, NULL);
472 create_cursor_fb(data);
473 igt_plane_set_position(data->cursor, 0, 0);
474 break;
475 }
476
477 igt_display_commit(&data->display);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300478
479 test_crc(data);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300480
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400481 test_cleanup(data);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300482 }
483}
484
Daniel Vetter3205a912014-09-23 15:15:51 +0200485static int opt_handler(int opt, int opt_index)
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300486{
Daniel Vetter3205a912014-09-23 15:15:51 +0200487 switch (opt) {
488 case 'n':
489 running_with_psr_disabled = true;
490 break;
491 default:
492 igt_assert(0);
493 }
494
495 return 0;
496}
497
498int main(int argc, char *argv[])
499{
500 const char *help_str =
501 " --no-psr\tRun test without PSR to check the CRC test logic.";
502 static struct option long_options[] = {
503 {"no-psr", 0, 0, 'n'},
504 { 0, 0, 0, 0 }
505 };
Rodrigo Vivi1ab04452014-08-29 17:58:31 -0400506 data_t data = {};
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400507 enum operations op;
Rodrigo Vivi1ab04452014-08-29 17:58:31 -0400508
Thomas Wood8fb19782015-02-18 16:19:59 +0000509 igt_subtest_init_parse_opts(&argc, argv, "", long_options,
Daniel Vetter3205a912014-09-23 15:15:51 +0200510 help_str, opt_handler);
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300511 igt_skip_on_simulation();
512
513 igt_fixture {
Imre Deakc256af52014-09-18 18:31:29 +0300514 data.drm_fd = drm_open_any_master();
Daniel Vetter33f08842014-08-12 11:23:09 +0200515 kmstest_set_vt_graphics_mode();
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300516 data.devid = intel_get_drm_devid(data.drm_fd);
517
Rodrigo Vivie90847f2014-08-22 09:37:08 -0700518 igt_skip_on(!psr_enabled(&data));
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300519
520 data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
521 igt_assert(data.bufmgr);
522 drm_intel_bufmgr_gem_enable_reuse(data.bufmgr);
523
524 display_init(&data);
525 }
526
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400527 for (op = PAGE_FLIP; op <= RENDER; op++) {
528 igt_subtest_f("primary_%s", op_str(op)) {
529 data.test_plane = PRIMARY;
530 data.op = op;
531 run_test(&data);
532 }
533 }
534
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400535 for (op = MMAP_GTT; op <= PLANE_ONOFF; op++) {
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400536 igt_subtest_f("sprite_%s", op_str(op)) {
537 data.test_plane = SPRITE;
538 data.op = op;
539 run_test(&data);
540 }
541 }
542
Rodrigo Vivid4e6a512014-08-29 19:12:54 -0400543 for (op = MMAP_GTT; op <= PLANE_ONOFF; op++) {
Rodrigo Vivi99efdc02014-09-09 17:58:45 -0400544 igt_subtest_f("cursor_%s", op_str(op)) {
545 data.test_plane = CURSOR;
546 data.op = op;
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300547 run_test(&data);
548 }
549 }
550
551 igt_fixture {
552 drm_intel_bufmgr_destroy(data.bufmgr);
553 display_fini(&data);
554 }
Daniel Vetter3205a912014-09-23 15:15:51 +0200555
556 igt_exit();
Rodrigo Vivi27d37a12014-03-19 22:43:51 -0300557}