From a6eafa1b0bb627d67892ff5fabb6e87ea11afa82 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sat, 20 Sep 2014 22:57:10 +0100 Subject: Add drm_armada_bo_create_size() Allow arbitary sized bos to be created. Signed-off-by: Russell King --- armada_bufmgr.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ armada_bufmgr.h | 2 ++ debian/changelog | 6 ++++++ 3 files changed, 65 insertions(+) diff --git a/armada_bufmgr.c b/armada_bufmgr.c index 22a2a14..99eddbf 100644 --- a/armada_bufmgr.c +++ b/armada_bufmgr.c @@ -333,6 +333,63 @@ struct drm_armada_bo *drm_armada_bo_create(struct drm_armada_bufmgr *mgr, return &bo->bo; } +struct drm_armada_bo *drm_armada_bo_create_size(struct drm_armada_bufmgr *mgr, + size_t alloc_size) +{ + struct drm_armada_gem_create arg; + struct armada_bucket *bucket; + struct armada_bo *bo; + int fd = mgr->fd; + int ret; + + /* Try to find a bucket for this allocation */ + bucket = armada_find_bucket(&mgr->cache, alloc_size); + if (bucket) { + /* Can we allocate from our cache? */ + bo = armada_bo_bucket_get(bucket, alloc_size); + if (bo) { + bo->bo.size = alloc_size; + bo->bo.pitch = 1; + bo->ref = 1; + return &bo->bo; + } + + /* Otherwise, allocate a bo of the bucket size */ + alloc_size = bucket->size; + } else { + /* No bucket, so round the size up according to our old rules */ + alloc_size = armada_bo_round_size(alloc_size); + } + + /* No, create a new bo */ + bo = calloc(1, sizeof *bo); + if (!bo) + return NULL; + + memset(&arg, 0, sizeof(arg)); + arg.size = alloc_size; + + ret = drmIoctl(fd, DRM_IOCTL_ARMADA_GEM_CREATE, &arg); + if (ret) { + free(bo); + return NULL; + } + + bo->bo.ref = 1; + bo->bo.handle = arg.handle; + bo->bo.size = alloc_size; + bo->bo.pitch = 1; + bo->bo.type = DRM_ARMADA_BO_SHMEM; + bo->alloc_size = alloc_size; + bo->ref = 1; + bo->mgr = mgr; + + /* Add it to the handle hash table */ + assert(drmHashInsert(mgr->handle_hash, bo->bo.handle, bo) == 0); + + return &bo->bo; +} + struct drm_armada_bo *drm_armada_bo_create_from_name(struct drm_armada_bufmgr *mgr, uint32_t name) { diff --git a/armada_bufmgr.h b/armada_bufmgr.h index 988b38c..4acc774 100644 --- a/armada_bufmgr.h +++ b/armada_bufmgr.h @@ -23,6 +23,8 @@ void drm_armada_fini(struct drm_armada_bufmgr *); struct drm_armada_bo *drm_armada_bo_create(struct drm_armada_bufmgr *, unsigned w, unsigned h, unsigned bpp); +struct drm_armada_bo *drm_armada_bo_create_size(struct drm_armada_bufmgr *, + size_t); struct drm_armada_bo *drm_armada_bo_dumb_create(struct drm_armada_bufmgr *, unsigned w, unsigned h, unsigned bpp); diff --git a/debian/changelog b/debian/changelog index 1b24f48..93c57b8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libdrm-armada (2.0.3-1) unstable; urgency=low + + * Add drm_armada_bo_create_size() + + -- Russell King Sat, 20 Sep 2014 23:07:21 +0100 + libdrm-armada (2.0.2-1) unstable; urgency=low * Updates for kernel ABI changes. -- cgit