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