summaryrefslogtreecommitdiff
path: root/libdrm
diff options
context:
space:
mode:
Diffstat (limited to 'libdrm')
-rw-r--r--libdrm/xf86drm.c208
-rw-r--r--libdrm/xf86drm.h36
2 files changed, 244 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;
+}
diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h
index 48a18f29..433191b4 100644
--- a/libdrm/xf86drm.h
+++ b/libdrm/xf86drm.h
@@ -280,6 +280,19 @@ typedef struct _drmSetVersion {
int drm_dd_minor;
} drmSetVersion, *drmSetVersionPtr;
+typedef struct _drmFence{
+ unsigned handle;
+ int class;
+ unsigned type;
+ unsigned signaled;
+} drmFence;
+
+typedef struct _drmTTM{
+ unsigned handle;
+ drm_handle_t user_token;
+ unsigned flags;
+ unsigned long size;
+} drmTTM;
#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
@@ -596,6 +609,29 @@ 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);
+
+/* TTMS */
+extern int drmTTMCreate(int fd, drmTTM *ttm, unsigned long size,
+ unsigned flags);
+extern int drmTTMDestroy(int fd, const drmTTM *ttm);
+extern int drmTTMReference(int fd, unsigned handle, drmTTM *ttm);
+extern int drmTTMUnreference(int fd, const drmTTM *ttm);
+extern drm_handle_t drmTTMMapHandle(int fd, const drmTTM *ttm);
+
+
/* Support routines */
extern int drmError(int err, const char *label);
extern void *drmMalloc(int size);