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