]>
Commit | Line | Data |
---|---|---|
821d28b8 MP |
1 | /* |
2 | * Vhost-user RNG virtio device | |
3 | * | |
4 | * Copyright (c) 2021 Mathieu Poirier <mathieu.poirier@linaro.org> | |
5 | * | |
233412bf | 6 | * Simple wrapper of the generic vhost-user-device. |
821d28b8 MP |
7 | * |
8 | * SPDX-License-Identifier: GPL-2.0-or-later | |
9 | */ | |
10 | ||
11 | #include "qemu/osdep.h" | |
12 | #include "qapi/error.h" | |
13 | #include "hw/qdev-properties.h" | |
14 | #include "hw/virtio/virtio-bus.h" | |
15 | #include "hw/virtio/vhost-user-rng.h" | |
821d28b8 MP |
16 | #include "standard-headers/linux/virtio_ids.h" |
17 | ||
821d28b8 MP |
18 | static const VMStateDescription vu_rng_vmstate = { |
19 | .name = "vhost-user-rng", | |
20 | .unmigratable = 1, | |
21 | }; | |
22 | ||
233412bf AB |
23 | static Property vrng_properties[] = { |
24 | DEFINE_PROP_CHR("chardev", VHostUserBase, chardev), | |
821d28b8 MP |
25 | DEFINE_PROP_END_OF_LIST(), |
26 | }; | |
27 | ||
233412bf AB |
28 | static void vu_rng_base_realize(DeviceState *dev, Error **errp) |
29 | { | |
30 | VHostUserBase *vub = VHOST_USER_BASE(dev); | |
31 | VHostUserBaseClass *vubs = VHOST_USER_BASE_GET_CLASS(dev); | |
32 | ||
33 | /* Fixed for RNG */ | |
34 | vub->virtio_id = VIRTIO_ID_RNG; | |
35 | vub->num_vqs = 1; | |
36 | vub->vq_size = 4; | |
37 | ||
38 | vubs->parent_realize(dev, errp); | |
39 | } | |
40 | ||
821d28b8 MP |
41 | static void vu_rng_class_init(ObjectClass *klass, void *data) |
42 | { | |
43 | DeviceClass *dc = DEVICE_CLASS(klass); | |
233412bf | 44 | VHostUserBaseClass *vubc = VHOST_USER_BASE_CLASS(klass); |
821d28b8 | 45 | |
821d28b8 | 46 | dc->vmsd = &vu_rng_vmstate; |
233412bf AB |
47 | device_class_set_props(dc, vrng_properties); |
48 | device_class_set_parent_realize(dc, vu_rng_base_realize, | |
49 | &vubc->parent_realize); | |
821d28b8 | 50 | |
233412bf | 51 | set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
821d28b8 MP |
52 | } |
53 | ||
54 | static const TypeInfo vu_rng_info = { | |
55 | .name = TYPE_VHOST_USER_RNG, | |
233412bf | 56 | .parent = TYPE_VHOST_USER_BASE, |
821d28b8 MP |
57 | .instance_size = sizeof(VHostUserRNG), |
58 | .class_init = vu_rng_class_init, | |
59 | }; | |
60 | ||
61 | static void vu_rng_register_types(void) | |
62 | { | |
63 | type_register_static(&vu_rng_info); | |
64 | } | |
65 | ||
66 | type_init(vu_rng_register_types) |