8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / uts / common / xen / os / hypercall.c
blob308c7246db511478415caae835a03e8290a40b64
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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
31 * eax = return value
32 * (argument registers may be clobbered on return)
34 * amd64:rax = vector: rdi, rsi, rdx, r10, r8, r9 = args 1-6
35 * rax = return value
36 * (arguments registers not clobbered on return; rcx, r11 are)
39 #include <sys/types.h>
40 #ifndef __xpv
41 #include <sys/xpv_support.h>
42 #else
43 #include <sys/xpv_user.h>
44 #endif
46 #include <sys/hypervisor.h>
47 #include <xen/public/sched.h>
48 #include <sys/debug.h>
49 #include <sys/archsystm.h>
51 long
52 HYPERVISOR_set_trap_table(trap_info_t *table)
54 return (__hypercall1(__HYPERVISOR_set_trap_table, (ulong_t)table));
57 int
58 HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count,
59 domid_t domain_id)
61 return (__hypercall4_int(__HYPERVISOR_mmu_update,
62 (ulong_t)req, (long)count, (ulong_t)success_count,
63 (ulong_t)domain_id));
66 long
67 HYPERVISOR_set_gdt(ulong_t *frame_list, int entries)
69 return (__hypercall2(
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.
77 long
78 HYPERVISOR_stack_switch(ulong_t ss, ulong_t esp)
80 return (__hypercall2(__HYPERVISOR_stack_switch, ss, esp));
83 #if defined(__amd64)
85 long
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));
93 #elif defined(__i386)
95 long
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));
105 #endif /* __amd64 */
107 long
108 HYPERVISOR_fpu_taskswitch(int set)
110 return (__hypercall1(__HYPERVISOR_fpu_taskswitch, (long)set));
113 /* *** __HYPERVISOR_sched_op_compat *** OBSOLETED */
115 long
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 */
125 long
126 HYPERVISOR_update_descriptor(maddr_t ma, uint64_t desc)
128 #if defined(__amd64)
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)));
138 #endif
141 long
142 HYPERVISOR_memory_op(int cmd, void *arg)
144 return (__hypercall2(__HYPERVISOR_memory_op, (long)cmd,
145 (ulong_t)arg));
148 long
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)
158 #if !defined(_BOOT)
159 if (IN_XPV_PANIC())
160 return (0);
161 #endif
162 #if defined(__amd64)
164 return (__hypercall3_int(__HYPERVISOR_update_va_mapping, va,
165 new_pte, flags));
167 #elif defined(__i386)
169 return (__hypercall4_int(__HYPERVISOR_update_va_mapping, va,
170 (ulong_t)new_pte, (ulong_t)(new_pte >> 32), flags));
172 #endif /* __i386 */
176 * Note: this timeout must be the Xen system time not hrtime (see
177 * xpv_timestamp.c).
179 long
180 HYPERVISOR_set_timer_op(uint64_t timeout)
182 #if defined(__amd64)
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));
193 #endif /* __i386 */
196 /* *** __HYPERVISOR_event_channel_op_compat *** OBSOLETED */
198 long
199 HYPERVISOR_xen_version(int cmd, void *arg)
201 return (__hypercall2(__HYPERVISOR_xen_version, (long)cmd,
202 (ulong_t)arg));
205 long
206 HYPERVISOR_console_io(int cmd, int count, char *str)
208 return (__hypercall3(__HYPERVISOR_console_io, (long)cmd, (long)count,
209 (ulong_t)str));
212 /* *** __HYPERVISOR_physdev_op_compat *** OBSOLETED */
215 * ****
216 * NOTE: this hypercall should not be called directly for a
217 * GNTTABOP_map_grant_ref. Instead xen_map_gref() should be called.
218 * ****
220 long
221 HYPERVISOR_grant_table_op(uint_t cmd, void *uop, uint_t count)
223 int ret_val;
224 ret_val = __hypercall3(__HYPERVISOR_grant_table_op,
225 (long)cmd, (ulong_t)uop, (ulong_t)count);
226 return (ret_val);
229 long
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)
240 #if defined(__amd64)
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));
251 #endif /* __i386 */
255 * *** __HYPERVISOR_iret ***
256 * see HYPERVISOR_IRET() macro in i86xpv/sys/machprivregs.h
259 long
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));
266 #if defined(__amd64)
268 long
269 HYPERVISOR_set_segment_base(int reg, ulong_t value)
271 return (__hypercall2(__HYPERVISOR_set_segment_base, (long)reg, value));
274 #endif /* __amd64 */
277 HYPERVISOR_mmuext_op(struct mmuext_op *req, int count, uint_t *success_count,
278 domid_t domain_id)
280 return (__hypercall4_int(__HYPERVISOR_mmuext_op,
281 (ulong_t)req, (long)count, (ulong_t)success_count,
282 (ulong_t)domain_id));
285 long
286 HYPERVISOR_nmi_op(int cmd, void *arg)
288 return (__hypercall2(__HYPERVISOR_nmi_op, (long)cmd, (ulong_t)arg));
291 long
292 HYPERVISOR_sched_op(int cmd, void *arg)
294 return (__hypercall2(__HYPERVISOR_sched_op,
295 (ulong_t)cmd, (ulong_t)arg));
298 long
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 */
307 long
308 HYPERVISOR_event_channel_op(int cmd, void *arg)
310 return (__hypercall2(__HYPERVISOR_event_channel_op, (long)cmd,
311 (ulong_t)arg));
314 long
315 HYPERVISOR_physdev_op(int cmd, void *arg)
317 return (__hypercall2(__HYPERVISOR_physdev_op, (long)cmd,
318 (ulong_t)arg));
321 long
322 HYPERVISOR_hvm_op(int cmd, void *arg)
324 return (__hypercall2(__HYPERVISOR_hvm_op, (long)cmd, (ulong_t)arg));
327 #if defined(__xpv)
328 long
329 HYPERVISOR_xsm_op(struct xen_acmctl *arg)
331 return (__hypercall1(__HYPERVISOR_xsm_op, (ulong_t)arg));
334 long
335 HYPERVISOR_sysctl(xen_sysctl_t *sysctl)
337 return (__hypercall1(__HYPERVISOR_sysctl, (ulong_t)sysctl));
340 long
341 HYPERVISOR_domctl(xen_domctl_t *domctl)
343 return (__hypercall1(__HYPERVISOR_domctl, (ulong_t)domctl));
345 #endif /* __xpv */
347 /* *** __HYPERVISOR_kexec_op *** NOT IMPLEMENTED */
351 * HYPERCALL HELPER ROUTINES
352 * These don't have there own unique hypercalls.
356 long
357 HYPERVISOR_yield(void)
359 return (HYPERVISOR_sched_op(SCHEDOP_yield, NULL));
362 long
363 HYPERVISOR_block(void)
365 return (HYPERVISOR_sched_op(SCHEDOP_block, NULL));
368 long
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
382 * xpv_timestamp.c).
384 long
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));
397 long
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));
408 long
409 HYPERVISOR_mca(uint32_t cmd, xen_mc_t *xmcp)
411 long rv;
413 switch (cmd) {
414 case XEN_MC_fetch:
415 case XEN_MC_physcpuinfo:
416 case XEN_MC_msrinject:
417 case XEN_MC_mceinject:
418 break;
420 case XEN_MC_notifydomain:
421 return (ENOTSUP);
423 default:
424 return (EINVAL);
427 xmcp->interface_version = XEN_MCA_INTERFACE_VERSION;
428 xmcp->cmd = cmd;
430 rv = __hypercall1(__HYPERVISOR_mca, (ulong_t)xmcp);
432 return (rv);