xf86drmMode.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
  12. * Copyright (c) 2007-2008 Dave Airlie <airlied@linux.ie>
  13. * Copyright (c) 2007-2008 Jakob Bornecrantz <wallbraker@gmail.com>
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a
  16. * copy of this software and associated documentation files (the "Software"),
  17. * to deal in the Software without restriction, including without limitation
  18. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  19. * and/or sell copies of the Software, and to permit persons to whom the
  20. * Software is furnished to do so, subject to the following conditions:
  21. *
  22. * The above copyright notice and this permission notice shall be included in
  23. * all copies or substantial portions of the Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  29. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  30. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  31. * IN THE SOFTWARE.
  32. *
  33. */
  34. #ifndef _XF86DRMMODE_H_
  35. #define _XF86DRMMODE_H_
  36. #if defined(__cplusplus)
  37. extern "C" {
  38. #endif
  39. #include <drm.h>
  40. /*
  41. * This is the interface for modesetting for drm.
  42. *
  43. * In order to use this interface you must include either <stdint.h> or another
  44. * header defining uint32_t, int32_t and uint16_t.
  45. *
  46. * It aims to provide a randr1.2 compatible interface for modesettings in the
  47. * kernel, the interface is also ment to be used by libraries like EGL.
  48. *
  49. * More information can be found in randrproto.txt which can be found here:
  50. * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
  51. *
  52. * There are some major diffrences to be noted. Unlike the randr1.2 proto you
  53. * need to create the memory object of the framebuffer yourself with the ttm
  54. * buffer object interface. This object needs to be pinned.
  55. */
  56. /*
  57. * If we pickup an old version of drm.h which doesn't include drm_mode.h
  58. * we should redefine defines. This is so that builds doesn't breaks with
  59. * new libdrm on old kernels.
  60. */
  61. #ifndef _DRM_MODE_H
  62. #define DRM_DISPLAY_INFO_LEN 32
  63. #define DRM_CONNECTOR_NAME_LEN 32
  64. #define DRM_DISPLAY_MODE_LEN 32
  65. #define DRM_PROP_NAME_LEN 32
  66. #define DRM_MODE_TYPE_BUILTIN (1<<0)
  67. #define DRM_MODE_TYPE_CLOCK_C ((1<<1) | DRM_MODE_TYPE_BUILTIN)
  68. #define DRM_MODE_TYPE_CRTC_C ((1<<2) | DRM_MODE_TYPE_BUILTIN)
  69. #define DRM_MODE_TYPE_PREFERRED (1<<3)
  70. #define DRM_MODE_TYPE_DEFAULT (1<<4)
  71. #define DRM_MODE_TYPE_USERDEF (1<<5)
  72. #define DRM_MODE_TYPE_DRIVER (1<<6)
  73. /* Video mode flags */
  74. /* bit compatible with the xorg definitions. */
  75. #define DRM_MODE_FLAG_PHSYNC (1<<0)
  76. #define DRM_MODE_FLAG_NHSYNC (1<<1)
  77. #define DRM_MODE_FLAG_PVSYNC (1<<2)
  78. #define DRM_MODE_FLAG_NVSYNC (1<<3)
  79. #define DRM_MODE_FLAG_INTERLACE (1<<4)
  80. #define DRM_MODE_FLAG_DBLSCAN (1<<5)
  81. #define DRM_MODE_FLAG_CSYNC (1<<6)
  82. #define DRM_MODE_FLAG_PCSYNC (1<<7)
  83. #define DRM_MODE_FLAG_NCSYNC (1<<8)
  84. #define DRM_MODE_FLAG_HSKEW (1<<9) /* hskew provided */
  85. #define DRM_MODE_FLAG_BCAST (1<<10)
  86. #define DRM_MODE_FLAG_PIXMUX (1<<11)
  87. #define DRM_MODE_FLAG_DBLCLK (1<<12)
  88. #define DRM_MODE_FLAG_CLKDIV2 (1<<13)
  89. #define DRM_MODE_FLAG_3D_MASK (0x1f<<14)
  90. #define DRM_MODE_FLAG_3D_NONE (0<<14)
  91. #define DRM_MODE_FLAG_3D_FRAME_PACKING (1<<14)
  92. #define DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE (2<<14)
  93. #define DRM_MODE_FLAG_3D_LINE_ALTERNATIVE (3<<14)
  94. #define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL (4<<14)
  95. #define DRM_MODE_FLAG_3D_L_DEPTH (5<<14)
  96. #define DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH (6<<14)
  97. #define DRM_MODE_FLAG_3D_TOP_AND_BOTTOM (7<<14)
  98. #define DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF (8<<14)
  99. /* DPMS flags */
  100. /* bit compatible with the xorg definitions. */
  101. #define DRM_MODE_DPMS_ON 0
  102. #define DRM_MODE_DPMS_STANDBY 1
  103. #define DRM_MODE_DPMS_SUSPEND 2
  104. #define DRM_MODE_DPMS_OFF 3
  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. /* Dithering mode options */
  111. #define DRM_MODE_DITHERING_OFF 0
  112. #define DRM_MODE_DITHERING_ON 1
  113. #define DRM_MODE_ENCODER_NONE 0
  114. #define DRM_MODE_ENCODER_DAC 1
  115. #define DRM_MODE_ENCODER_TMDS 2
  116. #define DRM_MODE_ENCODER_LVDS 3
  117. #define DRM_MODE_ENCODER_TVDAC 4
  118. #define DRM_MODE_ENCODER_VIRTUAL 5
  119. #define DRM_MODE_ENCODER_DSI 6
  120. #define DRM_MODE_SUBCONNECTOR_Automatic 0
  121. #define DRM_MODE_SUBCONNECTOR_Unknown 0
  122. #define DRM_MODE_SUBCONNECTOR_DVID 3
  123. #define DRM_MODE_SUBCONNECTOR_DVIA 4
  124. #define DRM_MODE_SUBCONNECTOR_Composite 5
  125. #define DRM_MODE_SUBCONNECTOR_SVIDEO 6
  126. #define DRM_MODE_SUBCONNECTOR_Component 8
  127. #define DRM_MODE_SUBCONNECTOR_SCART 9
  128. #define DRM_MODE_CONNECTOR_Unknown 0
  129. #define DRM_MODE_CONNECTOR_VGA 1
  130. #define DRM_MODE_CONNECTOR_DVII 2
  131. #define DRM_MODE_CONNECTOR_DVID 3
  132. #define DRM_MODE_CONNECTOR_DVIA 4
  133. #define DRM_MODE_CONNECTOR_Composite 5
  134. #define DRM_MODE_CONNECTOR_SVIDEO 6
  135. #define DRM_MODE_CONNECTOR_LVDS 7
  136. #define DRM_MODE_CONNECTOR_Component 8
  137. #define DRM_MODE_CONNECTOR_9PinDIN 9
  138. #define DRM_MODE_CONNECTOR_DisplayPort 10
  139. #define DRM_MODE_CONNECTOR_HDMIA 11
  140. #define DRM_MODE_CONNECTOR_HDMIB 12
  141. #define DRM_MODE_CONNECTOR_TV 13
  142. #define DRM_MODE_CONNECTOR_eDP 14
  143. #define DRM_MODE_CONNECTOR_VIRTUAL 15
  144. #define DRM_MODE_CONNECTOR_DSI 16
  145. #define DRM_MODE_PROP_PENDING (1<<0)
  146. #define DRM_MODE_PROP_RANGE (1<<1)
  147. #define DRM_MODE_PROP_IMMUTABLE (1<<2)
  148. #define DRM_MODE_PROP_ENUM (1<<3) /* enumerated type with text strings */
  149. #define DRM_MODE_PROP_BLOB (1<<4)
  150. #define DRM_MODE_CURSOR_BO (1<<0)
  151. #define DRM_MODE_CURSOR_MOVE (1<<1)
  152. #endif /* _DRM_MODE_H */
  153. /*
  154. * Feature defines
  155. *
  156. * Just because these are defined doesn't mean that the kernel
  157. * can do that feature, its just for new code vs old libdrm.
  158. */
  159. #define DRM_MODE_FEATURE_KMS 1
  160. #define DRM_MODE_FEATURE_DIRTYFB 1
  161. typedef struct _drmModeRes {
  162. int count_fbs;
  163. uint32_t *fbs;
  164. int count_crtcs;
  165. uint32_t *crtcs;
  166. int count_connectors;
  167. uint32_t *connectors;
  168. int count_encoders;
  169. uint32_t *encoders;
  170. uint32_t min_width, max_width;
  171. uint32_t min_height, max_height;
  172. } drmModeRes, *drmModeResPtr;
  173. typedef struct _drmModeModeInfo {
  174. uint32_t clock;
  175. uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
  176. uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
  177. uint32_t vrefresh;
  178. uint32_t flags;
  179. uint32_t type;
  180. char name[DRM_DISPLAY_MODE_LEN];
  181. } drmModeModeInfo, *drmModeModeInfoPtr;
  182. typedef struct _drmModeFB {
  183. uint32_t fb_id;
  184. uint32_t width, height;
  185. uint32_t pitch;
  186. uint32_t bpp;
  187. uint32_t depth;
  188. /* driver specific handle */
  189. uint32_t handle;
  190. } drmModeFB, *drmModeFBPtr;
  191. typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
  192. typedef struct _drmModePropertyBlob {
  193. uint32_t id;
  194. uint32_t length;
  195. void *data;
  196. } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
  197. typedef struct _drmModeProperty {
  198. uint32_t prop_id;
  199. uint32_t flags;
  200. char name[DRM_PROP_NAME_LEN];
  201. int count_values;
  202. uint64_t *values; /* store the blob lengths */
  203. int count_enums;
  204. struct drm_mode_property_enum *enums;
  205. int count_blobs;
  206. uint32_t *blob_ids; /* store the blob IDs */
  207. } drmModePropertyRes, *drmModePropertyPtr;
  208. static __inline int drm_property_type_is(drmModePropertyPtr property,
  209. uint32_t type)
  210. {
  211. /* instanceof for props.. handles extended type vs original types: */
  212. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  213. return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
  214. return property->flags & type;
  215. }
  216. typedef struct _drmModeCrtc {
  217. uint32_t crtc_id;
  218. uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
  219. uint32_t x, y; /**< Position on the framebuffer */
  220. uint32_t width, height;
  221. int mode_valid;
  222. drmModeModeInfo mode;
  223. int gamma_size; /**< Number of gamma stops */
  224. } drmModeCrtc, *drmModeCrtcPtr;
  225. typedef struct _drmModeEncoder {
  226. uint32_t encoder_id;
  227. uint32_t encoder_type;
  228. uint32_t crtc_id;
  229. uint32_t possible_crtcs;
  230. uint32_t possible_clones;
  231. } drmModeEncoder, *drmModeEncoderPtr;
  232. typedef enum {
  233. DRM_MODE_CONNECTED = 1,
  234. DRM_MODE_DISCONNECTED = 2,
  235. DRM_MODE_UNKNOWNCONNECTION = 3
  236. } drmModeConnection;
  237. typedef enum {
  238. DRM_MODE_SUBPIXEL_UNKNOWN = 1,
  239. DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
  240. DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
  241. DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4,
  242. DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5,
  243. DRM_MODE_SUBPIXEL_NONE = 6
  244. } drmModeSubPixel;
  245. typedef struct _drmModeConnector {
  246. uint32_t connector_id;
  247. uint32_t encoder_id; /**< Encoder currently connected to */
  248. uint32_t connector_type;
  249. uint32_t connector_type_id;
  250. drmModeConnection connection;
  251. uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
  252. drmModeSubPixel subpixel;
  253. int count_modes;
  254. drmModeModeInfoPtr modes;
  255. int count_props;
  256. uint32_t *props; /**< List of property ids */
  257. uint64_t *prop_values; /**< List of property values */
  258. int count_encoders;
  259. uint32_t *encoders; /**< List of encoder ids */
  260. } drmModeConnector, *drmModeConnectorPtr;
  261. #define DRM_PLANE_TYPE_OVERLAY 0
  262. #define DRM_PLANE_TYPE_PRIMARY 1
  263. #define DRM_PLANE_TYPE_CURSOR 2
  264. typedef struct _drmModeObjectProperties {
  265. uint32_t count_props;
  266. uint32_t *props;
  267. uint64_t *prop_values;
  268. } drmModeObjectProperties, *drmModeObjectPropertiesPtr;
  269. typedef struct _drmModePlane {
  270. uint32_t count_formats;
  271. uint32_t *formats;
  272. uint32_t plane_id;
  273. uint32_t crtc_id;
  274. uint32_t fb_id;
  275. uint32_t crtc_x, crtc_y;
  276. uint32_t x, y;
  277. uint32_t possible_crtcs;
  278. uint32_t gamma_size;
  279. } drmModePlane, *drmModePlanePtr;
  280. typedef struct _drmModePlaneRes {
  281. uint32_t count_planes;
  282. uint32_t *planes;
  283. } drmModePlaneRes, *drmModePlaneResPtr;
  284. extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
  285. extern void drmModeFreeResources( drmModeResPtr ptr );
  286. extern void drmModeFreeFB( drmModeFBPtr ptr );
  287. extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
  288. extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
  289. extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
  290. extern void drmModeFreePlane( drmModePlanePtr ptr );
  291. extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr);
  292. /**
  293. * Retrives all of the resources associated with a card.
  294. */
  295. extern drmModeResPtr drmModeGetResources(int fd);
  296. /*
  297. * FrameBuffer manipulation.
  298. */
  299. /**
  300. * Retrive information about framebuffer bufferId
  301. */
  302. extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
  303. /**
  304. * Creates a new framebuffer with an buffer object as its scanout buffer.
  305. */
  306. extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
  307. uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
  308. uint32_t *buf_id);
  309. /* ...with a specific pixel format */
  310. extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
  311. uint32_t pixel_format, uint32_t bo_handles[4],
  312. uint32_t pitches[4], uint32_t offsets[4],
  313. uint32_t *buf_id, uint32_t flags);
  314. /**
  315. * Destroies the given framebuffer.
  316. */
  317. extern int drmModeRmFB(int fd, uint32_t bufferId);
  318. /**
  319. * Mark a region of a framebuffer as dirty.
  320. */
  321. extern int drmModeDirtyFB(int fd, uint32_t bufferId,
  322. drmModeClipPtr clips, uint32_t num_clips);
  323. /*
  324. * Crtc functions
  325. */
  326. /**
  327. * Retrive information about the ctrt crtcId
  328. */
  329. extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
  330. /**
  331. * Set the mode on a crtc crtcId with the given mode modeId.
  332. */
  333. int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
  334. uint32_t x, uint32_t y, uint32_t *connectors, int count,
  335. drmModeModeInfoPtr mode);
  336. /*
  337. * Cursor functions
  338. */
  339. /**
  340. * Set the cursor on crtc
  341. */
  342. int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
  343. 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);
  344. /**
  345. * Move the cursor on crtc
  346. */
  347. int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
  348. /**
  349. * Encoder functions
  350. */
  351. drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
  352. /*
  353. * Connector manipulation
  354. */
  355. /**
  356. * Retrieve all information about the connector connectorId. This will do a
  357. * forced probe on the connector to retrieve remote information such as EDIDs
  358. * from the display device.
  359. */
  360. extern drmModeConnectorPtr drmModeGetConnector(int fd,
  361. uint32_t connectorId);
  362. /**
  363. * Retrieve current information, i.e the currently active mode and encoder,
  364. * about the connector connectorId. This will not do any probing on the
  365. * connector or remote device, and only reports what is currently known.
  366. * For the complete set of modes and encoders associated with the connector
  367. * use drmModeGetConnector() which will do a probe to determine any display
  368. * link changes first.
  369. */
  370. extern drmModeConnectorPtr drmModeGetConnectorCurrent(int fd,
  371. uint32_t connector_id);
  372. /**
  373. * Attaches the given mode to an connector.
  374. */
  375. extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
  376. /**
  377. * Detaches a mode from the connector
  378. * must be unused, by the given mode.
  379. */
  380. extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
  381. extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
  382. extern void drmModeFreeProperty(drmModePropertyPtr ptr);
  383. extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
  384. extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
  385. extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
  386. uint64_t value);
  387. extern int drmCheckModesettingSupported(const char *busid);
  388. extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
  389. uint16_t *red, uint16_t *green, uint16_t *blue);
  390. extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
  391. uint16_t *red, uint16_t *green, uint16_t *blue);
  392. extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
  393. uint32_t flags, void *user_data);
  394. extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
  395. extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
  396. extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
  397. uint32_t fb_id, uint32_t flags,
  398. int32_t crtc_x, int32_t crtc_y,
  399. uint32_t crtc_w, uint32_t crtc_h,
  400. uint32_t src_x, uint32_t src_y,
  401. uint32_t src_w, uint32_t src_h);
  402. extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
  403. uint32_t object_id,
  404. uint32_t object_type);
  405. extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
  406. extern int drmModeObjectSetProperty(int fd, uint32_t object_id,
  407. uint32_t object_type, uint32_t property_id,
  408. uint64_t value);
  409. typedef struct _drmModeAtomicReq drmModeAtomicReq, *drmModeAtomicReqPtr;
  410. extern drmModeAtomicReqPtr drmModeAtomicAlloc(void);
  411. extern drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr req);
  412. extern int drmModeAtomicMerge(drmModeAtomicReqPtr base,
  413. drmModeAtomicReqPtr augment);
  414. extern void drmModeAtomicFree(drmModeAtomicReqPtr req);
  415. extern int drmModeAtomicGetCursor(drmModeAtomicReqPtr req);
  416. extern void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor);
  417. extern int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
  418. uint32_t object_id,
  419. uint32_t property_id,
  420. uint64_t value);
  421. extern int drmModeAtomicCommit(int fd,
  422. drmModeAtomicReqPtr req,
  423. uint32_t flags,
  424. void *user_data);
  425. extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size,
  426. uint32_t *id);
  427. extern int drmModeDestroyPropertyBlob(int fd, uint32_t id);
  428. #if defined(__cplusplus)
  429. }
  430. #endif
  431. #endif