summaryrefslogtreecommitdiff
path: root/libdrm
diff options
context:
space:
mode:
Diffstat (limited to 'libdrm')
-rw-r--r--libdrm/Makefile.am4
-rw-r--r--libdrm/intel/intel_bufmgr_fake.c1
-rw-r--r--libdrm/libdrm_lists.h87
-rw-r--r--libdrm/xf86drm.c573
-rw-r--r--libdrm/xf86drm.h2
5 files changed, 90 insertions, 577 deletions
diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am
index 1187517a..b73cb673 100644
--- a/libdrm/Makefile.am
+++ b/libdrm/Makefile.am
@@ -26,10 +26,10 @@ libdrm_la_LDFLAGS = -version-number 2:3:0 -no-undefined
AM_CFLAGS = -I$(top_srcdir)/shared-core
libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c \
- dri_bufmgr.c
+ dri_bufmgr.c libdrm_lists.h
libdrm_la_LIBADD = intel/libdrm_intel.la
libdrmincludedir = ${includedir}
-libdrminclude_HEADERS = xf86drm.h xf86mm.h dri_bufmgr.h
+libdrminclude_HEADERS = xf86drm.h dri_bufmgr.h
EXTRA_DIST = ChangeLog TODO
diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c
index 63dd9bef..e2dd9dc7 100644
--- a/libdrm/intel/intel_bufmgr_fake.c
+++ b/libdrm/intel/intel_bufmgr_fake.c
@@ -42,6 +42,7 @@
#include "drm.h"
#include "i915_drm.h"
#include "mm.h"
+#include "libdrm_lists.h"
#define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
diff --git a/libdrm/libdrm_lists.h b/libdrm/libdrm_lists.h
new file mode 100644
index 00000000..8e23991f
--- /dev/null
+++ b/libdrm/libdrm_lists.h
@@ -0,0 +1,87 @@
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+
+/*
+ * List macros heavily inspired by the Linux kernel
+ * list handling. No list looping yet.
+ */
+
+typedef struct _drmMMListHead
+{
+ struct _drmMMListHead *prev;
+ struct _drmMMListHead *next;
+} drmMMListHead;
+
+#define DRMINITLISTHEAD(__item) \
+ do{ \
+ (__item)->prev = (__item); \
+ (__item)->next = (__item); \
+ } while (0)
+
+#define DRMLISTADD(__item, __list) \
+ do { \
+ (__item)->prev = (__list); \
+ (__item)->next = (__list)->next; \
+ (__list)->next->prev = (__item); \
+ (__list)->next = (__item); \
+ } while (0)
+
+#define DRMLISTADDTAIL(__item, __list) \
+ do { \
+ (__item)->next = (__list); \
+ (__item)->prev = (__list)->prev; \
+ (__list)->prev->next = (__item); \
+ (__list)->prev = (__item); \
+ } while(0)
+
+#define DRMLISTDEL(__item) \
+ do { \
+ (__item)->prev->next = (__item)->next; \
+ (__item)->next->prev = (__item)->prev; \
+ } while(0)
+
+#define DRMLISTDELINIT(__item) \
+ do { \
+ (__item)->prev->next = (__item)->next; \
+ (__item)->next->prev = (__item)->prev; \
+ (__item)->next = (__item); \
+ (__item)->prev = (__item); \
+ } while(0)
+
+#define DRMLISTENTRY(__type, __item, __field) \
+ ((__type *)(((char *) (__item)) - offsetof(__type, __field)))
+
+#define DRMLISTEMPTY(__item) ((__item)->next == (__item))
+
+#define DRMLISTFOREACHSAFE(__item, __temp, __list) \
+ for ((__item) = (__list)->next, (__temp) = (__item)->next; \
+ (__item) != (__list); \
+ (__item) = (__temp), (__temp) = (__item)->next)
+
+#define DRMLISTFOREACHSAFEREVERSE(__item, __temp, __list) \
+ for ((__item) = (__list)->prev, (__temp) = (__item)->prev; \
+ (__item) != (__list); \
+ (__item) = (__temp), (__temp) = (__item)->prev)
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index edb0c90b..150dd5f8 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -2349,579 +2349,6 @@ int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data,
return 0;
}
-
-/*
- * Valid flags are
- * DRM_FENCE_FLAG_EMIT
- * DRM_FENCE_FLAG_SHAREABLE
- * DRM_FENCE_MASK_DRIVER
- */
-
-int drmFenceCreate(int fd, unsigned flags, int fence_class, unsigned type,
- drmFence *fence)
-{
- drm_fence_arg_t arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.flags = flags;
- arg.type = type;
- arg.fence_class = fence_class;
-
- if (drmIoctl(fd, DRM_IOCTL_FENCE_CREATE, &arg))
- return -errno;
- fence->handle = arg.handle;
- fence->fence_class = arg.fence_class;
- fence->type = arg.type;
- fence->flags = arg.flags;
- fence->signaled = 0;
- return 0;
-}
-
-/*
- * Valid flags are
- * DRM_FENCE_FLAG_SHAREABLE
- * DRM_FENCE_MASK_DRIVER
- */
-
-int drmFenceBuffers(int fd, unsigned flags, uint32_t fence_class, drmFence *fence)
-{
- drm_fence_arg_t arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.flags = flags;
- arg.fence_class = fence_class;
-
- if (drmIoctl(fd, DRM_IOCTL_FENCE_BUFFERS, &arg))
- return -errno;
- fence->handle = arg.handle;
- fence->fence_class = arg.fence_class;
- fence->type = arg.type;
- fence->flags = arg.flags;
- fence->sequence = arg.sequence;
- fence->signaled = 0;
- return 0;
-}
-
-int drmFenceReference(int fd, unsigned handle, drmFence *fence)
-{
- drm_fence_arg_t arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = handle;
-
- if (drmIoctl(fd, DRM_IOCTL_FENCE_REFERENCE, &arg))
- return -errno;
- fence->handle = arg.handle;
- fence->fence_class = arg.fence_class;
- fence->type = arg.type;
- fence->flags = arg.flags;
- fence->signaled = arg.signaled;
- return 0;
-}
-
-int drmFenceUnreference(int fd, const drmFence *fence)
-{
- drm_fence_arg_t arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = fence->handle;
-
- if (drmIoctl(fd, DRM_IOCTL_FENCE_UNREFERENCE, &arg))
- return -errno;
- return 0;
-}
-
-int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type)
-{
- drm_fence_arg_t arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = fence->handle;
- arg.type = flush_type;
-
- if (drmIoctl(fd, DRM_IOCTL_FENCE_FLUSH, &arg))
- return -errno;
- fence->fence_class = arg.fence_class;
- fence->type = arg.type;
- fence->signaled = arg.signaled;
- return arg.error;
-}
-
-int drmFenceUpdate(int fd, drmFence *fence)
-{
- drm_fence_arg_t arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = fence->handle;
-
- if (drmIoctl(fd, DRM_IOCTL_FENCE_SIGNALED, &arg))
- return -errno;
- fence->fence_class = arg.fence_class;
- fence->type = arg.type;
- fence->signaled = arg.signaled;
- return 0;
-}
-
-int drmFenceSignaled(int fd, drmFence *fence, unsigned fenceType,
- int *signaled)
-{
- if ((fence->flags & DRM_FENCE_FLAG_SHAREABLE) ||
- ((fenceType & fence->signaled) != fenceType)) {
- int ret = drmFenceFlush(fd, fence, fenceType);
- if (ret)
- return ret;
- }
-
- *signaled = ((fenceType & fence->signaled) == fenceType);
-
- return 0;
-}
-
-/*
- * Valid flags are
- * DRM_FENCE_FLAG_SHAREABLE
- * DRM_FENCE_MASK_DRIVER
- */
-
-
-int drmFenceEmit(int fd, unsigned flags, drmFence *fence, unsigned emit_type)
-{
- drm_fence_arg_t arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.fence_class = fence->fence_class;
- arg.flags = flags;
- arg.handle = fence->handle;
- arg.type = emit_type;
-
- if (drmIoctl(fd, DRM_IOCTL_FENCE_EMIT, &arg))
- return -errno;
- fence->fence_class = arg.fence_class;
- fence->type = arg.type;
- fence->signaled = arg.signaled;
- fence->sequence = arg.sequence;
- return 0;
-}
-
-/*
- * Valid flags are
- * DRM_FENCE_FLAG_WAIT_LAZY
- * DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS
- */
-
-#define DRM_IOCTL_TIMEOUT_USEC 3000000UL
-
-static unsigned long
-drmTimeDiff(struct timeval *now, struct timeval *then)
-{
- uint64_t val;
-
- val = now->tv_sec - then->tv_sec;
- val *= 1000000LL;
- val += now->tv_usec;
- val -= then->tv_usec;
-
- return (unsigned long) val;
-}
-
-static int
-drmIoctlTimeout(int fd, unsigned long request, void *argp)
-{
- int haveThen = 0;
- struct timeval then, now;
- int ret;
-
- do {
- ret = drmIoctl(fd, request, argp);
- if (ret != 0 && errno == EAGAIN) {
- if (!haveThen) {
- gettimeofday(&then, NULL);
- haveThen = 1;
- }
- gettimeofday(&now, NULL);
- }
- } while (ret != 0 && errno == EAGAIN &&
- drmTimeDiff(&now, &then) < DRM_IOCTL_TIMEOUT_USEC);
-
- if (ret != 0)
- return ((errno == EAGAIN) ? -EBUSY : -errno);
-
- return 0;
-}
-
-
-
-
-int drmFenceWait(int fd, unsigned flags, drmFence *fence, unsigned flush_type)
-{
- drm_fence_arg_t arg;
- int ret;
-
- if (flush_type == 0) {
- flush_type = fence->type;
- }
-
- if (!(fence->flags & DRM_FENCE_FLAG_SHAREABLE)) {
- if ((flush_type & fence->signaled) == flush_type) {
- return 0;
- }
- }
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = fence->handle;
- arg.type = flush_type;
- arg.flags = flags;
-
-
- ret = drmIoctlTimeout(fd, DRM_IOCTL_FENCE_WAIT, &arg);
- if (ret)
- return ret;
-
- fence->fence_class = arg.fence_class;
- fence->type = arg.type;
- fence->signaled = arg.signaled;
- return arg.error;
-}
-
-static void drmBOCopyReply(const struct drm_bo_info_rep *rep, drmBO *buf)
-{
- buf->handle = rep->handle;
- buf->flags = rep->flags;
- buf->size = rep->size;
- buf->offset = rep->offset;
- buf->mapHandle = rep->arg_handle;
- buf->proposedFlags = rep->proposed_flags;
- buf->start = rep->buffer_start;
- buf->fenceFlags = rep->fence_flags;
- buf->replyFlags = rep->rep_flags;
- buf->pageAlignment = rep->page_alignment;
- buf->tileInfo = rep->tile_info;
- buf->hwTileStride = rep->hw_tile_stride;
- buf->desiredTileStride = rep->desired_tile_stride;
-}
-
-
-
-int drmBOCreate(int fd, unsigned long size,
- unsigned pageAlignment, void *user_buffer,
- uint64_t flags,
- unsigned hint, drmBO *buf)
-{
- struct drm_bo_create_arg arg;
- struct drm_bo_create_req *req = &arg.d.req;
- struct drm_bo_info_rep *rep = &arg.d.rep;
- int ret;
-
- memset(buf, 0, sizeof(*buf));
- memset(&arg, 0, sizeof(arg));
- req->flags = flags;
- req->hint = hint;
- req->size = size;
- req->page_alignment = pageAlignment;
- req->buffer_start = (unsigned long) user_buffer;
-
- buf->virtual = NULL;
-
- ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_CREATE, &arg);
- if (ret)
- return ret;
-
- drmBOCopyReply(rep, buf);
- buf->virtual = user_buffer;
- buf->mapCount = 0;
-
- return 0;
-}
-
-int drmBOReference(int fd, unsigned handle, drmBO *buf)
-{
- struct drm_bo_reference_info_arg arg;
- struct drm_bo_handle_arg *req = &arg.d.req;
- struct drm_bo_info_rep *rep = &arg.d.rep;
-
- memset(&arg, 0, sizeof(arg));
- req->handle = handle;
-
- if (drmIoctl(fd, DRM_IOCTL_BO_REFERENCE, &arg))
- return -errno;
-
- drmBOCopyReply(rep, buf);
- buf->mapVirtual = NULL;
- buf->mapCount = 0;
- buf->virtual = NULL;
-
- return 0;
-}
-
-int drmBOUnreference(int fd, drmBO *buf)
-{
- struct drm_bo_handle_arg arg;
-
- if (buf->mapVirtual && buf->mapHandle) {
- (void) munmap(buf->mapVirtual, buf->start + buf->size);
- buf->mapVirtual = NULL;
- buf->virtual = NULL;
- }
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = buf->handle;
-
- if (drmIoctl(fd, DRM_IOCTL_BO_UNREFERENCE, &arg))
- return -errno;
-
- buf->handle = 0;
- return 0;
-}
-
-
-/*
- * Flags can be DRM_BO_FLAG_READ, DRM_BO_FLAG_WRITE or'ed together
- * Hint currently be DRM_BO_HINT_DONT_BLOCK, which makes the
- * call return an -EBUSY if it can' immediately honor the mapping request.
- */
-
-int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
- void **address)
-{
- struct drm_bo_map_wait_idle_arg arg;
- struct drm_bo_info_req *req = &arg.d.req;
- struct drm_bo_info_rep *rep = &arg.d.rep;
- int ret = 0;
-
- /*
- * Make sure we have a virtual address of the buffer.
- */
-
- if (!buf->virtual) {
- drmAddress virtual;
- virtual = mmap(0, buf->size + buf->start,
- PROT_READ | PROT_WRITE, MAP_SHARED,
- fd, buf->mapHandle);
- if (virtual == MAP_FAILED) {
- ret = -errno;
- }
- if (ret)
- return ret;
- buf->mapVirtual = virtual;
- buf->virtual = ((char *) virtual) + buf->start;
- }
-
- memset(&arg, 0, sizeof(arg));
- req->handle = buf->handle;
- req->mask = mapFlags;
- req->hint = mapHint;
-
- /*
- * May hang if the buffer object is busy.
- * This IOCTL synchronizes the buffer.
- */
-
- ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_MAP, &arg);
- if (ret)
- return ret;
-
- drmBOCopyReply(rep, buf);
- buf->mapFlags = mapFlags;
- ++buf->mapCount;
- *address = buf->virtual;
-
- return 0;
-}
-
-
-int drmBOUnmap(int fd, drmBO *buf)
-{
- struct drm_bo_handle_arg arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = buf->handle;
-
- if (drmIoctl(fd, DRM_IOCTL_BO_UNMAP, &arg)) {
- return -errno;
- }
- buf->mapCount--;
- return 0;
-}
-
-int drmBOSetStatus(int fd, drmBO *buf,
- uint64_t flags, uint64_t mask,
- unsigned int hint,
- unsigned int desired_tile_stride,
- unsigned int tile_info)
-{
-
- struct drm_bo_map_wait_idle_arg arg;
- struct drm_bo_info_req *req = &arg.d.req;
- struct drm_bo_info_rep *rep = &arg.d.rep;
- int ret = 0;
-
- memset(&arg, 0, sizeof(arg));
- req->mask = mask;
- req->flags = flags;
- req->handle = buf->handle;
- req->hint = hint;
- req->desired_tile_stride = desired_tile_stride;
- req->tile_info = tile_info;
-
- ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_SETSTATUS, &arg);
- if (ret)
- return ret;
-
- drmBOCopyReply(rep, buf);
- return 0;
-}
-
-
-int drmBOInfo(int fd, drmBO *buf)
-{
- struct drm_bo_reference_info_arg arg;
- struct drm_bo_handle_arg *req = &arg.d.req;
- struct drm_bo_info_rep *rep = &arg.d.rep;
- int ret = 0;
-
- memset(&arg, 0, sizeof(arg));
- req->handle = buf->handle;
-
- ret = drmIoctl(fd, DRM_IOCTL_BO_INFO, &arg);
- if (ret)
- return -errno;
-
- drmBOCopyReply(rep, buf);
- return 0;
-}
-
-int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint)
-{
- struct drm_bo_map_wait_idle_arg arg;
- struct drm_bo_info_req *req = &arg.d.req;
- struct drm_bo_info_rep *rep = &arg.d.rep;
- int ret = 0;
-
- if ((buf->flags & DRM_BO_FLAG_SHAREABLE) ||
- (buf->replyFlags & DRM_BO_REP_BUSY)) {
- memset(&arg, 0, sizeof(arg));
- req->handle = buf->handle;
- req->hint = hint;
-
- ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_WAIT_IDLE, &arg);
- if (ret)
- return ret;
-
- drmBOCopyReply(rep, buf);
- }
- return 0;
-}
-
-int drmBOBusy(int fd, drmBO *buf, int *busy)
-{
- int ret = drmBOInfo(fd, buf);
-
- if (ret)
- return ret;
-
- *busy = (buf->replyFlags & DRM_BO_REP_BUSY);
- return 0;
-}
-
-int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize,
- unsigned memType)
-{
- struct drm_mm_init_arg arg;
-
- memset(&arg, 0, sizeof(arg));
-
- arg.magic = DRM_BO_INIT_MAGIC;
- arg.major = DRM_BO_INIT_MAJOR;
- arg.minor = DRM_BO_INIT_MINOR;
- arg.p_offset = pOffset;
- arg.p_size = pSize;
- arg.mem_type = memType;
-
- if (drmIoctl(fd, DRM_IOCTL_MM_INIT, &arg))
- return -errno;
- return 0;
-}
-
-int drmMMTakedown(int fd, unsigned memType)
-{
- struct drm_mm_type_arg arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.mem_type = memType;
-
- if (drmIoctl(fd, DRM_IOCTL_MM_TAKEDOWN, &arg))
- return -errno;
- return 0;
-}
-
-/*
- * If this function returns an error, and lockBM was set to 1,
- * the buffer manager is NOT locked.
- */
-
-int drmMMLock(int fd, unsigned memType, int lockBM, int ignoreNoEvict)
-{
- struct drm_mm_type_arg arg;
-
- memset(&arg, 0, sizeof(arg));
- arg.mem_type = memType;
- arg.lock_flags |= (lockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0;
- arg.lock_flags |= (ignoreNoEvict) ? DRM_BO_LOCK_IGNORE_NO_EVICT : 0;
-
- return drmIoctlTimeout(fd, DRM_IOCTL_MM_LOCK, &arg);
-}
-
-int drmMMUnlock(int fd, unsigned memType, int unlockBM)
-{
- struct drm_mm_type_arg arg;
-
- memset(&arg, 0, sizeof(arg));
-
- arg.mem_type = memType;
- arg.lock_flags |= (unlockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0;
-
- return drmIoctlTimeout(fd, DRM_IOCTL_MM_UNLOCK, &arg);
-}
-
-int drmMMInfo(int fd, unsigned memType, uint64_t *size)
-{
- struct drm_mm_info_arg arg;
-
- memset(&arg, 0, sizeof(arg));
-
- arg.mem_type = memType;
-
- if (drmIoctl(fd, DRM_IOCTL_MM_INFO, &arg))
- return -errno;
-
- *size = arg.p_size;
- return 0;
-}
-
-int drmBOVersion(int fd, unsigned int *major,
- unsigned int *minor,
- unsigned int *patchlevel)
-{
- struct drm_bo_version_arg arg;
- int ret;
-
- memset(&arg, 0, sizeof(arg));
- ret = drmIoctl(fd, DRM_IOCTL_BO_VERSION, &arg);
- if (ret)
- return -errno;
-
- if (major)
- *major = arg.major;
- if (minor)
- *minor = arg.minor;
- if (patchlevel)
- *patchlevel = arg.patchlevel;
-
- return 0;
-}
-
-
-
#define DRM_MAX_FDS 16
static struct {
char *BusID;
diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h
index 6ced284a..f4fa71b0 100644
--- a/libdrm/xf86drm.h
+++ b/libdrm/xf86drm.h
@@ -659,6 +659,4 @@ extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened);
extern void drmCloseOnce(int fd);
extern void drmMsg(const char *format, ...);
-#include "xf86mm.h"
-
#endif