1 #ifndef _ASM_X86_MSHYPER_H
2 #define _ASM_X86_MSHYPER_H
4 #include <linux/types.h>
5 #include <linux/interrupt.h>
6 #include <asm/hyperv.h>
9 * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
10 * is set by CPUID(HVCPUID_VERSION_FEATURES).
12 enum hv_cpuid_function
{
13 HVCPUID_VERSION_FEATURES
= 0x00000001,
14 HVCPUID_VENDOR_MAXFUNCTION
= 0x40000000,
15 HVCPUID_INTERFACE
= 0x40000001,
18 * The remaining functions depend on the value of
21 HVCPUID_VERSION
= 0x40000002,
22 HVCPUID_FEATURES
= 0x40000003,
23 HVCPUID_ENLIGHTENMENT_INFO
= 0x40000004,
24 HVCPUID_IMPLEMENTATION_LIMITS
= 0x40000005,
27 struct ms_hyperv_info
{
33 extern struct ms_hyperv_info ms_hyperv
;
36 * Declare the MSR used to setup pages used to communicate with the hypervisor.
38 union hv_x64_msr_hypercall_contents
{
43 u64 guest_physical_address
:52;
51 struct ms_hyperv_tsc_page
{
52 volatile u32 tsc_sequence
;
54 volatile u64 tsc_scale
;
55 volatile s64 tsc_offset
;
60 * The guest OS needs to register the guest ID with the hypervisor.
61 * The guest ID is a 64 bit entity and the structure of this ID is
62 * specified in the Hyper-V specification:
64 * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
66 * While the current guideline does not specify how Linux guest ID(s)
67 * need to be generated, our plan is to publish the guidelines for
68 * Linux and other guest operating systems that currently are hosted
69 * on Hyper-V. The implementation here conforms to this yet
70 * unpublished guidelines.
74 * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
75 * 62:56 - Os Type; Linux is 0x100
76 * 55:48 - Distro specific identification
77 * 47:16 - Linux kernel version number
78 * 15:0 - Distro specific identification
83 #define HV_LINUX_VENDOR_ID 0x8800
86 * Generate the guest ID based on the guideline described above.
89 static inline __u64
generate_guest_id(__u64 d_info1
, __u64 kernel_version
,
94 guest_id
= (((__u64
)HV_LINUX_VENDOR_ID
) << 56);
95 guest_id
|= (d_info1
<< 48);
96 guest_id
|= (kernel_version
<< 16);
103 /* Free the message slot and signal end-of-message if required */
104 static inline void vmbus_signal_eom(struct hv_message
*msg
, u32 old_msg_type
)
107 * On crash we're reading some other CPU's message page and we need
108 * to be careful: this other CPU may already had cleared the header
109 * and the host may already had delivered some other message there.
110 * In case we blindly write msg->header.message_type we're going
111 * to lose it. We can still lose a message of the same type but
112 * we count on the fact that there can only be one
113 * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages
116 if (cmpxchg(&msg
->header
.message_type
, old_msg_type
,
117 HVMSG_NONE
) != old_msg_type
)
121 * Make sure the write to MessageType (ie set to
122 * HVMSG_NONE) happens before we read the
123 * MessagePending and EOMing. Otherwise, the EOMing
124 * will not deliver any more messages since there is
129 if (msg
->header
.message_flags
.msg_pending
) {
131 * This will cause message queue rescan to
132 * possibly deliver another msg from the
135 wrmsrl(HV_X64_MSR_EOM
, 0);
139 #define hv_get_current_tick(tick) rdmsrl(HV_X64_MSR_TIME_REF_COUNT, tick)
140 #define hv_init_timer(timer, tick) wrmsrl(timer, tick)
141 #define hv_init_timer_config(config, val) wrmsrl(config, val)
143 #define hv_get_simp(val) rdmsrl(HV_X64_MSR_SIMP, val)
144 #define hv_set_simp(val) wrmsrl(HV_X64_MSR_SIMP, val)
146 #define hv_get_siefp(val) rdmsrl(HV_X64_MSR_SIEFP, val)
147 #define hv_set_siefp(val) wrmsrl(HV_X64_MSR_SIEFP, val)
149 #define hv_get_synic_state(val) rdmsrl(HV_X64_MSR_SCONTROL, val)
150 #define hv_set_synic_state(val) wrmsrl(HV_X64_MSR_SCONTROL, val)
152 #define hv_get_vp_index(index) rdmsrl(HV_X64_MSR_VP_INDEX, index)
154 #define hv_get_synint_state(int_num, val) rdmsrl(int_num, val)
155 #define hv_set_synint_state(int_num, val) wrmsrl(int_num, val)
157 void hyperv_callback_vector(void);
158 #ifdef CONFIG_TRACING
159 #define trace_hyperv_callback_vector hyperv_callback_vector
161 void hyperv_vector_handler(struct pt_regs
*regs
);
162 void hv_setup_vmbus_irq(void (*handler
)(void));
163 void hv_remove_vmbus_irq(void);
165 void hv_setup_kexec_handler(void (*handler
)(void));
166 void hv_remove_kexec_handler(void);
167 void hv_setup_crash_handler(void (*handler
)(struct pt_regs
*regs
));
168 void hv_remove_crash_handler(void);
170 #if IS_ENABLED(CONFIG_HYPERV)
171 void hyperv_init(void);
172 void hyperv_report_panic(struct pt_regs
*regs
);
173 bool hv_is_hypercall_page_setup(void);