diff options
author | Russell King <rmk@arm.linux.org.uk> | 2015-06-10 20:43:53 +0100 |
---|---|---|
committer | Russell King <rmk@arm.linux.org.uk> | 2015-07-31 17:50:24 +0100 |
commit | 00e9d6123d6fc48c7a5b510e95ade215c5b9bd72 (patch) | |
tree | 69e84f75794f5f0e5949a4b85840c4d803eeebf3 /armada_bufmgr.c | |
parent | 07d788ea1e7787c07ab5d3a4ac1c873e409bd50b (diff) |
Add prime import
Add DRM prime import support to the armada-drm buffer manager. This
allows dma_bufs to be imported into armada-drm for display.
Signed-off-by: Russell King <rmk@arm.linux.org.uk>
Diffstat (limited to 'armada_bufmgr.c')
-rw-r--r-- | armada_bufmgr.c | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/armada_bufmgr.c b/armada_bufmgr.c index 0803309..f552a31 100644 --- a/armada_bufmgr.c +++ b/armada_bufmgr.c @@ -393,6 +393,38 @@ struct drm_armada_bo *drm_armada_bo_create_size(struct drm_armada_bufmgr *mgr, return &bo->bo; } +static struct armada_bo *drm_armada_bo_lookup_or_create( + struct drm_armada_bufmgr *mgr, uint32_t handle, size_t size) +{ + struct armada_bo *bo; + + /* + * Lookup this handle in our hash of handles. If it + * already exists, increment the refcount and return it. + */ + if (drmHashLookup(mgr->handle_hash, handle, (void **)&bo) == 0) { + drm_armada_bo_get(&bo->bo); + return bo; + } + + bo = calloc(1, sizeof *bo); + if (!bo) + return NULL; + + bo->bo.ref = 1; + bo->bo.handle = handle; + bo->bo.size = size; + bo->bo.type = DRM_ARMADA_BO_LINEAR; /* assumed */ + bo->alloc_size = 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; +} + struct drm_armada_bo *drm_armada_bo_create_from_name(struct drm_armada_bufmgr *mgr, uint32_t name) { @@ -415,37 +447,42 @@ struct drm_armada_bo *drm_armada_bo_create_from_name(struct drm_armada_bufmgr *m if (ret == -1) return NULL; - /* - * Lookup this handle in our hash of handles. If it - * already exists, increment the refcount and return it. - */ - if (drmHashLookup(mgr->handle_hash, arg.handle, (void **)&bo) == 0) { - drm_armada_bo_get(&bo->bo); - return &bo->bo; - } - - bo = calloc(1, sizeof *bo); + bo = drm_armada_bo_lookup_or_create(mgr, arg.handle, arg.size); if (!bo) { armada_gem_handle_close(fd, arg.handle); return NULL; } - bo->bo.ref = 1; - bo->bo.handle = arg.handle; - bo->bo.size = arg.size; - bo->bo.type = DRM_ARMADA_BO_LINEAR; /* assumed */ - bo->alloc_size = arg.size; - bo->ref = 1; bo->name = name; - bo->mgr = mgr; - - /* Add it to the handle hash table */ - assert(drmHashInsert(mgr->handle_hash, bo->bo.handle, bo) == 0); assert(drmHashInsert(mgr->name_hash, bo->name, bo) == 0); return &bo->bo; } +struct drm_armada_bo *drm_armada_bo_from_fd(struct drm_armada_bufmgr *mgr, + int prime_fd) +{ + int fd = mgr->fd; + struct armada_bo *bo; + uint32_t handle; + off_t size; + + size = lseek(prime_fd, 0, SEEK_END); + if (size == (off_t)-1) + return NULL; + + if (drmPrimeFDToHandle(fd, prime_fd, &handle)) + return NULL; + + bo = drm_armada_bo_lookup_or_create(mgr, handle, size); + if (!bo) { + armada_gem_handle_close(fd, handle); + return NULL; + } + + return &bo->bo; +} + struct drm_armada_bo *drm_armada_bo_dumb_create(struct drm_armada_bufmgr *mgr, unsigned w, unsigned h, unsigned bpp) { |