hyperv_vmbus.h 19 KB

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