diff options
author | Russell King <rmk@arm.linux.org.uk> | 2014-09-20 22:57:10 +0100 |
---|---|---|
committer | Russell King <rmk@arm.linux.org.uk> | 2014-10-12 19:30:40 +0100 |
commit | a6eafa1b0bb627d67892ff5fabb6e87ea11afa82 (patch) | |
tree | 8c3063ac335c763e6cdde2f2d672237ee3c5667e /armada_bufmgr.c | |
parent | 426d4d9f244c35a2dc37b9e394ca40ad2dd0302a (diff) |
Add drm_armada_bo_create_size()
Allow arbitary sized bos to be created.
Signed-off-by: Russell King <rmk@arm.linux.org.uk>
Diffstat (limited to 'armada_bufmgr.c')
-rw-r--r-- | armada_bufmgr.c | 57 |
1 files changed, 57 insertions, 0 deletions
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) { |