summary refs log tree commit diff stats
path: root/hw/virtio/vhost-user-test-device.c
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2025-09-01 11:59:48 +0100
committerMichael S. Tsirkin <mst@redhat.com>2025-10-05 09:01:08 -0400
commit722e9022a0b6db175209bad75aa52b24033249e3 (patch)
treed9e1dc74ce30a20e798ffc19bf3de7e627bf6617 /hw/virtio/vhost-user-test-device.c
parent2e54e5fda779a7ba45578884276dca62462f7a06 (diff)
downloadfocaccia-qemu-722e9022a0b6db175209bad75aa52b24033249e3.tar.gz
focaccia-qemu-722e9022a0b6db175209bad75aa52b24033249e3.zip
hw/virtio: rename vhost-user-device and make user creatable
We didn't make the device user creatable in the first place because we
were worried users might get confused. Rename the device to make its
nature as a test device even more explicit. While we are at it add a
Kconfig variable so it can be skipped for those that want to thin out
their build configuration even further.

Acked-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-ID: <20250820195632.1956795-1-alex.bennee@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20250901105948.982583-1-alex.bennee@linaro.org>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/virtio/vhost-user-test-device.c')
-rw-r--r--hw/virtio/vhost-user-test-device.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/hw/virtio/vhost-user-test-device.c b/hw/virtio/vhost-user-test-device.c
new file mode 100644
index 0000000000..1b98ea3e48
--- /dev/null
+++ b/hw/virtio/vhost-user-test-device.c
@@ -0,0 +1,60 @@
+/*
+ * Generic vhost-user-test-device implementation for any vhost-user-backend
+ *
+ * This is a concrete implementation of vhost-user-base which can be
+ * configured via properties. It is useful for development and
+ * prototyping. It expects configuration details (if any) to be
+ * handled by the vhost-user daemon itself.
+ *
+ * Copyright (c) 2023 Linaro Ltd
+ * Author: Alex Bennée <alex.bennee@linaro.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/qdev-properties.h"
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/vhost-user-base.h"
+#include "qemu/error-report.h"
+
+/*
+ * The following is a concrete implementation of the base class which
+ * allows the user to define the key parameters via the command line.
+ */
+
+static const VMStateDescription vud_vmstate = {
+    .name = "vhost-user-test-device",
+    .unmigratable = 1,
+};
+
+static const Property vud_properties[] = {
+    DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
+    DEFINE_PROP_UINT16("virtio-id", VHostUserBase, virtio_id, 0),
+    DEFINE_PROP_UINT32("vq_size", VHostUserBase, vq_size, 64),
+    DEFINE_PROP_UINT32("num_vqs", VHostUserBase, num_vqs, 1),
+    DEFINE_PROP_UINT32("config_size", VHostUserBase, config_size, 0),
+};
+
+static void vud_class_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    device_class_set_props(dc, vud_properties);
+    dc->vmsd = &vud_vmstate;
+    set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
+}
+
+static const TypeInfo vud_info = {
+    .name = TYPE_VHOST_USER_TEST_DEVICE,
+    .parent = TYPE_VHOST_USER_BASE,
+    .class_init = vud_class_init,
+};
+
+static void vu_register_types(void)
+{
+    type_register_static(&vud_info);
+}
+
+type_init(vu_register_types)