master
c 64 lines 1.65 KB
Raw
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)