xref: /openbmc/qemu/hw/s390x/virtio-ccw-rng.c (revision 503bb0b9)
1 /*
2  * virtio ccw random number generator implementation
3  *
4  * Copyright 2012, 2015 IBM Corp.
5  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8  * your option) any later version. See the COPYING file in the top-level
9  * directory.
10  */
11 
12 #include "qemu/osdep.h"
13 #include "hw/virtio/virtio.h"
14 #include "qapi/error.h"
15 #include "virtio-ccw.h"
16 
17 static void virtio_ccw_rng_realize(VirtioCcwDevice *ccw_dev, Error **errp)
18 {
19     VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
20     DeviceState *vdev = DEVICE(&dev->vdev);
21     Error *err = NULL;
22 
23     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
24     object_property_set_bool(OBJECT(vdev), true, "realized", &err);
25     if (err) {
26         error_propagate(errp, err);
27         return;
28     }
29 
30     object_property_set_link(OBJECT(dev),
31                              OBJECT(dev->vdev.conf.rng), "rng",
32                              NULL);
33 }
34 
35 static void virtio_ccw_rng_instance_init(Object *obj)
36 {
37     VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
38 
39     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
40                                 TYPE_VIRTIO_RNG);
41 }
42 
43 static Property virtio_ccw_rng_properties[] = {
44     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
45                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
46     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
47                        VIRTIO_CCW_MAX_REV),
48     DEFINE_PROP_END_OF_LIST(),
49 };
50 
51 static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
52 {
53     DeviceClass *dc = DEVICE_CLASS(klass);
54     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
55 
56     k->realize = virtio_ccw_rng_realize;
57     dc->props = virtio_ccw_rng_properties;
58     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
59 }
60 
61 static const TypeInfo virtio_ccw_rng = {
62     .name          = TYPE_VIRTIO_RNG_CCW,
63     .parent        = TYPE_VIRTIO_CCW_DEVICE,
64     .instance_size = sizeof(VirtIORNGCcw),
65     .instance_init = virtio_ccw_rng_instance_init,
66     .class_init    = virtio_ccw_rng_class_init,
67 };
68 
69 static void virtio_ccw_rng_register(void)
70 {
71     type_register_static(&virtio_ccw_rng);
72 }
73 
74 type_init(virtio_ccw_rng_register)
75