vmmapi.h revision 239042
150472Speter/*- 234495Sjdp * Copyright (c) 2011 NetApp, Inc. 3131832Sobrien * All rights reserved. 4131832Sobrien * 5131832Sobrien * Redistribution and use in source and binary forms, with or without 644360Simp * modification, are permitted provided that the following conditions 744360Simp * are met: 8131832Sobrien * 1. Redistributions of source code must retain the above copyright 952930Sjb * notice, this list of conditions and the following disclaimer. 10131832Sobrien * 2. Redistributions in binary form must reproduce the above copyright 11218822Sdim * notice, this list of conditions and the following disclaimer in the 12218822Sdim * documentation and/or other materials provided with the distribution. 13218822Sdim * 14218822Sdim * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 15218822Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16218822Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17218822Sdim * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 18218822Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19218822Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20218822Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21218822Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22218822Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23218822Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24218822Sdim * SUCH DAMAGE. 25218822Sdim * 26218822Sdim * $FreeBSD$ 27218822Sdim */ 28218822Sdim 29218822Sdim#ifndef _VMMAPI_H_ 30218822Sdim#define _VMMAPI_H_ 31218822Sdim 32218822Sdimstruct vmctx; 33218822Sdim 34218822Sdimint vm_create(const char *name); 35218822Sdimstruct vmctx *vm_open(const char *name); 36218822Sdimvoid vm_destroy(struct vmctx *ctx); 37218822Sdimint vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, 38218822Sdim vm_paddr_t *ret_hpa, size_t *ret_len); 39218822Sdim/* 40218822Sdim * Create a memory segment of 'len' bytes in the guest physical address space 41131832Sobrien * at offset 'gpa'. 42131832Sobrien * 43131832Sobrien * If 'mapaddr' is not NULL then this region is mmap'ed into the address 44215082Simp * space of the calling process. If there is an mmap error then *mapaddr 45185922Simp * will be set to MAP_FAILED. 46233388Sgonzo */ 47233388Sgonzo 48233388Sgonzoint vm_setup_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len, 49233388Sgonzo char **mapaddr); 50233388Sgonzochar * vm_map_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len); 51233388Sgonzoint vm_set_desc(struct vmctx *ctx, int vcpu, int reg, 52185922Simp uint64_t base, uint32_t limit, uint32_t access); 53233388Sgonzoint vm_get_desc(struct vmctx *ctx, int vcpu, int reg, 54185922Simp uint64_t *base, uint32_t *limit, uint32_t *access); 55131832Sobrienint vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val); 56131832Sobrienint vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval); 57215352Snwhitehornint vm_get_pinning(struct vmctx *ctx, int vcpu, int *host_cpuid); 58131832Sobrienint vm_set_pinning(struct vmctx *ctx, int vcpu, int host_cpuid); 59131832Sobrienint vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, 60218822Sdim struct vm_exit *ret_vmexit); 61131832Sobrienint vm_build_tables(struct vmctx *ctxt, int ncpus, int ioapic, 62215082Simp void *oemtbl, int oemtblsz); 6352930Sjbint vm_apicid2vcpu(struct vmctx *ctx, int apicid); 6452930Sjbint vm_inject_event(struct vmctx *ctx, int vcpu, enum vm_event_type type, 65131832Sobrien int vector); 66131832Sobrienint vm_inject_event2(struct vmctx *ctx, int vcpu, enum vm_event_type type, 67131832Sobrien int vector, int error_code); 68131832Sobrienint vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector); 6952930Sjbint vm_inject_nmi(struct vmctx *ctx, int vcpu); 70162219Sobrienint vm_capability_name2type(const char *capname); 71162219Sobrienint vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, 72162219Sobrien int *retval); 73131832Sobrienint vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, 74218822Sdim int val); 75131832Sobrienint vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func); 76131832Sobrienint vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func); 77131832Sobrienint vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, 78131832Sobrien vm_paddr_t gpa, size_t len, vm_paddr_t hpa); 79218822Sdimint vm_setup_msi(struct vmctx *ctx, int vcpu, int bus, int slot, int func, 80215082Simp int dest, int vector, int numvec); 8134495Sjdpint vm_setup_msix(struct vmctx *ctx, int vcpu, int bus, int slot, int func, 82139112Sru int idx, uint32_t msg, uint32_t vector_control, uint64_t addr); 83131832Sobrien 84131832Sobrien/* 85131832Sobrien * Return a pointer to the statistics buffer. Note that this is not MT-safe. 86131832Sobrien */ 87131832Sobrienuint64_t *vm_get_stats(struct vmctx *ctx, int vcpu, struct timeval *ret_tv, 88131832Sobrien int *ret_entries); 89131832Sobrienconst char *vm_get_stat_desc(struct vmctx *ctx, int index); 90 91/* Reset vcpu register state */ 92int vcpu_reset(struct vmctx *ctx, int vcpu); 93 94/* 95 * FreeBSD specific APIs 96 */ 97int vm_setup_freebsd_registers(struct vmctx *ctx, int vcpu, 98 uint64_t rip, uint64_t cr3, uint64_t gdtbase, 99 uint64_t rsp); 100void vm_setup_freebsd_gdt(uint64_t *gdtr); 101#endif /* _VMMAPI_H_ */ 102