virtio-input: property fixes, add evdev passthrough

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJViRnZAAoJEEy22O7T6HE4hDEQANzlyRg5+m6WIJUbUY6LxSC3
 vv+NSErbtsd0EXIO1HaT9tgbtYbq5z/r1AFjsd1pdkb71AX4V3KttSIf+J5jKlbR
 NWJ4P8dAclVZvk4EoaHeYcnWtH/3v7vjBw7iZGh8k8Jd0Jf0bAQhtHXcw/BdU6OI
 E1AQ7ZE6wEK+h2H/VJraeNn76crjPCzudqCahTXXAg0fThSVM9yLWtTEwX5YHpzO
 qbNWONhRrl1xrhWZloIilVboU47PWzCGFuUsZzyRh6/urxw9Mt0ZjgRJO2nWvwTd
 8KZXb9eU5YqeF6RUxg4Y4xx6SgbTnVF6TESorgV4pu/8KPaxugwmUHwKz5O1uTnM
 uIx+EYtcBIL8F8ObsfvYCqLdF86Cqe5VguHbvHRBSY8eI2wqurUzFROhNMAXN297
 0TK1paBPunI7IvVcuS7j6rR6OUIQS3rhYbe/TMXYr9bjdQ8uRgyO03i6qOWQ5D8n
 7fVQq2DESkwYtP7RiDGZ1EiEC0Dcmxrnw+CJhAajiQ4llM8WmPfs+LFWahQoGHXJ
 nDnDKe9SS6UrMaTKEEdDRli7RR9GSbIrq+7P43cVCLkepD6jSGWxCX3yVCTuEwM7
 WFD4EsutkGfhKIGIDCd4Qc/QT55U/mTSQ7ZaC3GgmfGxZKBP7Dupr3vQOcg5C8eU
 XEwT3BZQp1+suA11tdXZ
 =QME2
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/kraxel/tags/pull-input-20150623-1' into staging

virtio-input: property fixes, add evdev passthrough

# gpg: Signature made Tue Jun 23 09:33:29 2015 BST using RSA key ID D3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"

* remotes/kraxel/tags/pull-input-20150623-1:
  Add MAINTAINERS entry for virtio-input
  virtio-input: evdev passthrough
  virtio-input: move properties, use virtio_instance_init_common

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2015-06-23 13:32:50 +01:00
commit 6966b2a071
7 changed files with 252 additions and 24 deletions

View File

@ -728,6 +728,12 @@ S: Supported
F: hw/s390x/virtio-ccw.[hc]
T: git git://github.com/cohuck/qemu virtio-ccw-upstr
virtio-input
M: Gerd Hoffmann <kraxel@redhat.com>
S: Maintained
F: hw/input/virtio-input*.c
F: include/hw/virtio/virtio-input.h
virtio-serial
M: Amit Shah <amit.shah@redhat.com>
S: Supported

View File

@ -11,6 +11,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
ifeq ($(CONFIG_LINUX),y)
common-obj-$(CONFIG_VIRTIO) += virtio-input.o
common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
common-obj-$(CONFIG_VIRTIO) += virtio-input-host.o
endif
obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o

View File

@ -0,0 +1,188 @@
/*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version. See the COPYING file in the
* top-level directory.
*/
#include "qemu-common.h"
#include "qemu/sockets.h"
#include "hw/qdev.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-input.h"
#include "standard-headers/linux/input.h"
/* ----------------------------------------------------------------- */
static struct virtio_input_config virtio_input_host_config[] = {
{ /* empty list */ },
};
static void virtio_input_host_event(void *opaque)
{
VirtIOInputHost *vih = opaque;
VirtIOInput *vinput = VIRTIO_INPUT(vih);
struct virtio_input_event virtio;
struct input_event evdev;
int rc;
for (;;) {
rc = read(vih->fd, &evdev, sizeof(evdev));
if (rc != sizeof(evdev)) {
break;
}
virtio.type = cpu_to_le16(evdev.type);
virtio.code = cpu_to_le16(evdev.code);
virtio.value = cpu_to_le32(evdev.value);
virtio_input_send(vinput, &virtio);
}
}
static void virtio_input_bits_config(VirtIOInputHost *vih,
int type, int count)
{
virtio_input_config bits;
int rc, i, size = 0;
memset(&bits, 0, sizeof(bits));
rc = ioctl(vih->fd, EVIOCGBIT(type, count/8), bits.u.bitmap);
if (rc < 0) {
return;
}
for (i = 0; i < count/8; i++) {
if (bits.u.bitmap[i]) {
size = i+1;
}
}
if (size == 0) {
return;
}
bits.select = VIRTIO_INPUT_CFG_EV_BITS;
bits.subsel = type;
bits.size = size;
virtio_input_add_config(VIRTIO_INPUT(vih), &bits);
}
static void virtio_input_host_realize(DeviceState *dev, Error **errp)
{
VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev);
VirtIOInput *vinput = VIRTIO_INPUT(dev);
virtio_input_config id;
struct input_id ids;
int rc, ver;
if (!vih->evdev) {
error_setg(errp, "evdev property is required");
return;
}
vih->fd = open(vih->evdev, O_RDWR);
if (vih->fd < 0) {
error_setg_file_open(errp, errno, vih->evdev);
return;
}
qemu_set_nonblock(vih->fd);
rc = ioctl(vih->fd, EVIOCGVERSION, &ver);
if (rc < 0) {
error_setg(errp, "%s: is not an evdev device", vih->evdev);
goto err_close;
}
rc = ioctl(vih->fd, EVIOCGRAB, 1);
if (rc < 0) {
error_setg_errno(errp, errno, "%s: failed to get exclusive access",
vih->evdev);
goto err_close;
}
memset(&id, 0, sizeof(id));
ioctl(vih->fd, EVIOCGNAME(sizeof(id.u.string)-1), id.u.string);
id.select = VIRTIO_INPUT_CFG_ID_NAME;
id.size = strlen(id.u.string);
virtio_input_add_config(vinput, &id);
if (ioctl(vih->fd, EVIOCGID, &ids) == 0) {
memset(&id, 0, sizeof(id));
id.select = VIRTIO_INPUT_CFG_ID_DEVIDS;
id.size = sizeof(struct virtio_input_devids);
id.u.ids.bustype = cpu_to_le16(ids.bustype);
id.u.ids.vendor = cpu_to_le16(ids.vendor);
id.u.ids.product = cpu_to_le16(ids.product);
id.u.ids.version = cpu_to_le16(ids.version);
virtio_input_add_config(vinput, &id);
}
virtio_input_bits_config(vih, EV_KEY, KEY_CNT);
virtio_input_bits_config(vih, EV_REL, REL_CNT);
virtio_input_bits_config(vih, EV_ABS, ABS_CNT);
virtio_input_bits_config(vih, EV_MSC, MSC_CNT);
virtio_input_bits_config(vih, EV_SW, SW_CNT);
qemu_set_fd_handler(vih->fd, virtio_input_host_event, NULL, vih);
return;
err_close:
close(vih->fd);
vih->fd = -1;
return;
}
static void virtio_input_host_unrealize(DeviceState *dev, Error **errp)
{
VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev);
if (vih->fd > 0) {
qemu_set_fd_handler(vih->fd, NULL, NULL, NULL);
close(vih->fd);
}
}
static const VMStateDescription vmstate_virtio_input_host = {
.name = "virtio-input-host",
.unmigratable = 1,
};
static Property virtio_input_host_properties[] = {
DEFINE_PROP_STRING("evdev", VirtIOInputHost, evdev),
DEFINE_PROP_END_OF_LIST(),
};
static void virtio_input_host_class_init(ObjectClass *klass, void *data)
{
VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
dc->vmsd = &vmstate_virtio_input_host;
dc->props = virtio_input_host_properties;
vic->realize = virtio_input_host_realize;
vic->unrealize = virtio_input_host_unrealize;
}
static void virtio_input_host_init(Object *obj)
{
VirtIOInput *vinput = VIRTIO_INPUT(obj);
virtio_input_init_config(vinput, virtio_input_host_config);
}
static const TypeInfo virtio_input_host_info = {
.name = TYPE_VIRTIO_INPUT_HOST,
.parent = TYPE_VIRTIO_INPUT,
.instance_size = sizeof(VirtIOInputHost),
.instance_init = virtio_input_host_init,
.class_init = virtio_input_host_class_init,
};
/* ----------------------------------------------------------------- */
static void virtio_register_types(void)
{
type_register_static(&virtio_input_host_info);
}
type_init(virtio_register_types)

View File

@ -216,7 +216,7 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp)
}
virtio_input_idstr_config(vinput, VIRTIO_INPUT_CFG_ID_SERIAL,
vinput->input.serial);
vinput->serial);
QTAILQ_FOREACH(cfg, &vinput->cfg_list, node) {
if (vinput->cfg_size < cfg->config.size) {
@ -248,11 +248,17 @@ static void virtio_input_device_unrealize(DeviceState *dev, Error **errp)
virtio_cleanup(vdev);
}
static Property virtio_input_properties[] = {
DEFINE_PROP_STRING("serial", VirtIOInput, serial),
DEFINE_PROP_END_OF_LIST(),
};
static void virtio_input_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
dc->props = virtio_input_properties;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
vdc->realize = virtio_input_device_realize;
vdc->unrealize = virtio_input_device_unrealize;

View File

@ -1900,8 +1900,7 @@ static const TypeInfo virtio_rng_pci_info = {
/* virtio-input-pci */
static Property virtio_input_hid_pci_properties[] = {
DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
static Property virtio_input_pci_properties[] = {
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
DEFINE_PROP_END_OF_LIST(),
};
@ -1924,19 +1923,13 @@ static void virtio_input_pci_class_init(ObjectClass *klass, void *data)
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
dc->props = virtio_input_pci_properties;
k->realize = virtio_input_pci_realize;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
pcidev_k->class_id = PCI_CLASS_INPUT_OTHER;
}
static void virtio_input_hid_pci_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
dc->props = virtio_input_hid_pci_properties;
}
static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data)
{
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
@ -1955,22 +1948,33 @@ static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
static void virtio_keyboard_initfn(Object *obj)
{
VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_KEYBOARD);
object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_KEYBOARD);
}
static void virtio_mouse_initfn(Object *obj)
{
VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_MOUSE);
object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_MOUSE);
}
static void virtio_tablet_initfn(Object *obj)
{
VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_TABLET);
object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_TABLET);
}
static void virtio_host_initfn(Object *obj)
{
VirtIOInputHostPCI *dev = VIRTIO_INPUT_HOST_PCI(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_INPUT_HOST);
}
static const TypeInfo virtio_input_pci_info = {
@ -1985,7 +1989,6 @@ static const TypeInfo virtio_input_hid_pci_info = {
.name = TYPE_VIRTIO_INPUT_HID_PCI,
.parent = TYPE_VIRTIO_INPUT_PCI,
.instance_size = sizeof(VirtIOInputHIDPCI),
.class_init = virtio_input_hid_pci_class_init,
.abstract = true,
};
@ -2012,6 +2015,13 @@ static const TypeInfo virtio_tablet_pci_info = {
.instance_init = virtio_tablet_initfn,
};
static const TypeInfo virtio_host_pci_info = {
.name = TYPE_VIRTIO_INPUT_HOST_PCI,
.parent = TYPE_VIRTIO_INPUT_PCI,
.instance_size = sizeof(VirtIOInputHostPCI),
.instance_init = virtio_host_initfn,
};
/* virtio-pci-bus */
static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@ -2058,6 +2068,7 @@ static void virtio_pci_register_types(void)
type_register_static(&virtio_keyboard_pci_info);
type_register_static(&virtio_mouse_pci_info);
type_register_static(&virtio_tablet_pci_info);
type_register_static(&virtio_host_pci_info);
type_register_static(&virtio_pci_bus_info);
type_register_static(&virtio_pci_info);
#ifdef CONFIG_VIRTFS

View File

@ -43,6 +43,7 @@ typedef struct VHostSCSIPCI VHostSCSIPCI;
typedef struct VirtIORngPCI VirtIORngPCI;
typedef struct VirtIOInputPCI VirtIOInputPCI;
typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
typedef struct VirtIOGPUPCI VirtIOGPUPCI;
/* virtio-pci-bus */
@ -263,6 +264,15 @@ struct VirtIOInputHIDPCI {
VirtIOInputHID vdev;
};
#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
#define VIRTIO_INPUT_HOST_PCI(obj) \
OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
struct VirtIOInputHostPCI {
VirtIOPCIProxy parent_obj;
VirtIOInputHost vdev;
};
/*
* virtio-gpu-pci: This extends VirtioPCIProxy.
*/

View File

@ -50,17 +50,17 @@ typedef struct virtio_input_event virtio_input_event;
#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)
#define TYPE_VIRTIO_INPUT_HOST "virtio-input-host-device"
#define VIRTIO_INPUT_HOST(obj) \
OBJECT_CHECK(VirtIOInputHost, (obj), TYPE_VIRTIO_INPUT_HOST)
#define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \
OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST)
typedef struct VirtIOInput VirtIOInput;
typedef struct VirtIOInputClass VirtIOInputClass;
typedef struct VirtIOInputConfig VirtIOInputConfig;
typedef struct VirtIOInputHID VirtIOInputHID;
struct virtio_input_conf {
char *serial;
};
typedef struct VirtIOInputHost VirtIOInputHost;
struct VirtIOInputConfig {
virtio_input_config config;
@ -74,7 +74,7 @@ struct VirtIOInput {
uint32_t cfg_size;
QTAILQ_HEAD(, VirtIOInputConfig) cfg_list;
VirtQueue *evt, *sts;
virtio_input_conf input;
char *serial;
virtio_input_event *queue;
uint32_t qindex, qsize;
@ -100,6 +100,12 @@ struct VirtIOInputHID {
int ledstate;
};
struct VirtIOInputHost {
VirtIOInput parent_obj;
char *evdev;
int fd;
};
void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
void virtio_input_init_config(VirtIOInput *vinput,
virtio_input_config *config);