xen-bus.h 4.7 KB

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