diff options
Diffstat (limited to 'libdrm')
-rw-r--r-- | libdrm/xf86drm.c | 127 | ||||
-rw-r--r-- | libdrm/xf86drm.h | 22 |
2 files changed, 149 insertions, 0 deletions
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index c9f1b2db..a2a2e28c 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2236,3 +2236,130 @@ 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; +} + + diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h index 48a18f29..78730785 100644 --- a/libdrm/xf86drm.h +++ b/libdrm/xf86drm.h @@ -280,6 +280,12 @@ typedef struct _drmSetVersion { int drm_dd_minor; } drmSetVersion, *drmSetVersionPtr; +typedef struct _drmFence{ + unsigned handle; + int class; + unsigned type; + unsigned signaled; +} drmFence; #define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock) @@ -596,6 +602,22 @@ extern int drmScatterGatherFree(int fd, drm_handle_t handle); extern int drmWaitVBlank(int fd, drmVBlankPtr vbl); +/* Fencing */ + +extern int drmFenceCreate(int fd, int shareable, int class, + unsigned type, int emit, + drmFence *fence); +extern int drmFenceDestroy(int fd, const drmFence *fence); +extern int drmFenceReference(int fd, unsigned handle, drmFence *fence); +extern int drmFenceUnreference(int fd, const drmFence *fence); +extern int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type); +extern int drmFenceSignaled(int fd, drmFence *fence); +extern int drmFenceWait(int fd, drmFence *fence, unsigned flush_type, + int lazy, int ignore_signals); +extern int drmFenceEmit(int fd, drmFence *fence, unsigned emit_type); + + + /* Support routines */ extern int drmError(int err, const char *label); extern void *drmMalloc(int size); |