hyperv_vmbus.h 17 KB

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