vmmapi.h revision 266933
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 266933 2014-05-31 23:37:34Z neel $
27221828Sgrehan */
28221828Sgrehan
29221828Sgrehan#ifndef _VMMAPI_H_
30221828Sgrehan#define	_VMMAPI_H_
31221828Sgrehan
32266933Sneel#include <sys/param.h>
33266933Sneel#include <sys/cpuset.h>
34266933Sneel
35266708Sneelstruct iovec;
36221828Sgrehanstruct vmctx;
37240922Sneelenum x2apic_state;
38221828Sgrehan
39248477Sneel/*
40248477Sneel * Different styles of mapping the memory assigned to a VM into the address
41248477Sneel * space of the controlling process.
42248477Sneel */
43248477Sneelenum vm_mmap_style {
44248477Sneel	VM_MMAP_NONE,		/* no mapping */
45248477Sneel	VM_MMAP_ALL,		/* fully and statically mapped */
46248477Sneel	VM_MMAP_SPARSE,		/* mappings created on-demand */
47248477Sneel};
48248477Sneel
49265951Sneel#define	VM_MEM_F_INCORE	0x01	/* include guest memory in core file */
50265951Sneel
51221828Sgrehanint	vm_create(const char *name);
52221828Sgrehanstruct vmctx *vm_open(const char *name);
53221828Sgrehanvoid	vm_destroy(struct vmctx *ctx);
54256176Sneelint	vm_parse_memsize(const char *optarg, size_t *memsize);
55256072Sneelint	vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len,
56256072Sneel			  int *wired);
57248477Sneelint	vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
58248477Sneelvoid	*vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len);
59256072Sneelint	vm_get_gpa_pmap(struct vmctx *, uint64_t gpa, uint64_t *pte, int *num);
60248477Sneeluint32_t vm_get_lowmem_limit(struct vmctx *ctx);
61248477Sneelvoid	vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
62265951Sneelvoid	vm_set_memflags(struct vmctx *ctx, int flags);
63221828Sgrehanint	vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
64221828Sgrehan		    uint64_t base, uint32_t limit, uint32_t access);
65221828Sgrehanint	vm_get_desc(struct vmctx *ctx, int vcpu, int reg,
66221828Sgrehan		    uint64_t *base, uint32_t *limit, uint32_t *access);
67221828Sgrehanint	vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val);
68221828Sgrehanint	vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval);
69221828Sgrehanint	vm_run(struct vmctx *ctx, int vcpu, uint64_t rip,
70221828Sgrehan	       struct vm_exit *ret_vmexit);
71265062Sneelint	vm_suspend(struct vmctx *ctx, enum vm_suspend_how how);
72239026Sneelint	vm_apicid2vcpu(struct vmctx *ctx, int apicid);
73262506Sneelint	vm_inject_exception(struct vmctx *ctx, int vcpu, int vec);
74262506Sneelint	vm_inject_exception2(struct vmctx *ctx, int vcpu, int vec, int errcode);
75221828Sgrehanint	vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector);
76259779Sjhbint	vm_lapic_local_irq(struct vmctx *ctx, int vcpu, int vector);
77259482Sneelint	vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg);
78258075Sneelint	vm_ioapic_assert_irq(struct vmctx *ctx, int irq);
79258075Sneelint	vm_ioapic_deassert_irq(struct vmctx *ctx, int irq);
80258494Sneelint	vm_ioapic_pulse_irq(struct vmctx *ctx, int irq);
81261268Sjhbint	vm_ioapic_pincount(struct vmctx *ctx, int *pincount);
82264468Stychonint	vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
83263035Stychonint	vm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
84263035Stychonint	vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
85266125Sjhbint	vm_isa_set_irq_trigger(struct vmctx *ctx, int atpic_irq,
86266125Sjhb	    enum vm_intr_trigger trigger);
87221828Sgrehanint	vm_inject_nmi(struct vmctx *ctx, int vcpu);
88221828Sgrehanint	vm_capability_name2type(const char *capname);
89241486Sneelconst char *vm_capability_type2name(int type);
90221828Sgrehanint	vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
91221828Sgrehan			  int *retval);
92221828Sgrehanint	vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
93221828Sgrehan			  int val);
94221828Sgrehanint	vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
95221828Sgrehanint	vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
96221828Sgrehanint	vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
97221828Sgrehan			   vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
98259537Sneelint	vm_setup_pptdev_msi(struct vmctx *ctx, int vcpu, int bus, int slot,
99259537Sneel	    int func, uint64_t addr, uint64_t msg, int numvec);
100259537Sneelint	vm_setup_pptdev_msix(struct vmctx *ctx, int vcpu, int bus, int slot,
101259537Sneel	    int func, int idx, uint64_t addr, uint64_t msg,
102259537Sneel	    uint32_t vector_control);
103221828Sgrehan
104221828Sgrehan/*
105221828Sgrehan * Return a pointer to the statistics buffer. Note that this is not MT-safe.
106221828Sgrehan */
107221828Sgrehanuint64_t *vm_get_stats(struct vmctx *ctx, int vcpu, struct timeval *ret_tv,
108221828Sgrehan		       int *ret_entries);
109221828Sgrehanconst char *vm_get_stat_desc(struct vmctx *ctx, int index);
110221828Sgrehan
111240922Sneelint	vm_get_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state *s);
112240922Sneelint	vm_set_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state s);
113240922Sneel
114258579Sneelint	vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities);
115258579Sneel
116266708Sneel/*
117266708Sneel * Translate the GLA range [gla,gla+len) into GPA segments in 'iov'.
118266708Sneel * The 'iovcnt' should be big enough to accomodate all GPA segments.
119266708Sneel * Returns 0 on success, 1 on a guest fault condition and -1 otherwise.
120266708Sneel */
121266708Sneelint	vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
122266708Sneel	    uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt);
123266708Sneelvoid	vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *guest_iov,
124266708Sneel	    void *host_dst, size_t len);
125266708Sneelvoid	vm_copyout(struct vmctx *ctx, int vcpu, const void *host_src,
126266708Sneel	    struct iovec *guest_iov, size_t len);
127266633Sneel
128221828Sgrehan/* Reset vcpu register state */
129221828Sgrehanint	vcpu_reset(struct vmctx *ctx, int vcpu);
130221828Sgrehan
131266933Sneelint	vm_active_cpus(struct vmctx *ctx, cpuset_t *cpus);
132266933Sneelint	vm_suspended_cpus(struct vmctx *ctx, cpuset_t *cpus);
133266933Sneelint	vm_activate_cpu(struct vmctx *ctx, int vcpu);
134266933Sneel
135221828Sgrehan/*
136221828Sgrehan * FreeBSD specific APIs
137221828Sgrehan */
138221828Sgrehanint	vm_setup_freebsd_registers(struct vmctx *ctx, int vcpu,
139221828Sgrehan				uint64_t rip, uint64_t cr3, uint64_t gdtbase,
140221828Sgrehan				uint64_t rsp);
141261504Sjhbint	vm_setup_freebsd_registers_i386(struct vmctx *vmctx, int vcpu,
142261504Sjhb					uint32_t eip, uint32_t gdtbase,
143261504Sjhb					uint32_t esp);
144221828Sgrehanvoid	vm_setup_freebsd_gdt(uint64_t *gdtr);
145221828Sgrehan#endif	/* _VMMAPI_H_ */
146