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