1 /******************************************************************************
2 * asm-x86/guest/hyperv.h
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms and conditions of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public
14 * License along with this program; If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Copyright (c) 2019 Microsoft.
17 */
18
19 #ifndef __X86_GUEST_HYPERV_H__
20 #define __X86_GUEST_HYPERV_H__
21
22 #include <xen/types.h>
23
24 /* Use top-most MFN for hypercall page */
25 #define HV_HCALL_MFN (((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT)
26
27 /*
28 * The specification says: "The partition reference time is computed
29 * by the following formula:
30 *
31 * ReferenceTime = ((VirtualTsc * TscScale) >> 64) + TscOffset
32 *
33 * The multiplication is a 64 bit multiplication, which results in a
34 * 128 bit number which is then shifted 64 times to the right to obtain
35 * the high 64 bits."
36 */
hv_scale_tsc(uint64_t tsc,uint64_t scale,int64_t offset)37 static inline uint64_t hv_scale_tsc(uint64_t tsc, uint64_t scale,
38 int64_t offset)
39 {
40 uint64_t result;
41
42 /*
43 * Quadword MUL takes an implicit operand in RAX, and puts the result
44 * in RDX:RAX. Because we only want the result of the multiplication
45 * after shifting right by 64 bits, we therefore only need the content
46 * of RDX.
47 */
48 asm ( "mulq %[scale]"
49 : "+a" (tsc), "=d" (result)
50 : [scale] "rm" (scale) );
51
52 return result + offset;
53 }
54
55 #ifdef CONFIG_HYPERV_GUEST
56
57 #include <asm/guest/hypervisor.h>
58
59 struct ms_hyperv_info {
60 uint32_t features;
61 uint32_t misc_features;
62 uint32_t hints;
63 uint32_t nested_features;
64 uint32_t max_vp_index;
65 uint32_t max_lp_index;
66 };
67 extern struct ms_hyperv_info ms_hyperv;
68
69 const struct hypervisor_ops *hyperv_probe(void);
70
71 #else
72
hyperv_probe(void)73 static inline const struct hypervisor_ops *hyperv_probe(void) { return NULL; }
74
75 #endif /* CONFIG_HYPERV_GUEST */
76 #endif /* __X86_GUEST_HYPERV_H__ */
77
78 /*
79 * Local variables:
80 * mode: C
81 * c-file-style: "BSD"
82 * c-basic-offset: 4
83 * tab-width: 4
84 * indent-tabs-mode: nil
85 * End:
86 */
87