diff options
-rwxr-xr-x | drm_slp/drm_slp_bufmgr.c | 9 | ||||
-rw-r--r-- | packaging/libtbm.spec | 4 | ||||
-rwxr-xr-x | src/tbm_bufmgr.c | 356 | ||||
-rwxr-xr-x | src/tbm_bufmgr.h | 20 | ||||
-rwxr-xr-x | src/tbm_bufmgr_backend.c | 22 | ||||
-rwxr-xr-x | src/tbm_bufmgr_backend.h | 11 | ||||
-rwxr-xr-x | src/tbm_bufmgr_int.h | 2 | ||||
-rw-r--r-- | src/tbm_bufmgr_tgl.h (renamed from src/tbm_bufmgr_glock.h) | 7 |
8 files changed, 247 insertions, 184 deletions
diff --git a/drm_slp/drm_slp_bufmgr.c b/drm_slp/drm_slp_bufmgr.c index 82e5c1b..c24b430 100755 --- a/drm_slp/drm_slp_bufmgr.c +++ b/drm_slp/drm_slp_bufmgr.c @@ -35,6 +35,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <stdlib.h> #include "drm_slp_bufmgr.h" #include "tbm_bufmgr.h" +#include "tbm_bufmgr_int.h" drm_slp_bufmgr drm_slp_bufmgr_init(int fd, void *arg) @@ -44,7 +45,7 @@ drm_slp_bufmgr_init(int fd, void *arg) bufmgr = tbm_bufmgr_init (fd); if (!bufmgr) { - fprintf (stderr, "[libdrm_slp:%d]: error bufmgr is null\n", getpid()); + TBM_LOG ("[libdrm_slp:%d]: error bufmgr is null\n", getpid()); return NULL; } @@ -71,7 +72,7 @@ drm_slp_bo_import(drm_slp_bufmgr bufmgr, unsigned int key) bo = tbm_bo_import ((tbm_bufmgr)bufmgr, key); if (!bo) { - fprintf (stderr, "[libdrm_slp:%d]: error bo is null\n", getpid()); + TBM_LOG ("[libdrm_slp:%d]: error bo is null\n", getpid()); return NULL; } @@ -87,7 +88,7 @@ drm_slp_bo_map(drm_slp_bo bo, int device, int opt) bo_handle = tbm_bo_map ((tbm_bo)bo, device, opt); if (bo_handle.ptr == NULL) { - fprintf (stderr, "[libdrm_slp:%d]: error bo_handle is null\n", getpid()); + TBM_LOG ("[libdrm_slp:%d]: error bo_handle is null\n", getpid()); return 0; } @@ -103,7 +104,7 @@ drm_slp_bo_map(drm_slp_bo bo, int device, int opt) ret = (unsigned long)bo_handle.ptr; break; default: - fprintf (stderr, "[libdrm_slp:%d]: error wrong device type\n", getpid()); + TBM_LOG ("[libdrm_slp:%d]: error wrong device type\n", getpid()); return 0; } diff --git a/packaging/libtbm.spec b/packaging/libtbm.spec index 5302194..0c8dbc6 100644 --- a/packaging/libtbm.spec +++ b/packaging/libtbm.spec @@ -1,6 +1,6 @@ Name: libtbm -Version: 1.0.5 -Release: 2 +Version: 1.0.6 +Release: 4 License: MIT Summary: Tizen Buffer Manager Library Group: System/Libraries diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index e9fe5a8..417ef11 100755 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -44,7 +44,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <errno.h> #include <pthread.h> #include "tbm_bufmgr.h" -#include "tbm_bufmgr_glock.h" +#include "tbm_bufmgr_tgl.h" #include "tbm_bufmgr_backend.h" #include "tbm_bufmgr_int.h" #include "list.h" @@ -52,8 +52,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define DEBUG #ifdef DEBUG static int bDebug = 0; -#define DBG(...) if(bDebug&0x1) fprintf(stderr, __VA_ARGS__) -#define DBG_LOCK(...) if(bDebug&0x2) fprintf(stderr, __VA_ARGS__) +#define DBG(...) if(bDebug&0x1) TBM_LOG (__VA_ARGS__) +#define DBG_LOCK(...) if(bDebug&0x2) TBM_LOG (__VA_ARGS__) #else #define DBG(...) #define DBG_LOCK(...) @@ -62,13 +62,13 @@ static int bDebug = 0; /* check condition */ #define TBM_RETURN_IF_FAIL(cond) {\ if (!(cond)) {\ - fprintf (stderr, "[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ return;\ }\ } #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\ if (!(cond)) {\ - fprintf (stderr, "[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ return val;\ }\ } @@ -95,8 +95,13 @@ static int bDebug = 0; bo->item_link.next && \ bo->item_link.next->prev == &bo->item_link) -#define CTRL_BACKEND_VALID(flags) ((flags&TBM_CACHE_CTRL_BACKEND) && \ - (flags&TBM_LOCK_CTRL_BACKEND)) +#define TBM_ALL_CTRL_BACKEND_VALID(flags) \ + ((flags&TBM_CACHE_CTRL_BACKEND) &&\ + (flags&TBM_LOCK_CTRL_BACKEND)) +#define TBM_CACHE_CTRL_BACKEND_VALID(flags) \ + (flags&TBM_CACHE_CTRL_BACKEND) +#define TBM_LOCK_CTRL_BACKEND_VALID(flags) \ + (flags&TBM_LOCK_CTRL_BACKEND) #define PREFIX_LIB "libtbm_" #define SUFFIX_LIB ".so" @@ -121,9 +126,9 @@ static int bDebug = 0; #define MODULE_VERSION_NUMERIC(maj, min, patch) \ ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF)) -#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF) -#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF) -#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF) +#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF) +#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF) +#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF) enum { LOCK_TRY_ONCE, @@ -163,7 +168,7 @@ _tgl_init (int fd, unsigned int key) err = ioctl (fd, TGL_IOC_INIT_LOCK, &attr); if (err) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ( "[libtbm:%d] " "error(%s) %s:%d key:%d\n", getpid(), strerror(errno), __FUNCTION__, __LINE__, key); return 0; @@ -179,7 +184,7 @@ _tgl_destroy (int fd, unsigned int key) err = ioctl (fd, TGL_IOC_DESTROY_LOCK, key); if (err) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ( "[libtbm:%d] " "error(%s) %s:%d key:%d\n", getpid(), strerror(errno), __FUNCTION__, __LINE__, key); return 0; @@ -195,7 +200,7 @@ _tgl_lock (int fd, unsigned int key) err = ioctl (fd, TGL_IOC_LOCK_LOCK, key); if (err) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error(%s) %s:%d key:%d\n", getpid(), strerror(errno), __FUNCTION__, __LINE__, key); return 0; @@ -211,7 +216,7 @@ _tgl_unlock (int fd, unsigned int key) err = ioctl (fd, TGL_IOC_UNLOCK_LOCK, key); if (err) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error(%s) %s:%d key:%d\n", getpid(), strerror(errno), __FUNCTION__, __LINE__, key); return 0; @@ -231,7 +236,7 @@ _tgl_set_data (int fd, unsigned int key, unsigned int val) err = ioctl (fd, TGL_IOC_SET_DATA, &arg); if (err) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error(%s) %s:%d key:%d\n", getpid(), strerror(errno), __FUNCTION__, __LINE__, key); return 0; @@ -250,7 +255,7 @@ _tgl_get_data (int fd, unsigned int key, unsigned int *locked) err = ioctl (fd, TGL_IOC_GET_DATA, &arg); if (err) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error(%s) %s:%d key:%d\n", getpid(), strerror(errno), __FUNCTION__, __LINE__, key); return 0; @@ -311,16 +316,27 @@ _user_data_delete (tbm_user_data *user_data) } static int -_bo_lock (tbm_bo bo) +_bo_lock (tbm_bo bo, int device, int opt) { tbm_bufmgr bufmgr = bo->bufmgr; int ret = 0; - if (bufmgr->backend->flags&TBM_LOCK_CTRL_BACKEND && - bufmgr->backend->bo_lock) + if (TBM_LOCK_CTRL_BACKEND_VALID(bufmgr->backend->flags)) { - /* use backend lock */ - ret = bufmgr->backend->bo_lock (bo); + if (bufmgr->backend->bo_lock2) + { + /* use bo_lock2 backend lock */ + ret = bufmgr->backend->bo_lock2 (bo, device, opt); + } + else if (bufmgr->backend->bo_lock) + { + /* use bo_lock backend lock */ + ret = bufmgr->backend->bo_lock (bo); + } + else + TBM_LOG ("[libtbm:%d] " + "error %s:%d no backend lock functions\n", + getpid(), __FUNCTION__, __LINE__); } else { @@ -336,11 +352,17 @@ _bo_unlock (tbm_bo bo) { tbm_bufmgr bufmgr = bo->bufmgr; - if (bufmgr->backend->flags&TBM_LOCK_CTRL_BACKEND && - bufmgr->backend->bo_unlock) + if (TBM_LOCK_CTRL_BACKEND_VALID(bufmgr->backend->flags)) { - /* use backend unlock */ - bufmgr->backend->bo_unlock (bo); + if (bufmgr->backend->bo_unlock) + { + /* use backend unlock */ + bufmgr->backend->bo_unlock (bo); + } + else + TBM_LOG ("[libtbm:%d] " + "error %s:%d no backend unlock functions\n", + getpid(), __FUNCTION__, __LINE__); } else { @@ -350,89 +372,52 @@ _bo_unlock (tbm_bo bo) } static int -_tbm_bo_lock (tbm_bo bo) +_tbm_bo_init_state (tbm_bo bo, int opt) { - tbm_bufmgr bufmgr = NULL; - int old; - int ret = 0; + tbm_bufmgr bufmgr = bo->bufmgr; + tbm_bo_cache_state cache_state; - if (!bo) - return 0; + RETURN_VAL_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); - bufmgr = bo->bufmgr; + cache_state.val = 0; + switch (opt) + { + case CACHE_OP_CREATE: /*Create*/ + if (bo->tgl_key == INITIAL_KEY) + bo->tgl_key = bufmgr->backend->bo_get_global_key (bo); - RETURN_VAL_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); + _tgl_init (bufmgr->lock_fd, bo->tgl_key); - if (bo->lock_cnt < 0) - { - fprintf (stderr, "[libtbm:%d] " - "error %s:%d bo:%p(%d) LOCK_CNT=%d\n", - getpid(), __FUNCTION__, __LINE__, bo, bo->tgl_key, bo->lock_cnt); - } + cache_state.data.isCacheable = BO_IS_CACHEABLE(bo); + cache_state.data.isDirtied = DEVICE_NONE; + cache_state.data.isCached = 0; + cache_state.data.cntFlush = 0; - old = bo->lock_cnt; - switch (bufmgr->lock_type) - { - case LOCK_TRY_ALWAYS: /* LOCK_TRY_ALWAYS */ - pthread_mutex_unlock (&bufmgr->lock); - ret = _bo_lock (bo); - pthread_mutex_lock (&bufmgr->lock); - if(ret) - bo->lock_cnt++; - break; - case LOCK_TRY_NEVER: /* LOCK_TRY_NEVER */ - return 1; - break; - default: - if (bo->lock_cnt == 0) - { - pthread_mutex_unlock (&bufmgr->lock); - ret = _bo_lock (bo); - pthread_mutex_lock (&bufmgr->lock); - if (ret) - bo->lock_cnt++; - } + _tgl_set_data (bufmgr->lock_fd, bo->tgl_key, cache_state.val); + break; + case CACHE_OP_IMPORT: /*Import*/ + if (bo->tgl_key == INITIAL_KEY) + bo->tgl_key = bufmgr->backend->bo_get_global_key (bo); - break; + _tgl_init (bufmgr->lock_fd, bo->tgl_key); + break; + default: + break; } - DBG_LOCK ("[libtbm:%d] >> LOCK bo:%p(%d, %d->%d)\n", getpid(), - bo, bo->tgl_key, old, bo->lock_cnt); - return 1; } static void -_tbm_bo_unlock (tbm_bo bo) +_tbm_bo_destroy_state (tbm_bo bo) { - tbm_bufmgr bufmgr = NULL; - - int old; - - if (!bo) - return; - - bufmgr = bo->bufmgr; - - RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags)); + tbm_bufmgr bufmgr = bo->bufmgr; - old = bo->lock_cnt; - if (bo->lock_cnt > 0) - { - bo->lock_cnt--; - if (bo->lock_cnt == 0) - _bo_unlock (bo); - } - else if (bo->lock_cnt < 0) - { - bo->lock_cnt = 0; - } + RETURN_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags)); - DBG_LOCK ("[libtbm:%d] << unlock bo:%p(%d, %d->%d)\n", getpid(), - bo, bo->tgl_key, old, bo->lock_cnt); + _tgl_destroy (bufmgr->lock_fd, bo->tgl_key); } - static int _tbm_bo_set_state (tbm_bo bo, int device, int opt) { @@ -441,7 +426,7 @@ _tbm_bo_set_state (tbm_bo bo, int device, int opt) unsigned short cntFlush = 0; unsigned int is_locked; - RETURN_VAL_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); + RETURN_VAL_CHECK_FLAG (TBM_CACHE_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); /* get cache state of a bo */ bo->cache_state.val = _tgl_get_data (bufmgr->lock_fd, bo->tgl_key, &is_locked); @@ -506,7 +491,7 @@ _tbm_bo_save_state (tbm_bo bo) tbm_bufmgr bufmgr = bo->bufmgr; unsigned short cntFlush = 0; - RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags)); + RETURN_CHECK_FLAG (TBM_CACHE_CTRL_BACKEND_VALID(bufmgr->backend->flags)); /* get global cache flush count */ cntFlush = (unsigned short)_tgl_get_data (bufmgr->lock_fd, GLOBAL_KEY, NULL); @@ -516,53 +501,108 @@ _tbm_bo_save_state (tbm_bo bo) _tgl_set_data(bufmgr->lock_fd, bo->tgl_key, bo->cache_state.val); } + static int -_tbm_bo_init_state (tbm_bo bo, int opt) +_tbm_bo_lock (tbm_bo bo, int device, int opt) { - tbm_bufmgr bufmgr = bo->bufmgr; - tbm_bo_cache_state cache_state; - - RETURN_VAL_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); + tbm_bufmgr bufmgr = NULL; + int old; + int ret = 0; - cache_state.val = 0; - switch (opt) - { - case CACHE_OP_CREATE: /*Create*/ - if (bo->tgl_key == INITIAL_KEY) - bo->tgl_key = bufmgr->backend->bo_get_global_key (bo); + if (!bo) + return 0; - _tgl_init (bufmgr->lock_fd, bo->tgl_key); + bufmgr = bo->bufmgr; - cache_state.data.isCacheable = BO_IS_CACHEABLE(bo); - cache_state.data.isDirtied = DEVICE_NONE; - cache_state.data.isCached = 0; - cache_state.data.cntFlush = 0; + /* do not try to lock the bo */ + if (bufmgr->lock_type == LOCK_TRY_NEVER) + return 1; - _tgl_set_data (bufmgr->lock_fd, bo->tgl_key, cache_state.val); - break; - case CACHE_OP_IMPORT: /*Import*/ - if (bo->tgl_key == INITIAL_KEY) - bo->tgl_key = bufmgr->backend->bo_get_global_key (bo); + if (bo->lock_cnt < 0) + { + TBM_LOG ("[libtbm:%d] " + "error %s:%d bo:%p(%d) LOCK_CNT=%d\n", + getpid(), __FUNCTION__, __LINE__, bo, bo->tgl_key, bo->lock_cnt); + } - _tgl_init (bufmgr->lock_fd, bo->tgl_key); - break; - default: - break; + old = bo->lock_cnt; + if (bufmgr->lock_type == LOCK_TRY_ONCE) + { + if (bo->lock_cnt == 0) + { + pthread_mutex_unlock (&bufmgr->lock); + ret = _bo_lock (bo, device, opt); + pthread_mutex_lock (&bufmgr->lock); + if (ret) + bo->lock_cnt++; + } + } + else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) + { + pthread_mutex_unlock (&bufmgr->lock); + ret = _bo_lock (bo, device, opt); + pthread_mutex_lock (&bufmgr->lock); + if(ret) + bo->lock_cnt++; } + else + TBM_LOG ("[libtbm:%d] " + "error %s:%d bo:%p lock_type is wrong.\n", + getpid(), __FUNCTION__, __LINE__, bo); + + DBG_LOCK ("[libtbm:%d] >> LOCK bo:%p(%d, %d->%d)\n", getpid(), + bo, bo->tgl_key, old, bo->lock_cnt); return 1; } static void -_tbm_bo_destroy_state (tbm_bo bo) +_tbm_bo_unlock (tbm_bo bo) { - tbm_bufmgr bufmgr = bo->bufmgr; + tbm_bufmgr bufmgr = NULL; - RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags)); + int old; - _tgl_destroy (bufmgr->lock_fd, bo->tgl_key); + if (!bo) + return; + + bufmgr = bo->bufmgr; + + /* do not try to unlock the bo */ + if (bufmgr->lock_type == LOCK_TRY_NEVER) + return; + + old = bo->lock_cnt; + if (bufmgr->lock_type == LOCK_TRY_ONCE) + { + if (bo->lock_cnt > 0) + { + bo->lock_cnt--; + if (bo->lock_cnt == 0) + _bo_unlock (bo); + } + } + else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) + { + if (bo->lock_cnt > 0) + { + bo->lock_cnt--; + _bo_unlock (bo); + } + } + else + TBM_LOG ("[libtbm:%d] " + "error %s:%d bo:%p lock_type is wrong.\n", + getpid(), __FUNCTION__, __LINE__, bo); + + if (bo->lock_cnt < 0) + bo->lock_cnt = 0; + + DBG_LOCK ("[libtbm:%d] << unlock bo:%p(%d, %d->%d)\n", getpid(), + bo, bo->tgl_key, old, bo->lock_cnt); } + static void _tbm_bo_ref (tbm_bo bo) { @@ -593,7 +633,7 @@ _tbm_bo_unref (tbm_bo bo) if (bo->lock_cnt > 0) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error %s:%d lock_cnt:%d\n", getpid(), __FUNCTION__, __LINE__, bo->lock_cnt); _bo_unlock (bo); @@ -616,21 +656,26 @@ _tbm_bo_unref (tbm_bo bo) static int _tbm_bufmgr_init_state (tbm_bufmgr bufmgr) { - RETURN_VAL_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); + RETURN_VAL_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); - bufmgr->lock_fd = open(tgl_devfile, O_RDWR); + bufmgr->lock_fd = open (tgl_devfile, O_RDWR); if(bufmgr->lock_fd < 0) { - fprintf (stderr, "[libtbm:%d] " - "error: Fail to open global_lock:%s\n", - getpid(), tgl_devfile); - return 0; + bufmgr->lock_fd = open (tgl_devfile1, O_RDWR); + if(bufmgr->lock_fd < 0) + { + + TBM_LOG ("[libtbm:%d] " + "error: Fail to open global_lock:%s\n", + getpid(), tgl_devfile); + return 0; + } } if (!_tgl_init(bufmgr->lock_fd, GLOBAL_KEY)) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error: Fail to initialize the tgl\n", getpid()); return 0; @@ -642,7 +687,7 @@ _tbm_bufmgr_init_state (tbm_bufmgr bufmgr) static void _tbm_bufmgr_destroy_state (tbm_bufmgr bufmgr) { - RETURN_CHECK_FLAG (CTRL_BACKEND_VALID(bufmgr->backend->flags)); + RETURN_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags)); close (bufmgr->lock_fd); } @@ -656,7 +701,7 @@ _check_version (TBMModuleVersionInfo *data) abimaj = GET_ABI_MAJOR (data->abiversion); abimin = GET_ABI_MINOR (data->abiversion); - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "TBM module %s: vendor=\"%s\" ABI=%d,%d\n", getpid(), data->modname ? data->modname : "UNKNOWN!", data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin); @@ -668,14 +713,14 @@ _check_version (TBMModuleVersionInfo *data) if (abimaj != vermaj) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n", getpid(), abimaj, vermaj); return 0; } else if (abimin > vermin) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n", getpid(), abimin, vermin); return 0; @@ -695,7 +740,7 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file) module_data = dlopen (path, RTLD_LAZY); if (!module_data) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "failed to load module: %s(%s)\n", getpid(), dlerror(), file); return 0; @@ -720,7 +765,7 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file) } else { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "Error: module does not supply version information.\n", getpid()); @@ -732,7 +777,7 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file) { if(!init (bufmgr, fd)) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "Fail to init module(%s)\n", getpid(), file); dlclose (module_data); @@ -741,7 +786,7 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file) } else { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "Error: module does not supply init symbol.\n", getpid()); dlclose (module_data); return 0; @@ -749,7 +794,7 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file) } else { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "Error: module does not have data object.\n", getpid()); dlclose (module_data); return 0; @@ -757,7 +802,7 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file) bufmgr->module_data = module_data; - fprintf (stderr,"[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "Success to load module(%s)\n", getpid(), file); return 1; @@ -778,7 +823,7 @@ static int _tbm_load_module (tbm_bufmgr bufmgr, int fd) { n = scandir (BUFMGR_MODULE_DIR, &namelist, 0, alphasort); if (n < 0) - fprintf (stderr,"[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "no files : %s\n", getpid(), BUFMGR_MODULE_DIR); else { @@ -812,7 +857,7 @@ tbm_bufmgr_init (int fd) if(env) { bDebug = atoi(env); - fprintf(stderr, "GEM_DEBUG=%s\n", env); + TBM_LOG ("GEM_DEBUG=%s\n", env); } else bDebug = 0; @@ -834,14 +879,14 @@ tbm_bufmgr_init (int fd) if(bufmgr->fd == fd) { bufmgr->ref_count++; - fprintf (stderr, "[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n", + TBM_LOG ("[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n", getpid(), fd, bufmgr->ref_count); return bufmgr; } } bufmgr = NULL; } - fprintf(stderr, "[libtbm:%d] bufmgr init: fd=%d\n", getpid(), fd); + TBM_LOG ("[libtbm:%d] bufmgr init: fd=%d\n", getpid(), fd); /* allocate bufmgr */ bufmgr = calloc (1, sizeof(struct _tbm_bufmgr)); @@ -851,7 +896,7 @@ tbm_bufmgr_init (int fd) /* load bufmgr priv from env */ if (!_tbm_load_module(bufmgr, fd)) { - fprintf (stderr,"[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error : Fail to load bufmgr backend\n", getpid()); free (bufmgr); @@ -862,7 +907,7 @@ tbm_bufmgr_init (int fd) bufmgr->ref_count = 1; bufmgr->fd = fd; - fprintf(stderr, "[libtbm:%d] create tizen bufmgr: ref_count:%d\n", + TBM_LOG ("[libtbm:%d] create tizen bufmgr: ref_count:%d\n", getpid(), bufmgr->ref_count); if (pthread_mutex_init (&bufmgr->lock, NULL) != 0) @@ -876,7 +921,7 @@ tbm_bufmgr_init (int fd) /* intialize the tizen global status */ if (!_tbm_bufmgr_init_state (bufmgr)) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error: Fail to init state\n", getpid()); bufmgr->backend->bufmgr_deinit (bufmgr); @@ -923,7 +968,7 @@ tbm_bufmgr_deinit (tbm_bufmgr bufmgr) bufmgr->ref_count--; if (bufmgr->ref_count > 0) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "tizen bufmgr destroy: bufmgr:%p, ref_cnt:%d\n", getpid(), bufmgr, bufmgr->ref_count); return; @@ -934,7 +979,7 @@ tbm_bufmgr_deinit (tbm_bufmgr bufmgr) { LIST_FOR_EACH_ENTRY_SAFE (bo, tmp, &bufmgr->bo_list, item_link) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "Un-freed bo(%p, ref:%d) \n", getpid(), bo, bo->ref_cnt); bo->ref_cnt = 1; @@ -953,7 +998,7 @@ tbm_bufmgr_deinit (tbm_bufmgr bufmgr) pthread_mutex_destroy (&bufmgr->lock); - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "tizen bufmgr destroy: bufmgr:%p, ref_cnt:%d\n", getpid(), bufmgr, bufmgr->ref_count); @@ -1148,11 +1193,9 @@ tbm_bo_map (tbm_bo bo, int device, int opt) pthread_mutex_lock (&bufmgr->lock); - _tbm_bo_lock (bo); bo_handle = bufmgr->backend->bo_map (bo, device, opt); - /* increase the ref_count */ -// _tbm_bo_ref (bo); + _tbm_bo_lock (bo, device, opt); if (bufmgr->use_map_cache == 1 && bo->map_cnt == 0) _tbm_bo_set_state (bo, device, opt); @@ -1177,6 +1220,8 @@ tbm_bo_unmap (tbm_bo bo) pthread_mutex_lock (&bufmgr->lock); + _tbm_bo_unlock (bo); + ret = bufmgr->backend->bo_unmap (bo); /* decrease the map_count */ @@ -1185,11 +1230,6 @@ tbm_bo_unmap (tbm_bo bo) if (bo->map_cnt == 0) _tbm_bo_save_state (bo); - _tbm_bo_unlock (bo); - - /* decrease the ref_count */ -// _tbm_bo_unref (bo); - pthread_mutex_unlock (&bufmgr->lock); return ret; @@ -1259,7 +1299,7 @@ tbm_bo_add_user_data (tbm_bo bo, unsigned long key, tbm_data_free data_free_func data = _user_data_lookup (&bo->user_data_list, key); if (data) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "waring: %s:%d user data already exist. key:%ld\n", getpid(), __FUNCTION__, __LINE__, key); return 0; diff --git a/src/tbm_bufmgr.h b/src/tbm_bufmgr.h index 07654f6..7bf2597 100755 --- a/src/tbm_bufmgr.h +++ b/src/tbm_bufmgr.h @@ -43,7 +43,7 @@ typedef struct _tbm_bo *tbm_bo; /* TBM_DEVICE_TYPE */ #define TBM_DEVICE_DEFAULT 0 /**< device type to get the default handle */ -#define TBM_DEVICE_CPU 1 /**< device type to get the virtual pointer */ +#define TBM_DEVICE_CPU 1 /**< device type to get the virtual memory */ #define TBM_DEVICE_2D 2 /**< device type to get the 2D memory handle */ #define TBM_DEVICE_3D 3 /**< device type to get the 3D memory handle */ #define TBM_DEVICE_MM 4 /**< device type to get the multimedia handle */ @@ -51,6 +51,7 @@ typedef struct _tbm_bo *tbm_bo; /* TBM_OPTION */ #define TBM_OPTION_READ (1 << 0) /**< access option to read */ #define TBM_OPTION_WRITE (1 << 1) /**< access option to write */ +#define TBM_OPTION_VENDOR (0xffff0000) /**< vendor specific option: it depends on the backend */ /** * @brief tbm_bo_handle @@ -70,12 +71,17 @@ typedef union _tbm_bo_handle */ enum TBM_BO_FLAGS { - TBM_BO_DEFAULT = 0, /**< physically non-contiguous memory */ - TBM_BO_SCANOUT = (1<<0), /**< physically contiguous memory */ - TBM_BO_NONCACHABLE = (1<<1), /**< non-cachable memory */ - TBM_BO_WC = (1<<2), /**< write-combine memory */ + TBM_BO_DEFAULT = 0, /**< default memory: it depends on the backend */ + TBM_BO_SCANOUT = (1<<0), /**< scanout memory */ + TBM_BO_NONCACHABLE = (1<<1), /**< non-cachable memory */ + TBM_BO_WC = (1<<2), /**< write-combine memory */ + TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */ }; +#ifdef __cplusplus +extern "C" { +#endif + /* Functions for buffer manager */ /** @@ -215,5 +221,9 @@ int tbm_bo_set_user_data (tbm_bo bo, unsigned long key, void* data); */ int tbm_bo_get_user_data (tbm_bo bo, unsigned long key, void** data); +#ifdef __cplusplus +} +#endif + #endif /* _TBM_BUFMGR_H_ */ diff --git a/src/tbm_bufmgr_backend.c b/src/tbm_bufmgr_backend.c index d6017b6..dd82402 100755 --- a/src/tbm_bufmgr_backend.c +++ b/src/tbm_bufmgr_backend.c @@ -65,7 +65,7 @@ tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend) if (!bufmgr) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error (%s): fail to init tbm backend... bufmgr is null\n", getpid(), __FUNCTION__); return 0; @@ -73,7 +73,7 @@ tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend) if (!backend) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error (%s): fail to init tbm backend... backend is null\n", getpid(), __FUNCTION__); return 0; @@ -85,7 +85,7 @@ tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend) { if (!backend->bo_cache_flush) { - fprintf (stderr, "[libtbm:%d] " + TBM_LOG ("[libtbm:%d] " "error (%s): TBM_FLAG_CACHE_CTRL_TBM needs backend->bo_cache_flush\n", getpid(), __FUNCTION__); return 0; @@ -93,18 +93,18 @@ tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend) } /* log for tbm flags */ - fprintf (stderr, "[libtbm:%d] ", getpid()); - fprintf (stderr, "cache_crtl:"); + TBM_LOG ("[libtbm:%d] ", getpid()); + TBM_LOG ("cache_crtl:"); if (flags&TBM_CACHE_CTRL_BACKEND) - fprintf (stderr, "BACKEND "); + TBM_LOG ("BACKEND "); else - fprintf (stderr, "TBM "); - fprintf (stderr, "lock_crtl:"); + TBM_LOG ("TBM "); + TBM_LOG ("lock_crtl:"); if (flags&TBM_LOCK_CTRL_BACKEND) - fprintf (stderr, "BACKEND "); + TBM_LOG ("BACKEND "); else - fprintf (stderr, "TBM "); - fprintf (stderr, "\n"); + TBM_LOG ("TBM "); + TBM_LOG ("\n"); bufmgr->backend = backend; diff --git a/src/tbm_bufmgr_backend.h b/src/tbm_bufmgr_backend.h index f1f5672..b0b3501 100755 --- a/src/tbm_bufmgr_backend.h +++ b/src/tbm_bufmgr_backend.h @@ -192,11 +192,20 @@ struct _tbm_bufmgr_backend */
int (*bo_unlock) (tbm_bo bo);
+ /**
+ * @brief lock the buffer object with a device and an opt.
+ * @param[in] bo : the buffer object
+ * @param[in] device : the device type to get a handle
+ * @param[in] option : the option to access the buffer object
+ * @return 1 if this function succeeds, otherwise 0.
+ * @remark This function pointer could be null. (default: use the tizen global lock)
+ */
+ int (*bo_lock2) (tbm_bo bo, int device, int opt);
+
/* Padding for future extension */
void (*reserved1) (void);
void (*reserved2) (void);
void (*reserved3) (void);
- void (*reserved4) (void);
};
/**
diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index a73b694..e13535a 100755 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -35,6 +35,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <pthread.h>
#include "tbm_bufmgr_backend.h"
+#define TBM_LOG(...) fprintf (stderr, __VA_ARGS__)
+
typedef union _tbm_bo_cache_state tbm_bo_cache_state;
struct list_head
diff --git a/src/tbm_bufmgr_glock.h b/src/tbm_bufmgr_tgl.h index cde87ef..10ec1a8 100644 --- a/src/tbm_bufmgr_glock.h +++ b/src/tbm_bufmgr_tgl.h @@ -8,12 +8,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __TBM_BUFMGR_GLOCK_H__ -#define __TBM_BUFMGR_GLOCK_H__ +#ifndef __TBM_BUFMGR_TGL_H__ +#define __TBM_BUFMGR_TGL_H__ #include <linux/ioctl.h> static char tgl_devfile[] = "/dev/slp_global_lock"; +static char tgl_devfile1[] = "/dev/tgl"; #define TGL_IOC_BASE 0x32 @@ -45,4 +46,4 @@ typedef enum { #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 *) -#endif /* __TBM_BUFMGR_GLOCK_H__ */ +#endif /* __TBM_BUFMGR_TGL_H__ */ |