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