change the slp_global_lock to the tgl 56/99256/3
authorSooChan Lim <sc1.lim@samsung.com>
Tue, 22 Nov 2016 08:27:36 +0000 (17:27 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Tue, 22 Nov 2016 08:50:01 +0000 (17:50 +0900)
We do not use slp_global_lock device anymore.
We use tgl device instead and
the use space interface is changed because of this change.

When the kernel version is up and kernel can use
the dma_fence, libtbm-exynos does not use the tgl for
the bo lock and for the bo cache_flush anymore.

Change-Id: I738338b0834f6d84b94d84552509f7d9073f4429

rules/99-libtbm_exynos.rules
src/tbm_bufmgr_exynos.c
src/tbm_bufmgr_tgl.h

index b00652e..a826c4c 100644 (file)
@@ -1 +1,2 @@
+KERNEL=="tgl", MODE="0666", GROUP="display", SECLABEL{smack}="*"
 KERNEL=="slp_global_lock*", MODE="0666", GROUP="display", SECLABEL{smack}="*"
index a15a7cc..98f812f 100644 (file)
@@ -266,27 +266,44 @@ char *STR_OPT[] = {
 
 
 uint32_t tbm_exynos_color_format_list[TBM_COLOR_FORMAT_COUNT] = {
-                                    TBM_FORMAT_ARGB8888,
-                                    TBM_FORMAT_XRGB8888,
-                                    TBM_FORMAT_NV12,
-                                    TBM_FORMAT_YUV420
-                                    };
+                                                                               TBM_FORMAT_ARGB8888,
+                                                                               TBM_FORMAT_XRGB8888,
+                                                                               TBM_FORMAT_NV12,
+                                                                               TBM_FORMAT_YUV420
+                                                                       };
 
 #ifdef ENABLE_CACHECRTL
+#ifdef TGL_GET_VERSION
+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_EXYNOS_LOG("error(%s) %s:%d\n",     strerror(errno));
+               return 0;
+       }
+
+       DBG("tgl version is (%u, %u).\n", data.major, data.minor);
+
+       return 1;
+}
+#endif
+
 static inline int
 _tgl_init(int fd, unsigned int key)
 {
-       struct tgl_attribute attr;
+       struct tgl_reg_data data;
        int err;
 
-       attr.key = key;
-       attr.timeout_ms = 1000;
+       data.key = key;
+       data.timeout_ms = 1000;
 
-       err = ioctl(fd, TGL_IOC_INIT_LOCK, &attr);
+       err = ioctl(fd, TGL_IOCTL_REGISTER, &data);
        if (err) {
-               TBM_EXYNOS_LOG("[libtbm:%d] "
-                              "warning(%s) %s:%d key:%d\n",
-                              getpid(), strerror(errno), __func__, __LINE__, key);
+               TBM_EXYNOS_LOG("error(%s) key:%d\n", strerror(errno), key);
                return 0;
        }
 
@@ -296,32 +313,83 @@ _tgl_init(int fd, unsigned int key)
 static inline int
 _tgl_destroy(int fd, unsigned int key)
 {
+       struct tgl_reg_data data;
        int err;
 
-       err = ioctl(fd, TGL_IOC_DESTROY_LOCK, key);
+       data.key = key;
+       err = ioctl(fd, TGL_IOCTL_UNREGISTER, &data);
        if (err) {
-               TBM_EXYNOS_LOG("[libtbm:%d] "
-                              "warning(%s) %s:%d key:%d\n",
-                              getpid(), strerror(errno), __func__, __LINE__, key);
+               TBM_EXYNOS_LOG("error(%s) key:%d\n", strerror(errno), key);
                return 0;
        }
 
        return 1;
 }
+
+static inline int
+_tgl_lock(int fd, unsigned int key, int opt)
+{
+       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);
+       if (err) {
+               TBM_EXYNOS_LOG("error(%s) key:%d opt:%d\n",
+                       strerror(errno), key, opt);
+               return 0;
+       }
+
+       return 1;
+}
+
+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);
+       if (err) {
+               TBM_EXYNOS_LOG("error(%s) key:%d\n",
+                       strerror(errno), key);
+               return 0;
+       }
+
+       return 1;
+}
+
 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;
 
-       arg.key = key;
-       arg.data1 = val;
-       err = ioctl(fd, TGL_IOC_SET_DATA, &arg);
+       err = ioctl(fd, TGL_IOCTL_SET_DATA, &data);
        if (err) {
-               TBM_EXYNOS_LOG("[libtbm:%d] "
-                              "warning(%s) %s:%d key:%d\n",
-                              getpid(), strerror(errno), __func__, __LINE__, key);
+               TBM_EXYNOS_LOG("error(%s) key:%d\n",
+                       strerror(errno), key);
                return 0;
        }
 
@@ -331,19 +399,19 @@ _tgl_set_data(int fd, unsigned int key, unsigned int val)
 static inline unsigned int
 _tgl_get_data(int fd, unsigned int key)
 {
+       struct tgl_usr_data data = { 0, };
        int err;
-       struct tgl_user_data arg = { 0, };
 
-       arg.key = key;
-       err = ioctl(fd, TGL_IOC_GET_DATA, &arg);
+       data.key = key;
+
+       err = ioctl(fd, TGL_IOCTL_GET_DATA, &data);
        if (err) {
-               TBM_EXYNOS_LOG("[libtbm:%d] "
-                              "warning(%s) %s:%d key:%d\n",
-                              getpid(), strerror(errno), __func__, __LINE__, key);
+               TBM_EXYNOS_LOG("error(%s) key:%d\n",
+                       strerror(errno), key);
                return 0;
        }
 
-       return arg.data1;
+       return data.data1;
 }
 
 static int
@@ -408,10 +476,10 @@ _bo_init_cache_state(tbm_bufmgr_exynos bufmgr_exynos, tbm_bo_exynos bo_exynos, i
        if (bufmgr_exynos->use_dma_fence)
                return 1;
 
-       tbm_bo_cache_state cache_state;
-
        _tgl_init(bufmgr_exynos->tgl_fd, bo_exynos->name);
 
+       tbm_bo_cache_state cache_state;
+
        if (import == 0) {
                cache_state.data.isDirtied = DEVICE_NONE;
                cache_state.data.isCached = 0;
@@ -543,14 +611,22 @@ _bufmgr_init_cache_state(tbm_bufmgr_exynos bufmgr_exynos)
        bufmgr_exynos->tgl_fd = open(tgl_devfile, O_RDWR);
 
        if (bufmgr_exynos->tgl_fd < 0) {
-               bufmgr_exynos->tgl_fd = open(tgl_devfile1, O_RDWR);
-               if (bufmgr_exynos->tgl_fd < 0) {
-                       TBM_EXYNOS_LOG("[libtbm-exynos:%d] "
-                                      "warning: Fail to open global_lock:%s\n",
-                                      getpid(), tgl_devfile);
-                       return 0;
-               }
+           bufmgr_exynos->tgl_fd = open(tgl_devfile1, O_RDWR);
+           if (bufmgr_exynos->tgl_fd < 0) {
+                   TBM_EXYNOS_LOG("[libtbm-exynos:%d] "
+                                       "warning: Fail to open global_lock:%s\n",
+                                       getpid(), tgl_devfile1);
+                   return 0;
+           }
+       }
+
+#ifdef TGL_GET_VERSION
+       if (!_tgl_get_version(bufmgr_exynos->tgl_fd)) {
+               TBM_EXYNOS_LOG("fail to get tgl_version. tgl init failed.\n");
+               close(bufmgr_sprd->tgl_fd);
+               return 0;
        }
+#endif
 
        if (!_tgl_init(bufmgr_exynos->tgl_fd, GLOBAL_KEY)) {
                TBM_EXYNOS_LOG("[libtbm-exynos:%d] "
index f1baa14..f9cbd6f 100644 (file)
@@ -39,38 +39,93 @@ static char tgl_devfile[] = "/dev/slp_global_lock";
 static char tgl_devfile1[] = "/dev/tgl";
 #endif
 
-#define TGL_IOC_BASE                           0x32
+#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)
 
-struct tgl_attribute {
+/**
+ * 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 {
        unsigned int key;
        unsigned int timeout_ms;
 };
 
-struct tgl_user_data {
+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 {
        unsigned int key;
        unsigned int data1;
        unsigned int data2;
-       unsigned int locked;
+       enum tgl_status_data status;
 };
 
-typedef enum {
-       _TGL_INIT_LOCK = 1,
-       _TGL_DESTROY_LOCK,
-       _TGL_LOCK_LOCK,
-       _TGL_UNLOCK_LOCK,
+enum {
+       _TGL_GET_VERSION,
+       _TGL_REGISTER,
+       _TGL_UNREGISTER,
+       _TGL_LOCK,
+       _TGL_UNLOCK,
        _TGL_SET_DATA,
        _TGL_GET_DATA,
-} _tgl_ioctls;
+};
 
-#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 *)
+/* 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)
 
 #ifdef ENABLE_CACHECRTL
-
 /* indicate cache units. */
 enum e_drm_exynos_gem_cache_sel {
        EXYNOS_DRM_L1_CACHE             = 1 << 0,