18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * KVM Microsoft Hyper-V emulation
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * derived from arch/x86/kvm/x86.c
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (C) 2006 Qumranet, Inc.
88c2ecf20Sopenharmony_ci * Copyright (C) 2008 Qumranet, Inc.
98c2ecf20Sopenharmony_ci * Copyright IBM Corporation, 2008
108c2ecf20Sopenharmony_ci * Copyright 2010 Red Hat, Inc. and/or its affiliates.
118c2ecf20Sopenharmony_ci * Copyright (C) 2015 Andrey Smetanin <asmetanin@virtuozzo.com>
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * Authors:
148c2ecf20Sopenharmony_ci *   Avi Kivity   <avi@qumranet.com>
158c2ecf20Sopenharmony_ci *   Yaniv Kamay  <yaniv@qumranet.com>
168c2ecf20Sopenharmony_ci *   Amit Shah    <amit.shah@qumranet.com>
178c2ecf20Sopenharmony_ci *   Ben-Ami Yassour <benami@il.ibm.com>
188c2ecf20Sopenharmony_ci *   Andrey Smetanin <asmetanin@virtuozzo.com>
198c2ecf20Sopenharmony_ci */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifndef __ARCH_X86_KVM_HYPERV_H__
228c2ecf20Sopenharmony_ci#define __ARCH_X86_KVM_HYPERV_H__
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <linux/kvm_host.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/*
278c2ecf20Sopenharmony_ci * The #defines related to the synthetic debugger are required by KDNet, but
288c2ecf20Sopenharmony_ci * they are not documented in the Hyper-V TLFS because the synthetic debugger
298c2ecf20Sopenharmony_ci * functionality has been deprecated and is subject to removal in future
308c2ecf20Sopenharmony_ci * versions of Windows.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#define HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS	0x40000080
338c2ecf20Sopenharmony_ci#define HYPERV_CPUID_SYNDBG_INTERFACE			0x40000081
348c2ecf20Sopenharmony_ci#define HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES	0x40000082
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/*
378c2ecf20Sopenharmony_ci * Hyper-V synthetic debugger platform capabilities
388c2ecf20Sopenharmony_ci * These are HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING	BIT(1)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* Hyper-V Synthetic debug options MSR */
438c2ecf20Sopenharmony_ci#define HV_X64_MSR_SYNDBG_CONTROL		0x400000F1
448c2ecf20Sopenharmony_ci#define HV_X64_MSR_SYNDBG_STATUS		0x400000F2
458c2ecf20Sopenharmony_ci#define HV_X64_MSR_SYNDBG_SEND_BUFFER		0x400000F3
468c2ecf20Sopenharmony_ci#define HV_X64_MSR_SYNDBG_RECV_BUFFER		0x400000F4
478c2ecf20Sopenharmony_ci#define HV_X64_MSR_SYNDBG_PENDING_BUFFER	0x400000F5
488c2ecf20Sopenharmony_ci#define HV_X64_MSR_SYNDBG_OPTIONS		0x400000FF
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* Hyper-V HV_X64_MSR_SYNDBG_OPTIONS bits */
518c2ecf20Sopenharmony_ci#define HV_X64_SYNDBG_OPTION_USE_HCALLS		BIT(2)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic inline struct kvm_vcpu_hv *vcpu_to_hv_vcpu(struct kvm_vcpu *vcpu)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	return &vcpu->arch.hyperv;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic inline struct kvm_vcpu *hv_vcpu_to_vcpu(struct kvm_vcpu_hv *hv_vcpu)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	struct kvm_vcpu_arch *arch;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	arch = container_of(hv_vcpu, struct kvm_vcpu_arch, hyperv);
638c2ecf20Sopenharmony_ci	return container_of(arch, struct kvm_vcpu, arch);
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistatic inline struct kvm_vcpu_hv_synic *vcpu_to_synic(struct kvm_vcpu *vcpu)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	return &vcpu->arch.hyperv.synic;
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistatic inline struct kvm_vcpu *synic_to_vcpu(struct kvm_vcpu_hv_synic *synic)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	return hv_vcpu_to_vcpu(container_of(synic, struct kvm_vcpu_hv, synic));
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic inline struct kvm_hv_syndbg *vcpu_to_hv_syndbg(struct kvm_vcpu *vcpu)
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci	return &vcpu->kvm->arch.hyperv.hv_syndbg;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciint kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host);
828c2ecf20Sopenharmony_ciint kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cibool kvm_hv_hypercall_enabled(struct kvm *kvm);
858c2ecf20Sopenharmony_ciint kvm_hv_hypercall(struct kvm_vcpu *vcpu);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_civoid kvm_hv_irq_routing_update(struct kvm *kvm);
888c2ecf20Sopenharmony_ciint kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint);
898c2ecf20Sopenharmony_civoid kvm_hv_synic_send_eoi(struct kvm_vcpu *vcpu, int vector);
908c2ecf20Sopenharmony_ciint kvm_hv_activate_synic(struct kvm_vcpu *vcpu, bool dont_zero_synic_pages);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_civoid kvm_hv_vcpu_init(struct kvm_vcpu *vcpu);
938c2ecf20Sopenharmony_civoid kvm_hv_vcpu_postcreate(struct kvm_vcpu *vcpu);
948c2ecf20Sopenharmony_civoid kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cibool kvm_hv_assist_page_enabled(struct kvm_vcpu *vcpu);
978c2ecf20Sopenharmony_cibool kvm_hv_get_assist_page(struct kvm_vcpu *vcpu,
988c2ecf20Sopenharmony_ci			    struct hv_vp_assist_page *assist_page);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic inline struct kvm_vcpu_hv_stimer *vcpu_to_stimer(struct kvm_vcpu *vcpu,
1018c2ecf20Sopenharmony_ci							int timer_index)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	return &vcpu_to_hv_vcpu(vcpu)->stimer[timer_index];
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistatic inline struct kvm_vcpu *stimer_to_vcpu(struct kvm_vcpu_hv_stimer *stimer)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	struct kvm_vcpu_hv *hv_vcpu;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	hv_vcpu = container_of(stimer - stimer->index, struct kvm_vcpu_hv,
1118c2ecf20Sopenharmony_ci			       stimer[0]);
1128c2ecf20Sopenharmony_ci	return hv_vcpu_to_vcpu(hv_vcpu);
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic inline bool kvm_hv_has_stimer_pending(struct kvm_vcpu *vcpu)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	return !bitmap_empty(vcpu->arch.hyperv.stimer_pending_bitmap,
1188c2ecf20Sopenharmony_ci			     HV_SYNIC_STIMER_COUNT);
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_civoid kvm_hv_process_stimers(struct kvm_vcpu *vcpu);
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_civoid kvm_hv_setup_tsc_page(struct kvm *kvm,
1248c2ecf20Sopenharmony_ci			   struct pvclock_vcpu_time_info *hv_clock);
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_civoid kvm_hv_init_vm(struct kvm *kvm);
1278c2ecf20Sopenharmony_civoid kvm_hv_destroy_vm(struct kvm *kvm);
1288c2ecf20Sopenharmony_ciint kvm_vm_ioctl_hv_eventfd(struct kvm *kvm, struct kvm_hyperv_eventfd *args);
1298c2ecf20Sopenharmony_ciint kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid,
1308c2ecf20Sopenharmony_ci				struct kvm_cpuid_entry2 __user *entries);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#endif
133