10 #include "xf86drmMode.h"
13 const char* getConnectionText(drmModeConnection conn)
16 case DRM_MODE_CONNECTED:
18 case DRM_MODE_DISCONNECTED:
19 return "disconnected";
26 int printMode(struct drm_mode_modeinfo *mode)
29 printf("Mode: %s\n", mode->name);
30 printf("\tclock : %i\n", mode->clock);
31 printf("\thdisplay : %i\n", mode->hdisplay);
32 printf("\thsync_start : %i\n", mode->hsync_start);
33 printf("\thsync_end : %i\n", mode->hsync_end);
34 printf("\thtotal : %i\n", mode->htotal);
35 printf("\thskew : %i\n", mode->hskew);
36 printf("\tvdisplay : %i\n", mode->vdisplay);
37 printf("\tvsync_start : %i\n", mode->vsync_start);
38 printf("\tvsync_end : %i\n", mode->vsync_end);
39 printf("\tvtotal : %i\n", mode->vtotal);
40 printf("\tvscan : %i\n", mode->vscan);
41 printf("\tvrefresh : %i\n", mode->vrefresh);
42 printf("\tflags : %i\n", mode->flags);
44 printf("Mode: \"%s\" %ix%i %.0f\n", mode->name,
45 mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0);
50 int printOutput(int fd, drmModeResPtr res, drmModeOutputPtr output, uint32_t id)
53 struct drm_mode_modeinfo *mode = NULL;
54 drmModePropertyPtr props;
55 unsigned char *name = NULL;
57 printf("Output: %d-%d\n", output->output_type, output->output_type_id);
58 printf("\tid : %i\n", id);
59 printf("\tcrtc id : %i\n", output->crtc);
60 printf("\tconn : %s\n", getConnectionText(output->connection));
61 printf("\tsize : %ix%i (mm)\n", output->mmWidth, output->mmHeight);
62 printf("\tcount_crtcs : %i\n", output->count_crtcs);
63 printf("\tcrtcs : %i\n", output->crtcs);
64 printf("\tcount_clones : %i\n", output->count_clones);
65 printf("\tclones : %i\n", output->clones);
66 printf("\tcount_modes : %i\n", output->count_modes);
67 printf("\tcount_props : %i\n", output->count_props);
69 for (i = 0; i < output->count_props; i++) {
70 props = drmModeGetProperty(fd, output->props[i]);
73 printf("Property: %s\n", props->name);
74 printf("\tid: %i\n", props->prop_id);
75 printf("\tflags: %i\n", props->flags);
76 printf("\tvalues %d: ", props->count_values);
77 for (j = 0; j < props->count_values; j++)
78 printf("%lld ", props->values[j]);
80 printf("\n\tenums %d: \n", props->count_enums);
82 if (props->flags & DRM_MODE_PROP_BLOB) {
83 drmModePropertyBlobPtr blob;
85 blob = drmModeGetPropertyBlob(fd, output->prop_values[i]);
87 printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data);
88 drmModeFreePropertyBlob(blob);
92 if (!strncmp(props->name, "DPMS", 4))
93 dpms_prop_id = props->prop_id;
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 (output->prop_values[i] == props->enums[j].value)
98 name = props->enums[j].name;
102 if (props->count_enums && name) {
103 printf("\toutput property name %s %s\n", props->name, name);
105 printf("\toutput property id %s %lli\n", props->name, output->prop_values[i]);
109 drmModeFreeProperty(props);
113 for (i = 0; i < output->count_modes; i++) {
114 mode = &output->modes[i];
118 printf("\t\tmode: Invalid mode %p\n", &output->modes[i]);
124 int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
127 printf("\tid : %i\n", id);
128 printf("\tx : %i\n", crtc->x);
129 printf("\ty : %i\n", crtc->y);
130 printf("\twidth : %i\n", crtc->width);
131 printf("\theight : %i\n", crtc->height);
132 printf("\tmode : %p\n", &crtc->mode);
133 printf("\tnum outputs : %i\n", crtc->count_outputs);
134 printf("\toutputs : %i\n", crtc->outputs);
135 printf("\tnum possible : %i\n", crtc->count_possibles);
136 printf("\tpossibles : %i\n", crtc->possibles);
141 int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb)
143 printf("Framebuffer\n");
144 printf("\thandle : %i\n", fb->handle);
145 printf("\twidth : %i\n", fb->width);
146 printf("\theight : %i\n", fb->height);
147 printf("\tpitch : %i\n", fb->pitch);;
148 printf("\tbpp : %i\n", fb->bpp);
149 printf("\tdepth : %i\n", fb->depth);
150 printf("\tbuffer_id : %i\n", fb->buffer_id);
155 int printRes(int fd, drmModeResPtr res)
158 drmModeOutputPtr output;
162 for (i = 0; i < res->count_outputs; i++) {
163 output = drmModeGetOutput(fd, res->outputs[i]);
166 printf("Could not get output %i\n", i);
168 printOutput(fd, res, output, res->outputs[i]);
169 drmModeFreeOutput(output);
173 for (i = 0; i < res->count_crtcs; i++) {
174 crtc = drmModeGetCrtc(fd, res->crtcs[i]);
177 printf("Could not get crtc %i\n", i);
179 printCrtc(fd, res, crtc, res->crtcs[i]);
180 drmModeFreeCrtc(crtc);
184 for (i = 0; i < res->count_fbs; i++) {
185 fb = drmModeGetFB(fd, res->fbs[i]);
188 printf("Could not get fb %i\n", res->fbs[i]);
190 printFrameBuffer(fd, res, fb);
198 static struct drm_mode_modeinfo mode = {
211 .vrefresh = 60000, /* vertical refresh * 1000 */
215 int testMode(int fd, drmModeResPtr res)
217 uint32_t output = res->outputs[0];
218 uint32_t newMode = 0;
222 printf("Test: adding mode to output %i\n", output);
224 /* printMode(&mode); */
226 printf("\tAttaching mode %i to output %i\n", newMode, output);
228 ret = drmModeAttachMode(fd, output, &mode);
233 printf("\tDetaching mode %i from output %i\n", newMode, output);
234 ret = drmModeDetachMode(fd, output, &mode);
242 printf("\tFailed\n");
245 printf("\tFailed to delete mode %i\n", newMode);
250 int testFrameBufferGet(int fd, uint32_t fb)
254 printf("Test: get framebuffer %i\n", fb);
256 frame = drmModeGetFB(fd, fb);
259 printf("\tFailed\n");
261 printFrameBuffer(fd, frame);
262 drmModeFreeFB(frame);
269 int testFrameBufferAdd(int fd, drmModeResPtr res)
273 drmModeFBPtr frame = 0;
276 printf("Test: adding framebuffer\n");
278 printf("\tCreating BO\n");
281 ret = drmBOCreate(fd, 800 * 600 * 4, 0, 0,
285 DRM_BO_FLAG_MEM_VRAM |
286 DRM_BO_FLAG_NO_EVICT,
287 DRM_BO_HINT_DONT_FENCE, &bo);
289 printf("\tgot %i\n", ret);
293 printf("\tAdding FB\n");
294 ret = drmModeAddFB(fd, 800, 600, 32, 8, 0, bo.handle, &fb);
298 frame = drmModeGetFB(fd, fb);
301 printf("Couldn't retrive created framebuffer\n");
303 printFrameBuffer(fd, res, frame);
304 drmModeFreeFB(frame);
307 printf("\tRemoveing FB\n");
309 ret = drmModeRmFB(fd, fb);
312 printf("\tFailed this shouldn't happen!\n");
316 printf("\tRemoveing BO\n");
318 ret = drmBOUnreference(fb, &bo);
323 drmBOUnreference(fd, &bo);
326 printf("\tFailed\n");
331 int testDPMS(int fd, drmModeResPtr res)
336 for (i = 0; i < res->count_outputs; i++) {
337 output_id = res->outputs[i];
338 /* turn output off */
339 drmModeOutputSetProperty(fd, output_id, dpms_prop_id, 3);
341 drmModeOutputSetProperty(fd, output_id, dpms_prop_id, 0);
347 int main(int argc, char **argv)
352 printf("Starting test\n");
354 fd = drmOpenControl(0);
357 printf("Failed to open the card fb (%d)\n",fd);
361 res = drmModeGetResources(fd);
363 printf("Failed to get resources from card\n");
372 testFrameBufferAdd(fd, res);
376 drmModeFreeResources(res);