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 1216c915baSAmit Shah #ifndef _QEMU_VIRTIO_RNG_H 1316c915baSAmit Shah #define _QEMU_VIRTIO_RNG_H 1416c915baSAmit Shah 15dccfcd0eSPaolo Bonzini #include "sysemu/rng.h" 16dccfcd0eSPaolo Bonzini #include "sysemu/rng-random.h" 1716c915baSAmit Shah 18*6eac8aecSKONRAD Frederic #define TYPE_VIRTIO_RNG "virtio-rng-device" 19*6eac8aecSKONRAD Frederic #define VIRTIO_RNG(obj) \ 20*6eac8aecSKONRAD Frederic OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG) 21*6eac8aecSKONRAD Frederic 2216c915baSAmit Shah /* The Virtio ID for the virtio rng device */ 2316c915baSAmit Shah #define VIRTIO_ID_RNG 4 2416c915baSAmit Shah 2516c915baSAmit Shah struct VirtIORNGConf { 2616c915baSAmit Shah RngBackend *rng; 27904d6f58SAnthony Liguori uint64_t max_bytes; 28904d6f58SAnthony Liguori uint32_t period_ms; 29500054f1SAnthony Liguori RndRandom *default_backend; 3016c915baSAmit Shah }; 3116c915baSAmit Shah 32f1b24e84SKONRAD Frederic typedef struct VirtIORNG { 33f1b24e84SKONRAD Frederic VirtIODevice vdev; 34f1b24e84SKONRAD Frederic 35f1b24e84SKONRAD Frederic DeviceState *qdev; 36f1b24e84SKONRAD Frederic 37f1b24e84SKONRAD Frederic /* Only one vq - guest puts buffer(s) on it when it needs entropy */ 38f1b24e84SKONRAD Frederic VirtQueue *vq; 39f1b24e84SKONRAD Frederic 40af1a8ad6SKONRAD Frederic VirtIORNGConf conf; 41f1b24e84SKONRAD Frederic 42f1b24e84SKONRAD Frederic RngBackend *rng; 43f1b24e84SKONRAD Frederic 44f1b24e84SKONRAD Frederic /* We purposefully don't migrate this state. The quota will reset on the 45f1b24e84SKONRAD Frederic * destination as a result. Rate limiting is host state, not guest state. 46f1b24e84SKONRAD Frederic */ 47f1b24e84SKONRAD Frederic QEMUTimer *rate_limit_timer; 48f1b24e84SKONRAD Frederic int64_t quota_remaining; 49f1b24e84SKONRAD Frederic } VirtIORNG; 50f1b24e84SKONRAD Frederic 51*6eac8aecSKONRAD Frederic /* Set a default rate limit of 2^47 bytes per minute or roughly 2TB/s. If 52*6eac8aecSKONRAD Frederic you have an entropy source capable of generating more entropy than this 53*6eac8aecSKONRAD Frederic and you can pass it through via virtio-rng, then hats off to you. Until 54*6eac8aecSKONRAD Frederic then, this is unlimited for all practical purposes. 55*6eac8aecSKONRAD Frederic */ 56*6eac8aecSKONRAD Frederic #define DEFINE_VIRTIO_RNG_PROPERTIES(_state, _conf_field) \ 57*6eac8aecSKONRAD Frederic DEFINE_PROP_UINT64("max-bytes", _state, _conf_field.max_bytes, \ 58*6eac8aecSKONRAD Frederic INT64_MAX), \ 59*6eac8aecSKONRAD Frederic DEFINE_PROP_UINT32("period", _state, _conf_field.period_ms, 1 << 16) 60*6eac8aecSKONRAD Frederic 6116c915baSAmit Shah #endif 62