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"
54 const char* getConnectionText(drmModeConnection conn)
57 case DRM_MODE_CONNECTED:
59 case DRM_MODE_DISCONNECTED:
60 return "disconnected";
67 int printMode(struct drm_mode_modeinfo *mode)
70 printf("Mode: %s\n", mode->name);
71 printf("\tclock : %i\n", mode->clock);
72 printf("\thdisplay : %i\n", mode->hdisplay);
73 printf("\thsync_start : %i\n", mode->hsync_start);
74 printf("\thsync_end : %i\n", mode->hsync_end);
75 printf("\thtotal : %i\n", mode->htotal);
76 printf("\thskew : %i\n", mode->hskew);
77 printf("\tvdisplay : %i\n", mode->vdisplay);
78 printf("\tvsync_start : %i\n", mode->vsync_start);
79 printf("\tvsync_end : %i\n", mode->vsync_end);
80 printf("\tvtotal : %i\n", mode->vtotal);
81 printf("\tvscan : %i\n", mode->vscan);
82 printf("\tvrefresh : %i\n", mode->vrefresh);
83 printf("\tflags : %i\n", mode->flags);
85 printf("Mode: \"%s\" %ix%i %i\n", mode->name,
86 mode->hdisplay, mode->vdisplay, mode->vrefresh);
91 int printProperty(int fd, drmModeResPtr res, drmModePropertyPtr props, uint64_t value)
93 const char *name = NULL;
96 printf("Property: %s\n", props->name);
97 printf("\tid : %i\n", props->prop_id);
98 printf("\tflags : %i\n", props->flags);
99 printf("\tcount_values : %d\n", props->count_values);
102 if (props->count_values) {
103 printf("\tvalues :");
104 for (j = 0; j < props->count_values; j++)
105 printf(" %" PRIu64, props->values[j]);
110 printf("\tcount_enums : %d\n", props->count_enums);
112 if (props->flags & DRM_MODE_PROP_BLOB) {
113 drmModePropertyBlobPtr blob;
115 blob = drmModeGetPropertyBlob(fd, value);
117 printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data);
118 drmModeFreePropertyBlob(blob);
120 printf("error getting blob %" PRIu64 "\n", value);
124 if (!strncmp(props->name, "DPMS", 4))
127 for (j = 0; j < props->count_enums; j++) {
128 printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name);
129 if (props->enums[j].value == value)
130 name = props->enums[j].name;
133 if (props->count_enums && name) {
134 printf("\tcon_value : %s\n", name);
136 printf("\tcon_value : %" PRIu64 "\n", value);
143 int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id)
146 struct drm_mode_modeinfo *mode = NULL;
147 drmModePropertyPtr props;
149 printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id);
150 printf("\tid : %i\n", id);
151 printf("\tencoder id : %i\n", connector->encoder_id);
152 printf("\tconn : %s\n", getConnectionText(connector->connection));
153 printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight);
154 printf("\tcount_modes : %i\n", connector->count_modes);
155 printf("\tcount_props : %i\n", connector->count_props);
156 if (connector->count_props) {
158 for (i = 0; i < connector->count_props; i++)
159 printf(" %i", connector->props[i]);
163 printf("\tcount_encoders : %i\n", connector->count_encoders);
164 if (connector->count_encoders) {
165 printf("\tencoders :");
166 for (i = 0; i < connector->count_encoders; i++)
167 printf(" %i", connector->encoders[i]);
172 for (i = 0; i < connector->count_modes; i++) {
173 mode = (struct drm_mode_modeinfo *)&connector->modes[i];
179 for (i = 0; i < connector->count_props; i++) {
180 props = drmModeGetProperty(fd, connector->props[i]);
182 printProperty(fd, res, props, connector->prop_values[i]);
183 drmModeFreeProperty(props);
191 int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id)
194 printf("\tid :%i\n", id);
195 printf("\tcrtc_id :%d\n", encoder->crtc_id);
196 printf("\ttype :%d\n", encoder->encoder_type);
197 printf("\tpossible_crtcs :0x%x\n", encoder->possible_crtcs);
198 printf("\tpossible_clones :0x%x\n", encoder->possible_clones);
202 int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
205 printf("\tid : %i\n", id);
206 printf("\tx : %i\n", crtc->x);
207 printf("\ty : %i\n", crtc->y);
208 printf("\twidth : %i\n", crtc->width);
209 printf("\theight : %i\n", crtc->height);
210 printf("\tmode : %p\n", &crtc->mode);
211 printf("\tgamma size : %d\n", crtc->gamma_size);
216 int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb)
218 printf("Framebuffer\n");
219 printf("\thandle : %i\n", fb->handle);
220 printf("\twidth : %i\n", fb->width);
221 printf("\theight : %i\n", fb->height);
222 printf("\tpitch : %i\n", fb->pitch);;
223 printf("\tbpp : %i\n", fb->bpp);
224 printf("\tdepth : %i\n", fb->depth);
225 printf("\tbuffer_id : %i\n", fb->handle);
230 int printRes(int fd, drmModeResPtr res)
235 drmModeEncoderPtr encoder;
236 drmModeConnectorPtr connector;
238 printf("Resources\n\n");
240 printf("count_connectors : %i\n", res->count_connectors);
241 printf("count_encoders : %i\n", res->count_encoders);
242 printf("count_crtcs : %i\n", res->count_crtcs);
243 printf("count_fbs : %i\n", res->count_fbs);
248 for (i = 0; i < res->count_connectors; i++) {
249 connector = drmModeGetConnector(fd, res->connectors[i]);
252 printf("Could not get connector %i\n", res->connectors[i]);
254 printConnector(fd, res, connector, res->connectors[i]);
255 drmModeFreeConnector(connector);
263 for (i = 0; i < res->count_encoders; i++) {
264 encoder = drmModeGetEncoder(fd, res->encoders[i]);
267 printf("Could not get encoder %i\n", res->encoders[i]);
269 printEncoder(fd, res, encoder, res->encoders[i]);
270 drmModeFreeEncoder(encoder);
277 for (i = 0; i < res->count_crtcs; i++) {
278 crtc = drmModeGetCrtc(fd, res->crtcs[i]);
281 printf("Could not get crtc %i\n", res->crtcs[i]);
283 printCrtc(fd, res, crtc, res->crtcs[i]);
284 drmModeFreeCrtc(crtc);
291 for (i = 0; i < res->count_fbs; i++) {
292 fb = drmModeGetFB(fd, res->fbs[i]);
295 printf("Could not get fb %i\n", res->fbs[i]);
297 printFrameBuffer(fd, res, fb);
306 void args(int argc, char **argv)
319 module_name = argv[1];
321 for (i = 2; i < argc; i++) {
322 if (strcmp(argv[i], "-fb") == 0) {
324 } else if (strcmp(argv[i], "-crtcs") == 0) {
326 } else if (strcmp(argv[i], "-cons") == 0) {
329 } else if (strcmp(argv[i], "-modes") == 0) {
332 } else if (strcmp(argv[i], "-full") == 0) {
336 } else if (strcmp(argv[i], "-props") == 0) {
339 } else if (strcmp(argv[i], "-edids") == 0) {
342 } else if (strcmp(argv[i], "-encoders") == 0) {
344 } else if (strcmp(argv[i], "-v") == 0) {
368 int main(int argc, char **argv)
374 printf("Please add modulename as first argument\n");
380 printf("Starting test\n");
382 fd = drmOpen(module_name, NULL);
385 printf("Failed to open the card fd (%d)\n",fd);
389 res = drmModeGetResources(fd);
391 printf("Failed to get resources from card\n");
398 drmModeFreeResources(res);