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