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