Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

hyperv.h 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 );
  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. /** Post message */
  51. #define HV_POST_MESSAGE 0x005c
  52. /** A posted message
  53. *
  54. * This is the input parameter list for the HvPostMessage hypercall.
  55. */
  56. struct hv_post_message {
  57. /** Connection ID */
  58. uint32_t id;
  59. /** Padding */
  60. uint32_t reserved;
  61. /** Type */
  62. uint32_t type;
  63. /** Length of message */
  64. uint32_t len;
  65. /** Message */
  66. uint8_t data[240];
  67. } __attribute__ (( packed ));
  68. /** A received message
  69. *
  70. * This is the HV_MESSAGE structure from the Hypervisor Top-Level
  71. * Functional Specification. The field order given in the
  72. * documentation is incorrect.
  73. */
  74. struct hv_message {
  75. /** Type */
  76. uint32_t type;
  77. /** Length of message */
  78. uint8_t len;
  79. /** Flags */
  80. uint8_t flags;
  81. /** Padding */
  82. uint16_t reserved;
  83. /** Origin */
  84. uint64_t origin;
  85. /** Message */
  86. uint8_t data[240];
  87. } __attribute__ (( packed ));
  88. /** Signal event */
  89. #define HV_SIGNAL_EVENT 0x005d
  90. /** A signalled event */
  91. struct hv_signal_event {
  92. /** Connection ID */
  93. uint32_t id;
  94. /** Flag number */
  95. uint16_t flag;
  96. /** Reserved */
  97. uint16_t reserved;
  98. } __attribute__ (( packed ));
  99. /** A received event */
  100. struct hv_event {
  101. /** Event flags */
  102. uint8_t flags[256];
  103. } __attribute__ (( packed ));
  104. /** A monitor trigger group
  105. *
  106. * This is the HV_MONITOR_TRIGGER_GROUP structure from the Hypervisor
  107. * Top-Level Functional Specification.
  108. */
  109. struct hv_monitor_trigger {
  110. /** Pending events */
  111. uint32_t pending;
  112. /** Armed events */
  113. uint32_t armed;
  114. } __attribute__ (( packed ));
  115. /** A monitor parameter set
  116. *
  117. * This is the HV_MONITOR_PARAMETER structure from the Hypervisor
  118. * Top-Level Functional Specification.
  119. */
  120. struct hv_monitor_parameter {
  121. /** Connection ID */
  122. uint32_t id;
  123. /** Flag number */
  124. uint16_t flag;
  125. /** Reserved */
  126. uint16_t reserved;
  127. } __attribute__ (( packed ));
  128. /** A monitor page
  129. *
  130. * This is the HV_MONITOR_PAGE structure from the Hypervisor Top-Level
  131. * Functional Specification.
  132. */
  133. struct hv_monitor {
  134. /** Flags */
  135. uint32_t flags;
  136. /** Reserved */
  137. uint8_t reserved_a[4];
  138. /** Trigger groups */
  139. struct hv_monitor_trigger trigger[4];
  140. /** Reserved */
  141. uint8_t reserved_b[536];
  142. /** Latencies */
  143. uint16 latency[4][32];
  144. /** Reserved */
  145. uint8_t reserved_c[256];
  146. /** Parameters */
  147. struct hv_monitor_parameter param[4][32];
  148. /** Reserved */
  149. uint8_t reserved_d[1984];
  150. } __attribute__ (( packed ));
  151. /** A synthetic interrupt controller */
  152. struct hv_synic {
  153. /** Message page */
  154. struct hv_message *message;
  155. /** Event flag page */
  156. struct hv_event *event;
  157. };
  158. /** A message buffer */
  159. union hv_message_buffer {
  160. /** Posted message */
  161. struct hv_post_message posted;
  162. /** Received message */
  163. struct hv_message received;
  164. /** Signalled event */
  165. struct hv_signal_event signalled;
  166. };
  167. /** A Hyper-V hypervisor */
  168. struct hv_hypervisor {
  169. /** Hypercall page */
  170. void *hypercall;
  171. /** Synthetic interrupt controller (SynIC) */
  172. struct hv_synic synic;
  173. /** Message buffer */
  174. union hv_message_buffer *message;
  175. /** Virtual machine bus */
  176. struct vmbus *vmbus;
  177. };
  178. #include <bits/hyperv.h>
  179. /**
  180. * Calculate the number of pages covering an address range
  181. *
  182. * @v data Start of data
  183. * @v len Length of data (must be non-zero)
  184. * @ret pfn_count Number of pages covered
  185. */
  186. static inline unsigned int hv_pfn_count ( physaddr_t data, size_t len ) {
  187. unsigned int first_pfn = ( data / PAGE_SIZE );
  188. unsigned int last_pfn = ( ( data + len - 1 ) / PAGE_SIZE );
  189. return ( last_pfn - first_pfn + 1 );
  190. }
  191. extern __attribute__ (( sentinel )) int
  192. hv_alloc_pages ( struct hv_hypervisor *hv, ... );
  193. extern __attribute__ (( sentinel )) void
  194. hv_free_pages ( struct hv_hypervisor *hv, ... );
  195. extern void hv_enable_sint ( struct hv_hypervisor *hv, unsigned int sintx );
  196. extern void hv_disable_sint ( struct hv_hypervisor *hv, unsigned int sintx );
  197. extern int hv_post_message ( struct hv_hypervisor *hv, unsigned int id,
  198. unsigned int type, const void *data, size_t len );
  199. extern int hv_wait_for_message ( struct hv_hypervisor *hv, unsigned int sintx );
  200. extern int hv_signal_event ( struct hv_hypervisor *hv, unsigned int id,
  201. unsigned int flag );
  202. #endif /* _IPXE_HYPERV_H */