drm: introduce generation counter to interface.
[profile/ivi/libdrm.git] / libdrm / 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  */
10
11 /*
12  * Copyright (c) <year> <copyright holders>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included in
22  * all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * IN THE SOFTWARE.
31  *
32  */
33
34 #include <drm.h>
35 #include "xf86mm.h"
36
37 /*
38  * This is the interface for modesetting for drm.
39  *
40  * In order to use this interface you must include either <stdint.h> or another
41  * header defining uint32_t, int32_t and uint16_t.
42  *
43  * It aims to provide a randr1.2 compatible interface for modesettings in the
44  * kernel, the interface is also ment to be used by libraries like EGL.
45  *
46  * More information can be found in randrproto.txt which can be found here:
47  * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
48  *
49  * There are some major diffrences to be noted. Unlike the randr1.2 proto you
50  * need to create the memory object of the framebuffer yourself with the ttm
51  * buffer object interface. This object needs to be pinned.
52  */
53
54 /*
55  * generation - these are to be read by userspace, and if it notices
56  * while calling a get output or get crtc that the generation has changed
57  * it should re-call the mode resource functions resync its view of the
58  * outputs with current view.
59  */
60
61 typedef struct _drmModeRes {
62
63         uint32_t generation;
64         int count_fbs;
65         uint32_t *fbs;
66
67         int count_crtcs;
68         uint32_t *crtcs;
69
70         int count_connectors;
71         uint32_t *connectors;
72
73         int count_encoders;
74         uint32_t *encoders;
75
76         uint32_t min_width, max_width;
77         uint32_t min_height, max_height;
78 } drmModeRes, *drmModeResPtr;
79
80 typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr;
81
82 typedef struct _drmModePropertyBlob {
83         uint32_t id;
84         uint32_t length;
85         void *data;
86 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
87
88 typedef struct _drmModeProperty {
89         unsigned int prop_id;
90         unsigned int flags;
91         char name[DRM_PROP_NAME_LEN];
92         int count_values;
93         uint64_t *values; // store the blob lengths
94         int count_enums;
95         struct drm_mode_property_enum *enums;
96         int count_blobs;
97         uint32_t *blob_ids; // store the blob IDs
98 } drmModePropertyRes, *drmModePropertyPtr;
99
100 typedef struct _drmModeCrtc {
101         unsigned int crtc_id;
102         unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/
103         uint32_t generation;
104
105         uint32_t x, y; /**< Position on the frameuffer */
106         uint32_t width, height;
107         int mode_valid;
108         struct drm_mode_modeinfo mode;
109
110         int count_connectors;
111         uint32_t connectors; /**< Connectors that are connected */
112
113         int count_possibles;
114         uint32_t possibles; /**< Connectors that can be connected */
115
116         int gamma_size; /**< Number of gamma stops */
117
118 } drmModeCrtc, *drmModeCrtcPtr;
119
120 typedef struct _drmModeEncoder {
121         uint32_t generation;
122         unsigned int encoder_id;
123         unsigned int encoder_type;
124         uint32_t crtc;
125         uint32_t crtcs;
126         uint32_t clones;
127 } drmModeEncoder, *drmModeEncoderPtr;
128
129 typedef enum {
130         DRM_MODE_CONNECTED         = 1,
131         DRM_MODE_DISCONNECTED      = 2,
132         DRM_MODE_UNKNOWNCONNECTION = 3
133 } drmModeConnection;
134
135 typedef enum {
136         DRM_MODE_SUBPIXEL_UNKNOWN        = 1,
137         DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
138         DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
139         DRM_MODE_SUBPIXEL_VERTICAL_RGB   = 4,
140         DRM_MODE_SUBPIXEL_VERTICAL_BGR   = 5,
141         DRM_MODE_SUBPIXEL_NONE           = 6
142 } drmModeSubPixel;
143
144 typedef struct _drmModeConnector {
145         uint32_t generation;
146         unsigned int connector_id;
147         unsigned int encoder; /**< Crtc currently connected to */
148         unsigned int connector_type;
149         unsigned int connector_type_id;
150         drmModeConnection connection;
151         uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
152         drmModeSubPixel subpixel;
153
154         int count_modes;
155         struct drm_mode_modeinfo *modes;
156
157         int count_props;
158         uint32_t *props; /**< List of property ids */
159         uint64_t *prop_values; /**< List of property values */
160
161         int count_encoders;
162         uint32_t *encoders; /**< List of encoder ids */
163 } drmModeConnector, *drmModeConnectorPtr;
164
165
166
167 extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr );
168 extern void drmModeFreeResources( drmModeResPtr ptr );
169 extern void drmModeFreeFB( drmModeFBPtr ptr );
170 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
171 extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
172 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
173
174 /**
175  * Retrives all of the resources associated with a card.
176  */
177 extern drmModeResPtr drmModeGetResources(int fd);
178
179 /**
180  * Retrives the hotplug counter
181  */
182 extern uint32_t drmModeGetHotplug(int fd);
183
184 /*
185  * FrameBuffer manipulation.
186  */
187
188 /**
189  * Retrive information about framebuffer bufferId
190  */
191 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
192
193 /**
194  * Creates a new framebuffer with an buffer object as its scanout buffer.
195  */
196 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
197                         uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
198                         uint32_t *buf_id);
199 /**
200  * Destroies the given framebuffer.
201  */
202 extern int drmModeRmFB(int fd, uint32_t bufferId);
203
204 /**
205  * Replace a framebuffer object with a new one - for resizing the screen.
206  */
207 extern int drmModeReplaceFB(int fd, uint32_t buffer_id,
208                             uint32_t width, uint32_t height, uint8_t depth,
209                             uint8_t bpp, uint32_t pitch, uint32_t bo_handle);
210
211 /*
212  * Crtc functions
213  */
214
215 /**
216  * Retrive information about the ctrt crtcId
217  */
218 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
219
220 /**
221  * Set the mode on a crtc crtcId with the given mode modeId.
222  */
223 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
224                    uint32_t x, uint32_t y, uint32_t *connectors, int count,
225                    struct drm_mode_modeinfo *mode);
226
227 /*
228  * Cursor functions
229  */
230
231 /**
232  * Set the cursor on crtc
233  */
234 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
235
236 /**
237  * Move the cursor on crtc
238  */
239 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
240
241 /**
242  * Encoder functions
243  */
244 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
245
246 /*
247  * Connector manipulation
248  */
249
250 /**
251  * Retrive information about the connector connectorId.
252  */
253 extern drmModeConnectorPtr drmModeGetConnector(int fd,
254                 uint32_t connectorId);
255
256 /**
257  * Attaches the given mode to an connector.
258  */
259 extern int drmModeAttachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info);
260
261 /**
262  * Detaches a mode from the connector
263  * must be unused, by the given mode.
264  */
265 extern int drmModeDetachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info);
266
267 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
268 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
269
270 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
271 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
272 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
273                                     uint64_t value);
274 extern int drmCheckModesettingSupported(const char *busid);
275
276 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
277                                uint16_t *red, uint16_t *green, uint16_t *blue);
278 extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
279                                uint16_t *red, uint16_t *green, uint16_t *blue);