xref: /linux-6.15/include/asm-generic/mshyperv.h (revision e2575ffe)
1765e33f5SMichael Kelley /* SPDX-License-Identifier: GPL-2.0 */
2765e33f5SMichael Kelley 
3765e33f5SMichael Kelley /*
4765e33f5SMichael Kelley  * Linux-specific definitions for managing interactions with Microsoft's
5765e33f5SMichael Kelley  * Hyper-V hypervisor. The definitions in this file are architecture
6765e33f5SMichael Kelley  * independent. See arch/<arch>/include/asm/mshyperv.h for definitions
7765e33f5SMichael Kelley  * that are specific to architecture <arch>.
8765e33f5SMichael Kelley  *
9ef5a3c92SNuno Das Neves  * Definitions that are derived from Hyper-V code or headers should not go in
10ef5a3c92SNuno Das Neves  * this file, but should instead go in the relevant files in include/hyperv.
11765e33f5SMichael Kelley  *
12765e33f5SMichael Kelley  * Copyright (C) 2019, Microsoft, Inc.
13765e33f5SMichael Kelley  *
14765e33f5SMichael Kelley  * Author : Michael Kelley <[email protected]>
15765e33f5SMichael Kelley  */
16765e33f5SMichael Kelley 
17765e33f5SMichael Kelley #ifndef _ASM_GENERIC_MSHYPERV_H
18765e33f5SMichael Kelley #define _ASM_GENERIC_MSHYPERV_H
19765e33f5SMichael Kelley 
20765e33f5SMichael Kelley #include <linux/types.h>
21765e33f5SMichael Kelley #include <linux/atomic.h>
22765e33f5SMichael Kelley #include <linux/bitops.h>
231f1dc442SNuno Das Neves #include <acpi/acpi_numa.h>
24765e33f5SMichael Kelley #include <linux/cpumask.h>
25ba3f5839SMichael Kelley #include <linux/nmi.h>
26765e33f5SMichael Kelley #include <asm/ptrace.h>
27ef5a3c92SNuno Das Neves #include <hyperv/hvhdk.h>
28765e33f5SMichael Kelley 
29812b0597SMichael Kelley #define VTPM_BASE_ADDRESS 0xfed40000
30812b0597SMichael Kelley 
31db912b89SNuno Das Neves enum hv_partition_type {
32db912b89SNuno Das Neves 	HV_PARTITION_TYPE_GUEST,
33db912b89SNuno Das Neves 	HV_PARTITION_TYPE_ROOT,
34db912b89SNuno Das Neves };
35db912b89SNuno Das Neves 
36765e33f5SMichael Kelley struct ms_hyperv_info {
37765e33f5SMichael Kelley 	u32 features;
386dc2a774SSunil Muthuswamy 	u32 priv_high;
398cac5179SStanislav Kinsburskii 	u32 ext_features;
40765e33f5SMichael Kelley 	u32 misc_features;
41765e33f5SMichael Kelley 	u32 hints;
42765e33f5SMichael Kelley 	u32 nested_features;
43765e33f5SMichael Kelley 	u32 max_vp_index;
44765e33f5SMichael Kelley 	u32 max_lp_index;
45cfc7461aSOlaf Hering 	u8 vtl;
46d6e2d652STianyu Lan 	union {
47a6c76bb0SAndrea Parri (Microsoft) 		u32 isolation_config_a;
48d6e2d652STianyu Lan 		struct {
49d6e2d652STianyu Lan 			u32 paravisor_present : 1;
50d6e2d652STianyu Lan 			u32 reserved_a1 : 31;
51d6e2d652STianyu Lan 		};
52d6e2d652STianyu Lan 	};
53af788f35STianyu Lan 	union {
54a6c76bb0SAndrea Parri (Microsoft) 		u32 isolation_config_b;
55af788f35STianyu Lan 		struct {
56af788f35STianyu Lan 			u32 cvm_type : 4;
57d6e2d652STianyu Lan 			u32 reserved_b1 : 1;
58af788f35STianyu Lan 			u32 shared_gpa_boundary_active : 1;
59af788f35STianyu Lan 			u32 shared_gpa_boundary_bits : 6;
60d6e2d652STianyu Lan 			u32 reserved_b2 : 20;
61af788f35STianyu Lan 		};
62af788f35STianyu Lan 	};
63af788f35STianyu Lan 	u64 shared_gpa_boundary;
64765e33f5SMichael Kelley };
65765e33f5SMichael Kelley extern struct ms_hyperv_info ms_hyperv;
66c4bdf94fSJinank Jain extern bool hv_nested;
67e96204e5SNuno Das Neves extern u64 hv_current_partition_id;
68db912b89SNuno Das Neves extern enum hv_partition_type hv_curr_partition_type;
69765e33f5SMichael Kelley 
70db3c65bcSMichael Kelley extern void * __percpu *hyperv_pcpu_input_arg;
71db3c65bcSMichael Kelley extern void * __percpu *hyperv_pcpu_output_arg;
72afca4d95SMichael Kelley 
73feba84c2SNuno Das Neves u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);
74feba84c2SNuno Das Neves u64 hv_do_fast_hypercall8(u16 control, u64 input8);
75feba84c2SNuno Das Neves u64 hv_do_fast_hypercall16(u16 control, u64 input1, u64 input2);
76feba84c2SNuno Das Neves 
77e3131f1cSDexuan Cui bool hv_isolation_type_snp(void);
7808e9d120SDexuan Cui bool hv_isolation_type_tdx(void);
79765e33f5SMichael Kelley 
80af37bc75SNuno Das Neves /*
81af37bc75SNuno Das Neves  * On architectures where Hyper-V doesn't support AEOI (e.g., ARM64),
82af37bc75SNuno Das Neves  * it doesn't provide a recommendation flag and AEOI must be disabled.
83af37bc75SNuno Das Neves  */
hv_recommend_using_aeoi(void)84af37bc75SNuno Das Neves static inline bool hv_recommend_using_aeoi(void)
85af37bc75SNuno Das Neves {
86af37bc75SNuno Das Neves #ifdef HV_DEPRECATING_AEOI_RECOMMENDED
87af37bc75SNuno Das Neves 	return !(ms_hyperv.hints & HV_DEPRECATING_AEOI_RECOMMENDED);
88af37bc75SNuno Das Neves #else
89af37bc75SNuno Das Neves 	return false;
90af37bc75SNuno Das Neves #endif
91af37bc75SNuno Das Neves }
92af37bc75SNuno Das Neves 
hv_numa_node_to_pxm_info(int node)931f1dc442SNuno Das Neves static inline struct hv_proximity_domain_info hv_numa_node_to_pxm_info(int node)
941f1dc442SNuno Das Neves {
951f1dc442SNuno Das Neves 	struct hv_proximity_domain_info pxm_info = {};
961f1dc442SNuno Das Neves 
971f1dc442SNuno Das Neves 	if (node != NUMA_NO_NODE) {
981f1dc442SNuno Das Neves 		pxm_info.domain_id = node_to_pxm(node);
991f1dc442SNuno Das Neves 		pxm_info.flags.proximity_info_valid = 1;
1001f1dc442SNuno Das Neves 		pxm_info.flags.proximity_preferred = 1;
1011f1dc442SNuno Das Neves 	}
1021f1dc442SNuno Das Neves 
1031f1dc442SNuno Das Neves 	return pxm_info;
1041f1dc442SNuno Das Neves }
1051f1dc442SNuno Das Neves 
106753ed9c9SJoseph Salisbury /* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */
hv_result(u64 status)107753ed9c9SJoseph Salisbury static inline int hv_result(u64 status)
108753ed9c9SJoseph Salisbury {
109753ed9c9SJoseph Salisbury 	return status & HV_HYPERCALL_RESULT_MASK;
110753ed9c9SJoseph Salisbury }
111753ed9c9SJoseph Salisbury 
hv_result_success(u64 status)112753ed9c9SJoseph Salisbury static inline bool hv_result_success(u64 status)
113753ed9c9SJoseph Salisbury {
114753ed9c9SJoseph Salisbury 	return hv_result(status) == HV_STATUS_SUCCESS;
115753ed9c9SJoseph Salisbury }
116753ed9c9SJoseph Salisbury 
hv_repcomp(u64 status)117753ed9c9SJoseph Salisbury static inline unsigned int hv_repcomp(u64 status)
118753ed9c9SJoseph Salisbury {
119753ed9c9SJoseph Salisbury 	/* Bits [43:32] of status have 'Reps completed' data. */
120753ed9c9SJoseph Salisbury 	return (status & HV_HYPERCALL_REP_COMP_MASK) >>
121753ed9c9SJoseph Salisbury 			 HV_HYPERCALL_REP_COMP_OFFSET;
122753ed9c9SJoseph Salisbury }
123753ed9c9SJoseph Salisbury 
1246523592cSJoseph Salisbury /*
1256523592cSJoseph Salisbury  * Rep hypercalls. Callers of this functions are supposed to ensure that
1266523592cSJoseph Salisbury  * rep_count and varhead_size comply with Hyper-V hypercall definition.
1276523592cSJoseph Salisbury  */
hv_do_rep_hypercall(u16 code,u16 rep_count,u16 varhead_size,void * input,void * output)1286523592cSJoseph Salisbury static inline u64 hv_do_rep_hypercall(u16 code, u16 rep_count, u16 varhead_size,
1296523592cSJoseph Salisbury 				      void *input, void *output)
1306523592cSJoseph Salisbury {
1316523592cSJoseph Salisbury 	u64 control = code;
1326523592cSJoseph Salisbury 	u64 status;
1336523592cSJoseph Salisbury 	u16 rep_comp;
1346523592cSJoseph Salisbury 
1356523592cSJoseph Salisbury 	control |= (u64)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET;
1366523592cSJoseph Salisbury 	control |= (u64)rep_count << HV_HYPERCALL_REP_COMP_OFFSET;
1376523592cSJoseph Salisbury 
1386523592cSJoseph Salisbury 	do {
1396523592cSJoseph Salisbury 		status = hv_do_hypercall(control, input, output);
140753ed9c9SJoseph Salisbury 		if (!hv_result_success(status))
1416523592cSJoseph Salisbury 			return status;
1426523592cSJoseph Salisbury 
143753ed9c9SJoseph Salisbury 		rep_comp = hv_repcomp(status);
1446523592cSJoseph Salisbury 
1456523592cSJoseph Salisbury 		control &= ~HV_HYPERCALL_REP_START_MASK;
1466523592cSJoseph Salisbury 		control |= (u64)rep_comp << HV_HYPERCALL_REP_START_OFFSET;
1476523592cSJoseph Salisbury 
1486523592cSJoseph Salisbury 		touch_nmi_watchdog();
1496523592cSJoseph Salisbury 	} while (rep_comp < rep_count);
1506523592cSJoseph Salisbury 
1516523592cSJoseph Salisbury 	return status;
1526523592cSJoseph Salisbury }
153765e33f5SMichael Kelley 
154765e33f5SMichael Kelley /* Generate the guest OS identifier as described in the Hyper-V TLFS */
hv_generate_guest_id(u64 kernel_version)155d5ebde1eSLi kunyu static inline u64 hv_generate_guest_id(u64 kernel_version)
156765e33f5SMichael Kelley {
157d5ebde1eSLi kunyu 	u64 guest_id;
158765e33f5SMichael Kelley 
159d5ebde1eSLi kunyu 	guest_id = (((u64)HV_LINUX_VENDOR_ID) << 48);
160765e33f5SMichael Kelley 	guest_id |= (kernel_version << 16);
161765e33f5SMichael Kelley 
162765e33f5SMichael Kelley 	return guest_id;
163765e33f5SMichael Kelley }
164765e33f5SMichael Kelley 
165765e33f5SMichael Kelley /* Free the message slot and signal end-of-message if required */
vmbus_signal_eom(struct hv_message * msg,u32 old_msg_type)166765e33f5SMichael Kelley static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
167765e33f5SMichael Kelley {
168765e33f5SMichael Kelley 	/*
169765e33f5SMichael Kelley 	 * On crash we're reading some other CPU's message page and we need
170765e33f5SMichael Kelley 	 * to be careful: this other CPU may already had cleared the header
171765e33f5SMichael Kelley 	 * and the host may already had delivered some other message there.
172765e33f5SMichael Kelley 	 * In case we blindly write msg->header.message_type we're going
173765e33f5SMichael Kelley 	 * to lose it. We can still lose a message of the same type but
174765e33f5SMichael Kelley 	 * we count on the fact that there can only be one
175765e33f5SMichael Kelley 	 * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages
176765e33f5SMichael Kelley 	 * on crash.
177765e33f5SMichael Kelley 	 */
178765e33f5SMichael Kelley 	if (cmpxchg(&msg->header.message_type, old_msg_type,
179765e33f5SMichael Kelley 		    HVMSG_NONE) != old_msg_type)
180765e33f5SMichael Kelley 		return;
181765e33f5SMichael Kelley 
182765e33f5SMichael Kelley 	/*
183765e33f5SMichael Kelley 	 * The cmxchg() above does an implicit memory barrier to
184765e33f5SMichael Kelley 	 * ensure the write to MessageType (ie set to
185765e33f5SMichael Kelley 	 * HVMSG_NONE) happens before we read the
186765e33f5SMichael Kelley 	 * MessagePending and EOMing. Otherwise, the EOMing
187765e33f5SMichael Kelley 	 * will not deliver any more messages since there is
188765e33f5SMichael Kelley 	 * no empty slot
189765e33f5SMichael Kelley 	 */
190765e33f5SMichael Kelley 	if (msg->header.message_flags.msg_pending) {
191765e33f5SMichael Kelley 		/*
192765e33f5SMichael Kelley 		 * This will cause message queue rescan to
193765e33f5SMichael Kelley 		 * possibly deliver another msg from the
194765e33f5SMichael Kelley 		 * hypervisor
195765e33f5SMichael Kelley 		 */
1960e3f7d12SNuno Das Neves 		hv_set_msr(HV_MSR_EOM, 0);
197765e33f5SMichael Kelley 	}
198765e33f5SMichael Kelley }
199765e33f5SMichael Kelley 
200410779d8SNuno Das Neves int hv_get_hypervisor_version(union hv_hypervisor_version_info *info);
201410779d8SNuno Das Neves 
202d608715dSMichael Kelley void hv_setup_vmbus_handler(void (*handler)(void));
203d608715dSMichael Kelley void hv_remove_vmbus_handler(void);
204a620bbaaSMichael Kelley void hv_setup_stimer0_handler(void (*handler)(void));
205a620bbaaSMichael Kelley void hv_remove_stimer0_handler(void);
206765e33f5SMichael Kelley 
207765e33f5SMichael Kelley void hv_setup_kexec_handler(void (*handler)(void));
208765e33f5SMichael Kelley void hv_remove_kexec_handler(void);
209765e33f5SMichael Kelley void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
210765e33f5SMichael Kelley void hv_remove_crash_handler(void);
211*e2575ffeSNuno Das Neves void hv_setup_mshv_handler(void (*handler)(void));
212765e33f5SMichael Kelley 
213626b901fSMichael Kelley extern int vmbus_interrupt;
214d608715dSMichael Kelley extern int vmbus_irq;
215626b901fSMichael Kelley 
216765e33f5SMichael Kelley #if IS_ENABLED(CONFIG_HYPERV)
217765e33f5SMichael Kelley /*
218765e33f5SMichael Kelley  * Hypervisor's notion of virtual processor ID is different from
219765e33f5SMichael Kelley  * Linux' notion of CPU ID. This information can only be retrieved
220765e33f5SMichael Kelley  * in the context of the calling CPU. Setup a map for easy access
221765e33f5SMichael Kelley  * to this information.
222765e33f5SMichael Kelley  */
223765e33f5SMichael Kelley extern u32 *hv_vp_index;
224765e33f5SMichael Kelley extern u32 hv_max_vp_index;
225765e33f5SMichael Kelley 
22631e5e646SMichael Kelley extern u64 (*hv_read_reference_counter)(void);
22731e5e646SMichael Kelley 
228765e33f5SMichael Kelley /* Sentinel value for an uninitialized entry in hv_vp_index array */
229765e33f5SMichael Kelley #define VP_INVAL	U32_MAX
230765e33f5SMichael Kelley 
231afca4d95SMichael Kelley int __init hv_common_init(void);
232e96204e5SNuno Das Neves void __init hv_get_partition_id(void);
233afca4d95SMichael Kelley void __init hv_common_free(void);
234f2580a90SMichael Kelley void __init ms_hyperv_late_init(void);
235afca4d95SMichael Kelley int hv_common_cpu_init(unsigned int cpu);
236afca4d95SMichael Kelley int hv_common_cpu_die(unsigned int cpu);
237db912b89SNuno Das Neves void hv_identify_partition_type(void);
238afca4d95SMichael Kelley 
239ca48739eSMichael Kelley void *hv_alloc_hyperv_page(void);
240ca48739eSMichael Kelley void *hv_alloc_hyperv_zeroed_page(void);
241a6fe0438SKameron Carr void hv_free_hyperv_page(void *addr);
242ca48739eSMichael Kelley 
243765e33f5SMichael Kelley /**
244765e33f5SMichael Kelley  * hv_cpu_number_to_vp_number() - Map CPU to VP.
245765e33f5SMichael Kelley  * @cpu_number: CPU number in Linux terms
246765e33f5SMichael Kelley  *
247765e33f5SMichael Kelley  * This function returns the mapping between the Linux processor
248765e33f5SMichael Kelley  * number and the hypervisor's virtual processor number, useful
249765e33f5SMichael Kelley  * in making hypercalls and such that talk about specific
250765e33f5SMichael Kelley  * processors.
251765e33f5SMichael Kelley  *
252765e33f5SMichael Kelley  * Return: Virtual processor number in Hyper-V terms
253765e33f5SMichael Kelley  */
hv_cpu_number_to_vp_number(int cpu_number)254765e33f5SMichael Kelley static inline int hv_cpu_number_to_vp_number(int cpu_number)
255765e33f5SMichael Kelley {
256765e33f5SMichael Kelley 	return hv_vp_index[cpu_number];
257765e33f5SMichael Kelley }
258765e33f5SMichael Kelley 
__cpumask_to_vpset(struct hv_vpset * vpset,const struct cpumask * cpus,bool (* func)(int cpu))2597ad9bb9dSWei Liu static inline int __cpumask_to_vpset(struct hv_vpset *vpset,
2607ad9bb9dSWei Liu 				    const struct cpumask *cpus,
261d7b6ba96SMichael Kelley 				    bool (*func)(int cpu))
262765e33f5SMichael Kelley {
263765e33f5SMichael Kelley 	int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1;
264bd19c94aSVitaly Kuznetsov 	int max_vcpu_bank = hv_max_vp_index / HV_VCPUS_PER_SPARSE_BANK;
265765e33f5SMichael Kelley 
266bd19c94aSVitaly Kuznetsov 	/* vpset.valid_bank_mask can represent up to HV_MAX_SPARSE_VCPU_BANKS banks */
267bd19c94aSVitaly Kuznetsov 	if (max_vcpu_bank >= HV_MAX_SPARSE_VCPU_BANKS)
268765e33f5SMichael Kelley 		return 0;
269765e33f5SMichael Kelley 
270765e33f5SMichael Kelley 	/*
271765e33f5SMichael Kelley 	 * Clear all banks up to the maximum possible bank as hv_tlb_flush_ex
272765e33f5SMichael Kelley 	 * structs are not cleared between calls, we risk flushing unneeded
273765e33f5SMichael Kelley 	 * vCPUs otherwise.
274765e33f5SMichael Kelley 	 */
275bd19c94aSVitaly Kuznetsov 	for (vcpu_bank = 0; vcpu_bank <= max_vcpu_bank; vcpu_bank++)
276765e33f5SMichael Kelley 		vpset->bank_contents[vcpu_bank] = 0;
277765e33f5SMichael Kelley 
278765e33f5SMichael Kelley 	/*
279765e33f5SMichael Kelley 	 * Some banks may end up being empty but this is acceptable.
280765e33f5SMichael Kelley 	 */
281765e33f5SMichael Kelley 	for_each_cpu(cpu, cpus) {
282d7b6ba96SMichael Kelley 		if (func && func(cpu))
2837ad9bb9dSWei Liu 			continue;
284765e33f5SMichael Kelley 		vcpu = hv_cpu_number_to_vp_number(cpu);
285765e33f5SMichael Kelley 		if (vcpu == VP_INVAL)
286765e33f5SMichael Kelley 			return -1;
287bd19c94aSVitaly Kuznetsov 		vcpu_bank = vcpu / HV_VCPUS_PER_SPARSE_BANK;
288bd19c94aSVitaly Kuznetsov 		vcpu_offset = vcpu % HV_VCPUS_PER_SPARSE_BANK;
289765e33f5SMichael Kelley 		__set_bit(vcpu_offset, (unsigned long *)
290765e33f5SMichael Kelley 			  &vpset->bank_contents[vcpu_bank]);
291765e33f5SMichael Kelley 		if (vcpu_bank >= nr_bank)
292765e33f5SMichael Kelley 			nr_bank = vcpu_bank + 1;
293765e33f5SMichael Kelley 	}
294765e33f5SMichael Kelley 	vpset->valid_bank_mask = GENMASK_ULL(nr_bank - 1, 0);
295765e33f5SMichael Kelley 	return nr_bank;
296765e33f5SMichael Kelley }
297765e33f5SMichael Kelley 
298d7b6ba96SMichael Kelley /*
299d7b6ba96SMichael Kelley  * Convert a Linux cpumask into a Hyper-V VPset. In the _skip variant,
300d7b6ba96SMichael Kelley  * 'func' is called for each CPU present in cpumask.  If 'func' returns
301d7b6ba96SMichael Kelley  * true, that CPU is skipped -- i.e., that CPU from cpumask is *not*
302d7b6ba96SMichael Kelley  * added to the Hyper-V VPset. If 'func' is NULL, no CPUs are
303d7b6ba96SMichael Kelley  * skipped.
304d7b6ba96SMichael Kelley  */
cpumask_to_vpset(struct hv_vpset * vpset,const struct cpumask * cpus)3057ad9bb9dSWei Liu static inline int cpumask_to_vpset(struct hv_vpset *vpset,
3067ad9bb9dSWei Liu 				    const struct cpumask *cpus)
3077ad9bb9dSWei Liu {
308d7b6ba96SMichael Kelley 	return __cpumask_to_vpset(vpset, cpus, NULL);
3097ad9bb9dSWei Liu }
3107ad9bb9dSWei Liu 
cpumask_to_vpset_skip(struct hv_vpset * vpset,const struct cpumask * cpus,bool (* func)(int cpu))311d7b6ba96SMichael Kelley static inline int cpumask_to_vpset_skip(struct hv_vpset *vpset,
312d7b6ba96SMichael Kelley 				    const struct cpumask *cpus,
313d7b6ba96SMichael Kelley 				    bool (*func)(int cpu))
3147ad9bb9dSWei Liu {
315d7b6ba96SMichael Kelley 	return __cpumask_to_vpset(vpset, cpus, func);
3167ad9bb9dSWei Liu }
3177ad9bb9dSWei Liu 
3183817854bSNuno Das Neves #define _hv_status_fmt(fmt) "%s: Hyper-V status: %#x = %s: " fmt
3193817854bSNuno Das Neves #define hv_status_printk(level, status, fmt, ...) \
3203817854bSNuno Das Neves do { \
3213817854bSNuno Das Neves 	u64 __status = (status); \
3223817854bSNuno Das Neves 	pr_##level(_hv_status_fmt(fmt), __func__, hv_result(__status), \
3233817854bSNuno Das Neves 		   hv_result_to_string(__status), ##__VA_ARGS__); \
3243817854bSNuno Das Neves } while (0)
3253817854bSNuno Das Neves #define hv_status_err(status, fmt, ...) \
3263817854bSNuno Das Neves 	hv_status_printk(err, status, fmt, ##__VA_ARGS__)
3273817854bSNuno Das Neves #define hv_status_debug(status, fmt, ...) \
3283817854bSNuno Das Neves 	hv_status_printk(debug, status, fmt, ##__VA_ARGS__)
3293817854bSNuno Das Neves 
3303817854bSNuno Das Neves const char *hv_result_to_string(u64 hv_status);
3319d8731a1SNuno Das Neves int hv_result_to_errno(u64 status);
332f3a99e76STianyu Lan void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die);
333765e33f5SMichael Kelley bool hv_is_hyperv_initialized(void);
334b96f8653SDexuan Cui bool hv_is_hibernation_supported(void);
335a6c76bb0SAndrea Parri (Microsoft) enum hv_isolation_type hv_get_isolation_type(void);
336a6c76bb0SAndrea Parri (Microsoft) bool hv_is_isolation_supported(void);
3370cc4f6d9STianyu Lan bool hv_isolation_type_snp(void);
33820c89a55STianyu Lan u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_size);
339d6e0228dSDexuan Cui u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2);
340765e33f5SMichael Kelley void hyperv_cleanup(void);
3416dc2a774SSunil Muthuswamy bool hv_query_ext_cap(u64 cap_query);
34237200078SMichael Kelley void hv_setup_dma_ops(struct device *dev, bool coherent);
343765e33f5SMichael Kelley #else /* CONFIG_HYPERV */
hv_identify_partition_type(void)344db912b89SNuno Das Neves static inline void hv_identify_partition_type(void) {}
hv_is_hyperv_initialized(void)345765e33f5SMichael Kelley static inline bool hv_is_hyperv_initialized(void) { return false; }
hv_is_hibernation_supported(void)346b96f8653SDexuan Cui static inline bool hv_is_hibernation_supported(void) { return false; }
hyperv_cleanup(void)347765e33f5SMichael Kelley static inline void hyperv_cleanup(void) {}
ms_hyperv_late_init(void)348f2580a90SMichael Kelley static inline void ms_hyperv_late_init(void) {}
hv_is_isolation_supported(void)3490cc4f6d9STianyu Lan static inline bool hv_is_isolation_supported(void) { return false; }
hv_get_isolation_type(void)3500cc4f6d9STianyu Lan static inline enum hv_isolation_type hv_get_isolation_type(void)
3510cc4f6d9STianyu Lan {
3520cc4f6d9STianyu Lan 	return HV_ISOLATION_TYPE_NONE;
3530cc4f6d9STianyu Lan }
354765e33f5SMichael Kelley #endif /* CONFIG_HYPERV */
355765e33f5SMichael Kelley 
356461fbbd0SNuno Das Neves #if IS_ENABLED(CONFIG_MSHV_ROOT)
hv_root_partition(void)357db912b89SNuno Das Neves static inline bool hv_root_partition(void)
358db912b89SNuno Das Neves {
359db912b89SNuno Das Neves 	return hv_curr_partition_type == HV_PARTITION_TYPE_ROOT;
360db912b89SNuno Das Neves }
361461fbbd0SNuno Das Neves int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
362461fbbd0SNuno Das Neves int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
363461fbbd0SNuno Das Neves int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
364461fbbd0SNuno Das Neves 
365461fbbd0SNuno Das Neves #else /* CONFIG_MSHV_ROOT */
hv_root_partition(void)366461fbbd0SNuno Das Neves static inline bool hv_root_partition(void) { return false; }
hv_call_deposit_pages(int node,u64 partition_id,u32 num_pages)367461fbbd0SNuno Das Neves static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
368461fbbd0SNuno Das Neves {
369461fbbd0SNuno Das Neves 	return -EOPNOTSUPP;
370461fbbd0SNuno Das Neves }
hv_call_add_logical_proc(int node,u32 lp_index,u32 acpi_id)371461fbbd0SNuno Das Neves static inline int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id)
372461fbbd0SNuno Das Neves {
373461fbbd0SNuno Das Neves 	return -EOPNOTSUPP;
374461fbbd0SNuno Das Neves }
hv_call_create_vp(int node,u64 partition_id,u32 vp_index,u32 flags)375461fbbd0SNuno Das Neves static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
376461fbbd0SNuno Das Neves {
377461fbbd0SNuno Das Neves 	return -EOPNOTSUPP;
378461fbbd0SNuno Das Neves }
379461fbbd0SNuno Das Neves #endif /* CONFIG_MSHV_ROOT */
380db912b89SNuno Das Neves 
381765e33f5SMichael Kelley #endif
382