2
0

hyperv.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Hyper-V guest/hypervisor interaction
  3. *
  4. * Copyright (c) 2015-2018 Virtuozzo International GmbH.
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. */
  9. #ifndef HW_HYPERV_HYPERV_H
  10. #define HW_HYPERV_HYPERV_H
  11. #include "cpu-qom.h"
  12. #include "hw/hyperv/hyperv-proto.h"
  13. typedef struct HvSintRoute HvSintRoute;
  14. /*
  15. * Callback executed in a bottom-half when the status of posting the message
  16. * becomes known, before unblocking the connection for further messages
  17. */
  18. typedef void (*HvSintMsgCb)(void *data, int status);
  19. HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
  20. HvSintMsgCb cb, void *cb_data);
  21. void hyperv_sint_route_ref(HvSintRoute *sint_route);
  22. void hyperv_sint_route_unref(HvSintRoute *sint_route);
  23. int hyperv_sint_route_set_sint(HvSintRoute *sint_route);
  24. /*
  25. * Submit a message to be posted in vcpu context. If the submission succeeds,
  26. * the status of posting the message is reported via the callback associated
  27. * with the @sint_route; until then no more messages are accepted.
  28. */
  29. int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg);
  30. /*
  31. * Set event flag @eventno, and signal the SINT if the flag has changed.
  32. */
  33. int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno);
  34. /*
  35. * Handler for messages arriving from the guest via HV_POST_MESSAGE hypercall.
  36. * Executed in vcpu context.
  37. */
  38. typedef uint16_t (*HvMsgHandler)(const struct hyperv_post_message_input *msg,
  39. void *data);
  40. /*
  41. * Associate @handler with the message connection @conn_id, such that @handler
  42. * is called with @data when the guest executes HV_POST_MESSAGE hypercall on
  43. * @conn_id. If @handler is NULL clear the association.
  44. */
  45. int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data);
  46. /*
  47. * Associate @notifier with the event connection @conn_id, such that @notifier
  48. * is signaled when the guest executes HV_SIGNAL_EVENT hypercall on @conn_id.
  49. * If @notifier is NULL clear the association.
  50. */
  51. int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier);
  52. /*
  53. * Process HV_POST_MESSAGE hypercall: parse the data in the guest memory as
  54. * specified in @param, and call the HvMsgHandler associated with the
  55. * connection on the message contained therein.
  56. */
  57. uint16_t hyperv_hcall_post_message(uint64_t param, bool fast);
  58. /*
  59. * Process HV_SIGNAL_EVENT hypercall: signal the EventNotifier associated with
  60. * the connection as specified in @param.
  61. */
  62. uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast);
  63. static inline uint32_t hyperv_vp_index(CPUState *cs)
  64. {
  65. return cs->cpu_index;
  66. }
  67. void hyperv_synic_add(CPUState *cs);
  68. void hyperv_synic_reset(CPUState *cs);
  69. void hyperv_synic_update(CPUState *cs, bool enable,
  70. hwaddr msg_page_addr, hwaddr event_page_addr);
  71. bool hyperv_is_synic_enabled(void);
  72. /*
  73. * Process HVCALL_RESET_DEBUG_SESSION hypercall.
  74. */
  75. uint16_t hyperv_hcall_reset_dbg_session(uint64_t outgpa);
  76. /*
  77. * Process HVCALL_RETREIVE_DEBUG_DATA hypercall.
  78. */
  79. uint16_t hyperv_hcall_retreive_dbg_data(uint64_t ingpa, uint64_t outgpa,
  80. bool fast);
  81. /*
  82. * Process HVCALL_POST_DEBUG_DATA hypercall.
  83. */
  84. uint16_t hyperv_hcall_post_dbg_data(uint64_t ingpa, uint64_t outgpa, bool fast);
  85. uint32_t hyperv_syndbg_send(uint64_t ingpa, uint32_t count);
  86. uint32_t hyperv_syndbg_recv(uint64_t ingpa, uint32_t count);
  87. void hyperv_syndbg_set_pending_page(uint64_t ingpa);
  88. uint64_t hyperv_syndbg_query_options(void);
  89. typedef enum HvSynthDbgMsgType {
  90. HV_SYNDBG_MSG_CONNECTION_INFO,
  91. HV_SYNDBG_MSG_SEND,
  92. HV_SYNDBG_MSG_RECV,
  93. HV_SYNDBG_MSG_SET_PENDING_PAGE,
  94. HV_SYNDBG_MSG_QUERY_OPTIONS
  95. } HvDbgSynthMsgType;
  96. typedef struct HvSynDbgMsg {
  97. HvDbgSynthMsgType type;
  98. union {
  99. struct {
  100. uint32_t host_ip;
  101. uint16_t host_port;
  102. } connection_info;
  103. struct {
  104. uint64_t buf_gpa;
  105. uint32_t count;
  106. uint32_t pending_count;
  107. bool is_raw;
  108. } send;
  109. struct {
  110. uint64_t buf_gpa;
  111. uint32_t count;
  112. uint32_t options;
  113. uint64_t timeout;
  114. uint32_t retrieved_count;
  115. bool is_raw;
  116. } recv;
  117. struct {
  118. uint64_t buf_gpa;
  119. } pending_page;
  120. struct {
  121. uint64_t options;
  122. } query_options;
  123. } u;
  124. } HvSynDbgMsg;
  125. typedef uint16_t (*HvSynDbgHandler)(void *context, HvSynDbgMsg *msg);
  126. void hyperv_set_syndbg_handler(HvSynDbgHandler handler, void *context);
  127. bool hyperv_are_vmbus_recommended_features_enabled(void);
  128. void hyperv_set_vmbus_recommended_features_enabled(void);
  129. #endif