vmmapi.h revision 265951
1221828Sgrehan/*- 2221828Sgrehan * Copyright (c) 2011 NetApp, Inc. 3221828Sgrehan * All rights reserved. 4221828Sgrehan * 5221828Sgrehan * Redistribution and use in source and binary forms, with or without 6221828Sgrehan * modification, are permitted provided that the following conditions 7221828Sgrehan * are met: 8221828Sgrehan * 1. Redistributions of source code must retain the above copyright 9221828Sgrehan * notice, this list of conditions and the following disclaimer. 10221828Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 11221828Sgrehan * notice, this list of conditions and the following disclaimer in the 12221828Sgrehan * documentation and/or other materials provided with the distribution. 13221828Sgrehan * 14221828Sgrehan * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 15221828Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16221828Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17221828Sgrehan * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 18221828Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19221828Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20221828Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21221828Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22221828Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23221828Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24221828Sgrehan * SUCH DAMAGE. 25221828Sgrehan * 26221828Sgrehan * $FreeBSD: head/lib/libvmmapi/vmmapi.h 265951 2014-05-13 16:40:27Z neel $ 27221828Sgrehan */ 28221828Sgrehan 29221828Sgrehan#ifndef _VMMAPI_H_ 30221828Sgrehan#define _VMMAPI_H_ 31221828Sgrehan 32221828Sgrehanstruct vmctx; 33240922Sneelenum x2apic_state; 34221828Sgrehan 35248477Sneel/* 36248477Sneel * Different styles of mapping the memory assigned to a VM into the address 37248477Sneel * space of the controlling process. 38248477Sneel */ 39248477Sneelenum vm_mmap_style { 40248477Sneel VM_MMAP_NONE, /* no mapping */ 41248477Sneel VM_MMAP_ALL, /* fully and statically mapped */ 42248477Sneel VM_MMAP_SPARSE, /* mappings created on-demand */ 43248477Sneel}; 44248477Sneel 45265951Sneel#define VM_MEM_F_INCORE 0x01 /* include guest memory in core file */ 46265951Sneel 47221828Sgrehanint vm_create(const char *name); 48221828Sgrehanstruct vmctx *vm_open(const char *name); 49221828Sgrehanvoid vm_destroy(struct vmctx *ctx); 50256176Sneelint vm_parse_memsize(const char *optarg, size_t *memsize); 51256072Sneelint vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len, 52256072Sneel int *wired); 53248477Sneelint vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s); 54248477Sneelvoid *vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len); 55256072Sneelint vm_get_gpa_pmap(struct vmctx *, uint64_t gpa, uint64_t *pte, int *num); 56248477Sneeluint32_t vm_get_lowmem_limit(struct vmctx *ctx); 57248477Sneelvoid vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit); 58265951Sneelvoid vm_set_memflags(struct vmctx *ctx, int flags); 59221828Sgrehanint vm_set_desc(struct vmctx *ctx, int vcpu, int reg, 60221828Sgrehan uint64_t base, uint32_t limit, uint32_t access); 61221828Sgrehanint vm_get_desc(struct vmctx *ctx, int vcpu, int reg, 62221828Sgrehan uint64_t *base, uint32_t *limit, uint32_t *access); 63221828Sgrehanint vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val); 64221828Sgrehanint vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval); 65221828Sgrehanint vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, 66221828Sgrehan struct vm_exit *ret_vmexit); 67265062Sneelint vm_suspend(struct vmctx *ctx, enum vm_suspend_how how); 68239026Sneelint vm_apicid2vcpu(struct vmctx *ctx, int apicid); 69262506Sneelint vm_inject_exception(struct vmctx *ctx, int vcpu, int vec); 70262506Sneelint vm_inject_exception2(struct vmctx *ctx, int vcpu, int vec, int errcode); 71221828Sgrehanint vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector); 72259779Sjhbint vm_lapic_local_irq(struct vmctx *ctx, int vcpu, int vector); 73259482Sneelint vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg); 74258075Sneelint vm_ioapic_assert_irq(struct vmctx *ctx, int irq); 75258075Sneelint vm_ioapic_deassert_irq(struct vmctx *ctx, int irq); 76258494Sneelint vm_ioapic_pulse_irq(struct vmctx *ctx, int irq); 77261268Sjhbint vm_ioapic_pincount(struct vmctx *ctx, int *pincount); 78264468Stychonint vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq); 79263035Stychonint vm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq); 80263035Stychonint vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq); 81221828Sgrehanint vm_inject_nmi(struct vmctx *ctx, int vcpu); 82221828Sgrehanint vm_capability_name2type(const char *capname); 83241486Sneelconst char *vm_capability_type2name(int type); 84221828Sgrehanint vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, 85221828Sgrehan int *retval); 86221828Sgrehanint vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, 87221828Sgrehan int val); 88221828Sgrehanint vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func); 89221828Sgrehanint vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func); 90221828Sgrehanint vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, 91221828Sgrehan vm_paddr_t gpa, size_t len, vm_paddr_t hpa); 92259537Sneelint vm_setup_pptdev_msi(struct vmctx *ctx, int vcpu, int bus, int slot, 93259537Sneel int func, uint64_t addr, uint64_t msg, int numvec); 94259537Sneelint vm_setup_pptdev_msix(struct vmctx *ctx, int vcpu, int bus, int slot, 95259537Sneel int func, int idx, uint64_t addr, uint64_t msg, 96259537Sneel uint32_t vector_control); 97221828Sgrehan 98221828Sgrehan/* 99221828Sgrehan * Return a pointer to the statistics buffer. Note that this is not MT-safe. 100221828Sgrehan */ 101221828Sgrehanuint64_t *vm_get_stats(struct vmctx *ctx, int vcpu, struct timeval *ret_tv, 102221828Sgrehan int *ret_entries); 103221828Sgrehanconst char *vm_get_stat_desc(struct vmctx *ctx, int index); 104221828Sgrehan 105240922Sneelint vm_get_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state *s); 106240922Sneelint vm_set_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state s); 107240922Sneel 108258579Sneelint vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities); 109258579Sneel 110221828Sgrehan/* Reset vcpu register state */ 111221828Sgrehanint vcpu_reset(struct vmctx *ctx, int vcpu); 112221828Sgrehan 113221828Sgrehan/* 114221828Sgrehan * FreeBSD specific APIs 115221828Sgrehan */ 116221828Sgrehanint vm_setup_freebsd_registers(struct vmctx *ctx, int vcpu, 117221828Sgrehan uint64_t rip, uint64_t cr3, uint64_t gdtbase, 118221828Sgrehan uint64_t rsp); 119261504Sjhbint vm_setup_freebsd_registers_i386(struct vmctx *vmctx, int vcpu, 120261504Sjhb uint32_t eip, uint32_t gdtbase, 121261504Sjhb uint32_t esp); 122221828Sgrehanvoid vm_setup_freebsd_gdt(uint64_t *gdtr); 123221828Sgrehan#endif /* _VMMAPI_H_ */ 124