vmmapi.h revision 276428
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 276428 2014-12-30 22:19: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);
63267811Sneelsize_t	vm_get_lowmem_size(struct vmctx *ctx);
64267811Sneelsize_t	vm_get_highmem_size(struct vmctx *ctx);
65221828Sgrehanint	vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
66221828Sgrehan		    uint64_t base, uint32_t limit, uint32_t access);
67221828Sgrehanint	vm_get_desc(struct vmctx *ctx, int vcpu, int reg,
68221828Sgrehan		    uint64_t *base, uint32_t *limit, uint32_t *access);
69269008Sneelint	vm_get_seg_desc(struct vmctx *ctx, int vcpu, int reg,
70269008Sneel			struct seg_desc *seg_desc);
71221828Sgrehanint	vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val);
72221828Sgrehanint	vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval);
73221828Sgrehanint	vm_run(struct vmctx *ctx, int vcpu, uint64_t rip,
74221828Sgrehan	       struct vm_exit *ret_vmexit);
75265062Sneelint	vm_suspend(struct vmctx *ctx, enum vm_suspend_how how);
76267216Sneelint	vm_reinit(struct vmctx *ctx);
77239026Sneelint	vm_apicid2vcpu(struct vmctx *ctx, int apicid);
78262506Sneelint	vm_inject_exception(struct vmctx *ctx, int vcpu, int vec);
79262506Sneelint	vm_inject_exception2(struct vmctx *ctx, int vcpu, int vec, int errcode);
80221828Sgrehanint	vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector);
81259779Sjhbint	vm_lapic_local_irq(struct vmctx *ctx, int vcpu, int vector);
82259482Sneelint	vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg);
83258075Sneelint	vm_ioapic_assert_irq(struct vmctx *ctx, int irq);
84258075Sneelint	vm_ioapic_deassert_irq(struct vmctx *ctx, int irq);
85258494Sneelint	vm_ioapic_pulse_irq(struct vmctx *ctx, int irq);
86261268Sjhbint	vm_ioapic_pincount(struct vmctx *ctx, int *pincount);
87264468Stychonint	vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
88263035Stychonint	vm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
89263035Stychonint	vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
90266125Sjhbint	vm_isa_set_irq_trigger(struct vmctx *ctx, int atpic_irq,
91266125Sjhb	    enum vm_intr_trigger trigger);
92221828Sgrehanint	vm_inject_nmi(struct vmctx *ctx, int vcpu);
93221828Sgrehanint	vm_capability_name2type(const char *capname);
94241486Sneelconst char *vm_capability_type2name(int type);
95221828Sgrehanint	vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
96221828Sgrehan			  int *retval);
97221828Sgrehanint	vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
98221828Sgrehan			  int val);
99221828Sgrehanint	vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
100221828Sgrehanint	vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
101221828Sgrehanint	vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
102221828Sgrehan			   vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
103259537Sneelint	vm_setup_pptdev_msi(struct vmctx *ctx, int vcpu, int bus, int slot,
104259537Sneel	    int func, uint64_t addr, uint64_t msg, int numvec);
105259537Sneelint	vm_setup_pptdev_msix(struct vmctx *ctx, int vcpu, int bus, int slot,
106259537Sneel	    int func, int idx, uint64_t addr, uint64_t msg,
107259537Sneel	    uint32_t vector_control);
108221828Sgrehan
109268889Sneelint	vm_get_intinfo(struct vmctx *ctx, int vcpu, uint64_t *i1, uint64_t *i2);
110268889Sneelint	vm_set_intinfo(struct vmctx *ctx, int vcpu, uint64_t exit_intinfo);
111268889Sneel
112221828Sgrehan/*
113221828Sgrehan * Return a pointer to the statistics buffer. Note that this is not MT-safe.
114221828Sgrehan */
115221828Sgrehanuint64_t *vm_get_stats(struct vmctx *ctx, int vcpu, struct timeval *ret_tv,
116221828Sgrehan		       int *ret_entries);
117221828Sgrehanconst char *vm_get_stat_desc(struct vmctx *ctx, int index);
118221828Sgrehan
119240922Sneelint	vm_get_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state *s);
120240922Sneelint	vm_set_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state s);
121240922Sneel
122258579Sneelint	vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities);
123258579Sneel
124266708Sneel/*
125266708Sneel * Translate the GLA range [gla,gla+len) into GPA segments in 'iov'.
126266708Sneel * The 'iovcnt' should be big enough to accomodate all GPA segments.
127266708Sneel * Returns 0 on success, 1 on a guest fault condition and -1 otherwise.
128266708Sneel */
129269008Sneelint	vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *pg,
130266708Sneel	    uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt);
131266708Sneelvoid	vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *guest_iov,
132266708Sneel	    void *host_dst, size_t len);
133266708Sneelvoid	vm_copyout(struct vmctx *ctx, int vcpu, const void *host_src,
134266708Sneel	    struct iovec *guest_iov, size_t len);
135266633Sneel
136276428Sneel/* RTC */
137276428Sneelint	vm_rtc_write(struct vmctx *ctx, int offset, uint8_t value);
138276428Sneelint	vm_rtc_read(struct vmctx *ctx, int offset, uint8_t *retval);
139276428Sneelint	vm_rtc_settime(struct vmctx *ctx, time_t secs);
140276428Sneelint	vm_rtc_gettime(struct vmctx *ctx, time_t *secs);
141276428Sneel
142221828Sgrehan/* Reset vcpu register state */
143221828Sgrehanint	vcpu_reset(struct vmctx *ctx, int vcpu);
144221828Sgrehan
145266933Sneelint	vm_active_cpus(struct vmctx *ctx, cpuset_t *cpus);
146266933Sneelint	vm_suspended_cpus(struct vmctx *ctx, cpuset_t *cpus);
147266933Sneelint	vm_activate_cpu(struct vmctx *ctx, int vcpu);
148266933Sneel
149221828Sgrehan/*
150221828Sgrehan * FreeBSD specific APIs
151221828Sgrehan */
152221828Sgrehanint	vm_setup_freebsd_registers(struct vmctx *ctx, int vcpu,
153221828Sgrehan				uint64_t rip, uint64_t cr3, uint64_t gdtbase,
154221828Sgrehan				uint64_t rsp);
155261504Sjhbint	vm_setup_freebsd_registers_i386(struct vmctx *vmctx, int vcpu,
156261504Sjhb					uint32_t eip, uint32_t gdtbase,
157261504Sjhb					uint32_t esp);
158221828Sgrehanvoid	vm_setup_freebsd_gdt(uint64_t *gdtr);
159221828Sgrehan#endif	/* _VMMAPI_H_ */
160