xf86drmMode.h revision 4b3d3f37
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#ifndef _XF86DRMMODE_H_
37#define _XF86DRMMODE_H_
38
39#if defined(__cplusplus)
40extern "C" {
41#endif
42
43#include <drm.h>
44#include <drm_mode.h>
45#include <stddef.h>
46#include <stdint.h>
47
48/*
49 * This is the interface for modesetting for drm.
50 *
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.
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 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.
60 */
61
62/*
63 * Feature defines
64 *
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.
67 */
68#define DRM_MODE_FEATURE_KMS		1
69#define DRM_MODE_FEATURE_DIRTYFB	1
70
71
72typedef struct _drmModeRes {
73
74	int count_fbs;
75	uint32_t *fbs;
76
77	int count_crtcs;
78	uint32_t *crtcs;
79
80	int count_connectors;
81	uint32_t *connectors;
82
83	int count_encoders;
84	uint32_t *encoders;
85
86	uint32_t min_width, max_width;
87	uint32_t min_height, max_height;
88} drmModeRes, *drmModeResPtr;
89
90typedef 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;
94
95	uint32_t vrefresh;
96
97	uint32_t flags;
98	uint32_t type;
99	char name[DRM_DISPLAY_MODE_LEN];
100} drmModeModeInfo, *drmModeModeInfoPtr;
101
102typedef 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;
111
112typedef 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;
118
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;
124
125typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
126
127typedef struct _drmModePropertyBlob {
128	uint32_t id;
129	uint32_t length;
130	void *data;
131} drmModePropertyBlobRes, *drmModePropertyBlobPtr;
132
133typedef 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;
144
145static __inline int drm_property_type_is(drmModePropertyPtr property,
146		uint32_t type)
147{
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;
152}
153
154static inline uint32_t drmModeGetPropertyType(const drmModePropertyRes *prop)
155{
156	return prop->flags & (DRM_MODE_PROP_LEGACY_TYPE | DRM_MODE_PROP_EXTENDED_TYPE);
157}
158
159typedef struct _drmModeCrtc {
160	uint32_t crtc_id;
161	uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
162
163	uint32_t x, y; /**< Position on the framebuffer */
164	uint32_t width, height;
165	int mode_valid;
166	drmModeModeInfo mode;
167
168	int gamma_size; /**< Number of gamma stops */
169
170} drmModeCrtc, *drmModeCrtcPtr;
171
172typedef 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;
179
180/**
181 * Describes the connector status.
182 *
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.
186 *
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.
191 */
192typedef enum {
193	DRM_MODE_CONNECTED         = 1,
194	DRM_MODE_DISCONNECTED      = 2,
195	DRM_MODE_UNKNOWNCONNECTION = 3
196} drmModeConnection;
197
198typedef 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;
206
207typedef 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;
215
216	int count_modes;
217	drmModeModeInfoPtr modes;
218
219	int count_props;
220	uint32_t *props; /**< List of property ids */
221	uint64_t *prop_values; /**< List of property values */
222
223	int count_encoders;
224	uint32_t *encoders; /**< List of encoder ids */
225} drmModeConnector, *drmModeConnectorPtr;
226
227#define DRM_PLANE_TYPE_OVERLAY 0
228#define DRM_PLANE_TYPE_PRIMARY 1
229#define DRM_PLANE_TYPE_CURSOR  2
230
231typedef struct _drmModeObjectProperties {
232	uint32_t count_props;
233	uint32_t *props;
234	uint64_t *prop_values;
235} drmModeObjectProperties, *drmModeObjectPropertiesPtr;
236
237typedef struct _drmModePlane {
238	uint32_t count_formats;
239	uint32_t *formats;
240	uint32_t plane_id;
241
242	uint32_t crtc_id;
243	uint32_t fb_id;
244
245	uint32_t crtc_x, crtc_y;
246	uint32_t x, y;
247
248	uint32_t possible_crtcs;
249	uint32_t gamma_size;
250} drmModePlane, *drmModePlanePtr;
251
252typedef struct _drmModePlaneRes {
253	uint32_t count_planes;
254	uint32_t *planes;
255} drmModePlaneRes, *drmModePlaneResPtr;
256
257extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
258extern void drmModeFreeResources( drmModeResPtr ptr );
259extern void drmModeFreeFB( drmModeFBPtr ptr );
260extern void drmModeFreeFB2( drmModeFB2Ptr ptr );
261extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
262extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
263extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
264extern void drmModeFreePlane( drmModePlanePtr ptr );
265extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr);
266
267/**
268 * Check whether the DRM node supports Kernel Mode-Setting.
269 *
270 * Returns 1 if suitable for KMS, 0 otherwise.
271 */
272extern int drmIsKMS(int fd);
273
274/**
275 * Retrieves all of the resources associated with a card.
276 */
277extern drmModeResPtr drmModeGetResources(int fd);
278
279/*
280 * FrameBuffer manipulation.
281 */
282
283/**
284 * Retrieve information about framebuffer bufferId
285 */
286extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
287extern drmModeFB2Ptr drmModeGetFB2(int fd, uint32_t bufferId);
288
289/**
290 * Creates a new framebuffer with an buffer object as its scanout buffer.
291 */
292extern 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 */
296extern 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);
300
301/* ...with format modifiers */
302int 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);
307
308/**
309 * Destroies the given framebuffer.
310 */
311extern int drmModeRmFB(int fd, uint32_t bufferId);
312
313/**
314 * Mark a region of a framebuffer as dirty.
315 */
316extern int drmModeDirtyFB(int fd, uint32_t bufferId,
317			  drmModeClipPtr clips, uint32_t num_clips);
318
319
320/*
321 * Crtc functions
322 */
323
324/**
325 * Retrieve information about the ctrt crtcId
326 */
327extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
328
329/**
330 * Set the mode on a crtc crtcId with the given mode modeId.
331 */
332int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
333                   uint32_t x, uint32_t y, uint32_t *connectors, int count,
334		   drmModeModeInfoPtr mode);
335
336/*
337 * Cursor functions
338 */
339
340/**
341 * Set the cursor on crtc
342 */
343int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
344
345int drmModeSetCursor2(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height, int32_t hot_x, int32_t hot_y);
346/**
347 * Move the cursor on crtc
348 */
349int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
350
351/**
352 * Encoder functions
353 */
354drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
355
356/*
357 * Connector manipulation
358 */
359
360/**
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.
364 */
365extern drmModeConnectorPtr drmModeGetConnector(int fd,
366					       uint32_t connectorId);
367
368/**
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.
375 */
376extern drmModeConnectorPtr drmModeGetConnectorCurrent(int fd,
377						      uint32_t connector_id);
378
379/**
380 * Attaches the given mode to an connector.
381 */
382extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
383
384/**
385 * Detaches a mode from the connector
386 * must be unused, by the given mode.
387 */
388extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
389
390extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
391extern void drmModeFreeProperty(drmModePropertyPtr ptr);
392
393extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
394extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
395extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
396				    uint64_t value);
397extern int drmCheckModesettingSupported(const char *busid);
398
399extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
400			       uint16_t *red, uint16_t *green, uint16_t *blue);
401extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
402			       uint16_t *red, uint16_t *green, uint16_t *blue);
403extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
404			   uint32_t flags, void *user_data);
405extern int drmModePageFlipTarget(int fd, uint32_t crtc_id, uint32_t fb_id,
406				 uint32_t flags, void *user_data,
407				 uint32_t target_vblank);
408
409extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
410extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
411extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
412			   uint32_t fb_id, uint32_t flags,
413			   uint32_t crtc_x, uint32_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);
417
418extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
419							uint32_t object_id,
420							uint32_t object_type);
421extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
422extern int drmModeObjectSetProperty(int fd, uint32_t object_id,
423				    uint32_t object_type, uint32_t property_id,
424				    uint64_t value);
425
426
427typedef struct _drmModeAtomicReq drmModeAtomicReq, *drmModeAtomicReqPtr;
428
429extern drmModeAtomicReqPtr drmModeAtomicAlloc(void);
430extern drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr req);
431extern int drmModeAtomicMerge(drmModeAtomicReqPtr base,
432			      drmModeAtomicReqPtr augment);
433extern void drmModeAtomicFree(drmModeAtomicReqPtr req);
434extern int drmModeAtomicGetCursor(drmModeAtomicReqPtr req);
435extern void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor);
436extern int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
437				    uint32_t object_id,
438				    uint32_t property_id,
439				    uint64_t value);
440extern int drmModeAtomicCommit(int fd,
441			       drmModeAtomicReqPtr req,
442			       uint32_t flags,
443			       void *user_data);
444
445extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size,
446				     uint32_t *id);
447extern int drmModeDestroyPropertyBlob(int fd, uint32_t id);
448
449/*
450 * DRM mode lease APIs. These create and manage new drm_masters with
451 * access to a subset of the available DRM resources
452 */
453
454extern int drmModeCreateLease(int fd, const uint32_t *objects, int num_objects, int flags, uint32_t *lessee_id);
455
456typedef struct drmModeLesseeList {
457	uint32_t count;
458	uint32_t lessees[];
459} drmModeLesseeListRes, *drmModeLesseeListPtr;
460
461extern drmModeLesseeListPtr drmModeListLessees(int fd);
462
463typedef struct drmModeObjectList {
464	uint32_t count;
465	uint32_t objects[];
466} drmModeObjectListRes, *drmModeObjectListPtr;
467
468extern drmModeObjectListPtr drmModeGetLease(int fd);
469
470extern int drmModeRevokeLease(int fd, uint32_t lessee_id);
471
472#if defined(__cplusplus)
473}
474#endif
475
476#endif
477