Home | History | Annotate | Download | only in libdrm
      1 /**
      2  * \file xf86drm.h
      3  * OS-independent header for DRM user-level library interface.
      4  *
      5  * \author Rickard E. (Rik) Faith <faith (at) valinux.com>
      6  */
      7 
      8 /*
      9  * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
     10  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
     11  * All Rights Reserved.
     12  *
     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:
     19  *
     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
     22  * Software.
     23  *
     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.
     31  *
     32  */
     33 
     34 #ifndef _XF86DRM_H_
     35 #define _XF86DRM_H_
     36 
     37 #if defined(__cplusplus) || defined(c_plusplus)
     38 extern "C" {
     39 #endif
     40 
     41 #include <stdarg.h>
     42 #include <sys/types.h>
     43 #include <stdint.h>
     44 #include <drm.h>
     45 
     46 				/* Defaults, if nothing set in xf86config */
     47 #define DRM_DEV_UID	 0
     48 #define DRM_DEV_GID	 0
     49 /* Default /dev/dri directory permissions 0755 */
     50 #define DRM_DEV_DIRMODE	 	\
     51 	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
     52 #define DRM_DEV_MODE	 (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
     53 
     54 #define DRM_DIR_NAME  "/dev/dri"
     55 #define DRM_DEV_NAME  "%s/card%d"
     56 #define DRM_CONTROL_DEV_NAME  "%s/controlD%d"
     57 #define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
     58 
     59 #define DRM_ERR_NO_DEVICE  (-1001)
     60 #define DRM_ERR_NO_ACCESS  (-1002)
     61 #define DRM_ERR_NOT_ROOT   (-1003)
     62 #define DRM_ERR_INVALID    (-1004)
     63 #define DRM_ERR_NO_FD      (-1005)
     64 
     65 #define DRM_AGP_NO_HANDLE 0
     66 
     67 typedef unsigned int  drmSize,     *drmSizePtr;	    /**< For mapped regions */
     68 typedef void          *drmAddress, **drmAddressPtr; /**< For mapped regions */
     69 
     70 typedef struct _drmServerInfo {
     71   int (*debug_print)(const char *format, va_list ap);
     72   int (*load_module)(const char *name);
     73   void (*get_perms)(gid_t *, mode_t *);
     74 } drmServerInfo, *drmServerInfoPtr;
     75 
     76 typedef struct drmHashEntry {
     77     int      fd;
     78     void     (*f)(int, void *, void *);
     79     void     *tagTable;
     80 } drmHashEntry;
     81 
     82 extern int drmIoctl(int fd, unsigned long request, void *arg);
     83 extern void *drmGetHashTable(void);
     84 extern drmHashEntry *drmGetEntry(int fd);
     85 
     86 /**
     87  * Driver version information.
     88  *
     89  * \sa drmGetVersion() and drmSetVersion().
     90  */
     91 typedef struct _drmVersion {
     92     int     version_major;        /**< Major version */
     93     int     version_minor;        /**< Minor version */
     94     int     version_patchlevel;   /**< Patch level */
     95     int     name_len; 	          /**< Length of name buffer */
     96     char    *name;	          /**< Name of driver */
     97     int     date_len;             /**< Length of date buffer */
     98     char    *date;                /**< User-space buffer to hold date */
     99     int     desc_len;	          /**< Length of desc buffer */
    100     char    *desc;                /**< User-space buffer to hold desc */
    101 } drmVersion, *drmVersionPtr;
    102 
    103 typedef struct _drmStats {
    104     unsigned long count;	     /**< Number of data */
    105     struct {
    106 	unsigned long value;	     /**< Value from kernel */
    107 	const char    *long_format;  /**< Suggested format for long_name */
    108 	const char    *long_name;    /**< Long name for value */
    109 	const char    *rate_format;  /**< Suggested format for rate_name */
    110 	const char    *rate_name;    /**< Short name for value per second */
    111 	int           isvalue;       /**< True if value (vs. counter) */
    112 	const char    *mult_names;   /**< Multiplier names (e.g., "KGM") */
    113 	int           mult;          /**< Multiplier value (e.g., 1024) */
    114 	int           verbose;       /**< Suggest only in verbose output */
    115     } data[15];
    116 } drmStatsT;
    117 
    118 
    119 				/* All of these enums *MUST* match with the
    120                                    kernel implementation -- so do *NOT*
    121                                    change them!  (The drmlib implementation
    122                                    will just copy the flags instead of
    123                                    translating them.) */
    124 typedef enum {
    125     DRM_FRAME_BUFFER    = 0,      /**< WC, no caching, no core dump */
    126     DRM_REGISTERS       = 1,      /**< no caching, no core dump */
    127     DRM_SHM             = 2,      /**< shared, cached */
    128     DRM_AGP             = 3,	  /**< AGP/GART */
    129     DRM_SCATTER_GATHER  = 4,	  /**< PCI scatter/gather */
    130     DRM_CONSISTENT      = 5	  /**< PCI consistent */
    131 } drmMapType;
    132 
    133 typedef enum {
    134     DRM_RESTRICTED      = 0x0001, /**< Cannot be mapped to client-virtual */
    135     DRM_READ_ONLY       = 0x0002, /**< Read-only in client-virtual */
    136     DRM_LOCKED          = 0x0004, /**< Physical pages locked */
    137     DRM_KERNEL          = 0x0008, /**< Kernel requires access */
    138     DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */
    139     DRM_CONTAINS_LOCK   = 0x0020, /**< SHM page that contains lock */
    140     DRM_REMOVABLE	= 0x0040  /**< Removable mapping */
    141 } drmMapFlags;
    142 
    143 /**
    144  * \warning These values *MUST* match drm.h
    145  */
    146 typedef enum {
    147     /** \name Flags for DMA buffer dispatch */
    148     /*@{*/
    149     DRM_DMA_BLOCK        = 0x01, /**<
    150 				  * Block until buffer dispatched.
    151 				  *
    152 				  * \note the buffer may not yet have been
    153 				  * processed by the hardware -- getting a
    154 				  * hardware lock with the hardware quiescent
    155 				  * will ensure that the buffer has been
    156 				  * processed.
    157 				  */
    158     DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
    159     DRM_DMA_PRIORITY     = 0x04, /**< High priority dispatch */
    160     /*@}*/
    161 
    162     /** \name Flags for DMA buffer request */
    163     /*@{*/
    164     DRM_DMA_WAIT         = 0x10, /**< Wait for free buffers */
    165     DRM_DMA_SMALLER_OK   = 0x20, /**< Smaller-than-requested buffers OK */
    166     DRM_DMA_LARGER_OK    = 0x40  /**< Larger-than-requested buffers OK */
    167     /*@}*/
    168 } drmDMAFlags;
    169 
    170 typedef enum {
    171     DRM_PAGE_ALIGN       = 0x01,
    172     DRM_AGP_BUFFER       = 0x02,
    173     DRM_SG_BUFFER        = 0x04,
    174     DRM_FB_BUFFER        = 0x08,
    175     DRM_PCI_BUFFER_RO    = 0x10
    176 } drmBufDescFlags;
    177 
    178 typedef enum {
    179     DRM_LOCK_READY      = 0x01, /**< Wait until hardware is ready for DMA */
    180     DRM_LOCK_QUIESCENT  = 0x02, /**< Wait until hardware quiescent */
    181     DRM_LOCK_FLUSH      = 0x04, /**< Flush this context's DMA queue first */
    182     DRM_LOCK_FLUSH_ALL  = 0x08, /**< Flush all DMA queues first */
    183 				/* These *HALT* flags aren't supported yet
    184                                    -- they will be used to support the
    185                                    full-screen DGA-like mode. */
    186     DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
    187     DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
    188 } drmLockFlags;
    189 
    190 typedef enum {
    191     DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and
    192 				     never swapped. */
    193     DRM_CONTEXT_2DONLY    = 0x02  /**< This context is for 2D rendering only. */
    194 } drm_context_tFlags, *drm_context_tFlagsPtr;
    195 
    196 typedef struct _drmBufDesc {
    197     int              count;	  /**< Number of buffers of this size */
    198     int              size;	  /**< Size in bytes */
    199     int              low_mark;	  /**< Low water mark */
    200     int              high_mark;	  /**< High water mark */
    201 } drmBufDesc, *drmBufDescPtr;
    202 
    203 typedef struct _drmBufInfo {
    204     int              count;	  /**< Number of buffers described in list */
    205     drmBufDescPtr    list;	  /**< List of buffer descriptions */
    206 } drmBufInfo, *drmBufInfoPtr;
    207 
    208 typedef struct _drmBuf {
    209     int              idx;	  /**< Index into the master buffer list */
    210     int              total;	  /**< Buffer size */
    211     int              used;	  /**< Amount of buffer in use (for DMA) */
    212     drmAddress       address;	  /**< Address */
    213 } drmBuf, *drmBufPtr;
    214 
    215 /**
    216  * Buffer mapping information.
    217  *
    218  * Used by drmMapBufs() and drmUnmapBufs() to store information about the
    219  * mapped buffers.
    220  */
    221 typedef struct _drmBufMap {
    222     int              count;	  /**< Number of buffers mapped */
    223     drmBufPtr        list;	  /**< Buffers */
    224 } drmBufMap, *drmBufMapPtr;
    225 
    226 typedef struct _drmLock {
    227     volatile unsigned int lock;
    228     char                      padding[60];
    229     /* This is big enough for most current (and future?) architectures:
    230        DEC Alpha:              32 bytes
    231        Intel Merced:           ?
    232        Intel P5/PPro/PII/PIII: 32 bytes
    233        Intel StrongARM:        32 bytes
    234        Intel i386/i486:        16 bytes
    235        MIPS:                   32 bytes (?)
    236        Motorola 68k:           16 bytes
    237        Motorola PowerPC:       32 bytes
    238        Sun SPARC:              32 bytes
    239     */
    240 } drmLock, *drmLockPtr;
    241 
    242 /**
    243  * Indices here refer to the offset into
    244  * list in drmBufInfo
    245  */
    246 typedef struct _drmDMAReq {
    247     drm_context_t    context;  	  /**< Context handle */
    248     int           send_count;     /**< Number of buffers to send */
    249     int           *send_list;     /**< List of handles to buffers */
    250     int           *send_sizes;    /**< Lengths of data to send, in bytes */
    251     drmDMAFlags   flags;          /**< Flags */
    252     int           request_count;  /**< Number of buffers requested */
    253     int           request_size;	  /**< Desired size of buffers requested */
    254     int           *request_list;  /**< Buffer information */
    255     int           *request_sizes; /**< Minimum acceptable sizes */
    256     int           granted_count;  /**< Number of buffers granted at this size */
    257 } drmDMAReq, *drmDMAReqPtr;
    258 
    259 typedef struct _drmRegion {
    260     drm_handle_t     handle;
    261     unsigned int  offset;
    262     drmSize       size;
    263     drmAddress    map;
    264 } drmRegion, *drmRegionPtr;
    265 
    266 typedef struct _drmTextureRegion {
    267     unsigned char next;
    268     unsigned char prev;
    269     unsigned char in_use;
    270     unsigned char padding;	/**< Explicitly pad this out */
    271     unsigned int  age;
    272 } drmTextureRegion, *drmTextureRegionPtr;
    273 
    274 
    275 typedef enum {
    276     DRM_VBLANK_ABSOLUTE = 0x0,	/**< Wait for specific vblank sequence number */
    277     DRM_VBLANK_RELATIVE = 0x1,	/**< Wait for given number of vblanks */
    278     DRM_VBLANK_FLIP = 0x8000000,	/**< Scheduled buffer swap should flip */
    279     DRM_VBLANK_NEXTONMISS = 0x10000000,	/**< If missed, wait for next vblank */
    280     DRM_VBLANK_SECONDARY = 0x20000000,	/**< Secondary display controller */
    281     DRM_VBLANK_SIGNAL   = 0x40000000	/* Send signal instead of blocking */
    282 } drmVBlankSeqType;
    283 
    284 typedef struct _drmVBlankReq {
    285 	drmVBlankSeqType type;
    286 	unsigned int sequence;
    287 	unsigned long signal;
    288 } drmVBlankReq, *drmVBlankReqPtr;
    289 
    290 typedef struct _drmVBlankReply {
    291 	drmVBlankSeqType type;
    292 	unsigned int sequence;
    293 	long tval_sec;
    294 	long tval_usec;
    295 } drmVBlankReply, *drmVBlankReplyPtr;
    296 
    297 typedef union _drmVBlank {
    298 	drmVBlankReq request;
    299 	drmVBlankReply reply;
    300 } drmVBlank, *drmVBlankPtr;
    301 
    302 typedef struct _drmSetVersion {
    303 	int drm_di_major;
    304 	int drm_di_minor;
    305 	int drm_dd_major;
    306 	int drm_dd_minor;
    307 } drmSetVersion, *drmSetVersionPtr;
    308 
    309 #define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
    310 
    311 #define DRM_LOCK_HELD  0x80000000U /**< Hardware lock is held */
    312 #define DRM_LOCK_CONT  0x40000000U /**< Hardware lock is contended */
    313 
    314 #if defined(__GNUC__) && (__GNUC__ >= 2)
    315 # if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
    316 				/* Reflect changes here to drmP.h */
    317 #define DRM_CAS(lock,old,new,__ret)                                    \
    318 	do {                                                           \
    319                 int __dummy;	/* Can't mark eax as clobbered */      \
    320 		__asm__ __volatile__(                                  \
    321 			"lock ; cmpxchg %4,%1\n\t"                     \
    322                         "setnz %0"                                     \
    323 			: "=d" (__ret),                                \
    324    			  "=m" (__drm_dummy_lock(lock)),               \
    325                           "=a" (__dummy)                               \
    326 			: "2" (old),                                   \
    327 			  "r" (new));                                  \
    328 	} while (0)
    329 
    330 #elif defined(__alpha__)
    331 
    332 #define	DRM_CAS(lock, old, new, ret)		\
    333 	do {					\
    334 		int tmp, old32;			\
    335 		__asm__ __volatile__(		\
    336 		"	addl	$31, %5, %3\n"	\
    337 		"1:	ldl_l	%0, %2\n"	\
    338 		"	cmpeq	%0, %3, %1\n"	\
    339 		"	beq	%1, 2f\n"	\
    340 		"	mov	%4, %0\n"	\
    341 		"	stl_c	%0, %2\n"	\
    342 		"	beq	%0, 3f\n"	\
    343 		"	mb\n"			\
    344 		"2:	cmpeq	%1, 0, %1\n"	\
    345 		".subsection 2\n"		\
    346 		"3:	br	1b\n"		\
    347 		".previous"			\
    348 		: "=&r"(tmp), "=&r"(ret),	\
    349 		  "=m"(__drm_dummy_lock(lock)),	\
    350 		  "=&r"(old32)			\
    351 		: "r"(new), "r"(old)		\
    352 		: "memory");			\
    353 	} while (0)
    354 
    355 #elif defined(__sparc__)
    356 
    357 #define DRM_CAS(lock,old,new,__ret)				\
    358 do {	register unsigned int __old __asm("o0");		\
    359 	register unsigned int __new __asm("o1");		\
    360 	register volatile unsigned int *__lock __asm("o2");	\
    361 	__old = old;						\
    362 	__new = new;						\
    363 	__lock = (volatile unsigned int *)lock;			\
    364 	__asm__ __volatile__(					\
    365 		/*"cas [%2], %3, %0"*/				\
    366 		".word 0xd3e29008\n\t"				\
    367 		/*"membar #StoreStore | #StoreLoad"*/		\
    368 		".word 0x8143e00a"				\
    369 		: "=&r" (__new)					\
    370 		: "0" (__new),					\
    371 		  "r" (__lock),					\
    372 		  "r" (__old)					\
    373 		: "memory");					\
    374 	__ret = (__new != __old);				\
    375 } while(0)
    376 
    377 #elif defined(__ia64__)
    378 
    379 #ifdef __INTEL_COMPILER
    380 /* this currently generates bad code (missing stop bits)... */
    381 #include <ia64intrin.h>
    382 
    383 #define DRM_CAS(lock,old,new,__ret)					      \
    384 	do {								      \
    385 		unsigned long __result, __old = (old) & 0xffffffff;		\
    386 		__mf();							      	\
    387 		__result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\
    388 		__ret = (__result) != (__old);					\
    389 /*		__ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
    390 						     (old), (new))	      \
    391 			 != (old));					      */\
    392 	} while (0)
    393 
    394 #else
    395 #define DRM_CAS(lock,old,new,__ret)					  \
    396 	do {								  \
    397 		unsigned int __result, __old = (old);			  \
    398 		__asm__ __volatile__(					  \
    399 			"mf\n"						  \
    400 			"mov ar.ccv=%2\n"				  \
    401 			";;\n"						  \
    402 			"cmpxchg4.acq %0=%1,%3,ar.ccv"			  \
    403 			: "=r" (__result), "=m" (__drm_dummy_lock(lock))  \
    404 			: "r" ((unsigned long)__old), "r" (new)			  \
    405 			: "memory");					  \
    406 		__ret = (__result) != (__old);				  \
    407 	} while (0)
    408 
    409 #endif
    410 
    411 #elif defined(__powerpc__)
    412 
    413 #define DRM_CAS(lock,old,new,__ret)			\
    414 	do {						\
    415 		__asm__ __volatile__(			\
    416 			"sync;"				\
    417 			"0:    lwarx %0,0,%1;"		\
    418 			"      xor. %0,%3,%0;"		\
    419 			"      bne 1f;"			\
    420 			"      stwcx. %2,0,%1;"		\
    421 			"      bne- 0b;"		\
    422 			"1:    "			\
    423 			"sync;"				\
    424 		: "=&r"(__ret)				\
    425 		: "r"(lock), "r"(new), "r"(old)		\
    426 		: "cr0", "memory");			\
    427 	} while (0)
    428 
    429 #endif /* architecture */
    430 #endif /* __GNUC__ >= 2 */
    431 
    432 #ifndef DRM_CAS
    433 #define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
    434 #endif
    435 
    436 #if defined(__alpha__)
    437 #define DRM_CAS_RESULT(_result)		long _result
    438 #elif defined(__powerpc__)
    439 #define DRM_CAS_RESULT(_result)		int _result
    440 #else
    441 #define DRM_CAS_RESULT(_result)		char _result
    442 #endif
    443 
    444 #define DRM_LIGHT_LOCK(fd,lock,context)                                \
    445 	do {                                                           \
    446                 DRM_CAS_RESULT(__ret);                                 \
    447 		DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret);     \
    448                 if (__ret) drmGetLock(fd,context,0);                   \
    449         } while(0)
    450 
    451 				/* This one counts fast locks -- for
    452                                    benchmarking only. */
    453 #define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count)                    \
    454 	do {                                                           \
    455                 DRM_CAS_RESULT(__ret);                                 \
    456 		DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret);     \
    457                 if (__ret) drmGetLock(fd,context,0);                   \
    458                 else       ++count;                                    \
    459         } while(0)
    460 
    461 #define DRM_LOCK(fd,lock,context,flags)                                \
    462 	do {                                                           \
    463 		if (flags) drmGetLock(fd,context,flags);               \
    464 		else       DRM_LIGHT_LOCK(fd,lock,context);            \
    465 	} while(0)
    466 
    467 #define DRM_UNLOCK(fd,lock,context)                                    \
    468 	do {                                                           \
    469                 DRM_CAS_RESULT(__ret);                                 \
    470 		DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret);     \
    471                 if (__ret) drmUnlock(fd,context);                      \
    472         } while(0)
    473 
    474 				/* Simple spin locks */
    475 #define DRM_SPINLOCK(spin,val)                                         \
    476 	do {                                                           \
    477             DRM_CAS_RESULT(__ret);                                     \
    478 	    do {                                                       \
    479 		DRM_CAS(spin,0,val,__ret);                             \
    480 		if (__ret) while ((spin)->lock);                       \
    481 	    } while (__ret);                                           \
    482 	} while(0)
    483 
    484 #define DRM_SPINLOCK_TAKE(spin,val)                                    \
    485 	do {                                                           \
    486             DRM_CAS_RESULT(__ret);                                     \
    487             int  cur;                                                  \
    488 	    do {                                                       \
    489                 cur = (*spin).lock;                                    \
    490 		DRM_CAS(spin,cur,val,__ret);                           \
    491 	    } while (__ret);                                           \
    492 	} while(0)
    493 
    494 #define DRM_SPINLOCK_COUNT(spin,val,count,__ret)                       \
    495 	do {                                                           \
    496             int  __i;                                                  \
    497             __ret = 1;                                                 \
    498             for (__i = 0; __ret && __i < count; __i++) {               \
    499 		DRM_CAS(spin,0,val,__ret);                             \
    500 		if (__ret) for (;__i < count && (spin)->lock; __i++);  \
    501 	    }                                                          \
    502 	} while(0)
    503 
    504 #define DRM_SPINUNLOCK(spin,val)                                       \
    505 	do {                                                           \
    506             DRM_CAS_RESULT(__ret);                                     \
    507             if ((*spin).lock == val) { /* else server stole lock */    \
    508 	        do {                                                   \
    509 		    DRM_CAS(spin,val,0,__ret);                         \
    510 	        } while (__ret);                                       \
    511             }                                                          \
    512 	} while(0)
    513 
    514 
    515 
    516 /* General user-level programmer's API: unprivileged */
    517 extern int           drmAvailable(void);
    518 extern int           drmOpen(const char *name, const char *busid);
    519 extern int drmOpenControl(int minor);
    520 extern int           drmClose(int fd);
    521 extern drmVersionPtr drmGetVersion(int fd);
    522 extern drmVersionPtr drmGetLibVersion(int fd);
    523 extern void          drmFreeVersion(drmVersionPtr);
    524 extern int           drmGetMagic(int fd, drm_magic_t * magic);
    525 extern char          *drmGetBusid(int fd);
    526 extern int           drmGetInterruptFromBusID(int fd, int busnum, int devnum,
    527 					      int funcnum);
    528 extern int           drmGetMap(int fd, int idx, drm_handle_t *offset,
    529 			       drmSize *size, drmMapType *type,
    530 			       drmMapFlags *flags, drm_handle_t *handle,
    531 			       int *mtrr);
    532 extern int           drmGetClient(int fd, int idx, int *auth, int *pid,
    533 				  int *uid, unsigned long *magic,
    534 				  unsigned long *iocs);
    535 extern int           drmGetStats(int fd, drmStatsT *stats);
    536 extern int           drmSetInterfaceVersion(int fd, drmSetVersion *version);
    537 extern int           drmCommandNone(int fd, unsigned long drmCommandIndex);
    538 extern int           drmCommandRead(int fd, unsigned long drmCommandIndex,
    539                                     void *data, unsigned long size);
    540 extern int           drmCommandWrite(int fd, unsigned long drmCommandIndex,
    541                                      void *data, unsigned long size);
    542 extern int           drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
    543                                          void *data, unsigned long size);
    544 
    545 /* General user-level programmer's API: X server (root) only  */
    546 extern void          drmFreeBusid(const char *busid);
    547 extern int           drmSetBusid(int fd, const char *busid);
    548 extern int           drmAuthMagic(int fd, drm_magic_t magic);
    549 extern int           drmAddMap(int fd,
    550 			       drm_handle_t offset,
    551 			       drmSize size,
    552 			       drmMapType type,
    553 			       drmMapFlags flags,
    554 			       drm_handle_t * handle);
    555 extern int	     drmRmMap(int fd, drm_handle_t handle);
    556 extern int	     drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
    557 						 drm_handle_t handle);
    558 
    559 extern int           drmAddBufs(int fd, int count, int size,
    560 				drmBufDescFlags flags,
    561 				int agp_offset);
    562 extern int           drmMarkBufs(int fd, double low, double high);
    563 extern int           drmCreateContext(int fd, drm_context_t * handle);
    564 extern int           drmSetContextFlags(int fd, drm_context_t context,
    565 					drm_context_tFlags flags);
    566 extern int           drmGetContextFlags(int fd, drm_context_t context,
    567 					drm_context_tFlagsPtr flags);
    568 extern int           drmAddContextTag(int fd, drm_context_t context, void *tag);
    569 extern int           drmDelContextTag(int fd, drm_context_t context);
    570 extern void          *drmGetContextTag(int fd, drm_context_t context);
    571 extern drm_context_t * drmGetReservedContextList(int fd, int *count);
    572 extern void          drmFreeReservedContextList(drm_context_t *);
    573 extern int           drmSwitchToContext(int fd, drm_context_t context);
    574 extern int           drmDestroyContext(int fd, drm_context_t handle);
    575 extern int           drmCreateDrawable(int fd, drm_drawable_t * handle);
    576 extern int           drmDestroyDrawable(int fd, drm_drawable_t handle);
    577 extern int           drmUpdateDrawableInfo(int fd, drm_drawable_t handle,
    578 					   drm_drawable_info_type_t type,
    579 					   unsigned int num, void *data);
    580 extern int           drmCtlInstHandler(int fd, int irq);
    581 extern int           drmCtlUninstHandler(int fd);
    582 
    583 /* General user-level programmer's API: authenticated client and/or X */
    584 extern int           drmMap(int fd,
    585 			    drm_handle_t handle,
    586 			    drmSize size,
    587 			    drmAddressPtr address);
    588 extern int           drmUnmap(drmAddress address, drmSize size);
    589 extern drmBufInfoPtr drmGetBufInfo(int fd);
    590 extern drmBufMapPtr  drmMapBufs(int fd);
    591 extern int           drmUnmapBufs(drmBufMapPtr bufs);
    592 extern int           drmDMA(int fd, drmDMAReqPtr request);
    593 extern int           drmFreeBufs(int fd, int count, int *list);
    594 extern int           drmGetLock(int fd,
    595 			        drm_context_t context,
    596 			        drmLockFlags flags);
    597 extern int           drmUnlock(int fd, drm_context_t context);
    598 extern int           drmFinish(int fd, int context, drmLockFlags flags);
    599 extern int	     drmGetContextPrivateMapping(int fd, drm_context_t ctx_id,
    600 						 drm_handle_t * handle);
    601 
    602 /* AGP/GART support: X server (root) only */
    603 extern int           drmAgpAcquire(int fd);
    604 extern int           drmAgpRelease(int fd);
    605 extern int           drmAgpEnable(int fd, unsigned long mode);
    606 extern int           drmAgpAlloc(int fd, unsigned long size,
    607 				 unsigned long type, unsigned long *address,
    608 				 drm_handle_t *handle);
    609 extern int           drmAgpFree(int fd, drm_handle_t handle);
    610 extern int 	     drmAgpBind(int fd, drm_handle_t handle,
    611 				unsigned long offset);
    612 extern int           drmAgpUnbind(int fd, drm_handle_t handle);
    613 
    614 /* AGP/GART info: authenticated client and/or X */
    615 extern int           drmAgpVersionMajor(int fd);
    616 extern int           drmAgpVersionMinor(int fd);
    617 extern unsigned long drmAgpGetMode(int fd);
    618 extern unsigned long drmAgpBase(int fd); /* Physical location */
    619 extern unsigned long drmAgpSize(int fd); /* Bytes */
    620 extern unsigned long drmAgpMemoryUsed(int fd);
    621 extern unsigned long drmAgpMemoryAvail(int fd);
    622 extern unsigned int  drmAgpVendorId(int fd);
    623 extern unsigned int  drmAgpDeviceId(int fd);
    624 
    625 /* PCI scatter/gather support: X server (root) only */
    626 extern int           drmScatterGatherAlloc(int fd, unsigned long size,
    627 					   drm_handle_t *handle);
    628 extern int           drmScatterGatherFree(int fd, drm_handle_t handle);
    629 
    630 extern int           drmWaitVBlank(int fd, drmVBlankPtr vbl);
    631 
    632 /* Support routines */
    633 extern void          drmSetServerInfo(drmServerInfoPtr info);
    634 extern int           drmError(int err, const char *label);
    635 extern void          *drmMalloc(int size);
    636 extern void          drmFree(void *pt);
    637 
    638 /* Hash table routines */
    639 extern void *drmHashCreate(void);
    640 extern int  drmHashDestroy(void *t);
    641 extern int  drmHashLookup(void *t, unsigned long key, void **value);
    642 extern int  drmHashInsert(void *t, unsigned long key, void *value);
    643 extern int  drmHashDelete(void *t, unsigned long key);
    644 extern int  drmHashFirst(void *t, unsigned long *key, void **value);
    645 extern int  drmHashNext(void *t, unsigned long *key, void **value);
    646 
    647 /* PRNG routines */
    648 extern void          *drmRandomCreate(unsigned long seed);
    649 extern int           drmRandomDestroy(void *state);
    650 extern unsigned long drmRandom(void *state);
    651 extern double        drmRandomDouble(void *state);
    652 
    653 /* Skip list routines */
    654 
    655 extern void *drmSLCreate(void);
    656 extern int  drmSLDestroy(void *l);
    657 extern int  drmSLLookup(void *l, unsigned long key, void **value);
    658 extern int  drmSLInsert(void *l, unsigned long key, void *value);
    659 extern int  drmSLDelete(void *l, unsigned long key);
    660 extern int  drmSLNext(void *l, unsigned long *key, void **value);
    661 extern int  drmSLFirst(void *l, unsigned long *key, void **value);
    662 extern void drmSLDump(void *l);
    663 extern int  drmSLLookupNeighbors(void *l, unsigned long key,
    664 				 unsigned long *prev_key, void **prev_value,
    665 				 unsigned long *next_key, void **next_value);
    666 
    667 extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
    668 extern void drmCloseOnce(int fd);
    669 extern void drmMsg(const char *format, ...);
    670 
    671 extern int drmSetMaster(int fd);
    672 extern int drmDropMaster(int fd);
    673 
    674 #if defined(__cplusplus) || defined(c_plusplus)
    675 }
    676 #endif
    677 
    678 #endif
    679