evdi : emulator virtual device interface is added
authorDaiYoung Kim <daiyoung777.kim@samsung.com>
Sat, 6 Apr 2013 11:52:58 +0000 (20:52 +0900)
committerDaiYoung Kim <daiyoung777.kim@samsung.com>
Sat, 6 Apr 2013 11:52:58 +0000 (20:52 +0900)
evdi is added.
incharge of communicating between guest and host.
virt-io pci is supported.

Signed-off-by : DaiYoung, Kim <daiyoung777.kim@samsung.com>

hw/virtio-pci.c [changed mode: 0644->0755]
tizen/src/Makefile.tizen
tizen/src/hw/maru_device_ids.h [changed mode: 0644->0755]
tizen/src/hw/maru_virtio_evdi.c [new file with mode: 0755]
tizen/src/hw/maru_virtio_evdi.h [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index eb6e236..f8ad834
@@ -35,6 +35,7 @@
 #include "range.h"
 #ifdef CONFIG_MARU
 #include "../tizen/src/hw/maru_device_ids.h"
+#include "../tizen/src/hw/maru_virtio_evdi.h"
 #include "../tizen/src/mloop_event.h"
 #endif
 
@@ -993,6 +994,28 @@ static void virtio_hwkey_exit_pci(PCIDevice *pci_dev)
     virtio_exit_pci(pci_dev);
 }
 
+static int virtio_evdi_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev;
+
+    vdev = virtio_evdi_init(&pci_dev->qdev);
+    if (!vdev) {
+        return -1;
+    }
+    virtio_init_pci(proxy, vdev);
+    return 0;
+}
+
+static void virtio_evdi_exit_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    virtio_pci_stop_ioeventfd(proxy);
+    virtio_evdi_exit(proxy->vdev);
+    virtio_exit_pci(pci_dev);
+}
+
 #endif
 
 static Property virtio_blk_properties[] = {
@@ -1290,6 +1313,27 @@ static TypeInfo virtio_hwkey_info = {
     .class_init    = virtio_hwkey_class_init,
 };
 
+static void virtio_evdi_class_init(ObjectClass *klass, void *data) {
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = virtio_evdi_init_pci;
+    k->exit = virtio_evdi_exit_pci;
+    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    k->device_id = PCI_DEVICE_ID_VIRTIO_EVDI;
+    k->revision = VIRTIO_PCI_ABI_VERSION;
+    k->class_id = PCI_CLASS_OTHERS;
+    dc->reset = virtio_pci_reset;
+}
+
+static TypeInfo virtio_evdi_info = {
+    .name          = "virtio-evdi-pci",
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VirtIOPCIProxy),
+    .class_init    = virtio_evdi_class_init,
+};
+
+
 #endif /* CONFIG_MARU */
 
 static void virtio_pci_register_types(void)
@@ -1307,6 +1351,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_keyboard_info);
     type_register_static(&virtio_esm_info);
     type_register_static(&virtio_hwkey_info);
+    type_register_static(&virtio_evdi_info);
 #endif
 }
 
index 292f4621a1ed2e4c52b4f7d22cb0d2a19d07c1f4..5b90201622f3eed793de819d9ae454e5a68734a4 100755 (executable)
@@ -113,6 +113,7 @@ obj-y += maru_virtio_keyboard.o
 obj-y += maru_codec.o
 obj-y += maru_virtio_esm.o
 obj-y += maru_virtio_hwkey.o
+obj-y += maru_virtio_evdi.o
 
 obj-$(CONFIG_PCI) += maru_camera_common_pci.o
 obj-$(CONFIG_LINUX) += maru_camera_linux_pci.o
old mode 100644 (file)
new mode 100755 (executable)
index 8a2a0bd..47a2fda
@@ -12,6 +12,7 @@
  * SungMin Ha <sungmin82.ha@samsung.com>
  * JiHye Kim <jihye1128.kim@samsung.com>
  * GiWoong Kim <giwoong.kim@samsung.com>
+ * DaiYoung Kim <daiyoung777.kim@samsung.com>
  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
  * DongKyun Yun
  * DoHyung Hong
@@ -52,6 +53,7 @@
 #define PCI_DEVICE_ID_VIRTIO_KEYBOARD    0x1020
 #define PCI_DEVICE_ID_VIRTIO_ESM         0x1024
 #define PCI_DEVICE_ID_VIRTIO_HWKEY       0x1028
+#define PCI_DEVICE_ID_VIRTIO_EVDI        0x1028
 
 /* Virtio */
 /*
@@ -84,5 +86,6 @@
 #define VIRTIO_ID_KEYBOARD      12
 #define VIRTIO_ID_ESM           13
 #define VIRTIO_ID_HWKEY         14
+#define VIRTIO_ID_EVDI          15
 
 #endif /* MARU_DEVICE_IDS_H_ */
diff --git a/tizen/src/hw/maru_virtio_evdi.c b/tizen/src/hw/maru_virtio_evdi.c
new file mode 100755 (executable)
index 0000000..01d54eb
--- /dev/null
@@ -0,0 +1,196 @@
+/*\r
+ * Virtio EmulatorVirtualDeviceInterface Device\r
+ *\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Contact:\r
+ *  DaiYoung Kim <daiyoung777.kim.hwang@samsung.com>\r
+ *  YeongKyoon Lee <yeongkyoon.lee@samsung.com>\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
+ *\r
+ * Contributors:\r
+ * - S-Core Co., Ltd\r
+ *\r
+ */\r
+\r
+#include "maru_device_ids.h"\r
+#include "maru_virtio_evdi.h"\r
+#include "debug_ch.h"\r
+\r
+MULTI_DEBUG_CHANNEL(qemu, virtio-evdi);\r
+\r
+#define VIRTIO_EVDI_DEVICE_NAME "virtio-evdi"\r
+\r
+#define __MAX_BUF_SIZE 1024\r
+\r
+enum {\r
+       IOTYPE_INPUT = 0,\r
+       IOTYPE_OUTPUT = 1\r
+};\r
+\r
+struct msg_info {\r
+       char buf[__MAX_BUF_SIZE];\r
+       uint32_t use;\r
+};\r
+\r
+typedef struct VirtIO_EVDI{\r
+    VirtIODevice    vdev;\r
+    VirtQueue       *rvq;\r
+    VirtQueue          *svq;\r
+    DeviceState     *qdev;\r
+\r
+    QEMUBH *bh;\r
+} VirtIO_EVDI;\r
+\r
+\r
+VirtIO_EVDI* vio_evdi;\r
+\r
+static int g_cnt = 0;\r
+\r
+static void virtio_evdi_recv(VirtIODevice *vdev, VirtQueue *vq)\r
+{\r
+    int index = 0;\r
+\r
+    struct msg_info _msg;\r
+\r
+    INFO(">> evdirecv : virtio_evdi_recv\n");\r
+\r
+       if (unlikely(virtio_queue_empty(vio_evdi->rvq))) {\r
+               INFO(">> evdirecv : virtqueue is empty\n");\r
+               return;\r
+       }\r
+\r
+    VirtQueueElement elem;\r
+\r
+    while ((index = virtqueue_pop(vq, &elem))) {\r
+\r
+       INFO(">> evdirecv : virtqueue_pop. index: %d\n", index);\r
+       INFO(">> evdirecv : element out_num : %d, in_num : %d\n", elem.out_num, elem.in_num);\r
+\r
+       if (index == 0) {\r
+               INFO("evdirecv : virtqueue break\n");\r
+                       break;\r
+               }\r
+\r
+       INFO(">> evdirecv : received use = %d, iov_len = %d\n", _msg.use, elem.in_sg[0].iov_len);\r
+\r
+       memcpy(&_msg, elem.in_sg[0].iov_base,  elem.in_sg[0].iov_len);\r
+\r
+\r
+       if (g_cnt < 10)\r
+       {\r
+                       memset(&_msg, 0x00, sizeof(_msg));\r
+                       sprintf(_msg.buf, "test_%d\n", g_cnt++);\r
+                       memcpy(elem.in_sg[0].iov_base, &_msg, sizeof(struct msg_info));\r
+\r
+                       INFO(">> evdirecv : send to guest msg use = %d, msg = %s, iov_len = %d \n",\r
+                                       _msg.use, _msg.buf, elem.in_sg[0].iov_len);\r
+\r
+\r
+                       virtqueue_push(vq, &elem, sizeof(VirtIO_EVDI));\r
+                       virtio_notify(&vio_evdi->vdev, vq);\r
+       }\r
+       }\r
+\r
+    INFO("enf of virtio_evdi_recv\n");\r
+}\r
+\r
+\r
+static void virtio_evdi_send(VirtIODevice *vdev, VirtQueue *vq)\r
+{\r
+       VirtIO_EVDI *vevdi = (VirtIO_EVDI *)vdev;\r
+    int index = 0;\r
+    struct msg_info _msg;\r
+\r
+    INFO("<< evdisend : virtio_evdi_send \n");\r
+    if (virtio_queue_empty(vevdi->svq)) {\r
+        INFO("<< evdisend : virtqueue is empty.\n");\r
+        return;\r
+    }\r
+\r
+    VirtQueueElement elem;\r
+\r
+    while ((index = virtqueue_pop(vq, &elem))) {\r
+\r
+               INFO("<< evdisend : virtqueue pop. index: %d\n", index);\r
+               INFO("<< evdisend : element out_num : %d, in_num : %d\n", elem.out_num, elem.in_num);\r
+\r
+               if (index == 0) {\r
+                       INFO("<< evdisend : virtqueue break\n");\r
+                       break;\r
+               }\r
+\r
+               INFO("<< evdisend : use=%d, iov_len = %d\n", _msg.use, elem.out_sg[0].iov_len);\r
+\r
+               memset(&_msg, 0x00, sizeof(_msg));\r
+               memcpy(&_msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len);\r
+\r
+               INFO("<< evdisend : recv from guest len = %d, msg = %s \n", _msg.use, _msg.buf);\r
+    }\r
+\r
+       virtqueue_push(vq, &elem, sizeof(VirtIO_EVDI));\r
+       virtio_notify(&vio_evdi->vdev, vq);\r
+}\r
+\r
+static void maru_virtio_evdi_notify(void)\r
+{\r
+       TRACE("nothing to do.\n");\r
+}\r
+\r
+static uint32_t virtio_evdi_get_features(VirtIODevice *vdev,\r
+                                            uint32_t request_feature)\r
+{\r
+    TRACE("virtio_evdi_get_features.\n");\r
+    return 0;\r
+}\r
+\r
+static void maru_evdi_bh(void *opaque)\r
+{\r
+    maru_virtio_evdi_notify();\r
+}\r
+\r
+VirtIODevice *virtio_evdi_init(DeviceState *dev)\r
+{\r
+    INFO("initialize evdi device\n");\r
+\r
+    vio_evdi = (VirtIO_EVDI *)virtio_common_init(VIRTIO_EVDI_DEVICE_NAME,\r
+            VIRTIO_ID_EVDI, 0, sizeof(VirtIO_EVDI));\r
+    if (vio_evdi == NULL) {\r
+        ERR("failed to initialize evdi device\n");\r
+        return NULL;\r
+    }\r
+\r
+    vio_evdi->vdev.get_features = virtio_evdi_get_features;\r
+    vio_evdi->rvq = virtio_add_queue(&vio_evdi->vdev, 256, virtio_evdi_recv);\r
+    vio_evdi->svq = virtio_add_queue(&vio_evdi->vdev, 256, virtio_evdi_send);\r
+    vio_evdi->qdev = dev;\r
+\r
+    vio_evdi->bh = qemu_bh_new(maru_evdi_bh, vio_evdi);\r
+\r
+    return &vio_evdi->vdev;\r
+}\r
+\r
+void virtio_evdi_exit(VirtIODevice *vdev)\r
+{\r
+    INFO("destroy evdi device\n");\r
+\r
+    if (vio_evdi->bh) {\r
+            qemu_bh_delete(vio_evdi->bh);\r
+        }\r
+\r
+    virtio_cleanup(vdev);\r
+}\r
+\r
diff --git a/tizen/src/hw/maru_virtio_evdi.h b/tizen/src/hw/maru_virtio_evdi.h
new file mode 100755 (executable)
index 0000000..ad88b68
--- /dev/null
@@ -0,0 +1,26 @@
+/*\r
+ * maru_virtio_evdi.h\r
+ *\r
+ *  Created on: 2013. 3. 30.\r
+ *      Author: dykim\r
+ */\r
+\r
+#ifndef MARU_VIRTIO_EVDI_H_\r
+#define MARU_VIRTIO_EVDI_H_\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "hw/virtio.h"\r
+\r
+VirtIODevice *virtio_evdi_init(DeviceState *dev);\r
+\r
+void virtio_evdi_exit(VirtIODevice *vdev);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif /* MARU_VIRTIO_EVDI_H_ */\r