xref: /qemu/hw/s390x/virtio-ccw-crypto.c (revision 0b8fa32f)
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"
12a8e1b5ffSThomas Huth #include "hw/virtio/virtio.h"
13a8e1b5ffSThomas Huth #include "qapi/error.h"
14*0b8fa32fSMarkus Armbruster #include "qemu/module.h"
15a8e1b5ffSThomas Huth #include "virtio-ccw.h"
16a8e1b5ffSThomas Huth 
17a8e1b5ffSThomas Huth static void virtio_ccw_crypto_realize(VirtioCcwDevice *ccw_dev, Error **errp)
18a8e1b5ffSThomas Huth {
19a8e1b5ffSThomas Huth     VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(ccw_dev);
20a8e1b5ffSThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
21a8e1b5ffSThomas Huth     Error *err = NULL;
22a8e1b5ffSThomas Huth 
23a8e1b5ffSThomas Huth     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
24a8e1b5ffSThomas Huth     object_property_set_bool(OBJECT(vdev), true, "realized", &err);
25a8e1b5ffSThomas Huth     if (err) {
26a8e1b5ffSThomas Huth         error_propagate(errp, err);
27a8e1b5ffSThomas Huth         return;
28a8e1b5ffSThomas Huth     }
29a8e1b5ffSThomas Huth 
30a8e1b5ffSThomas Huth     object_property_set_link(OBJECT(vdev),
31a8e1b5ffSThomas Huth                              OBJECT(dev->vdev.conf.cryptodev), "cryptodev",
32a8e1b5ffSThomas Huth                              NULL);
33a8e1b5ffSThomas Huth }
34a8e1b5ffSThomas Huth 
35a8e1b5ffSThomas Huth static void virtio_ccw_crypto_instance_init(Object *obj)
36a8e1b5ffSThomas Huth {
37a8e1b5ffSThomas Huth     VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(obj);
38a8e1b5ffSThomas Huth     VirtioCcwDevice *ccw_dev = VIRTIO_CCW_DEVICE(obj);
39a8e1b5ffSThomas Huth 
40a8e1b5ffSThomas Huth     ccw_dev->force_revision_1 = true;
41a8e1b5ffSThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
42a8e1b5ffSThomas Huth                                 TYPE_VIRTIO_CRYPTO);
43a8e1b5ffSThomas Huth }
44a8e1b5ffSThomas Huth 
45a8e1b5ffSThomas Huth static Property virtio_ccw_crypto_properties[] = {
46a8e1b5ffSThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
47a8e1b5ffSThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
48a8e1b5ffSThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
49a8e1b5ffSThomas Huth                        VIRTIO_CCW_MAX_REV),
50a8e1b5ffSThomas Huth     DEFINE_PROP_END_OF_LIST(),
51a8e1b5ffSThomas Huth };
52a8e1b5ffSThomas Huth 
53a8e1b5ffSThomas Huth static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data)
54a8e1b5ffSThomas Huth {
55a8e1b5ffSThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
56a8e1b5ffSThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
57a8e1b5ffSThomas Huth 
58a8e1b5ffSThomas Huth     k->realize = virtio_ccw_crypto_realize;
59a8e1b5ffSThomas Huth     dc->props = virtio_ccw_crypto_properties;
60a8e1b5ffSThomas Huth     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
61a8e1b5ffSThomas Huth }
62a8e1b5ffSThomas Huth 
63a8e1b5ffSThomas Huth static const TypeInfo virtio_ccw_crypto = {
64a8e1b5ffSThomas Huth     .name          = TYPE_VIRTIO_CRYPTO_CCW,
65a8e1b5ffSThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
66a8e1b5ffSThomas Huth     .instance_size = sizeof(VirtIOCryptoCcw),
67a8e1b5ffSThomas Huth     .instance_init = virtio_ccw_crypto_instance_init,
68a8e1b5ffSThomas Huth     .class_init    = virtio_ccw_crypto_class_init,
69a8e1b5ffSThomas Huth };
70a8e1b5ffSThomas Huth 
71a8e1b5ffSThomas Huth static void virtio_ccw_crypto_register(void)
72a8e1b5ffSThomas Huth {
73a8e1b5ffSThomas Huth     type_register_static(&virtio_ccw_crypto);
74a8e1b5ffSThomas Huth }
75a8e1b5ffSThomas Huth 
76a8e1b5ffSThomas Huth type_init(virtio_ccw_crypto_register)
77