virtio-input: property fixes, add passthrough
cover virtio-input: property fixes, add passthrough
Hi,
This little series updates the virtio-input devices to follow latest practices, so device properties are handled properly. It also adds evdev passthrough device for virtio-input (patch has updated property handling too), and finally a MAINTAINERS entry for virtio-input.
please review,
Gerd
Gerd Hoffmann (3):
virtio-input: move properties, use virtio_instance_init_common
virtio-input: evdev passthrough
Add MAINTAINERS entry for virtio-input
MAINTAINERS | 6 ++ hw/input/Makefile.objs | 1 + hw/input/virtio-input-host.c | 188 +++++++++++++++++++++++++++++++++++++++ hw/input/virtio-input.c | 8 +- hw/virtio/virtio-pci.c | 43 +++++---- hw/virtio/virtio-pci.h | 10 +++ include/hw/virtio/virtio-input.h | 20 +++-- 7 files changed, 252 insertions(+), 24 deletions(-) create mode 100644 hw/input/virtio-input-host.c
Signature · 1 line
1.8.3.1
PATCH 1/3 virtio-input: move properties, use virtio_instance_init_common
Move properties from virtio-*-pci to virtio-*-device. Also make better use of QOM and attach common properties to the abstract parent classes (virtio-input-device and virtio-input-pci-device).
Switch the hid device instance init functions over to use virtio_instance_init_common, so we get the properties of the virtio device aliased properly to the virtio pci proxy.
--- hw/input/virtio-input.c | 8 +++++++- hw/virtio/virtio-pci.c | 27 +++++++++++---------------- include/hw/virtio/virtio-input.h | 9 +-------- 3 files changed, 19 insertions(+), 25 deletions(-)
hw/input/virtio-input.c +7 -1
@@ -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;
hw/virtio/virtio-pci.c +11 -16
@@ -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,25 @@ 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 const TypeInfo virtio_input_pci_info = {
@@ -1985,7 +1981,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, };
include/hw/virtio/virtio-input.h +1 -8
@@ -50,18 +50,11 @@ 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) -typedef struct VirtIOInput VirtIOInput ;typedef struct VirtIOInputClass VirtIOInputClass ;typedef struct VirtIOInputConfig VirtIOInputConfig ;typedef struct VirtIOInputHID VirtIOInputHID ; -struct virtio_input_conf { -char *serial; -}; -struct VirtIOInputConfig {virtio_input_config config;QTAILQ_ENTRY (VirtIOInputConfig) node;
@@ -74,7 +67,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;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH for-2.4 1/3] virtio-input: move properties, use virtio_instance_init_common
Quoted 10 lines · Gerd Hoffmann
Move properties from virtio-*-pci to virtio-*-device. Also make better use of QOM and attach common properties to the abstract parent classes (virtio-input-device and virtio-input-pci-device).
Switch the hid device instance init functions over to use
virtio_instance_init_common, so we get the properties of the virtio device aliased properly to the virtio pci proxy.Signed-off-by Gerd Hoffmann <[email protected]>
Quoted 146 lines
--- hw/input/virtio-input.c | 8 +++++++- hw/virtio/virtio-pci.c | 27 +++++++++++---------------- include/hw/virtio/virtio-input.h | 9 +-------- 3 files changed, 19 insertions(+), 25 deletions(-)hw/input/virtio-input.c +7
-1@@ -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;hw/virtio/virtio-pci.c +11
-16@@ -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,25 @@ 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 const TypeInfo virtio_input_pci_info = {@@ -1985,7 +1981,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, };include/hw/virtio/virtio-input.h +1
-8@@ -50,18 +50,11 @@ 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) -typedef struct VirtIOInput VirtIOInput ;typedef struct VirtIOInputClass VirtIOInputClass ;typedef struct VirtIOInputConfig VirtIOInputConfig ;typedef struct VirtIOInputHID VirtIOInputHID ; -struct virtio_input_conf { -char *serial; -}; -struct VirtIOInputConfig {virtio_input_config config;QTAILQ_ENTRY (VirtIOInputConfig) node;@@ -74,7 +67,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;Signature · 1 line
1.8.3.1
PATCH 2/3 virtio-input: evdev passthrough
In reply to Gerd HoffmannThis allows to assign host input devices to the guest:
qemu -device virtio-input-host-pci,evdev=/dev/input/event<nr>
The guest gets exclusive access to the input device, so be careful with assigning the keyboard if you have only one connected to your machine.
--- hw/input/Makefile.objs | 1 + hw/input/virtio-input-host.c | 188 +++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.c | 16 ++++ hw/virtio/virtio-pci.h | 10 +++ include/hw/virtio/virtio-input.h | 13 +++ 5 files changed, 228 insertions(+) create mode 100644 hw/input/virtio-input-host.c
hw/input/Makefile.objs +1 -0
@@ -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
hw/input/virtio-input-host.c new file +188 -0
188 lines not on this page · raw message
hw/virtio/virtio-pci.c +16 -0
@@ -1969,6 +1969,14 @@ static void virtio_tablet_initfn(Object *obj) 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 = { .name =TYPE_VIRTIO_INPUT_PCI , .parent =TYPE_VIRTIO_PCI ,
@@ -2007,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,
@@ -2053,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
hw/virtio/virtio-pci.h +10 -0
@@ -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. */
include/hw/virtio/virtio-input.h +13 -0
@@ -50,10 +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 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 ; +typedef struct VirtIOInputHost VirtIOInputHost ;struct VirtIOInputConfig {virtio_input_config config;
@@ -93,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);
Signature · 1 line
1.8.3.1
PATCH 3/3 Add MAINTAINERS entry for virtio-input
In reply to Gerd Hoffmann--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -727,6 +727,12 @@ S: Supported F: hw/s390x/virtio-ccw.[hc] T: git git://github.com/cohuck/qemu virtio-ccw-upstr +virtio-input +M: Gerd Hoffmann <[email protected]> +S: Maintained +F: hw/input/virtio-input*.c +F: include/hw/virtio/virtio-input.h + virtio-serial M: Amit Shah <[email protected]> S: Supported
Signature · 1 line
1.8.3.1