xref: /netbsd-src/sys/arch/i386/include/xen/hypercalls.h (revision c24c993fe4cf289234b8ce9b47d92eb1278cfbda)
1*c24c993fSbouyer /*	$NetBSD: hypercalls.h,v 1.2 2020/04/25 15:26:17 bouyer Exp $	*/
2*c24c993fSbouyer 
3*c24c993fSbouyer /*
4*c24c993fSbouyer  * Copyright (c) 2006 Manuel Bouyer.
5*c24c993fSbouyer  *
6*c24c993fSbouyer  * Redistribution and use in source and binary forms, with or without
7*c24c993fSbouyer  * modification, are permitted provided that the following conditions
8*c24c993fSbouyer  * are met:
9*c24c993fSbouyer  * 1. Redistributions of source code must retain the above copyright
10*c24c993fSbouyer  *    notice, this list of conditions and the following disclaimer.
11*c24c993fSbouyer  * 2. Redistributions in binary form must reproduce the above copyright
12*c24c993fSbouyer  *    notice, this list of conditions and the following disclaimer in the
13*c24c993fSbouyer  *    documentation and/or other materials provided with the distribution.
14*c24c993fSbouyer  *
15*c24c993fSbouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*c24c993fSbouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*c24c993fSbouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*c24c993fSbouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*c24c993fSbouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*c24c993fSbouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*c24c993fSbouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*c24c993fSbouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*c24c993fSbouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*c24c993fSbouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*c24c993fSbouyer  *
26*c24c993fSbouyer  */
27*c24c993fSbouyer 
28*c24c993fSbouyer /*
29*c24c993fSbouyer  *
30*c24c993fSbouyer  * Communication to/from hypervisor.
31*c24c993fSbouyer  *
32*c24c993fSbouyer  * Copyright (c) 2002-2004, K A Fraser
33*c24c993fSbouyer  *
34*c24c993fSbouyer  * Permission is hereby granted, free of charge, to any person obtaining a copy
35*c24c993fSbouyer  * of this source file (the "Software"), to deal in the Software without
36*c24c993fSbouyer  * restriction, including without limitation the rights to use, copy, modify,
37*c24c993fSbouyer  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
38*c24c993fSbouyer  * and to permit persons to whom the Software is furnished to do so, subject to
39*c24c993fSbouyer  * the following conditions:
40*c24c993fSbouyer  *
41*c24c993fSbouyer  * The above copyright notice and this permission notice shall be included in
42*c24c993fSbouyer  * all copies or substantial portions of the Software.
43*c24c993fSbouyer  *
44*c24c993fSbouyer  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45*c24c993fSbouyer  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46*c24c993fSbouyer  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47*c24c993fSbouyer  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48*c24c993fSbouyer  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
49*c24c993fSbouyer  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
50*c24c993fSbouyer  * IN THE SOFTWARE.
51*c24c993fSbouyer  */
52*c24c993fSbouyer 
53*c24c993fSbouyer 
54*c24c993fSbouyer #ifndef _XENI386_HYPERVISOR_H_
55*c24c993fSbouyer #define _XENI386_HYPERVISOR_H_
56*c24c993fSbouyer /*
57*c24c993fSbouyer  * Assembler stubs for hyper-calls.
58*c24c993fSbouyer  */
59*c24c993fSbouyer 
60*c24c993fSbouyer #include <machine/pte.h> /* pt_entry_t */
61*c24c993fSbouyer 
62*c24c993fSbouyer /* hypercall via the hypercall call page */
63*c24c993fSbouyer #define __str(x) #x
64*c24c993fSbouyer #define _str(x) __str(x)
65*c24c993fSbouyer #define _hypercall(name, input_const, output_const) \
66*c24c993fSbouyer 	__asm volatile ( \
67*c24c993fSbouyer 	    "call hypercall_page + ("_str(name)" * 32)" \
68*c24c993fSbouyer 	    : output_const \
69*c24c993fSbouyer 	    : input_const \
70*c24c993fSbouyer 	    : "memory" )
71*c24c993fSbouyer 
72*c24c993fSbouyer #define _harg(...) __VA_ARGS__
73*c24c993fSbouyer 
74*c24c993fSbouyer 
75*c24c993fSbouyer static __inline int
HYPERVISOR_set_trap_table(trap_info_t * table)76*c24c993fSbouyer HYPERVISOR_set_trap_table(trap_info_t *table)
77*c24c993fSbouyer {
78*c24c993fSbouyer     int ret;
79*c24c993fSbouyer     unsigned long ign1;
80*c24c993fSbouyer 
81*c24c993fSbouyer 	_hypercall(__HYPERVISOR_set_trap_table, _harg("1" (table)),
82*c24c993fSbouyer 	    _harg("=a" (ret), "=b" (ign1)));
83*c24c993fSbouyer 
84*c24c993fSbouyer     return ret;
85*c24c993fSbouyer }
86*c24c993fSbouyer 
87*c24c993fSbouyer static __inline int
HYPERVISOR_set_gdt(unsigned long * frame_list,int entries)88*c24c993fSbouyer HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
89*c24c993fSbouyer {
90*c24c993fSbouyer     int ret;
91*c24c993fSbouyer     unsigned long ign1, ign2;
92*c24c993fSbouyer 
93*c24c993fSbouyer     _hypercall(__HYPERVISOR_set_gdt, _harg("1" (frame_list), "2" (entries)),
94*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
95*c24c993fSbouyer 
96*c24c993fSbouyer     return ret;
97*c24c993fSbouyer }
98*c24c993fSbouyer 
99*c24c993fSbouyer static __inline int
HYPERVISOR_stack_switch(unsigned long ss,unsigned long esp)100*c24c993fSbouyer HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
101*c24c993fSbouyer {
102*c24c993fSbouyer     int ret;
103*c24c993fSbouyer     unsigned long ign1, ign2;
104*c24c993fSbouyer 
105*c24c993fSbouyer     _hypercall(__HYPERVISOR_stack_switch, _harg("1" (ss), "2" (esp)),
106*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
107*c24c993fSbouyer 
108*c24c993fSbouyer     return ret;
109*c24c993fSbouyer }
110*c24c993fSbouyer 
111*c24c993fSbouyer static __inline int
HYPERVISOR_set_callbacks(unsigned long event_selector,unsigned long event_address,unsigned long failsafe_selector,unsigned long failsafe_address)112*c24c993fSbouyer HYPERVISOR_set_callbacks(
113*c24c993fSbouyer     unsigned long event_selector, unsigned long event_address,
114*c24c993fSbouyer     unsigned long failsafe_selector, unsigned long failsafe_address)
115*c24c993fSbouyer {
116*c24c993fSbouyer     int ret;
117*c24c993fSbouyer     unsigned long ign1, ign2, ign3, ign4;
118*c24c993fSbouyer 
119*c24c993fSbouyer     _hypercall(__HYPERVISOR_set_callbacks,
120*c24c993fSbouyer 	_harg("1" (event_selector),"2" (event_address),
121*c24c993fSbouyer 	    "3" (failsafe_selector), "4" (failsafe_address)),
122*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
123*c24c993fSbouyer 
124*c24c993fSbouyer     return ret;
125*c24c993fSbouyer }
126*c24c993fSbouyer 
127*c24c993fSbouyer #if __XEN_INTERFACE_VERSION__ < 0x00030204
128*c24c993fSbouyer static __inline int
HYPERVISOR_dom0_op(dom0_op_t * dom0_op)129*c24c993fSbouyer HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
130*c24c993fSbouyer {
131*c24c993fSbouyer     int ret;
132*c24c993fSbouyer     unsigned long ign1;
133*c24c993fSbouyer 
134*c24c993fSbouyer     dom0_op->interface_version = DOM0_INTERFACE_VERSION;
135*c24c993fSbouyer     _hypercall(__HYPERVISOR_dom0_op, _harg("1" (dom0_op)),
136*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1)));
137*c24c993fSbouyer 
138*c24c993fSbouyer     return ret;
139*c24c993fSbouyer }
140*c24c993fSbouyer #endif	/* __XEN_INTERFACE_VERSION__ */
141*c24c993fSbouyer 
142*c24c993fSbouyer static __inline int
HYPERVISOR_set_debugreg(int reg,unsigned long value)143*c24c993fSbouyer HYPERVISOR_set_debugreg(int reg, unsigned long value)
144*c24c993fSbouyer {
145*c24c993fSbouyer     int ret;
146*c24c993fSbouyer     unsigned long ign1, ign2;
147*c24c993fSbouyer 
148*c24c993fSbouyer     _hypercall(__HYPERVISOR_set_debugreg, _harg("1" (reg), "2" (value)),
149*c24c993fSbouyer 	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
150*c24c993fSbouyer 
151*c24c993fSbouyer     return ret;
152*c24c993fSbouyer }
153*c24c993fSbouyer 
154*c24c993fSbouyer static __inline unsigned long
HYPERVISOR_get_debugreg(int reg)155*c24c993fSbouyer HYPERVISOR_get_debugreg(int reg)
156*c24c993fSbouyer {
157*c24c993fSbouyer     unsigned long ret;
158*c24c993fSbouyer     unsigned long ign1;
159*c24c993fSbouyer 
160*c24c993fSbouyer     _hypercall(__HYPERVISOR_get_debugreg, _harg("1" (reg)),
161*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1)));
162*c24c993fSbouyer 
163*c24c993fSbouyer     return ret;
164*c24c993fSbouyer }
165*c24c993fSbouyer 
166*c24c993fSbouyer #include <xen/include/public/arch-x86/xen-mca.h>
167*c24c993fSbouyer 
168*c24c993fSbouyer static __inline int
HYPERVISOR_machine_check(struct xen_mc * mc)169*c24c993fSbouyer HYPERVISOR_machine_check(struct xen_mc *mc)
170*c24c993fSbouyer {
171*c24c993fSbouyer      int ret;
172*c24c993fSbouyer      unsigned long ign1;
173*c24c993fSbouyer 
174*c24c993fSbouyer      mc->interface_version = XEN_MCA_INTERFACE_VERSION;
175*c24c993fSbouyer      _hypercall(__HYPERVISOR_mca, _harg("1" (mc)),
176*c24c993fSbouyer 	  _harg("=a" (ret), "=b" (ign1)));
177*c24c993fSbouyer 
178*c24c993fSbouyer      return ret;
179*c24c993fSbouyer }
180*c24c993fSbouyer 
181*c24c993fSbouyer static __inline int
HYPERVISOR_hvm_op(int cmd,void * arg)182*c24c993fSbouyer HYPERVISOR_hvm_op(int cmd, void *arg)
183*c24c993fSbouyer {
184*c24c993fSbouyer     int ret;
185*c24c993fSbouyer     unsigned long ign1, ign2;
186*c24c993fSbouyer 
187*c24c993fSbouyer     _hypercall(__HYPERVISOR_hvm_op, _harg("1" (cmd), "2" (arg)),
188*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
189*c24c993fSbouyer 
190*c24c993fSbouyer     return ret;
191*c24c993fSbouyer }
192*c24c993fSbouyer 
193*c24c993fSbouyer static __inline int
HYPERVISOR_mmu_update(mmu_update_t * req,int count,int * success_count,domid_t domid)194*c24c993fSbouyer HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count,
195*c24c993fSbouyer     domid_t domid)
196*c24c993fSbouyer {
197*c24c993fSbouyer     int ret;
198*c24c993fSbouyer     unsigned long ign1, ign2, ign3, ign4;
199*c24c993fSbouyer 
200*c24c993fSbouyer     _hypercall(__HYPERVISOR_mmu_update,
201*c24c993fSbouyer 	_harg("1" (req), "2" (count), "3" (success_count), "4" (domid)),
202*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
203*c24c993fSbouyer 
204*c24c993fSbouyer     return ret;
205*c24c993fSbouyer }
206*c24c993fSbouyer 
207*c24c993fSbouyer static __inline int
HYPERVISOR_mmuext_op(struct mmuext_op * op,int count,int * success_count,domid_t domid)208*c24c993fSbouyer HYPERVISOR_mmuext_op(struct mmuext_op *op, int count, int *success_count,
209*c24c993fSbouyer     domid_t domid)
210*c24c993fSbouyer {
211*c24c993fSbouyer     int ret;
212*c24c993fSbouyer     unsigned long ign1, ign2, ign3, ign4;
213*c24c993fSbouyer 
214*c24c993fSbouyer     _hypercall(__HYPERVISOR_mmuext_op,
215*c24c993fSbouyer 	_harg("1" (op), "2" (count), "3" (success_count), "4" (domid)),
216*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
217*c24c993fSbouyer 
218*c24c993fSbouyer     return ret;
219*c24c993fSbouyer }
220*c24c993fSbouyer 
221*c24c993fSbouyer static __inline int
HYPERVISOR_fpu_taskswitch(int set)222*c24c993fSbouyer HYPERVISOR_fpu_taskswitch(int set)
223*c24c993fSbouyer {
224*c24c993fSbouyer     long ret;
225*c24c993fSbouyer     long ign1;
226*c24c993fSbouyer 
227*c24c993fSbouyer     _hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (set)),
228*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1)));
229*c24c993fSbouyer 
230*c24c993fSbouyer     return ret;
231*c24c993fSbouyer }
232*c24c993fSbouyer 
233*c24c993fSbouyer static __inline int
HYPERVISOR_update_descriptor(uint64_t ma,uint32_t word1,uint32_t word2)234*c24c993fSbouyer HYPERVISOR_update_descriptor(uint64_t ma, uint32_t word1, uint32_t word2)
235*c24c993fSbouyer {
236*c24c993fSbouyer     int ret;
237*c24c993fSbouyer     unsigned long ign1, ign2, ign3, ign4;
238*c24c993fSbouyer     int ma1 = ma & 0xffffffff;
239*c24c993fSbouyer     int ma2 = (ma >> 32) & 0xffffffff;
240*c24c993fSbouyer 
241*c24c993fSbouyer     _hypercall(__HYPERVISOR_update_descriptor,
242*c24c993fSbouyer 	_harg("1" (ma1), "2" (ma2), "3" (word1), "4" (word2)),
243*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
244*c24c993fSbouyer 
245*c24c993fSbouyer     return ret;
246*c24c993fSbouyer }
247*c24c993fSbouyer 
248*c24c993fSbouyer static __inline int
HYPERVISOR_memory_op(unsigned int cmd,void * arg)249*c24c993fSbouyer HYPERVISOR_memory_op(unsigned int cmd, void *arg)
250*c24c993fSbouyer {
251*c24c993fSbouyer     int ret;
252*c24c993fSbouyer     unsigned long ign1, ign2;
253*c24c993fSbouyer 
254*c24c993fSbouyer     _hypercall(__HYPERVISOR_memory_op, _harg("1" (cmd), "2" (arg)),
255*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
256*c24c993fSbouyer 
257*c24c993fSbouyer     return ret;
258*c24c993fSbouyer }
259*c24c993fSbouyer 
260*c24c993fSbouyer #ifdef XENPV
261*c24c993fSbouyer static __inline int
HYPERVISOR_update_va_mapping(unsigned long page_nr,pt_entry_t new_val,unsigned long flags)262*c24c993fSbouyer HYPERVISOR_update_va_mapping(unsigned long page_nr, pt_entry_t new_val,
263*c24c993fSbouyer     unsigned long flags)
264*c24c993fSbouyer {
265*c24c993fSbouyer     int ret;
266*c24c993fSbouyer     unsigned long ign1, ign2, ign3, ign4;
267*c24c993fSbouyer     unsigned long pte_low, pte_hi;
268*c24c993fSbouyer 
269*c24c993fSbouyer     pte_low = new_val & 0xffffffff;
270*c24c993fSbouyer     pte_hi = new_val >> 32;
271*c24c993fSbouyer 
272*c24c993fSbouyer     _hypercall(__HYPERVISOR_update_va_mapping,
273*c24c993fSbouyer 	_harg("1" (page_nr), "2" (pte_low), "3" (pte_hi), "4" (flags)),
274*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
275*c24c993fSbouyer 
276*c24c993fSbouyer #ifdef notdef
277*c24c993fSbouyer     if (__predict_false(ret < 0))
278*c24c993fSbouyer         panic("Failed update VA mapping: %08lx, %08lx, %08lx",
279*c24c993fSbouyer               page_nr, new_val, flags);
280*c24c993fSbouyer #endif
281*c24c993fSbouyer 
282*c24c993fSbouyer     return ret;
283*c24c993fSbouyer }
284*c24c993fSbouyer 
285*c24c993fSbouyer static __inline int
HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr,pt_entry_t new_val,unsigned long flags,domid_t domid)286*c24c993fSbouyer HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr,
287*c24c993fSbouyer     pt_entry_t new_val, unsigned long flags, domid_t domid)
288*c24c993fSbouyer {
289*c24c993fSbouyer     int ret;
290*c24c993fSbouyer     unsigned long ign1, ign2, ign3, ign4, ign5;
291*c24c993fSbouyer     unsigned long pte_low, pte_hi;
292*c24c993fSbouyer 
293*c24c993fSbouyer     pte_low = new_val & 0xffffffff;
294*c24c993fSbouyer     pte_hi = new_val >> 32;
295*c24c993fSbouyer 
296*c24c993fSbouyer     _hypercall(__HYPERVISOR_update_va_mapping_otherdomain,
297*c24c993fSbouyer 	_harg("1" (page_nr), "2" (pte_low), "3" (pte_hi), "4" (flags), "5" (domid)),
298*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
299*c24c993fSbouyer 	    "=D" (ign5)));
300*c24c993fSbouyer 
301*c24c993fSbouyer     return ret;
302*c24c993fSbouyer }
303*c24c993fSbouyer #endif /* XENPV */
304*c24c993fSbouyer 
305*c24c993fSbouyer static __inline int
HYPERVISOR_xen_version(int cmd,void * arg)306*c24c993fSbouyer HYPERVISOR_xen_version(int cmd, void *arg)
307*c24c993fSbouyer {
308*c24c993fSbouyer     int ret;
309*c24c993fSbouyer     unsigned long ign1, ign2;
310*c24c993fSbouyer 
311*c24c993fSbouyer     _hypercall(__HYPERVISOR_xen_version, _harg("1" (cmd), "2" (arg)),
312*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
313*c24c993fSbouyer 
314*c24c993fSbouyer     return ret;
315*c24c993fSbouyer }
316*c24c993fSbouyer 
317*c24c993fSbouyer static __inline int
HYPERVISOR_grant_table_op(unsigned int cmd,void * uop,unsigned int count)318*c24c993fSbouyer HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
319*c24c993fSbouyer {
320*c24c993fSbouyer     int ret;
321*c24c993fSbouyer     unsigned long ign1, ign2, ign3;
322*c24c993fSbouyer 
323*c24c993fSbouyer     _hypercall(__HYPERVISOR_grant_table_op,
324*c24c993fSbouyer 	_harg("1" (cmd), "2" (uop), "3" (count)),
325*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
326*c24c993fSbouyer 
327*c24c993fSbouyer     return ret;
328*c24c993fSbouyer }
329*c24c993fSbouyer 
330*c24c993fSbouyer 
331*c24c993fSbouyer static __inline int
HYPERVISOR_vcpu_op(int cmd,int vcpuid,void * extra_args)332*c24c993fSbouyer HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
333*c24c993fSbouyer {
334*c24c993fSbouyer     long ret;
335*c24c993fSbouyer     unsigned long ign1, ign2, ign3;
336*c24c993fSbouyer 
337*c24c993fSbouyer     _hypercall(__HYPERVISOR_vcpu_op,
338*c24c993fSbouyer 	_harg("1" (cmd), "2" (vcpuid), "3" (extra_args)),
339*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
340*c24c993fSbouyer 
341*c24c993fSbouyer     return ret;
342*c24c993fSbouyer }
343*c24c993fSbouyer 
344*c24c993fSbouyer static __inline long
HYPERVISOR_yield(void)345*c24c993fSbouyer HYPERVISOR_yield(void)
346*c24c993fSbouyer {
347*c24c993fSbouyer     long ret;
348*c24c993fSbouyer     unsigned long ign1, ign2;
349*c24c993fSbouyer 
350*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_yield), "2" (0)),
351*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
352*c24c993fSbouyer 
353*c24c993fSbouyer     return ret;
354*c24c993fSbouyer }
355*c24c993fSbouyer 
356*c24c993fSbouyer static __inline long
HYPERVISOR_block(void)357*c24c993fSbouyer HYPERVISOR_block(void)
358*c24c993fSbouyer {
359*c24c993fSbouyer     long ret;
360*c24c993fSbouyer     unsigned long ign1, ign2;
361*c24c993fSbouyer 
362*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_block), "2" (0)),
363*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
364*c24c993fSbouyer 
365*c24c993fSbouyer     return ret;
366*c24c993fSbouyer }
367*c24c993fSbouyer 
368*c24c993fSbouyer static __inline long
HYPERVISOR_shutdown(void)369*c24c993fSbouyer HYPERVISOR_shutdown(void)
370*c24c993fSbouyer {
371*c24c993fSbouyer     long ret;
372*c24c993fSbouyer     unsigned long ign1, ign2;
373*c24c993fSbouyer 
374*c24c993fSbouyer #if __XEN_INTERFACE_VERSION__ >= 0x00030201
375*c24c993fSbouyer 
376*c24c993fSbouyer     struct sched_shutdown shutdown_reason = {
377*c24c993fSbouyer 	    .reason = SHUTDOWN_poweroff
378*c24c993fSbouyer     };
379*c24c993fSbouyer 
380*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op,
381*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2"  (&shutdown_reason)),
382*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
383*c24c993fSbouyer #else
384*c24c993fSbouyer      _hypercall(__HYPERVISOR_sched_op,
385*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_poweroff)),
386*c24c993fSbouyer  	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
387*c24c993fSbouyer 
388*c24c993fSbouyer #endif
389*c24c993fSbouyer 
390*c24c993fSbouyer     return ret;
391*c24c993fSbouyer }
392*c24c993fSbouyer 
393*c24c993fSbouyer static __inline long
HYPERVISOR_crash(void)394*c24c993fSbouyer HYPERVISOR_crash(void)
395*c24c993fSbouyer {
396*c24c993fSbouyer     long ret;
397*c24c993fSbouyer     unsigned long ign1, ign2;
398*c24c993fSbouyer 
399*c24c993fSbouyer #if __XEN_INTERFACE_VERSION__ >= 0x00030201
400*c24c993fSbouyer 
401*c24c993fSbouyer     struct sched_shutdown shutdown_reason = {
402*c24c993fSbouyer 	    .reason = SHUTDOWN_crash
403*c24c993fSbouyer     };
404*c24c993fSbouyer 
405*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op,
406*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2"  (&shutdown_reason)),
407*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
408*c24c993fSbouyer #else
409*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op,
410*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_crash)),
411*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
412*c24c993fSbouyer #endif
413*c24c993fSbouyer 
414*c24c993fSbouyer     return ret;
415*c24c993fSbouyer }
416*c24c993fSbouyer 
417*c24c993fSbouyer static __inline long
HYPERVISOR_reboot(void)418*c24c993fSbouyer HYPERVISOR_reboot(void)
419*c24c993fSbouyer {
420*c24c993fSbouyer     long ret;
421*c24c993fSbouyer     unsigned long ign1, ign2;
422*c24c993fSbouyer 
423*c24c993fSbouyer #if __XEN_INTERFACE_VERSION__ >= 0x00030201
424*c24c993fSbouyer 
425*c24c993fSbouyer     struct sched_shutdown shutdown_reason = {
426*c24c993fSbouyer 	    .reason = SHUTDOWN_reboot
427*c24c993fSbouyer     };
428*c24c993fSbouyer 
429*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op,
430*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2"  (&shutdown_reason)),
431*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
432*c24c993fSbouyer #else
433*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op,
434*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_reboot)),
435*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
436*c24c993fSbouyer #endif
437*c24c993fSbouyer 
438*c24c993fSbouyer     return ret;
439*c24c993fSbouyer }
440*c24c993fSbouyer 
441*c24c993fSbouyer static __inline long
HYPERVISOR_suspend(unsigned long srec)442*c24c993fSbouyer HYPERVISOR_suspend(unsigned long srec)
443*c24c993fSbouyer {
444*c24c993fSbouyer     long ret;
445*c24c993fSbouyer     unsigned long ign1, ign2, ign3;
446*c24c993fSbouyer 
447*c24c993fSbouyer #if __XEN_INTERFACE_VERSION__ >= 0x00030201
448*c24c993fSbouyer 
449*c24c993fSbouyer     struct sched_shutdown shutdown_reason = {
450*c24c993fSbouyer 	    .reason = SHUTDOWN_suspend
451*c24c993fSbouyer     };
452*c24c993fSbouyer 
453*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op,
454*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2"  (&shutdown_reason), "3" (srec)),
455*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
456*c24c993fSbouyer #else
457*c24c993fSbouyer     _hypercall(__HYPERVISOR_sched_op,
458*c24c993fSbouyer 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_suspend), "3" (srec)),
459*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
460*c24c993fSbouyer #endif
461*c24c993fSbouyer 
462*c24c993fSbouyer     return ret;
463*c24c993fSbouyer }
464*c24c993fSbouyer 
465*c24c993fSbouyer static __inline long
HYPERVISOR_set_timer_op(uint64_t timeout)466*c24c993fSbouyer HYPERVISOR_set_timer_op(uint64_t timeout)
467*c24c993fSbouyer {
468*c24c993fSbouyer     long ret;
469*c24c993fSbouyer     unsigned long timeout_hi = (unsigned long)(timeout>>32);
470*c24c993fSbouyer     unsigned long timeout_lo = (unsigned long)timeout;
471*c24c993fSbouyer     unsigned long ign1, ign2;
472*c24c993fSbouyer 
473*c24c993fSbouyer     _hypercall(__HYPERVISOR_set_timer_op,
474*c24c993fSbouyer 	 _harg("1" (timeout_lo), "2" (timeout_hi)),
475*c24c993fSbouyer 	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
476*c24c993fSbouyer 
477*c24c993fSbouyer     return ret;
478*c24c993fSbouyer }
479*c24c993fSbouyer 
480*c24c993fSbouyer static __inline int
HYPERVISOR_platform_op(struct xen_platform_op * platform_op)481*c24c993fSbouyer HYPERVISOR_platform_op(struct xen_platform_op *platform_op)
482*c24c993fSbouyer {
483*c24c993fSbouyer     int ret;
484*c24c993fSbouyer     unsigned long ign1;
485*c24c993fSbouyer 
486*c24c993fSbouyer     platform_op->interface_version = XENPF_INTERFACE_VERSION;
487*c24c993fSbouyer     _hypercall(__HYPERVISOR_platform_op, _harg("1" (platform_op)),
488*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1)));
489*c24c993fSbouyer 
490*c24c993fSbouyer     return ret;
491*c24c993fSbouyer }
492*c24c993fSbouyer 
493*c24c993fSbouyer static __inline int
HYPERVISOR_multicall(void * call_list,int nr_calls)494*c24c993fSbouyer HYPERVISOR_multicall(void *call_list, int nr_calls)
495*c24c993fSbouyer {
496*c24c993fSbouyer     int ret;
497*c24c993fSbouyer     unsigned long ign1, ign2;
498*c24c993fSbouyer 
499*c24c993fSbouyer     _hypercall(__HYPERVISOR_multicall,
500*c24c993fSbouyer 	 _harg("1" (call_list), "2" (nr_calls)),
501*c24c993fSbouyer 	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
502*c24c993fSbouyer 
503*c24c993fSbouyer     return ret;
504*c24c993fSbouyer }
505*c24c993fSbouyer 
506*c24c993fSbouyer 
507*c24c993fSbouyer static __inline int
HYPERVISOR_event_channel_op(evtchn_op_t * op)508*c24c993fSbouyer HYPERVISOR_event_channel_op(evtchn_op_t *op)
509*c24c993fSbouyer {
510*c24c993fSbouyer     int ret;
511*c24c993fSbouyer     unsigned long ign1;
512*c24c993fSbouyer 
513*c24c993fSbouyer #if __XEN_INTERFACE_VERSION__ < 0x00030202
514*c24c993fSbouyer     _hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op)),
515*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1)));
516*c24c993fSbouyer #else
517*c24c993fSbouyer     unsigned long ign2;
518*c24c993fSbouyer 
519*c24c993fSbouyer     _hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op->cmd), "2" (&op->u)),
520*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
521*c24c993fSbouyer #endif
522*c24c993fSbouyer     return ret;
523*c24c993fSbouyer }
524*c24c993fSbouyer 
525*c24c993fSbouyer static __inline int
HYPERVISOR_console_io(int cmd,int count,char * str)526*c24c993fSbouyer HYPERVISOR_console_io(int cmd, int count, char *str)
527*c24c993fSbouyer {
528*c24c993fSbouyer     int ret;
529*c24c993fSbouyer     unsigned long ign1, ign2, ign3;
530*c24c993fSbouyer 
531*c24c993fSbouyer     _hypercall(__HYPERVISOR_console_io,
532*c24c993fSbouyer 	_harg("1" (cmd), "2" (count), "3" (str)),
533*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
534*c24c993fSbouyer 
535*c24c993fSbouyer     return ret;
536*c24c993fSbouyer }
537*c24c993fSbouyer 
538*c24c993fSbouyer static __inline int
HYPERVISOR_physdev_op(int cmd,void * physdev_op)539*c24c993fSbouyer HYPERVISOR_physdev_op(int cmd, void *physdev_op)
540*c24c993fSbouyer {
541*c24c993fSbouyer     int ret;
542*c24c993fSbouyer     unsigned long ign1, ign2;
543*c24c993fSbouyer 
544*c24c993fSbouyer     _hypercall(__HYPERVISOR_physdev_op, _harg("1" (cmd), "2" (physdev_op)),
545*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
546*c24c993fSbouyer 
547*c24c993fSbouyer     return ret;
548*c24c993fSbouyer }
549*c24c993fSbouyer 
550*c24c993fSbouyer static __inline int
HYPERVISOR_vm_assist(unsigned int cmd,unsigned int type)551*c24c993fSbouyer HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type)
552*c24c993fSbouyer {
553*c24c993fSbouyer     int ret;
554*c24c993fSbouyer     unsigned long ign1, ign2;
555*c24c993fSbouyer 
556*c24c993fSbouyer     _hypercall(__HYPERVISOR_vm_assist, _harg("1" (cmd), "2" (type)),
557*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
558*c24c993fSbouyer 
559*c24c993fSbouyer     return ret;
560*c24c993fSbouyer }
561*c24c993fSbouyer 
562*c24c993fSbouyer static __inline int
HYPERVISOR_sysctl(void * sysctl)563*c24c993fSbouyer HYPERVISOR_sysctl(void *sysctl)
564*c24c993fSbouyer {
565*c24c993fSbouyer     int ret;
566*c24c993fSbouyer     unsigned long ign1;
567*c24c993fSbouyer 
568*c24c993fSbouyer     _hypercall(__HYPERVISOR_sysctl, _harg("1" (sysctl)),
569*c24c993fSbouyer 	_harg("=a" (ret), "=b" (ign1)));
570*c24c993fSbouyer 
571*c24c993fSbouyer     return ret;
572*c24c993fSbouyer }
573*c24c993fSbouyer #endif /* _XENI386_HYPERVISOR_H_ */
574