xf86drmMode.h revision 22944501
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) 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
13 * Copyright (c) 2007-2008 Dave Airlie <airlied@linux.ie>
14 * Copyright (c) 2007-2008 Jakob Bornecrantz <wallbraker@gmail.com>
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 * IN THE SOFTWARE.
33 *
34 */
35
36#include <drm.h>
37
38/*
39 * This is the interface for modesetting for drm.
40 *
41 * In order to use this interface you must include either <stdint.h> or another
42 * header defining uint32_t, int32_t and uint16_t.
43 *
44 * It aims to provide a randr1.2 compatible interface for modesettings in the
45 * kernel, the interface is also ment to be used by libraries like EGL.
46 *
47 * More information can be found in randrproto.txt which can be found here:
48 * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
49 *
50 * There are some major diffrences to be noted. Unlike the randr1.2 proto you
51 * need to create the memory object of the framebuffer yourself with the ttm
52 * buffer object interface. This object needs to be pinned.
53 */
54
55/*
56 * If we pickup an old version of drm.h which doesn't include drm_mode.h
57 * we should redefine defines. This is so that builds doesn't breaks with
58 * new libdrm on old kernels.
59 */
60#ifndef _DRM_MODE_H
61
62#define DRM_DISPLAY_INFO_LEN    32
63#define DRM_CONNECTOR_NAME_LEN  32
64#define DRM_DISPLAY_MODE_LEN    32
65#define DRM_PROP_NAME_LEN       32
66
67#define DRM_MODE_TYPE_BUILTIN   (1<<0)
68#define DRM_MODE_TYPE_CLOCK_C   ((1<<1) | DRM_MODE_TYPE_BUILTIN)
69#define DRM_MODE_TYPE_CRTC_C    ((1<<2) | DRM_MODE_TYPE_BUILTIN)
70#define DRM_MODE_TYPE_PREFERRED (1<<3)
71#define DRM_MODE_TYPE_DEFAULT   (1<<4)
72#define DRM_MODE_TYPE_USERDEF   (1<<5)
73#define DRM_MODE_TYPE_DRIVER    (1<<6)
74
75/* Video mode flags */
76/* bit compatible with the xorg definitions. */
77#define DRM_MODE_FLAG_PHSYNC    (1<<0)
78#define DRM_MODE_FLAG_NHSYNC    (1<<1)
79#define DRM_MODE_FLAG_PVSYNC    (1<<2)
80#define DRM_MODE_FLAG_NVSYNC    (1<<3)
81#define DRM_MODE_FLAG_INTERLACE (1<<4)
82#define DRM_MODE_FLAG_DBLSCAN   (1<<5)
83#define DRM_MODE_FLAG_CSYNC     (1<<6)
84#define DRM_MODE_FLAG_PCSYNC    (1<<7)
85#define DRM_MODE_FLAG_NCSYNC    (1<<8)
86#define DRM_MODE_FLAG_HSKEW     (1<<9) /* hskew provided */
87#define DRM_MODE_FLAG_BCAST     (1<<10)
88#define DRM_MODE_FLAG_PIXMUX    (1<<11)
89#define DRM_MODE_FLAG_DBLCLK    (1<<12)
90#define DRM_MODE_FLAG_CLKDIV2   (1<<13)
91
92/* DPMS flags */
93/* bit compatible with the xorg definitions. */
94#define DRM_MODE_DPMS_ON        0
95#define DRM_MODE_DPMS_STANDBY   1
96#define DRM_MODE_DPMS_SUSPEND   2
97#define DRM_MODE_DPMS_OFF       3
98
99/* Scaling mode options */
100#define DRM_MODE_SCALE_NON_GPU          0
101#define DRM_MODE_SCALE_FULLSCREEN       1
102#define DRM_MODE_SCALE_NO_SCALE         2
103#define DRM_MODE_SCALE_ASPECT           3
104
105/* Dithering mode options */
106#define DRM_MODE_DITHERING_OFF  0
107#define DRM_MODE_DITHERING_ON   1
108
109#define DRM_MODE_ENCODER_NONE   0
110#define DRM_MODE_ENCODER_DAC    1
111#define DRM_MODE_ENCODER_TMDS   2
112#define DRM_MODE_ENCODER_LVDS   3
113#define DRM_MODE_ENCODER_TVDAC  4
114
115#define DRM_MODE_SUBCONNECTOR_Automatic 0
116#define DRM_MODE_SUBCONNECTOR_Unknown   0
117#define DRM_MODE_SUBCONNECTOR_DVID      3
118#define DRM_MODE_SUBCONNECTOR_DVIA      4
119#define DRM_MODE_SUBCONNECTOR_Composite 5
120#define DRM_MODE_SUBCONNECTOR_SVIDEO    6
121#define DRM_MODE_SUBCONNECTOR_Component 8
122
123#define DRM_MODE_CONNECTOR_Unknown      0
124#define DRM_MODE_CONNECTOR_VGA          1
125#define DRM_MODE_CONNECTOR_DVII         2
126#define DRM_MODE_CONNECTOR_DVID         3
127#define DRM_MODE_CONNECTOR_DVIA         4
128#define DRM_MODE_CONNECTOR_Composite    5
129#define DRM_MODE_CONNECTOR_SVIDEO       6
130#define DRM_MODE_CONNECTOR_LVDS         7
131#define DRM_MODE_CONNECTOR_Component    8
132#define DRM_MODE_CONNECTOR_9PinDIN      9
133#define DRM_MODE_CONNECTOR_DisplayPort  10
134#define DRM_MODE_CONNECTOR_HDMIA        11
135#define DRM_MODE_CONNECTOR_HDMIB        12
136#define DRM_MODE_CONNECTOR_TV		13
137#define DRM_MODE_CONNECTOR_eDP		14
138
139#define DRM_MODE_PROP_PENDING   (1<<0)
140#define DRM_MODE_PROP_RANGE     (1<<1)
141#define DRM_MODE_PROP_IMMUTABLE (1<<2)
142#define DRM_MODE_PROP_ENUM      (1<<3) /* enumerated type with text strings */
143#define DRM_MODE_PROP_BLOB      (1<<4)
144
145#define DRM_MODE_CURSOR_BO      (1<<0)
146#define DRM_MODE_CURSOR_MOVE    (1<<1)
147
148#endif /* _DRM_MODE_H */
149
150
151/*
152 * Feature defines
153 *
154 * Just because these are defined doesn't mean that the kernel
155 * can do that feature, its just for new code vs old libdrm.
156 */
157#define DRM_MODE_FEATURE_KMS		1
158#define DRM_MODE_FEATURE_DIRTYFB	1
159
160
161typedef struct _drmModeRes {
162
163	int count_fbs;
164	uint32_t *fbs;
165
166	int count_crtcs;
167	uint32_t *crtcs;
168
169	int count_connectors;
170	uint32_t *connectors;
171
172	int count_encoders;
173	uint32_t *encoders;
174
175	uint32_t min_width, max_width;
176	uint32_t min_height, max_height;
177} drmModeRes, *drmModeResPtr;
178
179typedef struct _drmModeModeInfo {
180	uint32_t clock;
181	uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
182	uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
183
184	uint32_t vrefresh;
185
186	uint32_t flags;
187	uint32_t type;
188	char name[DRM_DISPLAY_MODE_LEN];
189} drmModeModeInfo, *drmModeModeInfoPtr;
190
191typedef struct _drmModeFB {
192	uint32_t fb_id;
193	uint32_t width, height;
194	uint32_t pitch;
195	uint32_t bpp;
196	uint32_t depth;
197	/* driver specific handle */
198	uint32_t handle;
199} drmModeFB, *drmModeFBPtr;
200
201typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
202
203typedef struct _drmModePropertyBlob {
204	uint32_t id;
205	uint32_t length;
206	void *data;
207} drmModePropertyBlobRes, *drmModePropertyBlobPtr;
208
209typedef struct _drmModeProperty {
210	uint32_t prop_id;
211	uint32_t flags;
212	char name[DRM_PROP_NAME_LEN];
213	int count_values;
214	uint64_t *values; // store the blob lengths
215	int count_enums;
216	struct drm_mode_property_enum *enums;
217	int count_blobs;
218	uint32_t *blob_ids; // store the blob IDs
219} drmModePropertyRes, *drmModePropertyPtr;
220
221typedef struct _drmModeCrtc {
222	uint32_t crtc_id;
223	uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
224
225	uint32_t x, y; /**< Position on the framebuffer */
226	uint32_t width, height;
227	int mode_valid;
228	drmModeModeInfo mode;
229
230	int gamma_size; /**< Number of gamma stops */
231
232} drmModeCrtc, *drmModeCrtcPtr;
233
234typedef struct _drmModeEncoder {
235	uint32_t encoder_id;
236	uint32_t encoder_type;
237	uint32_t crtc_id;
238	uint32_t possible_crtcs;
239	uint32_t possible_clones;
240} drmModeEncoder, *drmModeEncoderPtr;
241
242typedef enum {
243	DRM_MODE_CONNECTED         = 1,
244	DRM_MODE_DISCONNECTED      = 2,
245	DRM_MODE_UNKNOWNCONNECTION = 3
246} drmModeConnection;
247
248typedef enum {
249	DRM_MODE_SUBPIXEL_UNKNOWN        = 1,
250	DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
251	DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
252	DRM_MODE_SUBPIXEL_VERTICAL_RGB   = 4,
253	DRM_MODE_SUBPIXEL_VERTICAL_BGR   = 5,
254	DRM_MODE_SUBPIXEL_NONE           = 6
255} drmModeSubPixel;
256
257typedef struct _drmModeConnector {
258	uint32_t connector_id;
259	uint32_t encoder_id; /**< Encoder currently connected to */
260	uint32_t connector_type;
261	uint32_t connector_type_id;
262	drmModeConnection connection;
263	uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
264	drmModeSubPixel subpixel;
265
266	int count_modes;
267	drmModeModeInfoPtr modes;
268
269	int count_props;
270	uint32_t *props; /**< List of property ids */
271	uint64_t *prop_values; /**< List of property values */
272
273	int count_encoders;
274	uint32_t *encoders; /**< List of encoder ids */
275} drmModeConnector, *drmModeConnectorPtr;
276
277
278
279extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
280extern void drmModeFreeResources( drmModeResPtr ptr );
281extern void drmModeFreeFB( drmModeFBPtr ptr );
282extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
283extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
284extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
285
286/**
287 * Retrives all of the resources associated with a card.
288 */
289extern drmModeResPtr drmModeGetResources(int fd);
290
291/*
292 * FrameBuffer manipulation.
293 */
294
295/**
296 * Retrive information about framebuffer bufferId
297 */
298extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
299
300/**
301 * Creates a new framebuffer with an buffer object as its scanout buffer.
302 */
303extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
304			uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
305			uint32_t *buf_id);
306/**
307 * Destroies the given framebuffer.
308 */
309extern int drmModeRmFB(int fd, uint32_t bufferId);
310
311/**
312 * Mark a region of a framebuffer as dirty.
313 */
314extern int drmModeDirtyFB(int fd, uint32_t bufferId,
315			  drmModeClipPtr clips, uint32_t num_clips);
316
317
318/*
319 * Crtc functions
320 */
321
322/**
323 * Retrive information about the ctrt crtcId
324 */
325extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
326
327/**
328 * Set the mode on a crtc crtcId with the given mode modeId.
329 */
330int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
331                   uint32_t x, uint32_t y, uint32_t *connectors, int count,
332		   drmModeModeInfoPtr mode);
333
334/*
335 * Cursor functions
336 */
337
338/**
339 * Set the cursor on crtc
340 */
341int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
342
343/**
344 * Move the cursor on crtc
345 */
346int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
347
348/**
349 * Encoder functions
350 */
351drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
352
353/*
354 * Connector manipulation
355 */
356
357/**
358 * Retrive information about the connector connectorId.
359 */
360extern drmModeConnectorPtr drmModeGetConnector(int fd,
361		uint32_t connectorId);
362
363/**
364 * Attaches the given mode to an connector.
365 */
366extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
367
368/**
369 * Detaches a mode from the connector
370 * must be unused, by the given mode.
371 */
372extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
373
374extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
375extern void drmModeFreeProperty(drmModePropertyPtr ptr);
376
377extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
378extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
379extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
380				    uint64_t value);
381extern int drmCheckModesettingSupported(const char *busid);
382
383extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
384			       uint16_t *red, uint16_t *green, uint16_t *blue);
385extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
386			       uint16_t *red, uint16_t *green, uint16_t *blue);
387extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
388			   uint32_t flags, void *user_data);
389