Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 1 | /* |
| 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 Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 30 | #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 Vivi | 1ab0445 | 2014-08-29 17:58:31 -0400 | [diff] [blame] | 37 | #include "igt_aux.h" |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 38 | |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 39 | bool running_with_psr_disabled; |
| 40 | |
Rodrigo Vivi | 25aa69d | 2014-09-09 13:10:51 -0400 | [diff] [blame] | 41 | #define CRC_BLACK "000000000000" |
| 42 | |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 43 | enum planes { |
| 44 | PRIMARY, |
| 45 | SPRITE, |
| 46 | CURSOR, |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 47 | }; |
| 48 | |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 49 | enum 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 | |
| 60 | static 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 Vivi | 1ab0445 | 2014-08-29 17:58:31 -0400 | [diff] [blame] | 75 | |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 76 | typedef struct { |
| 77 | int drm_fd; |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 78 | enum planes test_plane; |
| 79 | enum operations op; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 80 | uint32_t devid; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 81 | uint32_t crtc_id; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 82 | igt_display_t display; |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 83 | drm_intel_bufmgr *bufmgr; |
| 84 | struct igt_fb fb_green, fb_white; |
| 85 | igt_plane_t *primary, *sprite, *cursor; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 86 | } data_t; |
| 87 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 88 | static void create_cursor_fb(data_t *data) |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 89 | { |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 90 | cairo_t *cr; |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 91 | uint32_t fb_id; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 92 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 93 | fb_id = igt_create_fb(data->drm_fd, 64, 64, |
Tvrtko Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 94 | DRM_FORMAT_ARGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 95 | &data->fb_white); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 96 | igt_assert(fb_id); |
| 97 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 98 | cr = igt_get_cairo_ctx(data->drm_fd, &data->fb_white); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 99 | 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 Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 103 | static void display_init(data_t *data) |
| 104 | { |
| 105 | igt_display_init(&data->display, data->drm_fd); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static void display_fini(data_t *data) |
| 109 | { |
| 110 | igt_display_fini(&data->display); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static 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 Wilson | 10552b5 | 2014-08-30 11:44:51 +0100 | [diff] [blame] | 123 | COLOR_BLIT_COPY_BATCH_START(0); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 124 | OUT_BATCH((1 << 24) | (0xf0 << 16) | 0); |
Rodrigo Vivi | 1447d83 | 2014-09-03 18:18:15 -0400 | [diff] [blame] | 125 | OUT_BATCH(0); |
Rodrigo Vivi | 3cb2124 | 2014-12-05 19:43:34 -0500 | [diff] [blame] | 126 | OUT_BATCH(0xfff << 16 | 0xfff); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 127 | 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 | |
| 137 | static 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 Vivi | f20690d | 2014-12-05 19:45:37 -0500 | [diff] [blame^] | 142 | buf->size = 64 * 4096; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 143 | } |
| 144 | |
Rodrigo Vivi | fb004a6 | 2014-09-03 17:53:35 -0400 | [diff] [blame] | 145 | static void fill_render(data_t *data, uint32_t handle, unsigned char color) |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 146 | { |
| 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 Vivi | f20690d | 2014-12-05 19:45:37 -0500 | [diff] [blame^] | 158 | src = drm_intel_bo_alloc(data->bufmgr, "", 64 * 4096, 4096); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 159 | 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 Vivi | fb004a6 | 2014-09-03 17:53:35 -0400 | [diff] [blame] | 169 | rendercopy(batch, NULL, |
Rodrigo Vivi | f20690d | 2014-12-05 19:45:37 -0500 | [diff] [blame^] | 170 | &src_buf, 0, 0, 0xff, 0xff, |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 171 | &dst_buf, 0, 0); |
| 172 | |
| 173 | intel_batchbuffer_free(batch); |
| 174 | |
| 175 | gem_bo_busy(data->drm_fd, handle); |
| 176 | } |
| 177 | |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 178 | static bool psr_enabled(data_t *data) |
| 179 | { |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 180 | FILE *file; |
Chris Wilson | f59935c | 2015-03-11 08:40:23 +0000 | [diff] [blame] | 181 | char buf[4096]; |
| 182 | int ret; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 183 | |
Rodrigo Vivi | 1ab0445 | 2014-08-29 17:58:31 -0400 | [diff] [blame] | 184 | if (running_with_psr_disabled) |
| 185 | return true; |
| 186 | |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 187 | file = igt_debugfs_fopen("i915_edp_psr_status", "r"); |
| 188 | igt_require(file); |
| 189 | |
Chris Wilson | f59935c | 2015-03-11 08:40:23 +0000 | [diff] [blame] | 190 | /* 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 Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 211 | |
| 212 | fclose(file); |
Chris Wilson | f59935c | 2015-03-11 08:40:23 +0000 | [diff] [blame] | 213 | return true; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 214 | } |
| 215 | |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 216 | static bool psr_active(data_t *data) |
| 217 | { |
| 218 | int ret; |
| 219 | FILE *file; |
| 220 | char str[4]; |
| 221 | |
Rodrigo Vivi | 1ab0445 | 2014-08-29 17:58:31 -0400 | [diff] [blame] | 222 | if (running_with_psr_disabled) |
| 223 | return true; |
| 224 | |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 225 | file = igt_debugfs_fopen("i915_edp_psr_status", "r"); |
| 226 | igt_require(file); |
| 227 | |
| 228 | ret = fscanf(file, "Sink_Support: %s\n", str); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 229 | igt_assert_neq(ret, 0); |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 230 | ret = fscanf(file, "Source_OK: %s\n", str); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 231 | igt_assert_neq(ret, 0); |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 232 | ret = fscanf(file, "Enabled: %s\n", str); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 233 | igt_assert_neq(ret, 0); |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 234 | ret = fscanf(file, "Active: %s\n", str); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 235 | igt_assert_neq(ret, 0); |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 236 | ret = fscanf(file, "Busy frontbuffer bits: %s\n", str); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 237 | igt_assert_neq(ret, 0); |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 238 | ret = fscanf(file, "Re-enable work scheduled: %s\n", str); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 239 | igt_assert_neq(ret, 0); |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 240 | ret = fscanf(file, "HW Enabled & Active bit: %s\n", str); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 241 | igt_assert_neq(ret, 0); |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 242 | |
| 243 | fclose(file); |
| 244 | return strcmp(str, "yes") == 0; |
| 245 | } |
| 246 | |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 247 | static bool wait_psr_entry(data_t *data, int timeout) |
| 248 | { |
| 249 | while (timeout--) { |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 250 | if (psr_active(data)) |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 251 | return true; |
| 252 | sleep(1); |
| 253 | } |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | static 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 Vivi | 1ab0445 | 2014-08-29 17:58:31 -0400 | [diff] [blame] | 268 | |
| 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 Vivi | 25aa69d | 2014-09-09 13:10:51 -0400 | [diff] [blame] | 276 | |
| 277 | /* Black screen is always invalid */ |
| 278 | igt_assert(strcmp(crc, CRC_BLACK) != 0); |
| 279 | } |
| 280 | |
| 281 | static 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 Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static void test_crc(data_t *data) |
| 311 | { |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 312 | uint32_t handle = data->fb_white.gem_handle; |
| 313 | igt_plane_t *test_plane; |
| 314 | void *ptr; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 315 | char ref_crc[12]; |
| 316 | char crc[12]; |
| 317 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 318 | igt_plane_set_fb(data->primary, &data->fb_green); |
| 319 | igt_display_commit(&data->display); |
| 320 | |
Rodrigo Vivi | 25aa69d | 2014-09-09 13:10:51 -0400 | [diff] [blame] | 321 | /* 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 Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 330 | /* 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 Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 335 | } |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 336 | igt_plane_set_fb(test_plane, &data->fb_white); |
| 337 | igt_display_commit(&data->display); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 338 | |
Rodrigo Vivi | 25aa69d | 2014-09-09 13:10:51 -0400 | [diff] [blame] | 339 | /* Confirm it is not Green anymore */ |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 340 | igt_assert(wait_psr_entry(data, 10)); |
| 341 | get_sink_crc(data, ref_crc); |
Rodrigo Vivi | 25aa69d | 2014-09-09 13:10:51 -0400 | [diff] [blame] | 342 | igt_assert(!is_green(ref_crc)); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 343 | |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 344 | switch (data->op) { |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 345 | case PAGE_FLIP: |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 346 | /* Only in use when testing primary plane */ |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 347 | igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id, |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 348 | data->fb_green.fb_id, 0, NULL) == 0); |
Rodrigo Vivi | 25aa69d | 2014-09-09 13:10:51 -0400 | [diff] [blame] | 349 | get_sink_crc(data, crc); |
| 350 | igt_assert(is_green(crc)); |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 351 | 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 Vetter | 8b556f7 | 2014-10-23 17:54:44 +0200 | [diff] [blame] | 369 | igt_info("Waiting 10s...\n"); |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 370 | sleep(10); |
| 371 | |
| 372 | /* Now lets print black to change the screen */ |
| 373 | memset(ptr, 0, 4); |
| 374 | munmap(ptr, 4096); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 375 | break; |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 376 | case MMAP_CPU: |
Chris Wilson | 6fff1f8 | 2014-11-04 12:06:17 +0000 | [diff] [blame] | 377 | ptr = gem_mmap__cpu(data->drm_fd, handle, 0, 4096, PROT_WRITE); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 378 | gem_set_domain(data->drm_fd, handle, |
| 379 | I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 380 | memset(ptr, 0, 4); |
| 381 | munmap(ptr, 4096); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 382 | gem_sw_finish(data->drm_fd, handle); |
| 383 | break; |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 384 | case BLT: |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 385 | fill_blt(data, handle, 0); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 386 | break; |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 387 | case RENDER: |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 388 | fill_render(data, handle, 0); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 389 | break; |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 390 | case PLANE_MOVE: |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 391 | /* Only in use when testing Sprite and Cursor */ |
| 392 | igt_plane_set_position(test_plane, 1, 1); |
| 393 | igt_display_commit(&data->display); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 394 | break; |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 395 | case PLANE_ONOFF: |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 396 | /* Only in use when testing Sprite and Cursor */ |
| 397 | igt_plane_set_fb(test_plane, NULL); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 398 | igt_display_commit(&data->display); |
| 399 | break; |
| 400 | } |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 401 | get_sink_crc(data, crc); |
| 402 | igt_assert(strcmp(ref_crc, crc) != 0); |
| 403 | } |
| 404 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 405 | static 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 Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 411 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 412 | igt_display_commit(&data->display); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 413 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 414 | igt_remove_fb(data->drm_fd, &data->fb_green); |
| 415 | igt_remove_fb(data->drm_fd, &data->fb_white); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 416 | } |
| 417 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 418 | static void run_test(data_t *data) |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 419 | { |
| 420 | igt_display_t *display = &data->display; |
| 421 | igt_output_t *output; |
| 422 | drmModeModeInfo *mode; |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 423 | uint32_t white_h, white_v; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 424 | |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 425 | 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 Vivi | 9c8ee51 | 2014-10-10 08:14:32 -0700 | [diff] [blame] | 432 | igt_output_set_pipe(output, PIPE_ANY); |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 433 | data->crtc_id = output->config.crtc->crtc_id; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 434 | |
| 435 | mode = igt_output_get_mode(output); |
| 436 | |
| 437 | igt_create_color_fb(data->drm_fd, |
| 438 | mode->hdisplay, mode->vdisplay, |
Tvrtko Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 439 | DRM_FORMAT_XRGB8888, |
| 440 | LOCAL_I915_FORMAT_MOD_X_TILED, |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 441 | 0.0, 1.0, 0.0, |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 442 | &data->fb_green); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 443 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 444 | data->primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
| 445 | igt_plane_set_fb(data->primary, NULL); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 446 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 447 | 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 Ursulin | e36091d | 2015-03-03 14:11:01 +0000 | [diff] [blame] | 463 | DRM_FORMAT_XRGB8888, |
| 464 | LOCAL_I915_FORMAT_MOD_X_TILED, |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 465 | 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 Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 478 | |
| 479 | test_crc(data); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 480 | |
Rodrigo Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 481 | test_cleanup(data); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
Daniel Vetter | 3205a91 | 2014-09-23 15:15:51 +0200 | [diff] [blame] | 485 | static int opt_handler(int opt, int opt_index) |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 486 | { |
Daniel Vetter | 3205a91 | 2014-09-23 15:15:51 +0200 | [diff] [blame] | 487 | 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 | |
| 498 | int 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 Vivi | 1ab0445 | 2014-08-29 17:58:31 -0400 | [diff] [blame] | 506 | data_t data = {}; |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 507 | enum operations op; |
Rodrigo Vivi | 1ab0445 | 2014-08-29 17:58:31 -0400 | [diff] [blame] | 508 | |
Thomas Wood | 8fb1978 | 2015-02-18 16:19:59 +0000 | [diff] [blame] | 509 | igt_subtest_init_parse_opts(&argc, argv, "", long_options, |
Daniel Vetter | 3205a91 | 2014-09-23 15:15:51 +0200 | [diff] [blame] | 510 | help_str, opt_handler); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 511 | igt_skip_on_simulation(); |
| 512 | |
| 513 | igt_fixture { |
Imre Deak | c256af5 | 2014-09-18 18:31:29 +0300 | [diff] [blame] | 514 | data.drm_fd = drm_open_any_master(); |
Daniel Vetter | 33f0884 | 2014-08-12 11:23:09 +0200 | [diff] [blame] | 515 | kmstest_set_vt_graphics_mode(); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 516 | data.devid = intel_get_drm_devid(data.drm_fd); |
| 517 | |
Rodrigo Vivi | e90847f | 2014-08-22 09:37:08 -0700 | [diff] [blame] | 518 | igt_skip_on(!psr_enabled(&data)); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 519 | |
| 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 Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 527 | 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 Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 535 | for (op = MMAP_GTT; op <= PLANE_ONOFF; op++) { |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 536 | 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 Vivi | d4e6a51 | 2014-08-29 19:12:54 -0400 | [diff] [blame] | 543 | for (op = MMAP_GTT; op <= PLANE_ONOFF; op++) { |
Rodrigo Vivi | 99efdc0 | 2014-09-09 17:58:45 -0400 | [diff] [blame] | 544 | igt_subtest_f("cursor_%s", op_str(op)) { |
| 545 | data.test_plane = CURSOR; |
| 546 | data.op = op; |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 547 | run_test(&data); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | igt_fixture { |
| 552 | drm_intel_bufmgr_destroy(data.bufmgr); |
| 553 | display_fini(&data); |
| 554 | } |
Daniel Vetter | 3205a91 | 2014-09-23 15:15:51 +0200 | [diff] [blame] | 555 | |
| 556 | igt_exit(); |
Rodrigo Vivi | 27d37a1 | 2014-03-19 22:43:51 -0300 | [diff] [blame] | 557 | } |