chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013,2014 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 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 25 | #include "igt.h" |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 26 | #include <math.h> |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 27 | #include <sys/stat.h> |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 28 | |
| 29 | IGT_TEST_DESCRIPTION("Test display panel fitting"); |
| 30 | |
| 31 | typedef struct { |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 32 | int drm_fd; |
| 33 | igt_display_t display; |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 34 | |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 35 | struct igt_fb fb1; |
| 36 | struct igt_fb fb2; |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 37 | |
| 38 | igt_plane_t *plane1; |
| 39 | igt_plane_t *plane2; |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 40 | } data_t; |
| 41 | |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 42 | static void cleanup_crtc(data_t *data) |
| 43 | { |
| 44 | igt_display_reset(&data->display); |
| 45 | igt_remove_fb(data->drm_fd, &data->fb1); |
| 46 | igt_remove_fb(data->drm_fd, &data->fb2); |
| 47 | } |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 48 | |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 49 | static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe, |
| 50 | igt_plane_t *plane, drmModeModeInfo *mode, enum igt_commit_style s) |
| 51 | { |
| 52 | igt_display_t *display = &data->display; |
| 53 | |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 54 | igt_output_override_mode(output, mode); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 55 | igt_output_set_pipe(output, pipe); |
| 56 | |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 57 | /* before allocating, free if any older fb */ |
Maarten Lankhorst | aa5068c | 2018-02-02 11:00:50 +0100 | [diff] [blame] | 58 | igt_remove_fb(data->drm_fd, &data->fb1); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 59 | |
| 60 | /* allocate fb for plane 1 */ |
Maarten Lankhorst | 2646ae1 | 2018-01-18 12:54:07 +0100 | [diff] [blame] | 61 | igt_create_pattern_fb(data->drm_fd, |
| 62 | mode->hdisplay, mode->vdisplay, |
| 63 | DRM_FORMAT_XRGB8888, |
| 64 | LOCAL_DRM_FORMAT_MOD_NONE, |
| 65 | &data->fb1); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 66 | |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 67 | /* |
| 68 | * We always set the primary plane to actually enable the pipe as |
| 69 | * there's no way (that works) to light up a pipe with only a sprite |
| 70 | * plane enabled at the moment. |
| 71 | */ |
Robert Foss | 303937a | 2017-01-10 20:04:55 -0500 | [diff] [blame] | 72 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) { |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 73 | igt_plane_t *primary; |
| 74 | |
Robert Foss | 303937a | 2017-01-10 20:04:55 -0500 | [diff] [blame] | 75 | primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 76 | igt_plane_set_fb(primary, &data->fb1); |
| 77 | } |
| 78 | |
| 79 | igt_plane_set_fb(plane, &data->fb1); |
Maarten Lankhorst | 7df7e3b | 2017-09-21 12:53:27 +0200 | [diff] [blame] | 80 | igt_display_commit2(display, s); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 81 | } |
| 82 | |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 83 | static void test_panel_fitting(data_t *d) |
| 84 | { |
| 85 | igt_display_t *display = &d->display; |
| 86 | igt_output_t *output; |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 87 | enum pipe pipe; |
| 88 | int valid_tests = 0; |
| 89 | |
Maarten Lankhorst | 5af520a | 2016-07-05 12:53:05 +0200 | [diff] [blame] | 90 | for_each_pipe_with_valid_output(display, pipe, output) { |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 91 | drmModeModeInfo *mode, native_mode; |
Maarten Lankhorst | 24c5e07 | 2018-05-24 09:00:47 +0200 | [diff] [blame] | 92 | uint32_t devid = intel_get_drm_devid(display->drm_fd); |
Robert Foss | ec83ef9 | 2016-05-03 10:40:22 -0400 | [diff] [blame] | 93 | |
| 94 | /* Check that the "scaling mode" property has been set. */ |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 95 | if (!igt_output_has_prop(output, IGT_CONNECTOR_SCALING_MODE)) |
Robert Foss | 26afcfc | 2016-05-03 10:40:16 -0400 | [diff] [blame] | 96 | continue; |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 97 | |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 98 | cleanup_crtc(d); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 99 | igt_output_set_pipe(output, pipe); |
| 100 | |
| 101 | mode = igt_output_get_mode(output); |
| 102 | native_mode = *mode; |
| 103 | |
Maarten Lankhorst | 2646ae1 | 2018-01-18 12:54:07 +0100 | [diff] [blame] | 104 | /* allocate fb2 with image */ |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 105 | igt_create_pattern_fb(d->drm_fd, mode->hdisplay / 2, mode->vdisplay / 2, |
| 106 | DRM_FORMAT_XRGB8888, |
| 107 | LOCAL_DRM_FORMAT_MOD_NONE, &d->fb2); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 108 | |
| 109 | /* Set up display to enable panel fitting */ |
| 110 | mode->hdisplay = 640; |
| 111 | mode->vdisplay = 480; |
Robert Foss | 303937a | 2017-01-10 20:04:55 -0500 | [diff] [blame] | 112 | d->plane1 = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 113 | prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY); |
| 114 | |
| 115 | /* disable panel fitting */ |
| 116 | prepare_crtc(d, output, pipe, d->plane1, &native_mode, COMMIT_LEGACY); |
| 117 | |
| 118 | /* enable panel fitting */ |
| 119 | mode->hdisplay = 800; |
| 120 | mode->vdisplay = 600; |
| 121 | prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY); |
| 122 | |
| 123 | /* disable panel fitting */ |
| 124 | prepare_crtc(d, output, pipe, d->plane1, &native_mode, COMMIT_LEGACY); |
| 125 | |
| 126 | /* Set up fb2->plane2 mapping. */ |
Robert Foss | 303937a | 2017-01-10 20:04:55 -0500 | [diff] [blame] | 127 | d->plane2 = igt_output_get_plane_type(output, DRM_PLANE_TYPE_OVERLAY); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 128 | igt_plane_set_fb(d->plane2, &d->fb2); |
| 129 | |
| 130 | /* enable sprite plane */ |
| 131 | igt_fb_set_position(&d->fb2, d->plane2, 100, 100); |
| 132 | igt_fb_set_size(&d->fb2, d->plane2, d->fb2.width-200, d->fb2.height-200); |
| 133 | igt_plane_set_position(d->plane2, 100, 100); |
| 134 | igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200); |
| 135 | igt_display_commit2(display, COMMIT_UNIVERSAL); |
| 136 | |
Maarten Lankhorst | 8a26e0e | 2018-03-14 11:47:30 +0100 | [diff] [blame] | 137 | /* |
Maarten Lankhorst | 24c5e07 | 2018-05-24 09:00:47 +0200 | [diff] [blame] | 138 | * most of gen7 and all of gen8 doesn't support scaling at all. |
| 139 | * |
Maarten Lankhorst | 8a26e0e | 2018-03-14 11:47:30 +0100 | [diff] [blame] | 140 | * gen9 pipe C has only 1 scaler shared with the crtc, which |
| 141 | * means pipe scaling can't work simultaneously with panel |
| 142 | * fitting. |
| 143 | * |
| 144 | * Since this is the legacy path, userspace has to know about |
| 145 | * the HW limitations, whereas atomic can ask. |
| 146 | */ |
Maarten Lankhorst | 24c5e07 | 2018-05-24 09:00:47 +0200 | [diff] [blame] | 147 | if (IS_GEN8(devid) || (IS_GEN7(devid) && !IS_IVYBRIDGE(devid)) || |
| 148 | (IS_GEN9(devid) && pipe == PIPE_C)) |
Maarten Lankhorst | 8a26e0e | 2018-03-14 11:47:30 +0100 | [diff] [blame] | 149 | igt_plane_set_size(d->plane2, d->fb2.width-200, d->fb2.height-200); |
| 150 | |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 151 | /* enable panel fitting along with sprite scaling */ |
| 152 | mode->hdisplay = 1024; |
| 153 | mode->vdisplay = 768; |
| 154 | prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY); |
| 155 | |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 156 | valid_tests++; |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 157 | } |
| 158 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
| 159 | } |
| 160 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 161 | static void |
| 162 | test_panel_fitting_fastset(igt_display_t *display, const enum pipe pipe, igt_output_t *output) |
| 163 | { |
| 164 | igt_plane_t *primary, *sprite; |
| 165 | drmModeModeInfo mode; |
Maarten Lankhorst | 56f1bd6 | 2016-11-28 12:36:02 +0100 | [diff] [blame] | 166 | struct igt_fb red, green, blue; |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 167 | |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 168 | mode = *igt_output_get_mode(output); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 169 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 170 | igt_output_set_pipe(output, pipe); |
| 171 | |
Robert Foss | 303937a | 2017-01-10 20:04:55 -0500 | [diff] [blame] | 172 | primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
| 173 | sprite = igt_output_get_plane_type(output, DRM_PLANE_TYPE_OVERLAY); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 174 | |
| 175 | igt_create_color_fb(display->drm_fd, mode.hdisplay, mode.vdisplay, |
| 176 | DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
Maarten Lankhorst | 56f1bd6 | 2016-11-28 12:36:02 +0100 | [diff] [blame] | 177 | 0.f, 0.f, 1.f, &blue); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 178 | |
| 179 | igt_create_color_fb(display->drm_fd, 640, 480, |
| 180 | DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 181 | 1.f, 0.f, 0.f, &red); |
| 182 | |
Maarten Lankhorst | 56f1bd6 | 2016-11-28 12:36:02 +0100 | [diff] [blame] | 183 | igt_create_color_fb(display->drm_fd, 800, 600, |
| 184 | DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE, |
| 185 | 0.f, 1.f, 0.f, &green); |
| 186 | |
| 187 | igt_plane_set_fb(primary, &blue); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 188 | igt_plane_set_fb(sprite, &red); |
| 189 | |
| 190 | igt_display_commit2(display, COMMIT_ATOMIC); |
| 191 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 192 | mode.hdisplay = 640; |
| 193 | mode.vdisplay = 480; |
| 194 | igt_output_override_mode(output, &mode); |
| 195 | |
| 196 | igt_plane_set_fb(sprite, NULL); |
| 197 | igt_plane_set_fb(primary, &red); |
| 198 | |
| 199 | /* Don't pass ALLOW_MODESET with overridden mode, force fastset. */ |
| 200 | igt_display_commit_atomic(display, 0, NULL); |
| 201 | |
Maarten Lankhorst | 56f1bd6 | 2016-11-28 12:36:02 +0100 | [diff] [blame] | 202 | /* Test with different scaled mode */ |
| 203 | mode.hdisplay = 800; |
| 204 | mode.vdisplay = 600; |
| 205 | igt_output_override_mode(output, &mode); |
| 206 | igt_plane_set_fb(primary, &green); |
| 207 | igt_display_commit_atomic(display, 0, NULL); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 210 | static void test_atomic_fastset(data_t *data) |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 211 | { |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 212 | igt_display_t *display = &data->display; |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 213 | igt_output_t *output; |
| 214 | enum pipe pipe; |
| 215 | int valid_tests = 0; |
| 216 | struct stat sb; |
| 217 | |
| 218 | /* Until this is force enabled, force modeset evasion. */ |
| 219 | if (stat("/sys/module/i915/parameters/fastboot", &sb) == 0) |
| 220 | igt_set_module_param_int("fastboot", 1); |
| 221 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 222 | igt_require(display->is_atomic); |
| 223 | igt_require(intel_gen(intel_get_drm_devid(display->drm_fd)) >= 5); |
| 224 | |
| 225 | for_each_pipe_with_valid_output(display, pipe, output) { |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 226 | if (!igt_output_has_prop(output, IGT_CONNECTOR_SCALING_MODE)) |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 227 | continue; |
| 228 | |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 229 | cleanup_crtc(data); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 230 | test_panel_fitting_fastset(display, pipe, output); |
| 231 | valid_tests++; |
| 232 | } |
| 233 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
| 234 | } |
| 235 | |
| 236 | igt_main |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 237 | { |
| 238 | data_t data = {}; |
| 239 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 240 | igt_fixture { |
| 241 | igt_skip_on_simulation(); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 242 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 243 | data.drm_fd = drm_open_driver(DRIVER_ANY); |
Chris Wilson | 7f41adf | 2018-09-14 21:10:05 +0100 | [diff] [blame] | 244 | igt_display_require(&data.display, data.drm_fd); |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 245 | igt_display_require_output(&data.display); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 246 | } |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 247 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 248 | igt_subtest("legacy") |
| 249 | test_panel_fitting(&data); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 250 | |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 251 | igt_subtest("atomic-fastset") |
Maarten Lankhorst | 3df9f71 | 2018-02-22 13:37:10 +0100 | [diff] [blame] | 252 | test_atomic_fastset(&data); |
Maarten Lankhorst | 3817052 | 2016-07-05 14:55:52 +0200 | [diff] [blame] | 253 | |
| 254 | igt_fixture |
| 255 | igt_display_fini(&data.display); |
chandra konduru | 8b3082a | 2015-03-30 13:53:00 -0700 | [diff] [blame] | 256 | } |