#include "tbm_bufmgr_tgl.h"
//#define USE_CONTIG_ONLY
-//#define USE_CACHE
#define USE_DMAIMPORT
#define TBM_COLOR_FORMAT_COUNT 4
uint32_t tbm_sprd_color_format_list[TBM_COLOR_FORMAT_COUNT] = {
- TBM_FORMAT_ARGB8888,
- TBM_FORMAT_XRGB8888,
- TBM_FORMAT_NV12,
- TBM_FORMAT_YUV420
- };
-
-static inline int
-_tgl_get_version(int fd)
-{
- struct tgl_ver_data data;
- int err;
-
- 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__);
- return 0;
- }
-
- TBM_SPRD_LOG("[libtbm-sprd:%d] %s:%d tgl version is (%u, %u).\n",
- getpid(), __func__, __LINE__, data.major, data.minor);
-
- return 1;
-}
-
+ TBM_FORMAT_ARGB8888,
+ TBM_FORMAT_XRGB8888,
+ TBM_FORMAT_NV12,
+ TBM_FORMAT_YUV420
+ };
static inline int
_tgl_init(int fd, unsigned int key)
{
- struct tgl_reg_data data;
+ struct tgl_attribute attr;
int err;
- data.key = key;
- data.timeout_ms = 1000;
+ attr.key = key;
+ attr.timeout_ms = 1000;
- err = ioctl(fd, TGL_IOCTL_REGISTER, &data);
+ err = ioctl(fd, TGL_IOC_INIT_LOCK, &attr);
if (err) {
TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ getpid(), strerror(errno), __func__, __LINE__, key);
return 0;
}
static inline int
_tgl_destroy(int fd, unsigned int key)
{
- struct tgl_reg_data data;
int err;
- data.key = key;
- err = ioctl(fd, TGL_IOCTL_UNREGISTER, &data);
+ err = ioctl(fd, TGL_IOC_DESTROY_LOCK, key);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_LOG("[libtbm-sprd:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __func__, __LINE__, key);
return 0;
}
}
static inline int
-_tgl_lock(int fd, unsigned int key, int opt)
+_tgl_lock(int fd, unsigned int key)
{
- struct tgl_lock_data data;
- enum tgl_type_data tgl_type;
int err;
- switch (opt) {
- case TBM_OPTION_READ:
- tgl_type = TGL_TYPE_READ;
- break;
- case TBM_OPTION_WRITE:
- tgl_type = TGL_TYPE_WRITE;
- break;
- default:
- tgl_type = TGL_TYPE_NONE;
- break;
- }
-
- data.key = key;
- data.type = tgl_type;
-
- err = ioctl(fd, TGL_IOCTL_LOCK, data);
+ err = ioctl(fd, TGL_IOC_LOCK_LOCK, key);
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_LOG("[libtbm-sprd:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __func__, __LINE__, key);
return 0;
}
static inline int
_tgl_unlock(int fd, unsigned int key)
{
- struct tgl_lock_data data;
int err;
- data.key = key;
- data.type = TGL_TYPE_NONE;
-
- err = ioctl(fd, TGL_IOCTL_UNLOCK, data);
+ err = ioctl(fd, TGL_IOC_UNLOCK_LOCK, key);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_LOG("[libtbm-sprd:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __func__, __LINE__, key);
return 0;
}
static inline int
_tgl_set_data(int fd, unsigned int key, unsigned int val)
{
- struct tgl_usr_data data;
int err;
+ struct tgl_user_data arg;
- data.key = key;
- data.data1 = val;
-
- err = ioctl(fd, TGL_IOCTL_SET_DATA, &data);
+ arg.key = key;
+ arg.data1 = val;
+ err = ioctl(fd, TGL_IOC_SET_DATA, &arg);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_LOG("[libtbm-sprd:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __func__, __LINE__, key);
return 0;
}
static inline unsigned int
_tgl_get_data(int fd, unsigned int key, unsigned int *locked)
{
- struct tgl_usr_data data = { 0, };
int err;
+ struct tgl_user_data arg = { 0, };
- data.key = key;
-
- err = ioctl(fd, TGL_IOCTL_GET_DATA, &data);
+ arg.key = key;
+ err = ioctl(fd, TGL_IOC_GET_DATA, &arg);
if (err) {
- TBM_SPRD_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
- getpid(), strerror(errno), __func__, __LINE__, key);
+ TBM_SPRD_LOG("[libtbm-sprd:%d] "
+ "error(%s) %s:%d key:%d\n",
+ getpid(), strerror(errno), __func__, __LINE__, key);
return 0;
}
if (locked)
- *locked = (unsigned int)data.status;
+ *locked = arg.locked;
- return data.data1;
+ return arg.data1;
}
#endif
/* cache flush is managed by kernel side when using dma-fence. */
if (bufmgr_sprd->use_dma_fence)
return 1;
-// TODO: The tm1 kernel does not support ioctl for cache flush right now.
-// The drm in tm1 kernel has to support cache_flush to turn on this feature(TBM_SRPD_CACHE_FLUSH).
-#if TBM_SRPD_CACHE_FLUSH
+
struct drm_sprd_gem_cache_op cache_op = {0, };
int ret;
getpid(), __FUNCTION__, __LINE__);
return 0;
}
-#endif
+
return 1;
}
#endif
/* 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;
- }
- 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());
-
- close(bufmgr_sprd->tgl_fd);
- return 0;
+ 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);
+ 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());
+ "error: Fail to initialize the tgl\n",
+ getpid());
close(bufmgr_sprd->tgl_fd);
return 0;
getpid(),
__FUNCTION__, bo_sprd->name, bo_sprd->dmabuf);
} else {
- ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name, opt);
+ ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name);
DBG("[libtbm-sprd:%d] lock tgl flink_id:%d\n",
getpid(), __FUNCTION__, bo_sprd->name);
#include <linux/ioctl.h>
-static char tgl_devfile[] = "/dev/tgl";
+static char tgl_devfile[] = "/dev/slp_global_lock";
+static char tgl_devfile1[] = "/dev/tgl";
-#define TGL_IOCTL_BASE 0x32
-#define TGL_IO(nr) _IO(TGL_IOCTL_BASE, nr)
-#define TGL_IOR(nr, type) _IOR(TGL_IOCTL_BASE, nr, type)
-#define TGL_IOW(nr, type) _IOW(TGL_IOCTL_BASE, nr, type)
-#define TGL_IOWR(nr, type) _IOWR(TGL_IOCTL_BASE, nr, type)
+#define TGL_IOC_BASE 0x32
-/**
- * struct tgl_ver_data - tgl version data structure
- * @major: major version
- * @minor: minor version
- */
-struct tgl_ver_data {
- unsigned int major;
- unsigned int minor;
-};
-
-/**
- * struct tgl_reg_data - tgl data structure
- * @key: lookup key
- * @timeout_ms: timeout value for waiting event
- */
-struct tgl_reg_data {
+struct tgl_attribute {
unsigned int key;
unsigned int timeout_ms;
};
-enum tgl_type_data {
- TGL_TYPE_NONE = 0,
- TGL_TYPE_READ = (1 << 0),
- TGL_TYPE_WRITE = (1 << 1),
-};
-
-/**
- * struct tgl_lock_data - tgl lock data structure
- * @key: lookup key
- * @type: lock type that is in tgl_type_data
- */
-struct tgl_lock_data {
- unsigned int key;
- enum tgl_type_data type;
-};
-
-enum tgl_status_data {
- TGL_STATUS_UNLOCKED,
- TGL_STATUS_LOCKED,
-};
-
-/**
- * struct tgl_usr_data - tgl user data structure
- * @key: lookup key
- * @data1: user data 1
- * @data2: user data 2
- * @status: lock status that is in tgl_status_data
- */
-struct tgl_usr_data {
+struct tgl_user_data {
unsigned int key;
unsigned int data1;
unsigned int data2;
- enum tgl_status_data status;
+ unsigned int locked;
};
-enum {
- _TGL_GET_VERSION,
- _TGL_REGISTER,
- _TGL_UNREGISTER,
- _TGL_LOCK,
- _TGL_UNLOCK,
+typedef enum {
+ _TGL_INIT_LOCK = 1,
+ _TGL_DESTROY_LOCK,
+ _TGL_LOCK_LOCK,
+ _TGL_UNLOCK_LOCK,
_TGL_SET_DATA,
_TGL_GET_DATA,
-};
+} _tgl_ioctls;
-/* get version information */
-#define TGL_IOCTL_GET_VERSION TGL_IOR(_TGL_GET_VERSION, struct tgl_ver_data)
-/* register key */
-#define TGL_IOCTL_REGISTER TGL_IOW(_TGL_REGISTER, struct tgl_reg_data)
-/* unregister key */
-#define TGL_IOCTL_UNREGISTER TGL_IOW(_TGL_UNREGISTER, struct tgl_reg_data)
-/* lock with key */
-#define TGL_IOCTL_LOCK TGL_IOW(_TGL_LOCK, struct tgl_lock_data)
-/* unlock with key */
-#define TGL_IOCTL_UNLOCK TGL_IOW(_TGL_UNLOCK, struct tgl_lock_data)
-/* set user data with key */
-#define TGL_IOCTL_SET_DATA TGL_IOW(_TGL_SET_DATA, struct tgl_usr_data)
-/* get user data with key */
-#define TGL_IOCTL_GET_DATA TGL_IOR(_TGL_GET_DATA, struct tgl_usr_data)
+#define TGL_IOC_INIT_LOCK _IOW(TGL_IOC_BASE, _TGL_INIT_LOCK, struct tgl_attribute *)
+#define TGL_IOC_DESTROY_LOCK _IOW(TGL_IOC_BASE, _TGL_DESTROY_LOCK, unsigned int)
+#define TGL_IOC_LOCK_LOCK _IOW(TGL_IOC_BASE, _TGL_LOCK_LOCK, unsigned int)
+#define TGL_IOC_UNLOCK_LOCK _IOW(TGL_IOC_BASE, _TGL_UNLOCK_LOCK, unsigned int)
+#define TGL_IOC_SET_DATA _IOW(TGL_IOC_BASE, _TGL_SET_DATA, struct tgl_user_data *)
+#define TGL_IOC_GET_DATA _IOW(TGL_IOC_BASE, _TGL_GET_DATA, struct tgl_user_data *)
-#endif /* __TBM_BUFMGR_TGL_H__ */
+#endif /* __TBM_BUFMGR_TGL_H__ */