blob: 991e3f94cc363d2bd8a381730559d42a82e306a7 [file] [log] [blame]
Jesse Barnes731cd552008-12-17 10:09:49 -08001/*
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
David Herrmanfd39e612012-03-09 13:40:14 -050036#ifndef _XF86DRMMODE_H_
37#define _XF86DRMMODE_H_
38
Tapani Pällicfee5212011-09-23 14:17:42 +030039#if defined(__cplusplus) || defined(c_plusplus)
40extern "C" {
41#endif
42
Jesse Barnes731cd552008-12-17 10:09:49 -080043#include <drm.h>
44
45/*
46 * This is the interface for modesetting for drm.
47 *
48 * In order to use this interface you must include either <stdint.h> or another
49 * header defining uint32_t, int32_t and uint16_t.
50 *
51 * It aims to provide a randr1.2 compatible interface for modesettings in the
52 * kernel, the interface is also ment to be used by libraries like EGL.
53 *
54 * More information can be found in randrproto.txt which can be found here:
55 * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
56 *
57 * There are some major diffrences to be noted. Unlike the randr1.2 proto you
58 * need to create the memory object of the framebuffer yourself with the ttm
59 * buffer object interface. This object needs to be pinned.
60 */
61
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +010062/*
63 * If we pickup an old version of drm.h which doesn't include drm_mode.h
64 * we should redefine defines. This is so that builds doesn't breaks with
65 * new libdrm on old kernels.
66 */
67#ifndef _DRM_MODE_H
68
69#define DRM_DISPLAY_INFO_LEN 32
70#define DRM_CONNECTOR_NAME_LEN 32
71#define DRM_DISPLAY_MODE_LEN 32
72#define DRM_PROP_NAME_LEN 32
73
74#define DRM_MODE_TYPE_BUILTIN (1<<0)
75#define DRM_MODE_TYPE_CLOCK_C ((1<<1) | DRM_MODE_TYPE_BUILTIN)
76#define DRM_MODE_TYPE_CRTC_C ((1<<2) | DRM_MODE_TYPE_BUILTIN)
77#define DRM_MODE_TYPE_PREFERRED (1<<3)
78#define DRM_MODE_TYPE_DEFAULT (1<<4)
79#define DRM_MODE_TYPE_USERDEF (1<<5)
80#define DRM_MODE_TYPE_DRIVER (1<<6)
81
82/* Video mode flags */
83/* bit compatible with the xorg definitions. */
84#define DRM_MODE_FLAG_PHSYNC (1<<0)
85#define DRM_MODE_FLAG_NHSYNC (1<<1)
86#define DRM_MODE_FLAG_PVSYNC (1<<2)
87#define DRM_MODE_FLAG_NVSYNC (1<<3)
88#define DRM_MODE_FLAG_INTERLACE (1<<4)
89#define DRM_MODE_FLAG_DBLSCAN (1<<5)
90#define DRM_MODE_FLAG_CSYNC (1<<6)
91#define DRM_MODE_FLAG_PCSYNC (1<<7)
92#define DRM_MODE_FLAG_NCSYNC (1<<8)
93#define DRM_MODE_FLAG_HSKEW (1<<9) /* hskew provided */
94#define DRM_MODE_FLAG_BCAST (1<<10)
95#define DRM_MODE_FLAG_PIXMUX (1<<11)
96#define DRM_MODE_FLAG_DBLCLK (1<<12)
97#define DRM_MODE_FLAG_CLKDIV2 (1<<13)
98
99/* DPMS flags */
100/* bit compatible with the xorg definitions. */
101#define DRM_MODE_DPMS_ON 0
102#define DRM_MODE_DPMS_STANDBY 1
103#define DRM_MODE_DPMS_SUSPEND 2
104#define DRM_MODE_DPMS_OFF 3
105
106/* Scaling mode options */
107#define DRM_MODE_SCALE_NON_GPU 0
108#define DRM_MODE_SCALE_FULLSCREEN 1
109#define DRM_MODE_SCALE_NO_SCALE 2
110#define DRM_MODE_SCALE_ASPECT 3
111
112/* Dithering mode options */
113#define DRM_MODE_DITHERING_OFF 0
114#define DRM_MODE_DITHERING_ON 1
115
116#define DRM_MODE_ENCODER_NONE 0
117#define DRM_MODE_ENCODER_DAC 1
118#define DRM_MODE_ENCODER_TMDS 2
119#define DRM_MODE_ENCODER_LVDS 3
120#define DRM_MODE_ENCODER_TVDAC 4
121
122#define DRM_MODE_SUBCONNECTOR_Automatic 0
123#define DRM_MODE_SUBCONNECTOR_Unknown 0
124#define DRM_MODE_SUBCONNECTOR_DVID 3
125#define DRM_MODE_SUBCONNECTOR_DVIA 4
126#define DRM_MODE_SUBCONNECTOR_Composite 5
127#define DRM_MODE_SUBCONNECTOR_SVIDEO 6
128#define DRM_MODE_SUBCONNECTOR_Component 8
129
130#define DRM_MODE_CONNECTOR_Unknown 0
131#define DRM_MODE_CONNECTOR_VGA 1
132#define DRM_MODE_CONNECTOR_DVII 2
133#define DRM_MODE_CONNECTOR_DVID 3
134#define DRM_MODE_CONNECTOR_DVIA 4
135#define DRM_MODE_CONNECTOR_Composite 5
136#define DRM_MODE_CONNECTOR_SVIDEO 6
137#define DRM_MODE_CONNECTOR_LVDS 7
138#define DRM_MODE_CONNECTOR_Component 8
139#define DRM_MODE_CONNECTOR_9PinDIN 9
140#define DRM_MODE_CONNECTOR_DisplayPort 10
141#define DRM_MODE_CONNECTOR_HDMIA 11
142#define DRM_MODE_CONNECTOR_HDMIB 12
Alex Deucher4a17be42010-02-10 19:39:46 -0500143#define DRM_MODE_CONNECTOR_TV 13
144#define DRM_MODE_CONNECTOR_eDP 14
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100145
146#define DRM_MODE_PROP_PENDING (1<<0)
147#define DRM_MODE_PROP_RANGE (1<<1)
148#define DRM_MODE_PROP_IMMUTABLE (1<<2)
149#define DRM_MODE_PROP_ENUM (1<<3) /* enumerated type with text strings */
150#define DRM_MODE_PROP_BLOB (1<<4)
151
152#define DRM_MODE_CURSOR_BO (1<<0)
153#define DRM_MODE_CURSOR_MOVE (1<<1)
154
155#endif /* _DRM_MODE_H */
156
Jakob Bornecrantz3e486132009-11-24 18:00:12 +0100157
158/*
159 * Feature defines
160 *
161 * Just because these are defined doesn't mean that the kernel
162 * can do that feature, its just for new code vs old libdrm.
163 */
164#define DRM_MODE_FEATURE_KMS 1
165#define DRM_MODE_FEATURE_DIRTYFB 1
166
167
Jesse Barnes731cd552008-12-17 10:09:49 -0800168typedef struct _drmModeRes {
169
170 int count_fbs;
171 uint32_t *fbs;
172
173 int count_crtcs;
174 uint32_t *crtcs;
175
176 int count_connectors;
177 uint32_t *connectors;
178
179 int count_encoders;
180 uint32_t *encoders;
181
182 uint32_t min_width, max_width;
183 uint32_t min_height, max_height;
184} drmModeRes, *drmModeResPtr;
185
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100186typedef struct _drmModeModeInfo {
187 uint32_t clock;
188 uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
189 uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
190
Marcin Kościelnicki694ef592010-02-27 15:04:42 +0000191 uint32_t vrefresh;
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100192
193 uint32_t flags;
194 uint32_t type;
195 char name[DRM_DISPLAY_MODE_LEN];
196} drmModeModeInfo, *drmModeModeInfoPtr;
197
198typedef struct _drmModeFB {
199 uint32_t fb_id;
200 uint32_t width, height;
201 uint32_t pitch;
202 uint32_t bpp;
203 uint32_t depth;
204 /* driver specific handle */
205 uint32_t handle;
206} drmModeFB, *drmModeFBPtr;
Jesse Barnes731cd552008-12-17 10:09:49 -0800207
Jakob Bornecrantz3e486132009-11-24 18:00:12 +0100208typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
209
Jesse Barnes731cd552008-12-17 10:09:49 -0800210typedef struct _drmModePropertyBlob {
211 uint32_t id;
212 uint32_t length;
213 void *data;
214} drmModePropertyBlobRes, *drmModePropertyBlobPtr;
215
216typedef struct _drmModeProperty {
217 uint32_t prop_id;
218 uint32_t flags;
219 char name[DRM_PROP_NAME_LEN];
220 int count_values;
221 uint64_t *values; // store the blob lengths
222 int count_enums;
223 struct drm_mode_property_enum *enums;
224 int count_blobs;
225 uint32_t *blob_ids; // store the blob IDs
226} drmModePropertyRes, *drmModePropertyPtr;
227
228typedef struct _drmModeCrtc {
229 uint32_t crtc_id;
230 uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
231
232 uint32_t x, y; /**< Position on the framebuffer */
233 uint32_t width, height;
234 int mode_valid;
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100235 drmModeModeInfo mode;
Jesse Barnes731cd552008-12-17 10:09:49 -0800236
237 int gamma_size; /**< Number of gamma stops */
238
239} drmModeCrtc, *drmModeCrtcPtr;
240
241typedef struct _drmModeEncoder {
242 uint32_t encoder_id;
243 uint32_t encoder_type;
244 uint32_t crtc_id;
245 uint32_t possible_crtcs;
246 uint32_t possible_clones;
247} drmModeEncoder, *drmModeEncoderPtr;
248
249typedef enum {
250 DRM_MODE_CONNECTED = 1,
251 DRM_MODE_DISCONNECTED = 2,
252 DRM_MODE_UNKNOWNCONNECTION = 3
253} drmModeConnection;
254
255typedef enum {
256 DRM_MODE_SUBPIXEL_UNKNOWN = 1,
257 DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
258 DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
259 DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4,
260 DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5,
261 DRM_MODE_SUBPIXEL_NONE = 6
262} drmModeSubPixel;
263
264typedef struct _drmModeConnector {
265 uint32_t connector_id;
266 uint32_t encoder_id; /**< Encoder currently connected to */
267 uint32_t connector_type;
268 uint32_t connector_type_id;
269 drmModeConnection connection;
270 uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
271 drmModeSubPixel subpixel;
272
273 int count_modes;
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100274 drmModeModeInfoPtr modes;
Jesse Barnes731cd552008-12-17 10:09:49 -0800275
276 int count_props;
277 uint32_t *props; /**< List of property ids */
278 uint64_t *prop_values; /**< List of property values */
279
280 int count_encoders;
281 uint32_t *encoders; /**< List of encoder ids */
282} drmModeConnector, *drmModeConnectorPtr;
283
Jesse Barnesac168bf2011-04-29 08:53:53 -0700284typedef struct _drmModePlane {
285 uint32_t count_formats;
286 uint32_t *formats;
287 uint32_t plane_id;
Jesse Barnes731cd552008-12-17 10:09:49 -0800288
Jesse Barnesac168bf2011-04-29 08:53:53 -0700289 uint32_t crtc_id;
290 uint32_t fb_id;
291
292 uint32_t crtc_x, crtc_y;
293 uint32_t x, y;
294
295 uint32_t possible_crtcs;
296 uint32_t gamma_size;
297} drmModePlane, *drmModePlanePtr;
298
299typedef struct _drmModePlaneRes {
300 uint32_t count_planes;
301 uint32_t *planes;
302} drmModePlaneRes, *drmModePlaneResPtr;
Jesse Barnes731cd552008-12-17 10:09:49 -0800303
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100304extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
Jesse Barnes731cd552008-12-17 10:09:49 -0800305extern void drmModeFreeResources( drmModeResPtr ptr );
306extern void drmModeFreeFB( drmModeFBPtr ptr );
307extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
308extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
309extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
Jesse Barnesac168bf2011-04-29 08:53:53 -0700310extern void drmModeFreePlane( drmModePlanePtr ptr );
Ville Syrjäläa14c3dd2012-02-02 14:53:41 -0500311extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr);
Jesse Barnes731cd552008-12-17 10:09:49 -0800312
313/**
314 * Retrives all of the resources associated with a card.
315 */
316extern drmModeResPtr drmModeGetResources(int fd);
317
318/*
319 * FrameBuffer manipulation.
320 */
321
322/**
323 * Retrive information about framebuffer bufferId
324 */
325extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
326
327/**
328 * Creates a new framebuffer with an buffer object as its scanout buffer.
329 */
330extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
331 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
332 uint32_t *buf_id);
Jesse Barnesac168bf2011-04-29 08:53:53 -0700333/* ...with a specific pixel format */
334extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
335 uint32_t pixel_format, uint32_t bo_handles[4],
336 uint32_t pitches[4], uint32_t offsets[4],
337 uint32_t *buf_id, uint32_t flags);
Jesse Barnes731cd552008-12-17 10:09:49 -0800338/**
339 * Destroies the given framebuffer.
340 */
341extern int drmModeRmFB(int fd, uint32_t bufferId);
342
Jakob Bornecrantz3e486132009-11-24 18:00:12 +0100343/**
344 * Mark a region of a framebuffer as dirty.
345 */
346extern int drmModeDirtyFB(int fd, uint32_t bufferId,
347 drmModeClipPtr clips, uint32_t num_clips);
348
349
Jesse Barnes731cd552008-12-17 10:09:49 -0800350/*
351 * Crtc functions
352 */
353
354/**
355 * Retrive information about the ctrt crtcId
356 */
357extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
358
359/**
360 * Set the mode on a crtc crtcId with the given mode modeId.
361 */
362int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
363 uint32_t x, uint32_t y, uint32_t *connectors, int count,
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100364 drmModeModeInfoPtr mode);
Jesse Barnes731cd552008-12-17 10:09:49 -0800365
366/*
367 * Cursor functions
368 */
369
370/**
371 * Set the cursor on crtc
372 */
373int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
374
375/**
376 * Move the cursor on crtc
377 */
378int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
379
380/**
381 * Encoder functions
382 */
383drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
384
385/*
386 * Connector manipulation
387 */
388
389/**
390 * Retrive information about the connector connectorId.
391 */
392extern drmModeConnectorPtr drmModeGetConnector(int fd,
393 uint32_t connectorId);
394
395/**
396 * Attaches the given mode to an connector.
397 */
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100398extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
Jesse Barnes731cd552008-12-17 10:09:49 -0800399
400/**
401 * Detaches a mode from the connector
402 * must be unused, by the given mode.
403 */
Jakob Bornecrantzeb78c532009-02-11 16:43:20 +0100404extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
Jesse Barnes731cd552008-12-17 10:09:49 -0800405
406extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
407extern void drmModeFreeProperty(drmModePropertyPtr ptr);
408
409extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
410extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
411extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
412 uint64_t value);
413extern int drmCheckModesettingSupported(const char *busid);
414
415extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
416 uint16_t *red, uint16_t *green, uint16_t *blue);
417extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
418 uint16_t *red, uint16_t *green, uint16_t *blue);
Kristian Høgsbergb80bcff2009-11-12 14:06:45 -0500419extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
420 uint32_t flags, void *user_data);
Tapani Pällicfee5212011-09-23 14:17:42 +0300421
Jesse Barnesac168bf2011-04-29 08:53:53 -0700422extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
423extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
424extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
425 uint32_t fb_id, uint32_t flags,
426 uint32_t crtc_x, uint32_t crtc_y,
427 uint32_t crtc_w, uint32_t crtc_h,
428 uint32_t src_x, uint32_t src_y,
429 uint32_t src_w, uint32_t src_h);
430
Tapani Pällicfee5212011-09-23 14:17:42 +0300431#if defined(__cplusplus) || defined(c_plusplus)
432}
433#endif
David Herrmanfd39e612012-03-09 13:40:14 -0500434
435#endif