1 /* xf86drm.h -- OS-independent header for DRM user-level library interface
2 * Created: Tue Jan 5 08:17:23 1999 by faith@precisioninsight.com
4 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
27 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
29 * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/xf86drm.h,v 1.22 2003/06/12 14:12:35 eich Exp $
36 /* Defaults, if nothing set in xf86config */
39 /* Default /dev/dri directory permissions 0755 */
40 #define DRM_DEV_DIRMODE \
41 (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
42 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
44 #define DRM_DIR_NAME "/dev/dri"
45 #define DRM_DEV_NAME "%s/card%d"
46 #define DRM_PROC_NAME "/proc/dri/" /* For backware Linux compatibility */
48 #define DRM_ERR_NO_DEVICE (-1001)
49 #define DRM_ERR_NO_ACCESS (-1002)
50 #define DRM_ERR_NOT_ROOT (-1003)
51 #define DRM_ERR_INVALID (-1004)
52 #define DRM_ERR_NO_FD (-1005)
54 #define DRM_AGP_NO_HANDLE 0
56 typedef unsigned long drmHandle
, *drmHandlePtr
; /* To mapped regions */
57 typedef unsigned int drmSize
, *drmSizePtr
; /* For mapped regions */
58 typedef void *drmAddress
, **drmAddressPtr
; /* For mapped regions */
59 typedef unsigned int drmContext
, *drmContextPtr
; /* GLXContext handle */
60 typedef unsigned int drmDrawable
, *drmDrawablePtr
; /* Unused */
61 typedef unsigned int drmMagic
, *drmMagicPtr
; /* Magic for auth */
63 typedef struct _drmVersion
{
64 int version_major
; /* Major version */
65 int version_minor
; /* Minor version */
66 int version_patchlevel
; /* Patch level */
67 int name_len
; /* Length of name buffer */
68 char *name
; /* Name of driver */
69 int date_len
; /* Length of date buffer */
70 char *date
; /* User-space buffer to hold date */
71 int desc_len
; /* Length of desc buffer */
72 char *desc
; /* User-space buffer to hold desc */
73 } drmVersion
, *drmVersionPtr
;
75 typedef struct _drmStats
{
76 unsigned long count
; /* Number of data */
78 unsigned long value
; /* Value from kernel */
79 const char *long_format
; /* Suggested format for long_name */
80 const char *long_name
; /* Long name for value */
81 const char *rate_format
; /* Suggested format for rate_name */
82 const char *rate_name
; /* Short name for value per second */
83 int isvalue
; /* True if value (vs. counter) */
84 const char *mult_names
; /* Multiplier names (e.g., "KGM") */
85 int mult
; /* Multiplier value (e.g., 1024) */
86 int verbose
; /* Suggest only in verbose output */
91 /* All of these enums *MUST* match with the
92 kernel implementation -- so do *NOT*
93 change them! (The drmlib implementation
94 will just copy the flags instead of
97 DRM_FRAME_BUFFER
= 0, /* WC, no caching, no core dump */
98 DRM_REGISTERS
= 1, /* no caching, no core dump */
99 DRM_SHM
= 2, /* shared, cached */
100 DRM_AGP
= 3, /* AGP/GART */
101 DRM_SCATTER_GATHER
= 4 /* PCI scatter/gather */
105 DRM_RESTRICTED
= 0x0001, /* Cannot be mapped to client-virtual */
106 DRM_READ_ONLY
= 0x0002, /* Read-only in client-virtual */
107 DRM_LOCKED
= 0x0004, /* Physical pages locked */
108 DRM_KERNEL
= 0x0008, /* Kernel requires access */
109 DRM_WRITE_COMBINING
= 0x0010, /* Use write-combining, if available */
110 DRM_CONTAINS_LOCK
= 0x0020, /* SHM page that contains lock */
111 DRM_REMOVABLE
= 0x0040 /* Removable mapping */
114 typedef enum { /* These values *MUST* match drm.h */
115 /* Flags for DMA buffer dispatch */
116 DRM_DMA_BLOCK
= 0x01, /* Block until buffer dispatched. Note,
117 the buffer may not yet have been
118 processed by the hardware -- getting a
119 hardware lock with the hardware
120 quiescent will ensure that the buffer
121 has been processed. */
122 DRM_DMA_WHILE_LOCKED
= 0x02, /* Dispatch while lock held */
123 DRM_DMA_PRIORITY
= 0x04, /* High priority dispatch */
125 /* Flags for DMA buffer request */
126 DRM_DMA_WAIT
= 0x10, /* Wait for free buffers */
127 DRM_DMA_SMALLER_OK
= 0x20, /* Smaller-than-requested buffers ok */
128 DRM_DMA_LARGER_OK
= 0x40 /* Larger-than-requested buffers ok */
132 DRM_PAGE_ALIGN
= 0x01,
133 DRM_AGP_BUFFER
= 0x02,
138 DRM_LOCK_READY
= 0x01, /* Wait until hardware is ready for DMA */
139 DRM_LOCK_QUIESCENT
= 0x02, /* Wait until hardware quiescent */
140 DRM_LOCK_FLUSH
= 0x04, /* Flush this context's DMA queue first */
141 DRM_LOCK_FLUSH_ALL
= 0x08, /* Flush all DMA queues first */
142 /* These *HALT* flags aren't supported yet
143 -- they will be used to support the
144 full-screen DGA-like mode. */
145 DRM_HALT_ALL_QUEUES
= 0x10, /* Halt all current and future queues */
146 DRM_HALT_CUR_QUEUES
= 0x20 /* Halt all current queues */
150 DRM_CONTEXT_PRESERVED
= 0x01, /* This context is preserved and
152 DRM_CONTEXT_2DONLY
= 0x02 /* This context is for 2D rendering only. */
153 } drmContextFlags
, *drmContextFlagsPtr
;
155 typedef struct _drmBufDesc
{
156 int count
; /* Number of buffers of this size */
157 int size
; /* Size in bytes */
158 int low_mark
; /* Low water mark */
159 int high_mark
; /* High water mark */
160 } drmBufDesc
, *drmBufDescPtr
;
162 typedef struct _drmBufInfo
{
163 int count
; /* Number of buffers described in list */
164 drmBufDescPtr list
; /* List of buffer descriptions */
165 } drmBufInfo
, *drmBufInfoPtr
;
167 typedef struct _drmBuf
{
168 int idx
; /* Index into master buflist */
169 int total
; /* Buffer size */
170 int used
; /* Amount of buffer in use (for DMA) */
171 drmAddress address
; /* Address */
172 } drmBuf
, *drmBufPtr
;
174 typedef struct _drmBufMap
{
175 int count
; /* Number of buffers mapped */
176 drmBufPtr list
; /* Buffers */
177 } drmBufMap
, *drmBufMapPtr
;
179 typedef struct _drmLock
{
180 volatile unsigned int lock
;
182 /* This is big enough for most current (and future?) architectures:
185 Intel P5/PPro/PII/PIII: 32 bytes
186 Intel StrongARM: 32 bytes
187 Intel i386/i486: 16 bytes
189 Motorola 68k: 16 bytes
190 Motorola PowerPC: 32 bytes
193 } drmLock
, *drmLockPtr
;
195 typedef struct _drmDMAReq
{
196 /* Indices here refer to the offset into
197 list in drmBufInfo */
198 drmContext context
; /* Context handle */
199 int send_count
; /* Number of buffers to send */
200 int *send_list
; /* List of handles to buffers */
201 int *send_sizes
; /* Lengths of data to send, in bytes */
202 drmDMAFlags flags
; /* Flags */
203 int request_count
; /* Number of buffers requested */
204 int request_size
; /* Desired size of buffers requested */
205 int *request_list
; /* Buffer information */
206 int *request_sizes
; /* Minimum acceptable sizes */
207 int granted_count
; /* Number of buffers granted at this size */
208 } drmDMAReq
, *drmDMAReqPtr
;
210 typedef struct _drmRegion
{
215 } drmRegion
, *drmRegionPtr
;
217 typedef struct _drmTextureRegion
{
220 unsigned char in_use
;
221 unsigned char padding
; /* Explicitly pad this out */
223 } drmTextureRegion
, *drmTextureRegionPtr
;
226 typedef struct _drmClipRect
{
227 unsigned short x1
; /* Upper left: inclusive */
229 unsigned short x2
; /* Lower right: exclusive */
231 } drmClipRect
, *drmClipRectPtr
;
235 DRM_VBLANK_ABSOLUTE
= 0x0, /* Wait for specific vblank sequence number */
236 DRM_VBLANK_RELATIVE
= 0x1, /* Wait for given number of vblanks */
237 DRM_VBLANK_SIGNAL
= 0x40000000 /* Send signal instead of blocking */
240 typedef struct _drmVBlankReq
{
241 drmVBlankSeqType type
;
242 unsigned int sequence
;
243 unsigned long signal
;
244 } drmVBlankReq
, *drmVBlankReqPtr
;
246 typedef struct _drmVBlankReply
{
247 drmVBlankSeqType type
;
248 unsigned int sequence
;
251 } drmVBlankReply
, *drmVBlankReplyPtr
;
253 typedef union _drmVBlank
{
254 drmVBlankReq request
;
255 drmVBlankReply reply
;
256 } drmVBlank
, *drmVBlankPtr
;
260 #define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
262 #define DRM_LOCK_HELD 0x80000000 /* Hardware lock is held */
263 #define DRM_LOCK_CONT 0x40000000 /* Hardware lock is contended */
265 #if defined(__GNUC__) && (__GNUC__ >= 2)
266 # if defined(__i386) || defined(__AMD64__)
267 /* Reflect changes here to drmP.h */
268 #define DRM_CAS(lock,old,new,__ret) \
270 int __dummy; /* Can't mark eax as clobbered */ \
271 __asm__ __volatile__( \
272 "lock ; cmpxchg %4,%1\n\t" \
275 "=m" (__drm_dummy_lock(lock)), \
281 #elif defined(__alpha__)
283 #define DRM_CAS(lock, old, new, ret) \
287 __asm__ __volatile__( \
289 " zap %4, 0xF0, %0\n" \
291 " zap %1, 0xF0, %1\n" \
292 " cmpeq %0, %1, %1\n" \
294 " bis %5, %5, %1\n" \
296 "1: xor %1, 1, %1\n" \
300 "=m" (__drm_dummy_lock(lock)),\
306 #elif defined(__sparc__)
308 #define DRM_CAS(lock,old,new,__ret) \
309 do { register unsigned int __old __asm("o0"); \
310 register unsigned int __new __asm("o1"); \
311 register volatile unsigned int *__lock __asm("o2"); \
314 __lock = (volatile unsigned int *)lock; \
315 __asm__ __volatile__( \
316 /*"cas [%2], %3, %0"*/ \
317 ".word 0xd3e29008\n\t" \
318 /*"membar #StoreStore | #StoreLoad"*/ \
325 __ret = (__new != __old); \
328 #elif defined(__ia64__)
331 /* this currently generates bad code (missing stop bits)... */
332 #include <ia64intrin.h>
334 #define DRM_CAS(lock,old,new,__ret) \
336 __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
342 #define DRM_CAS(lock,old,new,__ret) \
344 unsigned int __result, __old = (old); \
345 __asm__ __volatile__( \
349 "cmpxchg4.acq %0=%1,%3,ar.ccv" \
350 : "=r" (__result), "=m" (__drm_dummy_lock(lock)) \
351 : "r" (__old), "r" (new) \
353 __ret = (__result) != (__old); \
358 #elif defined(__powerpc__)
360 #define DRM_CAS(lock,old,new,__ret) \
362 __asm__ __volatile__( \
364 "0: lwarx %0,0,%1;" \
372 : "r"(lock), "r"(new), "r"(old) \
373 : "cr0", "memory"); \
376 #endif /* architecture */
377 #endif /* __GNUC__ >= 2 */
380 #define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
383 #if defined(__alpha__) || defined(__powerpc__)
384 #define DRM_CAS_RESULT(_result) int _result
386 #define DRM_CAS_RESULT(_result) char _result
389 #define DRM_LIGHT_LOCK(fd,lock,context) \
391 DRM_CAS_RESULT(__ret); \
392 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
393 if (__ret) drmGetLock(fd,context,0); \
396 /* This one counts fast locks -- for
397 benchmarking only. */
398 #define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \
400 DRM_CAS_RESULT(__ret); \
401 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
402 if (__ret) drmGetLock(fd,context,0); \
406 #define DRM_LOCK(fd,lock,context,flags) \
408 if (flags) drmGetLock(fd,context,flags); \
409 else DRM_LIGHT_LOCK(fd,lock,context); \
412 #define DRM_UNLOCK(fd,lock,context) \
414 DRM_CAS_RESULT(__ret); \
415 DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \
416 if (__ret) drmUnlock(fd,context); \
419 /* Simple spin locks */
420 #define DRM_SPINLOCK(spin,val) \
422 DRM_CAS_RESULT(__ret); \
424 DRM_CAS(spin,0,val,__ret); \
425 if (__ret) while ((spin)->lock); \
429 #define DRM_SPINLOCK_TAKE(spin,val) \
431 DRM_CAS_RESULT(__ret); \
434 cur = (*spin).lock; \
435 DRM_CAS(spin,cur,val,__ret); \
439 #define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \
443 for (__i = 0; __ret && __i < count; __i++) { \
444 DRM_CAS(spin,0,val,__ret); \
445 if (__ret) for (;__i < count && (spin)->lock; __i++); \
449 #define DRM_SPINUNLOCK(spin,val) \
451 DRM_CAS_RESULT(__ret); \
452 if ((*spin).lock == val) { /* else server stole lock */ \
454 DRM_CAS(spin,val,0,__ret); \
459 /* General user-level programmer's API: unprivileged */
460 extern int drmAvailable(void);
461 extern int drmOpen(const char *name
, const char *busid
);
462 extern int drmClose(int fd
);
463 extern drmVersionPtr
drmGetVersion(int fd
);
464 extern drmVersionPtr
drmGetLibVersion(int fd
);
465 extern void drmFreeVersion(drmVersionPtr
);
466 extern int drmGetMagic(int fd
, drmMagicPtr magic
);
467 extern char *drmGetBusid(int fd
);
468 extern int drmGetInterruptFromBusID(int fd
, int busnum
, int devnum
,
470 extern int drmGetMap(int fd
, int idx
, drmHandle
*offset
,
471 drmSize
*size
, drmMapType
*type
,
472 drmMapFlags
*flags
, drmHandle
*handle
,
474 extern int drmGetClient(int fd
, int idx
, int *auth
, int *pid
,
475 int *uid
, unsigned long *magic
,
476 unsigned long *iocs
);
477 extern int drmGetStats(int fd
, drmStatsT
*stats
);
478 extern int drmCommandNone(int fd
, unsigned long drmCommandIndex
);
479 extern int drmCommandRead(int fd
, unsigned long drmCommandIndex
,
480 void *data
, unsigned long size
);
481 extern int drmCommandWrite(int fd
, unsigned long drmCommandIndex
,
482 void *data
, unsigned long size
);
483 extern int drmCommandWriteRead(int fd
, unsigned long drmCommandIndex
,
484 void *data
, unsigned long size
);
486 /* General user-level programmer's API: X server (root) only */
487 extern void drmFreeBusid(const char *busid
);
488 extern int drmSetBusid(int fd
, const char *busid
);
489 extern int drmAuthMagic(int fd
, drmMagic magic
);
490 extern int drmAddMap(int fd
,
495 drmHandlePtr handle
);
496 extern int drmRmMap(int fd
, drmHandle handle
);
497 extern int drmAddContextPrivateMapping(int fd
, drmContext ctx_id
,
500 extern int drmAddBufs(int fd
, int count
, int size
,
501 drmBufDescFlags flags
,
503 extern int drmMarkBufs(int fd
, double low
, double high
);
504 extern int drmCreateContext(int fd
, drmContextPtr handle
);
505 extern int drmSetContextFlags(int fd
, drmContext context
,
506 drmContextFlags flags
);
507 extern int drmGetContextFlags(int fd
, drmContext context
,
508 drmContextFlagsPtr flags
);
509 extern int drmAddContextTag(int fd
, drmContext context
, void *tag
);
510 extern int drmDelContextTag(int fd
, drmContext context
);
511 extern void *drmGetContextTag(int fd
, drmContext context
);
512 extern drmContextPtr
drmGetReservedContextList(int fd
, int *count
);
513 extern void drmFreeReservedContextList(drmContextPtr
);
514 extern int drmSwitchToContext(int fd
, drmContext context
);
515 extern int drmDestroyContext(int fd
, drmContext handle
);
516 extern int drmCreateDrawable(int fd
, drmDrawablePtr handle
);
517 extern int drmDestroyDrawable(int fd
, drmDrawable handle
);
518 extern int drmCtlInstHandler(int fd
, int irq
);
519 extern int drmCtlUninstHandler(int fd
);
520 extern int drmInstallSIGIOHandler(int fd
,
524 extern int drmRemoveSIGIOHandler(int fd
);
526 /* General user-level programmer's API: authenticated client and/or X */
527 extern int drmMap(int fd
,
530 drmAddressPtr address
);
531 extern int drmUnmap(drmAddress address
, drmSize size
);
532 extern drmBufInfoPtr
drmGetBufInfo(int fd
);
533 extern drmBufMapPtr
drmMapBufs(int fd
);
534 extern int drmUnmapBufs(drmBufMapPtr bufs
);
535 extern int drmDMA(int fd
, drmDMAReqPtr request
);
536 extern int drmFreeBufs(int fd
, int count
, int *list
);
537 extern int drmGetLock(int fd
,
540 extern int drmUnlock(int fd
, drmContext context
);
541 extern int drmFinish(int fd
, int context
, drmLockFlags flags
);
542 extern int drmGetContextPrivateMapping(int fd
, drmContext ctx_id
,
543 drmHandlePtr handle
);
545 /* AGP/GART support: X server (root) only */
546 extern int drmAgpAcquire(int fd
);
547 extern int drmAgpRelease(int fd
);
548 extern int drmAgpEnable(int fd
, unsigned long mode
);
549 extern int drmAgpAlloc(int fd
, unsigned long size
,
550 unsigned long type
, unsigned long *address
,
551 unsigned long *handle
);
552 extern int drmAgpFree(int fd
, unsigned long handle
);
553 extern int drmAgpBind(int fd
, unsigned long handle
,
554 unsigned long offset
);
555 extern int drmAgpUnbind(int fd
, unsigned long handle
);
557 /* AGP/GART info: authenticated client and/or X */
558 extern int drmAgpVersionMajor(int fd
);
559 extern int drmAgpVersionMinor(int fd
);
560 extern unsigned long drmAgpGetMode(int fd
);
561 extern unsigned long drmAgpBase(int fd
); /* Physical location */
562 extern unsigned long drmAgpSize(int fd
); /* Bytes */
563 extern unsigned long drmAgpMemoryUsed(int fd
);
564 extern unsigned long drmAgpMemoryAvail(int fd
);
565 extern unsigned int drmAgpVendorId(int fd
);
566 extern unsigned int drmAgpDeviceId(int fd
);
568 /* PCI scatter/gather support: X server (root) only */
569 extern int drmScatterGatherAlloc(int fd
, unsigned long size
,
570 unsigned long *handle
);
571 extern int drmScatterGatherFree(int fd
, unsigned long handle
);
573 extern int drmWaitVBlank(int fd
, drmVBlankPtr vbl
);
575 /* Support routines */
576 extern int drmError(int err
, const char *label
);
577 extern void *drmMalloc(int size
);
578 extern void drmFree(void *pt
);
580 /* Hash table routines */
581 extern void *drmHashCreate(void);
582 extern int drmHashDestroy(void *t
);
583 extern int drmHashLookup(void *t
, unsigned long key
, void **value
);
584 extern int drmHashInsert(void *t
, unsigned long key
, void *value
);
585 extern int drmHashDelete(void *t
, unsigned long key
);
586 extern int drmHashFirst(void *t
, unsigned long *key
, void **value
);
587 extern int drmHashNext(void *t
, unsigned long *key
, void **value
);
590 extern void *drmRandomCreate(unsigned long seed
);
591 extern int drmRandomDestroy(void *state
);
592 extern unsigned long drmRandom(void *state
);
593 extern double drmRandomDouble(void *state
);
595 /* Skip list routines */
597 extern void *drmSLCreate(void);
598 extern int drmSLDestroy(void *l
);
599 extern int drmSLLookup(void *l
, unsigned long key
, void **value
);
600 extern int drmSLInsert(void *l
, unsigned long key
, void *value
);
601 extern int drmSLDelete(void *l
, unsigned long key
);
602 extern int drmSLNext(void *l
, unsigned long *key
, void **value
);
603 extern int drmSLFirst(void *l
, unsigned long *key
, void **value
);
604 extern void drmSLDump(void *l
);
605 extern int drmSLLookupNeighbors(void *l
, unsigned long key
,
606 unsigned long *prev_key
, void **prev_value
,
607 unsigned long *next_key
, void **next_value
);