From e5014610400e16c002cfdd80f8d78a0b7a0e4e3d Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Tue, 21 Jun 2016 12:17:38 +0900 Subject: [PATCH] esm: rewrite with new virtio API Change-Id: Ic0ab82d0fb256d836626ccbfc874929680755f1a Signed-off-by: SeokYeon Hwang --- tizen/src/hw/virtio/maru_virtio_esm.c | 84 +++++++++++++++++------------------ tizen/src/hw/virtio/maru_virtio_esm.h | 1 + 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/tizen/src/hw/virtio/maru_virtio_esm.c b/tizen/src/hw/virtio/maru_virtio_esm.c index 068e17c..099c5be 100644 --- a/tizen/src/hw/virtio/maru_virtio_esm.c +++ b/tizen/src/hw/virtio/maru_virtio_esm.c @@ -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 - * YeongKyoon Lee * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,15 +25,20 @@ * */ -#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 = { diff --git a/tizen/src/hw/virtio/maru_virtio_esm.h b/tizen/src/hw/virtio/maru_virtio_esm.h index 93559e6..0def193 100644 --- a/tizen/src/hw/virtio/maru_virtio_esm.h +++ b/tizen/src/hw/virtio/maru_virtio_esm.h @@ -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" -- 2.7.4