Skip to content
Newer
Older
100644 373 lines (289 sloc) 9.08 KB
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
1 /*
2 * Copyright © 2011 Kristian Høgsberg
3 * Copyright © 2011 Benjamin Franzke
4 *
5 * Copyright © 2012 matsi
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that copyright
10 * notice and this permission notice appear in supporting documentation, and
11 * that the name of the copyright holders not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. The copyright holders make no representations
14 * about the suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
16 *
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 * OF THIS SOFTWARE.
24 */
25
26 #include <stdbool.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <stdio.h>
01dfa08 drm_info: no point in pinging gbm, disable it
Dmitry Eremin-Solenikov authored Oct 11, 2012
31 #include <stdint.h>
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
32 #include <fcntl.h>
33
34 #include <drm.h>
35 #include <xf86drmMode.h>
36
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
37 /* */
38
39 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
40
41 struct type_name {
42 int type;
43 char *name;
44 };
45
46 #define type_name_fn(res) \
47 char * res##_str(int type) { \
48 unsigned int i; \
49 for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
50 if (res##_names[i].type == type) \
51 return res##_names[i].name; \
52 } \
53 return "(invalid)"; \
54 }
55
56 struct type_name encoder_type_names[] = {
57 { DRM_MODE_ENCODER_NONE, "none" },
58 { DRM_MODE_ENCODER_DAC, "DAC" },
59 { DRM_MODE_ENCODER_TMDS, "TMDS" },
60 { DRM_MODE_ENCODER_LVDS, "LVDS" },
61 { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
62 };
63
64 type_name_fn(encoder_type)
65
66 struct type_name connector_status_names[] = {
67 { DRM_MODE_CONNECTED, "connected" },
68 { DRM_MODE_DISCONNECTED, "disconnected" },
69 { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
70 };
71
72 type_name_fn(connector_status)
73
74 struct type_name connector_type_names[] = {
75 { DRM_MODE_CONNECTOR_Unknown, "unknown" },
76 { DRM_MODE_CONNECTOR_VGA, "VGA" },
77 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
78 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
79 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
80 { DRM_MODE_CONNECTOR_Composite, "composite" },
81 { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
82 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
83 { DRM_MODE_CONNECTOR_Component, "component" },
84 { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
85 { DRM_MODE_CONNECTOR_DisplayPort, "displayport" },
86 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
87 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
88 { DRM_MODE_CONNECTOR_TV, "TV" },
89 { DRM_MODE_CONNECTOR_eDP, "embedded displayport" },
90 };
91
92 type_name_fn(connector_type)
93
94 /* */
95
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
96 static const char device_name[] = "/dev/dri/card0";
97
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
98 /* */
99
dda3e38 drm_info: output information about crtcs
Dmitry Eremin-Solenikov authored Oct 19, 2012
100 void crtc_info(drmModeRes *resources, drmModeCrtc *crtc)
101 {
9ba242f drm_info: add crtc struct description
Dmitry Eremin-Solenikov authored Nov 9, 2012
102 /* From xf86drmMode.h:
103
104 typedef struct _drmModeCrtc {
105 uint32_t crtc_id;
106 uint32_t buffer_id; // FB id to connect to 0 = disconnect
107
108 uint32_t x, y; // Position on the framebuffer
109 uint32_t width, height;
110 int mode_valid;
111 drmModeModeInfo mode;
112
113 int gamma_size; // Number of gamma stops
114
115 } drmModeCrtc, *drmModeCrtcPtr;
116
117 */
118
dda3e38 drm_info: output information about crtcs
Dmitry Eremin-Solenikov authored Oct 19, 2012
119 printf("\ncrtc [id = %u]\n", crtc->crtc_id);
120 printf("\tbuffer [id = %u]\n", crtc->buffer_id);
121 printf("\tposition: %xx%x @ %xx%x\n", crtc->width, crtc->height, crtc->x, crtc->y);
122 if (crtc->mode_valid)
123 printf("\tMode: valid [%s]\n", crtc->mode.name);
124 else
125 printf("\tMode: invalid\n");
126 }
127
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
128 void connector_info(drmModeRes *resources, drmModeConnector *connector)
129 {
130 drmModeModeInfo *mode;
131
132 uint32_t *enc;
133 int i;
134
135 /* From xf86drmMode.h:
136
137 typedef struct _drmModeConnector {
138 uint32_t connector_id;
139 uint32_t encoder_id; // Encoder currently connected
140 uint32_t connector_type;
141 uint32_t connector_type_id;
142 drmModeConnection connection;
143 uint32_t mmWidth, mmHeight; // HxW in millimeters
144 drmModeSubPixel subpixel;
145
146 int count_modes;
147 drmModeModeInfoPtr modes;
148
149 int count_props;
150 uint32_t *props; // List of property ids
151 uint64_t *prop_values; // List of property values
152
153 int count_encoders;
154 uint32_t *encoders; // List of encoder ids
155 } drmModeConnector, *drmModeConnectorPtr;
156
157 */
158
159 printf("\nConnector [id = %u]\n", connector->connector_id);
160 printf("\ttype [%s]\n", connector_type_str(connector->connector_type));
161 printf("\tstatus [%s]\n", connector_status_str(connector->connection));
162
163 for(i = 0, enc = connector->encoders; i < connector->count_encoders; i++, enc++) {
164 printf("%s[%u]%s", i ? " " : "\tsupported encoders: ", *enc, i == connector->count_encoders - 1 ? "\n" : " ");
165 }
166
167 printf("\tcurrent encoder: %u\n", connector->encoder_id);
168
169 /* From xf86drmMode.h:
170
171 typedef struct _drmModeModeInfo {
172 uint32_t clock;
173 uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
174 uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
175
176 uint32_t vrefresh;
177
178 uint32_t flags;
179 uint32_t type;
180 char name[DRM_DISPLAY_MODE_LEN];
181 } drmModeModeInfo, *drmModeModeInfoPtr;
182
183 */
184
185 for (i = 0, mode = connector->modes; i < connector->count_modes; i++, mode++) {
186 printf("%s[%s]%s", i ? " " : "\tmodes: ", mode->name, i == connector->count_modes - 1 ? "\n" : " ");
187 }
188
189 return;
190 }
191
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
192 void encoder_info(drmModeRes *resources, drmModeEncoder *encoder, drmModeCrtc **crtcs)
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
193 {
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
194 int i;
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
195
196 /* From xf86drmMode.h:
197
198 typedef struct _drmModeEncoder {
199 uint32_t encoder_id;
200 uint32_t encoder_type;
201 uint32_t crtc_id;
202 uint32_t possible_crtcs;
203 uint32_t possible_clones;
204 } drmModeEncoder, *drmModeEncoderPtr;
205
206 */
207
208 printf("\nEncoder [id = %u]\n", encoder->encoder_id);
209 printf("\ttype [%s]\n", encoder_type_str(encoder->encoder_type));
dda3e38 drm_info: output information about crtcs
Dmitry Eremin-Solenikov authored Oct 19, 2012
210 printf("\tCrtc [id = %u]\n", encoder->crtc_id);
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
211
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
212 printf("\tSupported crtc:");
213 for (i = 0; i < 31; i++)
214 if (encoder->possible_crtcs & (1 << i)) {
215 if (crtcs[i] != NULL)
216 printf(" [id = %d]", crtcs[i]->crtc_id);
217 else
218 printf(" [#%d, ??]", i);
219 }
220 printf("\n");
221
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
222 return;
223 }
224
ce8edb3 drm_info: dump information about planes
Dmitry Eremin-Solenikov authored Nov 9, 2012
225 void plane_info(drmModePlane *plane, drmModeCrtc **crtcs)
226 {
227 int i;
228
229 /* From xf86drmMode.h:
230
231 typedef struct _drmModePlane {
232 uint32_t count_formats;
233 uint32_t *formats;
234 uint32_t plane_id;
235
236 uint32_t crtc_id;
237 uint32_t fb_id;
238
239 uint32_t crtc_x, crtc_y;
240 uint32_t x, y;
241
242 uint32_t possible_crtcs;
243 uint32_t gamma_size;
244 } drmModePlane, *drmModePlanePtr;
245 */
246 printf("\nPlane [id = %u]\n", plane->plane_id);
247 printf("\tFB ID [id = %u]\n", plane->fb_id);
248 printf("\tcrtc ID [id = %u]\n", plane->crtc_id);
249
250 printf("\tCRTC XxY %ux%x\n", plane->crtc_x, plane->crtc_y);
251 printf("\tXxY %ux%x\n", plane->x, plane->y);
252 printf("\tSupported crtc:");
253 for (i = 0; i < 31; i++)
254 if (plane->possible_crtcs & (1 << i)) {
255 if (crtcs[i] != NULL)
256 printf(" [id = %d]", crtcs[i]->crtc_id);
257 else
258 printf(" [#%d, ??]", i);
259 }
260 printf("\n");
261 }
262
263 void planes_info(int fd, drmModeCrtc **crtcs)
264 {
265 drmModePlaneRes *plane_resources;
266 int i;
267
268 plane_resources = drmModeGetPlaneResources(fd);
269 if (!plane_resources) {
270 fprintf(stderr, "Error getting plane resources\n");
271 return;
272 }
273
274 for (i = 0; i < plane_resources->count_planes; i++) {
275 drmModePlane *plane = drmModeGetPlane(fd, plane_resources->planes[i]);
276 if (!plane)
277 continue;
278
279 plane_info(plane, crtcs);
280
281 drmModeFreePlane(plane);
282 }
283 }
284
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
285 int main(int argc, char *argv[])
286 {
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
287 drmModeCrtcPtr *crtcs;
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
288 drmModeConnector *connector;
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
289 drmModeEncoder *encoder;
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
290 drmModeRes *resources;
291
292 int i, fd, ret;
293
294 fd = open(device_name, O_RDWR);
295 if (fd < 0) {
296 fprintf(stderr, "couldn't open %s, skipping\n", device_name);
297 ret = -1;
298 goto exit;
299 }
300
301 /* From xf86drmMode.h:
302
303 typedef struct _drmModeRes {
304
305 int count_fbs;
306 uint32_t *fbs;
307
308 int count_crtcs;
309 uint32_t *crtcs;
310
311 int count_connectors;
312 uint32_t *connectors;
313
314 int count_encoders;
315 uint32_t *encoders;
316
317 uint32_t min_width, max_width;
318 uint32_t min_height, max_height;
319 } drmModeRes, *drmModeResPtr;
320
321 */
322
323 resources = drmModeGetResources(fd);
324 if (!resources) {
325 fprintf(stderr, "drmModeGetResources failed\n");
326 ret = -1;
01dfa08 drm_info: no point in pinging gbm, disable it
Dmitry Eremin-Solenikov authored Oct 11, 2012
327 goto close_fd;
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
328 }
329
330
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
331 crtcs = calloc(32, sizeof(drmModeCrtcPtr));
dda3e38 drm_info: output information about crtcs
Dmitry Eremin-Solenikov authored Oct 19, 2012
332 for (i = 0; i < resources->count_crtcs; i++) {
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
333 crtcs[i] = drmModeGetCrtc(fd, resources->crtcs[i]);
334 if (crtcs[i] == NULL)
dda3e38 drm_info: output information about crtcs
Dmitry Eremin-Solenikov authored Oct 19, 2012
335 continue;
336
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
337 crtc_info(resources, crtcs[i]);
dda3e38 drm_info: output information about crtcs
Dmitry Eremin-Solenikov authored Oct 19, 2012
338 }
339
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
340 for (i = 0; i < resources->count_connectors; i++) {
341 connector = drmModeGetConnector(fd, resources->connectors[i]);
342 if (connector == NULL)
343 continue;
344
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
345 connector_info(resources, connector);
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
346 drmModeFreeConnector(connector);
347 }
348
f45fb49 dump information about connectors and encoders
matsi authored Sep 16, 2012
349 for (i = 0; i < resources->count_encoders; i++) {
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
350 encoder = drmModeGetEncoder(fd, resources->encoders[i]);
351
352 if (encoder == NULL)
353 continue;
354
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
355 encoder_info(resources, encoder, crtcs);
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
356 drmModeFreeEncoder(encoder);
357 }
358
ce8edb3 drm_info: dump information about planes
Dmitry Eremin-Solenikov authored Nov 9, 2012
359 planes_info(fd, crtcs);
360
352d989 drm_info: output possible CRTCs info on encoder
Dmitry Eremin-Solenikov authored Nov 9, 2012
361 for (i = 0; i < resources->count_crtcs; i++) {
362 if (crtcs[i] != NULL)
363 drmModeFreeCrtc(crtcs[i]);
364 }
365 free(crtcs);
15b42d5 init repo with drm tests and experiments
matsi authored Sep 4, 2012
366
367 close_fd:
368 close(fd);
369
370 exit:
371 return ret;
372 }
Something went wrong with that request. Please try again.