diff options
-rw-r--r-- | libdrm/xf86drm.c | 185 | ||||
-rw-r--r-- | libdrm/xf86mm.h | 2 | ||||
-rw-r--r-- | linux-core/drm_bo.c | 74 | ||||
-rw-r--r-- | shared-core/drm.h | 112 |
4 files changed, 206 insertions, 167 deletions
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index b53fe2fb..63b9354f 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2598,7 +2598,7 @@ int drmBOCreateList(int numTarget, drmBOList *list) return drmAdjustListNodes(list); } -static void drmBOCopyReply(const drm_bo_arg_reply_t *rep, +static void drmBOCopyReply(struct drm_bo_info_rep *rep, drmBO *buf) { buf->handle = rep->handle; @@ -2620,9 +2620,9 @@ int drmBOCreate(int fd, unsigned long start, unsigned long size, unsigned mask, unsigned hint, drmBO *buf) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + 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)); @@ -2649,21 +2649,13 @@ int drmBOCreate(int fd, unsigned long start, unsigned long size, default: return -EINVAL; } - req->op = drm_bo_create; do { - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); + ret = ioctl(fd, DRM_IOCTL_BO_CREATE, &arg); } while (ret != 0 && errno == EAGAIN); if (ret) return -errno; - if (!arg.handled) { - return -EFAULT; - } - if (rep->ret) { - fprintf(stderr, "Error %d\n", rep->ret); - return rep->ret; - } drmBOCopyReply(rep, buf); buf->mapVirtual = NULL; @@ -2674,9 +2666,7 @@ int drmBOCreate(int fd, unsigned long start, unsigned long size, int drmBODestroy(int fd, drmBO *buf) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + struct drm_bo_handle_arg arg; if (buf->mapVirtual && (buf->type != drm_bo_type_fake)) { (void) drmUnmap(buf->mapVirtual, buf->start + buf->size); @@ -2685,41 +2675,27 @@ int drmBODestroy(int fd, drmBO *buf) } memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->op = drm_bo_destroy; + arg.handle = buf->handle; - if (ioctl(fd, DRM_IOCTL_BUFOBJ, &arg)) + if (ioctl(fd, DRM_IOCTL_BO_DESTROY, &arg)) return -errno; - if (!arg.handled) { - return -EFAULT; - } - if (rep->ret) { - return rep->ret; - } buf->handle = 0; return 0; } - + int drmBOReference(int fd, unsigned handle, drmBO *buf) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + 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; - req->op = drm_bo_reference; - if (ioctl(fd, DRM_IOCTL_BUFOBJ, &arg)) + if (ioctl(fd, DRM_IOCTL_BO_REFERENCE, &arg)) return -errno; - if (!arg.handled) { - return -EFAULT; - } - if (rep->ret) { - return rep->ret; - } drmBOCopyReply(rep, buf); buf->type = drm_bo_type_dc; @@ -2732,10 +2708,7 @@ int drmBOReference(int fd, unsigned handle, drmBO *buf) int drmBOUnReference(int fd, drmBO *buf) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; - + struct drm_bo_handle_arg arg; if (buf->mapVirtual && (buf->type != drm_bo_type_fake)) { (void) munmap(buf->mapVirtual, buf->start + buf->size); @@ -2744,22 +2717,16 @@ int drmBOUnReference(int fd, drmBO *buf) } memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->op = drm_bo_unreference; + arg.handle = buf->handle; - if (ioctl(fd, DRM_IOCTL_BUFOBJ, &arg)) + if (ioctl(fd, DRM_IOCTL_BO_UNREFERENCE, &arg)) return -errno; - if (!arg.handled) { - return -EFAULT; - } - if (rep->ret) { - return rep->ret; - } 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 @@ -2770,9 +2737,9 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, void **address) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + 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; /* @@ -2797,7 +2764,6 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, req->handle = buf->handle; req->mask = mapFlags; req->hint = mapHint; - req->op = drm_bo_map; /* * May hang if the buffer object is busy. @@ -2805,15 +2771,11 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, */ do { - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); + ret = ioctl(fd, DRM_IOCTL_BO_MAP, &arg); } while (ret != 0 && errno == EAGAIN); if (ret) return -errno; - if (!arg.handled) - return -EFAULT; - if (rep->ret) - return rep->ret; drmBOCopyReply(rep, buf); buf->mapFlags = mapFlags; @@ -2823,45 +2785,37 @@ int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, return 0; } + int drmBOUnmap(int fd, drmBO *buf) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; - + struct drm_bo_handle_arg arg; memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->op = drm_bo_unmap; + arg.handle = buf->handle; - if (ioctl(fd, DRM_IOCTL_BUFOBJ, &arg)) { + if (ioctl(fd, DRM_IOCTL_BO_UNMAP, &arg)) { return -errno; } - if (!arg.handled) - return -EFAULT; - if (rep->ret) - return rep->ret; - return 0; } int drmBOValidate(int fd, drmBO *buf, unsigned flags, unsigned mask, unsigned hint) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + struct drm_bo_op_arg arg; + struct drm_bo_op_req *req = &arg.d.req; + struct drm_bo_arg_rep *rep = &arg.d.rep; int ret = 0; memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->mask = flags; - req->hint = hint; + req->bo_req.handle = buf->handle; + req->bo_req.mask = flags; + req->bo_req.hint = hint; req->arg_handle = mask; /* Encode mask in the arg_handle field :/ */ req->op = drm_bo_validate; do{ - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); + ret = ioctl(fd, DRM_IOCTL_BO_OP, &arg); } while (ret && errno == EAGAIN); if (ret) @@ -2871,25 +2825,25 @@ int drmBOValidate(int fd, drmBO *buf, unsigned flags, unsigned mask, if (rep->ret) return rep->ret; - drmBOCopyReply(rep, buf); + drmBOCopyReply(&rep->bo_info, buf); return 0; } int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + struct drm_bo_op_arg arg; + struct drm_bo_op_req *req = &arg.d.req; + struct drm_bo_arg_rep *rep = &arg.d.rep; int ret = 0; memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->mask = flags; + req->bo_req.handle = buf->handle; + req->bo_req.mask = flags; req->arg_handle = fenceHandle; - req->op = drm_bo_validate; + req->op = drm_bo_fence; - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); + ret = ioctl(fd, DRM_IOCTL_BO_OP, &arg); if (ret) return -errno; @@ -2902,51 +2856,43 @@ int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle) int drmBOInfo(int fd, drmBO *buf) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + 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; - req->op = drm_bo_info; - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); + ret = ioctl(fd, DRM_IOCTL_BO_INFO, &arg); if (ret) return -errno; - if (!arg.handled) - return -EFAULT; - if (rep->ret) - return rep->ret; + drmBOCopyReply(rep, buf); return 0; } int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint) { - drm_bo_arg_t arg; - drm_bo_arg_request_t *req = &arg.d.req; - drm_bo_arg_reply_t *rep = &arg.d.rep; + 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->op = drm_bo_wait_idle; req->hint = hint; do { - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg); + ret = ioctl(fd, DRM_IOCTL_BO_WAIT_IDLE, &arg); } while (ret && errno == EAGAIN); if (ret) return -errno; - if (!arg.handled) - return -EFAULT; - if (rep->ret) - return rep->ret; + drmBOCopyReply(rep, buf); } return 0; @@ -2967,7 +2913,6 @@ int drmBOBusy(int fd, drmBO *buf, int *busy) } } - int drmAddValidateItem(drmBOList *list, drmBO *buf, unsigned flags, unsigned mask, int *newItem) @@ -3029,9 +2974,9 @@ int drmBOValidateList(int fd, drmBOList *list) drmBONode *node; drmMMListHead *l; - drm_bo_arg_t *arg, *first; - drm_bo_arg_request_t *req; - drm_bo_arg_reply_t *rep; + struct drm_bo_op_arg *arg, *first; + struct drm_bo_op_req *req; + struct drm_bo_arg_rep *rep; drm_u64_t *prevNext = NULL; drmBO *buf; int ret; @@ -3052,10 +2997,10 @@ int drmBOValidateList(int fd, drmBOList *list) memset(arg, 0, sizeof(*arg)); prevNext = &arg->next; - req->handle = node->buf->handle; + req->bo_req.handle = node->buf->handle; req->op = drm_bo_validate; - req->mask = node->arg0; - req->hint = 0; + req->bo_req.mask = node->arg0; + req->bo_req.hint = 0; req->arg_handle = node->arg1; } @@ -3063,7 +3008,7 @@ int drmBOValidateList(int fd, drmBOList *list) return 0; do{ - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, first); + ret = ioctl(fd, DRM_IOCTL_BO_OP, first); } while (ret && errno == EAGAIN); @@ -3083,7 +3028,7 @@ int drmBOValidateList(int fd, drmBOList *list) return rep->ret; buf = node->buf; - drmBOCopyReply(rep, buf); + drmBOCopyReply(&rep->bo_info, buf); } return 0; @@ -3095,9 +3040,9 @@ int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle) drmBONode *node; drmMMListHead *l; - drm_bo_arg_t *arg, *first; - drm_bo_arg_request_t *req; - drm_bo_arg_reply_t *rep; + struct drm_bo_op_arg *arg, *first; + struct drm_bo_op_req *req; + struct drm_bo_arg_rep *rep; drm_u64_t *prevNext = NULL; drmBO *buf; unsigned fence_flags; @@ -3119,16 +3064,16 @@ int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle) memset(arg, 0, sizeof(*arg)); prevNext = &arg->next; - req->handle = node->buf->handle; + req->bo_req.handle = node->buf->handle; req->op = drm_bo_fence; - req->mask = node->arg0; + req->bo_req.mask = node->arg0; req->arg_handle = fenceHandle; } if (!first) return 0; - ret = ioctl(fd, DRM_IOCTL_BUFOBJ, first); + ret = ioctl(fd, DRM_IOCTL_BO_OP, first); if (ret) return -errno; @@ -3143,7 +3088,7 @@ int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle) return -EFAULT; if (rep->ret) return rep->ret; - drmBOCopyReply(rep, node->buf); + drmBOCopyReply(&rep->bo_info, node->buf); } return 0; diff --git a/libdrm/xf86mm.h b/libdrm/xf86mm.h index bd0d2812..0b284cc0 100644 --- a/libdrm/xf86mm.h +++ b/libdrm/xf86mm.h @@ -125,7 +125,7 @@ typedef struct _drmBO{ typedef struct _drmBONode { drmMMListHead head; drmBO *buf; - drm_bo_arg_t bo_arg; + struct drm_bo_op_arg bo_arg; unsigned long arg0; unsigned long arg1; } drmBONode; diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index f78a6f95..43be21a8 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1784,6 +1784,80 @@ int drm_bo_ioctl(DRM_IOCTL_ARGS) return 0; } +int drm_bo_create_ioctl(DRM_IOCTL_ARGS) +{ + DRM_DEVICE; + drm_bo_create_arg_t arg; + unsigned long next; + drm_user_object_t *uo; + drm_buffer_object_t *entry; + int ret = 0; + + if (!dev->bm.initialized) { + DRM_ERROR("Buffer object manager is not initialized.\n"); + return -EINVAL; + } + + DRM_COPY_FROM_USER_IOCTL(arg, (void __user *)data, sizeof(arg)); + + ret = drm_bo_lock_test(dev, filp); + if (ret) + goto out; + + ret = drm_buffer_object_create(priv->head->dev, + req->size, req->type, req->mask, + req->hint, req->page_alignment, + req->buffer_start, &entry); + if (ret) + goto out; + + ret = drm_bo_add_user_object(priv, entry, + req->mask & DRM_BO_FLAG_SHAREABLE); + if (ret) { + drm_bo_usage_deref_unlocked(entry); + goto out; + } + + mutex_lock(&entry->mutex); + drm_bo_fill_rep_arg(entry, &rep); + mutex_unlock(&entry->mutex); + + DRM_COPY_TO_USER_IOCTL((void __user *)data, arg, sizeof(arg)); +out: + return 0; +} + +int drm_bo_ioctl(DRM_IOCTL_ARGS) +{ + DRM_DEVICE; + drm_bo_arg_t arg; + drm_bo_arg_request_t *req = &arg.d.req; + drm_bo_arg_reply_t rep; + unsigned long next; + drm_user_object_t *uo; + drm_buffer_object_t *entry; + + if (!dev->bm.initialized) { + DRM_ERROR("Buffer object manager is not initialized.\n"); + return -EINVAL; + } + + DRM_COPY_FROM_USER_IOCTL(arg, (void __user *)data, sizeof(arg)); + + rep.ret = 0; + + rep.ret = drm_buffer_object_unmap(priv, req->handle); + + + if (rep.ret == -EAGAIN) + return -EAGAIN; + + + DRM_COPY_TO_USER_IOCTL((void __user *)data, arg, sizeof(arg)); + + return 0; +} + /** *Clean the unfenced list and put on regular LRU. *This is part of the memory manager cleanup and should only be diff --git a/shared-core/drm.h b/shared-core/drm.h index 9810321e..7b3ee153 100644 --- a/shared-core/drm.h +++ b/shared-core/drm.h @@ -782,32 +782,29 @@ typedef enum { drm_bo_type_kernel, /* for initial kernel allocations */ }drm_bo_type_t; +struct drm_bo_info_req { + unsigned int handle; + unsigned int mask; + unsigned int hint; +}; -typedef struct drm_bo_arg_request { - unsigned handle; /* User space handle */ - unsigned mask; - unsigned hint; +struct drm_bo_create_req { + unsigned int mask; + unsigned int hint; + unsigned page_alignment; drm_u64_t size; drm_bo_type_t type; - unsigned arg_handle; drm_u64_t buffer_start; - unsigned page_alignment; - unsigned expand_pad[4]; /*Future expansion */ +}; + +struct drm_bo_op_req { + struct drm_bo_info_req bo_req; + unsigned int arg_handle; enum { - drm_bo_create, drm_bo_validate, - drm_bo_map, - drm_bo_unmap, drm_bo_fence, - drm_bo_destroy, - drm_bo_reference, - drm_bo_unreference, - drm_bo_info, - drm_bo_wait_idle, - drm_bo_ref_fence } op; -} drm_bo_arg_request_t; - +}; /* * Reply flags @@ -815,30 +812,58 @@ typedef struct drm_bo_arg_request { #define DRM_BO_REP_BUSY 0x00000001 -typedef struct drm_bo_arg_reply { - int ret; - unsigned handle; - unsigned flags; +struct drm_bo_info_rep { + unsigned int handle; + unsigned int flags; drm_u64_t size; drm_u64_t offset; drm_u64_t arg_handle; - unsigned mask; + unsigned int mask; drm_u64_t buffer_start; - unsigned fence_flags; - unsigned rep_flags; - unsigned page_alignment; - unsigned expand_pad[4]; /*Future expansion */ -}drm_bo_arg_reply_t; + unsigned int fence_flags; + unsigned int rep_flags; + unsigned int page_alignment; + unsigned int expand_pad[4]; /*Future expansion */ +}; + +struct drm_bo_arg_rep { + int ret; + struct drm_bo_info_rep bo_info; +}; + +struct drm_bo_create_arg { + union { + struct drm_bo_create_req req; + struct drm_bo_info_rep rep; + } d; +}; + +struct drm_bo_handle_arg { + unsigned int handle; +}; + +struct drm_bo_reference_info_arg { + union { + struct drm_bo_handle_arg req; + struct drm_bo_info_rep rep; + } d; +}; +struct drm_bo_map_wait_idle_arg { + union { + struct drm_bo_info_req req; + struct drm_bo_info_rep rep; + } d; +}; -typedef struct drm_bo_arg{ +struct drm_bo_op_arg { int handled; drm_u64_t next; union { - drm_bo_arg_request_t req; - drm_bo_arg_reply_t rep; + struct drm_bo_op_req req; + struct drm_bo_arg_rep rep; } d; -} drm_bo_arg_t; +}; #define DRM_BO_MEM_LOCAL 0 #define DRM_BO_MEM_TT 1 @@ -926,9 +951,6 @@ typedef struct drm_mm_init_arg { #define DRM_IOCTL_WAIT_VBLANK DRM_IOWR(0x3a, drm_wait_vblank_t) -#define DRM_IOCTL_FENCE DRM_IOWR(0x3b, drm_fence_arg_t) -#define DRM_IOCTL_BUFOBJ DRM_IOWR(0x3d, drm_bo_arg_t) - #define DRM_IOCTL_UPDATE_DRAW DRM_IOW(0x3f, drm_update_draw_t) #define DRM_IOCTL_MM_INIT DRM_IOWR(0xc0, drm_mm_init_arg_t) @@ -946,17 +968,15 @@ typedef struct drm_mm_init_arg { #define DRM_IOCTL_FENCE_EMIT DRM_IOWR(0xcb, drm_fence_arg_t) #define DRM_IOCTL_FENCE_BUFFERS DRM_IOWR(0xcc, drm_fence_arg_t) -#define DRM_IOCTL_BO_CREATE DRM_IOWR(0xcd, drm_bo_arg_t) -#define DRM_IOCTL_BO_DESTROY DRM_IOWR(0xce, drm_bo_arg_t) -#define DRM_IOCTL_BO_MAP DRM_IOWR(0xcf, drm_bo_arg_t) -#define DRM_IOCTL_BO_UNMAP DRM_IOWR(0xd0, drm_bo_arg_t) -#define DRM_IOCTL_BO_REFERENCE DRM_IOWR(0xd1, drm_bo_arg_t) -#define DRM_IOCTL_BO_UNREFERENCE DRM_IOWR(0xd2, drm_bo_arg_t) -#define DRM_IOCTL_BO_VALIDATE DRM_IOWR(0xd3, drm_bo_arg_t) -#define DRM_IOCTL_BO_FENCE DRM_IOWR(0xd4, drm_bo_arg_t) -#define DRM_IOCTL_BO_INFO DRM_IOWR(0xd5, drm_bo_arg_t) -#define DRM_IOCTL_BO_WAIT_IDLE DRM_IOWR(0xd6, drm_bo_arg_t) -#define DRM_IOCTL_BO_REF_FENCE DRM_IOWR(0xd7, drm_bo_arg_t) +#define DRM_IOCTL_BO_CREATE DRM_IOWR(0xcd, struct drm_bo_create_arg) +#define DRM_IOCTL_BO_DESTROY DRM_IOWR(0xce, struct drm_bo_handle_arg) +#define DRM_IOCTL_BO_MAP DRM_IOWR(0xcf, struct drm_bo_map_wait_idle_arg) +#define DRM_IOCTL_BO_UNMAP DRM_IOWR(0xd0, struct drm_bo_handle_arg) +#define DRM_IOCTL_BO_REFERENCE DRM_IOWR(0xd1, struct drm_bo_reference_info_arg) +#define DRM_IOCTL_BO_UNREFERENCE DRM_IOWR(0xd2, struct drm_bo_handle_arg) +#define DRM_IOCTL_BO_OP DRM_IOWR(0xd3, struct drm_bo_op_arg) +#define DRM_IOCTL_BO_INFO DRM_IOWR(0xd4, struct drm_bo_reference_info_arg) +#define DRM_IOCTL_BO_WAIT_IDLE DRM_IOWR(0xd5, struct drm_bo_map_wait_idle_arg) /*@}*/ |