187c7fb78SLeo Yan /*
287c7fb78SLeo Yan * This work is licensed under the terms of the GNU GPL, version 2 or
387c7fb78SLeo Yan * (at your option) any later version. See the COPYING file in the
487c7fb78SLeo Yan * top-level directory.
587c7fb78SLeo Yan */
687c7fb78SLeo Yan
787c7fb78SLeo Yan #include "qemu/osdep.h"
887c7fb78SLeo Yan #include "hw/virtio/virtio-input.h"
987c7fb78SLeo Yan
10*bad38726SLeo Yan static Property vinput_properties[] = {
11*bad38726SLeo Yan DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
12*bad38726SLeo Yan DEFINE_PROP_END_OF_LIST(),
1387c7fb78SLeo Yan };
1487c7fb78SLeo Yan
vinput_realize(DeviceState * dev,Error ** errp)15*bad38726SLeo Yan static void vinput_realize(DeviceState *dev, Error **errp)
1687c7fb78SLeo Yan {
17*bad38726SLeo Yan VHostUserBase *vub = VHOST_USER_BASE(dev);
18*bad38726SLeo Yan VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev);
1987c7fb78SLeo Yan
20*bad38726SLeo Yan /* Fixed for input device */
21*bad38726SLeo Yan vub->virtio_id = VIRTIO_ID_INPUT;
22*bad38726SLeo Yan vub->num_vqs = 2;
23*bad38726SLeo Yan vub->vq_size = 4;
24*bad38726SLeo Yan vub->config_size = sizeof(virtio_input_config);
2587c7fb78SLeo Yan
26*bad38726SLeo Yan vubc->parent_realize(dev, errp);
2787c7fb78SLeo Yan }
2887c7fb78SLeo Yan
2987c7fb78SLeo Yan static const VMStateDescription vmstate_vhost_input = {
3087c7fb78SLeo Yan .name = "vhost-user-input",
3187c7fb78SLeo Yan .unmigratable = 1,
3287c7fb78SLeo Yan };
3387c7fb78SLeo Yan
vhost_input_class_init(ObjectClass * klass,void * data)3487c7fb78SLeo Yan static void vhost_input_class_init(ObjectClass *klass, void *data)
3587c7fb78SLeo Yan {
36*bad38726SLeo Yan VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass);
3787c7fb78SLeo Yan DeviceClass *dc = DEVICE_CLASS(klass);
3887c7fb78SLeo Yan
3987c7fb78SLeo Yan dc->vmsd = &vmstate_vhost_input;
40*bad38726SLeo Yan device_class_set_props(dc, vinput_properties);
41*bad38726SLeo Yan device_class_set_parent_realize(dc, vinput_realize,
42*bad38726SLeo Yan &vubc->parent_realize);
43*bad38726SLeo Yan set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
4487c7fb78SLeo Yan }
4587c7fb78SLeo Yan
4687c7fb78SLeo Yan static const TypeInfo vhost_input_info = {
4787c7fb78SLeo Yan .name = TYPE_VHOST_USER_INPUT,
48*bad38726SLeo Yan .parent = TYPE_VHOST_USER_BASE,
4987c7fb78SLeo Yan .instance_size = sizeof(VHostUserInput),
5087c7fb78SLeo Yan .class_init = vhost_input_class_init,
5187c7fb78SLeo Yan };
5287c7fb78SLeo Yan
vhost_input_register_types(void)5387c7fb78SLeo Yan static void vhost_input_register_types(void)
5487c7fb78SLeo Yan {
5587c7fb78SLeo Yan type_register_static(&vhost_input_info);
5687c7fb78SLeo Yan }
5787c7fb78SLeo Yan
5887c7fb78SLeo Yan type_init(vhost_input_register_types)
59