From 5642912318e722860e426355b233c6802ac9be70 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Fri, 25 Mar 2016 14:24:30 +0900 Subject: [PATCH 01/16] Set and unset tbm master fd Change-Id: I5f0eb70d6dcef075ea4fec644fee9b0c3405b9cd --- src/tbm_bufmgr_sprd.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 064fafc..16ada73 100755 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1519,6 +1519,9 @@ tbm_sprd_bufmgr_deinit (void *priv) if (bufmgr_sprd->bind_display) tbm_drm_helper_wl_auth_server_deinit(); + if (tbm_backend_is_display_server()) + tbm_drm_helper_unset_tbm_master_fd(); + if (bufmgr_sprd->device_name) free(bufmgr_sprd->device_name); @@ -1863,19 +1866,19 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) bufmgr_sprd->fd = -1; master_fd = tbm_drm_helper_get_master_fd(); - if (master_fd < 0) { + if (master_fd < 0) bufmgr_sprd->fd = _tbm_sprd_open_drm(); - tbm_drm_helper_set_master_fd(bufmgr_sprd->fd); - } else { - bufmgr_sprd->fd = dup(master_fd); - } - + else + bufmgr_sprd->fd = master_fd; + if (bufmgr_sprd->fd < 0) { TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); free (bufmgr_sprd); return 0; } + tbm_drm_helper_set_tbm_master_fd(bufmgr_sprd->fd); + bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd); if (!bufmgr_sprd->device_name) -- 2.7.4 From 294ad4e4c0aebc25d1d2dbca2e5b6c9a94bf6f29 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Wed, 30 Mar 2016 19:33:39 +0900 Subject: [PATCH 02/16] only use tgl if cache control enable and fix memory leak Change-Id: I6c460bdf9c640aff1214a47fc910e2c66de69faf --- src/tbm_bufmgr_sprd.c | 213 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 128 insertions(+), 85 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 16ada73..aa93b82 100755 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -230,7 +230,6 @@ struct _tbm_bufmgr_sprd { int tgl_fd; void *bind_display; - char *device_name; }; @@ -259,7 +258,7 @@ uint32_t tbm_sprd_color_format_list[TBM_COLOR_FORMAT_COUNT] = { TBM_FORMAT_RGBA8 TBM_FORMAT_YUV420, TBM_FORMAT_YVU420 }; - +#ifdef USE_CACHE static inline int _tgl_init(int fd, unsigned int key) { @@ -366,6 +365,7 @@ _tgl_get_data(int fd, unsigned int key, unsigned int *locked) return arg.data1; } +#endif static int _tbm_sprd_open_drm() @@ -460,23 +460,16 @@ _tbm_sprd_open_drm() } static int -_sprd_bo_cache_flush (tbm_bo bo, int flags) +_sprd_bo_cache_flush (tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags) { - tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); +#ifdef USE_CACHE 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) return 1; - 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); - -#ifdef USE_CACHE struct drm_sprd_gem_cache_op cache_op = {0, }; int ret; @@ -523,37 +516,43 @@ _sprd_bo_cache_flush (tbm_bo bo, int flags) } static int -_bo_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) +_bo_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int import) { - tbm_bo_cache_state cache_state; - +#ifdef USE_CACHE SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); + tbm_bo_cache_state cache_state; + + if (bufmgr_sprd->use_dma_fence) + return 1; + _tgl_init(bufmgr_sprd->tgl_fd, bo_sprd->name); - cache_state.data.isDirtied = DEVICE_NONE; - cache_state.data.isCached = 0; - cache_state.data.cntFlush = 0; + if (import == 0) { + cache_state.data.isDirtied = DEVICE_NONE; + cache_state.data.isCached = 0; + cache_state.data.cntFlush = 0; - _tgl_set_data(bufmgr_sprd->tgl_fd, bo_sprd->name, cache_state.val); + _tgl_set_data(bufmgr_sprd->tgl_fd, bo_sprd->name, cache_state.val); + } +#endif return 1; } static int -_bo_set_cache_state(tbm_bo bo, int device, int opt) +_bo_set_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int device, int opt) { - tbm_bo_sprd bo_sprd; - tbm_bufmgr_sprd bufmgr_sprd; +#ifdef USE_CACHE + 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; - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); - 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); + if (bufmgr_sprd->use_dma_fence) + return 1; if (bo_sprd->flags_sprd & SPRD_BO_NONCACHABLE) return 1; @@ -595,7 +594,7 @@ _bo_set_cache_state(tbm_bo bo, int device, int opt) _tgl_set_data(bufmgr_sprd->tgl_fd, GLOBAL_KEY, (unsigned int)(++cntFlush)); /* call cache flush */ - _sprd_bo_cache_flush (bo, 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(), @@ -604,46 +603,97 @@ _bo_set_cache_state(tbm_bo bo, int device, int opt) need_flush, cntFlush); } +#endif return 1; } static int -_bo_save_cache_state(tbm_bo bo) +_bo_save_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) { - unsigned short cntFlush = 0; - tbm_bo_sprd bo_sprd; - tbm_bufmgr_sprd bufmgr_sprd; - - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); +#ifdef USE_CACHE 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); + if (bufmgr_sprd->use_dma_fence) + return 1; + + unsigned short cntFlush = 0; + /* get global cache flush count */ cntFlush = (unsigned short)_tgl_get_data(bufmgr_sprd->tgl_fd, GLOBAL_KEY, NULL); /* save global cache flush count */ bo_sprd->cache_state.data.cntFlush = cntFlush; _tgl_set_data(bufmgr_sprd->tgl_fd, bo_sprd->name, bo_sprd->cache_state.val); +#endif return 1; } static void -_bo_destroy_cache_state(tbm_bo bo) +_bo_destroy_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) { - tbm_bo_sprd bo_sprd; - tbm_bufmgr_sprd bufmgr_sprd; - - bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); +#ifdef USE_CACHE SPRD_RETURN_IF_FAIL (bo_sprd != NULL); - - bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); SPRD_RETURN_IF_FAIL (bufmgr_sprd != NULL); + if (bufmgr_sprd->use_dma_fence) + return; + _tgl_destroy(bufmgr_sprd->tgl_fd, bo_sprd->name); +#endif +} + +static int +_bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) +{ +#ifdef USE_CACHE + SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); + + if (bufmgr_sprd->use_dma_fence) + return 1; + + /* 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); + + close(bufmgr_sprd->tgl_fd); + return 0; + } + } + + if (!_tgl_init(bufmgr_sprd->tgl_fd, GLOBAL_KEY)) { + TBM_SPRD_LOG("[libtbm-sprd:%d] " + "error: Fail to initialize the tgl\n", + getpid()); + + close(bufmgr_sprd->tgl_fd); + return 0; + } +#endif + + return 1; +} + +static void +_bufmgr_deinit_cache_state(tbm_bufmgr_sprd bufmgr_sprd) +{ +#ifdef USE_CACHE + SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); + + if (bufmgr_sprd->use_dma_fence) + return; + + if (bufmgr_sprd->tgl_fd >= 0) + close(bufmgr_sprd->tgl_fd); +#endif } #ifndef USE_CONTIG_ONLY @@ -850,7 +900,7 @@ tbm_sprd_bo_alloc (tbm_bo bo, int size, int 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)) { + 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); return 0; @@ -941,7 +991,7 @@ tbm_sprd_bo_free(tbm_bo bo) getpid(), __FUNCTION__, __LINE__, bo_sprd->name, ret); } - _bo_destroy_cache_state(bo); + _bo_destroy_cache_state(bufmgr_sprd, bo_sprd); /* Free gem handle */ struct drm_gem_close arg = {0, }; @@ -972,7 +1022,6 @@ tbm_sprd_bo_import (tbm_bo bo, unsigned int key) ret = drmHashLookup (bufmgr_sprd->hashBos, key, (void **)&privGem); if (ret == 0) { - privGem->ref_count++; return privGem->bo_priv; } @@ -1018,8 +1067,8 @@ tbm_sprd_bo_import (tbm_bo bo, unsigned int key) bo_sprd->flags_tbm = _get_tbm_flag_from_sprd (bo_sprd->flags_sprd); #endif - if (!_tgl_init(bufmgr_sprd->tgl_fd, bo_sprd->name)) { - TBM_SPRD_LOG ("error fail tgl init(%d)\n", bo_sprd->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; } @@ -1088,7 +1137,6 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) ret = drmHashLookup (bufmgr_sprd->hashBos, name, (void **)&privGem); if (ret == 0) { if (gem == privGem->bo_priv->gem) { - privGem->ref_count++; return privGem->bo_priv; } } @@ -1136,8 +1184,8 @@ tbm_sprd_bo_import_fd (tbm_bo bo, tbm_fd key) return 0; } - if (!_tgl_init(bufmgr_sprd->tgl_fd, bo_sprd->name)) { - TBM_SPRD_LOG ("error fail tgl init(%d)\n", bo_sprd->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; } @@ -1275,6 +1323,10 @@ tbm_sprd_bo_map (tbm_bo bo, int device, int opt) 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); bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, (tbm_bo_handle) NULL); @@ -1299,7 +1351,7 @@ tbm_sprd_bo_map (tbm_bo bo, int device, int opt) } if (bo_sprd->map_cnt == 0) - _bo_set_cache_state (bo, device, opt); + _bo_set_cache_state (bufmgr_sprd, bo_sprd, device, opt); bo_sprd->map_cnt++; @@ -1312,6 +1364,10 @@ 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; + + bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); + 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); @@ -1322,7 +1378,7 @@ tbm_sprd_bo_unmap (tbm_bo bo) bo_sprd->map_cnt--; if (bo_sprd->map_cnt == 0) - _bo_save_cache_state (bo); + _bo_save_cache_state (bufmgr_sprd, bo_sprd); DBG ("[libtbm-sprd:%d] %s gem:%d(%d) \n", getpid(), __FUNCTION__, bo_sprd->gem, bo_sprd->name); @@ -1525,7 +1581,8 @@ tbm_sprd_bufmgr_deinit (void *priv) if (bufmgr_sprd->device_name) free(bufmgr_sprd->device_name); - close (bufmgr_sprd->tgl_fd); + _bufmgr_deinit_cache_state(bufmgr_sprd); + close (bufmgr_sprd->fd); free (bufmgr_sprd); @@ -1870,7 +1927,7 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) bufmgr_sprd->fd = _tbm_sprd_open_drm(); else bufmgr_sprd->fd = master_fd; - + if (bufmgr_sprd->fd < 0) { TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); free (bufmgr_sprd); @@ -1897,34 +1954,6 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) } } - /* 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:%d] " - "error: Fail to open global_lock:%s\n", - getpid(), tgl_devfile); - - close(bufmgr_sprd->fd); - free (bufmgr_sprd); - return 0; - } - } - - if (!_tgl_init(bufmgr_sprd->tgl_fd, GLOBAL_KEY)) { - TBM_SPRD_LOG("[libtbm:%d] " - "error: Fail to initialize the tgl\n", - getpid()); - - close(bufmgr_sprd->fd); - close(bufmgr_sprd->tgl_fd); - - free (bufmgr_sprd); - return 0; - } - //Create Hash Table bufmgr_sprd->hashBos = drmHashCreate (); @@ -1941,12 +1970,24 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) close(fp); } + if (!_bufmgr_init_cache_state(bufmgr_sprd)) { + TBM_SPRD_LOG ("[libtbm-sprd:%d] error: init bufmgr cache state failed!\n", getpid()); + + tbm_drm_helper_unset_tbm_master_fd(); + close(bufmgr_sprd->fd); + + free(bufmgr_sprd); + return 0; + } + 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); + + tbm_drm_helper_unset_tbm_master_fd(); close(bufmgr_sprd->fd); - close(bufmgr_sprd->tgl_fd); free (bufmgr_sprd); return 0; @@ -1975,7 +2016,9 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to init backend!\n", getpid()); tbm_backend_free (bufmgr_backend); - close(bufmgr_sprd->tgl_fd); + _bufmgr_deinit_cache_state(bufmgr_sprd); + + tbm_drm_helper_unset_tbm_master_fd(); close(bufmgr_sprd->fd); free (bufmgr_sprd); -- 2.7.4 From 176169d4928c04514758558de49473d858ea9107 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Wed, 30 Mar 2016 20:47:38 +0900 Subject: [PATCH 03/16] use tgl lock if don't support dma fence Change-Id: Ia8cd5f7d666418cf3902fad9b8df7b7637051ddf --- src/tbm_bufmgr_sprd.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index aa93b82..428658a 100755 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -258,7 +258,7 @@ uint32_t tbm_sprd_color_format_list[TBM_COLOR_FORMAT_COUNT] = { TBM_FORMAT_RGBA8 TBM_FORMAT_YUV420, TBM_FORMAT_YVU420 }; -#ifdef USE_CACHE + static inline int _tgl_init(int fd, unsigned int key) { @@ -326,6 +326,7 @@ _tgl_unlock(int fd, unsigned int key) return 1; } +#ifdef USE_CACHE static inline int _tgl_set_data(int fd, unsigned int key, unsigned int val) { @@ -459,10 +460,10 @@ _tbm_sprd_open_drm() return fd; } +#ifdef USE_CACHE static int _sprd_bo_cache_flush (tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags) { -#ifdef USE_CACHE SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); @@ -510,25 +511,25 @@ _sprd_bo_cache_flush (tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flag getpid(), __FUNCTION__, __LINE__); return 0; } -#endif return 1; } +#endif 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_bo_cache_state cache_state; - if (bufmgr_sprd->use_dma_fence) return 1; _tgl_init(bufmgr_sprd->tgl_fd, bo_sprd->name); +#ifdef USE_CACHE + tbm_bo_cache_state cache_state; + if (import == 0) { cache_state.data.isDirtied = DEVICE_NONE; cache_state.data.isCached = 0; @@ -634,7 +635,6 @@ _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) { -#ifdef USE_CACHE SPRD_RETURN_IF_FAIL (bo_sprd != NULL); SPRD_RETURN_IF_FAIL (bufmgr_sprd != NULL); @@ -642,13 +642,11 @@ _bo_destroy_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd) return; _tgl_destroy(bufmgr_sprd->tgl_fd, bo_sprd->name); -#endif } static int _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) { -#ifdef USE_CACHE SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) @@ -669,6 +667,7 @@ _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) } } +#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", @@ -685,7 +684,6 @@ _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) static void _bufmgr_deinit_cache_state(tbm_bufmgr_sprd bufmgr_sprd) { -#ifdef USE_CACHE SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL); if (bufmgr_sprd->use_dma_fence) @@ -693,7 +691,6 @@ _bufmgr_deinit_cache_state(tbm_bufmgr_sprd bufmgr_sprd) if (bufmgr_sprd->tgl_fd >= 0) close(bufmgr_sprd->tgl_fd); -#endif } #ifndef USE_CONTIG_ONLY @@ -1391,7 +1388,6 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) { SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); -#if USE_BACKEND_LOCK tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; int ret = 0; @@ -1403,6 +1399,7 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) { +#if USE_BACKEND_LOCK struct dma_buf_fence fence; memset(&fence, 0, sizeof(struct dma_buf_fence)); @@ -1472,6 +1469,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); DBG ("[libtbm-sprd:%d] lock tgl flink_id:%d\n", @@ -1479,8 +1477,8 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) return ret; } - #endif + return 1; } @@ -1489,7 +1487,6 @@ tbm_sprd_bo_unlock(tbm_bo bo) { SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0); -#if USE_BACKEND_LOCK tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; int ret = 0; @@ -1501,6 +1498,7 @@ tbm_sprd_bo_unlock(tbm_bo bo) SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); if (bufmgr_sprd->use_dma_fence) { +#if USE_BACKEND_LOCK struct dma_buf_fence fence; if (!bo_sprd->dma_fence[0].ctx) { @@ -1547,6 +1545,7 @@ tbm_sprd_bo_unlock(tbm_bo bo) return ret; } #endif + return 1; } -- 2.7.4 From 53ba714efdd39f18b0db84b22eb6d53371cd2d47 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Mon, 11 Apr 2016 14:32:05 +0900 Subject: [PATCH 04/16] only display server unset tbm master fd if tbm_bufmgr_init fail Change-Id: I1662647f30e0e341f871ab0f9eb8ae28e05048ab --- src/tbm_bufmgr_sprd.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c index 428658a..bd5be03 100755 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -1390,7 +1390,6 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; - int ret = 0; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); @@ -1398,8 +1397,11 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt) bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); - if (bufmgr_sprd->use_dma_fence) { #if USE_BACKEND_LOCK + int ret = 0; + + if (bufmgr_sprd->use_dma_fence) { + struct dma_buf_fence fence; memset(&fence, 0, sizeof(struct dma_buf_fence)); @@ -1489,7 +1491,6 @@ tbm_sprd_bo_unlock(tbm_bo bo) tbm_bufmgr_sprd bufmgr_sprd; tbm_bo_sprd bo_sprd; - int ret = 0; bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo); SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0); @@ -1497,8 +1498,10 @@ tbm_sprd_bo_unlock(tbm_bo bo) bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo); SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0); - if (bufmgr_sprd->use_dma_fence) { #if USE_BACKEND_LOCK + int ret = 0; + + if (bufmgr_sprd->use_dma_fence) { struct dma_buf_fence fence; if (!bo_sprd->dma_fence[0].ctx) { @@ -1918,14 +1921,11 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) } if (tbm_backend_is_display_server()) { - int master_fd = -1; - bufmgr_sprd->fd = -1; - master_fd = tbm_drm_helper_get_master_fd(); - if (master_fd < 0) + + bufmgr_sprd->fd = tbm_drm_helper_get_master_fd(); + if (bufmgr_sprd->fd < 0) bufmgr_sprd->fd = _tbm_sprd_open_drm(); - else - bufmgr_sprd->fd = master_fd; if (bufmgr_sprd->fd < 0) { TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid()); @@ -1940,6 +1940,7 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int 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; @@ -1972,7 +1973,9 @@ 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_drm_helper_unset_tbm_master_fd(); + if (tbm_backend_is_display_server()) + tbm_drm_helper_unset_tbm_master_fd(); + close(bufmgr_sprd->fd); free(bufmgr_sprd); @@ -1985,7 +1988,9 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) _bufmgr_deinit_cache_state(bufmgr_sprd); - tbm_drm_helper_unset_tbm_master_fd(); + if (tbm_backend_is_display_server()) + tbm_drm_helper_unset_tbm_master_fd(); + close(bufmgr_sprd->fd); free (bufmgr_sprd); @@ -2017,7 +2022,9 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) _bufmgr_deinit_cache_state(bufmgr_sprd); - tbm_drm_helper_unset_tbm_master_fd(); + if (tbm_backend_is_display_server()) + tbm_drm_helper_unset_tbm_master_fd(); + close(bufmgr_sprd->fd); free (bufmgr_sprd); -- 2.7.4 From c0c842a70be9b8a5d6b856887e703626fcc3f0fe Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Mon, 18 Apr 2016 16:07:23 +0900 Subject: [PATCH 05/16] fix handle leak error Change-Id: I788f0ee9a34d45e186f066ecb16e5c0222a32a05 Signed-off-by: Junkyeong Kim --- src/tbm_bufmgr_sprd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) mode change 100755 => 100644 src/tbm_bufmgr_sprd.c diff --git a/src/tbm_bufmgr_sprd.c b/src/tbm_bufmgr_sprd.c old mode 100755 new mode 100644 index bd5be03..abea509 --- a/src/tbm_bufmgr_sprd.c +++ b/src/tbm_bufmgr_sprd.c @@ -388,7 +388,6 @@ _tbm_sprd_open_drm() struct udev_device *device = NULL, *drm_device = NULL, *device_parent = NULL; const char *filepath; struct stat s; - int fd = -1; int ret; TBM_SPRD_LOG ("[libtbm-sprd:%d] " @@ -447,6 +446,7 @@ _tbm_sprd_open_drm() 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; @@ -661,8 +661,6 @@ _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd) TBM_SPRD_LOG("[libtbm-sprd:%d] " "error: Fail to open global_lock:%s\n", getpid(), tgl_devfile); - - close(bufmgr_sprd->tgl_fd); return 0; } } -- 2.7.4 From a0698ea7569f40f40e75bebf5c799409ea583d0a Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Wed, 18 May 2016 15:45:52 +0900 Subject: [PATCH 06/16] Add udev rules file for slp_global_lock node Change-Id: I436a69d98ef76ea07273668bdc48d33d5bf25d08 --- packaging/libtbm-sprd.spec | 3 +++ rules/99-libtbm_sprd.rules | 1 + 2 files changed, 4 insertions(+) create mode 100644 rules/99-libtbm_sprd.rules diff --git a/packaging/libtbm-sprd.spec b/packaging/libtbm-sprd.spec index 9bcb46a..7cb2649 100644 --- a/packaging/libtbm-sprd.spec +++ b/packaging/libtbm-sprd.spec @@ -37,6 +37,8 @@ make %{?_smp_mflags} rm -rf %{buildroot} mkdir -p %{buildroot}/%{TZ_SYS_RO_SHARE}/license cp -af COPYING %{buildroot}/%{TZ_SYS_RO_SHARE}/license/%{name} +mkdir -p %{buildroot}%{_libdir}/udev/rules.d/ +cp -af rules/99-libtbm_sprd.rules %{buildroot}%{_libdir}/udev/rules.d/ %make_install @@ -52,4 +54,5 @@ ln -s libtbm_sprd.so %{_libdir}/bufmgr/libtbm_default.so %defattr(-,root,root,-) %{TZ_SYS_RO_SHARE}/license/%{name} %{_libdir}/bufmgr/libtbm_*.so* +%{_libdir}/udev/rules.d/99-libtbm_sprd.rules diff --git a/rules/99-libtbm_sprd.rules b/rules/99-libtbm_sprd.rules new file mode 100644 index 0000000..b00652e --- /dev/null +++ b/rules/99-libtbm_sprd.rules @@ -0,0 +1 @@ +KERNEL=="slp_global_lock*", MODE="0666", GROUP="display", SECLABEL{smack}="*" -- 2.7.4 From 58bb03ff0a8a5dd60826c1452897f6e7c70512bb Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Wed, 29 Jun 2016 11:49:21 +0900 Subject: [PATCH 07/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 08/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 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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