xref: /openbmc/qemu/hw/virtio/vhost-user-input.c (revision d6fd5d83)
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 Property vinput_properties[] = {
11     DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
12     DEFINE_PROP_END_OF_LIST(),
13 };
14 
15 static void vinput_realize(DeviceState *dev, Error **errp)
16 {
17     VHostUserBase *vub = VHOST_USER_BASE(dev);
18     VHostUserBaseClass *vubc = VHOST_USER_BASE_GET_CLASS(dev);
19 
20     /* Fixed for input device */
21     vub->virtio_id = VIRTIO_ID_INPUT;
22     vub->num_vqs = 2;
23     vub->vq_size = 4;
24     vub->config_size = sizeof(virtio_input_config);
25 
26     vubc->parent_realize(dev, errp);
27 }
28 
29 static const VMStateDescription vmstate_vhost_input = {
30     .name = "vhost-user-input",
31     .unmigratable = 1,
32 };
33 
34 static void vhost_input_class_init(ObjectClass *klass, void *data)
35 {
36     VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass);
37     DeviceClass *dc = DEVICE_CLASS(klass);
38 
39     dc->vmsd = &vmstate_vhost_input;
40     device_class_set_props(dc, vinput_properties);
41     device_class_set_parent_realize(dc, vinput_realize,
42                                     &vubc->parent_realize);
43     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
44 }
45 
46 static const TypeInfo vhost_input_info = {
47     .name          = TYPE_VHOST_USER_INPUT,
48     .parent        = TYPE_VHOST_USER_BASE,
49     .instance_size = sizeof(VHostUserInput),
50     .class_init    = vhost_input_class_init,
51 };
52 
53 static void vhost_input_register_types(void)
54 {
55     type_register_static(&vhost_input_info);
56 }
57 
58 type_init(vhost_input_register_types)
59