1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Provides basic C wrappers around hypervisor invocation.
*
* i386: eax = vector: ebx, ecx, edx, esi, edi = args 1-5
* eax = return value
* (argument registers may be clobbered on return)
*
* amd64:rax = vector: rdi, rsi, rdx, r10, r8, r9 = args 1-6
* rax = return value
* (arguments registers not clobbered on return; rcx, r11 are)
*/
#include <sys/types.h>
#ifndef __xpv
#include <sys/xpv_support.h>
#else
#include <sys/xpv_user.h>
#endif
#include <sys/hypervisor.h>
#include <xen/public/sched.h>
#include <sys/debug.h>
#include <sys/archsystm.h>
long
HYPERVISOR_set_trap_table(trap_info_t *table)
{
return (__hypercall1(__HYPERVISOR_set_trap_table, (ulong_t)table));
}
int
HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count,
domid_t domain_id)
{
return (__hypercall4_int(__HYPERVISOR_mmu_update,
(ulong_t)req, (long)count, (ulong_t)success_count,
(ulong_t)domain_id));
}
long
HYPERVISOR_set_gdt(ulong_t *frame_list, int entries)
{
return (__hypercall2(
__HYPERVISOR_set_gdt, (ulong_t)frame_list, (long)entries));
}
/*
* XXPV Seems like "sp" would be a better name for both amd64 and i386?
* For now stay consistent with xen project source.
*/
long
HYPERVISOR_stack_switch(ulong_t ss, ulong_t esp)
{
return (__hypercall2(__HYPERVISOR_stack_switch, ss, esp));
}
#if defined(__amd64)
long
HYPERVISOR_set_callbacks(ulong_t event_address, ulong_t failsafe_address,
ulong_t syscall_address)
{
return (__hypercall3(__HYPERVISOR_set_callbacks,
event_address, failsafe_address, syscall_address));
}
#elif defined(__i386)
long
HYPERVISOR_set_callbacks(
ulong_t event_selector, ulong_t event_address,
ulong_t failsafe_selector, ulong_t failsafe_address)
{
return (__hypercall4(__HYPERVISOR_set_callbacks,
event_selector, event_address,
failsafe_selector, failsafe_address));
}
#endif /* __amd64 */
long
HYPERVISOR_fpu_taskswitch(int set)
{
return (__hypercall1(__HYPERVISOR_fpu_taskswitch, (long)set));
}
/* *** __HYPERVISOR_sched_op_compat *** OBSOLETED */
long
HYPERVISOR_platform_op(xen_platform_op_t *platform_op)
{
return (__hypercall1(__HYPERVISOR_platform_op, (ulong_t)platform_op));
}
/* *** __HYPERVISOR_set_debugreg *** NOT IMPLEMENTED */
/* *** __HYPERVISOR_get_debugreg *** NOT IMPLEMENTED */
long
HYPERVISOR_update_descriptor(maddr_t ma, uint64_t desc)
{
#if defined(__amd64)
return (__hypercall2(__HYPERVISOR_update_descriptor, ma, desc));
#elif defined(__i386)
return (__hypercall4(__HYPERVISOR_update_descriptor,
(ulong_t)ma, (ulong_t)(ma >>32),
(ulong_t)desc, (ulong_t)(desc >> 32)));
#endif
}
long
HYPERVISOR_memory_op(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_memory_op, (long)cmd,
(ulong_t)arg));
}
long
HYPERVISOR_multicall(void *call_list, uint_t nr_calls)
{
return (__hypercall2(__HYPERVISOR_multicall,
(ulong_t)call_list, (ulong_t)nr_calls));
}
int
HYPERVISOR_update_va_mapping(ulong_t va, uint64_t new_pte, ulong_t flags)
{
#if !defined(_BOOT)
if (IN_XPV_PANIC())
return (0);
#endif
#if defined(__amd64)
return (__hypercall3_int(__HYPERVISOR_update_va_mapping, va,
new_pte, flags));
#elif defined(__i386)
return (__hypercall4_int(__HYPERVISOR_update_va_mapping, va,
(ulong_t)new_pte, (ulong_t)(new_pte >> 32), flags));
#endif /* __i386 */
}
/*
* Note: this timeout must be the Xen system time not hrtime (see
* xpv_timestamp.c).
*/
long
HYPERVISOR_set_timer_op(uint64_t timeout)
{
#if defined(__amd64)
return (__hypercall1(__HYPERVISOR_set_timer_op, timeout));
#elif defined(__i386)
uint32_t timeout_hi = (uint32_t)(timeout >> 32);
uint32_t timeout_lo = (uint32_t)timeout;
return (__hypercall2(__HYPERVISOR_set_timer_op,
(ulong_t)timeout_lo, (ulong_t)timeout_hi));
#endif /* __i386 */
}
/* *** __HYPERVISOR_event_channel_op_compat *** OBSOLETED */
long
HYPERVISOR_xen_version(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_xen_version, (long)cmd,
(ulong_t)arg));
}
long
HYPERVISOR_console_io(int cmd, int count, char *str)
{
return (__hypercall3(__HYPERVISOR_console_io, (long)cmd, (long)count,
(ulong_t)str));
}
/* *** __HYPERVISOR_physdev_op_compat *** OBSOLETED */
/*
* ****
* NOTE: this hypercall should not be called directly for a
* GNTTABOP_map_grant_ref. Instead xen_map_gref() should be called.
* ****
*/
long
HYPERVISOR_grant_table_op(uint_t cmd, void *uop, uint_t count)
{
int ret_val;
ret_val = __hypercall3(__HYPERVISOR_grant_table_op,
(long)cmd, (ulong_t)uop, (ulong_t)count);
return (ret_val);
}
long
HYPERVISOR_vm_assist(uint_t cmd, uint_t type)
{
return (__hypercall2(__HYPERVISOR_vm_assist,
(ulong_t)cmd, (ulong_t)type));
}
int
HYPERVISOR_update_va_mapping_otherdomain(ulong_t va,
uint64_t new_pte, ulong_t flags, domid_t domain_id)
{
#if defined(__amd64)
return (__hypercall4_int(__HYPERVISOR_update_va_mapping_otherdomain,
va, new_pte, flags, (ulong_t)domain_id));
#elif defined(__i386)
return (__hypercall5_int(__HYPERVISOR_update_va_mapping_otherdomain,
va, (ulong_t)new_pte, (ulong_t)(new_pte >> 32), flags,
(ulong_t)domain_id));
#endif /* __i386 */
}
/*
* *** __HYPERVISOR_iret ***
* see HYPERVISOR_IRET() macro in i86xpv/sys/machprivregs.h
*/
long
HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
{
return (__hypercall3(__HYPERVISOR_vcpu_op, (long)cmd, (long)vcpuid,
(ulong_t)extra_args));
}
#if defined(__amd64)
long
HYPERVISOR_set_segment_base(int reg, ulong_t value)
{
return (__hypercall2(__HYPERVISOR_set_segment_base, (long)reg, value));
}
#endif /* __amd64 */
int
HYPERVISOR_mmuext_op(struct mmuext_op *req, int count, uint_t *success_count,
domid_t domain_id)
{
return (__hypercall4_int(__HYPERVISOR_mmuext_op,
(ulong_t)req, (long)count, (ulong_t)success_count,
(ulong_t)domain_id));
}
long
HYPERVISOR_nmi_op(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_nmi_op, (long)cmd, (ulong_t)arg));
}
long
HYPERVISOR_sched_op(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_sched_op,
(ulong_t)cmd, (ulong_t)arg));
}
long
HYPERVISOR_callback_op(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_callback_op,
(ulong_t)cmd, (ulong_t)arg));
}
/* *** __HYPERVISOR_xenoprof_op *** NOT IMPLEMENTED */
long
HYPERVISOR_event_channel_op(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_event_channel_op, (long)cmd,
(ulong_t)arg));
}
long
HYPERVISOR_physdev_op(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_physdev_op, (long)cmd,
(ulong_t)arg));
}
long
HYPERVISOR_hvm_op(int cmd, void *arg)
{
return (__hypercall2(__HYPERVISOR_hvm_op, (long)cmd, (ulong_t)arg));
}
#if defined(__xpv)
long
HYPERVISOR_xsm_op(struct xen_acmctl *arg)
{
return (__hypercall1(__HYPERVISOR_xsm_op, (ulong_t)arg));
}
long
HYPERVISOR_sysctl(xen_sysctl_t *sysctl)
{
return (__hypercall1(__HYPERVISOR_sysctl, (ulong_t)sysctl));
}
long
HYPERVISOR_domctl(xen_domctl_t *domctl)
{
return (__hypercall1(__HYPERVISOR_domctl, (ulong_t)domctl));
}
#endif /* __xpv */
/* *** __HYPERVISOR_kexec_op *** NOT IMPLEMENTED */
/*
*
* HYPERCALL HELPER ROUTINES
* These don't have there own unique hypercalls.
*
*/
long
HYPERVISOR_yield(void)
{
return (HYPERVISOR_sched_op(SCHEDOP_yield, NULL));
}
long
HYPERVISOR_block(void)
{
return (HYPERVISOR_sched_op(SCHEDOP_block, NULL));
}
long
HYPERVISOR_shutdown(uint_t reason)
{
struct sched_shutdown sched_shutdown;
sched_shutdown.reason = reason;
return (HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown));
}
/*
* Poll one or more event-channel ports, and return when pending.
* An optional timeout (in nanoseconds, absolute time since boot) may be
* specified. Note: this timeout must be the Xen system time not hrtime (see
* xpv_timestamp.c).
*/
long
HYPERVISOR_poll(evtchn_port_t *ports, uint_t nr_ports, uint64_t timeout)
{
struct sched_poll sched_poll;
/*LINTED: constant in conditional context*/
set_xen_guest_handle(sched_poll.ports, ports);
sched_poll.nr_ports = nr_ports;
sched_poll.timeout = timeout;
return (HYPERVISOR_sched_op(SCHEDOP_poll, &sched_poll));
}
long
HYPERVISOR_suspend(ulong_t start_info_mfn)
{
struct sched_shutdown sched_shutdown;
sched_shutdown.reason = SHUTDOWN_suspend;
return (__hypercall3(__HYPERVISOR_sched_op, SCHEDOP_shutdown,
(ulong_t)&sched_shutdown, start_info_mfn));
}
long
HYPERVISOR_mca(uint32_t cmd, xen_mc_t *xmcp)
{
long rv;
switch (cmd) {
case XEN_MC_fetch:
case XEN_MC_physcpuinfo:
case XEN_MC_msrinject:
case XEN_MC_mceinject:
break;
case XEN_MC_notifydomain:
return (ENOTSUP);
default:
return (EINVAL);
}
xmcp->interface_version = XEN_MCA_INTERFACE_VERSION;
xmcp->cmd = cmd;
rv = __hypercall1(__HYPERVISOR_mca, (ulong_t)xmcp);
return (rv);
}
|