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"
57 static const char* getConnectionText(drmModeConnection conn)
60 case DRM_MODE_CONNECTED:
62 case DRM_MODE_DISCONNECTED:
63 return "disconnected";
64 case DRM_MODE_UNKNOWNCONNECTION:
71 static int printMode(struct drm_mode_modeinfo *mode)
74 printf("Mode: %s\n", mode->name);
75 printf("\tclock : %i\n", mode->clock);
76 printf("\thdisplay : %i\n", mode->hdisplay);
77 printf("\thsync_start : %i\n", mode->hsync_start);
78 printf("\thsync_end : %i\n", mode->hsync_end);
79 printf("\thtotal : %i\n", mode->htotal);
80 printf("\thskew : %i\n", mode->hskew);
81 printf("\tvdisplay : %i\n", mode->vdisplay);
82 printf("\tvsync_start : %i\n", mode->vsync_start);
83 printf("\tvsync_end : %i\n", mode->vsync_end);
84 printf("\tvtotal : %i\n", mode->vtotal);
85 printf("\tvscan : %i\n", mode->vscan);
86 printf("\tvrefresh : %i\n", mode->vrefresh);
87 printf("\tflags : %i\n", mode->flags);
89 printf("Mode: \"%s\" %ix%i %i\n", mode->name,
90 mode->hdisplay, mode->vdisplay, mode->vrefresh);
95 static int printProperty(int fd, drmModeResPtr res, drmModePropertyPtr props, uint64_t value)
97 const char *name = NULL;
100 printf("Property: %s\n", props->name);
101 printf("\tid : %i\n", props->prop_id);
102 printf("\tflags : %i\n", props->flags);
103 printf("\tcount_values : %d\n", props->count_values);
106 if (props->count_values) {
107 printf("\tvalues :");
108 for (j = 0; j < props->count_values; j++)
109 printf(" %" PRIu64, props->values[j]);
114 printf("\tcount_enums : %d\n", props->count_enums);
116 if (props->flags & DRM_MODE_PROP_BLOB) {
117 drmModePropertyBlobPtr blob;
119 blob = drmModeGetPropertyBlob(fd, value);
121 printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data);
122 drmModeFreePropertyBlob(blob);
124 printf("error getting blob %" PRIu64 "\n", value);
128 for (j = 0; j < props->count_enums; j++) {
129 printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name);
130 if (props->enums[j].value == value)
131 name = props->enums[j].name;
134 if (props->count_enums && name) {
135 printf("\tcon_value : %s\n", name);
137 printf("\tcon_value : %" PRIu64 "\n", value);
144 static const char * const output_names[] = { "None",
163 static int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id)
166 struct drm_mode_modeinfo *mode = NULL;
167 drmModePropertyPtr props;
169 if (connector->connector_type < ARRAY_SIZE(output_names))
170 printf("Connector: %s-%d\n", output_names[connector->connector_type],
171 connector->connector_type_id);
173 printf("Connector: %d-%d\n", connector->connector_type,
174 connector->connector_type_id);
175 printf("\tid : %i\n", id);
176 printf("\tencoder id : %i\n", connector->encoder_id);
177 printf("\tconn : %s\n", getConnectionText(connector->connection));
178 printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight);
179 printf("\tcount_modes : %i\n", connector->count_modes);
180 printf("\tcount_props : %i\n", connector->count_props);
181 if (connector->count_props) {
183 for (i = 0; i < connector->count_props; i++)
184 printf(" %i", connector->props[i]);
188 printf("\tcount_encoders : %i\n", connector->count_encoders);
189 if (connector->count_encoders) {
190 printf("\tencoders :");
191 for (i = 0; i < connector->count_encoders; i++)
192 printf(" %i", connector->encoders[i]);
197 for (i = 0; i < connector->count_modes; i++) {
198 mode = (struct drm_mode_modeinfo *)&connector->modes[i];
204 for (i = 0; i < connector->count_props; i++) {
205 props = drmModeGetProperty(fd, connector->props[i]);
207 printProperty(fd, res, props, connector->prop_values[i]);
208 drmModeFreeProperty(props);
216 static int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id)
219 printf("\tid :%i\n", id);
220 printf("\tcrtc_id :%d\n", encoder->crtc_id);
221 printf("\ttype :%d\n", encoder->encoder_type);
222 printf("\tpossible_crtcs :0x%x\n", encoder->possible_crtcs);
223 printf("\tpossible_clones :0x%x\n", encoder->possible_clones);
227 static int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
230 printf("\tid : %i\n", id);
231 printf("\tx : %i\n", crtc->x);
232 printf("\ty : %i\n", crtc->y);
233 printf("\twidth : %i\n", crtc->width);
234 printf("\theight : %i\n", crtc->height);
235 printf("\tmode : %p\n", &crtc->mode);
236 printf("\tgamma size : %d\n", crtc->gamma_size);
241 static int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb)
243 printf("Framebuffer\n");
244 printf("\thandle : %i\n", fb->handle);
245 printf("\twidth : %i\n", fb->width);
246 printf("\theight : %i\n", fb->height);
247 printf("\tpitch : %i\n", fb->pitch);
248 printf("\tbpp : %i\n", fb->bpp);
249 printf("\tdepth : %i\n", fb->depth);
250 printf("\tbuffer_id : %i\n", fb->handle);
255 static int printRes(int fd, drmModeResPtr res)
260 drmModeEncoderPtr encoder;
261 drmModeConnectorPtr connector;
263 printf("Resources\n\n");
265 printf("count_connectors : %i\n", res->count_connectors);
266 printf("count_encoders : %i\n", res->count_encoders);
267 printf("count_crtcs : %i\n", res->count_crtcs);
268 printf("count_fbs : %i\n", res->count_fbs);
273 for (i = 0; i < res->count_connectors; i++) {
274 connector = (current ? drmModeGetConnectorCurrent : drmModeGetConnector) (fd, res->connectors[i]);
277 printf("Could not get connector %i\n", res->connectors[i]);
279 printConnector(fd, res, connector, res->connectors[i]);
280 drmModeFreeConnector(connector);
288 for (i = 0; i < res->count_encoders; i++) {
289 encoder = drmModeGetEncoder(fd, res->encoders[i]);
292 printf("Could not get encoder %i\n", res->encoders[i]);
294 printEncoder(fd, res, encoder, res->encoders[i]);
295 drmModeFreeEncoder(encoder);
302 for (i = 0; i < res->count_crtcs; i++) {
303 crtc = drmModeGetCrtc(fd, res->crtcs[i]);
306 printf("Could not get crtc %i\n", res->crtcs[i]);
308 printCrtc(fd, res, crtc, res->crtcs[i]);
309 drmModeFreeCrtc(crtc);
316 for (i = 0; i < res->count_fbs; i++) {
317 fb = drmModeGetFB(fd, res->fbs[i]);
320 printf("Could not get fb %i\n", res->fbs[i]);
322 printFrameBuffer(fd, res, fb);
331 static void args(int argc, char **argv)
346 module_name = argv[1];
348 for (i = 2; i < argc; i++) {
349 if (strcmp(argv[i], "-fb") == 0) {
352 } else if (strcmp(argv[i], "-crtcs") == 0) {
355 } else if (strcmp(argv[i], "-cons") == 0) {
359 } else if (strcmp(argv[i], "-modes") == 0) {
363 } else if (strcmp(argv[i], "-full") == 0) {
368 } else if (strcmp(argv[i], "-props") == 0) {
372 } else if (strcmp(argv[i], "-edids") == 0) {
376 } else if (strcmp(argv[i], "-encoders") == 0) {
379 } else if (strcmp(argv[i], "-v") == 0) {
389 } else if (strcmp(argv[i], "-current") == 0) {
406 int main(int argc, char **argv)
412 printf("Please add modulename as first argument\n");
418 printf("Starting test\n");
420 fd = drmOpen(module_name, NULL);
423 printf("Failed to open the card fd (%d)\n",fd);
427 res = drmModeGetResources(fd);
429 printf("Failed to get resources from card\n");
436 drmModeFreeResources(res);