xen-bus.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2018 Citrix Systems Inc.
  3. *
  4. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  5. * See the COPYING file in the top-level directory.
  6. */
  7. #ifndef HW_XEN_BUS_H
  8. #define HW_XEN_BUS_H
  9. #include "hw/xen/xen_backend_ops.h"
  10. #include "hw/sysbus.h"
  11. #include "qemu/notify.h"
  12. #include "qom/object.h"
  13. typedef struct XenEventChannel XenEventChannel;
  14. struct XenDevice {
  15. DeviceState qdev;
  16. domid_t frontend_id;
  17. char *name;
  18. struct qemu_xs_handle *xsh;
  19. char *backend_path, *frontend_path;
  20. enum xenbus_state backend_state, frontend_state;
  21. Notifier exit;
  22. struct qemu_xs_watch *backend_state_watch, *frontend_state_watch;
  23. bool backend_online;
  24. struct qemu_xs_watch *backend_online_watch;
  25. xengnttab_handle *xgth;
  26. bool inactive;
  27. QLIST_HEAD(, XenEventChannel) event_channels;
  28. QLIST_ENTRY(XenDevice) list;
  29. };
  30. typedef struct XenDevice XenDevice;
  31. typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
  32. typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
  33. typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
  34. enum xenbus_state frontend_state,
  35. Error **errp);
  36. typedef void (*XenDeviceUnrealize)(XenDevice *xendev);
  37. struct XenDeviceClass {
  38. /*< private >*/
  39. DeviceClass parent_class;
  40. /*< public >*/
  41. const char *backend;
  42. const char *device;
  43. XenDeviceGetName get_name;
  44. XenDeviceRealize realize;
  45. XenDeviceFrontendChanged frontend_changed;
  46. XenDeviceUnrealize unrealize;
  47. };
  48. #define TYPE_XEN_DEVICE "xen-device"
  49. OBJECT_DECLARE_TYPE(XenDevice, XenDeviceClass, XEN_DEVICE)
  50. struct XenBus {
  51. BusState qbus;
  52. domid_t backend_id;
  53. struct qemu_xs_handle *xsh;
  54. unsigned int backend_types;
  55. struct qemu_xs_watch **backend_watch;
  56. QLIST_HEAD(, XenDevice) inactive_devices;
  57. };
  58. struct XenBusClass {
  59. /*< private >*/
  60. BusClass parent_class;
  61. };
  62. #define TYPE_XEN_BUS "xen-bus"
  63. OBJECT_DECLARE_TYPE(XenBus, XenBusClass,
  64. XEN_BUS)
  65. void xen_bus_init(void);
  66. void xen_device_backend_set_state(XenDevice *xendev,
  67. enum xenbus_state state);
  68. enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
  69. void xen_device_backend_printf(XenDevice *xendev, const char *key,
  70. const char *fmt, ...)
  71. G_GNUC_PRINTF(3, 4);
  72. void xen_device_frontend_printf(XenDevice *xendev, const char *key,
  73. const char *fmt, ...)
  74. G_GNUC_PRINTF(3, 4);
  75. int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
  76. const char *fmt, ...)
  77. G_GNUC_SCANF(3, 4);
  78. void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
  79. Error **errp);
  80. void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
  81. unsigned int nr_refs, int prot,
  82. Error **errp);
  83. void xen_device_unmap_grant_refs(XenDevice *xendev, void *map, uint32_t *refs,
  84. unsigned int nr_refs, Error **errp);
  85. typedef struct XenDeviceGrantCopySegment {
  86. union {
  87. void *virt;
  88. struct {
  89. uint32_t ref;
  90. off_t offset;
  91. } foreign;
  92. } source, dest;
  93. size_t len;
  94. } XenDeviceGrantCopySegment;
  95. void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
  96. XenDeviceGrantCopySegment segs[],
  97. unsigned int nr_segs, Error **errp);
  98. typedef bool (*XenEventHandler)(void *opaque);
  99. XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
  100. unsigned int port,
  101. XenEventHandler handler,
  102. void *opaque, Error **errp);
  103. void xen_device_set_event_channel_context(XenDevice *xendev,
  104. XenEventChannel *channel,
  105. AioContext *ctx,
  106. Error **errp);
  107. void xen_device_notify_event_channel(XenDevice *xendev,
  108. XenEventChannel *channel,
  109. Error **errp);
  110. void xen_device_unbind_event_channel(XenDevice *xendev,
  111. XenEventChannel *channel,
  112. Error **errp);
  113. #endif /* HW_XEN_BUS_H */