#ifndef _XENI386_HYPERVISOR_H_
#define _XENI386_HYPERVISOR_H_
#include <machine/pte.h>
#define __str(x) #x
#define _str(x) __str(x)
#define _hypercall(name, input_const, output_const) \
__asm volatile ( \
"call hypercall_page + ("_str(name)" * 32)" \
: output_const \
: input_const \
: "memory" )
#define _harg(...) __VA_ARGS__
static __inline int
HYPERVISOR_set_trap_table(trap_info_t *table)
{
int ret;
unsigned long ign1;
_hypercall(__HYPERVISOR_set_trap_table, _harg("1" (table)),
_harg("=a" (ret), "=b" (ign1)));
return ret;
}
static __inline int
HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_set_gdt, _harg("1" (frame_list), "2" (entries)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_stack_switch, _harg("1" (ss), "2" (esp)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_set_callbacks(
unsigned long event_selector, unsigned long event_address,
unsigned long failsafe_selector, unsigned long failsafe_address)
{
int ret;
unsigned long ign1, ign2, ign3, ign4;
_hypercall(__HYPERVISOR_set_callbacks,
_harg("1" (event_selector),"2" (event_address),
"3" (failsafe_selector), "4" (failsafe_address)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
return ret;
}
#if __XEN_INTERFACE_VERSION__ < 0x00030204
static __inline int
HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
{
int ret;
unsigned long ign1;
dom0_op->interface_version = DOM0_INTERFACE_VERSION;
_hypercall(__HYPERVISOR_dom0_op, _harg("1" (dom0_op)),
_harg("=a" (ret), "=b" (ign1)));
return ret;
}
#endif
static __inline int
HYPERVISOR_set_debugreg(int reg, unsigned long value)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_set_debugreg, _harg("1" (reg), "2" (value)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline unsigned long
HYPERVISOR_get_debugreg(int reg)
{
unsigned long ret;
unsigned long ign1;
_hypercall(__HYPERVISOR_get_debugreg, _harg("1" (reg)),
_harg("=a" (ret), "=b" (ign1)));
return ret;
}
#include <xen/include/public/arch-x86/xen-mca.h>
static __inline int
HYPERVISOR_machine_check(struct xen_mc *mc)
{
int ret;
unsigned long ign1;
mc->interface_version = XEN_MCA_INTERFACE_VERSION;
_hypercall(__HYPERVISOR_mca, _harg("1" (mc)),
_harg("=a" (ret), "=b" (ign1)));
return ret;
}
static __inline int
HYPERVISOR_hvm_op(int cmd, void *arg)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_hvm_op, _harg("1" (cmd), "2" (arg)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count,
domid_t domid)
{
int ret;
unsigned long ign1, ign2, ign3, ign4;
_hypercall(__HYPERVISOR_mmu_update,
_harg("1" (req), "2" (count), "3" (success_count), "4" (domid)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
return ret;
}
static __inline int
HYPERVISOR_mmuext_op(struct mmuext_op *op, int count, int *success_count,
domid_t domid)
{
int ret;
unsigned long ign1, ign2, ign3, ign4;
_hypercall(__HYPERVISOR_mmuext_op,
_harg("1" (op), "2" (count), "3" (success_count), "4" (domid)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
return ret;
}
static __inline int
HYPERVISOR_fpu_taskswitch(int set)
{
long ret;
long ign1;
_hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (set)),
_harg("=a" (ret), "=b" (ign1)));
return ret;
}
static __inline int
HYPERVISOR_update_descriptor(uint64_t ma, uint32_t word1, uint32_t word2)
{
int ret;
unsigned long ign1, ign2, ign3, ign4;
int ma1 = ma & 0xffffffff;
int ma2 = (ma >> 32) & 0xffffffff;
_hypercall(__HYPERVISOR_update_descriptor,
_harg("1" (ma1), "2" (ma2), "3" (word1), "4" (word2)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
return ret;
}
static __inline int
HYPERVISOR_memory_op(unsigned int cmd, void *arg)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_memory_op, _harg("1" (cmd), "2" (arg)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
#ifdef XENPV
static __inline int
HYPERVISOR_update_va_mapping(unsigned long page_nr, pt_entry_t new_val,
unsigned long flags)
{
int ret;
unsigned long ign1, ign2, ign3, ign4;
unsigned long pte_low, pte_hi;
pte_low = new_val & 0xffffffff;
pte_hi = new_val >> 32;
_hypercall(__HYPERVISOR_update_va_mapping,
_harg("1" (page_nr), "2" (pte_low), "3" (pte_hi), "4" (flags)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)));
#ifdef notdef
if (__predict_false(ret < 0))
panic("Failed update VA mapping: %08lx, %08lx, %08lx",
page_nr, new_val, flags);
#endif
return ret;
}
static __inline int
HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr,
pt_entry_t new_val, unsigned long flags, domid_t domid)
{
int ret;
unsigned long ign1, ign2, ign3, ign4, ign5;
unsigned long pte_low, pte_hi;
pte_low = new_val & 0xffffffff;
pte_hi = new_val >> 32;
_hypercall(__HYPERVISOR_update_va_mapping_otherdomain,
_harg("1" (page_nr), "2" (pte_low), "3" (pte_hi), "4" (flags), "5" (domid)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
"=D" (ign5)));
return ret;
}
#endif
static __inline int
HYPERVISOR_xen_version(int cmd, void *arg)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_xen_version, _harg("1" (cmd), "2" (arg)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
{
int ret;
unsigned long ign1, ign2, ign3;
_hypercall(__HYPERVISOR_grant_table_op,
_harg("1" (cmd), "2" (uop), "3" (count)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
return ret;
}
static __inline int
HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
{
long ret;
unsigned long ign1, ign2, ign3;
_hypercall(__HYPERVISOR_vcpu_op,
_harg("1" (cmd), "2" (vcpuid), "3" (extra_args)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
return ret;
}
static __inline long
HYPERVISOR_yield(void)
{
long ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_yield), "2" (0)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline long
HYPERVISOR_block(void)
{
long ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_block), "2" (0)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline long
HYPERVISOR_shutdown(void)
{
long ret;
unsigned long ign1, ign2;
#if __XEN_INTERFACE_VERSION__ >= 0x00030201
struct sched_shutdown shutdown_reason = {
.reason = SHUTDOWN_poweroff
};
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (&shutdown_reason)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
#else
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_poweroff)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
#endif
return ret;
}
static __inline long
HYPERVISOR_crash(void)
{
long ret;
unsigned long ign1, ign2;
#if __XEN_INTERFACE_VERSION__ >= 0x00030201
struct sched_shutdown shutdown_reason = {
.reason = SHUTDOWN_crash
};
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (&shutdown_reason)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
#else
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_crash)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
#endif
return ret;
}
static __inline long
HYPERVISOR_reboot(void)
{
long ret;
unsigned long ign1, ign2;
#if __XEN_INTERFACE_VERSION__ >= 0x00030201
struct sched_shutdown shutdown_reason = {
.reason = SHUTDOWN_reboot
};
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (&shutdown_reason)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
#else
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_reboot)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
#endif
return ret;
}
static __inline long
HYPERVISOR_suspend(unsigned long srec)
{
long ret;
unsigned long ign1, ign2, ign3;
#if __XEN_INTERFACE_VERSION__ >= 0x00030201
struct sched_shutdown shutdown_reason = {
.reason = SHUTDOWN_suspend
};
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (&shutdown_reason), "3" (srec)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
#else
_hypercall(__HYPERVISOR_sched_op,
_harg("1" (SCHEDOP_shutdown), "2" (SHUTDOWN_suspend), "3" (srec)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
#endif
return ret;
}
static __inline long
HYPERVISOR_set_timer_op(uint64_t timeout)
{
long ret;
unsigned long timeout_hi = (unsigned long)(timeout>>32);
unsigned long timeout_lo = (unsigned long)timeout;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_set_timer_op,
_harg("1" (timeout_lo), "2" (timeout_hi)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_platform_op(struct xen_platform_op *platform_op)
{
int ret;
unsigned long ign1;
platform_op->interface_version = XENPF_INTERFACE_VERSION;
_hypercall(__HYPERVISOR_platform_op, _harg("1" (platform_op)),
_harg("=a" (ret), "=b" (ign1)));
return ret;
}
static __inline int
HYPERVISOR_multicall(void *call_list, int nr_calls)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_multicall,
_harg("1" (call_list), "2" (nr_calls)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_event_channel_op(evtchn_op_t *op)
{
int ret;
unsigned long ign1;
#if __XEN_INTERFACE_VERSION__ < 0x00030202
_hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op)),
_harg("=a" (ret), "=b" (ign1)));
#else
unsigned long ign2;
_hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op->cmd), "2" (&op->u)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
#endif
return ret;
}
static __inline int
HYPERVISOR_console_io(int cmd, int count, char *str)
{
int ret;
unsigned long ign1, ign2, ign3;
_hypercall(__HYPERVISOR_console_io,
_harg("1" (cmd), "2" (count), "3" (str)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)));
return ret;
}
static __inline int
HYPERVISOR_physdev_op(int cmd, void *physdev_op)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_physdev_op, _harg("1" (cmd), "2" (physdev_op)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type)
{
int ret;
unsigned long ign1, ign2;
_hypercall(__HYPERVISOR_vm_assist, _harg("1" (cmd), "2" (type)),
_harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
return ret;
}
static __inline int
HYPERVISOR_sysctl(void *sysctl)
{
int ret;
unsigned long ign1;
_hypercall(__HYPERVISOR_sysctl, _harg("1" (sysctl)),
_harg("=a" (ret), "=b" (ign1)));
return ret;
}
#endif