virtio-hwkey: modified structure of virtio-hwkey
authorsungmin ha <sungmin82.ha@samsung.com>
Thu, 25 Jul 2013 07:36:35 +0000 (16:36 +0900)
committersungmin ha <sungmin82.ha@samsung.com>
Thu, 25 Jul 2013 07:36:35 +0000 (16:36 +0900)
Change-Id: Ie1140f9c0ac52e61f73910f7d236d1ef54ac064d
Signed-off-by: Sungmin Ha <sungmin82.ha@samsung.com>
drivers/maru/maru_virtio_hwkey.c
package/changelog
package/pkginfo.manifest

index 937f8601f845dc97c8ca20aede976c8535fc442b..479b01023e74a91ad60324a53d747ab8bb333288 100644 (file)
@@ -44,20 +44,27 @@ MODULE_AUTHOR("Sungmin Ha <sungmin82.ha@samsung.com>");
 MODULE_DESCRIPTION("Emulator Virtio Hwkey driver");
 
 #define DEVICE_NAME "virtio-hwkey"
+#define MAX_BUF_COUNT 64
+static int vqidx = 0;
 
 /* This structure must match the qemu definitions */
 typedef struct EmulHwkeyEvent {
     uint8_t event_type;
     uint32_t keycode;
 } EmulHwkeyEvent;
-static EmulHwkeyEvent *event;
 
 typedef struct virtio_hwkey
 {
     struct virtio_device *vdev;
     struct virtqueue *vq;
     struct input_dev *idev;
+
+    struct scatterlist sg[MAX_BUF_COUNT];
+    struct EmulHwkeyEvent vbuf[MAX_BUF_COUNT];
+
+    struct mutex event_mutex;
 } virtio_hwkey;
+
 virtio_hwkey *vh;
 
 static struct virtio_device_id id_table[] = {
@@ -65,10 +72,6 @@ static struct virtio_device_id id_table[] = {
     { 0 },
 };
 
-#define MAX_BUF_COUNT 10
-static struct scatterlist sg[MAX_BUF_COUNT];
-static EmulHwkeyEvent vbuf[MAX_BUF_COUNT];
-
 /* keep it consistent with emulator-skin definition */
 enum {  
     KEY_PRESSED = 1,
@@ -76,36 +79,28 @@ enum {
 };
 
 static int err = 0;
-static unsigned int len = 0; /* not used */
 static unsigned int index = 0;
-static unsigned int recv_index = 0;
 
 /**
 * @brief : callback for virtqueue
 */
 static void vq_hwkey_callback(struct virtqueue *vq)
 {
+    struct EmulHwkeyEvent hwkey_event;
 #if 0
     printk(KERN_INFO "vq hwkey callback\n");
 #endif
-
-    recv_index = (unsigned int)virtqueue_get_buf(vh->vq, &len);
-    if (recv_index == 0) {
-        printk(KERN_ERR "failed to get buffer\n");
-        return;
-    }
-
-    do {
-        event = &vbuf[recv_index - 1];
-#if 0
-        printk(KERN_INFO "hwkey event_type=%d, keycodey=%d, recv_index=%d\n",
-            event->event_type, event->keycode, recv_index);
-#endif
-        if (event->event_type == KEY_PRESSED) { /* pressed */
-          input_event(vh->idev, EV_KEY, event->keycode, true);
+    while (1) {
+        memcpy(&hwkey_event, &vh->vbuf[vqidx], sizeof(hwkey_event));
+        if (hwkey_event.event_type == 0) {
+            break;
         }
-        else if (event->event_type == KEY_RELEASED) { /* released */
-          input_event(vh->idev, EV_KEY, event->keycode, false);
+        printk(KERN_ERR "keycode: %d, event_type: %d, vqidx: %d\n", hwkey_event.keycode, hwkey_event.event_type, vqidx);
+        if (hwkey_event.event_type == KEY_PRESSED) {
+          input_event(vh->idev, EV_KEY, hwkey_event.keycode, true);
+        }
+        else if (hwkey_event.event_type == KEY_RELEASED) {
+          input_event(vh->idev, EV_KEY, hwkey_event.keycode, false);
         }
         else {
           printk(KERN_ERR "Unknown event type\n");
@@ -113,20 +108,12 @@ static void vq_hwkey_callback(struct virtqueue *vq)
         }
 
         input_sync(vh->idev);
-
-        /* expose buffer to other end */
-        err = virtqueue_add_buf(vh->vq, sg, 0,
-            recv_index, (void *)recv_index, GFP_ATOMIC);
-
-        if (err < 0) {
-            printk(KERN_ERR "failed to add buffer!\n");
-        }
-
-        recv_index = (unsigned int)virtqueue_get_buf(vh->vq, &len);
-        if (recv_index == 0) {
-            break;
+        memset(&vh->vbuf[vqidx], 0x00, sizeof(hwkey_event));
+        vqidx++;
+        if (vqidx == MAX_BUF_COUNT) {
+            vqidx = 0;
         }
-    } while(true);
+    }
 
     virtqueue_kick(vh->vq);
 }
@@ -163,6 +150,7 @@ struct file_operations virtio_hwkey_fops = {
 static int virtio_hwkey_probe(struct virtio_device *vdev)
 {
     int ret = 0;
+    vqidx = 0;
 
     printk(KERN_INFO "virtio hwkey driver is probed\n");
 
@@ -171,11 +159,11 @@ static int virtio_hwkey_probe(struct virtio_device *vdev)
     if (!vh) {
         return -ENOMEM;
     }
+    memset(&vh->vbuf, 0x00, sizeof(vh->vbuf));
 
     vh->vdev = vdev;
 
-    vh->vq = virtio_find_single_vq(vh->vdev,
-        vq_hwkey_callback, "virtio-hwkey-vq");
+    vh->vq = virtio_find_single_vq(vh->vdev, vq_hwkey_callback, "virtio-hwkey-vq");
     if (IS_ERR(vh->vq)) {
         ret = PTR_ERR(vh->vq);
 
@@ -187,14 +175,11 @@ static int virtio_hwkey_probe(struct virtio_device *vdev)
     /* enable callback */
     virtqueue_enable_cb(vh->vq);
 
-    sg_init_table(sg, MAX_BUF_COUNT);
+    sg_init_table(vh->sg, MAX_BUF_COUNT);
 
     /* prepare the buffers */
     for (index = 0; index < MAX_BUF_COUNT; index++) {
-        sg_set_buf(&sg[index], &vbuf[index], sizeof(EmulHwkeyEvent));
-
-        err = virtqueue_add_buf(vh->vq, sg, 0,
-            index + 1, (void *)index + 1, GFP_ATOMIC);
+        sg_set_buf(&vh->sg[index], &vh->vbuf[index], sizeof(EmulHwkeyEvent));
 
         if (err < 0) {
             printk(KERN_ERR "failed to add buffer\n");
@@ -205,6 +190,9 @@ static int virtio_hwkey_probe(struct virtio_device *vdev)
         }
     }
 
+    err = virtqueue_add_buf(vh->vq, vh->sg, 0,
+            MAX_BUF_COUNT, (void *)MAX_BUF_COUNT, GFP_ATOMIC);
+
     /* register for input device */
     vh->idev = input_allocate_device();
     if (!vh->idev) {
index c6e827d5e8bafa4eb7d0512d06b0d131e4deea7b..bdb48e3a04922d5d8392145607802726af342bb1 100644 (file)
@@ -1,3 +1,6 @@
+* 1.4.24
+- modified structure of virtio-hwkey
+== Sungmin Ha <sungmin82.ha@samsung.com> 2013-07-25
 * 1.4.23
 - fixed one of Smack bugs which is about IP packet access check.
 == Kitae Kim <kt920.kim@samsung.com> 2013-06-28
index 9c3b864e54aed58c3e3549de427dfaf852ae2cd0..96f8e28bf2f2a5dcee42bf5fd9f66239000252d7 100644 (file)
@@ -1,4 +1,4 @@
-Version: 1.4.23
+Version: 1.4.24
 Maintainer: Yeong-Kyoon, Lee <yeongkyoon.lee@samsung.com>
 Source: emulator-kernel