2
0

virtio-crypto-pci.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/qdev-properties.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"
  22. #include "qemu/module.h"
  23. typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
  24. /*
  25. * virtio-crypto-pci: This extends VirtioPCIProxy.
  26. */
  27. #define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
  28. #define VIRTIO_CRYPTO_PCI(obj) \
  29. OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
  30. struct VirtIOCryptoPCI {
  31. VirtIOPCIProxy parent_obj;
  32. VirtIOCrypto vdev;
  33. };
  34. static Property virtio_crypto_pci_properties[] = {
  35. DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
  36. VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
  37. DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
  38. DEFINE_PROP_END_OF_LIST(),
  39. };
  40. static void virtio_crypto_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
  41. {
  42. VirtIOCryptoPCI *vcrypto = VIRTIO_CRYPTO_PCI(vpci_dev);
  43. DeviceState *vdev = DEVICE(&vcrypto->vdev);
  44. if (vcrypto->vdev.conf.cryptodev == NULL) {
  45. error_setg(errp, "'cryptodev' parameter expects a valid object");
  46. return;
  47. }
  48. virtio_pci_force_virtio_1(vpci_dev);
  49. if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
  50. return;
  51. }
  52. }
  53. static void virtio_crypto_pci_class_init(ObjectClass *klass, void *data)
  54. {
  55. DeviceClass *dc = DEVICE_CLASS(klass);
  56. VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
  57. PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
  58. k->realize = virtio_crypto_pci_realize;
  59. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  60. device_class_set_props(dc, virtio_crypto_pci_properties);
  61. pcidev_k->class_id = PCI_CLASS_OTHERS;
  62. }
  63. static void virtio_crypto_initfn(Object *obj)
  64. {
  65. VirtIOCryptoPCI *dev = VIRTIO_CRYPTO_PCI(obj);
  66. virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
  67. TYPE_VIRTIO_CRYPTO);
  68. }
  69. static const VirtioPCIDeviceTypeInfo virtio_crypto_pci_info = {
  70. .generic_name = TYPE_VIRTIO_CRYPTO_PCI,
  71. .instance_size = sizeof(VirtIOCryptoPCI),
  72. .instance_init = virtio_crypto_initfn,
  73. .class_init = virtio_crypto_pci_class_init,
  74. };
  75. static void virtio_crypto_pci_register_types(void)
  76. {
  77. virtio_pci_types_register(&virtio_crypto_pci_info);
  78. }
  79. type_init(virtio_crypto_pci_register_types)