Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_MSHYPER_H |
| 3 | #define _ASM_X86_MSHYPER_H |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 4 | |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 5 | #include <linux/types.h> |
Vitaly Kuznetsov | 806c892 | 2017-08-02 18:09:17 +0200 | [diff] [blame] | 6 | #include <linux/nmi.h> |
Boqun Feng | 1cf106d | 2020-02-10 11:39:53 +0800 | [diff] [blame] | 7 | #include <linux/msi.h> |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 8 | #include <asm/io.h> |
Vitaly Kuznetsov | 5a48580 | 2018-03-20 15:02:05 +0100 | [diff] [blame] | 9 | #include <asm/hyperv-tlfs.h> |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 10 | #include <asm/nospec-branch.h> |
Michael Kelley | b9d8cf2 | 2020-08-09 18:29:51 -0700 | [diff] [blame] | 11 | #include <asm/paravirt.h> |
Joseph Salisbury | 753ed9c | 2021-04-16 17:43:03 -0700 | [diff] [blame^] | 12 | #include <asm/mshyperv.h> |
H. Peter Anvin | e08cae4 | 2010-05-07 16:57:28 -0700 | [diff] [blame] | 13 | |
Lan Tianyu | cc4edae4 | 2018-12-06 21:21:05 +0800 | [diff] [blame] | 14 | typedef int (*hyperv_fill_flush_list_func)( |
| 15 | struct hv_guest_mapping_flush_list *flush, |
| 16 | void *data); |
| 17 | |
Michael Kelley | f3c5e63 | 2021-03-02 13:38:15 -0800 | [diff] [blame] | 18 | static inline void hv_set_register(unsigned int reg, u64 value) |
| 19 | { |
| 20 | wrmsrl(reg, value); |
| 21 | } |
K. Y. Srinivasan | d5116b4 | 2017-01-19 11:51:51 -0700 | [diff] [blame] | 22 | |
Michael Kelley | f3c5e63 | 2021-03-02 13:38:15 -0800 | [diff] [blame] | 23 | static inline u64 hv_get_register(unsigned int reg) |
| 24 | { |
| 25 | u64 value; |
K. Y. Srinivasan | 155e4a2 | 2017-01-19 11:51:54 -0700 | [diff] [blame] | 26 | |
Michael Kelley | f3c5e63 | 2021-03-02 13:38:15 -0800 | [diff] [blame] | 27 | rdmsrl(reg, value); |
| 28 | return value; |
| 29 | } |
K. Y. Srinivasan | 8e307bf | 2017-01-19 11:51:55 -0700 | [diff] [blame] | 30 | |
Michael Kelley | dd2cb34 | 2019-07-01 04:26:06 +0000 | [diff] [blame] | 31 | #define hv_get_raw_timer() rdtsc_ordered() |
| 32 | |
K. Y. Srinivasan | bc2b033 | 2013-02-03 17:22:39 -0800 | [diff] [blame] | 33 | void hyperv_vector_handler(struct pt_regs *regs); |
K. Y. Srinivasan | 8730046 | 2017-01-18 16:45:02 -0700 | [diff] [blame] | 34 | |
| 35 | #if IS_ENABLED(CONFIG_HYPERV) |
Dexuan Cui | dfe94d4 | 2020-12-21 22:55:41 -0800 | [diff] [blame] | 36 | extern int hyperv_init_cpuhp; |
| 37 | |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 38 | extern void *hv_hypercall_pg; |
K. Y. Srinivasan | 68bb7bf | 2018-05-16 14:53:31 -0700 | [diff] [blame] | 39 | extern void __percpu **hyperv_pcpu_input_arg; |
Wei Liu | 5d0f077 | 2021-02-03 15:04:24 +0000 | [diff] [blame] | 40 | extern void __percpu **hyperv_pcpu_output_arg; |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 41 | |
Wei Liu | 99a0f46 | 2021-02-03 15:04:25 +0000 | [diff] [blame] | 42 | extern u64 hv_current_partition_id; |
| 43 | |
Wei Liu | 86b5ec3 | 2021-02-03 15:04:28 +0000 | [diff] [blame] | 44 | int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); |
| 45 | int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); |
| 46 | int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); |
| 47 | |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 48 | static inline u64 hv_do_hypercall(u64 control, void *input, void *output) |
| 49 | { |
| 50 | u64 input_address = input ? virt_to_phys(input) : 0; |
| 51 | u64 output_address = output ? virt_to_phys(output) : 0; |
| 52 | u64 hv_status; |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 53 | |
| 54 | #ifdef CONFIG_X86_64 |
| 55 | if (!hv_hypercall_pg) |
| 56 | return U64_MAX; |
| 57 | |
| 58 | __asm__ __volatile__("mov %4, %%r8\n" |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 59 | CALL_NOSPEC |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 60 | : "=a" (hv_status), ASM_CALL_CONSTRAINT, |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 61 | "+c" (control), "+d" (input_address) |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 62 | : "r" (output_address), |
| 63 | THUNK_TARGET(hv_hypercall_pg) |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 64 | : "cc", "memory", "r8", "r9", "r10", "r11"); |
| 65 | #else |
| 66 | u32 input_address_hi = upper_32_bits(input_address); |
| 67 | u32 input_address_lo = lower_32_bits(input_address); |
| 68 | u32 output_address_hi = upper_32_bits(output_address); |
| 69 | u32 output_address_lo = lower_32_bits(output_address); |
| 70 | |
| 71 | if (!hv_hypercall_pg) |
| 72 | return U64_MAX; |
| 73 | |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 74 | __asm__ __volatile__(CALL_NOSPEC |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 75 | : "=A" (hv_status), |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 76 | "+c" (input_address_lo), ASM_CALL_CONSTRAINT |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 77 | : "A" (control), |
| 78 | "b" (input_address_hi), |
| 79 | "D"(output_address_hi), "S"(output_address_lo), |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 80 | THUNK_TARGET(hv_hypercall_pg) |
Vitaly Kuznetsov | fc53662 | 2017-08-02 18:09:14 +0200 | [diff] [blame] | 81 | : "cc", "memory"); |
| 82 | #endif /* !x86_64 */ |
| 83 | return hv_status; |
| 84 | } |
Vitaly Kuznetsov | dee863b | 2017-02-04 09:57:13 -0700 | [diff] [blame] | 85 | |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 86 | /* Fast hypercall with 8 bytes of input and no output */ |
| 87 | static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1) |
| 88 | { |
| 89 | u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT; |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 90 | |
| 91 | #ifdef CONFIG_X86_64 |
| 92 | { |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 93 | __asm__ __volatile__(CALL_NOSPEC |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 94 | : "=a" (hv_status), ASM_CALL_CONSTRAINT, |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 95 | "+c" (control), "+d" (input1) |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 96 | : THUNK_TARGET(hv_hypercall_pg) |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 97 | : "cc", "r8", "r9", "r10", "r11"); |
| 98 | } |
| 99 | #else |
| 100 | { |
| 101 | u32 input1_hi = upper_32_bits(input1); |
| 102 | u32 input1_lo = lower_32_bits(input1); |
| 103 | |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 104 | __asm__ __volatile__ (CALL_NOSPEC |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 105 | : "=A"(hv_status), |
| 106 | "+c"(input1_lo), |
Josh Poimboeuf | f5caf62 | 2017-09-20 16:24:33 -0500 | [diff] [blame] | 107 | ASM_CALL_CONSTRAINT |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 108 | : "A" (control), |
| 109 | "b" (input1_hi), |
David Woodhouse | e70e589 | 2018-01-11 21:46:30 +0000 | [diff] [blame] | 110 | THUNK_TARGET(hv_hypercall_pg) |
Vitaly Kuznetsov | 6a8edbd | 2017-08-02 18:09:15 +0200 | [diff] [blame] | 111 | : "cc", "edi", "esi"); |
| 112 | } |
| 113 | #endif |
| 114 | return hv_status; |
| 115 | } |
| 116 | |
Vitaly Kuznetsov | 53e5296 | 2018-06-22 19:06:22 +0200 | [diff] [blame] | 117 | /* Fast hypercall with 16 bytes of input */ |
| 118 | static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2) |
| 119 | { |
| 120 | u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT; |
| 121 | |
| 122 | #ifdef CONFIG_X86_64 |
| 123 | { |
| 124 | __asm__ __volatile__("mov %4, %%r8\n" |
| 125 | CALL_NOSPEC |
| 126 | : "=a" (hv_status), ASM_CALL_CONSTRAINT, |
| 127 | "+c" (control), "+d" (input1) |
| 128 | : "r" (input2), |
| 129 | THUNK_TARGET(hv_hypercall_pg) |
| 130 | : "cc", "r8", "r9", "r10", "r11"); |
| 131 | } |
| 132 | #else |
| 133 | { |
| 134 | u32 input1_hi = upper_32_bits(input1); |
| 135 | u32 input1_lo = lower_32_bits(input1); |
| 136 | u32 input2_hi = upper_32_bits(input2); |
| 137 | u32 input2_lo = lower_32_bits(input2); |
| 138 | |
| 139 | __asm__ __volatile__ (CALL_NOSPEC |
| 140 | : "=A"(hv_status), |
| 141 | "+c"(input1_lo), ASM_CALL_CONSTRAINT |
| 142 | : "A" (control), "b" (input1_hi), |
| 143 | "D"(input2_hi), "S"(input2_lo), |
| 144 | THUNK_TARGET(hv_hypercall_pg) |
| 145 | : "cc"); |
| 146 | } |
| 147 | #endif |
Yi Wang | b42967d | 2018-10-29 15:17:31 +0800 | [diff] [blame] | 148 | return hv_status; |
Vitaly Kuznetsov | 53e5296 | 2018-06-22 19:06:22 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Vitaly Kuznetsov | a46d15c | 2018-03-20 15:02:08 +0100 | [diff] [blame] | 151 | extern struct hv_vp_assist_page **hv_vp_assist_page; |
| 152 | |
| 153 | static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) |
| 154 | { |
| 155 | if (!hv_vp_assist_page) |
| 156 | return NULL; |
| 157 | |
| 158 | return hv_vp_assist_page[cpu]; |
| 159 | } |
Vitaly Kuznetsov | 7415aea | 2017-08-02 18:09:18 +0200 | [diff] [blame] | 160 | |
K. Y. Srinivasan | 6b48cb5 | 2018-05-16 14:53:30 -0700 | [diff] [blame] | 161 | void __init hyperv_init(void); |
Vitaly Kuznetsov | 2ffd9e3 | 2017-08-02 18:09:19 +0200 | [diff] [blame] | 162 | void hyperv_setup_mmu_ops(void); |
Vitaly Kuznetsov | 9328626 | 2018-01-24 14:23:33 +0100 | [diff] [blame] | 163 | void set_hv_tscchange_cb(void (*cb)(void)); |
| 164 | void clear_hv_tscchange_cb(void); |
| 165 | void hyperv_stop_tsc_emulation(void); |
Tianyu Lan | eb914cf | 2018-07-19 08:40:06 +0000 | [diff] [blame] | 166 | int hyperv_flush_guest_mapping(u64 as); |
Lan Tianyu | cc4edae4 | 2018-12-06 21:21:05 +0800 | [diff] [blame] | 167 | int hyperv_flush_guest_mapping_range(u64 as, |
| 168 | hyperv_fill_flush_list_func fill_func, void *data); |
| 169 | int hyperv_fill_flush_guest_mapping_list( |
| 170 | struct hv_guest_mapping_flush_list *flush, |
| 171 | u64 start_gfn, u64 end_gfn); |
Thomas Gleixner | 2d2ccf24 | 2018-05-19 21:22:48 +0200 | [diff] [blame] | 172 | |
Wei Liu | e997720 | 2021-02-03 15:04:21 +0000 | [diff] [blame] | 173 | extern bool hv_root_partition; |
| 174 | |
Thomas Gleixner | 2d2ccf24 | 2018-05-19 21:22:48 +0200 | [diff] [blame] | 175 | #ifdef CONFIG_X86_64 |
K. Y. Srinivasan | 6b48cb5 | 2018-05-16 14:53:30 -0700 | [diff] [blame] | 176 | void hv_apic_init(void); |
Yi Sun | 3a025de | 2018-10-08 16:29:34 +0800 | [diff] [blame] | 177 | void __init hv_init_spinlocks(void); |
| 178 | bool hv_vcpu_is_preempted(int vcpu); |
Thomas Gleixner | 2d2ccf24 | 2018-05-19 21:22:48 +0200 | [diff] [blame] | 179 | #else |
| 180 | static inline void hv_apic_init(void) {} |
| 181 | #endif |
| 182 | |
Boqun Feng | 1cf106d | 2020-02-10 11:39:53 +0800 | [diff] [blame] | 183 | static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry, |
| 184 | struct msi_desc *msi_desc) |
| 185 | { |
Wei Liu | d589ae6 | 2021-02-03 15:04:30 +0000 | [diff] [blame] | 186 | msi_entry->address.as_uint32 = msi_desc->msg.address_lo; |
| 187 | msi_entry->data.as_uint32 = msi_desc->msg.data; |
Boqun Feng | 1cf106d | 2020-02-10 11:39:53 +0800 | [diff] [blame] | 188 | } |
| 189 | |
Wei Liu | e39397d | 2021-02-03 15:04:34 +0000 | [diff] [blame] | 190 | struct irq_domain *hv_create_pci_msi_domain(void); |
| 191 | |
Wei Liu | fb5ef35 | 2021-02-03 15:04:35 +0000 | [diff] [blame] | 192 | int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector, |
| 193 | struct hv_interrupt_entry *entry); |
| 194 | int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry); |
| 195 | |
Vitaly Kuznetsov | 79cadff | 2017-08-02 18:09:13 +0200 | [diff] [blame] | 196 | #else /* CONFIG_HYPERV */ |
| 197 | static inline void hyperv_init(void) {} |
Vitaly Kuznetsov | 2ffd9e3 | 2017-08-02 18:09:19 +0200 | [diff] [blame] | 198 | static inline void hyperv_setup_mmu_ops(void) {} |
Vitaly Kuznetsov | 9328626 | 2018-01-24 14:23:33 +0100 | [diff] [blame] | 199 | static inline void set_hv_tscchange_cb(void (*cb)(void)) {} |
| 200 | static inline void clear_hv_tscchange_cb(void) {} |
| 201 | static inline void hyperv_stop_tsc_emulation(void) {}; |
Vitaly Kuznetsov | a46d15c | 2018-03-20 15:02:08 +0100 | [diff] [blame] | 202 | static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) |
| 203 | { |
| 204 | return NULL; |
| 205 | } |
Tianyu Lan | eb914cf | 2018-07-19 08:40:06 +0000 | [diff] [blame] | 206 | static inline int hyperv_flush_guest_mapping(u64 as) { return -1; } |
Lan Tianyu | cc4edae4 | 2018-12-06 21:21:05 +0800 | [diff] [blame] | 207 | static inline int hyperv_flush_guest_mapping_range(u64 as, |
| 208 | hyperv_fill_flush_list_func fill_func, void *data) |
| 209 | { |
| 210 | return -1; |
| 211 | } |
Vitaly Kuznetsov | 79cadff | 2017-08-02 18:09:13 +0200 | [diff] [blame] | 212 | #endif /* CONFIG_HYPERV */ |
| 213 | |
Michael Kelley | 765e33f | 2019-05-30 00:14:00 +0000 | [diff] [blame] | 214 | |
| 215 | #include <asm-generic/mshyperv.h> |
| 216 | |
Ky Srinivasan | a2a47c6 | 2010-05-06 12:08:41 -0700 | [diff] [blame] | 217 | #endif |