hyperv-proto.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Definitions for Hyper-V guest/hypervisor interaction
  3. *
  4. * Copyright (c) 2017-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_PROTO_H
  10. #define HW_HYPERV_HYPERV_PROTO_H
  11. #include "qemu/bitmap.h"
  12. /*
  13. * Hypercall status code
  14. */
  15. #define HV_STATUS_SUCCESS 0
  16. #define HV_STATUS_INVALID_HYPERCALL_CODE 2
  17. #define HV_STATUS_INVALID_HYPERCALL_INPUT 3
  18. #define HV_STATUS_INVALID_ALIGNMENT 4
  19. #define HV_STATUS_INVALID_PARAMETER 5
  20. #define HV_STATUS_INSUFFICIENT_MEMORY 11
  21. #define HV_STATUS_INVALID_PORT_ID 17
  22. #define HV_STATUS_INVALID_CONNECTION_ID 18
  23. #define HV_STATUS_INSUFFICIENT_BUFFERS 19
  24. #define HV_STATUS_NOT_ACKNOWLEDGED 20
  25. #define HV_STATUS_NO_DATA 27
  26. /*
  27. * Hypercall numbers
  28. */
  29. #define HV_POST_MESSAGE 0x005c
  30. #define HV_SIGNAL_EVENT 0x005d
  31. #define HV_POST_DEBUG_DATA 0x0069
  32. #define HV_RETRIEVE_DEBUG_DATA 0x006a
  33. #define HV_RESET_DEBUG_SESSION 0x006b
  34. #define HV_HYPERCALL_FAST (1u << 16)
  35. /*
  36. * Message size
  37. */
  38. #define HV_MESSAGE_PAYLOAD_SIZE 240
  39. /*
  40. * Message types
  41. */
  42. #define HV_MESSAGE_NONE 0x00000000
  43. #define HV_MESSAGE_VMBUS 0x00000001
  44. #define HV_MESSAGE_UNMAPPED_GPA 0x80000000
  45. #define HV_MESSAGE_GPA_INTERCEPT 0x80000001
  46. #define HV_MESSAGE_TIMER_EXPIRED 0x80000010
  47. #define HV_MESSAGE_INVALID_VP_REGISTER_VALUE 0x80000020
  48. #define HV_MESSAGE_UNRECOVERABLE_EXCEPTION 0x80000021
  49. #define HV_MESSAGE_UNSUPPORTED_FEATURE 0x80000022
  50. #define HV_MESSAGE_EVENTLOG_BUFFERCOMPLETE 0x80000040
  51. #define HV_MESSAGE_X64_IOPORT_INTERCEPT 0x80010000
  52. #define HV_MESSAGE_X64_MSR_INTERCEPT 0x80010001
  53. #define HV_MESSAGE_X64_CPUID_INTERCEPT 0x80010002
  54. #define HV_MESSAGE_X64_EXCEPTION_INTERCEPT 0x80010003
  55. #define HV_MESSAGE_X64_APIC_EOI 0x80010004
  56. #define HV_MESSAGE_X64_LEGACY_FP_ERROR 0x80010005
  57. /*
  58. * Hyper-V Synthetic debug options MSR
  59. */
  60. #define HV_X64_MSR_SYNDBG_CONTROL 0x400000F1
  61. #define HV_X64_MSR_SYNDBG_STATUS 0x400000F2
  62. #define HV_X64_MSR_SYNDBG_SEND_BUFFER 0x400000F3
  63. #define HV_X64_MSR_SYNDBG_RECV_BUFFER 0x400000F4
  64. #define HV_X64_MSR_SYNDBG_PENDING_BUFFER 0x400000F5
  65. #define HV_X64_MSR_SYNDBG_OPTIONS 0x400000FF
  66. #define HV_X64_SYNDBG_OPTION_USE_HCALLS BIT(2)
  67. /*
  68. * Message flags
  69. */
  70. #define HV_MESSAGE_FLAG_PENDING 0x1
  71. /*
  72. * Number of synthetic interrupts
  73. */
  74. #define HV_SINT_COUNT 16
  75. /*
  76. * Event flags number per SINT
  77. */
  78. #define HV_EVENT_FLAGS_COUNT (256 * 8)
  79. /*
  80. * Connection id valid bits
  81. */
  82. #define HV_CONNECTION_ID_MASK 0x00ffffff
  83. /*
  84. * Input structure for POST_MESSAGE hypercall
  85. */
  86. struct hyperv_post_message_input {
  87. uint32_t connection_id;
  88. uint32_t _reserved;
  89. uint32_t message_type;
  90. uint32_t payload_size;
  91. uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE];
  92. };
  93. /*
  94. * Input structure for SIGNAL_EVENT hypercall
  95. */
  96. struct hyperv_signal_event_input {
  97. uint32_t connection_id;
  98. uint16_t flag_number;
  99. uint16_t _reserved_zero;
  100. };
  101. /*
  102. * SynIC message structures
  103. */
  104. struct hyperv_message_header {
  105. uint32_t message_type;
  106. uint8_t payload_size;
  107. uint8_t message_flags; /* HV_MESSAGE_FLAG_XX */
  108. uint8_t _reserved[2];
  109. uint64_t sender;
  110. };
  111. struct hyperv_message {
  112. struct hyperv_message_header header;
  113. uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE];
  114. };
  115. struct hyperv_message_page {
  116. struct hyperv_message slot[HV_SINT_COUNT];
  117. };
  118. /*
  119. * SynIC event flags structures
  120. */
  121. struct hyperv_event_flags {
  122. DECLARE_BITMAP(flags, HV_EVENT_FLAGS_COUNT);
  123. };
  124. struct hyperv_event_flags_page {
  125. struct hyperv_event_flags slot[HV_SINT_COUNT];
  126. };
  127. /*
  128. * Kernel debugger structures
  129. */
  130. /* Options flags for hyperv_reset_debug_session */
  131. #define HV_DEBUG_PURGE_INCOMING_DATA 0x00000001
  132. #define HV_DEBUG_PURGE_OUTGOING_DATA 0x00000002
  133. struct hyperv_reset_debug_session_input {
  134. uint32_t options;
  135. } __attribute__ ((__packed__));
  136. struct hyperv_reset_debug_session_output {
  137. uint32_t host_ip;
  138. uint32_t target_ip;
  139. uint16_t host_port;
  140. uint16_t target_port;
  141. uint8_t host_mac[6];
  142. uint8_t target_mac[6];
  143. } __attribute__ ((__packed__));
  144. /* Options for hyperv_post_debug_data */
  145. #define HV_DEBUG_POST_LOOP 0x00000001
  146. struct hyperv_post_debug_data_input {
  147. uint32_t count;
  148. uint32_t options;
  149. /*uint8_t data[HV_HYP_PAGE_SIZE - 2 * sizeof(uint32_t)];*/
  150. } __attribute__ ((__packed__));
  151. struct hyperv_post_debug_data_output {
  152. uint32_t pending_count;
  153. } __attribute__ ((__packed__));
  154. /* Options for hyperv_retrieve_debug_data */
  155. #define HV_DEBUG_RETRIEVE_LOOP 0x00000001
  156. #define HV_DEBUG_RETRIEVE_TEST_ACTIVITY 0x00000002
  157. struct hyperv_retrieve_debug_data_input {
  158. uint32_t count;
  159. uint32_t options;
  160. uint64_t timeout;
  161. } __attribute__ ((__packed__));
  162. struct hyperv_retrieve_debug_data_output {
  163. uint32_t retrieved_count;
  164. uint32_t remaining_count;
  165. } __attribute__ ((__packed__));
  166. #endif