3 * Test program to dump DRM kernel mode setting related information.
4 * Queries the kernel for all available information and dumps it to stdout.
6 * \author Jakob Bornecrantz <wallbraker@gmail.com>
10 * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
11 * Copyright (c) 2007-2008 Jakob Bornecrantz <wallbraker@gmail.com>
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
42 #include "xf86drmMode.h"
44 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
56 const char* getConnectionText(drmModeConnection conn)
59 case DRM_MODE_CONNECTED:
61 case DRM_MODE_DISCONNECTED:
62 return "disconnected";
69 int printMode(struct drm_mode_modeinfo *mode)
72 printf("Mode: %s\n", mode->name);
73 printf("\tclock : %i\n", mode->clock);
74 printf("\thdisplay : %i\n", mode->hdisplay);
75 printf("\thsync_start : %i\n", mode->hsync_start);
76 printf("\thsync_end : %i\n", mode->hsync_end);
77 printf("\thtotal : %i\n", mode->htotal);
78 printf("\thskew : %i\n", mode->hskew);
79 printf("\tvdisplay : %i\n", mode->vdisplay);
80 printf("\tvsync_start : %i\n", mode->vsync_start);
81 printf("\tvsync_end : %i\n", mode->vsync_end);
82 printf("\tvtotal : %i\n", mode->vtotal);
83 printf("\tvscan : %i\n", mode->vscan);
84 printf("\tvrefresh : %i\n", mode->vrefresh);
85 printf("\tflags : %i\n", mode->flags);
87 printf("Mode: \"%s\" %ix%i %i\n", mode->name,
88 mode->hdisplay, mode->vdisplay, mode->vrefresh);
93 int printProperty(int fd, drmModeResPtr res, drmModePropertyPtr props, uint64_t value)
95 const char *name = NULL;
98 printf("Property: %s\n", props->name);
99 printf("\tid : %i\n", props->prop_id);
100 printf("\tflags : %i\n", props->flags);
101 printf("\tcount_values : %d\n", props->count_values);
104 if (props->count_values) {
105 printf("\tvalues :");
106 for (j = 0; j < props->count_values; j++)
107 printf(" %" PRIu64, props->values[j]);
112 printf("\tcount_enums : %d\n", props->count_enums);
114 if (props->flags & DRM_MODE_PROP_BLOB) {
115 drmModePropertyBlobPtr blob;
117 blob = drmModeGetPropertyBlob(fd, value);
119 printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data);
120 drmModeFreePropertyBlob(blob);
122 printf("error getting blob %" PRIu64 "\n", value);
126 if (!strncmp(props->name, "DPMS", 4))
129 for (j = 0; j < props->count_enums; j++) {
130 printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name);
131 if (props->enums[j].value == value)
132 name = props->enums[j].name;
135 if (props->count_enums && name) {
136 printf("\tcon_value : %s\n", name);
138 printf("\tcon_value : %" PRIu64 "\n", value);
145 static const char * const output_names[] = { "None",
164 int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id)
167 struct drm_mode_modeinfo *mode = NULL;
168 drmModePropertyPtr props;
170 if (connector->connector_type < ARRAY_SIZE(output_names))
171 printf("Connector: %s-%d\n", output_names[connector->connector_type],
172 connector->connector_type_id);
174 printf("Connector: %d-%d\n", connector->connector_type,
175 connector->connector_type_id);
176 printf("\tid : %i\n", id);
177 printf("\tencoder id : %i\n", connector->encoder_id);
178 printf("\tconn : %s\n", getConnectionText(connector->connection));
179 printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight);
180 printf("\tcount_modes : %i\n", connector->count_modes);
181 printf("\tcount_props : %i\n", connector->count_props);
182 if (connector->count_props) {
184 for (i = 0; i < connector->count_props; i++)
185 printf(" %i", connector->props[i]);
189 printf("\tcount_encoders : %i\n", connector->count_encoders);
190 if (connector->count_encoders) {
191 printf("\tencoders :");
192 for (i = 0; i < connector->count_encoders; i++)
193 printf(" %i", connector->encoders[i]);
198 for (i = 0; i < connector->count_modes; i++) {
199 mode = (struct drm_mode_modeinfo *)&connector->modes[i];
205 for (i = 0; i < connector->count_props; i++) {
206 props = drmModeGetProperty(fd, connector->props[i]);
208 printProperty(fd, res, props, connector->prop_values[i]);
209 drmModeFreeProperty(props);
217 int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id)
220 printf("\tid :%i\n", id);
221 printf("\tcrtc_id :%d\n", encoder->crtc_id);
222 printf("\ttype :%d\n", encoder->encoder_type);
223 printf("\tpossible_crtcs :0x%x\n", encoder->possible_crtcs);
224 printf("\tpossible_clones :0x%x\n", encoder->possible_clones);
228 int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
231 printf("\tid : %i\n", id);
232 printf("\tx : %i\n", crtc->x);
233 printf("\ty : %i\n", crtc->y);
234 printf("\twidth : %i\n", crtc->width);
235 printf("\theight : %i\n", crtc->height);
236 printf("\tmode : %p\n", &crtc->mode);
237 printf("\tgamma size : %d\n", crtc->gamma_size);
242 int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb)
244 printf("Framebuffer\n");
245 printf("\thandle : %i\n", fb->handle);
246 printf("\twidth : %i\n", fb->width);
247 printf("\theight : %i\n", fb->height);
248 printf("\tpitch : %i\n", fb->pitch);;
249 printf("\tbpp : %i\n", fb->bpp);
250 printf("\tdepth : %i\n", fb->depth);
251 printf("\tbuffer_id : %i\n", fb->handle);
256 int printRes(int fd, drmModeResPtr res)
261 drmModeEncoderPtr encoder;
262 drmModeConnectorPtr connector;
264 printf("Resources\n\n");
266 printf("count_connectors : %i\n", res->count_connectors);
267 printf("count_encoders : %i\n", res->count_encoders);
268 printf("count_crtcs : %i\n", res->count_crtcs);
269 printf("count_fbs : %i\n", res->count_fbs);
274 for (i = 0; i < res->count_connectors; i++) {
275 connector = drmModeGetConnector(fd, res->connectors[i]);
278 printf("Could not get connector %i\n", res->connectors[i]);
280 printConnector(fd, res, connector, res->connectors[i]);
281 drmModeFreeConnector(connector);
289 for (i = 0; i < res->count_encoders; i++) {
290 encoder = drmModeGetEncoder(fd, res->encoders[i]);
293 printf("Could not get encoder %i\n", res->encoders[i]);
295 printEncoder(fd, res, encoder, res->encoders[i]);
296 drmModeFreeEncoder(encoder);
303 for (i = 0; i < res->count_crtcs; i++) {
304 crtc = drmModeGetCrtc(fd, res->crtcs[i]);
307 printf("Could not get crtc %i\n", res->crtcs[i]);
309 printCrtc(fd, res, crtc, res->crtcs[i]);
310 drmModeFreeCrtc(crtc);
317 for (i = 0; i < res->count_fbs; i++) {
318 fb = drmModeGetFB(fd, res->fbs[i]);
321 printf("Could not get fb %i\n", res->fbs[i]);
323 printFrameBuffer(fd, res, fb);
332 void args(int argc, char **argv)
345 module_name = argv[1];
347 for (i = 2; i < argc; i++) {
348 if (strcmp(argv[i], "-fb") == 0) {
350 } else if (strcmp(argv[i], "-crtcs") == 0) {
352 } else if (strcmp(argv[i], "-cons") == 0) {
355 } else if (strcmp(argv[i], "-modes") == 0) {
358 } else if (strcmp(argv[i], "-full") == 0) {
362 } else if (strcmp(argv[i], "-props") == 0) {
365 } else if (strcmp(argv[i], "-edids") == 0) {
368 } else if (strcmp(argv[i], "-encoders") == 0) {
370 } else if (strcmp(argv[i], "-v") == 0) {
394 int main(int argc, char **argv)
400 printf("Please add modulename as first argument\n");
406 printf("Starting test\n");
408 fd = drmOpen(module_name, NULL);
411 printf("Failed to open the card fd (%d)\n",fd);
415 res = drmModeGetResources(fd);
417 printf("Failed to get resources from card\n");
424 drmModeFreeResources(res);