xref: /qemu/hw/virtio/virtio-crypto-pci.c (revision 305f5131ac30b4a03e698bae0976f4cd24bb0a86)
1b307d308SGonglei /*
2b307d308SGonglei  * Virtio crypto device
3b307d308SGonglei  *
4b307d308SGonglei  * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5b307d308SGonglei  *
6b307d308SGonglei  * Authors:
7b307d308SGonglei  *    Gonglei <arei.gonglei@huawei.com>
8b307d308SGonglei  *
9b307d308SGonglei  * This work is licensed under the terms of the GNU GPL, version 2 or
10b307d308SGonglei  * (at your option) any later version.  See the COPYING file in the
11b307d308SGonglei  * top-level directory.
12b307d308SGonglei  *
13b307d308SGonglei  */
14b307d308SGonglei #include "qemu/osdep.h"
15b307d308SGonglei #include "hw/pci/pci.h"
16b307d308SGonglei #include "hw/virtio/virtio.h"
17b307d308SGonglei #include "hw/virtio/virtio-bus.h"
18b307d308SGonglei #include "hw/virtio/virtio-pci.h"
19b307d308SGonglei #include "hw/virtio/virtio-crypto.h"
20b307d308SGonglei #include "qapi/error.h"
21b307d308SGonglei 
22b307d308SGonglei static Property virtio_crypto_pci_properties[] = {
23b307d308SGonglei     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
24b307d308SGonglei                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
25b307d308SGonglei     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
26b307d308SGonglei     DEFINE_PROP_END_OF_LIST(),
27b307d308SGonglei };
28b307d308SGonglei 
29b307d308SGonglei static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
30b307d308SGonglei {
31b307d308SGonglei     VirtIOCryptoPCI *vcrypto = VIRTIO_CRYPTO_PCI(vpci_dev);
32b307d308SGonglei     DeviceState *vdev = DEVICE(&vcrypto->vdev);
33b307d308SGonglei 
34*305f5131SGonglei     if (vcrypto->vdev.conf.cryptodev == NULL) {
35*305f5131SGonglei         error_setg(errp, "'cryptodev' parameter expects a valid object");
36*305f5131SGonglei         return;
37*305f5131SGonglei     }
38*305f5131SGonglei 
39b307d308SGonglei     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
40b307d308SGonglei     virtio_pci_force_virtio_1(vpci_dev);
41b307d308SGonglei     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
42b307d308SGonglei     object_property_set_link(OBJECT(vcrypto),
43b307d308SGonglei                  OBJECT(vcrypto->vdev.conf.cryptodev), "cryptodev",
44b307d308SGonglei                  NULL);
45b307d308SGonglei }
46b307d308SGonglei 
47b307d308SGonglei static void virtio_crypto_pci_class_init(ObjectClass *klass, void *data)
48b307d308SGonglei {
49b307d308SGonglei     DeviceClass *dc = DEVICE_CLASS(klass);
50b307d308SGonglei     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
51b307d308SGonglei     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
52b307d308SGonglei 
53b307d308SGonglei     k->realize = virtio_crypto_pci_realize;
54b307d308SGonglei     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
55b307d308SGonglei     dc->props = virtio_crypto_pci_properties;
566e724d9dSGonglei     dc->hotpluggable = false;
57b307d308SGonglei     pcidev_k->class_id = PCI_CLASS_OTHERS;
58b307d308SGonglei }
59b307d308SGonglei 
60b307d308SGonglei static void virtio_crypto_initfn(Object *obj)
61b307d308SGonglei {
62b307d308SGonglei     VirtIOCryptoPCI *dev = VIRTIO_CRYPTO_PCI(obj);
63b307d308SGonglei 
64b307d308SGonglei     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
65b307d308SGonglei                                 TYPE_VIRTIO_CRYPTO);
66b307d308SGonglei     object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev),
67b307d308SGonglei                               "cryptodev", &error_abort);
68b307d308SGonglei }
69b307d308SGonglei 
70b307d308SGonglei static const TypeInfo virtio_crypto_pci_info = {
71b307d308SGonglei     .name          = TYPE_VIRTIO_CRYPTO_PCI,
72b307d308SGonglei     .parent        = TYPE_VIRTIO_PCI,
73b307d308SGonglei     .instance_size = sizeof(VirtIOCryptoPCI),
74b307d308SGonglei     .instance_init = virtio_crypto_initfn,
75b307d308SGonglei     .class_init    = virtio_crypto_pci_class_init,
76b307d308SGonglei };
77b307d308SGonglei 
78b307d308SGonglei static void virtio_crypto_pci_register_types(void)
79b307d308SGonglei {
80b307d308SGonglei     type_register_static(&virtio_crypto_pci_info);
81b307d308SGonglei }
82b307d308SGonglei type_init(virtio_crypto_pci_register_types)
83