xref: /openbmc/linux/arch/x86/include/asm/mshyperv.h (revision 63ed4e0c)
1 #ifndef _ASM_X86_MSHYPER_H
2 #define _ASM_X86_MSHYPER_H
3 
4 #include <linux/types.h>
5 #include <linux/interrupt.h>
6 #include <asm/hyperv.h>
7 
8 struct ms_hyperv_info {
9 	u32 features;
10 	u32 misc_features;
11 	u32 hints;
12 };
13 
14 extern struct ms_hyperv_info ms_hyperv;
15 
16 /*
17  * Declare the MSR used to setup pages used to communicate with the hypervisor.
18  */
19 union hv_x64_msr_hypercall_contents {
20 	u64 as_uint64;
21 	struct {
22 		u64 enable:1;
23 		u64 reserved:11;
24 		u64 guest_physical_address:52;
25 	};
26 };
27 
28 /*
29  * TSC page layout.
30  */
31 
32 struct ms_hyperv_tsc_page {
33 	volatile u32 tsc_sequence;
34 	u32 reserved1;
35 	volatile u64 tsc_scale;
36 	volatile s64 tsc_offset;
37 	u64 reserved2[509];
38 };
39 
40 /*
41  * The guest OS needs to register the guest ID with the hypervisor.
42  * The guest ID is a 64 bit entity and the structure of this ID is
43  * specified in the Hyper-V specification:
44  *
45  * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
46  *
47  * While the current guideline does not specify how Linux guest ID(s)
48  * need to be generated, our plan is to publish the guidelines for
49  * Linux and other guest operating systems that currently are hosted
50  * on Hyper-V. The implementation here conforms to this yet
51  * unpublished guidelines.
52  *
53  *
54  * Bit(s)
55  * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
56  * 62:56 - Os Type; Linux is 0x100
57  * 55:48 - Distro specific identification
58  * 47:16 - Linux kernel version number
59  * 15:0  - Distro specific identification
60  *
61  *
62  */
63 
64 #define HV_LINUX_VENDOR_ID              0x8800
65 
66 /*
67  * Generate the guest ID based on the guideline described above.
68  */
69 
70 static inline  __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,
71 				       __u64 d_info2)
72 {
73 	__u64 guest_id = 0;
74 
75 	guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 56);
76 	guest_id |= (d_info1 << 48);
77 	guest_id |= (kernel_version << 16);
78 	guest_id |= d_info2;
79 
80 	return guest_id;
81 }
82 
83 void hyperv_callback_vector(void);
84 #ifdef CONFIG_TRACING
85 #define trace_hyperv_callback_vector hyperv_callback_vector
86 #endif
87 void hyperv_vector_handler(struct pt_regs *regs);
88 void hv_setup_vmbus_irq(void (*handler)(void));
89 void hv_remove_vmbus_irq(void);
90 
91 void hv_setup_kexec_handler(void (*handler)(void));
92 void hv_remove_kexec_handler(void);
93 void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
94 void hv_remove_crash_handler(void);
95 
96 #if IS_ENABLED(CONFIG_HYPERV)
97 void hyperv_init(void);
98 #endif
99 #endif
100