blob: 481d882aa01719c805b12264c1e9bb683e917fa3 [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älli1c205742015-08-07 10:37:56 +030042#if defined(__cplusplus)
Tapani Pällicfee5212011-09-23 14:17:42 +030043extern "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
Jonathan Grayfc083322015-07-21 03:12:56 +100079#ifdef __OpenBSD__
80#define DRM_DIR_NAME "/dev"
81#define DRM_DEV_NAME "%s/drm%d"
82#define DRM_CONTROL_DEV_NAME "%s/drmC%d"
83#define DRM_RENDER_DEV_NAME "%s/drmR%d"
84#else
Jon Smirldeed1ec2004-07-07 04:22:17 +000085#define DRM_DIR_NAME "/dev/dri"
86#define DRM_DEV_NAME "%s/card%d"
Jesse Barnes731cd552008-12-17 10:09:49 -080087#define DRM_CONTROL_DEV_NAME "%s/controlD%d"
Frank Binns0c5aaee2015-01-14 14:07:51 +000088#define DRM_RENDER_DEV_NAME "%s/renderD%d"
Jon Smirldeed1ec2004-07-07 04:22:17 +000089#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */
Jonathan Grayfc083322015-07-21 03:12:56 +100090#endif
Jon Smirldeed1ec2004-07-07 04:22:17 +000091
92#define DRM_ERR_NO_DEVICE (-1001)
93#define DRM_ERR_NO_ACCESS (-1002)
94#define DRM_ERR_NOT_ROOT (-1003)
95#define DRM_ERR_INVALID (-1004)
96#define DRM_ERR_NO_FD (-1005)
97
98#define DRM_AGP_NO_HANDLE 0
99
100typedef unsigned int drmSize, *drmSizePtr; /**< For mapped regions */
101typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */
102
Keith Packardcb4bc8e2014-01-12 10:32:57 -0800103#if (__GNUC__ >= 3)
104#define DRM_PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a)))
105#else
106#define DRM_PRINTFLIKE(f, a)
107#endif
108
Dave Airlie79038752006-11-08 15:08:09 +1100109typedef struct _drmServerInfo {
Keith Packardcb4bc8e2014-01-12 10:32:57 -0800110 int (*debug_print)(const char *format, va_list ap) DRM_PRINTFLIKE(1,0);
Dave Airlie79038752006-11-08 15:08:09 +1100111 int (*load_module)(const char *name);
112 void (*get_perms)(gid_t *, mode_t *);
113} drmServerInfo, *drmServerInfoPtr;
114
115typedef struct drmHashEntry {
116 int fd;
117 void (*f)(int, void *, void *);
118 void *tagTable;
119} drmHashEntry;
120
Jesse Barnes731cd552008-12-17 10:09:49 -0800121extern int drmIoctl(int fd, unsigned long request, void *arg);
Dave Airlie79038752006-11-08 15:08:09 +1100122extern void *drmGetHashTable(void);
123extern drmHashEntry *drmGetEntry(int fd);
124
Jon Smirldeed1ec2004-07-07 04:22:17 +0000125/**
126 * Driver version information.
127 *
128 * \sa drmGetVersion() and drmSetVersion().
129 */
130typedef struct _drmVersion {
131 int version_major; /**< Major version */
132 int version_minor; /**< Minor version */
133 int version_patchlevel; /**< Patch level */
134 int name_len; /**< Length of name buffer */
135 char *name; /**< Name of driver */
136 int date_len; /**< Length of date buffer */
137 char *date; /**< User-space buffer to hold date */
138 int desc_len; /**< Length of desc buffer */
139 char *desc; /**< User-space buffer to hold desc */
140} drmVersion, *drmVersionPtr;
141
142typedef struct _drmStats {
143 unsigned long count; /**< Number of data */
144 struct {
145 unsigned long value; /**< Value from kernel */
146 const char *long_format; /**< Suggested format for long_name */
147 const char *long_name; /**< Long name for value */
148 const char *rate_format; /**< Suggested format for rate_name */
149 const char *rate_name; /**< Short name for value per second */
150 int isvalue; /**< True if value (vs. counter) */
151 const char *mult_names; /**< Multiplier names (e.g., "KGM") */
152 int mult; /**< Multiplier value (e.g., 1024) */
153 int verbose; /**< Suggest only in verbose output */
154 } data[15];
155} drmStatsT;
156
157
158 /* All of these enums *MUST* match with the
159 kernel implementation -- so do *NOT*
160 change them! (The drmlib implementation
161 will just copy the flags instead of
162 translating them.) */
163typedef enum {
164 DRM_FRAME_BUFFER = 0, /**< WC, no caching, no core dump */
165 DRM_REGISTERS = 1, /**< no caching, no core dump */
166 DRM_SHM = 2, /**< shared, cached */
167 DRM_AGP = 3, /**< AGP/GART */
Felix Kuehlinged165a22005-01-01 20:03:15 +0000168 DRM_SCATTER_GATHER = 4, /**< PCI scatter/gather */
169 DRM_CONSISTENT = 5 /**< PCI consistent */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000170} drmMapType;
171
172typedef enum {
173 DRM_RESTRICTED = 0x0001, /**< Cannot be mapped to client-virtual */
174 DRM_READ_ONLY = 0x0002, /**< Read-only in client-virtual */
175 DRM_LOCKED = 0x0004, /**< Physical pages locked */
176 DRM_KERNEL = 0x0008, /**< Kernel requires access */
177 DRM_WRITE_COMBINING = 0x0010, /**< Use write-combining, if available */
178 DRM_CONTAINS_LOCK = 0x0020, /**< SHM page that contains lock */
179 DRM_REMOVABLE = 0x0040 /**< Removable mapping */
180} drmMapFlags;
181
182/**
183 * \warning These values *MUST* match drm.h
184 */
185typedef enum {
186 /** \name Flags for DMA buffer dispatch */
187 /*@{*/
188 DRM_DMA_BLOCK = 0x01, /**<
189 * Block until buffer dispatched.
190 *
191 * \note the buffer may not yet have been
192 * processed by the hardware -- getting a
193 * hardware lock with the hardware quiescent
194 * will ensure that the buffer has been
195 * processed.
196 */
197 DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
198 DRM_DMA_PRIORITY = 0x04, /**< High priority dispatch */
199 /*@}*/
200
201 /** \name Flags for DMA buffer request */
202 /*@{*/
203 DRM_DMA_WAIT = 0x10, /**< Wait for free buffers */
204 DRM_DMA_SMALLER_OK = 0x20, /**< Smaller-than-requested buffers OK */
205 DRM_DMA_LARGER_OK = 0x40 /**< Larger-than-requested buffers OK */
206 /*@}*/
207} drmDMAFlags;
208
209typedef enum {
210 DRM_PAGE_ALIGN = 0x01,
211 DRM_AGP_BUFFER = 0x02,
Dave Airlie354dd172005-01-16 05:40:12 +0000212 DRM_SG_BUFFER = 0x04,
George Sapountzisf3deef72006-10-02 05:46:42 +0300213 DRM_FB_BUFFER = 0x08,
214 DRM_PCI_BUFFER_RO = 0x10
Jon Smirldeed1ec2004-07-07 04:22:17 +0000215} drmBufDescFlags;
216
217typedef enum {
218 DRM_LOCK_READY = 0x01, /**< Wait until hardware is ready for DMA */
219 DRM_LOCK_QUIESCENT = 0x02, /**< Wait until hardware quiescent */
220 DRM_LOCK_FLUSH = 0x04, /**< Flush this context's DMA queue first */
221 DRM_LOCK_FLUSH_ALL = 0x08, /**< Flush all DMA queues first */
222 /* These *HALT* flags aren't supported yet
223 -- they will be used to support the
224 full-screen DGA-like mode. */
225 DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
226 DRM_HALT_CUR_QUEUES = 0x20 /**< Halt all current queues */
227} drmLockFlags;
228
229typedef enum {
230 DRM_CONTEXT_PRESERVED = 0x01, /**< This context is preserved and
231 never swapped. */
232 DRM_CONTEXT_2DONLY = 0x02 /**< This context is for 2D rendering only. */
233} drm_context_tFlags, *drm_context_tFlagsPtr;
234
235typedef struct _drmBufDesc {
236 int count; /**< Number of buffers of this size */
237 int size; /**< Size in bytes */
238 int low_mark; /**< Low water mark */
239 int high_mark; /**< High water mark */
240} drmBufDesc, *drmBufDescPtr;
241
242typedef struct _drmBufInfo {
243 int count; /**< Number of buffers described in list */
244 drmBufDescPtr list; /**< List of buffer descriptions */
245} drmBufInfo, *drmBufInfoPtr;
246
247typedef struct _drmBuf {
248 int idx; /**< Index into the master buffer list */
249 int total; /**< Buffer size */
250 int used; /**< Amount of buffer in use (for DMA) */
251 drmAddress address; /**< Address */
252} drmBuf, *drmBufPtr;
253
254/**
255 * Buffer mapping information.
256 *
257 * Used by drmMapBufs() and drmUnmapBufs() to store information about the
258 * mapped buffers.
259 */
260typedef struct _drmBufMap {
261 int count; /**< Number of buffers mapped */
262 drmBufPtr list; /**< Buffers */
263} drmBufMap, *drmBufMapPtr;
264
265typedef struct _drmLock {
266 volatile unsigned int lock;
267 char padding[60];
268 /* This is big enough for most current (and future?) architectures:
269 DEC Alpha: 32 bytes
270 Intel Merced: ?
271 Intel P5/PPro/PII/PIII: 32 bytes
272 Intel StrongARM: 32 bytes
273 Intel i386/i486: 16 bytes
274 MIPS: 32 bytes (?)
275 Motorola 68k: 16 bytes
276 Motorola PowerPC: 32 bytes
277 Sun SPARC: 32 bytes
278 */
279} drmLock, *drmLockPtr;
280
281/**
282 * Indices here refer to the offset into
283 * list in drmBufInfo
284 */
285typedef struct _drmDMAReq {
286 drm_context_t context; /**< Context handle */
287 int send_count; /**< Number of buffers to send */
288 int *send_list; /**< List of handles to buffers */
289 int *send_sizes; /**< Lengths of data to send, in bytes */
290 drmDMAFlags flags; /**< Flags */
291 int request_count; /**< Number of buffers requested */
292 int request_size; /**< Desired size of buffers requested */
293 int *request_list; /**< Buffer information */
294 int *request_sizes; /**< Minimum acceptable sizes */
295 int granted_count; /**< Number of buffers granted at this size */
296} drmDMAReq, *drmDMAReqPtr;
297
298typedef struct _drmRegion {
299 drm_handle_t handle;
300 unsigned int offset;
301 drmSize size;
302 drmAddress map;
303} drmRegion, *drmRegionPtr;
304
305typedef struct _drmTextureRegion {
306 unsigned char next;
307 unsigned char prev;
308 unsigned char in_use;
309 unsigned char padding; /**< Explicitly pad this out */
310 unsigned int age;
311} drmTextureRegion, *drmTextureRegionPtr;
312
313
314typedef enum {
315 DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */
316 DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */
Ilija Hadzicbe8802a2011-03-24 13:24:28 -0400317 /* bits 1-6 are reserved for high crtcs */
318 DRM_VBLANK_HIGH_CRTC_MASK = 0x0000003e,
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400319 DRM_VBLANK_EVENT = 0x4000000, /**< Send event instead of blocking */
Michel Dänzer5a40c042007-02-22 17:19:30 +0100320 DRM_VBLANK_FLIP = 0x8000000, /**< Scheduled buffer swap should flip */
Michel Dänzer89e323e2006-09-01 11:27:14 +0200321 DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */
Michel Dänzer84b38b62006-08-31 18:32:08 +0200322 DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000323 DRM_VBLANK_SIGNAL = 0x40000000 /* Send signal instead of blocking */
324} drmVBlankSeqType;
Ilija Hadzicbe8802a2011-03-24 13:24:28 -0400325#define DRM_VBLANK_HIGH_CRTC_SHIFT 1
Jon Smirldeed1ec2004-07-07 04:22:17 +0000326
327typedef struct _drmVBlankReq {
328 drmVBlankSeqType type;
329 unsigned int sequence;
330 unsigned long signal;
331} drmVBlankReq, *drmVBlankReqPtr;
332
333typedef struct _drmVBlankReply {
334 drmVBlankSeqType type;
335 unsigned int sequence;
336 long tval_sec;
337 long tval_usec;
338} drmVBlankReply, *drmVBlankReplyPtr;
339
340typedef union _drmVBlank {
341 drmVBlankReq request;
342 drmVBlankReply reply;
343} drmVBlank, *drmVBlankPtr;
344
345typedef struct _drmSetVersion {
346 int drm_di_major;
347 int drm_di_minor;
348 int drm_dd_major;
349 int drm_dd_minor;
350} drmSetVersion, *drmSetVersionPtr;
351
Jon Smirldeed1ec2004-07-07 04:22:17 +0000352#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
353
Dave Airliecc4d0392004-07-31 08:12:39 +0000354#define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
355#define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
Jon Smirldeed1ec2004-07-07 04:22:17 +0000356
357#if defined(__GNUC__) && (__GNUC__ >= 2)
Dave Airlie5a52e532005-08-23 04:10:50 +0000358# if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000359 /* Reflect changes here to drmP.h */
360#define DRM_CAS(lock,old,new,__ret) \
361 do { \
362 int __dummy; /* Can't mark eax as clobbered */ \
363 __asm__ __volatile__( \
364 "lock ; cmpxchg %4,%1\n\t" \
365 "setnz %0" \
366 : "=d" (__ret), \
367 "=m" (__drm_dummy_lock(lock)), \
368 "=a" (__dummy) \
369 : "2" (old), \
370 "r" (new)); \
371 } while (0)
372
373#elif defined(__alpha__)
374
Ivan Kokshaysky6feac492009-02-23 15:54:18 -0500375#define DRM_CAS(lock, old, new, ret) \
376 do { \
377 int tmp, old32; \
378 __asm__ __volatile__( \
379 " addl $31, %5, %3\n" \
380 "1: ldl_l %0, %2\n" \
381 " cmpeq %0, %3, %1\n" \
382 " beq %1, 2f\n" \
383 " mov %4, %0\n" \
384 " stl_c %0, %2\n" \
385 " beq %0, 3f\n" \
386 " mb\n" \
387 "2: cmpeq %1, 0, %1\n" \
388 ".subsection 2\n" \
389 "3: br 1b\n" \
390 ".previous" \
391 : "=&r"(tmp), "=&r"(ret), \
392 "=m"(__drm_dummy_lock(lock)), \
393 "=&r"(old32) \
394 : "r"(new), "r"(old) \
395 : "memory"); \
396 } while (0)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000397
398#elif defined(__sparc__)
399
400#define DRM_CAS(lock,old,new,__ret) \
401do { register unsigned int __old __asm("o0"); \
402 register unsigned int __new __asm("o1"); \
403 register volatile unsigned int *__lock __asm("o2"); \
404 __old = old; \
405 __new = new; \
406 __lock = (volatile unsigned int *)lock; \
407 __asm__ __volatile__( \
408 /*"cas [%2], %3, %0"*/ \
409 ".word 0xd3e29008\n\t" \
410 /*"membar #StoreStore | #StoreLoad"*/ \
411 ".word 0x8143e00a" \
412 : "=&r" (__new) \
413 : "0" (__new), \
414 "r" (__lock), \
415 "r" (__old) \
416 : "memory"); \
417 __ret = (__new != __old); \
418} while(0)
419
420#elif defined(__ia64__)
421
422#ifdef __INTEL_COMPILER
423/* this currently generates bad code (missing stop bits)... */
424#include <ia64intrin.h>
425
426#define DRM_CAS(lock,old,new,__ret) \
427 do { \
428 unsigned long __result, __old = (old) & 0xffffffff; \
429 __mf(); \
430 __result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\
431 __ret = (__result) != (__old); \
432/* __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \
433 (old), (new)) \
434 != (old)); */\
435 } while (0)
436
437#else
438#define DRM_CAS(lock,old,new,__ret) \
439 do { \
440 unsigned int __result, __old = (old); \
441 __asm__ __volatile__( \
442 "mf\n" \
443 "mov ar.ccv=%2\n" \
444 ";;\n" \
445 "cmpxchg4.acq %0=%1,%3,ar.ccv" \
446 : "=r" (__result), "=m" (__drm_dummy_lock(lock)) \
447 : "r" ((unsigned long)__old), "r" (new) \
448 : "memory"); \
449 __ret = (__result) != (__old); \
450 } while (0)
451
452#endif
453
454#elif defined(__powerpc__)
455
456#define DRM_CAS(lock,old,new,__ret) \
457 do { \
458 __asm__ __volatile__( \
459 "sync;" \
460 "0: lwarx %0,0,%1;" \
461 " xor. %0,%3,%0;" \
462 " bne 1f;" \
463 " stwcx. %2,0,%1;" \
464 " bne- 0b;" \
465 "1: " \
466 "sync;" \
467 : "=&r"(__ret) \
468 : "r"(lock), "r"(new), "r"(old) \
469 : "cr0", "memory"); \
470 } while (0)
471
472#endif /* architecture */
473#endif /* __GNUC__ >= 2 */
474
475#ifndef DRM_CAS
476#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */
477#endif
478
Ivan Kokshaysky6feac492009-02-23 15:54:18 -0500479#if defined(__alpha__)
480#define DRM_CAS_RESULT(_result) long _result
481#elif defined(__powerpc__)
Jon Smirldeed1ec2004-07-07 04:22:17 +0000482#define DRM_CAS_RESULT(_result) int _result
483#else
484#define DRM_CAS_RESULT(_result) char _result
485#endif
486
487#define DRM_LIGHT_LOCK(fd,lock,context) \
488 do { \
489 DRM_CAS_RESULT(__ret); \
490 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
491 if (__ret) drmGetLock(fd,context,0); \
492 } while(0)
493
494 /* This one counts fast locks -- for
495 benchmarking only. */
496#define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \
497 do { \
498 DRM_CAS_RESULT(__ret); \
499 DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \
500 if (__ret) drmGetLock(fd,context,0); \
501 else ++count; \
502 } while(0)
503
504#define DRM_LOCK(fd,lock,context,flags) \
505 do { \
506 if (flags) drmGetLock(fd,context,flags); \
507 else DRM_LIGHT_LOCK(fd,lock,context); \
508 } while(0)
509
510#define DRM_UNLOCK(fd,lock,context) \
511 do { \
512 DRM_CAS_RESULT(__ret); \
513 DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \
514 if (__ret) drmUnlock(fd,context); \
515 } while(0)
516
517 /* Simple spin locks */
518#define DRM_SPINLOCK(spin,val) \
519 do { \
520 DRM_CAS_RESULT(__ret); \
521 do { \
522 DRM_CAS(spin,0,val,__ret); \
523 if (__ret) while ((spin)->lock); \
524 } while (__ret); \
525 } while(0)
526
527#define DRM_SPINLOCK_TAKE(spin,val) \
528 do { \
529 DRM_CAS_RESULT(__ret); \
530 int cur; \
531 do { \
532 cur = (*spin).lock; \
533 DRM_CAS(spin,cur,val,__ret); \
534 } while (__ret); \
535 } while(0)
536
537#define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \
538 do { \
539 int __i; \
540 __ret = 1; \
541 for (__i = 0; __ret && __i < count; __i++) { \
542 DRM_CAS(spin,0,val,__ret); \
543 if (__ret) for (;__i < count && (spin)->lock; __i++); \
544 } \
545 } while(0)
546
547#define DRM_SPINUNLOCK(spin,val) \
548 do { \
549 DRM_CAS_RESULT(__ret); \
550 if ((*spin).lock == val) { /* else server stole lock */ \
551 do { \
552 DRM_CAS(spin,val,0,__ret); \
553 } while (__ret); \
554 } \
555 } while(0)
556
Thomas Hellstrome181f592006-08-28 09:49:09 +0200557
558
Jon Smirldeed1ec2004-07-07 04:22:17 +0000559/* General user-level programmer's API: unprivileged */
560extern int drmAvailable(void);
561extern int drmOpen(const char *name, const char *busid);
Jammy Zhouf1adc4b2015-02-11 12:40:51 +0800562
563#define DRM_NODE_PRIMARY 0
564#define DRM_NODE_CONTROL 1
565#define DRM_NODE_RENDER 2
Emil Velikovb556ea12015-08-17 11:09:06 +0800566#define DRM_NODE_MAX 3
567
Jammy Zhouf1adc4b2015-02-11 12:40:51 +0800568extern int drmOpenWithType(const char *name, const char *busid,
569 int type);
570
571extern int drmOpenControl(int minor);
Frank Binns0c5aaee2015-01-14 14:07:51 +0000572extern int drmOpenRender(int minor);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000573extern int drmClose(int fd);
574extern drmVersionPtr drmGetVersion(int fd);
575extern drmVersionPtr drmGetLibVersion(int fd);
Ben Skeggs5c6c6912011-02-21 11:27:19 +1000576extern int drmGetCap(int fd, uint64_t capability, uint64_t *value);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000577extern void drmFreeVersion(drmVersionPtr);
578extern int drmGetMagic(int fd, drm_magic_t * magic);
579extern char *drmGetBusid(int fd);
580extern int drmGetInterruptFromBusID(int fd, int busnum, int devnum,
581 int funcnum);
582extern int drmGetMap(int fd, int idx, drm_handle_t *offset,
583 drmSize *size, drmMapType *type,
584 drmMapFlags *flags, drm_handle_t *handle,
585 int *mtrr);
586extern int drmGetClient(int fd, int idx, int *auth, int *pid,
587 int *uid, unsigned long *magic,
588 unsigned long *iocs);
589extern int drmGetStats(int fd, drmStatsT *stats);
590extern int drmSetInterfaceVersion(int fd, drmSetVersion *version);
591extern int drmCommandNone(int fd, unsigned long drmCommandIndex);
592extern int drmCommandRead(int fd, unsigned long drmCommandIndex,
593 void *data, unsigned long size);
594extern int drmCommandWrite(int fd, unsigned long drmCommandIndex,
595 void *data, unsigned long size);
596extern int drmCommandWriteRead(int fd, unsigned long drmCommandIndex,
597 void *data, unsigned long size);
598
599/* General user-level programmer's API: X server (root) only */
600extern void drmFreeBusid(const char *busid);
601extern int drmSetBusid(int fd, const char *busid);
602extern int drmAuthMagic(int fd, drm_magic_t magic);
603extern int drmAddMap(int fd,
604 drm_handle_t offset,
605 drmSize size,
606 drmMapType type,
607 drmMapFlags flags,
608 drm_handle_t * handle);
609extern int drmRmMap(int fd, drm_handle_t handle);
610extern int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id,
611 drm_handle_t handle);
612
613extern int drmAddBufs(int fd, int count, int size,
614 drmBufDescFlags flags,
615 int agp_offset);
616extern int drmMarkBufs(int fd, double low, double high);
617extern int drmCreateContext(int fd, drm_context_t * handle);
618extern int drmSetContextFlags(int fd, drm_context_t context,
619 drm_context_tFlags flags);
620extern int drmGetContextFlags(int fd, drm_context_t context,
621 drm_context_tFlagsPtr flags);
622extern int drmAddContextTag(int fd, drm_context_t context, void *tag);
623extern int drmDelContextTag(int fd, drm_context_t context);
624extern void *drmGetContextTag(int fd, drm_context_t context);
625extern drm_context_t * drmGetReservedContextList(int fd, int *count);
626extern void drmFreeReservedContextList(drm_context_t *);
627extern int drmSwitchToContext(int fd, drm_context_t context);
628extern int drmDestroyContext(int fd, drm_context_t handle);
629extern int drmCreateDrawable(int fd, drm_drawable_t * handle);
630extern int drmDestroyDrawable(int fd, drm_drawable_t handle);
Michel Dänzer29598e52006-08-22 16:40:07 +0200631extern int drmUpdateDrawableInfo(int fd, drm_drawable_t handle,
632 drm_drawable_info_type_t type,
633 unsigned int num, void *data);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000634extern int drmCtlInstHandler(int fd, int irq);
635extern int drmCtlUninstHandler(int fd);
Damien Lespiauddbbdb12013-09-03 15:34:41 +0100636extern int drmSetClientCap(int fd, uint64_t capability,
637 uint64_t value);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000638
639/* General user-level programmer's API: authenticated client and/or X */
640extern int drmMap(int fd,
641 drm_handle_t handle,
642 drmSize size,
643 drmAddressPtr address);
644extern int drmUnmap(drmAddress address, drmSize size);
645extern drmBufInfoPtr drmGetBufInfo(int fd);
646extern drmBufMapPtr drmMapBufs(int fd);
647extern int drmUnmapBufs(drmBufMapPtr bufs);
648extern int drmDMA(int fd, drmDMAReqPtr request);
649extern int drmFreeBufs(int fd, int count, int *list);
650extern int drmGetLock(int fd,
651 drm_context_t context,
652 drmLockFlags flags);
653extern int drmUnlock(int fd, drm_context_t context);
654extern int drmFinish(int fd, int context, drmLockFlags flags);
655extern int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id,
656 drm_handle_t * handle);
657
658/* AGP/GART support: X server (root) only */
659extern int drmAgpAcquire(int fd);
660extern int drmAgpRelease(int fd);
661extern int drmAgpEnable(int fd, unsigned long mode);
662extern int drmAgpAlloc(int fd, unsigned long size,
663 unsigned long type, unsigned long *address,
Dave Airlie645e2d42005-11-29 09:19:20 +0000664 drm_handle_t *handle);
665extern int drmAgpFree(int fd, drm_handle_t handle);
666extern int drmAgpBind(int fd, drm_handle_t handle,
Jon Smirldeed1ec2004-07-07 04:22:17 +0000667 unsigned long offset);
Dave Airlie645e2d42005-11-29 09:19:20 +0000668extern int drmAgpUnbind(int fd, drm_handle_t handle);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000669
670/* AGP/GART info: authenticated client and/or X */
671extern int drmAgpVersionMajor(int fd);
672extern int drmAgpVersionMinor(int fd);
673extern unsigned long drmAgpGetMode(int fd);
674extern unsigned long drmAgpBase(int fd); /* Physical location */
675extern unsigned long drmAgpSize(int fd); /* Bytes */
676extern unsigned long drmAgpMemoryUsed(int fd);
677extern unsigned long drmAgpMemoryAvail(int fd);
678extern unsigned int drmAgpVendorId(int fd);
679extern unsigned int drmAgpDeviceId(int fd);
680
681/* PCI scatter/gather support: X server (root) only */
682extern int drmScatterGatherAlloc(int fd, unsigned long size,
Dave Airlie645e2d42005-11-29 09:19:20 +0000683 drm_handle_t *handle);
684extern int drmScatterGatherFree(int fd, drm_handle_t handle);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000685
686extern int drmWaitVBlank(int fd, drmVBlankPtr vbl);
687
688/* Support routines */
Dave Airlie79038752006-11-08 15:08:09 +1100689extern void drmSetServerInfo(drmServerInfoPtr info);
Jon Smirldeed1ec2004-07-07 04:22:17 +0000690extern int drmError(int err, const char *label);
691extern void *drmMalloc(int size);
692extern void drmFree(void *pt);
693
694/* Hash table routines */
695extern void *drmHashCreate(void);
696extern int drmHashDestroy(void *t);
697extern int drmHashLookup(void *t, unsigned long key, void **value);
698extern int drmHashInsert(void *t, unsigned long key, void *value);
699extern int drmHashDelete(void *t, unsigned long key);
700extern int drmHashFirst(void *t, unsigned long *key, void **value);
701extern int drmHashNext(void *t, unsigned long *key, void **value);
702
703/* PRNG routines */
704extern void *drmRandomCreate(unsigned long seed);
705extern int drmRandomDestroy(void *state);
706extern unsigned long drmRandom(void *state);
707extern double drmRandomDouble(void *state);
708
709/* Skip list routines */
710
711extern void *drmSLCreate(void);
712extern int drmSLDestroy(void *l);
713extern int drmSLLookup(void *l, unsigned long key, void **value);
714extern int drmSLInsert(void *l, unsigned long key, void *value);
715extern int drmSLDelete(void *l, unsigned long key);
716extern int drmSLNext(void *l, unsigned long *key, void **value);
717extern int drmSLFirst(void *l, unsigned long *key, void **value);
718extern void drmSLDump(void *l);
719extern int drmSLLookupNeighbors(void *l, unsigned long key,
720 unsigned long *prev_key, void **prev_value,
721 unsigned long *next_key, void **next_value);
722
Dave Airlied51e1bb2006-11-09 08:55:58 +1100723extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
Jammy Zhoudbc8b112015-02-02 18:06:27 +0800724extern int drmOpenOnceWithType(const char *BusID, int *newlyopened, int type);
Dave Airlied51e1bb2006-11-09 08:55:58 +1100725extern void drmCloseOnce(int fd);
Thierry Reding44b08c02014-01-22 12:06:51 +0100726extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
Dave Airlied51e1bb2006-11-09 08:55:58 +1100727
Jesse Barnes731cd552008-12-17 10:09:49 -0800728extern int drmSetMaster(int fd);
729extern int drmDropMaster(int fd);
730
Jesse Barnes14f59582009-12-03 14:20:51 -0800731#define DRM_EVENT_CONTEXT_VERSION 2
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400732
733typedef struct _drmEventContext {
734
735 /* This struct is versioned so we can add more pointers if we
736 * add more events. */
737 int version;
738
739 void (*vblank_handler)(int fd,
740 unsigned int sequence,
741 unsigned int tv_sec,
742 unsigned int tv_usec,
743 void *user_data);
744
Jesse Barnes53addc52009-12-03 14:17:26 -0800745 void (*page_flip_handler)(int fd,
746 unsigned int sequence,
747 unsigned int tv_sec,
748 unsigned int tv_usec,
749 void *user_data);
750
Kristian Høgsbergb0b96632009-09-11 13:27:35 -0400751} drmEventContext, *drmEventContextPtr;
752
753extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
754
Kristian Høgsberg22d46662009-11-23 20:51:34 -0500755extern char *drmGetDeviceNameFromFd(int fd);
Frank Binns1f735782015-02-13 10:51:15 +0000756extern int drmGetNodeTypeFromFd(int fd);
Kristian Høgsberg22d46662009-11-23 20:51:34 -0500757
Dave Airliecc0a1452012-07-14 09:52:17 +0000758extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd);
759extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle);
760
Emil Velikov0ca03a42015-03-07 00:58:39 +0000761extern char *drmGetPrimaryDeviceNameFromFd(int fd);
762extern char *drmGetRenderDeviceNameFromFd(int fd);
763
Emil Velikovb556ea12015-08-17 11:09:06 +0800764#define DRM_BUS_PCI 0
765
766typedef struct _drmPciBusInfo {
767 uint16_t domain;
768 uint8_t bus;
769 uint8_t dev;
770 uint8_t func;
771} drmPciBusInfo, *drmPciBusInfoPtr;
772
773typedef struct _drmPciDeviceInfo {
774 uint16_t vendor_id;
775 uint16_t device_id;
776 uint16_t subvendor_id;
777 uint16_t subdevice_id;
778 uint8_t revision_id;
779} drmPciDeviceInfo, *drmPciDeviceInfoPtr;
780
781typedef struct _drmDevice {
782 char **nodes; /* DRM_NODE_MAX sized array */
783 int available_nodes; /* DRM_NODE_* bitmask */
784 int bustype;
785 union {
786 drmPciBusInfoPtr pci;
787 } businfo;
788 union {
789 drmPciDeviceInfoPtr pci;
790 } deviceinfo;
791} drmDevice, *drmDevicePtr;
792
Emil Velikovccedf662015-09-09 16:02:18 +0100793extern int drmGetDevice(int fd, drmDevicePtr *device);
794extern void drmFreeDevice(drmDevicePtr *device);
795
Emil Velikovb556ea12015-08-17 11:09:06 +0800796extern int drmGetDevices(drmDevicePtr devices[], int max_devices);
797extern void drmFreeDevices(drmDevicePtr devices[], int count);
798
Tapani Pälli1c205742015-08-07 10:37:56 +0300799#if defined(__cplusplus)
Tapani Pällicfee5212011-09-23 14:17:42 +0300800}
801#endif
802
Jon Smirldeed1ec2004-07-07 04:22:17 +0000803#endif