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 #include "util/common.h"
58 static int printMode(struct drm_mode_modeinfo
*mode
)
61 printf("Mode: %s\n", mode
->name
);
62 printf("\tclock : %i\n", mode
->clock
);
63 printf("\thdisplay : %i\n", mode
->hdisplay
);
64 printf("\thsync_start : %i\n", mode
->hsync_start
);
65 printf("\thsync_end : %i\n", mode
->hsync_end
);
66 printf("\thtotal : %i\n", mode
->htotal
);
67 printf("\thskew : %i\n", mode
->hskew
);
68 printf("\tvdisplay : %i\n", mode
->vdisplay
);
69 printf("\tvsync_start : %i\n", mode
->vsync_start
);
70 printf("\tvsync_end : %i\n", mode
->vsync_end
);
71 printf("\tvtotal : %i\n", mode
->vtotal
);
72 printf("\tvscan : %i\n", mode
->vscan
);
73 printf("\tvrefresh : %i\n", mode
->vrefresh
);
74 printf("\tflags : %i\n", mode
->flags
);
76 printf("Mode: \"%s\" %ix%i %i\n", mode
->name
,
77 mode
->hdisplay
, mode
->vdisplay
, mode
->vrefresh
);
82 static int printProperty(int fd
, drmModeResPtr res
, drmModePropertyPtr props
, uint64_t value
)
84 const char *name
= NULL
;
87 printf("Property: %s\n", props
->name
);
88 printf("\tid : %i\n", props
->prop_id
);
89 printf("\tflags : %i\n", props
->flags
);
90 printf("\tcount_values : %d\n", props
->count_values
);
93 if (props
->count_values
) {
95 for (j
= 0; j
< props
->count_values
; j
++)
96 printf(" %" PRIu64
, props
->values
[j
]);
101 printf("\tcount_enums : %d\n", props
->count_enums
);
103 if (props
->flags
& DRM_MODE_PROP_BLOB
) {
104 drmModePropertyBlobPtr blob
;
106 blob
= drmModeGetPropertyBlob(fd
, value
);
108 printf("blob is %d length, %08X\n", blob
->length
, *(uint32_t *)blob
->data
);
109 drmModeFreePropertyBlob(blob
);
111 printf("error getting blob %" PRIu64
"\n", value
);
115 for (j
= 0; j
< props
->count_enums
; j
++) {
116 printf("\t\t%" PRIu64
" = %s\n", (uint64_t)props
->enums
[j
].value
, props
->enums
[j
].name
);
117 if (props
->enums
[j
].value
== value
)
118 name
= props
->enums
[j
].name
;
121 if (props
->count_enums
&& name
) {
122 printf("\tcon_value : %s\n", name
);
124 printf("\tcon_value : %" PRIu64
"\n", value
);
131 static int printConnector(int fd
, drmModeResPtr res
, drmModeConnectorPtr connector
, uint32_t id
)
134 struct drm_mode_modeinfo
*mode
= NULL
;
135 drmModePropertyPtr props
;
136 const char *connector_type_name
= NULL
;
138 connector_type_name
= drmModeGetConnectorTypeName(connector
->connector_type
);
140 if (connector_type_name
)
141 printf("Connector: %s-%d\n", connector_type_name
,
142 connector
->connector_type_id
);
144 printf("Connector: %d-%d\n", connector
->connector_type
,
145 connector
->connector_type_id
);
146 printf("\tid : %i\n", id
);
147 printf("\tencoder id : %i\n", connector
->encoder_id
);
148 printf("\tconn : %s\n", util_lookup_connector_status_name(connector
->connection
));
149 printf("\tsize : %ix%i (mm)\n", connector
->mmWidth
, connector
->mmHeight
);
150 printf("\tcount_modes : %i\n", connector
->count_modes
);
151 printf("\tcount_props : %i\n", connector
->count_props
);
152 if (connector
->count_props
) {
154 for (i
= 0; i
< connector
->count_props
; i
++)
155 printf(" %i", connector
->props
[i
]);
159 printf("\tcount_encoders : %i\n", connector
->count_encoders
);
160 if (connector
->count_encoders
) {
161 printf("\tencoders :");
162 for (i
= 0; i
< connector
->count_encoders
; i
++)
163 printf(" %i", connector
->encoders
[i
]);
168 for (i
= 0; i
< connector
->count_modes
; i
++) {
169 mode
= (struct drm_mode_modeinfo
*)&connector
->modes
[i
];
175 for (i
= 0; i
< connector
->count_props
; i
++) {
176 props
= drmModeGetProperty(fd
, connector
->props
[i
]);
178 printProperty(fd
, res
, props
, connector
->prop_values
[i
]);
179 drmModeFreeProperty(props
);
187 static int printEncoder(int fd
, drmModeResPtr res
, drmModeEncoderPtr encoder
, uint32_t id
)
189 const char *encoder_name
;
191 encoder_name
= util_lookup_encoder_type_name(encoder
->encoder_type
);
193 printf("Encoder: %s\n", encoder_name
);
196 printf("\tid :%i\n", id
);
197 printf("\tcrtc_id :%d\n", encoder
->crtc_id
);
198 printf("\ttype :%d\n", encoder
->encoder_type
);
199 printf("\tpossible_crtcs :0x%x\n", encoder
->possible_crtcs
);
200 printf("\tpossible_clones :0x%x\n", encoder
->possible_clones
);
204 static int printCrtc(int fd
, drmModeResPtr res
, drmModeCrtcPtr crtc
, uint32_t id
)
207 printf("\tid : %i\n", id
);
208 printf("\tx : %i\n", crtc
->x
);
209 printf("\ty : %i\n", crtc
->y
);
210 printf("\twidth : %i\n", crtc
->width
);
211 printf("\theight : %i\n", crtc
->height
);
212 printf("\tmode : %p\n", &crtc
->mode
);
213 printf("\tgamma size : %d\n", crtc
->gamma_size
);
218 static int printFrameBuffer(int fd
, drmModeResPtr res
, drmModeFBPtr fb
)
220 printf("Framebuffer\n");
221 printf("\thandle : %i\n", fb
->handle
);
222 printf("\twidth : %i\n", fb
->width
);
223 printf("\theight : %i\n", fb
->height
);
224 printf("\tpitch : %i\n", fb
->pitch
);
225 printf("\tbpp : %i\n", fb
->bpp
);
226 printf("\tdepth : %i\n", fb
->depth
);
227 printf("\tbuffer_id : %i\n", fb
->handle
);
232 static int printRes(int fd
, drmModeResPtr res
)
237 drmModeEncoderPtr encoder
;
238 drmModeConnectorPtr connector
;
240 printf("Resources\n\n");
242 printf("count_connectors : %i\n", res
->count_connectors
);
243 printf("count_encoders : %i\n", res
->count_encoders
);
244 printf("count_crtcs : %i\n", res
->count_crtcs
);
245 printf("count_fbs : %i\n", res
->count_fbs
);
250 for (i
= 0; i
< res
->count_connectors
; i
++) {
251 connector
= (current
? drmModeGetConnectorCurrent
: drmModeGetConnector
) (fd
, res
->connectors
[i
]);
254 printf("Could not get connector %i\n", res
->connectors
[i
]);
256 printConnector(fd
, res
, connector
, res
->connectors
[i
]);
257 drmModeFreeConnector(connector
);
265 for (i
= 0; i
< res
->count_encoders
; i
++) {
266 encoder
= drmModeGetEncoder(fd
, res
->encoders
[i
]);
269 printf("Could not get encoder %i\n", res
->encoders
[i
]);
271 printEncoder(fd
, res
, encoder
, res
->encoders
[i
]);
272 drmModeFreeEncoder(encoder
);
279 for (i
= 0; i
< res
->count_crtcs
; i
++) {
280 crtc
= drmModeGetCrtc(fd
, res
->crtcs
[i
]);
283 printf("Could not get crtc %i\n", res
->crtcs
[i
]);
285 printCrtc(fd
, res
, crtc
, res
->crtcs
[i
]);
286 drmModeFreeCrtc(crtc
);
293 for (i
= 0; i
< res
->count_fbs
; i
++) {
294 fb
= drmModeGetFB(fd
, res
->fbs
[i
]);
297 printf("Could not get fb %i\n", res
->fbs
[i
]);
299 printFrameBuffer(fd
, res
, fb
);
308 static void args(int argc
, char **argv
)
323 module_name
= argv
[1];
325 for (i
= 2; i
< argc
; i
++) {
326 if (strcmp(argv
[i
], "-fb") == 0) {
329 } else if (strcmp(argv
[i
], "-crtcs") == 0) {
332 } else if (strcmp(argv
[i
], "-cons") == 0) {
336 } else if (strcmp(argv
[i
], "-modes") == 0) {
340 } else if (strcmp(argv
[i
], "-full") == 0) {
345 } else if (strcmp(argv
[i
], "-props") == 0) {
349 } else if (strcmp(argv
[i
], "-edids") == 0) {
353 } else if (strcmp(argv
[i
], "-encoders") == 0) {
356 } else if (strcmp(argv
[i
], "-v") == 0) {
366 } else if (strcmp(argv
[i
], "-current") == 0) {
383 int main(int argc
, char **argv
)
389 printf("Please add modulename as first argument\n");
395 printf("Starting test\n");
397 fd
= drmOpen(module_name
, NULL
);
400 printf("Failed to open the card fd (%d)\n",fd
);
404 res
= drmModeGetResources(fd
);
406 printf("Failed to get resources from card\n");
413 drmModeFreeResources(res
);