From: KONRAD Frederic <fred.kon...@greensocs.com> Here the virtio-rng-ccw is modified for the new API. The device virtio-rng-pci extends virtio-pci. It creates and connects a virtio-rng-device during the init. The properties are not changed.
Signed-off-by: KONRAD Frederic <fred.kon...@greensocs.com> --- hw/s390x/virtio-ccw.c | 48 +++++++++++++++++++++--------------------------- hw/s390x/virtio-ccw.h | 12 +++++++++++- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index f3c1ea4..65d960b 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -687,28 +687,21 @@ static void virtio_ccw_scsi_instance_init(Object *obj) object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); } -static int virtio_ccw_rng_init(VirtioCcwDevice *dev) +static int virtio_ccw_rng_init(VirtioCcwDevice *ccw_dev) { - VirtIODevice *vdev; - - if (dev->rng.rng == NULL) { - dev->rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM)); - object_property_add_child(OBJECT(dev), "default-backend", - OBJECT(dev->rng.default_backend), NULL); - object_property_set_link(OBJECT(dev), OBJECT(dev->rng.default_backend), - "rng", NULL); - } - vdev = virtio_rng_init((DeviceState *)dev, &dev->rng); - if (!vdev) { + VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev); + DeviceState *vdev = DEVICE(&dev->vdev); + + qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); + if (qdev_init(vdev) < 0) { return -1; } - return virtio_ccw_device_init(dev, vdev); -} -static int virtio_ccw_rng_exit(VirtioCcwDevice *dev) -{ - virtio_rng_exit(dev->vdev); - return virtio_ccw_exit(dev); + object_property_set_link(OBJECT(dev), + OBJECT(dev->vdev.conf.default_backend), "rng", + NULL); + + return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev)); } /* DeviceState to VirtioCcwDevice. Note: used on datapath, @@ -897,18 +890,19 @@ static const TypeInfo virtio_ccw_scsi = { .class_init = virtio_ccw_scsi_class_init, }; -static void virtio_ccw_rng_initfn(Object *obj) +static void virtio_ccw_rng_instance_init(Object *obj) { - VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(obj); - + VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj); + object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG); + object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); object_property_add_link(obj, "rng", TYPE_RNG_BACKEND, - (Object **)&dev->rng.rng, NULL); + (Object **)&dev->vdev.conf.rng, NULL); } static Property virtio_ccw_rng_properties[] = { DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]), - DEFINE_VIRTIO_RNG_PROPERTIES(VirtioCcwDevice, rng), + DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGCcw, vdev.conf), DEFINE_PROP_END_OF_LIST(), }; @@ -918,16 +912,16 @@ static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data) VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); k->init = virtio_ccw_rng_init; - k->exit = virtio_ccw_rng_exit; + k->exit = virtio_ccw_exit; dc->reset = virtio_ccw_reset; dc->props = virtio_ccw_rng_properties; } static const TypeInfo virtio_ccw_rng = { - .name = "virtio-rng-ccw", + .name = TYPE_VIRTIO_RNG_CCW, .parent = TYPE_VIRTIO_CCW_DEVICE, - .instance_size = sizeof(VirtioCcwDevice), - .instance_init = virtio_ccw_rng_initfn, + .instance_size = sizeof(VirtIORNGCcw), + .instance_init = virtio_ccw_rng_instance_init, .class_init = virtio_ccw_rng_class_init, }; diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h index 35ab1a5..fea9208 100644 --- a/hw/s390x/virtio-ccw.h +++ b/hw/s390x/virtio-ccw.h @@ -74,7 +74,6 @@ struct VirtioCcwDevice { VirtIODevice *vdev; char *bus_id; uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE]; - VirtIORNGConf rng; VirtioBusState bus; /* Guest provided values: */ hwaddr indicators; @@ -146,6 +145,17 @@ typedef struct VirtIONetCcw { VirtIONet vdev; } VirtIONetCcw; +/* virtio-rng-ccw */ + +#define TYPE_VIRTIO_RNG_CCW "virtio-rng-ccw" +#define VIRTIO_RNG_CCW(obj) \ + OBJECT_CHECK(VirtIORNGCcw, (obj), TYPE_VIRTIO_RNG_CCW) + +typedef struct VirtIORNGCcw { + VirtioCcwDevice parent_obj; + VirtIORNG vdev; +} VirtIORNGCcw; + VirtualCssBus *virtual_css_bus_init(void); void virtio_ccw_device_update_status(SubchDev *sch); VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch); -- 1.7.11.7