libdrm: NOTE! Default branch is now main
[drm/libdrm.git] / xf86drmMode.h
blob4bde6e352e547c3118cc17f74087cee5f893b9eb
1 /*
2 * \file xf86drmMode.h
3 * Header for DRM modesetting interface.
5 * \author Jakob Bornecrantz <wallbraker@gmail.com>
7 * \par Acknowledgements:
8 * Feb 2007, Dave Airlie <airlied@linux.ie>
9 */
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
32 * IN THE SOFTWARE.
36 #ifndef _XF86DRMMODE_H_
37 #define _XF86DRMMODE_H_
39 #if defined(__cplusplus)
40 extern "C" {
41 #endif
43 #include <drm.h>
44 #include <drm_mode.h>
45 #include <stddef.h>
46 #include <stdint.h>
49 * This is the interface for modesetting for drm.
51 * It aims to provide a randr1.2 compatible interface for modesettings in the
52 * kernel, the interface is also meant 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 differences 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 * Feature defines
65 * Just because these are defined doesn't mean that the kernel
66 * can do that feature, its just for new code vs old libdrm.
68 #define DRM_MODE_FEATURE_KMS 1
69 #define DRM_MODE_FEATURE_DIRTYFB 1
72 typedef struct _drmModeRes {
74 int count_fbs;
75 uint32_t *fbs;
77 int count_crtcs;
78 uint32_t *crtcs;
80 int count_connectors;
81 uint32_t *connectors;
83 int count_encoders;
84 uint32_t *encoders;
86 uint32_t min_width, max_width;
87 uint32_t min_height, max_height;
88 } drmModeRes, *drmModeResPtr;
90 typedef struct _drmModeModeInfo {
91 uint32_t clock;
92 uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
93 uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
95 uint32_t vrefresh;
97 uint32_t flags;
98 uint32_t type;
99 char name[DRM_DISPLAY_MODE_LEN];
100 } drmModeModeInfo, *drmModeModeInfoPtr;
102 typedef struct _drmModeFB {
103 uint32_t fb_id;
104 uint32_t width, height;
105 uint32_t pitch;
106 uint32_t bpp;
107 uint32_t depth;
108 /* driver specific handle */
109 uint32_t handle;
110 } drmModeFB, *drmModeFBPtr;
112 typedef struct _drmModeFB2 {
113 uint32_t fb_id;
114 uint32_t width, height;
115 uint32_t pixel_format; /* fourcc code from drm_fourcc.h */
116 uint64_t modifier; /* applies to all buffers */
117 uint32_t flags;
119 /* per-plane GEM handle; may be duplicate entries for multiple planes */
120 uint32_t handles[4];
121 uint32_t pitches[4]; /* bytes */
122 uint32_t offsets[4]; /* bytes */
123 } drmModeFB2, *drmModeFB2Ptr;
125 typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
127 typedef struct _drmModePropertyBlob {
128 uint32_t id;
129 uint32_t length;
130 void *data;
131 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
133 typedef struct _drmModeProperty {
134 uint32_t prop_id;
135 uint32_t flags;
136 char name[DRM_PROP_NAME_LEN];
137 int count_values;
138 uint64_t *values; /* store the blob lengths */
139 int count_enums;
140 struct drm_mode_property_enum *enums;
141 int count_blobs;
142 uint32_t *blob_ids; /* store the blob IDs */
143 } drmModePropertyRes, *drmModePropertyPtr;
145 static __inline int drm_property_type_is(drmModePropertyPtr property,
146 uint32_t type)
148 /* instanceof for props.. handles extended type vs original types: */
149 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
150 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
151 return property->flags & type;
154 static inline uint32_t drmModeGetPropertyType(const drmModePropertyRes *prop)
156 return prop->flags & (DRM_MODE_PROP_LEGACY_TYPE | DRM_MODE_PROP_EXTENDED_TYPE);
159 typedef struct _drmModeCrtc {
160 uint32_t crtc_id;
161 uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
163 uint32_t x, y; /**< Position on the framebuffer */
164 uint32_t width, height;
165 int mode_valid;
166 drmModeModeInfo mode;
168 int gamma_size; /**< Number of gamma stops */
170 } drmModeCrtc, *drmModeCrtcPtr;
172 typedef struct _drmModeEncoder {
173 uint32_t encoder_id;
174 uint32_t encoder_type;
175 uint32_t crtc_id;
176 uint32_t possible_crtcs;
177 uint32_t possible_clones;
178 } drmModeEncoder, *drmModeEncoderPtr;
181 * Describes the connector status.
183 * DRM_MODE_CONNECTED means that the connector has a sink plugged in.
184 * DRM_MODE_DISCONNECTED means the contrary. DRM_MODE_UNKNOWNCONNECTION is used
185 * when it could be either.
187 * User-space should first try to enable DRM_MODE_CONNECTED connectors and
188 * ignore other connectors. If there are no DRM_MODE_CONNECTED connectors,
189 * user-space should then try to probe and enable DRM_MODE_UNKNOWNCONNECTION
190 * connectors.
192 typedef enum {
193 DRM_MODE_CONNECTED = 1,
194 DRM_MODE_DISCONNECTED = 2,
195 DRM_MODE_UNKNOWNCONNECTION = 3
196 } drmModeConnection;
198 typedef enum {
199 DRM_MODE_SUBPIXEL_UNKNOWN = 1,
200 DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
201 DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
202 DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4,
203 DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5,
204 DRM_MODE_SUBPIXEL_NONE = 6
205 } drmModeSubPixel;
207 typedef struct _drmModeConnector {
208 uint32_t connector_id;
209 uint32_t encoder_id; /**< Encoder currently connected to */
210 uint32_t connector_type;
211 uint32_t connector_type_id;
212 drmModeConnection connection;
213 uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
214 drmModeSubPixel subpixel;
216 int count_modes;
217 drmModeModeInfoPtr modes;
219 int count_props;
220 uint32_t *props; /**< List of property ids */
221 uint64_t *prop_values; /**< List of property values */
223 int count_encoders;
224 uint32_t *encoders; /**< List of encoder ids */
225 } drmModeConnector, *drmModeConnectorPtr;
227 #define DRM_PLANE_TYPE_OVERLAY 0
228 #define DRM_PLANE_TYPE_PRIMARY 1
229 #define DRM_PLANE_TYPE_CURSOR 2
231 typedef struct _drmModeObjectProperties {
232 uint32_t count_props;
233 uint32_t *props;
234 uint64_t *prop_values;
235 } drmModeObjectProperties, *drmModeObjectPropertiesPtr;
237 typedef struct _drmModePlane {
238 uint32_t count_formats;
239 uint32_t *formats;
240 uint32_t plane_id;
242 uint32_t crtc_id;
243 uint32_t fb_id;
245 uint32_t crtc_x, crtc_y;
246 uint32_t x, y;
248 uint32_t possible_crtcs;
249 uint32_t gamma_size;
250 } drmModePlane, *drmModePlanePtr;
252 typedef struct _drmModePlaneRes {
253 uint32_t count_planes;
254 uint32_t *planes;
255 } drmModePlaneRes, *drmModePlaneResPtr;
257 extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
258 extern void drmModeFreeResources( drmModeResPtr ptr );
259 extern void drmModeFreeFB( drmModeFBPtr ptr );
260 extern void drmModeFreeFB2( drmModeFB2Ptr ptr );
261 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
262 extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
263 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
264 extern void drmModeFreePlane( drmModePlanePtr ptr );
265 extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr);
268 * Check whether the DRM node supports Kernel Mode-Setting.
270 * Returns 1 if suitable for KMS, 0 otherwise.
272 extern int drmIsKMS(int fd);
275 * Retrieves all of the resources associated with a card.
277 extern drmModeResPtr drmModeGetResources(int fd);
280 * FrameBuffer manipulation.
284 * Retrieve information about framebuffer bufferId
286 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
287 extern drmModeFB2Ptr drmModeGetFB2(int fd, uint32_t bufferId);
290 * Creates a new framebuffer with an buffer object as its scanout buffer.
292 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
293 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
294 uint32_t *buf_id);
295 /* ...with a specific pixel format */
296 extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
297 uint32_t pixel_format, const uint32_t bo_handles[4],
298 const uint32_t pitches[4], const uint32_t offsets[4],
299 uint32_t *buf_id, uint32_t flags);
301 /* ...with format modifiers */
302 int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height,
303 uint32_t pixel_format, const uint32_t bo_handles[4],
304 const uint32_t pitches[4], const uint32_t offsets[4],
305 const uint64_t modifier[4], uint32_t *buf_id,
306 uint32_t flags);
309 * Destroies the given framebuffer.
311 extern int drmModeRmFB(int fd, uint32_t bufferId);
314 * Mark a region of a framebuffer as dirty.
316 extern int drmModeDirtyFB(int fd, uint32_t bufferId,
317 drmModeClipPtr clips, uint32_t num_clips);
321 * Crtc functions
325 * Retrieve information about the ctrt crtcId
327 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
330 * Set the mode on a crtc crtcId with the given mode modeId.
332 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
333 uint32_t x, uint32_t y, uint32_t *connectors, int count,
334 drmModeModeInfoPtr mode);
337 * Cursor functions
341 * Set the cursor on crtc
343 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
345 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);
347 * Move the cursor on crtc
349 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
352 * Encoder functions
354 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
357 * Connector manipulation
361 * Retrieve all information about the connector connectorId. This will do a
362 * forced probe on the connector to retrieve remote information such as EDIDs
363 * from the display device.
365 extern drmModeConnectorPtr drmModeGetConnector(int fd,
366 uint32_t connectorId);
369 * Retrieve current information, i.e the currently active mode and encoder,
370 * about the connector connectorId. This will not do any probing on the
371 * connector or remote device, and only reports what is currently known.
372 * For the complete set of modes and encoders associated with the connector
373 * use drmModeGetConnector() which will do a probe to determine any display
374 * link changes first.
376 extern drmModeConnectorPtr drmModeGetConnectorCurrent(int fd,
377 uint32_t connector_id);
380 * Attaches the given mode to an connector.
382 extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
385 * Detaches a mode from the connector
386 * must be unused, by the given mode.
388 extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
390 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
391 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
393 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
394 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
395 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
396 uint64_t value);
397 extern int drmCheckModesettingSupported(const char *busid);
399 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
400 uint16_t *red, uint16_t *green, uint16_t *blue);
401 extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
402 uint16_t *red, uint16_t *green, uint16_t *blue);
403 extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
404 uint32_t flags, void *user_data);
405 extern int drmModePageFlipTarget(int fd, uint32_t crtc_id, uint32_t fb_id,
406 uint32_t flags, void *user_data,
407 uint32_t target_vblank);
409 extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
410 extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
411 extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
412 uint32_t fb_id, uint32_t flags,
413 int32_t crtc_x, int32_t crtc_y,
414 uint32_t crtc_w, uint32_t crtc_h,
415 uint32_t src_x, uint32_t src_y,
416 uint32_t src_w, uint32_t src_h);
418 extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
419 uint32_t object_id,
420 uint32_t object_type);
421 extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
422 extern int drmModeObjectSetProperty(int fd, uint32_t object_id,
423 uint32_t object_type, uint32_t property_id,
424 uint64_t value);
427 typedef struct _drmModeAtomicReq drmModeAtomicReq, *drmModeAtomicReqPtr;
429 extern drmModeAtomicReqPtr drmModeAtomicAlloc(void);
430 extern drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr req);
431 extern int drmModeAtomicMerge(drmModeAtomicReqPtr base,
432 drmModeAtomicReqPtr augment);
433 extern void drmModeAtomicFree(drmModeAtomicReqPtr req);
434 extern int drmModeAtomicGetCursor(drmModeAtomicReqPtr req);
435 extern void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor);
436 extern int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
437 uint32_t object_id,
438 uint32_t property_id,
439 uint64_t value);
440 extern int drmModeAtomicCommit(int fd,
441 drmModeAtomicReqPtr req,
442 uint32_t flags,
443 void *user_data);
445 extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size,
446 uint32_t *id);
447 extern int drmModeDestroyPropertyBlob(int fd, uint32_t id);
450 * DRM mode lease APIs. These create and manage new drm_masters with
451 * access to a subset of the available DRM resources
454 extern int drmModeCreateLease(int fd, const uint32_t *objects, int num_objects, int flags, uint32_t *lessee_id);
456 typedef struct drmModeLesseeList {
457 uint32_t count;
458 uint32_t lessees[];
459 } drmModeLesseeListRes, *drmModeLesseeListPtr;
461 extern drmModeLesseeListPtr drmModeListLessees(int fd);
463 typedef struct drmModeObjectList {
464 uint32_t count;
465 uint32_t objects[];
466 } drmModeObjectListRes, *drmModeObjectListPtr;
468 extern drmModeObjectListPtr drmModeGetLease(int fd);
470 extern int drmModeRevokeLease(int fd, uint32_t lessee_id);
472 #if defined(__cplusplus)
474 #endif
476 #endif