Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/drm into modesetting-101
[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         uint32_t min_width, max_width;
67         uint32_t min_height, max_height;
68 } drmModeRes, *drmModeResPtr;
69
70 typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr;
71
72 typedef struct _drmModePropertyBlob {
73         uint32_t id;
74         uint32_t length;
75         void *data;
76 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
77
78 typedef struct _drmModeProperty {
79         unsigned int prop_id;
80         unsigned int flags;
81         unsigned char name[DRM_PROP_NAME_LEN];
82         int count_values;
83         uint64_t *values; // store the blob lengths
84         int count_enums;
85         struct drm_mode_property_enum *enums;
86         int count_blobs;
87         uint32_t *blob_ids; // store the blob IDs
88 } drmModePropertyRes, *drmModePropertyPtr;
89
90 typedef struct _drmModeCrtc {
91         unsigned int crtc_id;
92         unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/
93
94         uint32_t x, y; /**< Position on the frameuffer */
95         uint32_t width, height;
96         int mode_valid;
97         struct drm_mode_modeinfo mode;
98
99         int count_outputs;
100         uint32_t outputs; /**< Outputs that are connected */
101
102         int count_possibles;
103         uint32_t possibles; /**< Outputs that can be connected */
104
105         int gamma_size; /**< Number of gamma stops */
106
107 } drmModeCrtc, *drmModeCrtcPtr;
108
109 typedef enum {
110         DRM_MODE_CONNECTED         = 1,
111         DRM_MODE_DISCONNECTED      = 2,
112         DRM_MODE_UNKNOWNCONNECTION = 3
113 } drmModeConnection;
114
115 typedef enum {
116         DRM_MODE_SUBPIXEL_UNKNOWN        = 1,
117         DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
118         DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
119         DRM_MODE_SUBPIXEL_VERTICAL_RGB   = 4,
120         DRM_MODE_SUBPIXEL_VERTICAL_BGR   = 5,
121         DRM_MODE_SUBPIXEL_NONE           = 6
122 } drmModeSubPixel;
123
124 typedef struct _drmModeOutput {
125         unsigned int output_id;
126
127         unsigned int crtc; /**< Crtc currently connected to */
128         unsigned char name[DRM_OUTPUT_NAME_LEN];
129         drmModeConnection connection;
130         uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
131         drmModeSubPixel subpixel;
132
133         int count_crtcs;
134         uint32_t crtcs; /**< Possible crtc to connect to */
135
136         int count_clones;
137         uint32_t clones; /**< Mask of clones */
138
139         int count_modes;
140         struct drm_mode_modeinfo *modes;
141
142         int count_props;
143         uint32_t *props; /**< List of property ids */
144         uint64_t *prop_values; /**< List of property values */
145
146 } drmModeOutput, *drmModeOutputPtr;
147
148
149
150 extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr );
151 extern void drmModeFreeResources( drmModeResPtr ptr );
152 extern void drmModeFreeFB( drmModeFBPtr ptr );
153 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
154 extern void drmModeFreeOutput( drmModeOutputPtr ptr );
155
156 /**
157  * Retrives all of the resources associated with a card.
158  */
159 extern drmModeResPtr drmModeGetResources(int fd);
160
161
162 /*
163  * FrameBuffer manipulation.
164  */
165
166 /**
167  * Retrive information about framebuffer bufferId
168  */
169 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
170
171 /**
172  * Creates a new framebuffer with an buffer object as its scanout buffer.
173  */
174 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
175                         uint8_t bpp, uint32_t pitch, drmBO *bo,
176                         uint32_t *buf_id);
177 /**
178  * Destroies the given framebuffer.
179  */
180 extern int drmModeRmFB(int fd, uint32_t bufferId);
181
182
183 /*
184  * Crtc functions
185  */
186
187 /**
188  * Retrive information about the ctrt crtcId
189  */
190 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
191
192 /**
193  * Set the mode on a crtc crtcId with the given mode modeId.
194  */
195 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
196                    uint32_t x, uint32_t y, uint32_t *outputs, int count,
197                    struct drm_mode_modeinfo *mode);
198
199
200 /*
201  * Output manipulation
202  */
203
204 /**
205  * Retrive information about the output outputId.
206  */
207 extern drmModeOutputPtr drmModeGetOutput(int fd,
208                 uint32_t outputId);
209
210 /**
211  * Attaches the given mode to an output.
212  */
213 extern int drmModeAttachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info);
214
215 /**
216  * Detaches a mode from the output
217  * must be unused, by the given mode.
218  */
219 extern int drmModeDetachMode(int fd, uint32_t outputId, struct drm_mode_modeinfo *mode_info);
220
221 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
222 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
223
224 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
225 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
226 extern int drmModeOutputSetProperty(int fd, uint32_t output_id, uint32_t property_id,
227                                     uint64_t value);