-static int _tbm_bo_set_state(tbm_bo bo, int device, int opt)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- char need_flush = 0;
- unsigned short cntFlush = 0;
- unsigned int is_locked;
-
- 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);
-
- if (!bo->cache_state.data.isCacheable)
- return 1;
-
- /* get global cache flush count */
- cntFlush = (unsigned short)_tgl_get_data(bufmgr->lock_fd, GLOBAL_KEY, NULL);
-
- if (DEVICE_IS_CACHE_AWARE(device)) {
- if (bo->cache_state.data.isDirtied == DEVICE_CO &&
- bo->cache_state.data.isCached)
- need_flush = TBM_CACHE_INV;
-
- bo->cache_state.data.isCached = 1;
- if (opt & TBM_OPTION_WRITE)
- bo->cache_state.data.isDirtied = DEVICE_CA;
- else {
- if (bo->cache_state.data.isDirtied != DEVICE_CA)
- bo->cache_state.data.isDirtied = DEVICE_NONE;
- }
- } else {
- if (bo->cache_state.data.isDirtied == DEVICE_CA &&
- bo->cache_state.data.isCached &&
- bo->cache_state.data.cntFlush == cntFlush)
- need_flush = TBM_CACHE_CLN | TBM_CACHE_ALL;
-
- if (opt & TBM_OPTION_WRITE)
- bo->cache_state.data.isDirtied = DEVICE_CO;
- else {
- if (bo->cache_state.data.isDirtied != DEVICE_CO)
- bo->cache_state.data.isDirtied = DEVICE_NONE;
- }
- }
-
- if (need_flush) {
- /* set global cache flush count */
- if (need_flush & TBM_CACHE_ALL)
- _tgl_set_data(bufmgr->lock_fd, GLOBAL_KEY, (unsigned int)(++cntFlush));
-
- /* call backend cache flush */
- bufmgr->backend->bo_cache_flush(bo, need_flush);
-
- DBG("[libtbm:%d] \tcache(%d,%d,%d)....flush:0x%x, cntFlush(%d)\n",
- getpid(),
- bo->cache_state.data.isCacheable,
- bo->cache_state.data.isCached,
- bo->cache_state.data.isDirtied,
- need_flush,
- cntFlush);
- }
-
- return 1;
-}
-
-static void _tbm_bo_save_state(tbm_bo bo)
-{
- tbm_bufmgr bufmgr = bo->bufmgr;
- unsigned short cntFlush = 0;
-
- 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);
-
- /* save global cache flush count */
- bo->cache_state.data.cntFlush = cntFlush;
- _tgl_set_data(bufmgr->lock_fd, bo->tgl_key, bo->cache_state.val);
-}
-
-static int _tbm_bo_lock(tbm_bo bo, int device, int opt)