debuggers.hg

view linux-2.6.10-rc2-xen-sparse/include/asm-xen/hypervisor.h @ 3289:a169836882cb

bitkeeper revision 1.1159.170.59 (41b4c2fdJ2gj_BWy27Vj3ptayZp_yg)

sync w/ head.
author cl349@arcadians.cl.cam.ac.uk
date Mon Dec 06 20:37:17 2004 +0000 (2004-12-06)
parents f65b65977b19
children
line source
1 /******************************************************************************
2 * hypervisor.h
3 *
4 * Linux-specific hypervisor handling.
5 *
6 * Copyright (c) 2002-2004, K A Fraser
7 *
8 * This file may be distributed separately from the Linux kernel, or
9 * incorporated into other software packages, subject to the following license:
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this source file (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use, copy, modify,
14 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
15 * and to permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * IN THE SOFTWARE.
28 */
30 #ifndef __HYPERVISOR_H__
31 #define __HYPERVISOR_H__
33 #include <linux/types.h>
34 #include <linux/kernel.h>
35 #include <linux/version.h>
36 #include <asm-xen/xen-public/xen.h>
37 #include <asm-xen/xen-public/dom0_ops.h>
38 #include <asm-xen/xen-public/io/domain_controller.h>
39 #include <asm/ptrace.h>
40 #include <asm/page.h>
42 /* arch/xen/i386/kernel/setup.c */
43 union xen_start_info_union
44 {
45 start_info_t xen_start_info;
46 char padding[512];
47 };
48 extern union xen_start_info_union xen_start_info_union;
49 #define xen_start_info (xen_start_info_union.xen_start_info)
51 /* arch/xen/kernel/process.c */
52 void xen_cpu_idle (void);
54 /* arch/xen/i386/kernel/hypervisor.c */
55 void do_hypervisor_callback(struct pt_regs *regs);
57 /* arch/xen/i386/kernel/head.S */
58 void lgdt_finish(void);
60 /* arch/xen/i386/mm/hypervisor.c */
61 /*
62 * NB. ptr values should be PHYSICAL, not MACHINE. 'vals' should be already
63 * be MACHINE addresses.
64 */
66 extern unsigned int mmu_update_queue_idx;
68 void queue_l1_entry_update(pte_t *ptr, unsigned long val);
69 void queue_l2_entry_update(pmd_t *ptr, unsigned long val);
70 void queue_pt_switch(unsigned long ptr);
71 void queue_tlb_flush(void);
72 void queue_invlpg(unsigned long ptr);
73 void queue_pgd_pin(unsigned long ptr);
74 void queue_pgd_unpin(unsigned long ptr);
75 void queue_pte_pin(unsigned long ptr);
76 void queue_pte_unpin(unsigned long ptr);
77 void queue_set_ldt(unsigned long ptr, unsigned long bytes);
78 void queue_machphys_update(unsigned long mfn, unsigned long pfn);
79 void xen_l1_entry_update(pte_t *ptr, unsigned long val);
80 void xen_l2_entry_update(pmd_t *ptr, unsigned long val);
81 void xen_pt_switch(unsigned long ptr);
82 void xen_tlb_flush(void);
83 void xen_invlpg(unsigned long ptr);
84 void xen_pgd_pin(unsigned long ptr);
85 void xen_pgd_unpin(unsigned long ptr);
86 void xen_pte_pin(unsigned long ptr);
87 void xen_pte_unpin(unsigned long ptr);
88 void xen_set_ldt(unsigned long ptr, unsigned long bytes);
89 void xen_machphys_update(unsigned long mfn, unsigned long pfn);
91 void _flush_page_update_queue(void);
92 static inline int flush_page_update_queue(void)
93 {
94 unsigned int idx = mmu_update_queue_idx;
95 if ( idx != 0 ) _flush_page_update_queue();
96 return idx;
97 }
98 #define xen_flush_page_update_queue() (_flush_page_update_queue())
99 #define XEN_flush_page_update_queue() (_flush_page_update_queue())
100 void MULTICALL_flush_page_update_queue(void);
102 #ifdef CONFIG_XEN_PHYSDEV_ACCESS
103 /* Allocate a contiguous empty region of low memory. Return virtual start. */
104 unsigned long allocate_empty_lowmem_region(unsigned long pages);
105 #endif
107 /*
108 * Assembler stubs for hyper-calls.
109 */
111 static inline int
112 HYPERVISOR_set_trap_table(
113 trap_info_t *table)
114 {
115 int ret;
116 unsigned long ignore;
118 __asm__ __volatile__ (
119 TRAP_INSTR
120 : "=a" (ret), "=b" (ignore)
121 : "0" (__HYPERVISOR_set_trap_table), "1" (table)
122 : "memory" );
124 return ret;
125 }
127 static inline int
128 HYPERVISOR_mmu_update(
129 mmu_update_t *req, int count, int *success_count)
130 {
131 int ret;
132 unsigned long ign1, ign2, ign3;
134 __asm__ __volatile__ (
135 TRAP_INSTR
136 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
137 : "0" (__HYPERVISOR_mmu_update), "1" (req), "2" (count),
138 "3" (success_count)
139 : "memory" );
141 return ret;
142 }
144 static inline int
145 HYPERVISOR_set_gdt(
146 unsigned long *frame_list, int entries)
147 {
148 int ret;
149 unsigned long ign1, ign2;
151 __asm__ __volatile__ (
152 TRAP_INSTR
153 : "=a" (ret), "=b" (ign1), "=c" (ign2)
154 : "0" (__HYPERVISOR_set_gdt), "1" (frame_list), "2" (entries)
155 : "memory" );
158 return ret;
159 }
161 static inline int
162 HYPERVISOR_stack_switch(
163 unsigned long ss, unsigned long esp)
164 {
165 int ret;
166 unsigned long ign1, ign2;
168 __asm__ __volatile__ (
169 TRAP_INSTR
170 : "=a" (ret), "=b" (ign1), "=c" (ign2)
171 : "0" (__HYPERVISOR_stack_switch), "1" (ss), "2" (esp)
172 : "memory" );
174 return ret;
175 }
177 static inline int
178 HYPERVISOR_set_callbacks(
179 unsigned long event_selector, unsigned long event_address,
180 unsigned long failsafe_selector, unsigned long failsafe_address)
181 {
182 int ret;
183 unsigned long ign1, ign2, ign3, ign4;
185 __asm__ __volatile__ (
186 TRAP_INSTR
187 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
188 : "0" (__HYPERVISOR_set_callbacks), "1" (event_selector),
189 "2" (event_address), "3" (failsafe_selector), "4" (failsafe_address)
190 : "memory" );
192 return ret;
193 }
195 static inline int
196 HYPERVISOR_fpu_taskswitch(
197 void)
198 {
199 int ret;
200 __asm__ __volatile__ (
201 TRAP_INSTR
202 : "=a" (ret) : "0" (__HYPERVISOR_fpu_taskswitch) : "memory" );
204 return ret;
205 }
207 static inline int
208 HYPERVISOR_yield(
209 void)
210 {
211 int ret;
212 unsigned long ign;
214 __asm__ __volatile__ (
215 TRAP_INSTR
216 : "=a" (ret), "=b" (ign)
217 : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_yield)
218 : "memory" );
220 return ret;
221 }
223 static inline int
224 HYPERVISOR_block(
225 void)
226 {
227 int ret;
228 unsigned long ign1;
229 __asm__ __volatile__ (
230 TRAP_INSTR
231 : "=a" (ret), "=b" (ign1)
232 : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_block)
233 : "memory" );
235 return ret;
236 }
238 static inline int
239 HYPERVISOR_shutdown(
240 void)
241 {
242 int ret;
243 unsigned long ign1;
244 __asm__ __volatile__ (
245 TRAP_INSTR
246 : "=a" (ret), "=b" (ign1)
247 : "0" (__HYPERVISOR_sched_op),
248 "1" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
249 : "memory" );
251 return ret;
252 }
254 static inline int
255 HYPERVISOR_reboot(
256 void)
257 {
258 int ret;
259 unsigned long ign1;
260 __asm__ __volatile__ (
261 TRAP_INSTR
262 : "=a" (ret), "=b" (ign1)
263 : "0" (__HYPERVISOR_sched_op),
264 "1" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
265 : "memory" );
267 return ret;
268 }
270 static inline int
271 HYPERVISOR_suspend(
272 unsigned long srec)
273 {
274 int ret;
275 unsigned long ign1, ign2;
277 /* NB. On suspend, control software expects a suspend record in %esi. */
278 __asm__ __volatile__ (
279 TRAP_INSTR
280 : "=a" (ret), "=b" (ign1), "=S" (ign2)
281 : "0" (__HYPERVISOR_sched_op),
282 "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)),
283 "S" (srec) : "memory");
285 return ret;
286 }
288 static inline long
289 HYPERVISOR_set_timer_op(
290 u64 timeout)
291 {
292 int ret;
293 unsigned long timeout_hi = (unsigned long)(timeout>>32);
294 unsigned long timeout_lo = (unsigned long)timeout;
295 unsigned long ign1, ign2;
297 __asm__ __volatile__ (
298 TRAP_INSTR
299 : "=a" (ret), "=b" (ign1), "=c" (ign2)
300 : "0" (__HYPERVISOR_set_timer_op), "b" (timeout_hi), "c" (timeout_lo)
301 : "memory");
303 return ret;
304 }
306 static inline int
307 HYPERVISOR_dom0_op(
308 dom0_op_t *dom0_op)
309 {
310 int ret;
311 unsigned long ign1;
313 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
314 __asm__ __volatile__ (
315 TRAP_INSTR
316 : "=a" (ret), "=b" (ign1)
317 : "0" (__HYPERVISOR_dom0_op), "1" (dom0_op)
318 : "memory");
320 return ret;
321 }
323 static inline int
324 HYPERVISOR_set_debugreg(
325 int reg, unsigned long value)
326 {
327 int ret;
328 unsigned long ign1, ign2;
329 __asm__ __volatile__ (
330 TRAP_INSTR
331 : "=a" (ret), "=b" (ign1), "=c" (ign2)
332 : "0" (__HYPERVISOR_set_debugreg), "1" (reg), "2" (value)
333 : "memory" );
335 return ret;
336 }
338 static inline unsigned long
339 HYPERVISOR_get_debugreg(
340 int reg)
341 {
342 unsigned long ret;
343 unsigned long ign;
344 __asm__ __volatile__ (
345 TRAP_INSTR
346 : "=a" (ret), "=b" (ign)
347 : "0" (__HYPERVISOR_get_debugreg), "1" (reg)
348 : "memory" );
350 return ret;
351 }
353 static inline int
354 HYPERVISOR_update_descriptor(
355 unsigned long ma, unsigned long word1, unsigned long word2)
356 {
357 int ret;
358 unsigned long ign1, ign2, ign3;
360 __asm__ __volatile__ (
361 TRAP_INSTR
362 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
363 : "0" (__HYPERVISOR_update_descriptor), "1" (ma), "2" (word1),
364 "3" (word2)
365 : "memory" );
367 return ret;
368 }
370 static inline int
371 HYPERVISOR_set_fast_trap(
372 int idx)
373 {
374 int ret;
375 unsigned long ign;
377 __asm__ __volatile__ (
378 TRAP_INSTR
379 : "=a" (ret), "=b" (ign)
380 : "0" (__HYPERVISOR_set_fast_trap), "1" (idx)
381 : "memory" );
383 return ret;
384 }
386 static inline int
387 HYPERVISOR_dom_mem_op(
388 unsigned int op, unsigned long *extent_list,
389 unsigned long nr_extents, unsigned int extent_order)
390 {
391 int ret;
392 unsigned long ign1, ign2, ign3, ign4, ign5;
394 __asm__ __volatile__ (
395 TRAP_INSTR
396 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
397 "=D" (ign5)
398 : "0" (__HYPERVISOR_dom_mem_op), "1" (op), "2" (extent_list),
399 "3" (nr_extents), "4" (extent_order), "5" (DOMID_SELF)
400 : "memory" );
402 return ret;
403 }
405 static inline int
406 HYPERVISOR_multicall(
407 void *call_list, int nr_calls)
408 {
409 int ret;
410 unsigned long ign1, ign2;
412 __asm__ __volatile__ (
413 TRAP_INSTR
414 : "=a" (ret), "=b" (ign1), "=c" (ign2)
415 : "0" (__HYPERVISOR_multicall), "1" (call_list), "2" (nr_calls)
416 : "memory" );
418 return ret;
419 }
421 static inline int
422 HYPERVISOR_update_va_mapping(
423 unsigned long page_nr, pte_t new_val, unsigned long flags)
424 {
425 int ret;
426 unsigned long ign1, ign2, ign3;
428 __asm__ __volatile__ (
429 TRAP_INSTR
430 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
431 : "0" (__HYPERVISOR_update_va_mapping),
432 "1" (page_nr), "2" ((new_val).pte_low), "3" (flags)
433 : "memory" );
435 if ( unlikely(ret < 0) )
436 {
437 printk(KERN_ALERT "Failed update VA mapping: %08lx, %08lx, %08lx\n",
438 page_nr, (new_val).pte_low, flags);
439 BUG();
440 }
442 return ret;
443 }
445 static inline int
446 HYPERVISOR_event_channel_op(
447 void *op)
448 {
449 int ret;
450 unsigned long ignore;
451 __asm__ __volatile__ (
452 TRAP_INSTR
453 : "=a" (ret), "=b" (ignore)
454 : "0" (__HYPERVISOR_event_channel_op), "1" (op)
455 : "memory" );
457 return ret;
458 }
460 static inline int
461 HYPERVISOR_xen_version(
462 int cmd)
463 {
464 int ret;
465 unsigned long ignore;
467 __asm__ __volatile__ (
468 TRAP_INSTR
469 : "=a" (ret), "=b" (ignore)
470 : "0" (__HYPERVISOR_xen_version), "1" (cmd)
471 : "memory" );
473 return ret;
474 }
476 static inline int
477 HYPERVISOR_console_io(
478 int cmd, int count, char *str)
479 {
480 int ret;
481 unsigned long ign1, ign2, ign3;
482 __asm__ __volatile__ (
483 TRAP_INSTR
484 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
485 : "0" (__HYPERVISOR_console_io), "1" (cmd), "2" (count), "3" (str)
486 : "memory" );
488 return ret;
489 }
491 static inline int
492 HYPERVISOR_physdev_op(
493 void *physdev_op)
494 {
495 int ret;
496 unsigned long ign;
498 __asm__ __volatile__ (
499 TRAP_INSTR
500 : "=a" (ret), "=b" (ign)
501 : "0" (__HYPERVISOR_physdev_op), "1" (physdev_op)
502 : "memory" );
504 return ret;
505 }
507 static inline int
508 HYPERVISOR_grant_table_op(
509 unsigned int cmd, void *uop, unsigned int count)
510 {
511 int ret;
512 unsigned long ign1, ign2, ign3;
514 __asm__ __volatile__ (
515 TRAP_INSTR
516 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
517 : "0" (__HYPERVISOR_grant_table_op), "1" (cmd), "2" (count), "3" (uop)
518 : "memory" );
520 return ret;
521 }
523 static inline int
524 HYPERVISOR_update_va_mapping_otherdomain(
525 unsigned long page_nr, pte_t new_val, unsigned long flags, domid_t domid)
526 {
527 int ret;
528 unsigned long ign1, ign2, ign3, ign4;
530 __asm__ __volatile__ (
531 TRAP_INSTR
532 : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
533 : "0" (__HYPERVISOR_update_va_mapping_otherdomain),
534 "1" (page_nr), "2" ((new_val).pte_low), "3" (flags), "4" (domid) :
535 "memory" );
537 return ret;
538 }
540 static inline int
541 HYPERVISOR_vm_assist(
542 unsigned int cmd, unsigned int type)
543 {
544 int ret;
545 unsigned long ign1, ign2;
547 __asm__ __volatile__ (
548 TRAP_INSTR
549 : "=a" (ret), "=b" (ign1), "=c" (ign2)
550 : "0" (__HYPERVISOR_vm_assist), "1" (cmd), "2" (type)
551 : "memory" );
553 return ret;
554 }
556 #endif /* __HYPERVISOR_H__ */