3 * Header for DRM modesetting interface.
5 * \author Jakob Bornecrantz <wallbraker@gmail.com>
7 * \par Acknowledgements:
8 * Feb 2007, Dave Airlie <airlied@linux.ie>
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>
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:
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
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
36 #ifndef _XF86DRMMODE_H_
37 #define _XF86DRMMODE_H_
39 #if defined(__cplusplus) || defined(c_plusplus)
46 * This is the interface for modesetting for drm.
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.
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.
54 * More information can be found in randrproto.txt which can be found here:
55 * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
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.
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.
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
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)
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 #define DRM_MODE_FLAG_3D_MASK (0x1f<<14)
99 #define DRM_MODE_FLAG_3D_NONE (0<<14)
100 #define DRM_MODE_FLAG_3D_FRAME_PACKING (1<<14)
101 #define DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE (2<<14)
102 #define DRM_MODE_FLAG_3D_LINE_ALTERNATIVE (3<<14)
103 #define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
104 #define DRM_MODE_FLAG_3D_L_DEPTH (5<<14)
105 #define DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
106 #define DRM_MODE_FLAG_3D_TOP_AND_BOTTOM (7<<14)
107 #define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
110 /* bit compatible with the xorg definitions. */
111 #define DRM_MODE_DPMS_ON 0
112 #define DRM_MODE_DPMS_STANDBY 1
113 #define DRM_MODE_DPMS_SUSPEND 2
114 #define DRM_MODE_DPMS_OFF 3
116 /* Scaling mode options */
117 #define DRM_MODE_SCALE_NON_GPU 0
118 #define DRM_MODE_SCALE_FULLSCREEN 1
119 #define DRM_MODE_SCALE_NO_SCALE 2
120 #define DRM_MODE_SCALE_ASPECT 3
122 /* Dithering mode options */
123 #define DRM_MODE_DITHERING_OFF 0
124 #define DRM_MODE_DITHERING_ON 1
126 #define DRM_MODE_ENCODER_NONE 0
127 #define DRM_MODE_ENCODER_DAC 1
128 #define DRM_MODE_ENCODER_TMDS 2
129 #define DRM_MODE_ENCODER_LVDS 3
130 #define DRM_MODE_ENCODER_TVDAC 4
131 #define DRM_MODE_ENCODER_VIRTUAL 5
132 #define DRM_MODE_ENCODER_DSI 6
134 #define DRM_MODE_SUBCONNECTOR_Automatic 0
135 #define DRM_MODE_SUBCONNECTOR_Unknown 0
136 #define DRM_MODE_SUBCONNECTOR_DVID 3
137 #define DRM_MODE_SUBCONNECTOR_DVIA 4
138 #define DRM_MODE_SUBCONNECTOR_Composite 5
139 #define DRM_MODE_SUBCONNECTOR_SVIDEO 6
140 #define DRM_MODE_SUBCONNECTOR_Component 8
141 #define DRM_MODE_SUBCONNECTOR_SCART 9
143 #define DRM_MODE_CONNECTOR_Unknown 0
144 #define DRM_MODE_CONNECTOR_VGA 1
145 #define DRM_MODE_CONNECTOR_DVII 2
146 #define DRM_MODE_CONNECTOR_DVID 3
147 #define DRM_MODE_CONNECTOR_DVIA 4
148 #define DRM_MODE_CONNECTOR_Composite 5
149 #define DRM_MODE_CONNECTOR_SVIDEO 6
150 #define DRM_MODE_CONNECTOR_LVDS 7
151 #define DRM_MODE_CONNECTOR_Component 8
152 #define DRM_MODE_CONNECTOR_9PinDIN 9
153 #define DRM_MODE_CONNECTOR_DisplayPort 10
154 #define DRM_MODE_CONNECTOR_HDMIA 11
155 #define DRM_MODE_CONNECTOR_HDMIB 12
156 #define DRM_MODE_CONNECTOR_TV 13
157 #define DRM_MODE_CONNECTOR_eDP 14
158 #define DRM_MODE_CONNECTOR_VIRTUAL 15
159 #define DRM_MODE_CONNECTOR_DSI 16
161 #define DRM_MODE_PROP_PENDING (1<<0)
162 #define DRM_MODE_PROP_RANGE (1<<1)
163 #define DRM_MODE_PROP_IMMUTABLE (1<<2)
164 #define DRM_MODE_PROP_ENUM (1<<3) /* enumerated type with text strings */
165 #define DRM_MODE_PROP_BLOB (1<<4)
167 #define DRM_MODE_CURSOR_BO (1<<0)
168 #define DRM_MODE_CURSOR_MOVE (1<<1)
170 #endif /* _DRM_MODE_H */
176 * Just because these are defined doesn't mean that the kernel
177 * can do that feature, its just for new code vs old libdrm.
179 #define DRM_MODE_FEATURE_KMS 1
180 #define DRM_MODE_FEATURE_DIRTYFB 1
183 typedef struct _drmModeRes {
191 int count_connectors;
192 uint32_t *connectors;
197 uint32_t min_width, max_width;
198 uint32_t min_height, max_height;
199 } drmModeRes, *drmModeResPtr;
201 typedef struct _drmModeModeInfo {
203 uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
204 uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
210 char name[DRM_DISPLAY_MODE_LEN];
211 } drmModeModeInfo, *drmModeModeInfoPtr;
213 typedef struct _drmModeFB {
215 uint32_t width, height;
219 /* driver specific handle */
221 } drmModeFB, *drmModeFBPtr;
223 typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
225 typedef struct _drmModePropertyBlob {
229 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
231 typedef struct _drmModeProperty {
234 char name[DRM_PROP_NAME_LEN];
236 uint64_t *values; /* store the blob lengths */
238 struct drm_mode_property_enum *enums;
240 uint32_t *blob_ids; /* store the blob IDs */
241 } drmModePropertyRes, *drmModePropertyPtr;
243 typedef struct _drmModeCrtc {
245 uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
247 uint32_t x, y; /**< Position on the framebuffer */
248 uint32_t width, height;
250 drmModeModeInfo mode;
252 int gamma_size; /**< Number of gamma stops */
254 } drmModeCrtc, *drmModeCrtcPtr;
256 typedef struct _drmModeEncoder {
258 uint32_t encoder_type;
260 uint32_t possible_crtcs;
261 uint32_t possible_clones;
262 } drmModeEncoder, *drmModeEncoderPtr;
265 DRM_MODE_CONNECTED = 1,
266 DRM_MODE_DISCONNECTED = 2,
267 DRM_MODE_UNKNOWNCONNECTION = 3
271 DRM_MODE_SUBPIXEL_UNKNOWN = 1,
272 DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
273 DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
274 DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4,
275 DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5,
276 DRM_MODE_SUBPIXEL_NONE = 6
279 typedef struct _drmModeConnector {
280 uint32_t connector_id;
281 uint32_t encoder_id; /**< Encoder currently connected to */
282 uint32_t connector_type;
283 uint32_t connector_type_id;
284 drmModeConnection connection;
285 uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
286 drmModeSubPixel subpixel;
289 drmModeModeInfoPtr modes;
292 uint32_t *props; /**< List of property ids */
293 uint64_t *prop_values; /**< List of property values */
296 uint32_t *encoders; /**< List of encoder ids */
297 } drmModeConnector, *drmModeConnectorPtr;
299 typedef struct _drmModeObjectProperties {
300 uint32_t count_props;
302 uint64_t *prop_values;
303 } drmModeObjectProperties, *drmModeObjectPropertiesPtr;
305 typedef struct _drmModePlane {
306 uint32_t count_formats;
313 uint32_t crtc_x, crtc_y;
316 uint32_t possible_crtcs;
318 } drmModePlane, *drmModePlanePtr;
320 typedef struct _drmModePlaneRes {
321 uint32_t count_planes;
323 } drmModePlaneRes, *drmModePlaneResPtr;
325 extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
326 extern void drmModeFreeResources( drmModeResPtr ptr );
327 extern void drmModeFreeFB( drmModeFBPtr ptr );
328 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
329 extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
330 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
331 extern void drmModeFreePlane( drmModePlanePtr ptr );
332 extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr);
335 * Retrives all of the resources associated with a card.
337 extern drmModeResPtr drmModeGetResources(int fd);
340 * FrameBuffer manipulation.
344 * Retrive information about framebuffer bufferId
346 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
349 * Creates a new framebuffer with an buffer object as its scanout buffer.
351 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
352 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
354 /* ...with a specific pixel format */
355 extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
356 uint32_t pixel_format, uint32_t bo_handles[4],
357 uint32_t pitches[4], uint32_t offsets[4],
358 uint32_t *buf_id, uint32_t flags);
360 * Destroies the given framebuffer.
362 extern int drmModeRmFB(int fd, uint32_t bufferId);
365 * Mark a region of a framebuffer as dirty.
367 extern int drmModeDirtyFB(int fd, uint32_t bufferId,
368 drmModeClipPtr clips, uint32_t num_clips);
376 * Retrive information about the ctrt crtcId
378 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
381 * Set the mode on a crtc crtcId with the given mode modeId.
383 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
384 uint32_t x, uint32_t y, uint32_t *connectors, int count,
385 drmModeModeInfoPtr mode);
392 * Set the cursor on crtc
394 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
396 int drmModeSetCursor2(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height, int32_t hot_x, int32_t hot_y);
398 * Move the cursor on crtc
400 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
405 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
408 * Connector manipulation
412 * Retrive information about the connector connectorId.
414 extern drmModeConnectorPtr drmModeGetConnector(int fd,
415 uint32_t connectorId);
418 * Attaches the given mode to an connector.
420 extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
423 * Detaches a mode from the connector
424 * must be unused, by the given mode.
426 extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
428 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
429 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
431 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
432 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
433 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
435 extern int drmCheckModesettingSupported(const char *busid);
437 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
438 uint16_t *red, uint16_t *green, uint16_t *blue);
439 extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
440 uint16_t *red, uint16_t *green, uint16_t *blue);
441 extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
442 uint32_t flags, void *user_data);
444 extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
445 extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
446 extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
447 uint32_t fb_id, uint32_t flags,
448 uint32_t crtc_x, uint32_t crtc_y,
449 uint32_t crtc_w, uint32_t crtc_h,
450 uint32_t src_x, uint32_t src_y,
451 uint32_t src_w, uint32_t src_h);
453 extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
455 uint32_t object_type);
456 extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
457 extern int drmModeObjectSetProperty(int fd, uint32_t object_id,
458 uint32_t object_type, uint32_t property_id,
461 #if defined(__cplusplus) || defined(c_plusplus)