xref: /netbsd-src/sys/arch/xen/include/hypervisor.h (revision fd5cb0acea84d278e04e640d37ca2398f894991f)
1 /*	$NetBSD: hypervisor.h,v 1.9 2004/12/10 18:51:15 christos 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 hypervisor_attach_args {
34 	const char 		*haa_busname;
35 };
36 
37 struct xencons_attach_args {
38 	const char 		*xa_device;
39 };
40 
41 struct xen_npx_attach_args {
42 	const char 		*xa_device;
43 };
44 
45 
46 #define	u16 uint16_t
47 #define	u32 uint32_t
48 #define	u64 uint64_t
49 
50 #include <machine/hypervisor-ifs/block.h>
51 #include <machine/hypervisor-ifs/hypervisor-if.h>
52 #include <machine/hypervisor-ifs/dom0_ops.h>
53 #include <machine/hypervisor-ifs/network.h>
54 #include <machine/hypervisor-ifs/vbd.h>
55 
56 #undef u16
57 #undef u32
58 #undef u64
59 
60 
61 /*
62  * a placeholder for the start of day information passed up from the hypervisor
63  */
64 union start_info_union
65 {
66     start_info_t start_info;
67     char padding[512];
68 };
69 extern union start_info_union start_info_union;
70 #define xen_start_info (start_info_union.start_info)
71 
72 
73 /* hypervisor.c */
74 struct trapframe;
75 void do_hypervisor_callback(struct trapframe *regs);
76 void hypervisor_enable_event(unsigned int ev);
77 void hypervisor_disable_event(unsigned int ev);
78 void hypervisor_acknowledge_event(unsigned int ev);
79 
80 /*
81  * Assembler stubs for hyper-calls.
82  */
83 
84 static inline int HYPERVISOR_set_trap_table(trap_info_t *table)
85 {
86     int ret;
87     __asm__ __volatile__ (
88         TRAP_INSTR
89         : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table),
90         "b" (table) : "memory" );
91 
92     return ret;
93 }
94 
95 static inline int HYPERVISOR_mmu_update(mmu_update_t *req, int count)
96 {
97     int ret;
98     __asm__ __volatile__ (
99         TRAP_INSTR
100         : "=a" (ret) : "0" (__HYPERVISOR_mmu_update),
101         "b" (req), "c" (count) : "memory" );
102 
103 #ifdef notdef
104     if (__predict_false(ret < 0))
105         panic("Failed mmu update: %p, %d", req, count);
106 #endif
107 
108     return ret;
109 }
110 
111 static inline int HYPERVISOR_mmu_update_fail_ok(mmu_update_t *req, int count)
112 {
113     int ret;
114     __asm__ __volatile__ (
115         TRAP_INSTR
116         : "=a" (ret) : "0" (__HYPERVISOR_mmu_update),
117         "b" (req), "c" (count) : "memory" );
118 
119     return ret;
120 }
121 
122 static inline int HYPERVISOR_console_write(const char *str, int count)
123 {
124     int ret;
125     __asm__ __volatile__ (
126         TRAP_INSTR
127         : "=a" (ret) : "0" (__HYPERVISOR_console_write),
128         "b" (str), "c" (count) : "memory" );
129 
130 
131     return ret;
132 }
133 
134 static inline int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
135 {
136     int ret;
137     __asm__ __volatile__ (
138         TRAP_INSTR
139         : "=a" (ret) : "0" (__HYPERVISOR_set_gdt),
140         "b" (frame_list), "c" (entries) : "memory" );
141 
142 
143     return ret;
144 }
145 
146 static inline int HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
147 {
148     int ret;
149     __asm__ __volatile__ (
150         TRAP_INSTR
151         : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
152         "b" (ss), "c" (esp) : "memory" );
153 
154     return ret;
155 }
156 
157 static inline int HYPERVISOR_set_callbacks(
158     unsigned long event_selector, unsigned long event_address,
159     unsigned long failsafe_selector, unsigned long failsafe_address)
160 {
161     int ret;
162     __asm__ __volatile__ (
163         TRAP_INSTR
164         : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
165         "b" (event_selector), "c" (event_address),
166         "d" (failsafe_selector), "S" (failsafe_address) : "memory" );
167 
168     return ret;
169 }
170 
171 static inline int HYPERVISOR_net_io_op(netop_t *op)
172 {
173     int ret;
174     __asm__ __volatile__ (
175         TRAP_INSTR
176         : "=a" (ret) : "0" (__HYPERVISOR_net_io_op),
177         "b" (op) : "memory" );
178 
179     return ret;
180 }
181 
182 static inline int HYPERVISOR_fpu_taskswitch(void)
183 {
184     int ret;
185     __asm__ __volatile__ (
186         TRAP_INSTR
187         : "=a" (ret) : "0" (__HYPERVISOR_fpu_taskswitch) : "memory" );
188 
189     return ret;
190 }
191 
192 static inline int HYPERVISOR_yield(void)
193 {
194     int ret;
195     __asm__ __volatile__ (
196         TRAP_INSTR
197         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
198         "b" (SCHEDOP_yield) : "memory" );
199 
200     return ret;
201 }
202 
203 static inline int HYPERVISOR_exit(void)
204 {
205     int ret;
206     __asm__ __volatile__ (
207         TRAP_INSTR
208         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
209         "b" (SCHEDOP_exit) : "memory" );
210 
211     return ret;
212 }
213 
214 static inline int HYPERVISOR_stop(unsigned long srec)
215 {
216     int ret;
217     /* NB. On suspend, control software expects a suspend record in %esi. */
218     __asm__ __volatile__ (
219         TRAP_INSTR
220         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
221         "b" (SCHEDOP_stop), "S" (srec) : "memory" );
222 
223     return ret;
224 }
225 
226 static inline int HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
227 {
228     int ret;
229     dom0_op->interface_version = DOM0_INTERFACE_VERSION;
230     __asm__ __volatile__ (
231         TRAP_INSTR
232         : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
233         "b" (dom0_op) : "memory" );
234 
235     return ret;
236 }
237 
238 static inline int HYPERVISOR_network_op(void *network_op)
239 {
240     int ret;
241     __asm__ __volatile__ (
242         TRAP_INSTR
243         : "=a" (ret) : "0" (__HYPERVISOR_network_op),
244         "b" (network_op) : "memory" );
245 
246     return ret;
247 }
248 
249 static inline int HYPERVISOR_block_io_op(void * block_io_op)
250 {
251     int ret;
252     __asm__ __volatile__ (
253         TRAP_INSTR
254         : "=a" (ret) : "0" (__HYPERVISOR_block_io_op),
255         "b" (block_io_op) : "memory" );
256 
257     return ret;
258 }
259 
260 static inline int HYPERVISOR_set_debugreg(int reg, unsigned long value)
261 {
262     int ret;
263     __asm__ __volatile__ (
264         TRAP_INSTR
265         : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
266         "b" (reg), "c" (value) : "memory" );
267 
268     return ret;
269 }
270 
271 static inline unsigned long HYPERVISOR_get_debugreg(int reg)
272 {
273     unsigned long ret;
274     __asm__ __volatile__ (
275         TRAP_INSTR
276         : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
277         "b" (reg) : "memory" );
278 
279     return ret;
280 }
281 
282 static inline int HYPERVISOR_update_descriptor(
283     unsigned long pa, unsigned long word1, unsigned long word2)
284 {
285     int ret;
286     __asm__ __volatile__ (
287         TRAP_INSTR
288         : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor),
289         "b" (pa), "c" (word1), "d" (word2) : "memory" );
290 
291     return ret;
292 }
293 
294 static inline int HYPERVISOR_set_fast_trap(int idx)
295 {
296     int ret;
297     __asm__ __volatile__ (
298         TRAP_INSTR
299         : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap),
300         "b" (idx) : "memory" );
301 
302     return ret;
303 }
304 
305 static inline int HYPERVISOR_dom_mem_op(void *dom_mem_op)
306 {
307     int ret;
308     __asm__ __volatile__ (
309         TRAP_INSTR
310         : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
311         "b" (dom_mem_op) : "memory" );
312 
313     return ret;
314 }
315 
316 static inline int HYPERVISOR_multicall(void *call_list, int nr_calls)
317 {
318     int ret;
319     __asm__ __volatile__ (
320         TRAP_INSTR
321         : "=a" (ret) : "0" (__HYPERVISOR_multicall),
322         "b" (call_list), "c" (nr_calls) : "memory" );
323 
324     return ret;
325 }
326 
327 static inline long HYPERVISOR_kbd_op(unsigned char op, unsigned char val)
328 {
329     int ret;
330     __asm__ __volatile__ (
331         TRAP_INSTR
332         : "=a" (ret) : "0" (__HYPERVISOR_kbd_op),
333         "b" (op), "c" (val) : "memory" );
334 
335     return ret;
336 }
337 
338 static inline int HYPERVISOR_update_va_mapping(
339     unsigned long page_nr, unsigned long new_val, unsigned long flags)
340 {
341     int ret;
342     __asm__ __volatile__ (
343         TRAP_INSTR
344         : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping),
345         "b" (page_nr), "c" (new_val), "d" (flags) : "memory" );
346 
347 #ifdef notdef
348     if (__predict_false(ret < 0))
349         panic("Failed update VA mapping: %08lx, %08lx, %08lx",
350               page_nr, new_val, flags);
351 #endif
352 
353     return ret;
354 }
355 
356 #endif /* _XEN_HYPERVISOR_H_ */
357