blob: c024cc4463545d60f1d951f18b017fa1f907fd5a [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
Keith Packardcb4bc8e2014-01-12 10:32:57 -080095#if (__GNUC__ >= 3)
96#define DRM_PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a)))
97#else
98#define DRM_PRINTFLIKE(f, a)
99#endif
100
Dave Airlie79038752006-11-08 15:08:09 +1100101typedef struct _drmServerInfo {
Keith Packardcb4bc8e2014-01-12 10:32:57 -0800102 int (*debug_print)(const char *format, va_list ap) DRM_PRINTFLIKE(1,0);
Dave Airlie79038752006-11-08 15:08:09 +1100103 int (*load_module)(const char *name);
104 void (*get_perms)(gid_t *, mode_t *);
105} drmServerInfo, *drmServerInfoPtr;
106
107typedef struct drmHashEntry {
108 int fd;
109 void (*f)(int, void *, void *);
110 void *tagTable;
111} drmHashEntry;
112
Jesse Barnes731cd552008-12-17 10:09:49 -0800113extern int drmIoctl(int fd, unsigned long request, void *arg);
Dave Airlie79038752006-11-08 15:08:09 +1100114extern void *drmGetHashTable(void);
115extern drmHashEntry *drmGetEntry(int fd);
116
Jon Smirldeed1ec2004-07-07 04:22:17 +0000117/**
118 * Driver version information.
119 *
120 * \sa drmGetVersion() and drmSetVersion().
121 */
122typedef struct _drmVersion {
123 int version_major; /**< Major version */
124 int version_minor; /**< Minor version */
125 int version_patchlevel; /**< Patch level */
126 int name_len; /**< Length of name buffer */
127 char *name; /**< Name of driver */
128 int date_len; /**< Length of date buffer */
129 char *date; /**< User-space buffer to hold date */
130 int desc_len; /**< Length of desc buffer */
131 char *desc; /**< User-space buffer to hold desc */
132} drmVersion, *drmVersionPtr;
133
134typedef struct _drmStats {
135 unsigned long count; /**< Number of data */
136 struct {
137 unsigned long value; /**< Value from kernel */
138 const char *long_format; /**< Suggested format for long_name */
139 const char *long_name; /**< Long name for value */
140 const char *rate_format; /**< Suggested format for rate_name */
141 const char *rate_name; /**< Short name for value per second */
142 int isvalue; /**< True if value (vs. counter) */
143 const char *mult_names; /**< Multiplier names (e.g., "KGM") */
144 int mult; /**< Multiplier value (e.g., 1024) */
145 int verbose; /**< Suggest only in verbose output */
146 } data[15];
147} drmStatsT;
148
149
150 /* All of these enums *MUST* match with the
151 kernel implementation -- so do *NOT*
152 change them! (The drmlib implementation
153 will just copy the flags instead of
154 translating them.) */
155typedef enum {
156 DRM_FRAME_BUFFER = 0, /**< WC, no caching, no core dump */
157 DRM_REGISTERS = 1, /**< no caching, no core dump */
158 DRM_SHM = 2, /**< shared, cached */
159 DRM_AGP = 3, /**< AGP/GART */
Felix Kuehlinged165a22005-01-01 20:03:15 +0000160 DRM_SCATTER_GATHER = 4, /**< PCI scatter/gather */
161 DRM_CONSISTENT = 5 /**< PCI consistent */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000162} drmMapType;
163
164typedef enum {
165 DRM_RESTRICTED = 0x0001, /**< Cannot be mapped to client-virtual */
166 DRM_READ_ONLY = 0x0002, /**< Read-only in client-virtual */
167 DRM_LOCKED = 0x0004, /**< Physical pages locked */
168 DRM_KERNEL = 0x0008, /**< Kernel requires access */
169 DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */
170 DRM_CONTAINS_LOCK = 0x0020, /**< SHM page that contains lock */
171 DRM_REMOVABLE = 0x0040 /**< Removable mapping */
172} drmMapFlags;
173
174/**
175 * \warning These values *MUST* match drm.h
176 */
177typedef enum {
178 /** \name Flags for DMA buffer dispatch */
179 /*@{*/
180 DRM_DMA_BLOCK = 0x01, /**<
181 * Block until buffer dispatched.
182 *
183 * \note the buffer may not yet have been
184 * processed by the hardware -- getting a
185 * hardware lock with the hardware quiescent
186 * will ensure that the buffer has been
187 * processed.
188 */
189 DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
190 DRM_DMA_PRIORITY = 0x04, /**< High priority dispatch */
191 /*@}*/
192
193 /** \name Flags for DMA buffer request */
194 /*@{*/
195 DRM_DMA_WAIT = 0x10, /**< Wait for free buffers */
196 DRM_DMA_SMALLER_OK = 0x20, /**< Smaller-than-requested buffers OK */
197 DRM_DMA_LARGER_OK = 0x40 /**< Larger-than-requested buffers OK */
198 /*@}*/
199} drmDMAFlags;
200
201typedef enum {
202 DRM_PAGE_ALIGN = 0x01,
203 DRM_AGP_BUFFER = 0x02,
Dave Airlie354dd172005-01-16 05:40:12 +0000204 DRM_SG_BUFFER = 0x04,
George Sapountzisf3deef72006-10-02 05:46:42 +0300205 DRM_FB_BUFFER = 0x08,
206 DRM_PCI_BUFFER_RO = 0x10
Jon Smirldeed1ec2004-07-07 04:22:17 +0000207} drmBufDescFlags;
208
209typedef enum {
210 DRM_LOCK_READY = 0x01, /**< Wait until hardware is ready for DMA */
211 DRM_LOCK_QUIESCENT = 0x02, /**< Wait until hardware quiescent */
212 DRM_LOCK_FLUSH = 0x04, /**< Flush this context's DMA queue first */
213 DRM_LOCK_FLUSH_ALL = 0x08, /**< Flush all DMA queues first */
214 /* These *HALT* flags aren't supported yet
215 -- they will be used to support the
216 full-screen DGA-like mode. */
217 DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
218 DRM_HALT_CUR_QUEUES = 0x20 /**< Halt all current queues */
219} drmLockFlags;
220
221typedef enum {
222 DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and
223 never swapped. */
224 DRM_CONTEXT_2DONLY = 0x02 /**< This context is for 2D rendering only. */
225} drm_context_tFlags, *drm_context_tFlagsPtr;
226
227typedef struct _drmBufDesc {
228 int count; /**< Number of buffers of this size */
229 int size; /**< Size in bytes */
230 int low_mark; /**< Low water mark */
231 int high_mark; /**< High water mark */
232} drmBufDesc, *drmBufDescPtr;
233
234typedef struct _drmBufInfo {
235 int count; /**< Number of buffers described in list */
236 drmBufDescPtr list; /**< List of buffer descriptions */
237} drmBufInfo, *drmBufInfoPtr;
238
239typedef struct _drmBuf {
240 int idx; /**< Index into the master buffer list */
241 int total; /**< Buffer size */
242 int used; /**< Amount of buffer in use (for DMA) */
243 drmAddress address; /**< Address */
244} drmBuf, *drmBufPtr;
245
246/**
247 * Buffer mapping information.
248 *
249 * Used by drmMapBufs() and drmUnmapBufs() to store information about the
250 * mapped buffers.
251 */
252typedef struct _drmBufMap {
253 int count; /**< Number of buffers mapped */
254 drmBufPtr list; /**< Buffers */
255} drmBufMap, *drmBufMapPtr;
256
257typedef struct _drmLock {
258 volatile unsigned int lock;
259 char padding[60];
260 /* This is big enough for most current (and future?) architectures:
261 DEC Alpha: 32 bytes
262 Intel Merced: ?
263 Intel P5/PPro/PII/PIII: 32 bytes
264 Intel StrongARM: 32 bytes
265 Intel i386/i486: 16 bytes
266 MIPS: 32 bytes (?)
267 Motorola 68k: 16 bytes
268 Motorola PowerPC: 32 bytes
269 Sun SPARC: 32 bytes
270 */
271} drmLock, *drmLockPtr;
272
273/**
274 * Indices here refer to the offset into
275 * list in drmBufInfo
276 */
277typedef struct _drmDMAReq {
278 drm_context_t context; /**< Context handle */
279 int send_count; /**< Number of buffers to send */
280 int *send_list; /**< List of handles to buffers */
281 int *send_sizes; /**< Lengths of data to send, in bytes */
282 drmDMAFlags flags; /**< Flags */
283 int request_count; /**< Number of buffers requested */
284 int request_size; /**< Desired size of buffers requested */
285 int *request_list; /**< Buffer information */
286 int *request_sizes; /**< Minimum acceptable sizes */
287 int granted_count; /**< Number of buffers granted at this size */
288} drmDMAReq, *drmDMAReqPtr;
289
290typedef struct _drmRegion {
291 drm_handle_t handle;
292 unsigned int offset;
293 drmSize size;
294 drmAddress map;
295} drmRegion, *drmRegionPtr;
296
297typedef struct _drmTextureRegion {
298 unsigned char next;
299 unsigned char prev;
300 unsigned char in_use;
301 unsigned char padding; /**< Explicitly pad this out */
302 unsigned int age;
303} drmTextureRegion, *drmTextureRegionPtr;
304
305
306typedef enum {
307 DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */
308 DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */
Ilija Hadzicbe8802a2011-03-24 13:24:28 -0400309 /* bits 1-6 are reserved for high crtcs */
310 DRM_VBLANK_HIGH_CRTC_MASK = 0x0000003e,
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400311 DRM_VBLANK_EVENT = 0x4000000, /**< Send event instead of blocking */
Michel Dänzer5a40c042007-02-22 17:19:30 +0100312 DRM_VBLANK_FLIP = 0x8000000, /**< Scheduled buffer swap should flip */
Michel Dänzer89e323e2006-09-01 11:27:14 +0200313 DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */
Michel Dänzer84b38b62006-08-31 18:32:08 +0200314 DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000315 DRM_VBLANK_SIGNAL = 0x40000000 /* Send signal instead of blocking */
316} drmVBlankSeqType;
Ilija Hadzicbe8802a2011-03-24 13:24:28 -0400317#define DRM_VBLANK_HIGH_CRTC_SHIFT 1
Jon Smirldeed1ec2004-07-07 04:22:17 +0000318
319typedef struct _drmVBlankReq {
320 drmVBlankSeqType type;
321 unsigned int sequence;
322 unsigned long signal;
323} drmVBlankReq, *drmVBlankReqPtr;
324
325typedef struct _drmVBlankReply {
326 drmVBlankSeqType type;
327 unsigned int sequence;
328 long tval_sec;
329 long tval_usec;
330} drmVBlankReply, *drmVBlankReplyPtr;
331
332typedef union _drmVBlank {
333 drmVBlankReq request;
334 drmVBlankReply reply;
335} drmVBlank, *drmVBlankPtr;
336
337typedef struct _drmSetVersion {
338 int drm_di_major;
339 int drm_di_minor;
340 int drm_dd_major;
341 int drm_dd_minor;
342} drmSetVersion, *drmSetVersionPtr;
343
Jon Smirldeed1ec2004-07-07 04:22:17 +0000344#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
345
Dave Airliecc4d0392004-07-31 08:12:39 +0000346#define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
347#define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000348
349#if defined(__GNUC__) && (__GNUC__ >= 2)
Dave Airlie5a52e532005-08-23 04:10:50 +0000350# if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000351 /* Reflect changes here to drmP.h */
352#define DRM_CAS(lock,old,new,__ret) \
353 do { \
354 int __dummy; /* Can't mark eax as clobbered */ \
355 __asm__ __volatile__( \
356 "lock ; cmpxchg %4,%1\n\t" \
357 "setnz %0" \
358 : "=d" (__ret), \
359 "=m" (__drm_dummy_lock(lock)), \
360 "=a" (__dummy) \
361 : "2" (old), \
362 "r" (new)); \
363 } while (0)
364
365#elif defined(__alpha__)
366
Ivan Kokshaysky6feac492009-02-23 15:54:18 -0500367#define DRM_CAS(lock, old, new, ret) \
368 do { \
369 int tmp, old32; \
370 __asm__ __volatile__( \
371 " addl $31, %5, %3\n" \
372 "1: ldl_l %0, %2\n" \
373 " cmpeq %0, %3, %1\n" \
374 " beq %1, 2f\n" \
375 " mov %4, %0\n" \
376 " stl_c %0, %2\n" \
377 " beq %0, 3f\n" \
378 " mb\n" \
379 "2: cmpeq %1, 0, %1\n" \
380 ".subsection 2\n" \
381 "3: br 1b\n" \
382 ".previous" \
383 : "=&r"(tmp), "=&r"(ret), \
384 "=m"(__drm_dummy_lock(lock)), \
385 "=&r"(old32) \
386 : "r"(new), "r"(old) \
387 : "memory"); \
388 } while (0)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000389
390#elif defined(__sparc__)
391
392#define DRM_CAS(lock,old,new,__ret) \
393do { register unsigned int __old __asm("o0"); \
394 register unsigned int __new __asm("o1"); \
395 register volatile unsigned int *__lock __asm("o2"); \
396 __old = old; \
397 __new = new; \
398 __lock = (volatile unsigned int *)lock; \
399 __asm__ __volatile__( \
400 /*"cas [%2], %3, %0"*/ \
401 ".word 0xd3e29008\n\t" \
402 /*"membar #StoreStore | #StoreLoad"*/ \
403 ".word 0x8143e00a" \
404 : "=&r" (__new) \
405 : "0" (__new), \
406 "r" (__lock), \
407 "r" (__old) \
408 : "memory"); \
409 __ret = (__new != __old); \
410} while(0)
411
412#elif defined(__ia64__)
413
414#ifdef __INTEL_COMPILER
415/* this currently generates bad code (missing stop bits)... */
416#include <ia64intrin.h>
417
418#define DRM_CAS(lock,old,new,__ret) \
419 do { \
420 unsigned long __result, __old = (old) & 0xffffffff; \
421 __mf(); \
422 __result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\
423 __ret = (__result) != (__old); \
424/* __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
425 (old), (new)) \
426 != (old)); */\
427 } while (0)
428
429#else
430#define DRM_CAS(lock,old,new,__ret) \
431 do { \
432 unsigned int __result, __old = (old); \
433 __asm__ __volatile__( \
434 "mf\n" \
435 "mov ar.ccv=%2\n" \
436 ";;\n" \
437 "cmpxchg4.acq %0=%1,%3,ar.ccv" \
438 : "=r" (__result), "=m" (__drm_dummy_lock(lock)) \
439 : "r" ((unsigned long)__old), "r" (new) \
440 : "memory"); \
441 __ret = (__result) != (__old); \
442 } while (0)
443
444#endif
445
446#elif defined(__powerpc__)
447
448#define DRM_CAS(lock,old,new,__ret) \
449 do { \
450 __asm__ __volatile__( \
451 "sync;" \
452 "0: lwarx %0,0,%1;" \
453 " xor. %0,%3,%0;" \
454 " bne 1f;" \
455 " stwcx. %2,0,%1;" \
456 " bne- 0b;" \
457 "1: " \
458 "sync;" \
459 : "=&r"(__ret) \
460 : "r"(lock), "r"(new), "r"(old) \
461 : "cr0", "memory"); \
462 } while (0)
463
464#endif /* architecture */
465#endif /* __GNUC__ >= 2 */
466
467#ifndef DRM_CAS
468#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
469#endif
470
Ivan Kokshaysky6feac492009-02-23 15:54:18 -0500471#if defined(__alpha__)
472#define DRM_CAS_RESULT(_result) long _result
473#elif defined(__powerpc__)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000474#define DRM_CAS_RESULT(_result) int _result
475#else
476#define DRM_CAS_RESULT(_result) char _result
477#endif
478
479#define DRM_LIGHT_LOCK(fd,lock,context) \
480 do { \
481 DRM_CAS_RESULT(__ret); \
482 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
483 if (__ret) drmGetLock(fd,context,0); \
484 } while(0)
485
486 /* This one counts fast locks -- for
487 benchmarking only. */
488#define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \
489 do { \
490 DRM_CAS_RESULT(__ret); \
491 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
492 if (__ret) drmGetLock(fd,context,0); \
493 else ++count; \
494 } while(0)
495
496#define DRM_LOCK(fd,lock,context,flags) \
497 do { \
498 if (flags) drmGetLock(fd,context,flags); \
499 else DRM_LIGHT_LOCK(fd,lock,context); \
500 } while(0)
501
502#define DRM_UNLOCK(fd,lock,context) \
503 do { \
504 DRM_CAS_RESULT(__ret); \
505 DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \
506 if (__ret) drmUnlock(fd,context); \
507 } while(0)
508
509 /* Simple spin locks */
510#define DRM_SPINLOCK(spin,val) \
511 do { \
512 DRM_CAS_RESULT(__ret); \
513 do { \
514 DRM_CAS(spin,0,val,__ret); \
515 if (__ret) while ((spin)->lock); \
516 } while (__ret); \
517 } while(0)
518
519#define DRM_SPINLOCK_TAKE(spin,val) \
520 do { \
521 DRM_CAS_RESULT(__ret); \
522 int cur; \
523 do { \
524 cur = (*spin).lock; \
525 DRM_CAS(spin,cur,val,__ret); \
526 } while (__ret); \
527 } while(0)
528
529#define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \
530 do { \
531 int __i; \
532 __ret = 1; \
533 for (__i = 0; __ret && __i < count; __i++) { \
534 DRM_CAS(spin,0,val,__ret); \
535 if (__ret) for (;__i < count && (spin)->lock; __i++); \
536 } \
537 } while(0)
538
539#define DRM_SPINUNLOCK(spin,val) \
540 do { \
541 DRM_CAS_RESULT(__ret); \
542 if ((*spin).lock == val) { /* else server stole lock */ \
543 do { \
544 DRM_CAS(spin,val,0,__ret); \
545 } while (__ret); \
546 } \
547 } while(0)
548
Thomas Hellstrome181f592006-08-28 09:49:09 +0200549
550
Jon Smirldeed1ec2004-07-07 04:22:17 +0000551/* General user-level programmer's API: unprivileged */
552extern int drmAvailable(void);
553extern int drmOpen(const char *name, const char *busid);
Jesse Barnes731cd552008-12-17 10:09:49 -0800554extern int drmOpenControl(int minor);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000555extern int drmClose(int fd);
556extern drmVersionPtr drmGetVersion(int fd);
557extern drmVersionPtr drmGetLibVersion(int fd);
Ben Skeggs5c6c6912011-02-21 11:27:19 +1000558extern int drmGetCap(int fd, uint64_t capability, uint64_t *value);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000559extern void drmFreeVersion(drmVersionPtr);
560extern int drmGetMagic(int fd, drm_magic_t * magic);
561extern char *drmGetBusid(int fd);
562extern int drmGetInterruptFromBusID(int fd, int busnum, int devnum,
563 int funcnum);
564extern int drmGetMap(int fd, int idx, drm_handle_t *offset,
565 drmSize *size, drmMapType *type,
566 drmMapFlags *flags, drm_handle_t *handle,
567 int *mtrr);
568extern int drmGetClient(int fd, int idx, int *auth, int *pid,
569 int *uid, unsigned long *magic,
570 unsigned long *iocs);
571extern int drmGetStats(int fd, drmStatsT *stats);
572extern int drmSetInterfaceVersion(int fd, drmSetVersion *version);
573extern int drmCommandNone(int fd, unsigned long drmCommandIndex);
574extern int drmCommandRead(int fd, unsigned long drmCommandIndex,
575 void *data, unsigned long size);
576extern int drmCommandWrite(int fd, unsigned long drmCommandIndex,
577 void *data, unsigned long size);
578extern int drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
579 void *data, unsigned long size);
580
581/* General user-level programmer's API: X server (root) only */
582extern void drmFreeBusid(const char *busid);
583extern int drmSetBusid(int fd, const char *busid);
584extern int drmAuthMagic(int fd, drm_magic_t magic);
585extern int drmAddMap(int fd,
586 drm_handle_t offset,
587 drmSize size,
588 drmMapType type,
589 drmMapFlags flags,
590 drm_handle_t * handle);
591extern int drmRmMap(int fd, drm_handle_t handle);
592extern int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
593 drm_handle_t handle);
594
595extern int drmAddBufs(int fd, int count, int size,
596 drmBufDescFlags flags,
597 int agp_offset);
598extern int drmMarkBufs(int fd, double low, double high);
599extern int drmCreateContext(int fd, drm_context_t * handle);
600extern int drmSetContextFlags(int fd, drm_context_t context,
601 drm_context_tFlags flags);
602extern int drmGetContextFlags(int fd, drm_context_t context,
603 drm_context_tFlagsPtr flags);
604extern int drmAddContextTag(int fd, drm_context_t context, void *tag);
605extern int drmDelContextTag(int fd, drm_context_t context);
606extern void *drmGetContextTag(int fd, drm_context_t context);
607extern drm_context_t * drmGetReservedContextList(int fd, int *count);
608extern void drmFreeReservedContextList(drm_context_t *);
609extern int drmSwitchToContext(int fd, drm_context_t context);
610extern int drmDestroyContext(int fd, drm_context_t handle);
611extern int drmCreateDrawable(int fd, drm_drawable_t * handle);
612extern int drmDestroyDrawable(int fd, drm_drawable_t handle);
Michel Dänzer29598e52006-08-22 16:40:07 +0200613extern int drmUpdateDrawableInfo(int fd, drm_drawable_t handle,
614 drm_drawable_info_type_t type,
615 unsigned int num, void *data);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000616extern int drmCtlInstHandler(int fd, int irq);
617extern int drmCtlUninstHandler(int fd);
Damien Lespiauddbbdb12013-09-03 15:34:41 +0100618extern int drmSetClientCap(int fd, uint64_t capability,
619 uint64_t value);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000620
621/* General user-level programmer's API: authenticated client and/or X */
622extern int drmMap(int fd,
623 drm_handle_t handle,
624 drmSize size,
625 drmAddressPtr address);
626extern int drmUnmap(drmAddress address, drmSize size);
627extern drmBufInfoPtr drmGetBufInfo(int fd);
628extern drmBufMapPtr drmMapBufs(int fd);
629extern int drmUnmapBufs(drmBufMapPtr bufs);
630extern int drmDMA(int fd, drmDMAReqPtr request);
631extern int drmFreeBufs(int fd, int count, int *list);
632extern int drmGetLock(int fd,
633 drm_context_t context,
634 drmLockFlags flags);
635extern int drmUnlock(int fd, drm_context_t context);
636extern int drmFinish(int fd, int context, drmLockFlags flags);
637extern int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id,
638 drm_handle_t * handle);
639
640/* AGP/GART support: X server (root) only */
641extern int drmAgpAcquire(int fd);
642extern int drmAgpRelease(int fd);
643extern int drmAgpEnable(int fd, unsigned long mode);
644extern int drmAgpAlloc(int fd, unsigned long size,
645 unsigned long type, unsigned long *address,
Dave Airlie645e2d42005-11-29 09:19:20 +0000646 drm_handle_t *handle);
647extern int drmAgpFree(int fd, drm_handle_t handle);
648extern int drmAgpBind(int fd, drm_handle_t handle,
Jon Smirldeed1ec2004-07-07 04:22:17 +0000649 unsigned long offset);
Dave Airlie645e2d42005-11-29 09:19:20 +0000650extern int drmAgpUnbind(int fd, drm_handle_t handle);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000651
652/* AGP/GART info: authenticated client and/or X */
653extern int drmAgpVersionMajor(int fd);
654extern int drmAgpVersionMinor(int fd);
655extern unsigned long drmAgpGetMode(int fd);
656extern unsigned long drmAgpBase(int fd); /* Physical location */
657extern unsigned long drmAgpSize(int fd); /* Bytes */
658extern unsigned long drmAgpMemoryUsed(int fd);
659extern unsigned long drmAgpMemoryAvail(int fd);
660extern unsigned int drmAgpVendorId(int fd);
661extern unsigned int drmAgpDeviceId(int fd);
662
663/* PCI scatter/gather support: X server (root) only */
664extern int drmScatterGatherAlloc(int fd, unsigned long size,
Dave Airlie645e2d42005-11-29 09:19:20 +0000665 drm_handle_t *handle);
666extern int drmScatterGatherFree(int fd, drm_handle_t handle);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000667
668extern int drmWaitVBlank(int fd, drmVBlankPtr vbl);
669
670/* Support routines */
Dave Airlie79038752006-11-08 15:08:09 +1100671extern void drmSetServerInfo(drmServerInfoPtr info);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000672extern int drmError(int err, const char *label);
673extern void *drmMalloc(int size);
674extern void drmFree(void *pt);
675
676/* Hash table routines */
677extern void *drmHashCreate(void);
678extern int drmHashDestroy(void *t);
679extern int drmHashLookup(void *t, unsigned long key, void **value);
680extern int drmHashInsert(void *t, unsigned long key, void *value);
681extern int drmHashDelete(void *t, unsigned long key);
682extern int drmHashFirst(void *t, unsigned long *key, void **value);
683extern int drmHashNext(void *t, unsigned long *key, void **value);
684
685/* PRNG routines */
686extern void *drmRandomCreate(unsigned long seed);
687extern int drmRandomDestroy(void *state);
688extern unsigned long drmRandom(void *state);
689extern double drmRandomDouble(void *state);
690
691/* Skip list routines */
692
693extern void *drmSLCreate(void);
694extern int drmSLDestroy(void *l);
695extern int drmSLLookup(void *l, unsigned long key, void **value);
696extern int drmSLInsert(void *l, unsigned long key, void *value);
697extern int drmSLDelete(void *l, unsigned long key);
698extern int drmSLNext(void *l, unsigned long *key, void **value);
699extern int drmSLFirst(void *l, unsigned long *key, void **value);
700extern void drmSLDump(void *l);
701extern int drmSLLookupNeighbors(void *l, unsigned long key,
702 unsigned long *prev_key, void **prev_value,
703 unsigned long *next_key, void **next_value);
704
Dave Airlied51e1bb2006-11-09 08:55:58 +1100705extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
706extern void drmCloseOnce(int fd);
Thierry Reding44b08c02014-01-22 12:06:51 +0100707extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
Dave Airlied51e1bb2006-11-09 08:55:58 +1100708
Jesse Barnes731cd552008-12-17 10:09:49 -0800709extern int drmSetMaster(int fd);
710extern int drmDropMaster(int fd);
711
Jesse Barnes14f59582009-12-03 14:20:51 -0800712#define DRM_EVENT_CONTEXT_VERSION 2
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400713
714typedef struct _drmEventContext {
715
716 /* This struct is versioned so we can add more pointers if we
717 * add more events. */
718 int version;
719
720 void (*vblank_handler)(int fd,
721 unsigned int sequence,
722 unsigned int tv_sec,
723 unsigned int tv_usec,
724 void *user_data);
725
Jesse Barnes53addc52009-12-03 14:17:26 -0800726 void (*page_flip_handler)(int fd,
727 unsigned int sequence,
728 unsigned int tv_sec,
729 unsigned int tv_usec,
730 void *user_data);
731
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400732} drmEventContext, *drmEventContextPtr;
733
734extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
735
Kristian Høgsberg22d46662009-11-23 20:51:34 -0500736extern char *drmGetDeviceNameFromFd(int fd);
737
Dave Airliecc0a1452012-07-14 09:52:17 +0000738extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd);
739extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle);
740
Tapani Pällicfee5212011-09-23 14:17:42 +0300741#if defined(__cplusplus) || defined(c_plusplus)
742}
743#endif
744
Jon Smirldeed1ec2004-07-07 04:22:17 +0000745#endif