blob: c91bb9d14f521d6e6473a06d59c3e2b9077b2779 [file] [log] [blame]
Jesse Barnes731cd552008-12-17 10:09:49 -08001/*
2 * DRM based mode setting test program
3 * Copyright 2008 Tungsten Graphics
4 * Jakob Bornecrantz <jakob@tungstengraphics.com>
5 * Copyright 2008 Intel Corporation
6 * Jesse Barnes <jesse.barnes@intel.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * IN THE SOFTWARE.
25 */
26
27/*
28 * This fairly simple test program dumps output in a similar format to the
29 * "xrandr" tool everyone knows & loves. It's necessarily slightly different
30 * since the kernel separates outputs into encoder and connector structures,
31 * each with their own unique ID. The program also allows test testing of the
32 * memory management and mode setting APIs by allowing the user to specify a
33 * connector and mode to use for mode setting. If all works as expected, a
34 * blue background should be painted on the monitor attached to the specified
35 * connector after the selected mode is set.
36 *
37 * TODO: use cairo to write the mode info on the selected output once
38 * the mode has been programmed, along with possible test patterns.
39 */
Kristian Høgsberg7a389aa2009-02-03 15:03:41 -050040#include "config.h"
41
Jesse Barnes731cd552008-12-17 10:09:49 -080042#include <assert.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <stdint.h>
Paulo Zanonid72a44c2012-04-21 17:51:53 -030046#include <inttypes.h>
Jesse Barnes731cd552008-12-17 10:09:49 -080047#include <unistd.h>
48#include <string.h>
49#include <errno.h>
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -050050#include <sys/poll.h>
Matthew W. S. Belle4a51962010-01-30 02:14:44 +000051#include <sys/time.h>
Jesse Barnes731cd552008-12-17 10:09:49 -080052
53#include "xf86drm.h"
54#include "xf86drmMode.h"
Rob Clarkd55de742011-12-14 21:06:43 -060055#include "drm_fourcc.h"
Benjamin Franzke8fef2902011-02-17 10:47:47 +010056#include "libkms.h"
Jesse Barnes731cd552008-12-17 10:09:49 -080057
Laurent Pinchartdb004ba2012-07-20 16:37:00 +020058#include "buffers.h"
Kristian Høgsberg7a389aa2009-02-03 15:03:41 -050059
Jesse Barnes731cd552008-12-17 10:09:49 -080060drmModeRes *resources;
61int fd, modes;
62
63#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
64
65struct type_name {
66 int type;
67 char *name;
68};
69
70#define type_name_fn(res) \
71char * res##_str(int type) { \
Paulo Zanoni9b44fbd2012-04-21 17:51:50 -030072 unsigned int i; \
Jesse Barnes731cd552008-12-17 10:09:49 -080073 for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
74 if (res##_names[i].type == type) \
75 return res##_names[i].name; \
76 } \
77 return "(invalid)"; \
78}
79
80struct type_name encoder_type_names[] = {
81 { DRM_MODE_ENCODER_NONE, "none" },
82 { DRM_MODE_ENCODER_DAC, "DAC" },
83 { DRM_MODE_ENCODER_TMDS, "TMDS" },
84 { DRM_MODE_ENCODER_LVDS, "LVDS" },
85 { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
86};
87
88type_name_fn(encoder_type)
89
90struct type_name connector_status_names[] = {
91 { DRM_MODE_CONNECTED, "connected" },
92 { DRM_MODE_DISCONNECTED, "disconnected" },
93 { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
94};
95
96type_name_fn(connector_status)
97
98struct type_name connector_type_names[] = {
99 { DRM_MODE_CONNECTOR_Unknown, "unknown" },
100 { DRM_MODE_CONNECTOR_VGA, "VGA" },
101 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
102 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
103 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
104 { DRM_MODE_CONNECTOR_Composite, "composite" },
105 { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
106 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
107 { DRM_MODE_CONNECTOR_Component, "component" },
108 { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
109 { DRM_MODE_CONNECTOR_DisplayPort, "displayport" },
110 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
111 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
Jesse Barnesb8abe612010-09-07 13:10:15 -0700112 { DRM_MODE_CONNECTOR_TV, "TV" },
113 { DRM_MODE_CONNECTOR_eDP, "embedded displayport" },
Jesse Barnes731cd552008-12-17 10:09:49 -0800114};
115
116type_name_fn(connector_type)
117
Kristian Høgsbergc0ed9b22012-06-28 10:48:31 -0400118#define bit_name_fn(res) \
119char * res##_str(int type) { \
120 int i; \
121 const char *sep = ""; \
122 for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
123 if (type & (1 << i)) { \
124 printf("%s%s", sep, res##_names[i]); \
125 sep = ", "; \
126 } \
127 } \
Tobias Klausmann6fa2b292012-08-12 00:00:40 +0200128 return NULL; \
Kristian Høgsbergc0ed9b22012-06-28 10:48:31 -0400129}
130
131static const char *mode_type_names[] = {
132 "builtin",
133 "clock_c",
134 "crtc_c",
135 "preferred",
136 "default",
137 "userdef",
138 "driver",
139};
140
141bit_name_fn(mode_type)
142
143static const char *mode_flag_names[] = {
144 "phsync",
145 "nhsync",
146 "pvsync",
147 "nvsync",
148 "interlace",
149 "dblscan",
150 "csync",
151 "pcsync",
152 "ncsync",
153 "hskew",
154 "bcast",
155 "pixmux",
156 "dblclk",
157 "clkdiv2"
158};
159
160bit_name_fn(mode_flag)
161
Jesse Barnes731cd552008-12-17 10:09:49 -0800162void dump_encoders(void)
163{
164 drmModeEncoder *encoder;
165 int i;
166
167 printf("Encoders:\n");
168 printf("id\tcrtc\ttype\tpossible crtcs\tpossible clones\t\n");
169 for (i = 0; i < resources->count_encoders; i++) {
170 encoder = drmModeGetEncoder(fd, resources->encoders[i]);
171
172 if (!encoder) {
173 fprintf(stderr, "could not get encoder %i: %s\n",
174 resources->encoders[i], strerror(errno));
175 continue;
176 }
177 printf("%d\t%d\t%s\t0x%08x\t0x%08x\n",
178 encoder->encoder_id,
179 encoder->crtc_id,
180 encoder_type_str(encoder->encoder_type),
181 encoder->possible_crtcs,
182 encoder->possible_clones);
183 drmModeFreeEncoder(encoder);
184 }
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500185 printf("\n");
186}
187
Kristian Høgsberg9fc85b42009-02-23 15:08:03 -0500188void dump_mode(drmModeModeInfo *mode)
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500189{
Kristian Høgsbergc0ed9b22012-06-28 10:48:31 -0400190 printf(" %s %d %d %d %d %d %d %d %d %d",
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500191 mode->name,
Marcin Kościelnicki694ef592010-02-27 15:04:42 +0000192 mode->vrefresh,
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500193 mode->hdisplay,
194 mode->hsync_start,
195 mode->hsync_end,
196 mode->htotal,
197 mode->vdisplay,
198 mode->vsync_start,
199 mode->vsync_end,
200 mode->vtotal);
Kristian Høgsbergc0ed9b22012-06-28 10:48:31 -0400201
202 printf(" flags: ");
203 mode_flag_str(mode->flags);
204 printf("; type: ");
205 mode_type_str(mode->type);
206 printf("\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800207}
208
Kristian Høgsberg9fc85b42009-02-23 15:08:03 -0500209static void
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300210dump_blob(uint32_t blob_id)
Kristian Høgsberg9fc85b42009-02-23 15:08:03 -0500211{
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300212 uint32_t i;
213 unsigned char *blob_data;
214 drmModePropertyBlobPtr blob;
Kristian Høgsberg9fc85b42009-02-23 15:08:03 -0500215
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300216 blob = drmModeGetPropertyBlob(fd, blob_id);
217 if (!blob)
218 return;
219
220 blob_data = blob->data;
221
222 for (i = 0; i < blob->length; i++) {
223 if (i % 16 == 0)
224 printf("\n\t\t\t");
225 printf("%.2hhx", blob_data[i]);
Kristian Høgsberg9fc85b42009-02-23 15:08:03 -0500226 }
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300227 printf("\n");
228
229 drmModeFreePropertyBlob(blob);
230}
231
232static void
233dump_prop(uint32_t prop_id, uint64_t value)
234{
235 int i;
236 drmModePropertyPtr prop;
237
238 prop = drmModeGetProperty(fd, prop_id);
239
240 printf("\t%d", prop_id);
241 if (!prop) {
242 printf("\n");
243 return;
244 }
245
246 printf(" %s:\n", prop->name);
247
248 printf("\t\tflags:");
249 if (prop->flags & DRM_MODE_PROP_PENDING)
250 printf(" pending");
251 if (prop->flags & DRM_MODE_PROP_RANGE)
252 printf(" range");
253 if (prop->flags & DRM_MODE_PROP_IMMUTABLE)
254 printf(" immutable");
255 if (prop->flags & DRM_MODE_PROP_ENUM)
256 printf(" enum");
Rob Clark6df9e6a2012-06-05 12:28:38 -0500257 if (prop->flags & DRM_MODE_PROP_BITMASK)
258 printf(" bitmask");
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300259 if (prop->flags & DRM_MODE_PROP_BLOB)
260 printf(" blob");
261 printf("\n");
262
263 if (prop->flags & DRM_MODE_PROP_RANGE) {
264 printf("\t\tvalues:");
265 for (i = 0; i < prop->count_values; i++)
266 printf(" %"PRIu64, prop->values[i]);
267 printf("\n");
268 }
269
270 if (prop->flags & DRM_MODE_PROP_ENUM) {
271 printf("\t\tenums:");
272 for (i = 0; i < prop->count_enums; i++)
273 printf(" %s=%llu", prop->enums[i].name,
274 prop->enums[i].value);
275 printf("\n");
Rob Clark6df9e6a2012-06-05 12:28:38 -0500276 } else if (prop->flags & DRM_MODE_PROP_BITMASK) {
277 printf("\t\tvalues:");
278 for (i = 0; i < prop->count_enums; i++)
279 printf(" %s=0x%llx", prop->enums[i].name,
280 (1LL << prop->enums[i].value));
281 printf("\n");
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300282 } else {
283 assert(prop->count_enums == 0);
284 }
285
286 if (prop->flags & DRM_MODE_PROP_BLOB) {
287 printf("\t\tblobs:\n");
288 for (i = 0; i < prop->count_blobs; i++)
289 dump_blob(prop->blob_ids[i]);
290 printf("\n");
291 } else {
292 assert(prop->count_blobs == 0);
293 }
294
295 printf("\t\tvalue:");
296 if (prop->flags & DRM_MODE_PROP_BLOB)
297 dump_blob(value);
298 else
299 printf(" %"PRIu64"\n", value);
300
301 drmModeFreeProperty(prop);
Kristian Høgsberg9fc85b42009-02-23 15:08:03 -0500302}
303
Jesse Barnes731cd552008-12-17 10:09:49 -0800304void dump_connectors(void)
305{
306 drmModeConnector *connector;
307 int i, j;
308
309 printf("Connectors:\n");
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500310 printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800311 for (i = 0; i < resources->count_connectors; i++) {
312 connector = drmModeGetConnector(fd, resources->connectors[i]);
313
314 if (!connector) {
315 fprintf(stderr, "could not get connector %i: %s\n",
316 resources->connectors[i], strerror(errno));
317 continue;
318 }
319
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500320 printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t",
Jesse Barnes731cd552008-12-17 10:09:49 -0800321 connector->connector_id,
322 connector->encoder_id,
323 connector_status_str(connector->connection),
324 connector_type_str(connector->connector_type),
325 connector->mmWidth, connector->mmHeight,
326 connector->count_modes);
327
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500328 for (j = 0; j < connector->count_encoders; j++)
329 printf("%s%d", j > 0 ? ", " : "", connector->encoders[j]);
330 printf("\n");
331
Paulo Zanonia10bcaa2012-04-21 17:51:51 -0300332 if (connector->count_modes) {
333 printf(" modes:\n");
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300334 printf("\tname refresh (Hz) hdisp hss hse htot vdisp "
Paulo Zanonia10bcaa2012-04-21 17:51:51 -0300335 "vss vse vtot)\n");
336 for (j = 0; j < connector->count_modes; j++)
337 dump_mode(&connector->modes[j]);
Jesse Barnes731cd552008-12-17 10:09:49 -0800338
Paulo Zanonia10bcaa2012-04-21 17:51:51 -0300339 printf(" props:\n");
Paulo Zanonid72a44c2012-04-21 17:51:53 -0300340 for (j = 0; j < connector->count_props; j++)
341 dump_prop(connector->props[j],
342 connector->prop_values[j]);
Paulo Zanonia10bcaa2012-04-21 17:51:51 -0300343 }
Marcin Kościelnicki9a374552010-02-27 15:04:40 +0000344
345 drmModeFreeConnector(connector);
Jesse Barnes731cd552008-12-17 10:09:49 -0800346 }
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500347 printf("\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800348}
349
350void dump_crtcs(void)
351{
352 drmModeCrtc *crtc;
Paulo Zanoni86dece42012-05-15 18:38:29 -0300353 drmModeObjectPropertiesPtr props;
Jesse Barnes731cd552008-12-17 10:09:49 -0800354 int i;
Paulo Zanoni86dece42012-05-15 18:38:29 -0300355 uint32_t j;
Jesse Barnes731cd552008-12-17 10:09:49 -0800356
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500357 printf("CRTCs:\n");
358 printf("id\tfb\tpos\tsize\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800359 for (i = 0; i < resources->count_crtcs; i++) {
360 crtc = drmModeGetCrtc(fd, resources->crtcs[i]);
361
362 if (!crtc) {
363 fprintf(stderr, "could not get crtc %i: %s\n",
364 resources->crtcs[i], strerror(errno));
365 continue;
366 }
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500367 printf("%d\t%d\t(%d,%d)\t(%dx%d)\n",
368 crtc->crtc_id,
369 crtc->buffer_id,
370 crtc->x, crtc->y,
371 crtc->width, crtc->height);
372 dump_mode(&crtc->mode);
373
Paulo Zanoni86dece42012-05-15 18:38:29 -0300374 printf(" props:\n");
375 props = drmModeObjectGetProperties(fd, crtc->crtc_id,
376 DRM_MODE_OBJECT_CRTC);
377 if (props) {
378 for (j = 0; j < props->count_props; j++)
379 dump_prop(props->props[j],
380 props->prop_values[j]);
381 drmModeFreeObjectProperties(props);
382 } else {
383 printf("\tcould not get crtc properties: %s\n",
384 strerror(errno));
385 }
386
Jesse Barnes731cd552008-12-17 10:09:49 -0800387 drmModeFreeCrtc(crtc);
388 }
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500389 printf("\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800390}
391
392void dump_framebuffers(void)
393{
394 drmModeFB *fb;
395 int i;
396
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500397 printf("Frame buffers:\n");
398 printf("id\tsize\tpitch\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800399 for (i = 0; i < resources->count_fbs; i++) {
400 fb = drmModeGetFB(fd, resources->fbs[i]);
401
402 if (!fb) {
403 fprintf(stderr, "could not get fb %i: %s\n",
404 resources->fbs[i], strerror(errno));
405 continue;
406 }
Matthew W. S. Belle4a51962010-01-30 02:14:44 +0000407 printf("%u\t(%ux%u)\t%u\n",
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500408 fb->fb_id,
Matthew W. S. Belle4a51962010-01-30 02:14:44 +0000409 fb->width, fb->height,
410 fb->pitch);
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500411
Jesse Barnes731cd552008-12-17 10:09:49 -0800412 drmModeFreeFB(fb);
413 }
Kristian Høgsberg0243c9f2008-12-18 00:02:43 -0500414 printf("\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800415}
416
Rob Clarkd55de742011-12-14 21:06:43 -0600417static void dump_planes(void)
418{
Rob Clark25e4cb42012-06-05 12:28:47 -0500419 drmModeObjectPropertiesPtr props;
Rob Clarkd55de742011-12-14 21:06:43 -0600420 drmModePlaneRes *plane_resources;
421 drmModePlane *ovr;
Paulo Zanoni9b44fbd2012-04-21 17:51:50 -0300422 unsigned int i, j;
Rob Clarkd55de742011-12-14 21:06:43 -0600423
424 plane_resources = drmModeGetPlaneResources(fd);
425 if (!plane_resources) {
426 fprintf(stderr, "drmModeGetPlaneResources failed: %s\n",
427 strerror(errno));
428 return;
429 }
430
431 printf("Planes:\n");
432 printf("id\tcrtc\tfb\tCRTC x,y\tx,y\tgamma size\n");
433 for (i = 0; i < plane_resources->count_planes; i++) {
434 ovr = drmModeGetPlane(fd, plane_resources->planes[i]);
435 if (!ovr) {
436 fprintf(stderr, "drmModeGetPlane failed: %s\n",
437 strerror(errno));
438 continue;
439 }
440
441 printf("%d\t%d\t%d\t%d,%d\t\t%d,%d\t%d\n",
442 ovr->plane_id, ovr->crtc_id, ovr->fb_id,
443 ovr->crtc_x, ovr->crtc_y, ovr->x, ovr->y,
444 ovr->gamma_size);
445
446 if (!ovr->count_formats)
447 continue;
448
449 printf(" formats:");
450 for (j = 0; j < ovr->count_formats; j++)
451 printf(" %4.4s", (char *)&ovr->formats[j]);
452 printf("\n");
453
Rob Clark25e4cb42012-06-05 12:28:47 -0500454 printf(" props:\n");
455 props = drmModeObjectGetProperties(fd, ovr->plane_id,
456 DRM_MODE_OBJECT_PLANE);
457 if (props) {
458 for (j = 0; j < props->count_props; j++)
459 dump_prop(props->props[j],
460 props->prop_values[j]);
461 drmModeFreeObjectProperties(props);
462 } else {
463 printf("\tcould not get plane properties: %s\n",
464 strerror(errno));
465 }
466
Rob Clarkd55de742011-12-14 21:06:43 -0600467 drmModeFreePlane(ovr);
468 }
469 printf("\n");
470
Paulo Zanoni0ef76442012-04-21 17:51:52 -0300471 drmModeFreePlaneResources(plane_resources);
Rob Clarkd55de742011-12-14 21:06:43 -0600472 return;
473}
474
Laurent Pincharta94ee622012-07-20 14:50:42 +0200475/* -----------------------------------------------------------------------------
476 * Connectors and planes
477 */
478
Jesse Barnes731cd552008-12-17 10:09:49 -0800479/*
480 * Mode setting with the kernel interfaces is a bit of a chore.
481 * First you have to find the connector in question and make sure the
482 * requested mode is available.
483 * Then you need to find the encoder attached to that connector so you
484 * can bind it with a free crtc.
485 */
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500486struct connector {
Matthew W. S. Belle4a51962010-01-30 02:14:44 +0000487 uint32_t id;
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500488 char mode_str[64];
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200489 char format_str[5];
490 unsigned int fourcc;
Kristian Høgsberg9fc85b42009-02-23 15:08:03 -0500491 drmModeModeInfo *mode;
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500492 drmModeEncoder *encoder;
Kristian Høgsberg8b880362009-02-04 12:17:13 -0500493 int crtc;
Rob Clarkd55de742011-12-14 21:06:43 -0600494 int pipe;
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500495 unsigned int fb_id[2], current_fb_id;
496 struct timeval start;
497
498 int swap_count;
Rob Clarkd55de742011-12-14 21:06:43 -0600499};
500
501struct plane {
502 uint32_t con_id; /* the id of connector to bind to */
503 uint32_t w, h;
504 unsigned int fb_id;
Rob Clarkb83ad862011-12-14 22:24:14 -0600505 char format_str[5]; /* need to leave room for terminating \0 */
Laurent Pinchart03752222012-07-20 14:50:47 +0200506 unsigned int fourcc;
Rob Clarkd55de742011-12-14 21:06:43 -0600507};
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500508
509static void
510connector_find_mode(struct connector *c)
Jesse Barnes731cd552008-12-17 10:09:49 -0800511{
512 drmModeConnector *connector;
Matthew W. S. Belle4a51962010-01-30 02:14:44 +0000513 int i, j;
Jesse Barnes731cd552008-12-17 10:09:49 -0800514
515 /* First, find the connector & mode */
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500516 c->mode = NULL;
Jesse Barnes731cd552008-12-17 10:09:49 -0800517 for (i = 0; i < resources->count_connectors; i++) {
518 connector = drmModeGetConnector(fd, resources->connectors[i]);
519
520 if (!connector) {
521 fprintf(stderr, "could not get connector %i: %s\n",
522 resources->connectors[i], strerror(errno));
523 drmModeFreeConnector(connector);
524 continue;
525 }
526
527 if (!connector->count_modes) {
528 drmModeFreeConnector(connector);
529 continue;
530 }
531
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500532 if (connector->connector_id != c->id) {
Jesse Barnes731cd552008-12-17 10:09:49 -0800533 drmModeFreeConnector(connector);
534 continue;
535 }
536
537 for (j = 0; j < connector->count_modes; j++) {
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500538 c->mode = &connector->modes[j];
539 if (!strcmp(c->mode->name, c->mode_str))
Jesse Barnes731cd552008-12-17 10:09:49 -0800540 break;
541 }
542
543 /* Found it, break out */
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500544 if (c->mode)
Jesse Barnes731cd552008-12-17 10:09:49 -0800545 break;
546
547 drmModeFreeConnector(connector);
548 }
549
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500550 if (!c->mode) {
551 fprintf(stderr, "failed to find mode \"%s\"\n", c->mode_str);
Jesse Barnes731cd552008-12-17 10:09:49 -0800552 return;
553 }
554
Jesse Barnes731cd552008-12-17 10:09:49 -0800555 /* Now get the encoder */
556 for (i = 0; i < resources->count_encoders; i++) {
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500557 c->encoder = drmModeGetEncoder(fd, resources->encoders[i]);
Jesse Barnes731cd552008-12-17 10:09:49 -0800558
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500559 if (!c->encoder) {
Jesse Barnes731cd552008-12-17 10:09:49 -0800560 fprintf(stderr, "could not get encoder %i: %s\n",
561 resources->encoders[i], strerror(errno));
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500562 drmModeFreeEncoder(c->encoder);
Jesse Barnes731cd552008-12-17 10:09:49 -0800563 continue;
564 }
565
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500566 if (c->encoder->encoder_id == connector->encoder_id)
Jesse Barnes731cd552008-12-17 10:09:49 -0800567 break;
568
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500569 drmModeFreeEncoder(c->encoder);
570 }
Kristian Høgsberg8b880362009-02-04 12:17:13 -0500571
572 if (c->crtc == -1)
573 c->crtc = c->encoder->crtc_id;
Rob Clarkd55de742011-12-14 21:06:43 -0600574
575 /* and figure out which crtc index it is: */
576 for (i = 0; i < resources->count_crtcs; i++) {
577 if (c->crtc == resources->crtcs[i]) {
578 c->pipe = i;
579 break;
580 }
581 }
582
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500583}
584
Laurent Pinchart3fdc1772012-07-20 14:50:41 +0200585/* -------------------------------------------------------------------------- */
586
587void
588page_flip_handler(int fd, unsigned int frame,
589 unsigned int sec, unsigned int usec, void *data)
590{
591 struct connector *c;
592 unsigned int new_fb_id;
593 struct timeval end;
594 double t;
595
596 c = data;
597 if (c->current_fb_id == c->fb_id[0])
598 new_fb_id = c->fb_id[1];
599 else
600 new_fb_id = c->fb_id[0];
601
602 drmModePageFlip(fd, c->crtc, new_fb_id,
603 DRM_MODE_PAGE_FLIP_EVENT, c);
604 c->current_fb_id = new_fb_id;
605 c->swap_count++;
606 if (c->swap_count == 60) {
607 gettimeofday(&end, NULL);
608 t = end.tv_sec + end.tv_usec * 1e-6 -
609 (c->start.tv_sec + c->start.tv_usec * 1e-6);
610 fprintf(stderr, "freq: %.02fHz\n", c->swap_count / t);
611 c->swap_count = 0;
612 c->start = end;
613 }
614}
615
Rob Clarkd55de742011-12-14 21:06:43 -0600616static int
617set_plane(struct kms_driver *kms, struct connector *c, struct plane *p)
618{
619 drmModePlaneRes *plane_resources;
620 drmModePlane *ovr;
621 uint32_t handles[4], pitches[4], offsets[4] = {0}; /* we only use [0] */
622 uint32_t plane_id = 0;
623 struct kms_bo *plane_bo;
Laurent Pinchart03752222012-07-20 14:50:47 +0200624 uint32_t plane_flags = 0;
Paulo Zanoni9b44fbd2012-04-21 17:51:50 -0300625 int ret, crtc_x, crtc_y, crtc_w, crtc_h;
626 unsigned int i;
Rob Clarkd55de742011-12-14 21:06:43 -0600627
628 /* find an unused plane which can be connected to our crtc */
629 plane_resources = drmModeGetPlaneResources(fd);
630 if (!plane_resources) {
631 fprintf(stderr, "drmModeGetPlaneResources failed: %s\n",
632 strerror(errno));
633 return -1;
634 }
635
636 for (i = 0; i < plane_resources->count_planes && !plane_id; i++) {
637 ovr = drmModeGetPlane(fd, plane_resources->planes[i]);
638 if (!ovr) {
639 fprintf(stderr, "drmModeGetPlane failed: %s\n",
640 strerror(errno));
641 return -1;
642 }
643
644 if ((ovr->possible_crtcs & (1 << c->pipe)) && !ovr->crtc_id)
645 plane_id = ovr->plane_id;
646
647 drmModeFreePlane(ovr);
648 }
649
Rob Clarkb83ad862011-12-14 22:24:14 -0600650 fprintf(stderr, "testing %dx%d@%s overlay plane\n",
651 p->w, p->h, p->format_str);
652
Rob Clarkd55de742011-12-14 21:06:43 -0600653 if (!plane_id) {
654 fprintf(stderr, "failed to find plane!\n");
655 return -1;
656 }
657
Laurent Pinchart03752222012-07-20 14:50:47 +0200658 plane_bo = create_test_buffer(kms, p->fourcc, p->w, p->h, handles,
Laurent Pincharta94ee622012-07-20 14:50:42 +0200659 pitches, offsets, PATTERN_TILES);
Laurent Pinchart3fdc1772012-07-20 14:50:41 +0200660 if (plane_bo == NULL)
661 return -1;
Rob Clarkd55de742011-12-14 21:06:43 -0600662
663 /* just use single plane format for now.. */
Laurent Pinchart03752222012-07-20 14:50:47 +0200664 if (drmModeAddFB2(fd, p->w, p->h, p->fourcc,
Rob Clarkd55de742011-12-14 21:06:43 -0600665 handles, pitches, offsets, &p->fb_id, plane_flags)) {
666 fprintf(stderr, "failed to add fb: %s\n", strerror(errno));
667 return -1;
668 }
669
670 /* ok, boring.. but for now put in middle of screen: */
671 crtc_x = c->mode->hdisplay / 3;
672 crtc_y = c->mode->vdisplay / 3;
673 crtc_w = crtc_x;
674 crtc_h = crtc_y;
675
676 /* note src coords (last 4 args) are in Q16 format */
677 if (drmModeSetPlane(fd, plane_id, c->crtc, p->fb_id,
678 plane_flags, crtc_x, crtc_y, crtc_w, crtc_h,
679 0, 0, p->w << 16, p->h << 16)) {
680 fprintf(stderr, "failed to enable plane: %s\n",
681 strerror(errno));
682 return -1;
683 }
684
685 return 0;
686}
687
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500688static void
Rob Clarkd55de742011-12-14 21:06:43 -0600689set_mode(struct connector *c, int count, struct plane *p, int plane_count,
690 int page_flip)
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500691{
Benjamin Franzke8fef2902011-02-17 10:47:47 +0100692 struct kms_driver *kms;
693 struct kms_bo *bo, *other_bo;
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500694 unsigned int fb_id, other_fb_id;
Laurent Pinchart3fdc1772012-07-20 14:50:41 +0200695 int i, j, ret, width, height, x;
696 uint32_t handles[4], pitches[4], offsets[4] = {0}; /* we only use [0] */
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500697 drmEventContext evctx;
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500698
699 width = 0;
700 height = 0;
701 for (i = 0; i < count; i++) {
702 connector_find_mode(&c[i]);
703 if (c[i].mode == NULL)
704 continue;
705 width += c[i].mode->hdisplay;
706 if (height < c[i].mode->vdisplay)
707 height = c[i].mode->vdisplay;
Jesse Barnes731cd552008-12-17 10:09:49 -0800708 }
709
Benjamin Franzke8fef2902011-02-17 10:47:47 +0100710 ret = kms_create(fd, &kms);
711 if (ret) {
712 fprintf(stderr, "failed to create kms driver: %s\n",
713 strerror(-ret));
Jesse Barnes731cd552008-12-17 10:09:49 -0800714 return;
715 }
716
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200717 bo = create_test_buffer(kms, c->fourcc, width, height, handles,
Laurent Pincharta94ee622012-07-20 14:50:42 +0200718 pitches, offsets, PATTERN_SMPTE);
Laurent Pinchart3fdc1772012-07-20 14:50:41 +0200719 if (bo == NULL)
Jesse Barnes731cd552008-12-17 10:09:49 -0800720 return;
Jesse Barnes731cd552008-12-17 10:09:49 -0800721
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200722 ret = drmModeAddFB2(fd, width, height, c->fourcc,
723 handles, pitches, offsets, &fb_id, 0);
Jesse Barnes731cd552008-12-17 10:09:49 -0800724 if (ret) {
Jakob Bornecrantz680b9c42011-10-19 13:32:26 +0200725 fprintf(stderr, "failed to add fb (%ux%u): %s\n",
726 width, height, strerror(errno));
Jesse Barnes731cd552008-12-17 10:09:49 -0800727 return;
728 }
729
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500730 x = 0;
731 for (i = 0; i < count; i++) {
732 if (c[i].mode == NULL)
733 continue;
Kristian Høgsberg8b880362009-02-04 12:17:13 -0500734
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200735 printf("setting mode %s@%s on connector %d, crtc %d\n",
736 c[i].mode_str, c[i].format_str, c[i].id, c[i].crtc);
Kristian Høgsberg8b880362009-02-04 12:17:13 -0500737
738 ret = drmModeSetCrtc(fd, c[i].crtc, fb_id, x, 0,
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500739 &c[i].id, 1, c[i].mode);
Jakob Bornecrantzd23146f2011-10-19 13:32:43 +0200740
741 /* XXX: Actually check if this is needed */
742 drmModeDirtyFB(fd, fb_id, NULL, 0);
743
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500744 x += c[i].mode->hdisplay;
745
746 if (ret) {
747 fprintf(stderr, "failed to set mode: %s\n", strerror(errno));
748 return;
749 }
Rob Clarkd55de742011-12-14 21:06:43 -0600750
751 /* if we have a plane/overlay to show, set that up now: */
752 for (j = 0; j < plane_count; j++)
753 if (p[j].con_id == c[i].id)
754 if (set_plane(kms, &c[i], &p[j]))
755 return;
Jesse Barnes731cd552008-12-17 10:09:49 -0800756 }
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500757
758 if (!page_flip)
759 return;
Benjamin Franzke8fef2902011-02-17 10:47:47 +0100760
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200761 other_bo = create_test_buffer(kms, c->fourcc, width, height, handles,
Laurent Pincharta94ee622012-07-20 14:50:42 +0200762 pitches, offsets, PATTERN_PLAIN);
Laurent Pinchart3fdc1772012-07-20 14:50:41 +0200763 if (other_bo == NULL)
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500764 return;
765
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200766 ret = drmModeAddFB2(fd, width, height, c->fourcc, handles, pitches, offsets,
767 &other_fb_id, 0);
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500768 if (ret) {
769 fprintf(stderr, "failed to add fb: %s\n", strerror(errno));
770 return;
771 }
772
773 for (i = 0; i < count; i++) {
774 if (c[i].mode == NULL)
775 continue;
776
Jakob Bornecrantz3c8adda2011-09-28 23:34:09 +0200777 ret = drmModePageFlip(fd, c[i].crtc, other_fb_id,
778 DRM_MODE_PAGE_FLIP_EVENT, &c[i]);
779 if (ret) {
780 fprintf(stderr, "failed to page flip: %s\n", strerror(errno));
781 return;
782 }
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500783 gettimeofday(&c[i].start, NULL);
784 c[i].swap_count = 0;
Matthew W. S. Belle4a51962010-01-30 02:14:44 +0000785 c[i].fb_id[0] = fb_id;
786 c[i].fb_id[1] = other_fb_id;
Benjamin Franzkea697fb62011-02-17 20:36:42 +0100787 c[i].current_fb_id = other_fb_id;
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500788 }
789
790 memset(&evctx, 0, sizeof evctx);
791 evctx.version = DRM_EVENT_CONTEXT_VERSION;
792 evctx.vblank_handler = NULL;
Jesse Barnes6f1eba02009-12-04 09:09:19 -0800793 evctx.page_flip_handler = page_flip_handler;
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500794
795 while (1) {
Jesse Barnese6b3f902010-03-26 13:13:57 -0700796#if 0
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500797 struct pollfd pfd[2];
798
799 pfd[0].fd = 0;
800 pfd[0].events = POLLIN;
801 pfd[1].fd = fd;
802 pfd[1].events = POLLIN;
803
804 if (poll(pfd, 2, -1) < 0) {
805 fprintf(stderr, "poll error\n");
806 break;
807 }
808
809 if (pfd[0].revents)
810 break;
Jesse Barnese6b3f902010-03-26 13:13:57 -0700811#else
812 struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
813 fd_set fds;
814 int ret;
815
816 FD_ZERO(&fds);
817 FD_SET(0, &fds);
818 FD_SET(fd, &fds);
819 ret = select(fd + 1, &fds, NULL, NULL, &timeout);
820
821 if (ret <= 0) {
822 fprintf(stderr, "select timed out or error (ret %d)\n",
823 ret);
824 continue;
825 } else if (FD_ISSET(0, &fds)) {
826 break;
827 }
828#endif
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500829
830 drmHandleEvent(fd, &evctx);
831 }
Benjamin Franzke8fef2902011-02-17 10:47:47 +0100832
833 kms_bo_destroy(&bo);
834 kms_bo_destroy(&other_bo);
835 kms_destroy(&kms);
Jesse Barnes731cd552008-12-17 10:09:49 -0800836}
837
838extern char *optarg;
839extern int optind, opterr, optopt;
Rob Clarkd55de742011-12-14 21:06:43 -0600840static char optstr[] = "ecpmfs:P:v";
Jesse Barnes731cd552008-12-17 10:09:49 -0800841
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200842#define min(a, b) ((a) < (b) ? (a) : (b))
843
Laurent Pinchart03752222012-07-20 14:50:47 +0200844static int parse_connector(struct connector *c, const char *arg)
845{
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200846 unsigned int len;
847 const char *p;
848 char *endp;
849
Laurent Pinchart03752222012-07-20 14:50:47 +0200850 c->crtc = -1;
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200851 strcpy(c->format_str, "XR24");
Laurent Pinchart03752222012-07-20 14:50:47 +0200852
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200853 c->id = strtoul(arg, &endp, 10);
854 if (*endp == '@') {
855 arg = endp + 1;
856 c->crtc = strtoul(arg, &endp, 10);
857 }
858 if (*endp != ':')
859 return -1;
Laurent Pinchart03752222012-07-20 14:50:47 +0200860
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200861 arg = endp + 1;
Laurent Pinchart03752222012-07-20 14:50:47 +0200862
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200863 p = strchrnul(arg, '@');
864 len = min(sizeof c->mode_str - 1, p - arg);
865 strncpy(c->mode_str, arg, len);
866 c->mode_str[len] = '\0';
867
868 if (*p == '@') {
869 strncpy(c->format_str, p + 1, 4);
870 c->format_str[4] = '\0';
Rob Clarkebd79042012-07-23 11:35:06 -0500871 }
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200872
Rob Clarkebd79042012-07-23 11:35:06 -0500873 c->fourcc = format_fourcc(c->format_str);
874 if (c->fourcc == 0) {
875 fprintf(stderr, "unknown format %s\n", c->format_str);
876 return -1;
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200877 }
878
879 return 0;
Laurent Pinchart03752222012-07-20 14:50:47 +0200880}
881
882static int parse_plane(struct plane *p, const char *arg)
883{
884 strcpy(p->format_str, "XR24");
885
886 if (sscanf(arg, "%d:%dx%d@%4s", &p->con_id, &p->w, &p->h, &p->format_str) != 4 &&
887 sscanf(arg, "%d:%dx%d", &p->con_id, &p->w, &p->h) != 3)
888 return -1;
889
890 p->fourcc = format_fourcc(p->format_str);
891 if (p->fourcc == 0) {
892 fprintf(stderr, "unknown format %s\n", p->format_str);
893 return -1;
894 }
895
896 return 0;
897}
898
Jesse Barnes731cd552008-12-17 10:09:49 -0800899void usage(char *name)
900{
901 fprintf(stderr, "usage: %s [-ecpmf]\n", name);
902 fprintf(stderr, "\t-e\tlist encoders\n");
903 fprintf(stderr, "\t-c\tlist connectors\n");
Rob Clarkd55de742011-12-14 21:06:43 -0600904 fprintf(stderr, "\t-p\tlist CRTCs and planes (pipes)\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800905 fprintf(stderr, "\t-m\tlist modes\n");
906 fprintf(stderr, "\t-f\tlist framebuffers\n");
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500907 fprintf(stderr, "\t-v\ttest vsynced page flipping\n");
Laurent Pinchartcc90ffa2012-07-20 14:50:48 +0200908 fprintf(stderr, "\t-s <connector_id>[@<crtc_id>]:<mode>[@<format>]\tset a mode\n");
909 fprintf(stderr, "\t-P <connector_id>:<w>x<h>[@<format>]\tset a plane\n");
Jesse Barnes731cd552008-12-17 10:09:49 -0800910 fprintf(stderr, "\n\tDefault is to dump all info.\n");
911 exit(0);
912}
913
914#define dump_resource(res) if (res) dump_##res()
915
Paulo Zanoni9b44fbd2012-04-21 17:51:50 -0300916static int page_flipping_supported(void)
Kristian Høgsberg59d97e72009-12-09 10:36:53 -0500917{
Benjamin Franzke8fef2902011-02-17 10:47:47 +0100918 /*FIXME: generic ioctl needed? */
919 return 1;
920#if 0
Kristian Høgsberg59d97e72009-12-09 10:36:53 -0500921 int ret, value;
922 struct drm_i915_getparam gp;
923
924 gp.param = I915_PARAM_HAS_PAGEFLIPPING;
925 gp.value = &value;
926
927 ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
928 if (ret) {
929 fprintf(stderr, "drm_i915_getparam: %m\n");
930 return 0;
931 }
932
Matthew W. S. Belle4a51962010-01-30 02:14:44 +0000933 return *gp.value;
Benjamin Franzke8fef2902011-02-17 10:47:47 +0100934#endif
Kristian Høgsberg59d97e72009-12-09 10:36:53 -0500935}
936
Jesse Barnes731cd552008-12-17 10:09:49 -0800937int main(int argc, char **argv)
938{
939 int c;
Rob Clarkd55de742011-12-14 21:06:43 -0600940 int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0;
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500941 int test_vsync = 0;
Inki Daee07b6502012-05-04 19:13:14 +0900942 char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos" };
Paulo Zanoni9b44fbd2012-04-21 17:51:50 -0300943 unsigned int i;
944 int count = 0, plane_count = 0;
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500945 struct connector con_args[2];
Rob Clarkb83ad862011-12-14 22:24:14 -0600946 struct plane plane_args[2] = {0};
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500947
Jesse Barnes731cd552008-12-17 10:09:49 -0800948 opterr = 0;
949 while ((c = getopt(argc, argv, optstr)) != -1) {
950 switch (c) {
951 case 'e':
952 encoders = 1;
953 break;
954 case 'c':
955 connectors = 1;
956 break;
957 case 'p':
958 crtcs = 1;
Rob Clarkd55de742011-12-14 21:06:43 -0600959 planes = 1;
Jesse Barnes731cd552008-12-17 10:09:49 -0800960 break;
961 case 'm':
962 modes = 1;
963 break;
964 case 'f':
965 framebuffers = 1;
966 break;
Kristian Høgsberg1e1b3c02009-11-17 15:32:23 -0500967 case 'v':
968 test_vsync = 1;
969 break;
Jesse Barnes731cd552008-12-17 10:09:49 -0800970 case 's':
Laurent Pinchart03752222012-07-20 14:50:47 +0200971 if (parse_connector(&con_args[count], optarg) < 0)
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500972 usage(argv[0]);
Kristian Høgsberg669fde32009-02-03 14:00:00 -0500973 count++;
Jesse Barnes731cd552008-12-17 10:09:49 -0800974 break;
Rob Clarkd55de742011-12-14 21:06:43 -0600975 case 'P':
Laurent Pinchart03752222012-07-20 14:50:47 +0200976 if (parse_plane(&plane_args[plane_count], optarg) < 0)
Rob Clarkd55de742011-12-14 21:06:43 -0600977 usage(argv[0]);
978 plane_count++;
979 break;
Jesse Barnes731cd552008-12-17 10:09:49 -0800980 default:
981 usage(argv[0]);
982 break;
983 }
984 }
985
986 if (argc == 1)
Rob Clarkd55de742011-12-14 21:06:43 -0600987 encoders = connectors = crtcs = planes = modes = framebuffers = 1;
Jesse Barnes731cd552008-12-17 10:09:49 -0800988
989 for (i = 0; i < ARRAY_SIZE(modules); i++) {
990 printf("trying to load module %s...", modules[i]);
991 fd = drmOpen(modules[i], NULL);
992 if (fd < 0) {
993 printf("failed.\n");
994 } else {
995 printf("success.\n");
996 break;
997 }
998 }
999
Paulo Zanoni9b44fbd2012-04-21 17:51:50 -03001000 if (test_vsync && !page_flipping_supported()) {
Kristian Høgsberg59d97e72009-12-09 10:36:53 -05001001 fprintf(stderr, "page flipping not supported by drm.\n");
1002 return -1;
1003 }
1004
Jesse Barnes731cd552008-12-17 10:09:49 -08001005 if (i == ARRAY_SIZE(modules)) {
1006 fprintf(stderr, "failed to load any modules, aborting.\n");
1007 return -1;
1008 }
1009
1010 resources = drmModeGetResources(fd);
1011 if (!resources) {
1012 fprintf(stderr, "drmModeGetResources failed: %s\n",
1013 strerror(errno));
1014 drmClose(fd);
1015 return 1;
1016 }
1017
1018 dump_resource(encoders);
1019 dump_resource(connectors);
1020 dump_resource(crtcs);
Rob Clarkd55de742011-12-14 21:06:43 -06001021 dump_resource(planes);
Jesse Barnes731cd552008-12-17 10:09:49 -08001022 dump_resource(framebuffers);
1023
Kristian Høgsberg669fde32009-02-03 14:00:00 -05001024 if (count > 0) {
Rob Clarkd55de742011-12-14 21:06:43 -06001025 set_mode(con_args, count, plane_args, plane_count, test_vsync);
Kristian Høgsberg2c113a12009-02-03 14:02:50 -05001026 getchar();
Jesse Barnes731cd552008-12-17 10:09:49 -08001027 }
1028
Jesse Barnes731cd552008-12-17 10:09:49 -08001029 drmModeFreeResources(resources);
1030
1031 return 0;
1032}