Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Intel Corporation |
| 3 | * Jesse Barnes <jesse.barnes@intel.com> |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the 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 THE |
| 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * This program is intended for testing of display functionality. It should |
| 26 | * allow for testing of |
| 27 | * - hotplug |
| 28 | * - mode setting |
| 29 | * - clone & twin modes |
| 30 | * - panel fitting |
| 31 | * - test patterns & pixel generators |
| 32 | * Additional programs can test the detected outputs against VBT provided |
| 33 | * device lists (both docked & undocked). |
| 34 | * |
| 35 | * TODO: |
| 36 | * - pixel generator in transcoder |
| 37 | * - test pattern reg in pipe |
| 38 | * - test patterns on outputs (e.g. TV) |
| 39 | * - handle hotplug (leaks crtcs, can't handle clones) |
| 40 | * - allow mode force |
| 41 | * - expose output specific controls |
| 42 | * - e.g. DDC-CI brightness |
| 43 | * - HDMI controls |
| 44 | * - panel brightness |
| 45 | * - DP commands (e.g. poweroff) |
| 46 | * - verify outputs against VBT/physical connectors |
| 47 | */ |
Damien Lespiau | 7ee278f | 2013-02-20 14:40:07 +0000 | [diff] [blame] | 48 | #ifdef HAVE_CONFIG_H |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 49 | #include "config.h" |
Damien Lespiau | 7ee278f | 2013-02-20 14:40:07 +0000 | [diff] [blame] | 50 | #endif |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 51 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 52 | #include <cairo.h> |
| 53 | #include <errno.h> |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 54 | #include <math.h> |
| 55 | #include <stdint.h> |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 56 | #include <stdbool.h> |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 57 | #include <strings.h> |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 58 | #include <unistd.h> |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 59 | #include <termios.h> |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 60 | #include <sys/poll.h> |
| 61 | #include <sys/time.h> |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 62 | #include <sys/ioctl.h> |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 63 | #include <sys/types.h> |
| 64 | #include <sys/stat.h> |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 65 | |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 66 | #include "ioctl_wrappers.h" |
Daniel Vetter | 7a6042e | 2012-01-10 18:29:30 +0100 | [diff] [blame] | 67 | #include "drmtest.h" |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 68 | #include "testdisplay.h" |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 69 | #include "igt_kms.h" |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 70 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 71 | #include <stdlib.h> |
| 72 | #include <signal.h> |
| 73 | |
Thomas Wood | ff6b068 | 2014-07-31 16:26:55 +0100 | [diff] [blame] | 74 | #define SUBTEST_OPTS 1 |
| 75 | |
Imre Deak | 6374641 | 2014-05-12 13:29:49 +0300 | [diff] [blame] | 76 | static int tio_fd; |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 77 | struct termios saved_tio; |
| 78 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 79 | drmModeRes *resources; |
Daniel Vetter | 73d1b88 | 2012-01-10 18:20:39 +0100 | [diff] [blame] | 80 | int drm_fd, modes; |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 81 | int test_all_modes = 0, test_preferred_mode = 0, force_mode = 0, test_plane, |
Damien Lespiau | d9ffb7d | 2014-06-20 12:02:09 +0100 | [diff] [blame] | 82 | test_stereo_modes; |
| 83 | unsigned int tiling = I915_TILING_NONE; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 84 | int sleep_between_modes = 5; |
Daniel Vetter | cef9b31 | 2014-02-13 19:22:35 +0100 | [diff] [blame] | 85 | int do_dpms = 0; /* This aliases to DPMS_ON */ |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 86 | uint32_t depth = 24, stride, bpp; |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 87 | int qr_code = 0; |
Yi Sun | 6157d24 | 2013-02-12 23:11:35 +0800 | [diff] [blame] | 88 | int specified_mode_num = -1, specified_disp_id = -1; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 89 | |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 90 | drmModeModeInfo force_timing; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 91 | |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 92 | int crtc_x, crtc_y, crtc_w, crtc_h, width, height; |
Jesse Barnes | 1f4c37a | 2011-10-28 05:25:53 +0200 | [diff] [blame] | 93 | unsigned int plane_fb_id; |
| 94 | unsigned int plane_crtc_id; |
| 95 | unsigned int plane_id; |
| 96 | int plane_width, plane_height; |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 97 | static const uint32_t SPRITE_COLOR_KEY = 0x00aaaaaa; |
Jesse Barnes | 24e6038 | 2011-10-24 17:15:34 +0200 | [diff] [blame] | 98 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 99 | /* |
| 100 | * Mode setting with the kernel interfaces is a bit of a chore. |
| 101 | * First you have to find the connector in question and make sure the |
| 102 | * requested mode is available. |
| 103 | * Then you need to find the encoder attached to that connector so you |
| 104 | * can bind it with a free crtc. |
| 105 | */ |
| 106 | struct connector { |
| 107 | uint32_t id; |
| 108 | int mode_valid; |
| 109 | drmModeModeInfo mode; |
| 110 | drmModeEncoder *encoder; |
| 111 | drmModeConnector *connector; |
| 112 | int crtc; |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 113 | int crtc_idx; |
Jesse Barnes | 9c29be4 | 2011-11-02 12:57:40 -0700 | [diff] [blame] | 114 | int pipe; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 117 | static void dump_connectors_fd(int drmfd) |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 118 | { |
| 119 | int i, j; |
| 120 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 121 | drmModeRes *mode_resources = drmModeGetResources(drmfd); |
| 122 | |
| 123 | if (!mode_resources) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 124 | igt_warn("drmModeGetResources failed: %s\n", strerror(errno)); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 125 | return; |
| 126 | } |
| 127 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 128 | igt_info("Connectors:\n"); |
| 129 | igt_info("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 130 | for (i = 0; i < mode_resources->count_connectors; i++) { |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 131 | drmModeConnector *connector; |
| 132 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 133 | connector = drmModeGetConnector(drmfd, mode_resources->connectors[i]); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 134 | if (!connector) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 135 | igt_warn("could not get connector %i: %s\n", mode_resources->connectors[i], strerror(errno)); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 136 | continue; |
| 137 | } |
| 138 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 139 | igt_info("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n", connector->connector_id, connector->encoder_id, kmstest_connector_status_str(connector->connection), kmstest_connector_type_str(connector->connector_type), connector->mmWidth, connector->mmHeight, connector->count_modes); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 140 | |
| 141 | if (!connector->count_modes) |
| 142 | continue; |
| 143 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 144 | igt_info(" modes:\n"); |
| 145 | igt_info(" name refresh (Hz) hdisp hss hse htot vdisp ""vss vse vtot flags type clock\n"); |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 146 | for (j = 0; j < connector->count_modes; j++){ |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 147 | igt_info("[%d]", j); |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 148 | kmstest_dump_mode(&connector->modes[j]); |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 149 | } |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 150 | |
| 151 | drmModeFreeConnector(connector); |
| 152 | } |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 153 | igt_info("\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 154 | |
| 155 | drmModeFreeResources(mode_resources); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 156 | } |
| 157 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 158 | static void dump_crtcs_fd(int drmfd) |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 159 | { |
| 160 | int i; |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 161 | drmModeRes *mode_resources = drmModeGetResources(drmfd); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 162 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 163 | igt_info("CRTCs:\n"); |
| 164 | igt_info("id\tfb\tpos\tsize\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 165 | for (i = 0; i < mode_resources->count_crtcs; i++) { |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 166 | drmModeCrtc *crtc; |
| 167 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 168 | crtc = drmModeGetCrtc(drmfd, mode_resources->crtcs[i]); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 169 | if (!crtc) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 170 | igt_warn("could not get crtc %i: %s\n", mode_resources->crtcs[i], strerror(errno)); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 171 | continue; |
| 172 | } |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 173 | igt_info("%d\t%d\t(%d,%d)\t(%dx%d)\n", crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, crtc->width, crtc->height); |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 174 | kmstest_dump_mode(&crtc->mode); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 175 | |
| 176 | drmModeFreeCrtc(crtc); |
| 177 | } |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 178 | igt_info("\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 179 | |
| 180 | drmModeFreeResources(mode_resources); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 181 | } |
| 182 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 183 | static void dump_info(void) |
| 184 | { |
| 185 | dump_connectors_fd(drm_fd); |
| 186 | dump_crtcs_fd(drm_fd); |
| 187 | } |
| 188 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 189 | static void connector_find_preferred_mode(uint32_t connector_id, |
| 190 | unsigned long crtc_idx_mask, |
| 191 | int mode_num, struct connector *c) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 192 | { |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 193 | struct kmstest_connector_config config; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 194 | |
Daniel Vetter | 1cad834 | 2014-08-12 11:57:32 +0200 | [diff] [blame] | 195 | if (!kmstest_get_connector_config(drm_fd, connector_id, crtc_idx_mask, |
| 196 | &config)) { |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 197 | c->mode_valid = 0; |
| 198 | return; |
| 199 | } |
| 200 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 201 | c->connector = config.connector; |
| 202 | c->encoder = config.encoder; |
| 203 | c->crtc = config.crtc->crtc_id; |
| 204 | c->crtc_idx = config.crtc_idx; |
| 205 | c->pipe = config.pipe; |
| 206 | |
| 207 | if (mode_num != -1) { |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 208 | igt_assert(mode_num < config.connector->count_modes); |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 209 | c->mode = config.connector->modes[mode_num]; |
| 210 | } else { |
| 211 | c->mode = config.default_mode; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 212 | } |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 213 | c->mode_valid = 1; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Jesse Barnes | 0d3043f | 2011-04-18 16:48:27 -0700 | [diff] [blame] | 216 | static void |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 217 | paint_color_key(struct igt_fb *fb_info) |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 218 | { |
| 219 | int i, j; |
Damien Lespiau | 5a1d843 | 2013-09-04 12:12:37 +0100 | [diff] [blame] | 220 | uint32_t *fb_ptr; |
| 221 | |
| 222 | fb_ptr = gem_mmap(drm_fd, fb_info->gem_handle, |
| 223 | fb_info->size, PROT_READ | PROT_WRITE); |
| 224 | igt_assert(fb_ptr); |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 225 | |
| 226 | for (i = crtc_y; i < crtc_y + crtc_h; i++) |
| 227 | for (j = crtc_x; j < crtc_x + crtc_w; j++) { |
| 228 | uint32_t offset; |
| 229 | |
Damien Lespiau | b118877 | 2012-11-27 19:14:05 +0000 | [diff] [blame] | 230 | offset = (i * fb_info->stride / 4) + j; |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 231 | fb_ptr[offset] = SPRITE_COLOR_KEY; |
| 232 | } |
Damien Lespiau | 5a1d843 | 2013-09-04 12:12:37 +0100 | [diff] [blame] | 233 | |
| 234 | munmap(fb_ptr, fb_info->size); |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 237 | static void paint_image(cairo_t *cr, const char *file) |
| 238 | { |
| 239 | int img_x, img_y, img_w, img_h, img_w_o, img_h_o; |
| 240 | double img_w_scale, img_h_scale; |
| 241 | |
| 242 | cairo_surface_t *image; |
| 243 | |
| 244 | img_y = height * (0.10 ); |
| 245 | img_h = height * 0.08 * 4; |
| 246 | img_w = img_h; |
| 247 | |
| 248 | img_x = (width / 2) - (img_w / 2); |
| 249 | |
| 250 | image = cairo_image_surface_create_from_png(file); |
| 251 | |
| 252 | img_w_o = cairo_image_surface_get_width(image); |
| 253 | img_h_o = cairo_image_surface_get_height(image); |
| 254 | |
| 255 | cairo_translate(cr, img_x, img_y); |
| 256 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 257 | img_w_scale = (double)img_w / (double)img_w_o; |
| 258 | img_h_scale = (double)img_h / (double)img_h_o; |
| 259 | cairo_scale(cr, img_w_scale, img_h_scale); |
| 260 | |
| 261 | cairo_set_source_surface(cr, image, 0, 0); |
| 262 | cairo_scale(cr, 1, 1); |
| 263 | |
| 264 | cairo_paint(cr); |
| 265 | cairo_surface_destroy(image); |
| 266 | } |
| 267 | |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 268 | static void paint_output_info(struct connector *c, struct igt_fb *fb) |
Jesse Barnes | 0d3043f | 2011-04-18 16:48:27 -0700 | [diff] [blame] | 269 | { |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 270 | cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb); |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 271 | int l_width = fb->width; |
| 272 | int l_height = fb->height; |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 273 | double str_width; |
| 274 | double x, y, top_y; |
| 275 | double max_width; |
| 276 | int i; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 277 | |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 278 | igt_paint_test_pattern(cr, l_width, l_height); |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 279 | |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 280 | cairo_move_to(cr, l_width / 2, l_height / 2); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 281 | |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 282 | /* Print connector and mode name */ |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 283 | cairo_set_font_size(cr, 48); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 284 | igt_cairo_printf_line(cr, align_hcenter, 10, "%s", |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 285 | kmstest_connector_type_str(c->connector->connector_type)); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 286 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 287 | cairo_set_font_size(cr, 36); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 288 | str_width = igt_cairo_printf_line(cr, align_hcenter, 10, |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 289 | "%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh, |
| 290 | kmstest_encoder_type_str(c->encoder->encoder_type)); |
| 291 | |
| 292 | cairo_rel_move_to(cr, -str_width / 2, 0); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 293 | |
| 294 | /* List available modes */ |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 295 | cairo_set_font_size(cr, 18); |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 296 | str_width = igt_cairo_printf_line(cr, align_left, 10, |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 297 | "Available modes:"); |
| 298 | cairo_rel_move_to(cr, str_width, 0); |
| 299 | cairo_get_current_point(cr, &x, &top_y); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 300 | |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 301 | max_width = 0; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 302 | for (i = 0; i < c->connector->count_modes; i++) { |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 303 | cairo_get_current_point(cr, &x, &y); |
| 304 | if (y >= l_height) { |
| 305 | x += max_width + 10; |
| 306 | max_width = 0; |
| 307 | cairo_move_to(cr, x, top_y); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 308 | } |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 309 | str_width = igt_cairo_printf_line(cr, align_right, 10, |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 310 | "%s @ %dHz", c->connector->modes[i].name, |
| 311 | c->connector->modes[i].vrefresh); |
| 312 | if (str_width > max_width) |
| 313 | max_width = str_width; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 314 | } |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 315 | |
| 316 | if (qr_code) |
Damien Lespiau | 951b37e | 2013-09-06 11:44:41 +0100 | [diff] [blame] | 317 | paint_image(cr, IGT_DATADIR"/pass.png"); |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 318 | |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 319 | igt_assert(!cairo_status(cr)); |
Damien Lespiau | 660a7ff | 2014-06-30 16:19:05 +0100 | [diff] [blame] | 320 | |
| 321 | cairo_destroy(cr); |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static void sighandler(int signo) |
| 325 | { |
| 326 | return; |
| 327 | } |
| 328 | |
| 329 | static void set_single(void) |
| 330 | { |
| 331 | int sigs[] = { SIGUSR1 }; |
| 332 | struct sigaction sa; |
| 333 | sa.sa_handler = sighandler; |
| 334 | |
| 335 | sigemptyset(&sa.sa_mask); |
| 336 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 337 | igt_warn_on_f(sigaction(sigs[0], &sa, NULL) == -1, |
| 338 | "Could not set signal handler"); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 341 | static void |
| 342 | set_mode(struct connector *c) |
| 343 | { |
Daniel Vetter | 434be47 | 2012-07-21 17:36:36 +0200 | [diff] [blame] | 344 | unsigned int fb_id = 0; |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 345 | struct igt_fb fb_info[2] = { }; |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 346 | int j, test_mode_num, current_fb = 0, old_fb = -1; |
Jesse Barnes | c56cd10 | 2011-04-19 11:50:16 -0700 | [diff] [blame] | 347 | |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 348 | test_mode_num = 1; |
| 349 | if (force_mode){ |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 350 | memcpy( &c->mode, &force_timing, sizeof(force_timing)); |
| 351 | c->mode.vrefresh =(force_timing.clock*1e3)/(force_timing.htotal*force_timing.vtotal); |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 352 | c->mode_valid = 1; |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 353 | sprintf(c->mode.name, "%dx%d", force_timing.hdisplay, force_timing.vdisplay); |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 354 | } else if (test_all_modes) |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 355 | test_mode_num = c->connector->count_modes; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 356 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 357 | for (j = 0; j < test_mode_num; j++) { |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 358 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 359 | if (test_all_modes) |
| 360 | c->mode = c->connector->modes[j]; |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 361 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 362 | /* set_mode() only tests 2D modes */ |
Damien Lespiau | a7d1937 | 2013-09-26 17:56:01 +0100 | [diff] [blame] | 363 | if (c->mode.flags & DRM_MODE_FLAG_3D_MASK) |
| 364 | continue; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 365 | |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 366 | if (!c->mode_valid) |
| 367 | continue; |
| 368 | |
| 369 | width = c->mode.hdisplay; |
| 370 | height = c->mode.vdisplay; |
| 371 | |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 372 | fb_id = igt_create_fb(drm_fd, width, height, |
Damien Lespiau | d9ffb7d | 2014-06-20 12:02:09 +0100 | [diff] [blame] | 373 | igt_bpp_depth_to_drm_format(bpp, depth), |
| 374 | tiling, &fb_info[current_fb]); |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 375 | paint_output_info(c, &fb_info[current_fb]); |
| 376 | paint_color_key(&fb_info[current_fb]); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 377 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 378 | igt_info("CRTC(%u):[%d]", c->crtc, j); |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 379 | kmstest_dump_mode(&c->mode); |
Daniel Vetter | 73d1b88 | 2012-01-10 18:20:39 +0100 | [diff] [blame] | 380 | if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 381 | &c->id, 1, &c->mode)) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 382 | igt_warn("failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno)); |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 383 | continue; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 384 | } |
| 385 | |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 386 | if (old_fb != -1) |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 387 | igt_remove_fb(drm_fd, &fb_info[old_fb]); |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 388 | old_fb = current_fb; |
| 389 | current_fb = 1 - current_fb; |
| 390 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 391 | if (sleep_between_modes && test_all_modes && !qr_code) |
Hai Lan | dac602b | 2011-02-11 23:25:36 -0500 | [diff] [blame] | 392 | sleep(sleep_between_modes); |
Yi Sun | 1f41a30 | 2011-12-01 18:57:16 +0800 | [diff] [blame] | 393 | |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 394 | if (do_dpms) { |
Daniel Vetter | 29ee36f | 2014-04-24 23:33:09 +0200 | [diff] [blame] | 395 | kmstest_set_connector_dpms(drm_fd, c->connector, do_dpms); |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 396 | sleep(sleep_between_modes); |
Daniel Vetter | 29ee36f | 2014-04-24 23:33:09 +0200 | [diff] [blame] | 397 | kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON); |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 398 | } |
| 399 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 400 | if (qr_code){ |
| 401 | set_single(); |
| 402 | pause(); |
| 403 | } |
Yi Sun | 1f41a30 | 2011-12-01 18:57:16 +0800 | [diff] [blame] | 404 | } |
| 405 | |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 406 | if (test_all_modes) |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 407 | igt_remove_fb(drm_fd, &fb_info[old_fb]); |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 408 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 409 | drmModeFreeEncoder(c->encoder); |
| 410 | drmModeFreeConnector(c->connector); |
| 411 | } |
| 412 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 413 | static void do_set_stereo_mode(struct connector *c) |
| 414 | { |
| 415 | uint32_t fb_id; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 416 | |
Thomas Wood | 4cb1946 | 2014-08-04 16:14:51 +0100 | [diff] [blame] | 417 | fb_id = igt_create_stereo_fb(drm_fd, &c->mode, |
| 418 | igt_bpp_depth_to_drm_format(bpp, depth), |
| 419 | tiling); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 420 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 421 | igt_warn_on_f(drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, &c->id, 1, &c->mode), |
| 422 | "failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno)); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static void |
| 426 | set_stereo_mode(struct connector *c) |
| 427 | { |
Damien Lespiau | e836b60 | 2013-09-30 17:42:33 +0100 | [diff] [blame] | 428 | int i, n; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 429 | |
Damien Lespiau | e836b60 | 2013-09-30 17:42:33 +0100 | [diff] [blame] | 430 | |
| 431 | if (specified_mode_num != -1) |
| 432 | n = 1; |
| 433 | else |
| 434 | n = c->connector->count_modes; |
| 435 | |
| 436 | for (i = 0; i < n; i++) { |
| 437 | if (specified_mode_num == -1) |
| 438 | c->mode = c->connector->modes[i]; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 439 | |
| 440 | if (!c->mode_valid) |
| 441 | continue; |
| 442 | |
Damien Lespiau | a7d1937 | 2013-09-26 17:56:01 +0100 | [diff] [blame] | 443 | if (!(c->mode.flags & DRM_MODE_FLAG_3D_MASK)) |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 444 | continue; |
| 445 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 446 | igt_info("CRTC(%u): [%d]", c->crtc, i); |
Damien Lespiau | 6de613f | 2013-09-30 18:03:33 +0100 | [diff] [blame] | 447 | kmstest_dump_mode(&c->mode); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 448 | do_set_stereo_mode(c); |
| 449 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 450 | if (qr_code) { |
| 451 | set_single(); |
| 452 | pause(); |
| 453 | } else if (sleep_between_modes) |
| 454 | sleep(sleep_between_modes); |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 455 | |
| 456 | if (do_dpms) { |
Daniel Vetter | 29ee36f | 2014-04-24 23:33:09 +0200 | [diff] [blame] | 457 | kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 458 | sleep(sleep_between_modes); |
Daniel Vetter | 29ee36f | 2014-04-24 23:33:09 +0200 | [diff] [blame] | 459 | kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON); |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 460 | } |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | drmModeFreeEncoder(c->encoder); |
| 464 | drmModeFreeConnector(c->connector); |
| 465 | } |
| 466 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 467 | /* |
| 468 | * Re-probe outputs and light up as many as possible. |
| 469 | * |
| 470 | * On Intel, we have two CRTCs that we can drive independently with |
| 471 | * different timings and scanout buffers. |
| 472 | * |
| 473 | * Each connector has a corresponding encoder, except in the SDVO case |
| 474 | * where an encoder may have multiple connectors. |
| 475 | */ |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 476 | int update_display(void) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 477 | { |
| 478 | struct connector *connectors; |
| 479 | int c; |
| 480 | |
Daniel Vetter | 73d1b88 | 2012-01-10 18:20:39 +0100 | [diff] [blame] | 481 | resources = drmModeGetResources(drm_fd); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 482 | if (!resources) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 483 | igt_warn("drmModeGetResources failed: %s\n", strerror(errno)); |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 484 | return 0; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | connectors = calloc(resources->count_connectors, |
| 488 | sizeof(struct connector)); |
| 489 | if (!connectors) |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 490 | return 0; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 491 | |
Damien Lespiau | e836b60 | 2013-09-30 17:42:33 +0100 | [diff] [blame] | 492 | if (test_preferred_mode || test_all_modes || |
| 493 | force_mode || specified_disp_id != -1) { |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 494 | unsigned long crtc_idx_mask = -1UL; |
| 495 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 496 | /* Find any connected displays */ |
| 497 | for (c = 0; c < resources->count_connectors; c++) { |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 498 | struct connector *connector = &connectors[c]; |
| 499 | |
| 500 | connector->id = resources->connectors[c]; |
| 501 | if (specified_disp_id != -1 && |
| 502 | connector->id != specified_disp_id) |
Yi Sun | 05bfbf4 | 2012-12-26 17:12:39 +0800 | [diff] [blame] | 503 | continue; |
| 504 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 505 | connector_find_preferred_mode(connector->id, |
| 506 | crtc_idx_mask, |
| 507 | specified_mode_num, |
| 508 | connector); |
| 509 | if (!connector->mode_valid) |
| 510 | continue; |
| 511 | |
| 512 | set_mode(connector); |
| 513 | |
| 514 | if (test_preferred_mode || force_mode || |
| 515 | specified_mode_num != -1) |
| 516 | crtc_idx_mask &= ~(1 << connector->crtc_idx); |
| 517 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 518 | } |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 519 | } |
Damien Lespiau | 5d99634 | 2013-09-04 14:21:55 +0100 | [diff] [blame] | 520 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 521 | if (test_stereo_modes) { |
| 522 | for (c = 0; c < resources->count_connectors; c++) { |
| 523 | struct connector *connector = &connectors[c]; |
| 524 | |
| 525 | connector->id = resources->connectors[c]; |
Damien Lespiau | c128b73 | 2013-09-30 17:02:21 +0100 | [diff] [blame] | 526 | if (specified_disp_id != -1 && |
| 527 | connector->id != specified_disp_id) |
| 528 | continue; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 529 | |
| 530 | connector_find_preferred_mode(connector->id, |
| 531 | -1UL, |
| 532 | specified_mode_num, |
| 533 | connector); |
| 534 | if (!connector->mode_valid) |
| 535 | continue; |
| 536 | |
| 537 | set_stereo_mode(connector); |
| 538 | } |
| 539 | } |
| 540 | |
Damien Lespiau | 5d99634 | 2013-09-04 14:21:55 +0100 | [diff] [blame] | 541 | free(connectors); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 542 | drmModeFreeResources(resources); |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 543 | return 1; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Daniel Vetter | cef9b31 | 2014-02-13 19:22:35 +0100 | [diff] [blame] | 546 | static char optstr[] = "3hiaf:s:d:p:mrto:j:"; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 547 | |
Ben Widawsky | 54ed938 | 2012-08-30 14:03:54 -0700 | [diff] [blame] | 548 | static void __attribute__((noreturn)) usage(char *name) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 549 | { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 550 | igt_info("usage: %s [-hiasdpmtf]\n", name); |
| 551 | igt_info("\t-i\tdump info\n"); |
| 552 | igt_info("\t-a\ttest all modes\n"); |
| 553 | igt_info("\t-s\t<duration>\tsleep between each mode test\n"); |
| 554 | igt_info("\t-d\t<depth>\tbit depth of scanout buffer\n"); |
| 555 | igt_info("\t-p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n"); |
| 556 | igt_info("\t-m\ttest the preferred mode\n"); |
| 557 | igt_info("\t-3\ttest all 3D modes\n"); |
| 558 | igt_info("\t-t\tuse a tiled framebuffer\n"); |
| 559 | igt_info("\t-j\tdo dpms off, optional arg to select dpms leve (1-3)\n"); |
| 560 | igt_info("\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n"); |
| 561 | igt_info("\t-o\t<id of the display>,<number of the mode>\tonly test specified mode on the specified display\n"); |
| 562 | igt_info("\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n"); |
| 563 | igt_info("\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n"); |
| 564 | igt_info("\t\ttest force mode\n"); |
| 565 | igt_info("\tDefault is to test all modes.\n"); |
Thomas Wood | 8fc4107 | 2014-07-25 15:35:36 +0100 | [diff] [blame] | 566 | exit((optopt) ? -1 : 0); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 569 | #define dump_resource(res) if (res) dump_##res() |
| 570 | |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 571 | static void cleanup_and_exit(int ret) |
| 572 | { |
| 573 | close(drm_fd); |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 574 | exit(ret); |
| 575 | } |
| 576 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 577 | static gboolean input_event(GIOChannel *source, GIOCondition condition, |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 578 | gpointer data) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 579 | { |
Daniel Vetter | 74d6545 | 2011-12-18 00:24:45 +0100 | [diff] [blame] | 580 | gchar buf[2]; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 581 | gsize count; |
| 582 | |
Chris Wilson | 2803238 | 2011-02-11 10:56:41 +0000 | [diff] [blame] | 583 | count = read(g_io_channel_unix_get_fd(source), buf, sizeof(buf)); |
Jesse Barnes | 24e6038 | 2011-10-24 17:15:34 +0200 | [diff] [blame] | 584 | if (buf[0] == 'q' && (count == 1 || buf[1] == '\n')) { |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 585 | cleanup_and_exit(0); |
Jesse Barnes | ea41633 | 2012-02-27 12:46:11 -0800 | [diff] [blame] | 586 | } |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 587 | |
| 588 | return TRUE; |
| 589 | } |
| 590 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 591 | static void enter_exec_path( char **argv ) |
| 592 | { |
| 593 | char *exec_path = NULL; |
| 594 | char *pos = NULL; |
| 595 | short len_path = 0; |
Imre Deak | 31dfc98 | 2012-10-10 16:04:45 +0300 | [diff] [blame] | 596 | int ret; |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 597 | |
| 598 | len_path = strlen( argv[0] ); |
| 599 | exec_path = (char*) malloc(len_path); |
| 600 | |
| 601 | memcpy(exec_path, argv[0], len_path); |
| 602 | pos = strrchr(exec_path, '/'); |
| 603 | if (pos != NULL) |
| 604 | *(pos+1) = '\0'; |
| 605 | |
Imre Deak | 31dfc98 | 2012-10-10 16:04:45 +0300 | [diff] [blame] | 606 | ret = chdir(exec_path); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 607 | igt_assert(ret == 0); |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 608 | free(exec_path); |
| 609 | } |
| 610 | |
Imre Deak | 6374641 | 2014-05-12 13:29:49 +0300 | [diff] [blame] | 611 | static void restore_termio_mode(int sig) |
| 612 | { |
| 613 | tcsetattr(tio_fd, TCSANOW, &saved_tio); |
| 614 | close(tio_fd); |
| 615 | } |
| 616 | |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 617 | static void set_termio_mode(void) |
| 618 | { |
| 619 | struct termios tio; |
| 620 | |
Thomas Wood | 8408e00 | 2014-07-24 17:45:48 +0100 | [diff] [blame] | 621 | /* don't attempt to set terminal attributes if not in the foreground |
| 622 | * process group */ |
| 623 | if (getpgrp() != tcgetpgrp(STDOUT_FILENO)) |
| 624 | return; |
| 625 | |
Imre Deak | 6374641 | 2014-05-12 13:29:49 +0300 | [diff] [blame] | 626 | tio_fd = dup(STDIN_FILENO); |
| 627 | tcgetattr(tio_fd, &saved_tio); |
| 628 | igt_install_exit_handler(restore_termio_mode); |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 629 | tio = saved_tio; |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 630 | tio.c_lflag &= ~(ICANON | ECHO); |
Imre Deak | 6374641 | 2014-05-12 13:29:49 +0300 | [diff] [blame] | 631 | tcsetattr(tio_fd, TCSANOW, &tio); |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 634 | int main(int argc, char **argv) |
| 635 | { |
| 636 | int c; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 637 | int ret = 0; |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 638 | GIOChannel *stdinchannel; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 639 | GMainLoop *mainloop; |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 640 | float force_clock; |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 641 | bool opt_dump_info = false; |
Thomas Wood | ff6b068 | 2014-07-31 16:26:55 +0100 | [diff] [blame] | 642 | struct option long_opts[] = { |
| 643 | {"list-subtests", 0, 0, SUBTEST_OPTS}, |
| 644 | {"run-subtest", 1, 0, SUBTEST_OPTS}, |
| 645 | { 0, 0, 0, 0 } |
| 646 | }; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 647 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 648 | igt_skip_on_simulation(); |
Damien Lespiau | 5fa15f7 | 2013-04-29 18:40:39 +0100 | [diff] [blame] | 649 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 650 | enter_exec_path( argv ); |
| 651 | |
Thomas Wood | ff6b068 | 2014-07-31 16:26:55 +0100 | [diff] [blame] | 652 | while ((c = getopt_long(argc, argv, optstr, long_opts, NULL)) != -1) { |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 653 | switch (c) { |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 654 | case '3': |
| 655 | test_stereo_modes = 1; |
| 656 | break; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 657 | case 'i': |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 658 | opt_dump_info = true; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 659 | break; |
| 660 | case 'a': |
| 661 | test_all_modes = 1; |
| 662 | break; |
| 663 | case 'f': |
| 664 | force_mode = 1; |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 665 | if(sscanf(optarg,"%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu", |
| 666 | &force_clock,&force_timing.hdisplay, &force_timing.hsync_start,&force_timing.hsync_end,&force_timing.htotal, |
| 667 | &force_timing.vdisplay, &force_timing.vsync_start, &force_timing.vsync_end, &force_timing.vtotal)!= 9) |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 668 | usage(argv[0]); |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 669 | force_timing.clock = force_clock*1000; |
| 670 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 671 | break; |
| 672 | case 's': |
| 673 | sleep_between_modes = atoi(optarg); |
| 674 | break; |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 675 | case 'j': |
Daniel Vetter | cef9b31 | 2014-02-13 19:22:35 +0100 | [diff] [blame] | 676 | do_dpms = atoi(optarg); |
| 677 | if (do_dpms == 0) |
| 678 | do_dpms = DRM_MODE_DPMS_OFF; |
Daniel Vetter | 30cfde5 | 2014-02-13 19:15:38 +0100 | [diff] [blame] | 679 | break; |
Jesse Barnes | c56cd10 | 2011-04-19 11:50:16 -0700 | [diff] [blame] | 680 | case 'd': |
| 681 | depth = atoi(optarg); |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 682 | igt_info("using depth %d\n", depth); |
Jesse Barnes | c56cd10 | 2011-04-19 11:50:16 -0700 | [diff] [blame] | 683 | break; |
Jesse Barnes | 7230c01 | 2011-06-07 13:17:46 -0700 | [diff] [blame] | 684 | case 'p': |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 685 | if (sscanf(optarg, "%d,%d,%d,%d,%d,%d", &plane_width, |
| 686 | &plane_height, &crtc_x, &crtc_y, |
| 687 | &crtc_w, &crtc_h) != 6) |
Jesse Barnes | 24e6038 | 2011-10-24 17:15:34 +0200 | [diff] [blame] | 688 | usage(argv[0]); |
Jesse Barnes | 7230c01 | 2011-06-07 13:17:46 -0700 | [diff] [blame] | 689 | test_plane = 1; |
| 690 | break; |
Paulo Zanoni | 9fe1148 | 2011-09-15 15:13:41 -0300 | [diff] [blame] | 691 | case 'm': |
| 692 | test_preferred_mode = 1; |
| 693 | break; |
Jesse Barnes | b707feb | 2011-06-07 13:27:35 -0700 | [diff] [blame] | 694 | case 't': |
Damien Lespiau | d9ffb7d | 2014-06-20 12:02:09 +0100 | [diff] [blame] | 695 | tiling = I915_TILING_X; |
Jesse Barnes | b707feb | 2011-06-07 13:27:35 -0700 | [diff] [blame] | 696 | break; |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 697 | case 'r': |
| 698 | qr_code = 1; |
| 699 | break; |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 700 | case 'o': |
Yi Sun | 05bfbf4 | 2012-12-26 17:12:39 +0800 | [diff] [blame] | 701 | sscanf(optarg, "%d,%d", &specified_disp_id, &specified_mode_num); |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 702 | break; |
Thomas Wood | ff6b068 | 2014-07-31 16:26:55 +0100 | [diff] [blame] | 703 | case SUBTEST_OPTS: |
| 704 | /* invalid subtest options */ |
| 705 | exit(IGT_EXIT_INVALID); |
| 706 | break; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 707 | default: |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 708 | /* fall through */ |
| 709 | case 'h': |
| 710 | usage(argv[0]); |
| 711 | break; |
| 712 | } |
| 713 | } |
Damien Lespiau | 0396273 | 2013-09-03 14:57:31 +0100 | [diff] [blame] | 714 | |
Jesse Barnes | 7255a84 | 2014-03-26 11:02:48 -0700 | [diff] [blame] | 715 | set_termio_mode(); |
| 716 | |
Damien Lespiau | 0396273 | 2013-09-03 14:57:31 +0100 | [diff] [blame] | 717 | if (depth <= 8) |
| 718 | bpp = 8; |
| 719 | else if (depth <= 16) |
| 720 | bpp = 16; |
| 721 | else if (depth <= 32) |
| 722 | bpp = 32; |
| 723 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 724 | if (!test_all_modes && !force_mode && !test_preferred_mode && |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 725 | specified_mode_num == -1 && !test_stereo_modes) |
Paulo Zanoni | 9fe1148 | 2011-09-15 15:13:41 -0300 | [diff] [blame] | 726 | test_all_modes = 1; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 727 | |
Daniel Vetter | 0732cc5 | 2012-05-22 12:01:36 +0200 | [diff] [blame] | 728 | drm_fd = drm_open_any(); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 729 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 730 | if (test_stereo_modes && |
| 731 | drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 732 | igt_warn("DRM_CLIENT_CAP_STEREO_3D failed\n"); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 733 | goto out_close; |
| 734 | } |
| 735 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 736 | if (opt_dump_info) { |
| 737 | dump_info(); |
| 738 | goto out_close; |
| 739 | } |
| 740 | |
Daniel Vetter | 33f0884 | 2014-08-12 11:23:09 +0200 | [diff] [blame] | 741 | kmstest_set_vt_graphics_mode(); |
Imre Deak | 01b408e | 2013-05-08 19:06:44 +0300 | [diff] [blame] | 742 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 743 | mainloop = g_main_loop_new(NULL, FALSE); |
| 744 | if (!mainloop) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 745 | igt_warn("failed to create glib mainloop\n"); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 746 | ret = -1; |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 747 | goto out_close; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 750 | if (!testdisplay_setup_hotplug()) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 751 | igt_warn("failed to initialize hotplug support\n"); |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 752 | goto out_mainloop; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | stdinchannel = g_io_channel_unix_new(0); |
| 756 | if (!stdinchannel) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 757 | igt_warn("failed to create stdin GIO channel\n"); |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 758 | goto out_hotplug; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event, |
| 762 | NULL); |
| 763 | if (ret < 0) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 764 | igt_warn("failed to add watch on stdin GIO channel\n"); |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 765 | goto out_stdio; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 766 | } |
| 767 | |
Paulo Zanoni | 17cecce | 2011-09-16 18:06:27 -0300 | [diff] [blame] | 768 | ret = 0; |
| 769 | |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 770 | if (!update_display()) { |
| 771 | ret = 1; |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 772 | goto out_stdio; |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 773 | } |
| 774 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 775 | if (test_all_modes) |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 776 | goto out_stdio; |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 777 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 778 | g_main_loop_run(mainloop); |
| 779 | |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 780 | out_stdio: |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 781 | g_io_channel_shutdown(stdinchannel, TRUE, NULL); |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 782 | out_hotplug: |
| 783 | testdisplay_cleanup_hotplug(); |
| 784 | out_mainloop: |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 785 | g_main_loop_unref(mainloop); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 786 | out_close: |
Daniel Vetter | 0732cc5 | 2012-05-22 12:01:36 +0200 | [diff] [blame] | 787 | close(drm_fd); |
| 788 | |
Daniel Vetter | 4306538 | 2014-10-02 11:18:20 +0200 | [diff] [blame^] | 789 | igt_assert(ret); |
| 790 | |
| 791 | igt_exit(); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 792 | } |