Revert "Revert "change the slp_global_lock to the tgl"" 89/99789/1
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 24 Nov 2016 05:50:34 +0000 (14:50 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 24 Nov 2016 06:22:25 +0000 (15:22 +0900)
This reverts commit 1b2b409b690224f724eff0581f6d22e76732c443.

Change-Id: Ib1da168fea7009e3185e82a62d5f52a620e284fe

rules/99-libtbm_sprd.rules
src/tbm_bufmgr_sprd.c
src/tbm_bufmgr_tgl.h

index b00652e..13cef12 100644 (file)
@@ -1 +1 @@
-KERNEL=="slp_global_lock*", MODE="0666", GROUP="display", SECLABEL{smack}="*"
+KERNEL=="tgl", MODE="0666", GROUP="display", SECLABEL{smack}="*"
index 1b30142..1db8ac5 100644 (file)
@@ -59,6 +59,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "tbm_bufmgr_tgl.h"
 
 //#define USE_CONTIG_ONLY
+//#define USE_CACHE
 #define USE_DMAIMPORT
 
 #define TBM_COLOR_FORMAT_COUNT 4
@@ -246,25 +247,45 @@ char *STR_OPT[] = {
 
 
 uint32_t tbm_sprd_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
+                                                                       };
+
+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;
+}
+
 
 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_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;
        }
 
@@ -274,13 +295,14 @@ _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_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;
        }
 
@@ -288,15 +310,31 @@ _tgl_destroy(int fd, unsigned int key)
 }
 
 static inline int
-_tgl_lock(int fd, unsigned int key)
+_tgl_lock(int fd, unsigned int key, int opt)
 {
+       struct tgl_lock_data data;
+       enum tgl_type_data tgl_type;
        int err;
 
-       err = ioctl(fd, TGL_IOC_LOCK_LOCK, key);
+       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_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 opt:%d\n",
+                       getpid(), strerror(errno), __func__, __LINE__, key, opt);
                return 0;
        }
 
@@ -306,13 +344,16 @@ _tgl_lock(int fd, unsigned int key)
 static inline int
 _tgl_unlock(int fd, unsigned int key)
 {
+       struct tgl_lock_data data;
        int err;
 
-       err = ioctl(fd, TGL_IOC_UNLOCK_LOCK, key);
+       data.key = key;
+       data.type = TGL_TYPE_NONE;
+
+       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_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
+                       getpid(), strerror(errno), __func__, __LINE__, key);
                return 0;
        }
 
@@ -323,16 +364,16 @@ _tgl_unlock(int fd, unsigned int key)
 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;
 
-       arg.key = key;
-       arg.data1 = val;
-       err = ioctl(fd, TGL_IOC_SET_DATA, &arg);
+       data.key = key;
+       data.data1 = 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_LOG("[libtbm-sprd:%d] error(%s) %s:%d key:%d\n",
+                       getpid(), strerror(errno), __func__, __LINE__, key);
                return 0;
        }
 
@@ -342,22 +383,22 @@ _tgl_set_data(int fd, unsigned int key, unsigned int val)
 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, };
 
-       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_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 = arg.locked;
+               *locked = (unsigned int)data.status;
 
-       return arg.data1;
+       return data.data1;
 }
 #endif
 
@@ -457,7 +498,9 @@ _sprd_bo_cache_flush(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags
        /* 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;
 
@@ -498,7 +541,7 @@ _sprd_bo_cache_flush(tbm_bufmgr_sprd bufmgr_sprd, tbm_bo_sprd bo_sprd, int flags
                              getpid(), __FUNCTION__, __LINE__);
                return 0;
        }
-
+#endif
        return 1;
 }
 #endif
@@ -641,22 +684,26 @@ _bufmgr_init_cache_state(tbm_bufmgr_sprd bufmgr_sprd)
 
        /* 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);
-                       return 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;
        }
 
 #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;
@@ -1474,7 +1521,7 @@ tbm_sprd_bo_lock(tbm_bo bo, int device, int opt)
                     getpid(),
                     __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf);
        } else {
-               ret = _tgl_lock(bufmgr_sprd->tgl_fd, bo_sprd->name);
+               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);
index 2279cac..1790885 100644 (file)
 
 #include <linux/ioctl.h>
 
-static char tgl_devfile[] = "/dev/slp_global_lock";
-static char tgl_devfile1[] = "/dev/tgl";
+static char tgl_devfile[] = "/dev/tgl";
 
-#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)
 
-#endif                                                 /* __TBM_BUFMGR_TGL_H__ */
+#endif /* __TBM_BUFMGR_TGL_H__ */