#include <tbm_drm_helper.h>
#define DEBUG
-#include "tbm_bufmgr_tgl.h"
-
//#define USE_CONTIG_ONLY
//#define USE_CACHE
#define USE_DMAIMPORT
+#ifdef USE_CACHE
+#include "tbm_bufmgr_tgl.h"
+#endif
+
#define TBM_COLOR_FORMAT_COUNT 4
#ifdef DEBUG
return app_name;
}
-#define TBM_SPRD_LOG(fmt, args...) LOGE("\033[31m" "[%s]" fmt "\033[0m", _target_name(), ##args)
-#define DBG(fmt, args...) if (bDebug&01) LOGE("[%s]" fmt, _target_name(), ##args)
+
+#define TBM_SPRD_ERROR(fmt, args...) LOGE("\033[31m" "[%s] " fmt "\033[0m", _target_name(), ##args)
+#define TBM_SPRD_DEBUG(fmt, args...) if (bDebug&01) LOGD("[%s] " fmt, _target_name(), ##args)
#else
-#define TBM_SPRD_LOG(...)
-#define DBG(...)
+#define TBM_SPRD_ERROR(...)
+#define TBM_SPRD_DEBUG(...)
#endif
#define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
/* check condition */
#define SPRD_RETURN_IF_FAIL(cond) {\
if (!(cond)) {\
- TBM_SPRD_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
+ TBM_SPRD_ERROR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
return;\
} \
}
#define SPRD_RETURN_VAL_IF_FAIL(cond, val) {\
if (!(cond)) {\
- TBM_SPRD_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
+ TBM_SPRD_ERROR("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
return val;\
} \
}
TBM_FORMAT_YUV420
};
+#ifdef USE_CACHE
static inline int
_tgl_get_version(int fd)
{
err = ioctl(fd, TGL_IOCTL_GET_VERSION, &data);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d\n",
- getpid(), strerror(errno), __func__, __LINE__);
+ TBM_SPRD_ERROR("error(%s) %s:%d\n", strerror(errno));
return 0;
}
- TBM_SPRD_LOG("[libtbm-sprd:%d] %s:%d tgl version is (%u, %u).\n",
- getpid(), __func__, __LINE__, data.major, data.minor);
+ TBM_SPRD_DEBUG("tgl version is (%u, %u).\n", data.major, data.minor);
return 1;
}
-
static inline int
_tgl_init(int fd, unsigned int key)
{
err = ioctl(fd, TGL_IOCTL_REGISTER, &data);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_ERROR("error(%s) key:%d\n", strerror(errno), key);
return 0;
}
data.key = key;
err = ioctl(fd, TGL_IOCTL_UNREGISTER, &data);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_ERROR("error(%s) key:%d\n", strerror(errno), key);
return 0;
}
data.key = key;
data.type = tgl_type;
- err = ioctl(fd, TGL_IOCTL_LOCK, data);
+ err = ioctl(fd, TGL_IOCTL_LOCK, &data);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d opt:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key, opt);
+ TBM_SPRD_ERROR("error(%s) key:%d opt:%d\n",
+ strerror(errno), key, opt);
return 0;
}
data.key = key;
data.type = TGL_TYPE_NONE;
- err = ioctl(fd, TGL_IOCTL_UNLOCK, data);
+ err = ioctl(fd, TGL_IOCTL_UNLOCK, &data);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_ERROR("error(%s) key:%d\n",
+ strerror(errno), key);
return 0;
}
return 1;
}
-#ifdef USE_CACHE
static inline int
_tgl_set_data(int fd, unsigned int key, unsigned int val)
{
err = ioctl(fd, TGL_IOCTL_SET_DATA, &data);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_ERROR("error(%s) key:%d\n",
+ strerror(errno), key);
return 0;
}
err = ioctl(fd, TGL_IOCTL_GET_DATA, &data);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_ERROR("error(%s) key:%d\n",
+ strerror(errno), key);
return 0;
}
return fd;
#ifdef HAVE_UDEV
- TBM_SPRD_LOG("[libtbm-sprd:%d] warning %s:%d fail to open drm, "
- "so search drm-device by udev\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_DEBUG("warning fail to open drm. search drm-device by udev\n");
udev = udev_new();
if (!udev) {
- TBM_SPRD_LOG("udev_new() failed.\n");
+ TBM_SPRD_ERROR("udev_new() failed.\n");
return -1;
}
if (device_parent) {
if (strcmp(udev_device_get_sysname(device_parent), "sprd-drm") == 0) {
drm_device = device;
- DBG("[%s] Found render device: '%s' (%s)\n",
- _target_name(),
+ TBM_SPRD_DEBUG("Found render device: '%s' (%s)\n",
udev_device_get_syspath(drm_device),
udev_device_get_sysname(device_parent));
break;
/* Get device file path. */
filepath = udev_device_get_devnode(drm_device);
if (!filepath) {
- TBM_SPRD_LOG("udev_device_get_devnode() failed.\n");
+ TBM_SPRD_ERROR("udev_device_get_devnode() failed.\n");
udev_device_unref(drm_device);
udev_unref(udev);
return -1;
/* Open DRM device file and check validity. */
fd = open(filepath, O_RDWR | O_CLOEXEC);
if (fd < 0) {
- TBM_SPRD_LOG("open(%s, O_RDWR | O_CLOEXEC) failed.\n");
+ TBM_SPRD_ERROR("open(%s, O_RDWR | O_CLOEXEC) failed.\n");
return -1;
}
if (fstat(fd, &s)) {
- TBM_SPRD_LOG("fstat() failed %s.\n");
+ TBM_SPRD_ERROR("fstat() failed %s.\n");
close(fd);
return -1;
}
#else
- TBM_SPRD_LOG("[libtbm-sprd:%d] warning %s:%d fail to open drm\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_ERROR("warning fail to open drm\n");
#endif
return fd;
cache_op.flags |= SPRD_DRM_ALL_CACHES_CORES;
ret = drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CACHE_OP, &cache_op,
- sizeof(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__);
+ TBM_SPRD_ERROR("error fail to flush the cache.\n");
return 0;
}
#endif
+
return 1;
}
#endif
static int
_bo_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int import)
{
+#ifdef USE_CACHE
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);
-#ifdef USE_CACHE
tbm_bo_cache_state cache_state;
if (import == 0) {
/* call cache flush */
_sprd_bo_cache_flush(bufmgr_sprd, bo_sprd, need_flush);
- DBG("[libtbm:%d] \tcache(%d,%d)....flush:0x%x, cntFlush(%d)\n",
- getpid(),
+ TBM_SPRD_DEBUG("\tcache(%d,%d)....flush:0x%x, cntFlush(%d)\n",
bo_sprd->cache_state.data.isCached,
bo_sprd->cache_state.data.isDirtied,
need_flush,
static void
_bo_destroy_cache_state(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd)
{
+#ifdef USE_CACHE
SPRD_RETURN_IF_FAIL(bo_sprd != NULL);
SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL);
return;
_tgl_destroy(bufmgr_sprd->tgl_fd, bo_sprd->name);
+#endif
}
static int
_bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd)
{
+#ifdef USE_CACHE
SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0);
if (bufmgr_sprd->use_dma_fence)
/* open tgl fd for saving cache flush data */
bufmgr_sprd->tgl_fd = open(tgl_devfile, 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);
- return 0;
+ bufmgr_sprd->tgl_fd = open(tgl_devfile1, O_RDWR);
+ if (bufmgr_sprd->tgl_fd < 0) {
+ TBM_SPRD_ERROR("fail to open global_lock:%s\n",
+ tgl_devfile1);
+ return 0;
+ }
}
if (!_tgl_get_version(bufmgr_sprd->tgl_fd)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error: fail to get tgl_version. tgl init failed.\n",
- getpid());
-
+ TBM_SPRD_ERROR("fail to get tgl_version. tgl init failed.\n");
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());
-
+ TBM_SPRD_ERROR("fail to initialize the tgl\n");
close(bufmgr_sprd->tgl_fd);
return 0;
}
static void
_bufmgr_deinit_cache_state(tbm_bufmgr_sprd bufmgr_sprd)
{
+#ifdef USE_CACHE
SPRD_RETURN_IF_FAIL(bufmgr_sprd != NULL);
if (bufmgr_sprd->use_dma_fence)
if (bufmgr_sprd->tgl_fd >= 0)
close(bufmgr_sprd->tgl_fd);
+#endif
}
#ifndef USE_CONTIG_ONLY
arg.handle = gem;
if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d fail to get flink gem=%d\n",
- getpid(), __FUNCTION__, __LINE__, gem);
+ TBM_SPRD_ERROR("error fail to get flink gem=%d\n", gem);
return 0;
}
arg.handle = bo_sprd->gem;
arg.size = bo_sprd->size;
if (drmCommandWriteRead(bo_sprd->fd, DRM_SPRD_GEM_MMAP, &arg, sizeof(arg))) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot usrptr gem=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
+ TBM_SPRD_ERROR("error Cannot usrptr gem=%d\n", bo_sprd->gem);
return (tbm_bo_handle) NULL;
}
bo_sprd->pBase = (void *)((uint32_t)arg.mapped);
struct drm_prime_handle arg = {0, };
arg.handle = bo_sprd->gem;
if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot dmabuf=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
+ TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem);
return (tbm_bo_handle) NULL;
}
bo_sprd->dmabuf = arg.fd;
case TBM_DEVICE_MM:
#ifdef USE_HEAP_ID
//TODO : Add ioctl for GSP MAP once available.
- DBG("[libtbm-sprd:%d] %s In case TBM_DEVICE_MM: \n", getpid(),
- __FUNCTION_);
- _
-
+ TBM_SPRD_DEBUG("%s In case TBM_DEVICE_MM: \n", __FUNCTION_);
#else
if (!bo_sprd->dmabuf) {
struct drm_prime_handle arg = {0, };
arg.handle = bo_sprd->gem;
if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot dmabuf=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
+ TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem);
return (tbm_bo_handle) NULL;
}
bo_sprd->dmabuf = arg.fd;
bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd));
if (!bo_sprd) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d fail to allocate the bo private\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_ERROR("error fail to allocate the bo private\n");
return 0;
}
arg.flags = sprd_flags;
if (drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CREATE, &arg,
sizeof(arg))) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot create bo(flag:%x, size:%d)\n",
- getpid(), __FUNCTION__, __LINE__, arg.flags, (unsigned int)arg.size);
+ TBM_SPRD_ERROR("error Cannot create bo(flag:%x, size:%d)\n",
+ arg.flags, (unsigned int)arg.size);
free(bo_sprd);
return 0;
}
bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem);
if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 0)) {
- TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name);
+ TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name);
free(bo_sprd);
return 0;
}
arg.handle = bo_sprd->gem;
if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot dmabuf=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
+ TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem);
free(bo_sprd);
return 0;
}
/* add bo to hash */
PrivGem *privGem = calloc(1, sizeof(PrivGem));
if (!privGem) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Fail to calloc PrivGem\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_ERROR("error Fail to calloc PrivGem\n");
free(bo_sprd);
return 0;
}
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",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->name);
- }
+ if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0)
+ TBM_SPRD_ERROR("error Cannot insert bo to Hash(%d)\n", bo_sprd->name);
- DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(),
- __FUNCTION__, bo_sprd->size,
- bo_sprd->gem, bo_sprd->name,
- flags, sprd_flags);
+ TBM_SPRD_DEBUG("%s size:%d, gem:%d(%d), flags:%d(%d)\n",
+ __FUNCTION__, bo_sprd->size,
+ bo_sprd->gem, bo_sprd->name,
+ flags, sprd_flags);
return (void *)bo_sprd;
}
bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
SPRD_RETURN_IF_FAIL(bo_sprd != NULL);
- DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d)\n",
- getpid(), __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name);
+ TBM_SPRD_DEBUG("size:%d, gem:%d(%d)\n",
+ bo_sprd->size, bo_sprd->gem, bo_sprd->name);
if (bo_sprd->pBase) {
- if (munmap(bo_sprd->pBase, bo_sprd->size) == -1) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d\n",
- getpid(), __FUNCTION__, __LINE__);
- }
+ if (munmap(bo_sprd->pBase, bo_sprd->size) == -1)
+ TBM_SPRD_ERROR("error fail to munmap.\n");
}
/* closedmabuf */
privGem = NULL;
}
} else {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "warning %s:%d Cannot find bo to Hash(%d), ret=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->name, ret);
+ TBM_SPRD_DEBUG("warning Cannot find bo to Hash(%d), ret=%d\n", bo_sprd->name, ret);
}
_bo_destroy_cache_state(bufmgr_sprd, bo_sprd);
struct drm_gem_close arg = {0, };
memset(&arg, 0, sizeof(arg));
arg.handle = bo_sprd->gem;
- if (drmIoctl(bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d\n",
- getpid(), __FUNCTION__, __LINE__);
- }
+ if (drmIoctl(bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg))
+ TBM_SPRD_ERROR("error fail to DRM_IOCTL_GEM_CLOSE\n");
free(bo_sprd);
}
arg.name = key;
if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot open gem name=%d\n",
- getpid(), __FUNCTION__, __LINE__, key);
+ TBM_SPRD_ERROR("error Cannot open gem name=%d\n", key);
return NULL;
}
DRM_SPRD_GEM_GET,
&info,
sizeof(struct drm_sprd_gem_info))) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot get gem info=%d\n",
- getpid(), __FUNCTION__, __LINE__, key);
+ TBM_SPRD_ERROR("error Cannot get gem info=%d\n", key);
goto fail_get_gem;
}
bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd));
if (!bo_sprd) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d fail to allocate the bo private\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_ERROR("error fail to allocate the bo private\n");
goto fail_alloc_bo;
}
#endif
if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) {
- TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name);
+ TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name);
goto fail_init_cache;
}
arg.handle = bo_sprd->gem;
if (drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot dmabuf=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
+ TBM_SPRD_ERROR("error Cannot dmabuf=%d\n", bo_sprd->gem);
goto fail_prime_handle_to_fd;
}
bo_sprd->dmabuf = arg.fd;
/* add bo to hash */
privGem = calloc(1, sizeof(PrivGem));
if (!privGem) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error %s:%d Fail to alloc\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_ERROR("error Fail to alloc\n");
goto fail_alloc_gem_priv;
}
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",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->name);
- }
+ if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0)
+ TBM_SPRD_ERROR("error Cannot insert bo to Hash(%d)\n", bo_sprd->name);
- DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(),
- __FUNCTION__, bo_sprd->size,
- bo_sprd->gem, bo_sprd->name,
- bo_sprd->flags_tbm, bo_sprd->flags_sprd);
+ TBM_SPRD_DEBUG("size:%d, gem:%d(%d), flags:%d(%d)\n",
+ bo_sprd->size, bo_sprd->gem, bo_sprd->name,
+ bo_sprd->flags_tbm, bo_sprd->flags_sprd);
return (void *)bo_sprd;
arg.fd = key;
if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) {
- TBM_SPRD_LOG("error bo:%p Cannot get gem handle from fd:%d (%s)\n",
- bo, arg.fd, strerror(errno));
+ TBM_SPRD_ERROR("error bo:%p Cannot get gem handle from fd:%d (%s)\n",
+ bo, arg.fd, strerror(errno));
return NULL;
}
gem = arg.handle;
name = _get_name(bufmgr_sprd->fd, gem);
if (!name) {
- TBM_SPRD_LOG("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n",
- bo, gem, key, strerror(errno));
+ TBM_SPRD_ERROR("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n",
+ bo, gem, key, strerror(errno));
return NULL;
}
DRM_SPRD_GEM_GET,
&info,
sizeof(struct drm_sprd_gem_info))) {
- TBM_SPRD_LOG("error bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n",
- bo, gem, key, strerror(errno));
+ TBM_SPRD_ERROR("error bo:%p Cannot get gem info from gem:%d, fd:%d (%s)\n",
+ bo, gem, key, strerror(errno));
return NULL;
}
bo_sprd = calloc(1, sizeof(struct _tbm_bo_sprd));
if (!bo_sprd) {
- TBM_SPRD_LOG("error bo:%p fail to allocate the bo private\n", bo);
+ TBM_SPRD_ERROR("error bo:%p fail to allocate the bo private\n", bo);
return NULL;
}
bo_sprd->name = name;
if (!bo_sprd->name) {
- TBM_SPRD_LOG("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n",
- bo, gem, key, strerror(errno));
+ TBM_SPRD_ERROR("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n",
+ bo, gem, key, strerror(errno));
goto fail_check_name;
}
if (!_bo_init_cache_state(bufmgr_sprd, bo_sprd, 1)) {
- TBM_SPRD_LOG("error fail init cache state(%d)\n", bo_sprd->name);
+ TBM_SPRD_ERROR("error fail init cache state(%d)\n", bo_sprd->name);
goto fail_init_cache;
}
/* add bo to hash */
privGem = calloc(1, sizeof(PrivGem));
if (!privGem) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Fail to callocprivGem\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_ERROR("error Fail to callocprivGem\n");
goto fail_alloc_gem_priv;
}
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);
+ TBM_SPRD_ERROR("error bo:%p Cannot insert bo to Hash(%d) from gem:%d, fd:%d\n",
+ 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(),
+ TBM_SPRD_DEBUG("bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n",
bo,
bo_sprd->gem, bo_sprd->name,
bo_sprd->dmabuf,
if (!bo_sprd->name) {
bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem);
if (!bo_sprd->name) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot get name\n",
- getpid(), __FUNCTION__, __LINE__);
+ TBM_SPRD_ERROR("error Cannot get name\n");
return 0;
}
}
- DBG("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(),
- __FUNCTION__, bo_sprd->size,
- bo_sprd->gem, bo_sprd->name,
- bo_sprd->flags_tbm, bo_sprd->flags_sprd);
+ TBM_SPRD_DEBUG("size:%d, gem:%d(%d), flags:%d(%d)\n",
+ bo_sprd->size, bo_sprd->gem, bo_sprd->name,
+ bo_sprd->flags_tbm, bo_sprd->flags_sprd);
return (unsigned int)bo_sprd->name;
}
arg.handle = bo_sprd->gem;
ret = drmIoctl(bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg);
if (ret) {
- TBM_SPRD_LOG("error bo:%p Cannot dmabuf=%d (%s)\n",
- bo, bo_sprd->gem, strerror(errno));
+ TBM_SPRD_ERROR("error bo:%p Cannot dmabuf=%d (%s)\n",
+ bo, bo_sprd->gem, strerror(errno));
return (tbm_fd) ret;
}
- DBG(" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n",
- _target_name(),
- bo,
- bo_sprd->gem, bo_sprd->name,
- bo_sprd->dmabuf,
- arg.fd,
- bo_sprd->flags_tbm, bo_sprd->flags_sprd,
- bo_sprd->size);
+ TBM_SPRD_DEBUG("bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n",
+ bo,
+ bo_sprd->gem, bo_sprd->name,
+ bo_sprd->dmabuf,
+ arg.fd,
+ bo_sprd->flags_tbm, bo_sprd->flags_sprd,
+ bo_sprd->size);
return (tbm_fd)arg.fd;
}
SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, (tbm_bo_handle) NULL);
if (!bo_sprd->gem) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot map gem=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
+ TBM_SPRD_ERROR("error Cannot map gem=%d\n", bo_sprd->gem);
return (tbm_bo_handle) NULL;
}
- DBG("[libtbm-sprd:%d] %s gem:%d(%d), %s\n", getpid(),
- __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device]);
+ TBM_SPRD_DEBUG("gem:%d(%d), %s\n",
+ bo_sprd->gem, bo_sprd->name, STR_DEVICE[device]);
/*Get mapped bo_handle*/
bo_handle = _sprd_bo_handle(bo_sprd, device);
if (bo_handle.ptr == NULL) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot get handle: gem:%d, device:%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem, device);
+ TBM_SPRD_ERROR("error Cannot get handle: gem:%d, device:%d\n",
+ bo_sprd->gem, device);
return (tbm_bo_handle) NULL;
}
SPRD_RETURN_VAL_IF_FAIL(bo_sprd != NULL, (tbm_bo_handle) NULL);
if (!bo_sprd->gem) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot map gem=%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
+ TBM_SPRD_ERROR("error Cannot map gem=%d\n", bo_sprd->gem);
return (tbm_bo_handle) NULL;
}
- DBG("[libtbm-sprd:%d] %s gem:%d(%d), %s, %s\n", getpid(),
- __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device], STR_OPT[opt]);
+ TBM_SPRD_DEBUG("%s gem:%d(%d), %s, %s\n",
+ __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device], STR_OPT[opt]);
/*Get mapped bo_handle*/
bo_handle = _sprd_bo_handle(bo_sprd, device);
if (bo_handle.ptr == NULL) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Cannot get handle: gem:%d, device:%d, opt:%d\n",
- getpid(), __FUNCTION__, __LINE__, bo_sprd->gem, device, opt);
+ TBM_SPRD_ERROR("error Cannot get handle: gem:%d, device:%d, opt:%d\n",
+ bo_sprd->gem, device, opt);
return (tbm_bo_handle) NULL;
}
if (bo_sprd->map_cnt == 0)
_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);
-
- return 1;
-}
-
-static int
-tbm_sprd_bo_lock(tbm_bo bo, int device, int opt)
-{
- SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0);
-
- tbm_bufmgr_sprd bufmgr_sprd;
- 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);
-
- bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
- SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0);
-
-#if USE_BACKEND_LOCK
- int ret = 0;
-
- if (bufmgr_sprd->use_dma_fence) {
- struct dma_buf_fence fence;
-
- memset(&fence, 0, sizeof(struct dma_buf_fence));
-
- /* Check if the given type is valid or not. */
- if (opt & TBM_OPTION_WRITE) {
- if (device == TBM_DEVICE_CPU)
- fence.type = DMA_BUF_ACCESS_WRITE;
- else if (device == TBM_DEVICE_3D)
- fence.type = DMA_BUF_ACCESS_WRITE | DMA_BUF_ACCESS_DMA;
- else {
- DBG("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n",
- getpid(), __FUNCTION__);
- return 0;
- }
- } else if (opt & TBM_OPTION_READ) {
- if (device == TBM_DEVICE_CPU)
- fence.type = DMA_BUF_ACCESS_READ;
- else if (device == TBM_DEVICE_3D)
- fence.type = DMA_BUF_ACCESS_READ | DMA_BUF_ACCESS_DMA;
- else {
- DBG("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n",
- getpid(), __FUNCTION__);
- return 0;
- }
- } else {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error %s:%d Invalid argument\n", getpid(),
- __FUNCTION__, __LINE__);
- return 0;
- }
-
- ret = ioctl(bo_sprd->dmabuf, DMABUF_IOCTL_GET_FENCE, &fence);
- if (ret < 0) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Can not set GET FENCE(%s)\n",
- getpid(), __FUNCTION__, __LINE__, strerror(errno));
- return 0;
- }
-
- pthread_mutex_lock(&bo_sprd->mutex);
- int i;
- for (i = 0; i < DMA_FENCE_LIST_MAX; i++) {
- if (bo_sprd->dma_fence[i].ctx == 0) {
- bo_sprd->dma_fence[i].type = fence.type;
- bo_sprd->dma_fence[i].ctx = fence.ctx;
- break;
- }
- }
- if (i == DMA_FENCE_LIST_MAX) {
- //TODO: if dma_fence list is full, it needs realloc. I will fix this. by minseok3.kim
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d fence list is full\n",
- getpid(), __FUNCTION__, __LINE__);
- }
- pthread_mutex_unlock(&bo_sprd->mutex);
-
- DBG("[libtbm-sprd:%d] %s DMABUF_IOCTL_GET_FENCE! flink_id=%d dmabuf=%d\n",
- getpid(),
- __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf);
- } else {
- ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name, opt);
-
- DBG("[libtbm-sprd:%d] lock tgl flink_id:%d\n",
- getpid(), __FUNCTION__, bo_sprd->name);
-
- return ret;
- }
-#endif
-
- return 1;
-}
-
-static int
-tbm_sprd_bo_unlock(tbm_bo bo)
-{
- SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0);
-
- tbm_bufmgr_sprd bufmgr_sprd;
- 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);
-
- bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
- SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0);
-
-#if USE_BACKEND_LOCK
- int ret = 0;
-
- if (bufmgr_sprd->use_dma_fence) {
- struct dma_buf_fence fence;
-
- if (!bo_sprd->dma_fence[0].ctx) {
- DBG("[libtbm-sprd:%d] %s FENCE not support or ignored,\n", getpid(),
- __FUNCTION__);
- return 0;
- }
-
- if (!bo_sprd->dma_fence[0].type) {
- DBG("[libtbm-sprd:%d] %s device type is not 3D/CPU,\n", getpid(),
- __FUNCTION__);
- return 0;
- }
-
- pthread_mutex_lock(&bo_sprd->mutex);
- fence.type = bo_sprd->dma_fence[0].type;
- fence.ctx = bo_sprd->dma_fence[0].ctx;
- int i;
- for (i = 1; i < DMA_FENCE_LIST_MAX; i++) {
- bo_sprd->dma_fence[i - 1].type = bo_sprd->dma_fence[i].type;
- bo_sprd->dma_fence[i - 1].ctx = bo_sprd->dma_fence[i].ctx;
- }
- bo_sprd->dma_fence[DMA_FENCE_LIST_MAX - 1].type = 0;
- bo_sprd->dma_fence[DMA_FENCE_LIST_MAX - 1].ctx = 0;
- pthread_mutex_unlock(&bo_sprd->mutex);
-
- ret = ioctl(bo_sprd->dmabuf, DMABUF_IOCTL_PUT_FENCE, &fence);
- if (ret < 0) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] "
- "error %s:%d Can not set PUT FENCE(%s)\n",
- getpid(), __FUNCTION__, __LINE__, strerror(errno));
- return 0;
- }
-
- DBG("[libtbm-sprd:%d] %s DMABUF_IOCTL_PUT_FENCE! flink_id=%d dmabuf=%d\n",
- getpid(),
- __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf);
- } else {
- ret = _tgl_unlock(bufmgr_sprd->tgl_fd, bo_sprd->name);
-
- DBG("[libtbm-sprd:%d] unlock tgl flink_id:%d\n",
- getpid(), __FUNCTION__, bo_sprd->name);
-
- return ret;
- }
-#endif
+ TBM_SPRD_DEBUG("gem:%d(%d) \n", bo_sprd->gem, bo_sprd->name);
return 1;
}
if (tbm_backend_is_display_server())
tbm_drm_helper_unset_tbm_master_fd();
+ else
+ tbm_drm_helper_unset_fd();
if (bufmgr_sprd->device_name)
free(bufmgr_sprd->device_name);
if (!tbm_drm_helper_wl_auth_server_init(NativeDisplay, bufmgr_sprd->fd,
bufmgr_sprd->device_name, 0)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error:Fail to tbm_drm_helper_wl_server_init\n");
+ TBM_SPRD_ERROR("fail to tbm_drm_helper_wl_server_init\n");
return 0;
}
bufmgr_sprd = calloc(1, sizeof(struct _tbm_bufmgr_sprd));
if (!bufmgr_sprd) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to alloc bufmgr_sprd!\n", getpid());
+ TBM_SPRD_ERROR("fail to alloc bufmgr_sprd!\n");
return 0;
}
if (bufmgr_sprd->fd < 0) {
bufmgr_sprd->fd = _tbm_sprd_open_drm();
if (bufmgr_sprd->fd < 0) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to open drm!\n", getpid());
+ TBM_SPRD_ERROR("fail to open drm!\n");
goto fail_open_drm;
}
}
bufmgr_sprd->device_name = drmGetDeviceNameFromFd(bufmgr_sprd->fd);
if (!bufmgr_sprd->device_name) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get device name!\n", getpid());
+ TBM_SPRD_ERROR("fail to get device name!\n");
tbm_drm_helper_unset_tbm_master_fd();
goto fail_get_device_name;
}
} else {
if (!tbm_drm_helper_get_auth_info(&(bufmgr_sprd->fd), &(bufmgr_sprd->device_name), NULL)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to get auth drm info!\n", getpid());
+ TBM_SPRD_ERROR("fail to get auth drm info!\n");
goto fail_get_auth_info;
}
+
+ tbm_drm_helper_set_fd(bufmgr_sprd->fd);
}
//Create Hash Table
}
if (!_bufmgr_init_cache_state(bufmgr_sprd)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to init bufmgr cache state\n", getpid());
+ TBM_SPRD_ERROR("fail to init bufmgr cache state\n");
goto fail_init_cache_state;
}
bufmgr_backend = tbm_backend_alloc();
if (!bufmgr_backend) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to alloc backend!\n", getpid());
+ TBM_SPRD_ERROR("fail to alloc backend!\n");
goto fail_alloc_backend;
}
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 = tbm_sprd_bo_lock;
- bufmgr_backend->bo_unlock = tbm_sprd_bo_unlock;
+ bufmgr_backend->bo_lock = NULL;
+ bufmgr_backend->bo_unlock = NULL;
bufmgr_backend->bufmgr_bind_native_display = tbm_sprd_bufmgr_bind_native_display;
if (!tbm_backend_init(bufmgr, bufmgr_backend)) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error: Fail to init backend!\n", getpid());
+ TBM_SPRD_ERROR("fail to init backend!\n");
goto fail_init_backend;
}
env = getenv("TBM_SPRD_DEBUG");
if (env) {
bDebug = atoi(env);
- TBM_SPRD_LOG("TBM_SPRD_DEBUG=%s\n", env);
+ TBM_SPRD_ERROR("TBM_SPRD_DEBUG=%s\n", env);
} else
bDebug = 0;
}
#endif
- DBG("[libtbm-sprd:%d] %s DMABUF FENCE is %s\n", getpid(),
- __FUNCTION__, bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!");
- DBG("[libtbm-sprd:%d] %s fd:%d\n", getpid(),
- __FUNCTION__, bufmgr_sprd->fd);
+ TBM_SPRD_DEBUG("DMABUF FENCE is %s\n",
+ bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!");
+ TBM_SPRD_DEBUG("fd:%d\n", bufmgr_sprd->fd);
return 1;
drmHashDestroy(bufmgr_sprd->hashBos);
if (tbm_backend_is_display_server())
tbm_drm_helper_unset_tbm_master_fd();
+ else
+ tbm_drm_helper_unset_fd();
+ if (bufmgr_sprd->device_name)
+ free(bufmgr_sprd->device_name);
fail_get_device_name:
close(bufmgr_sprd->fd);
fail_get_auth_info: