hyperv_vmbus.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. *
  3. * Copyright (c) 2011, Microsoft Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. * Place - Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. * Authors:
  19. * Haiyang Zhang <haiyangz@microsoft.com>
  20. * Hank Janssen <hjanssen@microsoft.com>
  21. * K. Y. Srinivasan <kys@microsoft.com>
  22. *
  23. */
  24. #ifndef _HYPERV_VMBUS_H
  25. #define _HYPERV_VMBUS_H
  26. #include <linux/list.h>
  27. #include <asm/sync_bitops.h>
  28. #include <linux/atomic.h>
  29. #include <linux/hyperv.h>
  30. /*
  31. * Timeout for services such as KVP and fcopy.
  32. */
  33. #define HV_UTIL_TIMEOUT 30
  34. /*
  35. * Timeout for guest-host handshake for services.
  36. */
  37. #define HV_UTIL_NEGO_TIMEOUT 60
  38. /*
  39. * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
  40. * is set by CPUID(HVCPUID_VERSION_FEATURES).
  41. */
  42. enum hv_cpuid_function {
  43. HVCPUID_VERSION_FEATURES = 0x00000001,
  44. HVCPUID_VENDOR_MAXFUNCTION = 0x40000000,
  45. HVCPUID_INTERFACE = 0x40000001,
  46. /*
  47. * The remaining functions depend on the value of
  48. * HVCPUID_INTERFACE
  49. */
  50. HVCPUID_VERSION = 0x40000002,
  51. HVCPUID_FEATURES = 0x40000003,
  52. HVCPUID_ENLIGHTENMENT_INFO = 0x40000004,
  53. HVCPUID_IMPLEMENTATION_LIMITS = 0x40000005,
  54. };
  55. #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE 0x400
  56. #define HV_X64_MSR_CRASH_P0 0x40000100
  57. #define HV_X64_MSR_CRASH_P1 0x40000101
  58. #define HV_X64_MSR_CRASH_P2 0x40000102
  59. #define HV_X64_MSR_CRASH_P3 0x40000103
  60. #define HV_X64_MSR_CRASH_P4 0x40000104
  61. #define HV_X64_MSR_CRASH_CTL 0x40000105
  62. #define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
  63. /* Define version of the synthetic interrupt controller. */
  64. #define HV_SYNIC_VERSION (1)
  65. #define HV_ANY_VP (0xFFFFFFFF)
  66. /* Define synthetic interrupt controller flag constants. */
  67. #define HV_EVENT_FLAGS_COUNT (256 * 8)
  68. #define HV_EVENT_FLAGS_BYTE_COUNT (256)
  69. #define HV_EVENT_FLAGS_DWORD_COUNT (256 / sizeof(u32))
  70. /* Define invalid partition identifier. */
  71. #define HV_PARTITION_ID_INVALID ((u64)0x0)
  72. /* Define port type. */
  73. enum hv_port_type {
  74. HVPORT_MSG = 1,
  75. HVPORT_EVENT = 2,
  76. HVPORT_MONITOR = 3
  77. };
  78. /* Define port information structure. */
  79. struct hv_port_info {
  80. enum hv_port_type port_type;
  81. u32 padding;
  82. union {
  83. struct {
  84. u32 target_sint;
  85. u32 target_vp;
  86. u64 rsvdz;
  87. } message_port_info;
  88. struct {
  89. u32 target_sint;
  90. u32 target_vp;
  91. u16 base_flag_number;
  92. u16 flag_count;
  93. u32 rsvdz;
  94. } event_port_info;
  95. struct {
  96. u64 monitor_address;
  97. u64 rsvdz;
  98. } monitor_port_info;
  99. };
  100. };
  101. struct hv_connection_info {
  102. enum hv_port_type port_type;
  103. u32 padding;
  104. union {
  105. struct {
  106. u64 rsvdz;
  107. } message_connection_info;
  108. struct {
  109. u64 rsvdz;
  110. } event_connection_info;
  111. struct {
  112. u64 monitor_address;
  113. } monitor_connection_info;
  114. };
  115. };
  116. /*
  117. * Timer configuration register.
  118. */
  119. union hv_timer_config {
  120. u64 as_uint64;
  121. struct {
  122. u64 enable:1;
  123. u64 periodic:1;
  124. u64 lazy:1;
  125. u64 auto_enable:1;
  126. u64 reserved_z0:12;
  127. u64 sintx:4;
  128. u64 reserved_z1:44;
  129. };
  130. };
  131. /* Define the number of message buffers associated with each port. */
  132. #define HV_PORT_MESSAGE_BUFFER_COUNT (16)
  133. /* Define the synthetic interrupt controller event flags format. */
  134. union hv_synic_event_flags {
  135. u8 flags8[HV_EVENT_FLAGS_BYTE_COUNT];
  136. u32 flags32[HV_EVENT_FLAGS_DWORD_COUNT];
  137. };
  138. /* Define the synthetic interrupt flags page layout. */
  139. struct hv_synic_event_flags_page {
  140. union hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT];
  141. };
  142. /* Define SynIC control register. */
  143. union hv_synic_scontrol {
  144. u64 as_uint64;
  145. struct {
  146. u64 enable:1;
  147. u64 reserved:63;
  148. };
  149. };
  150. /* Define synthetic interrupt source. */
  151. union hv_synic_sint {
  152. u64 as_uint64;
  153. struct {
  154. u64 vector:8;
  155. u64 reserved1:8;
  156. u64 masked:1;
  157. u64 auto_eoi:1;
  158. u64 reserved2:46;
  159. };
  160. };
  161. /* Define the format of the SIMP register */
  162. union hv_synic_simp {
  163. u64 as_uint64;
  164. struct {
  165. u64 simp_enabled:1;
  166. u64 preserved:11;
  167. u64 base_simp_gpa:52;
  168. };
  169. };
  170. /* Define the format of the SIEFP register */
  171. union hv_synic_siefp {
  172. u64 as_uint64;
  173. struct {
  174. u64 siefp_enabled:1;
  175. u64 preserved:11;
  176. u64 base_siefp_gpa:52;
  177. };
  178. };
  179. /* Definitions for the monitored notification facility */
  180. union hv_monitor_trigger_group {
  181. u64 as_uint64;
  182. struct {
  183. u32 pending;
  184. u32 armed;
  185. };
  186. };
  187. struct hv_monitor_parameter {
  188. union hv_connection_id connectionid;
  189. u16 flagnumber;
  190. u16 rsvdz;
  191. };
  192. union hv_monitor_trigger_state {
  193. u32 asu32;
  194. struct {
  195. u32 group_enable:4;
  196. u32 rsvdz:28;
  197. };
  198. };
  199. /* struct hv_monitor_page Layout */
  200. /* ------------------------------------------------------ */
  201. /* | 0 | TriggerState (4 bytes) | Rsvd1 (4 bytes) | */
  202. /* | 8 | TriggerGroup[0] | */
  203. /* | 10 | TriggerGroup[1] | */
  204. /* | 18 | TriggerGroup[2] | */
  205. /* | 20 | TriggerGroup[3] | */
  206. /* | 28 | Rsvd2[0] | */
  207. /* | 30 | Rsvd2[1] | */
  208. /* | 38 | Rsvd2[2] | */
  209. /* | 40 | NextCheckTime[0][0] | NextCheckTime[0][1] | */
  210. /* | ... | */
  211. /* | 240 | Latency[0][0..3] | */
  212. /* | 340 | Rsvz3[0] | */
  213. /* | 440 | Parameter[0][0] | */
  214. /* | 448 | Parameter[0][1] | */
  215. /* | ... | */
  216. /* | 840 | Rsvd4[0] | */
  217. /* ------------------------------------------------------ */
  218. struct hv_monitor_page {
  219. union hv_monitor_trigger_state trigger_state;
  220. u32 rsvdz1;
  221. union hv_monitor_trigger_group trigger_group[4];
  222. u64 rsvdz2[3];
  223. s32 next_checktime[4][32];
  224. u16 latency[4][32];
  225. u64 rsvdz3[32];
  226. struct hv_monitor_parameter parameter[4][32];
  227. u8 rsvdz4[1984];
  228. };
  229. /* Definition of the hv_post_message hypercall input structure. */
  230. struct hv_input_post_message {
  231. union hv_connection_id connectionid;
  232. u32 reserved;
  233. u32 message_type;
  234. u32 payload_size;
  235. u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
  236. };
  237. /*
  238. * Versioning definitions used for guests reporting themselves to the
  239. * hypervisor, and visa versa.
  240. */
  241. /* Version info reported by guest OS's */
  242. enum hv_guest_os_vendor {
  243. HVGUESTOS_VENDOR_MICROSOFT = 0x0001
  244. };
  245. enum hv_guest_os_microsoft_ids {
  246. HVGUESTOS_MICROSOFT_UNDEFINED = 0x00,
  247. HVGUESTOS_MICROSOFT_MSDOS = 0x01,
  248. HVGUESTOS_MICROSOFT_WINDOWS3X = 0x02,
  249. HVGUESTOS_MICROSOFT_WINDOWS9X = 0x03,
  250. HVGUESTOS_MICROSOFT_WINDOWSNT = 0x04,
  251. HVGUESTOS_MICROSOFT_WINDOWSCE = 0x05
  252. };
  253. /*
  254. * Declare the MSR used to identify the guest OS.
  255. */
  256. #define HV_X64_MSR_GUEST_OS_ID 0x40000000
  257. union hv_x64_msr_guest_os_id_contents {
  258. u64 as_uint64;
  259. struct {
  260. u64 build_number:16;
  261. u64 service_version:8; /* Service Pack, etc. */
  262. u64 minor_version:8;
  263. u64 major_version:8;
  264. u64 os_id:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */
  265. u64 vendor_id:16; /* enum hv_guest_os_vendor */
  266. };
  267. };
  268. /*
  269. * Declare the MSR used to setup pages used to communicate with the hypervisor.
  270. */
  271. #define HV_X64_MSR_HYPERCALL 0x40000001
  272. union hv_x64_msr_hypercall_contents {
  273. u64 as_uint64;
  274. struct {
  275. u64 enable:1;
  276. u64 reserved:11;
  277. u64 guest_physical_address:52;
  278. };
  279. };
  280. enum {
  281. VMBUS_MESSAGE_CONNECTION_ID = 1,
  282. VMBUS_MESSAGE_PORT_ID = 1,
  283. VMBUS_EVENT_CONNECTION_ID = 2,
  284. VMBUS_EVENT_PORT_ID = 2,
  285. VMBUS_MONITOR_CONNECTION_ID = 3,
  286. VMBUS_MONITOR_PORT_ID = 3,
  287. VMBUS_MESSAGE_SINT = 2,
  288. };
  289. /* #defines */
  290. #define HV_PRESENT_BIT 0x80000000
  291. /*
  292. * The guest OS needs to register the guest ID with the hypervisor.
  293. * The guest ID is a 64 bit entity and the structure of this ID is
  294. * specified in the Hyper-V specification:
  295. *
  296. * http://msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
  297. *
  298. * While the current guideline does not specify how Linux guest ID(s)
  299. * need to be generated, our plan is to publish the guidelines for
  300. * Linux and other guest operating systems that currently are hosted
  301. * on Hyper-V. The implementation here conforms to this yet
  302. * unpublished guidelines.
  303. *
  304. *
  305. * Bit(s)
  306. * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
  307. * 62:56 - Os Type; Linux is 0x100
  308. * 55:48 - Distro specific identification
  309. * 47:16 - Linux kernel version number
  310. * 15:0 - Distro specific identification
  311. *
  312. *
  313. */
  314. #define HV_LINUX_VENDOR_ID 0x8100
  315. /*
  316. * Generate the guest ID based on the guideline described above.
  317. */
  318. static inline __u64 generate_guest_id(__u8 d_info1, __u32 kernel_version,
  319. __u16 d_info2)
  320. {
  321. __u64 guest_id = 0;
  322. guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 48);
  323. guest_id |= (((__u64)(d_info1)) << 48);
  324. guest_id |= (((__u64)(kernel_version)) << 16);
  325. guest_id |= ((__u64)(d_info2));
  326. return guest_id;
  327. }
  328. #define HV_CPU_POWER_MANAGEMENT (1 << 0)
  329. #define HV_RECOMMENDATIONS_MAX 4
  330. #define HV_X64_MAX 5
  331. #define HV_CAPS_MAX 8
  332. #define HV_HYPERCALL_PARAM_ALIGN sizeof(u64)
  333. /* Service definitions */
  334. #define HV_SERVICE_PARENT_PORT (0)
  335. #define HV_SERVICE_PARENT_CONNECTION (0)
  336. #define HV_SERVICE_CONNECT_RESPONSE_SUCCESS (0)
  337. #define HV_SERVICE_CONNECT_RESPONSE_INVALID_PARAMETER (1)
  338. #define HV_SERVICE_CONNECT_RESPONSE_UNKNOWN_SERVICE (2)
  339. #define HV_SERVICE_CONNECT_RESPONSE_CONNECTION_REJECTED (3)
  340. #define HV_SERVICE_CONNECT_REQUEST_MESSAGE_ID (1)
  341. #define HV_SERVICE_CONNECT_RESPONSE_MESSAGE_ID (2)
  342. #define HV_SERVICE_DISCONNECT_REQUEST_MESSAGE_ID (3)
  343. #define HV_SERVICE_DISCONNECT_RESPONSE_MESSAGE_ID (4)
  344. #define HV_SERVICE_MAX_MESSAGE_ID (4)
  345. #define HV_SERVICE_PROTOCOL_VERSION (0x0010)
  346. #define HV_CONNECT_PAYLOAD_BYTE_COUNT 64
  347. /* #define VMBUS_REVISION_NUMBER 6 */
  348. /* Our local vmbus's port and connection id. Anything >0 is fine */
  349. /* #define VMBUS_PORT_ID 11 */
  350. /* 628180B8-308D-4c5e-B7DB-1BEB62E62EF4 */
  351. static const uuid_le VMBUS_SERVICE_ID = {
  352. .b = {
  353. 0xb8, 0x80, 0x81, 0x62, 0x8d, 0x30, 0x5e, 0x4c,
  354. 0xb7, 0xdb, 0x1b, 0xeb, 0x62, 0xe6, 0x2e, 0xf4
  355. },
  356. };
  357. struct hv_context {
  358. /* We only support running on top of Hyper-V
  359. * So at this point this really can only contain the Hyper-V ID
  360. */
  361. u64 guestid;
  362. void *hypercall_page;
  363. void *tsc_page;
  364. bool synic_initialized;
  365. void *synic_message_page[NR_CPUS];
  366. void *synic_event_page[NR_CPUS];
  367. /*
  368. * Hypervisor's notion of virtual processor ID is different from
  369. * Linux' notion of CPU ID. This information can only be retrieved
  370. * in the context of the calling CPU. Setup a map for easy access
  371. * to this information:
  372. *
  373. * vp_index[a] is the Hyper-V's processor ID corresponding to
  374. * Linux cpuid 'a'.
  375. */
  376. u32 vp_index[NR_CPUS];
  377. /*
  378. * Starting with win8, we can take channel interrupts on any CPU;
  379. * we will manage the tasklet that handles events messages on a per CPU
  380. * basis.
  381. */
  382. struct tasklet_struct *event_dpc[NR_CPUS];
  383. struct tasklet_struct *msg_dpc[NR_CPUS];
  384. /*
  385. * To optimize the mapping of relid to channel, maintain
  386. * per-cpu list of the channels based on their CPU affinity.
  387. */
  388. struct list_head percpu_list[NR_CPUS];
  389. /*
  390. * buffer to post messages to the host.
  391. */
  392. void *post_msg_page[NR_CPUS];
  393. /*
  394. * Support PV clockevent device.
  395. */
  396. struct clock_event_device *clk_evt[NR_CPUS];
  397. /*
  398. * To manage allocations in a NUMA node.
  399. * Array indexed by numa node ID.
  400. */
  401. struct cpumask *hv_numa_map;
  402. };
  403. extern struct hv_context hv_context;
  404. struct ms_hyperv_tsc_page {
  405. volatile u32 tsc_sequence;
  406. u32 reserved1;
  407. volatile u64 tsc_scale;
  408. volatile s64 tsc_offset;
  409. u64 reserved2[509];
  410. };
  411. struct hv_ring_buffer_debug_info {
  412. u32 current_interrupt_mask;
  413. u32 current_read_index;
  414. u32 current_write_index;
  415. u32 bytes_avail_toread;
  416. u32 bytes_avail_towrite;
  417. };
  418. /* Hv Interface */
  419. extern int hv_init(void);
  420. extern void hv_cleanup(bool crash);
  421. extern int hv_post_message(union hv_connection_id connection_id,
  422. enum hv_message_type message_type,
  423. void *payload, size_t payload_size);
  424. extern int hv_synic_alloc(void);
  425. extern void hv_synic_free(void);
  426. extern void hv_synic_init(void *irqarg);
  427. extern void hv_synic_cleanup(void *arg);
  428. extern void hv_synic_clockevents_cleanup(void);
  429. /*
  430. * Host version information.
  431. */
  432. extern unsigned int host_info_eax;
  433. extern unsigned int host_info_ebx;
  434. extern unsigned int host_info_ecx;
  435. extern unsigned int host_info_edx;
  436. /* Interface */
  437. int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info,
  438. struct page *pages, u32 pagecnt);
  439. void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info);
  440. int hv_ringbuffer_write(struct vmbus_channel *channel,
  441. struct kvec *kv_list,
  442. u32 kv_count, bool lock,
  443. bool kick_q);
  444. int hv_ringbuffer_read(struct vmbus_channel *channel,
  445. void *buffer, u32 buflen, u32 *buffer_actual_len,
  446. u64 *requestid, bool raw);
  447. void hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
  448. struct hv_ring_buffer_debug_info *debug_info);
  449. void hv_begin_read(struct hv_ring_buffer_info *rbi);
  450. u32 hv_end_read(struct hv_ring_buffer_info *rbi);
  451. /*
  452. * Maximum channels is determined by the size of the interrupt page
  453. * which is PAGE_SIZE. 1/2 of PAGE_SIZE is for send endpoint interrupt
  454. * and the other is receive endpoint interrupt
  455. */
  456. #define MAX_NUM_CHANNELS ((PAGE_SIZE >> 1) << 3) /* 16348 channels */
  457. /* The value here must be in multiple of 32 */
  458. /* TODO: Need to make this configurable */
  459. #define MAX_NUM_CHANNELS_SUPPORTED 256
  460. enum vmbus_connect_state {
  461. DISCONNECTED,
  462. CONNECTING,
  463. CONNECTED,
  464. DISCONNECTING
  465. };
  466. #define MAX_SIZE_CHANNEL_MESSAGE HV_MESSAGE_PAYLOAD_BYTE_COUNT
  467. struct vmbus_connection {
  468. enum vmbus_connect_state conn_state;
  469. atomic_t next_gpadl_handle;
  470. struct completion unload_event;
  471. /*
  472. * Represents channel interrupts. Each bit position represents a
  473. * channel. When a channel sends an interrupt via VMBUS, it finds its
  474. * bit in the sendInterruptPage, set it and calls Hv to generate a port
  475. * event. The other end receives the port event and parse the
  476. * recvInterruptPage to see which bit is set
  477. */
  478. void *int_page;
  479. void *send_int_page;
  480. void *recv_int_page;
  481. /*
  482. * 2 pages - 1st page for parent->child notification and 2nd
  483. * is child->parent notification
  484. */
  485. struct hv_monitor_page *monitor_pages[2];
  486. struct list_head chn_msg_list;
  487. spinlock_t channelmsg_lock;
  488. /* List of channels */
  489. struct list_head chn_list;
  490. struct mutex channel_mutex;
  491. struct workqueue_struct *work_queue;
  492. };
  493. struct vmbus_msginfo {
  494. /* Bookkeeping stuff */
  495. struct list_head msglist_entry;
  496. /* The message itself */
  497. unsigned char msg[0];
  498. };
  499. extern struct vmbus_connection vmbus_connection;
  500. enum vmbus_message_handler_type {
  501. /* The related handler can sleep. */
  502. VMHT_BLOCKING = 0,
  503. /* The related handler must NOT sleep. */
  504. VMHT_NON_BLOCKING = 1,
  505. };
  506. struct vmbus_channel_message_table_entry {
  507. enum vmbus_channel_message_type message_type;
  508. enum vmbus_message_handler_type handler_type;
  509. void (*message_handler)(struct vmbus_channel_message_header *msg);
  510. };
  511. extern struct vmbus_channel_message_table_entry
  512. channel_message_table[CHANNELMSG_COUNT];
  513. /* Free the message slot and signal end-of-message if required */
  514. static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
  515. {
  516. /*
  517. * On crash we're reading some other CPU's message page and we need
  518. * to be careful: this other CPU may already had cleared the header
  519. * and the host may already had delivered some other message there.
  520. * In case we blindly write msg->header.message_type we're going
  521. * to lose it. We can still lose a message of the same type but
  522. * we count on the fact that there can only be one
  523. * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages
  524. * on crash.
  525. */
  526. if (cmpxchg(&msg->header.message_type, old_msg_type,
  527. HVMSG_NONE) != old_msg_type)
  528. return;
  529. /*
  530. * Make sure the write to MessageType (ie set to
  531. * HVMSG_NONE) happens before we read the
  532. * MessagePending and EOMing. Otherwise, the EOMing
  533. * will not deliver any more messages since there is
  534. * no empty slot
  535. */
  536. mb();
  537. if (msg->header.message_flags.msg_pending) {
  538. /*
  539. * This will cause message queue rescan to
  540. * possibly deliver another msg from the
  541. * hypervisor
  542. */
  543. wrmsrl(HV_X64_MSR_EOM, 0);
  544. }
  545. }
  546. /* General vmbus interface */
  547. struct hv_device *vmbus_device_create(const uuid_le *type,
  548. const uuid_le *instance,
  549. struct vmbus_channel *channel);
  550. int vmbus_device_register(struct hv_device *child_device_obj);
  551. void vmbus_device_unregister(struct hv_device *device_obj);
  552. /* static void */
  553. /* VmbusChildDeviceDestroy( */
  554. /* struct hv_device *); */
  555. struct vmbus_channel *relid2channel(u32 relid);
  556. void vmbus_free_channels(void);
  557. /* Connection interface */
  558. int vmbus_connect(void);
  559. void vmbus_disconnect(void);
  560. int vmbus_post_msg(void *buffer, size_t buflen, bool can_sleep);
  561. void vmbus_on_event(unsigned long data);
  562. void vmbus_on_msg_dpc(unsigned long data);
  563. int hv_kvp_init(struct hv_util_service *);
  564. void hv_kvp_deinit(void);
  565. void hv_kvp_onchannelcallback(void *);
  566. int hv_vss_init(struct hv_util_service *);
  567. void hv_vss_deinit(void);
  568. void hv_vss_onchannelcallback(void *);
  569. int hv_fcopy_init(struct hv_util_service *);
  570. void hv_fcopy_deinit(void);
  571. void hv_fcopy_onchannelcallback(void *);
  572. void vmbus_initiate_unload(bool crash);
  573. static inline void hv_poll_channel(struct vmbus_channel *channel,
  574. void (*cb)(void *))
  575. {
  576. if (!channel)
  577. return;
  578. smp_call_function_single(channel->target_cpu, cb, channel, true);
  579. }
  580. enum hvutil_device_state {
  581. HVUTIL_DEVICE_INIT = 0, /* driver is loaded, waiting for userspace */
  582. HVUTIL_READY, /* userspace is registered */
  583. HVUTIL_HOSTMSG_RECEIVED, /* message from the host was received */
  584. HVUTIL_USERSPACE_REQ, /* request to userspace was sent */
  585. HVUTIL_USERSPACE_RECV, /* reply from userspace was received */
  586. HVUTIL_DEVICE_DYING, /* driver unload is in progress */
  587. };
  588. #endif /* _HYPERV_VMBUS_H */