xref: /openbmc/qemu/hw/virtio/vhost-user-device.c (revision e9206163)
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 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     DEFINE_PROP_END_OF_LIST(),
39 };
40 
41 static void vud_class_init(ObjectClass *klass, void *data)
42 {
43     DeviceClass *dc = DEVICE_CLASS(klass);
44 
45     /* Reason: stop inexperienced users confusing themselves */
46     dc->user_creatable = false;
47 
48     device_class_set_props(dc, vud_properties);
49     dc->vmsd = &vud_vmstate;
50     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
51 }
52 
53 static const TypeInfo vud_info = {
54     .name = TYPE_VHOST_USER_DEVICE,
55     .parent = TYPE_VHOST_USER_BASE,
56     .class_init = vud_class_init,
57 };
58 
59 static void vu_register_types(void)
60 {
61     type_register_static(&vud_info);
62 }
63 
64 type_init(vu_register_types)
65