3 * OS-independent header for DRM user-level library interface.
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
9 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
10 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
11 * All Rights Reserved.
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice (including the next
21 * paragraph) shall be included in all copies or substantial portions of the
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
27 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 * DEALINGS IN THE SOFTWARE.
38 #include <sys/types.h>
42 #if defined(__cplusplus)
47 #define DRM_MAX_MINOR 64 /* deprecated */
50 #if defined(__linux__)
52 #define DRM_IOCTL_NR(n) _IOC_NR(n)
53 #define DRM_IOC_VOID _IOC_NONE
54 #define DRM_IOC_READ _IOC_READ
55 #define DRM_IOC_WRITE _IOC_WRITE
56 #define DRM_IOC_READWRITE _IOC_READ|_IOC_WRITE
57 #define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
59 #else /* One of the *BSDs */
61 #include <sys/ioccom.h>
62 #define DRM_IOCTL_NR(n) ((n) & 0xff)
63 #define DRM_IOC_VOID IOC_VOID
64 #define DRM_IOC_READ IOC_OUT
65 #define DRM_IOC_WRITE IOC_IN
66 #define DRM_IOC_READWRITE IOC_INOUT
67 #define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
71 /* Defaults, if nothing set in xf86config */
74 /* Default /dev/dri directory permissions 0755 */
75 #define DRM_DEV_DIRMODE \
76 (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
77 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
80 #define DRM_DIR_NAME "/dev"
81 #define DRM_PRIMARY_MINOR_NAME "drm"
82 #define DRM_CONTROL_MINOR_NAME "drmC" /* deprecated */
83 #define DRM_RENDER_MINOR_NAME "drmR"
85 #define DRM_DIR_NAME "/dev/dri"
86 #define DRM_PRIMARY_MINOR_NAME "card"
87 #define DRM_CONTROL_MINOR_NAME "controlD" /* deprecated */
88 #define DRM_RENDER_MINOR_NAME "renderD"
89 #define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
92 #define DRM_DEV_NAME "%s/" DRM_PRIMARY_MINOR_NAME "%d"
93 #define DRM_CONTROL_DEV_NAME "%s/" DRM_CONTROL_MINOR_NAME "%d" /* deprecated */
94 #define DRM_RENDER_DEV_NAME "%s/" DRM_RENDER_MINOR_NAME "%d"
96 #define DRM_NODE_NAME_MAX \
97 (sizeof(DRM_DIR_NAME) + 1 /* slash */ \
98 + MAX3(sizeof(DRM_PRIMARY_MINOR_NAME), \
99 sizeof(DRM_CONTROL_MINOR_NAME), \
100 sizeof(DRM_RENDER_MINOR_NAME)) \
101 + sizeof("1048575") /* highest possible node number 2^MINORBITS - 1 */ \
102 + 1) /* NULL-terminator */
104 #define DRM_ERR_NO_DEVICE (-1001)
105 #define DRM_ERR_NO_ACCESS (-1002)
106 #define DRM_ERR_NOT_ROOT (-1003)
107 #define DRM_ERR_INVALID (-1004)
108 #define DRM_ERR_NO_FD (-1005)
110 #define DRM_AGP_NO_HANDLE 0
112 typedef unsigned int drmSize
, *drmSizePtr
; /**< For mapped regions */
113 typedef void *drmAddress
, **drmAddressPtr
; /**< For mapped regions */
116 #define DRM_PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a)))
118 #define DRM_PRINTFLIKE(f, a)
121 typedef struct _drmServerInfo
{
122 int (*debug_print
)(const char *format
, va_list ap
) DRM_PRINTFLIKE(1,0);
123 int (*load_module
)(const char *name
);
124 void (*get_perms
)(gid_t
*, mode_t
*);
125 } drmServerInfo
, *drmServerInfoPtr
;
127 typedef struct drmHashEntry
{
129 void (*f
)(int, void *, void *);
133 extern int drmIoctl(int fd
, unsigned long request
, void *arg
);
134 extern void *drmGetHashTable(void);
135 extern drmHashEntry
*drmGetEntry(int fd
);
138 * Driver version information.
140 * \sa drmGetVersion() and drmSetVersion().
142 typedef struct _drmVersion
{
143 int version_major
; /**< Major version */
144 int version_minor
; /**< Minor version */
145 int version_patchlevel
; /**< Patch level */
146 int name_len
; /**< Length of name buffer */
147 char *name
; /**< Name of driver */
148 int date_len
; /**< Length of date buffer */
149 char *date
; /**< User-space buffer to hold date */
150 int desc_len
; /**< Length of desc buffer */
151 char *desc
; /**< User-space buffer to hold desc */
152 } drmVersion
, *drmVersionPtr
;
154 typedef struct _drmStats
{
155 unsigned long count
; /**< Number of data */
157 unsigned long value
; /**< Value from kernel */
158 const char *long_format
; /**< Suggested format for long_name */
159 const char *long_name
; /**< Long name for value */
160 const char *rate_format
; /**< Suggested format for rate_name */
161 const char *rate_name
; /**< Short name for value per second */
162 int isvalue
; /**< True if value (vs. counter) */
163 const char *mult_names
; /**< Multiplier names (e.g., "KGM") */
164 int mult
; /**< Multiplier value (e.g., 1024) */
165 int verbose
; /**< Suggest only in verbose output */
170 /* All of these enums *MUST* match with the
171 kernel implementation -- so do *NOT*
172 change them! (The drmlib implementation
173 will just copy the flags instead of
174 translating them.) */
176 DRM_FRAME_BUFFER
= 0, /**< WC, no caching, no core dump */
177 DRM_REGISTERS
= 1, /**< no caching, no core dump */
178 DRM_SHM
= 2, /**< shared, cached */
179 DRM_AGP
= 3, /**< AGP/GART */
180 DRM_SCATTER_GATHER
= 4, /**< PCI scatter/gather */
181 DRM_CONSISTENT
= 5 /**< PCI consistent */
185 DRM_RESTRICTED
= 0x0001, /**< Cannot be mapped to client-virtual */
186 DRM_READ_ONLY
= 0x0002, /**< Read-only in client-virtual */
187 DRM_LOCKED
= 0x0004, /**< Physical pages locked */
188 DRM_KERNEL
= 0x0008, /**< Kernel requires access */
189 DRM_WRITE_COMBINING
= 0x0010, /**< Use write-combining, if available */
190 DRM_CONTAINS_LOCK
= 0x0020, /**< SHM page that contains lock */
191 DRM_REMOVABLE
= 0x0040 /**< Removable mapping */
195 * \warning These values *MUST* match drm.h
198 /** \name Flags for DMA buffer dispatch */
200 DRM_DMA_BLOCK
= 0x01, /**<
201 * Block until buffer dispatched.
203 * \note the buffer may not yet have been
204 * processed by the hardware -- getting a
205 * hardware lock with the hardware quiescent
206 * will ensure that the buffer has been
209 DRM_DMA_WHILE_LOCKED
= 0x02, /**< Dispatch while lock held */
210 DRM_DMA_PRIORITY
= 0x04, /**< High priority dispatch */
213 /** \name Flags for DMA buffer request */
215 DRM_DMA_WAIT
= 0x10, /**< Wait for free buffers */
216 DRM_DMA_SMALLER_OK
= 0x20, /**< Smaller-than-requested buffers OK */
217 DRM_DMA_LARGER_OK
= 0x40 /**< Larger-than-requested buffers OK */
222 DRM_PAGE_ALIGN
= 0x01,
223 DRM_AGP_BUFFER
= 0x02,
224 DRM_SG_BUFFER
= 0x04,
225 DRM_FB_BUFFER
= 0x08,
226 DRM_PCI_BUFFER_RO
= 0x10
230 DRM_LOCK_READY
= 0x01, /**< Wait until hardware is ready for DMA */
231 DRM_LOCK_QUIESCENT
= 0x02, /**< Wait until hardware quiescent */
232 DRM_LOCK_FLUSH
= 0x04, /**< Flush this context's DMA queue first */
233 DRM_LOCK_FLUSH_ALL
= 0x08, /**< Flush all DMA queues first */
234 /* These *HALT* flags aren't supported yet
235 -- they will be used to support the
236 full-screen DGA-like mode. */
237 DRM_HALT_ALL_QUEUES
= 0x10, /**< Halt all current and future queues */
238 DRM_HALT_CUR_QUEUES
= 0x20 /**< Halt all current queues */
242 DRM_CONTEXT_PRESERVED
= 0x01, /**< This context is preserved and
244 DRM_CONTEXT_2DONLY
= 0x02 /**< This context is for 2D rendering only. */
245 } drm_context_tFlags
, *drm_context_tFlagsPtr
;
247 typedef struct _drmBufDesc
{
248 int count
; /**< Number of buffers of this size */
249 int size
; /**< Size in bytes */
250 int low_mark
; /**< Low water mark */
251 int high_mark
; /**< High water mark */
252 } drmBufDesc
, *drmBufDescPtr
;
254 typedef struct _drmBufInfo
{
255 int count
; /**< Number of buffers described in list */
256 drmBufDescPtr list
; /**< List of buffer descriptions */
257 } drmBufInfo
, *drmBufInfoPtr
;
259 typedef struct _drmBuf
{
260 int idx
; /**< Index into the master buffer list */
261 int total
; /**< Buffer size */
262 int used
; /**< Amount of buffer in use (for DMA) */
263 drmAddress address
; /**< Address */
264 } drmBuf
, *drmBufPtr
;
267 * Buffer mapping information.
269 * Used by drmMapBufs() and drmUnmapBufs() to store information about the
272 typedef struct _drmBufMap
{
273 int count
; /**< Number of buffers mapped */
274 drmBufPtr list
; /**< Buffers */
275 } drmBufMap
, *drmBufMapPtr
;
277 typedef struct _drmLock
{
278 volatile unsigned int lock
;
280 /* This is big enough for most current (and future?) architectures:
283 Intel P5/PPro/PII/PIII: 32 bytes
284 Intel StrongARM: 32 bytes
285 Intel i386/i486: 16 bytes
287 Motorola 68k: 16 bytes
288 Motorola PowerPC: 32 bytes
291 } drmLock
, *drmLockPtr
;
294 * Indices here refer to the offset into
297 typedef struct _drmDMAReq
{
298 drm_context_t context
; /**< Context handle */
299 int send_count
; /**< Number of buffers to send */
300 int *send_list
; /**< List of handles to buffers */
301 int *send_sizes
; /**< Lengths of data to send, in bytes */
302 drmDMAFlags flags
; /**< Flags */
303 int request_count
; /**< Number of buffers requested */
304 int request_size
; /**< Desired size of buffers requested */
305 int *request_list
; /**< Buffer information */
306 int *request_sizes
; /**< Minimum acceptable sizes */
307 int granted_count
; /**< Number of buffers granted at this size */
308 } drmDMAReq
, *drmDMAReqPtr
;
310 typedef struct _drmRegion
{
315 } drmRegion
, *drmRegionPtr
;
317 typedef struct _drmTextureRegion
{
320 unsigned char in_use
;
321 unsigned char padding
; /**< Explicitly pad this out */
323 } drmTextureRegion
, *drmTextureRegionPtr
;
327 DRM_VBLANK_ABSOLUTE
= 0x0, /**< Wait for specific vblank sequence number */
328 DRM_VBLANK_RELATIVE
= 0x1, /**< Wait for given number of vblanks */
329 /* bits 1-6 are reserved for high crtcs */
330 DRM_VBLANK_HIGH_CRTC_MASK
= 0x0000003e,
331 DRM_VBLANK_EVENT
= 0x4000000, /**< Send event instead of blocking */
332 DRM_VBLANK_FLIP
= 0x8000000, /**< Scheduled buffer swap should flip */
333 DRM_VBLANK_NEXTONMISS
= 0x10000000, /**< If missed, wait for next vblank */
334 DRM_VBLANK_SECONDARY
= 0x20000000, /**< Secondary display controller */
335 DRM_VBLANK_SIGNAL
= 0x40000000 /* Send signal instead of blocking */
337 #define DRM_VBLANK_HIGH_CRTC_SHIFT 1
339 typedef struct _drmVBlankReq
{
340 drmVBlankSeqType type
;
341 unsigned int sequence
;
342 unsigned long signal
;
343 } drmVBlankReq
, *drmVBlankReqPtr
;
345 typedef struct _drmVBlankReply
{
346 drmVBlankSeqType type
;
347 unsigned int sequence
;
350 } drmVBlankReply
, *drmVBlankReplyPtr
;
352 typedef union _drmVBlank
{
353 drmVBlankReq request
;
354 drmVBlankReply reply
;
355 } drmVBlank
, *drmVBlankPtr
;
357 typedef struct _drmSetVersion
{
362 } drmSetVersion
, *drmSetVersionPtr
;
364 #define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
366 #define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
367 #define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
369 #if defined(__GNUC__) && (__GNUC__ >= 2)
370 # if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
371 /* Reflect changes here to drmP.h */
372 #define DRM_CAS(lock,old,new,__ret) \
374 int __dummy; /* Can't mark eax as clobbered */ \
375 __asm__ __volatile__( \
376 "lock ; cmpxchg %4,%1\n\t" \
379 "=m" (__drm_dummy_lock(lock)), \
385 #elif defined(__alpha__)
387 #define DRM_CAS(lock, old, new, ret) \
390 __asm__ __volatile__( \
391 " addl $31, %5, %3\n" \
392 "1: ldl_l %0, %2\n" \
393 " cmpeq %0, %3, %1\n" \
399 "2: cmpeq %1, 0, %1\n" \
403 : "=&r"(tmp), "=&r"(ret), \
404 "=m"(__drm_dummy_lock(lock)), \
406 : "r"(new), "r"(old) \
410 #elif defined(__sparc__)
412 #define DRM_CAS(lock,old,new,__ret) \
413 do { register unsigned int __old __asm("o0"); \
414 register unsigned int __new __asm("o1"); \
415 register volatile unsigned int *__lock __asm("o2"); \
418 __lock = (volatile unsigned int *)lock; \
419 __asm__ __volatile__( \
420 /*"cas [%2], %3, %0"*/ \
421 ".word 0xd3e29008\n\t" \
422 /*"membar #StoreStore | #StoreLoad"*/ \
429 __ret = (__new != __old); \
432 #elif defined(__ia64__)
434 #ifdef __INTEL_COMPILER
435 /* this currently generates bad code (missing stop bits)... */
436 #include <ia64intrin.h>
438 #define DRM_CAS(lock,old,new,__ret) \
440 unsigned long __result, __old = (old) & 0xffffffff; \
442 __result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\
443 __ret = (__result) != (__old); \
444 /* __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
450 #define DRM_CAS(lock,old,new,__ret) \
452 unsigned int __result, __old = (old); \
453 __asm__ __volatile__( \
457 "cmpxchg4.acq %0=%1,%3,ar.ccv" \
458 : "=r" (__result), "=m" (__drm_dummy_lock(lock)) \
459 : "r" ((unsigned long)__old), "r" (new) \
461 __ret = (__result) != (__old); \
466 #elif defined(__powerpc__)
468 #define DRM_CAS(lock,old,new,__ret) \
470 __asm__ __volatile__( \
472 "0: lwarx %0,0,%1;" \
480 : "r"(lock), "r"(new), "r"(old) \
481 : "cr0", "memory"); \
484 # elif defined (__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
485 || defined (__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \
486 || defined (__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) \
487 || defined (__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
488 || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
489 || defined(__ARM_ARCH_7EM__)
490 /* excluding ARMv4/ARMv5 and lower (lacking ldrex/strex support) */
492 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
494 #define DRM_CAS(lock,old,new,__ret) \
496 __asm__ __volatile__ ( \
497 "1: ldrex %0, [%1]\n" \
500 " strexeq %0, %3, [%1]\n" \
503 : "r" (lock), "r" (old), "r" (new) \
507 #endif /* architecture */
508 #endif /* __GNUC__ >= 2 */
511 #define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
514 #if defined(__alpha__)
515 #define DRM_CAS_RESULT(_result) long _result
516 #elif defined(__powerpc__)
517 #define DRM_CAS_RESULT(_result) int _result
519 #define DRM_CAS_RESULT(_result) char _result
522 #define DRM_LIGHT_LOCK(fd,lock,context) \
524 DRM_CAS_RESULT(__ret); \
525 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
526 if (__ret) drmGetLock(fd,context,0); \
529 /* This one counts fast locks -- for
530 benchmarking only. */
531 #define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \
533 DRM_CAS_RESULT(__ret); \
534 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
535 if (__ret) drmGetLock(fd,context,0); \
539 #define DRM_LOCK(fd,lock,context,flags) \
541 if (flags) drmGetLock(fd,context,flags); \
542 else DRM_LIGHT_LOCK(fd,lock,context); \
545 #define DRM_UNLOCK(fd,lock,context) \
547 DRM_CAS_RESULT(__ret); \
548 DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \
549 if (__ret) drmUnlock(fd,context); \
552 /* Simple spin locks */
553 #define DRM_SPINLOCK(spin,val) \
555 DRM_CAS_RESULT(__ret); \
557 DRM_CAS(spin,0,val,__ret); \
558 if (__ret) while ((spin)->lock); \
562 #define DRM_SPINLOCK_TAKE(spin,val) \
564 DRM_CAS_RESULT(__ret); \
567 cur = (*spin).lock; \
568 DRM_CAS(spin,cur,val,__ret); \
572 #define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \
576 for (__i = 0; __ret && __i < count; __i++) { \
577 DRM_CAS(spin,0,val,__ret); \
578 if (__ret) for (;__i < count && (spin)->lock; __i++); \
582 #define DRM_SPINUNLOCK(spin,val) \
584 DRM_CAS_RESULT(__ret); \
585 if ((*spin).lock == val) { /* else server stole lock */ \
587 DRM_CAS(spin,val,0,__ret); \
594 /* General user-level programmer's API: unprivileged */
595 extern int drmAvailable(void);
596 extern int drmOpen(const char *name
, const char *busid
);
598 #define DRM_NODE_PRIMARY 0
599 #define DRM_NODE_CONTROL 1 /* deprecated: never returned */
600 #define DRM_NODE_RENDER 2
601 #define DRM_NODE_MAX 3
603 extern int drmOpenWithType(const char *name
, const char *busid
,
606 extern int drmOpenControl(int minor
); /* deprecated: always fails */
607 extern int drmOpenRender(int minor
);
608 extern int drmClose(int fd
);
609 extern drmVersionPtr
drmGetVersion(int fd
);
610 extern drmVersionPtr
drmGetLibVersion(int fd
);
611 extern int drmGetCap(int fd
, uint64_t capability
, uint64_t *value
);
612 extern void drmFreeVersion(drmVersionPtr
);
613 extern int drmGetMagic(int fd
, drm_magic_t
* magic
);
614 extern char *drmGetBusid(int fd
);
615 extern int drmGetInterruptFromBusID(int fd
, int busnum
, int devnum
,
617 extern int drmGetMap(int fd
, int idx
, drm_handle_t
*offset
,
618 drmSize
*size
, drmMapType
*type
,
619 drmMapFlags
*flags
, drm_handle_t
*handle
,
621 extern int drmGetClient(int fd
, int idx
, int *auth
, int *pid
,
622 int *uid
, unsigned long *magic
,
623 unsigned long *iocs
);
624 extern int drmGetStats(int fd
, drmStatsT
*stats
);
625 extern int drmSetInterfaceVersion(int fd
, drmSetVersion
*version
);
626 extern int drmCommandNone(int fd
, unsigned long drmCommandIndex
);
627 extern int drmCommandRead(int fd
, unsigned long drmCommandIndex
,
628 void *data
, unsigned long size
);
629 extern int drmCommandWrite(int fd
, unsigned long drmCommandIndex
,
630 void *data
, unsigned long size
);
631 extern int drmCommandWriteRead(int fd
, unsigned long drmCommandIndex
,
632 void *data
, unsigned long size
);
634 /* General user-level programmer's API: X server (root) only */
635 extern void drmFreeBusid(const char *busid
);
636 extern int drmSetBusid(int fd
, const char *busid
);
637 extern int drmAuthMagic(int fd
, drm_magic_t magic
);
638 extern int drmAddMap(int fd
,
643 drm_handle_t
* handle
);
644 extern int drmRmMap(int fd
, drm_handle_t handle
);
645 extern int drmAddContextPrivateMapping(int fd
, drm_context_t ctx_id
,
646 drm_handle_t handle
);
648 extern int drmAddBufs(int fd
, int count
, int size
,
649 drmBufDescFlags flags
,
651 extern int drmMarkBufs(int fd
, double low
, double high
);
652 extern int drmCreateContext(int fd
, drm_context_t
* handle
);
653 extern int drmSetContextFlags(int fd
, drm_context_t context
,
654 drm_context_tFlags flags
);
655 extern int drmGetContextFlags(int fd
, drm_context_t context
,
656 drm_context_tFlagsPtr flags
);
657 extern int drmAddContextTag(int fd
, drm_context_t context
, void *tag
);
658 extern int drmDelContextTag(int fd
, drm_context_t context
);
659 extern void *drmGetContextTag(int fd
, drm_context_t context
);
660 extern drm_context_t
* drmGetReservedContextList(int fd
, int *count
);
661 extern void drmFreeReservedContextList(drm_context_t
*);
662 extern int drmSwitchToContext(int fd
, drm_context_t context
);
663 extern int drmDestroyContext(int fd
, drm_context_t handle
);
664 extern int drmCreateDrawable(int fd
, drm_drawable_t
* handle
);
665 extern int drmDestroyDrawable(int fd
, drm_drawable_t handle
);
666 extern int drmUpdateDrawableInfo(int fd
, drm_drawable_t handle
,
667 drm_drawable_info_type_t type
,
668 unsigned int num
, void *data
);
669 extern int drmCtlInstHandler(int fd
, int irq
);
670 extern int drmCtlUninstHandler(int fd
);
671 extern int drmSetClientCap(int fd
, uint64_t capability
,
674 extern int drmCrtcGetSequence(int fd
, uint32_t crtcId
,
675 uint64_t *sequence
, uint64_t *ns
);
676 extern int drmCrtcQueueSequence(int fd
, uint32_t crtcId
,
677 uint32_t flags
, uint64_t sequence
,
678 uint64_t *sequence_queued
,
680 /* General user-level programmer's API: authenticated client and/or X */
681 extern int drmMap(int fd
,
684 drmAddressPtr address
);
685 extern int drmUnmap(drmAddress address
, drmSize size
);
686 extern drmBufInfoPtr
drmGetBufInfo(int fd
);
687 extern drmBufMapPtr
drmMapBufs(int fd
);
688 extern int drmUnmapBufs(drmBufMapPtr bufs
);
689 extern int drmDMA(int fd
, drmDMAReqPtr request
);
690 extern int drmFreeBufs(int fd
, int count
, int *list
);
691 extern int drmGetLock(int fd
,
692 drm_context_t context
,
694 extern int drmUnlock(int fd
, drm_context_t context
);
695 extern int drmFinish(int fd
, int context
, drmLockFlags flags
);
696 extern int drmGetContextPrivateMapping(int fd
, drm_context_t ctx_id
,
697 drm_handle_t
* handle
);
699 /* AGP/GART support: X server (root) only */
700 extern int drmAgpAcquire(int fd
);
701 extern int drmAgpRelease(int fd
);
702 extern int drmAgpEnable(int fd
, unsigned long mode
);
703 extern int drmAgpAlloc(int fd
, unsigned long size
,
704 unsigned long type
, unsigned long *address
,
705 drm_handle_t
*handle
);
706 extern int drmAgpFree(int fd
, drm_handle_t handle
);
707 extern int drmAgpBind(int fd
, drm_handle_t handle
,
708 unsigned long offset
);
709 extern int drmAgpUnbind(int fd
, drm_handle_t handle
);
711 /* AGP/GART info: authenticated client and/or X */
712 extern int drmAgpVersionMajor(int fd
);
713 extern int drmAgpVersionMinor(int fd
);
714 extern unsigned long drmAgpGetMode(int fd
);
715 extern unsigned long drmAgpBase(int fd
); /* Physical location */
716 extern unsigned long drmAgpSize(int fd
); /* Bytes */
717 extern unsigned long drmAgpMemoryUsed(int fd
);
718 extern unsigned long drmAgpMemoryAvail(int fd
);
719 extern unsigned int drmAgpVendorId(int fd
);
720 extern unsigned int drmAgpDeviceId(int fd
);
722 /* PCI scatter/gather support: X server (root) only */
723 extern int drmScatterGatherAlloc(int fd
, unsigned long size
,
724 drm_handle_t
*handle
);
725 extern int drmScatterGatherFree(int fd
, drm_handle_t handle
);
727 extern int drmWaitVBlank(int fd
, drmVBlankPtr vbl
);
729 /* Support routines */
730 extern void drmSetServerInfo(drmServerInfoPtr info
);
731 extern int drmError(int err
, const char *label
);
732 extern void *drmMalloc(int size
);
733 extern void drmFree(void *pt
);
735 /* Hash table routines */
736 extern void *drmHashCreate(void);
737 extern int drmHashDestroy(void *t
);
738 extern int drmHashLookup(void *t
, unsigned long key
, void **value
);
739 extern int drmHashInsert(void *t
, unsigned long key
, void *value
);
740 extern int drmHashDelete(void *t
, unsigned long key
);
741 extern int drmHashFirst(void *t
, unsigned long *key
, void **value
);
742 extern int drmHashNext(void *t
, unsigned long *key
, void **value
);
745 extern void *drmRandomCreate(unsigned long seed
);
746 extern int drmRandomDestroy(void *state
);
747 extern unsigned long drmRandom(void *state
);
748 extern double drmRandomDouble(void *state
);
750 /* Skip list routines */
752 extern void *drmSLCreate(void);
753 extern int drmSLDestroy(void *l
);
754 extern int drmSLLookup(void *l
, unsigned long key
, void **value
);
755 extern int drmSLInsert(void *l
, unsigned long key
, void *value
);
756 extern int drmSLDelete(void *l
, unsigned long key
);
757 extern int drmSLNext(void *l
, unsigned long *key
, void **value
);
758 extern int drmSLFirst(void *l
, unsigned long *key
, void **value
);
759 extern void drmSLDump(void *l
);
760 extern int drmSLLookupNeighbors(void *l
, unsigned long key
,
761 unsigned long *prev_key
, void **prev_value
,
762 unsigned long *next_key
, void **next_value
);
764 extern int drmOpenOnce(void *unused
, const char *BusID
, int *newlyopened
);
765 extern int drmOpenOnceWithType(const char *BusID
, int *newlyopened
, int type
);
766 extern void drmCloseOnce(int fd
);
767 extern void drmMsg(const char *format
, ...) DRM_PRINTFLIKE(1, 2);
769 extern int drmSetMaster(int fd
);
770 extern int drmDropMaster(int fd
);
771 extern int drmIsMaster(int fd
);
773 #define DRM_EVENT_CONTEXT_VERSION 4
775 typedef struct _drmEventContext
{
777 /* This struct is versioned so we can add more pointers if we
778 * add more events. */
781 void (*vblank_handler
)(int fd
,
782 unsigned int sequence
,
784 unsigned int tv_usec
,
787 void (*page_flip_handler
)(int fd
,
788 unsigned int sequence
,
790 unsigned int tv_usec
,
793 void (*page_flip_handler2
)(int fd
,
794 unsigned int sequence
,
796 unsigned int tv_usec
,
797 unsigned int crtc_id
,
800 void (*sequence_handler
)(int fd
,
804 } drmEventContext
, *drmEventContextPtr
;
806 extern int drmHandleEvent(int fd
, drmEventContextPtr evctx
);
808 extern char *drmGetDeviceNameFromFd(int fd
);
810 /* Improved version of drmGetDeviceNameFromFd which attributes for any type of
811 * device/node - card or renderD.
813 extern char *drmGetDeviceNameFromFd2(int fd
);
814 extern int drmGetNodeTypeFromFd(int fd
);
816 /* Convert between GEM handles and DMA-BUF file descriptors.
818 * Warning: since GEM handles are not reference-counted and are unique per
819 * DRM file description, the caller is expected to perform its own reference
820 * counting. drmPrimeFDToHandle is guaranteed to return the same handle for
821 * different FDs if they reference the same underlying buffer object. This
822 * could even be a buffer object originally created on the same DRM FD.
824 * When sharing a DRM FD with an API such as EGL or GBM, the caller must not
825 * use drmPrimeHandleToFD nor drmPrimeFDToHandle. A single user-space
826 * reference-counting implementation is necessary to avoid double-closing GEM
829 * Two processes can't share the same DRM FD and both use it to create or
830 * import GEM handles, even when using a single user-space reference-counting
831 * implementation like GBM, because GBM doesn't share its state between
834 extern int drmPrimeHandleToFD(int fd
, uint32_t handle
, uint32_t flags
, int *prime_fd
);
835 extern int drmPrimeFDToHandle(int fd
, int prime_fd
, uint32_t *handle
);
837 extern int drmCloseBufferHandle(int fd
, uint32_t handle
);
839 extern char *drmGetPrimaryDeviceNameFromFd(int fd
);
840 extern char *drmGetRenderDeviceNameFromFd(int fd
);
842 #define DRM_BUS_PCI 0
843 #define DRM_BUS_USB 1
844 #define DRM_BUS_PLATFORM 2
845 #define DRM_BUS_HOST1X 3
847 typedef struct _drmPciBusInfo
{
852 } drmPciBusInfo
, *drmPciBusInfoPtr
;
854 typedef struct _drmPciDeviceInfo
{
857 uint16_t subvendor_id
;
858 uint16_t subdevice_id
;
860 } drmPciDeviceInfo
, *drmPciDeviceInfoPtr
;
862 typedef struct _drmUsbBusInfo
{
865 } drmUsbBusInfo
, *drmUsbBusInfoPtr
;
867 typedef struct _drmUsbDeviceInfo
{
870 } drmUsbDeviceInfo
, *drmUsbDeviceInfoPtr
;
872 #define DRM_PLATFORM_DEVICE_NAME_LEN 512
874 typedef struct _drmPlatformBusInfo
{
875 char fullname
[DRM_PLATFORM_DEVICE_NAME_LEN
];
876 } drmPlatformBusInfo
, *drmPlatformBusInfoPtr
;
878 typedef struct _drmPlatformDeviceInfo
{
879 char **compatible
; /* NULL terminated list of compatible strings */
880 } drmPlatformDeviceInfo
, *drmPlatformDeviceInfoPtr
;
882 #define DRM_HOST1X_DEVICE_NAME_LEN 512
884 typedef struct _drmHost1xBusInfo
{
885 char fullname
[DRM_HOST1X_DEVICE_NAME_LEN
];
886 } drmHost1xBusInfo
, *drmHost1xBusInfoPtr
;
888 typedef struct _drmHost1xDeviceInfo
{
889 char **compatible
; /* NULL terminated list of compatible strings */
890 } drmHost1xDeviceInfo
, *drmHost1xDeviceInfoPtr
;
892 typedef struct _drmDevice
{
893 char **nodes
; /* DRM_NODE_MAX sized array */
894 int available_nodes
; /* DRM_NODE_* bitmask */
897 drmPciBusInfoPtr pci
;
898 drmUsbBusInfoPtr usb
;
899 drmPlatformBusInfoPtr platform
;
900 drmHost1xBusInfoPtr host1x
;
903 drmPciDeviceInfoPtr pci
;
904 drmUsbDeviceInfoPtr usb
;
905 drmPlatformDeviceInfoPtr platform
;
906 drmHost1xDeviceInfoPtr host1x
;
908 } drmDevice
, *drmDevicePtr
;
910 extern int drmGetDevice(int fd
, drmDevicePtr
*device
);
911 extern void drmFreeDevice(drmDevicePtr
*device
);
913 extern int drmGetDevices(drmDevicePtr devices
[], int max_devices
);
914 extern void drmFreeDevices(drmDevicePtr devices
[], int count
);
916 #define DRM_DEVICE_GET_PCI_REVISION (1 << 0)
917 extern int drmGetDevice2(int fd
, uint32_t flags
, drmDevicePtr
*device
);
918 extern int drmGetDevices2(uint32_t flags
, drmDevicePtr devices
[], int max_devices
);
920 extern int drmGetDeviceFromDevId(dev_t dev_id
, uint32_t flags
, drmDevicePtr
*device
);
923 * Get the node type (DRM_NODE_PRIMARY or DRM_NODE_RENDER) from a device ID.
925 * Returns negative errno on error.
927 extern int drmGetNodeTypeFromDevId(dev_t devid
);
929 extern int drmDevicesEqual(drmDevicePtr a
, drmDevicePtr b
);
931 extern int drmSyncobjCreate(int fd
, uint32_t flags
, uint32_t *handle
);
932 extern int drmSyncobjDestroy(int fd
, uint32_t handle
);
933 extern int drmSyncobjHandleToFD(int fd
, uint32_t handle
, int *obj_fd
);
934 extern int drmSyncobjFDToHandle(int fd
, int obj_fd
, uint32_t *handle
);
936 extern int drmSyncobjImportSyncFile(int fd
, uint32_t handle
, int sync_file_fd
);
937 extern int drmSyncobjExportSyncFile(int fd
, uint32_t handle
, int *sync_file_fd
);
938 extern int drmSyncobjWait(int fd
, uint32_t *handles
, unsigned num_handles
,
939 int64_t timeout_nsec
, unsigned flags
,
940 uint32_t *first_signaled
);
941 extern int drmSyncobjReset(int fd
, const uint32_t *handles
, uint32_t handle_count
);
942 extern int drmSyncobjSignal(int fd
, const uint32_t *handles
, uint32_t handle_count
);
943 extern int drmSyncobjTimelineSignal(int fd
, const uint32_t *handles
,
944 uint64_t *points
, uint32_t handle_count
);
945 extern int drmSyncobjTimelineWait(int fd
, uint32_t *handles
, uint64_t *points
,
946 unsigned num_handles
,
947 int64_t timeout_nsec
, unsigned flags
,
948 uint32_t *first_signaled
);
949 extern int drmSyncobjQuery(int fd
, uint32_t *handles
, uint64_t *points
,
950 uint32_t handle_count
);
951 extern int drmSyncobjQuery2(int fd
, uint32_t *handles
, uint64_t *points
,
952 uint32_t handle_count
, uint32_t flags
);
953 extern int drmSyncobjTransfer(int fd
,
954 uint32_t dst_handle
, uint64_t dst_point
,
955 uint32_t src_handle
, uint64_t src_point
,
957 extern int drmSyncobjEventfd(int fd
, uint32_t handle
, uint64_t point
, int ev_fd
,
961 drmGetFormatModifierVendor(uint64_t modifier
);
964 drmGetFormatModifierName(uint64_t modifier
);
967 drmGetFormatName(uint32_t format
);
969 #ifndef fourcc_mod_get_vendor
970 #define fourcc_mod_get_vendor(modifier) \
971 (((modifier) >> 56) & 0xff)
974 #if defined(__cplusplus)