virtio-9p-pci.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Virtio 9p PCI Bindings
  3. *
  4. * Copyright IBM, Corp. 2010
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  12. * Contributions after 2012-01-13 are licensed under the terms of the
  13. * GNU GPL, version 2 or (at your option) any later version.
  14. */
  15. #include "qemu/osdep.h"
  16. #include "virtio-pci.h"
  17. #include "hw/9pfs/virtio-9p.h"
  18. #include "hw/qdev-properties.h"
  19. #include "qemu/module.h"
  20. /*
  21. * virtio-9p-pci: This extends VirtioPCIProxy.
  22. */
  23. #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci-base"
  24. #define VIRTIO_9P_PCI(obj) \
  25. OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
  26. typedef struct V9fsPCIState {
  27. VirtIOPCIProxy parent_obj;
  28. V9fsVirtioState vdev;
  29. } V9fsPCIState;
  30. static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
  31. {
  32. V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev);
  33. DeviceState *vdev = DEVICE(&dev->vdev);
  34. qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
  35. object_property_set_bool(OBJECT(vdev), true, "realized", errp);
  36. }
  37. static Property virtio_9p_pci_properties[] = {
  38. DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
  39. VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
  40. DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
  41. DEFINE_PROP_END_OF_LIST(),
  42. };
  43. static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
  44. {
  45. DeviceClass *dc = DEVICE_CLASS(klass);
  46. PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
  47. VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
  48. k->realize = virtio_9p_pci_realize;
  49. pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
  50. pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_9P;
  51. pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
  52. pcidev_k->class_id = 0x2;
  53. set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
  54. dc->props = virtio_9p_pci_properties;
  55. }
  56. static void virtio_9p_pci_instance_init(Object *obj)
  57. {
  58. V9fsPCIState *dev = VIRTIO_9P_PCI(obj);
  59. virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
  60. TYPE_VIRTIO_9P);
  61. }
  62. static const VirtioPCIDeviceTypeInfo virtio_9p_pci_info = {
  63. .base_name = TYPE_VIRTIO_9P_PCI,
  64. .generic_name = "virtio-9p-pci",
  65. .transitional_name = "virtio-9p-pci-transitional",
  66. .non_transitional_name = "virtio-9p-pci-non-transitional",
  67. .instance_size = sizeof(V9fsPCIState),
  68. .instance_init = virtio_9p_pci_instance_init,
  69. .class_init = virtio_9p_pci_class_init,
  70. };
  71. static void virtio_9p_pci_register(void)
  72. {
  73. virtio_pci_types_register(&virtio_9p_pci_info);
  74. }
  75. type_init(virtio_9p_pci_register)