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) <year> <copyright holders>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
37 * This is the interface for modesetting for drm.
39 * In order to use this interface you must include either <stdint.h> or another
40 * header defining uint32_t, int32_t and uint16_t.
42 * It aims to provide a randr1.2 compatible interface for modesettings in the
43 * kernel, the interface is also ment to be used by libraries like EGL.
45 * More information can be found in randrproto.txt which can be found here:
46 * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
48 * There are some major diffrences to be noted. Unlike the randr1.2 proto you
49 * need to create the memory object of the framebuffer yourself with the ttm
50 * buffer object interface. This object needs to be pinned.
54 * generation - these are to be read by userspace, and if it notices
55 * while calling a get output or get crtc that the generation has changed
56 * it should re-call the mode resource functions resync its view of the
57 * outputs with current view.
60 typedef struct _drmModeRes {
75 uint32_t min_width, max_width;
76 uint32_t min_height, max_height;
77 } drmModeRes, *drmModeResPtr;
79 typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr;
81 typedef struct _drmModePropertyBlob {
85 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
87 typedef struct _drmModeProperty {
90 char name[DRM_PROP_NAME_LEN];
92 uint64_t *values; // store the blob lengths
94 struct drm_mode_property_enum *enums;
96 uint32_t *blob_ids; // store the blob IDs
97 } drmModePropertyRes, *drmModePropertyPtr;
99 typedef struct _drmModeCrtc {
100 unsigned int crtc_id;
101 unsigned int buffer_id; /**< FB id to connect to 0 = disconnect */
104 uint32_t x, y; /**< Position on the frameuffer */
105 uint32_t width, height;
107 struct drm_mode_modeinfo mode;
109 int gamma_size; /**< Number of gamma stops */
111 } drmModeCrtc, *drmModeCrtcPtr;
113 typedef struct _drmModeEncoder {
115 unsigned int encoder_id;
116 unsigned int encoder_type;
120 } drmModeEncoder, *drmModeEncoderPtr;
123 DRM_MODE_CONNECTED = 1,
124 DRM_MODE_DISCONNECTED = 2,
125 DRM_MODE_UNKNOWNCONNECTION = 3
129 DRM_MODE_SUBPIXEL_UNKNOWN = 1,
130 DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
131 DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
132 DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4,
133 DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5,
134 DRM_MODE_SUBPIXEL_NONE = 6
137 typedef struct _drmModeConnector {
139 unsigned int connector_id;
140 unsigned int encoder; /**< Encoder currently connected to */
141 unsigned int connector_type;
142 unsigned int connector_type_id;
143 drmModeConnection connection;
144 uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
145 drmModeSubPixel subpixel;
148 struct drm_mode_modeinfo *modes;
151 uint32_t *props; /**< List of property ids */
152 uint64_t *prop_values; /**< List of property values */
155 uint32_t *encoders; /**< List of encoder ids */
156 } drmModeConnector, *drmModeConnectorPtr;
160 extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr );
161 extern void drmModeFreeResources( drmModeResPtr ptr );
162 extern void drmModeFreeFB( drmModeFBPtr ptr );
163 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
164 extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
165 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
168 * Retrives all of the resources associated with a card.
170 extern drmModeResPtr drmModeGetResources(int fd);
173 * Retrives the hotplug counter
175 extern uint32_t drmModeGetHotplug(int fd);
178 * FrameBuffer manipulation.
182 * Retrive information about framebuffer bufferId
184 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
187 * Creates a new framebuffer with an buffer object as its scanout buffer.
189 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
190 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
193 * Destroies the given framebuffer.
195 extern int drmModeRmFB(int fd, uint32_t bufferId);
198 * Replace a framebuffer object with a new one - for resizing the screen.
200 extern int drmModeReplaceFB(int fd, uint32_t buffer_id,
201 uint32_t width, uint32_t height, uint8_t depth,
202 uint8_t bpp, uint32_t pitch, uint32_t bo_handle);
209 * Retrive information about the ctrt crtcId
211 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
214 * Set the mode on a crtc crtcId with the given mode modeId.
216 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
217 uint32_t x, uint32_t y, uint32_t *connectors, int count,
218 struct drm_mode_modeinfo *mode);
225 * Set the cursor on crtc
227 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
230 * Move the cursor on crtc
232 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
237 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
240 * Connector manipulation
244 * Retrive information about the connector connectorId.
246 extern drmModeConnectorPtr drmModeGetConnector(int fd,
247 uint32_t connectorId);
250 * Attaches the given mode to an connector.
252 extern int drmModeAttachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info);
255 * Detaches a mode from the connector
256 * must be unused, by the given mode.
258 extern int drmModeDetachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info);
260 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
261 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
263 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
264 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
265 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
267 extern int drmCheckModesettingSupported(const char *busid);
269 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
270 uint16_t *red, uint16_t *green, uint16_t *blue);
271 extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
272 uint16_t *red, uint16_t *green, uint16_t *blue);