4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Provides basic C wrappers around hypervisor invocation.
30 * i386: eax = vector: ebx, ecx, edx, esi, edi = args 1-5
32 * (argument registers may be clobbered on return)
34 * amd64:rax = vector: rdi, rsi, rdx, r10, r8, r9 = args 1-6
36 * (arguments registers not clobbered on return; rcx, r11 are)
39 #include <sys/types.h>
41 #include <sys/xpv_support.h>
43 #include <sys/xpv_user.h>
46 #include <sys/hypervisor.h>
47 #include <xen/public/sched.h>
48 #include <sys/debug.h>
49 #include <sys/archsystm.h>
52 HYPERVISOR_set_trap_table(trap_info_t
*table
)
54 return (__hypercall1(__HYPERVISOR_set_trap_table
, (ulong_t
)table
));
58 HYPERVISOR_mmu_update(mmu_update_t
*req
, int count
, int *success_count
,
61 return (__hypercall4_int(__HYPERVISOR_mmu_update
,
62 (ulong_t
)req
, (long)count
, (ulong_t
)success_count
,
67 HYPERVISOR_set_gdt(ulong_t
*frame_list
, int entries
)
70 __HYPERVISOR_set_gdt
, (ulong_t
)frame_list
, (long)entries
));
74 * XXPV Seems like "sp" would be a better name for both amd64 and i386?
75 * For now stay consistent with xen project source.
78 HYPERVISOR_stack_switch(ulong_t ss
, ulong_t esp
)
80 return (__hypercall2(__HYPERVISOR_stack_switch
, ss
, esp
));
86 HYPERVISOR_set_callbacks(ulong_t event_address
, ulong_t failsafe_address
,
87 ulong_t syscall_address
)
89 return (__hypercall3(__HYPERVISOR_set_callbacks
,
90 event_address
, failsafe_address
, syscall_address
));
96 HYPERVISOR_set_callbacks(
97 ulong_t event_selector
, ulong_t event_address
,
98 ulong_t failsafe_selector
, ulong_t failsafe_address
)
100 return (__hypercall4(__HYPERVISOR_set_callbacks
,
101 event_selector
, event_address
,
102 failsafe_selector
, failsafe_address
));
108 HYPERVISOR_fpu_taskswitch(int set
)
110 return (__hypercall1(__HYPERVISOR_fpu_taskswitch
, (long)set
));
113 /* *** __HYPERVISOR_sched_op_compat *** OBSOLETED */
116 HYPERVISOR_platform_op(xen_platform_op_t
*platform_op
)
118 return (__hypercall1(__HYPERVISOR_platform_op
, (ulong_t
)platform_op
));
121 /* *** __HYPERVISOR_set_debugreg *** NOT IMPLEMENTED */
123 /* *** __HYPERVISOR_get_debugreg *** NOT IMPLEMENTED */
126 HYPERVISOR_update_descriptor(maddr_t ma
, uint64_t desc
)
130 return (__hypercall2(__HYPERVISOR_update_descriptor
, ma
, desc
));
132 #elif defined(__i386)
134 return (__hypercall4(__HYPERVISOR_update_descriptor
,
135 (ulong_t
)ma
, (ulong_t
)(ma
>>32),
136 (ulong_t
)desc
, (ulong_t
)(desc
>> 32)));
142 HYPERVISOR_memory_op(int cmd
, void *arg
)
144 return (__hypercall2(__HYPERVISOR_memory_op
, (long)cmd
,
149 HYPERVISOR_multicall(void *call_list
, uint_t nr_calls
)
151 return (__hypercall2(__HYPERVISOR_multicall
,
152 (ulong_t
)call_list
, (ulong_t
)nr_calls
));
156 HYPERVISOR_update_va_mapping(ulong_t va
, uint64_t new_pte
, ulong_t flags
)
164 return (__hypercall3_int(__HYPERVISOR_update_va_mapping
, va
,
167 #elif defined(__i386)
169 return (__hypercall4_int(__HYPERVISOR_update_va_mapping
, va
,
170 (ulong_t
)new_pte
, (ulong_t
)(new_pte
>> 32), flags
));
176 * Note: this timeout must be the Xen system time not hrtime (see
180 HYPERVISOR_set_timer_op(uint64_t timeout
)
184 return (__hypercall1(__HYPERVISOR_set_timer_op
, timeout
));
186 #elif defined(__i386)
188 uint32_t timeout_hi
= (uint32_t)(timeout
>> 32);
189 uint32_t timeout_lo
= (uint32_t)timeout
;
190 return (__hypercall2(__HYPERVISOR_set_timer_op
,
191 (ulong_t
)timeout_lo
, (ulong_t
)timeout_hi
));
196 /* *** __HYPERVISOR_event_channel_op_compat *** OBSOLETED */
199 HYPERVISOR_xen_version(int cmd
, void *arg
)
201 return (__hypercall2(__HYPERVISOR_xen_version
, (long)cmd
,
206 HYPERVISOR_console_io(int cmd
, int count
, char *str
)
208 return (__hypercall3(__HYPERVISOR_console_io
, (long)cmd
, (long)count
,
212 /* *** __HYPERVISOR_physdev_op_compat *** OBSOLETED */
216 * NOTE: this hypercall should not be called directly for a
217 * GNTTABOP_map_grant_ref. Instead xen_map_gref() should be called.
221 HYPERVISOR_grant_table_op(uint_t cmd
, void *uop
, uint_t count
)
224 ret_val
= __hypercall3(__HYPERVISOR_grant_table_op
,
225 (long)cmd
, (ulong_t
)uop
, (ulong_t
)count
);
230 HYPERVISOR_vm_assist(uint_t cmd
, uint_t type
)
232 return (__hypercall2(__HYPERVISOR_vm_assist
,
233 (ulong_t
)cmd
, (ulong_t
)type
));
237 HYPERVISOR_update_va_mapping_otherdomain(ulong_t va
,
238 uint64_t new_pte
, ulong_t flags
, domid_t domain_id
)
242 return (__hypercall4_int(__HYPERVISOR_update_va_mapping_otherdomain
,
243 va
, new_pte
, flags
, (ulong_t
)domain_id
));
245 #elif defined(__i386)
247 return (__hypercall5_int(__HYPERVISOR_update_va_mapping_otherdomain
,
248 va
, (ulong_t
)new_pte
, (ulong_t
)(new_pte
>> 32), flags
,
249 (ulong_t
)domain_id
));
255 * *** __HYPERVISOR_iret ***
256 * see HYPERVISOR_IRET() macro in i86xpv/sys/machprivregs.h
260 HYPERVISOR_vcpu_op(int cmd
, int vcpuid
, void *extra_args
)
262 return (__hypercall3(__HYPERVISOR_vcpu_op
, (long)cmd
, (long)vcpuid
,
263 (ulong_t
)extra_args
));
269 HYPERVISOR_set_segment_base(int reg
, ulong_t value
)
271 return (__hypercall2(__HYPERVISOR_set_segment_base
, (long)reg
, value
));
277 HYPERVISOR_mmuext_op(struct mmuext_op
*req
, int count
, uint_t
*success_count
,
280 return (__hypercall4_int(__HYPERVISOR_mmuext_op
,
281 (ulong_t
)req
, (long)count
, (ulong_t
)success_count
,
282 (ulong_t
)domain_id
));
286 HYPERVISOR_nmi_op(int cmd
, void *arg
)
288 return (__hypercall2(__HYPERVISOR_nmi_op
, (long)cmd
, (ulong_t
)arg
));
292 HYPERVISOR_sched_op(int cmd
, void *arg
)
294 return (__hypercall2(__HYPERVISOR_sched_op
,
295 (ulong_t
)cmd
, (ulong_t
)arg
));
299 HYPERVISOR_callback_op(int cmd
, void *arg
)
301 return (__hypercall2(__HYPERVISOR_callback_op
,
302 (ulong_t
)cmd
, (ulong_t
)arg
));
305 /* *** __HYPERVISOR_xenoprof_op *** NOT IMPLEMENTED */
308 HYPERVISOR_event_channel_op(int cmd
, void *arg
)
310 return (__hypercall2(__HYPERVISOR_event_channel_op
, (long)cmd
,
315 HYPERVISOR_physdev_op(int cmd
, void *arg
)
317 return (__hypercall2(__HYPERVISOR_physdev_op
, (long)cmd
,
322 HYPERVISOR_hvm_op(int cmd
, void *arg
)
324 return (__hypercall2(__HYPERVISOR_hvm_op
, (long)cmd
, (ulong_t
)arg
));
329 HYPERVISOR_xsm_op(struct xen_acmctl
*arg
)
331 return (__hypercall1(__HYPERVISOR_xsm_op
, (ulong_t
)arg
));
335 HYPERVISOR_sysctl(xen_sysctl_t
*sysctl
)
337 return (__hypercall1(__HYPERVISOR_sysctl
, (ulong_t
)sysctl
));
341 HYPERVISOR_domctl(xen_domctl_t
*domctl
)
343 return (__hypercall1(__HYPERVISOR_domctl
, (ulong_t
)domctl
));
347 /* *** __HYPERVISOR_kexec_op *** NOT IMPLEMENTED */
351 * HYPERCALL HELPER ROUTINES
352 * These don't have there own unique hypercalls.
357 HYPERVISOR_yield(void)
359 return (HYPERVISOR_sched_op(SCHEDOP_yield
, NULL
));
363 HYPERVISOR_block(void)
365 return (HYPERVISOR_sched_op(SCHEDOP_block
, NULL
));
369 HYPERVISOR_shutdown(uint_t reason
)
371 struct sched_shutdown sched_shutdown
;
373 sched_shutdown
.reason
= reason
;
375 return (HYPERVISOR_sched_op(SCHEDOP_shutdown
, &sched_shutdown
));
379 * Poll one or more event-channel ports, and return when pending.
380 * An optional timeout (in nanoseconds, absolute time since boot) may be
381 * specified. Note: this timeout must be the Xen system time not hrtime (see
385 HYPERVISOR_poll(evtchn_port_t
*ports
, uint_t nr_ports
, uint64_t timeout
)
387 struct sched_poll sched_poll
;
389 /*LINTED: constant in conditional context*/
390 set_xen_guest_handle(sched_poll
.ports
, ports
);
391 sched_poll
.nr_ports
= nr_ports
;
392 sched_poll
.timeout
= timeout
;
394 return (HYPERVISOR_sched_op(SCHEDOP_poll
, &sched_poll
));
398 HYPERVISOR_suspend(ulong_t start_info_mfn
)
400 struct sched_shutdown sched_shutdown
;
402 sched_shutdown
.reason
= SHUTDOWN_suspend
;
404 return (__hypercall3(__HYPERVISOR_sched_op
, SCHEDOP_shutdown
,
405 (ulong_t
)&sched_shutdown
, start_info_mfn
));
409 HYPERVISOR_mca(uint32_t cmd
, xen_mc_t
*xmcp
)
415 case XEN_MC_physcpuinfo
:
416 case XEN_MC_msrinject
:
417 case XEN_MC_mceinject
:
420 case XEN_MC_notifydomain
:
427 xmcp
->interface_version
= XEN_MCA_INTERFACE_VERSION
;
430 rv
= __hypercall1(__HYPERVISOR_mca
, (ulong_t
)xmcp
);