#include <drm/sprd_drm.h>
#include <pthread.h>
#include <tbm_surface.h>
-#include "tbm_wayland.h"
+#include <tbm_drm_helper.h>
#define DEBUG
+#include "tbm_bufmgr_tgl.h"
//#define USE_CONTIG_ONLY
#define USE_DMAIMPORT
#define TBM_COLOR_FORMAT_COUNT 8
-
-
#ifdef DEBUG
#define LOG_TAG "TBM_BACKEND"
#include <dlog.h>
#define DMABUF_IOCTL_GET_FENCE DMABUF_IOWR(0x01, struct dma_buf_fence)
#define DMABUF_IOCTL_PUT_FENCE DMABUF_IOWR(0x02, struct dma_buf_fence)
+/* tgl key values */
+#define GLOBAL_KEY ((unsigned int)(-1))
+/* TBM_CACHE */
+#define TBM_SPRD_CACHE_INV 0x01 /**< cache invalidate */
+#define TBM_SPRD_CACHE_CLN 0x02 /**< cache clean */
+#define TBM_SPRD_CACHE_ALL 0x10 /**< cache all */
+#define TBM_SPRD_CACHE_FLUSH (TBM_SPRD_CACHE_INV|TBM_SPRD_CACHE_CLN) /**< cache flush */
+#define TBM_SPRD_CACHE_FLUSH_ALL (TBM_SPRD_CACHE_FLUSH|TBM_SPRD_CACHE_ALL) /**< cache flush all */
+
+enum {
+ DEVICE_NONE = 0,
+ DEVICE_CA, /* cache aware device */
+ DEVICE_CO /* cache oblivious device */
+};
+
+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;
+ } data;
+};
+
typedef struct _tbm_bufmgr_sprd *tbm_bufmgr_sprd;
typedef struct _tbm_bo_sprd *tbm_bo_sprd;
typedef struct _sprd_private
{
int ref_count;
+ struct _tbm_bo_sprd *bo_priv;
} PrivGem;
/* tbm buffor object for sprd */
struct dma_buf_fence dma_fence[DMA_FENCE_LIST_MAX];
int device;
int opt;
+
+ tbm_bo_cache_state cache_state;
+ unsigned int map_cnt;
};
/* tbm bufmgr private for sprd */
int use_dma_fence;
- int fd_owner;
+ int tgl_fd;
+
+ void *bind_display;
};
char *STR_DEVICE[]=
TBM_FORMAT_YUV420,
TBM_FORMAT_YVU420 };
+static inline int _tgl_init(int fd, unsigned int key)
+{
+ struct tgl_attribute attr;
+ int err;
+
+ attr.key = key;
+ attr.timeout_ms = 1000;
+
+ err = ioctl(fd, TGL_IOC_INIT_LOCK, &attr);
+ if (err) {
+ TBM_SPRD_LOG("[libtbm:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
+ return 0;
+ }
+
+ return 1;
+}
+
+static inline int _tgl_destroy(int fd, unsigned int key)
+{
+ int err;
+ err = ioctl(fd, TGL_IOC_DESTROY_LOCK, key);
+ if (err) {
+ TBM_SPRD_LOG("[libtbm:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
+ return 0;
+ }
+
+ return 1;
+}
+
+static inline int _tgl_set_data(int fd, unsigned int key, unsigned int val)
+{
+ int err;
+ struct tgl_user_data arg;
+
+ arg.key = key;
+ arg.data1 = val;
+ err = ioctl(fd, TGL_IOC_SET_DATA, &arg);
+ if (err) {
+ TBM_SPRD_LOG("[libtbm:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
+ return 0;
+ }
+
+ return 1;
+}
+
+static inline unsigned int _tgl_get_data(int fd, unsigned int key)
+{
+ int err;
+ struct tgl_user_data arg = { 0, };
+
+ arg.key = key;
+ err = ioctl(fd, TGL_IOC_GET_DATA, &arg);
+ if (err) {
+ TBM_SPRD_LOG("[libtbm:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __FUNCTION__, __LINE__, key);
+ return 0;
+ }
+
+ return arg.data1;
+}
+
+static int
+_sprd_bo_cache_flush (tbm_bo bo, 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);
+
+ /* 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;
+
+ /* if bo_sprd is null, do cache_flush_all */
+ if(bo_sprd)
+ {
+ cache_op.flags = 0;
+ cache_op.usr_addr = (uint64_t)((uint32_t)bo_sprd->pBase);
+ cache_op.size = bo_sprd->size;
+ }
+ else
+ {
+ flags = TBM_SPRD_CACHE_FLUSH_ALL;
+ cache_op.flags = 0;
+ cache_op.usr_addr = 0;
+ cache_op.size = 0;
+ }
+
+ if (flags & TBM_SPRD_CACHE_INV)
+ {
+ if(flags & TBM_SPRD_CACHE_ALL)
+ cache_op.flags |= SPRD_DRM_CACHE_INV_ALL;
+ else
+ cache_op.flags |= SPRD_DRM_CACHE_INV_RANGE;
+ }
+
+ if (flags & TBM_SPRD_CACHE_CLN)
+ {
+ if(flags & TBM_SPRD_CACHE_ALL)
+ cache_op.flags |= SPRD_DRM_CACHE_CLN_ALL;
+ else
+ cache_op.flags |= SPRD_DRM_CACHE_CLN_RANGE;
+ }
+
+ 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, sizeof(cache_op));
+ if (ret)
+ {
+ TBM_SPRD_LOG ("[libtbm-sprd:%d] "
+ "error %s:%d fail to flush the cache.\n",
+ getpid(), __FUNCTION__, __LINE__);
+ return 0;
+ }
+#endif
+
+ return 1;
+}
+
+static int
+_bo_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd)
+{
+ tbm_bo_cache_state cache_state;
+
+ SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, 0);
+ SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd!=NULL, 0);
+
+ _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;
+
+ _tgl_set_data(bufmgr_sprd->tgl_fd, bo_sprd->name, cache_state.val);
+
+ return 1;
+}
+
+static int
+_bo_set_cache_state(tbm_bo bo, int device, int opt)
+{
+ tbm_bo_sprd bo_sprd;
+ tbm_bufmgr_sprd bufmgr_sprd;
+ 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 (bo_sprd->flags_sprd & SPRD_BO_NONCACHABLE)
+ return 1;
+
+ /* get cache state of a bo */
+ bo_sprd->cache_state.val = _tgl_get_data(bufmgr_sprd->tgl_fd, bo_sprd->name);
+
+ /* get global cache flush count */
+ cntFlush = (unsigned short)_tgl_get_data(bufmgr_sprd->tgl_fd, GLOBAL_KEY);
+
+ if (opt == TBM_DEVICE_CPU) {
+ if (bo_sprd->cache_state.data.isDirtied == DEVICE_CO &&
+ bo_sprd->cache_state.data.isCached)
+ need_flush = TBM_SPRD_CACHE_INV;
+
+ bo_sprd->cache_state.data.isCached = 1;
+ if (opt & TBM_OPTION_WRITE)
+ bo_sprd->cache_state.data.isDirtied = DEVICE_CA;
+ else {
+ if (bo_sprd->cache_state.data.isDirtied != DEVICE_CA)
+ bo_sprd->cache_state.data.isDirtied = DEVICE_NONE;
+ }
+ } else {
+ if (bo_sprd->cache_state.data.isDirtied == DEVICE_CA &&
+ bo_sprd->cache_state.data.isCached &&
+ bo_sprd->cache_state.data.cntFlush == cntFlush)
+ need_flush = TBM_SPRD_CACHE_CLN | TBM_SPRD_CACHE_ALL;
+
+ if (opt & TBM_OPTION_WRITE)
+ bo_sprd->cache_state.data.isDirtied = DEVICE_CO;
+ else {
+ if (bo_sprd->cache_state.data.isDirtied != DEVICE_CO)
+ bo_sprd->cache_state.data.isDirtied = DEVICE_NONE;
+ }
+ }
+
+ if (need_flush)
+ {
+ if (need_flush & TBM_SPRD_CACHE_ALL)
+ _tgl_set_data(bufmgr_sprd->tgl_fd, GLOBAL_KEY, (unsigned int)(++cntFlush));
+
+ /* call cache flush */
+ _sprd_bo_cache_flush (bo, need_flush);
+
+ DBG("[libtbm:%d] \tcache(%d,%d)....flush:0x%x, cntFlush(%d)\n",
+ getpid(),
+ bo_sprd->cache_state.data.isCached,
+ bo_sprd->cache_state.data.isDirtied,
+ need_flush,
+ cntFlush);
+ }
+
+ return 1;
+}
+
+static int
+_bo_save_cache_state(tbm_bo bo)
+{
+ 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);
+ 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);
+
+ /* get global cache flush count */
+ cntFlush = (unsigned short)_tgl_get_data(bufmgr_sprd->tgl_fd, GLOBAL_KEY);
+
+ /* 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);
+
+ return 1;
+}
+
+static void
+_bo_destroy_cache_state(tbm_bo bo)
+{
+ 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);
+
+ _tgl_destroy(bufmgr_sprd->tgl_fd, bo_sprd->name);
+}
+
+static inline int
+_is_drm_master(int drm_fd)
+{
+ drm_magic_t magic;
+
+ return drmGetMagic(drm_fd, &magic) == 0 &&
+ drmAuthMagic(drm_fd, magic) == 0;
+}
+
#ifndef USE_CONTIG_ONLY
static unsigned int
return bo_handle;
}
-#ifdef USE_CACHE
-static int
-_sprd_cache_flush (int fd, tbm_bo_sprd bo_sprd, int flags)
-{
- struct drm_sprd_gem_cache_op cache_op = {0, };
- int ret;
-
- /* if bo_sprd is null, do cache_flush_all */
- if(bo_sprd)
- {
- cache_op.flags = 0;
- cache_op.usr_addr = (uint64_t)((uint32_t)bo_sprd->pBase);
- cache_op.size = bo_sprd->size;
- }
- else
- {
- flags = TBM_CACHE_FLUSH_ALL;
- cache_op.flags = 0;
- cache_op.usr_addr = 0;
- cache_op.size = 0;
- }
-
- if (flags & TBM_CACHE_INV)
- {
- if(flags & TBM_CACHE_ALL)
- cache_op.flags |= SPRD_DRM_CACHE_INV_ALL;
- else
- cache_op.flags |= SPRD_DRM_CACHE_INV_RANGE;
- }
-
- if (flags & TBM_CACHE_CLN)
- {
- if(flags & TBM_CACHE_ALL)
- cache_op.flags |= SPRD_DRM_CACHE_CLN_ALL;
- else
- cache_op.flags |= SPRD_DRM_CACHE_CLN_RANGE;
- }
-
- if(flags & TBM_CACHE_ALL)
- cache_op.flags |= SPRD_DRM_ALL_CACHES_CORES;
-
- ret = drmCommandWriteRead (fd, DRM_SPRD_GEM_CACHE_OP, &cache_op, sizeof(cache_op));
- if (ret)
- {
- TBM_SPRD_LOG ("[libtbm-sprd:%d] "
- "error %s:%d fail to flush the cache.\n",
- getpid(), __FUNCTION__, __LINE__);
- return 0;
- }
-
- return 1;
-}
-#endif
-
static int
tbm_sprd_bo_size (tbm_bo bo)
{
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))
+ {
+ TBM_SPRD_LOG ("error fail init cache state(%d)\n", bo_sprd->name);
+ free (bo_sprd);
+ return 0;
+ }
+
pthread_mutex_init(&bo_sprd->mutex, NULL);
if (bufmgr_sprd->use_dma_fence
/* add bo to hash */
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] "
getpid(), __FUNCTION__, __LINE__, bo_sprd->name, ret);
}
+ _bo_destroy_cache_state(bo);
+
/* Free gem handle */
struct drm_gem_close arg = {0, };
memset (&arg, 0, sizeof(arg));
tbm_bufmgr_sprd bufmgr_sprd;
tbm_bo_sprd bo_sprd;
+ PrivGem *privGem = NULL;
+ int ret;
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, key, (void**)&privGem);
+ if (ret == 0)
+ {
+ privGem->ref_count++;
+ return privGem->bo_priv;
+ }
+
struct drm_gem_open arg = {0, };
struct drm_sprd_gem_info info = {0, };
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);
+ free (bo_sprd);
+ return 0;
+ }
if (!bo_sprd->dmabuf)
{
}
/* add bo to hash */
- PrivGem *privGem = NULL;
- int ret;
-
- ret = drmHashLookup (bufmgr_sprd->hashBos, bo_sprd->name, (void**)&privGem);
- if (ret == 0)
- {
- privGem->ref_count++;
- }
- else if (ret == 1)
- {
- privGem = calloc (1, sizeof(PrivGem));
- privGem->ref_count = 1;
- 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);
- }
- }
- else
+ 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] "
"error %s:%d Cannot insert bo to Hash(%d)\n",
tbm_bufmgr_sprd bufmgr_sprd;
tbm_bo_sprd bo_sprd;
+ PrivGem *privGem = NULL;
+ int ret;
+ int name;
bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd!=NULL, 0);
- unsigned int gem = 0;
- unsigned int real_size = -1;
- struct drm_sprd_gem_info info = {0, };
-
//getting handle from fd
+ unsigned int gem = 0;
struct drm_prime_handle arg = {0, };
arg.fd = key;
}
gem = arg.handle;
+ name = _get_name (bufmgr_sprd->fd, gem);
+
+ ret = drmHashLookup (bufmgr_sprd->hashBos, name, (void**)&privGem);
+ if (ret == 0)
+ {
+ if (gem == privGem->bo_priv->gem)
+ {
+ privGem->ref_count++;
+ return privGem->bo_priv;
+ }
+ }
+
+ unsigned int real_size = -1;
+ struct drm_sprd_gem_info info = {0, };
+
/* Determine size of bo. The fd-to-handle ioctl really should
* return the size, but it doesn't. If we have kernel 3.12 or
* later, we can lseek on the prime fd to get the size. Older
bo_sprd->flags_sprd = info.flags;
bo_sprd->flags_tbm = _get_tbm_flag_from_sprd (bo_sprd->flags_sprd);
- bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem);
+ bo_sprd->name = name;
if (!bo_sprd->name)
{
TBM_SPRD_LOG ("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n",
return 0;
}
+ if (!_tgl_init(bufmgr_sprd->tgl_fd, bo_sprd->name))
+ {
+ TBM_SPRD_LOG ("error fail tgl init(%d)\n", bo_sprd->name);
+ free (bo_sprd);
+ return 0;
+ }
+
/* add bo to hash */
- PrivGem *privGem = NULL;
- int ret;
+ privGem = NULL;
- ret = drmHashLookup (bufmgr_sprd->hashBos, bo_sprd->name, (void**)&privGem);
- if (ret == 0)
+ privGem = calloc (1, sizeof(PrivGem));
+ if (!privGem)
{
- privGem->ref_count++;
+ TBM_SPRD_LOG ("[libtbm-sprd:%d] "
+ "error %s:%d Fail to calloc privGem\n",
+ getpid(), __FUNCTION__, __LINE__);
+ free (bo_sprd);
+ return 0;
}
- else if (ret == 1)
- {
- privGem = calloc (1, sizeof(PrivGem));
- if (!privGem)
- {
- TBM_SPRD_LOG ("[libtbm-sprd:%d] "
- "error %s:%d Fail to calloc privGem\n",
- getpid(), __FUNCTION__, __LINE__);
- free (bo_sprd);
- return 0;
- }
- privGem->ref_count = 1;
- 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);
- }
- }
- else
+ 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",
- bo, bo_sprd->name, gem, key);
+ bo, bo_sprd->name, gem, key);
}
DBG (" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", target_name(),
return (tbm_bo_handle) NULL;
}
+ if (bo_sprd->map_cnt == 0)
+ _bo_set_cache_state (bo, device, opt);
+
+ bo_sprd->map_cnt++;
+
return bo_handle;
}
if (!bo_sprd->gem)
return 0;
- DBG ("[libtbm-sprd:%d] %s gem:%d(%d) \n", getpid(),
- __FUNCTION__, bo_sprd->gem, bo_sprd->name);
+ bo_sprd->map_cnt--;
- return 1;
-}
-
-static int
-tbm_sprd_bo_cache_flush (tbm_bo bo, 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);
-
- /* cache flush is managed by kernel side when using dma-fence. */
- if (bufmgr_sprd->use_dma_fence)
- return 1;
+ if (bo_sprd->map_cnt == 0)
+ _bo_save_cache_state (bo);
- 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
- if (!_sprd_cache_flush(bo_sprd->fd, bo_sprd, flags))
- return 0;
-#endif
+ DBG ("[libtbm-sprd:%d] %s gem:%d(%d) \n", getpid(),
+ __FUNCTION__, bo_sprd->gem, bo_sprd->name);
return 1;
}
-static int
-tbm_sprd_bo_get_global_key (tbm_bo bo)
-{
- 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);
-
- if (!bo_sprd->name)
- {
- if (!bo_sprd->gem)
- return 0;
-
- bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem);
- }
-
- return bo_sprd->name;
-}
-
static int
tbm_sprd_bo_lock(tbm_bo bo, int device, int opt)
{
bufmgr_sprd->hashBos = NULL;
}
- if (bufmgr_sprd->fd_owner)
- close (bufmgr_sprd->fd_owner);
+ close (bufmgr_sprd->tgl_fd);
+
+ if (bufmgr_sprd->bind_display)
+ tbm_drm_helper_wl_server_deinit();
free (bufmgr_sprd);
}
return ret;
}
-/**
-* @brief get the size of the surface with a format.
-* @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 size of the surface if this function succeeds, otherwise 0.
-*/
int
-tbm_sprd_surface_get_size(tbm_surface_h surface, int width, int height, tbm_format format)
+tbm_sprd_bo_get_flags (tbm_bo bo)
{
- int ret = 0;
- int bpp = 0;
- int _pitch =0;
- int _size =0;
- int align =TBM_SURFACE_ALIGNMENT_PLANE;
-
-
- switch(format)
- {
- /* 16 bpp RGB */
- case TBM_FORMAT_XRGB4444:
- case TBM_FORMAT_XBGR4444:
- case TBM_FORMAT_RGBX4444:
- case TBM_FORMAT_BGRX4444:
- case TBM_FORMAT_ARGB4444:
- case TBM_FORMAT_ABGR4444:
- case TBM_FORMAT_RGBA4444:
- case TBM_FORMAT_BGRA4444:
- case TBM_FORMAT_XRGB1555:
- case TBM_FORMAT_XBGR1555:
- case TBM_FORMAT_RGBX5551:
- case TBM_FORMAT_BGRX5551:
- case TBM_FORMAT_ARGB1555:
- case TBM_FORMAT_ABGR1555:
- case TBM_FORMAT_RGBA5551:
- case TBM_FORMAT_BGRA5551:
- case TBM_FORMAT_RGB565:
- bpp = 16;
- _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- break;
- /* 24 bpp RGB */
- case TBM_FORMAT_RGB888:
- case TBM_FORMAT_BGR888:
- bpp = 24;
- _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- break;
- /* 32 bpp RGB */
- case TBM_FORMAT_XRGB8888:
- case TBM_FORMAT_XBGR8888:
- case TBM_FORMAT_RGBX8888:
- case TBM_FORMAT_BGRX8888:
- case TBM_FORMAT_ARGB8888:
- case TBM_FORMAT_ABGR8888:
- case TBM_FORMAT_RGBA8888:
- case TBM_FORMAT_BGRA8888:
- bpp = 32;
- _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- break;
- /* packed YCbCr */
- case TBM_FORMAT_YUYV:
- case TBM_FORMAT_YVYU:
- case TBM_FORMAT_UYVY:
- case TBM_FORMAT_VYUY:
- case TBM_FORMAT_AYUV:
- bpp = 32;
- _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- break;
- /*
- * 2 plane YCbCr
- * index 0 = Y plane, [7:0] Y
- * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
- * or
- * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
- */
- case TBM_FORMAT_NV12:
- case TBM_FORMAT_NV21:
- bpp = 12;
- //plane_idx == 0
- {
- _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- }
- //plane_idx ==1
- {
- _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
- }
- break;
- case TBM_FORMAT_NV16:
- case TBM_FORMAT_NV61:
- bpp = 16;
- //plane_idx == 0
- {
- _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- }
- //plane_idx ==1
- {
- _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- }
-
- break;
- /*
- * 3 plane YCbCr
- * index 0: Y plane, [7:0] Y
- * index 1: Cb plane, [7:0] Cb
- * index 2: Cr plane, [7:0] Cr
- * or
- * index 1: Cr plane, [7:0] Cr
- * index 2: Cb plane, [7:0] Cb
- */
- case TBM_FORMAT_YUV410:
- case TBM_FORMAT_YVU410:
- bpp = 9;
- align = TBM_SURFACE_ALIGNMENT_PITCH_YUV;
- break;
- case TBM_FORMAT_YUV411:
- case TBM_FORMAT_YVU411:
- case TBM_FORMAT_YUV420:
- case TBM_FORMAT_YVU420:
- bpp = 12;
- //plane_idx == 0
- {
- _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- }
- //plane_idx == 1
- {
- _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
- }
- //plane_idx == 2
- {
- _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
- }
-
- break;
- case TBM_FORMAT_YUV422:
- case TBM_FORMAT_YVU422:
- bpp = 16;
- //plane_idx == 0
- {
- _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- }
- //plane_idx == 1
- {
- _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- }
- //plane_idx == 2
- {
- _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
- }
- break;
- case TBM_FORMAT_YUV444:
- case TBM_FORMAT_YVU444:
- bpp = 24;
- align = TBM_SURFACE_ALIGNMENT_PITCH_YUV;
- break;
-
- default:
- bpp = 0;
- break;
- }
+ SPRD_RETURN_VAL_IF_FAIL (bo != NULL, 0);
- if(_size > 0)
- ret = _size;
- else
- ret = SIZE_ALIGN( (width * height * bpp) >> 3, align);
+ tbm_bo_sprd bo_sprd;
- return ret;
+ bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
+ SPRD_RETURN_VAL_IF_FAIL (bo_sprd != NULL, 0);
+ return bo_sprd->flags_tbm;
}
int
-tbm_sprd_surface_get_num_bos(tbm_format format)
-{
- int num = 0;
-
- switch(format)
- {
- /* 16 bpp RGB */
- case TBM_FORMAT_XRGB4444:
- case TBM_FORMAT_XBGR4444:
- case TBM_FORMAT_RGBX4444:
- case TBM_FORMAT_BGRX4444:
- case TBM_FORMAT_ARGB4444:
- case TBM_FORMAT_ABGR4444:
- case TBM_FORMAT_RGBA4444:
- case TBM_FORMAT_BGRA4444:
- case TBM_FORMAT_XRGB1555:
- case TBM_FORMAT_XBGR1555:
- case TBM_FORMAT_RGBX5551:
- case TBM_FORMAT_BGRX5551:
- case TBM_FORMAT_ARGB1555:
- case TBM_FORMAT_ABGR1555:
- case TBM_FORMAT_RGBA5551:
- case TBM_FORMAT_BGRA5551:
- case TBM_FORMAT_RGB565:
- /* 24 bpp RGB */
- case TBM_FORMAT_RGB888:
- case TBM_FORMAT_BGR888:
- /* 32 bpp RGB */
- case TBM_FORMAT_XRGB8888:
- case TBM_FORMAT_XBGR8888:
- case TBM_FORMAT_RGBX8888:
- case TBM_FORMAT_BGRX8888:
- case TBM_FORMAT_ARGB8888:
- case TBM_FORMAT_ABGR8888:
- case TBM_FORMAT_RGBA8888:
- case TBM_FORMAT_BGRA8888:
- /* packed YCbCr */
- case TBM_FORMAT_YUYV:
- case TBM_FORMAT_YVYU:
- case TBM_FORMAT_UYVY:
- case TBM_FORMAT_VYUY:
- case TBM_FORMAT_AYUV:
- /*
- * 2 plane YCbCr
- * index 0 = Y plane, [7:0] Y
- * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
- * or
- * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
- */
- case TBM_FORMAT_NV12:
- case TBM_FORMAT_NV21:
- case TBM_FORMAT_NV16:
- case TBM_FORMAT_NV61:
- /*
- * 3 plane YCbCr
- * index 0: Y plane, [7:0] Y
- * index 1: Cb plane, [7:0] Cb
- * index 2: Cr plane, [7:0] Cr
- * or
- * index 1: Cr plane, [7:0] Cr
- * index 2: Cb plane, [7:0] Cb
- */
- case TBM_FORMAT_YUV410:
- case TBM_FORMAT_YVU410:
- case TBM_FORMAT_YUV411:
- case TBM_FORMAT_YVU411:
- case TBM_FORMAT_YUV420:
- case TBM_FORMAT_YVU420:
- case TBM_FORMAT_YUV422:
- case TBM_FORMAT_YVU422:
- case TBM_FORMAT_YUV444:
- case TBM_FORMAT_YVU444:
- num = 1;
- break;
-
- default:
- num = 0;
- break;
- }
-
- return num;
-}
-
-tbm_bo_handle
-tbm_sprd_fd_to_handle(tbm_bufmgr bufmgr, tbm_fd fd, int device)
+tbm_sprd_bufmgr_bind_native_display (tbm_bufmgr bufmgr, void *NativeDisplay)
{
- SPRD_RETURN_VAL_IF_FAIL (bufmgr!=NULL, (tbm_bo_handle) NULL);
- SPRD_RETURN_VAL_IF_FAIL (fd > 0, (tbm_bo_handle) NULL);
+ tbm_bufmgr_sprd bufmgr_sprd;
- tbm_bo_handle bo_handle;
- memset (&bo_handle, 0x0, sizeof (uint64_t));
+ bufmgr_sprd = tbm_backend_get_priv_from_bufmgr(bufmgr);
+ SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0);
- tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_priv_from_bufmgr(bufmgr);
+ if (!tbm_drm_helper_wl_server_init(NativeDisplay, bufmgr_sprd->fd, "/dev/dri/card0", 0)) {
+ TBM_SPRD_LOG("[libtbm-sprd:%d] error:Fail to tbm_drm_helper_wl_server_init\n");
+ return 0;
+ }
- switch(device)
- {
- case TBM_DEVICE_DEFAULT:
- case TBM_DEVICE_2D:
- {
- //getting handle from fd
- struct drm_prime_handle arg = {0, };
+ bufmgr_sprd->bind_display = NativeDisplay;
- arg.fd = fd;
- arg.flags = 0;
- if (drmIoctl (bufmgr_sprd->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg))
- {
- TBM_SPRD_LOG ("error Cannot get gem handle from fd:%d (%s)\n",
- arg.fd, strerror(errno));
- return (tbm_bo_handle) NULL;
- }
-
- bo_handle.u32 = (uint32_t)arg.handle;;
- break;
- }
- case TBM_DEVICE_CPU:
- TBM_SPRD_LOG ("Not supported device:%d\n", device);
- bo_handle.ptr = (void *) NULL;
- break;
- case TBM_DEVICE_3D:
- case TBM_DEVICE_MM:
- bo_handle.u32 = (uint32_t)fd;
- break;
- default:
- TBM_SPRD_LOG ("error Not supported device:%d\n", device);
- bo_handle.ptr = (void *) NULL;
- break;
- }
-
- return bo_handle;
-}
-
-int
-tbm_sprd_bo_get_flags (tbm_bo bo)
-{
- 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);
-
- return bo_sprd->flags_tbm;
+ return 1;
}
-
MODULEINITPPROTO (init_tbm_bufmgr_priv);
static TBMModuleVersionInfo SprdVersRec =
return 0;
}
- if (fd < 0)
- {
- bufmgr_sprd->fd = tbm_bufmgr_get_drm_fd_wayland();
- bufmgr_sprd->fd_owner = 1;
+ 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();
+ tbm_drm_helper_set_master_fd(bufmgr_sprd->fd);
+ }
+ if (bufmgr_sprd->fd <0) {
+ TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
+ free (bufmgr_sprd);
+ return 0;
+ }
+ } else {
+ if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), NULL, NULL)) {
+ TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to get auth drm info!\n", getpid());
+ free (bufmgr_sprd);
+ return 0;
+ }
+ }
+
+ /* 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);
+
+ free (bufmgr_sprd);
+ return 0;
+ }
}
- else
- bufmgr_sprd->fd = fd;
- if (bufmgr_sprd->fd < 0)
- {
- TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
+ if (!_tgl_init(bufmgr_sprd->tgl_fd, GLOBAL_KEY)) {
+ TBM_SPRD_LOG("[libtbm:%d] "
+ "error: Fail to initialize the tgl\n",
+ getpid());
+
free (bufmgr_sprd);
return 0;
}
{
TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
- if (bufmgr_sprd->fd_owner)
- close(bufmgr_sprd->fd);
-
free (bufmgr_sprd);
return 0;
}
bufmgr_backend->bo_get_handle = tbm_sprd_bo_get_handle,
bufmgr_backend->bo_map = tbm_sprd_bo_map,
bufmgr_backend->bo_unmap = tbm_sprd_bo_unmap,
- bufmgr_backend->bo_cache_flush = tbm_sprd_bo_cache_flush,
- bufmgr_backend->bo_get_global_key = tbm_sprd_bo_get_global_key;
bufmgr_backend->surface_get_plane_data = tbm_sprd_surface_get_plane_data;
- bufmgr_backend->surface_get_size = tbm_sprd_surface_get_size;
bufmgr_backend->surface_supported_format = tbm_sprd_surface_supported_format;
- bufmgr_backend->fd_to_handle = tbm_sprd_fd_to_handle;
- bufmgr_backend->surface_get_num_bos = tbm_sprd_surface_get_num_bos;
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_unlock = tbm_sprd_bo_unlock;
+ bufmgr_backend->bufmgr_bind_native_display = tbm_sprd_bufmgr_bind_native_display;
- if (bufmgr_sprd->use_dma_fence)
- {
- bufmgr_backend->flags = (TBM_LOCK_CTRL_BACKEND | TBM_CACHE_CTRL_BACKEND);
- bufmgr_backend->bo_lock = NULL;
- bufmgr_backend->bo_lock2 = tbm_sprd_bo_lock;
- bufmgr_backend->bo_unlock = tbm_sprd_bo_unlock;
- }
- else
- {
- bufmgr_backend->flags = 0;
- bufmgr_backend->bo_lock = NULL;
- bufmgr_backend->bo_unlock = NULL;
- }
+ bufmgr_backend->flags |= TBM_LOCK_CTRL_BACKEND;
+ 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);
- if (bufmgr_sprd->fd_owner)
- close(bufmgr_sprd->fd);
-
free (bufmgr_sprd);
return 0;
}
+++ /dev/null
-/**************************************************************************
-
-libtbm
-
-Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
-Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#include "config.h"
-
-#include <xf86drm.h>
-
-#include <stdint.h>
-#include <stddef.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <wayland-client.h>
-
-#include "wayland-util.h"
-
-extern const struct wl_interface wl_buffer_interface;
-
-static const struct wl_interface *types[] = {
- NULL,
- NULL,
- NULL,
- &wl_buffer_interface,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- &wl_buffer_interface,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
-static const struct wl_message wl_tbm_requests[] = {
- {"create_buffer", "niiuiiiiiiiiiiuiuuu", types + 3},
- {"create_buffer_with_fd", "niiuiiiiiiiiiiuihhh", types + 22},
- {"get_authentication_info", "", types + 0},
-};
-
-static const struct wl_message wl_tbm_events[] = {
- {"authentication_info", "suh", types + 0},
-};
-
-WL_EXPORT const struct wl_interface wl_tbm_interface = {
- "wl_tbm", 1,
- 3, wl_tbm_requests,
- 1, wl_tbm_events,
-};
-
-struct wl_buffer;
-struct wl_tbm;
-
-extern const struct wl_interface wl_tbm_interface;
-
-#ifndef WL_TBM_ERROR_ENUM
-#define WL_TBM_ERROR_ENUM
-enum wl_tbm_error {
- WL_TBM_ERROR_AUTHENTICATE_FAIL = 0,
- WL_TBM_ERROR_INVALID_FORMAT = 1,
- WL_TBM_ERROR_INVALID_NAME = 2,
-};
-#endif /* WL_TBM_ERROR_ENUM */
-
-struct wl_tbm_listener {
- /**
- * authentication_info - (none)
- * @device_name: (none)
- * @capabilities: (none)
- * @auth_fd: (none)
- */
- void (*authentication_info) (void *data, struct wl_tbm * wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd);
-};
-
-static inline int wl_tbm_add_listener(struct wl_tbm *wl_tbm, const struct wl_tbm_listener *listener, void *data)
-{
- return wl_proxy_add_listener((struct wl_proxy *)wl_tbm, (void (**)(void))listener, data);
-}
-
-#define WL_TBM_CREATE_BUFFER 0
-#define WL_TBM_CREATE_BUFFER_WITH_FD 1
-#define WL_TBM_GET_AUTHENTICATION_INFO 2
-
-static inline void wl_tbm_set_user_data(struct wl_tbm *wl_tbm, void *user_data)
-{
- wl_proxy_set_user_data((struct wl_proxy *)wl_tbm, user_data);
-}
-
-static inline void *wl_tbm_get_user_data(struct wl_tbm *wl_tbm)
-{
- return wl_proxy_get_user_data((struct wl_proxy *)wl_tbm);
-}
-
-static inline void wl_tbm_destroy(struct wl_tbm *wl_tbm)
-{
- wl_proxy_destroy((struct wl_proxy *)wl_tbm);
-}
-
-static inline void wl_tbm_get_authentication_info(struct wl_tbm *wl_tbm)
-{
- wl_proxy_marshal((struct wl_proxy *)wl_tbm, WL_TBM_GET_AUTHENTICATION_INFO);
-}
-
-struct wl_tbm_info {
- struct wl_display *dpy;
- struct wl_event_queue *wl_queue;
- struct wl_tbm *wl_tbm;
-
- uint32_t capabilities;
- char *device;
- int32_t fd;
-};
-
-static void handle_tbm_authentication_info(void *data, struct wl_tbm *wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd)
-{
- struct wl_tbm_info *info = (struct wl_tbm_info *)data;
-
- info->fd = auth_fd;
- info->capabilities = capabilities;
- if (device_name)
- info->device = strndup(device_name, 256);
-}
-
-static const struct wl_tbm_listener wl_tbm_client_listener = {
- handle_tbm_authentication_info
-};
-
-static void wl_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
-{
- struct wl_tbm_info *info = (struct wl_tbm_info *)data;
-
- if (!strcmp(interface, "wl_tbm")) {
- info->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version);
- if (!info->wl_tbm) {
- printf("Failed to bind wl_tbm\n");
- return;
- }
-
- wl_tbm_add_listener(info->wl_tbm, &wl_tbm_client_listener, info);
- wl_proxy_set_queue((struct wl_proxy *)info->wl_tbm, info->wl_queue);
- }
-}
-
-static int tbm_util_get_drm_fd(void *dpy, int *fd)
-{
- struct wl_display *disp = NULL;
- struct wl_registry *wl_registry;
- struct wl_tbm_info info = {
- .dpy = NULL,
- .wl_queue = NULL,
- .wl_tbm = NULL,
- .capabilities = 0,
- .device = NULL,
- .fd = 0,
- };
-
- static const struct wl_registry_listener registry_listener = {
- wl_client_registry_handle_global,
- NULL
- };
-
- if (!fd)
- return -1;
-
- if (!dpy) {
- disp = wl_display_connect(NULL);
- if (!disp) {
- printf("Failed to create a new display connection\n");
- return -1;
- }
- dpy = disp;
- }
-
- info.dpy = dpy;
- info.wl_queue = wl_display_create_queue(dpy);
- if (!info.wl_queue) {
- printf("Failed to create a WL Queue\n");
- if (disp == dpy)
- wl_display_disconnect(disp);
-
- return -1;
- }
-
- wl_registry = wl_display_get_registry(dpy);
- if (!wl_registry) {
- printf("Failed to get registry\n");
- wl_event_queue_destroy(info.wl_queue);
- if (disp == dpy)
- wl_display_disconnect(disp);
-
- return -1;
- }
- wl_proxy_set_queue((struct wl_proxy *)wl_registry, info.wl_queue);
- wl_registry_add_listener(wl_registry, ®istry_listener, &info);
- wl_display_roundtrip_queue(dpy, info.wl_queue);
-
- wl_tbm_get_authentication_info(info.wl_tbm);
- wl_display_roundtrip_queue(dpy, info.wl_queue);
-
- *fd = info.fd;
-
- wl_event_queue_destroy(info.wl_queue);
- wl_registry_destroy(wl_registry);
-
- free(info.device);
- wl_tbm_set_user_data(info.wl_tbm, NULL);
- wl_tbm_destroy(info.wl_tbm);
-
- if (disp == dpy)
- wl_display_disconnect(disp);
-
- return *fd >= 0 ? 0 : -1;
-}
-
-int tbm_bufmgr_get_drm_fd_wayland()
-{
- int fd = -1;
-
- if (tbm_util_get_drm_fd(NULL, &fd))
- printf("Failed to get drm_fd\n");
-
- return fd;
-}