OSDN Git Service

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