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