Home | History | Annotate | Line # | Download | only in include
hypervisor.h revision 1.1.2.1
      1  1.1.2.1  he /*	$NetBSD: hypervisor.h,v 1.1.2.1 2004/05/22 15:58:19 he Exp $	*/
      2      1.1  cl 
      3      1.1  cl /*
      4      1.1  cl  *
      5      1.1  cl  * Communication to/from hypervisor.
      6      1.1  cl  *
      7      1.1  cl  * Copyright (c) 2002-2003, K A Fraser
      8      1.1  cl  *
      9      1.1  cl  * Permission is hereby granted, free of charge, to any person obtaining a copy
     10      1.1  cl  * of this software and associated documentation files (the "Software"), to
     11      1.1  cl  * deal in the Software without restriction, including without limitation the
     12      1.1  cl  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
     13      1.1  cl  * sell copies of the Software, and to permit persons to whom the Software is
     14      1.1  cl  * furnished to do so, subject to the following conditions:
     15      1.1  cl  *
     16      1.1  cl  * The above copyright notice and this permission notice shall be included in
     17      1.1  cl  * all copies or substantial portions of the Software.
     18      1.1  cl  *
     19      1.1  cl  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     20      1.1  cl  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     21      1.1  cl  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     22      1.1  cl  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     23      1.1  cl  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     24      1.1  cl  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     25      1.1  cl  * DEALINGS IN THE SOFTWARE.
     26      1.1  cl  */
     27      1.1  cl 
     28      1.1  cl 
     29      1.1  cl #ifndef _XEN_HYPERVISOR_H_
     30      1.1  cl #define _XEN_HYPERVISOR_H_
     31      1.1  cl 
     32      1.1  cl 
     33  1.1.2.1  he struct hypervisor_attach_args {
     34  1.1.2.1  he 	const char 		*haa_busname;
     35  1.1.2.1  he };
     36  1.1.2.1  he 
     37  1.1.2.1  he struct xencons_attach_args {
     38  1.1.2.1  he 	const char 		*xa_device;
     39      1.1  cl };
     40      1.1  cl 
     41      1.1  cl struct xen_npx_attach_args {
     42  1.1.2.1  he 	const char 		*xa_device;
     43      1.1  cl };
     44      1.1  cl 
     45      1.1  cl 
     46      1.1  cl /* include the hypervisor interface */
     47  1.1.2.1  he #include <sys/systm.h>
     48      1.1  cl #include <machine/hypervisor-ifs/block.h>
     49      1.1  cl #include <machine/hypervisor-ifs/hypervisor-if.h>
     50  1.1.2.1  he #include <machine/hypervisor-ifs/dom0_ops.h>
     51  1.1.2.1  he #include <machine/hypervisor-ifs/network.h>
     52      1.1  cl 
     53      1.1  cl 
     54      1.1  cl /*
     55      1.1  cl  * a placeholder for the start of day information passed up from the hypervisor
     56      1.1  cl  */
     57      1.1  cl union start_info_union
     58      1.1  cl {
     59      1.1  cl     start_info_t start_info;
     60      1.1  cl     char padding[512];
     61      1.1  cl };
     62      1.1  cl extern union start_info_union start_info_union;
     63      1.1  cl #define xen_start_info (start_info_union.start_info)
     64      1.1  cl 
     65      1.1  cl 
     66      1.1  cl /* hypervisor.c */
     67  1.1.2.1  he void do_hypervisor_callback(struct trapframe *regs);
     68      1.1  cl void hypervisor_enable_event(unsigned int ev);
     69      1.1  cl void hypervisor_disable_event(unsigned int ev);
     70      1.1  cl void hypervisor_acknowledge_event(unsigned int ev);
     71      1.1  cl 
     72      1.1  cl /*
     73      1.1  cl  * Assembler stubs for hyper-calls.
     74      1.1  cl  */
     75      1.1  cl 
     76      1.1  cl static inline int HYPERVISOR_set_trap_table(trap_info_t *table)
     77      1.1  cl {
     78      1.1  cl     int ret;
     79      1.1  cl     __asm__ __volatile__ (
     80      1.1  cl         TRAP_INSTR
     81      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table),
     82  1.1.2.1  he         "b" (table) : "memory" );
     83      1.1  cl 
     84      1.1  cl     return ret;
     85      1.1  cl }
     86      1.1  cl 
     87      1.1  cl static inline int HYPERVISOR_mmu_update(mmu_update_t *req, int count)
     88      1.1  cl {
     89      1.1  cl     int ret;
     90      1.1  cl     __asm__ __volatile__ (
     91      1.1  cl         TRAP_INSTR
     92      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_mmu_update),
     93  1.1.2.1  he         "b" (req), "c" (count) : "memory" );
     94  1.1.2.1  he 
     95  1.1.2.1  he     if (__predict_false(ret < 0))
     96  1.1.2.1  he         panic("Failed mmu update: %p, %d", req, count);
     97  1.1.2.1  he 
     98  1.1.2.1  he     return ret;
     99  1.1.2.1  he }
    100  1.1.2.1  he 
    101  1.1.2.1  he static inline int HYPERVISOR_mmu_update_fail_ok(mmu_update_t *req, int count)
    102  1.1.2.1  he {
    103  1.1.2.1  he     int ret;
    104  1.1.2.1  he     __asm__ __volatile__ (
    105  1.1.2.1  he         TRAP_INSTR
    106  1.1.2.1  he         : "=a" (ret) : "0" (__HYPERVISOR_mmu_update),
    107  1.1.2.1  he         "b" (req), "c" (count) : "memory" );
    108      1.1  cl 
    109      1.1  cl     return ret;
    110      1.1  cl }
    111      1.1  cl 
    112      1.1  cl static inline int HYPERVISOR_console_write(const char *str, int count)
    113      1.1  cl {
    114      1.1  cl     int ret;
    115      1.1  cl     __asm__ __volatile__ (
    116      1.1  cl         TRAP_INSTR
    117      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_console_write),
    118  1.1.2.1  he         "b" (str), "c" (count) : "memory" );
    119      1.1  cl 
    120      1.1  cl 
    121      1.1  cl     return ret;
    122      1.1  cl }
    123      1.1  cl 
    124      1.1  cl static inline int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
    125      1.1  cl {
    126      1.1  cl     int ret;
    127      1.1  cl     __asm__ __volatile__ (
    128      1.1  cl         TRAP_INSTR
    129      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_set_gdt),
    130  1.1.2.1  he         "b" (frame_list), "c" (entries) : "memory" );
    131      1.1  cl 
    132      1.1  cl 
    133      1.1  cl     return ret;
    134      1.1  cl }
    135      1.1  cl 
    136      1.1  cl static inline int HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
    137      1.1  cl {
    138      1.1  cl     int ret;
    139      1.1  cl     __asm__ __volatile__ (
    140      1.1  cl         TRAP_INSTR
    141      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_stack_switch),
    142      1.1  cl         "b" (ss), "c" (esp) : "memory" );
    143      1.1  cl 
    144      1.1  cl     return ret;
    145      1.1  cl }
    146      1.1  cl 
    147      1.1  cl static inline int HYPERVISOR_set_callbacks(
    148      1.1  cl     unsigned long event_selector, unsigned long event_address,
    149      1.1  cl     unsigned long failsafe_selector, unsigned long failsafe_address)
    150      1.1  cl {
    151      1.1  cl     int ret;
    152      1.1  cl     __asm__ __volatile__ (
    153      1.1  cl         TRAP_INSTR
    154      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks),
    155      1.1  cl         "b" (event_selector), "c" (event_address),
    156      1.1  cl         "d" (failsafe_selector), "S" (failsafe_address) : "memory" );
    157      1.1  cl 
    158      1.1  cl     return ret;
    159      1.1  cl }
    160      1.1  cl 
    161      1.1  cl static inline int HYPERVISOR_net_io_op(netop_t *op)
    162      1.1  cl {
    163      1.1  cl     int ret;
    164      1.1  cl     __asm__ __volatile__ (
    165      1.1  cl         TRAP_INSTR
    166      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_net_io_op),
    167  1.1.2.1  he         "b" (op) : "memory" );
    168      1.1  cl 
    169      1.1  cl     return ret;
    170      1.1  cl }
    171      1.1  cl 
    172      1.1  cl static inline int HYPERVISOR_fpu_taskswitch(void)
    173      1.1  cl {
    174      1.1  cl     int ret;
    175      1.1  cl     __asm__ __volatile__ (
    176      1.1  cl         TRAP_INSTR
    177  1.1.2.1  he         : "=a" (ret) : "0" (__HYPERVISOR_fpu_taskswitch) : "memory" );
    178      1.1  cl 
    179      1.1  cl     return ret;
    180      1.1  cl }
    181      1.1  cl 
    182      1.1  cl static inline int HYPERVISOR_yield(void)
    183      1.1  cl {
    184      1.1  cl     int ret;
    185      1.1  cl     __asm__ __volatile__ (
    186      1.1  cl         TRAP_INSTR
    187      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    188  1.1.2.1  he         "b" (SCHEDOP_yield) : "memory" );
    189      1.1  cl 
    190      1.1  cl     return ret;
    191      1.1  cl }
    192      1.1  cl 
    193      1.1  cl static inline int HYPERVISOR_exit(void)
    194      1.1  cl {
    195      1.1  cl     int ret;
    196      1.1  cl     __asm__ __volatile__ (
    197      1.1  cl         TRAP_INSTR
    198      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    199  1.1.2.1  he         "b" (SCHEDOP_exit) : "memory" );
    200      1.1  cl 
    201      1.1  cl     return ret;
    202      1.1  cl }
    203      1.1  cl 
    204  1.1.2.1  he static inline int HYPERVISOR_stop(unsigned long srec)
    205      1.1  cl {
    206      1.1  cl     int ret;
    207  1.1.2.1  he     /* NB. On suspend, control software expects a suspend record in %esi. */
    208      1.1  cl     __asm__ __volatile__ (
    209      1.1  cl         TRAP_INSTR
    210      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_sched_op),
    211  1.1.2.1  he         "b" (SCHEDOP_stop), "S" (srec) : "memory" );
    212      1.1  cl 
    213      1.1  cl     return ret;
    214      1.1  cl }
    215      1.1  cl 
    216  1.1.2.1  he static inline int HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
    217      1.1  cl {
    218      1.1  cl     int ret;
    219  1.1.2.1  he     dom0_op->interface_version = DOM0_INTERFACE_VERSION;
    220      1.1  cl     __asm__ __volatile__ (
    221      1.1  cl         TRAP_INSTR
    222      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
    223      1.1  cl         "b" (dom0_op) : "memory" );
    224      1.1  cl 
    225      1.1  cl     return ret;
    226      1.1  cl }
    227      1.1  cl 
    228      1.1  cl static inline int HYPERVISOR_network_op(void *network_op)
    229      1.1  cl {
    230      1.1  cl     int ret;
    231      1.1  cl     __asm__ __volatile__ (
    232      1.1  cl         TRAP_INSTR
    233      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_network_op),
    234  1.1.2.1  he         "b" (network_op) : "memory" );
    235      1.1  cl 
    236      1.1  cl     return ret;
    237      1.1  cl }
    238      1.1  cl 
    239  1.1.2.1  he static inline int HYPERVISOR_block_io_op(void * block_io_op)
    240      1.1  cl {
    241      1.1  cl     int ret;
    242      1.1  cl     __asm__ __volatile__ (
    243      1.1  cl         TRAP_INSTR
    244      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_block_io_op),
    245  1.1.2.1  he         "b" (block_io_op) : "memory" );
    246      1.1  cl 
    247      1.1  cl     return ret;
    248      1.1  cl }
    249      1.1  cl 
    250      1.1  cl static inline int HYPERVISOR_set_debugreg(int reg, unsigned long value)
    251      1.1  cl {
    252      1.1  cl     int ret;
    253      1.1  cl     __asm__ __volatile__ (
    254      1.1  cl         TRAP_INSTR
    255      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
    256  1.1.2.1  he         "b" (reg), "c" (value) : "memory" );
    257      1.1  cl 
    258      1.1  cl     return ret;
    259      1.1  cl }
    260      1.1  cl 
    261      1.1  cl static inline unsigned long HYPERVISOR_get_debugreg(int reg)
    262      1.1  cl {
    263      1.1  cl     unsigned long ret;
    264      1.1  cl     __asm__ __volatile__ (
    265      1.1  cl         TRAP_INSTR
    266      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
    267  1.1.2.1  he         "b" (reg) : "memory" );
    268      1.1  cl 
    269      1.1  cl     return ret;
    270      1.1  cl }
    271      1.1  cl 
    272      1.1  cl static inline int HYPERVISOR_update_descriptor(
    273      1.1  cl     unsigned long pa, unsigned long word1, unsigned long word2)
    274      1.1  cl {
    275      1.1  cl     int ret;
    276      1.1  cl     __asm__ __volatile__ (
    277      1.1  cl         TRAP_INSTR
    278      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor),
    279  1.1.2.1  he         "b" (pa), "c" (word1), "d" (word2) : "memory" );
    280      1.1  cl 
    281      1.1  cl     return ret;
    282      1.1  cl }
    283      1.1  cl 
    284      1.1  cl static inline int HYPERVISOR_set_fast_trap(int idx)
    285      1.1  cl {
    286      1.1  cl     int ret;
    287      1.1  cl     __asm__ __volatile__ (
    288      1.1  cl         TRAP_INSTR
    289      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap),
    290  1.1.2.1  he         "b" (idx) : "memory" );
    291      1.1  cl 
    292      1.1  cl     return ret;
    293      1.1  cl }
    294      1.1  cl 
    295      1.1  cl static inline int HYPERVISOR_dom_mem_op(void *dom_mem_op)
    296      1.1  cl {
    297      1.1  cl     int ret;
    298      1.1  cl     __asm__ __volatile__ (
    299      1.1  cl         TRAP_INSTR
    300      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
    301      1.1  cl         "b" (dom_mem_op) : "memory" );
    302      1.1  cl 
    303      1.1  cl     return ret;
    304      1.1  cl }
    305      1.1  cl 
    306      1.1  cl static inline int HYPERVISOR_multicall(void *call_list, int nr_calls)
    307      1.1  cl {
    308      1.1  cl     int ret;
    309      1.1  cl     __asm__ __volatile__ (
    310      1.1  cl         TRAP_INSTR
    311      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_multicall),
    312      1.1  cl         "b" (call_list), "c" (nr_calls) : "memory" );
    313      1.1  cl 
    314      1.1  cl     return ret;
    315      1.1  cl }
    316      1.1  cl 
    317      1.1  cl static inline long HYPERVISOR_kbd_op(unsigned char op, unsigned char val)
    318      1.1  cl {
    319      1.1  cl     int ret;
    320      1.1  cl     __asm__ __volatile__ (
    321      1.1  cl         TRAP_INSTR
    322      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_kbd_op),
    323  1.1.2.1  he         "b" (op), "c" (val) : "memory" );
    324      1.1  cl 
    325      1.1  cl     return ret;
    326      1.1  cl }
    327      1.1  cl 
    328      1.1  cl static inline int HYPERVISOR_update_va_mapping(
    329      1.1  cl     unsigned long page_nr, unsigned long new_val, unsigned long flags)
    330      1.1  cl {
    331      1.1  cl     int ret;
    332      1.1  cl     __asm__ __volatile__ (
    333      1.1  cl         TRAP_INSTR
    334      1.1  cl         : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping),
    335  1.1.2.1  he         "b" (page_nr), "c" (new_val), "d" (flags) : "memory" );
    336  1.1.2.1  he 
    337  1.1.2.1  he     if (__predict_false(ret < 0))
    338  1.1.2.1  he         panic("Failed update VA mapping: %08lx, %08lx, %08lx",
    339  1.1.2.1  he               page_nr, new_val, flags);
    340      1.1  cl 
    341      1.1  cl     return ret;
    342      1.1  cl }
    343      1.1  cl 
    344      1.1  cl #endif /* _XEN_HYPERVISOR_H_ */
    345