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>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
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.
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.
54 #include "xf86drmMode.h"
55 #include "drm_fourcc.h"
62 drmModeObjectProperties *props;
63 drmModePropertyRes **props_info;
67 drmModeEncoder *encoder;
71 drmModeConnector *connector;
72 drmModeObjectProperties *props;
73 drmModePropertyRes **props_info;
82 drmModeObjectProperties *props;
83 drmModePropertyRes **props_info;
88 drmModePlaneRes *plane_res;
91 struct encoder *encoders;
92 struct connector *connectors;
97 struct resources *resources;
100 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
107 #define type_name_fn(res) \
108 const char * res##_str(int type) { \
110 for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
111 if (res##_names[i].type == type) \
112 return res##_names[i].name; \
114 return "(invalid)"; \
117 struct type_name encoder_type_names[] = {
118 { DRM_MODE_ENCODER_NONE, "none" },
119 { DRM_MODE_ENCODER_DAC, "DAC" },
120 { DRM_MODE_ENCODER_TMDS, "TMDS" },
121 { DRM_MODE_ENCODER_LVDS, "LVDS" },
122 { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
125 static type_name_fn(encoder_type)
127 struct type_name connector_status_names[] = {
128 { DRM_MODE_CONNECTED, "connected" },
129 { DRM_MODE_DISCONNECTED, "disconnected" },
130 { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
133 static type_name_fn(connector_status)
135 struct type_name connector_type_names[] = {
136 { DRM_MODE_CONNECTOR_Unknown, "unknown" },
137 { DRM_MODE_CONNECTOR_VGA, "VGA" },
138 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
139 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
140 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
141 { DRM_MODE_CONNECTOR_Composite, "composite" },
142 { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
143 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
144 { DRM_MODE_CONNECTOR_Component, "component" },
145 { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
146 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
147 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
148 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
149 { DRM_MODE_CONNECTOR_TV, "TV" },
150 { DRM_MODE_CONNECTOR_eDP, "eDP" },
153 static type_name_fn(connector_type)
155 #define bit_name_fn(res) \
156 const char * res##_str(int type) { \
158 const char *sep = ""; \
159 for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
160 if (type & (1 << i)) { \
161 printf("%s%s", sep, res##_names[i]); \
168 static const char *mode_type_names[] = {
178 static bit_name_fn(mode_type)
180 static const char *mode_flag_names[] = {
197 static bit_name_fn(mode_flag)
199 static void dump_encoders(void)
201 drmModeEncoder *encoder;
204 printf("Encoders:\n");
205 printf("id\tcrtc\ttype\tpossible crtcs\tpossible clones\t\n");
206 for (i = 0; i < resources->res->count_encoders; i++) {
207 encoder = resources->encoders[i].encoder;
211 printf("%d\t%d\t%s\t0x%08x\t0x%08x\n",
214 encoder_type_str(encoder->encoder_type),
215 encoder->possible_crtcs,
216 encoder->possible_clones);
221 static void dump_mode(drmModeModeInfo *mode)
223 printf(" %s %d %d %d %d %d %d %d %d %d",
236 mode_flag_str(mode->flags);
238 mode_type_str(mode->type);
243 dump_blob(uint32_t blob_id)
246 unsigned char *blob_data;
247 drmModePropertyBlobPtr blob;
249 blob = drmModeGetPropertyBlob(fd, blob_id);
253 blob_data = blob->data;
255 for (i = 0; i < blob->length; i++) {
258 printf("%.2hhx", blob_data[i]);
262 drmModeFreePropertyBlob(blob);
266 dump_prop(drmModePropertyPtr prop, uint32_t prop_id, uint64_t value)
269 printf("\t%d", prop_id);
275 printf(" %s:\n", prop->name);
277 printf("\t\tflags:");
278 if (prop->flags & DRM_MODE_PROP_PENDING)
280 if (prop->flags & DRM_MODE_PROP_RANGE)
282 if (prop->flags & DRM_MODE_PROP_IMMUTABLE)
283 printf(" immutable");
284 if (prop->flags & DRM_MODE_PROP_ENUM)
286 if (prop->flags & DRM_MODE_PROP_BITMASK)
288 if (prop->flags & DRM_MODE_PROP_BLOB)
292 if (prop->flags & DRM_MODE_PROP_RANGE) {
293 printf("\t\tvalues:");
294 for (i = 0; i < prop->count_values; i++)
295 printf(" %"PRIu64, prop->values[i]);
299 if (prop->flags & DRM_MODE_PROP_ENUM) {
300 printf("\t\tenums:");
301 for (i = 0; i < prop->count_enums; i++)
302 printf(" %s=%llu", prop->enums[i].name,
303 prop->enums[i].value);
305 } else if (prop->flags & DRM_MODE_PROP_BITMASK) {
306 printf("\t\tvalues:");
307 for (i = 0; i < prop->count_enums; i++)
308 printf(" %s=0x%llx", prop->enums[i].name,
309 (1LL << prop->enums[i].value));
312 assert(prop->count_enums == 0);
315 if (prop->flags & DRM_MODE_PROP_BLOB) {
316 printf("\t\tblobs:\n");
317 for (i = 0; i < prop->count_blobs; i++)
318 dump_blob(prop->blob_ids[i]);
321 assert(prop->count_blobs == 0);
324 printf("\t\tvalue:");
325 if (prop->flags & DRM_MODE_PROP_BLOB)
328 printf(" %"PRIu64"\n", value);
331 static void dump_connectors(void)
335 printf("Connectors:\n");
336 printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");
337 for (i = 0; i < resources->res->count_connectors; i++) {
338 struct connector *_connector = &resources->connectors[i];
339 drmModeConnector *connector = _connector->connector;
343 printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t",
344 connector->connector_id,
345 connector->encoder_id,
346 connector_status_str(connector->connection),
347 connector_type_str(connector->connector_type),
348 connector->mmWidth, connector->mmHeight,
349 connector->count_modes);
351 for (j = 0; j < connector->count_encoders; j++)
352 printf("%s%d", j > 0 ? ", " : "", connector->encoders[j]);
355 if (connector->count_modes) {
357 printf("\tname refresh (Hz) hdisp hss hse htot vdisp "
359 for (j = 0; j < connector->count_modes; j++)
360 dump_mode(&connector->modes[j]);
363 if (_connector->props) {
365 for (j = 0; j < (int)_connector->props->count_props; j++)
366 dump_prop(_connector->props_info[j],
367 _connector->props->props[j],
368 _connector->props->prop_values[j]);
374 static void dump_crtcs(void)
380 printf("id\tfb\tpos\tsize\n");
381 for (i = 0; i < resources->res->count_crtcs; i++) {
382 struct crtc *_crtc = &resources->crtcs[i];
383 drmModeCrtc *crtc = _crtc->crtc;
387 printf("%d\t%d\t(%d,%d)\t(%dx%d)\n",
391 crtc->width, crtc->height);
392 dump_mode(&crtc->mode);
396 for (j = 0; j < _crtc->props->count_props; j++)
397 dump_prop(_crtc->props_info[j],
398 _crtc->props->props[j],
399 _crtc->props->prop_values[j]);
401 printf(" no properties found\n");
407 static void dump_framebuffers(void)
412 printf("Frame buffers:\n");
413 printf("id\tsize\tpitch\n");
414 for (i = 0; i < resources->res->count_fbs; i++) {
415 fb = resources->fbs[i].fb;
419 printf("%u\t(%ux%u)\t%u\n",
421 fb->width, fb->height,
427 static void dump_planes(void)
432 printf("id\tcrtc\tfb\tCRTC x,y\tx,y\tgamma size\tpossible crtcs\n");
434 if (!resources->plane_res)
437 for (i = 0; i < resources->plane_res->count_planes; i++) {
438 struct plane *plane = &resources->planes[i];
439 drmModePlane *ovr = plane->plane;
443 printf("%d\t%d\t%d\t%d,%d\t\t%d,%d\t%-8d\t0x%08x\n",
444 ovr->plane_id, ovr->crtc_id, ovr->fb_id,
445 ovr->crtc_x, ovr->crtc_y, ovr->x, ovr->y,
446 ovr->gamma_size, ovr->possible_crtcs);
448 if (!ovr->count_formats)
452 for (j = 0; j < ovr->count_formats; j++)
453 printf(" %4.4s", (char *)&ovr->formats[j]);
458 for (j = 0; j < plane->props->count_props; j++)
459 dump_prop(plane->props_info[j],
460 plane->props->props[j],
461 plane->props->prop_values[j]);
463 printf(" no properties found\n");
471 static void free_resources(struct resources *res)
476 #define free_resource(_res, __res, type, Type) \
479 if (!(_res)->type##s) \
481 for (i = 0; i < (int)(_res)->__res->count_##type##s; ++i) { \
482 if (!(_res)->type##s[i].type) \
484 drmModeFree##Type((_res)->type##s[i].type); \
486 free((_res)->type##s); \
489 #define free_properties(_res, __res, type) \
492 for (i = 0; i < (int)(_res)->__res->count_##type##s; ++i) { \
493 drmModeFreeObjectProperties(res->type##s[i].props); \
494 free(res->type##s[i].props_info); \
499 free_properties(res, res, crtc);
501 free_resource(res, res, crtc, Crtc);
502 free_resource(res, res, encoder, Encoder);
503 free_resource(res, res, connector, Connector);
504 free_resource(res, res, fb, FB);
506 drmModeFreeResources(res->res);
509 if (res->plane_res) {
510 free_properties(res, plane_res, plane);
512 free_resource(res, plane_res, plane, Plane);
514 drmModeFreePlaneResources(res->plane_res);
520 static struct resources *get_resources(int fd)
522 struct resources *res;
524 res = malloc(sizeof *res);
528 memset(res, 0, sizeof *res);
530 res->res = drmModeGetResources(fd);
532 fprintf(stderr, "drmModeGetResources failed: %s\n",
537 res->crtcs = malloc(res->res->count_crtcs * sizeof *res->crtcs);
538 res->encoders = malloc(res->res->count_encoders * sizeof *res->encoders);
539 res->connectors = malloc(res->res->count_connectors * sizeof *res->connectors);
540 res->fbs = malloc(res->res->count_fbs * sizeof *res->fbs);
542 if (!res->crtcs || !res->encoders || !res->connectors || !res->fbs)
545 memset(res->crtcs , 0, res->res->count_crtcs * sizeof *res->crtcs);
546 memset(res->encoders, 0, res->res->count_encoders * sizeof *res->encoders);
547 memset(res->connectors, 0, res->res->count_connectors * sizeof *res->connectors);
548 memset(res->fbs, 0, res->res->count_fbs * sizeof *res->fbs);
550 #define get_resource(_res, __res, type, Type) \
553 for (i = 0; i < (int)(_res)->__res->count_##type##s; ++i) { \
554 (_res)->type##s[i].type = \
555 drmModeGet##Type(fd, (_res)->__res->type##s[i]); \
556 if (!(_res)->type##s[i].type) \
557 fprintf(stderr, "could not get %s %i: %s\n", \
558 #type, (_res)->__res->type##s[i], \
563 get_resource(res, res, crtc, Crtc);
564 get_resource(res, res, encoder, Encoder);
565 get_resource(res, res, connector, Connector);
566 get_resource(res, res, fb, FB);
568 #define get_properties(_res, __res, type, Type) \
571 for (i = 0; i < (int)(_res)->__res->count_##type##s; ++i) { \
572 struct type *obj = &res->type##s[i]; \
575 drmModeObjectGetProperties(fd, obj->type->type##_id, \
576 DRM_MODE_OBJECT_##Type); \
579 "could not get %s %i properties: %s\n", \
580 #type, obj->type->type##_id, \
584 obj->props_info = malloc(obj->props->count_props * \
585 sizeof *obj->props_info); \
586 if (!obj->props_info) \
588 for (j = 0; j < obj->props->count_props; ++j) \
589 obj->props_info[j] = \
590 drmModeGetProperty(fd, obj->props->props[j]); \
594 get_properties(res, res, crtc, CRTC);
595 get_properties(res, res, connector, CONNECTOR);
597 res->plane_res = drmModeGetPlaneResources(fd);
598 if (!res->plane_res) {
599 fprintf(stderr, "drmModeGetPlaneResources failed: %s\n",
604 res->planes = malloc(res->plane_res->count_planes * sizeof *res->planes);
608 memset(res->planes, 0, res->plane_res->count_planes * sizeof *res->planes);
610 get_resource(res, plane_res, plane, Plane);
611 get_properties(res, plane_res, plane, PLANE);
620 /* -----------------------------------------------------------------------------
621 * Connectors and planes
625 * Mode setting with the kernel interfaces is a bit of a chore.
626 * First you have to find the connector in question and make sure the
627 * requested mode is available.
628 * Then you need to find the encoder attached to that connector so you
629 * can bind it with a free crtc.
631 struct connector_arg {
636 drmModeModeInfo *mode;
637 drmModeEncoder *encoder;
640 unsigned int fb_id[2], current_fb_id;
641 struct timeval start;
647 uint32_t con_id; /* the id of connector to bind to */
650 char format_str[5]; /* need to leave room for terminating \0 */
655 connector_find_mode(struct connector_arg *c)
657 drmModeConnector *connector;
660 /* First, find the connector & mode */
662 for (i = 0; i < resources->res->count_connectors; i++) {
663 connector = resources->connectors[i].connector;
667 if (!connector->count_modes)
670 if (connector->connector_id != c->id)
673 for (j = 0; j < connector->count_modes; j++) {
674 c->mode = &connector->modes[j];
675 if (!strcmp(c->mode->name, c->mode_str))
679 /* Found it, break out */
685 fprintf(stderr, "failed to find mode \"%s\"\n", c->mode_str);
689 /* Now get the encoder */
690 for (i = 0; i < resources->res->count_encoders; i++) {
691 c->encoder = resources->encoders[i].encoder;
695 if (c->encoder->encoder_id == connector->encoder_id)
700 c->crtc = c->encoder->crtc_id;
702 /* and figure out which crtc index it is: */
703 for (i = 0; i < resources->res->count_crtcs; i++) {
704 if (c->crtc == (int)resources->res->crtcs[i]) {
712 /* -------------------------------------------------------------------------- */
715 page_flip_handler(int fd, unsigned int frame,
716 unsigned int sec, unsigned int usec, void *data)
718 struct connector_arg *c;
719 unsigned int new_fb_id;
724 if (c->current_fb_id == c->fb_id[0])
725 new_fb_id = c->fb_id[1];
727 new_fb_id = c->fb_id[0];
729 drmModePageFlip(fd, c->crtc, new_fb_id,
730 DRM_MODE_PAGE_FLIP_EVENT, c);
731 c->current_fb_id = new_fb_id;
733 if (c->swap_count == 60) {
734 gettimeofday(&end, NULL);
735 t = end.tv_sec + end.tv_usec * 1e-6 -
736 (c->start.tv_sec + c->start.tv_usec * 1e-6);
737 fprintf(stderr, "freq: %.02fHz\n", c->swap_count / t);
744 set_plane(struct kms_driver *kms, struct connector_arg *c, struct plane_arg *p)
747 uint32_t handles[4], pitches[4], offsets[4] = {0}; /* we only use [0] */
748 uint32_t plane_id = 0;
749 struct kms_bo *plane_bo;
750 uint32_t plane_flags = 0;
751 int crtc_x, crtc_y, crtc_w, crtc_h;
754 /* find an unused plane which can be connected to our crtc */
755 for (i = 0; i < resources->plane_res->count_planes && !plane_id; i++) {
756 ovr = resources->planes[i].plane;
760 if ((ovr->possible_crtcs & (1 << c->pipe)) && !ovr->crtc_id)
761 plane_id = ovr->plane_id;
764 fprintf(stderr, "testing %dx%d@%s overlay plane\n",
765 p->w, p->h, p->format_str);
768 fprintf(stderr, "failed to find plane!\n");
772 plane_bo = create_test_buffer(kms, p->fourcc, p->w, p->h, handles,
773 pitches, offsets, PATTERN_TILES);
774 if (plane_bo == NULL)
777 /* just use single plane format for now.. */
778 if (drmModeAddFB2(fd, p->w, p->h, p->fourcc,
779 handles, pitches, offsets, &p->fb_id, plane_flags)) {
780 fprintf(stderr, "failed to add fb: %s\n", strerror(errno));
784 /* ok, boring.. but for now put in middle of screen: */
785 crtc_x = c->mode->hdisplay / 3;
786 crtc_y = c->mode->vdisplay / 3;
790 /* note src coords (last 4 args) are in Q16 format */
791 if (drmModeSetPlane(fd, plane_id, c->crtc, p->fb_id,
792 plane_flags, crtc_x, crtc_y, crtc_w, crtc_h,
793 0, 0, p->w << 16, p->h << 16)) {
794 fprintf(stderr, "failed to enable plane: %s\n",
799 ovr->crtc_id = c->crtc;
805 set_mode(struct connector_arg *c, int count, struct plane_arg *p, int plane_count,
808 struct kms_driver *kms;
809 struct kms_bo *bo, *other_bo;
810 unsigned int fb_id, other_fb_id;
811 int i, j, ret, width, height, x;
812 uint32_t handles[4], pitches[4], offsets[4] = {0}; /* we only use [0] */
813 drmEventContext evctx;
817 for (i = 0; i < count; i++) {
818 connector_find_mode(&c[i]);
819 if (c[i].mode == NULL)
821 width += c[i].mode->hdisplay;
822 if (height < c[i].mode->vdisplay)
823 height = c[i].mode->vdisplay;
826 ret = kms_create(fd, &kms);
828 fprintf(stderr, "failed to create kms driver: %s\n",
833 bo = create_test_buffer(kms, c->fourcc, width, height, handles,
834 pitches, offsets, PATTERN_SMPTE);
838 ret = drmModeAddFB2(fd, width, height, c->fourcc,
839 handles, pitches, offsets, &fb_id, 0);
841 fprintf(stderr, "failed to add fb (%ux%u): %s\n",
842 width, height, strerror(errno));
847 for (i = 0; i < count; i++) {
848 if (c[i].mode == NULL)
851 printf("setting mode %s@%s on connector %d, crtc %d\n",
852 c[i].mode_str, c[i].format_str, c[i].id, c[i].crtc);
854 ret = drmModeSetCrtc(fd, c[i].crtc, fb_id, x, 0,
855 &c[i].id, 1, c[i].mode);
857 /* XXX: Actually check if this is needed */
858 drmModeDirtyFB(fd, fb_id, NULL, 0);
860 x += c[i].mode->hdisplay;
863 fprintf(stderr, "failed to set mode: %s\n", strerror(errno));
867 /* if we have a plane/overlay to show, set that up now: */
868 for (j = 0; j < plane_count; j++)
869 if (p[j].con_id == c[i].id)
870 if (set_plane(kms, &c[i], &p[j]))
877 other_bo = create_test_buffer(kms, c->fourcc, width, height, handles,
878 pitches, offsets, PATTERN_PLAIN);
879 if (other_bo == NULL)
882 ret = drmModeAddFB2(fd, width, height, c->fourcc, handles, pitches, offsets,
885 fprintf(stderr, "failed to add fb: %s\n", strerror(errno));
889 for (i = 0; i < count; i++) {
890 if (c[i].mode == NULL)
893 ret = drmModePageFlip(fd, c[i].crtc, other_fb_id,
894 DRM_MODE_PAGE_FLIP_EVENT, &c[i]);
896 fprintf(stderr, "failed to page flip: %s\n", strerror(errno));
899 gettimeofday(&c[i].start, NULL);
901 c[i].fb_id[0] = fb_id;
902 c[i].fb_id[1] = other_fb_id;
903 c[i].current_fb_id = other_fb_id;
906 memset(&evctx, 0, sizeof evctx);
907 evctx.version = DRM_EVENT_CONTEXT_VERSION;
908 evctx.vblank_handler = NULL;
909 evctx.page_flip_handler = page_flip_handler;
913 struct pollfd pfd[2];
916 pfd[0].events = POLLIN;
918 pfd[1].events = POLLIN;
920 if (poll(pfd, 2, -1) < 0) {
921 fprintf(stderr, "poll error\n");
928 struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
935 ret = select(fd + 1, &fds, NULL, NULL, &timeout);
938 fprintf(stderr, "select timed out or error (ret %d)\n",
941 } else if (FD_ISSET(0, &fds)) {
946 drmHandleEvent(fd, &evctx);
950 kms_bo_destroy(&other_bo);
954 #define min(a, b) ((a) < (b) ? (a) : (b))
956 static int parse_connector(struct connector_arg *c, const char *arg)
963 strcpy(c->format_str, "XR24");
965 c->id = strtoul(arg, &endp, 10);
968 c->crtc = strtoul(arg, &endp, 10);
975 p = strchrnul(arg, '@');
976 len = min(sizeof c->mode_str - 1, (unsigned int)(p - arg));
977 strncpy(c->mode_str, arg, len);
978 c->mode_str[len] = '\0';
981 strncpy(c->format_str, p + 1, 4);
982 c->format_str[4] = '\0';
985 c->fourcc = format_fourcc(c->format_str);
986 if (c->fourcc == 0) {
987 fprintf(stderr, "unknown format %s\n", c->format_str);
994 static int parse_plane(struct plane_arg *p, const char *arg)
996 strcpy(p->format_str, "XR24");
998 if (sscanf(arg, "%d:%dx%d@%4s", &p->con_id, &p->w, &p->h, p->format_str) != 4 &&
999 sscanf(arg, "%d:%dx%d", &p->con_id, &p->w, &p->h) != 3)
1002 p->fourcc = format_fourcc(p->format_str);
1003 if (p->fourcc == 0) {
1004 fprintf(stderr, "unknown format %s\n", p->format_str);
1011 static void usage(char *name)
1013 fprintf(stderr, "usage: %s [-cdefMmPpsv]\n", name);
1015 fprintf(stderr, "\n Query options:\n\n");
1016 fprintf(stderr, "\t-c\tlist connectors\n");
1017 fprintf(stderr, "\t-e\tlist encoders\n");
1018 fprintf(stderr, "\t-f\tlist framebuffers\n");
1019 fprintf(stderr, "\t-m\tlist modes\n");
1020 fprintf(stderr, "\t-p\tlist CRTCs and planes (pipes)\n");
1022 fprintf(stderr, "\n Test options:\n\n");
1023 fprintf(stderr, "\t-P <connector_id>:<w>x<h>[@<format>]\tset a plane\n");
1024 fprintf(stderr, "\t-s <connector_id>[@<crtc_id>]:<mode>[@<format>]\tset a mode\n");
1025 fprintf(stderr, "\t-v\ttest vsynced page flipping\n");
1027 fprintf(stderr, "\n Generic options:\n\n");
1028 fprintf(stderr, "\t-d\tdrop master after mode set\n");
1029 fprintf(stderr, "\t-M module\tuse the given driver\n");
1031 fprintf(stderr, "\n\tDefault is to dump all info.\n");
1035 #define dump_resource(res) if (res) dump_##res()
1037 static int page_flipping_supported(void)
1039 /*FIXME: generic ioctl needed? */
1043 struct drm_i915_getparam gp;
1045 gp.param = I915_PARAM_HAS_PAGEFLIPPING;
1048 ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
1050 fprintf(stderr, "drm_i915_getparam: %m\n");
1058 static char optstr[] = "cdefM:mP:ps:v";
1060 int main(int argc, char **argv)
1063 int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0;
1064 int drop_master = 0;
1066 const char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "tilcdc" };
1067 char *module = NULL;
1069 int count = 0, plane_count = 0;
1070 struct connector_arg con_args[2];
1071 struct plane_arg plane_args[2] = { { 0, }, };
1072 unsigned int args = 0;
1075 while ((c = getopt(argc, argv, optstr)) != -1) {
1093 /* Preserve the default behaviour of dumping all information. */
1100 if (parse_plane(&plane_args[plane_count], optarg) < 0)
1109 if (parse_connector(&con_args[count], optarg) < 0)
1123 encoders = connectors = crtcs = planes = modes = framebuffers = 1;
1126 fd = drmOpen(module, NULL);
1128 fprintf(stderr, "failed to open device '%s'.\n", module);
1132 for (i = 0; i < ARRAY_SIZE(modules); i++) {
1133 printf("trying to open device '%s'...", modules[i]);
1134 fd = drmOpen(modules[i], NULL);
1136 printf("failed.\n");
1138 printf("success.\n");
1144 fprintf(stderr, "no device found.\n");
1149 if (test_vsync && !page_flipping_supported()) {
1150 fprintf(stderr, "page flipping not supported by drm.\n");
1154 resources = get_resources(fd);
1160 dump_resource(encoders);
1161 dump_resource(connectors);
1162 dump_resource(crtcs);
1163 dump_resource(planes);
1164 dump_resource(framebuffers);
1167 set_mode(con_args, count, plane_args, plane_count, test_vsync);
1173 free_resources(resources);