xref: /qemu/hw/virtio/vhost-user-device.c (revision ffd5a60e9b67e14f7bac7ea29300ea46a944e508)
1 /*
2  * Generic vhost-user-device implementation for any vhost-user-backend
3  *
4  * This is a concrete implementation of vhost-user-base which can be
5  * configured via properties. It is useful for development and
6  * prototyping. It expects configuration details (if any) to be
7  * handled by the vhost-user daemon itself.
8  *
9  * Copyright (c) 2023 Linaro Ltd
10  * Author: Alex Bennée <alex.bennee@linaro.org>
11  *
12  * SPDX-License-Identifier: GPL-2.0-or-later
13  */
14 
15 #include "qemu/osdep.h"
16 #include "qapi/error.h"
17 #include "hw/qdev-properties.h"
18 #include "hw/virtio/virtio-bus.h"
19 #include "hw/virtio/vhost-user-base.h"
20 #include "qemu/error-report.h"
21 
22 /*
23  * The following is a concrete implementation of the base class which
24  * allows the user to define the key parameters via the command line.
25  */
26 
27 static const VMStateDescription vud_vmstate = {
28     .name = "vhost-user-device",
29     .unmigratable = 1,
30 };
31 
32 static const Property vud_properties[] = {
33     DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
34     DEFINE_PROP_UINT16("virtio-id", VHostUserBase, virtio_id, 0),
35     DEFINE_PROP_UINT32("vq_size", VHostUserBase, vq_size, 64),
36     DEFINE_PROP_UINT32("num_vqs", VHostUserBase, num_vqs, 1),
37     DEFINE_PROP_UINT32("config_size", VHostUserBase, config_size, 0),
38 };
39 
40 static void vud_class_init(ObjectClass *klass, const void *data)
41 {
42     DeviceClass *dc = DEVICE_CLASS(klass);
43 
44     /* Reason: stop inexperienced users confusing themselves */
45     dc->user_creatable = false;
46 
47     device_class_set_props(dc, vud_properties);
48     dc->vmsd = &vud_vmstate;
49     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
50 }
51 
52 static const TypeInfo vud_info = {
53     .name = TYPE_VHOST_USER_DEVICE,
54     .parent = TYPE_VHOST_USER_BASE,
55     .class_init = vud_class_init,
56 };
57 
58 static void vu_register_types(void)
59 {
60     type_register_static(&vud_info);
61 }
62 
63 type_init(vu_register_types)
64