Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 1 | /* |
Damien Lespiau | 9cf7e8d | 2014-07-08 12:08:20 +0100 | [diff] [blame] | 2 | * Copyright © 2013,2014 Intel Corporation |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 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 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 25 | #include "igt.h" |
Damien Lespiau | 92b29b1 | 2014-07-08 12:49:03 +0100 | [diff] [blame] | 26 | #include <math.h> |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 27 | |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 28 | #define MAX_FENCES 32 |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 29 | |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 30 | typedef struct { |
| 31 | int gfx_fd; |
| 32 | igt_display_t display; |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 33 | struct igt_fb fb; |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 34 | struct igt_fb fb_reference; |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 35 | struct igt_fb fb_unrotated; |
Tvrtko Ursulin | d901106 | 2015-04-22 16:46:43 +0100 | [diff] [blame] | 36 | struct igt_fb fb_modeset; |
Tvrtko Ursulin | 061a38f | 2015-10-07 12:18:52 +0100 | [diff] [blame] | 37 | struct igt_fb fb_flip; |
Damien Lespiau | 19743a1 | 2014-07-08 12:59:03 +0100 | [diff] [blame] | 38 | igt_crc_t ref_crc; |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 39 | igt_crc_t flip_crc; |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 40 | igt_pipe_crc_t *pipe_crc; |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 41 | igt_rotation_t rotation; |
| 42 | int pos_x; |
| 43 | int pos_y; |
Tvrtko Ursulin | dbf6468 | 2015-04-22 16:46:48 +0100 | [diff] [blame] | 44 | uint32_t override_fmt; |
| 45 | uint64_t override_tiling; |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 46 | bool flips; |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 47 | int devid; |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 48 | } data_t; |
| 49 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 50 | typedef struct { |
| 51 | float r; |
| 52 | float g; |
| 53 | float b; |
| 54 | } rgb_color_t; |
| 55 | |
| 56 | static void set_color(rgb_color_t *color, float r, float g, float b) |
| 57 | { |
| 58 | color->r = r; |
| 59 | color->g = g; |
| 60 | color->b = b; |
| 61 | } |
| 62 | |
| 63 | static void rotate_colors(rgb_color_t *tl, rgb_color_t *tr, rgb_color_t *br, |
| 64 | rgb_color_t *bl, igt_rotation_t rotation) |
| 65 | { |
| 66 | rgb_color_t bl_tmp, br_tmp, tl_tmp, tr_tmp; |
| 67 | |
| 68 | if (rotation & IGT_REFLECT_X) { |
| 69 | igt_swap(*tl, *tr); |
| 70 | igt_swap(*bl, *br); |
| 71 | } |
| 72 | |
| 73 | if (rotation & IGT_ROTATION_90) { |
| 74 | bl_tmp = *bl; |
| 75 | br_tmp = *br; |
| 76 | tl_tmp = *tl; |
| 77 | tr_tmp = *tr; |
| 78 | *tl = tr_tmp; |
| 79 | *bl = tl_tmp; |
| 80 | *tr = br_tmp; |
| 81 | *br = bl_tmp; |
| 82 | } else if (rotation & IGT_ROTATION_180) { |
| 83 | igt_swap(*tl, *br); |
| 84 | igt_swap(*tr, *bl); |
| 85 | } else if (rotation & IGT_ROTATION_270) { |
| 86 | bl_tmp = *bl; |
| 87 | br_tmp = *br; |
| 88 | tl_tmp = *tl; |
| 89 | tr_tmp = *tr; |
| 90 | *tl = bl_tmp; |
| 91 | *bl = br_tmp; |
| 92 | *tr = tl_tmp; |
| 93 | *br = tr_tmp; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | #define RGB_COLOR(color) \ |
| 98 | color.r, color.g, color.b |
| 99 | |
Damien Lespiau | 92b29b1 | 2014-07-08 12:49:03 +0100 | [diff] [blame] | 100 | static void |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 101 | paint_squares(data_t *data, igt_rotation_t rotation, |
Tvrtko Ursulin | 061a38f | 2015-10-07 12:18:52 +0100 | [diff] [blame] | 102 | struct igt_fb *fb, float o) |
Damien Lespiau | 92b29b1 | 2014-07-08 12:49:03 +0100 | [diff] [blame] | 103 | { |
| 104 | cairo_t *cr; |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 105 | unsigned int w = fb->width; |
| 106 | unsigned int h = fb->height; |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 107 | rgb_color_t tl, tr, bl, br; |
Damien Lespiau | 92b29b1 | 2014-07-08 12:49:03 +0100 | [diff] [blame] | 108 | |
Tvrtko Ursulin | 061a38f | 2015-10-07 12:18:52 +0100 | [diff] [blame] | 109 | cr = igt_get_cairo_ctx(data->gfx_fd, fb); |
Damien Lespiau | 92b29b1 | 2014-07-08 12:49:03 +0100 | [diff] [blame] | 110 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 111 | set_color(&tl, o, 0.0f, 0.0f); |
| 112 | set_color(&tr, 0.0f, o, 0.0f); |
| 113 | set_color(&br, o, o, o); |
| 114 | set_color(&bl, 0.0f, 0.0f, o); |
Tvrtko Ursulin | b769a7c | 2015-04-22 16:46:46 +0100 | [diff] [blame] | 115 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 116 | rotate_colors(&tl, &tr, &br, &bl, rotation); |
| 117 | |
| 118 | igt_paint_color(cr, 0, 0, w / 2, h / 2, RGB_COLOR(tl)); |
| 119 | igt_paint_color(cr, w / 2, 0, w / 2, h / 2, RGB_COLOR(tr)); |
| 120 | igt_paint_color(cr, 0, h / 2, w / 2, h / 2, RGB_COLOR(bl)); |
| 121 | igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, RGB_COLOR(br)); |
Tvrtko Ursulin | b769a7c | 2015-04-22 16:46:46 +0100 | [diff] [blame] | 122 | |
Maarten Lankhorst | be2f6fc | 2018-02-01 12:48:45 +0100 | [diff] [blame^] | 123 | igt_put_cairo_ctx(data->gfx_fd, fb, cr); |
Damien Lespiau | 92b29b1 | 2014-07-08 12:49:03 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Daniel Vetter | 57259d7 | 2014-11-24 16:08:32 +0100 | [diff] [blame] | 126 | static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe, |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 127 | igt_plane_t *plane, enum igt_commit_style commit) |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 128 | { |
| 129 | drmModeModeInfo *mode; |
Tvrtko Ursulin | b769a7c | 2015-04-22 16:46:46 +0100 | [diff] [blame] | 130 | unsigned int w, h; |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 131 | uint64_t tiling = data->override_tiling ?: LOCAL_DRM_FORMAT_MOD_NONE; |
| 132 | uint32_t pixel_format = data->override_fmt ?: DRM_FORMAT_XRGB8888; |
| 133 | igt_display_t *display = &data->display; |
Maarten Lankhorst | 9d809cd | 2017-06-06 17:12:20 +0200 | [diff] [blame] | 134 | igt_plane_t *primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 135 | |
Damien Lespiau | 8facccf | 2014-07-08 18:28:53 +0100 | [diff] [blame] | 136 | igt_output_set_pipe(output, pipe); |
Maarten Lankhorst | 44023a2 | 2017-01-31 13:31:57 +0100 | [diff] [blame] | 137 | igt_plane_set_rotation(plane, IGT_ROTATION_0); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 138 | |
| 139 | /* create the pipe_crc object for this pipe */ |
Damien Lespiau | 2eaa50f | 2014-07-08 18:56:15 +0100 | [diff] [blame] | 140 | igt_pipe_crc_free(data->pipe_crc); |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 141 | data->pipe_crc = igt_pipe_crc_new(data->gfx_fd, pipe, INTEL_PIPE_CRC_SOURCE_AUTO); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 142 | |
Damien Lespiau | 19743a1 | 2014-07-08 12:59:03 +0100 | [diff] [blame] | 143 | mode = igt_output_get_mode(output); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 144 | |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 145 | w = mode->hdisplay; |
| 146 | h = mode->vdisplay; |
| 147 | |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 148 | igt_create_fb(data->gfx_fd, w, h, pixel_format, tiling, &data->fb_modeset); |
| 149 | |
| 150 | /* |
| 151 | * With igt_display_commit2 and COMMIT_UNIVERSAL, we call just the |
| 152 | * setplane without a modeset. So, to be able to call |
| 153 | * igt_display_commit and ultimately setcrtc to do the first modeset, |
| 154 | * we create an fb covering the crtc and call commit |
Maarten Lankhorst | 9d809cd | 2017-06-06 17:12:20 +0200 | [diff] [blame] | 155 | * |
| 156 | * It's also a good idea to set a primary fb on the primary plane |
| 157 | * regardless, to force a underrun when watermarks are allocated |
| 158 | * incorrectly for other planes. |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 159 | */ |
Maarten Lankhorst | 9d809cd | 2017-06-06 17:12:20 +0200 | [diff] [blame] | 160 | igt_plane_set_fb(primary, &data->fb_modeset); |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 161 | |
Maarten Lankhorst | 9d809cd | 2017-06-06 17:12:20 +0200 | [diff] [blame] | 162 | if (commit < COMMIT_ATOMIC) { |
Maarten Lankhorst | 5e42c62 | 2017-09-21 14:30:09 +0200 | [diff] [blame] | 163 | igt_plane_clear_prop_changed(primary, IGT_PLANE_ROTATION); |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 164 | igt_display_commit(display); |
| 165 | |
| 166 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) |
Maarten Lankhorst | 5e42c62 | 2017-09-21 14:30:09 +0200 | [diff] [blame] | 167 | igt_plane_set_prop_changed(primary, IGT_PLANE_ROTATION); |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | igt_plane_set_fb(plane, NULL); |
| 171 | |
| 172 | igt_display_commit2(display, commit); |
| 173 | } |
| 174 | |
| 175 | static void remove_fbs(data_t *data) |
| 176 | { |
| 177 | if (!data->fb.fb_id) |
| 178 | return; |
| 179 | |
| 180 | igt_remove_fb(data->gfx_fd, &data->fb); |
| 181 | igt_remove_fb(data->gfx_fd, &data->fb_reference); |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 182 | igt_remove_fb(data->gfx_fd, &data->fb_unrotated); |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 183 | |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 184 | if (data->fb_flip.fb_id) |
| 185 | igt_remove_fb(data->gfx_fd, &data->fb_flip); |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 186 | |
Maarten Lankhorst | 9d809cd | 2017-06-06 17:12:20 +0200 | [diff] [blame] | 187 | data->fb_flip.fb_id = data->fb.fb_id = 0; |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 190 | enum rectangle_type { |
Maarten Lankhorst | a645824 | 2017-06-12 10:56:01 +0200 | [diff] [blame] | 191 | rectangle, |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 192 | square, |
| 193 | portrait, |
| 194 | landscape, |
| 195 | num_rectangle_types /* must be last */ |
| 196 | }; |
| 197 | |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 198 | static void prepare_fbs(data_t *data, igt_output_t *output, |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 199 | igt_plane_t *plane, enum rectangle_type rect) |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 200 | { |
| 201 | drmModeModeInfo *mode; |
| 202 | igt_display_t *display = &data->display; |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 203 | unsigned int w, h, ref_w, ref_h, min_w, min_h; |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 204 | uint64_t tiling = data->override_tiling ?: LOCAL_DRM_FORMAT_MOD_NONE; |
| 205 | uint32_t pixel_format = data->override_fmt ?: DRM_FORMAT_XRGB8888; |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 206 | const float flip_opacity = 0.75; |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 207 | |
| 208 | if (data->fb.fb_id) { |
| 209 | igt_plane_set_fb(plane, NULL); |
| 210 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_UNIVERSAL); |
| 211 | |
| 212 | remove_fbs(data); |
| 213 | } |
| 214 | |
| 215 | igt_plane_set_rotation(plane, IGT_ROTATION_0); |
| 216 | |
| 217 | mode = igt_output_get_mode(output); |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 218 | if (plane->type != DRM_PLANE_TYPE_CURSOR) { |
| 219 | w = mode->hdisplay; |
| 220 | h = mode->vdisplay; |
| 221 | |
| 222 | min_w = 256; |
| 223 | min_h = 256; |
| 224 | } else { |
| 225 | pixel_format = data->override_fmt ?: DRM_FORMAT_ARGB8888; |
| 226 | |
| 227 | w = h = 256; |
| 228 | min_w = min_h = 64; |
| 229 | } |
| 230 | |
| 231 | switch (rect) { |
Maarten Lankhorst | a645824 | 2017-06-12 10:56:01 +0200 | [diff] [blame] | 232 | case rectangle: |
| 233 | break; |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 234 | case square: |
| 235 | w = h = min(h, w); |
| 236 | break; |
| 237 | case portrait: |
| 238 | w = min_w; |
| 239 | break; |
| 240 | case landscape: |
| 241 | h = min_h; |
| 242 | break; |
| 243 | case num_rectangle_types: |
| 244 | igt_assert(0); |
| 245 | } |
| 246 | |
| 247 | ref_w = w; |
| 248 | ref_h = h; |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 249 | |
| 250 | /* |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 251 | * For 90/270, we will use create smaller fb so that the rotated |
| 252 | * frame can fit in |
| 253 | */ |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 254 | if (data->rotation & (IGT_ROTATION_90 | IGT_ROTATION_270)) { |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 255 | tiling = data->override_tiling ?: LOCAL_I915_FORMAT_MOD_Y_TILED; |
| 256 | |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 257 | igt_swap(w, h); |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 258 | } |
| 259 | |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 260 | /* |
| 261 | * Create a reference software rotated flip framebuffer. |
| 262 | */ |
| 263 | if (data->flips) { |
| 264 | igt_create_fb(data->gfx_fd, ref_w, ref_h, pixel_format, tiling, |
| 265 | &data->fb_flip); |
| 266 | paint_squares(data, data->rotation, &data->fb_flip, |
| 267 | flip_opacity); |
| 268 | igt_plane_set_fb(plane, &data->fb_flip); |
| 269 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 270 | igt_plane_set_position(plane, data->pos_x, data->pos_y); |
| 271 | igt_display_commit2(display, |
| 272 | display->is_atomic ? |
| 273 | COMMIT_ATOMIC : COMMIT_UNIVERSAL); |
| 274 | igt_pipe_crc_collect_crc(data->pipe_crc, &data->flip_crc); |
Tvrtko Ursulin | 061a38f | 2015-10-07 12:18:52 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 277 | /* |
| 278 | * Create a reference CRC for a software-rotated fb. |
| 279 | */ |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 280 | igt_create_fb(data->gfx_fd, ref_w, ref_h, pixel_format, |
| 281 | data->override_tiling ?: LOCAL_DRM_FORMAT_MOD_NONE, &data->fb_reference); |
| 282 | paint_squares(data, data->rotation, &data->fb_reference, 1.0); |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 283 | |
| 284 | igt_plane_set_fb(plane, &data->fb_reference); |
| 285 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 286 | igt_plane_set_position(plane, data->pos_x, data->pos_y); |
| 287 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_UNIVERSAL); |
| 288 | |
Damien Lespiau | 19743a1 | 2014-07-08 12:59:03 +0100 | [diff] [blame] | 289 | igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 290 | |
Damien Lespiau | 282f560 | 2014-07-10 17:44:28 +0100 | [diff] [blame] | 291 | /* |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 292 | * Prepare the non-rotated reference fb. |
| 293 | */ |
| 294 | igt_create_fb(data->gfx_fd, ref_w, ref_h, pixel_format, tiling, &data->fb_unrotated); |
| 295 | paint_squares(data, IGT_ROTATION_0, &data->fb_unrotated, 1.0); |
| 296 | igt_plane_set_fb(plane, &data->fb_unrotated); |
| 297 | igt_plane_set_rotation(plane, IGT_ROTATION_0); |
| 298 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 299 | igt_plane_set_position(plane, data->pos_x, data->pos_y); |
| 300 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_UNIVERSAL); |
| 301 | |
| 302 | /* |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 303 | * Prepare the plane with an non-rotated fb let the hw rotate it. |
Damien Lespiau | 282f560 | 2014-07-10 17:44:28 +0100 | [diff] [blame] | 304 | */ |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 305 | igt_create_fb(data->gfx_fd, w, h, pixel_format, tiling, &data->fb); |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 306 | paint_squares(data, IGT_ROTATION_0, &data->fb, 1.0); |
Tvrtko Ursulin | b769a7c | 2015-04-22 16:46:46 +0100 | [diff] [blame] | 307 | igt_plane_set_fb(plane, &data->fb); |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 308 | |
| 309 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 310 | igt_plane_set_position(plane, data->pos_x, data->pos_y); |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * Prepare the non-rotated flip fb. |
| 314 | */ |
| 315 | if (data->flips) { |
| 316 | igt_remove_fb(data->gfx_fd, &data->fb_flip); |
| 317 | igt_create_fb(data->gfx_fd, w, h, pixel_format, tiling, |
| 318 | &data->fb_flip); |
| 319 | paint_squares(data, IGT_ROTATION_0, &data->fb_flip, |
| 320 | flip_opacity); |
| 321 | } |
| 322 | |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 323 | } |
| 324 | |
Damien Lespiau | 05f90b0 | 2014-07-08 18:51:25 +0100 | [diff] [blame] | 325 | static void cleanup_crtc(data_t *data, igt_output_t *output, igt_plane_t *plane) |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 326 | { |
| 327 | igt_display_t *display = &data->display; |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 328 | |
| 329 | igt_pipe_crc_free(data->pipe_crc); |
| 330 | data->pipe_crc = NULL; |
| 331 | |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 332 | remove_fbs(data); |
Damien Lespiau | 1a75439 | 2014-07-09 14:00:59 +0100 | [diff] [blame] | 333 | |
Maarten Lankhorst | 9d809cd | 2017-06-06 17:12:20 +0200 | [diff] [blame] | 334 | igt_remove_fb(data->gfx_fd, &data->fb_modeset); |
| 335 | |
Damien Lespiau | 1a75439 | 2014-07-09 14:00:59 +0100 | [diff] [blame] | 336 | /* XXX: see the note in prepare_crtc() */ |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 337 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) { |
Damien Lespiau | 1a75439 | 2014-07-09 14:00:59 +0100 | [diff] [blame] | 338 | igt_plane_t *primary; |
| 339 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 340 | primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
Damien Lespiau | 1a75439 | 2014-07-09 14:00:59 +0100 | [diff] [blame] | 341 | igt_plane_set_fb(primary, NULL); |
| 342 | } |
| 343 | |
Damien Lespiau | 05f90b0 | 2014-07-08 18:51:25 +0100 | [diff] [blame] | 344 | igt_plane_set_fb(plane, NULL); |
Maarten Lankhorst | 44023a2 | 2017-01-31 13:31:57 +0100 | [diff] [blame] | 345 | igt_plane_set_rotation(plane, IGT_ROTATION_0); |
| 346 | |
| 347 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 348 | |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 349 | igt_output_set_pipe(output, PIPE_ANY); |
Damien Lespiau | eb81a92 | 2014-07-08 18:20:51 +0100 | [diff] [blame] | 350 | |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 351 | igt_display_commit(display); |
| 352 | } |
| 353 | |
Tvrtko Ursulin | 061a38f | 2015-10-07 12:18:52 +0100 | [diff] [blame] | 354 | static void wait_for_pageflip(int fd) |
| 355 | { |
Daniel Stone | d7db79d | 2017-04-07 14:15:26 +0100 | [diff] [blame] | 356 | drmEventContext evctx = { .version = 2 }; |
Maarten Lankhorst | 3c1362f | 2016-01-05 15:19:13 +0100 | [diff] [blame] | 357 | struct timeval timeout = { .tv_sec = 0, .tv_usec = 50000 }; |
Tvrtko Ursulin | 061a38f | 2015-10-07 12:18:52 +0100 | [diff] [blame] | 358 | fd_set fds; |
| 359 | int ret; |
| 360 | |
| 361 | /* Wait for pageflip completion, then consume event on fd */ |
| 362 | FD_ZERO(&fds); |
| 363 | FD_SET(fd, &fds); |
| 364 | do { |
| 365 | ret = select(fd + 1, &fds, NULL, NULL, &timeout); |
| 366 | } while (ret < 0 && errno == EINTR); |
| 367 | igt_assert_eq(ret, 1); |
| 368 | igt_assert(drmHandleEvent(fd, &evctx) == 0); |
| 369 | } |
| 370 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 371 | static void __test_plane_rotation(data_t *data, int plane_type, bool test_bad_format) |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 372 | { |
| 373 | igt_display_t *display = &data->display; |
| 374 | igt_output_t *output; |
Damien Lespiau | aef475b | 2014-07-08 18:43:44 +0100 | [diff] [blame] | 375 | enum pipe pipe; |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 376 | int valid_tests = 0; |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 377 | igt_crc_t crc_output; |
Damien Lespiau | c4564e0 | 2014-07-08 19:24:24 +0100 | [diff] [blame] | 378 | enum igt_commit_style commit = COMMIT_LEGACY; |
Tvrtko Ursulin | dbf6468 | 2015-04-22 16:46:48 +0100 | [diff] [blame] | 379 | int ret; |
Damien Lespiau | 13e979c | 2014-07-08 18:13:47 +0100 | [diff] [blame] | 380 | |
Maarten Lankhorst | 5f68064 | 2017-09-21 08:36:33 +0200 | [diff] [blame] | 381 | if (data->flips && plane_type != DRM_PLANE_TYPE_PRIMARY) |
| 382 | igt_require(data->display.is_atomic); |
| 383 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 384 | if (plane_type == DRM_PLANE_TYPE_PRIMARY || plane_type == DRM_PLANE_TYPE_CURSOR) |
Damien Lespiau | c4564e0 | 2014-07-08 19:24:24 +0100 | [diff] [blame] | 385 | commit = COMMIT_UNIVERSAL; |
Lyude | 80baeb0 | 2016-12-07 19:02:04 -0500 | [diff] [blame] | 386 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 387 | if (plane_type == DRM_PLANE_TYPE_CURSOR) |
Lyude | 80baeb0 | 2016-12-07 19:02:04 -0500 | [diff] [blame] | 388 | igt_require(display->has_cursor_plane); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 389 | |
pvishwak | 8b8d7aa | 2016-04-11 11:24:56 +0530 | [diff] [blame] | 390 | if (data->display.is_atomic) |
| 391 | commit = COMMIT_ATOMIC; |
| 392 | |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 393 | for_each_pipe_with_valid_output(display, pipe, output) { |
| 394 | igt_plane_t *plane; |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 395 | int i; |
Damien Lespiau | 05f90b0 | 2014-07-08 18:51:25 +0100 | [diff] [blame] | 396 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 397 | if (IS_CHERRYVIEW(data->devid) && pipe != PIPE_B) |
| 398 | continue; |
| 399 | |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 400 | igt_output_set_pipe(output, pipe); |
Damien Lespiau | 05f90b0 | 2014-07-08 18:51:25 +0100 | [diff] [blame] | 401 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 402 | plane = igt_output_get_plane_type(output, plane_type); |
Maarten Lankhorst | 2f7519a | 2017-10-04 16:29:51 +0200 | [diff] [blame] | 403 | igt_require(igt_plane_has_prop(plane, IGT_PLANE_ROTATION)); |
Damien Lespiau | 05f90b0 | 2014-07-08 18:51:25 +0100 | [diff] [blame] | 404 | |
Maarten Lankhorst | ca23986 | 2017-06-06 12:16:43 +0200 | [diff] [blame] | 405 | prepare_crtc(data, output, pipe, plane, commit); |
| 406 | |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 407 | for (i = 0; i < num_rectangle_types; i++) { |
| 408 | /* Unsupported on i915 */ |
| 409 | if (plane_type == DRM_PLANE_TYPE_CURSOR && |
| 410 | i != square) |
| 411 | continue; |
Daniel Vetter | 57259d7 | 2014-11-24 16:08:32 +0100 | [diff] [blame] | 412 | |
Maarten Lankhorst | a645824 | 2017-06-12 10:56:01 +0200 | [diff] [blame] | 413 | /* Only support partial covering primary plane on gen9+ */ |
| 414 | if (plane_type == DRM_PLANE_TYPE_PRIMARY && |
| 415 | i != rectangle && intel_gen(intel_get_drm_devid(data->gfx_fd)) < 9) |
| 416 | continue; |
| 417 | |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 418 | igt_debug("Testing case %i on pipe %s\n", i, kmstest_pipe_name(pipe)); |
| 419 | prepare_fbs(data, output, plane, i); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 420 | |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 421 | igt_plane_set_rotation(plane, data->rotation); |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 422 | if (data->rotation & (IGT_ROTATION_90 | IGT_ROTATION_270)) |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 423 | igt_plane_set_size(plane, data->fb.height, data->fb.width); |
| 424 | |
| 425 | ret = igt_display_try_commit2(display, commit); |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 426 | if (test_bad_format && (data->override_fmt || data->override_tiling)) { |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 427 | igt_assert_eq(ret, -EINVAL); |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 428 | continue; |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 429 | } |
| 430 | |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 431 | /* Verify commit was ok. */ |
| 432 | igt_assert_eq(ret, 0); |
| 433 | |
| 434 | /* Check CRC */ |
| 435 | igt_pipe_crc_collect_crc(data->pipe_crc, &crc_output); |
| 436 | igt_assert_crc_equal(&data->ref_crc, &crc_output); |
| 437 | |
| 438 | /* |
| 439 | * If flips are requested flip to a different fb and |
| 440 | * check CRC against that one as well. |
| 441 | */ |
| 442 | if (data->flips) { |
Maarten Lankhorst | 5f68064 | 2017-09-21 08:36:33 +0200 | [diff] [blame] | 443 | igt_plane_set_fb(plane, &data->fb_flip); |
| 444 | if (data->rotation == IGT_ROTATION_90 || data->rotation == IGT_ROTATION_270) |
| 445 | igt_plane_set_size(plane, data->fb.height, data->fb.width); |
| 446 | |
| 447 | if (plane_type != DRM_PLANE_TYPE_PRIMARY) { |
| 448 | igt_display_commit_atomic(display, DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK, NULL); |
| 449 | } else { |
| 450 | ret = drmModePageFlip(data->gfx_fd, |
| 451 | output->config.crtc->crtc_id, |
| 452 | data->fb_flip.fb_id, |
| 453 | DRM_MODE_PAGE_FLIP_EVENT, |
| 454 | NULL); |
| 455 | igt_assert_eq(ret, 0); |
| 456 | } |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 457 | wait_for_pageflip(data->gfx_fd); |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 458 | igt_pipe_crc_collect_crc(data->pipe_crc, |
| 459 | &crc_output); |
| 460 | igt_assert_crc_equal(&data->flip_crc, |
| 461 | &crc_output); |
Maarten Lankhorst | a7fe05b | 2017-06-06 16:41:12 +0200 | [diff] [blame] | 462 | } |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 465 | valid_tests++; |
| 466 | cleanup_crtc(data, output, plane); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 467 | } |
| 468 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
| 469 | } |
| 470 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 471 | static inline void test_bad_plane_rotation(data_t *data, int plane_type) |
| 472 | { |
| 473 | __test_plane_rotation(data, plane_type, true); |
| 474 | } |
| 475 | |
| 476 | static inline void test_plane_rotation(data_t *data, int plane_type) |
| 477 | { |
| 478 | __test_plane_rotation(data, plane_type, false); |
| 479 | } |
| 480 | |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 481 | static void test_plane_rotation_ytiled_obj(data_t *data, |
| 482 | igt_output_t *output, |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 483 | int plane_type) |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 484 | { |
| 485 | igt_display_t *display = &data->display; |
| 486 | uint64_t tiling = LOCAL_I915_FORMAT_MOD_Y_TILED; |
| 487 | uint32_t format = DRM_FORMAT_XRGB8888; |
| 488 | int bpp = igt_drm_format_to_bpp(format); |
| 489 | enum igt_commit_style commit = COMMIT_LEGACY; |
| 490 | int fd = data->gfx_fd; |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 491 | igt_plane_t *plane; |
| 492 | drmModeModeInfo *mode; |
| 493 | unsigned int stride, size, w, h; |
| 494 | uint32_t gem_handle; |
| 495 | int ret; |
| 496 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 497 | plane = igt_output_get_plane_type(output, plane_type); |
Maarten Lankhorst | 2f7519a | 2017-10-04 16:29:51 +0200 | [diff] [blame] | 498 | igt_require(igt_plane_has_prop(plane, IGT_PLANE_ROTATION)); |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 499 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 500 | if (plane_type == DRM_PLANE_TYPE_PRIMARY || plane_type == DRM_PLANE_TYPE_CURSOR) |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 501 | commit = COMMIT_UNIVERSAL; |
Lyude | 80baeb0 | 2016-12-07 19:02:04 -0500 | [diff] [blame] | 502 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 503 | if (plane_type == DRM_PLANE_TYPE_CURSOR) |
Lyude | 80baeb0 | 2016-12-07 19:02:04 -0500 | [diff] [blame] | 504 | igt_require(display->has_cursor_plane); |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 505 | |
pvishwak | 8b8d7aa | 2016-04-11 11:24:56 +0530 | [diff] [blame] | 506 | if (data->display.is_atomic) |
| 507 | commit = COMMIT_ATOMIC; |
| 508 | |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 509 | mode = igt_output_get_mode(output); |
| 510 | w = mode->hdisplay; |
| 511 | h = mode->vdisplay; |
| 512 | |
| 513 | for (stride = 512; stride < (w * bpp / 8); stride *= 2) |
| 514 | ; |
| 515 | for (size = 1024*1024; size < stride * h; size *= 2) |
| 516 | ; |
| 517 | |
| 518 | gem_handle = gem_create(fd, size); |
| 519 | ret = __gem_set_tiling(fd, gem_handle, I915_TILING_Y, stride); |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 520 | igt_assert_eq(ret, 0); |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 521 | |
| 522 | do_or_die(__kms_addfb(fd, gem_handle, w, h, stride, |
| 523 | format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS, |
| 524 | &data->fb.fb_id)); |
| 525 | data->fb.width = w; |
| 526 | data->fb.height = h; |
| 527 | data->fb.gem_handle = gem_handle; |
| 528 | |
| 529 | igt_plane_set_fb(plane, NULL); |
| 530 | igt_display_commit(display); |
| 531 | |
| 532 | igt_plane_set_rotation(plane, data->rotation); |
| 533 | igt_plane_set_fb(plane, &data->fb); |
Maarten Lankhorst | 44023a2 | 2017-01-31 13:31:57 +0100 | [diff] [blame] | 534 | igt_plane_set_size(plane, h, w); |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 535 | |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 536 | ret = igt_display_try_commit2(display, commit); |
| 537 | |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 538 | igt_output_set_pipe(output, PIPE_NONE); |
| 539 | |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 540 | kmstest_restore_vt_mode(); |
| 541 | igt_remove_fb(fd, &data->fb); |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 542 | igt_assert_eq(ret, 0); |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 545 | static void test_plane_rotation_exhaust_fences(data_t *data, |
| 546 | igt_output_t *output, |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 547 | int plane_type) |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 548 | { |
| 549 | igt_display_t *display = &data->display; |
| 550 | uint64_t tiling = LOCAL_I915_FORMAT_MOD_Y_TILED; |
| 551 | uint32_t format = DRM_FORMAT_XRGB8888; |
| 552 | int bpp = igt_drm_format_to_bpp(format); |
| 553 | enum igt_commit_style commit = COMMIT_LEGACY; |
| 554 | int fd = data->gfx_fd; |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 555 | igt_plane_t *plane; |
| 556 | drmModeModeInfo *mode; |
| 557 | data_t data2[MAX_FENCES+1] = {}; |
| 558 | unsigned int stride, size, w, h; |
| 559 | uint32_t gem_handle; |
| 560 | uint64_t total_aperture_size, total_fbs_size; |
| 561 | int i, ret; |
| 562 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 563 | plane = igt_output_get_plane_type(output, plane_type); |
Maarten Lankhorst | 2f7519a | 2017-10-04 16:29:51 +0200 | [diff] [blame] | 564 | igt_require(igt_plane_has_prop(plane, IGT_PLANE_ROTATION)); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 565 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 566 | if (plane_type == DRM_PLANE_TYPE_PRIMARY || plane_type == DRM_PLANE_TYPE_CURSOR) |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 567 | commit = COMMIT_UNIVERSAL; |
Lyude | 80baeb0 | 2016-12-07 19:02:04 -0500 | [diff] [blame] | 568 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 569 | if (plane_type == DRM_PLANE_TYPE_CURSOR) |
Lyude | 80baeb0 | 2016-12-07 19:02:04 -0500 | [diff] [blame] | 570 | igt_require(display->has_cursor_plane); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 571 | |
pvishwak | 8b8d7aa | 2016-04-11 11:24:56 +0530 | [diff] [blame] | 572 | if (data->display.is_atomic) |
| 573 | commit = COMMIT_ATOMIC; |
| 574 | |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 575 | mode = igt_output_get_mode(output); |
| 576 | w = mode->hdisplay; |
| 577 | h = mode->vdisplay; |
| 578 | |
| 579 | for (stride = 512; stride < (w * bpp / 8); stride *= 2) |
| 580 | ; |
| 581 | for (size = 1024*1024; size < stride * h; size *= 2) |
| 582 | ; |
| 583 | |
| 584 | /* |
| 585 | * Make sure there is atleast 90% of the available GTT space left |
| 586 | * for creating (MAX_FENCES+1) framebuffers. |
| 587 | */ |
| 588 | total_fbs_size = size * (MAX_FENCES + 1); |
Chris Wilson | 1603890 | 2016-02-18 10:35:10 +0000 | [diff] [blame] | 589 | total_aperture_size = gem_available_aperture_size(fd); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 590 | igt_require(total_fbs_size < total_aperture_size * 0.9); |
| 591 | |
| 592 | igt_plane_set_fb(plane, NULL); |
| 593 | igt_display_commit(display); |
| 594 | |
| 595 | for (i = 0; i < MAX_FENCES + 1; i++) { |
| 596 | gem_handle = gem_create(fd, size); |
| 597 | ret = __gem_set_tiling(fd, gem_handle, I915_TILING_Y, stride); |
| 598 | if (ret) { |
| 599 | igt_warn("failed to set tiling\n"); |
| 600 | goto err_alloc; |
| 601 | } |
| 602 | |
| 603 | ret = (__kms_addfb(fd, gem_handle, w, h, stride, |
| 604 | format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS, |
| 605 | &data2[i].fb.fb_id)); |
| 606 | if (ret) { |
| 607 | igt_warn("failed to create framebuffer\n"); |
| 608 | goto err_alloc; |
| 609 | } |
| 610 | |
| 611 | data2[i].fb.width = w; |
| 612 | data2[i].fb.height = h; |
| 613 | data2[i].fb.gem_handle = gem_handle; |
| 614 | |
| 615 | igt_plane_set_fb(plane, &data2[i].fb); |
| 616 | igt_plane_set_rotation(plane, IGT_ROTATION_0); |
| 617 | |
| 618 | ret = igt_display_try_commit2(display, commit); |
| 619 | if (ret) { |
| 620 | igt_warn("failed to commit unrotated fb\n"); |
| 621 | goto err_commit; |
| 622 | } |
| 623 | |
| 624 | igt_plane_set_rotation(plane, IGT_ROTATION_90); |
Maarten Lankhorst | 44023a2 | 2017-01-31 13:31:57 +0100 | [diff] [blame] | 625 | igt_plane_set_size(plane, h, w); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 626 | |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 627 | igt_display_commit2(display, commit); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 628 | if (ret) { |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 629 | igt_warn("failed to commit hardware rotated fb: %i\n", ret); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 630 | goto err_commit; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | err_alloc: |
| 635 | if (ret) |
| 636 | gem_close(fd, gem_handle); |
| 637 | |
| 638 | i--; |
| 639 | err_commit: |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 640 | igt_plane_set_fb(plane, NULL); |
| 641 | igt_plane_set_rotation(plane, IGT_ROTATION_0); |
| 642 | |
| 643 | if (commit < COMMIT_ATOMIC) |
| 644 | igt_display_commit2(display, commit); |
| 645 | |
| 646 | igt_output_set_pipe(output, PIPE_NONE); |
| 647 | igt_display_commit2(display, display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY); |
| 648 | |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 649 | for (; i >= 0; i--) |
| 650 | igt_remove_fb(fd, &data2[i].fb); |
| 651 | |
| 652 | kmstest_restore_vt_mode(); |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 653 | igt_assert_eq(ret, 0); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 656 | static const char *plane_test_str(unsigned plane) |
| 657 | { |
| 658 | switch (plane) { |
| 659 | case DRM_PLANE_TYPE_PRIMARY: |
| 660 | return "primary"; |
| 661 | case DRM_PLANE_TYPE_OVERLAY: |
| 662 | return "sprite"; |
| 663 | case DRM_PLANE_TYPE_CURSOR: |
| 664 | return "cursor"; |
| 665 | default: |
| 666 | igt_assert(0); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | static const char *rot_test_str(igt_rotation_t rot) |
| 671 | { |
| 672 | switch (rot) { |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 673 | case IGT_ROTATION_0: |
| 674 | return "0"; |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 675 | case IGT_ROTATION_90: |
| 676 | return "90"; |
| 677 | case IGT_ROTATION_180: |
| 678 | return "180"; |
| 679 | case IGT_ROTATION_270: |
| 680 | return "270"; |
| 681 | default: |
| 682 | igt_assert(0); |
| 683 | } |
| 684 | } |
| 685 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 686 | static const char *tiling_test_str(uint64_t tiling) |
| 687 | { |
| 688 | switch (tiling) { |
| 689 | case LOCAL_I915_FORMAT_MOD_X_TILED: |
| 690 | return "x-tiled"; |
| 691 | case LOCAL_I915_FORMAT_MOD_Y_TILED: |
| 692 | return "y-tiled"; |
| 693 | case LOCAL_I915_FORMAT_MOD_Yf_TILED: |
| 694 | return "yf-tiled"; |
| 695 | default: |
| 696 | igt_assert(0); |
| 697 | } |
| 698 | } |
| 699 | |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 700 | static const char *flip_test_str(unsigned flips) |
| 701 | { |
| 702 | if (flips) |
| 703 | return "-flip"; |
| 704 | else |
| 705 | return ""; |
| 706 | } |
| 707 | |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 708 | igt_main |
| 709 | { |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 710 | struct rot_subtest { |
| 711 | unsigned plane; |
| 712 | igt_rotation_t rot; |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 713 | bool flips; |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 714 | } *subtest, subtests[] = { |
| 715 | { DRM_PLANE_TYPE_PRIMARY, IGT_ROTATION_90, 0 }, |
| 716 | { DRM_PLANE_TYPE_PRIMARY, IGT_ROTATION_180, 0 }, |
| 717 | { DRM_PLANE_TYPE_PRIMARY, IGT_ROTATION_270, 0 }, |
| 718 | { DRM_PLANE_TYPE_PRIMARY, IGT_ROTATION_90, 1 }, |
| 719 | { DRM_PLANE_TYPE_PRIMARY, IGT_ROTATION_180, 1 }, |
| 720 | { DRM_PLANE_TYPE_PRIMARY, IGT_ROTATION_270, 1 }, |
| 721 | { DRM_PLANE_TYPE_OVERLAY, IGT_ROTATION_90, 0 }, |
| 722 | { DRM_PLANE_TYPE_OVERLAY, IGT_ROTATION_180, 0 }, |
| 723 | { DRM_PLANE_TYPE_OVERLAY, IGT_ROTATION_270, 0 }, |
| 724 | { DRM_PLANE_TYPE_OVERLAY, IGT_ROTATION_90, 1 }, |
| 725 | { DRM_PLANE_TYPE_OVERLAY, IGT_ROTATION_180, 1 }, |
| 726 | { DRM_PLANE_TYPE_OVERLAY, IGT_ROTATION_270, 1 }, |
| 727 | { DRM_PLANE_TYPE_CURSOR, IGT_ROTATION_180, 0 }, |
| 728 | { 0, 0, 0} |
| 729 | }; |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 730 | |
| 731 | struct reflect_x { |
| 732 | uint64_t tiling; |
| 733 | igt_rotation_t rot; |
| 734 | bool flips; |
| 735 | } *reflect_x, reflect_x_subtests[] = { |
| 736 | { LOCAL_I915_FORMAT_MOD_X_TILED, IGT_ROTATION_0, 0 }, |
| 737 | { LOCAL_I915_FORMAT_MOD_X_TILED, IGT_ROTATION_180, 0 }, |
| 738 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_0, 0 }, |
| 739 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_90, 0 }, |
| 740 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_180, 0 }, |
| 741 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_270, 0 }, |
| 742 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_0, 0 }, |
| 743 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_90, 0 }, |
| 744 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_180, 0 }, |
| 745 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_270, 0 }, |
| 746 | { LOCAL_I915_FORMAT_MOD_X_TILED, IGT_ROTATION_0, 1 }, |
| 747 | { LOCAL_I915_FORMAT_MOD_X_TILED, IGT_ROTATION_180, 1 }, |
| 748 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_0, 1 }, |
| 749 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_90, 1 }, |
| 750 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_180, 1 }, |
| 751 | { LOCAL_I915_FORMAT_MOD_Y_TILED, IGT_ROTATION_270, 1 }, |
| 752 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_0, 1 }, |
| 753 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_90, 1 }, |
| 754 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_180, 1 }, |
| 755 | { LOCAL_I915_FORMAT_MOD_Yf_TILED, IGT_ROTATION_270, 1 }, |
| 756 | { 0, 0, 0 } |
| 757 | }; |
| 758 | |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 759 | data_t data = {}; |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 760 | int gen = 0; |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 761 | |
| 762 | igt_skip_on_simulation(); |
| 763 | |
| 764 | igt_fixture { |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 765 | data.gfx_fd = drm_open_driver_master(DRIVER_INTEL); |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 766 | data.devid = intel_get_drm_devid(data.gfx_fd); |
| 767 | gen = intel_gen(data.devid); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 768 | |
Daniel Vetter | 33f0884 | 2014-08-12 11:23:09 +0200 | [diff] [blame] | 769 | kmstest_set_vt_graphics_mode(); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 770 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 771 | igt_require_pipe_crc(data.gfx_fd); |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 772 | |
| 773 | igt_display_init(&data.display, data.gfx_fd); |
| 774 | } |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 775 | |
Tvrtko Ursulin | af41586 | 2017-09-11 18:14:57 +0100 | [diff] [blame] | 776 | for (subtest = subtests; subtest->rot; subtest++) { |
| 777 | igt_subtest_f("%s-rotation-%s%s", |
| 778 | plane_test_str(subtest->plane), |
| 779 | rot_test_str(subtest->rot), |
| 780 | flip_test_str(subtest->flips)) { |
| 781 | igt_require(!(subtest->rot & |
| 782 | (IGT_ROTATION_90 | IGT_ROTATION_270)) || |
| 783 | gen >= 9); |
| 784 | data.rotation = subtest->rot; |
| 785 | data.flips = subtest->flips; |
| 786 | test_plane_rotation(&data, subtest->plane); |
| 787 | } |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | igt_subtest_f("sprite-rotation-90-pos-100-0") { |
| 791 | igt_require(gen >= 9); |
| 792 | data.rotation = IGT_ROTATION_90; |
| 793 | data.pos_x = 100, |
| 794 | data.pos_y = 0; |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 795 | test_plane_rotation(&data, DRM_PLANE_TYPE_OVERLAY); |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 796 | } |
| 797 | |
Tvrtko Ursulin | dbf6468 | 2015-04-22 16:46:48 +0100 | [diff] [blame] | 798 | igt_subtest_f("bad-pixel-format") { |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 799 | igt_require(gen >= 9); |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 800 | data.pos_x = 0, |
| 801 | data.pos_y = 0; |
Tvrtko Ursulin | dbf6468 | 2015-04-22 16:46:48 +0100 | [diff] [blame] | 802 | data.rotation = IGT_ROTATION_90; |
| 803 | data.override_fmt = DRM_FORMAT_RGB565; |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 804 | test_bad_plane_rotation(&data, DRM_PLANE_TYPE_PRIMARY); |
Tvrtko Ursulin | dbf6468 | 2015-04-22 16:46:48 +0100 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | igt_subtest_f("bad-tiling") { |
| 808 | igt_require(gen >= 9); |
| 809 | data.override_fmt = 0; |
| 810 | data.rotation = IGT_ROTATION_90; |
| 811 | data.override_tiling = LOCAL_DRM_FORMAT_MOD_NONE; |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 812 | test_bad_plane_rotation(&data, DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | e1ce5ea | 2015-04-22 16:44:05 +0530 | [diff] [blame] | 813 | } |
Sonika Jindal | 4724698 | 2014-10-23 08:48:50 -0700 | [diff] [blame] | 814 | |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 815 | igt_subtest_f("primary-rotation-90-Y-tiled") { |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 816 | enum pipe pipe; |
| 817 | igt_output_t *output; |
| 818 | int valid_tests = 0; |
| 819 | |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 820 | igt_require(gen >= 9); |
| 821 | data.rotation = IGT_ROTATION_90; |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 822 | |
| 823 | for_each_pipe_with_valid_output(&data.display, pipe, output) { |
| 824 | igt_output_set_pipe(output, pipe); |
| 825 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 826 | test_plane_rotation_ytiled_obj(&data, output, DRM_PLANE_TYPE_PRIMARY); |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 827 | |
| 828 | valid_tests++; |
| 829 | break; |
| 830 | } |
| 831 | |
| 832 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
Vivek Kasireddy | fe548fa | 2015-10-22 18:34:03 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Joseph Garvey | d242cd8 | 2017-11-22 15:05:55 -0800 | [diff] [blame] | 835 | for (reflect_x = reflect_x_subtests; reflect_x->tiling; reflect_x++) { |
| 836 | igt_subtest_f("primary-%s-reflect-x-%s%s", |
| 837 | tiling_test_str(reflect_x->tiling), |
| 838 | rot_test_str(reflect_x->rot), |
| 839 | flip_test_str(reflect_x->flips)) { |
| 840 | igt_require(gen >= 10 || |
| 841 | (IS_CHERRYVIEW(data.devid) && reflect_x->rot == IGT_ROTATION_0 |
| 842 | && reflect_x->tiling == LOCAL_I915_FORMAT_MOD_X_TILED)); |
| 843 | data.rotation = (IGT_REFLECT_X | reflect_x->rot); |
| 844 | data.override_tiling = reflect_x->tiling; |
| 845 | data.flips = reflect_x->flips; |
| 846 | test_plane_rotation(&data, DRM_PLANE_TYPE_PRIMARY); |
| 847 | } |
| 848 | } |
| 849 | |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 850 | igt_subtest_f("exhaust-fences") { |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 851 | enum pipe pipe; |
| 852 | igt_output_t *output; |
| 853 | int valid_tests = 0; |
| 854 | |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 855 | igt_require(gen >= 9); |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 856 | |
| 857 | for_each_pipe_with_valid_output(&data.display, pipe, output) { |
| 858 | igt_output_set_pipe(output, pipe); |
| 859 | |
Robert Foss | 3e04c51 | 2017-01-10 20:18:41 -0500 | [diff] [blame] | 860 | test_plane_rotation_exhaust_fences(&data, output, DRM_PLANE_TYPE_PRIMARY); |
Maarten Lankhorst | eeffa25 | 2017-01-05 14:13:34 +0100 | [diff] [blame] | 861 | |
| 862 | valid_tests++; |
| 863 | break; |
| 864 | } |
| 865 | |
| 866 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
Vivek Kasireddy | 938b930 | 2015-11-04 16:10:15 -0800 | [diff] [blame] | 867 | } |
| 868 | |
Sonika Jindal | e361139 | 2014-06-18 14:27:27 +0530 | [diff] [blame] | 869 | igt_fixture { |
| 870 | igt_display_fini(&data.display); |
| 871 | } |
| 872 | } |