1 /*
2 * \file xf86drmMode.h
3 * Header for DRM modesetting interface.
4 *
5 * \author Jakob Bornecrantz <wallbraker@gmail.com>
6 *
7 * \par Acknowledgements:
8 * Feb 2007, Dave Airlie <airlied@linux.ie>
9 */
10
11 /*
12 * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
13 * Copyright (c) 2007-2008 Dave Airlie <airlied@linux.ie>
14 * Copyright (c) 2007-2008 Jakob Bornecrantz <wallbraker@gmail.com>
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 * IN THE SOFTWARE.
33 *
34 */
35
36 #ifndef _XF86DRMMODE_H_
37 #define _XF86DRMMODE_H_
38
39 #if defined(__cplusplus) || defined(c_plusplus)
40 extern "C" {
41 #endif
42
43 #include <drm.h>
44
45 /*
46 * This is the interface for modesetting for drm.
47 *
48 * In order to use this interface you must include either <stdint.h> or another
49 * header defining uint32_t, int32_t and uint16_t.
50 *
51 * It aims to provide a randr1.2 compatible interface for modesettings in the
52 * kernel, the interface is also ment to be used by libraries like EGL.
53 *
54 * More information can be found in randrproto.txt which can be found here:
55 * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
56 *
57 * There are some major diffrences to be noted. Unlike the randr1.2 proto you
58 * need to create the memory object of the framebuffer yourself with the ttm
59 * buffer object interface. This object needs to be pinned.
60 */
61
62 /*
63 * If we pickup an old version of drm.h which doesn't include drm_mode.h
64 * we should redefine defines. This is so that builds doesn't breaks with
65 * new libdrm on old kernels.
66 */
67 #ifndef _DRM_MODE_H
68
69 #define DRM_DISPLAY_INFO_LEN 32
70 #define DRM_CONNECTOR_NAME_LEN 32
71 #define DRM_DISPLAY_MODE_LEN 32
72 #define DRM_PROP_NAME_LEN 32
73
74 #define DRM_MODE_TYPE_BUILTIN (1<<0)
75 #define DRM_MODE_TYPE_CLOCK_C ((1<<1) | DRM_MODE_TYPE_BUILTIN)
76 #define DRM_MODE_TYPE_CRTC_C ((1<<2) | DRM_MODE_TYPE_BUILTIN)
77 #define DRM_MODE_TYPE_PREFERRED (1<<3)
78 #define DRM_MODE_TYPE_DEFAULT (1<<4)
79 #define DRM_MODE_TYPE_USERDEF (1<<5)
80 #define DRM_MODE_TYPE_DRIVER (1<<6)
81
82 /* Video mode flags */
83 /* bit compatible with the xorg definitions. */
84 #define DRM_MODE_FLAG_PHSYNC (1<<0)
85 #define DRM_MODE_FLAG_NHSYNC (1<<1)
86 #define DRM_MODE_FLAG_PVSYNC (1<<2)
87 #define DRM_MODE_FLAG_NVSYNC (1<<3)
88 #define DRM_MODE_FLAG_INTERLACE (1<<4)
89 #define DRM_MODE_FLAG_DBLSCAN (1<<5)
90 #define DRM_MODE_FLAG_CSYNC (1<<6)
91 #define DRM_MODE_FLAG_PCSYNC (1<<7)
92 #define DRM_MODE_FLAG_NCSYNC (1<<8)
93 #define DRM_MODE_FLAG_HSKEW (1<<9) /* hskew provided */
94 #define DRM_MODE_FLAG_BCAST (1<<10)
95 #define DRM_MODE_FLAG_PIXMUX (1<<11)
96 #define DRM_MODE_FLAG_DBLCLK (1<<12)
97 #define DRM_MODE_FLAG_CLKDIV2 (1<<13)
98 #define DRM_MODE_FLAG_3D_MASK (0x1f<<14)
99 #define DRM_MODE_FLAG_3D_NONE (0<<14)
100 #define DRM_MODE_FLAG_3D_FRAME_PACKING (1<<14)
101 #define DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE (2<<14)
102 #define DRM_MODE_FLAG_3D_LINE_ALTERNATIVE (3<<14)
103 #define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
104 #define DRM_MODE_FLAG_3D_L_DEPTH (5<<14)
105 #define DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
106 #define DRM_MODE_FLAG_3D_TOP_AND_BOTTOM (7<<14)
107 #define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
108
109 /* DPMS flags */
110 /* bit compatible with the xorg definitions. */
111 #define DRM_MODE_DPMS_ON 0
112 #define DRM_MODE_DPMS_STANDBY 1
113 #define DRM_MODE_DPMS_SUSPEND 2
114 #define DRM_MODE_DPMS_OFF 3
115
116 /* Scaling mode options */
117 #define DRM_MODE_SCALE_NON_GPU 0
118 #define DRM_MODE_SCALE_FULLSCREEN 1
119 #define DRM_MODE_SCALE_NO_SCALE 2
120 #define DRM_MODE_SCALE_ASPECT 3
121
122 /* Dithering mode options */
123 #define DRM_MODE_DITHERING_OFF 0
124 #define DRM_MODE_DITHERING_ON 1
125 #define DRM_MODE_DITHERING_AUTO 2
126
127 /* Dirty info options */
128 #define DRM_MODE_DIRTY_OFF 0
129 #define DRM_MODE_DIRTY_ON 1
130 #define DRM_MODE_DIRTY_ANNOTATE 2
131
132 #define DRM_MODE_ENCODER_NONE 0
133 #define DRM_MODE_ENCODER_DAC 1
134 #define DRM_MODE_ENCODER_TMDS 2
135 #define DRM_MODE_ENCODER_LVDS 3
136 #define DRM_MODE_ENCODER_TVDAC 4
137 #define DRM_MODE_ENCODER_VIRTUAL 5
138 #define DRM_MODE_ENCODER_DSI 6
139 #define DRM_MODE_ENCODER_DPMST 7
140
141 #define DRM_MODE_SUBCONNECTOR_Automatic 0
142 #define DRM_MODE_SUBCONNECTOR_Unknown 0
143 #define DRM_MODE_SUBCONNECTOR_DVID 3
144 #define DRM_MODE_SUBCONNECTOR_DVIA 4
145 #define DRM_MODE_SUBCONNECTOR_Composite 5
146 #define DRM_MODE_SUBCONNECTOR_SVIDEO 6
147 #define DRM_MODE_SUBCONNECTOR_Component 8
148 #define DRM_MODE_SUBCONNECTOR_SCART 9
149
150 #define DRM_MODE_CONNECTOR_Unknown 0
151 #define DRM_MODE_CONNECTOR_VGA 1
152 #define DRM_MODE_CONNECTOR_DVII 2
153 #define DRM_MODE_CONNECTOR_DVID 3
154 #define DRM_MODE_CONNECTOR_DVIA 4
155 #define DRM_MODE_CONNECTOR_Composite 5
156 #define DRM_MODE_CONNECTOR_SVIDEO 6
157 #define DRM_MODE_CONNECTOR_LVDS 7
158 #define DRM_MODE_CONNECTOR_Component 8
159 #define DRM_MODE_CONNECTOR_9PinDIN 9
160 #define DRM_MODE_CONNECTOR_DisplayPort 10
161 #define DRM_MODE_CONNECTOR_HDMIA 11
162 #define DRM_MODE_CONNECTOR_HDMIB 12
163 #define DRM_MODE_CONNECTOR_TV 13
164 #define DRM_MODE_CONNECTOR_eDP 14
165 #define DRM_MODE_CONNECTOR_VIRTUAL 15
166 #define DRM_MODE_CONNECTOR_DSI 16
167
168 #define DRM_MODE_PROP_PENDING (1<<0)
169 #define DRM_MODE_PROP_RANGE (1<<1)
170 #define DRM_MODE_PROP_IMMUTABLE (1<<2)
171 #define DRM_MODE_PROP_ENUM (1<<3) /* enumerated type with text strings */
172 #define DRM_MODE_PROP_BLOB (1<<4)
173 #define DRM_MODE_PROP_BITMASK (1<<5) /* bitmask of enumerated types */
174
175 /* non-extended types: legacy bitmask, one bit per type: */
176 #define DRM_MODE_PROP_LEGACY_TYPE ( \
177 DRM_MODE_PROP_RANGE | \
178 DRM_MODE_PROP_ENUM | \
179 DRM_MODE_PROP_BLOB | \
180 DRM_MODE_PROP_BITMASK)
181
182 /* extended-types: rather than continue to consume a bit per type,
183 * grab a chunk of the bits to use as integer type id.
184 */
185 #define DRM_MODE_PROP_EXTENDED_TYPE 0x0000ffc0
186 #define DRM_MODE_PROP_TYPE(n) ((n) << 6)
187 #define DRM_MODE_PROP_OBJECT DRM_MODE_PROP_TYPE(1)
188 #define DRM_MODE_PROP_SIGNED_RANGE DRM_MODE_PROP_TYPE(2)
189
190 #define DRM_MODE_CURSOR_BO (1<<0)
191 #define DRM_MODE_CURSOR_MOVE (1<<1)
192 #define DRM_MODE_CURSOR_FLAGS 0x03
193
194 #endif /* _DRM_MODE_H */
195
196 /*
197 * Feature defines
198 *
199 * Just because these are defined doesn't mean that the kernel
200 * can do that feature, its just for new code vs old libdrm.
201 */
202 #define DRM_MODE_FEATURE_KMS 1
203 #define DRM_MODE_FEATURE_DIRTYFB 1
204
205 typedef struct _drmModeRes {
206
207 int count_fbs;
208 uint32_t *fbs;
209
210 int count_crtcs;
211 uint32_t *crtcs;
212
213 int count_connectors;
214 uint32_t *connectors;
215
216 int count_encoders;
217 uint32_t *encoders;
218
219 uint32_t min_width, max_width;
220 uint32_t min_height, max_height;
221 } drmModeRes, *drmModeResPtr;
222
223 typedef struct _drmModeModeInfo {
224 uint32_t clock;
225 uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
226 uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
227
228 uint32_t vrefresh;
229
230 uint32_t flags;
231 uint32_t type;
232 char name[DRM_DISPLAY_MODE_LEN];
233 } drmModeModeInfo, *drmModeModeInfoPtr;
234
235 typedef struct _drmModeFB {
236 uint32_t fb_id;
237 uint32_t width, height;
238 uint32_t pitch;
239 uint32_t bpp;
240 uint32_t depth;
241 /* driver specific handle */
242 uint32_t handle;
243 } drmModeFB, *drmModeFBPtr;
244
245 typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
246
247 typedef struct _drmModePropertyBlob {
248 uint32_t id;
249 uint32_t length;
250 void *data;
251 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
252
253 typedef struct _drmModeProperty {
254 uint32_t prop_id;
255 uint32_t flags;
256 char name[DRM_PROP_NAME_LEN];
257 int count_values;
258 uint64_t *values; /* store the blob lengths */
259 int count_enums;
260 struct drm_mode_property_enum *enums;
261 int count_blobs;
262 uint32_t *blob_ids; /* store the blob IDs */
263 } drmModePropertyRes, *drmModePropertyPtr;
264
drm_property_type_is(drmModePropertyPtr property,uint32_t type)265 static __inline int drm_property_type_is(drmModePropertyPtr property,
266 uint32_t type)
267 {
268 /* instanceof for props.. handles extended type vs original types: */
269 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
270 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
271 return property->flags & type;
272 }
273
274 typedef struct _drmModeCrtc {
275 uint32_t crtc_id;
276 uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
277
278 uint32_t x, y; /**< Position on the framebuffer */
279 uint32_t width, height;
280 int mode_valid;
281 drmModeModeInfo mode;
282
283 int gamma_size; /**< Number of gamma stops */
284
285 } drmModeCrtc, *drmModeCrtcPtr;
286
287 typedef struct _drmModeEncoder {
288 uint32_t encoder_id;
289 uint32_t encoder_type;
290 uint32_t crtc_id;
291 uint32_t possible_crtcs;
292 uint32_t possible_clones;
293 } drmModeEncoder, *drmModeEncoderPtr;
294
295 typedef enum {
296 DRM_MODE_CONNECTED = 1,
297 DRM_MODE_DISCONNECTED = 2,
298 DRM_MODE_UNKNOWNCONNECTION = 3
299 } drmModeConnection;
300
301 typedef enum {
302 DRM_MODE_SUBPIXEL_UNKNOWN = 1,
303 DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
304 DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
305 DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4,
306 DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5,
307 DRM_MODE_SUBPIXEL_NONE = 6
308 } drmModeSubPixel;
309
310 typedef struct _drmModeConnector {
311 uint32_t connector_id;
312 uint32_t encoder_id; /**< Encoder currently connected to */
313 uint32_t connector_type;
314 uint32_t connector_type_id;
315 drmModeConnection connection;
316 uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
317 drmModeSubPixel subpixel;
318
319 int count_modes;
320 drmModeModeInfoPtr modes;
321
322 int count_props;
323 uint32_t *props; /**< List of property ids */
324 uint64_t *prop_values; /**< List of property values */
325
326 int count_encoders;
327 uint32_t *encoders; /**< List of encoder ids */
328 } drmModeConnector, *drmModeConnectorPtr;
329
330 #define DRM_PLANE_TYPE_OVERLAY 0
331 #define DRM_PLANE_TYPE_PRIMARY 1
332 #define DRM_PLANE_TYPE_CURSOR 2
333
334 typedef struct _drmModeObjectProperties {
335 uint32_t count_props;
336 uint32_t *props;
337 uint64_t *prop_values;
338 } drmModeObjectProperties, *drmModeObjectPropertiesPtr;
339
340 typedef struct _drmModePlane {
341 uint32_t count_formats;
342 uint32_t *formats;
343 uint32_t plane_id;
344
345 uint32_t crtc_id;
346 uint32_t fb_id;
347
348 uint32_t crtc_x, crtc_y;
349 uint32_t x, y;
350
351 uint32_t possible_crtcs;
352 uint32_t gamma_size;
353 } drmModePlane, *drmModePlanePtr;
354
355 typedef struct _drmModePlaneRes {
356 uint32_t count_planes;
357 uint32_t *planes;
358 } drmModePlaneRes, *drmModePlaneResPtr;
359
360 extern void drmModeFreeResources( drmModeResPtr ptr );
361
362 /**
363 * Retrives all of the resources associated with a card.
364 */
365 extern drmModeResPtr drmModeGetResources(int fd);
366
367 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
368 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
369
370 extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
371 uint32_t object_id,
372 uint32_t object_type);
373 extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
374
375 #if defined(__cplusplus) || defined(c_plusplus)
376 }
377 #endif
378
379 #endif
380