drm: add encoder free function
[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 typedef struct _drmModeRes {
56
57         int count_fbs;
58         uint32_t *fbs;
59
60         int count_crtcs;
61         uint32_t *crtcs;
62
63         int count_outputs;
64         uint32_t *outputs;
65
66         int count_encoders;
67         uint32_t *encoders;
68
69         uint32_t min_width, max_width;
70         uint32_t min_height, max_height;
71 } drmModeRes, *drmModeResPtr;
72
73 typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr;
74
75 typedef struct _drmModePropertyBlob {
76         uint32_t id;
77         uint32_t length;
78         void *data;
79 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
80
81 typedef struct _drmModeProperty {
82         unsigned int prop_id;
83         unsigned int flags;
84         char name[DRM_PROP_NAME_LEN];
85         int count_values;
86         uint64_t *values; // store the blob lengths
87         int count_enums;
88         struct drm_mode_property_enum *enums;
89         int count_blobs;
90         uint32_t *blob_ids; // store the blob IDs
91 } drmModePropertyRes, *drmModePropertyPtr;
92
93 typedef struct _drmModeCrtc {
94         unsigned int crtc_id;
95         unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/
96
97         uint32_t x, y; /**< Position on the frameuffer */
98         uint32_t width, height;
99         int mode_valid;
100         struct drm_mode_modeinfo mode;
101
102         int count_outputs;
103         uint32_t outputs; /**< Outputs that are connected */
104
105         int count_possibles;
106         uint32_t possibles; /**< Outputs that can be connected */
107
108         int gamma_size; /**< Number of gamma stops */
109
110 } drmModeCrtc, *drmModeCrtcPtr;
111
112 typedef struct _drmModeEncoder {
113         unsigned int encoder_id;
114         unsigned int encoder_type;
115         uint32_t crtcs;
116         uint32_t clones;
117 } drmModeEncoder, *drmModeEncoderPtr;
118
119 typedef enum {
120         DRM_MODE_CONNECTED         = 1,
121         DRM_MODE_DISCONNECTED      = 2,
122         DRM_MODE_UNKNOWNCONNECTION = 3
123 } drmModeConnection;
124
125 typedef enum {
126         DRM_MODE_SUBPIXEL_UNKNOWN        = 1,
127         DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
128         DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
129         DRM_MODE_SUBPIXEL_VERTICAL_RGB   = 4,
130         DRM_MODE_SUBPIXEL_VERTICAL_BGR   = 5,
131         DRM_MODE_SUBPIXEL_NONE           = 6
132 } drmModeSubPixel;
133
134 typedef struct _drmModeOutput {
135         unsigned int output_id;
136
137         unsigned int crtc; /**< Crtc currently connected to */
138         unsigned int output_type;
139         unsigned int output_type_id;
140         drmModeConnection connection;
141         uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
142         drmModeSubPixel subpixel;
143
144         int count_crtcs;
145         uint32_t crtcs; /**< Possible crtc to connect to */
146
147         int count_clones;
148         uint32_t clones; /**< Mask of clones */
149
150         int count_modes;
151         struct drm_mode_modeinfo *modes;
152
153         int count_props;
154         uint32_t *props; /**< List of property ids */
155         uint64_t *prop_values; /**< List of property values */
156
157         int count_encoders;
158         uint32_t *encoders; /**< List of encoder ids */
159 } drmModeOutput, *drmModeOutputPtr;
160
161
162
163 extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr );
164 extern void drmModeFreeResources( drmModeResPtr ptr );
165 extern void drmModeFreeFB( drmModeFBPtr ptr );
166 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
167 extern void drmModeFreeOutput( drmModeOutputPtr ptr );
168 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
169
170 /**
171  * Retrives all of the resources associated with a card.
172  */
173 extern drmModeResPtr drmModeGetResources(int fd);
174
175 /**
176  * Retrives the hotplug counter
177  */
178 extern uint32_t drmModeGetHotplug(int fd);
179
180 /*
181  * FrameBuffer manipulation.
182  */
183
184 /**
185  * Retrive information about framebuffer bufferId
186  */
187 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
188
189 /**
190  * Creates a new framebuffer with an buffer object as its scanout buffer.
191  */
192 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
193                         uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
194                         uint32_t *buf_id);
195 /**
196  * Destroies the given framebuffer.
197  */
198 extern int drmModeRmFB(int fd, uint32_t bufferId);
199
200 /**
201  * Replace a framebuffer object with a new one - for resizing the screen.
202  */
203 extern int drmModeReplaceFB(int fd, uint32_t buffer_id,
204                             uint32_t width, uint32_t height, uint8_t depth,
205                             uint8_t bpp, uint32_t pitch, uint32_t bo_handle);
206
207 /*
208  * Crtc functions
209  */
210
211 /**
212  * Retrive information about the ctrt crtcId
213  */
214 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
215
216 /**
217  * Set the mode on a crtc crtcId with the given mode modeId.
218  */
219 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
220                    uint32_t x, uint32_t y, uint32_t *outputs, int count,
221                    struct drm_mode_modeinfo *mode);
222
223 /*
224  * Cursor functions
225  */
226
227 /**
228  * Set the cursor on crtc
229  */
230 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
231
232 /**
233  * Move the cursor on crtc
234  */
235 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
236
237 /**
238  * Encoder functions
239  */
240 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
241
242 /*
243  * Output manipulation
244  */
245
246 /**
247  * Retrive information about the output outputId.
248  */
249 extern drmModeOutputPtr drmModeGetOutput(int fd,
250                 uint32_t outputId);
251
252 /**
253  * Attaches the given mode to an output.
254  */
255 extern int drmModeAttachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info);
256
257 /**
258  * Detaches a mode from the output
259  * must be unused, by the given mode.
260  */
261 extern int drmModeDetachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info);
262
263 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
264 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
265
266 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
267 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
268 extern int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id,
269                                     uint64_t value);
270 extern int drmCheckModesettingSupported(const char *busid);