From: giwoong.kim Date: Fri, 10 Aug 2012 09:44:29 +0000 (+0900) Subject: [Title] added virtio touchscreen skeleton X-Git-Tag: TizenStudio_2.0_p2.3~1394^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=56f60f97a08fb491ed6aa33605400fed4c43587e;p=sdk%2Femulator%2Fqemu.git [Title] added virtio touchscreen skeleton [Type] feature [Module] Emulator / touch [Priority] major [Jira#] [Redmine#] [Problem] [Cause] performance [Solution] [TestCase] --- diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 48a8d50..f859f79 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -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 */ } }; diff --git a/hw/virtio.h b/hw/virtio.h index 470e3ad..7dd8839 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -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), \ diff --git a/tizen/src/Makefile.tizen b/tizen/src/Makefile.tizen index b0d0a5d..c75e986 100755 --- a/tizen/src/Makefile.tizen +++ b/tizen/src/Makefile.tizen @@ -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 diff --git a/tizen/src/hw/maru_pci_ids.h b/tizen/src/hw/maru_pci_ids.h index af9264e..97bd386 100644 --- a/tizen/src/hw/maru_pci_ids.h +++ b/tizen/src/hw/maru_pci_ids.h @@ -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_ */ diff --git a/tizen/src/hw/maru_touchscreen.c b/tizen/src/hw/maru_touchscreen.c index 4941151..e6ebf27 100644 --- a/tizen/src/hw/maru_touchscreen.c +++ b/tizen/src/hw/maru_touchscreen.c @@ -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 index 0000000..f80d30a --- /dev/null +++ b/tizen/src/hw/maru_virtio_touchscreen.c @@ -0,0 +1,170 @@ +/* + * Maru Virtual Virtio Touchscreen emulation + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: + * GiWoong Kim + * YeongKyoon Lee + * + * 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 +#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 index 0000000..c5a42b5 --- /dev/null +++ b/tizen/src/hw/maru_virtio_touchscreen.h @@ -0,0 +1,37 @@ +/* + * Maru Virtual Virtio Touchscreen emulation + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: + * GiWoong Kim + * YeongKyoon Lee + * + * 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_ */