1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_MSHYPER_H
3 #define _ASM_X86_MSHYPER_H
5 #include <linux/types.h>
9 #include <asm/hyperv-tlfs.h>
10 #include <asm/nospec-branch.h>
11 #include <asm/paravirt.h>
12 #include <asm/mshyperv.h>
14 typedef int (*hyperv_fill_flush_list_func)(
15 struct hv_guest_mapping_flush_list *flush,
18 static inline void hv_set_register(unsigned int reg, u64 value)
23 static inline u64 hv_get_register(unsigned int reg)
31 #define hv_get_raw_timer() rdtsc_ordered()
33 void hyperv_vector_handler(struct pt_regs *regs);
35 #if IS_ENABLED(CONFIG_HYPERV)
36 extern int hyperv_init_cpuhp;
38 extern void *hv_hypercall_pg;
39 extern void __percpu **hyperv_pcpu_input_arg;
40 extern void __percpu **hyperv_pcpu_output_arg;
42 extern u64 hv_current_partition_id;
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);
48 static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
50 u64 input_address = input ? virt_to_phys(input) : 0;
51 u64 output_address = output ? virt_to_phys(output) : 0;
58 __asm__ __volatile__("mov %4, %%r8\n"
60 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
61 "+c" (control), "+d" (input_address)
62 : "r" (output_address),
63 THUNK_TARGET(hv_hypercall_pg)
64 : "cc", "memory", "r8", "r9", "r10", "r11");
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);
74 __asm__ __volatile__(CALL_NOSPEC
76 "+c" (input_address_lo), ASM_CALL_CONSTRAINT
78 "b" (input_address_hi),
79 "D"(output_address_hi), "S"(output_address_lo),
80 THUNK_TARGET(hv_hypercall_pg)
86 /* Fast hypercall with 8 bytes of input and no output */
87 static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
89 u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT;
93 __asm__ __volatile__(CALL_NOSPEC
94 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
95 "+c" (control), "+d" (input1)
96 : THUNK_TARGET(hv_hypercall_pg)
97 : "cc", "r8", "r9", "r10", "r11");
101 u32 input1_hi = upper_32_bits(input1);
102 u32 input1_lo = lower_32_bits(input1);
104 __asm__ __volatile__ (CALL_NOSPEC
110 THUNK_TARGET(hv_hypercall_pg)
111 : "cc", "edi", "esi");
117 /* Fast hypercall with 16 bytes of input */
118 static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
120 u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT;
124 __asm__ __volatile__("mov %4, %%r8\n"
126 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
127 "+c" (control), "+d" (input1)
129 THUNK_TARGET(hv_hypercall_pg)
130 : "cc", "r8", "r9", "r10", "r11");
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);
139 __asm__ __volatile__ (CALL_NOSPEC
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)
151 extern struct hv_vp_assist_page **hv_vp_assist_page;
153 static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
155 if (!hv_vp_assist_page)
158 return hv_vp_assist_page[cpu];
161 void __init hyperv_init(void);
162 void hyperv_setup_mmu_ops(void);
163 void set_hv_tscchange_cb(void (*cb)(void));
164 void clear_hv_tscchange_cb(void);
165 void hyperv_stop_tsc_emulation(void);
166 int hyperv_flush_guest_mapping(u64 as);
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);
173 extern bool hv_root_partition;
176 void hv_apic_init(void);
177 void __init hv_init_spinlocks(void);
178 bool hv_vcpu_is_preempted(int vcpu);
180 static inline void hv_apic_init(void) {}
183 static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry,
184 struct msi_desc *msi_desc)
186 msi_entry->address.as_uint32 = msi_desc->msg.address_lo;
187 msi_entry->data.as_uint32 = msi_desc->msg.data;
190 struct irq_domain *hv_create_pci_msi_domain(void);
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);
196 #else /* CONFIG_HYPERV */
197 static inline void hyperv_init(void) {}
198 static inline void hyperv_setup_mmu_ops(void) {}
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) {};
202 static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
206 static inline int hyperv_flush_guest_mapping(u64 as) { return -1; }
207 static inline int hyperv_flush_guest_mapping_range(u64 as,
208 hyperv_fill_flush_list_func fill_func, void *data)
212 #endif /* CONFIG_HYPERV */
215 #include <asm-generic/mshyperv.h>