blob: 5ecb2846591427de86140294acf4f23547ebd089 [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
Tapani Pällicfee5212011-09-23 14:17:42 +030042#if defined(__cplusplus) || defined(c_plusplus)
43extern "C" {
44#endif
45
Robert Noland6f66de92009-11-25 15:09:24 -060046#ifndef DRM_MAX_MINOR
47#define DRM_MAX_MINOR 16
48#endif
49
Kristian Høgsberg500f5b52009-11-23 18:25:08 -050050#if defined(__linux__)
51
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)
Kristian Høgsberg500f5b52009-11-23 18:25:08 -050058
59#else /* One of the *BSDs */
60
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)
68
69#endif
70
Jon Smirldeed1ec2004-07-07 04:22:17 +000071 /* 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)
78
79#define DRM_DIR_NAME "/dev/dri"
80#define DRM_DEV_NAME "%s/card%d"
Jesse Barnes731cd552008-12-17 10:09:49 -080081#define DRM_CONTROL_DEV_NAME "%s/controlD%d"
Jon Smirldeed1ec2004-07-07 04:22:17 +000082#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
83
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)
89
90#define DRM_AGP_NO_HANDLE 0
91
92typedef unsigned int drmSize, *drmSizePtr; /**< For mapped regions */
93typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */
94
Dave Airlie79038752006-11-08 15:08:09 +110095typedef 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;
100
101typedef struct drmHashEntry {
102 int fd;
103 void (*f)(int, void *, void *);
104 void *tagTable;
105} drmHashEntry;
106
Jesse Barnes731cd552008-12-17 10:09:49 -0800107extern int drmIoctl(int fd, unsigned long request, void *arg);
Dave Airlie79038752006-11-08 15:08:09 +1100108extern void *drmGetHashTable(void);
109extern drmHashEntry *drmGetEntry(int fd);
110
Jon Smirldeed1ec2004-07-07 04:22:17 +0000111/**
112 * Driver version information.
113 *
114 * \sa drmGetVersion() and drmSetVersion().
115 */
116typedef 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;
127
128typedef 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;
142
143
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.) */
149typedef 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 */
Felix Kuehlinged165a22005-01-01 20:03:15 +0000154 DRM_SCATTER_GATHER = 4, /**< PCI scatter/gather */
155 DRM_CONSISTENT = 5 /**< PCI consistent */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000156} drmMapType;
157
158typedef 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;
167
168/**
169 * \warning These values *MUST* match drm.h
170 */
171typedef 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 /*@}*/
186
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;
194
195typedef enum {
196 DRM_PAGE_ALIGN = 0x01,
197 DRM_AGP_BUFFER = 0x02,
Dave Airlie354dd172005-01-16 05:40:12 +0000198 DRM_SG_BUFFER = 0x04,
George Sapountzisf3deef72006-10-02 05:46:42 +0300199 DRM_FB_BUFFER = 0x08,
200 DRM_PCI_BUFFER_RO = 0x10
Jon Smirldeed1ec2004-07-07 04:22:17 +0000201} drmBufDescFlags;
202
203typedef 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;
214
215typedef 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;
220
221typedef 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;
227
228typedef struct _drmBufInfo {
229 int count; /**< Number of buffers described in list */
230 drmBufDescPtr list; /**< List of buffer descriptions */
231} drmBufInfo, *drmBufInfoPtr;
232
233typedef 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;
239
240/**
241 * Buffer mapping information.
242 *
243 * Used by drmMapBufs() and drmUnmapBufs() to store information about the
244 * mapped buffers.
245 */
246typedef struct _drmBufMap {
247 int count; /**< Number of buffers mapped */
248 drmBufPtr list; /**< Buffers */
249} drmBufMap, *drmBufMapPtr;
250
251typedef 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;
266
267/**
268 * Indices here refer to the offset into
269 * list in drmBufInfo
270 */
271typedef 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;
283
284typedef struct _drmRegion {
285 drm_handle_t handle;
286 unsigned int offset;
287 drmSize size;
288 drmAddress map;
289} drmRegion, *drmRegionPtr;
290
291typedef 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;
298
299
300typedef enum {
301 DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */
302 DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */
Ilija Hadzicbe8802a2011-03-24 13:24:28 -0400303 /* bits 1-6 are reserved for high crtcs */
304 DRM_VBLANK_HIGH_CRTC_MASK = 0x0000003e,
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400305 DRM_VBLANK_EVENT = 0x4000000, /**< Send event instead of blocking */
Michel Dänzer5a40c042007-02-22 17:19:30 +0100306 DRM_VBLANK_FLIP = 0x8000000, /**< Scheduled buffer swap should flip */
Michel Dänzer89e323e2006-09-01 11:27:14 +0200307 DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */
Michel Dänzer84b38b62006-08-31 18:32:08 +0200308 DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000309 DRM_VBLANK_SIGNAL = 0x40000000 /* Send signal instead of blocking */
310} drmVBlankSeqType;
Ilija Hadzicbe8802a2011-03-24 13:24:28 -0400311#define DRM_VBLANK_HIGH_CRTC_SHIFT 1
Jon Smirldeed1ec2004-07-07 04:22:17 +0000312
313typedef struct _drmVBlankReq {
314 drmVBlankSeqType type;
315 unsigned int sequence;
316 unsigned long signal;
317} drmVBlankReq, *drmVBlankReqPtr;
318
319typedef struct _drmVBlankReply {
320 drmVBlankSeqType type;
321 unsigned int sequence;
322 long tval_sec;
323 long tval_usec;
324} drmVBlankReply, *drmVBlankReplyPtr;
325
326typedef union _drmVBlank {
327 drmVBlankReq request;
328 drmVBlankReply reply;
329} drmVBlank, *drmVBlankPtr;
330
331typedef 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;
337
Jon Smirldeed1ec2004-07-07 04:22:17 +0000338#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
339
Dave Airliecc4d0392004-07-31 08:12:39 +0000340#define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
341#define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000342
343#if defined(__GNUC__) && (__GNUC__ >= 2)
Dave Airlie5a52e532005-08-23 04:10:50 +0000344# if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000345 /* 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)
358
359#elif defined(__alpha__)
360
Ivan Kokshaysky6feac492009-02-23 15:54:18 -0500361#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)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000383
384#elif defined(__sparc__)
385
386#define DRM_CAS(lock,old,new,__ret) \
387do { 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)
405
406#elif defined(__ia64__)
407
408#ifdef __INTEL_COMPILER
409/* this currently generates bad code (missing stop bits)... */
410#include <ia64intrin.h>
411
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)
422
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)
437
438#endif
439
440#elif defined(__powerpc__)
441
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)
457
458#endif /* architecture */
459#endif /* __GNUC__ >= 2 */
460
461#ifndef DRM_CAS
462#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
463#endif
464
Ivan Kokshaysky6feac492009-02-23 15:54:18 -0500465#if defined(__alpha__)
466#define DRM_CAS_RESULT(_result) long _result
467#elif defined(__powerpc__)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000468#define DRM_CAS_RESULT(_result) int _result
469#else
470#define DRM_CAS_RESULT(_result) char _result
471#endif
472
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)
479
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)
489
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)
495
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)
502
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)
512
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)
522
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)
532
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)
542
Thomas Hellstrome181f592006-08-28 09:49:09 +0200543
544
Jon Smirldeed1ec2004-07-07 04:22:17 +0000545/* General user-level programmer's API: unprivileged */
546extern int drmAvailable(void);
547extern int drmOpen(const char *name, const char *busid);
Jesse Barnes731cd552008-12-17 10:09:49 -0800548extern int drmOpenControl(int minor);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000549extern int drmClose(int fd);
550extern drmVersionPtr drmGetVersion(int fd);
551extern drmVersionPtr drmGetLibVersion(int fd);
Ben Skeggs5c6c6912011-02-21 11:27:19 +1000552extern int drmGetCap(int fd, uint64_t capability, uint64_t *value);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000553extern void drmFreeVersion(drmVersionPtr);
554extern int drmGetMagic(int fd, drm_magic_t * magic);
555extern char *drmGetBusid(int fd);
556extern int drmGetInterruptFromBusID(int fd, int busnum, int devnum,
557 int funcnum);
558extern 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);
562extern int drmGetClient(int fd, int idx, int *auth, int *pid,
563 int *uid, unsigned long *magic,
564 unsigned long *iocs);
565extern int drmGetStats(int fd, drmStatsT *stats);
566extern int drmSetInterfaceVersion(int fd, drmSetVersion *version);
567extern int drmCommandNone(int fd, unsigned long drmCommandIndex);
568extern int drmCommandRead(int fd, unsigned long drmCommandIndex,
569 void *data, unsigned long size);
570extern int drmCommandWrite(int fd, unsigned long drmCommandIndex,
571 void *data, unsigned long size);
572extern int drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
573 void *data, unsigned long size);
574
575/* General user-level programmer's API: X server (root) only */
576extern void drmFreeBusid(const char *busid);
577extern int drmSetBusid(int fd, const char *busid);
578extern int drmAuthMagic(int fd, drm_magic_t magic);
579extern int drmAddMap(int fd,
580 drm_handle_t offset,
581 drmSize size,
582 drmMapType type,
583 drmMapFlags flags,
584 drm_handle_t * handle);
585extern int drmRmMap(int fd, drm_handle_t handle);
586extern int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
587 drm_handle_t handle);
588
589extern int drmAddBufs(int fd, int count, int size,
590 drmBufDescFlags flags,
591 int agp_offset);
592extern int drmMarkBufs(int fd, double low, double high);
593extern int drmCreateContext(int fd, drm_context_t * handle);
594extern int drmSetContextFlags(int fd, drm_context_t context,
595 drm_context_tFlags flags);
596extern int drmGetContextFlags(int fd, drm_context_t context,
597 drm_context_tFlagsPtr flags);
598extern int drmAddContextTag(int fd, drm_context_t context, void *tag);
599extern int drmDelContextTag(int fd, drm_context_t context);
600extern void *drmGetContextTag(int fd, drm_context_t context);
601extern drm_context_t * drmGetReservedContextList(int fd, int *count);
602extern void drmFreeReservedContextList(drm_context_t *);
603extern int drmSwitchToContext(int fd, drm_context_t context);
604extern int drmDestroyContext(int fd, drm_context_t handle);
605extern int drmCreateDrawable(int fd, drm_drawable_t * handle);
606extern int drmDestroyDrawable(int fd, drm_drawable_t handle);
Michel Dänzer29598e52006-08-22 16:40:07 +0200607extern int drmUpdateDrawableInfo(int fd, drm_drawable_t handle,
608 drm_drawable_info_type_t type,
609 unsigned int num, void *data);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000610extern int drmCtlInstHandler(int fd, int irq);
611extern int drmCtlUninstHandler(int fd);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000612
613/* General user-level programmer's API: authenticated client and/or X */
614extern int drmMap(int fd,
615 drm_handle_t handle,
616 drmSize size,
617 drmAddressPtr address);
618extern int drmUnmap(drmAddress address, drmSize size);
619extern drmBufInfoPtr drmGetBufInfo(int fd);
620extern drmBufMapPtr drmMapBufs(int fd);
621extern int drmUnmapBufs(drmBufMapPtr bufs);
622extern int drmDMA(int fd, drmDMAReqPtr request);
623extern int drmFreeBufs(int fd, int count, int *list);
624extern int drmGetLock(int fd,
625 drm_context_t context,
626 drmLockFlags flags);
627extern int drmUnlock(int fd, drm_context_t context);
628extern int drmFinish(int fd, int context, drmLockFlags flags);
629extern int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id,
630 drm_handle_t * handle);
631
632/* AGP/GART support: X server (root) only */
633extern int drmAgpAcquire(int fd);
634extern int drmAgpRelease(int fd);
635extern int drmAgpEnable(int fd, unsigned long mode);
636extern int drmAgpAlloc(int fd, unsigned long size,
637 unsigned long type, unsigned long *address,
Dave Airlie645e2d42005-11-29 09:19:20 +0000638 drm_handle_t *handle);
639extern int drmAgpFree(int fd, drm_handle_t handle);
640extern int drmAgpBind(int fd, drm_handle_t handle,
Jon Smirldeed1ec2004-07-07 04:22:17 +0000641 unsigned long offset);
Dave Airlie645e2d42005-11-29 09:19:20 +0000642extern int drmAgpUnbind(int fd, drm_handle_t handle);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000643
644/* AGP/GART info: authenticated client and/or X */
645extern int drmAgpVersionMajor(int fd);
646extern int drmAgpVersionMinor(int fd);
647extern unsigned long drmAgpGetMode(int fd);
648extern unsigned long drmAgpBase(int fd); /* Physical location */
649extern unsigned long drmAgpSize(int fd); /* Bytes */
650extern unsigned long drmAgpMemoryUsed(int fd);
651extern unsigned long drmAgpMemoryAvail(int fd);
652extern unsigned int drmAgpVendorId(int fd);
653extern unsigned int drmAgpDeviceId(int fd);
654
655/* PCI scatter/gather support: X server (root) only */
656extern int drmScatterGatherAlloc(int fd, unsigned long size,
Dave Airlie645e2d42005-11-29 09:19:20 +0000657 drm_handle_t *handle);
658extern int drmScatterGatherFree(int fd, drm_handle_t handle);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000659
660extern int drmWaitVBlank(int fd, drmVBlankPtr vbl);
661
662/* Support routines */
Dave Airlie79038752006-11-08 15:08:09 +1100663extern void drmSetServerInfo(drmServerInfoPtr info);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000664extern int drmError(int err, const char *label);
665extern void *drmMalloc(int size);
666extern void drmFree(void *pt);
667
668/* Hash table routines */
669extern void *drmHashCreate(void);
670extern int drmHashDestroy(void *t);
671extern int drmHashLookup(void *t, unsigned long key, void **value);
672extern int drmHashInsert(void *t, unsigned long key, void *value);
673extern int drmHashDelete(void *t, unsigned long key);
674extern int drmHashFirst(void *t, unsigned long *key, void **value);
675extern int drmHashNext(void *t, unsigned long *key, void **value);
676
677/* PRNG routines */
678extern void *drmRandomCreate(unsigned long seed);
679extern int drmRandomDestroy(void *state);
680extern unsigned long drmRandom(void *state);
681extern double drmRandomDouble(void *state);
682
683/* Skip list routines */
684
685extern void *drmSLCreate(void);
686extern int drmSLDestroy(void *l);
687extern int drmSLLookup(void *l, unsigned long key, void **value);
688extern int drmSLInsert(void *l, unsigned long key, void *value);
689extern int drmSLDelete(void *l, unsigned long key);
690extern int drmSLNext(void *l, unsigned long *key, void **value);
691extern int drmSLFirst(void *l, unsigned long *key, void **value);
692extern void drmSLDump(void *l);
693extern int drmSLLookupNeighbors(void *l, unsigned long key,
694 unsigned long *prev_key, void **prev_value,
695 unsigned long *next_key, void **next_value);
696
Dave Airlied51e1bb2006-11-09 08:55:58 +1100697extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
698extern void drmCloseOnce(int fd);
Eric Anholtc4857422008-06-03 10:20:49 -0700699extern void drmMsg(const char *format, ...);
Dave Airlied51e1bb2006-11-09 08:55:58 +1100700
Jesse Barnes731cd552008-12-17 10:09:49 -0800701extern int drmSetMaster(int fd);
702extern int drmDropMaster(int fd);
703
Jesse Barnes14f59582009-12-03 14:20:51 -0800704#define DRM_EVENT_CONTEXT_VERSION 2
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400705
706typedef struct _drmEventContext {
707
708 /* This struct is versioned so we can add more pointers if we
709 * add more events. */
710 int version;
711
712 void (*vblank_handler)(int fd,
713 unsigned int sequence,
714 unsigned int tv_sec,
715 unsigned int tv_usec,
716 void *user_data);
717
Jesse Barnes53addc52009-12-03 14:17:26 -0800718 void (*page_flip_handler)(int fd,
719 unsigned int sequence,
720 unsigned int tv_sec,
721 unsigned int tv_usec,
722 void *user_data);
723
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400724} drmEventContext, *drmEventContextPtr;
725
726extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
727
Kristian Høgsberg22d46662009-11-23 20:51:34 -0500728extern char *drmGetDeviceNameFromFd(int fd);
729
Dave Airliecc0a1452012-07-14 09:52:17 +0000730extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd);
731extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle);
732
Tapani Pällicfee5212011-09-23 14:17:42 +0300733#if defined(__cplusplus) || defined(c_plusplus)
734}
735#endif
736
Jon Smirldeed1ec2004-07-07 04:22:17 +0000737#endif