-/* LCOV_EXCL_STOP */
-
-tbm_user_data
-*user_data_lookup(struct list_head *user_data_list, unsigned long key)
-{
- tbm_user_data *user_data = NULL;
- tbm_user_data *old_data = NULL, *tmp = NULL;
-
- if (!LIST_IS_EMPTY(user_data_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, user_data_list, item_link) {
- if (old_data->key == key) {
- user_data = old_data;
- return user_data;
- }
- }
- }
-
- return user_data;
-}
-
-tbm_user_data
-*user_data_create(unsigned long key, tbm_data_free data_free_func)
-{
- tbm_user_data *user_data = NULL;
-
- user_data = calloc(1, sizeof(tbm_user_data));
- if (!user_data)
- return NULL;
-
- user_data->key = key;
- user_data->free_func = data_free_func;
- user_data->data = (void *)0;
-
- return user_data;
-}
-
-void
-user_data_delete(tbm_user_data *user_data)
-{
- if (user_data->data && user_data->free_func)
- user_data->free_func(user_data->data);
-
- LIST_DEL(&user_data->item_link);
-
- free(user_data);
-}
-
-static int
-_bo_lock(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- int ret = 0;
-
- if (bufmgr->backend->bo_lock)
- ret = bufmgr->backend->bo_lock(bo, device, opt);
- else
- ret = 1;
-
- return ret;
-}
-
-static void
-_bo_unlock(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
-
- if (bufmgr->backend->bo_unlock)
- bufmgr->backend->bo_unlock(bo);
-}
-
-static int
-_tbm_bo_lock(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr = NULL;
- int old;
- int ret = 0;
-
- if (!bo)
- return 0;
-
- bufmgr = bo->bufmgr;
-
- /* do not try to lock the bo */
- if (bufmgr->lock_type == LOCK_TRY_NEVER)
- return 1;
-
- if (bo->lock_cnt < 0) {
- TBM_LOG_E("error bo:%p LOCK_CNT=%d\n",
- bo, bo->lock_cnt);
- }
-
- old = bo->lock_cnt;
- if (bufmgr->lock_type == LOCK_TRY_ONCE) {
- if (bo->lock_cnt == 0) {
- _tbm_bufmgr_mutex_unlock();
- ret = _bo_lock(bo, device, opt);
- _tbm_bufmgr_mutex_lock();
- if (ret)
- bo->lock_cnt++;
- } else
- ret = 1;
- } else if (bufmgr->lock_type == LOCK_TRY_ALWAYS) {
- _tbm_bufmgr_mutex_unlock();
- ret = _bo_lock(bo, device, opt);
- _tbm_bufmgr_mutex_lock();
- if (ret)
- bo->lock_cnt++;
- } else {
- TBM_LOG_E("error bo:%p lock_type is wrong.\n",
- bo);
- }
-
- DBG_LOCK(">> LOCK bo:%p(%d->%d)\n",
- bo, old, bo->lock_cnt);
-
- return ret;
-}
-
-static void
-_tbm_bo_unlock(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = NULL;
-
- int old;
-
- 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_E("error bo:%p lock_type is wrong.\n",
- bo);
- }
-
- if (bo->lock_cnt < 0)
- bo->lock_cnt = 0;
-
- DBG_LOCK(">> UNLOCK bo:%p(%d->%d)\n",
- bo, old, bo->lock_cnt);
-}
-
-static int
-_tbm_bo_is_valid(tbm_bo bo)
-{
- tbm_bo old_data = NULL, tmp = NULL;
-
- if (bo == NULL)
- return 0;
-
- if (gBufMgr == NULL) {
- TBM_LOG_E("error tbm_bufmgr was deinited\n");
- return 0;
- }
-
- if (!LIST_IS_EMPTY(&gBufMgr->bo_list)) {
- LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &gBufMgr->bo_list, item_link) {
- if (old_data == bo)
- return 1;
- }
-
- }
- return 0;
-}
-
-/* LCOV_EXCL_START */
-static int
-_check_version(TBMModuleVersionInfo *data)
-{
- int abimaj, abimin;
- int vermaj, vermin;
-
- abimaj = GET_ABI_MAJOR(data->abiversion);
- abimin = GET_ABI_MINOR(data->abiversion);
-
- DBG("TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
- data->modname ? data->modname : "UNKNOWN!",
- data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin);
-
- vermaj = GET_ABI_MAJOR(TBM_ABI_VERSION);
- vermin = GET_ABI_MINOR(TBM_ABI_VERSION);
-
- DBG("TBM ABI version %d.%d\n",
- vermaj, vermin);
-
- if (abimaj != vermaj) {
- TBM_LOG_E("TBM module ABI major ver(%d) doesn't match the TBM's ver(%d)\n",
- abimaj, vermaj);
- return 0;
- } else if (abimin > vermin) {
- TBM_LOG_E("TBM module ABI minor ver(%d) is newer than the TBM's ver(%d)\n",
- abimin, vermin);
- return 0;
- }
- return 1;
-}
-
-static int
-_tbm_bufmgr_load_module(tbm_bufmgr bufmgr, int fd, const char *file)
-{
- char path[PATH_MAX] = { 0, };
- TBMModuleData *initdata = NULL;
- void *module_data;
-
- snprintf(path, sizeof(path), BUFMGR_MODULE_DIR "/%s", file);
-
- module_data = dlopen(path, RTLD_LAZY);
- if (!module_data) {
- TBM_LOG_E("failed to load module: %s(%s)\n",
- dlerror(), file);
- return 0;
- }
-
- initdata = dlsym(module_data, "tbmModuleData");
- if (initdata) {
- ModuleInitProc init;
- TBMModuleVersionInfo *vers;
-
- vers = initdata->vers;
- init = initdata->init;
-
- if (vers) {
- if (!_check_version(vers)) {
- dlclose(module_data);
- return 0;
- }
- } else {
- TBM_LOG_E("Error: module does not supply version information.\n");
-
- dlclose(module_data);
- return 0;
- }
-
- if (init) {
- if (!init(bufmgr, fd)) {
- TBM_LOG_E("Fail to init module(%s)\n",
- file);
- dlclose(module_data);
- return 0;
- }
-
- if (!bufmgr->backend || !bufmgr->backend->priv) {
- TBM_LOG_E("Error: module(%s) wrong operation. Check backend or backend's priv.\n",
- file);
- dlclose(module_data);
- return 0;
- }
- } else {
- TBM_LOG_E("Error: module does not supply init symbol.\n");
- dlclose(module_data);
- return 0;
- }
- } else {
- TBM_LOG_E("Error: module does not have data object.\n");
- dlclose(module_data);
- return 0;
- }
-
- bufmgr->module_data = module_data;
-
- DBG("Success to load module(%s)\n",
- file);
-
- return 1;
-}
-
-static int
-_tbm_load_module(tbm_bufmgr bufmgr, int fd)
-{
- struct dirent **namelist;
- const char *p = NULL;
- int n;
- int ret = 0;
-
- /* load bufmgr priv from default lib */
- ret = _tbm_bufmgr_load_module(bufmgr, fd, DEFAULT_LIB);
-
- /* load bufmgr priv from configured path */
- if (!ret) {
- n = scandir(BUFMGR_MODULE_DIR, &namelist, 0, alphasort);
- if (n < 0) {
- TBM_LOG_E("no files : %s\n",
- BUFMGR_MODULE_DIR);
- } else {
- while (n--) {
- if (!ret && strstr(namelist[n]->d_name, PREFIX_LIB)) {
- p = strstr(namelist[n]->d_name, SUFFIX_LIB);
- if (p && !strcmp(p, SUFFIX_LIB))
- ret = _tbm_bufmgr_load_module(bufmgr, fd, namelist[n]->d_name);
- }
- free(namelist[n]);
- }
- free(namelist);
- }
- }