From f73ddbad397f98c1d476ffbf93d65af1cfa796e6 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 14 Mar 2014 14:39:20 +0100 Subject: virtio-input: core code & base class [device] This patch adds virtio-input support to qemu. It brings a abstract base class providing core support, other classes can build on it to actually implement input devices. virtio-input basically sends linux input layer events (evdev) over virtio. Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-input.h | 84 ++++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 85 insertions(+) create mode 100644 include/hw/virtio/virtio-input.h (limited to 'include/hw') diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h new file mode 100644 index 0000000..ad915cc --- /dev/null +++ b/include/hw/virtio/virtio-input.h @@ -0,0 +1,84 @@ +#ifndef _QEMU_VIRTIO_INPUT_H +#define _QEMU_VIRTIO_INPUT_H + +#include "ui/input.h" + +/* ----------------------------------------------------------------- */ +/* virtio input protocol */ + +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_input.h" + +typedef struct virtio_input_absinfo virtio_input_absinfo; +typedef struct virtio_input_config virtio_input_config; +typedef struct virtio_input_event virtio_input_event; + +#if defined(HOST_WORDS_BIGENDIAN) +# define const_le32(_x) bswap32(_x) +# define const_le16(_x) bswap32(_x) +#else +# define const_le32(_x) (_x) +# define const_le16(_x) (_x) +#endif + +/* ----------------------------------------------------------------- */ +/* qemu internals */ + +#define TYPE_VIRTIO_INPUT "virtio-input-device" +#define VIRTIO_INPUT(obj) \ + OBJECT_CHECK(VirtIOInput, (obj), TYPE_VIRTIO_INPUT) +#define VIRTIO_INPUT_GET_PARENT_CLASS(obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT) +#define VIRTIO_INPUT_GET_CLASS(obj) \ + OBJECT_GET_CLASS(VirtIOInputClass, obj, TYPE_VIRTIO_INPUT) +#define VIRTIO_INPUT_CLASS(klass) \ + OBJECT_CLASS_CHECK(VirtIOInputClass, klass, TYPE_VIRTIO_INPUT) + +typedef struct VirtIOInput VirtIOInput; +typedef struct VirtIOInputClass VirtIOInputClass; +typedef struct VirtIOInputConfig VirtIOInputConfig; + +struct virtio_input_conf { + char *serial; +}; + +struct VirtIOInputConfig { + virtio_input_config config; + QTAILQ_ENTRY(VirtIOInputConfig) node; +}; + +struct VirtIOInput { + VirtIODevice parent_obj; + uint8_t cfg_select; + uint8_t cfg_subsel; + uint32_t cfg_size; + QTAILQ_HEAD(, VirtIOInputConfig) cfg_list; + VirtQueue *evt, *sts; + virtio_input_conf input; + + virtio_input_event *queue; + uint32_t qindex, qsize; + + bool active; +}; + +struct VirtIOInputClass { + /*< private >*/ + VirtioDeviceClass parent; + /*< public >*/ + + DeviceRealize realize; + DeviceUnrealize unrealize; + void (*change_active)(VirtIOInput *vinput); + void (*handle_status)(VirtIOInput *vinput, virtio_input_event *event); +}; + +void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event); +void virtio_input_init_config(VirtIOInput *vinput, + virtio_input_config *config); +void virtio_input_add_config(VirtIOInput *vinput, + virtio_input_config *config); +void virtio_input_idstr_config(VirtIOInput *vinput, + uint8_t select, const char *string); + +#endif /* _QEMU_VIRTIO_INPUT_H */ diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 8210cb3..ba74765 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -188,6 +188,7 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val); typedef struct VirtIOBlkConf VirtIOBlkConf; struct virtio_net_conf; typedef struct virtio_serial_conf virtio_serial_conf; +typedef struct virtio_input_conf virtio_input_conf; typedef struct VirtIOSCSIConf VirtIOSCSIConf; typedef struct VirtIORNGConf VirtIORNGConf; -- cgit v1.1 From 55a1d80a41032d6133adec041c0096820beaa1b7 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Tue, 1 Apr 2014 10:06:29 +0200 Subject: virtio-input: emulated devices [device] This patch adds the virtio-input-hid base class and virtio-{keyboard,mouse,tablet} subclasses building on the base class. They are hooked up to the qemu input core and deliver input events to the guest like all other hid devices (ps/2 kbd, usb tablet, ...). Using them is as simple as adding "-device virtio-tablet-device" to your command line, for use all transports except pci. virtio-pci support comes as separate patch, once virtio-pci got virtio 1.0 support. Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-input.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/hw') diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h index ad915cc..a265519 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -34,9 +34,23 @@ typedef struct virtio_input_event virtio_input_event; #define VIRTIO_INPUT_CLASS(klass) \ OBJECT_CLASS_CHECK(VirtIOInputClass, klass, TYPE_VIRTIO_INPUT) +#define TYPE_VIRTIO_INPUT_HID "virtio-input-hid" +#define TYPE_VIRTIO_KEYBOARD "virtio-keyboard" +#define TYPE_VIRTIO_MOUSE "virtio-mouse" +#define TYPE_VIRTIO_TABLET "virtio-tablet" + +#define VIRTIO_INPUT_HID(obj) \ + OBJECT_CHECK(VirtIOInputHID, (obj), TYPE_VIRTIO_INPUT_HID) +#define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HID) + +#define DEFINE_VIRTIO_INPUT_PROPERTIES(_state, _field) \ + DEFINE_PROP_STRING("serial", _state, _field.serial) + typedef struct VirtIOInput VirtIOInput; typedef struct VirtIOInputClass VirtIOInputClass; typedef struct VirtIOInputConfig VirtIOInputConfig; +typedef struct VirtIOInputHID VirtIOInputHID; struct virtio_input_conf { char *serial; @@ -73,6 +87,13 @@ struct VirtIOInputClass { void (*handle_status)(VirtIOInput *vinput, virtio_input_event *event); }; +struct VirtIOInputHID { + VirtIOInput parent_obj; + QemuInputHandler *handler; + QemuInputHandlerState *hs; + int ledstate; +}; + void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event); void virtio_input_init_config(VirtIOInput *vinput, virtio_input_config *config); -- cgit v1.1