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 16
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_DEV_NAME "%s/drm%d"
82 #define DRM_CONTROL_DEV_NAME "%s/drmC%d"
83 #define DRM_RENDER_DEV_NAME "%s/drmR%d"
85 #define DRM_DIR_NAME "/dev/dri"
86 #define DRM_DEV_NAME "%s/card%d"
87 #define DRM_CONTROL_DEV_NAME "%s/controlD%d"
88 #define DRM_RENDER_DEV_NAME "%s/renderD%d"
89 #define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
92 #define DRM_ERR_NO_DEVICE (-1001)
93 #define DRM_ERR_NO_ACCESS (-1002)
94 #define DRM_ERR_NOT_ROOT (-1003)
95 #define DRM_ERR_INVALID (-1004)
96 #define DRM_ERR_NO_FD (-1005)
98 #define DRM_AGP_NO_HANDLE 0
100 typedef unsigned int drmSize, *drmSizePtr; /**< For mapped regions */
101 typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */
104 #define DRM_PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a)))
106 #define DRM_PRINTFLIKE(f, a)
109 typedef struct _drmServerInfo {
110 int (*debug_print)(const char *format, va_list ap) DRM_PRINTFLIKE(1,0);
111 int (*load_module)(const char *name);
112 void (*get_perms)(gid_t *, mode_t *);
113 } drmServerInfo, *drmServerInfoPtr;
115 typedef struct drmHashEntry {
117 void (*f)(int, void *, void *);
121 extern int drmIoctl(int fd, unsigned long request, void *arg);
122 extern void *drmGetHashTable(void);
123 extern drmHashEntry *drmGetEntry(int fd);
126 * Driver version information.
128 * \sa drmGetVersion() and drmSetVersion().
130 typedef struct _drmVersion {
131 int version_major; /**< Major version */
132 int version_minor; /**< Minor version */
133 int version_patchlevel; /**< Patch level */
134 int name_len; /**< Length of name buffer */
135 char *name; /**< Name of driver */
136 int date_len; /**< Length of date buffer */
137 char *date; /**< User-space buffer to hold date */
138 int desc_len; /**< Length of desc buffer */
139 char *desc; /**< User-space buffer to hold desc */
140 } drmVersion, *drmVersionPtr;
142 typedef struct _drmStats {
143 unsigned long count; /**< Number of data */
145 unsigned long value; /**< Value from kernel */
146 const char *long_format; /**< Suggested format for long_name */
147 const char *long_name; /**< Long name for value */
148 const char *rate_format; /**< Suggested format for rate_name */
149 const char *rate_name; /**< Short name for value per second */
150 int isvalue; /**< True if value (vs. counter) */
151 const char *mult_names; /**< Multiplier names (e.g., "KGM") */
152 int mult; /**< Multiplier value (e.g., 1024) */
153 int verbose; /**< Suggest only in verbose output */
158 /* All of these enums *MUST* match with the
159 kernel implementation -- so do *NOT*
160 change them! (The drmlib implementation
161 will just copy the flags instead of
162 translating them.) */
164 DRM_FRAME_BUFFER = 0, /**< WC, no caching, no core dump */
165 DRM_REGISTERS = 1, /**< no caching, no core dump */
166 DRM_SHM = 2, /**< shared, cached */
167 DRM_AGP = 3, /**< AGP/GART */
168 DRM_SCATTER_GATHER = 4, /**< PCI scatter/gather */
169 DRM_CONSISTENT = 5 /**< PCI consistent */
173 DRM_RESTRICTED = 0x0001, /**< Cannot be mapped to client-virtual */
174 DRM_READ_ONLY = 0x0002, /**< Read-only in client-virtual */
175 DRM_LOCKED = 0x0004, /**< Physical pages locked */
176 DRM_KERNEL = 0x0008, /**< Kernel requires access */
177 DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */
178 DRM_CONTAINS_LOCK = 0x0020, /**< SHM page that contains lock */
179 DRM_REMOVABLE = 0x0040 /**< Removable mapping */
183 * \warning These values *MUST* match drm.h
186 /** \name Flags for DMA buffer dispatch */
188 DRM_DMA_BLOCK = 0x01, /**<
189 * Block until buffer dispatched.
191 * \note the buffer may not yet have been
192 * processed by the hardware -- getting a
193 * hardware lock with the hardware quiescent
194 * will ensure that the buffer has been
197 DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
198 DRM_DMA_PRIORITY = 0x04, /**< High priority dispatch */
201 /** \name Flags for DMA buffer request */
203 DRM_DMA_WAIT = 0x10, /**< Wait for free buffers */
204 DRM_DMA_SMALLER_OK = 0x20, /**< Smaller-than-requested buffers OK */
205 DRM_DMA_LARGER_OK = 0x40 /**< Larger-than-requested buffers OK */
210 DRM_PAGE_ALIGN = 0x01,
211 DRM_AGP_BUFFER = 0x02,
212 DRM_SG_BUFFER = 0x04,
213 DRM_FB_BUFFER = 0x08,
214 DRM_PCI_BUFFER_RO = 0x10
218 DRM_LOCK_READY = 0x01, /**< Wait until hardware is ready for DMA */
219 DRM_LOCK_QUIESCENT = 0x02, /**< Wait until hardware quiescent */
220 DRM_LOCK_FLUSH = 0x04, /**< Flush this context's DMA queue first */
221 DRM_LOCK_FLUSH_ALL = 0x08, /**< Flush all DMA queues first */
222 /* These *HALT* flags aren't supported yet
223 -- they will be used to support the
224 full-screen DGA-like mode. */
225 DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
226 DRM_HALT_CUR_QUEUES = 0x20 /**< Halt all current queues */
230 DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and
232 DRM_CONTEXT_2DONLY = 0x02 /**< This context is for 2D rendering only. */
233 } drm_context_tFlags, *drm_context_tFlagsPtr;
235 typedef struct _drmBufDesc {
236 int count; /**< Number of buffers of this size */
237 int size; /**< Size in bytes */
238 int low_mark; /**< Low water mark */
239 int high_mark; /**< High water mark */
240 } drmBufDesc, *drmBufDescPtr;
242 typedef struct _drmBufInfo {
243 int count; /**< Number of buffers described in list */
244 drmBufDescPtr list; /**< List of buffer descriptions */
245 } drmBufInfo, *drmBufInfoPtr;
247 typedef struct _drmBuf {
248 int idx; /**< Index into the master buffer list */
249 int total; /**< Buffer size */
250 int used; /**< Amount of buffer in use (for DMA) */
251 drmAddress address; /**< Address */
252 } drmBuf, *drmBufPtr;
255 * Buffer mapping information.
257 * Used by drmMapBufs() and drmUnmapBufs() to store information about the
260 typedef struct _drmBufMap {
261 int count; /**< Number of buffers mapped */
262 drmBufPtr list; /**< Buffers */
263 } drmBufMap, *drmBufMapPtr;
265 typedef struct _drmLock {
266 volatile unsigned int lock;
268 /* This is big enough for most current (and future?) architectures:
271 Intel P5/PPro/PII/PIII: 32 bytes
272 Intel StrongARM: 32 bytes
273 Intel i386/i486: 16 bytes
275 Motorola 68k: 16 bytes
276 Motorola PowerPC: 32 bytes
279 } drmLock, *drmLockPtr;
282 * Indices here refer to the offset into
285 typedef struct _drmDMAReq {
286 drm_context_t context; /**< Context handle */
287 int send_count; /**< Number of buffers to send */
288 int *send_list; /**< List of handles to buffers */
289 int *send_sizes; /**< Lengths of data to send, in bytes */
290 drmDMAFlags flags; /**< Flags */
291 int request_count; /**< Number of buffers requested */
292 int request_size; /**< Desired size of buffers requested */
293 int *request_list; /**< Buffer information */
294 int *request_sizes; /**< Minimum acceptable sizes */
295 int granted_count; /**< Number of buffers granted at this size */
296 } drmDMAReq, *drmDMAReqPtr;
298 typedef struct _drmRegion {
303 } drmRegion, *drmRegionPtr;
305 typedef struct _drmTextureRegion {
308 unsigned char in_use;
309 unsigned char padding; /**< Explicitly pad this out */
311 } drmTextureRegion, *drmTextureRegionPtr;
315 DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */
316 DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */
317 /* bits 1-6 are reserved for high crtcs */
318 DRM_VBLANK_HIGH_CRTC_MASK = 0x0000003e,
319 DRM_VBLANK_EVENT = 0x4000000, /**< Send event instead of blocking */
320 DRM_VBLANK_FLIP = 0x8000000, /**< Scheduled buffer swap should flip */
321 DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */
322 DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */
323 DRM_VBLANK_SIGNAL = 0x40000000 /* Send signal instead of blocking */
325 #define DRM_VBLANK_HIGH_CRTC_SHIFT 1
327 typedef struct _drmVBlankReq {
328 drmVBlankSeqType type;
329 unsigned int sequence;
330 unsigned long signal;
331 } drmVBlankReq, *drmVBlankReqPtr;
333 typedef struct _drmVBlankReply {
334 drmVBlankSeqType type;
335 unsigned int sequence;
338 } drmVBlankReply, *drmVBlankReplyPtr;
340 typedef union _drmVBlank {
341 drmVBlankReq request;
342 drmVBlankReply reply;
343 } drmVBlank, *drmVBlankPtr;
345 typedef struct _drmSetVersion {
350 } drmSetVersion, *drmSetVersionPtr;
352 #define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
354 #define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
355 #define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
357 #if defined(__GNUC__) && (__GNUC__ >= 2)
358 # if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
359 /* Reflect changes here to drmP.h */
360 #define DRM_CAS(lock,old,new,__ret) \
362 int __dummy; /* Can't mark eax as clobbered */ \
363 __asm__ __volatile__( \
364 "lock ; cmpxchg %4,%1\n\t" \
367 "=m" (__drm_dummy_lock(lock)), \
373 #elif defined(__alpha__)
375 #define DRM_CAS(lock, old, new, ret) \
378 __asm__ __volatile__( \
379 " addl $31, %5, %3\n" \
380 "1: ldl_l %0, %2\n" \
381 " cmpeq %0, %3, %1\n" \
387 "2: cmpeq %1, 0, %1\n" \
391 : "=&r"(tmp), "=&r"(ret), \
392 "=m"(__drm_dummy_lock(lock)), \
394 : "r"(new), "r"(old) \
398 #elif defined(__sparc__)
400 #define DRM_CAS(lock,old,new,__ret) \
401 do { register unsigned int __old __asm("o0"); \
402 register unsigned int __new __asm("o1"); \
403 register volatile unsigned int *__lock __asm("o2"); \
406 __lock = (volatile unsigned int *)lock; \
407 __asm__ __volatile__( \
408 /*"cas [%2], %3, %0"*/ \
409 ".word 0xd3e29008\n\t" \
410 /*"membar #StoreStore | #StoreLoad"*/ \
417 __ret = (__new != __old); \
420 #elif defined(__ia64__)
422 #ifdef __INTEL_COMPILER
423 /* this currently generates bad code (missing stop bits)... */
424 #include <ia64intrin.h>
426 #define DRM_CAS(lock,old,new,__ret) \
428 unsigned long __result, __old = (old) & 0xffffffff; \
430 __result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\
431 __ret = (__result) != (__old); \
432 /* __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
438 #define DRM_CAS(lock,old,new,__ret) \
440 unsigned int __result, __old = (old); \
441 __asm__ __volatile__( \
445 "cmpxchg4.acq %0=%1,%3,ar.ccv" \
446 : "=r" (__result), "=m" (__drm_dummy_lock(lock)) \
447 : "r" ((unsigned long)__old), "r" (new) \
449 __ret = (__result) != (__old); \
454 #elif defined(__powerpc__)
456 #define DRM_CAS(lock,old,new,__ret) \
458 __asm__ __volatile__( \
460 "0: lwarx %0,0,%1;" \
468 : "r"(lock), "r"(new), "r"(old) \
469 : "cr0", "memory"); \
472 #endif /* architecture */
473 #endif /* __GNUC__ >= 2 */
476 #define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
479 #if defined(__alpha__)
480 #define DRM_CAS_RESULT(_result) long _result
481 #elif defined(__powerpc__)
482 #define DRM_CAS_RESULT(_result) int _result
484 #define DRM_CAS_RESULT(_result) char _result
487 #define DRM_LIGHT_LOCK(fd,lock,context) \
489 DRM_CAS_RESULT(__ret); \
490 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
491 if (__ret) drmGetLock(fd,context,0); \
494 /* This one counts fast locks -- for
495 benchmarking only. */
496 #define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \
498 DRM_CAS_RESULT(__ret); \
499 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
500 if (__ret) drmGetLock(fd,context,0); \
504 #define DRM_LOCK(fd,lock,context,flags) \
506 if (flags) drmGetLock(fd,context,flags); \
507 else DRM_LIGHT_LOCK(fd,lock,context); \
510 #define DRM_UNLOCK(fd,lock,context) \
512 DRM_CAS_RESULT(__ret); \
513 DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \
514 if (__ret) drmUnlock(fd,context); \
517 /* Simple spin locks */
518 #define DRM_SPINLOCK(spin,val) \
520 DRM_CAS_RESULT(__ret); \
522 DRM_CAS(spin,0,val,__ret); \
523 if (__ret) while ((spin)->lock); \
527 #define DRM_SPINLOCK_TAKE(spin,val) \
529 DRM_CAS_RESULT(__ret); \
532 cur = (*spin).lock; \
533 DRM_CAS(spin,cur,val,__ret); \
537 #define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \
541 for (__i = 0; __ret && __i < count; __i++) { \
542 DRM_CAS(spin,0,val,__ret); \
543 if (__ret) for (;__i < count && (spin)->lock; __i++); \
547 #define DRM_SPINUNLOCK(spin,val) \
549 DRM_CAS_RESULT(__ret); \
550 if ((*spin).lock == val) { /* else server stole lock */ \
552 DRM_CAS(spin,val,0,__ret); \
559 /* General user-level programmer's API: unprivileged */
560 extern int drmAvailable(void);
561 extern int drmOpen(const char *name, const char *busid);
563 #define DRM_NODE_PRIMARY 0
564 #define DRM_NODE_CONTROL 1
565 #define DRM_NODE_RENDER 2
566 #define DRM_NODE_MAX 3
568 extern int drmOpenWithType(const char *name, const char *busid,
571 extern int drmOpenControl(int minor);
572 extern int drmOpenRender(int minor);
573 extern int drmClose(int fd);
574 extern drmVersionPtr drmGetVersion(int fd);
575 extern drmVersionPtr drmGetLibVersion(int fd);
576 extern int drmGetCap(int fd, uint64_t capability, uint64_t *value);
577 extern void drmFreeVersion(drmVersionPtr);
578 extern int drmGetMagic(int fd, drm_magic_t * magic);
579 extern char *drmGetBusid(int fd);
580 extern int drmGetInterruptFromBusID(int fd, int busnum, int devnum,
582 extern int drmGetMap(int fd, int idx, drm_handle_t *offset,
583 drmSize *size, drmMapType *type,
584 drmMapFlags *flags, drm_handle_t *handle,
586 extern int drmGetClient(int fd, int idx, int *auth, int *pid,
587 int *uid, unsigned long *magic,
588 unsigned long *iocs);
589 extern int drmGetStats(int fd, drmStatsT *stats);
590 extern int drmSetInterfaceVersion(int fd, drmSetVersion *version);
591 extern int drmCommandNone(int fd, unsigned long drmCommandIndex);
592 extern int drmCommandRead(int fd, unsigned long drmCommandIndex,
593 void *data, unsigned long size);
594 extern int drmCommandWrite(int fd, unsigned long drmCommandIndex,
595 void *data, unsigned long size);
596 extern int drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
597 void *data, unsigned long size);
599 /* General user-level programmer's API: X server (root) only */
600 extern void drmFreeBusid(const char *busid);
601 extern int drmSetBusid(int fd, const char *busid);
602 extern int drmAuthMagic(int fd, drm_magic_t magic);
603 extern int drmAddMap(int fd,
608 drm_handle_t * handle);
609 extern int drmRmMap(int fd, drm_handle_t handle);
610 extern int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
611 drm_handle_t handle);
613 extern int drmAddBufs(int fd, int count, int size,
614 drmBufDescFlags flags,
616 extern int drmMarkBufs(int fd, double low, double high);
617 extern int drmCreateContext(int fd, drm_context_t * handle);
618 extern int drmSetContextFlags(int fd, drm_context_t context,
619 drm_context_tFlags flags);
620 extern int drmGetContextFlags(int fd, drm_context_t context,
621 drm_context_tFlagsPtr flags);
622 extern int drmAddContextTag(int fd, drm_context_t context, void *tag);
623 extern int drmDelContextTag(int fd, drm_context_t context);
624 extern void *drmGetContextTag(int fd, drm_context_t context);
625 extern drm_context_t * drmGetReservedContextList(int fd, int *count);
626 extern void drmFreeReservedContextList(drm_context_t *);
627 extern int drmSwitchToContext(int fd, drm_context_t context);
628 extern int drmDestroyContext(int fd, drm_context_t handle);
629 extern int drmCreateDrawable(int fd, drm_drawable_t * handle);
630 extern int drmDestroyDrawable(int fd, drm_drawable_t handle);
631 extern int drmUpdateDrawableInfo(int fd, drm_drawable_t handle,
632 drm_drawable_info_type_t type,
633 unsigned int num, void *data);
634 extern int drmCtlInstHandler(int fd, int irq);
635 extern int drmCtlUninstHandler(int fd);
636 extern int drmSetClientCap(int fd, uint64_t capability,
639 /* General user-level programmer's API: authenticated client and/or X */
640 extern int drmMap(int fd,
643 drmAddressPtr address);
644 extern int drmUnmap(drmAddress address, drmSize size);
645 extern drmBufInfoPtr drmGetBufInfo(int fd);
646 extern drmBufMapPtr drmMapBufs(int fd);
647 extern int drmUnmapBufs(drmBufMapPtr bufs);
648 extern int drmDMA(int fd, drmDMAReqPtr request);
649 extern int drmFreeBufs(int fd, int count, int *list);
650 extern int drmGetLock(int fd,
651 drm_context_t context,
653 extern int drmUnlock(int fd, drm_context_t context);
654 extern int drmFinish(int fd, int context, drmLockFlags flags);
655 extern int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id,
656 drm_handle_t * handle);
658 /* AGP/GART support: X server (root) only */
659 extern int drmAgpAcquire(int fd);
660 extern int drmAgpRelease(int fd);
661 extern int drmAgpEnable(int fd, unsigned long mode);
662 extern int drmAgpAlloc(int fd, unsigned long size,
663 unsigned long type, unsigned long *address,
664 drm_handle_t *handle);
665 extern int drmAgpFree(int fd, drm_handle_t handle);
666 extern int drmAgpBind(int fd, drm_handle_t handle,
667 unsigned long offset);
668 extern int drmAgpUnbind(int fd, drm_handle_t handle);
670 /* AGP/GART info: authenticated client and/or X */
671 extern int drmAgpVersionMajor(int fd);
672 extern int drmAgpVersionMinor(int fd);
673 extern unsigned long drmAgpGetMode(int fd);
674 extern unsigned long drmAgpBase(int fd); /* Physical location */
675 extern unsigned long drmAgpSize(int fd); /* Bytes */
676 extern unsigned long drmAgpMemoryUsed(int fd);
677 extern unsigned long drmAgpMemoryAvail(int fd);
678 extern unsigned int drmAgpVendorId(int fd);
679 extern unsigned int drmAgpDeviceId(int fd);
681 /* PCI scatter/gather support: X server (root) only */
682 extern int drmScatterGatherAlloc(int fd, unsigned long size,
683 drm_handle_t *handle);
684 extern int drmScatterGatherFree(int fd, drm_handle_t handle);
686 extern int drmWaitVBlank(int fd, drmVBlankPtr vbl);
688 /* Support routines */
689 extern void drmSetServerInfo(drmServerInfoPtr info);
690 extern int drmError(int err, const char *label);
691 extern void *drmMalloc(int size);
692 extern void drmFree(void *pt);
694 /* Hash table routines */
695 extern void *drmHashCreate(void);
696 extern int drmHashDestroy(void *t);
697 extern int drmHashLookup(void *t, unsigned long key, void **value);
698 extern int drmHashInsert(void *t, unsigned long key, void *value);
699 extern int drmHashDelete(void *t, unsigned long key);
700 extern int drmHashFirst(void *t, unsigned long *key, void **value);
701 extern int drmHashNext(void *t, unsigned long *key, void **value);
704 extern void *drmRandomCreate(unsigned long seed);
705 extern int drmRandomDestroy(void *state);
706 extern unsigned long drmRandom(void *state);
707 extern double drmRandomDouble(void *state);
709 /* Skip list routines */
711 extern void *drmSLCreate(void);
712 extern int drmSLDestroy(void *l);
713 extern int drmSLLookup(void *l, unsigned long key, void **value);
714 extern int drmSLInsert(void *l, unsigned long key, void *value);
715 extern int drmSLDelete(void *l, unsigned long key);
716 extern int drmSLNext(void *l, unsigned long *key, void **value);
717 extern int drmSLFirst(void *l, unsigned long *key, void **value);
718 extern void drmSLDump(void *l);
719 extern int drmSLLookupNeighbors(void *l, unsigned long key,
720 unsigned long *prev_key, void **prev_value,
721 unsigned long *next_key, void **next_value);
723 extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
724 extern int drmOpenOnceWithType(const char *BusID, int *newlyopened, int type);
725 extern void drmCloseOnce(int fd);
726 extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
728 extern int drmSetMaster(int fd);
729 extern int drmDropMaster(int fd);
731 #define DRM_EVENT_CONTEXT_VERSION 3
733 typedef struct _drmEventContext {
735 /* This struct is versioned so we can add more pointers if we
736 * add more events. */
739 void (*vblank_handler)(int fd,
740 unsigned int sequence,
742 unsigned int tv_usec,
745 void (*page_flip_handler)(int fd,
746 unsigned int sequence,
748 unsigned int tv_usec,
751 void (*page_flip_handler2)(int fd,
752 unsigned int sequence,
754 unsigned int tv_usec,
755 unsigned int crtc_id,
758 } drmEventContext, *drmEventContextPtr;
760 extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
762 extern char *drmGetDeviceNameFromFd(int fd);
764 /* Improved version of drmGetDeviceNameFromFd which attributes for any type of
765 * device/node - card, control or renderD.
767 extern char *drmGetDeviceNameFromFd2(int fd);
768 extern int drmGetNodeTypeFromFd(int fd);
770 extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd);
771 extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle);
773 extern char *drmGetPrimaryDeviceNameFromFd(int fd);
774 extern char *drmGetRenderDeviceNameFromFd(int fd);
776 #define DRM_BUS_PCI 0
777 #define DRM_BUS_USB 1
778 #define DRM_BUS_PLATFORM 2
779 #define DRM_BUS_HOST1X 3
781 typedef struct _drmPciBusInfo {
786 } drmPciBusInfo, *drmPciBusInfoPtr;
788 typedef struct _drmPciDeviceInfo {
791 uint16_t subvendor_id;
792 uint16_t subdevice_id;
794 } drmPciDeviceInfo, *drmPciDeviceInfoPtr;
796 typedef struct _drmUsbBusInfo {
799 } drmUsbBusInfo, *drmUsbBusInfoPtr;
801 typedef struct _drmUsbDeviceInfo {
804 } drmUsbDeviceInfo, *drmUsbDeviceInfoPtr;
806 #define DRM_PLATFORM_DEVICE_NAME_LEN 512
808 typedef struct _drmPlatformBusInfo {
809 char fullname[DRM_PLATFORM_DEVICE_NAME_LEN];
810 } drmPlatformBusInfo, *drmPlatformBusInfoPtr;
812 typedef struct _drmPlatformDeviceInfo {
813 char **compatible; /* NULL terminated list of compatible strings */
814 } drmPlatformDeviceInfo, *drmPlatformDeviceInfoPtr;
816 #define DRM_HOST1X_DEVICE_NAME_LEN 512
818 typedef struct _drmHost1xBusInfo {
819 char fullname[DRM_HOST1X_DEVICE_NAME_LEN];
820 } drmHost1xBusInfo, *drmHost1xBusInfoPtr;
822 typedef struct _drmHost1xDeviceInfo {
823 char **compatible; /* NULL terminated list of compatible strings */
824 } drmHost1xDeviceInfo, *drmHost1xDeviceInfoPtr;
826 typedef struct _drmDevice {
827 char **nodes; /* DRM_NODE_MAX sized array */
828 int available_nodes; /* DRM_NODE_* bitmask */
831 drmPciBusInfoPtr pci;
832 drmUsbBusInfoPtr usb;
833 drmPlatformBusInfoPtr platform;
834 drmHost1xBusInfoPtr host1x;
837 drmPciDeviceInfoPtr pci;
838 drmUsbDeviceInfoPtr usb;
839 drmPlatformDeviceInfoPtr platform;
840 drmHost1xDeviceInfoPtr host1x;
842 } drmDevice, *drmDevicePtr;
844 extern int drmGetDevice(int fd, drmDevicePtr *device);
845 extern void drmFreeDevice(drmDevicePtr *device);
847 extern int drmGetDevices(drmDevicePtr devices[], int max_devices);
848 extern void drmFreeDevices(drmDevicePtr devices[], int count);
850 #define DRM_DEVICE_GET_PCI_REVISION (1 << 0)
851 extern int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device);
852 extern int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices);
854 extern int drmDevicesEqual(drmDevicePtr a, drmDevicePtr b);
856 extern int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle);
857 extern int drmSyncobjDestroy(int fd, uint32_t handle);
858 extern int drmSyncobjHandleToFD(int fd, uint32_t handle, int *obj_fd);
859 extern int drmSyncobjFDToHandle(int fd, int obj_fd, uint32_t *handle);
861 extern int drmSyncobjImportSyncFile(int fd, uint32_t handle, int sync_file_fd);
862 extern int drmSyncobjExportSyncFile(int fd, uint32_t handle, int *sync_file_fd);
863 extern int drmSyncobjWait(int fd, uint32_t *handles, unsigned num_handles,
864 int64_t timeout_nsec, unsigned flags,
865 uint32_t *first_signaled);
866 extern int drmSyncobjReset(int fd, const uint32_t *handles, uint32_t handle_count);
867 extern int drmSyncobjSignal(int fd, const uint32_t *handles, uint32_t handle_count);
869 #if defined(__cplusplus)