xref: /linux/arch/x86/include/asm/mshyperv.h (revision e810e48c0c9a1a1ebb90cfe966bce6dc80ce08e7)
1e08cae41SH. Peter Anvin #ifndef _ASM_X86_MSHYPER_H
2e08cae41SH. Peter Anvin #define _ASM_X86_MSHYPER_H
3a2a47c6cSKy Srinivasan 
4e08cae41SH. Peter Anvin #include <linux/types.h>
51aec1696SThomas Gleixner #include <linux/interrupt.h>
6e08cae41SH. Peter Anvin #include <asm/hyperv.h>
7e08cae41SH. Peter Anvin 
88de8af7eSK. Y. Srinivasan /*
98de8af7eSK. Y. Srinivasan  * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
108de8af7eSK. Y. Srinivasan  * is set by CPUID(HVCPUID_VERSION_FEATURES).
118de8af7eSK. Y. Srinivasan  */
128de8af7eSK. Y. Srinivasan enum hv_cpuid_function {
138de8af7eSK. Y. Srinivasan 	HVCPUID_VERSION_FEATURES		= 0x00000001,
148de8af7eSK. Y. Srinivasan 	HVCPUID_VENDOR_MAXFUNCTION		= 0x40000000,
158de8af7eSK. Y. Srinivasan 	HVCPUID_INTERFACE			= 0x40000001,
168de8af7eSK. Y. Srinivasan 
178de8af7eSK. Y. Srinivasan 	/*
188de8af7eSK. Y. Srinivasan 	 * The remaining functions depend on the value of
198de8af7eSK. Y. Srinivasan 	 * HVCPUID_INTERFACE
208de8af7eSK. Y. Srinivasan 	 */
218de8af7eSK. Y. Srinivasan 	HVCPUID_VERSION				= 0x40000002,
228de8af7eSK. Y. Srinivasan 	HVCPUID_FEATURES			= 0x40000003,
238de8af7eSK. Y. Srinivasan 	HVCPUID_ENLIGHTENMENT_INFO		= 0x40000004,
248de8af7eSK. Y. Srinivasan 	HVCPUID_IMPLEMENTATION_LIMITS		= 0x40000005,
258de8af7eSK. Y. Srinivasan };
268de8af7eSK. Y. Srinivasan 
27e08cae41SH. Peter Anvin struct ms_hyperv_info {
28e08cae41SH. Peter Anvin 	u32 features;
29cc2dd402SDenis V. Lunev 	u32 misc_features;
30e08cae41SH. Peter Anvin 	u32 hints;
31e08cae41SH. Peter Anvin };
32e08cae41SH. Peter Anvin 
33e08cae41SH. Peter Anvin extern struct ms_hyperv_info ms_hyperv;
34a2a47c6cSKy Srinivasan 
353f646ed7SK. Y. Srinivasan /*
363f646ed7SK. Y. Srinivasan  * Declare the MSR used to setup pages used to communicate with the hypervisor.
373f646ed7SK. Y. Srinivasan  */
383f646ed7SK. Y. Srinivasan union hv_x64_msr_hypercall_contents {
393f646ed7SK. Y. Srinivasan 	u64 as_uint64;
403f646ed7SK. Y. Srinivasan 	struct {
413f646ed7SK. Y. Srinivasan 		u64 enable:1;
423f646ed7SK. Y. Srinivasan 		u64 reserved:11;
433f646ed7SK. Y. Srinivasan 		u64 guest_physical_address:52;
443f646ed7SK. Y. Srinivasan 	};
453f646ed7SK. Y. Srinivasan };
463f646ed7SK. Y. Srinivasan 
47352c9624SK. Y. Srinivasan /*
4863ed4e0cSK. Y. Srinivasan  * TSC page layout.
4963ed4e0cSK. Y. Srinivasan  */
5063ed4e0cSK. Y. Srinivasan 
5163ed4e0cSK. Y. Srinivasan struct ms_hyperv_tsc_page {
5263ed4e0cSK. Y. Srinivasan 	volatile u32 tsc_sequence;
5363ed4e0cSK. Y. Srinivasan 	u32 reserved1;
5463ed4e0cSK. Y. Srinivasan 	volatile u64 tsc_scale;
5563ed4e0cSK. Y. Srinivasan 	volatile s64 tsc_offset;
5663ed4e0cSK. Y. Srinivasan 	u64 reserved2[509];
5763ed4e0cSK. Y. Srinivasan };
5863ed4e0cSK. Y. Srinivasan 
5963ed4e0cSK. Y. Srinivasan /*
60352c9624SK. Y. Srinivasan  * The guest OS needs to register the guest ID with the hypervisor.
61352c9624SK. Y. Srinivasan  * The guest ID is a 64 bit entity and the structure of this ID is
62352c9624SK. Y. Srinivasan  * specified in the Hyper-V specification:
63352c9624SK. Y. Srinivasan  *
64352c9624SK. Y. Srinivasan  * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
65352c9624SK. Y. Srinivasan  *
66352c9624SK. Y. Srinivasan  * While the current guideline does not specify how Linux guest ID(s)
67352c9624SK. Y. Srinivasan  * need to be generated, our plan is to publish the guidelines for
68352c9624SK. Y. Srinivasan  * Linux and other guest operating systems that currently are hosted
69352c9624SK. Y. Srinivasan  * on Hyper-V. The implementation here conforms to this yet
70352c9624SK. Y. Srinivasan  * unpublished guidelines.
71352c9624SK. Y. Srinivasan  *
72352c9624SK. Y. Srinivasan  *
73352c9624SK. Y. Srinivasan  * Bit(s)
74352c9624SK. Y. Srinivasan  * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
75352c9624SK. Y. Srinivasan  * 62:56 - Os Type; Linux is 0x100
76352c9624SK. Y. Srinivasan  * 55:48 - Distro specific identification
77352c9624SK. Y. Srinivasan  * 47:16 - Linux kernel version number
78352c9624SK. Y. Srinivasan  * 15:0  - Distro specific identification
79352c9624SK. Y. Srinivasan  *
80352c9624SK. Y. Srinivasan  *
81352c9624SK. Y. Srinivasan  */
82352c9624SK. Y. Srinivasan 
83352c9624SK. Y. Srinivasan #define HV_LINUX_VENDOR_ID              0x8800
84352c9624SK. Y. Srinivasan 
85352c9624SK. Y. Srinivasan /*
86352c9624SK. Y. Srinivasan  * Generate the guest ID based on the guideline described above.
87352c9624SK. Y. Srinivasan  */
88352c9624SK. Y. Srinivasan 
89352c9624SK. Y. Srinivasan static inline  __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,
90352c9624SK. Y. Srinivasan 				       __u64 d_info2)
91352c9624SK. Y. Srinivasan {
92352c9624SK. Y. Srinivasan 	__u64 guest_id = 0;
93352c9624SK. Y. Srinivasan 
94352c9624SK. Y. Srinivasan 	guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 56);
95352c9624SK. Y. Srinivasan 	guest_id |= (d_info1 << 48);
96352c9624SK. Y. Srinivasan 	guest_id |= (kernel_version << 16);
97352c9624SK. Y. Srinivasan 	guest_id |= d_info2;
98352c9624SK. Y. Srinivasan 
99352c9624SK. Y. Srinivasan 	return guest_id;
100352c9624SK. Y. Srinivasan }
101352c9624SK. Y. Srinivasan 
102*e810e48cSK. Y. Srinivasan 
103*e810e48cSK. Y. Srinivasan /* Free the message slot and signal end-of-message if required */
104*e810e48cSK. Y. Srinivasan static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
105*e810e48cSK. Y. Srinivasan {
106*e810e48cSK. Y. Srinivasan 	/*
107*e810e48cSK. Y. Srinivasan 	 * On crash we're reading some other CPU's message page and we need
108*e810e48cSK. Y. Srinivasan 	 * to be careful: this other CPU may already had cleared the header
109*e810e48cSK. Y. Srinivasan 	 * and the host may already had delivered some other message there.
110*e810e48cSK. Y. Srinivasan 	 * In case we blindly write msg->header.message_type we're going
111*e810e48cSK. Y. Srinivasan 	 * to lose it. We can still lose a message of the same type but
112*e810e48cSK. Y. Srinivasan 	 * we count on the fact that there can only be one
113*e810e48cSK. Y. Srinivasan 	 * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages
114*e810e48cSK. Y. Srinivasan 	 * on crash.
115*e810e48cSK. Y. Srinivasan 	 */
116*e810e48cSK. Y. Srinivasan 	if (cmpxchg(&msg->header.message_type, old_msg_type,
117*e810e48cSK. Y. Srinivasan 		    HVMSG_NONE) != old_msg_type)
118*e810e48cSK. Y. Srinivasan 		return;
119*e810e48cSK. Y. Srinivasan 
120*e810e48cSK. Y. Srinivasan 	/*
121*e810e48cSK. Y. Srinivasan 	 * Make sure the write to MessageType (ie set to
122*e810e48cSK. Y. Srinivasan 	 * HVMSG_NONE) happens before we read the
123*e810e48cSK. Y. Srinivasan 	 * MessagePending and EOMing. Otherwise, the EOMing
124*e810e48cSK. Y. Srinivasan 	 * will not deliver any more messages since there is
125*e810e48cSK. Y. Srinivasan 	 * no empty slot
126*e810e48cSK. Y. Srinivasan 	 */
127*e810e48cSK. Y. Srinivasan 	mb();
128*e810e48cSK. Y. Srinivasan 
129*e810e48cSK. Y. Srinivasan 	if (msg->header.message_flags.msg_pending) {
130*e810e48cSK. Y. Srinivasan 		/*
131*e810e48cSK. Y. Srinivasan 		 * This will cause message queue rescan to
132*e810e48cSK. Y. Srinivasan 		 * possibly deliver another msg from the
133*e810e48cSK. Y. Srinivasan 		 * hypervisor
134*e810e48cSK. Y. Srinivasan 		 */
135*e810e48cSK. Y. Srinivasan 		wrmsrl(HV_X64_MSR_EOM, 0);
136*e810e48cSK. Y. Srinivasan 	}
137*e810e48cSK. Y. Srinivasan }
138*e810e48cSK. Y. Srinivasan 
139bc2b0331SK. Y. Srinivasan void hyperv_callback_vector(void);
140cf910e83SSeiji Aguchi #ifdef CONFIG_TRACING
141cf910e83SSeiji Aguchi #define trace_hyperv_callback_vector hyperv_callback_vector
142cf910e83SSeiji Aguchi #endif
143bc2b0331SK. Y. Srinivasan void hyperv_vector_handler(struct pt_regs *regs);
14476d388cdSThomas Gleixner void hv_setup_vmbus_irq(void (*handler)(void));
14576d388cdSThomas Gleixner void hv_remove_vmbus_irq(void);
146bc2b0331SK. Y. Srinivasan 
1472517281dSVitaly Kuznetsov void hv_setup_kexec_handler(void (*handler)(void));
1482517281dSVitaly Kuznetsov void hv_remove_kexec_handler(void);
149b4370df2SVitaly Kuznetsov void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
150b4370df2SVitaly Kuznetsov void hv_remove_crash_handler(void);
1518730046cSK. Y. Srinivasan 
1528730046cSK. Y. Srinivasan #if IS_ENABLED(CONFIG_HYPERV)
1538730046cSK. Y. Srinivasan void hyperv_init(void);
154d058fa7eSK. Y. Srinivasan void hyperv_report_panic(struct pt_regs *regs);
15573638cddSK. Y. Srinivasan bool hv_is_hypercall_page_setup(void);
1568730046cSK. Y. Srinivasan #endif
157a2a47c6cSKy Srinivasan #endif
158