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