Home | History | Annotate | Line # | Download | only in include
hypervisor.h revision 1.6
      1 /*	$NetBSD: hypervisor.h,v 1.6 2004/04/25 18:30:55 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_console_write(const char *str, int count)
    102 {
    103     int ret;
    104     __asm__ __volatile__ (
    105         TRAP_INSTR
    106         : "=a" (ret) : "0" (__HYPERVISOR_console_write),
    107         "b" (str), "c" (count) : "memory" );
    108 
    109 
    110     return ret;
    111 }
    112 
    113 static inline int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
    114 {
    115     int ret;
    116     __asm__ __volatile__ (
    117         TRAP_INSTR
    118         : "=a" (ret) : "0" (__HYPERVISOR_set_gdt),
    119         "b" (frame_list), "c" (entries) : "memory" );
    120 
    121 
    122     return ret;
    123 }
    124 
    125 static inline int HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
    126 {
    127     int ret;
    128     __asm__ __volatile__ (
    129         TRAP_INSTR
    130         : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
    131         "b" (ss), "c" (esp) : "memory" );
    132 
    133     return ret;
    134 }
    135 
    136 static inline int HYPERVISOR_set_callbacks(
    137     unsigned long event_selector, unsigned long event_address,
    138     unsigned long failsafe_selector, unsigned long failsafe_address)
    139 {
    140     int ret;
    141     __asm__ __volatile__ (
    142         TRAP_INSTR
    143         : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
    144         "b" (event_selector), "c" (event_address),
    145         "d" (failsafe_selector), "S" (failsafe_address) : "memory" );
    146 
    147     return ret;
    148 }
    149 
    150 static inline int HYPERVISOR_net_io_op(netop_t *op)
    151 {
    152     int ret;
    153     __asm__ __volatile__ (
    154         TRAP_INSTR
    155         : "=a" (ret) : "0" (__HYPERVISOR_net_io_op),
    156         "b" (op) : "memory" );
    157 
    158     return ret;
    159 }
    160 
    161 static inline int HYPERVISOR_fpu_taskswitch(void)
    162 {
    163     int ret;
    164     __asm__ __volatile__ (
    165         TRAP_INSTR
    166         : "=a" (ret) : "0" (__HYPERVISOR_fpu_taskswitch) : "memory" );
    167 
    168     return ret;
    169 }
    170 
    171 static inline int HYPERVISOR_yield(void)
    172 {
    173     int ret;
    174     __asm__ __volatile__ (
    175         TRAP_INSTR
    176         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    177         "b" (SCHEDOP_yield) : "memory" );
    178 
    179     return ret;
    180 }
    181 
    182 static inline int HYPERVISOR_exit(void)
    183 {
    184     int ret;
    185     __asm__ __volatile__ (
    186         TRAP_INSTR
    187         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    188         "b" (SCHEDOP_exit) : "memory" );
    189 
    190     return ret;
    191 }
    192 
    193 static inline int HYPERVISOR_stop(unsigned long srec)
    194 {
    195     int ret;
    196     /* NB. On suspend, control software expects a suspend record in %esi. */
    197     __asm__ __volatile__ (
    198         TRAP_INSTR
    199         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    200         "b" (SCHEDOP_stop), "S" (srec) : "memory" );
    201 
    202     return ret;
    203 }
    204 
    205 static inline int HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
    206 {
    207     int ret;
    208     dom0_op->interface_version = DOM0_INTERFACE_VERSION;
    209     __asm__ __volatile__ (
    210         TRAP_INSTR
    211         : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
    212         "b" (dom0_op) : "memory" );
    213 
    214     return ret;
    215 }
    216 
    217 static inline int HYPERVISOR_network_op(void *network_op)
    218 {
    219     int ret;
    220     __asm__ __volatile__ (
    221         TRAP_INSTR
    222         : "=a" (ret) : "0" (__HYPERVISOR_network_op),
    223         "b" (network_op) : "memory" );
    224 
    225     return ret;
    226 }
    227 
    228 static inline int HYPERVISOR_block_io_op(void * block_io_op)
    229 {
    230     int ret;
    231     __asm__ __volatile__ (
    232         TRAP_INSTR
    233         : "=a" (ret) : "0" (__HYPERVISOR_block_io_op),
    234         "b" (block_io_op) : "memory" );
    235 
    236     return ret;
    237 }
    238 
    239 static inline int HYPERVISOR_set_debugreg(int reg, unsigned long value)
    240 {
    241     int ret;
    242     __asm__ __volatile__ (
    243         TRAP_INSTR
    244         : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
    245         "b" (reg), "c" (value) : "memory" );
    246 
    247     return ret;
    248 }
    249 
    250 static inline unsigned long HYPERVISOR_get_debugreg(int reg)
    251 {
    252     unsigned long ret;
    253     __asm__ __volatile__ (
    254         TRAP_INSTR
    255         : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
    256         "b" (reg) : "memory" );
    257 
    258     return ret;
    259 }
    260 
    261 static inline int HYPERVISOR_update_descriptor(
    262     unsigned long pa, unsigned long word1, unsigned long word2)
    263 {
    264     int ret;
    265     __asm__ __volatile__ (
    266         TRAP_INSTR
    267         : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor),
    268         "b" (pa), "c" (word1), "d" (word2) : "memory" );
    269 
    270     return ret;
    271 }
    272 
    273 static inline int HYPERVISOR_set_fast_trap(int idx)
    274 {
    275     int ret;
    276     __asm__ __volatile__ (
    277         TRAP_INSTR
    278         : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap),
    279         "b" (idx) : "memory" );
    280 
    281     return ret;
    282 }
    283 
    284 static inline int HYPERVISOR_dom_mem_op(void *dom_mem_op)
    285 {
    286     int ret;
    287     __asm__ __volatile__ (
    288         TRAP_INSTR
    289         : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
    290         "b" (dom_mem_op) : "memory" );
    291 
    292     return ret;
    293 }
    294 
    295 static inline int HYPERVISOR_multicall(void *call_list, int nr_calls)
    296 {
    297     int ret;
    298     __asm__ __volatile__ (
    299         TRAP_INSTR
    300         : "=a" (ret) : "0" (__HYPERVISOR_multicall),
    301         "b" (call_list), "c" (nr_calls) : "memory" );
    302 
    303     return ret;
    304 }
    305 
    306 static inline long HYPERVISOR_kbd_op(unsigned char op, unsigned char val)
    307 {
    308     int ret;
    309     __asm__ __volatile__ (
    310         TRAP_INSTR
    311         : "=a" (ret) : "0" (__HYPERVISOR_kbd_op),
    312         "b" (op), "c" (val) : "memory" );
    313 
    314     return ret;
    315 }
    316 
    317 static inline int HYPERVISOR_update_va_mapping(
    318     unsigned long page_nr, unsigned long new_val, unsigned long flags)
    319 {
    320     int ret;
    321     __asm__ __volatile__ (
    322         TRAP_INSTR
    323         : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping),
    324         "b" (page_nr), "c" (new_val), "d" (flags) : "memory" );
    325 
    326     if (__predict_false(ret < 0))
    327         panic("Failed update VA mapping: %08lx, %08lx, %08lx",
    328               page_nr, new_val, flags);
    329 
    330     return ret;
    331 }
    332 
    333 #endif /* _XEN_HYPERVISOR_H_ */
    334