| 1 |
/** |
| 2 |
* \file xf86drm.h |
| 3 |
* OS-independent header for DRM user-level library interface. |
| 4 |
* |
| 5 |
* \author Rickard E. (Rik) Faith <[email protected]> |
| 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 <stdarg.h> |
| 38 |
#include <sys/types.h> |
| 39 |
#include <stdint.h> |
| 40 |
#include "drm.h" |
| 41 |
#include "libdrm_macros.h" |
| 42 |
#if defined(__cplusplus) |
| 43 |
extern "C" { |
| 44 |
#endif |
| 45 |
|
| 46 |
#ifndef DRM_MAX_MINOR |
| 47 |
#define DRM_MAX_MINOR 16 |
| 48 |
#endif |
| 49 |
|
| 50 |
#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) |
| 58 |
|
| 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 |
|
| 71 |
/* Defaults, if nothing set in xf86config */ |
| 72 |
#define DRM_DEV_UID 0 |
| 73 |
#define DRM_DEV_GID 0 |
| 74 |
/* Default /dev/dri directory permissions 0755 */ |
| 75 |
#define DRM_DEV_DIRMODE \ |
| 76 |
(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) |
| 77 |
#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) |
| 78 |
|
| 79 |
#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 |
| 85 |
#define DRM_DIR_NAME "/dev/dri" |
| 86 |
#define DRM_DEV_NAME "%s/card%d" |
| 87 |
#define DRM_CONTROL_DEV_NAME "%s/controlD%d" |
| 88 |
#define DRM_RENDER_DEV_NAME "%s/renderD%d" |
| 89 |
#define DRM_PROC_NAME "/proc/dri/" /* For backward Linux compatibility */ |
| 90 |
#endif |
| 91 |
|
| 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 |
|
| 100 |
typedef unsigned int drmSize, *drmSizePtr; /**< For mapped regions */ |
| 101 |
typedef void *drmAddress, **drmAddressPtr; /**< For mapped regions */ |
| 102 |
|
| 103 |
#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 |
|
| 109 |
typedef struct _drmServerInfo { |
| 110 |
int (*debug_print)(const char *format, va_list ap) DRM_PRINTFLIKE(1,0); |
| 111 |
int (*load_module)(const char *name); |
| 112 |
void (*get_perms)(gid_t *, mode_t *); |
| 113 |
} drmServerInfo, *drmServerInfoPtr; |
| 114 |
|
| 115 |
typedef struct drmHashEntry { |
| 116 |
int fd; |
| 117 |
void (*f)(int, void *, void *); |
| 118 |
void *tagTable; |
| 119 |
} drmHashEntry; |
| 120 |
|
| 121 |
extern drm_export int mosdrmIoctl(int fd, unsigned long request, void *arg); |
| 122 |
extern drm_export int drmIoctl(int fd, unsigned long request, void *arg); |
| 123 |
extern void *drmGetHashTable(void); |
| 124 |
extern drmHashEntry *drmGetEntry(int fd); |
| 125 |
|
| 126 |
/** |
| 127 |
* Driver version information. |
| 128 |
* |
| 129 |
* \sa drmGetVersion() and drmSetVersion(). |
| 130 |
*/ |
| 131 |
typedef struct _drmVersion { |
| 132 |
int version_major; /**< Major version */ |
| 133 |
int version_minor; /**< Minor version */ |
| 134 |
int version_patchlevel; /**< Patch level */ |
| 135 |
int name_len; /**< Length of name buffer */ |
| 136 |
char *name; /**< Name of driver */ |
| 137 |
int date_len; /**< Length of date buffer */ |
| 138 |
char *date; /**< User-space buffer to hold date */ |
| 139 |
int desc_len; /**< Length of desc buffer */ |
| 140 |
char *desc; /**< User-space buffer to hold desc */ |
| 141 |
} drmVersion, *drmVersionPtr; |
| 142 |
|
| 143 |
typedef struct _drmStats { |
| 144 |
unsigned long count; /**< Number of data */ |
| 145 |
struct { |
| 146 |
unsigned long value; /**< Value from kernel */ |
| 147 |
const char *long_format; /**< Suggested format for long_name */ |
| 148 |
const char *long_name; /**< Long name for value */ |
| 149 |
const char *rate_format; /**< Suggested format for rate_name */ |
| 150 |
const char *rate_name; /**< Short name for value per second */ |
| 151 |
int isvalue; /**< True if value (vs. counter) */ |
| 152 |
const char *mult_names; /**< Multiplier names (e.g., "KGM") */ |
| 153 |
int mult; /**< Multiplier value (e.g., 1024) */ |
| 154 |
int verbose; /**< Suggest only in verbose output */ |
| 155 |
} data[15]; |
| 156 |
} drmStatsT; |
| 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.) */ |
| 163 |
typedef 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 */ |
| 168 |
DRM_SCATTER_GATHER = 4, /**< PCI scatter/gather */ |
| 169 |
DRM_CONSISTENT = 5 /**< PCI consistent */ |
| 170 |
} drmMapType; |
| 171 |
|
| 172 |
typedef 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 |
*/ |
| 185 |
typedef 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 |
|
| 209 |
typedef enum { |
| 210 |
DRM_PAGE_ALIGN = 0x01, |
| 211 |
DRM_AGP_BUFFER = 0x02, |
| 212 |
DRM_SG_BUFFER = 0x04, |
| 213 |
DRM_FB_BUFFER = 0x08, |
| 214 |
DRM_PCI_BUFFER_RO = 0x10 |
| 215 |
} drmBufDescFlags; |
| 216 |
|
| 217 |
typedef 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 |
|
| 229 |
typedef 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 |
|
| 235 |
typedef 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 |
|
| 242 |
typedef struct _drmBufInfo { |
| 243 |
int count; /**< Number of buffers described in list */ |
| 244 |
drmBufDescPtr list; /**< List of buffer descriptions */ |
| 245 |
} drmBufInfo, *drmBufInfoPtr; |
| 246 |
|
| 247 |
typedef 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 |
*/ |
| 260 |
typedef struct _drmBufMap { |
| 261 |
int count; /**< Number of buffers mapped */ |
| 262 |
drmBufPtr list; /**< Buffers */ |
| 263 |
} drmBufMap, *drmBufMapPtr; |
| 264 |
|
| 265 |
typedef struct _drmLock { |
| 266 |
volatile unsigned int lock; |
| 267 |
char padding[60]; |
| 268 |
} drmLock, *drmLockPtr; |
| 269 |
|
| 270 |
/** |
| 271 |
* Indices here refer to the offset into |
| 272 |
* list in drmBufInfo |
| 273 |
*/ |
| 274 |
typedef struct _drmDMAReq { |
| 275 |
drm_context_t context; /**< Context handle */ |
| 276 |
int send_count; /**< Number of buffers to send */ |
| 277 |
int *send_list; /**< List of handles to buffers */ |
| 278 |
int *send_sizes; /**< Lengths of data to send, in bytes */ |
| 279 |
drmDMAFlags flags; /**< Flags */ |
| 280 |
int request_count; /**< Number of buffers requested */ |
| 281 |
int request_size; /**< Desired size of buffers requested */ |
| 282 |
int *request_list; /**< Buffer information */ |
| 283 |
int *request_sizes; /**< Minimum acceptable sizes */ |
| 284 |
int granted_count; /**< Number of buffers granted at this size */ |
| 285 |
} drmDMAReq, *drmDMAReqPtr; |
| 286 |
|
| 287 |
typedef struct _drmRegion { |
| 288 |
drm_handle_t handle; |
| 289 |
unsigned int offset; |
| 290 |
drmSize size; |
| 291 |
drmAddress map; |
| 292 |
} drmRegion, *drmRegionPtr; |
| 293 |
|
| 294 |
typedef struct _drmTextureRegion { |
| 295 |
unsigned char next; |
| 296 |
unsigned char prev; |
| 297 |
unsigned char in_use; |
| 298 |
unsigned char padding; /**< Explicitly pad this out */ |
| 299 |
unsigned int age; |
| 300 |
} drmTextureRegion, *drmTextureRegionPtr; |
| 301 |
|
| 302 |
typedef enum { |
| 303 |
DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */ |
| 304 |
DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */ |
| 305 |
/* bits 1-6 are reserved for high crtcs */ |
| 306 |
DRM_VBLANK_HIGH_CRTC_MASK = 0x0000003e, |
| 307 |
DRM_VBLANK_EVENT = 0x4000000, /**< Send event instead of blocking */ |
| 308 |
DRM_VBLANK_FLIP = 0x8000000, /**< Scheduled buffer swap should flip */ |
| 309 |
DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */ |
| 310 |
DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */ |
| 311 |
DRM_VBLANK_SIGNAL = 0x40000000 /* Send signal instead of blocking */ |
| 312 |
} drmVBlankSeqType; |
| 313 |
#define DRM_VBLANK_HIGH_CRTC_SHIFT 1 |
| 314 |
|
| 315 |
typedef struct _drmVBlankReq { |
| 316 |
drmVBlankSeqType type; |
| 317 |
unsigned int sequence; |
| 318 |
unsigned long signal; |
| 319 |
} drmVBlankReq, *drmVBlankReqPtr; |
| 320 |
|
| 321 |
typedef struct _drmVBlankReply { |
| 322 |
drmVBlankSeqType type; |
| 323 |
unsigned int sequence; |
| 324 |
long tval_sec; |
| 325 |
long tval_usec; |
| 326 |
} drmVBlankReply, *drmVBlankReplyPtr; |
| 327 |
|
| 328 |
typedef union _drmVBlank { |
| 329 |
drmVBlankReq request; |
| 330 |
drmVBlankReply reply; |
| 331 |
} drmVBlank, *drmVBlankPtr; |
| 332 |
|
| 333 |
typedef struct _drmSetVersion { |
| 334 |
int drm_di_major; |
| 335 |
int drm_di_minor; |
| 336 |
int drm_dd_major; |
| 337 |
int drm_dd_minor; |
| 338 |
} drmSetVersion, *drmSetVersionPtr; |
| 339 |
|
| 340 |
#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock) |
| 341 |
|
| 342 |
#define DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */ |
| 343 |
#define DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */ |
| 344 |
|
| 345 |
#if defined(__GNUC__) && (__GNUC__ >= 2) |
| 346 |
# if defined(__i386) || defined(__AMD64__) || defined(__x86_64__) || defined(__amd64__) |
| 347 |
/* Reflect changes here to drmP.h */ |
| 348 |
#define DRM_CAS(lock,old,new,__ret) \ |
| 349 |
do { \ |
| 350 |
int __dummy; /* Can't mark eax as clobbered */ \ |
| 351 |
__asm__ __volatile__( \ |
| 352 |
"lock ; cmpxchg %4,%1\n\t" \ |
| 353 |
"setnz %0" \ |
| 354 |
: "=d" (__ret), \ |
| 355 |
"=m" (__drm_dummy_lock(lock)), \ |
| 356 |
"=a" (__dummy) \ |
| 357 |
: "2" (old), \ |
| 358 |
"r" (new)); \ |
| 359 |
} while (0) |
| 360 |
|
| 361 |
#elif defined(__alpha__) |
| 362 |
|
| 363 |
#define DRM_CAS(lock, old, new, ret) \ |
| 364 |
do { \ |
| 365 |
int tmp, old32; \ |
| 366 |
__asm__ __volatile__( \ |
| 367 |
" addl $31, %5, %3\n" \ |
| 368 |
"1: ldl_l %0, %2\n" \ |
| 369 |
" cmpeq %0, %3, %1\n" \ |
| 370 |
" beq %1, 2f\n" \ |
| 371 |
" mov %4, %0\n" \ |
| 372 |
" stl_c %0, %2\n" \ |
| 373 |
" beq %0, 3f\n" \ |
| 374 |
" mb\n" \ |
| 375 |
"2: cmpeq %1, 0, %1\n" \ |
| 376 |
".subsection 2\n" \ |
| 377 |
"3: br 1b\n" \ |
| 378 |
".previous" \ |
| 379 |
: "=&r"(tmp), "=&r"(ret), \ |
| 380 |
"=m"(__drm_dummy_lock(lock)), \ |
| 381 |
"=&r"(old32) \ |
| 382 |
: "r"(new), "r"(old) \ |
| 383 |
: "memory"); \ |
| 384 |
} while (0) |
| 385 |
|
| 386 |
#elif defined(__sparc__) |
| 387 |
|
| 388 |
#define DRM_CAS(lock,old,new,__ret) \ |
| 389 |
do { register unsigned int __old __asm("o0"); \ |
| 390 |
register unsigned int __new __asm("o1"); \ |
| 391 |
register volatile unsigned int *__lock __asm("o2"); \ |
| 392 |
__old = old; \ |
| 393 |
__new = new; \ |
| 394 |
__lock = (volatile unsigned int *)lock; \ |
| 395 |
__asm__ __volatile__( \ |
| 396 |
/*"cas [%2], %3, %0"*/ \ |
| 397 |
".word 0xd3e29008\n\t" \ |
| 398 |
/*"membar #StoreStore | #StoreLoad"*/ \ |
| 399 |
".word 0x8143e00a" \ |
| 400 |
: "=&r" (__new) \ |
| 401 |
: "0" (__new), \ |
| 402 |
"r" (__lock), \ |
| 403 |
"r" (__old) \ |
| 404 |
: "memory"); \ |
| 405 |
__ret = (__new != __old); \ |
| 406 |
} while(0) |
| 407 |
|
| 408 |
#elif defined(__ia64__) |
| 409 |
|
| 410 |
#ifdef __INTEL_COMPILER |
| 411 |
/* this currently generates bad code (missing stop bits)... */ |
| 412 |
#include <ia64intrin.h> |
| 413 |
|
| 414 |
#define DRM_CAS(lock,old,new,__ret) \ |
| 415 |
do { \ |
| 416 |
unsigned long __result, __old = (old) & 0xffffffff; \ |
| 417 |
__mf(); \ |
| 418 |
__result = _InterlockedCompareExchange_acq(&__drm_dummy_lock(lock), (new), __old);\ |
| 419 |
__ret = (__result) != (__old); \ |
| 420 |
/* __ret = (__sync_val_compare_and_swap(&__drm_dummy_lock(lock), \ |
| 421 |
(old), (new)) \ |
| 422 |
!= (old)); */\ |
| 423 |
} while (0) |
| 424 |
|
| 425 |
#else |
| 426 |
#define DRM_CAS(lock,old,new,__ret) \ |
| 427 |
do { \ |
| 428 |
unsigned int __result, __old = (old); \ |
| 429 |
__asm__ __volatile__( \ |
| 430 |
"mf\n" \ |
| 431 |
"mov ar.ccv=%2\n" \ |
| 432 |
";;\n" \ |
| 433 |
"cmpxchg4.acq %0=%1,%3,ar.ccv" \ |
| 434 |
: "=r" (__result), "=m" (__drm_dummy_lock(lock)) \ |
| 435 |
: "r" ((unsigned long)__old), "r" (new) \ |
| 436 |
: "memory"); \ |
| 437 |
__ret = (__result) != (__old); \ |
| 438 |
} while (0) |
| 439 |
|
| 440 |
#endif |
| 441 |
|
| 442 |
#elif defined(__powerpc__) |
| 443 |
|
| 444 |
#define DRM_CAS(lock,old,new,__ret) \ |
| 445 |
do { \ |
| 446 |
__asm__ __volatile__( \ |
| 447 |
"sync;" \ |
| 448 |
"0: lwarx %0,0,%1;" \ |
| 449 |
" xor. %0,%3,%0;" \ |
| 450 |
" bne 1f;" \ |
| 451 |
" stwcx. %2,0,%1;" \ |
| 452 |
" bne- 0b;" \ |
| 453 |
"1: " \ |
| 454 |
"sync;" \ |
| 455 |
: "=&r"(__ret) \ |
| 456 |
: "r"(lock), "r"(new), "r"(old) \ |
| 457 |
: "cr0", "memory"); \ |
| 458 |
} while (0) |
| 459 |
|
| 460 |
#endif /* architecture */ |
| 461 |
#endif /* __GNUC__ >= 2 */ |
| 462 |
|
| 463 |
#ifndef DRM_CAS |
| 464 |
#define DRM_CAS(lock,old,new,ret) do { ret=1; } while (0) /* FAST LOCK FAILS */ |
| 465 |
#endif |
| 466 |
|
| 467 |
#if defined(__alpha__) |
| 468 |
#define DRM_CAS_RESULT(_result) long _result |
| 469 |
#elif defined(__powerpc__) |
| 470 |
#define DRM_CAS_RESULT(_result) int _result |
| 471 |
#else |
| 472 |
#define DRM_CAS_RESULT(_result) char _result |
| 473 |
#endif |
| 474 |
|
| 475 |
#define DRM_LIGHT_LOCK(fd,lock,context) \ |
| 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 |
} while(0) |
| 481 |
|
| 482 |
/* This one counts fast locks -- for |
| 483 |
benchmarking only. */ |
| 484 |
#define DRM_LIGHT_LOCK_COUNT(fd,lock,context,count) \ |
| 485 |
do { \ |
| 486 |
DRM_CAS_RESULT(__ret); \ |
| 487 |
DRM_CAS(lock,context,DRM_LOCK_HELD|context,__ret); \ |
| 488 |
if (__ret) drmGetLock(fd,context,0); \ |
| 489 |
else ++count; \ |
| 490 |
} while(0) |
| 491 |
|
| 492 |
#define DRM_LOCK(fd,lock,context,flags) \ |
| 493 |
do { \ |
| 494 |
if (flags) drmGetLock(fd,context,flags); \ |
| 495 |
else DRM_LIGHT_LOCK(fd,lock,context); \ |
| 496 |
} while(0) |
| 497 |
|
| 498 |
#define DRM_UNLOCK(fd,lock,context) \ |
| 499 |
do { \ |
| 500 |
DRM_CAS_RESULT(__ret); \ |
| 501 |
DRM_CAS(lock,DRM_LOCK_HELD|context,context,__ret); \ |
| 502 |
if (__ret) drmUnlock(fd,context); \ |
| 503 |
} while(0) |
| 504 |
|
| 505 |
/* Simple spin locks */ |
| 506 |
#define DRM_SPINLOCK(spin,val) \ |
| 507 |
do { \ |
| 508 |
DRM_CAS_RESULT(__ret); \ |
| 509 |
do { \ |
| 510 |
DRM_CAS(spin,0,val,__ret); \ |
| 511 |
if (__ret) while ((spin)->lock); \ |
| 512 |
} while (__ret); \ |
| 513 |
} while(0) |
| 514 |
|
| 515 |
#define DRM_SPINLOCK_TAKE(spin,val) \ |
| 516 |
do { \ |
| 517 |
DRM_CAS_RESULT(__ret); \ |
| 518 |
int cur; \ |
| 519 |
do { \ |
| 520 |
cur = (*spin).lock; \ |
| 521 |
DRM_CAS(spin,cur,val,__ret); \ |
| 522 |
} while (__ret); \ |
| 523 |
} while(0) |
| 524 |
|
| 525 |
#define DRM_SPINLOCK_COUNT(spin,val,count,__ret) \ |
| 526 |
do { \ |
| 527 |
int __i; \ |
| 528 |
__ret = 1; \ |
| 529 |
for (__i = 0; __ret && __i < count; __i++) { \ |
| 530 |
DRM_CAS(spin,0,val,__ret); \ |
| 531 |
if (__ret) for (;__i < count && (spin)->lock; __i++); \ |
| 532 |
} \ |
| 533 |
} while(0) |
| 534 |
|
| 535 |
#define DRM_SPINUNLOCK(spin,val) \ |
| 536 |
do { \ |
| 537 |
DRM_CAS_RESULT(__ret); \ |
| 538 |
if ((*spin).lock == val) { /* else server stole lock */ \ |
| 539 |
do { \ |
| 540 |
DRM_CAS(spin,val,0,__ret); \ |
| 541 |
} while (__ret); \ |
| 542 |
} \ |
| 543 |
} while(0) |
| 544 |
|
| 545 |
/* General user-level programmer's API: unprivileged */ |
| 546 |
extern int drmAvailable(void); |
| 547 |
extern int drmOpen(const char *name, const char *busid); |
| 548 |
|
| 549 |
#define DRM_NODE_PRIMARY 0 |
| 550 |
#define DRM_NODE_CONTROL 1 |
| 551 |
#define DRM_NODE_RENDER 2 |
| 552 |
#define DRM_NODE_MAX 3 |
| 553 |
|
| 554 |
extern int drmOpenWithType(const char *name, const char *busid, |
| 555 |
int type); |
| 556 |
|
| 557 |
extern int drmOpenControl(int minor); |
| 558 |
extern int drmOpenRender(int minor); |
| 559 |
extern int drmClose(int fd); |
| 560 |
extern drmVersionPtr drmGetVersion(int fd); |
| 561 |
extern void drmFreeVersion(drmVersionPtr); |
| 562 |
extern char *drmGetBusid(int fd); |
| 563 |
extern int drmGetInterruptFromBusID(int fd, int busnum, int devnum, |
| 564 |
int funcnum); |
| 565 |
extern int drmGetMap(int fd, int idx, drm_handle_t *offset, |
| 566 |
drmSize *size, drmMapType *type, |
| 567 |
drmMapFlags *flags, drm_handle_t *handle, |
| 568 |
int *mtrr); |
| 569 |
extern int drmGetClient(int fd, int idx, int *auth, int *pid, |
| 570 |
int *uid, unsigned long *magic, |
| 571 |
unsigned long *iocs); |
| 572 |
extern int drmGetStats(int fd, drmStatsT *stats); |
| 573 |
extern int drmSetInterfaceVersion(int fd, drmSetVersion *version); |
| 574 |
|
| 575 |
/* General user-level programmer's API: X server (root) only */ |
| 576 |
extern void drmFreeBusid(const char *busid); |
| 577 |
extern int drmAddMap(int fd, |
| 578 |
drm_handle_t offset, |
| 579 |
drmSize size, |
| 580 |
drmMapType type, |
| 581 |
drmMapFlags flags, |
| 582 |
drm_handle_t * handle); |
| 583 |
extern int drmRmMap(int fd, drm_handle_t handle); |
| 584 |
extern int drmAddContextPrivateMapping(int fd, drm_context_t ctx_id, |
| 585 |
drm_handle_t handle); |
| 586 |
|
| 587 |
extern int drmAddBufs(int fd, int count, int size, |
| 588 |
drmBufDescFlags flags, |
| 589 |
int agp_offset); |
| 590 |
extern int drmMarkBufs(int fd, double low, double high); |
| 591 |
extern int drmCreateContext(int fd, drm_context_t * handle); |
| 592 |
extern int drmSetContextFlags(int fd, drm_context_t context, |
| 593 |
drm_context_tFlags flags); |
| 594 |
extern int drmGetContextFlags(int fd, drm_context_t context, |
| 595 |
drm_context_tFlagsPtr flags); |
| 596 |
extern int drmAddContextTag(int fd, drm_context_t context, void *tag); |
| 597 |
extern int drmDelContextTag(int fd, drm_context_t context); |
| 598 |
extern void *drmGetContextTag(int fd, drm_context_t context); |
| 599 |
extern drm_context_t * drmGetReservedContextList(int fd, int *count); |
| 600 |
extern void drmFreeReservedContextList(drm_context_t *); |
| 601 |
extern int drmSwitchToContext(int fd, drm_context_t context); |
| 602 |
extern int drmDestroyContext(int fd, drm_context_t handle); |
| 603 |
extern int drmCreateDrawable(int fd, drm_drawable_t * handle); |
| 604 |
extern int drmDestroyDrawable(int fd, drm_drawable_t handle); |
| 605 |
extern int drmUpdateDrawableInfo(int fd, drm_drawable_t handle, |
| 606 |
drm_drawable_info_type_t type, |
| 607 |
unsigned int num, void *data); |
| 608 |
extern int drmCtlInstHandler(int fd, int irq); |
| 609 |
extern int drmCtlUninstHandler(int fd); |
| 610 |
|
| 611 |
/* General user-level programmer's API: authenticated client and/or X */ |
| 612 |
extern int drmDMA(int fd, drmDMAReqPtr request); |
| 613 |
extern int drmFreeBufs(int fd, int count, int *list); |
| 614 |
extern int drmGetLock(int fd, |
| 615 |
drm_context_t context, |
| 616 |
drmLockFlags flags); |
| 617 |
extern int drmUnlock(int fd, drm_context_t context); |
| 618 |
extern int drmFinish(int fd, int context, drmLockFlags flags); |
| 619 |
extern int drmGetContextPrivateMapping(int fd, drm_context_t ctx_id, |
| 620 |
drm_handle_t * handle); |
| 621 |
|
| 622 |
/* AGP/GART support: X server (root) only */ |
| 623 |
extern int drmAgpAcquire(int fd); |
| 624 |
extern int drmAgpRelease(int fd); |
| 625 |
extern int drmAgpEnable(int fd, unsigned long mode); |
| 626 |
extern int drmAgpAlloc(int fd, unsigned long size, |
| 627 |
unsigned long type, unsigned long *address, |
| 628 |
drm_handle_t *handle); |
| 629 |
extern int drmAgpFree(int fd, drm_handle_t handle); |
| 630 |
extern int drmAgpBind(int fd, drm_handle_t handle, |
| 631 |
unsigned long offset); |
| 632 |
extern int drmAgpUnbind(int fd, drm_handle_t handle); |
| 633 |
|
| 634 |
/* AGP/GART info: authenticated client and/or X */ |
| 635 |
extern int drmAgpVersionMajor(int fd); |
| 636 |
extern int drmAgpVersionMinor(int fd); |
| 637 |
extern unsigned long drmAgpGetMode(int fd); |
| 638 |
extern unsigned long drmAgpBase(int fd); /* Physical location */ |
| 639 |
extern unsigned long drmAgpSize(int fd); /* Bytes */ |
| 640 |
extern unsigned long drmAgpMemoryUsed(int fd); |
| 641 |
extern unsigned long drmAgpMemoryAvail(int fd); |
| 642 |
extern unsigned int drmAgpVendorId(int fd); |
| 643 |
extern unsigned int drmAgpDeviceId(int fd); |
| 644 |
|
| 645 |
/* PCI scatter/gather support: X server (root) only */ |
| 646 |
extern int drmScatterGatherAlloc(int fd, unsigned long size, |
| 647 |
drm_handle_t *handle); |
| 648 |
extern int drmScatterGatherFree(int fd, drm_handle_t handle); |
| 649 |
|
| 650 |
extern int drmWaitVBlank(int fd, drmVBlankPtr vbl); |
| 651 |
|
| 652 |
/* Support routines */ |
| 653 |
extern void drmSetServerInfo(drmServerInfoPtr info); |
| 654 |
extern int drmError(int err, const char *label); |
| 655 |
extern void *drmMalloc(int size); |
| 656 |
extern void drmFree(void *pt); |
| 657 |
|
| 658 |
/* Hash table routines */ |
| 659 |
extern void *drmHashCreate(void); |
| 660 |
extern int drmHashDestroy(void *t); |
| 661 |
extern int drmHashLookup(void *t, unsigned long key, void **value); |
| 662 |
extern int drmHashInsert(void *t, unsigned long key, void *value); |
| 663 |
extern int drmHashDelete(void *t, unsigned long key); |
| 664 |
|
| 665 |
/* PRNG routines */ |
| 666 |
extern void *drmRandomCreate(unsigned long seed); |
| 667 |
extern int drmRandomDestroy(void *state); |
| 668 |
extern unsigned long drmRandom(void *state); |
| 669 |
|
| 670 |
/* Skip list routines */ |
| 671 |
|
| 672 |
extern void *drmSLCreate(void); |
| 673 |
extern int drmSLDestroy(void *l); |
| 674 |
extern int drmSLLookup(void *l, unsigned long key, void **value); |
| 675 |
extern int drmSLInsert(void *l, unsigned long key, void *value); |
| 676 |
extern int drmSLDelete(void *l, unsigned long key); |
| 677 |
extern int drmSLNext(void *l, unsigned long *key, void **value); |
| 678 |
extern int drmSLFirst(void *l, unsigned long *key, void **value); |
| 679 |
extern void drmSLDump(void *l); |
| 680 |
extern int drmSLLookupNeighbors(void *l, unsigned long key, |
| 681 |
unsigned long *prev_key, void **prev_value, |
| 682 |
unsigned long *next_key, void **next_value); |
| 683 |
|
| 684 |
extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2); |
| 685 |
|
| 686 |
#define DRM_EVENT_CONTEXT_VERSION 2 |
| 687 |
|
| 688 |
typedef struct _drmEventContext { |
| 689 |
|
| 690 |
/* This struct is versioned so we can add more pointers if we |
| 691 |
* add more events. */ |
| 692 |
int version; |
| 693 |
|
| 694 |
void (*vblank_handler)(int fd, |
| 695 |
unsigned int sequence, |
| 696 |
unsigned int tv_sec, |
| 697 |
unsigned int tv_usec, |
| 698 |
void *user_data); |
| 699 |
|
| 700 |
void (*page_flip_handler)(int fd, |
| 701 |
unsigned int sequence, |
| 702 |
unsigned int tv_sec, |
| 703 |
unsigned int tv_usec, |
| 704 |
void *user_data); |
| 705 |
|
| 706 |
} drmEventContext, *drmEventContextPtr; |
| 707 |
|
| 708 |
extern int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd); |
| 709 |
extern int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle); |
| 710 |
|
| 711 |
extern char *drmGetPrimaryDeviceNameFromFd(int fd); |
| 712 |
extern char *drmGetRenderDeviceNameFromFd(int fd); |
| 713 |
|
| 714 |
#define DRM_BUS_PCI 0 |
| 715 |
|
| 716 |
#if defined(__cplusplus) |
| 717 |
} |
| 718 |
#endif |
| 719 |
|
| 720 |
#endif |