mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
virtio-rng: hardware random number generator device
The Linux kernel already has a virtio-rng driver, this is the device implementation. When the guest asks for entropy from the virtio hwrng, it puts a buffer in the vq. We then put entropy into that buffer, and push it back to the guest. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> --- aliguori: converted to new RngBackend interface aliguori: remove entropy needed event aliguori: fix migration
This commit is contained in:
parent
1da2738f55
commit
16c915ba42
9 changed files with 341 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "loader.h"
|
||||
#include "elf.h"
|
||||
#include "hw/virtio.h"
|
||||
#include "hw/virtio-rng.h"
|
||||
#include "hw/virtio-serial.h"
|
||||
#include "hw/virtio-net.h"
|
||||
#include "hw/sysbus.h"
|
||||
|
@ -206,6 +207,18 @@ static int s390_virtio_scsi_init(VirtIOS390Device *dev)
|
|||
return s390_virtio_device_init(dev, vdev);
|
||||
}
|
||||
|
||||
static int s390_virtio_rng_init(VirtIOS390Device *dev)
|
||||
{
|
||||
VirtIODevice *vdev;
|
||||
|
||||
vdev = virtio_rng_init((DeviceState *)dev, &dev->rng);
|
||||
if (!vdev) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return s390_virtio_device_init(dev, vdev);
|
||||
}
|
||||
|
||||
static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
|
||||
{
|
||||
ram_addr_t token_off;
|
||||
|
@ -448,6 +461,29 @@ static TypeInfo s390_virtio_serial = {
|
|||
.class_init = s390_virtio_serial_class_init,
|
||||
};
|
||||
|
||||
static void s390_virtio_rng_initfn(Object *obj)
|
||||
{
|
||||
VirtIOS390Device *dev = VIRTIO_S390_DEVICE(obj);
|
||||
|
||||
object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
|
||||
(Object **)&dev->rng.rng, NULL);
|
||||
}
|
||||
|
||||
static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
|
||||
|
||||
k->init = s390_virtio_rng_init;
|
||||
}
|
||||
|
||||
static TypeInfo s390_virtio_rng = {
|
||||
.name = "virtio-rng-s390",
|
||||
.parent = TYPE_VIRTIO_S390_DEVICE,
|
||||
.instance_size = sizeof(VirtIOS390Device),
|
||||
.instance_init = s390_virtio_rng_initfn,
|
||||
.class_init = s390_virtio_rng_class_init,
|
||||
};
|
||||
|
||||
static int s390_virtio_busdev_init(DeviceState *dev)
|
||||
{
|
||||
VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
|
||||
|
@ -528,6 +564,7 @@ static void s390_virtio_register_types(void)
|
|||
type_register_static(&s390_virtio_blk);
|
||||
type_register_static(&s390_virtio_net);
|
||||
type_register_static(&s390_virtio_scsi);
|
||||
type_register_static(&s390_virtio_rng);
|
||||
type_register_static(&s390_virtio_bridge_info);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue