Xen Test Framework
hypercall.h
Go to the documentation of this file.
1#ifndef XTF_HYPERCALL_H
2#define XTF_HYPERCALL_H
3
4#include <xtf/compiler.h>
5#include <xtf/types.h>
6#include <arch/desc.h>
7#include <arch/page.h>
8
9#if defined(__x86_64__)
10
12# define HYPERCALL0 _hypercall64_0
13# define HYPERCALL1 _hypercall64_1
14# define HYPERCALL2 _hypercall64_2
15# define HYPERCALL3 _hypercall64_3
16# define HYPERCALL4 _hypercall64_4
17# define HYPERCALL5 _hypercall64_5
18
19#elif defined(__i386__)
20
22# define HYPERCALL0 _hypercall32_0
23# define HYPERCALL1 _hypercall32_1
24# define HYPERCALL2 _hypercall32_2
25# define HYPERCALL3 _hypercall32_3
26# define HYPERCALL4 _hypercall32_4
27# define HYPERCALL5 _hypercall32_5
28
29#else
30# error Bad architecture for hypercalls
31#endif
32
34
35/* All Xen ABI for includers convenience .*/
36#include <xen/argo.h>
37#include <xen/callback.h>
38#include <xen/elfnote.h>
39#include <xen/errno.h>
40#include <xen/event_channel.h>
41#include <xen/grant_table.h>
42#include <xen/hvm/hvm_op.h>
43#include <xen/hvm/hvm_vcpu.h>
44#include <xen/hvm/params.h>
45#include <xen/memory.h>
46#include <xen/physdev.h>
47#include <xen/sched.h>
48#include <xen/sysctl.h>
49#include <xen/vcpu.h>
50#include <xen/version.h>
51#include <xen/xen.h>
52
53/*
54 * Hypercall primatives, compiled for the correct bitness
55 */
56static inline long hypercall_set_trap_table(const struct xen_trap_info *ti)
57{
58 return HYPERCALL1(long, __HYPERVISOR_set_trap_table, ti);
59}
60
61static inline long hypercall_mmu_update(const mmu_update_t reqs[],
62 unsigned int count,
63 unsigned int *done,
64 unsigned int foreigndom)
65{
66 return HYPERCALL4(long, __HYPERVISOR_mmu_update,
67 reqs, count, done, foreigndom);
68}
69
70static inline long hypercall_set_gdt(const unsigned long *mfns,
71 unsigned int entries)
72{
73 return HYPERCALL2(long, __HYPERVISOR_set_gdt, mfns, entries);
74}
75
76static inline long hypercall_stack_switch(const unsigned int ss, const void *sp)
77{
78 return HYPERCALL2(long, __HYPERVISOR_stack_switch, ss, sp);
79}
80
81static inline long hypercall_set_debugreg(unsigned int reg, unsigned long val)
82{
83 return HYPERCALL2(long, __HYPERVISOR_set_debugreg, reg, val);
84}
85
86static inline long hypercall_get_debugreg(unsigned int reg)
87{
88 return HYPERCALL1(long, __HYPERVISOR_get_debugreg, reg);
89}
90
91static inline long hypercall_update_descriptor(uint64_t maddr, user_desc desc)
92{
93#ifdef __x86_64__
94 return HYPERCALL2(long, __HYPERVISOR_update_descriptor, maddr, desc.raw);
95#else
96 return HYPERCALL4(long, __HYPERVISOR_update_descriptor,
97 maddr, maddr >> 32, desc.lo, desc.hi);
98#endif
99}
100
101static inline long hypercall_memory_op(unsigned int cmd, void *arg)
102{
103 return HYPERCALL2(long, __HYPERVISOR_memory_op, cmd, arg);
104}
105
106static inline long hypercall_multicall(struct multicall_entry *list,
107 unsigned int nr)
108{
109 return HYPERCALL2(long, __HYPERVISOR_multicall, list, nr);
110}
111
112/*
113 * This hypercall is misnamed in the Xen ABI, and actually operates on a
114 * linear address, not a virtual address.
115 */
117 unsigned long linear, uint64_t npte, enum XEN_UVMF flags)
118{
119#ifdef __x86_64__
120 return HYPERCALL3(long, __HYPERVISOR_update_va_mapping, linear, npte, flags);
121#else
122 return HYPERCALL4(long, __HYPERVISOR_update_va_mapping,
123 linear, npte, npte >> 32, flags);
124#endif
125}
126
127static inline long hypercall_xen_version(unsigned int cmd, void *arg)
128{
129 return HYPERCALL2(long, __HYPERVISOR_xen_version, cmd, arg);
130}
131
132static inline long hypercall_grant_table_op(unsigned int cmd, void *args,
133 unsigned int count)
134{
135 return HYPERCALL3(long, __HYPERVISOR_grant_table_op, cmd, args, count);
136}
137
138static inline long hypercall_vm_assist(unsigned int cmd, unsigned int type)
139{
140 return HYPERCALL2(long, __HYPERVISOR_vm_assist, cmd, type);
141}
142
143static inline long hypercall_vcpu_op(unsigned int cmd, unsigned int vcpu,
144 void *extra)
145{
146 return HYPERCALL3(long, __HYPERVISOR_vcpu_op, cmd, vcpu, extra);
147}
148
149static inline long hypercall_mmuext_op(const mmuext_op_t ops[],
150 unsigned int count,
151 unsigned int *done,
152 unsigned int foreigndom)
153{
154 return HYPERCALL4(long, __HYPERVISOR_mmuext_op,
155 ops, count, done, foreigndom);
156}
157
158static inline long hypercall_sched_op(unsigned int cmd, void *arg)
159{
160 return HYPERCALL2(long, __HYPERVISOR_sched_op, cmd, arg);
161}
162
163static inline long hypercall_callback_op(unsigned int cmd, const void *arg)
164{
165 return HYPERCALL2(long, __HYPERVISOR_callback_op, cmd, arg);
166}
167
168static inline long hypercall_event_channel_op(unsigned int cmd, void *arg)
169{
170 return HYPERCALL2(long, __HYPERVISOR_event_channel_op, cmd, arg);
171}
172
173static inline long hypercall_physdev_op(unsigned int cmd, void *arg)
174{
175 return HYPERCALL2(long, __HYPERVISOR_physdev_op, cmd, arg);
176}
177
178static inline long hypercall_hvm_op(unsigned int cmd, void *arg)
179{
180 return HYPERCALL2(long, __HYPERVISOR_hvm_op, cmd, arg);
181}
182
183static inline long hypercall_sysctl(xen_sysctl_t *arg)
184{
185 return HYPERCALL1(long, __HYPERVISOR_sysctl, arg);
186}
187
188static inline long hypercall_argo_op(unsigned int cmd, void *arg1, void *arg2,
189 unsigned long arg3, unsigned long arg4)
190{
191 return HYPERCALL5(long, __HYPERVISOR_argo_op, cmd, arg1, arg2, arg3, arg4);
192}
193
194/*
195 * Higher level hypercall helpers
196 */
197static inline void hypercall_console_write(const char *buf, unsigned long count)
198{
199 (void)HYPERCALL3(long, __HYPERVISOR_console_io, CONSOLEIO_write, count, buf);
200}
201
202static inline long hypercall_shutdown(unsigned int reason)
203{
204 return hypercall_sched_op(SCHEDOP_shutdown, &reason);
205}
206
207static inline void hypercall_yield(void)
208{
210}
211
212static inline long hypercall_poll(evtchn_port_t port)
213{
214 struct sched_poll poll = { .ports = &port, .nr_ports = 1 };
215
216 return hypercall_sched_op(SCHEDOP_poll, &poll);
217}
218
220{
222}
223
225{
227}
228
230{
232}
233
235{
237}
238
240{
242}
243
244static inline int hvm_set_param(unsigned int idx, uint64_t value)
245{
246 xen_hvm_param_t p = { .domid = DOMID_SELF, .index = idx, .value = value };
247
249}
250
251static inline int hvm_get_param(unsigned int idx, uint64_t *value)
252{
253 xen_hvm_param_t p = { .domid = DOMID_SELF, .index = idx };
254 int rc = hypercall_hvm_op(HVMOP_get_param, &p);
255
256 if ( rc == 0 )
257 *value = p.value;
258 return rc;
259}
260
261#endif /* XTF_HYPERCALL_H */
262
263/*
264 * Local variables:
265 * mode: C
266 * c-file-style: "BSD"
267 * c-basic-offset: 4
268 * tab-width: 4
269 * indent-tabs-mode: nil
270 * End:
271 */
#define CALLBACKOP_register
Definition: callback.h:61
x86 segment descriptor infrastructure.
#define EVTCHNOP_close
Definition: event_channel.h:6
#define EVTCHNOP_send
Definition: event_channel.h:7
#define EVTCHNOP_alloc_unbound
Definition: event_channel.h:9
#define EVTCHNOP_status
Definition: event_channel.h:8
uint32_t evtchn_port_t
Definition: event_channel.h:13
#define HVMOP_get_param
Definition: hvm_op.h:10
#define HVMOP_set_param
Definition: hvm_op.h:9
static long hypercall_mmuext_op(const mmuext_op_t ops[], unsigned int count, unsigned int *done, unsigned int foreigndom)
Definition: hypercall.h:149
static int hvm_get_param(unsigned int idx, uint64_t *value)
Definition: hypercall.h:251
static long hypercall_event_channel_op(unsigned int cmd, void *arg)
Definition: hypercall.h:168
static long hypercall_stack_switch(const unsigned int ss, const void *sp)
Definition: hypercall.h:76
static long hypercall_multicall(struct multicall_entry *list, unsigned int nr)
Definition: hypercall.h:106
static long hypercall_get_debugreg(unsigned int reg)
Definition: hypercall.h:86
static int hypercall_evtchn_alloc_unbound(struct evtchn_alloc_unbound *ub)
Definition: hypercall.h:239
static long hypercall_mmu_update(const mmu_update_t reqs[], unsigned int count, unsigned int *done, unsigned int foreigndom)
Definition: hypercall.h:61
static long hypercall_callback_op(unsigned int cmd, const void *arg)
Definition: hypercall.h:163
static long hypercall_set_gdt(const unsigned long *mfns, unsigned int entries)
Definition: hypercall.h:70
static int hypercall_evtchn_close(evtchn_port_t port)
Definition: hypercall.h:224
static long hypercall_sysctl(xen_sysctl_t *arg)
Definition: hypercall.h:183
static long hypercall_vcpu_op(unsigned int cmd, unsigned int vcpu, void *extra)
Definition: hypercall.h:143
static int hypercall_evtchn_send(evtchn_port_t port)
Definition: hypercall.h:229
static long hypercall_argo_op(unsigned int cmd, void *arg1, void *arg2, unsigned long arg3, unsigned long arg4)
Definition: hypercall.h:188
static long hypercall_physdev_op(unsigned int cmd, void *arg)
Definition: hypercall.h:173
static int hypercall_register_callback(const xen_callback_register_t *arg)
Definition: hypercall.h:219
static long hypercall_update_va_mapping(unsigned long linear, uint64_t npte, enum XEN_UVMF flags)
Definition: hypercall.h:116
static long hypercall_sched_op(unsigned int cmd, void *arg)
Definition: hypercall.h:158
static long hypercall_set_debugreg(unsigned int reg, unsigned long val)
Definition: hypercall.h:81
static long hypercall_set_trap_table(const struct xen_trap_info *ti)
Definition: hypercall.h:56
static long hypercall_update_descriptor(uint64_t maddr, user_desc desc)
Definition: hypercall.h:91
static long hypercall_hvm_op(unsigned int cmd, void *arg)
Definition: hypercall.h:178
static int hvm_set_param(unsigned int idx, uint64_t value)
Definition: hypercall.h:244
static void hypercall_console_write(const char *buf, unsigned long count)
Definition: hypercall.h:197
static long hypercall_poll(evtchn_port_t port)
Definition: hypercall.h:212
static int hypercall_evtchn_status(struct evtchn_status *status)
Definition: hypercall.h:234
static long hypercall_memory_op(unsigned int cmd, void *arg)
Definition: hypercall.h:101
uint8_t hypercall_page[PAGE_SIZE]
static long hypercall_shutdown(unsigned int reason)
Definition: hypercall.h:202
static long hypercall_xen_version(unsigned int cmd, void *arg)
Definition: hypercall.h:127
static long hypercall_grant_table_op(unsigned int cmd, void *args, unsigned int count)
Definition: hypercall.h:132
static void hypercall_yield(void)
Definition: hypercall.h:207
static long hypercall_vm_assist(unsigned int cmd, unsigned int type)
Definition: hypercall.h:138
#define PAGE_SIZE
Definition: page.h:11
static enum test_status status
Current status of this test.
Definition: report.c:14
#define SCHEDOP_poll
Definition: sched.h:12
#define SCHEDOP_shutdown
Definition: sched.h:11
#define SCHEDOP_yield
Definition: sched.h:10
#define NULL
Definition: stddef.h:12
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
__UINT8_TYPE__ uint8_t
Definition: stdint.h:14
Definition: xen.h:355
Definition: xen.h:263
evtchn_port_t * ports
Definition: sched.h:20
domid_t domid
Definition: hvm_op.h:12
uint64_t value
Definition: hvm_op.h:14
Common declarations for all tests.
#define __HYPERVISOR_hvm_op
Definition: xen.h:47
#define CONSOLEIO_write
Definition: xen.h:73
#define __HYPERVISOR_physdev_op
Definition: xen.h:46
#define __HYPERVISOR_sched_op
Definition: xen.h:42
#define __HYPERVISOR_set_trap_table
Definition: xen.h:14
#define __HYPERVISOR_callback_op
Definition: xen.h:43
#define __HYPERVISOR_vm_assist
Definition: xen.h:34
#define DOMID_SELF
Definition: xen.h:70
#define __HYPERVISOR_update_va_mapping
Definition: xen.h:27
#define __HYPERVISOR_multicall
Definition: xen.h:26
#define __HYPERVISOR_xen_version
Definition: xen.h:30
#define __HYPERVISOR_get_debugreg
Definition: xen.h:23
#define __HYPERVISOR_argo_op
Definition: xen.h:52
#define __HYPERVISOR_update_descriptor
Definition: xen.h:24
#define __HYPERVISOR_mmuext_op
Definition: xen.h:39
#define __HYPERVISOR_mmu_update
Definition: xen.h:15
#define __HYPERVISOR_set_debugreg
Definition: xen.h:22
#define __HYPERVISOR_memory_op
Definition: xen.h:25
#define __HYPERVISOR_vcpu_op
Definition: xen.h:37
#define __HYPERVISOR_stack_switch
Definition: xen.h:17
XEN_UVMF
Definition: xen.h:380
#define __HYPERVISOR_event_channel_op
Definition: xen.h:45
#define __HYPERVISOR_sysctl
Definition: xen.h:48
#define __HYPERVISOR_console_io
Definition: xen.h:31
#define __HYPERVISOR_grant_table_op
Definition: xen.h:33
#define __HYPERVISOR_set_gdt
Definition: xen.h:16