• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
48 #include "config.h"
49 
50 #include "igt.h"
51 #include <cairo.h>
52 #include <errno.h>
53 #include <getopt.h>
54 #include <libgen.h>
55 #include <math.h>
56 #include <stdint.h>
57 #include <stdbool.h>
58 #include <strings.h>
59 #include <unistd.h>
60 #include <termios.h>
61 #include <sys/poll.h>
62 #include <sys/time.h>
63 #include <sys/ioctl.h>
64 #include <sys/types.h>
65 #include <sys/stat.h>
66 
67 #include "testdisplay.h"
68 
69 #include <stdlib.h>
70 #include <signal.h>
71 
72 enum {
73 	OPT_YB,
74 	OPT_YF,
75 };
76 
77 static int tio_fd;
78 struct termios saved_tio;
79 
80 drmModeRes *resources;
81 int drm_fd, modes;
82 int test_all_modes = 0, test_preferred_mode = 0, force_mode = 0, test_plane,
83     test_stereo_modes, test_aspect_ratio;
84 uint64_t tiling = LOCAL_DRM_FORMAT_MOD_NONE;
85 int sleep_between_modes = 0;
86 int do_dpms = 0; /* This aliases to DPMS_ON */
87 uint32_t depth = 24, stride, bpp;
88 int qr_code = 0;
89 int specified_mode_num = -1, specified_disp_id = -1;
90 bool opt_dump_info = false;
91 
92 drmModeModeInfo force_timing;
93 
94 int crtc_x, crtc_y, crtc_w, crtc_h, width, height;
95 unsigned int plane_fb_id;
96 unsigned int plane_crtc_id;
97 unsigned int plane_id;
98 int plane_width, plane_height;
99 
100 /*
101  * Mode setting with the kernel interfaces is a bit of a chore.
102  * First you have to find the connector in question and make sure the
103  * requested mode is available.
104  * Then you need to find the encoder attached to that connector so you
105  * can bind it with a free crtc.
106  */
107 struct connector {
108 	uint32_t id;
109 	int mode_valid;
110 	drmModeModeInfo mode;
111 	drmModeEncoder *encoder;
112 	drmModeConnector *connector;
113 	int crtc;
114 	int pipe;
115 };
116 
dump_connectors_fd(int drmfd)117 static void dump_connectors_fd(int drmfd)
118 {
119 	int i, j;
120 
121 	drmModeRes *mode_resources = drmModeGetResources(drmfd);
122 
123 	if (!mode_resources) {
124 		igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
125 		return;
126 	}
127 
128 	igt_info("Connectors:\n");
129 	igt_info("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n");
130 	for (i = 0; i < mode_resources->count_connectors; i++) {
131 		drmModeConnector *connector;
132 
133 		connector = drmModeGetConnectorCurrent(drmfd,
134 						       mode_resources->connectors[i]);
135 		if (!connector) {
136 			igt_warn("could not get connector %i: %s\n", mode_resources->connectors[i], strerror(errno));
137 			continue;
138 		}
139 
140 		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);
141 
142 		if (!connector->count_modes)
143 			continue;
144 
145 		igt_info("  modes:\n");
146 		igt_info("  name refresh (Hz) hdisp hss hse htot vdisp ""vss vse vtot flags type clock\n");
147 		for (j = 0; j < connector->count_modes; j++){
148 			igt_info("[%d]", j);
149 			kmstest_dump_mode(&connector->modes[j]);
150 		}
151 
152 		drmModeFreeConnector(connector);
153 	}
154 	igt_info("\n");
155 
156 	drmModeFreeResources(mode_resources);
157 }
158 
dump_crtcs_fd(int drmfd)159 static void dump_crtcs_fd(int drmfd)
160 {
161 	drmModeRes *mode_resources;
162 
163 	mode_resources = drmModeGetResources(drmfd);
164 	if (!mode_resources)
165 		return;
166 
167 	igt_info("CRTCs:\n");
168 	igt_info("id\tfb\tpos\tsize\n");
169 	for (int i = 0; i < mode_resources->count_crtcs; i++) {
170 		drmModeCrtc *crtc;
171 
172 		crtc = drmModeGetCrtc(drmfd, mode_resources->crtcs[i]);
173 		if (!crtc) {
174 			igt_warn("could not get crtc %i: %s\n", mode_resources->crtcs[i], strerror(errno));
175 			continue;
176 		}
177 		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);
178 		kmstest_dump_mode(&crtc->mode);
179 
180 		drmModeFreeCrtc(crtc);
181 	}
182 	igt_info("\n");
183 
184 	drmModeFreeResources(mode_resources);
185 }
186 
dump_info(void)187 static void dump_info(void)
188 {
189 	dump_connectors_fd(drm_fd);
190 	dump_crtcs_fd(drm_fd);
191 }
192 
connector_find_preferred_mode(uint32_t connector_id,unsigned long crtc_idx_mask,int mode_num,struct connector * c,bool probe)193 static void connector_find_preferred_mode(uint32_t connector_id,
194 					  unsigned long crtc_idx_mask,
195 					  int mode_num, struct connector *c,
196 					  bool probe)
197 {
198 	struct kmstest_connector_config config;
199 	bool ret;
200 
201 	if (probe)
202 		ret = kmstest_probe_connector_config(drm_fd, connector_id,
203 						     crtc_idx_mask, &config);
204 	else
205 		ret = kmstest_get_connector_config(drm_fd, connector_id,
206 						   crtc_idx_mask, &config);
207 	if (!ret) {
208 		c->mode_valid = 0;
209 		return;
210 	}
211 
212 	c->connector = config.connector;
213 	c->encoder = config.encoder;
214 	c->crtc = config.crtc->crtc_id;
215 	c->pipe = config.pipe;
216 
217 	if (mode_num != -1) {
218 		igt_assert(mode_num < config.connector->count_modes);
219 		c->mode = config.connector->modes[mode_num];
220 	} else {
221 		c->mode = config.default_mode;
222 	}
223 	c->mode_valid = 1;
224 }
225 
226 static void
paint_color_key(struct igt_fb * fb_info)227 paint_color_key(struct igt_fb *fb_info)
228 {
229 	cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb_info);
230 
231 	cairo_rectangle(cr, crtc_x, crtc_y, crtc_w, crtc_h);
232 	cairo_set_source_rgb(cr, .8, .8, .8);
233 	cairo_fill(cr);
234 
235 	igt_put_cairo_ctx(drm_fd, fb_info, cr);
236 }
237 
paint_image(cairo_t * cr,const char * file)238 static void paint_image(cairo_t *cr, const char *file)
239 {
240 	int img_x, img_y, img_w, img_h;
241 
242 	img_y = height * (0.10 );
243 	img_h = height * 0.08 * 4;
244 	img_w = img_h;
245 
246 	img_x = (width / 2) - (img_w / 2);
247 
248 	igt_paint_image(cr, file, img_x, img_y, img_h, img_w);
249 }
250 
picture_aspect_ratio_str(uint32_t flags)251 static const char *picture_aspect_ratio_str(uint32_t flags)
252 {
253 	switch (flags & DRM_MODE_FLAG_PIC_AR_MASK) {
254 	case DRM_MODE_FLAG_PIC_AR_NONE:
255 		return "";
256 	case DRM_MODE_FLAG_PIC_AR_4_3:
257 		return "(4:3) ";
258 	case DRM_MODE_FLAG_PIC_AR_16_9:
259 		return "(16:9) ";
260 	case DRM_MODE_FLAG_PIC_AR_64_27:
261 		return "(64:27) ";
262 	case DRM_MODE_FLAG_PIC_AR_256_135:
263 		return "(256:135) ";
264 	default:
265 		return "(invalid) ";
266 	}
267 }
268 
paint_output_info(struct connector * c,struct igt_fb * fb)269 static void paint_output_info(struct connector *c, struct igt_fb *fb)
270 {
271 	cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb);
272 	int l_width = fb->width;
273 	int l_height = fb->height;
274 	double str_width;
275 	double x, y, top_y;
276 	double max_width;
277 	int i;
278 
279 	cairo_move_to(cr, l_width / 2, l_height / 2);
280 
281 	/* Print connector and mode name */
282 	cairo_set_font_size(cr, 48);
283 	igt_cairo_printf_line(cr, align_hcenter, 10, "%s",
284 		 kmstest_connector_type_str(c->connector->connector_type));
285 
286 	cairo_set_font_size(cr, 36);
287 	str_width = igt_cairo_printf_line(cr, align_hcenter, 10,
288 		"%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh,
289 		kmstest_encoder_type_str(c->encoder->encoder_type));
290 
291 	cairo_rel_move_to(cr, -str_width / 2, 0);
292 
293 	/* List available modes */
294 	cairo_set_font_size(cr, 18);
295 	str_width = igt_cairo_printf_line(cr, align_left, 10,
296 					      "Available modes:");
297 	cairo_rel_move_to(cr, str_width, 0);
298 	cairo_get_current_point(cr, &x, &top_y);
299 
300 	max_width = 0;
301 	for (i = 0; i < c->connector->count_modes; i++) {
302 		cairo_get_current_point(cr, &x, &y);
303 		if (y >= l_height) {
304 			x += max_width + 10;
305 			max_width = 0;
306 			cairo_move_to(cr, x, top_y);
307 		}
308 		str_width = igt_cairo_printf_line(cr, align_right, 10,
309 						  "%s%s @ %dHz",
310 						  picture_aspect_ratio_str(c->connector->modes[i].flags),
311 						  c->connector->modes[i].name,
312 						  c->connector->modes[i].vrefresh);
313 		if (str_width > max_width)
314 			max_width = str_width;
315 	}
316 
317 	if (qr_code)
318 		paint_image(cr, "pass.png");
319 
320 	igt_put_cairo_ctx(drm_fd, fb, cr);
321 }
322 
sighandler(int signo)323 static void sighandler(int signo)
324 {
325 	return;
326 }
327 
set_single(void)328 static void set_single(void)
329 {
330 	int sigs[] = { SIGUSR1 };
331 	struct sigaction sa;
332 	sa.sa_handler = sighandler;
333 
334 	sigemptyset(&sa.sa_mask);
335 
336 	igt_warn_on_f(sigaction(sigs[0], &sa, NULL) == -1,
337 		      "Could not set signal handler");
338 }
339 
340 static void
set_mode(struct connector * c)341 set_mode(struct connector *c)
342 {
343 	unsigned int fb_id = 0;
344 	struct igt_fb fb_info[2] = { };
345 	int j, test_mode_num, current_fb = 0, old_fb = -1;
346 
347 	test_mode_num = 1;
348 	if (force_mode){
349 		memcpy( &c->mode, &force_timing, sizeof(force_timing));
350 		c->mode.vrefresh =(force_timing.clock*1e3)/(force_timing.htotal*force_timing.vtotal);
351 		c->mode_valid = 1;
352 		sprintf(c->mode.name, "%dx%d", force_timing.hdisplay, force_timing.vdisplay);
353 	} else if (test_all_modes)
354 		test_mode_num = c->connector->count_modes;
355 
356 	for (j = 0; j < test_mode_num; j++) {
357 
358 		if (test_all_modes)
359 			c->mode = c->connector->modes[j];
360 
361 		/* set_mode() only tests 2D modes */
362 		if (c->mode.flags & DRM_MODE_FLAG_3D_MASK)
363 			continue;
364 
365 		if (!c->mode_valid)
366 			continue;
367 
368 		width = c->mode.hdisplay;
369 		height = c->mode.vdisplay;
370 
371 		fb_id = igt_create_pattern_fb(drm_fd, width, height,
372 					      igt_bpp_depth_to_drm_format(bpp, depth),
373 					      tiling, &fb_info[current_fb]);
374 		paint_output_info(c, &fb_info[current_fb]);
375 		paint_color_key(&fb_info[current_fb]);
376 
377 		igt_info("CRTC(%u):[%d]", c->crtc, j);
378 		kmstest_dump_mode(&c->mode);
379 		if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0,
380 				   &c->id, 1, &c->mode)) {
381 			igt_warn("failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));
382 			igt_remove_fb(drm_fd, &fb_info[current_fb]);
383 			continue;
384 		}
385 
386 		if (old_fb != -1)
387 			igt_remove_fb(drm_fd, &fb_info[old_fb]);
388 		old_fb = current_fb;
389 		current_fb = 1 - current_fb;
390 
391 		if (sleep_between_modes && test_all_modes && !qr_code)
392 			sleep(sleep_between_modes);
393 
394 		if (do_dpms) {
395 			kmstest_set_connector_dpms(drm_fd, c->connector, do_dpms);
396 			sleep(sleep_between_modes);
397 			kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
398 		}
399 
400 		if (qr_code){
401 			set_single();
402 			pause();
403 		}
404 	}
405 
406 	if (test_all_modes && old_fb != -1)
407 		igt_remove_fb(drm_fd, &fb_info[old_fb]);
408 
409 	drmModeFreeEncoder(c->encoder);
410 	drmModeFreeConnector(c->connector);
411 }
412 
do_set_stereo_mode(struct connector * c)413 static void do_set_stereo_mode(struct connector *c)
414 {
415 	uint32_t fb_id;
416 
417 	fb_id = igt_create_stereo_fb(drm_fd, &c->mode,
418 				     igt_bpp_depth_to_drm_format(bpp, depth),
419 				     tiling);
420 
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));
423 }
424 
425 static void
set_stereo_mode(struct connector * c)426 set_stereo_mode(struct connector *c)
427 {
428 	int i, n;
429 
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];
439 
440 		if (!c->mode_valid)
441 			continue;
442 
443 		if (!(c->mode.flags & DRM_MODE_FLAG_3D_MASK))
444 			continue;
445 
446 		igt_info("CRTC(%u): [%d]", c->crtc, i);
447 		kmstest_dump_mode(&c->mode);
448 		do_set_stereo_mode(c);
449 
450 		if (qr_code) {
451 			set_single();
452 			pause();
453 		} else if (sleep_between_modes)
454 			sleep(sleep_between_modes);
455 
456 		if (do_dpms) {
457 			kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_OFF);
458 			sleep(sleep_between_modes);
459 			kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
460 		}
461 	}
462 
463 	drmModeFreeEncoder(c->encoder);
464 	drmModeFreeConnector(c->connector);
465 }
466 
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  */
update_display(bool probe)476 int update_display(bool probe)
477 {
478 	struct connector *connectors;
479 	int c;
480 
481 	resources = drmModeGetResources(drm_fd);
482 	igt_require(resources);
483 
484 	connectors = calloc(resources->count_connectors,
485 			    sizeof(struct connector));
486 	if (!connectors)
487 		return 0;
488 
489 	if (test_preferred_mode || test_all_modes ||
490 	    force_mode || specified_disp_id != -1) {
491 		unsigned long crtc_idx_mask = -1UL;
492 
493 		/* Find any connected displays */
494 		for (c = 0; c < resources->count_connectors; c++) {
495 			struct connector *connector = &connectors[c];
496 
497 			connector->id = resources->connectors[c];
498 			if (specified_disp_id != -1 &&
499 			    connector->id != specified_disp_id)
500 				continue;
501 
502 			connector_find_preferred_mode(connector->id,
503 						      crtc_idx_mask,
504 						      specified_mode_num,
505 						      connector, probe);
506 			if (!connector->mode_valid)
507 				continue;
508 
509 			set_mode(connector);
510 
511 			if (test_preferred_mode || force_mode ||
512 			    specified_mode_num != -1)
513 				crtc_idx_mask &= ~(1 << connector->pipe);
514 
515 		}
516 	}
517 
518 	if (test_stereo_modes) {
519 		for (c = 0; c < resources->count_connectors; c++) {
520 			struct connector *connector = &connectors[c];
521 
522 			connector->id = resources->connectors[c];
523 			if (specified_disp_id != -1 &&
524 			    connector->id != specified_disp_id)
525 				continue;
526 
527 			connector_find_preferred_mode(connector->id,
528 						      -1UL,
529 						      specified_mode_num,
530 						      connector, probe);
531 			if (!connector->mode_valid)
532 				continue;
533 
534 			set_stereo_mode(connector);
535 		}
536 	}
537 
538 	free(connectors);
539 	drmModeFreeResources(resources);
540 	return 1;
541 }
542 
543 #define dump_resource(res) if (res) dump_##res()
544 
cleanup_and_exit(int ret)545 static void __attribute__((noreturn)) cleanup_and_exit(int ret)
546 {
547 	close(drm_fd);
548 	exit(ret);
549 }
550 
input_event(GIOChannel * source,GIOCondition condition,gpointer data)551 static gboolean input_event(GIOChannel *source, GIOCondition condition,
552 				gpointer data)
553 {
554 	gchar buf[2];
555 	gsize count;
556 
557 	count = read(g_io_channel_unix_get_fd(source), buf, sizeof(buf));
558 	if (buf[0] == 'q' && (count == 1 || buf[1] == '\n')) {
559 		cleanup_and_exit(0);
560 	}
561 
562 	return TRUE;
563 }
564 
enter_exec_path(void)565 static void enter_exec_path(void)
566 {
567 	char path[PATH_MAX];
568 
569 	if (readlink("/proc/self/exe", path, sizeof(path)) > 0)
570 		chdir(dirname(path));
571 }
572 
restore_termio_mode(int sig)573 static void restore_termio_mode(int sig)
574 {
575 	tcsetattr(tio_fd, TCSANOW, &saved_tio);
576 	close(tio_fd);
577 }
578 
set_termio_mode(void)579 static void set_termio_mode(void)
580 {
581 	struct termios tio;
582 
583 	/* don't attempt to set terminal attributes if not in the foreground
584 	 * process group */
585 	if (getpgrp() != tcgetpgrp(STDOUT_FILENO))
586 		return;
587 
588 	tio_fd = dup(STDIN_FILENO);
589 	tcgetattr(tio_fd, &saved_tio);
590 	igt_install_exit_handler(restore_termio_mode);
591 	tio = saved_tio;
592 	tio.c_lflag &= ~(ICANON | ECHO);
593 	tcsetattr(tio_fd, TCSANOW, &tio);
594 }
595 
596 static char optstr[] = "3Aiaf:s:d:p:mrto:j:y";
597 static struct option long_opts[] = {
598 	{"yb", 0, 0, OPT_YB},
599 	{"yf", 0, 0, OPT_YF},
600 	{ 0, 0, 0, 0 }
601 };
602 
603 static const char *help_str =
604 	"  -i\tdump info\n"
605 	"  -a\ttest all modes\n"
606 	"  -s\t<duration>\tsleep between each mode test (default: 0)\n"
607 	"  -d\t<depth>\tbit depth of scanout buffer\n"
608 	"  -p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n"
609 	"  -m\ttest the preferred mode\n"
610 	"  -3\ttest all 3D modes\n"
611 	"  -A\ttest all aspect ratios\n"
612 	"  -t\tuse an X-tiled framebuffer\n"
613 	"  -y, --yb\n"
614 	"  \tuse a Y-tiled framebuffer\n"
615 	"  --yf\tuse a Yf-tiled framebuffer\n"
616 	"  -j\tdo dpms off, optional arg to select dpms level (1-3)\n"
617 	"  -r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n"
618 	"  -o\t<id of the display>,<number of the mode>\tonly test specified mode on the specified display\n"
619 	"  -f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n"
620 	"  \t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n"
621 	"  \ttest force mode\n"
622 	"  \tDefault is to test all modes.\n"
623 	;
624 
opt_handler(int opt,int opt_index,void * data)625 static int opt_handler(int opt, int opt_index, void *data)
626 {
627 	float force_clock;
628 
629 	switch (opt) {
630 	case '3':
631 		test_stereo_modes = 1;
632 		break;
633 	case 'A':
634 		test_aspect_ratio = 1;
635 		break;
636 	case 'i':
637 		opt_dump_info = true;
638 		break;
639 	case 'a':
640 		test_all_modes = 1;
641 		break;
642 	case 'f':
643 		force_mode = 1;
644 		if (sscanf(optarg,"%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
645 			   &force_clock,&force_timing.hdisplay, &force_timing.hsync_start,&force_timing.hsync_end,&force_timing.htotal,
646 			   &force_timing.vdisplay, &force_timing.vsync_start, &force_timing.vsync_end, &force_timing.vtotal)!= 9)
647 			return IGT_OPT_HANDLER_ERROR;
648 		force_timing.clock = force_clock*1000;
649 
650 		break;
651 	case 's':
652 		sleep_between_modes = atoi(optarg);
653 		break;
654 	case 'j':
655 		do_dpms = atoi(optarg);
656 		if (do_dpms == 0)
657 			do_dpms = DRM_MODE_DPMS_OFF;
658 		break;
659 	case 'd':
660 		depth = atoi(optarg);
661 		igt_info("using depth %d\n", depth);
662 		break;
663 	case 'p':
664 		if (sscanf(optarg, "%d,%d,%d,%d,%d,%d", &plane_width,
665 			   &plane_height, &crtc_x, &crtc_y,
666 			   &crtc_w, &crtc_h) != 6)
667 			return IGT_OPT_HANDLER_ERROR;
668 		test_plane = 1;
669 		break;
670 	case 'm':
671 		test_preferred_mode = 1;
672 		break;
673 	case 't':
674 		tiling = LOCAL_I915_FORMAT_MOD_X_TILED;
675 		break;
676 	case 'y':
677 	case OPT_YB:
678 		tiling = LOCAL_I915_FORMAT_MOD_Y_TILED;
679 		break;
680 	case OPT_YF:
681 		tiling = LOCAL_I915_FORMAT_MOD_Yf_TILED;
682 		break;
683 	case 'r':
684 		qr_code = 1;
685 		break;
686 	case 'o':
687 		sscanf(optarg, "%d,%d", &specified_disp_id, &specified_mode_num);
688 		break;
689 	}
690 
691 	return IGT_OPT_HANDLER_SUCCESS;
692 }
693 
igt_simple_main_args(optstr,long_opts,help_str,opt_handler,NULL)694 igt_simple_main_args(optstr, long_opts, help_str, opt_handler, NULL)
695 {
696 	int ret = 0;
697 	GIOChannel *stdinchannel;
698 	GMainLoop *mainloop;
699 	igt_skip_on_simulation();
700 
701 	enter_exec_path();
702 
703 	set_termio_mode();
704 
705 	if (depth <= 8)
706 		bpp = 8;
707 	else if (depth <= 16)
708 		bpp = 16;
709 	else if (depth <= 32)
710 		bpp = 32;
711 
712 	if (!test_all_modes && !force_mode && !test_preferred_mode &&
713 	    specified_mode_num == -1 && !test_stereo_modes)
714 		test_all_modes = 1;
715 
716 	drm_fd = drm_open_driver(DRIVER_ANY);
717 
718 	if (test_stereo_modes &&
719 	    drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) {
720 		igt_warn("DRM_CLIENT_CAP_STEREO_3D failed\n");
721 		goto out_close;
722 	}
723 
724 	if (test_aspect_ratio &&
725 	    drmSetClientCap(drm_fd, DRM_CLIENT_CAP_ASPECT_RATIO, 1) < 0) {
726 		igt_warn("DRM_CLIENT_CAP_ASPECT_RATIO failed\n");
727 		goto out_close;
728 	}
729 
730 	if (opt_dump_info) {
731 		dump_info();
732 		goto out_close;
733 	}
734 
735 	kmstest_set_vt_graphics_mode();
736 
737 	mainloop = g_main_loop_new(NULL, FALSE);
738 	if (!mainloop) {
739 		igt_warn("failed to create glib mainloop\n");
740 		ret = -1;
741 		goto out_close;
742 	}
743 
744 	if (!testdisplay_setup_hotplug()) {
745 		igt_warn("failed to initialize hotplug support\n");
746 		goto out_mainloop;
747 	}
748 
749 	stdinchannel = g_io_channel_unix_new(0);
750 	if (!stdinchannel) {
751 		igt_warn("failed to create stdin GIO channel\n");
752 		goto out_hotplug;
753 	}
754 
755 	ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event,
756 			     NULL);
757 	if (ret < 0) {
758 		igt_warn("failed to add watch on stdin GIO channel\n");
759 		goto out_stdio;
760 	}
761 
762 	ret = 0;
763 
764 	if (!update_display(false)) {
765 		ret = 1;
766 		goto out_stdio;
767 	}
768 
769 	if (test_all_modes)
770 		goto out_stdio;
771 
772 	g_main_loop_run(mainloop);
773 
774 out_stdio:
775 	g_io_channel_shutdown(stdinchannel, TRUE, NULL);
776 out_hotplug:
777 	testdisplay_cleanup_hotplug();
778 out_mainloop:
779 	g_main_loop_unref(mainloop);
780 out_close:
781 	close(drm_fd);
782 
783 	igt_assert_eq(ret, 0);
784 }
785