1 /*
2  * Copyright (C) 2019-2022 Intel Corporation.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef HYPERV_H
8 #define HYPERV_H
9 
10 #include <asm/guest/vcpuid.h>
11 
12 /* Hyper-V MSR numbers */
13 #define HV_X64_MSR_GUEST_OS_ID		0x40000000U
14 #define HV_X64_MSR_HYPERCALL		0x40000001U
15 #define HV_X64_MSR_VP_INDEX		0x40000002U
16 
17 #define HV_X64_MSR_TIME_REF_COUNT	0x40000020U
18 #define HV_X64_MSR_REFERENCE_TSC	0x40000021U
19 #define HV_X64_MSR_TSC_FREQUENCY	0x40000022U
20 #define HV_X64_MSR_APIC_FREQUENCY	0x40000023U
21 
22 union hyperv_ref_tsc_page_msr {
23 	uint64_t val64;
24 	struct {
25 		uint64_t enabled:1;
26 		uint64_t rsvdp:11;
27 		uint64_t gpfn:52;
28 	};
29 };
30 
31 union hyperv_hypercall_msr {
32 	uint64_t val64;
33 	struct {
34 		uint64_t enabled:1;
35 		uint64_t locked:1;
36 		uint64_t rsvdp:10;
37 		uint64_t gpfn:52;
38 	};
39 };
40 
41 union hyperv_guest_os_id_msr {
42 	uint64_t val64;
43 	struct {
44 		uint64_t build_number:16;
45 		uint64_t service_version:8;
46 		uint64_t minor_version:8;
47 		uint64_t major_version:8;
48 		uint64_t os_id:8;
49 		uint64_t vendor_id:15;
50 		uint64_t os_type:1;
51 	};
52 };
53 
54 struct acrn_hyperv {
55 	union hyperv_hypercall_msr	hypercall_page;
56 	union hyperv_guest_os_id_msr	guest_os_id;
57 	union hyperv_ref_tsc_page_msr	ref_tsc_page;
58 	uint64_t			tsc_scale;
59 	uint64_t			tsc_offset;
60 };
61 
62 int32_t hyperv_wrmsr(struct acrn_vcpu *vcpu, uint32_t msr, uint64_t wval);
63 int32_t hyperv_rdmsr(struct acrn_vcpu *vcpu, uint32_t msr, uint64_t *rval);
64 void hyperv_init_time(struct acrn_vm *vm);
65 void hyperv_init_vcpuid_entry(uint32_t leaf, uint32_t subleaf, uint32_t flags,
66 	struct vcpuid_entry *entry);
67 void hyperv_page_destory(struct acrn_vm *vm);
68 #endif
69