virtio-serial-pci.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Virtio serial PCI Bindings
  3. *
  4. * Copyright IBM, Corp. 2007
  5. * Copyright (c) 2009 CodeSourcery
  6. *
  7. * Authors:
  8. * Anthony Liguori <aliguori@us.ibm.com>
  9. * Paul Brook <paul@codesourcery.com>
  10. *
  11. * This work is licensed under the terms of the GNU GPL, version 2. See
  12. * the COPYING file in the top-level directory.
  13. *
  14. * Contributions after 2012-01-13 are licensed under the terms of the
  15. * GNU GPL, version 2 or (at your option) any later version.
  16. */
  17. #include "qemu/osdep.h"
  18. #include "hw/qdev-properties.h"
  19. #include "hw/virtio/virtio-serial.h"
  20. #include "qemu/module.h"
  21. #include "virtio-pci.h"
  22. typedef struct VirtIOSerialPCI VirtIOSerialPCI;
  23. /*
  24. * virtio-serial-pci: This extends VirtioPCIProxy.
  25. */
  26. #define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci-base"
  27. #define VIRTIO_SERIAL_PCI(obj) \
  28. OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
  29. struct VirtIOSerialPCI {
  30. VirtIOPCIProxy parent_obj;
  31. VirtIOSerial vdev;
  32. };
  33. static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
  34. {
  35. VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev);
  36. DeviceState *vdev = DEVICE(&dev->vdev);
  37. DeviceState *proxy = DEVICE(vpci_dev);
  38. char *bus_name;
  39. if (vpci_dev->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
  40. vpci_dev->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
  41. vpci_dev->class_code != PCI_CLASS_OTHERS) { /* qemu-kvm */
  42. vpci_dev->class_code = PCI_CLASS_COMMUNICATION_OTHER;
  43. }
  44. /* backwards-compatibility with machines that were created with
  45. DEV_NVECTORS_UNSPECIFIED */
  46. if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
  47. vpci_dev->nvectors = dev->vdev.serial.max_virtserial_ports + 1;
  48. }
  49. /*
  50. * For command line compatibility, this sets the virtio-serial-device bus
  51. * name as before.
  52. */
  53. if (proxy->id) {
  54. bus_name = g_strdup_printf("%s.0", proxy->id);
  55. virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
  56. g_free(bus_name);
  57. }
  58. qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
  59. object_property_set_bool(OBJECT(vdev), true, "realized", errp);
  60. }
  61. static Property virtio_serial_pci_properties[] = {
  62. DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
  63. VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
  64. DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
  65. DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
  66. DEFINE_PROP_END_OF_LIST(),
  67. };
  68. static void virtio_serial_pci_class_init(ObjectClass *klass, void *data)
  69. {
  70. DeviceClass *dc = DEVICE_CLASS(klass);
  71. VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
  72. PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
  73. k->realize = virtio_serial_pci_realize;
  74. set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
  75. dc->props = virtio_serial_pci_properties;
  76. pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
  77. pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE;
  78. pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
  79. pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
  80. }
  81. static void virtio_serial_pci_instance_init(Object *obj)
  82. {
  83. VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(obj);
  84. virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
  85. TYPE_VIRTIO_SERIAL);
  86. }
  87. static const VirtioPCIDeviceTypeInfo virtio_serial_pci_info = {
  88. .base_name = TYPE_VIRTIO_SERIAL_PCI,
  89. .generic_name = "virtio-serial-pci",
  90. .transitional_name = "virtio-serial-pci-transitional",
  91. .non_transitional_name = "virtio-serial-pci-non-transitional",
  92. .instance_size = sizeof(VirtIOSerialPCI),
  93. .instance_init = virtio_serial_pci_instance_init,
  94. .class_init = virtio_serial_pci_class_init,
  95. };
  96. static void virtio_serial_pci_register(void)
  97. {
  98. virtio_pci_types_register(&virtio_serial_pci_info);
  99. }
  100. type_init(virtio_serial_pci_register)