esm: rewrite with new virtio API
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 21 Jun 2016 03:17:38 +0000 (12:17 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 27 Jun 2016 05:45:21 +0000 (14:45 +0900)
Change-Id: Ic0ab82d0fb256d836626ccbfc874929680755f1a
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/hw/virtio/maru_virtio_esm.c
tizen/src/hw/virtio/maru_virtio_esm.h

index 068e17c8c13f1d32fe80e238938dc9da52bbf30f..099c5be122d050958741ffcf29e805f8b79aa224 100644 (file)
@@ -1,11 +1,10 @@
 /*
  * Virtio EmulatorStatusMedium Device
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2012-2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Contact:
  *  SeokYeon Hwang <syeon.hwang@samsung.com>
- *  YeongKyoon Lee <yeongkyoon.lee@samsung.com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  *
  */
 
-#include "hw/maru_device_ids.h"
 #include "maru_virtio_esm.h"
+
+#include "qemu/iov.h"
+
+#include "hw/maru_device_ids.h"
 #include "emul_state.h"
-#include "debug_ch.h"
 
-MULTI_DEBUG_CHANNEL(qemu, esm);
+#include "util/new_debug_ch.h"
+
+DECLARE_DEBUG_CHANNEL(esm);
 
 #define SYSTEM_MODE_LAYER 1
 #define USER_MODE_LAYER 0
+
 static uint8_t boot_complete;
 
 struct progress_info {
@@ -48,49 +52,42 @@ struct progress_info progress;
 static void virtio_esm_handle(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOESM *vesm = VIRTIO_MARU_ESM(vdev);
-    int index = 0;
 
-    TRACE("virtqueue handler.\n");
+    LOG_TRACE("%s\n", __func__);
     if (virtio_queue_empty(vesm->vq)) {
-        INFO("virtqueue is empty.\n");
+        LOG_SEVERE("virtqueue is empty.\n");
         return;
     }
 
-    // Get a queue buffer.
-    index = virtqueue_pop(vq, &elem);
-    TRACE("virtqueue pop. index: %d\n", index);
-
-    TRACE("virtio element out number : %d\n", elem.out_num);
-    if (elem.out_num != 1) {
-        ERR("virtio element out number is wierd.\n");
-    }
-    else {
-        TRACE("caramis elem.out_sg[0].iov_len : %x\n", elem.out_sg[0].iov_len);
-        TRACE("caramis elem.out_sg[0].iov_base : %x\n", elem.out_sg[0].iov_base);
-        if (elem.out_sg[0].iov_len != 4) {
-            ERR("out lenth is wierd.\n");
+    if (!virtqueue_pop(vq, &elem) || elem.out_num != 1) {
+        LOG_SEVERE("virtqueue is broken or virtio element out number "
+                "is wierd.\n");
+    } else {
+        size_t len = iov_to_buf(elem.out_sg, elem.out_num,
+                0, &progress, sizeof(struct progress_info));
+        if (len != 4) {
+            LOG_SEVERE("out lenth is wierd.\n");
         }
-        else {
-            progress = *((struct progress_info*)elem.out_sg[0].iov_base);
-            TRACE("Boot up progress is [%u] percent done at %s.\n",
+
+        LOG_TRACE("Boot up progress is [%u] percent done at %s.\n",
                 progress.percentage,
-                progress.mode == 's' || progress.mode == 'S' ? "system mode" : "user mode");
-
-            if (progress.mode == 's' || progress.mode == 'S') {
-                if (progress.percentage >= 100) {
-                    boot_complete |= (1 << SYSTEM_MODE_LAYER);
-                }
-            } else {
-                if (progress.percentage >= 100) {
-                    boot_complete |= (1 << USER_MODE_LAYER);
-                }
+                progress.mode == 's' || progress.mode == 'S' ?
+                "system mode" : "user mode");
+
+        if (progress.mode == 's' || progress.mode == 'S') {
+            if (progress.percentage >= 100) {
+                boot_complete |= (1 << SYSTEM_MODE_LAYER);
             }
+        } else {
+            if (progress.percentage >= 100) {
+                boot_complete |= (1 << USER_MODE_LAYER);
+            }
+        }
 
-            /* booting complete check */
-            if ((boot_complete & (1 << SYSTEM_MODE_LAYER)) &&
+        /* booting complete check */
+        if ((boot_complete & (1 << SYSTEM_MODE_LAYER)) &&
                 (boot_complete & (1 << USER_MODE_LAYER))) {
-                set_emulator_condition(BOOT_COMPLETED);
-            }
+            set_emulator_condition(BOOT_COMPLETED);
         }
     }
 
@@ -102,13 +99,13 @@ static void virtio_esm_handle(VirtIODevice *vdev, VirtQueue *vq)
 static uint64_t virtio_esm_get_features(VirtIODevice *vdev,
         uint64_t feature, Error **Errp)
 {
-    TRACE("virtio_esm_get_features.\n");
+    LOG_TRACE("%s\n", __func__);
     return feature;
 }
 
 static void virtio_esm_reset(VirtIODevice* vdev)
 {
-    TRACE("virtio_esm_reset.\n");
+    LOG_TRACE("virtio_esm_reset.\n");
 
     progress.mode = '\0';
     progress.percentage = 0;
@@ -120,7 +117,7 @@ static void virtio_esm_device_realize(DeviceState *dev, Error **errp)
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOESM *vesm = VIRTIO_MARU_ESM(dev);
 
-    INFO("initialize virtio-esm device\n");
+    LOG_INFO("%s\n", __func__);
     virtio_init(vdev, "virtio-esm", VIRTIO_ID_MARU_ESM, 0);
 
     vesm->vq = virtio_add_queue(vdev, 1, virtio_esm_handle);
@@ -132,7 +129,7 @@ static void virtio_esm_device_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 
-    INFO("destroy device\n");
+    LOG_INFO("%s\n", __func__);
     virtio_cleanup(vdev);
 }
 
@@ -142,8 +139,7 @@ static void virtio_esm_class_init(ObjectClass *klass, void *data)
     vdc->realize = virtio_esm_device_realize;
     vdc->unrealize = virtio_esm_device_unrealize;
     vdc->get_features = virtio_esm_get_features;
-    // This device is no need to reset.
-    //vdc->reset = virtio_esm_reset;
+    vdc->reset = virtio_esm_reset;
 }
 
 static const TypeInfo virtio_device_info = {
index 93559e66cc234447494dfed1421df08507345b3c..0def193afa8e04c54fc7e0a859139c23d12175a2 100644 (file)
@@ -33,6 +33,7 @@
 extern "C" {
 #endif
 
+#include "qemu/osdep.h"
 #include "hw/virtio/virtio.h"
 
 #define TYPE_VIRTIO_MARU_ESM "virtio-maru-esm-device"