master
c 60 lines 1.73 KB
Raw
1 /*
2 * Generic vhost-user-test-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/core/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-test-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 device_class_set_props(dc, vud_properties);
45 dc->vmsd = &vud_vmstate;
46 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
47 }
48
49 static const TypeInfo vud_info = {
50 .name = TYPE_VHOST_USER_TEST_DEVICE,
51 .parent = TYPE_VHOST_USER_BASE,
52 .class_init = vud_class_init,
53 };
54
55 static void vu_register_types(void)
56 {
57 type_register_static(&vud_info);
58 }
59
60 type_init(vu_register_types)