xref: /openbmc/qemu/include/hw/virtio/virtio-rng.h (revision a68694cd)
1 /*
2  * Virtio RNG Support
3  *
4  * Copyright Red Hat, Inc. 2012
5  * Copyright Amit Shah <amit.shah@redhat.com>
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or
8  * (at your option) any later version.  See the COPYING file in the
9  * top-level directory.
10  */
11 
12 #ifndef QEMU_VIRTIO_RNG_H
13 #define QEMU_VIRTIO_RNG_H
14 
15 #include "hw/virtio/virtio.h"
16 #include "sysemu/rng.h"
17 #include "standard-headers/linux/virtio_rng.h"
18 #include "qom/object.h"
19 
20 #define TYPE_VIRTIO_RNG "virtio-rng-device"
21 typedef struct VirtIORNG VirtIORNG;
22 DECLARE_INSTANCE_CHECKER(VirtIORNG, VIRTIO_RNG,
23                          TYPE_VIRTIO_RNG)
24 #define VIRTIO_RNG_GET_PARENT_CLASS(obj) \
25         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG)
26 
27 struct VirtIORNGConf {
28     RngBackend *rng;
29     uint64_t max_bytes;
30     uint32_t period_ms;
31 };
32 
33 struct VirtIORNG {
34     VirtIODevice parent_obj;
35 
36     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
37     VirtQueue *vq;
38 
39     VirtIORNGConf conf;
40 
41     RngBackend *rng;
42 
43     /* We purposefully don't migrate this state.  The quota will reset on the
44      * destination as a result.  Rate limiting is host state, not guest state.
45      */
46     QEMUTimer *rate_limit_timer;
47     int64_t quota_remaining;
48     bool activate_timer;
49 
50     VMChangeStateEntry *vmstate;
51 };
52 
53 #endif
54