1
0

xf86drmMode.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /*
  2. * \file xf86drmMode.h
  3. * Header for DRM modesetting interface.
  4. *
  5. */
  6. /* SPDX-FileContributor: Jakob Bornecrantz <wallbraker@gmail.com>
  7. * SPDX-FileContributor: Dave Airlie <airlied@linux.ie>
  8. * SPDX-FileCopyrightText: 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
  9. * SPDX-FileCopyrightText: 2007-2008 Dave Airlie <airlied@linux.ie>
  10. * SPDX-FileCopyrightText: 2007-2008 Jakob Bornecrantz <wallbraker@gmail.com>
  11. * SPDX-License-Identifier: MIT
  12. *
  13. */
  14. #ifndef _XF86DRMMODE_H_
  15. #define _XF86DRMMODE_H_
  16. #if defined(__cplusplus)
  17. extern "C" {
  18. #endif
  19. #include <drm.h>
  20. #include <drm_mode.h>
  21. #include <stdbool.h>
  22. #include <stddef.h>
  23. #include <stdint.h>
  24. /*
  25. * This is the interface for modesetting for drm.
  26. *
  27. * It aims to provide a randr1.2 compatible interface for modesettings in the
  28. * kernel, the interface is also meant to be used by libraries like EGL.
  29. *
  30. * More information can be found in randrproto.txt which can be found here:
  31. * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
  32. *
  33. * There are some major differences to be noted. Unlike the randr1.2 proto you
  34. * need to create the memory object of the framebuffer yourself with the ttm
  35. * buffer object interface. This object needs to be pinned.
  36. */
  37. /*
  38. * Feature defines
  39. *
  40. * Just because these are defined doesn't mean that the kernel
  41. * can do that feature, its just for new code vs old libdrm.
  42. */
  43. #define DRM_MODE_FEATURE_KMS 1
  44. #define DRM_MODE_FEATURE_DIRTYFB 1
  45. typedef struct _drmModeRes {
  46. int count_fbs;
  47. uint32_t *fbs;
  48. int count_crtcs;
  49. uint32_t *crtcs;
  50. int count_connectors;
  51. uint32_t *connectors;
  52. int count_encoders;
  53. uint32_t *encoders;
  54. uint32_t min_width, max_width;
  55. uint32_t min_height, max_height;
  56. } drmModeRes, *drmModeResPtr;
  57. typedef struct _drmModeModeInfo {
  58. uint32_t clock;
  59. uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
  60. uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
  61. uint32_t vrefresh;
  62. uint32_t flags;
  63. uint32_t type;
  64. char name[DRM_DISPLAY_MODE_LEN];
  65. } drmModeModeInfo, *drmModeModeInfoPtr;
  66. typedef struct _drmModeFB {
  67. uint32_t fb_id;
  68. uint32_t width, height;
  69. uint32_t pitch;
  70. uint32_t bpp;
  71. uint32_t depth;
  72. /* driver specific handle */
  73. uint32_t handle;
  74. } drmModeFB, *drmModeFBPtr;
  75. typedef struct _drmModeFB2 {
  76. uint32_t fb_id;
  77. uint32_t width, height;
  78. uint32_t pixel_format; /* fourcc code from drm_fourcc.h */
  79. uint64_t modifier; /* applies to all buffers */
  80. uint32_t flags;
  81. /* per-plane GEM handle; may be duplicate entries for multiple planes */
  82. uint32_t handles[4];
  83. uint32_t pitches[4]; /* bytes */
  84. uint32_t offsets[4]; /* bytes */
  85. } drmModeFB2, *drmModeFB2Ptr;
  86. typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
  87. typedef struct _drmModePropertyBlob {
  88. uint32_t id;
  89. uint32_t length;
  90. void *data;
  91. } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
  92. typedef struct _drmModeProperty {
  93. uint32_t prop_id;
  94. uint32_t flags;
  95. char name[DRM_PROP_NAME_LEN];
  96. int count_values;
  97. uint64_t *values; /* store the blob lengths */
  98. int count_enums;
  99. struct drm_mode_property_enum *enums;
  100. int count_blobs;
  101. uint32_t *blob_ids; /* store the blob IDs */
  102. } drmModePropertyRes, *drmModePropertyPtr;
  103. static inline uint32_t drmModeGetPropertyType(const drmModePropertyRes *prop)
  104. {
  105. return prop->flags & (DRM_MODE_PROP_LEGACY_TYPE | DRM_MODE_PROP_EXTENDED_TYPE);
  106. }
  107. static inline int drm_property_type_is(const drmModePropertyPtr property,
  108. uint32_t type)
  109. {
  110. return drmModeGetPropertyType(property) == type;
  111. }
  112. typedef struct _drmModeCrtc {
  113. uint32_t crtc_id;
  114. uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
  115. uint32_t x, y; /**< Position on the framebuffer */
  116. uint32_t width, height;
  117. int mode_valid;
  118. drmModeModeInfo mode;
  119. int gamma_size; /**< Number of gamma stops */
  120. } drmModeCrtc, *drmModeCrtcPtr;
  121. typedef struct _drmModeEncoder {
  122. uint32_t encoder_id;
  123. uint32_t encoder_type;
  124. uint32_t crtc_id;
  125. uint32_t possible_crtcs;
  126. uint32_t possible_clones;
  127. } drmModeEncoder, *drmModeEncoderPtr;
  128. /**
  129. * Describes the connector status.
  130. *
  131. * DRM_MODE_CONNECTED means that the connector has a sink plugged in.
  132. * DRM_MODE_DISCONNECTED means the contrary. DRM_MODE_UNKNOWNCONNECTION is used
  133. * when it could be either.
  134. *
  135. * User-space should first try to enable DRM_MODE_CONNECTED connectors and
  136. * ignore other connectors. If there are no DRM_MODE_CONNECTED connectors,
  137. * user-space should then try to probe and enable DRM_MODE_UNKNOWNCONNECTION
  138. * connectors.
  139. */
  140. typedef enum {
  141. DRM_MODE_CONNECTED = 1,
  142. DRM_MODE_DISCONNECTED = 2,
  143. DRM_MODE_UNKNOWNCONNECTION = 3
  144. } drmModeConnection;
  145. typedef enum {
  146. DRM_MODE_SUBPIXEL_UNKNOWN = 1,
  147. DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
  148. DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
  149. DRM_MODE_SUBPIXEL_VERTICAL_RGB = 4,
  150. DRM_MODE_SUBPIXEL_VERTICAL_BGR = 5,
  151. DRM_MODE_SUBPIXEL_NONE = 6
  152. } drmModeSubPixel;
  153. typedef struct _drmModeConnector {
  154. uint32_t connector_id;
  155. uint32_t encoder_id; /**< Encoder currently connected to */
  156. uint32_t connector_type;
  157. uint32_t connector_type_id;
  158. drmModeConnection connection;
  159. uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
  160. drmModeSubPixel subpixel;
  161. int count_modes;
  162. drmModeModeInfoPtr modes;
  163. int count_props;
  164. uint32_t *props; /**< List of property ids */
  165. uint64_t *prop_values; /**< List of property values */
  166. int count_encoders;
  167. uint32_t *encoders; /**< List of encoder ids */
  168. } drmModeConnector, *drmModeConnectorPtr;
  169. #define DRM_PLANE_TYPE_OVERLAY 0
  170. #define DRM_PLANE_TYPE_PRIMARY 1
  171. #define DRM_PLANE_TYPE_CURSOR 2
  172. typedef struct _drmModeObjectProperties {
  173. uint32_t count_props;
  174. uint32_t *props;
  175. uint64_t *prop_values;
  176. } drmModeObjectProperties, *drmModeObjectPropertiesPtr;
  177. typedef struct _drmModeFormatModifierIterator {
  178. uint32_t fmt_idx, mod_idx;
  179. uint32_t fmt;
  180. uint64_t mod;
  181. } drmModeFormatModifierIterator;
  182. typedef struct _drmModePlane {
  183. uint32_t count_formats;
  184. uint32_t *formats;
  185. uint32_t plane_id;
  186. uint32_t crtc_id;
  187. uint32_t fb_id;
  188. uint32_t crtc_x, crtc_y;
  189. uint32_t x, y;
  190. uint32_t possible_crtcs;
  191. uint32_t gamma_size;
  192. } drmModePlane, *drmModePlanePtr;
  193. typedef struct _drmModePlaneRes {
  194. uint32_t count_planes;
  195. uint32_t *planes;
  196. } drmModePlaneRes, *drmModePlaneResPtr;
  197. extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
  198. extern void drmModeFreeResources( drmModeResPtr ptr );
  199. extern void drmModeFreeFB( drmModeFBPtr ptr );
  200. extern void drmModeFreeFB2( drmModeFB2Ptr ptr );
  201. extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
  202. extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
  203. extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
  204. extern void drmModeFreePlane( drmModePlanePtr ptr );
  205. extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr);
  206. /**
  207. * Check whether the DRM node supports Kernel Mode-Setting.
  208. *
  209. * Returns 1 if suitable for KMS, 0 otherwise.
  210. */
  211. extern int drmIsKMS(int fd);
  212. /**
  213. * Retrieves all of the resources associated with a card.
  214. */
  215. extern drmModeResPtr drmModeGetResources(int fd);
  216. /*
  217. * FrameBuffer manipulation.
  218. */
  219. /**
  220. * Retrieve information about framebuffer bufferId
  221. */
  222. extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
  223. extern drmModeFB2Ptr drmModeGetFB2(int fd, uint32_t bufferId);
  224. /**
  225. * Creates a new framebuffer with an buffer object as its scanout buffer.
  226. */
  227. extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
  228. uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
  229. uint32_t *buf_id);
  230. /* ...with a specific pixel format */
  231. extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
  232. uint32_t pixel_format, const uint32_t bo_handles[4],
  233. const uint32_t pitches[4], const uint32_t offsets[4],
  234. uint32_t *buf_id, uint32_t flags);
  235. /* ...with format modifiers */
  236. int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height,
  237. uint32_t pixel_format, const uint32_t bo_handles[4],
  238. const uint32_t pitches[4], const uint32_t offsets[4],
  239. const uint64_t modifier[4], uint32_t *buf_id,
  240. uint32_t flags);
  241. /**
  242. * Destroies the given framebuffer.
  243. */
  244. extern int drmModeRmFB(int fd, uint32_t bufferId);
  245. /**
  246. * Close a framebuffer.
  247. *
  248. * Same as drmModeRmFB(), except it doesn't implicitly disable planes and CRTCs.
  249. */
  250. extern int drmModeCloseFB(int fd, uint32_t buffer_id);
  251. /**
  252. * Mark a region of a framebuffer as dirty.
  253. */
  254. extern int drmModeDirtyFB(int fd, uint32_t bufferId,
  255. drmModeClipPtr clips, uint32_t num_clips);
  256. /*
  257. * Crtc functions
  258. */
  259. /**
  260. * Retrieve information about the ctrt crtcId
  261. */
  262. extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
  263. /**
  264. * Set the mode on a crtc crtcId with the given mode modeId.
  265. */
  266. int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
  267. uint32_t x, uint32_t y, uint32_t *connectors, int count,
  268. drmModeModeInfoPtr mode);
  269. /*
  270. * Cursor functions
  271. */
  272. /**
  273. * Set the cursor on crtc
  274. */
  275. int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
  276. 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);
  277. /**
  278. * Move the cursor on crtc
  279. */
  280. int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
  281. /**
  282. * Encoder functions
  283. */
  284. drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
  285. /*
  286. * Connector manipulation
  287. */
  288. /**
  289. * Retrieve all information about the connector connectorId. This will do a
  290. * forced probe on the connector to retrieve remote information such as EDIDs
  291. * from the display device.
  292. */
  293. extern drmModeConnectorPtr drmModeGetConnector(int fd,
  294. uint32_t connectorId);
  295. /**
  296. * Retrieve current information, i.e the currently active mode and encoder,
  297. * about the connector connectorId. This will not do any probing on the
  298. * connector or remote device, and only reports what is currently known.
  299. * For the complete set of modes and encoders associated with the connector
  300. * use drmModeGetConnector() which will do a probe to determine any display
  301. * link changes first.
  302. */
  303. extern drmModeConnectorPtr drmModeGetConnectorCurrent(int fd,
  304. uint32_t connector_id);
  305. /**
  306. * Get a bitmask of CRTCs a connector is compatible with.
  307. *
  308. * The bits reference CRTC indices. If the n-th CRTC is compatible with the
  309. * connector, the n-th bit will be set. The indices are taken from the array
  310. * returned by drmModeGetResources(). The indices are different from the object
  311. * IDs.
  312. *
  313. * Zero is returned on error.
  314. */
  315. extern uint32_t drmModeConnectorGetPossibleCrtcs(int fd,
  316. const drmModeConnector *connector);
  317. /**
  318. * Attaches the given mode to an connector.
  319. */
  320. extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
  321. /**
  322. * Detaches a mode from the connector
  323. * must be unused, by the given mode.
  324. */
  325. extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
  326. extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
  327. extern void drmModeFreeProperty(drmModePropertyPtr ptr);
  328. extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
  329. extern bool drmModeFormatModifierBlobIterNext(const drmModePropertyBlobRes *blob,
  330. drmModeFormatModifierIterator *iter);
  331. extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
  332. extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
  333. uint64_t value);
  334. extern int drmCheckModesettingSupported(const char *busid);
  335. extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
  336. const uint16_t *red, const uint16_t *green, const uint16_t *blue);
  337. extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
  338. uint16_t *red, uint16_t *green, uint16_t *blue);
  339. extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
  340. uint32_t flags, void *user_data);
  341. extern int drmModePageFlipTarget(int fd, uint32_t crtc_id, uint32_t fb_id,
  342. uint32_t flags, void *user_data,
  343. uint32_t target_vblank);
  344. extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
  345. extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
  346. extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
  347. uint32_t fb_id, uint32_t flags,
  348. int32_t crtc_x, int32_t crtc_y,
  349. uint32_t crtc_w, uint32_t crtc_h,
  350. uint32_t src_x, uint32_t src_y,
  351. uint32_t src_w, uint32_t src_h);
  352. extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
  353. uint32_t object_id,
  354. uint32_t object_type);
  355. extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
  356. extern int drmModeObjectSetProperty(int fd, uint32_t object_id,
  357. uint32_t object_type, uint32_t property_id,
  358. uint64_t value);
  359. typedef struct _drmModeAtomicReq drmModeAtomicReq, *drmModeAtomicReqPtr;
  360. extern drmModeAtomicReqPtr drmModeAtomicAlloc(void);
  361. extern drmModeAtomicReqPtr drmModeAtomicDuplicate(const drmModeAtomicReqPtr req);
  362. extern int drmModeAtomicMerge(drmModeAtomicReqPtr base,
  363. const drmModeAtomicReqPtr augment);
  364. extern void drmModeAtomicFree(drmModeAtomicReqPtr req);
  365. extern int drmModeAtomicGetCursor(const drmModeAtomicReqPtr req);
  366. extern void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor);
  367. extern int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
  368. uint32_t object_id,
  369. uint32_t property_id,
  370. uint64_t value);
  371. extern int drmModeAtomicCommit(int fd,
  372. const drmModeAtomicReqPtr req,
  373. uint32_t flags,
  374. void *user_data);
  375. extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size,
  376. uint32_t *id);
  377. extern int drmModeDestroyPropertyBlob(int fd, uint32_t id);
  378. /*
  379. * DRM mode lease APIs. These create and manage new drm_masters with
  380. * access to a subset of the available DRM resources
  381. */
  382. extern int drmModeCreateLease(int fd, const uint32_t *objects, int num_objects, int flags, uint32_t *lessee_id);
  383. typedef struct drmModeLesseeList {
  384. uint32_t count;
  385. uint32_t lessees[];
  386. } drmModeLesseeListRes, *drmModeLesseeListPtr;
  387. extern drmModeLesseeListPtr drmModeListLessees(int fd);
  388. typedef struct drmModeObjectList {
  389. uint32_t count;
  390. uint32_t objects[];
  391. } drmModeObjectListRes, *drmModeObjectListPtr;
  392. extern drmModeObjectListPtr drmModeGetLease(int fd);
  393. extern int drmModeRevokeLease(int fd, uint32_t lessee_id);
  394. /**
  395. * Get a string describing a connector type.
  396. *
  397. * NULL is returned if the connector type is unsupported. Callers should handle
  398. * this gracefully, e.g. by falling back to "Unknown" or printing the raw value.
  399. */
  400. extern const char *
  401. drmModeGetConnectorTypeName(uint32_t connector_type);
  402. /**
  403. * Create a dumb buffer.
  404. *
  405. * Given a width, height and bits-per-pixel, the kernel will return a buffer
  406. * handle, pitch and size. The flags must be zero.
  407. *
  408. * Returns 0 on success, negative errno on error.
  409. */
  410. extern int
  411. drmModeCreateDumbBuffer(int fd, uint32_t width, uint32_t height, uint32_t bpp,
  412. uint32_t flags, uint32_t *handle, uint32_t *pitch,
  413. uint64_t *size);
  414. /**
  415. * Destroy a dumb buffer.
  416. *
  417. * Returns 0 on success, negative errno on error.
  418. */
  419. extern int
  420. drmModeDestroyDumbBuffer(int fd, uint32_t handle);
  421. /**
  422. * Prepare a dumb buffer for mapping.
  423. *
  424. * The kernel returns an offset which can be used as an argument to mmap(2) on
  425. * the DRM FD.
  426. *
  427. * Returns 0 on success, negative errno on error.
  428. */
  429. extern int
  430. drmModeMapDumbBuffer(int fd, uint32_t handle, uint64_t *offset);
  431. #if defined(__cplusplus)
  432. }
  433. #endif
  434. #endif