Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-17 09:56:15

0001 /*
0002  * \file xf86drmMode.h
0003  * Header for DRM modesetting interface.
0004  *
0005  * \author Jakob Bornecrantz <wallbraker@gmail.com>
0006  *
0007  * \par Acknowledgements:
0008  * Feb 2007, Dave Airlie <airlied@linux.ie>
0009  */
0010 
0011 /*
0012  * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
0013  * Copyright (c) 2007-2008 Dave Airlie <airlied@linux.ie>
0014  * Copyright (c) 2007-2008 Jakob Bornecrantz <wallbraker@gmail.com>
0015  *
0016  * Permission is hereby granted, free of charge, to any person obtaining a
0017  * copy of this software and associated documentation files (the "Software"),
0018  * to deal in the Software without restriction, including without limitation
0019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0020  * and/or sell copies of the Software, and to permit persons to whom the
0021  * Software is furnished to do so, subject to the following conditions:
0022  *
0023  * The above copyright notice and this permission notice shall be included in
0024  * all copies or substantial portions of the Software.
0025  *
0026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0029  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0030  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0031  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0032  * IN THE SOFTWARE.
0033  *
0034  */
0035 
0036 #ifndef _XF86DRMMODE_H_
0037 #define _XF86DRMMODE_H_
0038 
0039 #if defined(__cplusplus)
0040 extern "C" {
0041 #endif
0042 
0043 #include <drm.h>
0044 #include <drm_mode.h>
0045 #include <stdbool.h>
0046 #include <stddef.h>
0047 #include <stdint.h>
0048 
0049 /*
0050  * This is the interface for modesetting for drm.
0051  *
0052  * It aims to provide a randr1.2 compatible interface for modesettings in the
0053  * kernel, the interface is also meant to be used by libraries like EGL.
0054  *
0055  * More information can be found in randrproto.txt which can be found here:
0056  * http://gitweb.freedesktop.org/?p=xorg/proto/randrproto.git
0057  *
0058  * There are some major differences to be noted. Unlike the randr1.2 proto you
0059  * need to create the memory object of the framebuffer yourself with the ttm
0060  * buffer object interface. This object needs to be pinned.
0061  */
0062 
0063 /*
0064  * Feature defines
0065  *
0066  * Just because these are defined doesn't mean that the kernel
0067  * can do that feature, its just for new code vs old libdrm.
0068  */
0069 #define DRM_MODE_FEATURE_KMS        1
0070 #define DRM_MODE_FEATURE_DIRTYFB    1
0071 
0072 
0073 typedef struct _drmModeRes {
0074 
0075     int count_fbs;
0076     uint32_t *fbs;
0077 
0078     int count_crtcs;
0079     uint32_t *crtcs;
0080 
0081     int count_connectors;
0082     uint32_t *connectors;
0083 
0084     int count_encoders;
0085     uint32_t *encoders;
0086 
0087     uint32_t min_width, max_width;
0088     uint32_t min_height, max_height;
0089 } drmModeRes, *drmModeResPtr;
0090 
0091 typedef struct _drmModeModeInfo {
0092     uint32_t clock;
0093     uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
0094     uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
0095 
0096     uint32_t vrefresh;
0097 
0098     uint32_t flags;
0099     uint32_t type;
0100     char name[DRM_DISPLAY_MODE_LEN];
0101 } drmModeModeInfo, *drmModeModeInfoPtr;
0102 
0103 typedef struct _drmModeFB {
0104     uint32_t fb_id;
0105     uint32_t width, height;
0106     uint32_t pitch;
0107     uint32_t bpp;
0108     uint32_t depth;
0109     /* driver specific handle */
0110     uint32_t handle;
0111 } drmModeFB, *drmModeFBPtr;
0112 
0113 typedef struct _drmModeFB2 {
0114     uint32_t fb_id;
0115     uint32_t width, height;
0116     uint32_t pixel_format; /* fourcc code from drm_fourcc.h */
0117     uint64_t modifier; /* applies to all buffers */
0118     uint32_t flags;
0119 
0120     /* per-plane GEM handle; may be duplicate entries for multiple planes */
0121     uint32_t handles[4];
0122     uint32_t pitches[4]; /* bytes */
0123     uint32_t offsets[4]; /* bytes */
0124 } drmModeFB2, *drmModeFB2Ptr;
0125 
0126 typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr;
0127 
0128 typedef struct _drmModePropertyBlob {
0129     uint32_t id;
0130     uint32_t length;
0131     void *data;
0132 } drmModePropertyBlobRes, *drmModePropertyBlobPtr;
0133 
0134 typedef struct _drmModeProperty {
0135     uint32_t prop_id;
0136     uint32_t flags;
0137     char name[DRM_PROP_NAME_LEN];
0138     int count_values;
0139     uint64_t *values; /* store the blob lengths */
0140     int count_enums;
0141     struct drm_mode_property_enum *enums;
0142     int count_blobs;
0143     uint32_t *blob_ids; /* store the blob IDs */
0144 } drmModePropertyRes, *drmModePropertyPtr;
0145 
0146 static inline uint32_t drmModeGetPropertyType(const drmModePropertyRes *prop)
0147 {
0148     return prop->flags & (DRM_MODE_PROP_LEGACY_TYPE | DRM_MODE_PROP_EXTENDED_TYPE);
0149 }
0150 
0151 static inline int drm_property_type_is(const drmModePropertyPtr property,
0152         uint32_t type)
0153 {
0154     return drmModeGetPropertyType(property) == type;
0155 }
0156 
0157 typedef struct _drmModeCrtc {
0158     uint32_t crtc_id;
0159     uint32_t buffer_id; /**< FB id to connect to 0 = disconnect */
0160 
0161     uint32_t x, y; /**< Position on the framebuffer */
0162     uint32_t width, height;
0163     int mode_valid;
0164     drmModeModeInfo mode;
0165 
0166     int gamma_size; /**< Number of gamma stops */
0167 
0168 } drmModeCrtc, *drmModeCrtcPtr;
0169 
0170 typedef struct _drmModeEncoder {
0171     uint32_t encoder_id;
0172     uint32_t encoder_type;
0173     uint32_t crtc_id;
0174     uint32_t possible_crtcs;
0175     uint32_t possible_clones;
0176 } drmModeEncoder, *drmModeEncoderPtr;
0177 
0178 /**
0179  * Describes the connector status.
0180  *
0181  * DRM_MODE_CONNECTED means that the connector has a sink plugged in.
0182  * DRM_MODE_DISCONNECTED means the contrary. DRM_MODE_UNKNOWNCONNECTION is used
0183  * when it could be either.
0184  *
0185  * User-space should first try to enable DRM_MODE_CONNECTED connectors and
0186  * ignore other connectors. If there are no DRM_MODE_CONNECTED connectors,
0187  * user-space should then try to probe and enable DRM_MODE_UNKNOWNCONNECTION
0188  * connectors.
0189  */
0190 typedef enum {
0191     DRM_MODE_CONNECTED         = 1,
0192     DRM_MODE_DISCONNECTED      = 2,
0193     DRM_MODE_UNKNOWNCONNECTION = 3
0194 } drmModeConnection;
0195 
0196 typedef enum {
0197     DRM_MODE_SUBPIXEL_UNKNOWN        = 1,
0198     DRM_MODE_SUBPIXEL_HORIZONTAL_RGB = 2,
0199     DRM_MODE_SUBPIXEL_HORIZONTAL_BGR = 3,
0200     DRM_MODE_SUBPIXEL_VERTICAL_RGB   = 4,
0201     DRM_MODE_SUBPIXEL_VERTICAL_BGR   = 5,
0202     DRM_MODE_SUBPIXEL_NONE           = 6
0203 } drmModeSubPixel;
0204 
0205 typedef struct _drmModeConnector {
0206     uint32_t connector_id;
0207     uint32_t encoder_id; /**< Encoder currently connected to */
0208     uint32_t connector_type;
0209     uint32_t connector_type_id;
0210     drmModeConnection connection;
0211     uint32_t mmWidth, mmHeight; /**< HxW in millimeters */
0212     drmModeSubPixel subpixel;
0213 
0214     int count_modes;
0215     drmModeModeInfoPtr modes;
0216 
0217     int count_props;
0218     uint32_t *props; /**< List of property ids */
0219     uint64_t *prop_values; /**< List of property values */
0220 
0221     int count_encoders;
0222     uint32_t *encoders; /**< List of encoder ids */
0223 } drmModeConnector, *drmModeConnectorPtr;
0224 
0225 #define DRM_PLANE_TYPE_OVERLAY 0
0226 #define DRM_PLANE_TYPE_PRIMARY 1
0227 #define DRM_PLANE_TYPE_CURSOR  2
0228 
0229 typedef struct _drmModeObjectProperties {
0230     uint32_t count_props;
0231     uint32_t *props;
0232     uint64_t *prop_values;
0233 } drmModeObjectProperties, *drmModeObjectPropertiesPtr;
0234 
0235 typedef struct _drmModeFormatModifierIterator {
0236     uint32_t fmt_idx, mod_idx;
0237     uint32_t fmt;
0238     uint64_t mod;
0239 } drmModeFormatModifierIterator;
0240 
0241 typedef struct _drmModePlane {
0242     uint32_t count_formats;
0243     uint32_t *formats;
0244     uint32_t plane_id;
0245 
0246     uint32_t crtc_id;
0247     uint32_t fb_id;
0248 
0249     uint32_t crtc_x, crtc_y;
0250     uint32_t x, y;
0251 
0252     uint32_t possible_crtcs;
0253     uint32_t gamma_size;
0254 } drmModePlane, *drmModePlanePtr;
0255 
0256 typedef struct _drmModePlaneRes {
0257     uint32_t count_planes;
0258     uint32_t *planes;
0259 } drmModePlaneRes, *drmModePlaneResPtr;
0260 
0261 extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
0262 extern void drmModeFreeResources( drmModeResPtr ptr );
0263 extern void drmModeFreeFB( drmModeFBPtr ptr );
0264 extern void drmModeFreeFB2( drmModeFB2Ptr ptr );
0265 extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
0266 extern void drmModeFreeConnector( drmModeConnectorPtr ptr );
0267 extern void drmModeFreeEncoder( drmModeEncoderPtr ptr );
0268 extern void drmModeFreePlane( drmModePlanePtr ptr );
0269 extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr);
0270 
0271 /**
0272  * Check whether the DRM node supports Kernel Mode-Setting.
0273  *
0274  * Returns 1 if suitable for KMS, 0 otherwise.
0275  */
0276 extern int drmIsKMS(int fd);
0277 
0278 /**
0279  * Retrieves all of the resources associated with a card.
0280  */
0281 extern drmModeResPtr drmModeGetResources(int fd);
0282 
0283 /*
0284  * FrameBuffer manipulation.
0285  */
0286 
0287 /**
0288  * Retrieve information about framebuffer bufferId
0289  */
0290 extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId);
0291 extern drmModeFB2Ptr drmModeGetFB2(int fd, uint32_t bufferId);
0292 
0293 /**
0294  * Creates a new framebuffer with an buffer object as its scanout buffer.
0295  */
0296 extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
0297             uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
0298             uint32_t *buf_id);
0299 /* ...with a specific pixel format */
0300 extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
0301              uint32_t pixel_format, const uint32_t bo_handles[4],
0302              const uint32_t pitches[4], const uint32_t offsets[4],
0303              uint32_t *buf_id, uint32_t flags);
0304 
0305 /* ...with format modifiers */
0306 int drmModeAddFB2WithModifiers(int fd, uint32_t width, uint32_t height,
0307                    uint32_t pixel_format, const uint32_t bo_handles[4],
0308                    const uint32_t pitches[4], const uint32_t offsets[4],
0309                    const uint64_t modifier[4], uint32_t *buf_id,
0310                    uint32_t flags);
0311 
0312 /**
0313  * Destroies the given framebuffer.
0314  */
0315 extern int drmModeRmFB(int fd, uint32_t bufferId);
0316 
0317 /**
0318  * Close a framebuffer.
0319  *
0320  * Same as drmModeRmFB(), except it doesn't implicitly disable planes and CRTCs.
0321  */
0322 extern int drmModeCloseFB(int fd, uint32_t buffer_id);
0323 
0324 /**
0325  * Mark a region of a framebuffer as dirty.
0326  */
0327 extern int drmModeDirtyFB(int fd, uint32_t bufferId,
0328               drmModeClipPtr clips, uint32_t num_clips);
0329 
0330 
0331 /*
0332  * Crtc functions
0333  */
0334 
0335 /**
0336  * Retrieve information about the ctrt crtcId
0337  */
0338 extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
0339 
0340 /**
0341  * Set the mode on a crtc crtcId with the given mode modeId.
0342  */
0343 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
0344                    uint32_t x, uint32_t y, uint32_t *connectors, int count,
0345            drmModeModeInfoPtr mode);
0346 
0347 /*
0348  * Cursor functions
0349  */
0350 
0351 /**
0352  * Set the cursor on crtc
0353  */
0354 int drmModeSetCursor(int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height);
0355 
0356 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);
0357 /**
0358  * Move the cursor on crtc
0359  */
0360 int drmModeMoveCursor(int fd, uint32_t crtcId, int x, int y);
0361 
0362 /**
0363  * Encoder functions
0364  */
0365 drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id);
0366 
0367 /*
0368  * Connector manipulation
0369  */
0370 
0371 /**
0372  * Retrieve all information about the connector connectorId. This will do a
0373  * forced probe on the connector to retrieve remote information such as EDIDs
0374  * from the display device.
0375  */
0376 extern drmModeConnectorPtr drmModeGetConnector(int fd,
0377                            uint32_t connectorId);
0378 
0379 /**
0380  * Retrieve current information, i.e the currently active mode and encoder,
0381  * about the connector connectorId. This will not do any probing on the
0382  * connector or remote device, and only reports what is currently known.
0383  * For the complete set of modes and encoders associated with the connector
0384  * use drmModeGetConnector() which will do a probe to determine any display
0385  * link changes first.
0386  */
0387 extern drmModeConnectorPtr drmModeGetConnectorCurrent(int fd,
0388                               uint32_t connector_id);
0389 
0390 /**
0391  * Get a bitmask of CRTCs a connector is compatible with.
0392  *
0393  * The bits reference CRTC indices. If the n-th CRTC is compatible with the
0394  * connector, the n-th bit will be set. The indices are taken from the array
0395  * returned by drmModeGetResources(). The indices are different from the object
0396  * IDs.
0397  *
0398  * Zero is returned on error.
0399  */
0400 extern uint32_t drmModeConnectorGetPossibleCrtcs(int fd,
0401                                                  const drmModeConnector *connector);
0402 
0403 /**
0404  * Attaches the given mode to an connector.
0405  */
0406 extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
0407 
0408 /**
0409  * Detaches a mode from the connector
0410  * must be unused, by the given mode.
0411  */
0412 extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
0413 
0414 extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
0415 extern void drmModeFreeProperty(drmModePropertyPtr ptr);
0416 
0417 extern drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id);
0418 extern bool drmModeFormatModifierBlobIterNext(const drmModePropertyBlobRes *blob,
0419                           drmModeFormatModifierIterator *iter);
0420 extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
0421 extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
0422                     uint64_t value);
0423 extern int drmCheckModesettingSupported(const char *busid);
0424 
0425 extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
0426                    const uint16_t *red, const uint16_t *green, const uint16_t *blue);
0427 extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
0428                    uint16_t *red, uint16_t *green, uint16_t *blue);
0429 extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
0430                uint32_t flags, void *user_data);
0431 extern int drmModePageFlipTarget(int fd, uint32_t crtc_id, uint32_t fb_id,
0432                  uint32_t flags, void *user_data,
0433                  uint32_t target_vblank);
0434 
0435 extern drmModePlaneResPtr drmModeGetPlaneResources(int fd);
0436 extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id);
0437 extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
0438                uint32_t fb_id, uint32_t flags,
0439                int32_t crtc_x, int32_t crtc_y,
0440                uint32_t crtc_w, uint32_t crtc_h,
0441                uint32_t src_x, uint32_t src_y,
0442                uint32_t src_w, uint32_t src_h);
0443 
0444 extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd,
0445                             uint32_t object_id,
0446                             uint32_t object_type);
0447 extern void drmModeFreeObjectProperties(drmModeObjectPropertiesPtr ptr);
0448 extern int drmModeObjectSetProperty(int fd, uint32_t object_id,
0449                     uint32_t object_type, uint32_t property_id,
0450                     uint64_t value);
0451 
0452 
0453 typedef struct _drmModeAtomicReq drmModeAtomicReq, *drmModeAtomicReqPtr;
0454 
0455 extern drmModeAtomicReqPtr drmModeAtomicAlloc(void);
0456 extern drmModeAtomicReqPtr drmModeAtomicDuplicate(const drmModeAtomicReqPtr req);
0457 extern int drmModeAtomicMerge(drmModeAtomicReqPtr base,
0458                   const drmModeAtomicReqPtr augment);
0459 extern void drmModeAtomicFree(drmModeAtomicReqPtr req);
0460 extern int drmModeAtomicGetCursor(const drmModeAtomicReqPtr req);
0461 extern void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor);
0462 extern int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
0463                     uint32_t object_id,
0464                     uint32_t property_id,
0465                     uint64_t value);
0466 extern int drmModeAtomicCommit(int fd,
0467                    const drmModeAtomicReqPtr req,
0468                    uint32_t flags,
0469                    void *user_data);
0470 
0471 extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size,
0472                      uint32_t *id);
0473 extern int drmModeDestroyPropertyBlob(int fd, uint32_t id);
0474 
0475 /*
0476  * DRM mode lease APIs. These create and manage new drm_masters with
0477  * access to a subset of the available DRM resources
0478  */
0479 
0480 extern int drmModeCreateLease(int fd, const uint32_t *objects, int num_objects, int flags, uint32_t *lessee_id);
0481 
0482 typedef struct drmModeLesseeList {
0483     uint32_t count;
0484     uint32_t lessees[];
0485 } drmModeLesseeListRes, *drmModeLesseeListPtr;
0486 
0487 extern drmModeLesseeListPtr drmModeListLessees(int fd);
0488 
0489 typedef struct drmModeObjectList {
0490     uint32_t count;
0491     uint32_t objects[];
0492 } drmModeObjectListRes, *drmModeObjectListPtr;
0493 
0494 extern drmModeObjectListPtr drmModeGetLease(int fd);
0495 
0496 extern int drmModeRevokeLease(int fd, uint32_t lessee_id);
0497 
0498 /**
0499  * Get a string describing a connector type.
0500  *
0501  * NULL is returned if the connector type is unsupported. Callers should handle
0502  * this gracefully, e.g. by falling back to "Unknown" or printing the raw value.
0503  */
0504 extern const char *
0505 drmModeGetConnectorTypeName(uint32_t connector_type);
0506 
0507 /**
0508  * Create a dumb buffer.
0509  *
0510  * Given a width, height and bits-per-pixel, the kernel will return a buffer
0511  * handle, pitch and size. The flags must be zero.
0512  *
0513  * Returns 0 on success, negative errno on error.
0514  */
0515 extern int
0516 drmModeCreateDumbBuffer(int fd, uint32_t width, uint32_t height, uint32_t bpp,
0517                         uint32_t flags, uint32_t *handle, uint32_t *pitch,
0518                         uint64_t *size);
0519 
0520 /**
0521  * Destroy a dumb buffer.
0522  *
0523  * Returns 0 on success, negative errno on error.
0524  */
0525 extern int
0526 drmModeDestroyDumbBuffer(int fd, uint32_t handle);
0527 
0528 /**
0529  * Prepare a dumb buffer for mapping.
0530  *
0531  * The kernel returns an offset which can be used as an argument to mmap(2) on
0532  * the DRM FD.
0533  *
0534  * Returns 0 on success, negative errno on error.
0535  */
0536 extern int
0537 drmModeMapDumbBuffer(int fd, uint32_t handle, uint64_t *offset);
0538 
0539 #if defined(__cplusplus)
0540 }
0541 #endif
0542 
0543 #endif