10 #include "xf86drmMode.h"
22 const char* getConnectionText(drmModeConnection conn)
25 case DRM_MODE_CONNECTED:
27 case DRM_MODE_DISCONNECTED:
28 return "disconnected";
35 int printMode(struct drm_mode_modeinfo *mode)
38 printf("Mode: %s\n", mode->name);
39 printf("\tclock : %i\n", mode->clock);
40 printf("\thdisplay : %i\n", mode->hdisplay);
41 printf("\thsync_start : %i\n", mode->hsync_start);
42 printf("\thsync_end : %i\n", mode->hsync_end);
43 printf("\thtotal : %i\n", mode->htotal);
44 printf("\thskew : %i\n", mode->hskew);
45 printf("\tvdisplay : %i\n", mode->vdisplay);
46 printf("\tvsync_start : %i\n", mode->vsync_start);
47 printf("\tvsync_end : %i\n", mode->vsync_end);
48 printf("\tvtotal : %i\n", mode->vtotal);
49 printf("\tvscan : %i\n", mode->vscan);
50 printf("\tvrefresh : %i\n", mode->vrefresh);
51 printf("\tflags : %i\n", mode->flags);
53 printf("Mode: \"%s\" %ix%i %.0f\n", mode->name,
54 mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0);
59 int printProperty(int fd, drmModeResPtr res, drmModePropertyPtr props, uint64_t value)
61 const unsigned char *name = NULL;
64 printf("Property: %s\n", props->name);
65 printf("\tid : %i\n", props->prop_id);
66 printf("\tflags : %i\n", props->flags);
67 printf("\tcount_values : %d\n", props->count_values);
70 if (props->count_values) {
72 for (j = 0; j < props->count_values; j++)
73 printf(" %lld", props->values[j]);
78 printf("\tcount_enums : %d\n", props->count_enums);
80 if (props->flags & DRM_MODE_PROP_BLOB) {
81 drmModePropertyBlobPtr blob;
83 blob = drmModeGetPropertyBlob(fd, value);
85 printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data);
86 drmModeFreePropertyBlob(blob);
88 printf("error getting blob %lld\n", value);
92 if (!strncmp(props->name, "DPMS", 4))
95 for (j = 0; j < props->count_enums; j++) {
96 printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name);
97 if (props->enums[j].value == value)
98 name = props->enums[j].name;
101 if (props->count_enums && name) {
102 printf("\tcon_value : %s\n", name);
104 printf("\tcon_value : %lld\n", value);
111 int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id)
114 struct drm_mode_modeinfo *mode = NULL;
115 drmModePropertyPtr props;
117 printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id);
118 printf("\tid : %i\n", id);
119 printf("\tencoder id : %i\n", connector->encoder_id);
120 printf("\tconn : %s\n", getConnectionText(connector->connection));
121 printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight);
122 printf("\tcount_modes : %i\n", connector->count_modes);
123 printf("\tcount_props : %i\n", connector->count_props);
124 if (connector->count_props) {
126 for (i = 0; i < connector->count_props; i++)
127 printf(" %i", connector->props[i]);
131 printf("\tcount_encoders : %i\n", connector->count_encoders);
132 if (connector->count_encoders) {
133 printf("\tencoders :");
134 for (i = 0; i < connector->count_encoders; i++)
135 printf(" %i", connector->encoders[i]);
140 for (i = 0; i < connector->count_modes; i++) {
141 mode = &connector->modes[i];
147 for (i = 0; i < connector->count_props; i++) {
148 props = drmModeGetProperty(fd, connector->props[i]);
150 printProperty(fd, res, props, connector->prop_values[i]);
151 drmModeFreeProperty(props);
159 int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id)
162 printf("\tid :%i\n", id);
163 printf("\tcrtc_id :%d\n", encoder->crtc_id);
164 printf("\ttype :%d\n", encoder->encoder_type);
165 printf("\tpossible_crtcs :%d\n", encoder->possible_crtcs);
166 printf("\tpossible_clones :%d\n", encoder->possible_clones);
170 int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
173 printf("\tid : %i\n", id);
174 printf("\tx : %i\n", crtc->x);
175 printf("\ty : %i\n", crtc->y);
176 printf("\twidth : %i\n", crtc->width);
177 printf("\theight : %i\n", crtc->height);
178 printf("\tmode : %p\n", &crtc->mode);
179 printf("\tgamma size : %d\n", crtc->gamma_size);
184 int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb)
186 printf("Framebuffer\n");
187 printf("\thandle : %i\n", fb->handle);
188 printf("\twidth : %i\n", fb->width);
189 printf("\theight : %i\n", fb->height);
190 printf("\tpitch : %i\n", fb->pitch);;
191 printf("\tbpp : %i\n", fb->bpp);
192 printf("\tdepth : %i\n", fb->depth);
193 printf("\tbuffer_id : %i\n", fb->buffer_id);
198 int printRes(int fd, drmModeResPtr res)
203 drmModeEncoderPtr encoder;
204 drmModeConnectorPtr connector;
206 printf("Resources\n\n");
208 printf("count_connectors : %i\n", res->count_connectors);
209 printf("count_encoders : %i\n", res->count_encoders);
210 printf("count_crtcs : %i\n", res->count_crtcs);
211 printf("count_fbs : %i\n", res->count_fbs);
216 for (i = 0; i < res->count_connectors; i++) {
217 connector = drmModeGetConnector(fd, res->connectors[i]);
220 printf("Could not get connector %i\n", res->connectors[i]);
222 printConnector(fd, res, connector, res->connectors[i]);
223 drmModeFreeConnector(connector);
231 for (i = 0; i < res->count_encoders; i++) {
232 encoder = drmModeGetEncoder(fd, res->encoders[i]);
235 printf("Could not get encoder %i\n", res->encoders[i]);
237 printEncoder(fd, res, encoder, res->encoders[i]);
238 drmModeFreeEncoder(encoder);
245 for (i = 0; i < res->count_crtcs; i++) {
246 crtc = drmModeGetCrtc(fd, res->crtcs[i]);
249 printf("Could not get crtc %i\n", res->crtcs[i]);
251 printCrtc(fd, res, crtc, res->crtcs[i]);
252 drmModeFreeCrtc(crtc);
259 for (i = 0; i < res->count_fbs; i++) {
260 fb = drmModeGetFB(fd, res->fbs[i]);
263 printf("Could not get fb %i\n", res->fbs[i]);
265 printFrameBuffer(fd, res, fb);
274 void args(int argc, char **argv)
287 module_name = argv[1];
289 for (i = 2; i < argc; i++) {
290 if (strcmp(argv[i], "-fb") == 0) {
292 } else if (strcmp(argv[i], "-crtcs") == 0) {
294 } else if (strcmp(argv[i], "-cons") == 0) {
297 } else if (strcmp(argv[i], "-modes") == 0) {
300 } else if (strcmp(argv[i], "-full") == 0) {
304 } else if (strcmp(argv[i], "-props") == 0) {
307 } else if (strcmp(argv[i], "-edids") == 0) {
310 } else if (strcmp(argv[i], "-encoders") == 0) {
312 } else if (strcmp(argv[i], "-v") == 0) {
336 int main(int argc, char **argv)
342 printf("Please add modulename as first argument\n");
348 printf("Starting test\n");
350 fd = drmOpen(module_name, NULL);
353 printf("Failed to open the card fd (%d)\n",fd);
357 res = drmModeGetResources(fd);
359 printf("Failed to get resources from card\n");
366 drmModeFreeResources(res);