xref: /qemu/hw/s390x/virtio-ccw-crypto.c (revision a27bd6c7)
1a8e1b5ffSThomas Huth /*
2a8e1b5ffSThomas Huth  * virtio ccw crypto implementation
3a8e1b5ffSThomas Huth  *
4a8e1b5ffSThomas Huth  * Copyright 2012, 2015 IBM Corp.
5a8e1b5ffSThomas Huth  *
6a8e1b5ffSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or (at
7a8e1b5ffSThomas Huth  * your option) any later version. See the COPYING file in the top-level
8a8e1b5ffSThomas Huth  * directory.
9a8e1b5ffSThomas Huth  */
10a8e1b5ffSThomas Huth 
11a8e1b5ffSThomas Huth #include "qemu/osdep.h"
12*a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
13a8e1b5ffSThomas Huth #include "hw/virtio/virtio.h"
14a8e1b5ffSThomas Huth #include "qapi/error.h"
150b8fa32fSMarkus Armbruster #include "qemu/module.h"
16a8e1b5ffSThomas Huth #include "virtio-ccw.h"
17a8e1b5ffSThomas Huth 
18a8e1b5ffSThomas Huth static void virtio_ccw_crypto_realize(VirtioCcwDevice *ccw_dev, Error **errp)
19a8e1b5ffSThomas Huth {
20a8e1b5ffSThomas Huth     VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(ccw_dev);
21a8e1b5ffSThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
22a8e1b5ffSThomas Huth     Error *err = NULL;
23a8e1b5ffSThomas Huth 
24a8e1b5ffSThomas Huth     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
25a8e1b5ffSThomas Huth     object_property_set_bool(OBJECT(vdev), true, "realized", &err);
26a8e1b5ffSThomas Huth     if (err) {
27a8e1b5ffSThomas Huth         error_propagate(errp, err);
28a8e1b5ffSThomas Huth         return;
29a8e1b5ffSThomas Huth     }
30a8e1b5ffSThomas Huth 
31a8e1b5ffSThomas Huth     object_property_set_link(OBJECT(vdev),
32a8e1b5ffSThomas Huth                              OBJECT(dev->vdev.conf.cryptodev), "cryptodev",
33a8e1b5ffSThomas Huth                              NULL);
34a8e1b5ffSThomas Huth }
35a8e1b5ffSThomas Huth 
36a8e1b5ffSThomas Huth static void virtio_ccw_crypto_instance_init(Object *obj)
37a8e1b5ffSThomas Huth {
38a8e1b5ffSThomas Huth     VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(obj);
39a8e1b5ffSThomas Huth     VirtioCcwDevice *ccw_dev = VIRTIO_CCW_DEVICE(obj);
40a8e1b5ffSThomas Huth 
41a8e1b5ffSThomas Huth     ccw_dev->force_revision_1 = true;
42a8e1b5ffSThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
43a8e1b5ffSThomas Huth                                 TYPE_VIRTIO_CRYPTO);
44a8e1b5ffSThomas Huth }
45a8e1b5ffSThomas Huth 
46a8e1b5ffSThomas Huth static Property virtio_ccw_crypto_properties[] = {
47a8e1b5ffSThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
48a8e1b5ffSThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
49a8e1b5ffSThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
50a8e1b5ffSThomas Huth                        VIRTIO_CCW_MAX_REV),
51a8e1b5ffSThomas Huth     DEFINE_PROP_END_OF_LIST(),
52a8e1b5ffSThomas Huth };
53a8e1b5ffSThomas Huth 
54a8e1b5ffSThomas Huth static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data)
55a8e1b5ffSThomas Huth {
56a8e1b5ffSThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
57a8e1b5ffSThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
58a8e1b5ffSThomas Huth 
59a8e1b5ffSThomas Huth     k->realize = virtio_ccw_crypto_realize;
60a8e1b5ffSThomas Huth     dc->props = virtio_ccw_crypto_properties;
61a8e1b5ffSThomas Huth     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
62a8e1b5ffSThomas Huth }
63a8e1b5ffSThomas Huth 
64a8e1b5ffSThomas Huth static const TypeInfo virtio_ccw_crypto = {
65a8e1b5ffSThomas Huth     .name          = TYPE_VIRTIO_CRYPTO_CCW,
66a8e1b5ffSThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
67a8e1b5ffSThomas Huth     .instance_size = sizeof(VirtIOCryptoCcw),
68a8e1b5ffSThomas Huth     .instance_init = virtio_ccw_crypto_instance_init,
69a8e1b5ffSThomas Huth     .class_init    = virtio_ccw_crypto_class_init,
70a8e1b5ffSThomas Huth };
71a8e1b5ffSThomas Huth 
72a8e1b5ffSThomas Huth static void virtio_ccw_crypto_register(void)
73a8e1b5ffSThomas Huth {
74a8e1b5ffSThomas Huth     type_register_static(&virtio_ccw_crypto);
75a8e1b5ffSThomas Huth }
76a8e1b5ffSThomas Huth 
77a8e1b5ffSThomas Huth type_init(virtio_ccw_crypto_register)
78