From 58bb03ff0a8a5dd60826c1452897f6e7c70512bb Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2016 11:49:21 +0900 Subject: [PATCH 01/16] remove pthread-stub dependency Change-Id: I54a5b9f228e68d347615de4dae60382e8b1bd16d --- packaging/libtbm-sprd.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 7cb2649..34cacf0 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -10,7 +10,6 @@ ExclusiveArch: %endif Source0: %{name}-%{version}.tar.gz -BuildRequires: pkgconfig(pthread-stubs) BuildRequires: pkgconfig(libdrm) BuildRequires: pkgconfig(libtbm) BuildRequires: pkgconfig(dlog) -- 2.7.4 From 5dbba033fd1179425abd3fafabec484713e7ec81 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Fri, 29 Jul 2016 13:33:17 +0900 Subject: [PATCH 02/16] tbm_surface: align height of NV12 format when calculate size sprd hw codec need to size with align height Change-Id: I83092fc97409f882c3ddb498c0be22bca692e617 --- src/tbm_bufmgr_sprd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index abea509..da5c9e5 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1634,6 +1634,7 @@ tbm_sprd_surface_get_plane_data(int width, int height, int _pitch = 0; int _size = 0; int _bo_idx = 0; + int _align_height = 0; switch (format) { /* 16 bpp RGB */ @@ -1711,12 +1712,14 @@ tbm_sprd_surface_get_plane_data(int width, int height, if (plane_idx == 0) { _offset = 0; _pitch = SIZE_ALIGN( width , TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); + _align_height = SIZE_ALIGN(height, TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch * _align_height, TBM_SURFACE_ALIGNMENT_PLANE); _bo_idx = 0; } else if ( plane_idx == 1 ) { _offset = width * height; _pitch = SIZE_ALIGN( width , TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); - _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); + _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; -- 2.7.4 From 0a146313b0e78ed744f09ba461d67a2bc6e4d6b9 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Mon, 22 Aug 2016 15:21:54 +0900 Subject: [PATCH 03/16] Apply tizen coding rule Change-Id: I59637ebe0abb94986c1096680b5af24191fdc842 --- src/tbm_bufmgr_sprd.c | 450 +++++++++++++++++++++++++------------------------- 1 file changed, 222 insertions(+), 228 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index da5c9e5..767f6e7 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -78,41 +78,39 @@ target_name() static int initialized = 0; static char app_name[128]; - if ( initialized ) + if (initialized) return app_name; /* get the application name */ f = fopen("/proc/self/cmdline", "r"); - if ( !f ) { + if (!f) return 0; - } memset(app_name, 0x00, sizeof(app_name)); - if ( fgets(app_name, 100, f) == NULL ) { + if (fgets(app_name, 100, f) == NULL) { fclose(f); return 0; } fclose(f); - if ( (slash = strrchr(app_name, '/')) != NULL ) { + if ((slash = strrchr(app_name, '/')) != NULL) memmove(app_name, slash + 1, strlen(slash)); - } initialized = 1; return app_name; } #define TBM_SPRD_LOG(fmt, args...) LOGE("\033[31m" "[%s]" fmt "\033[0m", target_name(), ##args) -#define DBG(fmt, args...) if(bDebug&01) LOGE("[%s]" fmt, target_name(), ##args) +#define DBG(fmt, args...) if (bDebug&01) LOGE("[%s]" fmt, target_name(), ##args) #else #define TBM_SPRD_LOG(...) #define DBG(...) #endif -#define SIZE_ALIGN( value, base ) (((value) + ((base) - 1)) & ~((base) - 1)) +#define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1)) #define TBM_SURFACE_ALIGNMENT_PLANE (64) #define TBM_SURFACE_ALIGNMENT_PITCH_RGB (128) @@ -121,16 +119,16 @@ target_name() /* check condition */ #define SPRD_RETURN_IF_FAIL(cond) {\ - if (!(cond)) {\ - TBM_SPRD_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return;\ - }\ + if (!(cond)) {\ + TBM_SPRD_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + return;\ + } \ } #define SPRD_RETURN_VAL_IF_FAIL(cond, val) {\ - if (!(cond)) {\ - TBM_SPRD_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return val;\ - }\ + if (!(cond)) {\ + TBM_SPRD_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + return val;\ + } \ } struct dma_buf_info { @@ -178,9 +176,9 @@ typedef union _tbm_bo_cache_state tbm_bo_cache_state; union _tbm_bo_cache_state { unsigned int val; struct { - unsigned int cntFlush: 16; /*Flush all index for sync */ - unsigned int isCached: 1; - unsigned int isDirtied: 2; + unsigned int cntFlush:16; /*Flush all index for sync */ + unsigned int isCached:1; + unsigned int isDirtied:2; } data; }; @@ -375,7 +373,7 @@ _tbm_sprd_open_drm() fd = drmOpen(SPRD_DRM_NAME, NULL); if (fd < 0) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "warning %s:%d fail to open drm\n", getpid(), __FUNCTION__, __LINE__); } @@ -390,7 +388,7 @@ _tbm_sprd_open_drm() struct stat s; int ret; - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "%s:%d search drm-device by udev\n", getpid(), __FUNCTION__, __LINE__); @@ -462,10 +460,10 @@ _tbm_sprd_open_drm() #ifdef USE_CACHE static int -_sprd_bo_cache_flush (tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags) +_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); - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); /* cache flush is managed by kernel side when using dma-fence. */ if (bufmgr_sprd->use_dma_fence) @@ -503,10 +501,10 @@ _sprd_bo_cache_flush (tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flag if (flags & TBM_SPRD_CACHE_ALL) cache_op.flags |= SPRD_DRM_ALL_CACHES_CORES; - ret = drmCommandWriteRead (bufmgr_sprd->fd, DRM_SPRD_GEM_CACHE_OP, &cache_op, + ret = drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CACHE_OP, &cache_op, sizeof(cache_op)); if (ret) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d fail to flush the cache.\n", getpid(), __FUNCTION__, __LINE__); return 0; @@ -519,8 +517,8 @@ _sprd_bo_cache_flush (tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flag static int _bo_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int import) { - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); - SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) return 1; @@ -546,8 +544,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); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); char need_flush = 0; unsigned short cntFlush = 0; @@ -595,7 +593,7 @@ _bo_set_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int device _tgl_set_data(bufmgr_sprd->tgl_fd, GLOBAL_KEY, (unsigned int)(++cntFlush)); /* call cache flush */ - _sprd_bo_cache_flush (bufmgr_sprd, bo_sprd, need_flush); + _sprd_bo_cache_flush(bufmgr_sprd, bo_sprd, need_flush); DBG("[libtbm:%d] \tcache(%d,%d)....flush:0x%x, cntFlush(%d)\n", getpid(), @@ -613,8 +611,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); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) return 1; @@ -635,8 +633,8 @@ _bo_save_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) static void _bo_destroy_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) { - SPRD_RETURN_IF_FAIL (bo_sprd != NULL); - SPRD_RETURN_IF_FAIL (bufmgr_sprd != NULL); + SPRD_RETURN_IF_FAIL(bo_sprd != NULL); + SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); if (bufmgr_sprd->use_dma_fence) return; @@ -693,7 +691,7 @@ _bufmgr_deinit_cache_state(tbm_bufmgr_sprd bufmgr_sprd) #ifndef USE_CONTIG_ONLY static unsigned int -_get_sprd_flag_from_tbm (unsigned int ftbm) +_get_sprd_flag_from_tbm(unsigned int ftbm) { unsigned int flags = 0; @@ -704,11 +702,10 @@ _get_sprd_flag_from_tbm (unsigned int ftbm) * To be updated appropriately once DRM-GEM supports different heap id masks. * */ - if (ftbm & TBM_BO_SCANOUT) { + if (ftbm & TBM_BO_SCANOUT) flags = SPRD_BO_CONTIG; - } else { + else flags = SPRD_BO_NONCONTIG | SPRD_BO_DEV_SYSTEM; - } if (ftbm & TBM_BO_WC) flags |= SPRD_BO_WC; @@ -719,7 +716,7 @@ _get_sprd_flag_from_tbm (unsigned int ftbm) } static unsigned int -_get_tbm_flag_from_sprd (unsigned int fsprd) +_get_tbm_flag_from_sprd(unsigned int fsprd) { unsigned int flags = 0; @@ -740,13 +737,13 @@ _get_tbm_flag_from_sprd (unsigned int fsprd) #endif static unsigned int -_get_name (int fd, unsigned int gem) +_get_name(int fd, unsigned int gem) { struct drm_gem_flink arg = {0,}; arg.handle = gem; - if (drmIoctl (fd, DRM_IOCTL_GEM_FLINK, &arg)) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d fail to get flink gem=%d\n", getpid(), __FUNCTION__, __LINE__, gem); return 0; @@ -756,10 +753,10 @@ _get_name (int fd, unsigned int gem) } static tbm_bo_handle -_sprd_bo_handle (tbm_bo_sprd bo_sprd, int device) +_sprd_bo_handle(tbm_bo_sprd bo_sprd, int device) { tbm_bo_handle bo_handle; - memset (&bo_handle, 0x0, sizeof (uint64_t)); + memset(&bo_handle, 0x0, sizeof(uint64_t)); switch (device) { case TBM_DEVICE_DEFAULT: @@ -772,8 +769,8 @@ _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_LOG ("[libtbm-sprd:%d] " + if (drmCommandWriteRead(bo_sprd->fd, DRM_SPRD_GEM_MMAP, &arg, sizeof(arg))) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot usrptr gem=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); return (tbm_bo_handle) NULL; @@ -788,8 +785,8 @@ _sprd_bo_handle (tbm_bo_sprd bo_sprd, int device) 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_LOG ("[libtbm-sprd:%d] " + if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot dmabuf=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); return (tbm_bo_handle) NULL; @@ -805,7 +802,7 @@ _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. - DBG ("[libtbm-sprd:%d] %s In case TBM_DEVICE_MM: \n", getpid(), + DBG("[libtbm-sprd:%d] %s In case TBM_DEVICE_MM: \n", getpid(), __FUNCTION_); _ @@ -814,8 +811,8 @@ _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_LOG ("[libtbm-sprd:%d] " + if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot dmabuf=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); return (tbm_bo_handle) NULL; @@ -835,9 +832,9 @@ _sprd_bo_handle (tbm_bo_sprd bo_sprd, int device) } static int -tbm_sprd_bo_size (tbm_bo bo) +tbm_sprd_bo_size(tbm_bo bo) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bo_sprd bo_sprd; @@ -847,20 +844,20 @@ tbm_sprd_bo_size (tbm_bo bo) } static void * -tbm_sprd_bo_alloc (tbm_bo bo, int size, int flags) +tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bo_sprd bo_sprd; tbm_bufmgr_sprd bufmgr_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); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); - bo_sprd = calloc (1, sizeof(struct _tbm_bo_sprd)); + bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d fail to allocate the bo private\n", getpid(), __FUNCTION__, __LINE__); return 0; @@ -870,7 +867,7 @@ tbm_sprd_bo_alloc (tbm_bo bo, int size, int flags) flags = TBM_BO_SCANOUT; sprd_flags = SPRD_BO_CONTIG; #else - sprd_flags = _get_sprd_flag_from_tbm (flags); + sprd_flags = _get_sprd_flag_from_tbm(flags); if ((flags & TBM_BO_SCANOUT) && size <= 4 * 1024) { sprd_flags |= SPRD_BO_NONCONTIG; @@ -881,10 +878,10 @@ tbm_sprd_bo_alloc (tbm_bo bo, int size, int flags) arg.flags = sprd_flags; if (drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CREATE, &arg, sizeof(arg))) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot create bo(flag:%x, size:%d)\n", getpid(), __FUNCTION__, __LINE__, arg.flags, (unsigned int)arg.size); - free (bo_sprd); + free(bo_sprd); return 0; } @@ -893,11 +890,11 @@ tbm_sprd_bo_alloc (tbm_bo bo, int size, int flags) 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); + bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 0)) { - TBM_SPRD_LOG ("error fail init cache state(%d)\n", bo_sprd->name); - free (bo_sprd); + TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name); + free(bo_sprd); return 0; } @@ -908,27 +905,27 @@ tbm_sprd_bo_alloc (tbm_bo bo, int size, int flags) 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_LOG ("[libtbm-sprd:%d] " + if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot dmabuf=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); - free (bo_sprd); + free(bo_sprd); return 0; } bo_sprd->dmabuf = arg.fd; } /* add bo to hash */ - PrivGem *privGem = calloc (1, sizeof(PrivGem)); + PrivGem *privGem = calloc(1, sizeof(PrivGem)); privGem->ref_count = 1; privGem->bo_priv = bo_sprd; if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot insert bo to Hash(%d)\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->name); } - DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(), + DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(), __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name, flags, sprd_flags); @@ -946,25 +943,25 @@ tbm_sprd_bo_free(tbm_bo bo) return; bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_IF_FAIL (bufmgr_sprd != NULL); + 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); + SPRD_RETURN_IF_FAIL(bo_sprd != NULL); - DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d)\n", + DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d)\n", getpid(), __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name); if (bo_sprd->pBase) { if (munmap(bo_sprd->pBase, bo_sprd->size) == -1) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d\n", getpid(), __FUNCTION__, __LINE__); } } - /* close dmabuf */ + /* closedmabuf */ if (bo_sprd->dmabuf) { - close (bo_sprd->dmabuf); + close(bo_sprd->dmabuf); bo_sprd->dmabuf = 0; } @@ -972,16 +969,16 @@ tbm_sprd_bo_free(tbm_bo bo) PrivGem *privGem = NULL; int ret; - ret = drmHashLookup (bufmgr_sprd->hashBos, bo_sprd->name, (void **)&privGem); + 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); + drmHashDelete(bufmgr_sprd->hashBos, bo_sprd->name); + free(privGem); privGem = NULL; } } else { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "warning %s:%d Cannot find bo to Hash(%d), ret=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->name, ret); } @@ -990,22 +987,22 @@ tbm_sprd_bo_free(tbm_bo bo) /* Free gem handle */ struct drm_gem_close arg = {0, }; - memset (&arg, 0, sizeof(arg)); + memset(&arg, 0, sizeof(arg)); arg.handle = bo_sprd->gem; - if (drmIoctl (bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg)) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + if (drmIoctl(bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d\n", getpid(), __FUNCTION__, __LINE__); } - free (bo_sprd); + free(bo_sprd); } static void * -tbm_sprd_bo_import (tbm_bo bo, unsigned int key) +tbm_sprd_bo_import(tbm_bo bo, unsigned int key) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; @@ -1013,19 +1010,18 @@ tbm_sprd_bo_import (tbm_bo bo, unsigned int key) int ret; bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); - ret = drmHashLookup (bufmgr_sprd->hashBos, key, (void **)&privGem); - if (ret == 0) { + ret = drmHashLookup(bufmgr_sprd->hashBos, key, (void **)&privGem); + if (ret == 0) return privGem->bo_priv; - } 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_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot open gem name=%d\n", getpid(), __FUNCTION__, __LINE__, key); return 0; @@ -1036,15 +1032,15 @@ tbm_sprd_bo_import (tbm_bo bo, unsigned int key) DRM_SPRD_GEM_GET, &info, sizeof(struct drm_sprd_gem_info))) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot get gem info=%d\n", getpid(), __FUNCTION__, __LINE__, key); return 0; } - bo_sprd = calloc (1, sizeof(struct _tbm_bo_sprd)); + bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d fail to allocate the bo private\n", getpid(), __FUNCTION__, __LINE__); return 0; @@ -1059,12 +1055,12 @@ tbm_sprd_bo_import (tbm_bo bo, unsigned int key) 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); + 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_LOG ("error fail init cache state(%d)\n", bo_sprd->name); - free (bo_sprd); + TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name); + free(bo_sprd); return 0; } @@ -1072,27 +1068,27 @@ tbm_sprd_bo_import (tbm_bo bo, unsigned int key) 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_LOG ("[libtbm-sprd:%d] " + if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot dmabuf=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); - free (bo_sprd); + free(bo_sprd); return 0; } bo_sprd->dmabuf = arg.fd; } /* add bo to hash */ - privGem = calloc (1, sizeof(PrivGem)); + privGem = calloc(1, sizeof(PrivGem)); privGem->ref_count = 1; privGem->bo_priv = bo_sprd; - if (drmHashInsert (bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot insert bo to Hash(%d)\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->name); } - DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(), + DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(), __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name, bo_sprd->flags_tbm, bo_sprd->flags_sprd); @@ -1101,9 +1097,9 @@ tbm_sprd_bo_import (tbm_bo bo, unsigned int key) } static void * -tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) +tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; @@ -1112,7 +1108,7 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) unsigned int name; bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); //getting handle from fd unsigned int gem = 0; @@ -1120,20 +1116,19 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) arg.fd = key; arg.flags = 0; - if (drmIoctl (bufmgr_sprd->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) { - TBM_SPRD_LOG ("error bo:%p Cannot get gem handle from fd:%d (%s)\n", + if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) { + TBM_SPRD_LOG("error bo:%p Cannot get gem handle from fd:%d (%s)\n", bo, arg.fd, strerror(errno)); return NULL; } gem = arg.handle; - name = _get_name (bufmgr_sprd->fd, gem); + name = _get_name(bufmgr_sprd->fd, gem); - ret = drmHashLookup (bufmgr_sprd->hashBos, name, (void **)&privGem); + ret = drmHashLookup(bufmgr_sprd->hashBos, name, (void **)&privGem); if (ret == 0) { - if (gem == privGem->bo_priv->gem) { + if (gem == privGem->bo_priv->gem) return privGem->bo_priv; - } } unsigned int real_size = -1; @@ -1151,7 +1146,7 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) DRM_SPRD_GEM_GET, &info, sizeof(struct drm_sprd_gem_info))) { - TBM_SPRD_LOG ("error bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n", + TBM_SPRD_LOG("error bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n", bo, gem, key, strerror(errno)); return 0; } @@ -1159,9 +1154,9 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) if (real_size == -1) real_size = info.size; - bo_sprd = calloc (1, sizeof(struct _tbm_bo_sprd)); + bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); if (!bo_sprd) { - TBM_SPRD_LOG ("error bo:%p fail to allocate the bo private\n", bo); + TBM_SPRD_LOG("error bo:%p fail to allocate the bo private\n", bo); return 0; } @@ -1169,42 +1164,42 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) 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->flags_tbm = _get_tbm_flag_from_sprd(bo_sprd->flags_sprd); bo_sprd->name = name; if (!bo_sprd->name) { - TBM_SPRD_LOG ("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n", + TBM_SPRD_LOG("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n", bo, gem, key, strerror(errno)); - free (bo_sprd); + free(bo_sprd); return 0; } if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { - TBM_SPRD_LOG ("error fail init cache state(%d)\n", bo_sprd->name); - free (bo_sprd); + TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name); + free(bo_sprd); return 0; } /* add bo to hash */ privGem = NULL; - privGem = calloc (1, sizeof(PrivGem)); + privGem = calloc(1, sizeof(PrivGem)); if (!privGem) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " - "error %s:%d Fail to calloc privGem\n", + TBM_SPRD_LOG("[libtbm-sprd:%d] " + "error %s:%d Fail to callocprivGem\n", getpid(), __FUNCTION__, __LINE__); - free (bo_sprd); + 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_LOG ("error bo:%p Cannot insert bo to Hash(%d) from gem:%d, fd:%d\n", + if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) { + TBM_SPRD_LOG("error bo:%p Cannot insert bo to Hash(%d) from gem:%d, fd:%d\n", bo, bo_sprd->name, gem, key); } - DBG (" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + DBG(" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", target_name(), bo, bo_sprd->gem, bo_sprd->name, @@ -1217,26 +1212,26 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) } static unsigned int -tbm_sprd_bo_export (tbm_bo bo) +tbm_sprd_bo_export(tbm_bo bo) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bo_sprd bo_sprd; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); if (!bo_sprd->name) { bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem); if (!bo_sprd->name) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot get name\n", getpid(), __FUNCTION__, __LINE__); return 0; } } - DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(), + DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(), __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name, bo_sprd->flags_tbm, bo_sprd->flags_sprd); @@ -1245,27 +1240,27 @@ tbm_sprd_bo_export (tbm_bo bo) } tbm_fd -tbm_sprd_bo_export_fd (tbm_bo bo) +tbm_sprd_bo_export_fd(tbm_bo bo) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, -1); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, -1); tbm_bo_sprd bo_sprd; int ret; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, -1); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, -1); struct drm_prime_handle arg = {0, }; arg.handle = bo_sprd->gem; - ret = drmIoctl (bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); + ret = drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg); if (ret) { - TBM_SPRD_LOG ("error bo:%p Cannot dmabuf=%d (%s)\n", + TBM_SPRD_LOG("error bo:%p Cannot dmabuf=%d (%s)\n", bo, bo_sprd->gem, strerror(errno)); return (tbm_fd) ret; } - DBG (" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", + DBG(" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", target_name(), bo, bo_sprd->gem, bo_sprd->name, @@ -1279,30 +1274,30 @@ tbm_sprd_bo_export_fd (tbm_bo bo) static tbm_bo_handle -tbm_sprd_bo_get_handle (tbm_bo bo, int device) +tbm_sprd_bo_get_handle(tbm_bo bo, int device) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, (tbm_bo_handle) NULL); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, (tbm_bo_handle) NULL); 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); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, (tbm_bo_handle) NULL); if (!bo_sprd->gem) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot map gem=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); return (tbm_bo_handle) NULL; } - DBG ("[libtbm-sprd:%d] %s gem:%d(%d), %s\n", getpid(), + DBG("[libtbm-sprd:%d] %s gem:%d(%d), %s\n", getpid(), __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device]); /*Get mapped bo_handle*/ - bo_handle = _sprd_bo_handle (bo_sprd, device); + bo_handle = _sprd_bo_handle(bo_sprd, device); if (bo_handle.ptr == NULL) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot get handle: gem:%d, device:%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem, device); return (tbm_bo_handle) NULL; @@ -1312,41 +1307,41 @@ tbm_sprd_bo_get_handle (tbm_bo bo, int device) } static tbm_bo_handle -tbm_sprd_bo_map (tbm_bo bo, int device, int opt) +tbm_sprd_bo_map(tbm_bo bo, int device, int opt) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, (tbm_bo_handle) NULL); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, (tbm_bo_handle) NULL); 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); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, (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); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, (tbm_bo_handle) NULL); if (!bo_sprd->gem) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot map gem=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); return (tbm_bo_handle) NULL; } - DBG ("[libtbm-sprd:%d] %s gem:%d(%d), %s, %s\n", getpid(), + DBG("[libtbm-sprd:%d] %s gem:%d(%d), %s, %s\n", getpid(), __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device], STR_OPT[opt]); /*Get mapped bo_handle*/ - bo_handle = _sprd_bo_handle (bo_sprd, device); + bo_handle = _sprd_bo_handle(bo_sprd, device); if (bo_handle.ptr == NULL) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot get handle: gem:%d, device:%d, opt:%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem, device, opt); return (tbm_bo_handle) NULL; } if (bo_sprd->map_cnt == 0) - _bo_set_cache_state (bufmgr_sprd, bo_sprd, device, opt); + _bo_set_cache_state(bufmgr_sprd, bo_sprd, device, opt); bo_sprd->map_cnt++; @@ -1354,18 +1349,18 @@ tbm_sprd_bo_map (tbm_bo bo, int device, int opt) } static int -tbm_sprd_bo_unmap (tbm_bo bo) +tbm_sprd_bo_unmap(tbm_bo bo) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); 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, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); if (!bo_sprd->gem) return 0; @@ -1373,9 +1368,9 @@ tbm_sprd_bo_unmap (tbm_bo bo) bo_sprd->map_cnt--; if (bo_sprd->map_cnt == 0) - _bo_save_cache_state (bufmgr_sprd, bo_sprd); + _bo_save_cache_state(bufmgr_sprd, bo_sprd); - DBG ("[libtbm-sprd:%d] %s gem:%d(%d) \n", getpid(), + DBG("[libtbm-sprd:%d] %s gem:%d(%d) \n", getpid(), __FUNCTION__, bo_sprd->gem, bo_sprd->name); return 1; @@ -1384,16 +1379,16 @@ tbm_sprd_bo_unmap (tbm_bo bo) static int tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); #if USE_BACKEND_LOCK int ret = 0; @@ -1411,7 +1406,7 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) else if (device == TBM_DEVICE_3D) fence.type = DMA_BUF_ACCESS_WRITE | DMA_BUF_ACCESS_DMA; else { - DBG ("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n", + DBG("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n", getpid(), __FUNCTION__); return 0; } @@ -1421,30 +1416,30 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) else if (device == TBM_DEVICE_3D) fence.type = DMA_BUF_ACCESS_READ | DMA_BUF_ACCESS_DMA; else { - DBG ("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n", + DBG("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n", getpid(), __FUNCTION__); return 0; } } else { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error %s:%d Invalid argument\n", getpid(), + TBM_SPRD_LOG("[libtbm-sprd:%d] error %s:%d Invalid argument\n", getpid(), __FUNCTION__, __LINE__); return 0; } /* Check if the tbm manager supports dma fence or not. */ if (!bufmgr_sprd->use_dma_fence) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Not support DMA FENCE(%s)\n", - getpid(), __FUNCTION__, __LINE__, strerror(errno) ); + getpid(), __FUNCTION__, __LINE__, strerror(errno)); return 0; } ret = ioctl(bo_sprd->dmabuf, DMABUF_IOCTL_GET_FENCE, &fence); if (ret < 0) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Can not set GET FENCE(%s)\n", - getpid(), __FUNCTION__, __LINE__, strerror(errno) ); + getpid(), __FUNCTION__, __LINE__, strerror(errno)); return 0; } @@ -1459,20 +1454,20 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) } if (i == DMA_FENCE_LIST_MAX) { //TODO: if dma_fence list is full, it needs realloc. I will fix this. by minseok3.kim - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d fence list is full\n", getpid(), __FUNCTION__, __LINE__); } pthread_mutex_unlock(&bo_sprd->mutex); - DBG ("[libtbm-sprd:%d] %s DMABUF_IOCTL_GET_FENCE! flink_id=%d dmabuf=%d\n", + DBG("[libtbm-sprd:%d] %s DMABUF_IOCTL_GET_FENCE! flink_id=%d dmabuf=%d\n", getpid(), __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf); } else { ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name); - DBG ("[libtbm-sprd:%d] lock tgl flink_id:%d\n", + DBG("[libtbm-sprd:%d] lock tgl flink_id:%d\n", getpid(), __FUNCTION__, bo_sprd->name); return ret; @@ -1485,16 +1480,16 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) static int tbm_sprd_bo_unlock(tbm_bo bo) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); #if USE_BACKEND_LOCK int ret = 0; @@ -1503,13 +1498,13 @@ tbm_sprd_bo_unlock(tbm_bo bo) struct dma_buf_fence fence; if (!bo_sprd->dma_fence[0].ctx) { - DBG ("[libtbm-sprd:%d] %s FENCE not support or ignored,\n", getpid(), + DBG("[libtbm-sprd:%d] %s FENCE not support or ignored,\n", getpid(), __FUNCTION__); return 0; } if (!bo_sprd->dma_fence[0].type) { - DBG ("[libtbm-sprd:%d] %s device type is not 3D/CPU,\n", getpid(), + DBG("[libtbm-sprd:%d] %s device type is not 3D/CPU,\n", getpid(), __FUNCTION__); return 0; } @@ -1528,19 +1523,19 @@ tbm_sprd_bo_unlock(tbm_bo bo) ret = ioctl(bo_sprd->dmabuf, DMABUF_IOCTL_PUT_FENCE, &fence); if (ret < 0) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] " + TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Can not set PUT FENCE(%s)\n", - getpid(), __FUNCTION__, __LINE__, strerror(errno) ); + getpid(), __FUNCTION__, __LINE__, strerror(errno)); return 0; } - DBG ("[libtbm-sprd:%d] %s DMABUF_IOCTL_PUT_FENCE! flink_id=%d dmabuf=%d\n", + DBG("[libtbm-sprd:%d] %s DMABUF_IOCTL_PUT_FENCE! flink_id=%d dmabuf=%d\n", getpid(), __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf); } else { ret = _tgl_unlock(bufmgr_sprd->tgl_fd, bo_sprd->name); - DBG ("[libtbm-sprd:%d] unlock tgl flink_id:%d\n", + DBG("[libtbm-sprd:%d] unlock tgl flink_id:%d\n", getpid(), __FUNCTION__, bo_sprd->name); return ret; @@ -1551,9 +1546,9 @@ tbm_sprd_bo_unlock(tbm_bo bo) } static void -tbm_sprd_bufmgr_deinit (void *priv) +tbm_sprd_bufmgr_deinit(void *priv) { - SPRD_RETURN_IF_FAIL (priv != NULL); + SPRD_RETURN_IF_FAIL(priv != NULL); tbm_bufmgr_sprd bufmgr_sprd; @@ -1564,11 +1559,11 @@ tbm_sprd_bufmgr_deinit (void *priv) void *value; while (drmHashFirst(bufmgr_sprd->hashBos, &key, &value) > 0) { - free (value); - drmHashDelete (bufmgr_sprd->hashBos, key); + free(value); + drmHashDelete(bufmgr_sprd->hashBos, key); } - drmHashDestroy (bufmgr_sprd->hashBos); + drmHashDestroy(bufmgr_sprd->hashBos); bufmgr_sprd->hashBos = NULL; } @@ -1583,9 +1578,9 @@ tbm_sprd_bufmgr_deinit (void *priv) _bufmgr_deinit_cache_state(bufmgr_sprd); - close (bufmgr_sprd->fd); + close(bufmgr_sprd->fd); - free (bufmgr_sprd); + free(bufmgr_sprd); } int @@ -1593,14 +1588,14 @@ tbm_sprd_surface_supported_format(uint32_t **formats, uint32_t *num) { uint32_t *color_formats = NULL; - color_formats = (uint32_t *)calloc (1, + color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); - if ( color_formats == NULL ) { + if (color_formats == NULL) return 0; - } - 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; @@ -1711,13 +1706,13 @@ tbm_sprd_surface_get_plane_data(int width, int height, bpp = 12; if (plane_idx == 0) { _offset = 0; - _pitch = SIZE_ALIGN( width , TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _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; - } else if ( plane_idx == 1 ) { + } else if (plane_idx == 1) { _offset = width * height; - _pitch = SIZE_ALIGN( width , TBM_SURFACE_ALIGNMENT_PITCH_YUV / 2); + _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; @@ -1865,20 +1860,20 @@ tbm_sprd_surface_get_plane_data(int width, int height, } int -tbm_sprd_bo_get_flags (tbm_bo bo) +tbm_sprd_bo_get_flags(tbm_bo bo) { - SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); tbm_bo_sprd bo_sprd; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); return bo_sprd->flags_tbm; } int -tbm_sprd_bufmgr_bind_native_display (tbm_bufmgr bufmgr, void *NativeDisplay) +tbm_sprd_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay) { tbm_bufmgr_sprd bufmgr_sprd; @@ -1896,7 +1891,7 @@ tbm_sprd_bufmgr_bind_native_display (tbm_bufmgr bufmgr, void *NativeDisplay) return 1; } -MODULEINITPPROTO (init_tbm_bufmgr_priv); +MODULEINITPPROTO(init_tbm_bufmgr_priv); static TBMModuleVersionInfo SprdVersRec = { "sprd", @@ -1907,7 +1902,7 @@ static TBMModuleVersionInfo SprdVersRec = { TBMModuleData tbmModuleData = { &SprdVersRec, init_tbm_bufmgr_priv}; int -init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) +init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) { tbm_bufmgr_sprd bufmgr_sprd; tbm_bufmgr_backend bufmgr_backend; @@ -1915,9 +1910,9 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) if (!bufmgr) return 0; - bufmgr_sprd = calloc (1, sizeof(struct _tbm_bufmgr_sprd)); + bufmgr_sprd = calloc(1, sizeof(struct _tbm_bufmgr_sprd)); if (!bufmgr_sprd) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to alloc bufmgr_sprd!\n", getpid()); + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to alloc bufmgr_sprd!\n", getpid()); return 0; } @@ -1929,8 +1924,8 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) bufmgr_sprd->fd = _tbm_sprd_open_drm(); if (bufmgr_sprd->fd < 0) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); - free (bufmgr_sprd); + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); + free(bufmgr_sprd); return 0; } @@ -1938,25 +1933,24 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd); - if (!bufmgr_sprd->device_name) - { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to get device name!\n", getpid()); + if (!bufmgr_sprd->device_name) { + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get device name!\n", getpid()); tbm_drm_helper_unset_tbm_master_fd(); close(bufmgr_sprd->fd); - free (bufmgr_sprd); + free(bufmgr_sprd); return 0; } } else { if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to get auth drm info!\n", getpid()); - free (bufmgr_sprd); + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get auth drm info!\n", getpid()); + free(bufmgr_sprd); return 0; } } //Create Hash Table - bufmgr_sprd->hashBos = drmHashCreate (); + bufmgr_sprd->hashBos = drmHashCreate(); //Check if the tbm manager supports dma fence or not. int fp = open("/sys/module/dmabuf_sync/parameters/enabled", O_RDONLY); @@ -1972,7 +1966,7 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) } if (!_bufmgr_init_cache_state(bufmgr_sprd)) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error: init bufmgr cache state failed!\n", getpid()); + TBM_SPRD_LOG("[libtbm-sprd:%d] error: init bufmgr cache state failed!\n", getpid()); if (tbm_backend_is_display_server()) tbm_drm_helper_unset_tbm_master_fd(); @@ -1985,7 +1979,7 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) bufmgr_backend = tbm_backend_alloc(); if (!bufmgr_backend) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); _bufmgr_deinit_cache_state(bufmgr_sprd); @@ -1994,7 +1988,7 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) close(bufmgr_sprd->fd); - free (bufmgr_sprd); + free(bufmgr_sprd); return 0; } @@ -2017,9 +2011,9 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) bufmgr_backend->bo_unlock = tbm_sprd_bo_unlock; bufmgr_backend->bufmgr_bind_native_display = tbm_sprd_bufmgr_bind_native_display; - if (!tbm_backend_init (bufmgr, bufmgr_backend)) { - TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to init backend!\n", getpid()); - tbm_backend_free (bufmgr_backend); + if (!tbm_backend_init(bufmgr, bufmgr_backend)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to init backend!\n", getpid()); + tbm_backend_free(bufmgr_backend); _bufmgr_deinit_cache_state(bufmgr_sprd); @@ -2028,27 +2022,27 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) close(bufmgr_sprd->fd); - free (bufmgr_sprd); + free(bufmgr_sprd); return 0; } #ifdef DEBUG { char *env; - env = getenv ("TBM_SPRD_DEBUG"); + env = getenv("TBM_SPRD_DEBUG"); if (env) { - bDebug = atoi (env); - TBM_SPRD_LOG ("TBM_SPRD_DEBUG=%s\n", env); + bDebug = atoi(env); + TBM_SPRD_LOG("TBM_SPRD_DEBUG=%s\n", env); } else { bDebug = 0; } } #endif - DBG ("[libtbm-sprd:%d] %s DMABUF FENCE is %s\n", getpid(), + DBG("[libtbm-sprd:%d] %s DMABUF FENCE is %s\n", getpid(), __FUNCTION__, bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!"); - DBG ("[libtbm-sprd:%d] %s fd:%d\n", getpid(), + DBG("[libtbm-sprd:%d] %s fd:%d\n", getpid(), __FUNCTION__, bufmgr_sprd->fd); return 1; -- 2.7.4 From 78d7b3d0a0b1b50319651a765a3b92fd5274fe35 Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Tue, 1 Nov 2016 11:41:16 +0900 Subject: [PATCH 04/16] tbm_bufmgr_sprd: clean up init_tbm_bufmgr_priv() This patch cleans up code and adds missed drmHashDestroy() calls. Change-Id: Ib87679562358dedaceda09088b78f1f57926627f Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 90 ++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 55 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 767f6e7..43c2fe3 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1904,8 +1904,9 @@ TBMModuleData tbmModuleData = { &SprdVersRec, init_tbm_bufmgr_priv}; int init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) { - tbm_bufmgr_sprd bufmgr_sprd; tbm_bufmgr_backend bufmgr_backend; + tbm_bufmgr_sprd bufmgr_sprd; + int fp; if (!bufmgr) return 0; @@ -1917,35 +1918,27 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) } if (tbm_backend_is_display_server()) { - bufmgr_sprd->fd = -1; - 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_LOG("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); - free(bufmgr_sprd); - return 0; + bufmgr_sprd->fd = _tbm_sprd_open_drm(); + if (bufmgr_sprd->fd < 0) { + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to open drm!\n", getpid()); + goto fail_open_drm; + } } tbm_drm_helper_set_tbm_master_fd(bufmgr_sprd->fd); bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd); - if (!bufmgr_sprd->device_name) { TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get device name!\n", getpid()); tbm_drm_helper_unset_tbm_master_fd(); - close(bufmgr_sprd->fd); - free(bufmgr_sprd); - return 0; + goto fail_get_device_name; } - } else { if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) { TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get auth drm info!\n", getpid()); - free(bufmgr_sprd); - return 0; + goto fail_get_auth_info; } } @@ -1953,11 +1946,10 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) bufmgr_sprd->hashBos = drmHashCreate(); //Check if the tbm manager supports dma fence or not. - int fp = open("/sys/module/dmabuf_sync/parameters/enabled", O_RDONLY); - int length; - char buf[1]; + fp = open("/sys/module/dmabuf_sync/parameters/enabled", O_RDONLY); if (fp != -1) { - length = read(fp, buf, 1); + char buf[1]; + int length = read(fp, buf, 1); if (length == 1 && buf[0] == '1') bufmgr_sprd->use_dma_fence = 1; @@ -1966,30 +1958,14 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) } if (!_bufmgr_init_cache_state(bufmgr_sprd)) { - TBM_SPRD_LOG("[libtbm-sprd:%d] error: init bufmgr cache state failed!\n", getpid()); - - if (tbm_backend_is_display_server()) - tbm_drm_helper_unset_tbm_master_fd(); - - close(bufmgr_sprd->fd); - - free(bufmgr_sprd); - return 0; + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to init bufmgr cache state\n", getpid()); + goto fail_init_cache_state; } bufmgr_backend = tbm_backend_alloc(); if (!bufmgr_backend) { - TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); - - _bufmgr_deinit_cache_state(bufmgr_sprd); - - if (tbm_backend_is_display_server()) - tbm_drm_helper_unset_tbm_master_fd(); - - close(bufmgr_sprd->fd); - - free(bufmgr_sprd); - return 0; + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to alloc backend!\n", getpid()); + goto fail_alloc_backend; } bufmgr_backend->priv = (void *)bufmgr_sprd; @@ -2013,39 +1989,43 @@ init_tbm_bufmgr_priv(tbm_bufmgr bufmgr, int fd) if (!tbm_backend_init(bufmgr, bufmgr_backend)) { TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to init backend!\n", getpid()); - tbm_backend_free(bufmgr_backend); - - _bufmgr_deinit_cache_state(bufmgr_sprd); - - if (tbm_backend_is_display_server()) - tbm_drm_helper_unset_tbm_master_fd(); - - close(bufmgr_sprd->fd); - - free(bufmgr_sprd); - return 0; + goto fail_init_backend; } #ifdef DEBUG { char *env; + env = getenv("TBM_SPRD_DEBUG"); if (env) { bDebug = atoi(env); TBM_SPRD_LOG("TBM_SPRD_DEBUG=%s\n", env); - } else { + } else bDebug = 0; - } } #endif DBG("[libtbm-sprd:%d] %s DMABUF FENCE is %s\n", getpid(), __FUNCTION__, bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!"); - DBG("[libtbm-sprd:%d] %s fd:%d\n", getpid(), __FUNCTION__, bufmgr_sprd->fd); return 1; -} +fail_init_backend: + tbm_backend_free(bufmgr_backend); +fail_alloc_backend: + _bufmgr_deinit_cache_state(bufmgr_sprd); +fail_init_cache_state: + if (bufmgr_sprd->hashBos) + drmHashDestroy(bufmgr_sprd->hashBos); + if (tbm_backend_is_display_server()) + tbm_drm_helper_unset_tbm_master_fd(); +fail_get_device_name: + close(bufmgr_sprd->fd); +fail_get_auth_info: +fail_open_drm: + free(bufmgr_sprd); + return 0; +} -- 2.7.4 From 2e2a0408114833d81f279950706475967a87b51f Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 8 Nov 2016 10:47:38 +0900 Subject: [PATCH 05/16] package version up to 1.0.2 Change-Id: Ib232582e96f5122e1d5d4fccfe08fc1fa785390b --- 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 34cacf0..66d54ad 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 1.0.1 +Version: 1.0.2 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From 668538f3f2e0b7f3dff0cfddf34e93f941a9c01e Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 9 Nov 2016 13:57:06 +0900 Subject: [PATCH 06/16] change the supported format four format supported. ARGB8888, XRGB8888, NV12 and YUV420 Change-Id: I7eca1bb90ec813a92c49cc3d74836952c84d120d --- src/tbm_bufmgr_sprd.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 43c2fe3..db9236a 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -61,7 +61,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //#define USE_CONTIG_ONLY #define USE_DMAIMPORT -#define TBM_COLOR_FORMAT_COUNT 8 +#define TBM_COLOR_FORMAT_COUNT 4 #ifdef DEBUG #define LOG_TAG "TBM_BACKEND" @@ -247,15 +247,12 @@ char *STR_OPT[] = { }; -uint32_t tbm_sprd_color_format_list[TBM_COLOR_FORMAT_COUNT] = { TBM_FORMAT_RGBA8888, - TBM_FORMAT_BGRA8888, - TBM_FORMAT_RGBX8888, - TBM_FORMAT_RGB888, - TBM_FORMAT_NV12, - TBM_FORMAT_NV21, - TBM_FORMAT_YUV420, - TBM_FORMAT_YVU420 - }; +uint32_t tbm_sprd_color_format_list[TBM_COLOR_FORMAT_COUNT] = { + TBM_FORMAT_ARGB8888, + TBM_FORMAT_XRGB8888, + TBM_FORMAT_NV12, + TBM_FORMAT_YUV420 + }; static inline int _tgl_init(int fd, unsigned int key) -- 2.7.4 From d27a9b6ca938829df489b3fb2096ceb44083fb43 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Thu, 10 Nov 2016 19:45:22 +0900 Subject: [PATCH 07/16] package version up to 1.0.3 Change-Id: I22c9363ea85c046e67217b8ea783c22ddf17d9cc --- 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 66d54ad..a4edbd9 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -1,5 +1,5 @@ Name: libtbm-sprd -Version: 1.0.2 +Version: 1.0.3 Release: 0 License: MIT Summary: Tizen Buffer Manager - sprd backend -- 2.7.4 From faaf0736a760a3e2db187e352eeb84140d171d68 Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 15:49:23 +0900 Subject: [PATCH 08/16] tbm_bufmgr_sprd: clean up target_name() This patch cleans up target_name(). - Renames it as _target_name(). Change-Id: I93ac6144a99ae6937377b8fadf0d21e48675adab Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index db9236a..46c1372 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -70,41 +70,39 @@ static int bDebug = 0; #define SPRD_DRM_NAME "sprd" -char * -target_name() +static char * +_target_name(void) { - FILE *f; + static char app_name[128] = {0, }; + static int initialized = 0; char *slash; - static int initialized = 0; - static char app_name[128]; + FILE *f; if (initialized) return app_name; /* get the application name */ f = fopen("/proc/self/cmdline", "r"); - if (!f) - return 0; - - memset(app_name, 0x00, sizeof(app_name)); + return NULL; if (fgets(app_name, 100, f) == NULL) { fclose(f); - return 0; + return NULL; } fclose(f); - if ((slash = strrchr(app_name, '/')) != NULL) + slash = strrchr(app_name, '/'); + if (slash != NULL) memmove(app_name, slash + 1, strlen(slash)); initialized = 1; return app_name; } -#define TBM_SPRD_LOG(fmt, args...) LOGE("\033[31m" "[%s]" fmt "\033[0m", target_name(), ##args) -#define DBG(fmt, args...) if (bDebug&01) LOGE("[%s]" fmt, target_name(), ##args) +#define TBM_SPRD_LOG(fmt, args...) LOGE("\033[31m" "[%s]" fmt "\033[0m", _target_name(), ##args) +#define DBG(fmt, args...) if (bDebug&01) LOGE("[%s]" fmt, _target_name(), ##args) #else #define TBM_SPRD_LOG(...) #define DBG(...) @@ -409,7 +407,7 @@ _tbm_sprd_open_drm() if (strcmp(udev_device_get_sysname(device_parent), "sprd-drm") == 0) { drm_device = device; DBG("[%s] Found render device: '%s' (%s)\n", - target_name(), + _target_name(), udev_device_get_syspath(drm_device), udev_device_get_sysname(device_parent)); break; @@ -1197,7 +1195,7 @@ tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) } DBG(" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - target_name(), + _target_name(), bo, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, @@ -1258,7 +1256,7 @@ tbm_sprd_bo_export_fd(tbm_bo bo) } DBG(" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", - target_name(), + _target_name(), bo, bo_sprd->gem, bo_sprd->name, bo_sprd->dmabuf, -- 2.7.4 From 8c539d74d7b69d1ac3ff10b38b271ec394b5f02b Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 15:53:19 +0900 Subject: [PATCH 09/16] tbm_bufmgr_sprd: clean up _tbm_sprd_open_drm() This patch cleans up _tbm_sprd_open_drm(). Change-Id: Ic55b1b347f1c09e698da21fb10e10e2977fbac5f Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 139 ++++++++++++++++++++++++-------------------------- 1 file changed, 67 insertions(+), 72 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 46c1372..bf2366e 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -362,92 +362,87 @@ _tgl_get_data(int fd, unsigned int key, unsigned int *locked) #endif static int -_tbm_sprd_open_drm() +_tbm_sprd_open_drm(void) { - int fd = -1; +#ifdef HAVE_UDEV + struct udev_device *drm_device = NULL; + struct udev_list_entry *entry = NULL; + struct udev_enumerate *e; + const char *filepath; + struct udev *udev; + struct stat s; +#endif + int fd; fd = drmOpen(SPRD_DRM_NAME, NULL); - if (fd < 0) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "warning %s:%d fail to open drm\n", - getpid(), __FUNCTION__, __LINE__); - } + if (fd != -1) + return fd; #ifdef HAVE_UDEV - if (fd < 0) { - struct udev *udev = NULL; - struct udev_enumerate *e = NULL; - struct udev_list_entry *entry = NULL; - struct udev_device *device = NULL, *drm_device = NULL, *device_parent = NULL; - const char *filepath; - struct stat s; - int ret; - - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "%s:%d search drm-device by udev\n", - getpid(), __FUNCTION__, __LINE__); - - udev = udev_new(); - if (!udev) { - TBM_SPRD_LOG("udev_new() failed.\n"); - return -1; - } + TBM_SPRD_LOG("[libtbm-sprd:%d] warning %s:%d fail to open drm, " + "so search drm-device by udev\n", + getpid(), __FUNCTION__, __LINE__); + + udev = udev_new(); + if (!udev) { + TBM_SPRD_LOG("udev_new() failed.\n"); + return -1; + } - e = udev_enumerate_new(udev); - udev_enumerate_add_match_subsystem(e, "drm"); - udev_enumerate_add_match_sysname(e, "card[0-9]*"); - udev_enumerate_scan_devices(e); - - udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { - device = udev_device_new_from_syspath(udev_enumerate_get_udev(e), - udev_list_entry_get_name(entry)); - device_parent = udev_device_get_parent(device); - /* Not need unref device_parent. device_parent and device have same refcnt */ - if (device_parent) { - if (strcmp(udev_device_get_sysname(device_parent), "sprd-drm") == 0) { - drm_device = device; - DBG("[%s] Found render device: '%s' (%s)\n", - _target_name(), - udev_device_get_syspath(drm_device), - udev_device_get_sysname(device_parent)); - break; - } + e = udev_enumerate_new(udev); + udev_enumerate_add_match_subsystem(e, "drm"); + udev_enumerate_add_match_sysname(e, "card[0-9]*"); + udev_enumerate_scan_devices(e); + + udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { + struct udev_device *device, *device_parent; + + device = udev_device_new_from_syspath(udev_enumerate_get_udev(e), + udev_list_entry_get_name(entry)); + device_parent = udev_device_get_parent(device); + /* Not need unref device_parent. device_parent and device have same refcnt */ + if (device_parent) { + if (strcmp(udev_device_get_sysname(device_parent), "sprd-drm") == 0) { + drm_device = device; + DBG("[%s] Found render device: '%s' (%s)\n", + _target_name(), + udev_device_get_syspath(drm_device), + udev_device_get_sysname(device_parent)); + break; } - udev_device_unref(device); } + udev_device_unref(device); + } - udev_enumerate_unref(e); + udev_enumerate_unref(e); - /* Get device file path. */ - filepath = udev_device_get_devnode(drm_device); - if (!filepath) { - TBM_SPRD_LOG("udev_device_get_devnode() failed.\n"); - udev_device_unref(drm_device); - udev_unref(udev); - return -1; - } + /* Get device file path. */ + filepath = udev_device_get_devnode(drm_device); + if (!filepath) { + TBM_SPRD_LOG("udev_device_get_devnode() failed.\n"); + udev_device_unref(drm_device); + udev_unref(udev); + return -1; + } - /* Open DRM device file and check validity. */ - fd = open(filepath, O_RDWR | O_CLOEXEC); - if (fd < 0) { - TBM_SPRD_LOG("open(%s, O_RDWR | O_CLOEXEC) failed.\n"); - udev_device_unref(drm_device); - udev_unref(udev); - return -1; - } + udev_device_unref(drm_device); + udev_unref(udev); - ret = fstat(fd, &s); - if (ret) { - TBM_SPRD_LOG("fstat() failed %s.\n"); - close(fd); - udev_device_unref(drm_device); - udev_unref(udev); - return -1; - } + /* Open DRM device file and check validity. */ + fd = open(filepath, O_RDWR | O_CLOEXEC); + if (fd < 0) { + TBM_SPRD_LOG("open(%s, O_RDWR | O_CLOEXEC) failed.\n"); + return -1; + } - udev_device_unref(drm_device); - udev_unref(udev); + if (fstat(fd, &s)) { + TBM_SPRD_LOG("fstat() failed %s.\n"); + close(fd); + return -1; } +#else + TBM_SPRD_LOG("[libtbm-sprd:%d] warning %s:%d fail to open drm\n", + getpid(), __FUNCTION__, __LINE__); #endif return fd; -- 2.7.4 From 1ab9dcf0283076b937a6674e27a9b2af5368b46c Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 16:04:31 +0900 Subject: [PATCH 10/16] tbm_bufmgr_sprd: clean up _sprd_bo_cache_flush() This patch cleans up _sprd_bo_cache_flush(). - There is a routine for bo_sprd is NULL case, so the NULL check routine is wrong. Change-Id: I7f62cc19300c6bec770d013e614f79d22224a8e0 Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index bf2366e..b93e42e 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -453,7 +453,6 @@ 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); - SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); /* cache flush is managed by kernel side when using dma-fence. */ if (bufmgr_sprd->use_dma_fence) -- 2.7.4 From 35d0f6aed0142311d1390332285a433d4b3ee906 Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 16:06:54 +0900 Subject: [PATCH 11/16] tbm_bufmgr_sprd: clean up tbm_sprd_bo_size() This patch cleans up tbm_sprd_bo_size(). - The tbm_exynos_bo_size() checkes whether bo_exynos is NULL or not. So it's safer to check also. Change-Id: Ie328c166a784a9e483f416707c512f79cc18cbf6 Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index b93e42e..29eba0b 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -828,6 +828,7 @@ tbm_sprd_bo_size(tbm_bo bo) tbm_bo_sprd bo_sprd; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); + SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, 0); return bo_sprd->size; } -- 2.7.4 From 5e3db9c0c095c0ceeadfe697eef379bc0579792d Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 16:11:58 +0900 Subject: [PATCH 12/16] tbm_bufmgr_sprd: clean up tbm_sprd_bo_alloc() This patch cleans up tbm_sprd_bo_alloc(). - The privGem could be NULL if calloc() is failed. Change-Id: I6052b6d5767191a6dc660a8aa7e5bd24b85a6d6d Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 29eba0b..ecca133 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -838,9 +838,9 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags) { SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); - tbm_bo_sprd bo_sprd; tbm_bufmgr_sprd bufmgr_sprd; unsigned int sprd_flags; + 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); @@ -858,11 +858,10 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags) sprd_flags = SPRD_BO_CONTIG; #else sprd_flags = _get_sprd_flag_from_tbm(flags); - if ((flags & TBM_BO_SCANOUT) && - size <= 4 * 1024) { + 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; @@ -907,6 +906,14 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags) /* add bo to hash */ PrivGem *privGem = calloc(1, sizeof(PrivGem)); + if (!privGem) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " + "error %s:%d Fail to calloc PrivGem\n", + getpid(), __FUNCTION__, __LINE__); + 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) { -- 2.7.4 From 4680e69630d25e12267dff1d1bbb26b0abbdf5f2 Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 16:17:44 +0900 Subject: [PATCH 13/16] tbm_bufmgr_sprd: clean up tbm_sprd_bo_import(_fd)() This patch cleans up tbm_sprd_bo_import(_fd)(). - Changes return value. - Closes gem handle for error routines. Change-Id: Ibf6a27cc05a155deec483d87179dcb428fb611f4 Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 81 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index ecca133..e8b84a0 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -999,7 +999,7 @@ tbm_sprd_bo_free(tbm_bo bo) static void * tbm_sprd_bo_import(tbm_bo bo, unsigned int key) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, NULL); tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; @@ -1007,21 +1007,21 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) int ret; bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, NULL); ret = drmHashLookup(bufmgr_sprd->hashBos, key, (void **)&privGem); if (ret == 0) return privGem->bo_priv; - struct drm_gem_open arg = {0, }; struct drm_sprd_gem_info info = {0, }; + struct drm_gem_open arg = {0, }; arg.name = key; if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg)) { TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot open gem name=%d\n", getpid(), __FUNCTION__, __LINE__, key); - return 0; + return NULL; } info.handle = arg.handle; @@ -1032,7 +1032,7 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot get gem info=%d\n", getpid(), __FUNCTION__, __LINE__, key); - return 0; + goto fail_get_gem; } bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd)); @@ -1040,7 +1040,7 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d fail to allocate the bo private\n", getpid(), __FUNCTION__, __LINE__); - return 0; + goto fail_alloc_bo; } bo_sprd->fd = bufmgr_sprd->fd; @@ -1057,8 +1057,7 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name); - free(bo_sprd); - return 0; + goto fail_init_cache; } if (!bo_sprd->dmabuf) { @@ -1069,14 +1068,19 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Cannot dmabuf=%d\n", getpid(), __FUNCTION__, __LINE__, bo_sprd->gem); - free(bo_sprd); - return 0; + goto fail_prime_handle_to_fd; } bo_sprd->dmabuf = arg.fd; } /* add bo to hash */ privGem = calloc(1, sizeof(PrivGem)); + if (!privGem) { + TBM_SPRD_LOG("[libtbm-sprd:%d] error %s:%d Fail to alloc\n", + getpid(), __FUNCTION__, __LINE__); + 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) { @@ -1091,28 +1095,41 @@ tbm_sprd_bo_import(tbm_bo bo, unsigned int key) bo_sprd->flags_tbm, bo_sprd->flags_sprd); return (void *)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: + 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 void * tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) { - SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bo != NULL, NULL); tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; - PrivGem *privGem = NULL; - int ret; unsigned int name; + PrivGem *privGem; bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); - SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, NULL); //getting handle from fd - unsigned int gem = 0; struct drm_prime_handle arg = {0, }; + unsigned int gem; arg.fd = key; - arg.flags = 0; if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) { TBM_SPRD_LOG("error bo:%p Cannot get gem handle from fd:%d (%s)\n", bo, arg.fd, strerror(errno)); @@ -1121,14 +1138,18 @@ tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) gem = arg.handle; name = _get_name(bufmgr_sprd->fd, gem); + if (!name) { + TBM_SPRD_LOG("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n", + bo, gem, key, strerror(errno)); + return NULL; + } - ret = drmHashLookup(bufmgr_sprd->hashBos, name, (void **)&privGem); - if (ret == 0) { + if (!drmHashLookup(bufmgr_sprd->hashBos, name, (void **)&privGem)) { if (gem == privGem->bo_priv->gem) return privGem->bo_priv; } - unsigned int real_size = -1; + unsigned int real_size; struct drm_sprd_gem_info info = {0, }; /* Determine size of bo. The fd-to-handle ioctl really should @@ -1145,7 +1166,7 @@ tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) sizeof(struct drm_sprd_gem_info))) { TBM_SPRD_LOG("error bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n", bo, gem, key, strerror(errno)); - return 0; + return NULL; } if (real_size == -1) @@ -1154,7 +1175,7 @@ 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_LOG("error bo:%p fail to allocate the bo private\n", bo); - return 0; + return NULL; } bo_sprd->fd = bufmgr_sprd->fd; @@ -1167,26 +1188,21 @@ tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) if (!bo_sprd->name) { TBM_SPRD_LOG("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n", bo, gem, key, strerror(errno)); - free(bo_sprd); - return 0; + goto fail_check_name; } if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) { TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name); - free(bo_sprd); - return 0; + goto fail_init_cache; } /* add bo to hash */ - privGem = NULL; - privGem = calloc(1, sizeof(PrivGem)); if (!privGem) { TBM_SPRD_LOG("[libtbm-sprd:%d] " "error %s:%d Fail to callocprivGem\n", getpid(), __FUNCTION__, __LINE__); - free(bo_sprd); - return 0; + goto fail_alloc_gem_priv; } privGem->ref_count = 1; @@ -1206,6 +1222,13 @@ tbm_sprd_bo_import_fd(tbm_bo bo, tbm_fd key) bo_sprd->size); return (void *)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 -- 2.7.4 From d2c938f451e1b043a3b97a163a401a2c4cf90665 Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 16:20:50 +0900 Subject: [PATCH 14/16] tbm_bufmgr_sprd: change functions as static one This patch changes functions as static one. - tbm_sprd_bo_export_fd() - tbm_sprd_surface_supported_format() - tbm_sprd_surface_get_plane_data() - tbm_sprd_bo_get_flags() - tbm_sprd_bufmgr_bind_native_display() Change-Id: I4b67b9200434cb1950b16bb4b734ecec902696b9 Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index e8b84a0..81676b8 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1259,7 +1259,7 @@ tbm_sprd_bo_export(tbm_bo bo) return (unsigned int)bo_sprd->name; } -tbm_fd +static tbm_fd tbm_sprd_bo_export_fd(tbm_bo bo) { SPRD_RETURN_VAL_IF_FAIL(bo != NULL, -1); @@ -1603,25 +1603,22 @@ tbm_sprd_bufmgr_deinit(void *priv) free(bufmgr_sprd); } -int +static int tbm_sprd_surface_supported_format(uint32_t **formats, uint32_t *num) { - uint32_t *color_formats = NULL; + uint32_t *color_formats; color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); - if (color_formats == NULL) return 0; 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; } @@ -1638,7 +1635,7 @@ tbm_sprd_surface_supported_format(uint32_t **formats, uint32_t *num) * @param[out] padding : the padding of the plane * @return 1 if this function succeeds, otherwise 0. */ -int +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) @@ -1879,7 +1876,7 @@ tbm_sprd_surface_get_plane_data(int width, int height, return ret; } -int +static int tbm_sprd_bo_get_flags(tbm_bo bo) { SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); @@ -1892,7 +1889,7 @@ tbm_sprd_bo_get_flags(tbm_bo bo) return bo_sprd->flags_tbm; } -int +static int tbm_sprd_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay) { tbm_bufmgr_sprd bufmgr_sprd; -- 2.7.4 From 24954801fd0aed3bc44104c93991d0328c0a66f7 Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 14 Nov 2016 16:24:06 +0900 Subject: [PATCH 15/16] tbm_bufmgr_sprd: clean up tbm_sprd_bo_unmap() This patch cleans up tbm_sprd_bo_unmap(). - The bufmgr_sprd->use_dma_fence is checked unnecessarily. Change-Id: I7e133e680b320dc0022ce10cac6e99798832d014 Signed-off-by: YoungJun Cho --- src/tbm_bufmgr_sprd.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 81676b8..1b30142 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1373,8 +1373,8 @@ tbm_sprd_bo_unmap(tbm_bo bo) { SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0); - tbm_bo_sprd bo_sprd; 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); @@ -1414,7 +1414,6 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) int ret = 0; if (bufmgr_sprd->use_dma_fence) { - struct dma_buf_fence fence; memset(&fence, 0, sizeof(struct dma_buf_fence)); @@ -1446,15 +1445,6 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) return 0; } - /* Check if the tbm manager supports dma fence or not. */ - if (!bufmgr_sprd->use_dma_fence) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error %s:%d Not support DMA FENCE(%s)\n", - getpid(), __FUNCTION__, __LINE__, strerror(errno)); - return 0; - - } - ret = ioctl(bo_sprd->dmabuf, DMABUF_IOCTL_GET_FENCE, &fence); if (ret < 0) { TBM_SPRD_LOG("[libtbm-sprd:%d] " @@ -1484,7 +1474,6 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) getpid(), __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf); } else { - ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name); DBG("[libtbm-sprd:%d] lock tgl flink_id:%d\n", -- 2.7.4 From c0aa72545a4e3cab567478909dfd0d209e66e373 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Mon, 21 Nov 2016 13:49:26 +0900 Subject: [PATCH 16/16] change the slp_global_lock to the tgl We do not use slp_global_lock device anymore on tm1 target. We use tgl device instead and the use space interface is changed because of this change. This is only for the tm1 target. p.s. When the kernel version is up and kernel can use the dma_fence, libtbm-sprd does not use the tgl for the bo lock and for the bo cache_flush anymore. Change-Id: I4631a5f600bfaea47d8618036f40b17885c45493 --- rules/99-libtbm_sprd.rules | 2 +- src/tbm_bufmgr_sprd.c | 149 +++++++++++++++++++++++++++++---------------- src/tbm_bufmgr_tgl.h | 93 ++++++++++++++++++++++------ 3 files changed, 173 insertions(+), 71 deletions(-) diff --git a/rules/99-libtbm_sprd.rules b/rules/99-libtbm_sprd.rules index b00652e..13cef12 100644 --- a/rules/99-libtbm_sprd.rules +++ b/rules/99-libtbm_sprd.rules @@ -1 +1 @@ -KERNEL=="slp_global_lock*", MODE="0666", GROUP="display", SECLABEL{smack}="*" +KERNEL=="tgl", MODE="0666", GROUP="display", SECLABEL{smack}="*" diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 1b30142..1db8ac5 100644 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -59,6 +59,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "tbm_bufmgr_tgl.h" //#define USE_CONTIG_ONLY +//#define USE_CACHE #define USE_DMAIMPORT #define TBM_COLOR_FORMAT_COUNT 4 @@ -246,25 +247,45 @@ char *STR_OPT[] = { uint32_t tbm_sprd_color_format_list[TBM_COLOR_FORMAT_COUNT] = { - TBM_FORMAT_ARGB8888, - TBM_FORMAT_XRGB8888, - TBM_FORMAT_NV12, - TBM_FORMAT_YUV420 - }; + TBM_FORMAT_ARGB8888, + TBM_FORMAT_XRGB8888, + TBM_FORMAT_NV12, + TBM_FORMAT_YUV420 + }; + +static inline int +_tgl_get_version(int fd) +{ + struct tgl_ver_data data; + int err; + + err = ioctl(fd, TGL_IOCTL_GET_VERSION, &data); + if (err) { + TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d\n", + getpid(), strerror(errno), __func__, __LINE__); + return 0; + } + + TBM_SPRD_LOG("[libtbm-sprd:%d] %s:%d tgl version is (%u, %u).\n", + getpid(), __func__, __LINE__, data.major, data.minor); + + return 1; +} + static inline int _tgl_init(int fd, unsigned int key) { - struct tgl_attribute attr; + struct tgl_reg_data data; int err; - attr.key = key; - attr.timeout_ms = 1000; + data.key = key; + data.timeout_ms = 1000; - err = ioctl(fd, TGL_IOC_INIT_LOCK, &attr); + err = ioctl(fd, TGL_IOCTL_REGISTER, &data); if (err) { TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n", - getpid(), strerror(errno), __func__, __LINE__, key); + getpid(), strerror(errno), __func__, __LINE__, key); return 0; } @@ -274,13 +295,14 @@ _tgl_init(int fd, unsigned int key) static inline int _tgl_destroy(int fd, unsigned int key) { + struct tgl_reg_data data; int err; - err = ioctl(fd, TGL_IOC_DESTROY_LOCK, key); + data.key = key; + err = ioctl(fd, TGL_IOCTL_UNREGISTER, &data); if (err) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error(%s) %s:%d key:%d\n", - getpid(), strerror(errno), __func__, __LINE__, key); + TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n", + getpid(), strerror(errno), __func__, __LINE__, key); return 0; } @@ -288,15 +310,31 @@ _tgl_destroy(int fd, unsigned int key) } static inline int -_tgl_lock(int fd, unsigned int key) +_tgl_lock(int fd, unsigned int key, int opt) { + struct tgl_lock_data data; + enum tgl_type_data tgl_type; int err; - err = ioctl(fd, TGL_IOC_LOCK_LOCK, key); + switch (opt) { + case TBM_OPTION_READ: + tgl_type = TGL_TYPE_READ; + break; + case TBM_OPTION_WRITE: + tgl_type = TGL_TYPE_WRITE; + break; + default: + tgl_type = TGL_TYPE_NONE; + break; + } + + data.key = key; + data.type = tgl_type; + + err = ioctl(fd, TGL_IOCTL_LOCK, data); if (err) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error(%s) %s:%d key:%d\n", - getpid(), strerror(errno), __func__, __LINE__, key); + TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d opt:%d\n", + getpid(), strerror(errno), __func__, __LINE__, key, opt); return 0; } @@ -306,13 +344,16 @@ _tgl_lock(int fd, unsigned int key) static inline int _tgl_unlock(int fd, unsigned int key) { + struct tgl_lock_data data; int err; - err = ioctl(fd, TGL_IOC_UNLOCK_LOCK, key); + data.key = key; + data.type = TGL_TYPE_NONE; + + err = ioctl(fd, TGL_IOCTL_UNLOCK, data); if (err) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error(%s) %s:%d key:%d\n", - getpid(), strerror(errno), __func__, __LINE__, key); + TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n", + getpid(), strerror(errno), __func__, __LINE__, key); return 0; } @@ -323,16 +364,16 @@ _tgl_unlock(int fd, unsigned int key) static inline int _tgl_set_data(int fd, unsigned int key, unsigned int val) { + struct tgl_usr_data data; int err; - struct tgl_user_data arg; - arg.key = key; - arg.data1 = val; - err = ioctl(fd, TGL_IOC_SET_DATA, &arg); + data.key = key; + data.data1 = val; + + err = ioctl(fd, TGL_IOCTL_SET_DATA, &data); if (err) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error(%s) %s:%d key:%d\n", - getpid(), strerror(errno), __func__, __LINE__, key); + TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n", + getpid(), strerror(errno), __func__, __LINE__, key); return 0; } @@ -342,22 +383,22 @@ _tgl_set_data(int fd, unsigned int key, unsigned int val) static inline unsigned int _tgl_get_data(int fd, unsigned int key, unsigned int *locked) { + struct tgl_usr_data data = { 0, }; int err; - struct tgl_user_data arg = { 0, }; - arg.key = key; - err = ioctl(fd, TGL_IOC_GET_DATA, &arg); + data.key = key; + + err = ioctl(fd, TGL_IOCTL_GET_DATA, &data); if (err) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error(%s) %s:%d key:%d\n", - getpid(), strerror(errno), __func__, __LINE__, key); + TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n", + getpid(), strerror(errno), __func__, __LINE__, key); return 0; } if (locked) - *locked = arg.locked; + *locked = (unsigned int)data.status; - return arg.data1; + return data.data1; } #endif @@ -457,7 +498,9 @@ _sprd_bo_cache_flush(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags /* cache flush is managed by kernel side when using dma-fence. */ if (bufmgr_sprd->use_dma_fence) return 1; - +// TODO: The tm1 kernel does not support ioctl for cache flush right now. +// The drm in tm1 kernel has to support cache_flush to turn on this feature(TBM_SRPD_CACHE_FLUSH). +#if TBM_SRPD_CACHE_FLUSH struct drm_sprd_gem_cache_op cache_op = {0, }; int ret; @@ -498,7 +541,7 @@ _sprd_bo_cache_flush(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags getpid(), __FUNCTION__, __LINE__); return 0; } - +#endif return 1; } #endif @@ -641,22 +684,26 @@ _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) /* open tgl fd for saving cache flush data */ bufmgr_sprd->tgl_fd = open(tgl_devfile, O_RDWR); - if (bufmgr_sprd->tgl_fd < 0) { - bufmgr_sprd->tgl_fd = open(tgl_devfile1, O_RDWR); - if (bufmgr_sprd->tgl_fd < 0) { - TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error: Fail to open global_lock:%s\n", - getpid(), tgl_devfile); - return 0; - } + TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to open global_lock:%s\n", + getpid(), tgl_devfile); + return 0; + } + + if (!_tgl_get_version(bufmgr_sprd->tgl_fd)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " + "error: fail to get tgl_version. tgl init failed.\n", + getpid()); + + close(bufmgr_sprd->tgl_fd); + return 0; } #ifdef USE_CACHE if (!_tgl_init(bufmgr_sprd->tgl_fd, GLOBAL_KEY)) { TBM_SPRD_LOG("[libtbm-sprd:%d] " - "error: Fail to initialize the tgl\n", - getpid()); + "error: Fail to initialize the tgl\n", + getpid()); close(bufmgr_sprd->tgl_fd); return 0; @@ -1474,7 +1521,7 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) getpid(), __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf); } else { - ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name); + ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name, opt); DBG("[libtbm-sprd:%d] lock tgl flink_id:%d\n", getpid(), __FUNCTION__, bo_sprd->name); diff --git a/src/tbm_bufmgr_tgl.h b/src/tbm_bufmgr_tgl.h index 2279cac..1790885 100644 --- a/src/tbm_bufmgr_tgl.h +++ b/src/tbm_bufmgr_tgl.h @@ -34,37 +34,92 @@ #include -static char tgl_devfile[] = "/dev/slp_global_lock"; -static char tgl_devfile1[] = "/dev/tgl"; +static char tgl_devfile[] = "/dev/tgl"; -#define TGL_IOC_BASE 0x32 +#define TGL_IOCTL_BASE 0x32 +#define TGL_IO(nr) _IO(TGL_IOCTL_BASE, nr) +#define TGL_IOR(nr, type) _IOR(TGL_IOCTL_BASE, nr, type) +#define TGL_IOW(nr, type) _IOW(TGL_IOCTL_BASE, nr, type) +#define TGL_IOWR(nr, type) _IOWR(TGL_IOCTL_BASE, nr, type) -struct tgl_attribute { +/** + * struct tgl_ver_data - tgl version data structure + * @major: major version + * @minor: minor version + */ +struct tgl_ver_data { + unsigned int major; + unsigned int minor; +}; + +/** + * struct tgl_reg_data - tgl data structure + * @key: lookup key + * @timeout_ms: timeout value for waiting event + */ +struct tgl_reg_data { unsigned int key; unsigned int timeout_ms; }; -struct tgl_user_data { +enum tgl_type_data { + TGL_TYPE_NONE = 0, + TGL_TYPE_READ = (1 << 0), + TGL_TYPE_WRITE = (1 << 1), +}; + +/** + * struct tgl_lock_data - tgl lock data structure + * @key: lookup key + * @type: lock type that is in tgl_type_data + */ +struct tgl_lock_data { + unsigned int key; + enum tgl_type_data type; +}; + +enum tgl_status_data { + TGL_STATUS_UNLOCKED, + TGL_STATUS_LOCKED, +}; + +/** + * struct tgl_usr_data - tgl user data structure + * @key: lookup key + * @data1: user data 1 + * @data2: user data 2 + * @status: lock status that is in tgl_status_data + */ +struct tgl_usr_data { unsigned int key; unsigned int data1; unsigned int data2; - unsigned int locked; + enum tgl_status_data status; }; -typedef enum { - _TGL_INIT_LOCK = 1, - _TGL_DESTROY_LOCK, - _TGL_LOCK_LOCK, - _TGL_UNLOCK_LOCK, +enum { + _TGL_GET_VERSION, + _TGL_REGISTER, + _TGL_UNREGISTER, + _TGL_LOCK, + _TGL_UNLOCK, _TGL_SET_DATA, _TGL_GET_DATA, -} _tgl_ioctls; +}; -#define TGL_IOC_INIT_LOCK _IOW(TGL_IOC_BASE, _TGL_INIT_LOCK, struct tgl_attribute *) -#define TGL_IOC_DESTROY_LOCK _IOW(TGL_IOC_BASE, _TGL_DESTROY_LOCK, unsigned int) -#define TGL_IOC_LOCK_LOCK _IOW(TGL_IOC_BASE, _TGL_LOCK_LOCK, unsigned int) -#define TGL_IOC_UNLOCK_LOCK _IOW(TGL_IOC_BASE, _TGL_UNLOCK_LOCK, unsigned int) -#define TGL_IOC_SET_DATA _IOW(TGL_IOC_BASE, _TGL_SET_DATA, struct tgl_user_data *) -#define TGL_IOC_GET_DATA _IOW(TGL_IOC_BASE, _TGL_GET_DATA, struct tgl_user_data *) +/* get version information */ +#define TGL_IOCTL_GET_VERSION TGL_IOR(_TGL_GET_VERSION, struct tgl_ver_data) +/* register key */ +#define TGL_IOCTL_REGISTER TGL_IOW(_TGL_REGISTER, struct tgl_reg_data) +/* unregister key */ +#define TGL_IOCTL_UNREGISTER TGL_IOW(_TGL_UNREGISTER, struct tgl_reg_data) +/* lock with key */ +#define TGL_IOCTL_LOCK TGL_IOW(_TGL_LOCK, struct tgl_lock_data) +/* unlock with key */ +#define TGL_IOCTL_UNLOCK TGL_IOW(_TGL_UNLOCK, struct tgl_lock_data) +/* set user data with key */ +#define TGL_IOCTL_SET_DATA TGL_IOW(_TGL_SET_DATA, struct tgl_usr_data) +/* get user data with key */ +#define TGL_IOCTL_GET_DATA TGL_IOR(_TGL_GET_DATA, struct tgl_usr_data) -#endif /* __TBM_BUFMGR_TGL_H__ */ +#endif /* __TBM_BUFMGR_TGL_H__ */ -- 2.7.4