blob: 67ff0d637e554129454977d71ca03fc98badbd27 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvine08cae42010-05-07 16:57:28 -07002#ifndef _ASM_X86_MSHYPER_H
3#define _ASM_X86_MSHYPER_H
Ky Srinivasana2a47c62010-05-06 12:08:41 -07004
H. Peter Anvine08cae42010-05-07 16:57:28 -07005#include <linux/types.h>
Vitaly Kuznetsov806c8922017-08-02 18:09:17 +02006#include <linux/nmi.h>
Boqun Feng1cf106d2020-02-10 11:39:53 +08007#include <linux/msi.h>
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +02008#include <asm/io.h>
Vitaly Kuznetsov5a485802018-03-20 15:02:05 +01009#include <asm/hyperv-tlfs.h>
David Woodhousee70e5892018-01-11 21:46:30 +000010#include <asm/nospec-branch.h>
Michael Kelleyb9d8cf22020-08-09 18:29:51 -070011#include <asm/paravirt.h>
Joseph Salisbury753ed9c2021-04-16 17:43:03 -070012#include <asm/mshyperv.h>
H. Peter Anvine08cae42010-05-07 16:57:28 -070013
Lan Tianyucc4edae42018-12-06 21:21:05 +080014typedef int (*hyperv_fill_flush_list_func)(
15 struct hv_guest_mapping_flush_list *flush,
16 void *data);
17
Michael Kelleyf3c5e632021-03-02 13:38:15 -080018static inline void hv_set_register(unsigned int reg, u64 value)
19{
20 wrmsrl(reg, value);
21}
K. Y. Srinivasand5116b42017-01-19 11:51:51 -070022
Michael Kelleyf3c5e632021-03-02 13:38:15 -080023static inline u64 hv_get_register(unsigned int reg)
24{
25 u64 value;
K. Y. Srinivasan155e4a22017-01-19 11:51:54 -070026
Michael Kelleyf3c5e632021-03-02 13:38:15 -080027 rdmsrl(reg, value);
28 return value;
29}
K. Y. Srinivasan8e307bf2017-01-19 11:51:55 -070030
Michael Kelleydd2cb342019-07-01 04:26:06 +000031#define hv_get_raw_timer() rdtsc_ordered()
32
K. Y. Srinivasanbc2b0332013-02-03 17:22:39 -080033void hyperv_vector_handler(struct pt_regs *regs);
K. Y. Srinivasan87300462017-01-18 16:45:02 -070034
35#if IS_ENABLED(CONFIG_HYPERV)
Dexuan Cuidfe94d42020-12-21 22:55:41 -080036extern int hyperv_init_cpuhp;
37
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020038extern void *hv_hypercall_pg;
K. Y. Srinivasan68bb7bf2018-05-16 14:53:31 -070039extern void __percpu **hyperv_pcpu_input_arg;
Wei Liu5d0f0772021-02-03 15:04:24 +000040extern void __percpu **hyperv_pcpu_output_arg;
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020041
Wei Liu99a0f462021-02-03 15:04:25 +000042extern u64 hv_current_partition_id;
43
Wei Liu86b5ec32021-02-03 15:04:28 +000044int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
45int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
46int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
47
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020048static 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 Kuznetsovfc536622017-08-02 18:09:14 +020053
54#ifdef CONFIG_X86_64
55 if (!hv_hypercall_pg)
56 return U64_MAX;
57
58 __asm__ __volatile__("mov %4, %%r8\n"
David Woodhousee70e5892018-01-11 21:46:30 +000059 CALL_NOSPEC
Josh Poimboeuff5caf622017-09-20 16:24:33 -050060 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020061 "+c" (control), "+d" (input_address)
David Woodhousee70e5892018-01-11 21:46:30 +000062 : "r" (output_address),
63 THUNK_TARGET(hv_hypercall_pg)
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020064 : "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 Woodhousee70e5892018-01-11 21:46:30 +000074 __asm__ __volatile__(CALL_NOSPEC
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020075 : "=A" (hv_status),
Josh Poimboeuff5caf622017-09-20 16:24:33 -050076 "+c" (input_address_lo), ASM_CALL_CONSTRAINT
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020077 : "A" (control),
78 "b" (input_address_hi),
79 "D"(output_address_hi), "S"(output_address_lo),
David Woodhousee70e5892018-01-11 21:46:30 +000080 THUNK_TARGET(hv_hypercall_pg)
Vitaly Kuznetsovfc536622017-08-02 18:09:14 +020081 : "cc", "memory");
82#endif /* !x86_64 */
83 return hv_status;
84}
Vitaly Kuznetsovdee863b2017-02-04 09:57:13 -070085
Vitaly Kuznetsov6a8edbd2017-08-02 18:09:15 +020086/* Fast hypercall with 8 bytes of input and no output */
87static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
88{
89 u64 hv_status, control = (u64)code | HV_HYPERCALL_FAST_BIT;
Vitaly Kuznetsov6a8edbd2017-08-02 18:09:15 +020090
91#ifdef CONFIG_X86_64
92 {
David Woodhousee70e5892018-01-11 21:46:30 +000093 __asm__ __volatile__(CALL_NOSPEC
Josh Poimboeuff5caf622017-09-20 16:24:33 -050094 : "=a" (hv_status), ASM_CALL_CONSTRAINT,
Vitaly Kuznetsov6a8edbd2017-08-02 18:09:15 +020095 "+c" (control), "+d" (input1)
David Woodhousee70e5892018-01-11 21:46:30 +000096 : THUNK_TARGET(hv_hypercall_pg)
Vitaly Kuznetsov6a8edbd2017-08-02 18:09:15 +020097 : "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 Woodhousee70e5892018-01-11 21:46:30 +0000104 __asm__ __volatile__ (CALL_NOSPEC
Vitaly Kuznetsov6a8edbd2017-08-02 18:09:15 +0200105 : "=A"(hv_status),
106 "+c"(input1_lo),
Josh Poimboeuff5caf622017-09-20 16:24:33 -0500107 ASM_CALL_CONSTRAINT
Vitaly Kuznetsov6a8edbd2017-08-02 18:09:15 +0200108 : "A" (control),
109 "b" (input1_hi),
David Woodhousee70e5892018-01-11 21:46:30 +0000110 THUNK_TARGET(hv_hypercall_pg)
Vitaly Kuznetsov6a8edbd2017-08-02 18:09:15 +0200111 : "cc", "edi", "esi");
112 }
113#endif
114 return hv_status;
115}
116
Vitaly Kuznetsov53e52962018-06-22 19:06:22 +0200117/* Fast hypercall with 16 bytes of input */
118static 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 Wangb42967d2018-10-29 15:17:31 +0800148 return hv_status;
Vitaly Kuznetsov53e52962018-06-22 19:06:22 +0200149}
150
Vitaly Kuznetsova46d15c2018-03-20 15:02:08 +0100151extern struct hv_vp_assist_page **hv_vp_assist_page;
152
153static 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 Kuznetsov7415aea2017-08-02 18:09:18 +0200160
K. Y. Srinivasan6b48cb52018-05-16 14:53:30 -0700161void __init hyperv_init(void);
Vitaly Kuznetsov2ffd9e32017-08-02 18:09:19 +0200162void hyperv_setup_mmu_ops(void);
Vitaly Kuznetsov93286262018-01-24 14:23:33 +0100163void set_hv_tscchange_cb(void (*cb)(void));
164void clear_hv_tscchange_cb(void);
165void hyperv_stop_tsc_emulation(void);
Tianyu Laneb914cf2018-07-19 08:40:06 +0000166int hyperv_flush_guest_mapping(u64 as);
Lan Tianyucc4edae42018-12-06 21:21:05 +0800167int hyperv_flush_guest_mapping_range(u64 as,
168 hyperv_fill_flush_list_func fill_func, void *data);
169int hyperv_fill_flush_guest_mapping_list(
170 struct hv_guest_mapping_flush_list *flush,
171 u64 start_gfn, u64 end_gfn);
Thomas Gleixner2d2ccf242018-05-19 21:22:48 +0200172
Wei Liue9977202021-02-03 15:04:21 +0000173extern bool hv_root_partition;
174
Thomas Gleixner2d2ccf242018-05-19 21:22:48 +0200175#ifdef CONFIG_X86_64
K. Y. Srinivasan6b48cb52018-05-16 14:53:30 -0700176void hv_apic_init(void);
Yi Sun3a025de2018-10-08 16:29:34 +0800177void __init hv_init_spinlocks(void);
178bool hv_vcpu_is_preempted(int vcpu);
Thomas Gleixner2d2ccf242018-05-19 21:22:48 +0200179#else
180static inline void hv_apic_init(void) {}
181#endif
182
Boqun Feng1cf106d2020-02-10 11:39:53 +0800183static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entry,
184 struct msi_desc *msi_desc)
185{
Wei Liud589ae62021-02-03 15:04:30 +0000186 msi_entry->address.as_uint32 = msi_desc->msg.address_lo;
187 msi_entry->data.as_uint32 = msi_desc->msg.data;
Boqun Feng1cf106d2020-02-10 11:39:53 +0800188}
189
Wei Liue39397d2021-02-03 15:04:34 +0000190struct irq_domain *hv_create_pci_msi_domain(void);
191
Wei Liufb5ef352021-02-03 15:04:35 +0000192int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector,
193 struct hv_interrupt_entry *entry);
194int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);
195
Vitaly Kuznetsov79cadff2017-08-02 18:09:13 +0200196#else /* CONFIG_HYPERV */
197static inline void hyperv_init(void) {}
Vitaly Kuznetsov2ffd9e32017-08-02 18:09:19 +0200198static inline void hyperv_setup_mmu_ops(void) {}
Vitaly Kuznetsov93286262018-01-24 14:23:33 +0100199static inline void set_hv_tscchange_cb(void (*cb)(void)) {}
200static inline void clear_hv_tscchange_cb(void) {}
201static inline void hyperv_stop_tsc_emulation(void) {};
Vitaly Kuznetsova46d15c2018-03-20 15:02:08 +0100202static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
203{
204 return NULL;
205}
Tianyu Laneb914cf2018-07-19 08:40:06 +0000206static inline int hyperv_flush_guest_mapping(u64 as) { return -1; }
Lan Tianyucc4edae42018-12-06 21:21:05 +0800207static 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 Kuznetsov79cadff2017-08-02 18:09:13 +0200212#endif /* CONFIG_HYPERV */
213
Michael Kelley765e33f2019-05-30 00:14:00 +0000214
215#include <asm-generic/mshyperv.h>
216
Ky Srinivasana2a47c62010-05-06 12:08:41 -0700217#endif