Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016 Red Hat Inc. |
| 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 | * Authors: |
| 24 | * Lyude Paul <lyude@redhat.com> |
| 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | #include "igt.h" |
| 29 | |
| 30 | #include <fcntl.h> |
| 31 | #include <string.h> |
| 32 | |
| 33 | typedef struct { |
| 34 | struct chamelium *chamelium; |
| 35 | struct chamelium_port **ports; |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 36 | igt_display_t display; |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 37 | int port_count; |
| 38 | |
| 39 | int drm_fd; |
| 40 | |
| 41 | int edid_id; |
| 42 | int alt_edid_id; |
| 43 | } data_t; |
| 44 | |
| 45 | #define HOTPLUG_TIMEOUT 20 /* seconds */ |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 46 | |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 47 | #define HPD_STORM_PULSE_INTERVAL_DP 100 /* ms */ |
| 48 | #define HPD_STORM_PULSE_INTERVAL_HDMI 200 /* ms */ |
| 49 | |
Paul Kocialkowki | 7d714b2 | 2017-06-27 13:53:08 +0300 | [diff] [blame] | 50 | #define HPD_TOGGLE_COUNT_VGA 5 |
| 51 | #define HPD_TOGGLE_COUNT_DP_HDMI 15 |
Paul Kocialkowski | 4ee824e | 2017-08-23 18:21:12 +0300 | [diff] [blame] | 52 | #define HPD_TOGGLE_COUNT_FAST 3 |
Paul Kocialkowki | 7d714b2 | 2017-06-27 13:53:08 +0300 | [diff] [blame] | 53 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 54 | static void |
Paul Kocialkowski | a944394 | 2017-07-18 18:15:52 +0300 | [diff] [blame] | 55 | get_connectors_link_status_failed(data_t *data, bool *link_status_failed) |
| 56 | { |
| 57 | drmModeConnector *connector; |
| 58 | uint64_t link_status; |
| 59 | drmModePropertyPtr prop; |
| 60 | int p; |
| 61 | |
| 62 | for (p = 0; p < data->port_count; p++) { |
| 63 | connector = chamelium_port_get_connector(data->chamelium, |
| 64 | data->ports[p], false); |
| 65 | |
| 66 | igt_assert(kmstest_get_property(data->drm_fd, |
| 67 | connector->connector_id, |
| 68 | DRM_MODE_OBJECT_CONNECTOR, |
| 69 | "link-status", NULL, |
| 70 | &link_status, &prop)); |
| 71 | |
| 72 | link_status_failed[p] = link_status == DRM_MODE_LINK_STATUS_BAD; |
| 73 | |
| 74 | drmModeFreeProperty(prop); |
| 75 | drmModeFreeConnector(connector); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static void |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 80 | require_connector_present(data_t *data, unsigned int type) |
| 81 | { |
| 82 | int i; |
| 83 | bool found = false; |
| 84 | |
| 85 | for (i = 0; i < data->port_count && !found; i++) { |
| 86 | if (chamelium_port_get_type(data->ports[i]) == type) |
| 87 | found = true; |
| 88 | } |
| 89 | |
| 90 | igt_require_f(found, "No port of type %s was found\n", |
| 91 | kmstest_connector_type_str(type)); |
| 92 | } |
| 93 | |
| 94 | static drmModeConnection |
| 95 | reprobe_connector(data_t *data, struct chamelium_port *port) |
| 96 | { |
| 97 | drmModeConnector *connector; |
| 98 | drmModeConnection status; |
| 99 | |
| 100 | igt_debug("Reprobing %s...\n", chamelium_port_get_name(port)); |
| 101 | connector = chamelium_port_get_connector(data->chamelium, port, true); |
| 102 | igt_assert(connector); |
| 103 | status = connector->connection; |
| 104 | |
| 105 | drmModeFreeConnector(connector); |
| 106 | return status; |
| 107 | } |
| 108 | |
| 109 | static void |
| 110 | wait_for_connector(data_t *data, struct chamelium_port *port, |
| 111 | drmModeConnection status) |
| 112 | { |
| 113 | bool finished = false; |
| 114 | |
| 115 | igt_debug("Waiting for %s to %sconnect...\n", |
| 116 | chamelium_port_get_name(port), |
| 117 | status == DRM_MODE_DISCONNECTED ? "dis" : ""); |
| 118 | |
| 119 | /* |
| 120 | * Rely on simple reprobing so we don't fail tests that don't require |
| 121 | * that hpd events work in the event that hpd doesn't work on the system |
| 122 | */ |
| 123 | igt_until_timeout(HOTPLUG_TIMEOUT) { |
| 124 | if (reprobe_connector(data, port) == status) { |
| 125 | finished = true; |
| 126 | return; |
| 127 | } |
| 128 | |
Paul Kocialkowki | 8d30021 | 2017-06-26 16:59:02 +0300 | [diff] [blame] | 129 | usleep(50000); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | igt_assert(finished); |
| 133 | } |
| 134 | |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 135 | static int chamelium_vga_modes[][2] = { |
| 136 | { 1600, 1200 }, |
| 137 | { 1920, 1200 }, |
| 138 | { 1920, 1080 }, |
| 139 | { 1680, 1050 }, |
| 140 | { 1280, 1024 }, |
| 141 | { 1280, 960 }, |
| 142 | { 1440, 900 }, |
| 143 | { 1280, 800 }, |
| 144 | { 1024, 768 }, |
| 145 | { 1360, 768 }, |
| 146 | { 1280, 720 }, |
| 147 | { 800, 600 }, |
| 148 | { 640, 480 }, |
| 149 | { -1, -1 }, |
| 150 | }; |
| 151 | |
| 152 | static bool |
| 153 | prune_vga_mode(data_t *data, drmModeModeInfo *mode) |
| 154 | { |
| 155 | int i = 0; |
| 156 | |
| 157 | while (chamelium_vga_modes[i][0] != -1) { |
| 158 | if (mode->hdisplay == chamelium_vga_modes[i][0] && |
| 159 | mode->vdisplay == chamelium_vga_modes[i][1]) |
| 160 | return false; |
| 161 | |
| 162 | i++; |
| 163 | } |
| 164 | |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | static bool |
| 169 | check_analog_bridge(data_t *data, struct chamelium_port *port) |
| 170 | { |
| 171 | drmModePropertyBlobPtr edid_blob = NULL; |
| 172 | drmModeConnector *connector = chamelium_port_get_connector( |
| 173 | data->chamelium, port, false); |
| 174 | uint64_t edid_blob_id; |
| 175 | unsigned char *edid; |
| 176 | char edid_vendor[3]; |
| 177 | |
Paul Kocialkowski | f7271fe | 2018-11-14 16:29:18 +0100 | [diff] [blame^] | 178 | if (chamelium_port_get_type(port) != DRM_MODE_CONNECTOR_VGA) { |
| 179 | drmModeFreeConnector(connector); |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 180 | return false; |
Paul Kocialkowski | f7271fe | 2018-11-14 16:29:18 +0100 | [diff] [blame^] | 181 | } |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 182 | |
| 183 | igt_assert(kmstest_get_property(data->drm_fd, connector->connector_id, |
| 184 | DRM_MODE_OBJECT_CONNECTOR, "EDID", NULL, |
| 185 | &edid_blob_id, NULL)); |
| 186 | igt_assert(edid_blob = drmModeGetPropertyBlob(data->drm_fd, |
| 187 | edid_blob_id)); |
| 188 | |
| 189 | edid = (unsigned char *) edid_blob->data; |
| 190 | |
| 191 | edid_vendor[0] = ((edid[8] & 0x7c) >> 2) + '@'; |
| 192 | edid_vendor[1] = (((edid[8] & 0x03) << 3) | |
| 193 | ((edid[9] & 0xe0) >> 5)) + '@'; |
| 194 | edid_vendor[2] = (edid[9] & 0x1f) + '@'; |
| 195 | |
Paul Kocialkowski | f7271fe | 2018-11-14 16:29:18 +0100 | [diff] [blame^] | 196 | drmModeFreePropertyBlob(edid_blob); |
| 197 | drmModeFreeConnector(connector); |
| 198 | |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 199 | /* Analog bridges provide their own EDID */ |
| 200 | if (edid_vendor[0] != 'I' || edid_vendor[1] != 'G' || |
| 201 | edid_vendor[0] != 'T') |
| 202 | return true; |
| 203 | |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 207 | static void |
| 208 | reset_state(data_t *data, struct chamelium_port *port) |
| 209 | { |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 210 | int p; |
| 211 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 212 | chamelium_reset(data->chamelium); |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 213 | |
| 214 | if (port) { |
| 215 | wait_for_connector(data, port, DRM_MODE_DISCONNECTED); |
| 216 | } else { |
| 217 | for (p = 0; p < data->port_count; p++) { |
| 218 | port = data->ports[p]; |
| 219 | wait_for_connector(data, port, DRM_MODE_DISCONNECTED); |
| 220 | } |
| 221 | } |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static void |
Paul Kocialkowki | 7d714b2 | 2017-06-27 13:53:08 +0300 | [diff] [blame] | 225 | test_basic_hotplug(data_t *data, struct chamelium_port *port, int toggle_count) |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 226 | { |
| 227 | struct udev_monitor *mon = igt_watch_hotplug(); |
| 228 | int i; |
| 229 | |
Paul Kocialkowki | a22b4b1 | 2017-06-26 16:59:01 +0300 | [diff] [blame] | 230 | reset_state(data, NULL); |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 231 | igt_hpd_storm_set_threshold(data->drm_fd, 0); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 232 | |
Paul Kocialkowki | 7d714b2 | 2017-06-27 13:53:08 +0300 | [diff] [blame] | 233 | for (i = 0; i < toggle_count; i++) { |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 234 | igt_flush_hotplugs(mon); |
| 235 | |
| 236 | /* Check if we get a sysfs hotplug event */ |
| 237 | chamelium_plug(data->chamelium, port); |
| 238 | igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT)); |
| 239 | igt_assert_eq(reprobe_connector(data, port), |
| 240 | DRM_MODE_CONNECTED); |
| 241 | |
| 242 | igt_flush_hotplugs(mon); |
| 243 | |
| 244 | /* Now check if we get a hotplug from disconnection */ |
| 245 | chamelium_unplug(data->chamelium, port); |
| 246 | igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT)); |
| 247 | igt_assert_eq(reprobe_connector(data, port), |
| 248 | DRM_MODE_DISCONNECTED); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | igt_cleanup_hotplug(mon); |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 252 | igt_hpd_storm_reset(data->drm_fd); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static void |
| 256 | test_edid_read(data_t *data, struct chamelium_port *port, |
| 257 | int edid_id, const unsigned char *edid) |
| 258 | { |
| 259 | drmModePropertyBlobPtr edid_blob = NULL; |
| 260 | drmModeConnector *connector = chamelium_port_get_connector( |
| 261 | data->chamelium, port, false); |
| 262 | uint64_t edid_blob_id; |
| 263 | |
| 264 | reset_state(data, port); |
| 265 | |
| 266 | chamelium_port_set_edid(data->chamelium, port, edid_id); |
| 267 | chamelium_plug(data->chamelium, port); |
| 268 | wait_for_connector(data, port, DRM_MODE_CONNECTED); |
| 269 | |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 270 | igt_skip_on(check_analog_bridge(data, port)); |
| 271 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 272 | igt_assert(kmstest_get_property(data->drm_fd, connector->connector_id, |
| 273 | DRM_MODE_OBJECT_CONNECTOR, "EDID", NULL, |
| 274 | &edid_blob_id, NULL)); |
| 275 | igt_assert(edid_blob = drmModeGetPropertyBlob(data->drm_fd, |
| 276 | edid_blob_id)); |
| 277 | |
| 278 | igt_assert(memcmp(edid, edid_blob->data, EDID_LENGTH) == 0); |
| 279 | |
| 280 | drmModeFreePropertyBlob(edid_blob); |
| 281 | drmModeFreeConnector(connector); |
| 282 | } |
| 283 | |
| 284 | static void |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 285 | try_suspend_resume_hpd(data_t *data, struct chamelium_port *port, |
| 286 | enum igt_suspend_state state, enum igt_suspend_test test, |
| 287 | struct udev_monitor *mon, bool connected) |
| 288 | { |
Paul Kocialkowski | ebd6eb6 | 2017-07-04 16:33:19 +0300 | [diff] [blame] | 289 | int delay; |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 290 | int p; |
| 291 | |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 292 | igt_flush_hotplugs(mon); |
| 293 | |
Paul Kocialkowski | ebd6eb6 | 2017-07-04 16:33:19 +0300 | [diff] [blame] | 294 | delay = igt_get_autoresume_delay(state) * 1000 / 2; |
| 295 | |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 296 | if (port) { |
Paul Kocialkowski | ebd6eb6 | 2017-07-04 16:33:19 +0300 | [diff] [blame] | 297 | chamelium_schedule_hpd_toggle(data->chamelium, port, delay, |
Paul Kocialkowki | fa8b6ee | 2017-06-27 13:53:06 +0300 | [diff] [blame] | 298 | !connected); |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 299 | } else { |
| 300 | for (p = 0; p < data->port_count; p++) { |
| 301 | port = data->ports[p]; |
Paul Kocialkowki | fa8b6ee | 2017-06-27 13:53:06 +0300 | [diff] [blame] | 302 | chamelium_schedule_hpd_toggle(data->chamelium, port, |
Paul Kocialkowski | ebd6eb6 | 2017-07-04 16:33:19 +0300 | [diff] [blame] | 303 | delay, !connected); |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | port = NULL; |
| 307 | } |
| 308 | |
| 309 | igt_system_suspend_autoresume(state, test); |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 310 | |
| 311 | igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT)); |
| 312 | if (port) { |
| 313 | igt_assert_eq(reprobe_connector(data, port), connected ? |
| 314 | DRM_MODE_DISCONNECTED : DRM_MODE_CONNECTED); |
| 315 | } else { |
| 316 | for (p = 0; p < data->port_count; p++) { |
| 317 | port = data->ports[p]; |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 318 | igt_assert_eq(reprobe_connector(data, port), connected ? |
| 319 | DRM_MODE_DISCONNECTED : |
| 320 | DRM_MODE_CONNECTED); |
| 321 | } |
| 322 | |
| 323 | port = NULL; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | static void |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 328 | test_suspend_resume_hpd(data_t *data, struct chamelium_port *port, |
| 329 | enum igt_suspend_state state, |
| 330 | enum igt_suspend_test test) |
| 331 | { |
| 332 | struct udev_monitor *mon = igt_watch_hotplug(); |
| 333 | |
| 334 | reset_state(data, port); |
| 335 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 336 | /* Make sure we notice new connectors after resuming */ |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 337 | try_suspend_resume_hpd(data, port, state, test, mon, false); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 338 | |
| 339 | /* Now make sure we notice disconnected connectors after resuming */ |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 340 | try_suspend_resume_hpd(data, port, state, test, mon, true); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 341 | |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 342 | igt_cleanup_hotplug(mon); |
| 343 | } |
| 344 | |
| 345 | static void |
| 346 | test_suspend_resume_hpd_common(data_t *data, enum igt_suspend_state state, |
| 347 | enum igt_suspend_test test) |
| 348 | { |
| 349 | struct udev_monitor *mon = igt_watch_hotplug(); |
| 350 | struct chamelium_port *port; |
| 351 | int p; |
| 352 | |
| 353 | for (p = 0; p < data->port_count; p++) { |
| 354 | port = data->ports[p]; |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 355 | igt_debug("Testing port %s\n", chamelium_port_get_name(port)); |
| 356 | } |
| 357 | |
| 358 | reset_state(data, NULL); |
| 359 | |
| 360 | /* Make sure we notice new connectors after resuming */ |
| 361 | try_suspend_resume_hpd(data, NULL, state, test, mon, false); |
| 362 | |
| 363 | /* Now make sure we notice disconnected connectors after resuming */ |
| 364 | try_suspend_resume_hpd(data, NULL, state, test, mon, true); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 365 | |
| 366 | igt_cleanup_hotplug(mon); |
| 367 | } |
| 368 | |
| 369 | static void |
| 370 | test_suspend_resume_edid_change(data_t *data, struct chamelium_port *port, |
| 371 | enum igt_suspend_state state, |
| 372 | enum igt_suspend_test test, |
| 373 | int edid_id, |
| 374 | int alt_edid_id) |
| 375 | { |
| 376 | struct udev_monitor *mon = igt_watch_hotplug(); |
Paul Kocialkowski | a944394 | 2017-07-18 18:15:52 +0300 | [diff] [blame] | 377 | bool link_status_failed[2][data->port_count]; |
| 378 | int p; |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 379 | |
| 380 | reset_state(data, port); |
| 381 | |
Paul Kocialkowski | fb1ddc4 | 2017-07-18 18:16:27 +0300 | [diff] [blame] | 382 | /* Catch the event and flush all remaining ones. */ |
| 383 | igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT)); |
| 384 | igt_flush_hotplugs(mon); |
| 385 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 386 | /* First plug in the port */ |
| 387 | chamelium_port_set_edid(data->chamelium, port, edid_id); |
| 388 | chamelium_plug(data->chamelium, port); |
Paul Kocialkowski | fb1ddc4 | 2017-07-18 18:16:27 +0300 | [diff] [blame] | 389 | igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT)); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 390 | |
Paul Kocialkowski | fb1ddc4 | 2017-07-18 18:16:27 +0300 | [diff] [blame] | 391 | wait_for_connector(data, port, DRM_MODE_CONNECTED); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 392 | |
| 393 | /* |
| 394 | * Change the edid before we suspend. On resume, the machine should |
| 395 | * notice the EDID change and fire a hotplug event. |
| 396 | */ |
| 397 | chamelium_port_set_edid(data->chamelium, port, alt_edid_id); |
| 398 | |
Paul Kocialkowski | a944394 | 2017-07-18 18:15:52 +0300 | [diff] [blame] | 399 | get_connectors_link_status_failed(data, link_status_failed[0]); |
| 400 | |
Paul Kocialkowski | fb1ddc4 | 2017-07-18 18:16:27 +0300 | [diff] [blame] | 401 | igt_flush_hotplugs(mon); |
| 402 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 403 | igt_system_suspend_autoresume(state, test); |
Paul Kocialkowski | a944394 | 2017-07-18 18:15:52 +0300 | [diff] [blame] | 404 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 405 | igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT)); |
Paul Kocialkowski | a944394 | 2017-07-18 18:15:52 +0300 | [diff] [blame] | 406 | |
| 407 | get_connectors_link_status_failed(data, link_status_failed[1]); |
| 408 | |
| 409 | for (p = 0; p < data->port_count; p++) |
| 410 | igt_skip_on(!link_status_failed[0][p] && link_status_failed[1][p]); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static igt_output_t * |
| 414 | prepare_output(data_t *data, |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 415 | struct chamelium_port *port) |
| 416 | { |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 417 | igt_display_t *display = &data->display; |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 418 | igt_output_t *output; |
| 419 | drmModeRes *res; |
| 420 | drmModeConnector *connector = |
| 421 | chamelium_port_get_connector(data->chamelium, port, false); |
Maarten Lankhorst | d6fe4df | 2017-10-12 13:04:49 +0200 | [diff] [blame] | 422 | enum pipe pipe; |
| 423 | bool found = false; |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 424 | |
Chris Wilson | 519003c | 2018-10-03 20:43:49 +0100 | [diff] [blame] | 425 | igt_require(res = drmModeGetResources(data->drm_fd)); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 426 | |
| 427 | /* The chamelium's default EDID has a lot of resolutions, way more then |
| 428 | * we need to test |
| 429 | */ |
| 430 | chamelium_port_set_edid(data->chamelium, port, data->edid_id); |
| 431 | |
| 432 | chamelium_plug(data->chamelium, port); |
| 433 | wait_for_connector(data, port, DRM_MODE_CONNECTED); |
| 434 | |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 435 | igt_display_reset(display); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 436 | |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 437 | output = igt_output_from_connector(display, connector); |
Maarten Lankhorst | d6fe4df | 2017-10-12 13:04:49 +0200 | [diff] [blame] | 438 | |
| 439 | for_each_pipe(display, pipe) { |
| 440 | if (!igt_pipe_connector_valid(pipe, output)) |
| 441 | continue; |
| 442 | |
| 443 | found = true; |
| 444 | break; |
| 445 | } |
| 446 | |
| 447 | igt_assert_f(found, "No pipe found for output %s\n", igt_output_name(output)); |
| 448 | |
| 449 | igt_output_set_pipe(output, pipe); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 450 | |
| 451 | drmModeFreeConnector(connector); |
| 452 | drmModeFreeResources(res); |
| 453 | |
| 454 | return output; |
| 455 | } |
| 456 | |
| 457 | static void |
| 458 | enable_output(data_t *data, |
| 459 | struct chamelium_port *port, |
| 460 | igt_output_t *output, |
| 461 | drmModeModeInfo *mode, |
| 462 | struct igt_fb *fb) |
| 463 | { |
| 464 | igt_display_t *display = output->display; |
Petri Latvala | 26cde2a | 2017-02-01 12:56:34 +0200 | [diff] [blame] | 465 | igt_plane_t *primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 466 | drmModeConnector *connector = chamelium_port_get_connector( |
| 467 | data->chamelium, port, false); |
| 468 | |
| 469 | igt_assert(primary); |
| 470 | |
| 471 | igt_plane_set_size(primary, mode->hdisplay, mode->vdisplay); |
| 472 | igt_plane_set_fb(primary, fb); |
| 473 | igt_output_override_mode(output, mode); |
| 474 | |
| 475 | /* Clear any color correction values that might be enabled */ |
Maarten Lankhorst | d7fcd33 | 2018-03-05 19:11:15 +0100 | [diff] [blame] | 476 | if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_DEGAMMA_LUT)) |
| 477 | igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_DEGAMMA_LUT, NULL, 0); |
| 478 | if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_GAMMA_LUT)) |
| 479 | igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_GAMMA_LUT, NULL, 0); |
| 480 | if (igt_pipe_obj_has_prop(primary->pipe, IGT_CRTC_CTM)) |
| 481 | igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_CTM, NULL, 0); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 482 | |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 483 | igt_display_commit2(display, COMMIT_ATOMIC); |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 484 | |
| 485 | if (chamelium_port_get_type(port) == DRM_MODE_CONNECTOR_VGA) |
| 486 | usleep(250000); |
| 487 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 488 | drmModeFreeConnector(connector); |
| 489 | } |
| 490 | |
Maxime Ripard | 9aecda2 | 2018-10-04 14:39:06 +0200 | [diff] [blame] | 491 | static void chamelium_paint_xr24_pattern(uint32_t *data, |
| 492 | size_t width, size_t height) |
| 493 | { |
| 494 | uint32_t colors[] = { 0xff000000, |
| 495 | 0xffff0000, |
| 496 | 0xff00ff00, |
| 497 | 0xff0000ff, |
| 498 | 0xffffffff }; |
| 499 | unsigned i, j; |
| 500 | |
| 501 | for (i = 0; i < height; i++) |
| 502 | for (j = 0; j < width; j++) |
| 503 | *(data + i * width + j) = colors[((j / 64) + (i / 64)) % 5]; |
| 504 | } |
| 505 | |
| 506 | static int chamelium_get_pattern_fb(data_t *data, drmModeModeInfo *mode, |
| 507 | uint32_t fourcc, struct igt_fb *fb) |
| 508 | { |
| 509 | int fb_id; |
| 510 | void *ptr; |
| 511 | |
| 512 | igt_assert(fourcc == DRM_FORMAT_XRGB8888); |
| 513 | |
| 514 | fb_id = igt_create_fb(data->drm_fd, mode->hdisplay, mode->vdisplay, |
| 515 | fourcc, LOCAL_DRM_FORMAT_MOD_NONE, fb); |
| 516 | igt_assert(fb_id > 0); |
| 517 | |
| 518 | ptr = igt_fb_map_buffer(fb->fd, fb); |
| 519 | igt_assert(ptr); |
| 520 | |
| 521 | chamelium_paint_xr24_pattern(ptr, mode->vdisplay, mode->hdisplay); |
| 522 | igt_fb_unmap_buffer(fb, ptr); |
| 523 | |
| 524 | return fb_id; |
| 525 | } |
| 526 | |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 527 | static void do_test_display_crc(data_t *data, struct chamelium_port *port, |
| 528 | igt_output_t *output, drmModeModeInfo *mode, |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 529 | uint32_t fourcc, int count) |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 530 | { |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 531 | igt_crc_t *crc; |
Paul Kocialkowski | e0802ba | 2017-07-19 16:46:05 +0300 | [diff] [blame] | 532 | igt_crc_t *expected_crc; |
| 533 | struct chamelium_fb_crc_async_data *fb_crc; |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 534 | struct igt_fb frame_fb, fb; |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 535 | int i, fb_id, captured_frame_count; |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 536 | int frame_id; |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 537 | |
Maxime Ripard | 9aecda2 | 2018-10-04 14:39:06 +0200 | [diff] [blame] | 538 | fb_id = chamelium_get_pattern_fb(data, mode, |
| 539 | DRM_FORMAT_XRGB8888, &fb); |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 540 | igt_assert(fb_id > 0); |
| 541 | |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 542 | frame_id = igt_fb_convert(&frame_fb, &fb, fourcc); |
| 543 | igt_assert(frame_id > 0); |
| 544 | |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 545 | fb_crc = chamelium_calculate_fb_crc_async_start(data->drm_fd, |
| 546 | &fb); |
| 547 | |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 548 | enable_output(data, port, output, mode, &frame_fb); |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 549 | |
| 550 | /* We want to keep the display running for a little bit, since |
| 551 | * there's always the potential the driver isn't able to keep |
| 552 | * the display running properly for very long |
| 553 | */ |
| 554 | chamelium_capture(data->chamelium, port, 0, 0, 0, 0, count); |
| 555 | crc = chamelium_read_captured_crcs(data->chamelium, |
| 556 | &captured_frame_count); |
| 557 | |
| 558 | igt_assert(captured_frame_count == count); |
| 559 | |
| 560 | igt_debug("Captured %d frames\n", captured_frame_count); |
| 561 | |
| 562 | expected_crc = chamelium_calculate_fb_crc_async_finish(fb_crc); |
| 563 | |
| 564 | for (i = 0; i < captured_frame_count; i++) |
| 565 | chamelium_assert_crc_eq_or_dump(data->chamelium, |
| 566 | expected_crc, &crc[i], |
| 567 | &fb, i); |
| 568 | |
| 569 | free(expected_crc); |
| 570 | free(crc); |
| 571 | |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 572 | igt_remove_fb(data->drm_fd, &frame_fb); |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 573 | igt_remove_fb(data->drm_fd, &fb); |
| 574 | } |
| 575 | |
| 576 | static void test_display_crc_one_mode(data_t *data, struct chamelium_port *port, |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 577 | uint32_t fourcc, int count) |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 578 | { |
| 579 | igt_output_t *output; |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 580 | drmModeConnector *connector; |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 581 | igt_plane_t *primary; |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 582 | |
Paul Kocialkowski | 80aa69f | 2017-07-03 15:01:12 +0300 | [diff] [blame] | 583 | reset_state(data, port); |
| 584 | |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 585 | output = prepare_output(data, port); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 586 | connector = chamelium_port_get_connector(data->chamelium, port, false); |
Petri Latvala | 26cde2a | 2017-02-01 12:56:34 +0200 | [diff] [blame] | 587 | primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 588 | igt_assert(primary); |
| 589 | |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 590 | do_test_display_crc(data, port, output, &connector->modes[0], fourcc, count); |
Paul Kocialkowski | c4f1f8a | 2017-08-23 18:21:13 +0300 | [diff] [blame] | 591 | |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 592 | drmModeFreeConnector(connector); |
| 593 | } |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 594 | |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 595 | static void test_display_crc_all_modes(data_t *data, struct chamelium_port *port, |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 596 | uint32_t fourcc, int count) |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 597 | { |
| 598 | igt_output_t *output; |
| 599 | igt_plane_t *primary; |
| 600 | drmModeConnector *connector; |
| 601 | int i; |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 602 | |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 603 | reset_state(data, port); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 604 | |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 605 | output = prepare_output(data, port); |
| 606 | connector = chamelium_port_get_connector(data->chamelium, port, false); |
| 607 | primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
| 608 | igt_assert(primary); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 609 | |
Maxime Ripard | c526291 | 2018-10-04 14:39:05 +0200 | [diff] [blame] | 610 | for (i = 0; i < connector->count_modes; i++) { |
| 611 | drmModeModeInfo *mode = &connector->modes[i]; |
Paul Kocialkowski | 4b5ea65 | 2017-07-19 16:46:10 +0300 | [diff] [blame] | 612 | |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 613 | do_test_display_crc(data, port, output, mode, fourcc, count); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | drmModeFreeConnector(connector); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | static void |
| 620 | test_display_frame_dump(data_t *data, struct chamelium_port *port) |
| 621 | { |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 622 | igt_output_t *output; |
| 623 | igt_plane_t *primary; |
| 624 | struct igt_fb fb; |
| 625 | struct chamelium_frame_dump *frame; |
| 626 | drmModeModeInfo *mode; |
| 627 | drmModeConnector *connector; |
| 628 | int fb_id, i, j; |
| 629 | |
Paul Kocialkowski | 80aa69f | 2017-07-03 15:01:12 +0300 | [diff] [blame] | 630 | reset_state(data, port); |
| 631 | |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 632 | output = prepare_output(data, port); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 633 | connector = chamelium_port_get_connector(data->chamelium, port, false); |
Petri Latvala | 26cde2a | 2017-02-01 12:56:34 +0200 | [diff] [blame] | 634 | primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 635 | igt_assert(primary); |
| 636 | |
| 637 | for (i = 0; i < connector->count_modes; i++) { |
| 638 | mode = &connector->modes[i]; |
| 639 | fb_id = igt_create_color_pattern_fb(data->drm_fd, |
| 640 | mode->hdisplay, mode->vdisplay, |
| 641 | DRM_FORMAT_XRGB8888, |
| 642 | LOCAL_DRM_FORMAT_MOD_NONE, |
| 643 | 0, 0, 0, &fb); |
| 644 | igt_assert(fb_id > 0); |
| 645 | |
| 646 | enable_output(data, port, output, mode, &fb); |
| 647 | |
| 648 | igt_debug("Reading frame dumps from Chamelium...\n"); |
| 649 | chamelium_capture(data->chamelium, port, 0, 0, 0, 0, 5); |
| 650 | for (j = 0; j < 5; j++) { |
| 651 | frame = chamelium_read_captured_frame( |
| 652 | data->chamelium, j); |
| 653 | chamelium_assert_frame_eq(data->chamelium, frame, &fb); |
| 654 | chamelium_destroy_frame_dump(frame); |
| 655 | } |
| 656 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 657 | igt_remove_fb(data->drm_fd, &fb); |
| 658 | } |
| 659 | |
| 660 | drmModeFreeConnector(connector); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static void |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 664 | test_analog_frame_dump(data_t *data, struct chamelium_port *port) |
| 665 | { |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 666 | igt_output_t *output; |
| 667 | igt_plane_t *primary; |
| 668 | struct igt_fb fb; |
| 669 | struct chamelium_frame_dump *frame; |
| 670 | drmModeModeInfo *mode; |
| 671 | drmModeConnector *connector; |
| 672 | int fb_id, i; |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 673 | bool bridge; |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 674 | |
Paul Kocialkowski | 60f6a12 | 2017-08-25 15:03:37 +0300 | [diff] [blame] | 675 | reset_state(data, port); |
| 676 | |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 677 | output = prepare_output(data, port); |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 678 | connector = chamelium_port_get_connector(data->chamelium, port, false); |
| 679 | primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); |
| 680 | igt_assert(primary); |
| 681 | |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 682 | bridge = check_analog_bridge(data, port); |
| 683 | |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 684 | for (i = 0; i < connector->count_modes; i++) { |
| 685 | mode = &connector->modes[i]; |
| 686 | |
Paul Kocialkowski | f8d6afa | 2017-07-19 16:50:37 +0300 | [diff] [blame] | 687 | if (bridge && prune_vga_mode(data, mode)) |
| 688 | continue; |
| 689 | |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 690 | fb_id = igt_create_color_pattern_fb(data->drm_fd, |
| 691 | mode->hdisplay, mode->vdisplay, |
| 692 | DRM_FORMAT_XRGB8888, |
| 693 | LOCAL_DRM_FORMAT_MOD_NONE, |
| 694 | 0, 0, 0, &fb); |
| 695 | igt_assert(fb_id > 0); |
| 696 | |
| 697 | enable_output(data, port, output, mode, &fb); |
| 698 | |
| 699 | igt_debug("Reading frame dumps from Chamelium...\n"); |
| 700 | |
| 701 | frame = chamelium_port_dump_pixels(data->chamelium, port, 0, 0, |
| 702 | 0, 0); |
| 703 | |
| 704 | chamelium_crop_analog_frame(frame, mode->hdisplay, |
| 705 | mode->vdisplay); |
| 706 | |
| 707 | chamelium_assert_analog_frame_match_or_dump(data->chamelium, |
| 708 | port, frame, &fb); |
| 709 | |
| 710 | chamelium_destroy_frame_dump(frame); |
| 711 | |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 712 | igt_remove_fb(data->drm_fd, &fb); |
| 713 | } |
| 714 | |
| 715 | drmModeFreeConnector(connector); |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | static void |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 719 | test_hpd_without_ddc(data_t *data, struct chamelium_port *port) |
| 720 | { |
| 721 | struct udev_monitor *mon = igt_watch_hotplug(); |
| 722 | |
| 723 | reset_state(data, port); |
Lyude | 808a1aa | 2017-02-01 18:17:49 -0500 | [diff] [blame] | 724 | igt_flush_hotplugs(mon); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 725 | |
| 726 | /* Disable the DDC on the connector and make sure we still get a |
| 727 | * hotplug |
| 728 | */ |
| 729 | chamelium_port_set_ddc_state(data->chamelium, port, false); |
| 730 | chamelium_plug(data->chamelium, port); |
| 731 | |
| 732 | igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT)); |
| 733 | igt_assert_eq(reprobe_connector(data, port), DRM_MODE_CONNECTED); |
| 734 | |
| 735 | igt_cleanup_hotplug(mon); |
| 736 | } |
| 737 | |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 738 | static void |
| 739 | test_hpd_storm_detect(data_t *data, struct chamelium_port *port, int width) |
| 740 | { |
| 741 | struct udev_monitor *mon; |
| 742 | int count = 0; |
| 743 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 744 | igt_require_hpd_storm_ctl(data->drm_fd); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 745 | reset_state(data, port); |
| 746 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 747 | igt_hpd_storm_set_threshold(data->drm_fd, 1); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 748 | chamelium_fire_hpd_pulses(data->chamelium, port, width, 10); |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 749 | igt_assert(igt_hpd_storm_detected(data->drm_fd)); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 750 | |
| 751 | mon = igt_watch_hotplug(); |
| 752 | chamelium_fire_hpd_pulses(data->chamelium, port, width, 10); |
| 753 | |
| 754 | /* |
| 755 | * Polling should have been enabled by the HPD storm at this point, |
| 756 | * so we should only get at most 1 hotplug event |
| 757 | */ |
| 758 | igt_until_timeout(5) |
| 759 | count += igt_hotplug_detected(mon, 1); |
| 760 | igt_assert_lt(count, 2); |
| 761 | |
| 762 | igt_cleanup_hotplug(mon); |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 763 | igt_hpd_storm_reset(data->drm_fd); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void |
| 767 | test_hpd_storm_disable(data_t *data, struct chamelium_port *port, int width) |
| 768 | { |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 769 | igt_require_hpd_storm_ctl(data->drm_fd); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 770 | reset_state(data, port); |
| 771 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 772 | igt_hpd_storm_set_threshold(data->drm_fd, 0); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 773 | chamelium_fire_hpd_pulses(data->chamelium, port, |
| 774 | width, 10); |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 775 | igt_assert(!igt_hpd_storm_detected(data->drm_fd)); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 776 | |
Chris Wilson | 83884e9 | 2017-03-21 17:16:03 +0000 | [diff] [blame] | 777 | igt_hpd_storm_reset(data->drm_fd); |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 778 | } |
| 779 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 780 | #define for_each_port(p, port) \ |
| 781 | for (p = 0, port = data.ports[p]; \ |
| 782 | p < data.port_count; \ |
| 783 | p++, port = data.ports[p]) |
| 784 | |
| 785 | #define connector_subtest(name__, type__) \ |
| 786 | igt_subtest(name__) \ |
| 787 | for_each_port(p, port) \ |
| 788 | if (chamelium_port_get_type(port) == \ |
| 789 | DRM_MODE_CONNECTOR_ ## type__) |
| 790 | |
| 791 | static data_t data; |
| 792 | |
| 793 | igt_main |
| 794 | { |
| 795 | struct chamelium_port *port; |
| 796 | int edid_id, alt_edid_id, p; |
| 797 | |
| 798 | igt_fixture { |
| 799 | igt_skip_on_simulation(); |
| 800 | |
| 801 | data.drm_fd = drm_open_driver_master(DRIVER_ANY); |
| 802 | data.chamelium = chamelium_init(data.drm_fd); |
| 803 | igt_require(data.chamelium); |
| 804 | |
| 805 | data.ports = chamelium_get_ports(data.chamelium, |
| 806 | &data.port_count); |
| 807 | |
| 808 | edid_id = chamelium_new_edid(data.chamelium, |
| 809 | igt_kms_get_base_edid()); |
| 810 | alt_edid_id = chamelium_new_edid(data.chamelium, |
| 811 | igt_kms_get_alt_edid()); |
| 812 | data.edid_id = edid_id; |
| 813 | data.alt_edid_id = alt_edid_id; |
| 814 | |
| 815 | /* So fbcon doesn't try to reprobe things itself */ |
| 816 | kmstest_set_vt_graphics_mode(); |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 817 | |
Chris Wilson | 7f41adf | 2018-09-14 21:10:05 +0100 | [diff] [blame] | 818 | igt_display_require(&data.display, data.drm_fd); |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 819 | igt_require(data.display.is_atomic); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | igt_subtest_group { |
| 823 | igt_fixture { |
| 824 | require_connector_present( |
| 825 | &data, DRM_MODE_CONNECTOR_DisplayPort); |
| 826 | } |
| 827 | |
| 828 | connector_subtest("dp-hpd", DisplayPort) |
Paul Kocialkowki | 7d714b2 | 2017-06-27 13:53:08 +0300 | [diff] [blame] | 829 | test_basic_hotplug(&data, port, |
| 830 | HPD_TOGGLE_COUNT_DP_HDMI); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 831 | |
Paul Kocialkowski | 4ee824e | 2017-08-23 18:21:12 +0300 | [diff] [blame] | 832 | connector_subtest("dp-hpd-fast", DisplayPort) |
| 833 | test_basic_hotplug(&data, port, |
| 834 | HPD_TOGGLE_COUNT_FAST); |
| 835 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 836 | connector_subtest("dp-edid-read", DisplayPort) { |
| 837 | test_edid_read(&data, port, edid_id, |
| 838 | igt_kms_get_base_edid()); |
| 839 | test_edid_read(&data, port, alt_edid_id, |
| 840 | igt_kms_get_alt_edid()); |
| 841 | } |
| 842 | |
| 843 | connector_subtest("dp-hpd-after-suspend", DisplayPort) |
| 844 | test_suspend_resume_hpd(&data, port, |
| 845 | SUSPEND_STATE_MEM, |
| 846 | SUSPEND_TEST_NONE); |
| 847 | |
| 848 | connector_subtest("dp-hpd-after-hibernate", DisplayPort) |
| 849 | test_suspend_resume_hpd(&data, port, |
| 850 | SUSPEND_STATE_DISK, |
| 851 | SUSPEND_TEST_DEVICES); |
| 852 | |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 853 | connector_subtest("dp-hpd-storm", DisplayPort) |
| 854 | test_hpd_storm_detect(&data, port, |
| 855 | HPD_STORM_PULSE_INTERVAL_DP); |
| 856 | |
| 857 | connector_subtest("dp-hpd-storm-disable", DisplayPort) |
| 858 | test_hpd_storm_disable(&data, port, |
| 859 | HPD_STORM_PULSE_INTERVAL_DP); |
| 860 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 861 | connector_subtest("dp-edid-change-during-suspend", DisplayPort) |
| 862 | test_suspend_resume_edid_change(&data, port, |
| 863 | SUSPEND_STATE_MEM, |
| 864 | SUSPEND_TEST_NONE, |
| 865 | edid_id, alt_edid_id); |
| 866 | |
| 867 | connector_subtest("dp-edid-change-during-hibernate", DisplayPort) |
| 868 | test_suspend_resume_edid_change(&data, port, |
| 869 | SUSPEND_STATE_DISK, |
| 870 | SUSPEND_TEST_DEVICES, |
| 871 | edid_id, alt_edid_id); |
| 872 | |
| 873 | connector_subtest("dp-crc-single", DisplayPort) |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 874 | test_display_crc_all_modes(&data, port, |
| 875 | DRM_FORMAT_XRGB8888, 1); |
Paul Kocialkowski | c4f1f8a | 2017-08-23 18:21:13 +0300 | [diff] [blame] | 876 | |
| 877 | connector_subtest("dp-crc-fast", DisplayPort) |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 878 | test_display_crc_one_mode(&data, port, |
| 879 | DRM_FORMAT_XRGB8888, 1); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 880 | |
| 881 | connector_subtest("dp-crc-multiple", DisplayPort) |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 882 | test_display_crc_all_modes(&data, port, |
| 883 | DRM_FORMAT_XRGB8888, 3); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 884 | |
| 885 | connector_subtest("dp-frame-dump", DisplayPort) |
| 886 | test_display_frame_dump(&data, port); |
| 887 | } |
| 888 | |
| 889 | igt_subtest_group { |
| 890 | igt_fixture { |
| 891 | require_connector_present( |
| 892 | &data, DRM_MODE_CONNECTOR_HDMIA); |
| 893 | } |
| 894 | |
| 895 | connector_subtest("hdmi-hpd", HDMIA) |
Paul Kocialkowki | 7d714b2 | 2017-06-27 13:53:08 +0300 | [diff] [blame] | 896 | test_basic_hotplug(&data, port, |
| 897 | HPD_TOGGLE_COUNT_DP_HDMI); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 898 | |
Paul Kocialkowski | 4ee824e | 2017-08-23 18:21:12 +0300 | [diff] [blame] | 899 | connector_subtest("hdmi-hpd-fast", HDMIA) |
| 900 | test_basic_hotplug(&data, port, |
| 901 | HPD_TOGGLE_COUNT_FAST); |
| 902 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 903 | connector_subtest("hdmi-edid-read", HDMIA) { |
| 904 | test_edid_read(&data, port, edid_id, |
| 905 | igt_kms_get_base_edid()); |
| 906 | test_edid_read(&data, port, alt_edid_id, |
| 907 | igt_kms_get_alt_edid()); |
| 908 | } |
| 909 | |
| 910 | connector_subtest("hdmi-hpd-after-suspend", HDMIA) |
| 911 | test_suspend_resume_hpd(&data, port, |
| 912 | SUSPEND_STATE_MEM, |
| 913 | SUSPEND_TEST_NONE); |
| 914 | |
| 915 | connector_subtest("hdmi-hpd-after-hibernate", HDMIA) |
| 916 | test_suspend_resume_hpd(&data, port, |
| 917 | SUSPEND_STATE_DISK, |
| 918 | SUSPEND_TEST_DEVICES); |
| 919 | |
Lyude | a8ea5dd | 2017-02-22 21:16:16 -0500 | [diff] [blame] | 920 | connector_subtest("hdmi-hpd-storm", HDMIA) |
| 921 | test_hpd_storm_detect(&data, port, |
| 922 | HPD_STORM_PULSE_INTERVAL_HDMI); |
| 923 | |
| 924 | connector_subtest("hdmi-hpd-storm-disable", HDMIA) |
| 925 | test_hpd_storm_disable(&data, port, |
| 926 | HPD_STORM_PULSE_INTERVAL_HDMI); |
| 927 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 928 | connector_subtest("hdmi-edid-change-during-suspend", HDMIA) |
| 929 | test_suspend_resume_edid_change(&data, port, |
| 930 | SUSPEND_STATE_MEM, |
| 931 | SUSPEND_TEST_NONE, |
| 932 | edid_id, alt_edid_id); |
| 933 | |
| 934 | connector_subtest("hdmi-edid-change-during-hibernate", HDMIA) |
| 935 | test_suspend_resume_edid_change(&data, port, |
| 936 | SUSPEND_STATE_DISK, |
| 937 | SUSPEND_TEST_DEVICES, |
| 938 | edid_id, alt_edid_id); |
| 939 | |
| 940 | connector_subtest("hdmi-crc-single", HDMIA) |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 941 | test_display_crc_all_modes(&data, port, |
| 942 | DRM_FORMAT_XRGB8888, 1); |
Paul Kocialkowski | c4f1f8a | 2017-08-23 18:21:13 +0300 | [diff] [blame] | 943 | |
| 944 | connector_subtest("hdmi-crc-fast", HDMIA) |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 945 | test_display_crc_one_mode(&data, port, |
| 946 | DRM_FORMAT_XRGB8888, 1); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 947 | |
| 948 | connector_subtest("hdmi-crc-multiple", HDMIA) |
Maxime Ripard | c55a8c6 | 2018-10-04 14:39:07 +0200 | [diff] [blame] | 949 | test_display_crc_all_modes(&data, port, |
| 950 | DRM_FORMAT_XRGB8888, 3); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 951 | |
Maxime Ripard | 4497591 | 2018-10-04 14:39:08 +0200 | [diff] [blame] | 952 | connector_subtest("hdmi-crc-argb8888", HDMIA) |
| 953 | test_display_crc_one_mode(&data, port, |
| 954 | DRM_FORMAT_ARGB8888, 1); |
| 955 | |
| 956 | connector_subtest("hdmi-crc-abgr8888", HDMIA) |
| 957 | test_display_crc_one_mode(&data, port, |
| 958 | DRM_FORMAT_ABGR8888, 1); |
| 959 | |
| 960 | connector_subtest("hdmi-crc-xrgb8888", HDMIA) |
| 961 | test_display_crc_one_mode(&data, port, |
| 962 | DRM_FORMAT_XRGB8888, 1); |
| 963 | |
| 964 | connector_subtest("hdmi-crc-xbgr8888", HDMIA) |
| 965 | test_display_crc_one_mode(&data, port, |
| 966 | DRM_FORMAT_XBGR8888, 1); |
| 967 | |
| 968 | connector_subtest("hdmi-crc-rgb888", HDMIA) |
| 969 | test_display_crc_one_mode(&data, port, |
| 970 | DRM_FORMAT_RGB888, 1); |
| 971 | |
| 972 | connector_subtest("hdmi-crc-bgr888", HDMIA) |
| 973 | test_display_crc_one_mode(&data, port, |
| 974 | DRM_FORMAT_BGR888, 1); |
| 975 | |
| 976 | connector_subtest("hdmi-crc-rgb565", HDMIA) |
| 977 | test_display_crc_one_mode(&data, port, |
| 978 | DRM_FORMAT_RGB565, 1); |
| 979 | |
| 980 | connector_subtest("hdmi-crc-bgr565", HDMIA) |
| 981 | test_display_crc_one_mode(&data, port, |
| 982 | DRM_FORMAT_BGR565, 1); |
| 983 | |
| 984 | connector_subtest("hdmi-crc-argb1555", HDMIA) |
| 985 | test_display_crc_one_mode(&data, port, |
| 986 | DRM_FORMAT_ARGB1555, 1); |
| 987 | |
| 988 | connector_subtest("hdmi-crc-xrgb1555", HDMIA) |
| 989 | test_display_crc_one_mode(&data, port, |
| 990 | DRM_FORMAT_XRGB1555, 1); |
| 991 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 992 | connector_subtest("hdmi-frame-dump", HDMIA) |
| 993 | test_display_frame_dump(&data, port); |
| 994 | } |
| 995 | |
| 996 | igt_subtest_group { |
| 997 | igt_fixture { |
| 998 | require_connector_present( |
| 999 | &data, DRM_MODE_CONNECTOR_VGA); |
| 1000 | } |
| 1001 | |
| 1002 | connector_subtest("vga-hpd", VGA) |
Paul Kocialkowki | 7d714b2 | 2017-06-27 13:53:08 +0300 | [diff] [blame] | 1003 | test_basic_hotplug(&data, port, HPD_TOGGLE_COUNT_VGA); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 1004 | |
Paul Kocialkowski | 4ee824e | 2017-08-23 18:21:12 +0300 | [diff] [blame] | 1005 | connector_subtest("vga-hpd-fast", VGA) |
| 1006 | test_basic_hotplug(&data, port, HPD_TOGGLE_COUNT_FAST); |
| 1007 | |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 1008 | connector_subtest("vga-edid-read", VGA) { |
| 1009 | test_edid_read(&data, port, edid_id, |
| 1010 | igt_kms_get_base_edid()); |
| 1011 | test_edid_read(&data, port, alt_edid_id, |
| 1012 | igt_kms_get_alt_edid()); |
| 1013 | } |
| 1014 | |
Paul Kocialkowki | 2b15b2d | 2017-06-27 13:53:07 +0300 | [diff] [blame] | 1015 | connector_subtest("vga-hpd-after-suspend", VGA) |
| 1016 | test_suspend_resume_hpd(&data, port, |
| 1017 | SUSPEND_STATE_MEM, |
| 1018 | SUSPEND_TEST_NONE); |
| 1019 | |
| 1020 | connector_subtest("vga-hpd-after-hibernate", VGA) |
| 1021 | test_suspend_resume_hpd(&data, port, |
| 1022 | SUSPEND_STATE_DISK, |
| 1023 | SUSPEND_TEST_DEVICES); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 1024 | |
| 1025 | connector_subtest("vga-hpd-without-ddc", VGA) |
| 1026 | test_hpd_without_ddc(&data, port); |
Paul Kocialkowski | e246ff0 | 2017-07-20 18:13:37 +0300 | [diff] [blame] | 1027 | |
| 1028 | connector_subtest("vga-frame-dump", VGA) |
| 1029 | test_analog_frame_dump(&data, port); |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 1030 | } |
Paul Kocialkowski | 5d494bd | 2017-06-12 17:39:35 +0300 | [diff] [blame] | 1031 | |
Paul Kocialkowki | fea6f86 | 2017-06-19 12:39:05 +0300 | [diff] [blame] | 1032 | igt_subtest_group { |
| 1033 | igt_subtest("common-hpd-after-suspend") |
| 1034 | test_suspend_resume_hpd_common(&data, |
| 1035 | SUSPEND_STATE_MEM, |
| 1036 | SUSPEND_TEST_NONE); |
| 1037 | |
| 1038 | igt_subtest("common-hpd-after-hibernate") |
| 1039 | test_suspend_resume_hpd_common(&data, |
| 1040 | SUSPEND_STATE_DISK, |
| 1041 | SUSPEND_TEST_DEVICES); |
| 1042 | } |
| 1043 | |
Paul Kocialkowski | 5d494bd | 2017-06-12 17:39:35 +0300 | [diff] [blame] | 1044 | igt_fixture { |
Maarten Lankhorst | 0b735f1 | 2017-11-16 11:33:50 +0100 | [diff] [blame] | 1045 | igt_display_fini(&data.display); |
Paul Kocialkowski | 5d494bd | 2017-06-12 17:39:35 +0300 | [diff] [blame] | 1046 | close(data.drm_fd); |
| 1047 | } |
Lyude | c99f8b7 | 2016-10-18 14:12:09 -0400 | [diff] [blame] | 1048 | } |