diff options
Diffstat (limited to 'libdrm/xf86drm.c')
-rw-r--r-- | libdrm/xf86drm.c | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index c9f1b2db..88676083 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2236,3 +2236,211 @@ int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data, } return 0; } + +int drmFenceCreate(int fd, int shareable, int class,unsigned type, + int emit, + drmFence *fence) +{ + drm_fence_arg_t arg; + + arg.type = type; + arg.class = class; + arg.flags = (shareable) ? DRM_FENCE_FLAG_SHAREABLE : 0; + arg.flags |= (emit) ? DRM_FENCE_FLAG_EMIT : 0; + arg.op = drm_fence_create; + if (ioctl(fd, DRM_IOCTL_FENCE, &arg)) + return -errno; + fence->handle = arg.handle; + fence->class = arg.class; + fence->type = arg.type; + fence->signaled = 0; + return 0; +} + +int drmFenceDestroy(int fd, const drmFence *fence) +{ + drm_fence_arg_t arg; + + arg.handle = fence->handle; + arg.op = drm_fence_destroy; + if (ioctl(fd, DRM_IOCTL_FENCE, &arg)) + return -errno; + return 0; +} + +int drmFenceReference(int fd, unsigned handle, drmFence *fence) +{ + drm_fence_arg_t arg; + + arg.handle = handle; + arg.op = drm_fence_reference; + if (ioctl(fd, DRM_IOCTL_FENCE, &arg)) + return -errno; + fence->handle = arg.handle; + fence->class = arg.class; + fence->type = arg.type; + fence->signaled = arg.signaled; + return 0; +} + +int drmFenceUnreference(int fd, const drmFence *fence) +{ + drm_fence_arg_t arg; + + arg.handle = fence->handle; + arg.op = drm_fence_unreference; + if (ioctl(fd, DRM_IOCTL_FENCE, &arg)) + return -errno; + return 0; +} + +int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type) +{ + drm_fence_arg_t arg; + + arg.handle = fence->handle; + arg.type = flush_type; + arg.op = drm_fence_flush; + if (ioctl(fd, DRM_IOCTL_FENCE, &arg)) + return -errno; + fence->class = arg.class; + fence->type = arg.type; + fence->signaled = arg.signaled; + return 0; +} + +int drmFenceSignaled(int fd, drmFence *fence) +{ + drm_fence_arg_t arg; + + arg.handle = fence->handle; + arg.op = drm_fence_signaled; + if (ioctl(fd, DRM_IOCTL_FENCE, &arg)) + return -errno; + fence->class = arg.class; + fence->type = arg.type; + fence->signaled = arg.signaled; + return 0; +} + +int drmFenceEmit(int fd, drmFence *fence, unsigned emit_type) +{ + drm_fence_arg_t arg; + + arg.handle = fence->handle; + arg.type = emit_type; + arg.op = drm_fence_emit; + if (ioctl(fd, DRM_IOCTL_FENCE, &arg)) + return -errno; + fence->class = arg.class; + fence->type = arg.type; + fence->signaled = arg.signaled; + return 0; +} + +int drmFenceWait(int fd, drmFence *fence, unsigned flush_type, + int lazy, int ignore_signals) +{ + drm_fence_arg_t arg; + int ret; + + arg.handle = fence->handle; + arg.type = flush_type; + arg.flags = (lazy) ? DRM_FENCE_FLAG_WAIT_LAZY : 0; + arg.flags |= (ignore_signals) ? DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS : 0; + arg.op = drm_fence_wait; + do { + ret = ioctl(fd, DRM_IOCTL_FENCE, &arg); + } while (ret != 0 && errno == EAGAIN); + + if (ret) + return -errno; + + fence->class = arg.class; + fence->type = arg.type; + fence->signaled = arg.signaled; + return 0; +} + +static unsigned long combine64(unsigned lo, unsigned hi) +{ + unsigned long ret = lo; + if (sizeof(ret) == 8) { + int shift = 32; + ret |= (hi << shift); + } + return ret; +} + +static void split32(unsigned long val, unsigned *lo, unsigned *hi) +{ + *lo = val & 0xFFFFFFFFUL; + if (sizeof(val) == 8) { + int shift = 32; + *hi = val >> shift; + } else { + *hi = 0; + } +} + +int drmTTMCreate(int fd, drmTTM *ttm, unsigned long size, unsigned flags) +{ + drm_ttm_arg_t arg; + + arg.op = drm_ttm_create; + arg.flags = flags; + split32((unsigned long) size, &arg.size_lo, &arg.size_hi); + + if (ioctl(fd, DRM_IOCTL_TTM, &arg)) + return -errno; + + ttm->handle = arg.handle; + ttm->user_token = (drm_handle_t) arg.user_token; + ttm->flags = arg.flags; + ttm->size = combine64(arg.size_lo, arg.size_hi); + return 0; +} + +int drmTTMDestroy(int fd, const drmTTM *ttm) +{ + drm_ttm_arg_t arg; + + arg.op = drm_ttm_destroy; + arg.handle = ttm->handle; + if (ioctl(fd, DRM_IOCTL_TTM, &arg)) + return -errno; + return 0; +} + + +int drmTTMReference(int fd, unsigned handle, drmTTM *ttm) +{ + drm_ttm_arg_t arg; + + arg.handle = handle; + arg.op = drm_ttm_reference; + if (ioctl(fd, DRM_IOCTL_TTM, &arg)) + return -errno; + ttm->handle = arg.handle; + ttm->user_token = (drm_handle_t) arg.user_token; + ttm->flags = arg.flags; + ttm->size = combine64(arg.size_lo, arg.size_hi); + return 0; +} + +int drmTTMUnreference(int fd, const drmTTM *ttm) +{ + drm_ttm_arg_t arg; + + arg.op = drm_ttm_destroy; + arg.handle = ttm->handle; + if (ioctl(fd, DRM_IOCTL_TTM, &arg)) + return -errno; + return 0; +} + +drm_handle_t drmTTMMapHandle(int fd, const drmTTM *ttm) +{ + (void) fd; + return ttm->user_token; +} |