Subversion Repositories Kolibri OS

Rev

Rev 4363 | Rev 6110 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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