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