Home | History | Annotate | Line # | Download | only in include
hypervisor.h revision 1.21
      1  1.21  bouyer /*	$NetBSD: hypervisor.h,v 1.21 2006/09/24 15:30:14 bouyer Exp $	*/
      2  1.18  bouyer 
      3  1.18  bouyer /*
      4  1.18  bouyer  * Copyright (c) 2006 Manuel Bouyer.
      5  1.18  bouyer  *
      6  1.18  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.18  bouyer  * modification, are permitted provided that the following conditions
      8  1.18  bouyer  * are met:
      9  1.18  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.18  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.18  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.18  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.18  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.18  bouyer  * 3. All advertising materials mentioning features or use of this software
     15  1.18  bouyer  *    must display the following acknowledgement:
     16  1.18  bouyer  *	This product includes software developed by Manuel Bouyer.
     17  1.18  bouyer  * 4. The name of the author may not be used to endorse or promote products
     18  1.18  bouyer  *    derived from this software without specific prior written permission.
     19  1.18  bouyer  *
     20  1.18  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.18  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.18  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.18  bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.18  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.18  bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.18  bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.18  bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.18  bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.18  bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.18  bouyer  *
     31  1.18  bouyer  */
     32   1.1      cl 
     33   1.1      cl /*
     34   1.1      cl  *
     35   1.1      cl  * Communication to/from hypervisor.
     36   1.1      cl  *
     37  1.10  bouyer  * Copyright (c) 2002-2004, K A Fraser
     38   1.1      cl  *
     39   1.1      cl  * Permission is hereby granted, free of charge, to any person obtaining a copy
     40  1.10  bouyer  * of this source file (the "Software"), to deal in the Software without
     41  1.10  bouyer  * restriction, including without limitation the rights to use, copy, modify,
     42  1.10  bouyer  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
     43  1.10  bouyer  * and to permit persons to whom the Software is furnished to do so, subject to
     44  1.10  bouyer  * the following conditions:
     45   1.1      cl  *
     46   1.1      cl  * The above copyright notice and this permission notice shall be included in
     47   1.1      cl  * all copies or substantial portions of the Software.
     48   1.1      cl  *
     49  1.10  bouyer  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     50  1.10  bouyer  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     51  1.10  bouyer  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     52  1.10  bouyer  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     53  1.10  bouyer  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     54  1.10  bouyer  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     55  1.10  bouyer  * IN THE SOFTWARE.
     56   1.1      cl  */
     57   1.1      cl 
     58   1.1      cl 
     59   1.1      cl #ifndef _XEN_HYPERVISOR_H_
     60   1.1      cl #define _XEN_HYPERVISOR_H_
     61   1.1      cl 
     62  1.18  bouyer #include "opt_xen.h"
     63  1.18  bouyer 
     64   1.1      cl 
     65   1.4      cl struct hypervisor_attach_args {
     66   1.4      cl 	const char 		*haa_busname;
     67   1.4      cl };
     68   1.4      cl 
     69   1.5      cl struct xencons_attach_args {
     70   1.4      cl 	const char 		*xa_device;
     71   1.1      cl };
     72   1.1      cl 
     73   1.1      cl struct xen_npx_attach_args {
     74   1.4      cl 	const char 		*xa_device;
     75   1.1      cl };
     76   1.1      cl 
     77   1.1      cl 
     78  1.10  bouyer #define	u8 uint8_t
     79   1.8      cl #define	u16 uint16_t
     80   1.8      cl #define	u32 uint32_t
     81   1.8      cl #define	u64 uint64_t
     82  1.10  bouyer #define	s8 int8_t
     83  1.10  bouyer #define	s16 int16_t
     84  1.10  bouyer #define	s32 int32_t
     85  1.10  bouyer #define	s64 int64_t
     86  1.10  bouyer 
     87  1.18  bouyer #ifdef XEN3
     88  1.18  bouyer #include <machine/xen3-public/xen.h>
     89  1.18  bouyer #include <machine/xen3-public/sched.h>
     90  1.18  bouyer #include <machine/xen3-public/dom0_ops.h>
     91  1.18  bouyer #include <machine/xen3-public/event_channel.h>
     92  1.18  bouyer #include <machine/xen3-public/physdev.h>
     93  1.18  bouyer #include <machine/xen3-public/memory.h>
     94  1.18  bouyer #include <machine/xen3-public/io/netif.h>
     95  1.18  bouyer #include <machine/xen3-public/io/blkif.h>
     96  1.18  bouyer #else
     97  1.10  bouyer #include <machine/xen-public/xen.h>
     98  1.10  bouyer #include <machine/xen-public/dom0_ops.h>
     99  1.10  bouyer #include <machine/xen-public/event_channel.h>
    100  1.10  bouyer #include <machine/xen-public/physdev.h>
    101  1.10  bouyer #include <machine/xen-public/io/domain_controller.h>
    102  1.10  bouyer #include <machine/xen-public/io/netif.h>
    103  1.10  bouyer #include <machine/xen-public/io/blkif.h>
    104  1.18  bouyer #endif
    105   1.8      cl 
    106  1.10  bouyer #undef u8
    107   1.8      cl #undef u16
    108   1.8      cl #undef u32
    109   1.8      cl #undef u64
    110  1.10  bouyer #undef s8
    111  1.10  bouyer #undef s16
    112  1.10  bouyer #undef s32
    113  1.10  bouyer #undef s64
    114   1.1      cl 
    115   1.1      cl 
    116   1.1      cl /*
    117   1.1      cl  * a placeholder for the start of day information passed up from the hypervisor
    118   1.1      cl  */
    119   1.1      cl union start_info_union
    120   1.1      cl {
    121   1.1      cl     start_info_t start_info;
    122   1.1      cl     char padding[512];
    123   1.1      cl };
    124   1.1      cl extern union start_info_union start_info_union;
    125   1.1      cl #define xen_start_info (start_info_union.start_info)
    126   1.1      cl 
    127  1.18  bouyer /* For use in guest OSes. */
    128  1.18  bouyer volatile extern shared_info_t *HYPERVISOR_shared_info;
    129   1.1      cl 
    130   1.1      cl /* hypervisor.c */
    131  1.10  bouyer struct intrframe;
    132  1.10  bouyer void do_hypervisor_callback(struct intrframe *regs);
    133  1.11  bouyer void hypervisor_enable_event(unsigned int);
    134  1.10  bouyer 
    135  1.10  bouyer /* hypervisor_machdep.c */
    136  1.10  bouyer void hypervisor_unmask_event(unsigned int);
    137  1.10  bouyer void hypervisor_mask_event(unsigned int);
    138  1.10  bouyer void hypervisor_clear_event(unsigned int);
    139  1.12  bouyer void hypervisor_enable_ipl(unsigned int);
    140  1.13  bouyer void hypervisor_set_ipending(u_int32_t, int, int);
    141   1.1      cl 
    142   1.1      cl /*
    143   1.1      cl  * Assembler stubs for hyper-calls.
    144   1.1      cl  */
    145   1.1      cl 
    146  1.21  bouyer #define _hypercall(name, input_const, output_const) \
    147  1.21  bouyer 	__asm volatile ( \
    148  1.21  bouyer 	    TRAP_INSTR \
    149  1.21  bouyer 	    : output_const \
    150  1.21  bouyer 	    : "0" (name), input_const \
    151  1.21  bouyer 	    : "memory" )
    152  1.21  bouyer 
    153  1.21  bouyer #define _harg(...) __VA_ARGS__
    154  1.21  bouyer 
    155  1.21  bouyer 
    156  1.19   perry static __inline int
    157  1.10  bouyer HYPERVISOR_set_trap_table(trap_info_t *table)
    158   1.1      cl {
    159   1.1      cl     int ret;
    160  1.10  bouyer     unsigned long ign1;
    161  1.10  bouyer 
    162  1.21  bouyer 	_hypercall(__HYPERVISOR_set_trap_table, _harg("1" (table)),
    163  1.21  bouyer 	    _harg("=a" (ret), "=b" (ign1)));
    164   1.1      cl 
    165   1.1      cl     return ret;
    166   1.1      cl }
    167   1.1      cl 
    168  1.19   perry static __inline int
    169  1.10  bouyer HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
    170  1.10  bouyer {
    171  1.10  bouyer     int ret;
    172  1.10  bouyer     unsigned long ign1, ign2;
    173  1.10  bouyer 
    174  1.21  bouyer     _hypercall(__HYPERVISOR_set_gdt, _harg("1" (frame_list), "2" (entries)),
    175  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    176   1.2      cl 
    177   1.1      cl     return ret;
    178   1.1      cl }
    179   1.1      cl 
    180  1.19   perry static __inline int
    181  1.10  bouyer HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
    182   1.7      cl {
    183   1.7      cl     int ret;
    184  1.10  bouyer     unsigned long ign1, ign2;
    185  1.10  bouyer 
    186  1.21  bouyer     _hypercall(__HYPERVISOR_stack_switch, _harg("1" (ss), "2" (esp)),
    187  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    188   1.7      cl 
    189   1.7      cl     return ret;
    190   1.7      cl }
    191   1.7      cl 
    192  1.19   perry static __inline int
    193  1.10  bouyer HYPERVISOR_set_callbacks(
    194  1.10  bouyer     unsigned long event_selector, unsigned long event_address,
    195  1.10  bouyer     unsigned long failsafe_selector, unsigned long failsafe_address)
    196   1.1      cl {
    197   1.1      cl     int ret;
    198  1.10  bouyer     unsigned long ign1, ign2, ign3, ign4;
    199  1.10  bouyer 
    200  1.21  bouyer     _hypercall(__HYPERVISOR_set_callbacks,
    201  1.21  bouyer 	_harg("1" (event_selector),"2" (event_address),
    202  1.21  bouyer 	    "3" (failsafe_selector), "4" (failsafe_address)),
    203  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
    204   1.1      cl 
    205  1.10  bouyer     return ret;
    206  1.10  bouyer }
    207  1.10  bouyer 
    208  1.19   perry static __inline int
    209  1.18  bouyer HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
    210  1.10  bouyer {
    211  1.10  bouyer     int ret;
    212  1.18  bouyer     unsigned long ign1;
    213  1.18  bouyer 
    214  1.18  bouyer     dom0_op->interface_version = DOM0_INTERFACE_VERSION;
    215  1.21  bouyer     _hypercall(__HYPERVISOR_dom0_op, _harg("1" (dom0_op)),
    216  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1)));
    217   1.1      cl 
    218   1.1      cl     return ret;
    219   1.1      cl }
    220   1.1      cl 
    221  1.19   perry static __inline int
    222  1.18  bouyer HYPERVISOR_set_debugreg(int reg, unsigned long value)
    223   1.1      cl {
    224   1.1      cl     int ret;
    225  1.18  bouyer     unsigned long ign1, ign2;
    226  1.18  bouyer 
    227  1.21  bouyer     _hypercall(__HYPERVISOR_set_debugreg, _harg("1" (reg), "2" (value)),
    228  1.21  bouyer 	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    229  1.18  bouyer 
    230  1.18  bouyer     return ret;
    231  1.18  bouyer }
    232  1.18  bouyer 
    233  1.19   perry static __inline unsigned long
    234  1.18  bouyer HYPERVISOR_get_debugreg(int reg)
    235  1.18  bouyer {
    236  1.18  bouyer     unsigned long ret;
    237  1.10  bouyer     unsigned long ign1;
    238  1.10  bouyer 
    239  1.21  bouyer     _hypercall(__HYPERVISOR_get_debugreg, _harg("1" (reg)),
    240  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1)));
    241  1.10  bouyer 
    242  1.10  bouyer     return ret;
    243  1.10  bouyer }
    244  1.10  bouyer 
    245  1.18  bouyer #ifdef XEN3
    246  1.19   perry static __inline int
    247  1.18  bouyer HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count,
    248  1.18  bouyer     domid_t domid)
    249  1.10  bouyer {
    250  1.10  bouyer     int ret;
    251  1.18  bouyer     unsigned long ign1, ign2, ign3, ign4;
    252   1.1      cl 
    253  1.21  bouyer     _hypercall(__HYPERVISOR_mmu_update,
    254  1.21  bouyer 	_harg("1" (req), "2" (count), "3" (success_count), "4" (domid)),
    255  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
    256   1.1      cl 
    257   1.1      cl     return ret;
    258   1.1      cl }
    259   1.1      cl 
    260  1.19   perry static __inline int
    261  1.18  bouyer HYPERVISOR_mmuext_op(struct mmuext_op *op, int count, int *success_count,
    262  1.18  bouyer     domid_t domid)
    263   1.1      cl {
    264   1.1      cl     int ret;
    265  1.18  bouyer     unsigned long ign1, ign2, ign3, ign4;
    266  1.18  bouyer 
    267  1.21  bouyer     _hypercall(__HYPERVISOR_mmuext_op,
    268  1.21  bouyer 	_harg("1" (op), "2" (count), "3" (success_count), "4" (domid)),
    269  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
    270  1.18  bouyer 
    271  1.18  bouyer     return ret;
    272  1.18  bouyer }
    273  1.18  bouyer 
    274  1.18  bouyer #if 0
    275  1.19   perry static __inline int
    276  1.18  bouyer HYPERVISOR_fpu_taskswitch(int set)
    277  1.18  bouyer {
    278  1.18  bouyer     long ret;
    279  1.18  bouyer     long ign1;
    280  1.21  bouyer 
    281  1.21  bouyer     _hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (set)),
    282  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1)));
    283  1.10  bouyer 
    284  1.18  bouyer     return ret;
    285  1.18  bouyer }
    286  1.18  bouyer #else /* 0 */
    287  1.18  bouyer /* Xen2 compat: always i38HYPERVISOR_fpu_taskswitch(1) */
    288  1.19   perry static __inline int
    289  1.18  bouyer HYPERVISOR_fpu_taskswitch(void)
    290  1.18  bouyer {
    291  1.18  bouyer     long ret;
    292  1.18  bouyer     long ign1;
    293  1.21  bouyer     _hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (1)),
    294  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1)));
    295   1.1      cl 
    296   1.1      cl     return ret;
    297   1.1      cl }
    298  1.18  bouyer #endif /* 0 */
    299   1.1      cl 
    300  1.19   perry static __inline int
    301  1.18  bouyer HYPERVISOR_update_descriptor(uint64_t ma, uint32_t word1, uint32_t word2)
    302   1.1      cl {
    303   1.1      cl     int ret;
    304  1.18  bouyer     unsigned long ign1, ign2, ign3, ign4;
    305  1.18  bouyer     int ma1 = ma & 0xffffffff;
    306  1.18  bouyer     int ma2 = (ma >> 32) & 0xffffffff;
    307  1.10  bouyer 
    308  1.21  bouyer     _hypercall(__HYPERVISOR_update_descriptor,
    309  1.21  bouyer 	_harg("1" (ma1), "2" (ma2), "3" (word1), "4" (word2)),
    310  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
    311   1.1      cl 
    312   1.1      cl     return ret;
    313   1.1      cl }
    314   1.1      cl 
    315  1.19   perry static __inline int
    316  1.18  bouyer HYPERVISOR_memory_op(unsigned int cmd, void *arg)
    317   1.1      cl {
    318   1.1      cl     int ret;
    319  1.10  bouyer     unsigned long ign1, ign2;
    320  1.10  bouyer 
    321  1.21  bouyer     _hypercall(__HYPERVISOR_memory_op, _harg("1" (cmd), "2" (arg)),
    322  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    323  1.18  bouyer 
    324  1.18  bouyer     return ret;
    325  1.18  bouyer }
    326  1.18  bouyer 
    327  1.19   perry static __inline int
    328  1.18  bouyer HYPERVISOR_update_va_mapping(unsigned long page_nr, unsigned long new_val,
    329  1.18  bouyer     unsigned long flags)
    330  1.18  bouyer {
    331  1.18  bouyer     int ret;
    332  1.18  bouyer     unsigned long ign1, ign2, ign3, ign4;
    333  1.18  bouyer 
    334  1.21  bouyer     _hypercall(__HYPERVISOR_update_va_mapping,
    335  1.21  bouyer 	_harg("1" (page_nr), "2" (new_val), "3" (0), "4" (flags)),
    336  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
    337  1.18  bouyer 
    338  1.18  bouyer #ifdef notdef
    339  1.18  bouyer     if (__predict_false(ret < 0))
    340  1.18  bouyer         panic("Failed update VA mapping: %08lx, %08lx, %08lx",
    341  1.18  bouyer               page_nr, new_val, flags);
    342  1.18  bouyer #endif
    343   1.1      cl 
    344   1.1      cl     return ret;
    345   1.1      cl }
    346   1.1      cl 
    347  1.19   perry static __inline int
    348  1.18  bouyer HYPERVISOR_xen_version(int cmd, void *arg)
    349   1.1      cl {
    350   1.1      cl     int ret;
    351  1.10  bouyer     unsigned long ign1, ign2;
    352  1.10  bouyer 
    353  1.21  bouyer     _hypercall(__HYPERVISOR_xen_version, _harg("1" (cmd), "2" (arg)),
    354  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    355   1.1      cl 
    356   1.1      cl     return ret;
    357   1.1      cl }
    358   1.1      cl 
    359  1.19   perry static __inline int
    360  1.18  bouyer HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
    361   1.1      cl {
    362   1.1      cl     int ret;
    363  1.18  bouyer     unsigned long ign1, ign2, ign3;
    364  1.10  bouyer 
    365  1.21  bouyer     _hypercall(__HYPERVISOR_grant_table_op,
    366  1.21  bouyer 	_harg("1" (cmd), "2" (uop), "3" (count)),
    367  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
    368   1.1      cl 
    369   1.1      cl     return ret;
    370   1.1      cl }
    371   1.1      cl 
    372  1.19   perry static __inline int
    373  1.18  bouyer HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr,
    374  1.18  bouyer     unsigned long new_val, unsigned long flags, domid_t domid)
    375   1.1      cl {
    376   1.1      cl     int ret;
    377  1.18  bouyer     unsigned long ign1, ign2, ign3, ign4, ign5;
    378  1.18  bouyer 
    379  1.21  bouyer     _hypercall(__HYPERVISOR_update_va_mapping_otherdomain,
    380  1.21  bouyer 	_harg("1" (page_nr), "2" (new_val), "3" (0), "4" (flags), "5" (domid)),
    381  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
    382  1.21  bouyer 	    "=D" (ign5)));
    383  1.21  bouyer 
    384  1.18  bouyer     return ret;
    385  1.18  bouyer }
    386  1.18  bouyer 
    387  1.19   perry static __inline int
    388  1.18  bouyer HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
    389  1.18  bouyer {
    390  1.18  bouyer     long ret;
    391  1.18  bouyer     unsigned long ign1, ign2, ign3;
    392  1.18  bouyer 
    393  1.21  bouyer     _hypercall(__HYPERVISOR_vcpu_op,
    394  1.21  bouyer 	_harg("1" (cmd), "2" (vcpuid), "3" (extra_args)),
    395  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
    396  1.18  bouyer 
    397  1.18  bouyer     return ret;
    398  1.18  bouyer }
    399  1.18  bouyer 
    400  1.19   perry static __inline long
    401  1.18  bouyer HYPERVISOR_yield(void)
    402  1.18  bouyer {
    403  1.18  bouyer     long ret;
    404  1.10  bouyer     unsigned long ign1, ign2;
    405  1.10  bouyer 
    406  1.21  bouyer     _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_yield), "2" (0)),
    407  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    408  1.18  bouyer 
    409  1.18  bouyer     return ret;
    410  1.18  bouyer }
    411  1.18  bouyer 
    412  1.19   perry static __inline long
    413  1.18  bouyer HYPERVISOR_block(void)
    414  1.18  bouyer {
    415  1.18  bouyer     long ret;
    416  1.18  bouyer     unsigned long ign1, ign2;
    417  1.18  bouyer 
    418  1.21  bouyer     _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_block), "2" (0)),
    419  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    420   1.1      cl 
    421   1.1      cl     return ret;
    422   1.1      cl }
    423   1.1      cl 
    424  1.19   perry static __inline long
    425  1.18  bouyer HYPERVISOR_shutdown(void)
    426  1.18  bouyer {
    427  1.18  bouyer     long ret;
    428  1.18  bouyer     unsigned long ign1, ign2;
    429  1.18  bouyer 
    430  1.21  bouyer     _hypercall(__HYPERVISOR_sched_op,
    431  1.21  bouyer 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_poweroff)),
    432  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    433  1.18  bouyer 
    434  1.18  bouyer     return ret;
    435  1.18  bouyer }
    436  1.18  bouyer 
    437  1.19   perry static __inline long
    438  1.18  bouyer HYPERVISOR_reboot(void)
    439  1.18  bouyer {
    440  1.18  bouyer     long ret;
    441  1.18  bouyer     unsigned long ign1, ign2;
    442  1.18  bouyer 
    443  1.21  bouyer     _hypercall(__HYPERVISOR_sched_op,
    444  1.21  bouyer 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_reboot)),
    445  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    446  1.18  bouyer 
    447  1.18  bouyer     return ret;
    448  1.18  bouyer }
    449  1.18  bouyer 
    450  1.19   perry static __inline long
    451  1.18  bouyer HYPERVISOR_suspend(unsigned long srec)
    452  1.18  bouyer {
    453  1.18  bouyer     long ret;
    454  1.18  bouyer     unsigned long ign1, ign2, ign3;
    455  1.18  bouyer 
    456  1.21  bouyer     _hypercall(__HYPERVISOR_sched_op,
    457  1.21  bouyer 	_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_suspend), "3" (srec)),
    458  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
    459  1.18  bouyer 
    460  1.18  bouyer     return ret;
    461  1.18  bouyer }
    462  1.18  bouyer 
    463  1.19   perry static __inline long
    464  1.18  bouyer HYPERVISOR_set_timer_op(uint64_t timeout)
    465   1.1      cl {
    466  1.18  bouyer     long ret;
    467  1.18  bouyer     unsigned long timeout_hi = (unsigned long)(timeout>>32);
    468  1.18  bouyer     unsigned long timeout_lo = (unsigned long)timeout;
    469  1.18  bouyer     unsigned long ign1, ign2;
    470  1.10  bouyer 
    471  1.21  bouyer     _hypercall(__HYPERVISOR_set_timer_op,
    472  1.21  bouyer 	 _harg("1" (timeout_lo), "2" (timeout_hi)),
    473  1.21  bouyer 	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    474  1.18  bouyer 
    475  1.18  bouyer     return ret;
    476  1.18  bouyer }
    477  1.21  bouyer #else /* !XEN3 */
    478  1.19   perry static __inline int
    479  1.18  bouyer HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count)
    480  1.18  bouyer {
    481  1.18  bouyer     int ret;
    482  1.18  bouyer     unsigned long ign1, ign2, ign3;
    483  1.18  bouyer 
    484  1.18  bouyer     __asm__ __volatile__ (
    485  1.18  bouyer         TRAP_INSTR
    486  1.18  bouyer         : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
    487  1.18  bouyer 	: "0" (__HYPERVISOR_mmu_update), "1" (req), "2" (count),
    488  1.18  bouyer 	  "3" (success_count)
    489  1.10  bouyer 	: "memory" );
    490   1.1      cl 
    491   1.1      cl     return ret;
    492   1.1      cl }
    493   1.1      cl 
    494  1.19   perry static __inline int
    495  1.18  bouyer HYPERVISOR_fpu_taskswitch(void)
    496  1.18  bouyer {
    497  1.18  bouyer     int ret;
    498  1.18  bouyer     __asm volatile (
    499  1.18  bouyer         TRAP_INSTR
    500  1.18  bouyer         : "=a" (ret) : "0" (__HYPERVISOR_fpu_taskswitch) : "memory" );
    501  1.18  bouyer 
    502  1.18  bouyer     return ret;
    503  1.18  bouyer }
    504  1.18  bouyer 
    505  1.19   perry static __inline int
    506  1.10  bouyer HYPERVISOR_update_descriptor(unsigned long pa, unsigned long word1,
    507  1.10  bouyer     unsigned long word2)
    508   1.1      cl {
    509   1.1      cl     int ret;
    510  1.10  bouyer     unsigned long ign1, ign2, ign3;
    511  1.10  bouyer 
    512  1.17   perry     __asm volatile (
    513   1.1      cl         TRAP_INSTR
    514  1.10  bouyer         : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
    515  1.10  bouyer 	: "0" (__HYPERVISOR_update_descriptor), "1" (pa), "2" (word1),
    516  1.10  bouyer 	  "3" (word2)
    517  1.10  bouyer 	: "memory" );
    518   1.1      cl 
    519   1.1      cl     return ret;
    520   1.1      cl }
    521   1.1      cl 
    522  1.19   perry static __inline int
    523  1.18  bouyer HYPERVISOR_yield(void)
    524  1.18  bouyer {
    525  1.18  bouyer     int ret;
    526  1.18  bouyer     unsigned long ign1;
    527  1.18  bouyer 
    528  1.18  bouyer     __asm__ __volatile__ (
    529  1.18  bouyer         TRAP_INSTR
    530  1.18  bouyer         : "=a" (ret), "=b" (ign1)
    531  1.18  bouyer 	: "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_yield)
    532  1.18  bouyer 	: "memory" );
    533  1.18  bouyer 
    534  1.18  bouyer     return ret;
    535  1.18  bouyer }
    536  1.18  bouyer 
    537  1.19   perry static __inline int
    538  1.18  bouyer HYPERVISOR_block(void)
    539   1.1      cl {
    540   1.1      cl     int ret;
    541  1.10  bouyer     unsigned long ign1;
    542  1.10  bouyer 
    543  1.18  bouyer     __asm__ __volatile__ (
    544   1.1      cl         TRAP_INSTR
    545  1.10  bouyer         : "=a" (ret), "=b" (ign1)
    546  1.18  bouyer 	: "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_block)
    547  1.10  bouyer 	: "memory" );
    548   1.1      cl 
    549   1.1      cl     return ret;
    550   1.1      cl }
    551   1.1      cl 
    552  1.19   perry static __inline int
    553  1.18  bouyer HYPERVISOR_shutdown(void)
    554  1.18  bouyer {
    555  1.18  bouyer     int ret;
    556  1.18  bouyer     unsigned long ign1;
    557  1.18  bouyer 
    558  1.18  bouyer     __asm__ __volatile__ (
    559  1.18  bouyer         TRAP_INSTR
    560  1.18  bouyer         : "=a" (ret), "=b" (ign1)
    561  1.18  bouyer 	: "0" (__HYPERVISOR_sched_op),
    562  1.18  bouyer 	  "1" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
    563  1.18  bouyer         : "memory" );
    564  1.18  bouyer 
    565  1.18  bouyer     return ret;
    566  1.18  bouyer }
    567  1.18  bouyer 
    568  1.19   perry static __inline int
    569  1.18  bouyer HYPERVISOR_reboot(void)
    570   1.1      cl {
    571   1.1      cl     int ret;
    572  1.18  bouyer     unsigned long ign1;
    573  1.10  bouyer 
    574  1.18  bouyer     __asm__ __volatile__ (
    575   1.1      cl         TRAP_INSTR
    576  1.18  bouyer         : "=a" (ret), "=b" (ign1)
    577  1.18  bouyer 	: "0" (__HYPERVISOR_sched_op),
    578  1.18  bouyer 	  "1" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
    579  1.10  bouyer         : "memory" );
    580   1.1      cl 
    581   1.1      cl     return ret;
    582   1.1      cl }
    583   1.1      cl 
    584  1.19   perry static __inline int
    585  1.18  bouyer HYPERVISOR_suspend(unsigned long srec)
    586   1.1      cl {
    587   1.1      cl     int ret;
    588  1.10  bouyer     unsigned long ign1, ign2;
    589  1.10  bouyer 
    590  1.18  bouyer     /* NB. On suspend, control software expects a suspend record in %esi. */
    591  1.18  bouyer     __asm__ __volatile__ (
    592  1.18  bouyer         TRAP_INSTR
    593  1.18  bouyer         : "=a" (ret), "=b" (ign1), "=S" (ign2)
    594  1.18  bouyer 	: "0" (__HYPERVISOR_sched_op),
    595  1.18  bouyer         "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)),
    596  1.18  bouyer         "S" (srec) : "memory");
    597  1.18  bouyer 
    598  1.18  bouyer     return ret;
    599  1.18  bouyer }
    600  1.18  bouyer 
    601  1.19   perry static __inline int
    602  1.18  bouyer HYPERVISOR_set_fast_trap(int idx)
    603  1.18  bouyer {
    604  1.18  bouyer     int ret;
    605  1.18  bouyer     unsigned long ign1;
    606  1.18  bouyer 
    607  1.17   perry     __asm volatile (
    608   1.1      cl         TRAP_INSTR
    609  1.18  bouyer         : "=a" (ret), "=b" (ign1)
    610  1.18  bouyer 	: "0" (__HYPERVISOR_set_fast_trap), "1" (idx)
    611  1.10  bouyer 	: "memory" );
    612   1.1      cl 
    613   1.1      cl     return ret;
    614   1.1      cl }
    615   1.1      cl 
    616  1.19   perry static __inline int
    617  1.18  bouyer HYPERVISOR_dom_mem_op(unsigned int op, unsigned long *extent_list,
    618  1.18  bouyer     unsigned long nr_extents, unsigned int extent_order)
    619  1.18  bouyer {
    620  1.18  bouyer     int ret;
    621  1.18  bouyer     unsigned long ign1, ign2, ign3, ign4, ign5;
    622  1.18  bouyer 
    623  1.18  bouyer     __asm volatile (
    624  1.18  bouyer         TRAP_INSTR
    625  1.18  bouyer         : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
    626  1.18  bouyer 	  "=D" (ign5)
    627  1.18  bouyer 	: "0" (__HYPERVISOR_dom_mem_op), "1" (op), "2" (extent_list),
    628  1.18  bouyer 	  "3" (nr_extents), "4" (extent_order), "5" (DOMID_SELF)
    629  1.18  bouyer         : "memory" );
    630  1.18  bouyer 
    631  1.18  bouyer     return ret;
    632  1.18  bouyer }
    633  1.18  bouyer 
    634  1.19   perry static __inline int
    635  1.10  bouyer HYPERVISOR_update_va_mapping(unsigned long page_nr, unsigned long new_val,
    636  1.10  bouyer     unsigned long flags)
    637   1.1      cl {
    638  1.10  bouyer     int ret;
    639  1.10  bouyer     unsigned long ign1, ign2, ign3;
    640  1.10  bouyer 
    641  1.17   perry     __asm volatile (
    642   1.1      cl         TRAP_INSTR
    643  1.10  bouyer         : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
    644  1.10  bouyer 	: "0" (__HYPERVISOR_update_va_mapping),
    645  1.10  bouyer           "1" (page_nr), "2" (new_val), "3" (flags)
    646  1.10  bouyer 	: "memory" );
    647  1.10  bouyer 
    648  1.10  bouyer #ifdef notdef
    649  1.10  bouyer     if (__predict_false(ret < 0))
    650  1.10  bouyer         panic("Failed update VA mapping: %08lx, %08lx, %08lx",
    651  1.10  bouyer               page_nr, new_val, flags);
    652  1.10  bouyer #endif
    653   1.1      cl 
    654   1.1      cl     return ret;
    655   1.1      cl }
    656   1.1      cl 
    657  1.19   perry static __inline int
    658  1.18  bouyer HYPERVISOR_xen_version(int cmd)
    659   1.1      cl {
    660   1.1      cl     int ret;
    661  1.10  bouyer     unsigned long ign1;
    662  1.10  bouyer 
    663  1.17   perry     __asm volatile (
    664   1.1      cl         TRAP_INSTR
    665  1.10  bouyer         : "=a" (ret), "=b" (ign1)
    666  1.18  bouyer 	: "0" (__HYPERVISOR_xen_version), "1" (cmd)
    667  1.10  bouyer 	: "memory" );
    668   1.1      cl 
    669   1.1      cl     return ret;
    670   1.1      cl }
    671   1.1      cl 
    672  1.19   perry static __inline int
    673  1.18  bouyer HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
    674   1.1      cl {
    675   1.1      cl     int ret;
    676  1.18  bouyer     unsigned long ign1, ign2, ign3;
    677  1.10  bouyer 
    678  1.17   perry     __asm volatile (
    679   1.1      cl         TRAP_INSTR
    680  1.18  bouyer         : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
    681  1.18  bouyer 	: "0" (__HYPERVISOR_grant_table_op), "1" (cmd), "2" (count), "3" (uop)
    682  1.10  bouyer 	: "memory" );
    683   1.1      cl 
    684   1.1      cl     return ret;
    685   1.1      cl }
    686   1.1      cl 
    687  1.19   perry static __inline int
    688  1.18  bouyer HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr,
    689  1.18  bouyer     unsigned long new_val, unsigned long flags, domid_t domid)
    690  1.18  bouyer {
    691  1.18  bouyer     int ret;
    692  1.18  bouyer     unsigned long ign1, ign2, ign3, ign4;
    693  1.18  bouyer 
    694  1.18  bouyer     __asm volatile (
    695  1.18  bouyer         TRAP_INSTR
    696  1.18  bouyer         : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
    697  1.18  bouyer 	: "0" (__HYPERVISOR_update_va_mapping_otherdomain),
    698  1.18  bouyer           "1" (page_nr), "2" (new_val), "3" (flags), "4" (domid) :
    699  1.18  bouyer         "memory" );
    700  1.18  bouyer 
    701  1.18  bouyer     return ret;
    702  1.18  bouyer }
    703  1.18  bouyer 
    704  1.19   perry static __inline long
    705  1.18  bouyer HYPERVISOR_set_timer_op(uint64_t timeout)
    706  1.18  bouyer {
    707  1.18  bouyer     long ret;
    708  1.18  bouyer     unsigned long timeout_hi = (unsigned long)(timeout>>32);
    709  1.18  bouyer     unsigned long timeout_lo = (unsigned long)timeout;
    710  1.18  bouyer     unsigned long ign1, ign2;
    711  1.18  bouyer 
    712  1.18  bouyer     __asm volatile (
    713  1.18  bouyer         TRAP_INSTR
    714  1.18  bouyer         : "=a" (ret), "=b" (ign1), "=c" (ign2)
    715  1.18  bouyer 	: "0" (__HYPERVISOR_set_timer_op), "b" (timeout_hi), "c" (timeout_lo)
    716  1.18  bouyer 	: "memory");
    717  1.18  bouyer 
    718  1.18  bouyer     return ret;
    719  1.18  bouyer }
    720  1.18  bouyer #endif /* XEN3 */
    721  1.18  bouyer 
    722  1.19   perry static __inline int
    723  1.18  bouyer HYPERVISOR_multicall(void *call_list, int nr_calls)
    724   1.1      cl {
    725   1.1      cl     int ret;
    726  1.18  bouyer     unsigned long ign1, ign2;
    727  1.10  bouyer 
    728  1.21  bouyer     _hypercall(__HYPERVISOR_multicall,
    729  1.21  bouyer 	 _harg("1" (call_list), "2" (nr_calls)),
    730  1.21  bouyer 	 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    731   1.1      cl 
    732   1.1      cl     return ret;
    733   1.1      cl }
    734   1.1      cl 
    735  1.18  bouyer 
    736  1.19   perry static __inline int
    737  1.18  bouyer HYPERVISOR_event_channel_op(void *op)
    738   1.1      cl {
    739   1.1      cl     int ret;
    740  1.10  bouyer     unsigned long ign1;
    741  1.10  bouyer 
    742  1.21  bouyer     _hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op)),
    743  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1)));
    744   1.1      cl 
    745   1.1      cl     return ret;
    746   1.1      cl }
    747   1.1      cl 
    748  1.19   perry static __inline int
    749  1.18  bouyer HYPERVISOR_console_io(int cmd, int count, char *str)
    750   1.1      cl {
    751   1.1      cl     int ret;
    752  1.10  bouyer     unsigned long ign1, ign2, ign3;
    753  1.10  bouyer 
    754  1.21  bouyer     _hypercall(__HYPERVISOR_console_io,
    755  1.21  bouyer 	_harg("1" (cmd), "2" (count), "3" (str)),
    756  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
    757   1.1      cl 
    758   1.1      cl     return ret;
    759   1.1      cl }
    760   1.1      cl 
    761  1.19   perry static __inline int
    762  1.18  bouyer HYPERVISOR_physdev_op(void *physdev_op)
    763   1.1      cl {
    764   1.1      cl     int ret;
    765  1.18  bouyer     unsigned long ign1;
    766  1.10  bouyer 
    767  1.21  bouyer     _hypercall(__HYPERVISOR_physdev_op, _harg("1" (physdev_op)),
    768  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1)));
    769  1.18  bouyer 
    770  1.10  bouyer     return ret;
    771  1.10  bouyer }
    772   1.1      cl 
    773  1.19   perry static __inline int
    774  1.10  bouyer HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type)
    775  1.10  bouyer {
    776  1.10  bouyer     int ret;
    777  1.10  bouyer     unsigned long ign1, ign2;
    778  1.10  bouyer 
    779  1.21  bouyer     _hypercall(__HYPERVISOR_vm_assist, _harg("1" (cmd), "2" (type)),
    780  1.21  bouyer 	_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
    781   1.2      cl 
    782   1.1      cl     return ret;
    783   1.1      cl }
    784   1.1      cl 
    785  1.15  bouyer /*
    786  1.15  bouyer  * Force a proper event-channel callback from Xen after clearing the
    787  1.15  bouyer  * callback mask. We do this in a very simple manner, by making a call
    788  1.15  bouyer  * down into Xen. The pending flag will be checked by Xen on return.
    789  1.15  bouyer  */
    790  1.19   perry static __inline void hypervisor_force_callback(void)
    791  1.15  bouyer {
    792  1.18  bouyer #ifdef XEN3
    793  1.18  bouyer 	(void)HYPERVISOR_xen_version(0, (void*)0);
    794  1.18  bouyer #else
    795  1.15  bouyer 	(void)HYPERVISOR_xen_version(0);
    796  1.18  bouyer #endif
    797  1.15  bouyer } __attribute__((no_instrument_function)) /* used by mcount */
    798  1.15  bouyer 
    799  1.19   perry static __inline void
    800  1.15  bouyer hypervisor_notify_via_evtchn(unsigned int port)
    801  1.15  bouyer {
    802  1.15  bouyer 	evtchn_op_t op;
    803  1.15  bouyer 
    804  1.15  bouyer 	op.cmd = EVTCHNOP_send;
    805  1.18  bouyer #ifdef XEN3
    806  1.18  bouyer 	op.u.send.port = port;
    807  1.18  bouyer #else
    808  1.15  bouyer 	op.u.send.local_port = port;
    809  1.18  bouyer #endif
    810  1.15  bouyer 	(void)HYPERVISOR_event_channel_op(&op);
    811  1.15  bouyer }
    812  1.15  bouyer 
    813   1.1      cl #endif /* _XEN_HYPERVISOR_H_ */
    814