Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

hyperv.h 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #ifndef _IPXE_HYPERV_H
  2. #define _IPXE_HYPERV_H
  3. /** @file
  4. *
  5. * Hyper-V interface
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/io.h>
  11. /** Hyper-V interface identification */
  12. #define HV_INTERFACE_ID 0x31237648 /* "Hv#1" */
  13. /** Guest OS identity for iPXE
  14. *
  15. * This field comprises:
  16. *
  17. * Bit 63 : set to 1 to indicate an open source OS
  18. * Bits 62:56 : OS Type
  19. * Bits 55:48 : OS ID
  20. * Bits 47:16 : Version
  21. * Bits 15:0 : Build number
  22. *
  23. * There appears to be no central registry for the "OS Type". The
  24. * specification states that "Linux is 0x100", and the FreeBSD source
  25. * states that "FreeBSD is 0x200". Both of these statements are
  26. * actually referring to the combined "OS Type" and "OS ID" field.
  27. *
  28. * We choose to use 0x98ae: this is generated by setting bit 63 (to
  29. * indicate an open source OS) and setting the OS Type+ID equal to the
  30. * PnP vendor ID used in romprefix.S. No version information or build
  31. * number is included.
  32. */
  33. #define HV_GUEST_OS_ID_IPXE ( ( 1ULL << 63 ) | ( 0x18aeULL << 48 ) )
  34. /** Enable hypercall page */
  35. #define HV_HYPERCALL_ENABLE 0x00000001UL
  36. /** Enable SynIC */
  37. #define HV_SCONTROL_ENABLE 0x00000001UL
  38. /** Enable SynIC event flags */
  39. #define HV_SIEFP_ENABLE 0x00000001UL
  40. /** Enable SynIC messages */
  41. #define HV_SIMP_ENABLE 0x00000001UL
  42. /** Perform implicit EOI upon synthetic interrupt delivery */
  43. #define HV_SINT_AUTO_EOI 0x00020000UL
  44. /** Mask synthetic interrupt */
  45. #define HV_SINT_MASKED 0x00010000UL
  46. /** Synthetic interrupt vector */
  47. #define HV_SINT_VECTOR(x) ( (x) << 0 )
  48. /** Synthetic interrupt vector mask */
  49. #define HV_SINT_VECTOR_MASK HV_SINT_VECTOR ( 0xff )
  50. /** Maximum synthetic interrupt number */
  51. #define HV_SINT_MAX 15
  52. /** Post message */
  53. #define HV_POST_MESSAGE 0x005c
  54. /** A posted message
  55. *
  56. * This is the input parameter list for the HvPostMessage hypercall.
  57. */
  58. struct hv_post_message {
  59. /** Connection ID */
  60. uint32_t id;
  61. /** Padding */
  62. uint32_t reserved;
  63. /** Type */
  64. uint32_t type;
  65. /** Length of message */
  66. uint32_t len;
  67. /** Message */
  68. uint8_t data[240];
  69. } __attribute__ (( packed ));
  70. /** A received message
  71. *
  72. * This is the HV_MESSAGE structure from the Hypervisor Top-Level
  73. * Functional Specification. The field order given in the
  74. * documentation is incorrect.
  75. */
  76. struct hv_message {
  77. /** Type */
  78. uint32_t type;
  79. /** Length of message */
  80. uint8_t len;
  81. /** Flags */
  82. uint8_t flags;
  83. /** Padding */
  84. uint16_t reserved;
  85. /** Origin */
  86. uint64_t origin;
  87. /** Message */
  88. uint8_t data[240];
  89. } __attribute__ (( packed ));
  90. /** Signal event */
  91. #define HV_SIGNAL_EVENT 0x005d
  92. /** A signalled event */
  93. struct hv_signal_event {
  94. /** Connection ID */
  95. uint32_t id;
  96. /** Flag number */
  97. uint16_t flag;
  98. /** Reserved */
  99. uint16_t reserved;
  100. } __attribute__ (( packed ));
  101. /** A received event */
  102. struct hv_event {
  103. /** Event flags */
  104. uint8_t flags[256];
  105. } __attribute__ (( packed ));
  106. /** A monitor trigger group
  107. *
  108. * This is the HV_MONITOR_TRIGGER_GROUP structure from the Hypervisor
  109. * Top-Level Functional Specification.
  110. */
  111. struct hv_monitor_trigger {
  112. /** Pending events */
  113. uint32_t pending;
  114. /** Armed events */
  115. uint32_t armed;
  116. } __attribute__ (( packed ));
  117. /** A monitor parameter set
  118. *
  119. * This is the HV_MONITOR_PARAMETER structure from the Hypervisor
  120. * Top-Level Functional Specification.
  121. */
  122. struct hv_monitor_parameter {
  123. /** Connection ID */
  124. uint32_t id;
  125. /** Flag number */
  126. uint16_t flag;
  127. /** Reserved */
  128. uint16_t reserved;
  129. } __attribute__ (( packed ));
  130. /** A monitor page
  131. *
  132. * This is the HV_MONITOR_PAGE structure from the Hypervisor Top-Level
  133. * Functional Specification.
  134. */
  135. struct hv_monitor {
  136. /** Flags */
  137. uint32_t flags;
  138. /** Reserved */
  139. uint8_t reserved_a[4];
  140. /** Trigger groups */
  141. struct hv_monitor_trigger trigger[4];
  142. /** Reserved */
  143. uint8_t reserved_b[536];
  144. /** Latencies */
  145. uint16 latency[4][32];
  146. /** Reserved */
  147. uint8_t reserved_c[256];
  148. /** Parameters */
  149. struct hv_monitor_parameter param[4][32];
  150. /** Reserved */
  151. uint8_t reserved_d[1984];
  152. } __attribute__ (( packed ));
  153. /** A synthetic interrupt controller */
  154. struct hv_synic {
  155. /** Message page */
  156. struct hv_message *message;
  157. /** Event flag page */
  158. struct hv_event *event;
  159. };
  160. /** A message buffer */
  161. union hv_message_buffer {
  162. /** Posted message */
  163. struct hv_post_message posted;
  164. /** Received message */
  165. struct hv_message received;
  166. /** Signalled event */
  167. struct hv_signal_event signalled;
  168. };
  169. /** A Hyper-V hypervisor */
  170. struct hv_hypervisor {
  171. /** Hypercall page */
  172. void *hypercall;
  173. /** Synthetic interrupt controller (SynIC) */
  174. struct hv_synic synic;
  175. /** Message buffer */
  176. union hv_message_buffer *message;
  177. /** Virtual machine bus */
  178. struct vmbus *vmbus;
  179. };
  180. #include <bits/hyperv.h>
  181. /**
  182. * Calculate the number of pages covering an address range
  183. *
  184. * @v data Start of data
  185. * @v len Length of data (must be non-zero)
  186. * @ret pfn_count Number of pages covered
  187. */
  188. static inline unsigned int hv_pfn_count ( physaddr_t data, size_t len ) {
  189. unsigned int first_pfn = ( data / PAGE_SIZE );
  190. unsigned int last_pfn = ( ( data + len - 1 ) / PAGE_SIZE );
  191. return ( last_pfn - first_pfn + 1 );
  192. }
  193. extern __attribute__ (( sentinel )) int
  194. hv_alloc_pages ( struct hv_hypervisor *hv, ... );
  195. extern __attribute__ (( sentinel )) void
  196. hv_free_pages ( struct hv_hypervisor *hv, ... );
  197. extern void hv_enable_sint ( struct hv_hypervisor *hv, unsigned int sintx );
  198. extern void hv_disable_sint ( struct hv_hypervisor *hv, unsigned int sintx );
  199. extern int hv_post_message ( struct hv_hypervisor *hv, unsigned int id,
  200. unsigned int type, const void *data, size_t len );
  201. extern int hv_wait_for_message ( struct hv_hypervisor *hv, unsigned int sintx );
  202. extern int hv_signal_event ( struct hv_hypervisor *hv, unsigned int id,
  203. unsigned int flag );
  204. #endif /* _IPXE_HYPERV_H */