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
41 #include "xf86drmMode.h"
53 const char* getConnectionText(drmModeConnection conn
)
56 case DRM_MODE_CONNECTED
:
58 case DRM_MODE_DISCONNECTED
:
59 return "disconnected";
66 int printMode(struct drm_mode_modeinfo
*mode
)
69 printf("Mode: %s\n", mode
->name
);
70 printf("\tclock : %i\n", mode
->clock
);
71 printf("\thdisplay : %i\n", mode
->hdisplay
);
72 printf("\thsync_start : %i\n", mode
->hsync_start
);
73 printf("\thsync_end : %i\n", mode
->hsync_end
);
74 printf("\thtotal : %i\n", mode
->htotal
);
75 printf("\thskew : %i\n", mode
->hskew
);
76 printf("\tvdisplay : %i\n", mode
->vdisplay
);
77 printf("\tvsync_start : %i\n", mode
->vsync_start
);
78 printf("\tvsync_end : %i\n", mode
->vsync_end
);
79 printf("\tvtotal : %i\n", mode
->vtotal
);
80 printf("\tvscan : %i\n", mode
->vscan
);
81 printf("\tvrefresh : %i\n", mode
->vrefresh
);
82 printf("\tflags : %i\n", mode
->flags
);
84 printf("Mode: \"%s\" %ix%i %.0f\n", mode
->name
,
85 mode
->hdisplay
, mode
->vdisplay
, mode
->vrefresh
/ 1000.0);
90 int printProperty(int fd
, drmModeResPtr res
, drmModePropertyPtr props
, uint64_t value
)
92 const unsigned char *name
= NULL
;
95 printf("Property: %s\n", props
->name
);
96 printf("\tid : %i\n", props
->prop_id
);
97 printf("\tflags : %i\n", props
->flags
);
98 printf("\tcount_values : %d\n", props
->count_values
);
101 if (props
->count_values
) {
102 printf("\tvalues :");
103 for (j
= 0; j
< props
->count_values
; j
++)
104 printf(" %lld", props
->values
[j
]);
109 printf("\tcount_enums : %d\n", props
->count_enums
);
111 if (props
->flags
& DRM_MODE_PROP_BLOB
) {
112 drmModePropertyBlobPtr blob
;
114 blob
= drmModeGetPropertyBlob(fd
, value
);
116 printf("blob is %d length, %08X\n", blob
->length
, *(uint32_t *)blob
->data
);
117 drmModeFreePropertyBlob(blob
);
119 printf("error getting blob %lld\n", value
);
123 if (!strncmp(props
->name
, "DPMS", 4))
126 for (j
= 0; j
< props
->count_enums
; j
++) {
127 printf("\t\t%lld = %s\n", props
->enums
[j
].value
, props
->enums
[j
].name
);
128 if (props
->enums
[j
].value
== value
)
129 name
= props
->enums
[j
].name
;
132 if (props
->count_enums
&& name
) {
133 printf("\tcon_value : %s\n", name
);
135 printf("\tcon_value : %lld\n", value
);
142 int printConnector(int fd
, drmModeResPtr res
, drmModeConnectorPtr connector
, uint32_t id
)
145 struct drm_mode_modeinfo
*mode
= NULL
;
146 drmModePropertyPtr props
;
148 printf("Connector: %d-%d\n", connector
->connector_type
, connector
->connector_type_id
);
149 printf("\tid : %i\n", id
);
150 printf("\tencoder id : %i\n", connector
->encoder_id
);
151 printf("\tconn : %s\n", getConnectionText(connector
->connection
));
152 printf("\tsize : %ix%i (mm)\n", connector
->mmWidth
, connector
->mmHeight
);
153 printf("\tcount_modes : %i\n", connector
->count_modes
);
154 printf("\tcount_props : %i\n", connector
->count_props
);
155 if (connector
->count_props
) {
157 for (i
= 0; i
< connector
->count_props
; i
++)
158 printf(" %i", connector
->props
[i
]);
162 printf("\tcount_encoders : %i\n", connector
->count_encoders
);
163 if (connector
->count_encoders
) {
164 printf("\tencoders :");
165 for (i
= 0; i
< connector
->count_encoders
; i
++)
166 printf(" %i", connector
->encoders
[i
]);
171 for (i
= 0; i
< connector
->count_modes
; i
++) {
172 mode
= &connector
->modes
[i
];
178 for (i
= 0; i
< connector
->count_props
; i
++) {
179 props
= drmModeGetProperty(fd
, connector
->props
[i
]);
181 printProperty(fd
, res
, props
, connector
->prop_values
[i
]);
182 drmModeFreeProperty(props
);
190 int printEncoder(int fd
, drmModeResPtr res
, drmModeEncoderPtr encoder
, uint32_t id
)
193 printf("\tid :%i\n", id
);
194 printf("\tcrtc_id :%d\n", encoder
->crtc_id
);
195 printf("\ttype :%d\n", encoder
->encoder_type
);
196 printf("\tpossible_crtcs :%d\n", encoder
->possible_crtcs
);
197 printf("\tpossible_clones :%d\n", encoder
->possible_clones
);
201 int printCrtc(int fd
, drmModeResPtr res
, drmModeCrtcPtr crtc
, uint32_t id
)
204 printf("\tid : %i\n", id
);
205 printf("\tx : %i\n", crtc
->x
);
206 printf("\ty : %i\n", crtc
->y
);
207 printf("\twidth : %i\n", crtc
->width
);
208 printf("\theight : %i\n", crtc
->height
);
209 printf("\tmode : %p\n", &crtc
->mode
);
210 printf("\tgamma size : %d\n", crtc
->gamma_size
);
215 int printFrameBuffer(int fd
, drmModeResPtr res
, drmModeFBPtr fb
)
217 printf("Framebuffer\n");
218 printf("\thandle : %i\n", fb
->handle
);
219 printf("\twidth : %i\n", fb
->width
);
220 printf("\theight : %i\n", fb
->height
);
221 printf("\tpitch : %i\n", fb
->pitch
);;
222 printf("\tbpp : %i\n", fb
->bpp
);
223 printf("\tdepth : %i\n", fb
->depth
);
224 printf("\tbuffer_id : %i\n", fb
->handle
);
229 int printRes(int fd
, drmModeResPtr res
)
234 drmModeEncoderPtr encoder
;
235 drmModeConnectorPtr connector
;
237 printf("Resources\n\n");
239 printf("count_connectors : %i\n", res
->count_connectors
);
240 printf("count_encoders : %i\n", res
->count_encoders
);
241 printf("count_crtcs : %i\n", res
->count_crtcs
);
242 printf("count_fbs : %i\n", res
->count_fbs
);
247 for (i
= 0; i
< res
->count_connectors
; i
++) {
248 connector
= drmModeGetConnector(fd
, res
->connectors
[i
]);
251 printf("Could not get connector %i\n", res
->connectors
[i
]);
253 printConnector(fd
, res
, connector
, res
->connectors
[i
]);
254 drmModeFreeConnector(connector
);
262 for (i
= 0; i
< res
->count_encoders
; i
++) {
263 encoder
= drmModeGetEncoder(fd
, res
->encoders
[i
]);
266 printf("Could not get encoder %i\n", res
->encoders
[i
]);
268 printEncoder(fd
, res
, encoder
, res
->encoders
[i
]);
269 drmModeFreeEncoder(encoder
);
276 for (i
= 0; i
< res
->count_crtcs
; i
++) {
277 crtc
= drmModeGetCrtc(fd
, res
->crtcs
[i
]);
280 printf("Could not get crtc %i\n", res
->crtcs
[i
]);
282 printCrtc(fd
, res
, crtc
, res
->crtcs
[i
]);
283 drmModeFreeCrtc(crtc
);
290 for (i
= 0; i
< res
->count_fbs
; i
++) {
291 fb
= drmModeGetFB(fd
, res
->fbs
[i
]);
294 printf("Could not get fb %i\n", res
->fbs
[i
]);
296 printFrameBuffer(fd
, res
, fb
);
305 void args(int argc
, char **argv
)
318 module_name
= argv
[1];
320 for (i
= 2; i
< argc
; i
++) {
321 if (strcmp(argv
[i
], "-fb") == 0) {
323 } else if (strcmp(argv
[i
], "-crtcs") == 0) {
325 } else if (strcmp(argv
[i
], "-cons") == 0) {
328 } else if (strcmp(argv
[i
], "-modes") == 0) {
331 } else if (strcmp(argv
[i
], "-full") == 0) {
335 } else if (strcmp(argv
[i
], "-props") == 0) {
338 } else if (strcmp(argv
[i
], "-edids") == 0) {
341 } else if (strcmp(argv
[i
], "-encoders") == 0) {
343 } else if (strcmp(argv
[i
], "-v") == 0) {
367 int main(int argc
, char **argv
)
373 printf("Please add modulename as first argument\n");
379 printf("Starting test\n");
381 fd
= drmOpen(module_name
, NULL
);
384 printf("Failed to open the card fd (%d)\n",fd
);
388 res
= drmModeGetResources(fd
);
390 printf("Failed to get resources from card\n");
397 drmModeFreeResources(res
);