| 1 | /* |
| 2 | * This work is licensed under the terms of the GNU GPL, version 2 or |
| 3 | * (at your option) any later version. See the COPYING file in the |
| 4 | * top-level directory. |
| 5 | */ |
| 6 | |
| 7 | #include "qemu/osdep.h" |
| 8 | #include "hw/virtio/virtio-input.h" |
| 9 | |
| 10 | static const Property vinput_properties[] = { |
| 11 | DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), |
| 12 | }; |
| 13 | |
| 14 | static void vinput_realize(DeviceState *dev, Error **errp) |
| 15 | { |
| 16 | VHostUserBase *vub = VHOST_USER_BASE(dev); |
| 17 | VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev); |
| 18 | |
| 19 | /* Fixed for input device */ |
| 20 | vub->virtio_id = VIRTIO_ID_INPUT; |
| 21 | vub->num_vqs = 2; |
| 22 | vub->vq_size = 4; |
| 23 | vub->config_size = sizeof(virtio_input_config); |
| 24 | |
| 25 | vubc->parent_realize(dev, errp); |
| 26 | } |
| 27 | |
| 28 | static const VMStateDescription vmstate_vhost_input = { |
| 29 | .name = "vhost-user-input", |
| 30 | .unmigratable = 1, |
| 31 | }; |
| 32 | |
| 33 | static void vhost_input_class_init(ObjectClass *klass, const void *data) |
| 34 | { |
| 35 | VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); |
| 36 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 37 | |
| 38 | dc->vmsd = &vmstate_vhost_input; |
| 39 | device_class_set_props(dc, vinput_properties); |
| 40 | device_class_set_parent_realize(dc, vinput_realize, |
| 41 | &vubc->parent_realize); |
| 42 | set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
| 43 | } |
| 44 | |
| 45 | static const TypeInfo vhost_input_info = { |
| 46 | .name = TYPE_VHOST_USER_INPUT, |
| 47 | .parent = TYPE_VHOST_USER_BASE, |
| 48 | .instance_size = sizeof(VHostUserInput), |
| 49 | .class_init = vhost_input_class_init, |
| 50 | }; |
| 51 | |
| 52 | static void vhost_input_register_types(void) |
| 53 | { |
| 54 | type_register_static(&vhost_input_info); |
| 55 | } |
| 56 | |
| 57 | type_init(vhost_input_register_types) |