]> git.proxmox.com Git - mirror_qemu.git/blame - hw/virtio/virtio-crypto-pci.c
virtio: Helper for registering virtio device types
[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 */
14#include "qemu/osdep.h"
15#include "hw/pci/pci.h"
16#include "hw/virtio/virtio.h"
17#include "hw/virtio/virtio-bus.h"
18#include "hw/virtio/virtio-pci.h"
19#include "hw/virtio/virtio-crypto.h"
20#include "qapi/error.h"
21
22static Property virtio_crypto_pci_properties[] = {
23 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
24 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
25 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
26 DEFINE_PROP_END_OF_LIST(),
27};
28
29static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
30{
31 VirtIOCryptoPCI *vcrypto = VIRTIO_CRYPTO_PCI(vpci_dev);
32 DeviceState *vdev = DEVICE(&vcrypto->vdev);
33
305f5131
GA
34 if (vcrypto->vdev.conf.cryptodev == NULL) {
35 error_setg(errp, "'cryptodev' parameter expects a valid object");
36 return;
37 }
38
b307d308
GA
39 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
40 virtio_pci_force_virtio_1(vpci_dev);
41 object_property_set_bool(OBJECT(vdev), true, "realized", errp);
42 object_property_set_link(OBJECT(vcrypto),
43 OBJECT(vcrypto->vdev.conf.cryptodev), "cryptodev",
44 NULL);
45}
46
47static void virtio_crypto_pci_class_init(ObjectClass *klass, void *data)
48{
49 DeviceClass *dc = DEVICE_CLASS(klass);
50 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
51 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
52
53 k->realize = virtio_crypto_pci_realize;
54 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
55 dc->props = virtio_crypto_pci_properties;
b307d308
GA
56 pcidev_k->class_id = PCI_CLASS_OTHERS;
57}
58
59static void virtio_crypto_initfn(Object *obj)
60{
61 VirtIOCryptoPCI *dev = VIRTIO_CRYPTO_PCI(obj);
62
63 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
64 TYPE_VIRTIO_CRYPTO);
b307d308
GA
65}
66
a4ee4c8b
EH
67static const VirtioPCIDeviceTypeInfo virtio_crypto_pci_info = {
68 .generic_name = TYPE_VIRTIO_CRYPTO_PCI,
b307d308
GA
69 .instance_size = sizeof(VirtIOCryptoPCI),
70 .instance_init = virtio_crypto_initfn,
71 .class_init = virtio_crypto_pci_class_init,
72};
73
74static void virtio_crypto_pci_register_types(void)
75{
a4ee4c8b 76 virtio_pci_types_register(&virtio_crypto_pci_info);
b307d308
GA
77}
78type_init(virtio_crypto_pci_register_types)