H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_MSHYPER_H |
| 2 | #define _ASM_X86_MSHYPER_H |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 3 | |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 4 | #include <linux/types.h> |
Thomas Gleixner | 1aec169 | 2014-02-23 21:40:22 +0000 | [diff] [blame] | 5 | #include <linux/interrupt.h> |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 6 | #include <asm/hyperv.h> |
| 7 | |
K. Y. Srinivasan | 8de8af7 | 2017-01-19 11:51:47 -0700 | [diff] [blame] | 8 | /* |
| 9 | * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent |
| 10 | * is set by CPUID(HVCPUID_VERSION_FEATURES). |
| 11 | */ |
| 12 | enum hv_cpuid_function { |
| 13 | HVCPUID_VERSION_FEATURES = 0x00000001, |
| 14 | HVCPUID_VENDOR_MAXFUNCTION = 0x40000000, |
| 15 | HVCPUID_INTERFACE = 0x40000001, |
| 16 | |
| 17 | /* |
| 18 | * The remaining functions depend on the value of |
| 19 | * HVCPUID_INTERFACE |
| 20 | */ |
| 21 | HVCPUID_VERSION = 0x40000002, |
| 22 | HVCPUID_FEATURES = 0x40000003, |
| 23 | HVCPUID_ENLIGHTENMENT_INFO = 0x40000004, |
| 24 | HVCPUID_IMPLEMENTATION_LIMITS = 0x40000005, |
| 25 | }; |
| 26 | |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 27 | struct ms_hyperv_info { |
| 28 | u32 features; |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 29 | u32 misc_features; |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 30 | u32 hints; |
| 31 | }; |
| 32 | |
| 33 | extern struct ms_hyperv_info ms_hyperv; |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 34 | |
K. Y. Srinivasan | 3f646ed | 2017-01-18 16:45:00 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Declare the MSR used to setup pages used to communicate with the hypervisor. |
| 37 | */ |
| 38 | union hv_x64_msr_hypercall_contents { |
| 39 | u64 as_uint64; |
| 40 | struct { |
| 41 | u64 enable:1; |
| 42 | u64 reserved:11; |
| 43 | u64 guest_physical_address:52; |
| 44 | }; |
| 45 | }; |
| 46 | |
K. Y. Srinivasan | 352c962 | 2017-01-18 16:45:01 -0700 | [diff] [blame] | 47 | /* |
K. Y. Srinivasan | 63ed4e0 | 2017-01-19 11:51:46 -0700 | [diff] [blame] | 48 | * TSC page layout. |
| 49 | */ |
| 50 | |
| 51 | struct ms_hyperv_tsc_page { |
| 52 | volatile u32 tsc_sequence; |
| 53 | u32 reserved1; |
| 54 | volatile u64 tsc_scale; |
| 55 | volatile s64 tsc_offset; |
| 56 | u64 reserved2[509]; |
| 57 | }; |
| 58 | |
| 59 | /* |
K. Y. Srinivasan | 352c962 | 2017-01-18 16:45:01 -0700 | [diff] [blame] | 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: |
| 63 | * |
| 64 | * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx |
| 65 | * |
| 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. |
| 71 | * |
| 72 | * |
| 73 | * Bit(s) |
| 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 |
| 79 | * |
| 80 | * |
| 81 | */ |
| 82 | |
| 83 | #define HV_LINUX_VENDOR_ID 0x8800 |
| 84 | |
| 85 | /* |
| 86 | * Generate the guest ID based on the guideline described above. |
| 87 | */ |
| 88 | |
| 89 | static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version, |
| 90 | __u64 d_info2) |
| 91 | { |
| 92 | __u64 guest_id = 0; |
| 93 | |
| 94 | guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 56); |
| 95 | guest_id |= (d_info1 << 48); |
| 96 | guest_id |= (kernel_version << 16); |
| 97 | guest_id |= d_info2; |
| 98 | |
| 99 | return guest_id; |
| 100 | } |
| 101 | |
K. Y. Srinivasan | bc2b033 | 2013-02-03 17:22:39 -0800 | [diff] [blame] | 102 | void hyperv_callback_vector(void); |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 103 | #ifdef CONFIG_TRACING |
| 104 | #define trace_hyperv_callback_vector hyperv_callback_vector |
| 105 | #endif |
K. Y. Srinivasan | bc2b033 | 2013-02-03 17:22:39 -0800 | [diff] [blame] | 106 | void hyperv_vector_handler(struct pt_regs *regs); |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 107 | void hv_setup_vmbus_irq(void (*handler)(void)); |
| 108 | void hv_remove_vmbus_irq(void); |
K. Y. Srinivasan | bc2b033 | 2013-02-03 17:22:39 -0800 | [diff] [blame] | 109 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 110 | void hv_setup_kexec_handler(void (*handler)(void)); |
| 111 | void hv_remove_kexec_handler(void); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 112 | void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs)); |
| 113 | void hv_remove_crash_handler(void); |
K. Y. Srinivasan | 8730046 | 2017-01-18 16:45:02 -0700 | [diff] [blame] | 114 | |
| 115 | #if IS_ENABLED(CONFIG_HYPERV) |
| 116 | void hyperv_init(void); |
K. Y. Srinivasan | d058fa7 | 2017-01-19 11:51:48 -0700 | [diff] [blame] | 117 | void hyperv_report_panic(struct pt_regs *regs); |
K. Y. Srinivasan | 73638cd | 2017-01-19 11:51:49 -0700 | [diff] [blame^] | 118 | bool hv_is_hypercall_page_setup(void); |
K. Y. Srinivasan | 8730046 | 2017-01-18 16:45:02 -0700 | [diff] [blame] | 119 | #endif |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 120 | #endif |