blob: f60e66d5089b98ca68dd6a710e35e2c467972282 [file] [log] [blame]
Jesse Barnes5406c632010-12-21 09:38:23 -08001/*
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 Lespiau7ee278f2013-02-20 14:40:07 +000048#ifdef HAVE_CONFIG_H
Jesse Barnes5406c632010-12-21 09:38:23 -080049#include "config.h"
Damien Lespiau7ee278f2013-02-20 14:40:07 +000050#endif
Jesse Barnes5406c632010-12-21 09:38:23 -080051
Jesse Barnes5406c632010-12-21 09:38:23 -080052#include <cairo.h>
53#include <errno.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080054#include <math.h>
55#include <stdint.h>
Damien Lespiau66477a22013-09-05 16:49:11 +010056#include <stdbool.h>
Damien Lespiau9a8fda72012-09-10 13:33:26 +010057#include <strings.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080058#include <unistd.h>
Jesse Barnes7255a842014-03-26 11:02:48 -070059#include <termios.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080060#include <sys/poll.h>
61#include <sys/time.h>
Chris Wilson5534cb12011-02-11 10:48:04 +000062#include <sys/ioctl.h>
Damien Lespiau9a8fda72012-09-10 13:33:26 +010063#include <sys/types.h>
64#include <sys/stat.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080065
Daniel Vettere49ceb82014-03-22 21:07:37 +010066#include "ioctl_wrappers.h"
Daniel Vetter7a6042e2012-01-10 18:29:30 +010067#include "drmtest.h"
Daniel Vetter7f7cafe2012-01-24 10:50:05 +010068#include "testdisplay.h"
Oscar Mateo37f26d12013-11-12 11:50:38 +000069#include "igt_kms.h"
Jesse Barnes5406c632010-12-21 09:38:23 -080070
Yi Sun41fe8112012-07-26 14:23:36 +080071#include <stdlib.h>
72#include <signal.h>
73
Imre Deak63746412014-05-12 13:29:49 +030074static int tio_fd;
Jesse Barnes7255a842014-03-26 11:02:48 -070075struct termios saved_tio;
76
Jesse Barnes5406c632010-12-21 09:38:23 -080077drmModeRes *resources;
Daniel Vetter73d1b882012-01-10 18:20:39 +010078int drm_fd, modes;
Damien Lespiau66477a22013-09-05 16:49:11 +010079int test_all_modes = 0, test_preferred_mode = 0, force_mode = 0, test_plane,
Damien Lespiau9a8fda72012-09-10 13:33:26 +010080 test_stereo_modes, enable_tiling;
Hai Lan62d51682011-02-11 11:14:15 -050081int sleep_between_modes = 5;
Daniel Vettercef9b312014-02-13 19:22:35 +010082int do_dpms = 0; /* This aliases to DPMS_ON */
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080083uint32_t depth = 24, stride, bpp;
Yi Sun41fe8112012-07-26 14:23:36 +080084int qr_code = 0;
Yi Sun6157d242013-02-12 23:11:35 +080085int specified_mode_num = -1, specified_disp_id = -1;
Hai Lan62d51682011-02-11 11:14:15 -050086
Yi Sun4cceae72012-02-03 19:23:55 +080087drmModeModeInfo force_timing;
Jesse Barnes5406c632010-12-21 09:38:23 -080088
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080089int crtc_x, crtc_y, crtc_w, crtc_h, width, height;
Jesse Barnes1f4c37a2011-10-28 05:25:53 +020090unsigned int plane_fb_id;
91unsigned int plane_crtc_id;
92unsigned int plane_id;
93int plane_width, plane_height;
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080094static const uint32_t SPRITE_COLOR_KEY = 0x00aaaaaa;
Jesse Barnes24e60382011-10-24 17:15:34 +020095
Jesse Barnes5406c632010-12-21 09:38:23 -080096/*
97 * Mode setting with the kernel interfaces is a bit of a chore.
98 * First you have to find the connector in question and make sure the
99 * requested mode is available.
100 * Then you need to find the encoder attached to that connector so you
101 * can bind it with a free crtc.
102 */
103struct connector {
104 uint32_t id;
105 int mode_valid;
106 drmModeModeInfo mode;
107 drmModeEncoder *encoder;
108 drmModeConnector *connector;
109 int crtc;
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300110 int crtc_idx;
Jesse Barnes9c29be42011-11-02 12:57:40 -0700111 int pipe;
Jesse Barnes5406c632010-12-21 09:38:23 -0800112};
113
Yi Sun3d46ca82012-02-03 22:45:39 +0800114static void dump_connectors_fd(int drmfd)
Hai Lan62d51682011-02-11 11:14:15 -0500115{
116 int i, j;
117
Yi Sun3d46ca82012-02-03 22:45:39 +0800118 drmModeRes *mode_resources = drmModeGetResources(drmfd);
119
120 if (!mode_resources) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200121 igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
Yi Sun3d46ca82012-02-03 22:45:39 +0800122 return;
123 }
124
Daniel Vetterc9c55452014-06-13 18:27:59 +0200125 igt_info("Connectors:\n");
126 igt_info("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800127 for (i = 0; i < mode_resources->count_connectors; i++) {
Hai Lan62d51682011-02-11 11:14:15 -0500128 drmModeConnector *connector;
129
Yi Sun3d46ca82012-02-03 22:45:39 +0800130 connector = drmModeGetConnector(drmfd, mode_resources->connectors[i]);
Hai Lan62d51682011-02-11 11:14:15 -0500131 if (!connector) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200132 igt_warn("could not get connector %i: %s\n", mode_resources->connectors[i], strerror(errno));
Hai Lan62d51682011-02-11 11:14:15 -0500133 continue;
134 }
135
Daniel Vetterc9c55452014-06-13 18:27:59 +0200136 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 Lan62d51682011-02-11 11:14:15 -0500137
138 if (!connector->count_modes)
139 continue;
140
Daniel Vetterc9c55452014-06-13 18:27:59 +0200141 igt_info(" modes:\n");
142 igt_info(" name refresh (Hz) hdisp hss hse htot vdisp ""vss vse vtot flags type clock\n");
Yi Sun53895ac2012-09-25 17:13:17 +0800143 for (j = 0; j < connector->count_modes; j++){
Daniel Vetterc9c55452014-06-13 18:27:59 +0200144 igt_info("[%d]", j);
Daniel Vetter17787f32012-05-22 16:15:15 +0200145 kmstest_dump_mode(&connector->modes[j]);
Yi Sun53895ac2012-09-25 17:13:17 +0800146 }
Hai Lan62d51682011-02-11 11:14:15 -0500147
148 drmModeFreeConnector(connector);
149 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200150 igt_info("\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800151
152 drmModeFreeResources(mode_resources);
Hai Lan62d51682011-02-11 11:14:15 -0500153}
154
Yi Sun3d46ca82012-02-03 22:45:39 +0800155static void dump_crtcs_fd(int drmfd)
Hai Lan62d51682011-02-11 11:14:15 -0500156{
157 int i;
Yi Sun3d46ca82012-02-03 22:45:39 +0800158 drmModeRes *mode_resources = drmModeGetResources(drmfd);
Hai Lan62d51682011-02-11 11:14:15 -0500159
Daniel Vetterc9c55452014-06-13 18:27:59 +0200160 igt_info("CRTCs:\n");
161 igt_info("id\tfb\tpos\tsize\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800162 for (i = 0; i < mode_resources->count_crtcs; i++) {
Hai Lan62d51682011-02-11 11:14:15 -0500163 drmModeCrtc *crtc;
164
Yi Sun3d46ca82012-02-03 22:45:39 +0800165 crtc = drmModeGetCrtc(drmfd, mode_resources->crtcs[i]);
Hai Lan62d51682011-02-11 11:14:15 -0500166 if (!crtc) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200167 igt_warn("could not get crtc %i: %s\n", mode_resources->crtcs[i], strerror(errno));
Hai Lan62d51682011-02-11 11:14:15 -0500168 continue;
169 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200170 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 Vetter17787f32012-05-22 16:15:15 +0200171 kmstest_dump_mode(&crtc->mode);
Hai Lan62d51682011-02-11 11:14:15 -0500172
173 drmModeFreeCrtc(crtc);
174 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200175 igt_info("\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800176
177 drmModeFreeResources(mode_resources);
Hai Lan62d51682011-02-11 11:14:15 -0500178}
179
Damien Lespiau66477a22013-09-05 16:49:11 +0100180static void dump_info(void)
181{
182 dump_connectors_fd(drm_fd);
183 dump_crtcs_fd(drm_fd);
184}
185
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300186static void connector_find_preferred_mode(uint32_t connector_id,
187 unsigned long crtc_idx_mask,
188 int mode_num, struct connector *c)
Jesse Barnes5406c632010-12-21 09:38:23 -0800189{
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300190 struct kmstest_connector_config config;
Jesse Barnes5406c632010-12-21 09:38:23 -0800191
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300192 if (kmstest_get_connector_config(drm_fd, connector_id, crtc_idx_mask,
193 &config) < 0) {
Jesse Barnes5406c632010-12-21 09:38:23 -0800194 c->mode_valid = 0;
195 return;
196 }
197
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300198 c->connector = config.connector;
199 c->encoder = config.encoder;
200 c->crtc = config.crtc->crtc_id;
201 c->crtc_idx = config.crtc_idx;
202 c->pipe = config.pipe;
203
204 if (mode_num != -1) {
Daniel Vetter83440952013-08-13 12:35:58 +0200205 igt_assert(mode_num < config.connector->count_modes);
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300206 c->mode = config.connector->modes[mode_num];
207 } else {
208 c->mode = config.default_mode;
Jesse Barnes5406c632010-12-21 09:38:23 -0800209 }
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300210 c->mode_valid = 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800211}
212
Jesse Barnes0d3043f2011-04-18 16:48:27 -0700213static void
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100214paint_color_key(struct igt_fb *fb_info)
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800215{
216 int i, j;
Damien Lespiau5a1d8432013-09-04 12:12:37 +0100217 uint32_t *fb_ptr;
218
219 fb_ptr = gem_mmap(drm_fd, fb_info->gem_handle,
220 fb_info->size, PROT_READ | PROT_WRITE);
221 igt_assert(fb_ptr);
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800222
223 for (i = crtc_y; i < crtc_y + crtc_h; i++)
224 for (j = crtc_x; j < crtc_x + crtc_w; j++) {
225 uint32_t offset;
226
Damien Lespiaub1188772012-11-27 19:14:05 +0000227 offset = (i * fb_info->stride / 4) + j;
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800228 fb_ptr[offset] = SPRITE_COLOR_KEY;
229 }
Damien Lespiau5a1d8432013-09-04 12:12:37 +0100230
231 munmap(fb_ptr, fb_info->size);
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800232}
233
Yi Sun41fe8112012-07-26 14:23:36 +0800234static void paint_image(cairo_t *cr, const char *file)
235{
236 int img_x, img_y, img_w, img_h, img_w_o, img_h_o;
237 double img_w_scale, img_h_scale;
238
239 cairo_surface_t *image;
240
241 img_y = height * (0.10 );
242 img_h = height * 0.08 * 4;
243 img_w = img_h;
244
245 img_x = (width / 2) - (img_w / 2);
246
247 image = cairo_image_surface_create_from_png(file);
248
249 img_w_o = cairo_image_surface_get_width(image);
250 img_h_o = cairo_image_surface_get_height(image);
251
252 cairo_translate(cr, img_x, img_y);
253
Yi Sun41fe8112012-07-26 14:23:36 +0800254 img_w_scale = (double)img_w / (double)img_w_o;
255 img_h_scale = (double)img_h / (double)img_h_o;
256 cairo_scale(cr, img_w_scale, img_h_scale);
257
258 cairo_set_source_surface(cr, image, 0, 0);
259 cairo_scale(cr, 1, 1);
260
261 cairo_paint(cr);
262 cairo_surface_destroy(image);
263}
264
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100265static void paint_output_info(struct connector *c, struct igt_fb *fb)
Jesse Barnes0d3043f2011-04-18 16:48:27 -0700266{
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100267 cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb);
Imre Deakf68d9642013-05-24 17:26:54 +0300268 int l_width = fb->width;
269 int l_height = fb->height;
Imre Deak542a40c2013-05-30 15:03:48 +0300270 double str_width;
271 double x, y, top_y;
272 double max_width;
273 int i;
Jesse Barnes5406c632010-12-21 09:38:23 -0800274
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100275 igt_paint_test_pattern(cr, l_width, l_height);
Imre Deakf68d9642013-05-24 17:26:54 +0300276
Imre Deak542a40c2013-05-30 15:03:48 +0300277 cairo_move_to(cr, l_width / 2, l_height / 2);
Jesse Barnes5406c632010-12-21 09:38:23 -0800278
Imre Deak542a40c2013-05-30 15:03:48 +0300279 /* Print connector and mode name */
Jesse Barnes5406c632010-12-21 09:38:23 -0800280 cairo_set_font_size(cr, 48);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100281 igt_cairo_printf_line(cr, align_hcenter, 10, "%s",
Imre Deak542a40c2013-05-30 15:03:48 +0300282 kmstest_connector_type_str(c->connector->connector_type));
Jesse Barnes5406c632010-12-21 09:38:23 -0800283
Jesse Barnes5406c632010-12-21 09:38:23 -0800284 cairo_set_font_size(cr, 36);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100285 str_width = igt_cairo_printf_line(cr, align_hcenter, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300286 "%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh,
287 kmstest_encoder_type_str(c->encoder->encoder_type));
288
289 cairo_rel_move_to(cr, -str_width / 2, 0);
Jesse Barnes5406c632010-12-21 09:38:23 -0800290
291 /* List available modes */
Jesse Barnes5406c632010-12-21 09:38:23 -0800292 cairo_set_font_size(cr, 18);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100293 str_width = igt_cairo_printf_line(cr, align_left, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300294 "Available modes:");
295 cairo_rel_move_to(cr, str_width, 0);
296 cairo_get_current_point(cr, &x, &top_y);
Jesse Barnes5406c632010-12-21 09:38:23 -0800297
Imre Deak542a40c2013-05-30 15:03:48 +0300298 max_width = 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800299 for (i = 0; i < c->connector->count_modes; i++) {
Imre Deak542a40c2013-05-30 15:03:48 +0300300 cairo_get_current_point(cr, &x, &y);
301 if (y >= l_height) {
302 x += max_width + 10;
303 max_width = 0;
304 cairo_move_to(cr, x, top_y);
Jesse Barnes5406c632010-12-21 09:38:23 -0800305 }
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100306 str_width = igt_cairo_printf_line(cr, align_right, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300307 "%s @ %dHz", c->connector->modes[i].name,
308 c->connector->modes[i].vrefresh);
309 if (str_width > max_width)
310 max_width = str_width;
Jesse Barnes5406c632010-12-21 09:38:23 -0800311 }
Yi Sun41fe8112012-07-26 14:23:36 +0800312
313 if (qr_code)
Damien Lespiau951b37e2013-09-06 11:44:41 +0100314 paint_image(cr, IGT_DATADIR"/pass.png");
Imre Deakf68d9642013-05-24 17:26:54 +0300315
Daniel Vetter83440952013-08-13 12:35:58 +0200316 igt_assert(!cairo_status(cr));
Yi Sun41fe8112012-07-26 14:23:36 +0800317}
318
319static void sighandler(int signo)
320{
321 return;
322}
323
324static void set_single(void)
325{
326 int sigs[] = { SIGUSR1 };
327 struct sigaction sa;
328 sa.sa_handler = sighandler;
329
330 sigemptyset(&sa.sa_mask);
331
Daniel Vetterc9c55452014-06-13 18:27:59 +0200332 igt_warn_on_f(sigaction(sigs[0], &sa, NULL) == -1,
333 "Could not set signal handler");
Jesse Barnes5406c632010-12-21 09:38:23 -0800334}
335
Jesse Barnes5406c632010-12-21 09:38:23 -0800336static void
337set_mode(struct connector *c)
338{
Daniel Vetter434be472012-07-21 17:36:36 +0200339 unsigned int fb_id = 0;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100340 struct igt_fb fb_info[2] = { };
Damien Lespiaueecd0062013-09-03 19:46:19 +0100341 int j, test_mode_num, current_fb = 0, old_fb = -1;
Jesse Barnesc56cd102011-04-19 11:50:16 -0700342
Chris Wilson5534cb12011-02-11 10:48:04 +0000343 test_mode_num = 1;
344 if (force_mode){
Yi Sun4cceae72012-02-03 19:23:55 +0800345 memcpy( &c->mode, &force_timing, sizeof(force_timing));
346 c->mode.vrefresh =(force_timing.clock*1e3)/(force_timing.htotal*force_timing.vtotal);
Chris Wilson5534cb12011-02-11 10:48:04 +0000347 c->mode_valid = 1;
Yi Sun4cceae72012-02-03 19:23:55 +0800348 sprintf(c->mode.name, "%dx%d", force_timing.hdisplay, force_timing.vdisplay);
Chris Wilson5534cb12011-02-11 10:48:04 +0000349 } else if (test_all_modes)
Hai Lan62d51682011-02-11 11:14:15 -0500350 test_mode_num = c->connector->count_modes;
Jesse Barnes5406c632010-12-21 09:38:23 -0800351
Hai Lan62d51682011-02-11 11:14:15 -0500352 for (j = 0; j < test_mode_num; j++) {
Chris Wilson5534cb12011-02-11 10:48:04 +0000353
Hai Lan62d51682011-02-11 11:14:15 -0500354 if (test_all_modes)
355 c->mode = c->connector->modes[j];
Chris Wilson5534cb12011-02-11 10:48:04 +0000356
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100357 /* set_mode() only tests 2D modes */
Damien Lespiaua7d19372013-09-26 17:56:01 +0100358 if (c->mode.flags & DRM_MODE_FLAG_3D_MASK)
359 continue;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100360
Chris Wilson5534cb12011-02-11 10:48:04 +0000361 if (!c->mode_valid)
362 continue;
363
364 width = c->mode.hdisplay;
365 height = c->mode.vdisplay;
366
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100367 fb_id = igt_create_fb(drm_fd, width, height,
368 igt_bpp_depth_to_drm_format(bpp, depth),
Damien Lespiaueecd0062013-09-03 19:46:19 +0100369 enable_tiling, &fb_info[current_fb]);
370 paint_output_info(c, &fb_info[current_fb]);
371 paint_color_key(&fb_info[current_fb]);
Hai Lan62d51682011-02-11 11:14:15 -0500372
Daniel Vetterc9c55452014-06-13 18:27:59 +0200373 igt_info("CRTC(%u):[%d]", c->crtc, j);
Daniel Vetter17787f32012-05-22 16:15:15 +0200374 kmstest_dump_mode(&c->mode);
Daniel Vetter73d1b882012-01-10 18:20:39 +0100375 if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0,
Chris Wilson5534cb12011-02-11 10:48:04 +0000376 &c->id, 1, &c->mode)) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200377 igt_warn("failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));
Chris Wilson5534cb12011-02-11 10:48:04 +0000378 continue;
Hai Lan62d51682011-02-11 11:14:15 -0500379 }
380
Damien Lespiaueecd0062013-09-03 19:46:19 +0100381 if (old_fb != -1)
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100382 igt_remove_fb(drm_fd, &fb_info[old_fb]);
Damien Lespiaueecd0062013-09-03 19:46:19 +0100383 old_fb = current_fb;
384 current_fb = 1 - current_fb;
385
Yi Sun41fe8112012-07-26 14:23:36 +0800386 if (sleep_between_modes && test_all_modes && !qr_code)
Hai Landac602b2011-02-11 23:25:36 -0500387 sleep(sleep_between_modes);
Yi Sun1f41a302011-12-01 18:57:16 +0800388
Daniel Vetter30cfde52014-02-13 19:15:38 +0100389 if (do_dpms) {
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200390 kmstest_set_connector_dpms(drm_fd, c->connector, do_dpms);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100391 sleep(sleep_between_modes);
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200392 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100393 }
394
Yi Sun41fe8112012-07-26 14:23:36 +0800395 if (qr_code){
396 set_single();
397 pause();
398 }
Yi Sun1f41a302011-12-01 18:57:16 +0800399 }
400
Damien Lespiaueecd0062013-09-03 19:46:19 +0100401 if (test_all_modes)
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100402 igt_remove_fb(drm_fd, &fb_info[old_fb]);
Chris Wilson5534cb12011-02-11 10:48:04 +0000403
Jesse Barnes5406c632010-12-21 09:38:23 -0800404 drmModeFreeEncoder(c->encoder);
405 drmModeFreeConnector(c->connector);
406}
407
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100408struct box {
409 int x, y, width, height;
410};
411
412struct stereo_fb_layout {
413 int fb_width, fb_height;
414 struct box left, right;
415};
416
417static void box_init(struct box *box, int x, int y, int bwidth, int bheight)
418{
419 box->x = x;
420 box->y = y;
421 box->width = bwidth;
422 box->height = bheight;
423}
424
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100425static void stereo_fb_layout_from_mode(struct stereo_fb_layout *layout,
426 drmModeModeInfo *mode)
427{
Damien Lespiaua7d19372013-09-26 17:56:01 +0100428 unsigned int format = mode->flags & DRM_MODE_FLAG_3D_MASK;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100429 const int hdisplay = mode->hdisplay, vdisplay = mode->vdisplay;
430 int middle;
431
432 switch (format) {
433 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
434 layout->fb_width = hdisplay;
435 layout->fb_height = vdisplay;
436
437 middle = vdisplay / 2;
438 box_init(&layout->left, 0, 0, hdisplay, middle);
439 box_init(&layout->right,
440 0, middle, hdisplay, vdisplay - middle);
441 break;
442 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
443 layout->fb_width = hdisplay;
444 layout->fb_height = vdisplay;
445
446 middle = hdisplay / 2;
447 box_init(&layout->left, 0, 0, middle, vdisplay);
448 box_init(&layout->right,
449 middle, 0, hdisplay - middle, vdisplay);
450 break;
451 case DRM_MODE_FLAG_3D_FRAME_PACKING:
452 {
453 int vactive_space = mode->vtotal - vdisplay;
454
455 layout->fb_width = hdisplay;
456 layout->fb_height = 2 * vdisplay + vactive_space;
457
458 box_init(&layout->left,
459 0, 0, hdisplay, vdisplay);
460 box_init(&layout->right,
461 0, vdisplay + vactive_space, hdisplay, vdisplay);
462 break;
463 }
464 default:
Daniel Vetter0e22f142014-03-22 19:27:04 +0100465 igt_assert(0);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100466 }
467}
468
469static const char *stereo_mode_str(drmModeModeInfo *mode)
470{
Damien Lespiaua7d19372013-09-26 17:56:01 +0100471 unsigned int layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100472
473 switch (layout) {
474 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
475 return "TB";
476 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
477 return "SbSH";
478 case DRM_MODE_FLAG_3D_FRAME_PACKING:
479 return "FP";
480 default:
Daniel Vetter0e22f142014-03-22 19:27:04 +0100481 igt_assert(0);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100482 }
483}
484
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100485static uint32_t create_stereo_fb(drmModeModeInfo *mode, struct igt_fb *fb)
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100486{
487 struct stereo_fb_layout layout;
488 cairo_t *cr;
489 uint32_t fb_id;
490
491 stereo_fb_layout_from_mode(&layout, mode);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100492 fb_id = igt_create_fb(drm_fd, layout.fb_width, layout.fb_height,
493 igt_bpp_depth_to_drm_format(bpp, depth),
Daniel Vetter70182162014-03-23 16:36:40 +0100494 enable_tiling, fb);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100495 cr = igt_get_cairo_ctx(drm_fd, fb);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100496
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100497 igt_paint_image(cr, IGT_DATADIR"/1080p-left.png",
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100498 layout.left.x, layout.left.y,
499 layout.left.width, layout.left.height);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100500 igt_paint_image(cr, IGT_DATADIR"/1080p-right.png",
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100501 layout.right.x, layout.right.y,
502 layout.right.width, layout.right.height);
503
Chris Wilson164d9d22013-12-30 17:48:43 +0000504 cairo_destroy(cr);
505
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100506 {
507 char buffer[64];
508
509 snprintf(buffer, sizeof(buffer), "%dx%d@%dHz-%s.png",
510 mode->hdisplay,
511 mode->vdisplay,
512 mode->vrefresh,
513 stereo_mode_str(mode));
514
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100515 igt_write_fb_to_png(drm_fd, fb, buffer);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100516 }
517
518 return fb_id;
519}
520
521static void do_set_stereo_mode(struct connector *c)
522{
523 uint32_t fb_id;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100524 struct igt_fb fb_info;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100525
526 fb_id = create_stereo_fb(&c->mode, &fb_info);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100527
Daniel Vetterc9c55452014-06-13 18:27:59 +0200528 igt_warn_on_f(drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, &c->id, 1, &c->mode),
529 "failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100530}
531
532static void
533set_stereo_mode(struct connector *c)
534{
Damien Lespiaue836b602013-09-30 17:42:33 +0100535 int i, n;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100536
Damien Lespiaue836b602013-09-30 17:42:33 +0100537
538 if (specified_mode_num != -1)
539 n = 1;
540 else
541 n = c->connector->count_modes;
542
543 for (i = 0; i < n; i++) {
544 if (specified_mode_num == -1)
545 c->mode = c->connector->modes[i];
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100546
547 if (!c->mode_valid)
548 continue;
549
Damien Lespiaua7d19372013-09-26 17:56:01 +0100550 if (!(c->mode.flags & DRM_MODE_FLAG_3D_MASK))
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100551 continue;
552
Daniel Vetterc9c55452014-06-13 18:27:59 +0200553 igt_info("CRTC(%u): [%d]", c->crtc, i);
Damien Lespiau6de613f2013-09-30 18:03:33 +0100554 kmstest_dump_mode(&c->mode);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100555 do_set_stereo_mode(c);
556
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100557 if (qr_code) {
558 set_single();
559 pause();
560 } else if (sleep_between_modes)
561 sleep(sleep_between_modes);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100562
563 if (do_dpms) {
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200564 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_OFF);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100565 sleep(sleep_between_modes);
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200566 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100567 }
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100568 }
569
570 drmModeFreeEncoder(c->encoder);
571 drmModeFreeConnector(c->connector);
572}
573
Jesse Barnes5406c632010-12-21 09:38:23 -0800574/*
575 * Re-probe outputs and light up as many as possible.
576 *
577 * On Intel, we have two CRTCs that we can drive independently with
578 * different timings and scanout buffers.
579 *
580 * Each connector has a corresponding encoder, except in the SDVO case
581 * where an encoder may have multiple connectors.
582 */
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100583int update_display(void)
Jesse Barnes5406c632010-12-21 09:38:23 -0800584{
585 struct connector *connectors;
586 int c;
587
Daniel Vetter73d1b882012-01-10 18:20:39 +0100588 resources = drmModeGetResources(drm_fd);
Jesse Barnes5406c632010-12-21 09:38:23 -0800589 if (!resources) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200590 igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300591 return 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800592 }
593
594 connectors = calloc(resources->count_connectors,
595 sizeof(struct connector));
596 if (!connectors)
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300597 return 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800598
Damien Lespiaue836b602013-09-30 17:42:33 +0100599 if (test_preferred_mode || test_all_modes ||
600 force_mode || specified_disp_id != -1) {
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300601 unsigned long crtc_idx_mask = -1UL;
602
Hai Lan62d51682011-02-11 11:14:15 -0500603 /* Find any connected displays */
604 for (c = 0; c < resources->count_connectors; c++) {
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300605 struct connector *connector = &connectors[c];
606
607 connector->id = resources->connectors[c];
608 if (specified_disp_id != -1 &&
609 connector->id != specified_disp_id)
Yi Sun05bfbf42012-12-26 17:12:39 +0800610 continue;
611
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300612 connector_find_preferred_mode(connector->id,
613 crtc_idx_mask,
614 specified_mode_num,
615 connector);
616 if (!connector->mode_valid)
617 continue;
618
619 set_mode(connector);
620
621 if (test_preferred_mode || force_mode ||
622 specified_mode_num != -1)
623 crtc_idx_mask &= ~(1 << connector->crtc_idx);
624
Hai Lan62d51682011-02-11 11:14:15 -0500625 }
Jesse Barnes5406c632010-12-21 09:38:23 -0800626 }
Damien Lespiau5d996342013-09-04 14:21:55 +0100627
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100628 if (test_stereo_modes) {
629 for (c = 0; c < resources->count_connectors; c++) {
630 struct connector *connector = &connectors[c];
631
632 connector->id = resources->connectors[c];
Damien Lespiauc128b732013-09-30 17:02:21 +0100633 if (specified_disp_id != -1 &&
634 connector->id != specified_disp_id)
635 continue;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100636
637 connector_find_preferred_mode(connector->id,
638 -1UL,
639 specified_mode_num,
640 connector);
641 if (!connector->mode_valid)
642 continue;
643
644 set_stereo_mode(connector);
645 }
646 }
647
Damien Lespiau5d996342013-09-04 14:21:55 +0100648 free(connectors);
Jesse Barnes5406c632010-12-21 09:38:23 -0800649 drmModeFreeResources(resources);
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300650 return 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800651}
652
Daniel Vettercef9b312014-02-13 19:22:35 +0100653static char optstr[] = "3hiaf:s:d:p:mrto:j:";
Jesse Barnes5406c632010-12-21 09:38:23 -0800654
Ben Widawsky54ed9382012-08-30 14:03:54 -0700655static void __attribute__((noreturn)) usage(char *name)
Jesse Barnes5406c632010-12-21 09:38:23 -0800656{
Daniel Vetterc9c55452014-06-13 18:27:59 +0200657 igt_info("usage: %s [-hiasdpmtf]\n", name);
658 igt_info("\t-i\tdump info\n");
659 igt_info("\t-a\ttest all modes\n");
660 igt_info("\t-s\t<duration>\tsleep between each mode test\n");
661 igt_info("\t-d\t<depth>\tbit depth of scanout buffer\n");
662 igt_info("\t-p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n");
663 igt_info("\t-m\ttest the preferred mode\n");
664 igt_info("\t-3\ttest all 3D modes\n");
665 igt_info("\t-t\tuse a tiled framebuffer\n");
666 igt_info("\t-j\tdo dpms off, optional arg to select dpms leve (1-3)\n");
667 igt_info("\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n");
668 igt_info("\t-o\t<id of the display>,<number of the mode>\tonly test specified mode on the specified display\n");
669 igt_info("\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n");
670 igt_info("\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n");
671 igt_info("\t\ttest force mode\n");
672 igt_info("\tDefault is to test all modes.\n");
Jesse Barnes5406c632010-12-21 09:38:23 -0800673 exit(0);
674}
675
Hai Lan62d51682011-02-11 11:14:15 -0500676#define dump_resource(res) if (res) dump_##res()
677
Jesse Barnes7255a842014-03-26 11:02:48 -0700678static void cleanup_and_exit(int ret)
679{
680 close(drm_fd);
Jesse Barnes7255a842014-03-26 11:02:48 -0700681 exit(ret);
682}
683
Jesse Barnes5406c632010-12-21 09:38:23 -0800684static gboolean input_event(GIOChannel *source, GIOCondition condition,
Yi Sun41fe8112012-07-26 14:23:36 +0800685 gpointer data)
Jesse Barnes5406c632010-12-21 09:38:23 -0800686{
Daniel Vetter74d65452011-12-18 00:24:45 +0100687 gchar buf[2];
Jesse Barnes5406c632010-12-21 09:38:23 -0800688 gsize count;
689
Chris Wilson28032382011-02-11 10:56:41 +0000690 count = read(g_io_channel_unix_get_fd(source), buf, sizeof(buf));
Jesse Barnes24e60382011-10-24 17:15:34 +0200691 if (buf[0] == 'q' && (count == 1 || buf[1] == '\n')) {
Jesse Barnes7255a842014-03-26 11:02:48 -0700692 cleanup_and_exit(0);
Jesse Barnesea416332012-02-27 12:46:11 -0800693 }
Jesse Barnes5406c632010-12-21 09:38:23 -0800694
695 return TRUE;
696}
697
Yi Sun41fe8112012-07-26 14:23:36 +0800698static void enter_exec_path( char **argv )
699{
700 char *exec_path = NULL;
701 char *pos = NULL;
702 short len_path = 0;
Imre Deak31dfc982012-10-10 16:04:45 +0300703 int ret;
Yi Sun41fe8112012-07-26 14:23:36 +0800704
705 len_path = strlen( argv[0] );
706 exec_path = (char*) malloc(len_path);
707
708 memcpy(exec_path, argv[0], len_path);
709 pos = strrchr(exec_path, '/');
710 if (pos != NULL)
711 *(pos+1) = '\0';
712
Imre Deak31dfc982012-10-10 16:04:45 +0300713 ret = chdir(exec_path);
Daniel Vetter83440952013-08-13 12:35:58 +0200714 igt_assert(ret == 0);
Yi Sun41fe8112012-07-26 14:23:36 +0800715 free(exec_path);
716}
717
Imre Deak63746412014-05-12 13:29:49 +0300718static void restore_termio_mode(int sig)
719{
720 tcsetattr(tio_fd, TCSANOW, &saved_tio);
721 close(tio_fd);
722}
723
Jesse Barnes7255a842014-03-26 11:02:48 -0700724static void set_termio_mode(void)
725{
726 struct termios tio;
727
Thomas Wood8408e002014-07-24 17:45:48 +0100728 /* don't attempt to set terminal attributes if not in the foreground
729 * process group */
730 if (getpgrp() != tcgetpgrp(STDOUT_FILENO))
731 return;
732
Imre Deak63746412014-05-12 13:29:49 +0300733 tio_fd = dup(STDIN_FILENO);
734 tcgetattr(tio_fd, &saved_tio);
735 igt_install_exit_handler(restore_termio_mode);
Jesse Barnes7255a842014-03-26 11:02:48 -0700736 tio = saved_tio;
Jesse Barnes7255a842014-03-26 11:02:48 -0700737 tio.c_lflag &= ~(ICANON | ECHO);
Imre Deak63746412014-05-12 13:29:49 +0300738 tcsetattr(tio_fd, TCSANOW, &tio);
Jesse Barnes7255a842014-03-26 11:02:48 -0700739}
740
Jesse Barnes5406c632010-12-21 09:38:23 -0800741int main(int argc, char **argv)
742{
743 int c;
Jesse Barnes5406c632010-12-21 09:38:23 -0800744 int ret = 0;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100745 GIOChannel *stdinchannel;
Jesse Barnes5406c632010-12-21 09:38:23 -0800746 GMainLoop *mainloop;
Yi Sun4cceae72012-02-03 19:23:55 +0800747 float force_clock;
Damien Lespiau66477a22013-09-05 16:49:11 +0100748 bool opt_dump_info = false;
Jesse Barnes5406c632010-12-21 09:38:23 -0800749
Daniel Vetter1caaf0a2013-08-12 12:17:35 +0200750 igt_skip_on_simulation();
Damien Lespiau5fa15f72013-04-29 18:40:39 +0100751
Yi Sun41fe8112012-07-26 14:23:36 +0800752 enter_exec_path( argv );
753
Jesse Barnes5406c632010-12-21 09:38:23 -0800754 while ((c = getopt(argc, argv, optstr)) != -1) {
755 switch (c) {
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100756 case '3':
757 test_stereo_modes = 1;
758 break;
Hai Lan62d51682011-02-11 11:14:15 -0500759 case 'i':
Damien Lespiau66477a22013-09-05 16:49:11 +0100760 opt_dump_info = true;
Hai Lan62d51682011-02-11 11:14:15 -0500761 break;
762 case 'a':
763 test_all_modes = 1;
764 break;
765 case 'f':
766 force_mode = 1;
Yi Sun4cceae72012-02-03 19:23:55 +0800767 if(sscanf(optarg,"%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
768 &force_clock,&force_timing.hdisplay, &force_timing.hsync_start,&force_timing.hsync_end,&force_timing.htotal,
769 &force_timing.vdisplay, &force_timing.vsync_start, &force_timing.vsync_end, &force_timing.vtotal)!= 9)
Hai Lan62d51682011-02-11 11:14:15 -0500770 usage(argv[0]);
Yi Sun4cceae72012-02-03 19:23:55 +0800771 force_timing.clock = force_clock*1000;
772
Hai Lan62d51682011-02-11 11:14:15 -0500773 break;
774 case 's':
775 sleep_between_modes = atoi(optarg);
776 break;
Daniel Vetter30cfde52014-02-13 19:15:38 +0100777 case 'j':
Daniel Vettercef9b312014-02-13 19:22:35 +0100778 do_dpms = atoi(optarg);
779 if (do_dpms == 0)
780 do_dpms = DRM_MODE_DPMS_OFF;
Daniel Vetter30cfde52014-02-13 19:15:38 +0100781 break;
Jesse Barnesc56cd102011-04-19 11:50:16 -0700782 case 'd':
783 depth = atoi(optarg);
Daniel Vetterc9c55452014-06-13 18:27:59 +0200784 igt_info("using depth %d\n", depth);
Jesse Barnesc56cd102011-04-19 11:50:16 -0700785 break;
Jesse Barnes7230c012011-06-07 13:17:46 -0700786 case 'p':
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800787 if (sscanf(optarg, "%d,%d,%d,%d,%d,%d", &plane_width,
788 &plane_height, &crtc_x, &crtc_y,
789 &crtc_w, &crtc_h) != 6)
Jesse Barnes24e60382011-10-24 17:15:34 +0200790 usage(argv[0]);
Jesse Barnes7230c012011-06-07 13:17:46 -0700791 test_plane = 1;
792 break;
Paulo Zanoni9fe11482011-09-15 15:13:41 -0300793 case 'm':
794 test_preferred_mode = 1;
795 break;
Jesse Barnesb707feb2011-06-07 13:27:35 -0700796 case 't':
797 enable_tiling = 1;
798 break;
Yi Sun41fe8112012-07-26 14:23:36 +0800799 case 'r':
800 qr_code = 1;
801 break;
Yi Sun53895ac2012-09-25 17:13:17 +0800802 case 'o':
Yi Sun05bfbf42012-12-26 17:12:39 +0800803 sscanf(optarg, "%d,%d", &specified_disp_id, &specified_mode_num);
Yi Sun53895ac2012-09-25 17:13:17 +0800804 break;
Jesse Barnes5406c632010-12-21 09:38:23 -0800805 default:
Jesse Barnes5406c632010-12-21 09:38:23 -0800806 /* fall through */
807 case 'h':
808 usage(argv[0]);
809 break;
810 }
811 }
Damien Lespiau03962732013-09-03 14:57:31 +0100812
Jesse Barnes7255a842014-03-26 11:02:48 -0700813 set_termio_mode();
814
Damien Lespiau03962732013-09-03 14:57:31 +0100815 if (depth <= 8)
816 bpp = 8;
817 else if (depth <= 16)
818 bpp = 16;
819 else if (depth <= 32)
820 bpp = 32;
821
Damien Lespiau66477a22013-09-05 16:49:11 +0100822 if (!test_all_modes && !force_mode && !test_preferred_mode &&
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100823 specified_mode_num == -1 && !test_stereo_modes)
Paulo Zanoni9fe11482011-09-15 15:13:41 -0300824 test_all_modes = 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800825
Daniel Vetter0732cc52012-05-22 12:01:36 +0200826 drm_fd = drm_open_any();
Jesse Barnes5406c632010-12-21 09:38:23 -0800827
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100828 if (test_stereo_modes &&
829 drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200830 igt_warn("DRM_CLIENT_CAP_STEREO_3D failed\n");
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100831 goto out_close;
832 }
833
Damien Lespiau66477a22013-09-05 16:49:11 +0100834 if (opt_dump_info) {
835 dump_info();
836 goto out_close;
837 }
838
Daniel Vetter1f0cf2d2013-10-31 17:02:41 +0100839 igt_set_vt_graphics_mode();
Imre Deak01b408e2013-05-08 19:06:44 +0300840
Jesse Barnes5406c632010-12-21 09:38:23 -0800841 mainloop = g_main_loop_new(NULL, FALSE);
842 if (!mainloop) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200843 igt_warn("failed to create glib mainloop\n");
Jesse Barnes5406c632010-12-21 09:38:23 -0800844 ret = -1;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100845 goto out_close;
Jesse Barnes5406c632010-12-21 09:38:23 -0800846 }
847
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100848 if (!testdisplay_setup_hotplug()) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200849 igt_warn("failed to initialize hotplug support\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100850 goto out_mainloop;
Jesse Barnes5406c632010-12-21 09:38:23 -0800851 }
852
853 stdinchannel = g_io_channel_unix_new(0);
854 if (!stdinchannel) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200855 igt_warn("failed to create stdin GIO channel\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100856 goto out_hotplug;
Jesse Barnes5406c632010-12-21 09:38:23 -0800857 }
858
859 ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event,
860 NULL);
861 if (ret < 0) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200862 igt_warn("failed to add watch on stdin GIO channel\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100863 goto out_stdio;
Jesse Barnes5406c632010-12-21 09:38:23 -0800864 }
865
Paulo Zanoni17cecce2011-09-16 18:06:27 -0300866 ret = 0;
867
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300868 if (!update_display()) {
869 ret = 1;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100870 goto out_stdio;
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300871 }
872
Damien Lespiau66477a22013-09-05 16:49:11 +0100873 if (test_all_modes)
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100874 goto out_stdio;
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300875
Jesse Barnes5406c632010-12-21 09:38:23 -0800876 g_main_loop_run(mainloop);
877
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100878out_stdio:
Jesse Barnes5406c632010-12-21 09:38:23 -0800879 g_io_channel_shutdown(stdinchannel, TRUE, NULL);
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100880out_hotplug:
881 testdisplay_cleanup_hotplug();
882out_mainloop:
Jesse Barnes5406c632010-12-21 09:38:23 -0800883 g_main_loop_unref(mainloop);
Jesse Barnes5406c632010-12-21 09:38:23 -0800884out_close:
Daniel Vetter0732cc52012-05-22 12:01:36 +0200885 close(drm_fd);
886
Jesse Barnes5406c632010-12-21 09:38:23 -0800887 return ret;
888}