]> git.proxmox.com Git - mirror_qemu.git/blame - hw/virtio/virtio-crypto-pci.c
Revert "Revert "globals: Allow global properties to be optional""
[mirror_qemu.git] / hw / virtio / virtio-crypto-pci.c
CommitLineData
b307d308
GA
1/*
2 * Virtio crypto device
3 *
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5 *
6 * Authors:
7 * Gonglei <arei.gonglei@huawei.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or
10 * (at your option) any later version. See the COPYING file in the
11 * top-level directory.
12 *
13 */
0b8fa32f 14
b307d308
GA
15#include "qemu/osdep.h"
16#include "hw/pci/pci.h"
17#include "hw/virtio/virtio.h"
18#include "hw/virtio/virtio-bus.h"
19#include "hw/virtio/virtio-pci.h"
20#include "hw/virtio/virtio-crypto.h"
21#include "qapi/error.h"
0b8fa32f 22#include "qemu/module.h"
b307d308 23
7c8681d0
JQ
24typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
25
26/*
27 * virtio-crypto-pci: This extends VirtioPCIProxy.
28 */
29#define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
30#define VIRTIO_CRYPTO_PCI(obj) \
31 OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
32
33struct VirtIOCryptoPCI {
34 VirtIOPCIProxy parent_obj;
35 VirtIOCrypto vdev;
36};
37
b307d308
GA
38static Property virtio_crypto_pci_properties[] = {
39 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
40 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
41 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
42 DEFINE_PROP_END_OF_LIST(),
43};
44
45static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
46{
47 VirtIOCryptoPCI *vcrypto = VIRTIO_CRYPTO_PCI(vpci_dev);
48 DeviceState *vdev = DEVICE(&vcrypto->vdev);
49
305f5131
GA
50 if (vcrypto->vdev.conf.cryptodev == NULL) {
51 error_setg(errp, "'cryptodev' parameter expects a valid object");
52 return;
53 }
54
b307d308 55 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
f2784eed
DB
56 if (!virtio_pci_force_virtio_1(vpci_dev, errp)) {
57 return;
58 }
b307d308
GA
59 object_property_set_bool(OBJECT(vdev), true, "realized", errp);
60 object_property_set_link(OBJECT(vcrypto),
61 OBJECT(vcrypto->vdev.conf.cryptodev), "cryptodev",
62 NULL);
63}
64
65static void virtio_crypto_pci_class_init(ObjectClass *klass, void *data)
66{
67 DeviceClass *dc = DEVICE_CLASS(klass);
68 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
69 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
70
71 k->realize = virtio_crypto_pci_realize;
72 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
73 dc->props = virtio_crypto_pci_properties;
b307d308
GA
74 pcidev_k->class_id = PCI_CLASS_OTHERS;
75}
76
77static void virtio_crypto_initfn(Object *obj)
78{
79 VirtIOCryptoPCI *dev = VIRTIO_CRYPTO_PCI(obj);
80
81 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
82 TYPE_VIRTIO_CRYPTO);
b307d308
GA
83}
84
a4ee4c8b
EH
85static const VirtioPCIDeviceTypeInfo virtio_crypto_pci_info = {
86 .generic_name = TYPE_VIRTIO_CRYPTO_PCI,
b307d308
GA
87 .instance_size = sizeof(VirtIOCryptoPCI),
88 .instance_init = virtio_crypto_initfn,
89 .class_init = virtio_crypto_pci_class_init,
90};
91
92static void virtio_crypto_pci_register_types(void)
93{
a4ee4c8b 94 virtio_pci_types_register(&virtio_crypto_pci_info);
b307d308
GA
95}
96type_init(virtio_crypto_pci_register_types)