Merge branch 'master' of git+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         int count_modes;
67         struct drm_mode_modeinfo *modes;
68
69 } drmModeRes, *drmModeResPtr;
70
71 typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr;
72
73 typedef struct _drmModeCrtc {
74         unsigned int crtc_id;
75         unsigned int buffer_id; /**< FB id to connect to 0 = disconnect*/
76
77         uint32_t x, y; /**< Position on the frameuffer */
78         uint32_t width, height;
79         uint32_t mode; /**< Current mode used */
80
81         int count_outputs;
82         uint32_t outputs; /**< Outputs that are connected */
83
84         int count_possibles;
85         uint32_t possibles; /**< Outputs that can be connected */
86
87         int gamma_size; /**< Number of gamma stops */
88
89 } drmModeCrtc, *drmModeCrtcPtr;
90
91 typedef enum {
92         DRM_MODE_CONNECTED         = 1,
93         DRM_MODE_DISCONNECTED      = 2,
94         DRM_MODE_UNKNOWNCONNECTION = 3
95 } drmModeConnection;
96
97 typedef enum {
98         DRM_MODE_SUBPIXEL_UNKNOWN        = 1,
99         DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
100         DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
101         DRM_MODE_SUBPIXEL_VERTICAL_RGB   = 4,
102         DRM_MODE_SUBPIXEL_VERTICAL_BGR   = 5,
103         DRM_MODE_SUBPIXEL_NONE           = 6
104 } drmModeSubPixel;
105
106 typedef struct _drmModeOutput {
107         unsigned int output_id;
108
109         unsigned int crtc; /**< Crtc currently connected to */
110         unsigned char name[DRM_OUTPUT_NAME_LEN];
111         drmModeConnection connection;
112         uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
113         drmModeSubPixel subpixel;
114
115         int count_crtcs;
116         uint32_t crtcs; /**< Possible crtc to connect to */
117
118         int count_clones;
119         uint32_t clones; /**< Mask of clones */
120
121         int count_modes;
122         uint32_t *modes; /**< List of modes ids */
123
124 } drmModeOutput, *drmModeOutputPtr;
125
126
127
128 extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr );
129 extern void drmModeFreeResources( drmModeResPtr ptr );
130 extern void drmModeFreeFB( drmModeFBPtr ptr );
131 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
132 extern void drmModeFreeOutput( drmModeOutputPtr ptr );
133
134 /**
135  * Retrives all of the resources associated with a card.
136  */
137 extern drmModeResPtr drmModeGetResources(int fd);
138
139
140 /*
141  * FrameBuffer manipulation.
142  */
143
144 /**
145  * Retrive information about framebuffer bufferId
146  */
147 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
148
149 /**
150  * Creates a new framebuffer with an buffer object as its scanout buffer.
151  */
152 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
153                         uint8_t bpp, uint32_t pitch, drmBO *bo,
154                         uint32_t *buf_id);
155 /**
156  * Destroies the given framebuffer.
157  */
158 extern int drmModeRmFB(int fd, uint32_t bufferId);
159
160
161 /*
162  * Crtc functions
163  */
164
165 /**
166  * Retrive information about the ctrt crtcId
167  */
168 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
169
170 /**
171  * Set the mode on a crtc crtcId with the given mode modeId.
172  */
173 extern int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
174                 uint32_t x, uint32_t y, uint32_t modeId,
175                 uint32_t *outputs, int count);
176
177
178 /*
179  * Output manipulation
180  */
181
182 /**
183  * Retrive information about the output outputId.
184  */
185 extern drmModeOutputPtr drmModeGetOutput(int fd,
186                 uint32_t outputId);
187
188 /**
189  * Adds a new mode from the given mode info.
190  * Name must be unique.
191  */
192 extern uint32_t drmModeAddMode(int fd, struct drm_mode_modeinfo *modeInfo);
193
194 /**
195  * Removes a mode created with AddMode, must be unused.
196  */
197 extern int drmModeRmMode(int fd, uint32_t modeId);
198
199 /**
200  * Attaches the given mode to an output.
201  */
202 extern int drmModeAttachMode(int fd, uint32_t outputId, uint32_t modeId);
203
204 /**
205  * Detaches a mode from the output
206  * must be unused, by the given mode.
207  */
208 extern int drmModeDetachMode(int fd, uint32_t outputId, uint32_t modeId);
209