xref: /qemu/include/hw/virtio/virtio-rng.h (revision db1015e92e04835c9eb50c29625fe566d1202dbd)
116c915baSAmit Shah /*
216c915baSAmit Shah  * Virtio RNG Support
316c915baSAmit Shah  *
416c915baSAmit Shah  * Copyright Red Hat, Inc. 2012
516c915baSAmit Shah  * Copyright Amit Shah <amit.shah@redhat.com>
616c915baSAmit Shah  *
716c915baSAmit Shah  * This work is licensed under the terms of the GNU GPL, version 2 or
816c915baSAmit Shah  * (at your option) any later version.  See the COPYING file in the
916c915baSAmit Shah  * top-level directory.
1016c915baSAmit Shah  */
1116c915baSAmit Shah 
122a6a4076SMarkus Armbruster #ifndef QEMU_VIRTIO_RNG_H
132a6a4076SMarkus Armbruster #define QEMU_VIRTIO_RNG_H
1416c915baSAmit Shah 
15ec150c7eSMarkus Armbruster #include "hw/virtio/virtio.h"
16dccfcd0eSPaolo Bonzini #include "sysemu/rng.h"
173e96b2dbSMichael S. Tsirkin #include "standard-headers/linux/virtio_rng.h"
18*db1015e9SEduardo Habkost #include "qom/object.h"
1916c915baSAmit Shah 
206eac8aecSKONRAD Frederic #define TYPE_VIRTIO_RNG "virtio-rng-device"
21*db1015e9SEduardo Habkost typedef struct VirtIORNG VirtIORNG;
226eac8aecSKONRAD Frederic #define VIRTIO_RNG(obj) \
236eac8aecSKONRAD Frederic         OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG)
24a8d57dfbSAndreas Färber #define VIRTIO_RNG_GET_PARENT_CLASS(obj) \
25a8d57dfbSAndreas Färber         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG)
266eac8aecSKONRAD Frederic 
2716c915baSAmit Shah struct VirtIORNGConf {
2816c915baSAmit Shah     RngBackend *rng;
29904d6f58SAnthony Liguori     uint64_t max_bytes;
30904d6f58SAnthony Liguori     uint32_t period_ms;
3116c915baSAmit Shah };
3216c915baSAmit Shah 
33*db1015e9SEduardo Habkost struct VirtIORNG {
34611aa333SKONRAD Frederic     VirtIODevice parent_obj;
35f1b24e84SKONRAD Frederic 
36f1b24e84SKONRAD Frederic     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
37f1b24e84SKONRAD Frederic     VirtQueue *vq;
38f1b24e84SKONRAD Frederic 
39af1a8ad6SKONRAD Frederic     VirtIORNGConf conf;
40f1b24e84SKONRAD Frederic 
41f1b24e84SKONRAD Frederic     RngBackend *rng;
42f1b24e84SKONRAD Frederic 
43f1b24e84SKONRAD Frederic     /* We purposefully don't migrate this state.  The quota will reset on the
44f1b24e84SKONRAD Frederic      * destination as a result.  Rate limiting is host state, not guest state.
45f1b24e84SKONRAD Frederic      */
46f1b24e84SKONRAD Frederic     QEMUTimer *rate_limit_timer;
47f1b24e84SKONRAD Frederic     int64_t quota_remaining;
48621a20e0SPankaj Gupta     bool activate_timer;
49a23a6d18SLaurent Vivier 
50a23a6d18SLaurent Vivier     VMChangeStateEntry *vmstate;
51*db1015e9SEduardo Habkost };
52f1b24e84SKONRAD Frederic 
5316c915baSAmit Shah #endif
54