int tgl_fd;
void *bind_display;
-
char *device_name;
};
return 1;
}
+#ifdef USE_CACHE
static inline int
_tgl_set_data(int fd, unsigned int key, unsigned int val)
{
return arg.data1;
}
+#endif
-#if 0
static int
_tbm_sprd_open_drm()
{
return fd;
}
-#endif
+#ifdef USE_CACHE
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);
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;
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)
+_bo_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int import)
{
- tbm_bo_cache_state cache_state;
-
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;
+
_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;
+#ifdef USE_CACHE
+ tbm_bo_cache_state cache_state;
- _tgl_set_data(bufmgr_sprd->tgl_fd, bo_sprd->name, cache_state.val);
+ 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);
+ }
+#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;
_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(),
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);
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);
}
+static int
+_bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd)
+{
+ 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;
+ }
+ }
+
+#ifdef USE_CACHE
+ if (!_tgl_init(bufmgr_sprd->tgl_fd, GLOBAL_KEY)) {
+ TBM_SPRD_LOG("[libtbm-sprd:%d] "
+ "error: Fail to initialize the tgl\n",
+ getpid());
+
+ close(bufmgr_sprd->tgl_fd);
+ return 0;
+ }
+#endif
+
+ return 1;
+}
+
+static void
+_bufmgr_deinit_cache_state(tbm_bufmgr_sprd bufmgr_sprd)
+{
+ 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);
+}
+
#ifndef USE_CONTIG_ONLY
static unsigned int
_get_sprd_flag_from_tbm (unsigned int ftbm)
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;
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, };
ret = drmHashLookup (bufmgr_sprd->hashBos, key, (void **)&privGem);
if (ret == 0) {
- privGem->ref_count++;
return privGem->bo_priv;
}
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;
}
tbm_bo_sprd bo_sprd;
PrivGem *privGem = NULL;
int ret;
- int name;
+ unsigned int name;
bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd != NULL, 0);
ret = drmHashLookup (bufmgr_sprd->hashBos, name, (void **)&privGem);
if (ret == 0) {
if (gem == privGem->bo_priv->gem) {
- privGem->ref_count++;
return privGem->bo_priv;
}
}
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;
}
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);
}
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++;
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);
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);
{
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;
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));
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",
return ret;
}
-
#endif
+
return 1;
}
{
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;
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) {
return ret;
}
#endif
+
return 1;
}
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);
- close (bufmgr_sprd->tgl_fd);
+ _bufmgr_deinit_cache_state(bufmgr_sprd);
+
close (bufmgr_sprd->fd);
free (bufmgr_sprd);
/**
* @brief get the plane data of the surface.
- * @param[in] surface : the surface
* @param[in] width : the width of the surface
* @param[in] height : the height of the surface
* @param[in] format : the format of the surface
* @return 1 if this function succeeds, otherwise 0.
*/
int
-tbm_sprd_surface_get_plane_data(tbm_surface_h surface, int width, int height,
+tbm_sprd_surface_get_plane_data(int width, int height,
tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset,
uint32_t *pitch, int *bo_idx)
{
}
if (tbm_backend_is_display_server()) {
-#if 0
- /* this code is applied with libtdm-sprd */
int master_fd = -1;
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 = dup(fd);
-#endif
+ else
+ bufmgr_sprd->fd = master_fd;
if (bufmgr_sprd->fd < 0) {
TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
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)
}
}
- /* 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 ();
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;
bufmgr_backend->surface_get_plane_data = tbm_sprd_surface_get_plane_data;
bufmgr_backend->surface_supported_format = tbm_sprd_surface_supported_format;
bufmgr_backend->bo_get_flags = tbm_sprd_bo_get_flags;
- bufmgr_backend->bo_lock = NULL;
- bufmgr_backend->bo_lock2 = tbm_sprd_bo_lock;
+ bufmgr_backend->bo_lock = tbm_sprd_bo_lock;
bufmgr_backend->bo_unlock = tbm_sprd_bo_unlock;
bufmgr_backend->bufmgr_bind_native_display = tbm_sprd_bufmgr_bind_native_display;
- bufmgr_backend->flags |= TBM_USE_2_0_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);
- 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);