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 #ifndef _XF86DRMMODE_H_ 36 #define _XF86DRMMODE_H_ 37 38 #if defined(__cplusplus) || defined(c_plusplus) 39 extern "C" { 40 #endif 41 42 #include <drm.h> 43 44 /* 45 * This is the interface for modesetting for drm. 46 * 47 * In order to use this interface you must include either <stdint.h> or another 48 * header defining uint32_t, int32_t and uint16_t. 49 * 50 * It aims to provide a randr1.2 compatible interface for modesettings in the 51 * kernel, the interface is also ment to be used by libraries like EGL. 52 * 53 * More information can be found in randrproto.txt which can be found here: 54 * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git 55 * 56 * There are some major diffrences to be noted. Unlike the randr1.2 proto you 57 * need to create the memory object of the framebuffer yourself with the ttm 58 * buffer object interface. This object needs to be pinned. 59 */ 60 61 /* 62 * If we pickup an old version of drm.h which doesn't include drm_mode.h 63 * we should redefine defines. This is so that builds doesn't breaks with 64 * new libdrm on old kernels. 65 */ 66 #ifndef _DRM_MODE_H 67 68 #define DRM_DISPLAY_INFO_LEN 32 69 #define DRM_CONNECTOR_NAME_LEN 32 70 #define DRM_DISPLAY_MODE_LEN 32 71 #define DRM_PROP_NAME_LEN 32 72 73 #define DRM_MODE_TYPE_BUILTIN (1<<0) 74 #define DRM_MODE_TYPE_CLOCK_C ((1<<1) | DRM_MODE_TYPE_BUILTIN) 75 #define DRM_MODE_TYPE_CRTC_C ((1<<2) | DRM_MODE_TYPE_BUILTIN) 76 #define DRM_MODE_TYPE_PREFERRED (1<<3) 77 #define DRM_MODE_TYPE_DEFAULT (1<<4) 78 #define DRM_MODE_TYPE_USERDEF (1<<5) 79 #define DRM_MODE_TYPE_DRIVER (1<<6) 80 81 /* Video mode flags */ 82 /* bit compatible with the xorg definitions. */ 83 #define DRM_MODE_FLAG_PHSYNC (1<<0) 84 #define DRM_MODE_FLAG_NHSYNC (1<<1) 85 #define DRM_MODE_FLAG_PVSYNC (1<<2) 86 #define DRM_MODE_FLAG_NVSYNC (1<<3) 87 #define DRM_MODE_FLAG_INTERLACE (1<<4) 88 #define DRM_MODE_FLAG_DBLSCAN (1<<5) 89 #define DRM_MODE_FLAG_CSYNC (1<<6) 90 #define DRM_MODE_FLAG_PCSYNC (1<<7) 91 #define DRM_MODE_FLAG_NCSYNC (1<<8) 92 #define DRM_MODE_FLAG_HSKEW (1<<9) /* hskew provided */ 93 #define DRM_MODE_FLAG_BCAST (1<<10) 94 #define DRM_MODE_FLAG_PIXMUX (1<<11) 95 #define DRM_MODE_FLAG_DBLCLK (1<<12) 96 #define DRM_MODE_FLAG_CLKDIV2 (1<<13) 97 98 /* DPMS flags */ 99 /* bit compatible with the xorg definitions. */ 100 #define DRM_MODE_DPMS_ON 0 101 #define DRM_MODE_DPMS_STANDBY 1 102 #define DRM_MODE_DPMS_SUSPEND 2 103 #define DRM_MODE_DPMS_OFF 3 104 105 /* Scaling mode options */ 106 #define DRM_MODE_SCALE_NON_GPU 0 107 #define DRM_MODE_SCALE_FULLSCREEN 1 108 #define DRM_MODE_SCALE_NO_SCALE 2 109 #define DRM_MODE_SCALE_ASPECT 3 110 111 /* Dithering mode options */ 112 #define DRM_MODE_DITHERING_OFF 0 113 #define DRM_MODE_DITHERING_ON 1 114 115 #define DRM_MODE_ENCODER_NONE 0 116 #define DRM_MODE_ENCODER_DAC 1 117 #define DRM_MODE_ENCODER_TMDS 2 118 #define DRM_MODE_ENCODER_LVDS 3 119 #define DRM_MODE_ENCODER_TVDAC 4 120 121 #define DRM_MODE_SUBCONNECTOR_Automatic 0 122 #define DRM_MODE_SUBCONNECTOR_Unknown 0 123 #define DRM_MODE_SUBCONNECTOR_DVID 3 124 #define DRM_MODE_SUBCONNECTOR_DVIA 4 125 #define DRM_MODE_SUBCONNECTOR_Composite 5 126 #define DRM_MODE_SUBCONNECTOR_SVIDEO 6 127 #define DRM_MODE_SUBCONNECTOR_Component 8 128 129 #define DRM_MODE_CONNECTOR_Unknown 0 130 #define DRM_MODE_CONNECTOR_VGA 1 131 #define DRM_MODE_CONNECTOR_DVII 2 132 #define DRM_MODE_CONNECTOR_DVID 3 133 #define DRM_MODE_CONNECTOR_DVIA 4 134 #define DRM_MODE_CONNECTOR_Composite 5 135 #define DRM_MODE_CONNECTOR_SVIDEO 6 136 #define DRM_MODE_CONNECTOR_LVDS 7 137 #define DRM_MODE_CONNECTOR_Component 8 138 #define DRM_MODE_CONNECTOR_9PinDIN 9 139 #define DRM_MODE_CONNECTOR_DisplayPort 10 140 #define DRM_MODE_CONNECTOR_HDMIA 11 141 #define DRM_MODE_CONNECTOR_HDMIB 12 142 #define DRM_MODE_CONNECTOR_TV 13 143 #define DRM_MODE_CONNECTOR_eDP 14 144 #define DRM_MODE_CONNECTOR_MIPI 15 145 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 157 typedef struct _drmModeRes { 158 159 int count_fbs; 160 uint32_t *fbs; 161 162 int count_crtcs; 163 uint32_t *crtcs; 164 165 int count_connectors; 166 uint32_t *connectors; 167 168 int count_encoders; 169 uint32_t *encoders; 170 171 uint32_t min_width, max_width; 172 uint32_t min_height, max_height; 173 } drmModeRes, *drmModeResPtr; 174 175 typedef struct _drmModeModeInfo { 176 uint32_t clock; 177 uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew; 178 uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan; 179 180 uint32_t vrefresh; /* vertical refresh * 1000 */ 181 182 uint32_t flags; 183 uint32_t type; 184 char name[DRM_DISPLAY_MODE_LEN]; 185 } drmModeModeInfo, *drmModeModeInfoPtr; 186 187 typedef struct _drmModeFB { 188 uint32_t fb_id; 189 uint32_t width, height; 190 uint32_t pitch; 191 uint32_t bpp; 192 uint32_t depth; 193 /* driver specific handle */ 194 uint32_t handle; 195 } drmModeFB, *drmModeFBPtr; 196 197 typedef struct _drmModePropertyBlob { 198 uint32_t id; 199 uint32_t length; 200 void *data; 201 } drmModePropertyBlobRes, *drmModePropertyBlobPtr; 202 203 typedef struct _drmModeProperty { 204 uint32_t prop_id; 205 uint32_t flags; 206 char name[DRM_PROP_NAME_LEN]; 207 int count_values; 208 uint64_t *values; // store the blob lengths 209 int count_enums; 210 struct drm_mode_property_enum *enums; 211 int count_blobs; 212 uint32_t *blob_ids; // store the blob IDs 213 } drmModePropertyRes, *drmModePropertyPtr; 214 215 typedef struct _drmModeCrtc { 216 uint32_t crtc_id; 217 uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */ 218 219 uint32_t x, y; /**< Position on the framebuffer */ 220 uint32_t width, height; 221 int mode_valid; 222 drmModeModeInfo mode; 223 224 int gamma_size; /**< Number of gamma stops */ 225 226 } drmModeCrtc, *drmModeCrtcPtr; 227 228 typedef struct _drmModeEncoder { 229 uint32_t encoder_id; 230 uint32_t encoder_type; 231 uint32_t crtc_id; 232 uint32_t possible_crtcs; 233 uint32_t possible_clones; 234 } drmModeEncoder, *drmModeEncoderPtr; 235 236 typedef enum { 237 DRM_MODE_CONNECTED = 1, 238 DRM_MODE_DISCONNECTED = 2, 239 DRM_MODE_UNKNOWNCONNECTION = 3 240 } drmModeConnection; 241 242 typedef enum { 243 DRM_MODE_SUBPIXEL_UNKNOWN = 1, 244 DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2, 245 DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3, 246 DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4, 247 DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5, 248 DRM_MODE_SUBPIXEL_NONE = 6 249 } drmModeSubPixel; 250 251 typedef struct _drmModeConnector { 252 uint32_t connector_id; 253 uint32_t encoder_id; /**< Encoder currently connected to */ 254 uint32_t connector_type; 255 uint32_t connector_type_id; 256 drmModeConnection connection; 257 uint32_t mmWidth, mmHeight; /**< HxW in millimeters */ 258 drmModeSubPixel subpixel; 259 260 int count_modes; 261 drmModeModeInfoPtr modes; 262 263 int count_props; 264 uint32_t *props; /**< List of property ids */ 265 uint64_t *prop_values; /**< List of property values */ 266 267 int count_encoders; 268 uint32_t *encoders; /**< List of encoder ids */ 269 } drmModeConnector, *drmModeConnectorPtr; 270 271 272 273 extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr ); 274 extern void drmModeFreeResources( drmModeResPtr ptr ); 275 extern void drmModeFreeFB( drmModeFBPtr ptr ); 276 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr ); 277 extern void drmModeFreeConnector( drmModeConnectorPtr ptr ); 278 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr ); 279 280 /** 281 * Retrives all of the resources associated with a card. 282 */ 283 extern drmModeResPtr drmModeGetResources(int fd); 284 285 /* 286 * FrameBuffer manipulation. 287 */ 288 289 /** 290 * Retrive information about framebuffer bufferId 291 */ 292 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId); 293 294 /** 295 * Creates a new framebuffer with an buffer object as its scanout buffer. 296 */ 297 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth, 298 uint8_t bpp, uint32_t pitch, uint32_t bo_handle, 299 uint32_t *buf_id); 300 /** 301 * Destroies the given framebuffer. 302 */ 303 extern int drmModeRmFB(int fd, uint32_t bufferId); 304 305 /* 306 * Crtc functions 307 */ 308 309 /** 310 * Retrive information about the ctrt crtcId 311 */ 312 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId); 313 314 /** 315 * Set the mode on a crtc crtcId with the given mode modeId. 316 */ 317 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, 318 uint32_t x, uint32_t y, uint32_t *connectors, int count, 319 drmModeModeInfoPtr mode); 320 321 /* 322 * Cursor functions 323 */ 324 325 /** 326 * Set the cursor on crtc 327 */ 328 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height); 329 330 /** 331 * Move the cursor on crtc 332 */ 333 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y); 334 335 /** 336 * Encoder functions 337 */ 338 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id); 339 340 /* 341 * Connector manipulation 342 */ 343 344 /** 345 * Retrive information about the connector connectorId. 346 */ 347 extern drmModeConnectorPtr drmModeGetConnector(int fd, 348 uint32_t connectorId); 349 350 /** 351 * Attaches the given mode to an connector. 352 */ 353 extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info); 354 355 /** 356 * Detaches a mode from the connector 357 * must be unused, by the given mode. 358 */ 359 extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info); 360 361 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId); 362 extern void drmModeFreeProperty(drmModePropertyPtr ptr); 363 364 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id); 365 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr); 366 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id, 367 uint64_t value); 368 extern int drmCheckModesettingSupported(const char *busid); 369 370 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size, 371 uint16_t *red, uint16_t *green, uint16_t *blue); 372 extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size, 373 uint16_t *red, uint16_t *green, uint16_t *blue); 374 375 #if defined(__cplusplus) || defined(c_plusplus) 376 } 377 #endif 378 379 #endif 380