/*
* 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 {
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);
}
}
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;
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);
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
- INFO("destroy device\n");
+ LOG_INFO("%s\n", __func__);
virtio_cleanup(vdev);
}
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 = {