hyperv.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  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_H
  25. #define _HYPERV_H
  26. #include <linux/types.h>
  27. /*
  28. * Implementation of host controlled snapshot of the guest.
  29. */
  30. #define VSS_OP_REGISTER 128
  31. enum hv_vss_op {
  32. VSS_OP_CREATE = 0,
  33. VSS_OP_DELETE,
  34. VSS_OP_HOT_BACKUP,
  35. VSS_OP_GET_DM_INFO,
  36. VSS_OP_BU_COMPLETE,
  37. /*
  38. * Following operations are only supported with IC version >= 5.0
  39. */
  40. VSS_OP_FREEZE, /* Freeze the file systems in the VM */
  41. VSS_OP_THAW, /* Unfreeze the file systems */
  42. VSS_OP_AUTO_RECOVER,
  43. VSS_OP_COUNT /* Number of operations, must be last */
  44. };
  45. /*
  46. * Header for all VSS messages.
  47. */
  48. struct hv_vss_hdr {
  49. __u8 operation;
  50. __u8 reserved[7];
  51. } __attribute__((packed));
  52. /*
  53. * Flag values for the hv_vss_check_feature. Linux supports only
  54. * one value.
  55. */
  56. #define VSS_HBU_NO_AUTO_RECOVERY 0x00000005
  57. struct hv_vss_check_feature {
  58. __u32 flags;
  59. } __attribute__((packed));
  60. struct hv_vss_check_dm_info {
  61. __u32 flags;
  62. } __attribute__((packed));
  63. struct hv_vss_msg {
  64. union {
  65. struct hv_vss_hdr vss_hdr;
  66. int error;
  67. };
  68. union {
  69. struct hv_vss_check_feature vss_cf;
  70. struct hv_vss_check_dm_info dm_info;
  71. };
  72. } __attribute__((packed));
  73. /*
  74. * An implementation of HyperV key value pair (KVP) functionality for Linux.
  75. *
  76. *
  77. * Copyright (C) 2010, Novell, Inc.
  78. * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
  79. *
  80. */
  81. /*
  82. * Maximum value size - used for both key names and value data, and includes
  83. * any applicable NULL terminators.
  84. *
  85. * Note: This limit is somewhat arbitrary, but falls easily within what is
  86. * supported for all native guests (back to Win 2000) and what is reasonable
  87. * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
  88. * limited to 255 character key names.
  89. *
  90. * MSDN recommends not storing data values larger than 2048 bytes in the
  91. * registry.
  92. *
  93. * Note: This value is used in defining the KVP exchange message - this value
  94. * cannot be modified without affecting the message size and compatibility.
  95. */
  96. /*
  97. * bytes, including any null terminators
  98. */
  99. #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
  100. /*
  101. * Maximum key size - the registry limit for the length of an entry name
  102. * is 256 characters, including the null terminator
  103. */
  104. #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
  105. /*
  106. * In Linux, we implement the KVP functionality in two components:
  107. * 1) The kernel component which is packaged as part of the hv_utils driver
  108. * is responsible for communicating with the host and responsible for
  109. * implementing the host/guest protocol. 2) A user level daemon that is
  110. * responsible for data gathering.
  111. *
  112. * Host/Guest Protocol: The host iterates over an index and expects the guest
  113. * to assign a key name to the index and also return the value corresponding to
  114. * the key. The host will have atmost one KVP transaction outstanding at any
  115. * given point in time. The host side iteration stops when the guest returns
  116. * an error. Microsoft has specified the following mapping of key names to
  117. * host specified index:
  118. *
  119. * Index Key Name
  120. * 0 FullyQualifiedDomainName
  121. * 1 IntegrationServicesVersion
  122. * 2 NetworkAddressIPv4
  123. * 3 NetworkAddressIPv6
  124. * 4 OSBuildNumber
  125. * 5 OSName
  126. * 6 OSMajorVersion
  127. * 7 OSMinorVersion
  128. * 8 OSVersion
  129. * 9 ProcessorArchitecture
  130. *
  131. * The Windows host expects the Key Name and Key Value to be encoded in utf16.
  132. *
  133. * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
  134. * data gathering functionality in a user mode daemon. The user level daemon
  135. * is also responsible for binding the key name to the index as well. The
  136. * kernel and user-level daemon communicate using a connector channel.
  137. *
  138. * The user mode component first registers with the
  139. * the kernel component. Subsequently, the kernel component requests, data
  140. * for the specified keys. In response to this message the user mode component
  141. * fills in the value corresponding to the specified key. We overload the
  142. * sequence field in the cn_msg header to define our KVP message types.
  143. *
  144. *
  145. * The kernel component simply acts as a conduit for communication between the
  146. * Windows host and the user-level daemon. The kernel component passes up the
  147. * index received from the Host to the user-level daemon. If the index is
  148. * valid (supported), the corresponding key as well as its
  149. * value (both are strings) is returned. If the index is invalid
  150. * (not supported), a NULL key string is returned.
  151. */
  152. /*
  153. * Registry value types.
  154. */
  155. #define REG_SZ 1
  156. #define REG_U32 4
  157. #define REG_U64 8
  158. /*
  159. * As we look at expanding the KVP functionality to include
  160. * IP injection functionality, we need to maintain binary
  161. * compatibility with older daemons.
  162. *
  163. * The KVP opcodes are defined by the host and it was unfortunate
  164. * that I chose to treat the registration operation as part of the
  165. * KVP operations defined by the host.
  166. * Here is the level of compatibility
  167. * (between the user level daemon and the kernel KVP driver) that we
  168. * will implement:
  169. *
  170. * An older daemon will always be supported on a newer driver.
  171. * A given user level daemon will require a minimal version of the
  172. * kernel driver.
  173. * If we cannot handle the version differences, we will fail gracefully
  174. * (this can happen when we have a user level daemon that is more
  175. * advanced than the KVP driver.
  176. *
  177. * We will use values used in this handshake for determining if we have
  178. * workable user level daemon and the kernel driver. We begin by taking the
  179. * registration opcode out of the KVP opcode namespace. We will however,
  180. * maintain compatibility with the existing user-level daemon code.
  181. */
  182. /*
  183. * Daemon code not supporting IP injection (legacy daemon).
  184. */
  185. #define KVP_OP_REGISTER 4
  186. /*
  187. * Daemon code supporting IP injection.
  188. * The KVP opcode field is used to communicate the
  189. * registration information; so define a namespace that
  190. * will be distinct from the host defined KVP opcode.
  191. */
  192. #define KVP_OP_REGISTER1 100
  193. enum hv_kvp_exchg_op {
  194. KVP_OP_GET = 0,
  195. KVP_OP_SET,
  196. KVP_OP_DELETE,
  197. KVP_OP_ENUMERATE,
  198. KVP_OP_GET_IP_INFO,
  199. KVP_OP_SET_IP_INFO,
  200. KVP_OP_COUNT /* Number of operations, must be last. */
  201. };
  202. enum hv_kvp_exchg_pool {
  203. KVP_POOL_EXTERNAL = 0,
  204. KVP_POOL_GUEST,
  205. KVP_POOL_AUTO,
  206. KVP_POOL_AUTO_EXTERNAL,
  207. KVP_POOL_AUTO_INTERNAL,
  208. KVP_POOL_COUNT /* Number of pools, must be last. */
  209. };
  210. /*
  211. * Some Hyper-V status codes.
  212. */
  213. #define HV_S_OK 0x00000000
  214. #define HV_E_FAIL 0x80004005
  215. #define HV_S_CONT 0x80070103
  216. #define HV_ERROR_NOT_SUPPORTED 0x80070032
  217. #define HV_ERROR_MACHINE_LOCKED 0x800704F7
  218. #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
  219. #define HV_INVALIDARG 0x80070057
  220. #define HV_GUID_NOTFOUND 0x80041002
  221. #define ADDR_FAMILY_NONE 0x00
  222. #define ADDR_FAMILY_IPV4 0x01
  223. #define ADDR_FAMILY_IPV6 0x02
  224. #define MAX_ADAPTER_ID_SIZE 128
  225. #define MAX_IP_ADDR_SIZE 1024
  226. #define MAX_GATEWAY_SIZE 512
  227. struct hv_kvp_ipaddr_value {
  228. __u16 adapter_id[MAX_ADAPTER_ID_SIZE];
  229. __u8 addr_family;
  230. __u8 dhcp_enabled;
  231. __u16 ip_addr[MAX_IP_ADDR_SIZE];
  232. __u16 sub_net[MAX_IP_ADDR_SIZE];
  233. __u16 gate_way[MAX_GATEWAY_SIZE];
  234. __u16 dns_addr[MAX_IP_ADDR_SIZE];
  235. } __attribute__((packed));
  236. struct hv_kvp_hdr {
  237. __u8 operation;
  238. __u8 pool;
  239. __u16 pad;
  240. } __attribute__((packed));
  241. struct hv_kvp_exchg_msg_value {
  242. __u32 value_type;
  243. __u32 key_size;
  244. __u32 value_size;
  245. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  246. union {
  247. __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
  248. __u32 value_u32;
  249. __u64 value_u64;
  250. };
  251. } __attribute__((packed));
  252. struct hv_kvp_msg_enumerate {
  253. __u32 index;
  254. struct hv_kvp_exchg_msg_value data;
  255. } __attribute__((packed));
  256. struct hv_kvp_msg_get {
  257. struct hv_kvp_exchg_msg_value data;
  258. };
  259. struct hv_kvp_msg_set {
  260. struct hv_kvp_exchg_msg_value data;
  261. };
  262. struct hv_kvp_msg_delete {
  263. __u32 key_size;
  264. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  265. };
  266. struct hv_kvp_register {
  267. __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  268. };
  269. struct hv_kvp_msg {
  270. union {
  271. struct hv_kvp_hdr kvp_hdr;
  272. int error;
  273. };
  274. union {
  275. struct hv_kvp_msg_get kvp_get;
  276. struct hv_kvp_msg_set kvp_set;
  277. struct hv_kvp_msg_delete kvp_delete;
  278. struct hv_kvp_msg_enumerate kvp_enum_data;
  279. struct hv_kvp_ipaddr_value kvp_ip_val;
  280. struct hv_kvp_register kvp_register;
  281. } body;
  282. } __attribute__((packed));
  283. struct hv_kvp_ip_msg {
  284. __u8 operation;
  285. __u8 pool;
  286. struct hv_kvp_ipaddr_value kvp_ip_val;
  287. } __attribute__((packed));
  288. #ifdef __KERNEL__
  289. #include <linux/scatterlist.h>
  290. #include <linux/list.h>
  291. #include <linux/uuid.h>
  292. #include <linux/timer.h>
  293. #include <linux/workqueue.h>
  294. #include <linux/completion.h>
  295. #include <linux/device.h>
  296. #include <linux/mod_devicetable.h>
  297. #define MAX_PAGE_BUFFER_COUNT 19
  298. #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
  299. #pragma pack(push, 1)
  300. /* Single-page buffer */
  301. struct hv_page_buffer {
  302. u32 len;
  303. u32 offset;
  304. u64 pfn;
  305. };
  306. /* Multiple-page buffer */
  307. struct hv_multipage_buffer {
  308. /* Length and Offset determines the # of pfns in the array */
  309. u32 len;
  310. u32 offset;
  311. u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
  312. };
  313. /* 0x18 includes the proprietary packet header */
  314. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  315. (sizeof(struct hv_page_buffer) * \
  316. MAX_PAGE_BUFFER_COUNT))
  317. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  318. sizeof(struct hv_multipage_buffer))
  319. #pragma pack(pop)
  320. struct hv_ring_buffer {
  321. /* Offset in bytes from the start of ring data below */
  322. u32 write_index;
  323. /* Offset in bytes from the start of ring data below */
  324. u32 read_index;
  325. u32 interrupt_mask;
  326. /*
  327. * Win8 uses some of the reserved bits to implement
  328. * interrupt driven flow management. On the send side
  329. * we can request that the receiver interrupt the sender
  330. * when the ring transitions from being full to being able
  331. * to handle a message of size "pending_send_sz".
  332. *
  333. * Add necessary state for this enhancement.
  334. */
  335. u32 pending_send_sz;
  336. u32 reserved1[12];
  337. union {
  338. struct {
  339. u32 feat_pending_send_sz:1;
  340. };
  341. u32 value;
  342. } feature_bits;
  343. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  344. u8 reserved2[4028];
  345. /*
  346. * Ring data starts here + RingDataStartOffset
  347. * !!! DO NOT place any fields below this !!!
  348. */
  349. u8 buffer[0];
  350. } __packed;
  351. struct hv_ring_buffer_info {
  352. struct hv_ring_buffer *ring_buffer;
  353. u32 ring_size; /* Include the shared header */
  354. spinlock_t ring_lock;
  355. u32 ring_datasize; /* < ring_size */
  356. u32 ring_data_startoffset;
  357. };
  358. struct hv_ring_buffer_debug_info {
  359. u32 current_interrupt_mask;
  360. u32 current_read_index;
  361. u32 current_write_index;
  362. u32 bytes_avail_toread;
  363. u32 bytes_avail_towrite;
  364. };
  365. /*
  366. *
  367. * hv_get_ringbuffer_availbytes()
  368. *
  369. * Get number of bytes available to read and to write to
  370. * for the specified ring buffer
  371. */
  372. static inline void
  373. hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
  374. u32 *read, u32 *write)
  375. {
  376. u32 read_loc, write_loc, dsize;
  377. smp_read_barrier_depends();
  378. /* Capture the read/write indices before they changed */
  379. read_loc = rbi->ring_buffer->read_index;
  380. write_loc = rbi->ring_buffer->write_index;
  381. dsize = rbi->ring_datasize;
  382. *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  383. read_loc - write_loc;
  384. *read = dsize - *write;
  385. }
  386. /*
  387. * We use the same version numbering for all Hyper-V modules.
  388. *
  389. * Definition of versioning is as follows;
  390. *
  391. * Major Number Changes for these scenarios;
  392. * 1. When a new version of Windows Hyper-V
  393. * is released.
  394. * 2. A Major change has occurred in the
  395. * Linux IC's.
  396. * (For example the merge for the first time
  397. * into the kernel) Every time the Major Number
  398. * changes, the Revision number is reset to 0.
  399. * Minor Number Changes when new functionality is added
  400. * to the Linux IC's that is not a bug fix.
  401. *
  402. * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
  403. */
  404. #define HV_DRV_VERSION "3.1"
  405. /*
  406. * VMBUS version is 32 bit entity broken up into
  407. * two 16 bit quantities: major_number. minor_number.
  408. *
  409. * 0 . 13 (Windows Server 2008)
  410. * 1 . 1 (Windows 7)
  411. * 2 . 4 (Windows 8)
  412. */
  413. #define VERSION_WS2008 ((0 << 16) | (13))
  414. #define VERSION_WIN7 ((1 << 16) | (1))
  415. #define VERSION_WIN8 ((2 << 16) | (4))
  416. #define VERSION_INVAL -1
  417. #define VERSION_CURRENT VERSION_WIN8
  418. /* Make maximum size of pipe payload of 16K */
  419. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  420. /* Define PipeMode values. */
  421. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  422. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  423. /* The size of the user defined data buffer for non-pipe offers. */
  424. #define MAX_USER_DEFINED_BYTES 120
  425. /* The size of the user defined data buffer for pipe offers. */
  426. #define MAX_PIPE_USER_DEFINED_BYTES 116
  427. /*
  428. * At the center of the Channel Management library is the Channel Offer. This
  429. * struct contains the fundamental information about an offer.
  430. */
  431. struct vmbus_channel_offer {
  432. uuid_le if_type;
  433. uuid_le if_instance;
  434. /*
  435. * These two fields are not currently used.
  436. */
  437. u64 reserved1;
  438. u64 reserved2;
  439. u16 chn_flags;
  440. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  441. union {
  442. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  443. struct {
  444. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  445. } std;
  446. /*
  447. * Pipes:
  448. * The following sructure is an integrated pipe protocol, which
  449. * is implemented on top of standard user-defined data. Pipe
  450. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  451. * use.
  452. */
  453. struct {
  454. u32 pipe_mode;
  455. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  456. } pipe;
  457. } u;
  458. /*
  459. * The sub_channel_index is defined in win8.
  460. */
  461. u16 sub_channel_index;
  462. u16 reserved3;
  463. } __packed;
  464. /* Server Flags */
  465. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  466. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  467. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  468. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  469. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  470. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  471. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  472. struct vmpacket_descriptor {
  473. u16 type;
  474. u16 offset8;
  475. u16 len8;
  476. u16 flags;
  477. u64 trans_id;
  478. } __packed;
  479. struct vmpacket_header {
  480. u32 prev_pkt_start_offset;
  481. struct vmpacket_descriptor descriptor;
  482. } __packed;
  483. struct vmtransfer_page_range {
  484. u32 byte_count;
  485. u32 byte_offset;
  486. } __packed;
  487. struct vmtransfer_page_packet_header {
  488. struct vmpacket_descriptor d;
  489. u16 xfer_pageset_id;
  490. u8 sender_owns_set;
  491. u8 reserved;
  492. u32 range_cnt;
  493. struct vmtransfer_page_range ranges[1];
  494. } __packed;
  495. struct vmgpadl_packet_header {
  496. struct vmpacket_descriptor d;
  497. u32 gpadl;
  498. u32 reserved;
  499. } __packed;
  500. struct vmadd_remove_transfer_page_set {
  501. struct vmpacket_descriptor d;
  502. u32 gpadl;
  503. u16 xfer_pageset_id;
  504. u16 reserved;
  505. } __packed;
  506. /*
  507. * This structure defines a range in guest physical space that can be made to
  508. * look virtually contiguous.
  509. */
  510. struct gpa_range {
  511. u32 byte_count;
  512. u32 byte_offset;
  513. u64 pfn_array[0];
  514. };
  515. /*
  516. * This is the format for an Establish Gpadl packet, which contains a handle by
  517. * which this GPADL will be known and a set of GPA ranges associated with it.
  518. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  519. * ranges, then the resulting MDL will be "chained," representing multiple VA
  520. * ranges.
  521. */
  522. struct vmestablish_gpadl {
  523. struct vmpacket_descriptor d;
  524. u32 gpadl;
  525. u32 range_cnt;
  526. struct gpa_range range[1];
  527. } __packed;
  528. /*
  529. * This is the format for a Teardown Gpadl packet, which indicates that the
  530. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  531. */
  532. struct vmteardown_gpadl {
  533. struct vmpacket_descriptor d;
  534. u32 gpadl;
  535. u32 reserved; /* for alignment to a 8-byte boundary */
  536. } __packed;
  537. /*
  538. * This is the format for a GPA-Direct packet, which contains a set of GPA
  539. * ranges, in addition to commands and/or data.
  540. */
  541. struct vmdata_gpa_direct {
  542. struct vmpacket_descriptor d;
  543. u32 reserved;
  544. u32 range_cnt;
  545. struct gpa_range range[1];
  546. } __packed;
  547. /* This is the format for a Additional Data Packet. */
  548. struct vmadditional_data {
  549. struct vmpacket_descriptor d;
  550. u64 total_bytes;
  551. u32 offset;
  552. u32 byte_cnt;
  553. unsigned char data[1];
  554. } __packed;
  555. union vmpacket_largest_possible_header {
  556. struct vmpacket_descriptor simple_hdr;
  557. struct vmtransfer_page_packet_header xfer_page_hdr;
  558. struct vmgpadl_packet_header gpadl_hdr;
  559. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  560. struct vmestablish_gpadl establish_gpadl_hdr;
  561. struct vmteardown_gpadl teardown_gpadl_hdr;
  562. struct vmdata_gpa_direct data_gpa_direct_hdr;
  563. };
  564. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  565. (void *)(((unsigned char *)__packet) + \
  566. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  567. #define VMPACKET_DATA_LENGTH(__packet) \
  568. ((((struct vmpacket_descriptor)__packet)->len8 - \
  569. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  570. #define VMPACKET_TRANSFER_MODE(__packet) \
  571. (((struct IMPACT)__packet)->type)
  572. enum vmbus_packet_type {
  573. VM_PKT_INVALID = 0x0,
  574. VM_PKT_SYNCH = 0x1,
  575. VM_PKT_ADD_XFER_PAGESET = 0x2,
  576. VM_PKT_RM_XFER_PAGESET = 0x3,
  577. VM_PKT_ESTABLISH_GPADL = 0x4,
  578. VM_PKT_TEARDOWN_GPADL = 0x5,
  579. VM_PKT_DATA_INBAND = 0x6,
  580. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  581. VM_PKT_DATA_USING_GPADL = 0x8,
  582. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  583. VM_PKT_CANCEL_REQUEST = 0xa,
  584. VM_PKT_COMP = 0xb,
  585. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  586. VM_PKT_ADDITIONAL_DATA = 0xd
  587. };
  588. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  589. /* Version 1 messages */
  590. enum vmbus_channel_message_type {
  591. CHANNELMSG_INVALID = 0,
  592. CHANNELMSG_OFFERCHANNEL = 1,
  593. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  594. CHANNELMSG_REQUESTOFFERS = 3,
  595. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  596. CHANNELMSG_OPENCHANNEL = 5,
  597. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  598. CHANNELMSG_CLOSECHANNEL = 7,
  599. CHANNELMSG_GPADL_HEADER = 8,
  600. CHANNELMSG_GPADL_BODY = 9,
  601. CHANNELMSG_GPADL_CREATED = 10,
  602. CHANNELMSG_GPADL_TEARDOWN = 11,
  603. CHANNELMSG_GPADL_TORNDOWN = 12,
  604. CHANNELMSG_RELID_RELEASED = 13,
  605. CHANNELMSG_INITIATE_CONTACT = 14,
  606. CHANNELMSG_VERSION_RESPONSE = 15,
  607. CHANNELMSG_UNLOAD = 16,
  608. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  609. CHANNELMSG_VIEWRANGE_ADD = 17,
  610. CHANNELMSG_VIEWRANGE_REMOVE = 18,
  611. #endif
  612. CHANNELMSG_COUNT
  613. };
  614. struct vmbus_channel_message_header {
  615. enum vmbus_channel_message_type msgtype;
  616. u32 padding;
  617. } __packed;
  618. /* Query VMBus Version parameters */
  619. struct vmbus_channel_query_vmbus_version {
  620. struct vmbus_channel_message_header header;
  621. u32 version;
  622. } __packed;
  623. /* VMBus Version Supported parameters */
  624. struct vmbus_channel_version_supported {
  625. struct vmbus_channel_message_header header;
  626. u8 version_supported;
  627. } __packed;
  628. /* Offer Channel parameters */
  629. struct vmbus_channel_offer_channel {
  630. struct vmbus_channel_message_header header;
  631. struct vmbus_channel_offer offer;
  632. u32 child_relid;
  633. u8 monitorid;
  634. /*
  635. * win7 and beyond splits this field into a bit field.
  636. */
  637. u8 monitor_allocated:1;
  638. u8 reserved:7;
  639. /*
  640. * These are new fields added in win7 and later.
  641. * Do not access these fields without checking the
  642. * negotiated protocol.
  643. *
  644. * If "is_dedicated_interrupt" is set, we must not set the
  645. * associated bit in the channel bitmap while sending the
  646. * interrupt to the host.
  647. *
  648. * connection_id is to be used in signaling the host.
  649. */
  650. u16 is_dedicated_interrupt:1;
  651. u16 reserved1:15;
  652. u32 connection_id;
  653. } __packed;
  654. /* Rescind Offer parameters */
  655. struct vmbus_channel_rescind_offer {
  656. struct vmbus_channel_message_header header;
  657. u32 child_relid;
  658. } __packed;
  659. /*
  660. * Request Offer -- no parameters, SynIC message contains the partition ID
  661. * Set Snoop -- no parameters, SynIC message contains the partition ID
  662. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  663. * All Offers Delivered -- no parameters, SynIC message contains the partition
  664. * ID
  665. * Flush Client -- no parameters, SynIC message contains the partition ID
  666. */
  667. /* Open Channel parameters */
  668. struct vmbus_channel_open_channel {
  669. struct vmbus_channel_message_header header;
  670. /* Identifies the specific VMBus channel that is being opened. */
  671. u32 child_relid;
  672. /* ID making a particular open request at a channel offer unique. */
  673. u32 openid;
  674. /* GPADL for the channel's ring buffer. */
  675. u32 ringbuffer_gpadlhandle;
  676. /*
  677. * Starting with win8, this field will be used to specify
  678. * the target virtual processor on which to deliver the interrupt for
  679. * the host to guest communication.
  680. * Prior to win8, incoming channel interrupts would only
  681. * be delivered on cpu 0. Setting this value to 0 would
  682. * preserve the earlier behavior.
  683. */
  684. u32 target_vp;
  685. /*
  686. * The upstream ring buffer begins at offset zero in the memory
  687. * described by RingBufferGpadlHandle. The downstream ring buffer
  688. * follows it at this offset (in pages).
  689. */
  690. u32 downstream_ringbuffer_pageoffset;
  691. /* User-specific data to be passed along to the server endpoint. */
  692. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  693. } __packed;
  694. /* Open Channel Result parameters */
  695. struct vmbus_channel_open_result {
  696. struct vmbus_channel_message_header header;
  697. u32 child_relid;
  698. u32 openid;
  699. u32 status;
  700. } __packed;
  701. /* Close channel parameters; */
  702. struct vmbus_channel_close_channel {
  703. struct vmbus_channel_message_header header;
  704. u32 child_relid;
  705. } __packed;
  706. /* Channel Message GPADL */
  707. #define GPADL_TYPE_RING_BUFFER 1
  708. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  709. #define GPADL_TYPE_TRANSACTION 8
  710. /*
  711. * The number of PFNs in a GPADL message is defined by the number of
  712. * pages that would be spanned by ByteCount and ByteOffset. If the
  713. * implied number of PFNs won't fit in this packet, there will be a
  714. * follow-up packet that contains more.
  715. */
  716. struct vmbus_channel_gpadl_header {
  717. struct vmbus_channel_message_header header;
  718. u32 child_relid;
  719. u32 gpadl;
  720. u16 range_buflen;
  721. u16 rangecount;
  722. struct gpa_range range[0];
  723. } __packed;
  724. /* This is the followup packet that contains more PFNs. */
  725. struct vmbus_channel_gpadl_body {
  726. struct vmbus_channel_message_header header;
  727. u32 msgnumber;
  728. u32 gpadl;
  729. u64 pfn[0];
  730. } __packed;
  731. struct vmbus_channel_gpadl_created {
  732. struct vmbus_channel_message_header header;
  733. u32 child_relid;
  734. u32 gpadl;
  735. u32 creation_status;
  736. } __packed;
  737. struct vmbus_channel_gpadl_teardown {
  738. struct vmbus_channel_message_header header;
  739. u32 child_relid;
  740. u32 gpadl;
  741. } __packed;
  742. struct vmbus_channel_gpadl_torndown {
  743. struct vmbus_channel_message_header header;
  744. u32 gpadl;
  745. } __packed;
  746. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  747. struct vmbus_channel_view_range_add {
  748. struct vmbus_channel_message_header header;
  749. PHYSICAL_ADDRESS viewrange_base;
  750. u64 viewrange_length;
  751. u32 child_relid;
  752. } __packed;
  753. struct vmbus_channel_view_range_remove {
  754. struct vmbus_channel_message_header header;
  755. PHYSICAL_ADDRESS viewrange_base;
  756. u32 child_relid;
  757. } __packed;
  758. #endif
  759. struct vmbus_channel_relid_released {
  760. struct vmbus_channel_message_header header;
  761. u32 child_relid;
  762. } __packed;
  763. struct vmbus_channel_initiate_contact {
  764. struct vmbus_channel_message_header header;
  765. u32 vmbus_version_requested;
  766. u32 padding2;
  767. u64 interrupt_page;
  768. u64 monitor_page1;
  769. u64 monitor_page2;
  770. } __packed;
  771. struct vmbus_channel_version_response {
  772. struct vmbus_channel_message_header header;
  773. u8 version_supported;
  774. } __packed;
  775. enum vmbus_channel_state {
  776. CHANNEL_OFFER_STATE,
  777. CHANNEL_OPENING_STATE,
  778. CHANNEL_OPEN_STATE,
  779. };
  780. struct vmbus_channel_debug_info {
  781. u32 relid;
  782. enum vmbus_channel_state state;
  783. uuid_le interfacetype;
  784. uuid_le interface_instance;
  785. u32 monitorid;
  786. u32 servermonitor_pending;
  787. u32 servermonitor_latency;
  788. u32 servermonitor_connectionid;
  789. u32 clientmonitor_pending;
  790. u32 clientmonitor_latency;
  791. u32 clientmonitor_connectionid;
  792. struct hv_ring_buffer_debug_info inbound;
  793. struct hv_ring_buffer_debug_info outbound;
  794. };
  795. /*
  796. * Represents each channel msg on the vmbus connection This is a
  797. * variable-size data structure depending on the msg type itself
  798. */
  799. struct vmbus_channel_msginfo {
  800. /* Bookkeeping stuff */
  801. struct list_head msglistentry;
  802. /* So far, this is only used to handle gpadl body message */
  803. struct list_head submsglist;
  804. /* Synchronize the request/response if needed */
  805. struct completion waitevent;
  806. union {
  807. struct vmbus_channel_version_supported version_supported;
  808. struct vmbus_channel_open_result open_result;
  809. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  810. struct vmbus_channel_gpadl_created gpadl_created;
  811. struct vmbus_channel_version_response version_response;
  812. } response;
  813. u32 msgsize;
  814. /*
  815. * The channel message that goes out on the "wire".
  816. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  817. */
  818. unsigned char msg[0];
  819. };
  820. struct vmbus_close_msg {
  821. struct vmbus_channel_msginfo info;
  822. struct vmbus_channel_close_channel msg;
  823. };
  824. /* Define connection identifier type. */
  825. union hv_connection_id {
  826. u32 asu32;
  827. struct {
  828. u32 id:24;
  829. u32 reserved:8;
  830. } u;
  831. };
  832. /* Definition of the hv_signal_event hypercall input structure. */
  833. struct hv_input_signal_event {
  834. union hv_connection_id connectionid;
  835. u16 flag_number;
  836. u16 rsvdz;
  837. };
  838. struct hv_input_signal_event_buffer {
  839. u64 align8;
  840. struct hv_input_signal_event event;
  841. };
  842. struct vmbus_channel {
  843. struct list_head listentry;
  844. struct hv_device *device_obj;
  845. struct work_struct work;
  846. enum vmbus_channel_state state;
  847. struct vmbus_channel_offer_channel offermsg;
  848. /*
  849. * These are based on the OfferMsg.MonitorId.
  850. * Save it here for easy access.
  851. */
  852. u8 monitor_grp;
  853. u8 monitor_bit;
  854. u32 ringbuffer_gpadlhandle;
  855. /* Allocated memory for ring buffer */
  856. void *ringbuffer_pages;
  857. u32 ringbuffer_pagecount;
  858. struct hv_ring_buffer_info outbound; /* send to parent */
  859. struct hv_ring_buffer_info inbound; /* receive from parent */
  860. spinlock_t inbound_lock;
  861. struct workqueue_struct *controlwq;
  862. struct vmbus_close_msg close_msg;
  863. /* Channel callback are invoked in this workqueue context */
  864. /* HANDLE dataWorkQueue; */
  865. void (*onchannel_callback)(void *context);
  866. void *channel_callback_context;
  867. /*
  868. * A channel can be marked for efficient (batched)
  869. * reading:
  870. * If batched_reading is set to "true", we read until the
  871. * channel is empty and hold off interrupts from the host
  872. * during the entire read process.
  873. * If batched_reading is set to "false", the client is not
  874. * going to perform batched reading.
  875. *
  876. * By default we will enable batched reading; specific
  877. * drivers that don't want this behavior can turn it off.
  878. */
  879. bool batched_reading;
  880. bool is_dedicated_interrupt;
  881. struct hv_input_signal_event_buffer sig_buf;
  882. struct hv_input_signal_event *sig_event;
  883. /*
  884. * Starting with win8, this field will be used to specify
  885. * the target virtual processor on which to deliver the interrupt for
  886. * the host to guest communication.
  887. * Prior to win8, incoming channel interrupts would only
  888. * be delivered on cpu 0. Setting this value to 0 would
  889. * preserve the earlier behavior.
  890. */
  891. u32 target_vp;
  892. };
  893. static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
  894. {
  895. c->batched_reading = state;
  896. }
  897. void vmbus_onmessage(void *context);
  898. int vmbus_request_offers(void);
  899. /* The format must be the same as struct vmdata_gpa_direct */
  900. struct vmbus_channel_packet_page_buffer {
  901. u16 type;
  902. u16 dataoffset8;
  903. u16 length8;
  904. u16 flags;
  905. u64 transactionid;
  906. u32 reserved;
  907. u32 rangecount;
  908. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  909. } __packed;
  910. /* The format must be the same as struct vmdata_gpa_direct */
  911. struct vmbus_channel_packet_multipage_buffer {
  912. u16 type;
  913. u16 dataoffset8;
  914. u16 length8;
  915. u16 flags;
  916. u64 transactionid;
  917. u32 reserved;
  918. u32 rangecount; /* Always 1 in this case */
  919. struct hv_multipage_buffer range;
  920. } __packed;
  921. extern int vmbus_open(struct vmbus_channel *channel,
  922. u32 send_ringbuffersize,
  923. u32 recv_ringbuffersize,
  924. void *userdata,
  925. u32 userdatalen,
  926. void(*onchannel_callback)(void *context),
  927. void *context);
  928. extern void vmbus_close(struct vmbus_channel *channel);
  929. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  930. const void *buffer,
  931. u32 bufferLen,
  932. u64 requestid,
  933. enum vmbus_packet_type type,
  934. u32 flags);
  935. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  936. struct hv_page_buffer pagebuffers[],
  937. u32 pagecount,
  938. void *buffer,
  939. u32 bufferlen,
  940. u64 requestid);
  941. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  942. struct hv_multipage_buffer *mpb,
  943. void *buffer,
  944. u32 bufferlen,
  945. u64 requestid);
  946. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  947. void *kbuffer,
  948. u32 size,
  949. u32 *gpadl_handle);
  950. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  951. u32 gpadl_handle);
  952. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  953. void *buffer,
  954. u32 bufferlen,
  955. u32 *buffer_actual_len,
  956. u64 *requestid);
  957. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  958. void *buffer,
  959. u32 bufferlen,
  960. u32 *buffer_actual_len,
  961. u64 *requestid);
  962. extern void vmbus_get_debug_info(struct vmbus_channel *channel,
  963. struct vmbus_channel_debug_info *debug);
  964. extern void vmbus_ontimer(unsigned long data);
  965. struct hv_dev_port_info {
  966. u32 int_mask;
  967. u32 read_idx;
  968. u32 write_idx;
  969. u32 bytes_avail_toread;
  970. u32 bytes_avail_towrite;
  971. };
  972. /* Base driver object */
  973. struct hv_driver {
  974. const char *name;
  975. /* the device type supported by this driver */
  976. uuid_le dev_type;
  977. const struct hv_vmbus_device_id *id_table;
  978. struct device_driver driver;
  979. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  980. int (*remove)(struct hv_device *);
  981. void (*shutdown)(struct hv_device *);
  982. };
  983. /* Base device object */
  984. struct hv_device {
  985. /* the device type id of this device */
  986. uuid_le dev_type;
  987. /* the device instance id of this device */
  988. uuid_le dev_instance;
  989. struct device device;
  990. struct vmbus_channel *channel;
  991. };
  992. static inline struct hv_device *device_to_hv_device(struct device *d)
  993. {
  994. return container_of(d, struct hv_device, device);
  995. }
  996. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  997. {
  998. return container_of(d, struct hv_driver, driver);
  999. }
  1000. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  1001. {
  1002. dev_set_drvdata(&dev->device, data);
  1003. }
  1004. static inline void *hv_get_drvdata(struct hv_device *dev)
  1005. {
  1006. return dev_get_drvdata(&dev->device);
  1007. }
  1008. /* Vmbus interface */
  1009. #define vmbus_driver_register(driver) \
  1010. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  1011. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  1012. struct module *owner,
  1013. const char *mod_name);
  1014. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  1015. /**
  1016. * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  1017. *
  1018. * This macro is used to create a struct hv_vmbus_device_id that matches a
  1019. * specific device.
  1020. */
  1021. #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
  1022. g8, g9, ga, gb, gc, gd, ge, gf) \
  1023. .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
  1024. g8, g9, ga, gb, gc, gd, ge, gf },
  1025. /*
  1026. * GUID definitions of various offer types - services offered to the guest.
  1027. */
  1028. /*
  1029. * Network GUID
  1030. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  1031. */
  1032. #define HV_NIC_GUID \
  1033. .guid = { \
  1034. 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
  1035. 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
  1036. }
  1037. /*
  1038. * IDE GUID
  1039. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  1040. */
  1041. #define HV_IDE_GUID \
  1042. .guid = { \
  1043. 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
  1044. 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
  1045. }
  1046. /*
  1047. * SCSI GUID
  1048. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  1049. */
  1050. #define HV_SCSI_GUID \
  1051. .guid = { \
  1052. 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
  1053. 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
  1054. }
  1055. /*
  1056. * Shutdown GUID
  1057. * {0e0b6031-5213-4934-818b-38d90ced39db}
  1058. */
  1059. #define HV_SHUTDOWN_GUID \
  1060. .guid = { \
  1061. 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
  1062. 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
  1063. }
  1064. /*
  1065. * Time Synch GUID
  1066. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  1067. */
  1068. #define HV_TS_GUID \
  1069. .guid = { \
  1070. 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
  1071. 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
  1072. }
  1073. /*
  1074. * Heartbeat GUID
  1075. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  1076. */
  1077. #define HV_HEART_BEAT_GUID \
  1078. .guid = { \
  1079. 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
  1080. 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
  1081. }
  1082. /*
  1083. * KVP GUID
  1084. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  1085. */
  1086. #define HV_KVP_GUID \
  1087. .guid = { \
  1088. 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
  1089. 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
  1090. }
  1091. /*
  1092. * Dynamic memory GUID
  1093. * {525074dc-8985-46e2-8057-a307dc18a502}
  1094. */
  1095. #define HV_DM_GUID \
  1096. .guid = { \
  1097. 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
  1098. 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
  1099. }
  1100. /*
  1101. * Mouse GUID
  1102. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  1103. */
  1104. #define HV_MOUSE_GUID \
  1105. .guid = { \
  1106. 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
  1107. 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
  1108. }
  1109. /*
  1110. * VSS (Backup/Restore) GUID
  1111. */
  1112. #define HV_VSS_GUID \
  1113. .guid = { \
  1114. 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
  1115. 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
  1116. }
  1117. /*
  1118. * Synthetic Video GUID
  1119. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  1120. */
  1121. #define HV_SYNTHVID_GUID \
  1122. .guid = { \
  1123. 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
  1124. 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
  1125. }
  1126. /*
  1127. * Common header for Hyper-V ICs
  1128. */
  1129. #define ICMSGTYPE_NEGOTIATE 0
  1130. #define ICMSGTYPE_HEARTBEAT 1
  1131. #define ICMSGTYPE_KVPEXCHANGE 2
  1132. #define ICMSGTYPE_SHUTDOWN 3
  1133. #define ICMSGTYPE_TIMESYNC 4
  1134. #define ICMSGTYPE_VSS 5
  1135. #define ICMSGHDRFLAG_TRANSACTION 1
  1136. #define ICMSGHDRFLAG_REQUEST 2
  1137. #define ICMSGHDRFLAG_RESPONSE 4
  1138. /*
  1139. * While we want to handle util services as regular devices,
  1140. * there is only one instance of each of these services; so
  1141. * we statically allocate the service specific state.
  1142. */
  1143. struct hv_util_service {
  1144. u8 *recv_buffer;
  1145. void (*util_cb)(void *);
  1146. int (*util_init)(struct hv_util_service *);
  1147. void (*util_deinit)(void);
  1148. };
  1149. struct vmbuspipe_hdr {
  1150. u32 flags;
  1151. u32 msgsize;
  1152. } __packed;
  1153. struct ic_version {
  1154. u16 major;
  1155. u16 minor;
  1156. } __packed;
  1157. struct icmsg_hdr {
  1158. struct ic_version icverframe;
  1159. u16 icmsgtype;
  1160. struct ic_version icvermsg;
  1161. u16 icmsgsize;
  1162. u32 status;
  1163. u8 ictransaction_id;
  1164. u8 icflags;
  1165. u8 reserved[2];
  1166. } __packed;
  1167. struct icmsg_negotiate {
  1168. u16 icframe_vercnt;
  1169. u16 icmsg_vercnt;
  1170. u32 reserved;
  1171. struct ic_version icversion_data[1]; /* any size array */
  1172. } __packed;
  1173. struct shutdown_msg_data {
  1174. u32 reason_code;
  1175. u32 timeout_seconds;
  1176. u32 flags;
  1177. u8 display_message[2048];
  1178. } __packed;
  1179. struct heartbeat_msg_data {
  1180. u64 seq_num;
  1181. u32 reserved[8];
  1182. } __packed;
  1183. /* Time Sync IC defs */
  1184. #define ICTIMESYNCFLAG_PROBE 0
  1185. #define ICTIMESYNCFLAG_SYNC 1
  1186. #define ICTIMESYNCFLAG_SAMPLE 2
  1187. #ifdef __x86_64__
  1188. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1189. #else
  1190. #define WLTIMEDELTA 116444736000000000LL
  1191. #endif
  1192. struct ictimesync_data {
  1193. u64 parenttime;
  1194. u64 childtime;
  1195. u64 roundtriptime;
  1196. u8 flags;
  1197. } __packed;
  1198. struct hyperv_service_callback {
  1199. u8 msg_type;
  1200. char *log_msg;
  1201. uuid_le data;
  1202. struct vmbus_channel *channel;
  1203. void (*callback) (void *context);
  1204. };
  1205. #define MAX_SRV_VER 0x7ffffff
  1206. extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  1207. struct icmsg_negotiate *, u8 *, int,
  1208. int);
  1209. int hv_kvp_init(struct hv_util_service *);
  1210. void hv_kvp_deinit(void);
  1211. void hv_kvp_onchannelcallback(void *);
  1212. int hv_vss_init(struct hv_util_service *);
  1213. void hv_vss_deinit(void);
  1214. void hv_vss_onchannelcallback(void *);
  1215. /*
  1216. * Negotiated version with the Host.
  1217. */
  1218. extern __u32 vmbus_proto_version;
  1219. #endif /* __KERNEL__ */
  1220. #endif /* _HYPERV_H */