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