2
0

vhost-user-fs-pci.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Vhost-user filesystem virtio device PCI glue
  3. *
  4. * Copyright 2018-2019 Red Hat, Inc.
  5. *
  6. * Authors:
  7. * Dr. David Alan Gilbert <dgilbert@redhat.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. #include "qemu/osdep.h"
  14. #include "hw/qdev-properties.h"
  15. #include "hw/virtio/vhost-user-fs.h"
  16. #include "virtio-pci.h"
  17. struct VHostUserFSPCI {
  18. VirtIOPCIProxy parent_obj;
  19. VHostUserFS vdev;
  20. };
  21. typedef struct VHostUserFSPCI VHostUserFSPCI;
  22. #define TYPE_VHOST_USER_FS_PCI "vhost-user-fs-pci-base"
  23. #define VHOST_USER_FS_PCI(obj) \
  24. OBJECT_CHECK(VHostUserFSPCI, (obj), TYPE_VHOST_USER_FS_PCI)
  25. static Property vhost_user_fs_pci_properties[] = {
  26. DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
  27. DEV_NVECTORS_UNSPECIFIED),
  28. DEFINE_PROP_END_OF_LIST(),
  29. };
  30. static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
  31. {
  32. VHostUserFSPCI *dev = VHOST_USER_FS_PCI(vpci_dev);
  33. DeviceState *vdev = DEVICE(&dev->vdev);
  34. if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
  35. vpci_dev->nvectors = dev->vdev.conf.num_request_queues + 1;
  36. }
  37. qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
  38. object_property_set_bool(OBJECT(vdev), true, "realized", errp);
  39. }
  40. static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data)
  41. {
  42. DeviceClass *dc = DEVICE_CLASS(klass);
  43. VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
  44. PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
  45. k->realize = vhost_user_fs_pci_realize;
  46. set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
  47. dc->props = vhost_user_fs_pci_properties;
  48. pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
  49. pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */
  50. pcidev_k->revision = 0x00;
  51. pcidev_k->class_id = PCI_CLASS_STORAGE_OTHER;
  52. }
  53. static void vhost_user_fs_pci_instance_init(Object *obj)
  54. {
  55. VHostUserFSPCI *dev = VHOST_USER_FS_PCI(obj);
  56. virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
  57. TYPE_VHOST_USER_FS);
  58. }
  59. static const VirtioPCIDeviceTypeInfo vhost_user_fs_pci_info = {
  60. .base_name = TYPE_VHOST_USER_FS_PCI,
  61. .non_transitional_name = "vhost-user-fs-pci",
  62. .instance_size = sizeof(VHostUserFSPCI),
  63. .instance_init = vhost_user_fs_pci_instance_init,
  64. .class_init = vhost_user_fs_pci_class_init,
  65. };
  66. static void vhost_user_fs_pci_register(void)
  67. {
  68. virtio_pci_types_register(&vhost_user_fs_pci_info);
  69. }
  70. type_init(vhost_user_fs_pci_register);