virtio-esm: merged virtio-esm.
authorKitae Kim <kt920.kim@samsung.com>
Tue, 9 Jul 2013 13:09:09 +0000 (22:09 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Tue, 9 Jul 2013 13:09:09 +0000 (22:09 +0900)
Change-Id: I16023c102e0cd56b0ae852519521d31f0a52f58a
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
tizen/src/hw/maru_virtio_esm.c

index 0625f9e..03c550b 100644 (file)
@@ -36,7 +36,7 @@ MULTI_DEBUG_CHANNEL(qemu, virtio-esm);
 #define VIRTIO_ESM_DEVICE_NAME "virtio-guest-status-medium"
 
 struct progress_info {
-       uint16_t percentage;
+    uint16_t percentage;
 };
 
 #if 0
@@ -52,7 +52,7 @@ struct progress_info progress;
 
 static void virtio_esm_handle(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOESM *vesm = (VirtIOESM *)vdev;
+    VirtIOESM *vesm = VIRTIO_ESM(vdev);
     int index = 0;
 
     TRACE("virtqueue handler.\n");
@@ -88,36 +88,60 @@ static void virtio_esm_handle(VirtIODevice *vdev, VirtQueue *vq)
     virtio_notify(&vesm->vdev, vesm->vq);
 }
 
-static uint32_t virtio_esm_get_features(VirtIODevice *vdev,
-                                            uint32_t request_feature)
+static void virtio_esm_reset(VirtIODevice *vdev)
+{
+    TRACE("virtio_esm_reset.\n");
+}
+
+static uint32_t virtio_esm_get_features(VirtIODevice *vdev, uint32_t feature)
 {
     TRACE("virtio_esm_get_features.\n");
-    return 0;
+    return feature;
 }
 
-VirtIODevice *virtio_esm_init(DeviceState *dev)
+static int virtio_esm_device_init(VirtIODevice *vdev)
 {
-    VirtIOESM *vesm;
-    INFO("initialize virtio-esm device\n");
+//    DeviceState *qdev = DEVICE(vdev);
+    VirtIOESM *vesm = VIRTIO_ESM(vdev);
 
-    vesm = (VirtIOESM *)virtio_common_init("virtio-esm",
-            VIRTIO_ID_ESM, 0, sizeof(VirtIOESM));
-    if (vesm == NULL) {
-        ERR("failed to initialize device\n");
-        return NULL;
-    }
+    INFO("initialize virtio-esm device\n");
+    virtio_init(vdev, "virtio-esm", VIRTIO_ID_ESM, 0);
 
-    vesm->vdev.get_features = virtio_esm_get_features;
-    vesm->vq = virtio_add_queue(&vesm->vdev, 1, virtio_esm_handle);
-    vesm->qdev = dev;
+    vesm->vq = virtio_add_queue(vdev, 1, virtio_esm_handle);
 
-    return &vesm->vdev;
+    return 0;
 }
 
-void virtio_esm_exit(VirtIODevice *vdev)
+static int virtio_esm_device_exit(DeviceState *dev)
 {
-    INFO("destroy device\n");
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 
+    INFO("destroy device\n");
     virtio_cleanup(vdev);
+
+    return 0;
+}
+
+static void virtio_esm_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_esm_device_exit;
+    vdc->init = virtio_esm_device_init;
+    vdc->get_features = virtio_esm_get_features;
+    vdc->reset = virtio_esm_reset;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_ESM,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOESM),
+    .class_init = virtio_esm_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_device_info);
 }
 
+type_init(virtio_register_types)