]> git.proxmox.com Git - mirror_qemu.git/blame - hw/virtio/virtio-crypto-pci.c
Merge tag 'pull-maintainer-may24-160524-2' of https://gitlab.com/stsquad/qemu into...
[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"
a27bd6c7 17#include "hw/qdev-properties.h"
b307d308
GA
18#include "hw/virtio/virtio.h"
19#include "hw/virtio/virtio-bus.h"
20#include "hw/virtio/virtio-pci.h"
21#include "hw/virtio/virtio-crypto.h"
22#include "qapi/error.h"
0b8fa32f 23#include "qemu/module.h"
db1015e9 24#include "qom/object.h"
b307d308 25
7c8681d0
JQ
26typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
27
28/*
29 * virtio-crypto-pci: This extends VirtioPCIProxy.
30 */
31#define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
8110fa1d
EH
32DECLARE_INSTANCE_CHECKER(VirtIOCryptoPCI, VIRTIO_CRYPTO_PCI,
33 TYPE_VIRTIO_CRYPTO_PCI)
7c8681d0
JQ
34
35struct VirtIOCryptoPCI {
36 VirtIOPCIProxy parent_obj;
37 VirtIOCrypto vdev;
38};
39
b307d308
GA
40static Property virtio_crypto_pci_properties[] = {
41 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
42 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
43 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
44 DEFINE_PROP_END_OF_LIST(),
45};
46
47static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
48{
49 VirtIOCryptoPCI *vcrypto = VIRTIO_CRYPTO_PCI(vpci_dev);
50 DeviceState *vdev = DEVICE(&vcrypto->vdev);
51
305f5131
GA
52 if (vcrypto->vdev.conf.cryptodev == NULL) {
53 error_setg(errp, "'cryptodev' parameter expects a valid object");
54 return;
55 }
56
dd56040d 57 virtio_pci_force_virtio_1(vpci_dev);
79c3e2bc
MA
58 if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
59 return;
60 }
b307d308
GA
61}
62
63static void virtio_crypto_pci_class_init(ObjectClass *klass, void *data)
64{
65 DeviceClass *dc = DEVICE_CLASS(klass);
66 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
67 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
68
69 k->realize = virtio_crypto_pci_realize;
70 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
4f67d30b 71 device_class_set_props(dc, virtio_crypto_pci_properties);
b307d308
GA
72 pcidev_k->class_id = PCI_CLASS_OTHERS;
73}
74
75static void virtio_crypto_initfn(Object *obj)
76{
77 VirtIOCryptoPCI *dev = VIRTIO_CRYPTO_PCI(obj);
78
79 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
80 TYPE_VIRTIO_CRYPTO);
b307d308
GA
81}
82
a4ee4c8b
EH
83static const VirtioPCIDeviceTypeInfo virtio_crypto_pci_info = {
84 .generic_name = TYPE_VIRTIO_CRYPTO_PCI,
b307d308
GA
85 .instance_size = sizeof(VirtIOCryptoPCI),
86 .instance_init = virtio_crypto_initfn,
87 .class_init = virtio_crypto_pci_class_init,
88};
89
90static void virtio_crypto_pci_register_types(void)
91{
a4ee4c8b 92 virtio_pci_types_register(&virtio_crypto_pci_info);
b307d308
GA
93}
94type_init(virtio_crypto_pci_register_types)