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