misc: add Tizen global lock module 03/100103/2
authorInki Dae <inki.dae@samsung.com>
Fri, 25 Nov 2016 05:41:49 +0000 (14:41 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 28 Nov 2016 04:59:52 +0000 (20:59 -0800)
This module is enhanced version - including some refactoring
and bug fixups - of SGL module which resolves rendering order
issue of Utgard DDK.

Change-Id: I94a59232e31fb7bba1be22c463b8c9c469667a8b
Signed-off-by: Inki Dae <inki.dae@samsung.com>
drivers/misc/tizen_global_lock.c
drivers/misc/tizen_global_lock.h

index cc5fb89..6fdd900 100644 (file)
@@ -27,6 +27,9 @@
 
 #define TGL_DEV_NAME           "tgl"
 
+#define TGL_VERSION_MAJOR      1
+#define TGL_VERSION_MINOR      1
+
 #define TGL_HASH_BITS          4
 #define TGL_HASH_BUCKETS       (1 << TGL_HASH_BITS)
 
 /**
  * struct tgl_device - tgl device structure
  * @dev: (misc )device pointer
+ * @version: version data
  * @heads: hash heads for global node data
  * @lock: lock for hash heads
  */
 static struct tgl_device {
        struct device *dev;
 
+       struct tgl_ver_data version;
+
        struct hlist_head heads[TGL_HASH_BUCKETS];
        struct mutex lock;
 } tgl;
@@ -406,6 +412,18 @@ static struct tgl_node *tgl_find_node(struct hlist_head *heads,
        return found;
 }
 
+static int tgl_get_version(struct tgl_session *session, void __user *arg)
+{
+       struct tgl_ver_data ver_data;
+
+       memcpy(&ver_data, &tgl.version, sizeof(ver_data));
+
+       if (copy_to_user(arg, &ver_data, sizeof(ver_data)))
+               return -EFAULT;
+
+       return 0;
+}
+
 static int tgl_register(struct tgl_session *session, void __user *arg)
 {
        struct tgl_reg_data reg_data;
@@ -596,7 +614,6 @@ static int tgl_lock(struct tgl_session *session, void __user *arg)
        }
 
        /* add to waiter */
-       INIT_LIST_HEAD(&wait_node.node);
        mutex_lock(&data->lock);
        list_add_tail(&wait_node.node, &data->list);
        mutex_unlock(&data->lock);
@@ -673,7 +690,7 @@ static int tgl_unlock(struct tgl_session *session, void __user *arg)
                node = tgl_find_node(session->heads, lock_data.key);
                if (node) {
                        /* check waiter */
-                       tgl_remove_wait_node(data, session);
+                       tgl_remove_wait_node(node->data, session);
                        mutex_unlock(&session->lock);
                        return 0;
                }
@@ -766,6 +783,12 @@ static long tgl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        int ret;
 
        switch (cmd) {
+       case TGL_IOCTL_GET_VERSION:
+               ret = tgl_get_version(session, (void __user *)arg);
+               if (ret)
+                       dev_err(tgl.dev,
+                               "%s: failed to get version[%d]\n",
+                               __func__, ret);
        case TGL_IOCTL_REGISTER:
                ret = tgl_register(session, (void __user *)arg);
                if (ret)
@@ -807,8 +830,8 @@ static long tgl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                break;
        default:
                dev_err(tgl.dev,
-                       "%s: failed to call ioctl: tgid[%d]\n",
-                       __func__, task_tgid_nr(current));
+                       "%s: failed to call ioctl: tgid[%d]:0x%x\n",
+                       __func__, task_tgid_nr(current), cmd);
                ret = -ENOTTY;
                break;
        }
@@ -834,8 +857,12 @@ static struct miscdevice tgl_misc_device = {
 
 static int __init tgl_init(void)
 {
+       struct tgl_ver_data *version = &tgl.version;
        int ret, i;
 
+       version->major = TGL_VERSION_MAJOR;
+       version->minor = TGL_VERSION_MINOR;
+
        ret = misc_register(&tgl_misc_device);
        if (ret) {
                pr_err("%s: failed to register misc device[%d]\n",
index 1f3c6b4..6203812 100644 (file)
@@ -10,8 +10,8 @@
  * by the Free Software Foundation.
  */
 
-#ifndef __TGL__
-#define __TGL__
+#ifndef __TIZEN_GLOBAL_LOOK_H__
+#define __TIZEN_GLOBAL_LOOK_H__
 
 #define TGL_IOCTL_BASE         0x32
 #define TGL_IO(nr)             _IO(TGL_IOCTL_BASE, nr)
 #define TGL_IOWR(nr, type)     _IOWR(TGL_IOCTL_BASE, nr, type)
 
 /**
+ * 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 register data structure
  * @key: lookup key
  * @timeout_ms: timeout value for waiting event
@@ -65,7 +75,8 @@ struct tgl_usr_data {
 };
 
 enum {
-       _TGL_REGISTER = 1,
+       _TGL_GET_VERSION,
+       _TGL_REGISTER,
        _TGL_UNREGISTER,
        _TGL_LOCK,
        _TGL_UNLOCK,
@@ -73,6 +84,8 @@ enum {
        _TGL_GET_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 */
@@ -86,4 +99,4 @@ enum {
 /* get user data with key */
 #define TGL_IOCTL_GET_DATA     TGL_IOR(_TGL_GET_DATA, struct tgl_usr_data)
 
-#endif /* __TGL__ */
+#endif /* __TIZEN_GLOBAL_LOOK_H__ */