hyperv_vmbus.h 19 KB

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