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