hypervisor.h revision 1.3 1 /* $NetBSD: hypervisor.h,v 1.3 2004/04/17 12:46:42 cl Exp $ */
2
3 /*
4 *
5 * Communication to/from hypervisor.
6 *
7 * Copyright (c) 2002-2003, K A Fraser
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to
11 * deal in the Software without restriction, including without limitation the
12 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 * sell copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
27
28
29 #ifndef _XEN_HYPERVISOR_H_
30 #define _XEN_HYPERVISOR_H_
31
32
33 struct xenc_attach_args {
34 const char *xa_busname;
35 };
36
37 struct xen_npx_attach_args {
38 const char *xa_busname;
39 };
40
41
42 /* include the hypervisor interface */
43 #include <sys/systm.h>
44 #include <machine/hypervisor-ifs/block.h>
45 #include <machine/hypervisor-ifs/hypervisor-if.h>
46 #include <machine/hypervisor-ifs/dom0_ops.h>
47 #include <machine/hypervisor-ifs/network.h>
48
49
50 /*
51 * a placeholder for the start of day information passed up from the hypervisor
52 */
53 union start_info_union
54 {
55 start_info_t start_info;
56 char padding[512];
57 };
58 extern union start_info_union start_info_union;
59 #define xen_start_info (start_info_union.start_info)
60
61
62 /* hypervisor.c */
63 void do_hypervisor_callback(struct trapframe *regs);
64 void hypervisor_enable_event(unsigned int ev);
65 void hypervisor_disable_event(unsigned int ev);
66 void hypervisor_acknowledge_event(unsigned int ev);
67
68 /*
69 * Assembler stubs for hyper-calls.
70 */
71
72 static inline int HYPERVISOR_set_trap_table(trap_info_t *table)
73 {
74 int ret;
75 __asm__ __volatile__ (
76 TRAP_INSTR
77 : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table),
78 "b" (table) );
79
80 return ret;
81 }
82
83 static inline int HYPERVISOR_mmu_update(mmu_update_t *req, int count)
84 {
85 int ret;
86 __asm__ __volatile__ (
87 TRAP_INSTR
88 : "=a" (ret) : "0" (__HYPERVISOR_mmu_update),
89 "b" (req), "c" (count) );
90
91 if (__predict_false(ret < 0))
92 panic("Failed mmu update: %p, %d", req, count);
93
94 return ret;
95 }
96
97 static inline int HYPERVISOR_console_write(const char *str, int count)
98 {
99 int ret;
100 __asm__ __volatile__ (
101 TRAP_INSTR
102 : "=a" (ret) : "0" (__HYPERVISOR_console_write),
103 "b" (str), "c" (count) );
104
105
106 return ret;
107 }
108
109 static inline int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
110 {
111 int ret;
112 __asm__ __volatile__ (
113 TRAP_INSTR
114 : "=a" (ret) : "0" (__HYPERVISOR_set_gdt),
115 "b" (frame_list), "c" (entries) );
116
117
118 return ret;
119 }
120
121 static inline int HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
122 {
123 int ret;
124 __asm__ __volatile__ (
125 TRAP_INSTR
126 : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
127 "b" (ss), "c" (esp) : "memory" );
128
129 return ret;
130 }
131
132 static inline int HYPERVISOR_set_callbacks(
133 unsigned long event_selector, unsigned long event_address,
134 unsigned long failsafe_selector, unsigned long failsafe_address)
135 {
136 int ret;
137 __asm__ __volatile__ (
138 TRAP_INSTR
139 : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
140 "b" (event_selector), "c" (event_address),
141 "d" (failsafe_selector), "S" (failsafe_address) : "memory" );
142
143 return ret;
144 }
145
146 static inline int HYPERVISOR_net_io_op(netop_t *op)
147 {
148 int ret;
149 __asm__ __volatile__ (
150 TRAP_INSTR
151 : "=a" (ret) : "0" (__HYPERVISOR_net_io_op),
152 "b" (op) : "memory" );
153
154 return ret;
155 }
156
157 static inline int HYPERVISOR_fpu_taskswitch(void)
158 {
159 int ret;
160 __asm__ __volatile__ (
161 TRAP_INSTR
162 : "=a" (ret) : "0" (__HYPERVISOR_fpu_taskswitch) );
163
164 return ret;
165 }
166
167 static inline int HYPERVISOR_yield(void)
168 {
169 int ret;
170 __asm__ __volatile__ (
171 TRAP_INSTR
172 : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
173 "b" (SCHEDOP_yield) );
174
175 return ret;
176 }
177
178 static inline int HYPERVISOR_exit(void)
179 {
180 int ret;
181 __asm__ __volatile__ (
182 TRAP_INSTR
183 : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
184 "b" (SCHEDOP_exit) );
185
186 return ret;
187 }
188
189 static inline int HYPERVISOR_stop(unsigned long srec)
190 {
191 int ret;
192 /* NB. On suspend, control software expects a suspend record in %esi. */
193 __asm__ __volatile__ (
194 TRAP_INSTR
195 : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
196 "b" (SCHEDOP_stop), "S" (srec) : "memory" );
197
198 return ret;
199 }
200
201 static inline int HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
202 {
203 int ret;
204 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
205 __asm__ __volatile__ (
206 TRAP_INSTR
207 : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
208 "b" (dom0_op) : "memory" );
209
210 return ret;
211 }
212
213 static inline int HYPERVISOR_network_op(void *network_op)
214 {
215 int ret;
216 __asm__ __volatile__ (
217 TRAP_INSTR
218 : "=a" (ret) : "0" (__HYPERVISOR_network_op),
219 "b" (network_op) : "memory" );
220
221 return ret;
222 }
223
224 static inline int HYPERVISOR_block_io_op(void * block_io_op)
225 {
226 int ret;
227 __asm__ __volatile__ (
228 TRAP_INSTR
229 : "=a" (ret) : "0" (__HYPERVISOR_block_io_op),
230 "b" (block_io_op) : "memory" );
231
232 return ret;
233 }
234
235 static inline int HYPERVISOR_set_debugreg(int reg, unsigned long value)
236 {
237 int ret;
238 __asm__ __volatile__ (
239 TRAP_INSTR
240 : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
241 "b" (reg), "c" (value) );
242
243 return ret;
244 }
245
246 static inline unsigned long HYPERVISOR_get_debugreg(int reg)
247 {
248 unsigned long ret;
249 __asm__ __volatile__ (
250 TRAP_INSTR
251 : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
252 "b" (reg) );
253
254 return ret;
255 }
256
257 static inline int HYPERVISOR_update_descriptor(
258 unsigned long pa, unsigned long word1, unsigned long word2)
259 {
260 int ret;
261 __asm__ __volatile__ (
262 TRAP_INSTR
263 : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor),
264 "b" (pa), "c" (word1), "d" (word2) );
265
266 return ret;
267 }
268
269 static inline int HYPERVISOR_set_fast_trap(int idx)
270 {
271 int ret;
272 __asm__ __volatile__ (
273 TRAP_INSTR
274 : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap),
275 "b" (idx) );
276
277 return ret;
278 }
279
280 static inline int HYPERVISOR_dom_mem_op(void *dom_mem_op)
281 {
282 int ret;
283 __asm__ __volatile__ (
284 TRAP_INSTR
285 : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
286 "b" (dom_mem_op) : "memory" );
287
288 return ret;
289 }
290
291 static inline int HYPERVISOR_multicall(void *call_list, int nr_calls)
292 {
293 int ret;
294 __asm__ __volatile__ (
295 TRAP_INSTR
296 : "=a" (ret) : "0" (__HYPERVISOR_multicall),
297 "b" (call_list), "c" (nr_calls) : "memory" );
298
299 return ret;
300 }
301
302 static inline long HYPERVISOR_kbd_op(unsigned char op, unsigned char val)
303 {
304 int ret;
305 __asm__ __volatile__ (
306 TRAP_INSTR
307 : "=a" (ret) : "0" (__HYPERVISOR_kbd_op),
308 "b" (op), "c" (val) );
309
310 return ret;
311 }
312
313 static inline int HYPERVISOR_update_va_mapping(
314 unsigned long page_nr, unsigned long new_val, unsigned long flags)
315 {
316 int ret;
317 __asm__ __volatile__ (
318 TRAP_INSTR
319 : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping),
320 "b" (page_nr), "c" (new_val), "d" (flags) );
321
322 if (__predict_false(ret < 0))
323 panic("Failed update VA mapping: %08lx, %08lx, %08lx",
324 page_nr, new_val, flags);
325
326 return ret;
327 }
328
329 #endif /* _XEN_HYPERVISOR_H_ */
330