]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdrm.git/blob - xf86drmMode.h
drmModeFreeResources() always leaked some memory.
[glsdk/libdrm.git] / xf86drmMode.h
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  */
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  */
36 #if defined(__cplusplus) || defined(c_plusplus)
37 extern "C" {
38 #endif
40 #include <drm.h>
42 /*
43  * This is the interface for modesetting for drm.
44  *
45  * In order to use this interface you must include either <stdint.h> or another
46  * header defining uint32_t, int32_t and uint16_t.
47  *
48  * It aims to provide a randr1.2 compatible interface for modesettings in the
49  * kernel, the interface is also ment to be used by libraries like EGL.
50  *
51  * More information can be found in randrproto.txt which can be found here:
52  * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
53  *
54  * There are some major diffrences to be noted. Unlike the randr1.2 proto you
55  * need to create the memory object of the framebuffer yourself with the ttm
56  * buffer object interface. This object needs to be pinned.
57  */
59 /*
60  * If we pickup an old version of drm.h which doesn't include drm_mode.h
61  * we should redefine defines. This is so that builds doesn't breaks with
62  * new libdrm on old kernels.
63  */
64 #ifndef _DRM_MODE_H
66 #define DRM_DISPLAY_INFO_LEN    32
67 #define DRM_CONNECTOR_NAME_LEN  32
68 #define DRM_DISPLAY_MODE_LEN    32
69 #define DRM_PROP_NAME_LEN       32
71 #define DRM_MODE_TYPE_BUILTIN   (1<<0)
72 #define DRM_MODE_TYPE_CLOCK_C   ((1<<1) | DRM_MODE_TYPE_BUILTIN)
73 #define DRM_MODE_TYPE_CRTC_C    ((1<<2) | DRM_MODE_TYPE_BUILTIN)
74 #define DRM_MODE_TYPE_PREFERRED (1<<3)
75 #define DRM_MODE_TYPE_DEFAULT   (1<<4)
76 #define DRM_MODE_TYPE_USERDEF   (1<<5)
77 #define DRM_MODE_TYPE_DRIVER    (1<<6)
79 /* Video mode flags */
80 /* bit compatible with the xorg definitions. */
81 #define DRM_MODE_FLAG_PHSYNC    (1<<0)
82 #define DRM_MODE_FLAG_NHSYNC    (1<<1)
83 #define DRM_MODE_FLAG_PVSYNC    (1<<2)
84 #define DRM_MODE_FLAG_NVSYNC    (1<<3)
85 #define DRM_MODE_FLAG_INTERLACE (1<<4)
86 #define DRM_MODE_FLAG_DBLSCAN   (1<<5)
87 #define DRM_MODE_FLAG_CSYNC     (1<<6)
88 #define DRM_MODE_FLAG_PCSYNC    (1<<7)
89 #define DRM_MODE_FLAG_NCSYNC    (1<<8)
90 #define DRM_MODE_FLAG_HSKEW     (1<<9) /* hskew provided */
91 #define DRM_MODE_FLAG_BCAST     (1<<10)
92 #define DRM_MODE_FLAG_PIXMUX    (1<<11)
93 #define DRM_MODE_FLAG_DBLCLK    (1<<12)
94 #define DRM_MODE_FLAG_CLKDIV2   (1<<13)
96 /* DPMS flags */
97 /* bit compatible with the xorg definitions. */
98 #define DRM_MODE_DPMS_ON        0
99 #define DRM_MODE_DPMS_STANDBY   1
100 #define DRM_MODE_DPMS_SUSPEND   2
101 #define DRM_MODE_DPMS_OFF       3
103 /* Scaling mode options */
104 #define DRM_MODE_SCALE_NON_GPU          0
105 #define DRM_MODE_SCALE_FULLSCREEN       1
106 #define DRM_MODE_SCALE_NO_SCALE         2
107 #define DRM_MODE_SCALE_ASPECT           3
109 /* Dithering mode options */
110 #define DRM_MODE_DITHERING_OFF  0
111 #define DRM_MODE_DITHERING_ON   1
113 #define DRM_MODE_ENCODER_NONE   0
114 #define DRM_MODE_ENCODER_DAC    1
115 #define DRM_MODE_ENCODER_TMDS   2
116 #define DRM_MODE_ENCODER_LVDS   3
117 #define DRM_MODE_ENCODER_TVDAC  4
119 #define DRM_MODE_SUBCONNECTOR_Automatic 0
120 #define DRM_MODE_SUBCONNECTOR_Unknown   0
121 #define DRM_MODE_SUBCONNECTOR_DVID      3
122 #define DRM_MODE_SUBCONNECTOR_DVIA      4
123 #define DRM_MODE_SUBCONNECTOR_Composite 5
124 #define DRM_MODE_SUBCONNECTOR_SVIDEO    6
125 #define DRM_MODE_SUBCONNECTOR_Component 8
127 #define DRM_MODE_CONNECTOR_Unknown      0
128 #define DRM_MODE_CONNECTOR_VGA          1
129 #define DRM_MODE_CONNECTOR_DVII         2
130 #define DRM_MODE_CONNECTOR_DVID         3
131 #define DRM_MODE_CONNECTOR_DVIA         4
132 #define DRM_MODE_CONNECTOR_Composite    5
133 #define DRM_MODE_CONNECTOR_SVIDEO       6
134 #define DRM_MODE_CONNECTOR_LVDS         7
135 #define DRM_MODE_CONNECTOR_Component    8
136 #define DRM_MODE_CONNECTOR_9PinDIN      9
137 #define DRM_MODE_CONNECTOR_DisplayPort  10
138 #define DRM_MODE_CONNECTOR_HDMIA        11
139 #define DRM_MODE_CONNECTOR_HDMIB        12
140 #define DRM_MODE_CONNECTOR_TV           13
141 #define DRM_MODE_CONNECTOR_eDP          14
143 #define DRM_MODE_PROP_PENDING   (1<<0)
144 #define DRM_MODE_PROP_RANGE     (1<<1)
145 #define DRM_MODE_PROP_IMMUTABLE (1<<2)
146 #define DRM_MODE_PROP_ENUM      (1<<3) /* enumerated type with text strings */
147 #define DRM_MODE_PROP_BLOB      (1<<4)
149 #define DRM_MODE_CURSOR_BO      (1<<0)
150 #define DRM_MODE_CURSOR_MOVE    (1<<1)
152 #endif /* _DRM_MODE_H */
155 /*
156  * Feature defines
157  *
158  * Just because these are defined doesn't mean that the kernel
159  * can do that feature, its just for new code vs old libdrm.
160  */
161 #define DRM_MODE_FEATURE_KMS            1
162 #define DRM_MODE_FEATURE_DIRTYFB        1
165 typedef struct _drmModeRes {
167         int count_fbs;
168         uint32_t *fbs;
170         int count_crtcs;
171         uint32_t *crtcs;
173         int count_connectors;
174         uint32_t *connectors;
176         int count_encoders;
177         uint32_t *encoders;
179         uint32_t min_width, max_width;
180         uint32_t min_height, max_height;
181 } drmModeRes, *drmModeResPtr;
183 typedef struct _drmModeModeInfo {
184         uint32_t clock;
185         uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
186         uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
188         uint32_t vrefresh;
190         uint32_t flags;
191         uint32_t type;
192         char name[DRM_DISPLAY_MODE_LEN];
193 } drmModeModeInfo, *drmModeModeInfoPtr;
195 typedef struct _drmModeFB {
196         uint32_t fb_id;
197         uint32_t width, height;
198         uint32_t pitch;
199         uint32_t bpp;
200         uint32_t depth;
201         /* driver specific handle */
202         uint32_t handle;
203 } drmModeFB, *drmModeFBPtr;
205 typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
207 typedef struct _drmModePropertyBlob {
208         uint32_t id;
209         uint32_t length;
210         void *data;
211 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
213 typedef struct _drmModeProperty {
214         uint32_t prop_id;
215         uint32_t flags;
216         char name[DRM_PROP_NAME_LEN];
217         int count_values;
218         uint64_t *values; // store the blob lengths
219         int count_enums;
220         struct drm_mode_property_enum *enums;
221         int count_blobs;
222         uint32_t *blob_ids; // store the blob IDs
223 } drmModePropertyRes, *drmModePropertyPtr;
225 typedef struct _drmModeCrtc {
226         uint32_t crtc_id;
227         uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
229         uint32_t x, y; /**< Position on the framebuffer */
230         uint32_t width, height;
231         int mode_valid;
232         drmModeModeInfo mode;
234         int gamma_size; /**< Number of gamma stops */
236 } drmModeCrtc, *drmModeCrtcPtr;
238 typedef struct _drmModeEncoder {
239         uint32_t encoder_id;
240         uint32_t encoder_type;
241         uint32_t crtc_id;
242         uint32_t possible_crtcs;
243         uint32_t possible_clones;
244 } drmModeEncoder, *drmModeEncoderPtr;
246 typedef enum {
247         DRM_MODE_CONNECTED         = 1,
248         DRM_MODE_DISCONNECTED      = 2,
249         DRM_MODE_UNKNOWNCONNECTION = 3
250 } drmModeConnection;
252 typedef enum {
253         DRM_MODE_SUBPIXEL_UNKNOWN        = 1,
254         DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
255         DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
256         DRM_MODE_SUBPIXEL_VERTICAL_RGB   = 4,
257         DRM_MODE_SUBPIXEL_VERTICAL_BGR   = 5,
258         DRM_MODE_SUBPIXEL_NONE           = 6
259 } drmModeSubPixel;
261 typedef struct _drmModeConnector {
262         uint32_t connector_id;
263         uint32_t encoder_id; /**< Encoder currently connected to */
264         uint32_t connector_type;
265         uint32_t connector_type_id;
266         drmModeConnection connection;
267         uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
268         drmModeSubPixel subpixel;
270         int count_modes;
271         drmModeModeInfoPtr modes;
273         int count_props;
274         uint32_t *props; /**< List of property ids */
275         uint64_t *prop_values; /**< List of property values */
277         int count_encoders;
278         uint32_t *encoders; /**< List of encoder ids */
279 } drmModeConnector, *drmModeConnectorPtr;
281 typedef struct _drmModePlane {
282         uint32_t count_formats;
283         uint32_t *formats;
284         uint32_t plane_id;
286         uint32_t crtc_id;
287         uint32_t fb_id;
289         uint32_t crtc_x, crtc_y;
290         uint32_t x, y;
292         uint32_t possible_crtcs;
293         uint32_t gamma_size;
294 } drmModePlane, *drmModePlanePtr;
296 typedef struct _drmModePlaneRes {
297         uint32_t count_planes;
298         uint32_t *planes;
299 } drmModePlaneRes, *drmModePlaneResPtr;
301 extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
302 extern void drmModeFreeResources( drmModeResPtr ptr );
303 extern void drmModeFreeFB( drmModeFBPtr ptr );
304 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
305 extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
306 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
307 extern void drmModeFreePlane( drmModePlanePtr ptr );
309 /**
310  * Retrives all of the resources associated with a card.
311  */
312 extern drmModeResPtr drmModeGetResources(int fd);
314 /*
315  * FrameBuffer manipulation.
316  */
318 /**
319  * Retrive information about framebuffer bufferId
320  */
321 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
323 /**
324  * Creates a new framebuffer with an buffer object as its scanout buffer.
325  */
326 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
327                         uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
328                         uint32_t *buf_id);
329 /* ...with a specific pixel format */
330 extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
331                          uint32_t pixel_format, uint32_t bo_handles[4],
332                          uint32_t pitches[4], uint32_t offsets[4],
333                          uint32_t *buf_id, uint32_t flags);
334 /**
335  * Destroies the given framebuffer.
336  */
337 extern int drmModeRmFB(int fd, uint32_t bufferId);
339 /**
340  * Mark a region of a framebuffer as dirty.
341  */
342 extern int drmModeDirtyFB(int fd, uint32_t bufferId,
343                           drmModeClipPtr clips, uint32_t num_clips);
346 /*
347  * Crtc functions
348  */
350 /**
351  * Retrive information about the ctrt crtcId
352  */
353 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
355 /**
356  * Set the mode on a crtc crtcId with the given mode modeId.
357  */
358 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
359                    uint32_t x, uint32_t y, uint32_t *connectors, int count,
360                    drmModeModeInfoPtr mode);
362 /*
363  * Cursor functions
364  */
366 /**
367  * Set the cursor on crtc
368  */
369 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
371 /**
372  * Move the cursor on crtc
373  */
374 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
376 /**
377  * Encoder functions
378  */
379 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
381 /*
382  * Connector manipulation
383  */
385 /**
386  * Retrive information about the connector connectorId.
387  */
388 extern drmModeConnectorPtr drmModeGetConnector(int fd,
389                 uint32_t connectorId);
391 /**
392  * Attaches the given mode to an connector.
393  */
394 extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
396 /**
397  * Detaches a mode from the connector
398  * must be unused, by the given mode.
399  */
400 extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
402 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
403 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
405 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
406 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
407 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
408                                     uint64_t value);
409 extern int drmCheckModesettingSupported(const char *busid);
411 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
412                                uint16_t *red, uint16_t *green, uint16_t *blue);
413 extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
414                                uint16_t *red, uint16_t *green, uint16_t *blue);
415 extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
416                            uint32_t flags, void *user_data);
418 extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
419 extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
420 extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
421                            uint32_t fb_id, uint32_t flags,
422                            uint32_t crtc_x, uint32_t crtc_y,
423                            uint32_t crtc_w, uint32_t crtc_h,
424                            uint32_t src_x, uint32_t src_y,
425                            uint32_t src_w, uint32_t src_h);
427 #if defined(__cplusplus) || defined(c_plusplus)
429 #endif