virtio-bus.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * VirtioBus
  3. *
  4. * Copyright (C) 2012 : GreenSocs Ltd
  5. * http://www.greensocs.com/ , email: info@greensocs.com
  6. *
  7. * Developed by :
  8. * Frederic Konrad <fred.konrad@greensocs.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. #ifndef VIRTIO_BUS_H
  25. #define VIRTIO_BUS_H
  26. #include "qdev.h"
  27. #include "sysemu/sysemu.h"
  28. #include "virtio.h"
  29. #define TYPE_VIRTIO_BUS "virtio-bus"
  30. #define VIRTIO_BUS_GET_CLASS(obj) \
  31. OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
  32. #define VIRTIO_BUS_CLASS(klass) \
  33. OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
  34. #define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
  35. typedef struct VirtioBusState VirtioBusState;
  36. typedef struct VirtioBusClass {
  37. /* This is what a VirtioBus must implement */
  38. BusClass parent;
  39. void (*notify)(DeviceState *d, uint16_t vector);
  40. void (*save_config)(DeviceState *d, QEMUFile *f);
  41. void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
  42. int (*load_config)(DeviceState *d, QEMUFile *f);
  43. int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
  44. int (*load_done)(DeviceState *d, QEMUFile *f);
  45. unsigned (*get_features)(DeviceState *d);
  46. bool (*query_guest_notifiers)(DeviceState *d);
  47. int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
  48. int (*set_host_notifier)(DeviceState *d, int n, bool assigned);
  49. void (*vmstate_change)(DeviceState *d, bool running);
  50. /*
  51. * transport independent init function.
  52. * This is called by virtio-bus just after the device is plugged.
  53. */
  54. void (*device_plugged)(DeviceState *d);
  55. /*
  56. * transport independent exit function.
  57. * This is called by virtio-bus just before the device is unplugged.
  58. */
  59. void (*device_unplug)(DeviceState *d);
  60. } VirtioBusClass;
  61. struct VirtioBusState {
  62. BusState parent_obj;
  63. /*
  64. * Only one VirtIODevice can be plugged on the bus.
  65. */
  66. VirtIODevice *vdev;
  67. /*
  68. * This will be removed at the end of the series.
  69. */
  70. VirtIOBindings bindings;
  71. };
  72. int virtio_bus_plug_device(VirtIODevice *vdev);
  73. void virtio_bus_reset(VirtioBusState *bus);
  74. void virtio_bus_destroy_device(VirtioBusState *bus);
  75. /* Get the device id of the plugged device. */
  76. uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
  77. /* Get the config_len field of the plugged device. */
  78. size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus);
  79. /* Get the features of the plugged device. */
  80. uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
  81. uint32_t requested_features);
  82. /* Get bad features of the plugged device. */
  83. uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus);
  84. /* Get config of the plugged device. */
  85. void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
  86. #endif /* VIRTIO_BUS_H */