3 * Copyright (c) 2011, Microsoft Corporation.
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.
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
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.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
21 * K. Y. Srinivasan <kys@microsoft.com>
28 #include <linux/types.h>
31 * An implementation of HyperV key value pair (KVP) functionality for Linux.
34 * Copyright (C) 2010, Novell, Inc.
35 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
40 * Maximum value size - used for both key names and value data, and includes
41 * any applicable NULL terminators.
43 * Note: This limit is somewhat arbitrary, but falls easily within what is
44 * supported for all native guests (back to Win 2000) and what is reasonable
45 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
46 * limited to 255 character key names.
48 * MSDN recommends not storing data values larger than 2048 bytes in the
51 * Note: This value is used in defining the KVP exchange message - this value
52 * cannot be modified without affecting the message size and compatibility.
56 * bytes, including any null terminators
58 #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
62 * Maximum key size - the registry limit for the length of an entry name
63 * is 256 characters, including the null terminator
66 #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
69 * In Linux, we implement the KVP functionality in two components:
70 * 1) The kernel component which is packaged as part of the hv_utils driver
71 * is responsible for communicating with the host and responsible for
72 * implementing the host/guest protocol. 2) A user level daemon that is
73 * responsible for data gathering.
75 * Host/Guest Protocol: The host iterates over an index and expects the guest
76 * to assign a key name to the index and also return the value corresponding to
77 * the key. The host will have atmost one KVP transaction outstanding at any
78 * given point in time. The host side iteration stops when the guest returns
79 * an error. Microsoft has specified the following mapping of key names to
80 * host specified index:
83 * 0 FullyQualifiedDomainName
84 * 1 IntegrationServicesVersion
85 * 2 NetworkAddressIPv4
86 * 3 NetworkAddressIPv6
92 * 9 ProcessorArchitecture
94 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
96 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
97 * data gathering functionality in a user mode daemon. The user level daemon
98 * is also responsible for binding the key name to the index as well. The
99 * kernel and user-level daemon communicate using a connector channel.
101 * The user mode component first registers with the
102 * the kernel component. Subsequently, the kernel component requests, data
103 * for the specified keys. In response to this message the user mode component
104 * fills in the value corresponding to the specified key. We overload the
105 * sequence field in the cn_msg header to define our KVP message types.
108 * The kernel component simply acts as a conduit for communication between the
109 * Windows host and the user-level daemon. The kernel component passes up the
110 * index received from the Host to the user-level daemon. If the index is
111 * valid (supported), the corresponding key as well as its
112 * value (both are strings) is returned. If the index is invalid
113 * (not supported), a NULL key string is returned.
118 * The following definitions are shared with the user-mode component; do not
119 * change any of this without making the corresponding changes in
120 * the KVP user-mode component.
124 KVP_REGISTER
= 0, /* Register the user mode component */
125 KVP_KERNEL_GET
, /* Kernel is requesting the value */
126 KVP_KERNEL_SET
, /* Kernel is providing the value */
127 KVP_USER_GET
, /* User is requesting the value */
128 KVP_USER_SET
/* User is providing the value */
132 __u32 kvp_index
; /* Key index */
133 __u8 kvp_key
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
]; /* Key name */
134 __u8 kvp_value
[HV_KVP_EXCHANGE_MAX_VALUE_SIZE
]; /* Key value */
142 * Registry value types.
147 enum hv_kvp_exchg_op
{
152 KVP_OP_COUNT
/* Number of operations, must be last. */
155 enum hv_kvp_exchg_pool
{
156 KVP_POOL_EXTERNAL
= 0,
159 KVP_POOL_AUTO_EXTERNAL
,
160 KVP_POOL_AUTO_INTERNAL
,
161 KVP_POOL_COUNT
/* Number of pools, must be last. */
168 } __attribute__((packed
));
170 struct hv_kvp_exchg_msg_value
{
174 __u8 key
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
];
175 __u8 value
[HV_KVP_EXCHANGE_MAX_VALUE_SIZE
];
176 } __attribute__((packed
));
178 struct hv_kvp_msg_enumerate
{
180 struct hv_kvp_exchg_msg_value data
;
181 } __attribute__((packed
));
184 struct hv_kvp_hdr kvp_hdr
;
185 struct hv_kvp_msg_enumerate kvp_data
;
186 } __attribute__((packed
));
189 #include <linux/scatterlist.h>
190 #include <linux/list.h>
191 #include <linux/uuid.h>
192 #include <linux/timer.h>
193 #include <linux/workqueue.h>
194 #include <linux/completion.h>
195 #include <linux/device.h>
196 #include <linux/mod_devicetable.h>
199 #define MAX_PAGE_BUFFER_COUNT 18
200 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
202 #pragma pack(push, 1)
204 /* Single-page buffer */
205 struct hv_page_buffer
{
211 /* Multiple-page buffer */
212 struct hv_multipage_buffer
{
213 /* Length and Offset determines the # of pfns in the array */
216 u64 pfn_array
[MAX_MULTIPAGE_BUFFER_COUNT
];
219 /* 0x18 includes the proprietary packet header */
220 #define MAX_PAGE_BUFFER_PACKET (0x18 + \
221 (sizeof(struct hv_page_buffer) * \
222 MAX_PAGE_BUFFER_COUNT))
223 #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
224 sizeof(struct hv_multipage_buffer))
229 struct hv_ring_buffer
{
230 /* Offset in bytes from the start of ring data below */
233 /* Offset in bytes from the start of ring data below */
238 /* Pad it to PAGE_SIZE so that data starts on page boundary */
242 * The interrupt_mask field is used only for channels but since our
243 * vmbus connection also uses this data structure and its data starts
244 * here, we commented out this field.
248 * Ring data starts here + RingDataStartOffset
249 * !!! DO NOT place any fields below this !!!
254 struct hv_ring_buffer_info
{
255 struct hv_ring_buffer
*ring_buffer
;
256 u32 ring_size
; /* Include the shared header */
257 spinlock_t ring_lock
;
259 u32 ring_datasize
; /* < ring_size */
260 u32 ring_data_startoffset
;
263 struct hv_ring_buffer_debug_info
{
264 u32 current_interrupt_mask
;
265 u32 current_read_index
;
266 u32 current_write_index
;
267 u32 bytes_avail_toread
;
268 u32 bytes_avail_towrite
;
272 * We use the same version numbering for all Hyper-V modules.
274 * Definition of versioning is as follows;
276 * Major Number Changes for these scenarios;
277 * 1. When a new version of Windows Hyper-V
279 * 2. A Major change has occurred in the
281 * (For example the merge for the first time
282 * into the kernel) Every time the Major Number
283 * changes, the Revision number is reset to 0.
284 * Minor Number Changes when new functionality is added
285 * to the Linux IC's that is not a bug fix.
287 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
289 #define HV_DRV_VERSION "3.1"
293 * A revision number of vmbus that is used for ensuring both ends on a
294 * partition are using compatible versions.
296 #define VMBUS_REVISION_NUMBER 13
298 /* Make maximum size of pipe payload of 16K */
299 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
301 /* Define PipeMode values. */
302 #define VMBUS_PIPE_TYPE_BYTE 0x00000000
303 #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
305 /* The size of the user defined data buffer for non-pipe offers. */
306 #define MAX_USER_DEFINED_BYTES 120
308 /* The size of the user defined data buffer for pipe offers. */
309 #define MAX_PIPE_USER_DEFINED_BYTES 116
312 * At the center of the Channel Management library is the Channel Offer. This
313 * struct contains the fundamental information about an offer.
315 struct vmbus_channel_offer
{
318 u64 int_latency
; /* in 100ns units */
320 u32 server_ctx_size
; /* in bytes */
322 u16 mmio_megabytes
; /* in bytes * 1024 * 1024 */
325 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
327 unsigned char user_def
[MAX_USER_DEFINED_BYTES
];
332 * The following sructure is an integrated pipe protocol, which
333 * is implemented on top of standard user-defined data. Pipe
334 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
339 unsigned char user_def
[MAX_PIPE_USER_DEFINED_BYTES
];
346 #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
347 #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
348 #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
349 #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
350 #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
351 #define VMBUS_CHANNEL_PARENT_OFFER 0x200
352 #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
354 struct vmpacket_descriptor
{
362 struct vmpacket_header
{
363 u32 prev_pkt_start_offset
;
364 struct vmpacket_descriptor descriptor
;
367 struct vmtransfer_page_range
{
372 struct vmtransfer_page_packet_header
{
373 struct vmpacket_descriptor d
;
375 bool sender_owns_set
;
378 struct vmtransfer_page_range ranges
[1];
381 struct vmgpadl_packet_header
{
382 struct vmpacket_descriptor d
;
387 struct vmadd_remove_transfer_page_set
{
388 struct vmpacket_descriptor d
;
395 * This structure defines a range in guest physical space that can be made to
396 * look virtually contiguous.
405 * This is the format for an Establish Gpadl packet, which contains a handle by
406 * which this GPADL will be known and a set of GPA ranges associated with it.
407 * This can be converted to a MDL by the guest OS. If there are multiple GPA
408 * ranges, then the resulting MDL will be "chained," representing multiple VA
411 struct vmestablish_gpadl
{
412 struct vmpacket_descriptor d
;
415 struct gpa_range range
[1];
419 * This is the format for a Teardown Gpadl packet, which indicates that the
420 * GPADL handle in the Establish Gpadl packet will never be referenced again.
422 struct vmteardown_gpadl
{
423 struct vmpacket_descriptor d
;
425 u32 reserved
; /* for alignment to a 8-byte boundary */
429 * This is the format for a GPA-Direct packet, which contains a set of GPA
430 * ranges, in addition to commands and/or data.
432 struct vmdata_gpa_direct
{
433 struct vmpacket_descriptor d
;
436 struct gpa_range range
[1];
439 /* This is the format for a Additional Data Packet. */
440 struct vmadditional_data
{
441 struct vmpacket_descriptor d
;
445 unsigned char data
[1];
448 union vmpacket_largest_possible_header
{
449 struct vmpacket_descriptor simple_hdr
;
450 struct vmtransfer_page_packet_header xfer_page_hdr
;
451 struct vmgpadl_packet_header gpadl_hdr
;
452 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr
;
453 struct vmestablish_gpadl establish_gpadl_hdr
;
454 struct vmteardown_gpadl teardown_gpadl_hdr
;
455 struct vmdata_gpa_direct data_gpa_direct_hdr
;
458 #define VMPACKET_DATA_START_ADDRESS(__packet) \
459 (void *)(((unsigned char *)__packet) + \
460 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
462 #define VMPACKET_DATA_LENGTH(__packet) \
463 ((((struct vmpacket_descriptor)__packet)->len8 - \
464 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
466 #define VMPACKET_TRANSFER_MODE(__packet) \
467 (((struct IMPACT)__packet)->type)
469 enum vmbus_packet_type
{
470 VM_PKT_INVALID
= 0x0,
472 VM_PKT_ADD_XFER_PAGESET
= 0x2,
473 VM_PKT_RM_XFER_PAGESET
= 0x3,
474 VM_PKT_ESTABLISH_GPADL
= 0x4,
475 VM_PKT_TEARDOWN_GPADL
= 0x5,
476 VM_PKT_DATA_INBAND
= 0x6,
477 VM_PKT_DATA_USING_XFER_PAGES
= 0x7,
478 VM_PKT_DATA_USING_GPADL
= 0x8,
479 VM_PKT_DATA_USING_GPA_DIRECT
= 0x9,
480 VM_PKT_CANCEL_REQUEST
= 0xa,
482 VM_PKT_DATA_USING_ADDITIONAL_PKT
= 0xc,
483 VM_PKT_ADDITIONAL_DATA
= 0xd
486 #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
489 /* Version 1 messages */
490 enum vmbus_channel_message_type
{
491 CHANNELMSG_INVALID
= 0,
492 CHANNELMSG_OFFERCHANNEL
= 1,
493 CHANNELMSG_RESCIND_CHANNELOFFER
= 2,
494 CHANNELMSG_REQUESTOFFERS
= 3,
495 CHANNELMSG_ALLOFFERS_DELIVERED
= 4,
496 CHANNELMSG_OPENCHANNEL
= 5,
497 CHANNELMSG_OPENCHANNEL_RESULT
= 6,
498 CHANNELMSG_CLOSECHANNEL
= 7,
499 CHANNELMSG_GPADL_HEADER
= 8,
500 CHANNELMSG_GPADL_BODY
= 9,
501 CHANNELMSG_GPADL_CREATED
= 10,
502 CHANNELMSG_GPADL_TEARDOWN
= 11,
503 CHANNELMSG_GPADL_TORNDOWN
= 12,
504 CHANNELMSG_RELID_RELEASED
= 13,
505 CHANNELMSG_INITIATE_CONTACT
= 14,
506 CHANNELMSG_VERSION_RESPONSE
= 15,
507 CHANNELMSG_UNLOAD
= 16,
508 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
509 CHANNELMSG_VIEWRANGE_ADD
= 17,
510 CHANNELMSG_VIEWRANGE_REMOVE
= 18,
515 struct vmbus_channel_message_header
{
516 enum vmbus_channel_message_type msgtype
;
520 /* Query VMBus Version parameters */
521 struct vmbus_channel_query_vmbus_version
{
522 struct vmbus_channel_message_header header
;
526 /* VMBus Version Supported parameters */
527 struct vmbus_channel_version_supported
{
528 struct vmbus_channel_message_header header
;
529 bool version_supported
;
532 /* Offer Channel parameters */
533 struct vmbus_channel_offer_channel
{
534 struct vmbus_channel_message_header header
;
535 struct vmbus_channel_offer offer
;
538 bool monitor_allocated
;
541 /* Rescind Offer parameters */
542 struct vmbus_channel_rescind_offer
{
543 struct vmbus_channel_message_header header
;
548 * Request Offer -- no parameters, SynIC message contains the partition ID
549 * Set Snoop -- no parameters, SynIC message contains the partition ID
550 * Clear Snoop -- no parameters, SynIC message contains the partition ID
551 * All Offers Delivered -- no parameters, SynIC message contains the partition
553 * Flush Client -- no parameters, SynIC message contains the partition ID
556 /* Open Channel parameters */
557 struct vmbus_channel_open_channel
{
558 struct vmbus_channel_message_header header
;
560 /* Identifies the specific VMBus channel that is being opened. */
563 /* ID making a particular open request at a channel offer unique. */
566 /* GPADL for the channel's ring buffer. */
567 u32 ringbuffer_gpadlhandle
;
569 /* GPADL for the channel's server context save area. */
570 u32 server_contextarea_gpadlhandle
;
573 * The upstream ring buffer begins at offset zero in the memory
574 * described by RingBufferGpadlHandle. The downstream ring buffer
575 * follows it at this offset (in pages).
577 u32 downstream_ringbuffer_pageoffset
;
579 /* User-specific data to be passed along to the server endpoint. */
580 unsigned char userdata
[MAX_USER_DEFINED_BYTES
];
583 /* Open Channel Result parameters */
584 struct vmbus_channel_open_result
{
585 struct vmbus_channel_message_header header
;
591 /* Close channel parameters; */
592 struct vmbus_channel_close_channel
{
593 struct vmbus_channel_message_header header
;
597 /* Channel Message GPADL */
598 #define GPADL_TYPE_RING_BUFFER 1
599 #define GPADL_TYPE_SERVER_SAVE_AREA 2
600 #define GPADL_TYPE_TRANSACTION 8
603 * The number of PFNs in a GPADL message is defined by the number of
604 * pages that would be spanned by ByteCount and ByteOffset. If the
605 * implied number of PFNs won't fit in this packet, there will be a
606 * follow-up packet that contains more.
608 struct vmbus_channel_gpadl_header
{
609 struct vmbus_channel_message_header header
;
614 struct gpa_range range
[0];
617 /* This is the followup packet that contains more PFNs. */
618 struct vmbus_channel_gpadl_body
{
619 struct vmbus_channel_message_header header
;
625 struct vmbus_channel_gpadl_created
{
626 struct vmbus_channel_message_header header
;
632 struct vmbus_channel_gpadl_teardown
{
633 struct vmbus_channel_message_header header
;
638 struct vmbus_channel_gpadl_torndown
{
639 struct vmbus_channel_message_header header
;
643 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
644 struct vmbus_channel_view_range_add
{
645 struct vmbus_channel_message_header header
;
646 PHYSICAL_ADDRESS viewrange_base
;
647 u64 viewrange_length
;
651 struct vmbus_channel_view_range_remove
{
652 struct vmbus_channel_message_header header
;
653 PHYSICAL_ADDRESS viewrange_base
;
658 struct vmbus_channel_relid_released
{
659 struct vmbus_channel_message_header header
;
663 struct vmbus_channel_initiate_contact
{
664 struct vmbus_channel_message_header header
;
665 u32 vmbus_version_requested
;
672 struct vmbus_channel_version_response
{
673 struct vmbus_channel_message_header header
;
674 bool version_supported
;
677 enum vmbus_channel_state
{
679 CHANNEL_OPENING_STATE
,
683 struct vmbus_channel_debug_info
{
685 enum vmbus_channel_state state
;
686 uuid_le interfacetype
;
687 uuid_le interface_instance
;
689 u32 servermonitor_pending
;
690 u32 servermonitor_latency
;
691 u32 servermonitor_connectionid
;
692 u32 clientmonitor_pending
;
693 u32 clientmonitor_latency
;
694 u32 clientmonitor_connectionid
;
696 struct hv_ring_buffer_debug_info inbound
;
697 struct hv_ring_buffer_debug_info outbound
;
701 * Represents each channel msg on the vmbus connection This is a
702 * variable-size data structure depending on the msg type itself
704 struct vmbus_channel_msginfo
{
705 /* Bookkeeping stuff */
706 struct list_head msglistentry
;
708 /* So far, this is only used to handle gpadl body message */
709 struct list_head submsglist
;
711 /* Synchronize the request/response if needed */
712 struct completion waitevent
;
714 struct vmbus_channel_version_supported version_supported
;
715 struct vmbus_channel_open_result open_result
;
716 struct vmbus_channel_gpadl_torndown gpadl_torndown
;
717 struct vmbus_channel_gpadl_created gpadl_created
;
718 struct vmbus_channel_version_response version_response
;
723 * The channel message that goes out on the "wire".
724 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
726 unsigned char msg
[0];
729 struct vmbus_close_msg
{
730 struct vmbus_channel_msginfo info
;
731 struct vmbus_channel_close_channel msg
;
734 struct vmbus_channel
{
735 struct list_head listentry
;
737 struct hv_device
*device_obj
;
739 struct work_struct work
;
741 enum vmbus_channel_state state
;
743 struct vmbus_channel_offer_channel offermsg
;
745 * These are based on the OfferMsg.MonitorId.
746 * Save it here for easy access.
751 u32 ringbuffer_gpadlhandle
;
753 /* Allocated memory for ring buffer */
754 void *ringbuffer_pages
;
755 u32 ringbuffer_pagecount
;
756 struct hv_ring_buffer_info outbound
; /* send to parent */
757 struct hv_ring_buffer_info inbound
; /* receive from parent */
758 spinlock_t inbound_lock
;
759 struct workqueue_struct
*controlwq
;
761 struct vmbus_close_msg close_msg
;
763 /* Channel callback are invoked in this workqueue context */
764 /* HANDLE dataWorkQueue; */
766 void (*onchannel_callback
)(void *context
);
767 void *channel_callback_context
;
770 void vmbus_onmessage(void *context
);
772 int vmbus_request_offers(void);
774 /* The format must be the same as struct vmdata_gpa_direct */
775 struct vmbus_channel_packet_page_buffer
{
783 struct hv_page_buffer range
[MAX_PAGE_BUFFER_COUNT
];
786 /* The format must be the same as struct vmdata_gpa_direct */
787 struct vmbus_channel_packet_multipage_buffer
{
794 u32 rangecount
; /* Always 1 in this case */
795 struct hv_multipage_buffer range
;
799 extern int vmbus_open(struct vmbus_channel
*channel
,
800 u32 send_ringbuffersize
,
801 u32 recv_ringbuffersize
,
804 void(*onchannel_callback
)(void *context
),
807 extern void vmbus_close(struct vmbus_channel
*channel
);
809 extern int vmbus_sendpacket(struct vmbus_channel
*channel
,
813 enum vmbus_packet_type type
,
816 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel
*channel
,
817 struct hv_page_buffer pagebuffers
[],
823 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel
*channel
,
824 struct hv_multipage_buffer
*mpb
,
829 extern int vmbus_establish_gpadl(struct vmbus_channel
*channel
,
834 extern int vmbus_teardown_gpadl(struct vmbus_channel
*channel
,
837 extern int vmbus_recvpacket(struct vmbus_channel
*channel
,
840 u32
*buffer_actual_len
,
843 extern int vmbus_recvpacket_raw(struct vmbus_channel
*channel
,
846 u32
*buffer_actual_len
,
850 extern void vmbus_get_debug_info(struct vmbus_channel
*channel
,
851 struct vmbus_channel_debug_info
*debug
);
853 extern void vmbus_ontimer(unsigned long data
);
855 struct hv_dev_port_info
{
859 u32 bytes_avail_toread
;
860 u32 bytes_avail_towrite
;
863 /* Base driver object */
867 /* the device type supported by this driver */
869 const struct hv_vmbus_device_id
*id_table
;
871 struct device_driver driver
;
873 int (*probe
)(struct hv_device
*, const struct hv_vmbus_device_id
*);
874 int (*remove
)(struct hv_device
*);
875 void (*shutdown
)(struct hv_device
*);
879 /* Base device object */
881 /* the device type id of this device */
884 /* the device instance id of this device */
885 uuid_le dev_instance
;
887 struct device device
;
889 struct vmbus_channel
*channel
;
893 static inline struct hv_device
*device_to_hv_device(struct device
*d
)
895 return container_of(d
, struct hv_device
, device
);
898 static inline struct hv_driver
*drv_to_hv_drv(struct device_driver
*d
)
900 return container_of(d
, struct hv_driver
, driver
);
903 static inline void hv_set_drvdata(struct hv_device
*dev
, void *data
)
905 dev_set_drvdata(&dev
->device
, data
);
908 static inline void *hv_get_drvdata(struct hv_device
*dev
)
910 return dev_get_drvdata(&dev
->device
);
913 /* Vmbus interface */
914 #define vmbus_driver_register(driver) \
915 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
916 int __must_check
__vmbus_driver_register(struct hv_driver
*hv_driver
,
917 struct module
*owner
,
918 const char *mod_name
);
919 void vmbus_driver_unregister(struct hv_driver
*hv_driver
);
922 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
924 * This macro is used to create a struct hv_vmbus_device_id that matches a
927 #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
928 g8, g9, ga, gb, gc, gd, ge, gf) \
929 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
930 g8, g9, ga, gb, gc, gd, ge, gf },
933 * Common header for Hyper-V ICs
936 #define ICMSGTYPE_NEGOTIATE 0
937 #define ICMSGTYPE_HEARTBEAT 1
938 #define ICMSGTYPE_KVPEXCHANGE 2
939 #define ICMSGTYPE_SHUTDOWN 3
940 #define ICMSGTYPE_TIMESYNC 4
941 #define ICMSGTYPE_VSS 5
943 #define ICMSGHDRFLAG_TRANSACTION 1
944 #define ICMSGHDRFLAG_REQUEST 2
945 #define ICMSGHDRFLAG_RESPONSE 4
947 #define HV_S_OK 0x00000000
948 #define HV_E_FAIL 0x80004005
949 #define HV_ERROR_NOT_SUPPORTED 0x80070032
950 #define HV_ERROR_MACHINE_LOCKED 0x800704F7
953 * While we want to handle util services as regular devices,
954 * there is only one instance of each of these services; so
955 * we statically allocate the service specific state.
958 struct hv_util_service
{
960 void (*util_cb
)(void *);
961 int (*util_init
)(struct hv_util_service
*);
962 void (*util_deinit
)(void);
965 struct vmbuspipe_hdr
{
976 struct ic_version icverframe
;
978 struct ic_version icvermsg
;
986 struct icmsg_negotiate
{
990 struct ic_version icversion_data
[1]; /* any size array */
993 struct shutdown_msg_data
{
997 u8 display_message
[2048];
1000 struct heartbeat_msg_data
{
1005 /* Time Sync IC defs */
1006 #define ICTIMESYNCFLAG_PROBE 0
1007 #define ICTIMESYNCFLAG_SYNC 1
1008 #define ICTIMESYNCFLAG_SAMPLE 2
1011 #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1013 #define WLTIMEDELTA 116444736000000000LL
1016 struct ictimesync_data
{
1023 struct hyperv_service_callback
{
1027 struct vmbus_channel
*channel
;
1028 void (*callback
) (void *context
);
1031 extern void vmbus_prep_negotiate_resp(struct icmsg_hdr
*,
1032 struct icmsg_negotiate
*, u8
*);
1034 int hv_kvp_init(struct hv_util_service
*);
1035 void hv_kvp_deinit(void);
1036 void hv_kvp_onchannelcallback(void *);
1038 #endif /* __KERNEL__ */
1039 #endif /* _HYPERV_H */