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