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;
40 extern u64 hv_current_partition_id;
42 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
43 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
44 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
46 static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
48 u64 input_address = input ? virt_to_phys(input) : 0;
49 u64 output_address = output ? virt_to_phys(output) : 0;
56 __asm__ __volatile__("mov %4, %%r8\n"
58 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
59 "+c" (control), "+d" (input_address)
60 : "r" (output_address),
61 THUNK_TARGET(hv_hypercall_pg)
62 : "cc", "memory", "r8", "r9", "r10", "r11");
64 u32 input_address_hi = upper_32_bits(input_address);
65 u32 input_address_lo = lower_32_bits(input_address);
66 u32 output_address_hi = upper_32_bits(output_address);
67 u32 output_address_lo = lower_32_bits(output_address);
72 __asm__ __volatile__(CALL_NOSPEC
74 "+c" (input_address_lo), ASM_CALL_CONSTRAINT
76 "b" (input_address_hi),
77 "D"(output_address_hi), "S"(output_address_lo),
78 THUNK_TARGET(hv_hypercall_pg)
84 /* Fast hypercall with 8 bytes of input and no output */
85 static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
87 u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT;
91 __asm__ __volatile__(CALL_NOSPEC
92 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
93 "+c" (control), "+d" (input1)
94 : THUNK_TARGET(hv_hypercall_pg)
95 : "cc", "r8", "r9", "r10", "r11");
99 u32 input1_hi = upper_32_bits(input1);
100 u32 input1_lo = lower_32_bits(input1);
102 __asm__ __volatile__ (CALL_NOSPEC
108 THUNK_TARGET(hv_hypercall_pg)
109 : "cc", "edi", "esi");
115 /* Fast hypercall with 16 bytes of input */
116 static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
118 u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT;
122 __asm__ __volatile__("mov %4, %%r8\n"
124 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
125 "+c" (control), "+d" (input1)
127 THUNK_TARGET(hv_hypercall_pg)
128 : "cc", "r8", "r9", "r10", "r11");
132 u32 input1_hi = upper_32_bits(input1);
133 u32 input1_lo = lower_32_bits(input1);
134 u32 input2_hi = upper_32_bits(input2);
135 u32 input2_lo = lower_32_bits(input2);
137 __asm__ __volatile__ (CALL_NOSPEC
139 "+c"(input1_lo), ASM_CALL_CONSTRAINT
140 : "A" (control), "b" (input1_hi),
141 "D"(input2_hi), "S"(input2_lo),
142 THUNK_TARGET(hv_hypercall_pg)
149 extern struct hv_vp_assist_page **hv_vp_assist_page;
151 static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
153 if (!hv_vp_assist_page)
156 return hv_vp_assist_page[cpu];
159 void __init hyperv_init(void);
160 void hyperv_setup_mmu_ops(void);
161 void set_hv_tscchange_cb(void (*cb)(void));
162 void clear_hv_tscchange_cb(void);
163 void hyperv_stop_tsc_emulation(void);
164 int hyperv_flush_guest_mapping(u64 as);
165 int hyperv_flush_guest_mapping_range(u64 as,
166 hyperv_fill_flush_list_func fill_func, void *data);
167 int hyperv_fill_flush_guest_mapping_list(
168 struct hv_guest_mapping_flush_list *flush,
169 u64 start_gfn, u64 end_gfn);
172 void hv_apic_init(void);
173 void __init hv_init_spinlocks(void);
174 bool hv_vcpu_is_preempted(int vcpu);
176 static inline void hv_apic_init(void) {}
179 static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry,
180 struct msi_desc *msi_desc)
182 msi_entry->address.as_uint32 = msi_desc->msg.address_lo;
183 msi_entry->data.as_uint32 = msi_desc->msg.data;
186 struct irq_domain *hv_create_pci_msi_domain(void);
188 int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector,
189 struct hv_interrupt_entry *entry);
190 int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);
192 #else /* CONFIG_HYPERV */
193 static inline void hyperv_init(void) {}
194 static inline void hyperv_setup_mmu_ops(void) {}
195 static inline void set_hv_tscchange_cb(void (*cb)(void)) {}
196 static inline void clear_hv_tscchange_cb(void) {}
197 static inline void hyperv_stop_tsc_emulation(void) {};
198 static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
202 static inline int hyperv_flush_guest_mapping(u64 as) { return -1; }
203 static inline int hyperv_flush_guest_mapping_range(u64 as,
204 hyperv_fill_flush_list_func fill_func, void *data)
208 #endif /* CONFIG_HYPERV */
211 #include <asm-generic/mshyperv.h>