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