From 1c0961001fe9fe87147d9a51f1e4f7fc23199e7c Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Fri, 12 Jan 2018 11:36:13 +0900 Subject: [PATCH 01/16] package version up to 1.0.11 Change-Id: I8358e59ed97233268a5ba42409b2eb9212779344 --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index a05d280..0e4696a 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 1.0.10 +Version: 1.0.11 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From 25c613f48d30e29ded3bd3c8c9d239048c8c8696 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 14 Mar 2018 18:49:19 +0900 Subject: [PATCH 02/16] make the new backend inteface with tbm_backend.h Change-Id: Ie574c5c28eadcb742579819dc5138784be922bdf --- src/tbm_bufmgr_sprd.c | 833 +++++++++++++++++++++++++++++--------------------- 1 file changed, 489 insertions(+), 344 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 63b7844..997e4d2 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -48,11 +48,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include -#include -#include #include #include -#include +#include #include #define DEBUG @@ -89,6 +87,8 @@ _target_name(void) if (!f) return NULL; + memset(app_name, 0x00, sizeof(app_name)); + if (fgets(app_name, 100, f) == NULL) { fclose(f); return NULL; @@ -112,6 +112,8 @@ _target_name(void) #define TBM_SPRD_DEBUG(...) #endif +#define STRERR_BUFSIZE 128 + #define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1)) #define TBM_SURFACE_ALIGNMENT_PLANE (64) @@ -134,29 +136,29 @@ _target_name(void) } struct dma_buf_info { - unsigned long size; - unsigned int fence_supported; - unsigned int padding; + unsigned long size; + unsigned int fence_supported; + unsigned int padding; }; -#define DMA_BUF_ACCESS_READ 0x1 -#define DMA_BUF_ACCESS_WRITE 0x2 -#define DMA_BUF_ACCESS_DMA 0x4 -#define DMA_BUF_ACCESS_MAX 0x8 +#define DMA_BUF_ACCESS_READ 0x1 +#define DMA_BUF_ACCESS_WRITE 0x2 +#define DMA_BUF_ACCESS_DMA 0x4 +#define DMA_BUF_ACCESS_MAX 0x8 -#define DMA_FENCE_LIST_MAX 5 +#define DMA_FENCE_LIST_MAX 5 struct dma_buf_fence { - unsigned long ctx; - unsigned int type; + unsigned long ctx; + unsigned int type; }; -#define DMABUF_IOCTL_BASE 'F' -#define DMABUF_IOWR(nr, type) _IOWR(DMABUF_IOCTL_BASE, nr, type) +#define DMABUF_IOCTL_BASE 'F' +#define DMABUF_IOWR(nr, type) _IOWR(DMABUF_IOCTL_BASE, nr, type) -#define DMABUF_IOCTL_GET_INFO DMABUF_IOWR(0x00, struct dma_buf_info) -#define DMABUF_IOCTL_GET_FENCE DMABUF_IOWR(0x01, struct dma_buf_fence) -#define DMABUF_IOCTL_PUT_FENCE DMABUF_IOWR(0x02, struct dma_buf_fence) +#define DMABUF_IOCTL_GET_INFO DMABUF_IOWR(0x00, struct dma_buf_info) +#define DMABUF_IOCTL_GET_FENCE DMABUF_IOWR(0x01, struct dma_buf_fence) +#define DMABUF_IOCTL_PUT_FENCE DMABUF_IOWR(0x02, struct dma_buf_fence) /* tgl key values */ #define GLOBAL_KEY ((unsigned int)(-1)) @@ -187,11 +189,6 @@ union _tbm_bo_cache_state { typedef struct _tbm_bufmgr_sprd *tbm_bufmgr_sprd; typedef struct _tbm_bo_sprd *tbm_bo_sprd; -typedef struct _sprd_private { - int ref_count; - struct _tbm_bo_sprd *bo_priv; -} PrivGem; - /* tbm buffor object for sprd */ struct _tbm_bo_sprd { int fd; @@ -209,8 +206,6 @@ struct _tbm_bo_sprd { unsigned int flags_sprd; unsigned int flags_tbm; - PrivGem *private; - pthread_mutex_t mutex; struct dma_buf_fence dma_fence[DMA_FENCE_LIST_MAX]; int device; @@ -218,6 +213,8 @@ struct _tbm_bo_sprd { tbm_bo_cache_state cache_state; unsigned int map_cnt; + + tbm_bufmgr_sprd bufmgr_sprd; }; /* tbm bufmgr private for sprd */ @@ -229,8 +226,13 @@ struct _tbm_bufmgr_sprd { int tgl_fd; - void *bind_display; char *device_name; + void *bind_display; + + tbm_backend_bufmgr_func *bufmgr_func; + tbm_backend_bo_func *bo_func; + + tbm_bufmgr bufmgr; }; char *STR_DEVICE[] = { @@ -262,10 +264,12 @@ _tgl_get_version(int fd) { struct tgl_ver_data data; int err; + char buf[STRERR_BUFSIZE]; err = ioctl(fd, TGL_IOCTL_GET_VERSION, &data); if (err) { - TBM_SPRD_ERROR("error(%s) %s:%d\n", strerror(errno)); + TBM_SPRD_ERROR("error(%s) %s:%d\n", + strerror_r(errno, buf, STRERR_BUFSIZE)); return 0; } @@ -279,13 +283,15 @@ _tgl_init(int fd, unsigned int key) { struct tgl_reg_data data; int err; + char buf[STRERR_BUFSIZE]; data.key = key; data.timeout_ms = 1000; err = ioctl(fd, TGL_IOCTL_REGISTER, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d\n", strerror(errno), key); + TBM_SPRD_ERROR("error(%s) key:%d\n", + strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -297,11 +303,13 @@ _tgl_destroy(int fd, unsigned int key) { struct tgl_reg_data data; int err; + char buf[STRERR_BUFSIZE]; data.key = key; err = ioctl(fd, TGL_IOCTL_UNREGISTER, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d\n", strerror(errno), key); + TBM_SPRD_ERROR("error(%s) key:%d\n", + strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -312,8 +320,9 @@ static inline int _tgl_lock(int fd, unsigned int key, int opt) { struct tgl_lock_data data; - enum tgl_type_data tgl_type; int err; + char buf[STRERR_BUFSIZE]; + enum tgl_type_data tgl_type; switch (opt) { case TBM_OPTION_READ: @@ -333,7 +342,7 @@ _tgl_lock(int fd, unsigned int key, int opt) err = ioctl(fd, TGL_IOCTL_LOCK, &data); if (err) { TBM_SPRD_ERROR("error(%s) key:%d opt:%d\n", - strerror(errno), key, opt); + strerror_r(errno, buf, STRERR_BUFSIZE), key, opt); return 0; } @@ -345,6 +354,7 @@ _tgl_unlock(int fd, unsigned int key) { struct tgl_lock_data data; int err; + char buf[STRERR_BUFSIZE]; data.key = key; data.type = TGL_TYPE_NONE; @@ -352,7 +362,7 @@ _tgl_unlock(int fd, unsigned int key) err = ioctl(fd, TGL_IOCTL_UNLOCK, &data); if (err) { TBM_SPRD_ERROR("error(%s) key:%d\n", - strerror(errno), key); + strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -364,6 +374,7 @@ _tgl_set_data(int fd, unsigned int key, unsigned int val) { struct tgl_usr_data data; int err; + char buf[STRERR_BUFSIZE]; data.key = key; data.data1 = val; @@ -371,7 +382,7 @@ _tgl_set_data(int fd, unsigned int key, unsigned int val) err = ioctl(fd, TGL_IOCTL_SET_DATA, &data); if (err) { TBM_SPRD_ERROR("error(%s) key:%d\n", - strerror(errno), key); + strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -383,13 +394,14 @@ _tgl_get_data(int fd, unsigned int key, unsigned int *locked) { struct tgl_usr_data data = { 0, }; int err; + char buf[STRERR_BUFSIZE]; data.key = key; err = ioctl(fd, TGL_IOCTL_GET_DATA, &data); if (err) { TBM_SPRD_ERROR("error(%s) key:%d\n", - strerror(errno), key); + strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -581,7 +593,7 @@ _bo_set_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int device if (bo_sprd->flags_sprd & SPRD_BO_NONCACHABLE) return 1; - /* get cache state of a bo */ + /* get cache state of a bo_sprd */ bo_sprd->cache_state.val = _tgl_get_data(bufmgr_sprd->tgl_fd, bo_sprd->name, NULL); /* get global cache flush count */ @@ -773,7 +785,7 @@ _get_name(int fd, unsigned int gem) arg.handle = gem; if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) { - TBM_SPRD_ERROR("error fail to get flink gem=%d\n", gem); + TBM_SPRD_ERROR("fail to DRM_IOCTL_GEM_FLINK gem:%d", gem); return 0; } @@ -784,6 +796,7 @@ static tbm_bo_handle _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) { tbm_bo_handle bo_handle; + memset(&bo_handle, 0x0, sizeof(uint64_t)); switch (device) { @@ -843,6 +856,7 @@ _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) #endif break; default: + TBM_SPRD_ERROR("Not supported device:%d\n", device); bo_handle.ptr = (void *) NULL; break; } @@ -851,35 +865,44 @@ _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) } static int -tbm_sprd_bo_size(tbm_bo bo) +tbm_sprd_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - tbm_bo_sprd bo_sprd; + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + if (error) + *error = TBM_ERROR_NONE; return bo_sprd->size; } -static void * -tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags) +static tbm_backend_bo_data * +tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_memory_type flags, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); - - tbm_bufmgr_sprd bufmgr_sprd; - unsigned int sprd_flags; + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; tbm_bo_sprd bo_sprd; + unsigned int sprd_flags; - bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + if (bufmgr_sprd == NULL) { + TBM_SPRD_ERROR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_ERROR("error fail to allocate the bo private\n"); - return 0; + TBM_SPRD_ERROR("error fail to allocate the bo_sprd\n"); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; } + bo_sprd->bufmgr_sprd = bufmgr_sprd; #ifdef USE_CONTIG_ONLY flags = TBM_BO_SCANOUT; @@ -891,14 +914,17 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags) #endif // USE_CONTIG_ONLY struct drm_sprd_gem_create arg = {0, }; + arg.size = (uint64_t)size; arg.flags = sprd_flags; if (drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CREATE, &arg, sizeof(arg))) { - TBM_SPRD_ERROR("error Cannot create bo(flag:%x, size:%d)\n", + TBM_SPRD_ERROR("error Cannot create bo_sprd(flag:%x, size:%d)\n", arg.flags, (unsigned int)arg.size); free(bo_sprd); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } bo_sprd->fd = bufmgr_sprd->fd; @@ -911,126 +937,130 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags) if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 0)) { TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); free(bo_sprd); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } pthread_mutex_init(&bo_sprd->mutex, NULL); - if (bufmgr_sprd->use_dma_fence - && !bo_sprd->dmabuf) { + if (bufmgr_sprd->use_dma_fence && !bo_sprd->dmabuf) { struct drm_prime_handle arg = {0, }; arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); free(bo_sprd); - return 0; + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } bo_sprd->dmabuf = arg.fd; } - /* add bo to hash */ - PrivGem *privGem = calloc(1, sizeof(PrivGem)); - if (!privGem) { - TBM_SPRD_ERROR("error Fail to calloc PrivGem\n"); - free(bo_sprd); - return 0; - } - - privGem->ref_count = 1; - privGem->bo_priv = bo_sprd; - if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) - TBM_SPRD_ERROR("error Cannot insert bo to Hash(%d)\n", bo_sprd->name); + /* add bo_sprd to hash */ + if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) + TBM_SPRD_ERROR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); TBM_SPRD_DEBUG("%s size:%d, gem:%d(%d), flags:%d(%d)\n", __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name, flags, sprd_flags); - return (void *)bo_sprd; + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_backend_bo_data *)bo_sprd; } static void -tbm_sprd_bo_free(tbm_bo bo) +tbm_sprd_bo_free(tbm_backend_bo_data *bo_data) { - tbm_bo_sprd bo_sprd; + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + tbm_bo_sprd temp; tbm_bufmgr_sprd bufmgr_sprd; + char buf[STRERR_BUFSIZE]; + int ret; - if (!bo) + if (!bo_data) return; - bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); - - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_IF_FAIL(bo_sprd != NULL); + bufmgr_sprd = bo_sprd->bufmgr_sprd; + if (!bufmgr_sprd) + return; - TBM_SPRD_DEBUG("size:%d, gem:%d(%d)\n", - bo_sprd->size, bo_sprd->gem, bo_sprd->name); + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, size:%d\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + bo_sprd->size); if (bo_sprd->pBase) { - if (munmap(bo_sprd->pBase, bo_sprd->size) == -1) - TBM_SPRD_ERROR("error fail to munmap.\n"); + if (munmap(bo_sprd->pBase, bo_sprd->size) == -1) { + TBM_SPRD_ERROR("bo_sprd:%p fail to munmap(%s)\n", + bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); + } } - /* closedmabuf */ + /* close dmabuf */ if (bo_sprd->dmabuf) { close(bo_sprd->dmabuf); bo_sprd->dmabuf = 0; } /* delete bo from hash */ - PrivGem *privGem = NULL; - int ret; + ret = drmHashLookup(bufmgr_sprd->hashBos, bo_sprd->name, + (void **)&temp); + if (ret == 0) + drmHashDelete(bufmgr_sprd->hashBos, bo_sprd->name); + else + TBM_SPRD_ERROR("Cannot find bo_sprd to Hash(%d), ret=%d\n", bo_sprd->name, ret); - ret = drmHashLookup(bufmgr_sprd->hashBos, bo_sprd->name, (void **)&privGem); - if (ret == 0) { - privGem->ref_count--; - if (privGem->ref_count == 0) { - drmHashDelete(bufmgr_sprd->hashBos, bo_sprd->name); - free(privGem); - privGem = NULL; - } - } else { - TBM_SPRD_DEBUG("warning Cannot find bo to Hash(%d), ret=%d\n", bo_sprd->name, ret); - } + if (temp != bo_sprd) + TBM_SPRD_ERROR("hashBos probably has several BOs with same name!!!\n"); _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); /* Free gem handle */ struct drm_gem_close arg = {0, }; + memset(&arg, 0, sizeof(arg)); arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg)) - TBM_SPRD_ERROR("error fail to DRM_IOCTL_GEM_CLOSE\n"); - + TBM_SPRD_ERROR("bo_sprd:%p fail to gem close.(%s)\n", + bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); free(bo_sprd); } - -static void * -tbm_sprd_bo_import(tbm_bo bo, unsigned int key) +static tbm_backend_bo_data * +tbm_sprd_bufmgr_import(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, NULL); - - tbm_bufmgr_sprd bufmgr_sprd; + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; tbm_bo_sprd bo_sprd; - PrivGem *privGem = NULL; int ret; - bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, NULL); + if (bufmgr_sprd == NULL) { + TBM_SPRD_ERROR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - ret = drmHashLookup(bufmgr_sprd->hashBos, key, (void **)&privGem); - if (ret == 0) - return privGem->bo_priv; + ret = drmHashLookup(bufmgr_sprd->hashBos, key, (void **)&bo_sprd); + if (ret == 0) { + if (error) + *error = TBM_ERROR_NONE; + return (tbm_backend_bo_data *)bo_sprd; + } - struct drm_sprd_gem_info info = {0, }; struct drm_gem_open arg = {0, }; + struct drm_sprd_gem_info info = {0, }; arg.name = key; if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg)) { TBM_SPRD_ERROR("error Cannot open gem name=%d\n", key); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return NULL; } @@ -1040,14 +1070,19 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) &info, sizeof(struct drm_sprd_gem_info))) { TBM_SPRD_ERROR("error Cannot get gem info=%d\n", key); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_gem; } bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_ERROR("error fail to allocate the bo private\n"); + TBM_SPRD_ERROR("error fail to allocate the bo_sprd\n"); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; goto fail_alloc_bo; } + bo_sprd->bufmgr_sprd = bufmgr_sprd; bo_sprd->fd = bufmgr_sprd->fd; bo_sprd->gem = arg.handle; @@ -1063,6 +1098,8 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_init_cache; } @@ -1072,32 +1109,29 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_prime_handle_to_fd; } bo_sprd->dmabuf = arg.fd; } - /* add bo to hash */ - privGem = calloc(1, sizeof(PrivGem)); - if (!privGem) { - TBM_SPRD_ERROR("error Fail to alloc\n"); - goto fail_alloc_gem_priv; - } + /* add bo_sprd to hash */ + if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) + TBM_SPRD_ERROR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); - privGem->ref_count = 1; - privGem->bo_priv = bo_sprd; - if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) - TBM_SPRD_ERROR("error Cannot insert bo to Hash(%d)\n", bo_sprd->name); + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + bo_sprd->flags_tbm, bo_sprd->flags_sprd, + bo_sprd->size); - TBM_SPRD_DEBUG("size:%d, gem:%d(%d), flags:%d(%d)\n", - bo_sprd->size, bo_sprd->gem, bo_sprd->name, - bo_sprd->flags_tbm, bo_sprd->flags_sprd); + if (error) + *error = TBM_ERROR_NONE; - return (void *)bo_sprd; + return (tbm_backend_bo_data *)bo_sprd; -fail_alloc_gem_priv: - if (bo_sprd->dmabuf) - close(bo_sprd->dmabuf); fail_prime_handle_to_fd: _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); fail_init_cache: @@ -1111,51 +1145,64 @@ fail_get_gem: return NULL; } -static void * -tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) +static tbm_backend_bo_data * +tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, NULL); - - tbm_bufmgr_sprd bufmgr_sprd; + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; tbm_bo_sprd bo_sprd; + unsigned int gem; unsigned int name; - PrivGem *privGem; + int ret; + char buf[STRERR_BUFSIZE]; - bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, NULL); + if (bufmgr_sprd == NULL) { + TBM_SPRD_ERROR("bufmgr_data is null\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } - //getting handle from fd + /*getting handle from fd*/ struct drm_prime_handle arg = {0, }; - unsigned int gem; arg.fd = key; if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) { - TBM_SPRD_ERROR("error bo:%p Cannot get gem handle from fd:%d (%s)\n", - bo, arg.fd, strerror(errno)); + TBM_SPRD_ERROR("Cannot get gem handle from fd:%d (%s)\n", + arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return NULL; } gem = arg.handle; name = _get_name(bufmgr_sprd->fd, gem); if (!name) { - TBM_SPRD_ERROR("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n", - bo, gem, key, strerror(errno)); + TBM_SPRD_ERROR("Cannot get name from gem:%d, fd:%d (%s)\n", + gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return NULL; } - if (!drmHashLookup(bufmgr_sprd->hashBos, name, (void **)&privGem)) { - if (gem == privGem->bo_priv->gem) - return privGem->bo_priv; + ret = drmHashLookup(bufmgr_sprd->hashBos, name, (void **)&bo_sprd); + if (ret == 0) { + if (gem == bo_sprd->gem) { + if (error) + *error = TBM_ERROR_NONE; + return bo_sprd; + } } - unsigned int real_size; - struct drm_sprd_gem_info info = {0, }; - - /* Determine size of bo. The fd-to-handle ioctl really should + /* Determine size of bo_sprd. The fd-to-handle ioctl really should * return the size, but it doesn't. If we have kernel 3.12 or * later, we can lseek on the prime fd to get the size. Older * kernels will just fail, in which case we fall back to the - * provided (estimated or guess size). */ + * provided (estimated or guess size). + * */ + + unsigned int real_size; + struct drm_sprd_gem_info info = {0, }; + real_size = lseek(key, 0, SEEK_END); info.handle = gem; @@ -1163,8 +1210,10 @@ tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) DRM_SPRD_GEM_GET, &info, sizeof(struct drm_sprd_gem_info))) { - TBM_SPRD_ERROR("error bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n", - bo, gem, key, strerror(errno)); + TBM_SPRD_ERROR("Cannot get gem info from gem:%d, fd:%d (%s)\n", + gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return NULL; } @@ -1173,176 +1222,207 @@ tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_ERROR("error bo:%p fail to allocate the bo private\n", bo); + TBM_SPRD_ERROR("error bo_sprd:%p fail to allocate the bo_sprd\n", bo_sprd); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; } + bo_sprd->bufmgr_sprd = bufmgr_sprd; bo_sprd->fd = bufmgr_sprd->fd; bo_sprd->gem = gem; bo_sprd->size = real_size; bo_sprd->flags_sprd = info.flags; bo_sprd->flags_tbm = _get_tbm_flag_from_sprd(bo_sprd->flags_sprd); - bo_sprd->name = name; - if (!bo_sprd->name) { - TBM_SPRD_ERROR("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n", - bo, gem, key, strerror(errno)); - goto fail_check_name; - } if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_init_cache; } - /* add bo to hash */ - privGem = calloc(1, sizeof(PrivGem)); - if (!privGem) { - TBM_SPRD_ERROR("error Fail to callocprivGem\n"); - goto fail_alloc_gem_priv; - } - - privGem->ref_count = 1; - privGem->bo_priv = bo_sprd; - if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) { - TBM_SPRD_ERROR("error bo:%p Cannot insert bo to Hash(%d) from gem:%d, fd:%d\n", - bo, bo_sprd->name, gem, key); - } + /* add bo_sprd to hash */ + if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) + TBM_SPRD_ERROR("bo_sprd:%p Cannot insert bo_sprd to Hash(%d) from gem:%d, fd:%d\n", + bo_sprd, bo_sprd->name, gem, key); - TBM_SPRD_DEBUG("bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - bo, + TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, key, bo_sprd->flags_tbm, bo_sprd->flags_sprd, bo_sprd->size); - return (void *)bo_sprd; + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_backend_bo_data *)bo_sprd; -fail_alloc_gem_priv: - _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); fail_init_cache: -fail_check_name: free(bo_sprd); return NULL; } -static unsigned int -tbm_sprd_bo_export(tbm_bo bo) +static tbm_key +tbm_sprd_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); - - tbm_bo_sprd bo_sprd; + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } if (!bo_sprd->name) { bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); if (!bo_sprd->name) { TBM_SPRD_ERROR("error Cannot get name\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return 0; } } - TBM_SPRD_DEBUG("size:%d, gem:%d(%d), flags:%d(%d)\n", - bo_sprd->size, bo_sprd->gem, bo_sprd->name, - bo_sprd->flags_tbm, bo_sprd->flags_sprd); + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + bo_sprd->flags_tbm, bo_sprd->flags_sprd, + bo_sprd->size); + + if (error) + *error = TBM_ERROR_NONE; - return (unsigned int)bo_sprd->name; + return (tbm_key)bo_sprd->name; } static tbm_fd -tbm_sprd_bo_export_fd(tbm_bo bo) +tbm_sprd_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, -1); - - tbm_bo_sprd bo_sprd; + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + struct drm_prime_handle arg = {0, }; int ret; + char buf[STRERR_BUFSIZE]; - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, -1); - - struct drm_prime_handle arg = {0, }; + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return -1; + } arg.handle = bo_sprd->gem; ret = drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); if (ret) { - TBM_SPRD_ERROR("error bo:%p Cannot dmabuf=%d (%s)\n", - bo, bo_sprd->gem, strerror(errno)); + TBM_SPRD_ERROR("bo_sprd:%p Cannot dmabuf=%d (%s)\n", + bo_sprd, bo_sprd->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return (tbm_fd) ret; } - TBM_SPRD_DEBUG("bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - bo, + TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, arg.fd, bo_sprd->flags_tbm, bo_sprd->flags_sprd, bo_sprd->size); + if (error) + *error = TBM_ERROR_NONE; + return (tbm_fd)arg.fd; } - static tbm_bo_handle -tbm_sprd_bo_get_handle(tbm_bo bo, int device) +tbm_sprd_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, (tbm_bo_handle) NULL); - + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; tbm_bo_handle bo_handle; - tbm_bo_sprd bo_sprd; - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, (tbm_bo_handle) NULL); + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } if (!bo_sprd->gem) { - TBM_SPRD_ERROR("error Cannot map gem=%d\n", bo_sprd->gem); + TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return (tbm_bo_handle) NULL; } - TBM_SPRD_DEBUG("gem:%d(%d), %s\n", - bo_sprd->gem, bo_sprd->name, STR_DEVICE[device]); + TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d, %s\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + bo_sprd->flags_tbm, bo_sprd->flags_sprd, + bo_sprd->size, + STR_DEVICE[device]); /*Get mapped bo_handle*/ bo_handle = _sprd_bo_handle(bo_sprd, device); if (bo_handle.ptr == NULL) { - TBM_SPRD_ERROR("error Cannot get handle: gem:%d, device:%d\n", + TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d\n", bo_sprd->gem, device); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return (tbm_bo_handle) NULL; } + if (error) + *error = TBM_ERROR_NONE; + return bo_handle; } static tbm_bo_handle -tbm_sprd_bo_map(tbm_bo bo, int device, int opt) +tbm_sprd_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, + tbm_bo_access_option opt, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, (tbm_bo_handle) NULL); - + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; tbm_bo_handle bo_handle; - tbm_bo_sprd bo_sprd; tbm_bufmgr_sprd bufmgr_sprd; - bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, (tbm_bo_handle) NULL); + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, (tbm_bo_handle) NULL); + bufmgr_sprd = bo_sprd->bufmgr_sprd; + if (!bufmgr_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } if (!bo_sprd->gem) { - TBM_SPRD_ERROR("error Cannot map gem=%d\n", bo_sprd->gem); + TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; return (tbm_bo_handle) NULL; } - TBM_SPRD_DEBUG("%s gem:%d(%d), %s, %s\n", - __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device], STR_OPT[opt]); + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, %s, %s\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + STR_DEVICE[device], + STR_OPT[opt]); /*Get mapped bo_handle*/ bo_handle = _sprd_bo_handle(bo_sprd, device); if (bo_handle.ptr == NULL) { - TBM_SPRD_ERROR("error Cannot get handle: gem:%d, device:%d, opt:%d\n", + TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d, opt:%d\n", bo_sprd->gem, device, opt); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; return (tbm_bo_handle) NULL; } @@ -1351,49 +1431,58 @@ tbm_sprd_bo_map(tbm_bo bo, int device, int opt) bo_sprd->map_cnt++; + if (error) + *error = TBM_ERROR_NONE; + return bo_handle; } -static int -tbm_sprd_bo_unmap(tbm_bo bo) +static tbm_error_e +tbm_sprd_bo_unmap(tbm_backend_bo_data *bo_data) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); - + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; tbm_bufmgr_sprd bufmgr_sprd; - tbm_bo_sprd bo_sprd; - bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + if (!bo_sprd) + return TBM_ERROR_INVALID_PARAMETER; - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + bufmgr_sprd = bo_sprd->bufmgr_sprd; + if (!bufmgr_sprd) + return TBM_ERROR_INVALID_PARAMETER; if (!bo_sprd->gem) - return 0; + return TBM_ERROR_INVALID_PARAMETER; bo_sprd->map_cnt--; if (bo_sprd->map_cnt == 0) _bo_save_cache_state(bufmgr_sprd, bo_sprd); - TBM_SPRD_DEBUG("gem:%d(%d) \n", bo_sprd->gem, bo_sprd->name); + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf); - return 1; + return TBM_ERROR_NONE; } static void -tbm_sprd_bufmgr_deinit(void *priv) +tbm_sprd_deinit(tbm_backend_bufmgr_data *bufmgr_data) { - SPRD_RETURN_IF_FAIL(priv != NULL); + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; + tbm_bufmgr bufmgr; + tbm_error_e error; + unsigned long key; + void *value; - tbm_bufmgr_sprd bufmgr_sprd; + SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); - bufmgr_sprd = (tbm_bufmgr_sprd)priv; + bufmgr = bufmgr_sprd->bufmgr; - if (bufmgr_sprd->hashBos) { - unsigned long key; - void *value; + tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_sprd->bufmgr_func); + tbm_backend_bufmgr_free_bo_func(bufmgr, bufmgr_sprd->bo_func); + if (bufmgr_sprd->hashBos) { while (drmHashFirst(bufmgr_sprd->hashBos, &key, &value) > 0) { free(value); drmHashDelete(bufmgr_sprd->hashBos, key); @@ -1406,7 +1495,7 @@ tbm_sprd_bufmgr_deinit(void *priv) if (bufmgr_sprd->bind_display) tbm_drm_helper_wl_auth_server_deinit(); - if (tbm_backend_is_display_server()) + if (tbm_backend_bufmgr_query_display_server(bufmgr, &error)) tbm_drm_helper_unset_tbm_master_fd(); tbm_drm_helper_unset_fd(); @@ -1421,44 +1510,36 @@ tbm_sprd_bufmgr_deinit(void *priv) free(bufmgr_sprd); } -static int -tbm_sprd_surface_supported_format(uint32_t **formats, uint32_t *num) +static tbm_error_e +tbm_sprd_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, + uint32_t **formats, uint32_t *num) { + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; uint32_t *color_formats; - color_formats = (uint32_t *)calloc(1, - sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); + + color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); if (color_formats == NULL) - return 0; + return TBM_ERROR_OUT_OF_MEMORY; - memcpy(color_formats, tbm_sprd_color_format_list, - sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); + memcpy(color_formats, tbm_sprd_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); *formats = color_formats; *num = TBM_COLOR_FORMAT_COUNT; - return 1; -} + TBM_SPRD_DEBUG("supported format count = %d\n", *num); + return TBM_ERROR_NONE; +} -/** - * @brief get the plane data of the surface. - * @param[in] width : the width of the surface - * @param[in] height : the height of the surface - * @param[in] format : the format of the surface - * @param[in] plane_idx : the format of the surface - * @param[out] size : the size of the plane - * @param[out] offset : the offset of the plane - * @param[out] pitch : the pitch of the plane - * @param[out] padding : the padding of the plane - * @return 1 if this function succeeds, otherwise 0. - */ -static int -tbm_sprd_surface_get_plane_data(int width, int height, - tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, - uint32_t *pitch, int *bo_idx) +static tbm_error_e +tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, + tbm_format format, int plane_idx, int width, + int height, uint32_t *size, uint32_t *offset, + uint32_t *pitch, int *bo_idx) { - int ret = 1; + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; int bpp; int _offset = 0; int _pitch = 0; @@ -1466,6 +1547,8 @@ tbm_sprd_surface_get_plane_data(int width, int height, int _bo_idx = 0; int _align_height = 0; + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); + switch (format) { /* 16 bpp RGB */ case TBM_FORMAT_XRGB4444: @@ -1699,73 +1782,88 @@ tbm_sprd_surface_get_plane_data(int width, int height, *pitch = _pitch; *bo_idx = _bo_idx; - return ret; + return TBM_ERROR_NONE; } -static int -tbm_sprd_bo_get_flags(tbm_bo bo) +static tbm_bo_memory_type +tbm_sprd_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - tbm_bo_sprd bo_sprd; + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return TBM_BO_DEFAULT; + } - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + if (error) + *error = TBM_ERROR_NONE; return bo_sprd->flags_tbm; } -static int -tbm_sprd_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay) +static tbm_bufmgr_capability +tbm_sprd_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) { - tbm_bufmgr_sprd bufmgr_sprd; + tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE; - bufmgr_sprd = tbm_backend_get_priv_from_bufmgr(bufmgr); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD; + + if (error) + *error = TBM_ERROR_NONE; + + return capabilities; +} + +static tbm_error_e +tbm_sprd_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) +{ + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); - if (!tbm_drm_helper_wl_auth_server_init(NativeDisplay, bufmgr_sprd->fd, + if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_sprd->fd, bufmgr_sprd->device_name, 0)) { TBM_SPRD_ERROR("fail to tbm_drm_helper_wl_server_init\n"); - return 0; + return TBM_ERROR_OPERATION_FAILED; } - bufmgr_sprd->bind_display = NativeDisplay; + bufmgr_sprd->bind_display = native_display; - return 1; + return TBM_ERROR_NONE; } -MODULEINITPPROTO(init_tbm_bufmgr_priv); - -static TBMModuleVersionInfo SprdVersRec = { - "sprd", - "Samsung", - TBM_ABI_VERSION, -}; - -TBMModuleData tbmModuleData = { &SprdVersRec, init_tbm_bufmgr_priv}; - -int -init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) +static tbm_backend_bufmgr_data * +tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) { - tbm_bufmgr_backend bufmgr_backend; - tbm_bufmgr_sprd bufmgr_sprd; + tbm_bufmgr_sprd bufmgr_sprd = NULL; + tbm_backend_bufmgr_func *bufmgr_func = NULL; + tbm_backend_bo_func *bo_func = NULL; int fp; + tbm_error_e err; - if (!bufmgr) - return 0; + if (!bufmgr) { + TBM_SPRD_ERROR("bufmgr is null.\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; + } bufmgr_sprd = calloc(1, sizeof(struct _tbm_bufmgr_sprd)); if (!bufmgr_sprd) { TBM_SPRD_ERROR("fail to alloc bufmgr_sprd!\n"); - return 0; + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + return NULL; } - if (tbm_backend_is_display_server()) { + if (tbm_backend_bufmgr_query_display_server(bufmgr, &err)) { bufmgr_sprd->fd = tbm_drm_helper_get_master_fd(); if (bufmgr_sprd->fd < 0) { bufmgr_sprd->fd = _tbm_sprd_open_drm(); if (bufmgr_sprd->fd < 0) { TBM_SPRD_ERROR("fail to open drm!\n"); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_open_drm; } } @@ -1776,20 +1874,21 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) if (!bufmgr_sprd->device_name) { TBM_SPRD_ERROR("fail to get device name!\n"); tbm_drm_helper_unset_tbm_master_fd(); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_device_name; } } else { if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) { TBM_SPRD_ERROR("fail to get auth drm info!\n"); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_auth_info; } } tbm_drm_helper_set_fd(bufmgr_sprd->fd); - //Create Hash Table - bufmgr_sprd->hashBos = drmHashCreate(); - //Check if the tbm manager supports dma fence or not. fp = open("/sys/module/dmabuf_sync/parameters/enabled", O_RDONLY); if (fp != -1) { @@ -1804,38 +1903,69 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) if (!_bufmgr_init_cache_state(bufmgr_sprd)) { TBM_SPRD_ERROR("fail to init bufmgr cache state\n"); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; goto fail_init_cache_state; } - bufmgr_backend = tbm_backend_alloc(); - if (!bufmgr_backend) { - TBM_SPRD_ERROR("fail to alloc backend!\n"); - goto fail_alloc_backend; - } - - bufmgr_backend->priv = (void *)bufmgr_sprd; - bufmgr_backend->bufmgr_deinit = tbm_sprd_bufmgr_deinit; - bufmgr_backend->bo_size = tbm_sprd_bo_size; - bufmgr_backend->bo_alloc = tbm_sprd_bo_alloc; - bufmgr_backend->bo_free = tbm_sprd_bo_free; - bufmgr_backend->bo_import = tbm_sprd_bo_import; - bufmgr_backend->bo_import_fd = tbm_sprd_bo_import_fd; - bufmgr_backend->bo_export = tbm_sprd_bo_export; - bufmgr_backend->bo_export_fd = tbm_sprd_bo_export_fd; - bufmgr_backend->bo_get_handle = tbm_sprd_bo_get_handle; - bufmgr_backend->bo_map = tbm_sprd_bo_map; - bufmgr_backend->bo_unmap = tbm_sprd_bo_unmap; - bufmgr_backend->surface_get_plane_data = tbm_sprd_surface_get_plane_data; - bufmgr_backend->surface_supported_format = tbm_sprd_surface_supported_format; - bufmgr_backend->bo_get_flags = tbm_sprd_bo_get_flags; - bufmgr_backend->bo_lock = NULL; - bufmgr_backend->bo_unlock = NULL; - bufmgr_backend->bufmgr_bind_native_display = tbm_sprd_bufmgr_bind_native_display; - - if (!tbm_backend_init(bufmgr, bufmgr_backend)) { - TBM_SPRD_ERROR("fail to init backend!\n"); - goto fail_init_backend; - } + /*Create Hash Table*/ + bufmgr_sprd->hashBos = drmHashCreate(); + + /* alloc and register bufmgr_funcs */ + bufmgr_func = tbm_backend_bufmgr_alloc_bufmgr_func(bufmgr, &err); + if (!bufmgr_func) { + TBM_SPRD_ERROR("fail to alloc bufmgr_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + goto fail_alloc_bufmgr_func; + } + + bufmgr_func->bufmgr_get_capabilities = tbm_sprd_bufmgr_get_capabilities; + bufmgr_func->bufmgr_bind_native_display = tbm_sprd_bufmgr_bind_native_display; + bufmgr_func->bufmgr_get_supported_formats = tbm_sprd_bufmgr_get_supported_formats; + bufmgr_func->bufmgr_get_plane_data = tbm_sprd_bufmgr_get_plane_data; + bufmgr_func->bufmgr_alloc_bo = tbm_sprd_bufmgr_alloc_bo; + bufmgr_func->bufmgr_alloc_bo_with_format = NULL; + bufmgr_func->bufmgr_import_fd = tbm_sprd_bufmgr_import_fd; + bufmgr_func->bufmgr_import_key = tbm_sprd_bufmgr_import; + + err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func); + if (err != TBM_ERROR_NONE) { + TBM_SPRD_ERROR("fail to register bufmgr_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + goto fail_register_bufmgr_func; + } + bufmgr_sprd->bufmgr_func = bufmgr_func; + + /* alloc and register bo_funcs */ + bo_func = tbm_backend_bufmgr_alloc_bo_func(bufmgr, &err); + if (!bo_func) { + TBM_SPRD_ERROR("fail to alloc bo_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OUT_OF_MEMORY; + goto fail_alloc_bo_func; + } + + bo_func->bo_free = tbm_sprd_bo_free; + bo_func->bo_get_size = tbm_sprd_bo_get_size; + bo_func->bo_get_memory_types = tbm_sprd_bo_get_memory_type; + bo_func->bo_get_handle = tbm_sprd_bo_get_handle; + bo_func->bo_map = tbm_sprd_bo_map; + bo_func->bo_unmap = tbm_sprd_bo_unmap; + bo_func->bo_lock = NULL; + bo_func->bo_unlock = NULL; + bo_func->bo_export_fd = tbm_sprd_bo_export_fd; + bo_func->bo_export_key = tbm_sprd_bo_export_key; + + err = tbm_backend_bufmgr_register_bo_func(bufmgr, bo_func); + if (err != TBM_ERROR_NONE) { + TBM_SPRD_ERROR("fail to register bo_func! err(%d)\n", err); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + goto fail_register_bo_func; + } + bufmgr_sprd->bo_func = bo_func; #ifdef DEBUG { @@ -1854,16 +1984,24 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!"); TBM_SPRD_DEBUG("fd:%d\n", bufmgr_sprd->fd); - return 1; + if (error) + *error = TBM_ERROR_NONE; -fail_init_backend: - tbm_backend_free(bufmgr_backend); -fail_alloc_backend: + bufmgr_sprd->bufmgr = bufmgr; + + return (tbm_backend_bufmgr_data *)bufmgr_sprd; + +fail_register_bo_func: + tbm_backend_bufmgr_free_bo_func(bufmgr, bo_func); +fail_alloc_bo_func: +fail_register_bufmgr_func: + tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_func); +fail_alloc_bufmgr_func: _bufmgr_deinit_cache_state(bufmgr_sprd); -fail_init_cache_state: if (bufmgr_sprd->hashBos) drmHashDestroy(bufmgr_sprd->hashBos); - if (tbm_backend_is_display_server()) +fail_init_cache_state: + if (tbm_backend_bufmgr_query_display_server(bufmgr, &err)) tbm_drm_helper_unset_tbm_master_fd(); tbm_drm_helper_unset_fd(); if (bufmgr_sprd->device_name) @@ -1873,6 +2011,13 @@ fail_get_device_name: fail_get_auth_info: fail_open_drm: free(bufmgr_sprd); - return 0; + return NULL; } +tbm_backend_module tbm_backend_module_data = { + "sprd", + "Samsung", + TBM_BACKEND_ABI_VERSION_2_0, + tbm_sprd_init, + tbm_sprd_deinit +}; -- 2.7.4 From 970b0af84a93a361468e9b88d92029e67211fe4d Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 19 Mar 2018 19:28:23 +0900 Subject: [PATCH 03/16] re-arrange the static functions. Change-Id: I4041bfde1dc4c29bacf74340442008086c95f6dc --- src/tbm_bufmgr_sprd.c | 1368 ++++++++++++++++++++++++------------------------- 1 file changed, 683 insertions(+), 685 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 997e4d2..437d6eb 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -488,8 +488,6 @@ _tbm_sprd_open_drm(void) close(fd); return -1; } -#else - TBM_SPRD_ERROR("warning fail to open drm\n"); #endif return fd; @@ -864,215 +862,323 @@ _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) return bo_handle; } -static int -tbm_sprd_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) +static tbm_bufmgr_capability +tbm_sprd_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) { - tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE; - if (!bo_sprd) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return 0; - } + capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD; if (error) *error = TBM_ERROR_NONE; - return bo_sprd->size; + return capabilities; } -static tbm_backend_bo_data * -tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_memory_type flags, tbm_error_e *error) +static tbm_error_e +tbm_sprd_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) { tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; - tbm_bo_sprd bo_sprd; - unsigned int sprd_flags; - - if (bufmgr_sprd == NULL) { - TBM_SPRD_ERROR("bufmgr_data is null\n"); - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return NULL; - } - - bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); - if (!bo_sprd) { - TBM_SPRD_ERROR("error fail to allocate the bo_sprd\n"); - if (error) - *error = TBM_ERROR_OUT_OF_MEMORY; - return NULL; - } - bo_sprd->bufmgr_sprd = bufmgr_sprd; - -#ifdef USE_CONTIG_ONLY - flags = TBM_BO_SCANOUT; - sprd_flags = SPRD_BO_CONTIG; -#else - sprd_flags = _get_sprd_flag_from_tbm(flags); - if ((flags & TBM_BO_SCANOUT) && (size <= 4 * 1024)) - sprd_flags |= SPRD_BO_NONCONTIG; -#endif // USE_CONTIG_ONLY - - struct drm_sprd_gem_create arg = {0, }; - - arg.size = (uint64_t)size; - arg.flags = sprd_flags; - if (drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CREATE, &arg, - sizeof(arg))) { - TBM_SPRD_ERROR("error Cannot create bo_sprd(flag:%x, size:%d)\n", - arg.flags, (unsigned int)arg.size); - free(bo_sprd); - if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return NULL; - } - - bo_sprd->fd = bufmgr_sprd->fd; - bo_sprd->gem = arg.handle; - bo_sprd->size = size; - bo_sprd->flags_tbm = flags; - bo_sprd->flags_sprd = sprd_flags; - bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); - - if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 0)) { - TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); - free(bo_sprd); - if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return NULL; - } - - pthread_mutex_init(&bo_sprd->mutex, NULL); - - if (bufmgr_sprd->use_dma_fence && !bo_sprd->dmabuf) { - struct drm_prime_handle arg = {0, }; + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); - arg.handle = bo_sprd->gem; - if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { - TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); - free(bo_sprd); - if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return NULL; - } - bo_sprd->dmabuf = arg.fd; + if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_sprd->fd, + bufmgr_sprd->device_name, 0)) { + TBM_SPRD_ERROR("fail to tbm_drm_helper_wl_server_init\n"); + return TBM_ERROR_OPERATION_FAILED; } - /* add bo_sprd to hash */ - if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) - TBM_SPRD_ERROR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); - - TBM_SPRD_DEBUG("%s size:%d, gem:%d(%d), flags:%d(%d)\n", - __FUNCTION__, bo_sprd->size, - bo_sprd->gem, bo_sprd->name, - flags, sprd_flags); - - if (error) - *error = TBM_ERROR_NONE; + bufmgr_sprd->bind_display = native_display; - return (tbm_backend_bo_data *)bo_sprd; + return TBM_ERROR_NONE; } -static void -tbm_sprd_bo_free(tbm_backend_bo_data *bo_data) +static tbm_error_e +tbm_sprd_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, + uint32_t **formats, uint32_t *num) { - tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - tbm_bo_sprd temp; - tbm_bufmgr_sprd bufmgr_sprd; - char buf[STRERR_BUFSIZE]; - int ret; - - if (!bo_data) - return; - - bufmgr_sprd = bo_sprd->bufmgr_sprd; - if (!bufmgr_sprd) - return; - - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, size:%d\n", - bo_sprd, - bo_sprd->gem, bo_sprd->name, - bo_sprd->dmabuf, - bo_sprd->size); - - if (bo_sprd->pBase) { - if (munmap(bo_sprd->pBase, bo_sprd->size) == -1) { - TBM_SPRD_ERROR("bo_sprd:%p fail to munmap(%s)\n", - bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); - } - } + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; + uint32_t *color_formats; - /* close dmabuf */ - if (bo_sprd->dmabuf) { - close(bo_sprd->dmabuf); - bo_sprd->dmabuf = 0; - } + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); - /* delete bo from hash */ - ret = drmHashLookup(bufmgr_sprd->hashBos, bo_sprd->name, - (void **)&temp); - if (ret == 0) - drmHashDelete(bufmgr_sprd->hashBos, bo_sprd->name); - else - TBM_SPRD_ERROR("Cannot find bo_sprd to Hash(%d), ret=%d\n", bo_sprd->name, ret); + color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); + if (color_formats == NULL) + return TBM_ERROR_OUT_OF_MEMORY; - if (temp != bo_sprd) - TBM_SPRD_ERROR("hashBos probably has several BOs with same name!!!\n"); + memcpy(color_formats, tbm_sprd_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); - _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); + *formats = color_formats; + *num = TBM_COLOR_FORMAT_COUNT; - /* Free gem handle */ - struct drm_gem_close arg = {0, }; + TBM_SPRD_DEBUG("supported format count = %d\n", *num); - memset(&arg, 0, sizeof(arg)); - arg.handle = bo_sprd->gem; - if (drmIoctl(bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg)) - TBM_SPRD_ERROR("bo_sprd:%p fail to gem close.(%s)\n", - bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); - free(bo_sprd); + return TBM_ERROR_NONE; } -static tbm_backend_bo_data * -tbm_sprd_bufmgr_import(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) +static tbm_error_e +tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, + tbm_format format, int plane_idx, int width, + int height, uint32_t *size, uint32_t *offset, + uint32_t *pitch, int *bo_idx) { tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; - tbm_bo_sprd bo_sprd; - int ret; - - if (bufmgr_sprd == NULL) { - TBM_SPRD_ERROR("bufmgr_data is null\n"); - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return NULL; - } + int bpp; + int _offset = 0; + int _pitch = 0; + int _size = 0; + int _bo_idx = 0; + int _align_height = 0; - ret = drmHashLookup(bufmgr_sprd->hashBos, key, (void **)&bo_sprd); - if (ret == 0) { - if (error) - *error = TBM_ERROR_NONE; - return (tbm_backend_bo_data *)bo_sprd; - } + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); - struct drm_gem_open arg = {0, }; - struct drm_sprd_gem_info info = {0, }; + switch (format) { + /* 16 bpp RGB */ + case TBM_FORMAT_XRGB4444: + case TBM_FORMAT_XBGR4444: + case TBM_FORMAT_RGBX4444: + case TBM_FORMAT_BGRX4444: + case TBM_FORMAT_ARGB4444: + case TBM_FORMAT_ABGR4444: + case TBM_FORMAT_RGBA4444: + case TBM_FORMAT_BGRA4444: + case TBM_FORMAT_XRGB1555: + case TBM_FORMAT_XBGR1555: + case TBM_FORMAT_RGBX5551: + case TBM_FORMAT_BGRX5551: + case TBM_FORMAT_ARGB1555: + case TBM_FORMAT_ABGR1555: + case TBM_FORMAT_RGBA5551: + case TBM_FORMAT_BGRA5551: + case TBM_FORMAT_RGB565: + bpp = 16; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; + /* 24 bpp RGB */ + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + bpp = 24; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; + /* 32 bpp RGB */ + case TBM_FORMAT_XRGB8888: + case TBM_FORMAT_XBGR8888: + case TBM_FORMAT_RGBX8888: + case TBM_FORMAT_BGRX8888: + case TBM_FORMAT_ARGB8888: + case TBM_FORMAT_ABGR8888: + case TBM_FORMAT_RGBA8888: + case TBM_FORMAT_BGRA8888: + bpp = 32; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; - arg.name = key; - if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg)) { - TBM_SPRD_ERROR("error Cannot open gem name=%d\n", key); - if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return NULL; + /* packed YCbCr */ + case TBM_FORMAT_YUYV: + case TBM_FORMAT_YVYU: + case TBM_FORMAT_UYVY: + case TBM_FORMAT_VYUY: + case TBM_FORMAT_AYUV: + bpp = 32; + _offset = 0; + _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + break; + + /* + * 2 plane YCbCr + * index 0 = Y plane, [7:0] Y + * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian + * or + * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian + */ + case TBM_FORMAT_NV12: + case TBM_FORMAT_NV21: + bpp = 12; +// if (plane_idx == 0) + { + _offset = 0; + _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _align_height = SIZE_ALIGN(height, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } +// else if (plane_idx == 1) + { + _offset = _size; + _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + bpp = 16; + //if(plane_idx == 0) + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + //else if( plane_idx ==1 ) + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + + /* + * 3 plane YCbCr + * index 0: Y plane, [7:0] Y + * index 1: Cb plane, [7:0] Cb + * index 2: Cr plane, [7:0] Cr + * or + * index 1: Cr plane, [7:0] Cr + * index 2: Cb plane, [7:0] Cb + */ + /* + NATIVE_BUFFER_FORMAT_YV12 + NATIVE_BUFFER_FORMAT_I420 + */ + case TBM_FORMAT_YUV410: + case TBM_FORMAT_YVU410: + bpp = 9; + break; + case TBM_FORMAT_YUV411: + case TBM_FORMAT_YVU411: + case TBM_FORMAT_YUV420: + case TBM_FORMAT_YVU420: + bpp = 12; + //if(plane_idx == 0) + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _align_height = SIZE_ALIGN(height, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + //else if( plane_idx == 1 ) + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 1) + break; + } + //else if (plane_idx == 2 ) + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + case TBM_FORMAT_YUV422: + case TBM_FORMAT_YVU422: + bpp = 16; + //if(plane_idx == 0) + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + //else if( plane_idx == 1 ) + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 1) + break; + } + //else if (plane_idx == 2 ) + { + _offset += _size; + _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + case TBM_FORMAT_YUV444: + case TBM_FORMAT_YVU444: + bpp = 24; + //if(plane_idx == 0) + { + _offset = 0; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 0) + break; + } + //else if( plane_idx == 1 ) + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + if (plane_idx == 1) + break; + } + //else if (plane_idx == 2 ) + { + _offset += _size; + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 0; + } + break; + default: + bpp = 0; + break; } - info.handle = arg.handle; - if (drmCommandWriteRead(bufmgr_sprd->fd, - DRM_SPRD_GEM_GET, - &info, - sizeof(struct drm_sprd_gem_info))) { - TBM_SPRD_ERROR("error Cannot get gem info=%d\n", key); + *size = _size; + *offset = _offset; + *pitch = _pitch; + *bo_idx = _bo_idx; + + return TBM_ERROR_NONE; +} + +static tbm_backend_bo_data * +tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_memory_type flags, tbm_error_e *error) +{ + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; + tbm_bo_sprd bo_sprd; + unsigned int sprd_flags; + + if (bufmgr_sprd == NULL) { + TBM_SPRD_ERROR("bufmgr_data is null\n"); if (error) - *error = TBM_ERROR_OPERATION_FAILED; - goto fail_get_gem; + *error = TBM_ERROR_INVALID_PARAMETER; + return NULL; } bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); @@ -1080,38 +1186,60 @@ tbm_sprd_bufmgr_import(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_er TBM_SPRD_ERROR("error fail to allocate the bo_sprd\n"); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; - goto fail_alloc_bo; + return NULL; } bo_sprd->bufmgr_sprd = bufmgr_sprd; - bo_sprd->fd = bufmgr_sprd->fd; - bo_sprd->gem = arg.handle; - bo_sprd->size = arg.size; - bo_sprd->flags_sprd = info.flags; - bo_sprd->name = key; #ifdef USE_CONTIG_ONLY - bo_sprd->flags_sprd = SPRD_BO_CONTIG; - bo_sprd->flags_tbm |= TBM_BO_SCANOUT; + flags = TBM_BO_SCANOUT; + sprd_flags = SPRD_BO_CONTIG; #else - bo_sprd->flags_tbm = _get_tbm_flag_from_sprd(bo_sprd->flags_sprd); -#endif + sprd_flags = _get_sprd_flag_from_tbm(flags); + if ((flags & TBM_BO_SCANOUT) && (size <= 4 * 1024)) + sprd_flags |= SPRD_BO_NONCONTIG; +#endif // USE_CONTIG_ONLY - if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { + struct drm_sprd_gem_create arg = {0, }; + + arg.size = (uint64_t)size; + arg.flags = sprd_flags; + if (drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CREATE, &arg, + sizeof(arg))) { + TBM_SPRD_ERROR("error Cannot create bo_sprd(flag:%x, size:%d)\n", + arg.flags, (unsigned int)arg.size); + free(bo_sprd); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; + } + + bo_sprd->fd = bufmgr_sprd->fd; + bo_sprd->gem = arg.handle; + bo_sprd->size = size; + bo_sprd->flags_tbm = flags; + bo_sprd->flags_sprd = sprd_flags; + bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); + + if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 0)) { TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); + free(bo_sprd); if (error) *error = TBM_ERROR_OPERATION_FAILED; - goto fail_init_cache; + return NULL; } - if (!bo_sprd->dmabuf) { + pthread_mutex_init(&bo_sprd->mutex, NULL); + + if (bufmgr_sprd->use_dma_fence && !bo_sprd->dmabuf) { struct drm_prime_handle arg = {0, }; arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); + free(bo_sprd); if (error) *error = TBM_ERROR_OPERATION_FAILED; - goto fail_prime_handle_to_fd; + return NULL; } bo_sprd->dmabuf = arg.fd; } @@ -1120,29 +1248,15 @@ tbm_sprd_bufmgr_import(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_er if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) TBM_SPRD_ERROR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", - bo_sprd, - bo_sprd->gem, bo_sprd->name, - bo_sprd->dmabuf, - bo_sprd->flags_tbm, bo_sprd->flags_sprd, - bo_sprd->size); + TBM_SPRD_DEBUG("%s size:%d, gem:%d(%d), flags:%d(%d)\n", + __FUNCTION__, bo_sprd->size, + bo_sprd->gem, bo_sprd->name, + flags, sprd_flags); if (error) *error = TBM_ERROR_NONE; return (tbm_backend_bo_data *)bo_sprd; - -fail_prime_handle_to_fd: - _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); -fail_init_cache: - free(bo_sprd); -fail_alloc_bo: -fail_get_gem: - { - struct drm_gem_close gem_close_arg = {arg.handle, 0}; - drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_CLOSE, &gem_close_arg); - } - return NULL; } static tbm_backend_bo_data * @@ -1266,523 +1380,193 @@ fail_init_cache: return NULL; } -static tbm_key -tbm_sprd_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) +static tbm_backend_bo_data * +tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error) { - tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; + tbm_bo_sprd bo_sprd; + int ret; - if (!bo_sprd) { + if (bufmgr_sprd == NULL) { + TBM_SPRD_ERROR("bufmgr_data is null\n"); if (error) *error = TBM_ERROR_INVALID_PARAMETER; - return 0; + return NULL; } - if (!bo_sprd->name) { - bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); - if (!bo_sprd->name) { - TBM_SPRD_ERROR("error Cannot get name\n"); - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return 0; - } + ret = drmHashLookup(bufmgr_sprd->hashBos, key, (void **)&bo_sprd); + if (ret == 0) { + if (error) + *error = TBM_ERROR_NONE; + return (tbm_backend_bo_data *)bo_sprd; } - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", - bo_sprd, - bo_sprd->gem, bo_sprd->name, - bo_sprd->dmabuf, - bo_sprd->flags_tbm, bo_sprd->flags_sprd, - bo_sprd->size); - - if (error) - *error = TBM_ERROR_NONE; - - return (tbm_key)bo_sprd->name; -} - -static tbm_fd -tbm_sprd_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) -{ - tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - struct drm_prime_handle arg = {0, }; - int ret; - char buf[STRERR_BUFSIZE]; + struct drm_gem_open arg = {0, }; + struct drm_sprd_gem_info info = {0, }; - if (!bo_sprd) { + arg.name = key; + if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg)) { + TBM_SPRD_ERROR("error Cannot open gem name=%d\n", key); if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return -1; + *error = TBM_ERROR_OPERATION_FAILED; + return NULL; } - arg.handle = bo_sprd->gem; - ret = drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); - if (ret) { - TBM_SPRD_ERROR("bo_sprd:%p Cannot dmabuf=%d (%s)\n", - bo_sprd, bo_sprd->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); + info.handle = arg.handle; + if (drmCommandWriteRead(bufmgr_sprd->fd, + DRM_SPRD_GEM_GET, + &info, + sizeof(struct drm_sprd_gem_info))) { + TBM_SPRD_ERROR("error Cannot get gem info=%d\n", key); if (error) *error = TBM_ERROR_OPERATION_FAILED; - return (tbm_fd) ret; + goto fail_get_gem; } - TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - bo_sprd, - bo_sprd->gem, bo_sprd->name, - bo_sprd->dmabuf, - arg.fd, - bo_sprd->flags_tbm, bo_sprd->flags_sprd, - bo_sprd->size); - - if (error) - *error = TBM_ERROR_NONE; - - return (tbm_fd)arg.fd; -} - -static tbm_bo_handle -tbm_sprd_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) -{ - tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - tbm_bo_handle bo_handle; - + bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { + TBM_SPRD_ERROR("error fail to allocate the bo_sprd\n"); if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return (tbm_bo_handle) NULL; + *error = TBM_ERROR_OUT_OF_MEMORY; + goto fail_alloc_bo; } + bo_sprd->bufmgr_sprd = bufmgr_sprd; - if (!bo_sprd->gem) { - TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); + bo_sprd->fd = bufmgr_sprd->fd; + bo_sprd->gem = arg.handle; + bo_sprd->size = arg.size; + bo_sprd->flags_sprd = info.flags; + bo_sprd->name = key; +#ifdef USE_CONTIG_ONLY + bo_sprd->flags_sprd = SPRD_BO_CONTIG; + bo_sprd->flags_tbm |= TBM_BO_SCANOUT; +#else + bo_sprd->flags_tbm = _get_tbm_flag_from_sprd(bo_sprd->flags_sprd); +#endif + + if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { + TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return (tbm_bo_handle) NULL; + *error = TBM_ERROR_OPERATION_FAILED; + goto fail_init_cache; } - TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d, %s\n", + if (!bo_sprd->dmabuf) { + struct drm_prime_handle arg = {0, }; + + arg.handle = bo_sprd->gem; + if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { + TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + goto fail_prime_handle_to_fd; + } + bo_sprd->dmabuf = arg.fd; + } + + /* add bo_sprd to hash */ + if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) + TBM_SPRD_ERROR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); + + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, bo_sprd->flags_tbm, bo_sprd->flags_sprd, - bo_sprd->size, - STR_DEVICE[device]); - - /*Get mapped bo_handle*/ - bo_handle = _sprd_bo_handle(bo_sprd, device); - if (bo_handle.ptr == NULL) { - TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d\n", - bo_sprd->gem, device); - if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return (tbm_bo_handle) NULL; - } + bo_sprd->size); if (error) *error = TBM_ERROR_NONE; - return bo_handle; + return (tbm_backend_bo_data *)bo_sprd; + +fail_prime_handle_to_fd: + _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); +fail_init_cache: + free(bo_sprd); +fail_alloc_bo: +fail_get_gem: + { + struct drm_gem_close gem_close_arg = {arg.handle, 0}; + drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_CLOSE, &gem_close_arg); + } + return NULL; } -static tbm_bo_handle -tbm_sprd_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, - tbm_bo_access_option opt, tbm_error_e *error) +static void +tbm_sprd_bo_free(tbm_backend_bo_data *bo_data) { tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - tbm_bo_handle bo_handle; + tbm_bo_sprd temp; tbm_bufmgr_sprd bufmgr_sprd; + char buf[STRERR_BUFSIZE]; + int ret; - if (!bo_sprd) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return (tbm_bo_handle) NULL; - } + if (!bo_data) + return; bufmgr_sprd = bo_sprd->bufmgr_sprd; - if (!bufmgr_sprd) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return (tbm_bo_handle) NULL; - } - - if (!bo_sprd->gem) { - TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return (tbm_bo_handle) NULL; - } + if (!bufmgr_sprd) + return; - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, %s, %s\n", + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, size:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, - STR_DEVICE[device], - STR_OPT[opt]); + bo_sprd->size); - /*Get mapped bo_handle*/ - bo_handle = _sprd_bo_handle(bo_sprd, device); - if (bo_handle.ptr == NULL) { - TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d, opt:%d\n", - bo_sprd->gem, device, opt); - if (error) - *error = TBM_ERROR_OPERATION_FAILED; - return (tbm_bo_handle) NULL; + if (bo_sprd->pBase) { + if (munmap(bo_sprd->pBase, bo_sprd->size) == -1) { + TBM_SPRD_ERROR("bo_sprd:%p fail to munmap(%s)\n", + bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); + } } - if (bo_sprd->map_cnt == 0) - _bo_set_cache_state(bufmgr_sprd, bo_sprd, device, opt); + /* close dmabuf */ + if (bo_sprd->dmabuf) { + close(bo_sprd->dmabuf); + bo_sprd->dmabuf = 0; + } - bo_sprd->map_cnt++; + /* delete bo from hash */ + ret = drmHashLookup(bufmgr_sprd->hashBos, bo_sprd->name, + (void **)&temp); + if (ret == 0) + drmHashDelete(bufmgr_sprd->hashBos, bo_sprd->name); + else + TBM_SPRD_ERROR("Cannot find bo_sprd to Hash(%d), ret=%d\n", bo_sprd->name, ret); - if (error) - *error = TBM_ERROR_NONE; + if (temp != bo_sprd) + TBM_SPRD_ERROR("hashBos probably has several BOs with same name!!!\n"); - return bo_handle; -} + _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); -static tbm_error_e -tbm_sprd_bo_unmap(tbm_backend_bo_data *bo_data) -{ - tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; - tbm_bufmgr_sprd bufmgr_sprd; - - if (!bo_sprd) - return TBM_ERROR_INVALID_PARAMETER; - - bufmgr_sprd = bo_sprd->bufmgr_sprd; - if (!bufmgr_sprd) - return TBM_ERROR_INVALID_PARAMETER; - - if (!bo_sprd->gem) - return TBM_ERROR_INVALID_PARAMETER; - - bo_sprd->map_cnt--; - - if (bo_sprd->map_cnt == 0) - _bo_save_cache_state(bufmgr_sprd, bo_sprd); - - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d\n", - bo_sprd, - bo_sprd->gem, bo_sprd->name, - bo_sprd->dmabuf); - - return TBM_ERROR_NONE; -} - -static void -tbm_sprd_deinit(tbm_backend_bufmgr_data *bufmgr_data) -{ - tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; - tbm_bufmgr bufmgr; - tbm_error_e error; - unsigned long key; - void *value; - - SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); - - bufmgr = bufmgr_sprd->bufmgr; - - tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_sprd->bufmgr_func); - tbm_backend_bufmgr_free_bo_func(bufmgr, bufmgr_sprd->bo_func); - - if (bufmgr_sprd->hashBos) { - while (drmHashFirst(bufmgr_sprd->hashBos, &key, &value) > 0) { - free(value); - drmHashDelete(bufmgr_sprd->hashBos, key); - } - - drmHashDestroy(bufmgr_sprd->hashBos); - bufmgr_sprd->hashBos = NULL; - } - - if (bufmgr_sprd->bind_display) - tbm_drm_helper_wl_auth_server_deinit(); - - if (tbm_backend_bufmgr_query_display_server(bufmgr, &error)) - tbm_drm_helper_unset_tbm_master_fd(); - - tbm_drm_helper_unset_fd(); - - if (bufmgr_sprd->device_name) - free(bufmgr_sprd->device_name); - - _bufmgr_deinit_cache_state(bufmgr_sprd); - - close(bufmgr_sprd->fd); - - free(bufmgr_sprd); -} - -static tbm_error_e -tbm_sprd_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, - uint32_t **formats, uint32_t *num) -{ - tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; - uint32_t *color_formats; - - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); - - color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); - if (color_formats == NULL) - return TBM_ERROR_OUT_OF_MEMORY; - - memcpy(color_formats, tbm_sprd_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); - - *formats = color_formats; - *num = TBM_COLOR_FORMAT_COUNT; - - TBM_SPRD_DEBUG("supported format count = %d\n", *num); + /* Free gem handle */ + struct drm_gem_close arg = {0, }; - return TBM_ERROR_NONE; + memset(&arg, 0, sizeof(arg)); + arg.handle = bo_sprd->gem; + if (drmIoctl(bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg)) + TBM_SPRD_ERROR("bo_sprd:%p fail to gem close.(%s)\n", + bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); + free(bo_sprd); } -static tbm_error_e -tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, - tbm_format format, int plane_idx, int width, - int height, uint32_t *size, uint32_t *offset, - uint32_t *pitch, int *bo_idx) -{ - tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; - int bpp; - int _offset = 0; - int _pitch = 0; - int _size = 0; - int _bo_idx = 0; - int _align_height = 0; - - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); - - switch (format) { - /* 16 bpp RGB */ - case TBM_FORMAT_XRGB4444: - case TBM_FORMAT_XBGR4444: - case TBM_FORMAT_RGBX4444: - case TBM_FORMAT_BGRX4444: - case TBM_FORMAT_ARGB4444: - case TBM_FORMAT_ABGR4444: - case TBM_FORMAT_RGBA4444: - case TBM_FORMAT_BGRA4444: - case TBM_FORMAT_XRGB1555: - case TBM_FORMAT_XBGR1555: - case TBM_FORMAT_RGBX5551: - case TBM_FORMAT_BGRX5551: - case TBM_FORMAT_ARGB1555: - case TBM_FORMAT_ABGR1555: - case TBM_FORMAT_RGBA5551: - case TBM_FORMAT_BGRA5551: - case TBM_FORMAT_RGB565: - bpp = 16; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - /* 24 bpp RGB */ - case TBM_FORMAT_RGB888: - case TBM_FORMAT_BGR888: - bpp = 24; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - /* 32 bpp RGB */ - case TBM_FORMAT_XRGB8888: - case TBM_FORMAT_XBGR8888: - case TBM_FORMAT_RGBX8888: - case TBM_FORMAT_BGRX8888: - case TBM_FORMAT_ARGB8888: - case TBM_FORMAT_ABGR8888: - case TBM_FORMAT_RGBA8888: - case TBM_FORMAT_BGRA8888: - bpp = 32; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - - /* packed YCbCr */ - case TBM_FORMAT_YUYV: - case TBM_FORMAT_YVYU: - case TBM_FORMAT_UYVY: - case TBM_FORMAT_VYUY: - case TBM_FORMAT_AYUV: - bpp = 32; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - - /* - * 2 plane YCbCr - * index 0 = Y plane, [7:0] Y - * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian - * or - * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian - */ - case TBM_FORMAT_NV12: - case TBM_FORMAT_NV21: - bpp = 12; -// if (plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _align_height = SIZE_ALIGN(height, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } -// else if (plane_idx == 1) - { - _offset = _size; - _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - - case TBM_FORMAT_NV16: - case TBM_FORMAT_NV61: - bpp = 16; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx ==1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - - /* - * 3 plane YCbCr - * index 0: Y plane, [7:0] Y - * index 1: Cb plane, [7:0] Cb - * index 2: Cr plane, [7:0] Cr - * or - * index 1: Cr plane, [7:0] Cr - * index 2: Cb plane, [7:0] Cb - */ - /* - NATIVE_BUFFER_FORMAT_YV12 - NATIVE_BUFFER_FORMAT_I420 - */ - case TBM_FORMAT_YUV410: - case TBM_FORMAT_YVU410: - bpp = 9; - break; - case TBM_FORMAT_YUV411: - case TBM_FORMAT_YVU411: - case TBM_FORMAT_YUV420: - case TBM_FORMAT_YVU420: - bpp = 12; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _align_height = SIZE_ALIGN(height, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx == 1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - //else if (plane_idx == 2 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_YUV422: - case TBM_FORMAT_YVU422: - bpp = 16; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx == 1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - //else if (plane_idx == 2 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_YUV444: - case TBM_FORMAT_YVU444: - bpp = 24; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx == 1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - //else if (plane_idx == 2 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - default: - bpp = 0; - break; +static int +tbm_sprd_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) +{ + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; } - *size = _size; - *offset = _offset; - *pitch = _pitch; - *bo_idx = _bo_idx; + if (error) + *error = TBM_ERROR_NONE; - return TBM_ERROR_NONE; + return bo_sprd->size; } static tbm_bo_memory_type @@ -1802,34 +1586,248 @@ tbm_sprd_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error) return bo_sprd->flags_tbm; } -static tbm_bufmgr_capability -tbm_sprd_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error) +static tbm_bo_handle +tbm_sprd_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) { - tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE; + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + tbm_bo_handle bo_handle; - capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD; + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } + + if (!bo_sprd->gem) { + TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } + + TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d, %s\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + bo_sprd->flags_tbm, bo_sprd->flags_sprd, + bo_sprd->size, + STR_DEVICE[device]); + + /*Get mapped bo_handle*/ + bo_handle = _sprd_bo_handle(bo_sprd, device); + if (bo_handle.ptr == NULL) { + TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d\n", + bo_sprd->gem, device); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return (tbm_bo_handle) NULL; + } if (error) *error = TBM_ERROR_NONE; - return capabilities; + return bo_handle; +} + +static tbm_bo_handle +tbm_sprd_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, + tbm_bo_access_option opt, tbm_error_e *error) +{ + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + tbm_bo_handle bo_handle; + tbm_bufmgr_sprd bufmgr_sprd; + + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } + + bufmgr_sprd = bo_sprd->bufmgr_sprd; + if (!bufmgr_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } + + if (!bo_sprd->gem) { + TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return (tbm_bo_handle) NULL; + } + + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, %s, %s\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + STR_DEVICE[device], + STR_OPT[opt]); + + /*Get mapped bo_handle*/ + bo_handle = _sprd_bo_handle(bo_sprd, device); + if (bo_handle.ptr == NULL) { + TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d, opt:%d\n", + bo_sprd->gem, device, opt); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return (tbm_bo_handle) NULL; + } + + if (bo_sprd->map_cnt == 0) + _bo_set_cache_state(bufmgr_sprd, bo_sprd, device, opt); + + bo_sprd->map_cnt++; + + if (error) + *error = TBM_ERROR_NONE; + + return bo_handle; } static tbm_error_e -tbm_sprd_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) +tbm_sprd_bo_unmap(tbm_backend_bo_data *bo_data) +{ + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + tbm_bufmgr_sprd bufmgr_sprd; + + if (!bo_sprd) + return TBM_ERROR_INVALID_PARAMETER; + + bufmgr_sprd = bo_sprd->bufmgr_sprd; + if (!bufmgr_sprd) + return TBM_ERROR_INVALID_PARAMETER; + + if (!bo_sprd->gem) + return TBM_ERROR_INVALID_PARAMETER; + + bo_sprd->map_cnt--; + + if (bo_sprd->map_cnt == 0) + _bo_save_cache_state(bufmgr_sprd, bo_sprd); + + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf); + + return TBM_ERROR_NONE; +} + +static tbm_fd +tbm_sprd_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) +{ + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + struct drm_prime_handle arg = {0, }; + int ret; + char buf[STRERR_BUFSIZE]; + + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return -1; + } + + arg.handle = bo_sprd->gem; + ret = drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); + if (ret) { + TBM_SPRD_ERROR("bo_sprd:%p Cannot dmabuf=%d (%s)\n", + bo_sprd, bo_sprd->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); + if (error) + *error = TBM_ERROR_OPERATION_FAILED; + return (tbm_fd) ret; + } + + TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + arg.fd, + bo_sprd->flags_tbm, bo_sprd->flags_sprd, + bo_sprd->size); + + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_fd)arg.fd; +} + +static tbm_key +tbm_sprd_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) +{ + tbm_bo_sprd bo_sprd = (tbm_bo_sprd)bo_data; + + if (!bo_sprd) { + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } + + if (!bo_sprd->name) { + bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); + if (!bo_sprd->name) { + TBM_SPRD_ERROR("error Cannot get name\n"); + if (error) + *error = TBM_ERROR_INVALID_PARAMETER; + return 0; + } + } + + TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + bo_sprd, + bo_sprd->gem, bo_sprd->name, + bo_sprd->dmabuf, + bo_sprd->flags_tbm, bo_sprd->flags_sprd, + bo_sprd->size); + + if (error) + *error = TBM_ERROR_NONE; + + return (tbm_key)bo_sprd->name; +} + +static void +tbm_sprd_deinit(tbm_backend_bufmgr_data *bufmgr_data) { tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); + tbm_bufmgr bufmgr; + tbm_error_e error; + unsigned long key; + void *value; - if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_sprd->fd, - bufmgr_sprd->device_name, 0)) { - TBM_SPRD_ERROR("fail to tbm_drm_helper_wl_server_init\n"); - return TBM_ERROR_OPERATION_FAILED; + SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); + + bufmgr = bufmgr_sprd->bufmgr; + + tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_sprd->bufmgr_func); + tbm_backend_bufmgr_free_bo_func(bufmgr, bufmgr_sprd->bo_func); + + if (bufmgr_sprd->hashBos) { + while (drmHashFirst(bufmgr_sprd->hashBos, &key, &value) > 0) { + free(value); + drmHashDelete(bufmgr_sprd->hashBos, key); + } + + drmHashDestroy(bufmgr_sprd->hashBos); + bufmgr_sprd->hashBos = NULL; } - bufmgr_sprd->bind_display = native_display; + if (bufmgr_sprd->bind_display) + tbm_drm_helper_wl_auth_server_deinit(); - return TBM_ERROR_NONE; + if (tbm_backend_bufmgr_query_display_server(bufmgr, &error)) + tbm_drm_helper_unset_tbm_master_fd(); + + tbm_drm_helper_unset_fd(); + + if (bufmgr_sprd->device_name) + free(bufmgr_sprd->device_name); + + _bufmgr_deinit_cache_state(bufmgr_sprd); + + close(bufmgr_sprd->fd); + + free(bufmgr_sprd); } static tbm_backend_bufmgr_data * @@ -1927,7 +1925,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) bufmgr_func->bufmgr_alloc_bo = tbm_sprd_bufmgr_alloc_bo; bufmgr_func->bufmgr_alloc_bo_with_format = NULL; bufmgr_func->bufmgr_import_fd = tbm_sprd_bufmgr_import_fd; - bufmgr_func->bufmgr_import_key = tbm_sprd_bufmgr_import; + bufmgr_func->bufmgr_import_key = tbm_sprd_bufmgr_import_key; err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func); if (err != TBM_ERROR_NONE) { -- 2.7.4 From 70702265d21303193aefdbe5901d17acb281734b Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 19 Mar 2018 20:54:51 +0900 Subject: [PATCH 04/16] use the tbm_log.h for logging Change-Id: I695630634cd3884a76ef207884923aeae869d871 --- src/tbm_bufmgr_sprd.c | 221 ++++++++++++++++++-------------------------------- 1 file changed, 81 insertions(+), 140 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 437d6eb..afe29f1 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -52,8 +52,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include -#define DEBUG //#define USE_CONTIG_ONLY //#define USE_CACHE #define USE_DMAIMPORT @@ -64,54 +64,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define TBM_COLOR_FORMAT_COUNT 4 -#ifdef DEBUG -#define LOG_TAG "TBM_BACKEND" -#include -static int bDebug = 0; - #define SPRD_DRM_NAME "sprd" -static char * -_target_name(void) -{ - static char app_name[128] = {0, }; - static int initialized = 0; - char *slash; - FILE *f; - - if (initialized) - return app_name; - - /* get the application name */ - f = fopen("/proc/self/cmdline", "r"); - if (!f) - return NULL; - - memset(app_name, 0x00, sizeof(app_name)); - - if (fgets(app_name, 100, f) == NULL) { - fclose(f); - return NULL; - } - - fclose(f); - - slash = strrchr(app_name, '/'); - if (slash != NULL) - memmove(app_name, slash + 1, strlen(slash)); - - initialized = 1; - - return app_name; -} - -#define TBM_SPRD_ERROR(fmt, args...) LOGE("\033[31m" "[%s] " fmt "\033[0m", _target_name(), ##args) -#define TBM_SPRD_DEBUG(fmt, args...) if (bDebug&01) LOGD("[%s] " fmt, _target_name(), ##args) -#else -#define TBM_SPRD_ERROR(...) -#define TBM_SPRD_DEBUG(...) -#endif - #define STRERR_BUFSIZE 128 #define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1)) @@ -124,13 +78,13 @@ _target_name(void) /* check condition */ #define SPRD_RETURN_IF_FAIL(cond) {\ if (!(cond)) {\ - TBM_SPRD_ERROR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + TBM_ERR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ return;\ } \ } #define SPRD_RETURN_VAL_IF_FAIL(cond, val) {\ if (!(cond)) {\ - TBM_SPRD_ERROR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + TBM_ERR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ return val;\ } \ } @@ -268,12 +222,12 @@ _tgl_get_version(int fd) err = ioctl(fd, TGL_IOCTL_GET_VERSION, &data); if (err) { - TBM_SPRD_ERROR("error(%s) %s:%d\n", + TBM_ERR("error(%s) %s:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE)); return 0; } - TBM_SPRD_DEBUG("tgl version is (%u, %u).\n", data.major, data.minor); + TBM_DBG("tgl version is (%u, %u).\n", data.major, data.minor); return 1; } @@ -290,7 +244,7 @@ _tgl_init(int fd, unsigned int key) err = ioctl(fd, TGL_IOCTL_REGISTER, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d\n", + TBM_ERR("error(%s) key:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -308,7 +262,7 @@ _tgl_destroy(int fd, unsigned int key) data.key = key; err = ioctl(fd, TGL_IOCTL_UNREGISTER, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d\n", + TBM_ERR("error(%s) key:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -341,7 +295,7 @@ _tgl_lock(int fd, unsigned int key, int opt) err = ioctl(fd, TGL_IOCTL_LOCK, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d opt:%d\n", + TBM_ERR("error(%s) key:%d opt:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key, opt); return 0; } @@ -361,7 +315,7 @@ _tgl_unlock(int fd, unsigned int key) err = ioctl(fd, TGL_IOCTL_UNLOCK, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d\n", + TBM_ERR("error(%s) key:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -381,7 +335,7 @@ _tgl_set_data(int fd, unsigned int key, unsigned int val) err = ioctl(fd, TGL_IOCTL_SET_DATA, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d\n", + TBM_ERR("error(%s) key:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -400,7 +354,7 @@ _tgl_get_data(int fd, unsigned int key, unsigned int *locked) err = ioctl(fd, TGL_IOCTL_GET_DATA, &data); if (err) { - TBM_SPRD_ERROR("error(%s) key:%d\n", + TBM_ERR("error(%s) key:%d\n", strerror_r(errno, buf, STRERR_BUFSIZE), key); return 0; } @@ -430,11 +384,11 @@ _tbm_sprd_open_drm(void) return fd; #ifdef HAVE_UDEV - TBM_SPRD_DEBUG("warning fail to open drm. search drm-device by udev\n"); + TBM_DBG("warning fail to open drm. search drm-device by udev\n"); udev = udev_new(); if (!udev) { - TBM_SPRD_ERROR("udev_new() failed.\n"); + TBM_ERR("udev_new() failed.\n"); return -1; } @@ -453,7 +407,7 @@ _tbm_sprd_open_drm(void) if (device_parent) { if (strcmp(udev_device_get_sysname(device_parent), "sprd-drm") == 0) { drm_device = device; - TBM_SPRD_DEBUG("Found render device: '%s' (%s)\n", + TBM_DBG("Found render device: '%s' (%s)\n", udev_device_get_syspath(drm_device), udev_device_get_sysname(device_parent)); break; @@ -467,7 +421,7 @@ _tbm_sprd_open_drm(void) /* Get device file path. */ filepath = udev_device_get_devnode(drm_device); if (!filepath) { - TBM_SPRD_ERROR("udev_device_get_devnode() failed.\n"); + TBM_ERR("udev_device_get_devnode() failed.\n"); udev_device_unref(drm_device); udev_unref(udev); return -1; @@ -479,12 +433,12 @@ _tbm_sprd_open_drm(void) /* Open DRM device file and check validity. */ fd = open(filepath, O_RDWR | O_CLOEXEC); if (fd < 0) { - TBM_SPRD_ERROR("open(%s, O_RDWR | O_CLOEXEC) failed.\n"); + TBM_ERR("open(%s, O_RDWR | O_CLOEXEC) failed.\n"); return -1; } if (fstat(fd, &s)) { - TBM_SPRD_ERROR("fstat() failed %s.\n"); + TBM_ERR("fstat() failed %s.\n"); close(fd); return -1; } @@ -540,7 +494,7 @@ _sprd_bo_cache_flush(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags ret = drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CACHE_OP, &cache_op, sizeof(cache_op)); if (ret) { - TBM_SPRD_ERROR("error fail to flush the cache.\n"); + TBM_ERR("error fail to flush the cache.\n"); return 0; } #endif @@ -630,7 +584,7 @@ _bo_set_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int device /* call cache flush */ _sprd_bo_cache_flush(bufmgr_sprd, bo_sprd, need_flush); - TBM_SPRD_DEBUG("\tcache(%d,%d)....flush:0x%x, cntFlush(%d)\n", + TBM_DBG("\tcache(%d,%d)....flush:0x%x, cntFlush(%d)\n", bo_sprd->cache_state.data.isCached, bo_sprd->cache_state.data.isDirtied, need_flush, @@ -693,20 +647,20 @@ _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) if (bufmgr_sprd->tgl_fd < 0) { bufmgr_sprd->tgl_fd = open(tgl_devfile1, O_RDWR); if (bufmgr_sprd->tgl_fd < 0) { - TBM_SPRD_ERROR("fail to open global_lock:%s\n", + TBM_ERR("fail to open global_lock:%s\n", tgl_devfile1); return 0; } } if (!_tgl_get_version(bufmgr_sprd->tgl_fd)) { - TBM_SPRD_ERROR("fail to get tgl_version. tgl init failed.\n"); + TBM_ERR("fail to get tgl_version. tgl init failed.\n"); close(bufmgr_sprd->tgl_fd); return 0; } if (!_tgl_init(bufmgr_sprd->tgl_fd, GLOBAL_KEY)) { - TBM_SPRD_ERROR("fail to initialize the tgl\n"); + TBM_ERR("fail to initialize the tgl\n"); close(bufmgr_sprd->tgl_fd); return 0; } @@ -783,7 +737,7 @@ _get_name(int fd, unsigned int gem) arg.handle = gem; if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) { - TBM_SPRD_ERROR("fail to DRM_IOCTL_GEM_FLINK gem:%d", gem); + TBM_ERR("fail to DRM_IOCTL_GEM_FLINK gem:%d", gem); return 0; } @@ -809,7 +763,7 @@ _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) arg.handle = bo_sprd->gem; arg.size = bo_sprd->size; if (drmCommandWriteRead(bo_sprd->fd, DRM_SPRD_GEM_MMAP, &arg, sizeof(arg))) { - TBM_SPRD_ERROR("error Cannot usrptr gem=%d\n", bo_sprd->gem); + TBM_ERR("error Cannot usrptr gem=%d\n", bo_sprd->gem); return (tbm_bo_handle) NULL; } bo_sprd->pBase = (void *)((uint32_t)arg.mapped); @@ -823,7 +777,7 @@ _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) struct drm_prime_handle arg = {0, }; arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { - TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); + TBM_ERR("error Cannot dmabuf=%d\n", bo_sprd->gem); return (tbm_bo_handle) NULL; } bo_sprd->dmabuf = arg.fd; @@ -837,14 +791,14 @@ _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) case TBM_DEVICE_MM: #ifdef USE_HEAP_ID //TODO : Add ioctl for GSP MAP once available. - TBM_SPRD_DEBUG("%s In case TBM_DEVICE_MM: \n", __FUNCTION_); + TBM_DBG("%s In case TBM_DEVICE_MM: \n", __FUNCTION_); #else if (!bo_sprd->dmabuf) { struct drm_prime_handle arg = {0, }; arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { - TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); + TBM_ERR("error Cannot dmabuf=%d\n", bo_sprd->gem); return (tbm_bo_handle) NULL; } bo_sprd->dmabuf = arg.fd; @@ -854,7 +808,7 @@ _sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) #endif break; default: - TBM_SPRD_ERROR("Not supported device:%d\n", device); + TBM_ERR("Not supported device:%d\n", device); bo_handle.ptr = (void *) NULL; break; } @@ -883,7 +837,7 @@ tbm_sprd_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_na if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_sprd->fd, bufmgr_sprd->device_name, 0)) { - TBM_SPRD_ERROR("fail to tbm_drm_helper_wl_server_init\n"); + TBM_ERR("fail to tbm_drm_helper_wl_server_init\n"); return TBM_ERROR_OPERATION_FAILED; } @@ -910,7 +864,7 @@ tbm_sprd_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, *formats = color_formats; *num = TBM_COLOR_FORMAT_COUNT; - TBM_SPRD_DEBUG("supported format count = %d\n", *num); + TBM_DBG("supported format count = %d\n", *num); return TBM_ERROR_NONE; } @@ -1175,7 +1129,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_ unsigned int sprd_flags; if (bufmgr_sprd == NULL) { - TBM_SPRD_ERROR("bufmgr_data is null\n"); + TBM_ERR("bufmgr_data is null\n"); if (error) *error = TBM_ERROR_INVALID_PARAMETER; return NULL; @@ -1183,7 +1137,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_ bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_ERROR("error fail to allocate the bo_sprd\n"); + TBM_ERR("error fail to allocate the bo_sprd\n"); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; @@ -1205,7 +1159,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_ arg.flags = sprd_flags; if (drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CREATE, &arg, sizeof(arg))) { - TBM_SPRD_ERROR("error Cannot create bo_sprd(flag:%x, size:%d)\n", + TBM_ERR("error Cannot create bo_sprd(flag:%x, size:%d)\n", arg.flags, (unsigned int)arg.size); free(bo_sprd); if (error) @@ -1221,7 +1175,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_ bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 0)) { - TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); + TBM_ERR("error fail init cache state(%d)\n", bo_sprd->name); free(bo_sprd); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1235,7 +1189,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_ arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { - TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); + TBM_ERR("error Cannot dmabuf=%d\n", bo_sprd->gem); free(bo_sprd); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1246,9 +1200,9 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_ /* add bo_sprd to hash */ if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) - TBM_SPRD_ERROR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); + TBM_ERR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); - TBM_SPRD_DEBUG("%s size:%d, gem:%d(%d), flags:%d(%d)\n", + TBM_DBG("%s size:%d, gem:%d(%d), flags:%d(%d)\n", __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name, flags, sprd_flags); @@ -1270,7 +1224,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ char buf[STRERR_BUFSIZE]; if (bufmgr_sprd == NULL) { - TBM_SPRD_ERROR("bufmgr_data is null\n"); + TBM_ERR("bufmgr_data is null\n"); if (error) *error = TBM_ERROR_INVALID_PARAMETER; return NULL; @@ -1281,7 +1235,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ arg.fd = key; if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) { - TBM_SPRD_ERROR("Cannot get gem handle from fd:%d (%s)\n", + TBM_ERR("Cannot get gem handle from fd:%d (%s)\n", arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1291,7 +1245,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ name = _get_name(bufmgr_sprd->fd, gem); if (!name) { - TBM_SPRD_ERROR("Cannot get name from gem:%d, fd:%d (%s)\n", + TBM_ERR("Cannot get name from gem:%d, fd:%d (%s)\n", gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1324,7 +1278,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ DRM_SPRD_GEM_GET, &info, sizeof(struct drm_sprd_gem_info))) { - TBM_SPRD_ERROR("Cannot get gem info from gem:%d, fd:%d (%s)\n", + TBM_ERR("Cannot get gem info from gem:%d, fd:%d (%s)\n", gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1336,7 +1290,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_ERROR("error bo_sprd:%p fail to allocate the bo_sprd\n", bo_sprd); + TBM_ERR("error bo_sprd:%p fail to allocate the bo_sprd\n", bo_sprd); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; @@ -1351,7 +1305,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ bo_sprd->name = name; if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { - TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); + TBM_ERR("error fail init cache state(%d)\n", bo_sprd->name); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_init_cache; @@ -1359,10 +1313,10 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ /* add bo_sprd to hash */ if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) - TBM_SPRD_ERROR("bo_sprd:%p Cannot insert bo_sprd to Hash(%d) from gem:%d, fd:%d\n", + TBM_ERR("bo_sprd:%p Cannot insert bo_sprd to Hash(%d) from gem:%d, fd:%d\n", bo_sprd, bo_sprd->name, gem, key); - TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + TBM_DBG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1388,7 +1342,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb int ret; if (bufmgr_sprd == NULL) { - TBM_SPRD_ERROR("bufmgr_data is null\n"); + TBM_ERR("bufmgr_data is null\n"); if (error) *error = TBM_ERROR_INVALID_PARAMETER; return NULL; @@ -1406,7 +1360,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb arg.name = key; if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg)) { - TBM_SPRD_ERROR("error Cannot open gem name=%d\n", key); + TBM_ERR("error Cannot open gem name=%d\n", key); if (error) *error = TBM_ERROR_OPERATION_FAILED; return NULL; @@ -1417,7 +1371,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb DRM_SPRD_GEM_GET, &info, sizeof(struct drm_sprd_gem_info))) { - TBM_SPRD_ERROR("error Cannot get gem info=%d\n", key); + TBM_ERR("error Cannot get gem info=%d\n", key); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_gem; @@ -1425,7 +1379,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_ERROR("error fail to allocate the bo_sprd\n"); + TBM_ERR("error fail to allocate the bo_sprd\n"); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; goto fail_alloc_bo; @@ -1445,7 +1399,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb #endif if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { - TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name); + TBM_ERR("error fail init cache state(%d)\n", bo_sprd->name); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_init_cache; @@ -1456,7 +1410,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { - TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem); + TBM_ERR("error Cannot dmabuf=%d\n", bo_sprd->gem); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_prime_handle_to_fd; @@ -1466,9 +1420,9 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb /* add bo_sprd to hash */ if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)bo_sprd) < 0) - TBM_SPRD_ERROR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); + TBM_ERR("Cannot insert bo_sprd to Hash(%d)\n", bo_sprd->name); - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + TBM_DBG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1509,7 +1463,7 @@ tbm_sprd_bo_free(tbm_backend_bo_data *bo_data) if (!bufmgr_sprd) return; - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, size:%d\n", + TBM_DBG(" bo_sprd:%p, gem:%d(%d), fd:%d, size:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1517,7 +1471,7 @@ tbm_sprd_bo_free(tbm_backend_bo_data *bo_data) if (bo_sprd->pBase) { if (munmap(bo_sprd->pBase, bo_sprd->size) == -1) { - TBM_SPRD_ERROR("bo_sprd:%p fail to munmap(%s)\n", + TBM_ERR("bo_sprd:%p fail to munmap(%s)\n", bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); } } @@ -1534,10 +1488,10 @@ tbm_sprd_bo_free(tbm_backend_bo_data *bo_data) if (ret == 0) drmHashDelete(bufmgr_sprd->hashBos, bo_sprd->name); else - TBM_SPRD_ERROR("Cannot find bo_sprd to Hash(%d), ret=%d\n", bo_sprd->name, ret); + TBM_ERR("Cannot find bo_sprd to Hash(%d), ret=%d\n", bo_sprd->name, ret); if (temp != bo_sprd) - TBM_SPRD_ERROR("hashBos probably has several BOs with same name!!!\n"); + TBM_ERR("hashBos probably has several BOs with same name!!!\n"); _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); @@ -1547,7 +1501,7 @@ tbm_sprd_bo_free(tbm_backend_bo_data *bo_data) memset(&arg, 0, sizeof(arg)); arg.handle = bo_sprd->gem; if (drmIoctl(bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg)) - TBM_SPRD_ERROR("bo_sprd:%p fail to gem close.(%s)\n", + TBM_ERR("bo_sprd:%p fail to gem close.(%s)\n", bo_sprd, strerror_r(errno, buf, STRERR_BUFSIZE)); free(bo_sprd); } @@ -1599,13 +1553,13 @@ tbm_sprd_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, } if (!bo_sprd->gem) { - TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); + TBM_ERR("Cannot map gem=%d\n", bo_sprd->gem); if (error) *error = TBM_ERROR_INVALID_PARAMETER; return (tbm_bo_handle) NULL; } - TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d, %s\n", + TBM_DBG("bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d, %s\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1616,7 +1570,7 @@ tbm_sprd_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, /*Get mapped bo_handle*/ bo_handle = _sprd_bo_handle(bo_sprd, device); if (bo_handle.ptr == NULL) { - TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d\n", + TBM_ERR("Cannot get handle: gem:%d, device:%d\n", bo_sprd->gem, device); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1651,13 +1605,13 @@ tbm_sprd_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, } if (!bo_sprd->gem) { - TBM_SPRD_ERROR("Cannot map gem=%d\n", bo_sprd->gem); + TBM_ERR("Cannot map gem=%d\n", bo_sprd->gem); if (error) *error = TBM_ERROR_INVALID_PARAMETER; return (tbm_bo_handle) NULL; } - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, %s, %s\n", + TBM_DBG(" bo_sprd:%p, gem:%d(%d), fd:%d, %s, %s\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1667,7 +1621,7 @@ tbm_sprd_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, /*Get mapped bo_handle*/ bo_handle = _sprd_bo_handle(bo_sprd, device); if (bo_handle.ptr == NULL) { - TBM_SPRD_ERROR("Cannot get handle: gem:%d, device:%d, opt:%d\n", + TBM_ERR("Cannot get handle: gem:%d, device:%d, opt:%d\n", bo_sprd->gem, device, opt); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1706,7 +1660,7 @@ tbm_sprd_bo_unmap(tbm_backend_bo_data *bo_data) if (bo_sprd->map_cnt == 0) _bo_save_cache_state(bufmgr_sprd, bo_sprd); - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d\n", + TBM_DBG(" bo_sprd:%p, gem:%d(%d), fd:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf); @@ -1731,14 +1685,14 @@ tbm_sprd_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) arg.handle = bo_sprd->gem; ret = drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); if (ret) { - TBM_SPRD_ERROR("bo_sprd:%p Cannot dmabuf=%d (%s)\n", + TBM_ERR("bo_sprd:%p Cannot dmabuf=%d (%s)\n", bo_sprd, bo_sprd->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) *error = TBM_ERROR_OPERATION_FAILED; return (tbm_fd) ret; } - TBM_SPRD_DEBUG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + TBM_DBG("bo_sprd:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1766,14 +1720,14 @@ tbm_sprd_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error) if (!bo_sprd->name) { bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); if (!bo_sprd->name) { - TBM_SPRD_ERROR("error Cannot get name\n"); + TBM_ERR("error Cannot get name\n"); if (error) *error = TBM_ERROR_INVALID_PARAMETER; return 0; } } - TBM_SPRD_DEBUG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", + TBM_DBG(" bo_sprd:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n", bo_sprd, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1840,7 +1794,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) tbm_error_e err; if (!bufmgr) { - TBM_SPRD_ERROR("bufmgr is null.\n"); + TBM_ERR("bufmgr is null.\n"); if (error) *error = TBM_ERROR_INVALID_PARAMETER; return NULL; @@ -1848,7 +1802,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) bufmgr_sprd = calloc(1, sizeof(struct _tbm_bufmgr_sprd)); if (!bufmgr_sprd) { - TBM_SPRD_ERROR("fail to alloc bufmgr_sprd!\n"); + TBM_ERR("fail to alloc bufmgr_sprd!\n"); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; return NULL; @@ -1859,7 +1813,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) if (bufmgr_sprd->fd < 0) { bufmgr_sprd->fd = _tbm_sprd_open_drm(); if (bufmgr_sprd->fd < 0) { - TBM_SPRD_ERROR("fail to open drm!\n"); + TBM_ERR("fail to open drm!\n"); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_open_drm; @@ -1870,7 +1824,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd); if (!bufmgr_sprd->device_name) { - TBM_SPRD_ERROR("fail to get device name!\n"); + TBM_ERR("fail to get device name!\n"); tbm_drm_helper_unset_tbm_master_fd(); if (error) *error = TBM_ERROR_OPERATION_FAILED; @@ -1878,7 +1832,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) } } else { if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) { - TBM_SPRD_ERROR("fail to get auth drm info!\n"); + TBM_ERR("fail to get auth drm info!\n"); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_get_auth_info; @@ -1900,7 +1854,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) } if (!_bufmgr_init_cache_state(bufmgr_sprd)) { - TBM_SPRD_ERROR("fail to init bufmgr cache state\n"); + TBM_ERR("fail to init bufmgr cache state\n"); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_init_cache_state; @@ -1912,7 +1866,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) /* alloc and register bufmgr_funcs */ bufmgr_func = tbm_backend_bufmgr_alloc_bufmgr_func(bufmgr, &err); if (!bufmgr_func) { - TBM_SPRD_ERROR("fail to alloc bufmgr_func! err(%d)\n", err); + TBM_ERR("fail to alloc bufmgr_func! err(%d)\n", err); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; goto fail_alloc_bufmgr_func; @@ -1929,7 +1883,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func); if (err != TBM_ERROR_NONE) { - TBM_SPRD_ERROR("fail to register bufmgr_func! err(%d)\n", err); + TBM_ERR("fail to register bufmgr_func! err(%d)\n", err); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_register_bufmgr_func; @@ -1939,7 +1893,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) /* alloc and register bo_funcs */ bo_func = tbm_backend_bufmgr_alloc_bo_func(bufmgr, &err); if (!bo_func) { - TBM_SPRD_ERROR("fail to alloc bo_func! err(%d)\n", err); + TBM_ERR("fail to alloc bo_func! err(%d)\n", err); if (error) *error = TBM_ERROR_OUT_OF_MEMORY; goto fail_alloc_bo_func; @@ -1958,29 +1912,16 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) err = tbm_backend_bufmgr_register_bo_func(bufmgr, bo_func); if (err != TBM_ERROR_NONE) { - TBM_SPRD_ERROR("fail to register bo_func! err(%d)\n", err); + TBM_ERR("fail to register bo_func! err(%d)\n", err); if (error) *error = TBM_ERROR_OPERATION_FAILED; goto fail_register_bo_func; } bufmgr_sprd->bo_func = bo_func; -#ifdef DEBUG - { - char *env; - - env = getenv("TBM_SPRD_DEBUG"); - if (env) { - bDebug = atoi(env); - TBM_SPRD_ERROR("TBM_SPRD_DEBUG=%s\n", env); - } else - bDebug = 0; - } -#endif - - TBM_SPRD_DEBUG("DMABUF FENCE is %s\n", + TBM_DBG("DMABUF FENCE is %s\n", bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!"); - TBM_SPRD_DEBUG("fd:%d\n", bufmgr_sprd->fd); + TBM_DBG("fd:%d\n", bufmgr_sprd->fd); if (error) *error = TBM_ERROR_NONE; -- 2.7.4 From e949c5c23d4ea2d328bb138eb70e1faa6cc92c42 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 20 Mar 2018 12:57:11 +0900 Subject: [PATCH 05/16] package version up to 2.0.0 Change-Id: Idaa2294aba5542d02ce0acc89943f60f84fdb357 --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 0e4696a..9e6e59d 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 1.0.11 +Version: 2.0.0 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From b0ad2c7c57ef561ccf2112612863047367ca1e1f Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 22 Mar 2018 11:40:56 +0900 Subject: [PATCH 06/16] use tbm_log.h Change-Id: I4cb5411e892e3dab07c9edab523ffbbe78af333f --- src/tbm_bufmgr_sprd.c | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index afe29f1..874deb0 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -74,21 +74,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define TBM_SURFACE_ALIGNMENT_PITCH_RGB (128) #define TBM_SURFACE_ALIGNMENT_PITCH_YUV (16) - -/* check condition */ -#define SPRD_RETURN_IF_FAIL(cond) {\ - if (!(cond)) {\ - TBM_ERR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return;\ - } \ -} -#define SPRD_RETURN_VAL_IF_FAIL(cond, val) {\ - if (!(cond)) {\ - TBM_ERR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return val;\ - } \ -} - struct dma_buf_info { unsigned long size; unsigned int fence_supported; @@ -451,7 +436,7 @@ _tbm_sprd_open_drm(void) static int _sprd_bo_cache_flush(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags) { - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); /* cache flush is managed by kernel side when using dma-fence. */ if (bufmgr_sprd->use_dma_fence) @@ -507,8 +492,8 @@ static int _bo_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int import) { #ifdef USE_CACHE - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) return 1; @@ -533,8 +518,8 @@ static int _bo_set_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int device, int opt) { #ifdef USE_CACHE - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); char need_flush = 0; unsigned short cntFlush = 0; @@ -599,8 +584,8 @@ static int _bo_save_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) { #ifdef USE_CACHE - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) return 1; @@ -622,8 +607,8 @@ static void _bo_destroy_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) { #ifdef USE_CACHE - SPRD_RETURN_IF_FAIL(bo_sprd != NULL); - SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); + TBM_RETURN_IF_FAIL(bo_sprd != NULL); + TBM_RETURN_IF_FAIL(bufmgr_sprd != NULL); if (bufmgr_sprd->use_dma_fence) return; @@ -636,7 +621,7 @@ static int _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) { #ifdef USE_CACHE - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) return 1; @@ -673,7 +658,7 @@ static void _bufmgr_deinit_cache_state(tbm_bufmgr_sprd bufmgr_sprd) { #ifdef USE_CACHE - SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); + TBM_RETURN_IF_FAIL(bufmgr_sprd != NULL); if (bufmgr_sprd->use_dma_fence) return; @@ -833,7 +818,7 @@ static tbm_error_e tbm_sprd_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) { tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_sprd->fd, bufmgr_sprd->device_name, 0)) { @@ -853,7 +838,7 @@ tbm_sprd_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; uint32_t *color_formats; - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); if (color_formats == NULL) @@ -883,7 +868,7 @@ tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, int _bo_idx = 0; int _align_height = 0; - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, TBM_ERROR_INVALID_PARAMETER); switch (format) { /* 16 bpp RGB */ @@ -1749,7 +1734,7 @@ tbm_sprd_deinit(tbm_backend_bufmgr_data *bufmgr_data) unsigned long key; void *value; - SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); + TBM_RETURN_IF_FAIL(bufmgr_sprd != NULL); bufmgr = bufmgr_sprd->bufmgr; -- 2.7.4 From 08bf76547e230bf311b52ffc077db143bdaf1217 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 23 Mar 2018 08:36:00 +0900 Subject: [PATCH 07/16] package version up to 2.0.1 Change-Id: I93ab415dc94d7850e1bd34a2128e1339304d3062 --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 9e6e59d..7f971ab 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 2.0.0 +Version: 2.0.1 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From d84ba5e84998c2276f0abfd09d234f504e824f82 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 28 Mar 2018 14:01:31 +0900 Subject: [PATCH 08/16] change the type of the size Change-Id: I59c965b5bef5c5faf74e323efa911cb28832ab9b --- src/tbm_bufmgr_sprd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 874deb0..fb1b09e 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1107,7 +1107,8 @@ tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, } static tbm_backend_bo_data * -tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_memory_type flags, tbm_error_e *error) +tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size, + tbm_bo_memory_type flags, tbm_error_e *error) { tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)bufmgr_data; tbm_bo_sprd bo_sprd; -- 2.7.4 From d16c0fc03155ee91e868882cc56981d88b66d5bc Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 28 Mar 2018 14:01:44 +0900 Subject: [PATCH 09/16] package version up to 2.1.0 Change-Id: Ibb13c84382739bb3dac41fbde2413109945830a6 --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 7f971ab..dd481fb 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 2.0.1 +Version: 2.1.0 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From 9205e3cf4adfe53bafa8e9e03c026ecb23d494d6 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 29 Mar 2018 20:47:32 +0900 Subject: [PATCH 10/16] use TBM_ERROR_INVALID_OPERATION Change-Id: I985c4f062930e1a3078a46a043e10e767f940c25 --- src/tbm_bufmgr_sprd.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index fb1b09e..f105c2d 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -823,7 +823,7 @@ tbm_sprd_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_na if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_sprd->fd, bufmgr_sprd->device_name, 0)) { TBM_ERR("fail to tbm_drm_helper_wl_server_init\n"); - return TBM_ERROR_OPERATION_FAILED; + return TBM_ERROR_INVALID_OPERATION; } bufmgr_sprd->bind_display = native_display; @@ -1149,7 +1149,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size arg.flags, (unsigned int)arg.size); free(bo_sprd); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return NULL; } @@ -1164,7 +1164,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size TBM_ERR("error fail init cache state(%d)\n", bo_sprd->name); free(bo_sprd); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return NULL; } @@ -1178,7 +1178,7 @@ tbm_sprd_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size TBM_ERR("error Cannot dmabuf=%d\n", bo_sprd->gem); free(bo_sprd); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return NULL; } bo_sprd->dmabuf = arg.fd; @@ -1224,7 +1224,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ TBM_ERR("Cannot get gem handle from fd:%d (%s)\n", arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return NULL; } gem = arg.handle; @@ -1234,7 +1234,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ TBM_ERR("Cannot get name from gem:%d, fd:%d (%s)\n", gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return NULL; } @@ -1267,7 +1267,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ TBM_ERR("Cannot get gem info from gem:%d, fd:%d (%s)\n", gem, key, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return NULL; } @@ -1293,7 +1293,7 @@ tbm_sprd_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_ if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { TBM_ERR("error fail init cache state(%d)\n", bo_sprd->name); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_init_cache; } @@ -1348,7 +1348,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg)) { TBM_ERR("error Cannot open gem name=%d\n", key); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return NULL; } @@ -1359,7 +1359,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb sizeof(struct drm_sprd_gem_info))) { TBM_ERR("error Cannot get gem info=%d\n", key); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_get_gem; } @@ -1387,7 +1387,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { TBM_ERR("error fail init cache state(%d)\n", bo_sprd->name); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_init_cache; } @@ -1398,7 +1398,7 @@ tbm_sprd_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tb if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { TBM_ERR("error Cannot dmabuf=%d\n", bo_sprd->gem); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_prime_handle_to_fd; } bo_sprd->dmabuf = arg.fd; @@ -1559,7 +1559,7 @@ tbm_sprd_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, TBM_ERR("Cannot get handle: gem:%d, device:%d\n", bo_sprd->gem, device); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return (tbm_bo_handle) NULL; } @@ -1610,7 +1610,7 @@ tbm_sprd_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, TBM_ERR("Cannot get handle: gem:%d, device:%d, opt:%d\n", bo_sprd->gem, device, opt); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return (tbm_bo_handle) NULL; } @@ -1674,7 +1674,7 @@ tbm_sprd_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) TBM_ERR("bo_sprd:%p Cannot dmabuf=%d (%s)\n", bo_sprd, bo_sprd->gem, strerror_r(errno, buf, STRERR_BUFSIZE)); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; return (tbm_fd) ret; } @@ -1801,7 +1801,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) if (bufmgr_sprd->fd < 0) { TBM_ERR("fail to open drm!\n"); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_open_drm; } } @@ -1813,14 +1813,14 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) TBM_ERR("fail to get device name!\n"); tbm_drm_helper_unset_tbm_master_fd(); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_get_device_name; } } else { if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) { TBM_ERR("fail to get auth drm info!\n"); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_get_auth_info; } @@ -1842,7 +1842,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) if (!_bufmgr_init_cache_state(bufmgr_sprd)) { TBM_ERR("fail to init bufmgr cache state\n"); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_init_cache_state; } @@ -1871,7 +1871,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) if (err != TBM_ERROR_NONE) { TBM_ERR("fail to register bufmgr_func! err(%d)\n", err); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_register_bufmgr_func; } bufmgr_sprd->bufmgr_func = bufmgr_func; @@ -1900,7 +1900,7 @@ tbm_sprd_init(tbm_bufmgr bufmgr, tbm_error_e *error) if (err != TBM_ERROR_NONE) { TBM_ERR("fail to register bo_func! err(%d)\n", err); if (error) - *error = TBM_ERROR_OPERATION_FAILED; + *error = TBM_ERROR_INVALID_OPERATION; goto fail_register_bo_func; } bufmgr_sprd->bo_func = bo_func; -- 2.7.4 From 4854bb95926e1da20f9ea6659ffd7cb95d6e8482 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 4 May 2018 11:26:59 +0900 Subject: [PATCH 11/16] use 3.0 version of tbm backend abi Change-Id: I87dbe99011d03deb115ef3385b925e50a5abea16 --- src/tbm_bufmgr_sprd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index f105c2d..6f8059e 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1942,7 +1942,7 @@ fail_open_drm: tbm_backend_module tbm_backend_module_data = { "sprd", "Samsung", - TBM_BACKEND_ABI_VERSION_2_0, + TBM_BACKEND_ABI_VERSION_3_0, tbm_sprd_init, tbm_sprd_deinit }; -- 2.7.4 From 32585d2d4a73f93981327d1e13fe9cad72153a56 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 4 May 2018 11:30:00 +0900 Subject: [PATCH 12/16] package version up to 2.2.0 Change-Id: I2a9f8ce08a302c385ce0295380827d7622d33f2d --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index dd481fb..50ea4c1 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 2.1.0 +Version: 2.2.0 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From fd9b0f53b9a01bc01b824d1809ba4e0266a83b68 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 26 Dec 2018 19:15:45 +0900 Subject: [PATCH 13/16] package version up to 2.3.0 Change-Id: I56205e69541c3db9ef58e4d02a4080661118891a --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 50ea4c1..1c0fec9 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 2.2.0 +Version: 2.3.0 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From aa61ae59ef809d35332d82e2ec9f78e33ae36f30 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 1 Nov 2019 13:05:51 +0900 Subject: [PATCH 14/16] package version up to 2.4.0 tizen 6.0 starts here. Change-Id: I29aa6fcc3a5783a58139de71f964d728132ff5d6 --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 1c0fec9..9646af7 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 2.3.0 +Version: 2.4.0 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From bd671e29249ed6e6bf69f27cd3303e92944bed79 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Wed, 11 Dec 2019 19:36:01 +0900 Subject: [PATCH 15/16] set same pitch to all plane of NV format Change-Id: I877a8c19f3e8fa12eddba3cdc99cc5a0dc85ea10 --- src/tbm_bufmgr_sprd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 6f8059e..2e2dd63 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -956,7 +956,7 @@ tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, // else if (plane_idx == 1) { _offset = _size; - _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV); _align_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV); _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); _bo_idx = 0; @@ -978,7 +978,7 @@ tbm_sprd_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data, //else if( plane_idx ==1 ) { _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); _bo_idx = 0; } -- 2.7.4 From e4732b6e173d97cbbe722b9d6262caa77961f485 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Wed, 11 Dec 2019 19:46:42 +0900 Subject: [PATCH 16/16] package version up to 2.4.1 Change-Id: Ie7a77a2436220724320500013d9540dd004cd8d1 --- packaging/libtbm-sprd.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 9646af7..f2a8ab3 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 2.4.0 +Version: 2.4.1 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4