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> |
| 59 | #include <sys/poll.h> |
| 60 | #include <sys/time.h> |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 61 | #include <sys/ioctl.h> |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 62 | #include <sys/types.h> |
| 63 | #include <sys/stat.h> |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 64 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 65 | #include "i915_drm.h" |
Daniel Vetter | 7a6042e | 2012-01-10 18:29:30 +0100 | [diff] [blame] | 66 | #include "drmtest.h" |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 67 | #include "testdisplay.h" |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 68 | #include "igt_kms.h" |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 69 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 70 | #include <stdlib.h> |
| 71 | #include <signal.h> |
| 72 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 73 | drmModeRes *resources; |
Daniel Vetter | 73d1b88 | 2012-01-10 18:20:39 +0100 | [diff] [blame] | 74 | int drm_fd, modes; |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 75 | int test_all_modes = 0, test_preferred_mode = 0, force_mode = 0, test_plane, |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 76 | test_stereo_modes, enable_tiling; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 77 | int sleep_between_modes = 5; |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 78 | uint32_t depth = 24, stride, bpp; |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 79 | int qr_code = 0; |
Yi Sun | 6157d24 | 2013-02-12 23:11:35 +0800 | [diff] [blame] | 80 | int specified_mode_num = -1, specified_disp_id = -1; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 81 | |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 82 | drmModeModeInfo force_timing; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 83 | |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 84 | int crtc_x, crtc_y, crtc_w, crtc_h, width, height; |
Jesse Barnes | 1f4c37a | 2011-10-28 05:25:53 +0200 | [diff] [blame] | 85 | unsigned int plane_fb_id; |
| 86 | unsigned int plane_crtc_id; |
| 87 | unsigned int plane_id; |
| 88 | int plane_width, plane_height; |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 89 | static const uint32_t SPRITE_COLOR_KEY = 0x00aaaaaa; |
Jesse Barnes | 24e6038 | 2011-10-24 17:15:34 +0200 | [diff] [blame] | 90 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 91 | /* |
| 92 | * Mode setting with the kernel interfaces is a bit of a chore. |
| 93 | * First you have to find the connector in question and make sure the |
| 94 | * requested mode is available. |
| 95 | * Then you need to find the encoder attached to that connector so you |
| 96 | * can bind it with a free crtc. |
| 97 | */ |
| 98 | struct connector { |
| 99 | uint32_t id; |
| 100 | int mode_valid; |
| 101 | drmModeModeInfo mode; |
| 102 | drmModeEncoder *encoder; |
| 103 | drmModeConnector *connector; |
| 104 | int crtc; |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 105 | int crtc_idx; |
Jesse Barnes | 9c29be4 | 2011-11-02 12:57:40 -0700 | [diff] [blame] | 106 | int pipe; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 109 | static void dump_connectors_fd(int drmfd) |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 110 | { |
| 111 | int i, j; |
| 112 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 113 | drmModeRes *mode_resources = drmModeGetResources(drmfd); |
| 114 | |
| 115 | if (!mode_resources) { |
| 116 | fprintf(stderr, "drmModeGetResources failed: %s\n", |
| 117 | strerror(errno)); |
| 118 | return; |
| 119 | } |
| 120 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 121 | printf("Connectors:\n"); |
| 122 | printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 123 | for (i = 0; i < mode_resources->count_connectors; i++) { |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 124 | drmModeConnector *connector; |
| 125 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 126 | connector = drmModeGetConnector(drmfd, mode_resources->connectors[i]); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 127 | if (!connector) { |
| 128 | fprintf(stderr, "could not get connector %i: %s\n", |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 129 | mode_resources->connectors[i], strerror(errno)); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 130 | continue; |
| 131 | } |
| 132 | |
| 133 | printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n", |
| 134 | connector->connector_id, |
| 135 | connector->encoder_id, |
Imre Deak | 3a2aed1 | 2013-05-30 22:53:53 +0300 | [diff] [blame] | 136 | kmstest_connector_status_str(connector->connection), |
| 137 | kmstest_connector_type_str(connector->connector_type), |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 138 | connector->mmWidth, connector->mmHeight, |
| 139 | connector->count_modes); |
| 140 | |
| 141 | if (!connector->count_modes) |
| 142 | continue; |
| 143 | |
| 144 | printf(" modes:\n"); |
| 145 | printf(" name refresh (Hz) hdisp hss hse htot vdisp " |
Sun Yi | 91f6097 | 2011-05-30 18:20:30 -0700 | [diff] [blame] | 146 | "vss vse vtot flags type clock\n"); |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 147 | for (j = 0; j < connector->count_modes; j++){ |
| 148 | fprintf(stdout, "[%d]", j ); |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 149 | kmstest_dump_mode(&connector->modes[j]); |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 150 | } |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 151 | |
| 152 | drmModeFreeConnector(connector); |
| 153 | } |
| 154 | printf("\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 155 | |
| 156 | drmModeFreeResources(mode_resources); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 157 | } |
| 158 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 159 | static void dump_crtcs_fd(int drmfd) |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 160 | { |
| 161 | int i; |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 162 | drmModeRes *mode_resources = drmModeGetResources(drmfd); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 163 | |
| 164 | printf("CRTCs:\n"); |
| 165 | printf("id\tfb\tpos\tsize\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 166 | for (i = 0; i < mode_resources->count_crtcs; i++) { |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 167 | drmModeCrtc *crtc; |
| 168 | |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 169 | crtc = drmModeGetCrtc(drmfd, mode_resources->crtcs[i]); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 170 | if (!crtc) { |
| 171 | fprintf(stderr, "could not get crtc %i: %s\n", |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 172 | mode_resources->crtcs[i], strerror(errno)); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 173 | continue; |
| 174 | } |
| 175 | printf("%d\t%d\t(%d,%d)\t(%dx%d)\n", |
| 176 | crtc->crtc_id, |
| 177 | crtc->buffer_id, |
| 178 | crtc->x, crtc->y, |
| 179 | crtc->width, crtc->height); |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 180 | kmstest_dump_mode(&crtc->mode); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 181 | |
| 182 | drmModeFreeCrtc(crtc); |
| 183 | } |
| 184 | printf("\n"); |
Yi Sun | 3d46ca8 | 2012-02-03 22:45:39 +0800 | [diff] [blame] | 185 | |
| 186 | drmModeFreeResources(mode_resources); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 187 | } |
| 188 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 189 | static void dump_info(void) |
| 190 | { |
| 191 | dump_connectors_fd(drm_fd); |
| 192 | dump_crtcs_fd(drm_fd); |
| 193 | } |
| 194 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 195 | static void connector_find_preferred_mode(uint32_t connector_id, |
| 196 | unsigned long crtc_idx_mask, |
| 197 | int mode_num, struct connector *c) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 198 | { |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 199 | struct kmstest_connector_config config; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 200 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 201 | if (kmstest_get_connector_config(drm_fd, connector_id, crtc_idx_mask, |
| 202 | &config) < 0) { |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 203 | c->mode_valid = 0; |
| 204 | return; |
| 205 | } |
| 206 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 207 | c->connector = config.connector; |
| 208 | c->encoder = config.encoder; |
| 209 | c->crtc = config.crtc->crtc_id; |
| 210 | c->crtc_idx = config.crtc_idx; |
| 211 | c->pipe = config.pipe; |
| 212 | |
| 213 | if (mode_num != -1) { |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 214 | igt_assert(mode_num < config.connector->count_modes); |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 215 | c->mode = config.connector->modes[mode_num]; |
| 216 | } else { |
| 217 | c->mode = config.default_mode; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 218 | } |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 219 | c->mode_valid = 1; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Jesse Barnes | 0d3043f | 2011-04-18 16:48:27 -0700 | [diff] [blame] | 222 | static void |
Damien Lespiau | b118877 | 2012-11-27 19:14:05 +0000 | [diff] [blame] | 223 | paint_color_key(struct kmstest_fb *fb_info) |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 224 | { |
| 225 | int i, j; |
Damien Lespiau | 5a1d843 | 2013-09-04 12:12:37 +0100 | [diff] [blame] | 226 | uint32_t *fb_ptr; |
| 227 | |
| 228 | fb_ptr = gem_mmap(drm_fd, fb_info->gem_handle, |
| 229 | fb_info->size, PROT_READ | PROT_WRITE); |
| 230 | igt_assert(fb_ptr); |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 231 | |
| 232 | for (i = crtc_y; i < crtc_y + crtc_h; i++) |
| 233 | for (j = crtc_x; j < crtc_x + crtc_w; j++) { |
| 234 | uint32_t offset; |
| 235 | |
Damien Lespiau | b118877 | 2012-11-27 19:14:05 +0000 | [diff] [blame] | 236 | offset = (i * fb_info->stride / 4) + j; |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 237 | fb_ptr[offset] = SPRITE_COLOR_KEY; |
| 238 | } |
Damien Lespiau | 5a1d843 | 2013-09-04 12:12:37 +0100 | [diff] [blame] | 239 | |
| 240 | munmap(fb_ptr, fb_info->size); |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 243 | static void paint_image(cairo_t *cr, const char *file) |
| 244 | { |
| 245 | int img_x, img_y, img_w, img_h, img_w_o, img_h_o; |
| 246 | double img_w_scale, img_h_scale; |
| 247 | |
| 248 | cairo_surface_t *image; |
| 249 | |
| 250 | img_y = height * (0.10 ); |
| 251 | img_h = height * 0.08 * 4; |
| 252 | img_w = img_h; |
| 253 | |
| 254 | img_x = (width / 2) - (img_w / 2); |
| 255 | |
| 256 | image = cairo_image_surface_create_from_png(file); |
| 257 | |
| 258 | img_w_o = cairo_image_surface_get_width(image); |
| 259 | img_h_o = cairo_image_surface_get_height(image); |
| 260 | |
| 261 | cairo_translate(cr, img_x, img_y); |
| 262 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 263 | img_w_scale = (double)img_w / (double)img_w_o; |
| 264 | img_h_scale = (double)img_h / (double)img_h_o; |
| 265 | cairo_scale(cr, img_w_scale, img_h_scale); |
| 266 | |
| 267 | cairo_set_source_surface(cr, image, 0, 0); |
| 268 | cairo_scale(cr, 1, 1); |
| 269 | |
| 270 | cairo_paint(cr); |
| 271 | cairo_surface_destroy(image); |
| 272 | } |
| 273 | |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 274 | static void paint_output_info(struct connector *c, struct kmstest_fb *fb) |
Jesse Barnes | 0d3043f | 2011-04-18 16:48:27 -0700 | [diff] [blame] | 275 | { |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 276 | cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb); |
| 277 | int l_width = fb->width; |
| 278 | int l_height = fb->height; |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 279 | double str_width; |
| 280 | double x, y, top_y; |
| 281 | double max_width; |
| 282 | int i; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 283 | |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 284 | kmstest_paint_test_pattern(cr, l_width, l_height); |
| 285 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 286 | cairo_select_font_face(cr, "Helvetica", |
| 287 | CAIRO_FONT_SLANT_NORMAL, |
| 288 | CAIRO_FONT_WEIGHT_NORMAL); |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 289 | cairo_move_to(cr, l_width / 2, l_height / 2); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 290 | |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 291 | /* Print connector and mode name */ |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 292 | cairo_set_font_size(cr, 48); |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 293 | kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", |
| 294 | kmstest_connector_type_str(c->connector->connector_type)); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 295 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 296 | cairo_set_font_size(cr, 36); |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 297 | str_width = kmstest_cairo_printf_line(cr, align_hcenter, 10, |
| 298 | "%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh, |
| 299 | kmstest_encoder_type_str(c->encoder->encoder_type)); |
| 300 | |
| 301 | cairo_rel_move_to(cr, -str_width / 2, 0); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 302 | |
| 303 | /* List available modes */ |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 304 | cairo_set_font_size(cr, 18); |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 305 | str_width = kmstest_cairo_printf_line(cr, align_left, 10, |
| 306 | "Available modes:"); |
| 307 | cairo_rel_move_to(cr, str_width, 0); |
| 308 | cairo_get_current_point(cr, &x, &top_y); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 309 | |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 310 | max_width = 0; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 311 | for (i = 0; i < c->connector->count_modes; i++) { |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 312 | cairo_get_current_point(cr, &x, &y); |
| 313 | if (y >= l_height) { |
| 314 | x += max_width + 10; |
| 315 | max_width = 0; |
| 316 | cairo_move_to(cr, x, top_y); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 317 | } |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 318 | str_width = kmstest_cairo_printf_line(cr, align_right, 10, |
| 319 | "%s @ %dHz", c->connector->modes[i].name, |
| 320 | c->connector->modes[i].vrefresh); |
| 321 | if (str_width > max_width) |
| 322 | max_width = str_width; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 323 | } |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 324 | |
| 325 | if (qr_code) |
Damien Lespiau | 951b37e | 2013-09-06 11:44:41 +0100 | [diff] [blame] | 326 | paint_image(cr, IGT_DATADIR"/pass.png"); |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 327 | |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 328 | igt_assert(!cairo_status(cr)); |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static void sighandler(int signo) |
| 332 | { |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | static void set_single(void) |
| 337 | { |
| 338 | int sigs[] = { SIGUSR1 }; |
| 339 | struct sigaction sa; |
| 340 | sa.sa_handler = sighandler; |
| 341 | |
| 342 | sigemptyset(&sa.sa_mask); |
| 343 | |
| 344 | if (sigaction(sigs[0], &sa, NULL) == -1) |
| 345 | perror("Could not set signal handler"); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 348 | static void |
| 349 | set_mode(struct connector *c) |
| 350 | { |
Daniel Vetter | 434be47 | 2012-07-21 17:36:36 +0200 | [diff] [blame] | 351 | unsigned int fb_id = 0; |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 352 | struct kmstest_fb fb_info[2] = { }; |
| 353 | int j, test_mode_num, current_fb = 0, old_fb = -1; |
Jesse Barnes | c56cd10 | 2011-04-19 11:50:16 -0700 | [diff] [blame] | 354 | |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 355 | test_mode_num = 1; |
| 356 | if (force_mode){ |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 357 | memcpy( &c->mode, &force_timing, sizeof(force_timing)); |
| 358 | 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] | 359 | c->mode_valid = 1; |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 360 | sprintf(c->mode.name, "%dx%d", force_timing.hdisplay, force_timing.vdisplay); |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 361 | } else if (test_all_modes) |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 362 | test_mode_num = c->connector->count_modes; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 363 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 364 | for (j = 0; j < test_mode_num; j++) { |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 365 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 366 | if (test_all_modes) |
| 367 | c->mode = c->connector->modes[j]; |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 368 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 369 | /* set_mode() only tests 2D modes */ |
Damien Lespiau | a7d1937 | 2013-09-26 17:56:01 +0100 | [diff] [blame] | 370 | if (c->mode.flags & DRM_MODE_FLAG_3D_MASK) |
| 371 | continue; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 372 | |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 373 | if (!c->mode_valid) |
| 374 | continue; |
| 375 | |
| 376 | width = c->mode.hdisplay; |
| 377 | height = c->mode.vdisplay; |
| 378 | |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 379 | fb_id = kmstest_create_fb(drm_fd, width, height, bpp, depth, |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 380 | enable_tiling, &fb_info[current_fb]); |
| 381 | paint_output_info(c, &fb_info[current_fb]); |
| 382 | paint_color_key(&fb_info[current_fb]); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 383 | |
Damien Lespiau | b9db1a6 | 2013-09-04 12:31:18 +0100 | [diff] [blame] | 384 | fprintf(stdout, "CRTC(%u):[%d]",c->crtc, j); |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 385 | kmstest_dump_mode(&c->mode); |
Daniel Vetter | 73d1b88 | 2012-01-10 18:20:39 +0100 | [diff] [blame] | 386 | if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 387 | &c->id, 1, &c->mode)) { |
| 388 | fprintf(stderr, "failed to set mode (%dx%d@%dHz): %s\n", |
| 389 | width, height, c->mode.vrefresh, |
| 390 | strerror(errno)); |
| 391 | continue; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 392 | } |
| 393 | |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 394 | if (old_fb != -1) |
| 395 | kmstest_remove_fb(drm_fd, &fb_info[old_fb]); |
| 396 | old_fb = current_fb; |
| 397 | current_fb = 1 - current_fb; |
| 398 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 399 | if (sleep_between_modes && test_all_modes && !qr_code) |
Hai Lan | dac602b | 2011-02-11 23:25:36 -0500 | [diff] [blame] | 400 | sleep(sleep_between_modes); |
Yi Sun | 1f41a30 | 2011-12-01 18:57:16 +0800 | [diff] [blame] | 401 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 402 | if (qr_code){ |
| 403 | set_single(); |
| 404 | pause(); |
| 405 | } |
Yi Sun | 1f41a30 | 2011-12-01 18:57:16 +0800 | [diff] [blame] | 406 | } |
| 407 | |
Damien Lespiau | eecd006 | 2013-09-03 19:46:19 +0100 | [diff] [blame] | 408 | if (test_all_modes) |
| 409 | kmstest_remove_fb(drm_fd, &fb_info[old_fb]); |
Chris Wilson | 5534cb1 | 2011-02-11 10:48:04 +0000 | [diff] [blame] | 410 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 411 | drmModeFreeEncoder(c->encoder); |
| 412 | drmModeFreeConnector(c->connector); |
| 413 | } |
| 414 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 415 | struct box { |
| 416 | int x, y, width, height; |
| 417 | }; |
| 418 | |
| 419 | struct stereo_fb_layout { |
| 420 | int fb_width, fb_height; |
| 421 | struct box left, right; |
| 422 | }; |
| 423 | |
| 424 | static void box_init(struct box *box, int x, int y, int bwidth, int bheight) |
| 425 | { |
| 426 | box->x = x; |
| 427 | box->y = y; |
| 428 | box->width = bwidth; |
| 429 | box->height = bheight; |
| 430 | } |
| 431 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 432 | static void stereo_fb_layout_from_mode(struct stereo_fb_layout *layout, |
| 433 | drmModeModeInfo *mode) |
| 434 | { |
Damien Lespiau | a7d1937 | 2013-09-26 17:56:01 +0100 | [diff] [blame] | 435 | unsigned int format = mode->flags & DRM_MODE_FLAG_3D_MASK; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 436 | const int hdisplay = mode->hdisplay, vdisplay = mode->vdisplay; |
| 437 | int middle; |
| 438 | |
| 439 | switch (format) { |
| 440 | case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: |
| 441 | layout->fb_width = hdisplay; |
| 442 | layout->fb_height = vdisplay; |
| 443 | |
| 444 | middle = vdisplay / 2; |
| 445 | box_init(&layout->left, 0, 0, hdisplay, middle); |
| 446 | box_init(&layout->right, |
| 447 | 0, middle, hdisplay, vdisplay - middle); |
| 448 | break; |
| 449 | case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: |
| 450 | layout->fb_width = hdisplay; |
| 451 | layout->fb_height = vdisplay; |
| 452 | |
| 453 | middle = hdisplay / 2; |
| 454 | box_init(&layout->left, 0, 0, middle, vdisplay); |
| 455 | box_init(&layout->right, |
| 456 | middle, 0, hdisplay - middle, vdisplay); |
| 457 | break; |
| 458 | case DRM_MODE_FLAG_3D_FRAME_PACKING: |
| 459 | { |
| 460 | int vactive_space = mode->vtotal - vdisplay; |
| 461 | |
| 462 | layout->fb_width = hdisplay; |
| 463 | layout->fb_height = 2 * vdisplay + vactive_space; |
| 464 | |
| 465 | box_init(&layout->left, |
| 466 | 0, 0, hdisplay, vdisplay); |
| 467 | box_init(&layout->right, |
| 468 | 0, vdisplay + vactive_space, hdisplay, vdisplay); |
| 469 | break; |
| 470 | } |
| 471 | default: |
| 472 | assert(0); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | static const char *stereo_mode_str(drmModeModeInfo *mode) |
| 477 | { |
Damien Lespiau | a7d1937 | 2013-09-26 17:56:01 +0100 | [diff] [blame] | 478 | unsigned int layout = mode->flags & DRM_MODE_FLAG_3D_MASK; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 479 | |
| 480 | switch (layout) { |
| 481 | case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: |
| 482 | return "TB"; |
| 483 | case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: |
| 484 | return "SbSH"; |
| 485 | case DRM_MODE_FLAG_3D_FRAME_PACKING: |
| 486 | return "FP"; |
| 487 | default: |
| 488 | assert(0); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | static uint32_t create_stereo_fb(drmModeModeInfo *mode, struct kmstest_fb *fb) |
| 493 | { |
| 494 | struct stereo_fb_layout layout; |
| 495 | cairo_t *cr; |
| 496 | uint32_t fb_id; |
| 497 | |
| 498 | stereo_fb_layout_from_mode(&layout, mode); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 499 | fb_id = kmstest_create_fb(drm_fd, layout.fb_width, layout.fb_height, |
| 500 | bpp, depth, enable_tiling, fb); |
| 501 | cr = kmstest_get_cairo_ctx(drm_fd, fb); |
| 502 | |
| 503 | kmstest_paint_image(cr, IGT_DATADIR"/1080p-left.png", |
| 504 | layout.left.x, layout.left.y, |
| 505 | layout.left.width, layout.left.height); |
| 506 | kmstest_paint_image(cr, IGT_DATADIR"/1080p-right.png", |
| 507 | layout.right.x, layout.right.y, |
| 508 | layout.right.width, layout.right.height); |
| 509 | |
| 510 | { |
| 511 | char buffer[64]; |
| 512 | |
| 513 | snprintf(buffer, sizeof(buffer), "%dx%d@%dHz-%s.png", |
| 514 | mode->hdisplay, |
| 515 | mode->vdisplay, |
| 516 | mode->vrefresh, |
| 517 | stereo_mode_str(mode)); |
| 518 | |
| 519 | kmstest_write_fb(drm_fd, fb, buffer); |
| 520 | } |
| 521 | |
| 522 | return fb_id; |
| 523 | } |
| 524 | |
| 525 | static void do_set_stereo_mode(struct connector *c) |
| 526 | { |
| 527 | uint32_t fb_id; |
| 528 | struct kmstest_fb fb_info; |
| 529 | |
| 530 | fb_id = create_stereo_fb(&c->mode, &fb_info); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 531 | |
| 532 | if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, |
| 533 | &c->id, 1, &c->mode)) { |
| 534 | fprintf(stderr, "failed to set mode (%dx%d@%dHz): %s\n", |
| 535 | width, height, c->mode.vrefresh, |
| 536 | strerror(errno)); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | static void |
| 541 | set_stereo_mode(struct connector *c) |
| 542 | { |
Damien Lespiau | e836b60 | 2013-09-30 17:42:33 +0100 | [diff] [blame] | 543 | int i, n; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 544 | |
Damien Lespiau | e836b60 | 2013-09-30 17:42:33 +0100 | [diff] [blame] | 545 | |
| 546 | if (specified_mode_num != -1) |
| 547 | n = 1; |
| 548 | else |
| 549 | n = c->connector->count_modes; |
| 550 | |
| 551 | for (i = 0; i < n; i++) { |
| 552 | if (specified_mode_num == -1) |
| 553 | c->mode = c->connector->modes[i]; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 554 | |
| 555 | if (!c->mode_valid) |
| 556 | continue; |
| 557 | |
Damien Lespiau | a7d1937 | 2013-09-26 17:56:01 +0100 | [diff] [blame] | 558 | if (!(c->mode.flags & DRM_MODE_FLAG_3D_MASK)) |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 559 | continue; |
| 560 | |
Damien Lespiau | 6de613f | 2013-09-30 18:03:33 +0100 | [diff] [blame] | 561 | fprintf(stdout, "CRTC(%u): [%d]", c->crtc, i); |
| 562 | kmstest_dump_mode(&c->mode); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 563 | do_set_stereo_mode(c); |
| 564 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 565 | if (qr_code) { |
| 566 | set_single(); |
| 567 | pause(); |
| 568 | } else if (sleep_between_modes) |
| 569 | sleep(sleep_between_modes); |
| 570 | } |
| 571 | |
| 572 | drmModeFreeEncoder(c->encoder); |
| 573 | drmModeFreeConnector(c->connector); |
| 574 | } |
| 575 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 576 | /* |
| 577 | * Re-probe outputs and light up as many as possible. |
| 578 | * |
| 579 | * On Intel, we have two CRTCs that we can drive independently with |
| 580 | * different timings and scanout buffers. |
| 581 | * |
| 582 | * Each connector has a corresponding encoder, except in the SDVO case |
| 583 | * where an encoder may have multiple connectors. |
| 584 | */ |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 585 | int update_display(void) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 586 | { |
| 587 | struct connector *connectors; |
| 588 | int c; |
| 589 | |
Daniel Vetter | 73d1b88 | 2012-01-10 18:20:39 +0100 | [diff] [blame] | 590 | resources = drmModeGetResources(drm_fd); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 591 | if (!resources) { |
| 592 | fprintf(stderr, "drmModeGetResources failed: %s\n", |
| 593 | strerror(errno)); |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 594 | return 0; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | connectors = calloc(resources->count_connectors, |
| 598 | sizeof(struct connector)); |
| 599 | if (!connectors) |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 600 | return 0; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 601 | |
Damien Lespiau | e836b60 | 2013-09-30 17:42:33 +0100 | [diff] [blame] | 602 | if (test_preferred_mode || test_all_modes || |
| 603 | force_mode || specified_disp_id != -1) { |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 604 | unsigned long crtc_idx_mask = -1UL; |
| 605 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 606 | /* Find any connected displays */ |
| 607 | for (c = 0; c < resources->count_connectors; c++) { |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 608 | struct connector *connector = &connectors[c]; |
| 609 | |
| 610 | connector->id = resources->connectors[c]; |
| 611 | if (specified_disp_id != -1 && |
| 612 | connector->id != specified_disp_id) |
Yi Sun | 05bfbf4 | 2012-12-26 17:12:39 +0800 | [diff] [blame] | 613 | continue; |
| 614 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 615 | connector_find_preferred_mode(connector->id, |
| 616 | crtc_idx_mask, |
| 617 | specified_mode_num, |
| 618 | connector); |
| 619 | if (!connector->mode_valid) |
| 620 | continue; |
| 621 | |
| 622 | set_mode(connector); |
| 623 | |
| 624 | if (test_preferred_mode || force_mode || |
| 625 | specified_mode_num != -1) |
| 626 | crtc_idx_mask &= ~(1 << connector->crtc_idx); |
| 627 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 628 | } |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 629 | } |
Damien Lespiau | 5d99634 | 2013-09-04 14:21:55 +0100 | [diff] [blame] | 630 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 631 | if (test_stereo_modes) { |
| 632 | for (c = 0; c < resources->count_connectors; c++) { |
| 633 | struct connector *connector = &connectors[c]; |
| 634 | |
| 635 | connector->id = resources->connectors[c]; |
Damien Lespiau | c128b73 | 2013-09-30 17:02:21 +0100 | [diff] [blame] | 636 | if (specified_disp_id != -1 && |
| 637 | connector->id != specified_disp_id) |
| 638 | continue; |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 639 | |
| 640 | connector_find_preferred_mode(connector->id, |
| 641 | -1UL, |
| 642 | specified_mode_num, |
| 643 | connector); |
| 644 | if (!connector->mode_valid) |
| 645 | continue; |
| 646 | |
| 647 | set_stereo_mode(connector); |
| 648 | } |
| 649 | } |
| 650 | |
Damien Lespiau | 5d99634 | 2013-09-04 14:21:55 +0100 | [diff] [blame] | 651 | free(connectors); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 652 | drmModeFreeResources(resources); |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 653 | return 1; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 656 | static char optstr[] = "3hiaf:s:d:p:mrto:"; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 657 | |
Ben Widawsky | 54ed938 | 2012-08-30 14:03:54 -0700 | [diff] [blame] | 658 | static void __attribute__((noreturn)) usage(char *name) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 659 | { |
Jesse Barnes | 24e6038 | 2011-10-24 17:15:34 +0200 | [diff] [blame] | 660 | fprintf(stderr, "usage: %s [-hiasdpmtf]\n", name); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 661 | fprintf(stderr, "\t-i\tdump info\n"); |
| 662 | fprintf(stderr, "\t-a\ttest all modes\n"); |
| 663 | fprintf(stderr, "\t-s\t<duration>\tsleep between each mode test\n"); |
Jesse Barnes | c56cd10 | 2011-04-19 11:50:16 -0700 | [diff] [blame] | 664 | fprintf(stderr, "\t-d\t<depth>\tbit depth of scanout buffer\n"); |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 665 | fprintf(stderr, "\t-p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n"); |
Paulo Zanoni | 9fe1148 | 2011-09-15 15:13:41 -0300 | [diff] [blame] | 666 | fprintf(stderr, "\t-m\ttest the preferred mode\n"); |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 667 | fprintf(stderr, "\t-3\ttest all 3D modes\n"); |
Jesse Barnes | b707feb | 2011-06-07 13:27:35 -0700 | [diff] [blame] | 668 | fprintf(stderr, "\t-t\tuse a tiled framebuffer\n"); |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 669 | fprintf(stderr, "\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n"); |
Yi Sun | 05bfbf4 | 2012-12-26 17:12:39 +0800 | [diff] [blame] | 670 | fprintf(stderr, "\t-o\t<id of the display>,<number of the mode>\tonly test specified mode on the specified display\n"); |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 671 | fprintf(stderr, "\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n"); |
| 672 | fprintf(stderr, "\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n"); |
| 673 | fprintf(stderr, "\t\ttest force mode\n"); |
Paulo Zanoni | 9fe1148 | 2011-09-15 15:13:41 -0300 | [diff] [blame] | 674 | fprintf(stderr, "\tDefault is to test all modes.\n"); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 675 | exit(0); |
| 676 | } |
| 677 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 678 | #define dump_resource(res) if (res) dump_##res() |
| 679 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 680 | static gboolean input_event(GIOChannel *source, GIOCondition condition, |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 681 | gpointer data) |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 682 | { |
Daniel Vetter | 74d6545 | 2011-12-18 00:24:45 +0100 | [diff] [blame] | 683 | gchar buf[2]; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 684 | gsize count; |
| 685 | |
Chris Wilson | 2803238 | 2011-02-11 10:56:41 +0000 | [diff] [blame] | 686 | count = read(g_io_channel_unix_get_fd(source), buf, sizeof(buf)); |
Jesse Barnes | 24e6038 | 2011-10-24 17:15:34 +0200 | [diff] [blame] | 687 | if (buf[0] == 'q' && (count == 1 || buf[1] == '\n')) { |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 688 | exit(0); |
Jesse Barnes | ea41633 | 2012-02-27 12:46:11 -0800 | [diff] [blame] | 689 | } |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 690 | |
| 691 | return TRUE; |
| 692 | } |
| 693 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 694 | static void enter_exec_path( char **argv ) |
| 695 | { |
| 696 | char *exec_path = NULL; |
| 697 | char *pos = NULL; |
| 698 | short len_path = 0; |
Imre Deak | 31dfc98 | 2012-10-10 16:04:45 +0300 | [diff] [blame] | 699 | int ret; |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 700 | |
| 701 | len_path = strlen( argv[0] ); |
| 702 | exec_path = (char*) malloc(len_path); |
| 703 | |
| 704 | memcpy(exec_path, argv[0], len_path); |
| 705 | pos = strrchr(exec_path, '/'); |
| 706 | if (pos != NULL) |
| 707 | *(pos+1) = '\0'; |
| 708 | |
Imre Deak | 31dfc98 | 2012-10-10 16:04:45 +0300 | [diff] [blame] | 709 | ret = chdir(exec_path); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 710 | igt_assert(ret == 0); |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 711 | free(exec_path); |
| 712 | } |
| 713 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 714 | int main(int argc, char **argv) |
| 715 | { |
| 716 | int c; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 717 | int ret = 0; |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 718 | GIOChannel *stdinchannel; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 719 | GMainLoop *mainloop; |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 720 | float force_clock; |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 721 | bool opt_dump_info = false; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 722 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 723 | igt_skip_on_simulation(); |
Damien Lespiau | 5fa15f7 | 2013-04-29 18:40:39 +0100 | [diff] [blame] | 724 | |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 725 | enter_exec_path( argv ); |
| 726 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 727 | while ((c = getopt(argc, argv, optstr)) != -1) { |
| 728 | switch (c) { |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 729 | case '3': |
| 730 | test_stereo_modes = 1; |
| 731 | break; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 732 | case 'i': |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 733 | opt_dump_info = true; |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 734 | break; |
| 735 | case 'a': |
| 736 | test_all_modes = 1; |
| 737 | break; |
| 738 | case 'f': |
| 739 | force_mode = 1; |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 740 | if(sscanf(optarg,"%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu", |
| 741 | &force_clock,&force_timing.hdisplay, &force_timing.hsync_start,&force_timing.hsync_end,&force_timing.htotal, |
| 742 | &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] | 743 | usage(argv[0]); |
Yi Sun | 4cceae7 | 2012-02-03 19:23:55 +0800 | [diff] [blame] | 744 | force_timing.clock = force_clock*1000; |
| 745 | |
Hai Lan | 62d5168 | 2011-02-11 11:14:15 -0500 | [diff] [blame] | 746 | break; |
| 747 | case 's': |
| 748 | sleep_between_modes = atoi(optarg); |
| 749 | break; |
Jesse Barnes | c56cd10 | 2011-04-19 11:50:16 -0700 | [diff] [blame] | 750 | case 'd': |
| 751 | depth = atoi(optarg); |
| 752 | fprintf(stderr, "using depth %d\n", depth); |
| 753 | break; |
Jesse Barnes | 7230c01 | 2011-06-07 13:17:46 -0700 | [diff] [blame] | 754 | case 'p': |
Jesse Barnes | 5a9d82c | 2011-12-07 08:22:41 -0800 | [diff] [blame] | 755 | if (sscanf(optarg, "%d,%d,%d,%d,%d,%d", &plane_width, |
| 756 | &plane_height, &crtc_x, &crtc_y, |
| 757 | &crtc_w, &crtc_h) != 6) |
Jesse Barnes | 24e6038 | 2011-10-24 17:15:34 +0200 | [diff] [blame] | 758 | usage(argv[0]); |
Jesse Barnes | 7230c01 | 2011-06-07 13:17:46 -0700 | [diff] [blame] | 759 | test_plane = 1; |
| 760 | break; |
Paulo Zanoni | 9fe1148 | 2011-09-15 15:13:41 -0300 | [diff] [blame] | 761 | case 'm': |
| 762 | test_preferred_mode = 1; |
| 763 | break; |
Jesse Barnes | b707feb | 2011-06-07 13:27:35 -0700 | [diff] [blame] | 764 | case 't': |
| 765 | enable_tiling = 1; |
| 766 | break; |
Yi Sun | 41fe811 | 2012-07-26 14:23:36 +0800 | [diff] [blame] | 767 | case 'r': |
| 768 | qr_code = 1; |
| 769 | break; |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 770 | case 'o': |
Yi Sun | 05bfbf4 | 2012-12-26 17:12:39 +0800 | [diff] [blame] | 771 | sscanf(optarg, "%d,%d", &specified_disp_id, &specified_mode_num); |
Yi Sun | 53895ac | 2012-09-25 17:13:17 +0800 | [diff] [blame] | 772 | break; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 773 | default: |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 774 | /* fall through */ |
| 775 | case 'h': |
| 776 | usage(argv[0]); |
| 777 | break; |
| 778 | } |
| 779 | } |
Damien Lespiau | 0396273 | 2013-09-03 14:57:31 +0100 | [diff] [blame] | 780 | |
| 781 | if (depth <= 8) |
| 782 | bpp = 8; |
| 783 | else if (depth <= 16) |
| 784 | bpp = 16; |
| 785 | else if (depth <= 32) |
| 786 | bpp = 32; |
| 787 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 788 | if (!test_all_modes && !force_mode && !test_preferred_mode && |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 789 | specified_mode_num == -1 && !test_stereo_modes) |
Paulo Zanoni | 9fe1148 | 2011-09-15 15:13:41 -0300 | [diff] [blame] | 790 | test_all_modes = 1; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 791 | |
Daniel Vetter | 0732cc5 | 2012-05-22 12:01:36 +0200 | [diff] [blame] | 792 | drm_fd = drm_open_any(); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 793 | |
Damien Lespiau | 9a8fda7 | 2012-09-10 13:33:26 +0100 | [diff] [blame] | 794 | if (test_stereo_modes && |
| 795 | drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) { |
| 796 | fprintf(stderr, "DRM_CLIENT_CAP_STEREO_3D failed\n"); |
| 797 | goto out_close; |
| 798 | } |
| 799 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 800 | if (opt_dump_info) { |
| 801 | dump_info(); |
| 802 | goto out_close; |
| 803 | } |
| 804 | |
Daniel Vetter | 1f0cf2d | 2013-10-31 17:02:41 +0100 | [diff] [blame] | 805 | igt_set_vt_graphics_mode(); |
Imre Deak | 01b408e | 2013-05-08 19:06:44 +0300 | [diff] [blame] | 806 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 807 | mainloop = g_main_loop_new(NULL, FALSE); |
| 808 | if (!mainloop) { |
| 809 | fprintf(stderr, "failed to create glib mainloop\n"); |
| 810 | ret = -1; |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 811 | goto out_close; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 812 | } |
| 813 | |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 814 | if (!testdisplay_setup_hotplug()) { |
| 815 | fprintf(stderr, "failed to initialize hotplug support\n"); |
| 816 | goto out_mainloop; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | stdinchannel = g_io_channel_unix_new(0); |
| 820 | if (!stdinchannel) { |
| 821 | fprintf(stderr, "failed to create stdin GIO channel\n"); |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 822 | goto out_hotplug; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event, |
| 826 | NULL); |
| 827 | if (ret < 0) { |
| 828 | fprintf(stderr, "failed to add watch on stdin GIO channel\n"); |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 829 | goto out_stdio; |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 830 | } |
| 831 | |
Paulo Zanoni | 17cecce | 2011-09-16 18:06:27 -0300 | [diff] [blame] | 832 | ret = 0; |
| 833 | |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 834 | if (!update_display()) { |
| 835 | ret = 1; |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 836 | goto out_stdio; |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 837 | } |
| 838 | |
Damien Lespiau | 66477a2 | 2013-09-05 16:49:11 +0100 | [diff] [blame] | 839 | if (test_all_modes) |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 840 | goto out_stdio; |
Paulo Zanoni | 7ead7ba | 2011-09-15 15:14:18 -0300 | [diff] [blame] | 841 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 842 | g_main_loop_run(mainloop); |
| 843 | |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 844 | out_stdio: |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 845 | g_io_channel_shutdown(stdinchannel, TRUE, NULL); |
Daniel Vetter | 7f7cafe | 2012-01-24 10:50:05 +0100 | [diff] [blame] | 846 | out_hotplug: |
| 847 | testdisplay_cleanup_hotplug(); |
| 848 | out_mainloop: |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 849 | g_main_loop_unref(mainloop); |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 850 | out_close: |
Daniel Vetter | 0732cc5 | 2012-05-22 12:01:36 +0200 | [diff] [blame] | 851 | close(drm_fd); |
| 852 | |
Jesse Barnes | 5406c63 | 2010-12-21 09:38:23 -0800 | [diff] [blame] | 853 | return ret; |
| 854 | } |