1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include "xf86drm.h"
#include "xf86drmMode.h"
int connectors;
int full_props;
int edid;
int modes;
int full_modes;
int encoders;
int crtcs;
int fbs;
const char* getConnectionText(drmModeConnection conn)
{
switch (conn) {
case DRM_MODE_CONNECTED:
return "connected";
case DRM_MODE_DISCONNECTED:
return "disconnected";
default:
return "unknown";
}
}
int printMode(struct drm_mode_modeinfo *mode)
{
if (full_modes) {
printf("Mode: %s\n", mode->name);
printf("\tclock : %i\n", mode->clock);
printf("\thdisplay : %i\n", mode->hdisplay);
printf("\thsync_start : %i\n", mode->hsync_start);
printf("\thsync_end : %i\n", mode->hsync_end);
printf("\thtotal : %i\n", mode->htotal);
printf("\thskew : %i\n", mode->hskew);
printf("\tvdisplay : %i\n", mode->vdisplay);
printf("\tvsync_start : %i\n", mode->vsync_start);
printf("\tvsync_end : %i\n", mode->vsync_end);
printf("\tvtotal : %i\n", mode->vtotal);
printf("\tvscan : %i\n", mode->vscan);
printf("\tvrefresh : %i\n", mode->vrefresh);
printf("\tflags : %i\n", mode->flags);
} else {
printf("Mode: \"%s\" %ix%i %.0f\n", mode->name,
mode->hdisplay, mode->vdisplay, mode->vrefresh / 1000.0);
}
return 0;
}
int printProperty(int fd, drmModeResPtr res, drmModePropertyPtr props, uint64_t value)
{
const unsigned char *name = NULL;
int j;
printf("Property: %s\n", props->name);
printf("\tid : %i\n", props->prop_id);
printf("\tflags : %i\n", props->flags);
printf("\tcount_values : %d\n", props->count_values);
if (props->count_values) {
printf("\tvalues :");
for (j = 0; j < props->count_values; j++)
printf(" %lld", props->values[j]);
printf("\n");
}
printf("\tcount_enums : %d\n", props->count_enums);
if (props->flags & DRM_MODE_PROP_BLOB) {
drmModePropertyBlobPtr blob;
blob = drmModeGetPropertyBlob(fd, value);
if (blob) {
printf("blob is %d length, %08X\n", blob->length, *(uint32_t *)blob->data);
drmModeFreePropertyBlob(blob);
} else {
printf("error getting blob %lld\n", value);
}
} else {
if (!strncmp(props->name, "DPMS", 4))
;
for (j = 0; j < props->count_enums; j++) {
printf("\t\t%lld = %s\n", props->enums[j].value, props->enums[j].name);
if (props->enums[j].value == value)
name = props->enums[j].name;
}
if (props->count_enums && name) {
printf("\tcon_value : %s\n", name);
} else {
printf("\tcon_value : %lld\n", value);
}
}
return 0;
}
int printConnector(int fd, drmModeResPtr res, drmModeConnectorPtr connector, uint32_t id)
{
int i = 0;
struct drm_mode_modeinfo *mode = NULL;
drmModePropertyPtr props;
printf("Connector: %d-%d\n", connector->connector_type, connector->connector_type_id);
printf("\tid : %i\n", id);
printf("\tencoder id : %i\n", connector->encoder);
printf("\tconn : %s\n", getConnectionText(connector->connection));
printf("\tsize : %ix%i (mm)\n", connector->mmWidth, connector->mmHeight);
printf("\tcount_modes : %i\n", connector->count_modes);
printf("\tcount_props : %i\n", connector->count_props);
if (connector->count_props) {
printf("\tprops :");
for (i = 0; i < connector->count_props; i++)
printf(" %i", connector->props[i]);
printf("\n");
}
printf("\tcount_encoders : %i\n", connector->count_encoders);
if (connector->count_encoders) {
printf("\tencoders :");
for (i = 0; i < connector->count_encoders; i++)
printf(" %i", connector->encoders[i]);
printf("\n");
}
if (modes) {
for (i = 0; i < connector->count_modes; i++) {
mode = &connector->modes[i];
printMode(mode);
}
}
if (full_props) {
for (i = 0; i < connector->count_props; i++) {
props = drmModeGetProperty(fd, connector->props[i]);
if (props) {
printProperty(fd, res, props, connector->prop_values[i]);
drmModeFreeProperty(props);
}
}
}
return 0;
}
int printEncoder(int fd, drmModeResPtr res, drmModeEncoderPtr encoder, uint32_t id)
{
printf("Encoder\n");
printf("\tid :%i\n", id);
printf("\tcrtc :%d\n", encoder->crtc);
printf("\ttype :%d\n", encoder->encoder_type);
printf("\tcrtcs :%d\n", encoder->crtcs);
printf("\tclones :%d\n", encoder->clones);
return 0;
}
int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
{
printf("Crtc\n");
printf("\tid : %i\n", id);
printf("\tx : %i\n", crtc->x);
printf("\ty : %i\n", crtc->y);
printf("\twidth : %i\n", crtc->width);
printf("\theight : %i\n", crtc->height);
printf("\tmode : %p\n", &crtc->mode);
printf("\tgamma size : %d\n", crtc->gamma_size);
printf("\tnum connectors : %i\n", crtc->count_connectors);
printf("\tconnectors : %i\n", crtc->connectors);
printf("\tnum possible : %i\n", crtc->count_possibles);
printf("\tpossibles : %i\n", crtc->possibles);
return 0;
}
int printFrameBuffer(int fd, drmModeResPtr res, drmModeFBPtr fb)
{
printf("Framebuffer\n");
printf("\thandle : %i\n", fb->handle);
printf("\twidth : %i\n", fb->width);
printf("\theight : %i\n", fb->height);
printf("\tpitch : %i\n", fb->pitch);;
printf("\tbpp : %i\n", fb->bpp);
printf("\tdepth : %i\n", fb->depth);
printf("\tbuffer_id : %i\n", fb->buffer_id);
return 0;
}
int printRes(int fd, drmModeResPtr res)
{
int i;
drmModeFBPtr fb;
drmModeCrtcPtr crtc;
drmModeEncoderPtr encoder;
drmModeConnectorPtr connector;
printf("Resources\n\n");
printf("count_connectors : %i\n", res->count_connectors);
printf("count_encoders : %i\n", res->count_encoders);
printf("count_crtcs : %i\n", res->count_crtcs);
printf("count_fbs : %i\n", res->count_fbs);
printf("\n");
if (connectors) {
for (i = 0; i < res->count_connectors; i++) {
connector = drmModeGetConnector(fd, res->connectors[i]);
if (!connector)
printf("Could not get connector %i\n", res->connectors[i]);
else {
printConnector(fd, res, connector, res->connectors[i]);
drmModeFreeConnector(connector);
}
}
printf("\n");
}
if (encoders) {
for (i = 0; i < res->count_encoders; i++) {
encoder = drmModeGetEncoder(fd, res->encoders[i]);
if (!encoder)
printf("Could not get encoder %i\n", res->encoders[i]);
else {
printEncoder(fd, res, encoder, res->encoders[i]);
drmModeFreeEncoder(encoder);
}
}
printf("\n");
}
if (crtcs) {
for (i = 0; i < res->count_crtcs; i++) {
crtc = drmModeGetCrtc(fd, res->crtcs[i]);
if (!crtc)
printf("Could not get crtc %i\n", res->crtcs[i]);
else {
printCrtc(fd, res, crtc, res->crtcs[i]);
drmModeFreeCrtc(crtc);
}
}
printf("\n");
}
if (fbs) {
for (i = 0; i < res->count_fbs; i++) {
fb = drmModeGetFB(fd, res->fbs[i]);
if (!fb)
printf("Could not get fb %i\n", res->fbs[i]);
else {
printFrameBuffer(fd, res, fb);
drmModeFreeFB(fb);
}
}
}
return 0;
}
void args(int argc, char **argv)
{
int i;
fbs = 0;
edid = 0;
crtcs = 0;
modes = 0;
encoders = 0;
full_modes = 0;
full_props = 0;
connectors = 0;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-fb") == 0) {
fbs = 1;
} else if (strcmp(argv[i], "-crtcs") == 0) {
crtcs = 1;
} else if (strcmp(argv[i], "-cons") == 0) {
connectors = 1;
modes = 1;
} else if (strcmp(argv[i], "-modes") == 0) {
connectors = 1;
modes = 1;
} else if (strcmp(argv[i], "-full") == 0) {
connectors = 1;
modes = 1;
full_modes = 1;
} else if (strcmp(argv[i], "-props") == 0) {
connectors = 1;
full_props = 1;
} else if (strcmp(argv[i], "-edids") == 0) {
connectors = 1;
edid = 1;
} else if (strcmp(argv[i], "-encoders") == 0) {
encoders = 1;
} else if (strcmp(argv[i], "-v") == 0) {
fbs = 1;
edid = 1;
crtcs = 1;
modes = 1;
encoders = 1;
full_modes = 1;
full_props = 1;
connectors = 1;
}
}
if (argc == 1) {
fbs = 1;
edid = 1;
crtcs = 1;
modes = 1;
encoders = 1;
full_modes = 0;
full_props = 0;
connectors = 1;
}
}
int main(int argc, char **argv)
{
int fd;
drmModeResPtr res;
args(argc, argv);
printf("Starting test\n");
fd = drmOpen("i915", NULL);
if (fd < 0) {
printf("Failed to open the card fd (%d)\n",fd);
return 1;
}
res = drmModeGetResources(fd);
if (res == 0) {
printf("Failed to get resources from card\n");
drmClose(fd);
return 1;
}
printRes(fd, res);
drmModeFreeResources(res);
printf("Ok\n");
return 0;
}
|