virtio: Add vhost-user-rtc and vhost-user-rtc-pci
Authored solely by me for Panasonic Automotive Systems Co., Ltd., but based on existing vhost-user devices I wrote in 2025, so the copyright is mixed. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Alex Bennée <alex.bennee@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260416-vhost-user-rtc-v2-1-100a53bfc6ce@linaro.org Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Manos Pitsidianakis committed
Oct 24, 2025 at 21:35 UTC
e331d3089ee64411013eea74fdf71ccf30bcb626
7 files changed
+173
MAINTAINERS
+6
@@ -2586,6 +2586,12 @@ S: Maintained
2586
F: include/hw/virtio/vhost-user-spi.h
2587
F: hw/virtio/vhost-user-spi*
2588
2589
+vhost-user-rtc
2590
+M: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2591
+S: Supported
2592
+F: include/hw/virtio/vhost-user-rtc.h
2593
+F: hw/virtio/vhost-user-rtc*
2594
+
2595
virtio-crypto
2596
M: Gonglei <arei.gonglei@huawei.com>
2597
S: Supported
docs/system/devices/virtio/vhost-user.rst
+3
@@ -61,6 +61,9 @@ platform details for what sort of virtio bus to use.
61
* - vhost-user-spi
62
- Proxy spi devices to host
63
- `vhost-device-spi <https://github.com/rust-vmm/vhost-device/tree/main/vhost-device-spi>`_
64
+ * - vhost-user-rtc
65
+ - Real time clock
66
+ - `vhost-device-rtc <https://github.com/rust-vmm/vhost-device/tree/main/vhost-device-rtc>`_
67
68
The referenced *daemons* are not exhaustive, any conforming backend
69
implementing the device and using the vhost-user protocol should work.
hw/virtio/Kconfig
+5
@@ -136,3 +136,8 @@ config VHOST_USER_TEST
136
bool
137
default y
138
depends on VIRTIO && VHOST_USER
139
+
140
+config VHOST_USER_RTC
141
+ bool
142
+ default y
143
+ depends on VIRTIO && VHOST_USER
hw/virtio/meson.build
+3
@@ -27,6 +27,7 @@ if have_vhost
27
system_virtio_ss.add(when: 'CONFIG_VHOST_USER_SND', if_true: files('vhost-user-snd.c'))
28
system_virtio_ss.add(when: 'CONFIG_VHOST_USER_INPUT', if_true: files('vhost-user-input.c'))
29
system_virtio_ss.add(when: 'CONFIG_VHOST_USER_SPI', if_true: files('vhost-user-spi.c'))
30
+ system_virtio_ss.add(when: 'CONFIG_VHOST_USER_RTC', if_true: files('vhost-user-rtc.c'))
31
32
# PCI Stubs
33
system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_TEST'],
@@ -43,6 +44,8 @@ if have_vhost
44
if_true: files('vhost-user-input-pci.c'))
45
system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_SPI'],
46
if_true: files('vhost-user-spi-pci.c'))
47
+ system_virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_RTC'],
48
+ if_true: files('vhost-user-rtc-pci.c'))
49
endif
50
if have_vhost_vdpa
51
system_virtio_ss.add(files('vhost-vdpa.c'))
hw/virtio/vhost-user-rtc-pci.c
new
+70
@@ -0,0 +1,70 @@
1
+/*
2
+ * Vhost-user RTC virtio device PCI glue
3
+ *
4
+ * Copyright (c) 2025 Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
5
+ * Copyright 2026 Panasonic Automotive Systems Co., Ltd.
6
+ *
7
+ * SPDX-License-Identifier: GPL-2.0-or-later
8
+ */
9
+
10
+#include "qemu/osdep.h"
11
+#include "hw/virtio/vhost-user-rtc.h"
12
+#include "hw/virtio/virtio-pci.h"
13
+
14
+struct VHostUserRTCPCI {
15
+ VirtIOPCIProxy parent_obj;
16
+ VHostUserRTC vdev;
17
+};
18
+
19
+typedef struct VHostUserRTCPCI VHostUserRTCPCI;
20
+
21
+#define TYPE_VHOST_USER_RTC_PCI "vhost-user-rtc-pci-base"
22
+
23
+DECLARE_INSTANCE_CHECKER(VHostUserRTCPCI, VHOST_USER_RTC_PCI,
24
+ TYPE_VHOST_USER_RTC_PCI)
25
+
26
+static void vhost_user_rtc_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
27
+{
28
+ VHostUserRTCPCI *dev = VHOST_USER_RTC_PCI(vpci_dev);
29
+ DeviceState *vdev = DEVICE(&dev->vdev);
30
+
31
+ vpci_dev->nvectors = 1;
32
+
33
+ qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
34
+}
35
+
36
+static void vhost_user_rtc_pci_class_init(ObjectClass *klass, const void *data)
37
+{
38
+ DeviceClass *dc = DEVICE_CLASS(klass);
39
+ VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
40
+ PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
41
+ k->realize = vhost_user_rtc_pci_realize;
42
+ set_bit(DEVICE_CATEGORY_MISC, dc->categories);
43
+ pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
44
+ pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */
45
+ pcidev_k->revision = 0x00;
46
+ pcidev_k->class_id = PCI_CLASS_SYSTEM_RTC;
47
+}
48
+
49
+static void vhost_user_rtc_pci_instance_init(Object *obj)
50
+{
51
+ VHostUserRTCPCI *dev = VHOST_USER_RTC_PCI(obj);
52
+
53
+ virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
54
+ TYPE_VHOST_USER_RTC);
55
+}
56
+
57
+static const VirtioPCIDeviceTypeInfo vhost_user_rtc_pci_info = {
58
+ .base_name = TYPE_VHOST_USER_RTC_PCI,
59
+ .non_transitional_name = "vhost-user-rtc-pci",
60
+ .instance_size = sizeof(VHostUserRTCPCI),
61
+ .instance_init = vhost_user_rtc_pci_instance_init,
62
+ .class_init = vhost_user_rtc_pci_class_init,
63
+};
64
+
65
+static void vhost_user_rtc_pci_register(void)
66
+{
67
+ virtio_pci_types_register(&vhost_user_rtc_pci_info);
68
+}
69
+
70
+type_init(vhost_user_rtc_pci_register);
hw/virtio/vhost-user-rtc.c
new
+64
@@ -0,0 +1,64 @@
1
+/*
2
+ * Vhost-user RTC virtio device
3
+ *
4
+ * Copyright (c) 2025 Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
5
+ * Copyright 2026 Panasonic Automotive Systems Co., Ltd.
6
+ *
7
+ * Simple wrapper of the generic vhost-user-device.
8
+ *
9
+ * SPDX-License-Identifier: GPL-2.0-or-later
10
+ */
11
+
12
+#include "qemu/osdep.h"
13
+#include "qapi/error.h"
14
+#include "hw/virtio/vhost-user-rtc.h"
15
+#include "standard-headers/linux/virtio_ids.h"
16
+
17
+static const VMStateDescription vu_rtc_vmstate = {
18
+ .name = "vhost-user-rtc",
19
+ .unmigratable = 1,
20
+};
21
+
22
+static const Property vrtc_properties[] = {
23
+ DEFINE_PROP_CHR("chardev", VHostUserBase, chardev),
24
+};
25
+
26
+static void vu_rtc_base_realize(DeviceState *dev, Error **errp)
27
+{
28
+ VHostUserBase *vub = VHOST_USER_BASE(dev);
29
+ VHostUserBaseClass *vubs = VHOST_USER_BASE_GET_CLASS(dev);
30
+
31
+ vub->virtio_id = VIRTIO_ID_CLOCK;
32
+ vub->num_vqs = 2;
33
+ vub->config_size = 0;
34
+ vub->vq_size = 1024;
35
+
36
+ vubs->parent_realize(dev, errp);
37
+}
38
+
39
+static void vu_rtc_class_init(ObjectClass *klass, const void *data)
40
+{
41
+ DeviceClass *dc = DEVICE_CLASS(klass);
42
+ VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass);
43
+
44
+ dc->vmsd = &vu_rtc_vmstate;
45
+ device_class_set_props(dc, vrtc_properties);
46
+ device_class_set_parent_realize(dc, vu_rtc_base_realize,
47
+ &vubc->parent_realize);
48
+
49
+ set_bit(DEVICE_CATEGORY_MISC, dc->categories);
50
+}
51
+
52
+static const TypeInfo vu_rtc_info = {
53
+ .name = TYPE_VHOST_USER_RTC,
54
+ .parent = TYPE_VHOST_USER_BASE,
55
+ .instance_size = sizeof(VHostUserRTC),
56
+ .class_init = vu_rtc_class_init,
57
+};
58
+
59
+static void vu_rtc_register_types(void)
60
+{
61
+ type_register_static(&vu_rtc_info);
62
+}
63
+
64
+type_init(vu_rtc_register_types)
include/hw/virtio/vhost-user-rtc.h
new
+22
@@ -0,0 +1,22 @@
1
+/*
2
+ * Vhost-user RTC virtio device
3
+ *
4
+ * Copyright (c) 2025 Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
5
+ * Copyright 2026 Panasonic Automotive Systems Co., Ltd.
6
+ *
7
+ * SPDX-License-Identifier: GPL-2.0-or-later
8
+ */
9
+
10
+#ifndef QEMU_VHOST_USER_RTC_H
11
+#define QEMU_VHOST_USER_RTC_H
12
+
13
+#include "hw/virtio/vhost-user-base.h"
14
+
15
+#define TYPE_VHOST_USER_RTC "vhost-user-rtc"
16
+OBJECT_DECLARE_SIMPLE_TYPE(VHostUserRTC, VHOST_USER_RTC)
17
+
18
+struct VHostUserRTC {
19
+ VHostUserBase parent_obj;
20
+};
21
+
22
+#endif /* QEMU_VHOST_USER_RTC_H */