1 /******************************************************************************
2 * asm-x86/guest/hyperv-hcall.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_HYPERV_HCALL_H__
20 #define __X86_HYPERV_HCALL_H__
21
22 #include <xen/lib.h>
23 #include <xen/types.h>
24
25 #include <asm/asm_defns.h>
26 #include <asm/fixmap.h>
27 #include <asm/guest/hyperv-tlfs.h>
28 #include <asm/page.h>
29
hv_do_hypercall(uint64_t control,paddr_t input_addr,paddr_t output_addr)30 static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t input_addr,
31 paddr_t output_addr)
32 {
33 uint64_t status;
34 register unsigned long r8 asm ( "r8" ) = output_addr;
35
36 /* See TLFS for volatile registers */
37 asm volatile ( "call hv_hcall_page"
38 : "=a" (status), "+c" (control),
39 "+d" (input_addr) ASM_CALL_CONSTRAINT
40 : "r" (r8)
41 : "memory" );
42
43 return status;
44 }
45
hv_do_fast_hypercall(uint16_t code,uint64_t input1,uint64_t input2)46 static inline uint64_t hv_do_fast_hypercall(uint16_t code,
47 uint64_t input1, uint64_t input2)
48 {
49 uint64_t status;
50 uint64_t control = code | HV_HYPERCALL_FAST_BIT;
51 register unsigned long r8 asm ( "r8" ) = input2;
52
53 /* See TLFS for volatile registers */
54 asm volatile ( "call hv_hcall_page"
55 : "=a" (status), "+c" (control),
56 "+d" (input1) ASM_CALL_CONSTRAINT
57 : "r" (r8) );
58
59 return status;
60 }
61
hv_do_rep_hypercall(uint16_t code,uint16_t rep_count,uint16_t varhead_size,paddr_t input,paddr_t output)62 static inline uint64_t hv_do_rep_hypercall(uint16_t code, uint16_t rep_count,
63 uint16_t varhead_size,
64 paddr_t input, paddr_t output)
65 {
66 uint64_t control = code;
67 uint64_t status;
68 uint16_t rep_comp;
69
70 control |= (uint64_t)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET;
71 control |= (uint64_t)rep_count << HV_HYPERCALL_REP_COMP_OFFSET;
72
73 do {
74 status = hv_do_hypercall(control, input, output);
75 if ( (status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS )
76 break;
77
78 rep_comp = MASK_EXTR(status, HV_HYPERCALL_REP_COMP_MASK);
79
80 control &= ~HV_HYPERCALL_REP_START_MASK;
81 control |= MASK_INSR(rep_comp, HV_HYPERCALL_REP_START_MASK);
82 } while ( rep_comp < rep_count );
83
84 return status;
85 }
86
87 #endif /* __X86_HYPERV_HCALL_H__ */
88
89 /*
90 * Local variables:
91 * mode: C
92 * c-file-style: "BSD"
93 * c-basic-offset: 4
94 * tab-width: 4
95 * indent-tabs-mode: nil
96 * End:
97 */
98