[Title] added virtio touchscreen skeleton
authorgiwoong.kim <giwoong.kim@samsung.com>
Fri, 10 Aug 2012 09:44:29 +0000 (18:44 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Fri, 10 Aug 2012 12:36:44 +0000 (21:36 +0900)
[Type] feature
[Module] Emulator / touch
[Priority] major
[Jira#]
[Redmine#]
[Problem]
[Cause] performance
[Solution]
[TestCase]

hw/virtio-pci.c
hw/virtio.h
tizen/src/Makefile.tizen
tizen/src/hw/maru_pci_ids.h
tizen/src/hw/maru_touchscreen.c
tizen/src/hw/maru_virtio_touchscreen.c [new file with mode: 0644]
tizen/src/hw/maru_virtio_touchscreen.h [new file with mode: 0644]

index 48a8d50c93ddd3fe17453a53fcc0a3dcacb47aec..f859f797dd335cc9074f465d0b8275581e0c0d91 100644 (file)
@@ -29,6 +29,9 @@
 #include "blockdev.h"
 #include "virtio-pci.h"
 #include "range.h"
+#ifdef CONFIG_MARU
+#include "../tizen/src/hw/maru_pci_ids.h"
+#endif
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -796,6 +799,31 @@ static int virtio_gl_init_pci(PCIDevice *pci_dev)
 }
 #endif
 
+#ifdef CONFIG_MARU
+static int maru_virtio_touchscreen_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev;
+
+    vdev = maru_virtio_touchscreen_init(&pci_dev->qdev);
+    if (!vdev) {
+        return -1;
+    }
+    virtio_init_pci(proxy, vdev);
+    return 0;
+}
+
+static int maru_virtio_touchscreen_exit_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    virtio_pci_stop_ioeventfd(proxy);
+    maru_virtio_touchscreen_exit(proxy->vdev);
+    return virtio_exit_pci(pci_dev);
+}
+#endif
+
+
 static PCIDeviceInfo virtio_info[] = {
     {
         .qdev.name = "virtio-blk-pci",
@@ -897,6 +925,24 @@ static PCIDeviceInfo virtio_info[] = {
                .qdev.reset = virtio_pci_reset,
        },{
 #endif
+
+#ifdef CONFIG_MARU
+        .qdev.name = "virtio-touchscreen-pci",
+        .qdev.alias = "virtio-touchscreen",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = maru_virtio_touchscreen_init_pci,
+        .exit      = maru_virtio_touchscreen_exit_pci,
+        .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+        .device_id = PCI_DEVICE_ID_VIRTUAL_TOUCHSCREEN,
+        .revision  = VIRTIO_PCI_ABI_VERSION,
+        .class_id  = PCI_CLASS_OTHERS,
+        .qdev.props = (Property[]) {
+            DEFINE_PROP_END_OF_LIST(),
+        },
+        .qdev.reset = virtio_pci_reset,
+    },{
+#endif
+
         /* end of list */
     }
 };
index 470e3adb1f8ce2badd57820780f77752bb4bccc7..7dd883943b6d109126c0a034a878e9efb616a38d 100644 (file)
@@ -210,6 +210,13 @@ void virtio_blk_exit(VirtIODevice *vdev);
 void virtio_serial_exit(VirtIODevice *vdev);
 void virtio_balloon_exit(VirtIODevice *vdev);
 
+/* Maru devices */
+#ifdef CONFIG_MARU
+VirtIODevice *maru_virtio_touchscreen_init(DeviceState *dev);
+void maru_virtio_touchscreen_exit(VirtIODevice *vdev);
+#endif
+
+
 #define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
        DEFINE_PROP_BIT("indirect_desc", _state, _field, \
                        VIRTIO_RING_F_INDIRECT_DESC, true), \
index b0d0a5d99bae50aaca3ee867284a53da0c027bc5..c75e98615f4dcafbf0116a96eeedae34da7df9a3 100755 (executable)
@@ -85,7 +85,7 @@ endif
 obj-i386-y += maru_pm.o
 obj-i386-y += maru_vga.o
 obj-i386-y += maru_brightness.o
-obj-i386-y += maru_touchscreen.o
+obj-i386-y += maru_touchscreen.o maru_virtio_touchscreen.o
 
 # FIXME: camera disabled
 ifndef CONFIG_DARWIN
index af9264e7fab29587827b111c5416bf9c63090030..97bd386454f444b8c166cc845107aab14ffa0548 100644 (file)
@@ -45,5 +45,9 @@
 #define PCI_DEVICE_ID_VIRTUAL_BRIGHTNESS 0x1014
 #define PCI_DEVICE_ID_VIRTUAL_CAMERA     0x1018
 #define PCI_DEVICE_ID_VIRTUAL_CODEC      0x101C
+#define PCI_DEVICE_ID_VIRTUAL_TOUCHSCREEN 0x101D
+
+
+#define VIRTIO_ID_TOUCHSCREEN 10
 
 #endif /* MARU_PCI_IDS_H_ */
index 49411510d398c898a55ac30b73973b5849b04a6c..e6ebf27a325f9e7b13c23928b0c1842b4387f3de 100644 (file)
@@ -32,7 +32,7 @@
 #include "maru_touchscreen.h"
 #include "debug_ch.h"
 
-MULTI_DEBUG_CHANNEL(qemu, touchscreen);
+MULTI_DEBUG_CHANNEL(qemu, usb_touchscreen);
 
 
 #define MAX_TOUCH_EVENT_CNT 128
diff --git a/tizen/src/hw/maru_virtio_touchscreen.c b/tizen/src/hw/maru_virtio_touchscreen.c
new file mode 100644 (file)
index 0000000..f80d30a
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Maru Virtual Virtio Touchscreen emulation
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  GiWoong Kim <giwoong.kim@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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+#include <pthread.h>
+#include "maru_virtio_touchscreen.h"
+#include "maru_pci_ids.h"
+#include "debug_ch.h"
+
+MULTI_DEBUG_CHANNEL(qemu, touchscreen);
+
+
+#define DEVICE_NAME "virtio-touchscreen"
+#define MAX_TOUCH_EVENT_CNT 128
+
+/* This structure must match the kernel definitions */
+typedef struct EmulTouchState {
+    uint16_t x, y, z;
+    uint8_t state;
+} EmulTouchState;
+
+typedef struct TouchEventEntry {
+    int index;
+    EmulTouchState touch;
+
+    QTAILQ_ENTRY(TouchEventEntry) node;
+} TouchEventEntry;
+
+static TouchEventEntry _events_buf[MAX_TOUCH_EVENT_CNT];
+static QTAILQ_HEAD(, TouchEventEntry) events_queue =
+    QTAILQ_HEAD_INITIALIZER(events_queue);
+
+static unsigned int ringbuf_cnt; // _events_buf
+static unsigned int queue_cnt; // events_queue
+
+
+typedef struct TouchscreenState
+{
+    VirtIODevice *vdev;
+    VirtQueue *vq;
+
+    // TODO:
+    unsigned int *queue_cnt;
+} TouchscreenState;
+TouchscreenState touchscreen_state;
+
+typedef struct VirtIOTouchscreen
+{
+    VirtIODevice vdev;
+    VirtQueue *vq;
+    DeviceState *qdev;
+
+    TouchscreenState *dev_state;
+} VirtIOTouchscreen;
+
+
+// lock for between communication thread and IO thread
+static pthread_mutex_t event_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void maru_mouse_to_touchevent(int x, int y, int z, int buttons_state)
+{
+    TouchEventEntry *te = NULL;
+
+    pthread_mutex_lock(&event_mutex);
+
+    if (queue_cnt >= MAX_TOUCH_EVENT_CNT) {
+        pthread_mutex_unlock(&event_mutex);
+        INFO("full touch event queue, lose event\n", queue_cnt);
+        return;
+    }
+
+    te = &(_events_buf[ringbuf_cnt % MAX_TOUCH_EVENT_CNT]);
+    ringbuf_cnt++;
+
+    /* mouse event is copied into the queue */
+    te->index = ++queue_cnt; // 1 ~
+    te->touch.x = x;
+    te->touch.y = y;
+    te->touch.z = z;
+    te->touch.state = buttons_state;
+
+    QTAILQ_INSERT_TAIL(&events_queue, te, node);
+
+    pthread_mutex_unlock(&event_mutex);
+
+    TRACE("touch event (%d) : x=%d, y=%d, z=%d, state=%d\n",
+            te->index, te->touch.x, te->touch.y, te->touch.z, te->touch.state);
+
+    // TODO:
+
+    virtio_notify(touchscreen_state.vdev, touchscreen_state.vq);
+}
+
+static void maru_virtio_touchscreen_handle(VirtIODevice *vdev, VirtQueue *vq)
+{
+}
+
+static uint32_t virtio_touchscreen_get_features(VirtIODevice *vdev, uint32_t request_features)
+{
+    // TODO:
+    return request_features;
+}
+
+VirtIODevice *maru_virtio_touchscreen_init(DeviceState *dev)
+{
+    VirtIOTouchscreen *s = NULL;
+
+    INFO("initialize the touchscreen device\n");
+    s = (VirtIOTouchscreen *)virtio_common_init(DEVICE_NAME,
+        VIRTIO_ID_TOUCHSCREEN, 0 /*check*/, sizeof(VirtIOTouchscreen));
+
+    if (s == NULL) {
+        ERR("failed to initialize the touchscreen device\n");
+        return NULL;
+    }
+
+    s->vdev.get_features = virtio_touchscreen_get_features;
+    s->vq = virtio_add_queue(&s->vdev, 128 /*check*/, maru_virtio_touchscreen_handle);
+
+    s->qdev = dev;
+
+    touchscreen_state.vdev = &(s->vdev);
+    touchscreen_state.vq = s->vq;
+    s->dev_state = &touchscreen_state;
+    /* reset the event counter */
+    queue_cnt = ringbuf_cnt = 0;
+
+    return &s->vdev;
+}
+
+void maru_virtio_touchscreen_exit(VirtIODevice *vdev)
+{
+    //VirtIOTouchscreen *s = DO_UPCAST(VirtIOTouchscreen, vdev, vdev);
+
+    virtio_cleanup(vdev);
+}
+
+#if 0 // moved to virtio-pci.c
+static void virtio_register_touchscreen(void)
+{
+    pci_qdev_register(virtio_info);
+}
+
+device_init(virtio_register_touchscreen);
+#endif
diff --git a/tizen/src/hw/maru_virtio_touchscreen.h b/tizen/src/hw/maru_virtio_touchscreen.h
new file mode 100644 (file)
index 0000000..c5a42b5
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Maru Virtual Virtio Touchscreen emulation
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  GiWoong Kim <giwoong.kim@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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef MARU_TOUCHSCREEN_H_
+#define MARU_TOUCHSCREEN_H_
+
+#include "virtio.h"
+
+void maru_mouse_to_touchevent(int x, int y, int z, int buttons_state);
+
+#endif /* MARU_TOUCHSCREEN_H_ */