1bf21cd93STycho Nightingale /*-
2*32640292SAndy Fiddaman  * SPDX-License-Identifier: BSD-2-Clause
34c87aefeSPatrick Mooney  *
4bf21cd93STycho Nightingale  * Copyright (c) 2011 NetApp, Inc.
5bf21cd93STycho Nightingale  * All rights reserved.
6bf21cd93STycho Nightingale  *
7bf21cd93STycho Nightingale  * Redistribution and use in source and binary forms, with or without
8bf21cd93STycho Nightingale  * modification, are permitted provided that the following conditions
9bf21cd93STycho Nightingale  * are met:
10bf21cd93STycho Nightingale  * 1. Redistributions of source code must retain the above copyright
11bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer.
12bf21cd93STycho Nightingale  * 2. Redistributions in binary form must reproduce the above copyright
13bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer in the
14bf21cd93STycho Nightingale  *    documentation and/or other materials provided with the distribution.
15bf21cd93STycho Nightingale  *
16bf21cd93STycho Nightingale  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17bf21cd93STycho Nightingale  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18bf21cd93STycho Nightingale  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19bf21cd93STycho Nightingale  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20bf21cd93STycho Nightingale  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21bf21cd93STycho Nightingale  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22bf21cd93STycho Nightingale  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23bf21cd93STycho Nightingale  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24bf21cd93STycho Nightingale  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25bf21cd93STycho Nightingale  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26bf21cd93STycho Nightingale  * SUCH DAMAGE.
27bf21cd93STycho Nightingale  */
28bf21cd93STycho Nightingale /*
29bf21cd93STycho Nightingale  * This file and its contents are supplied under the terms of the
30bf21cd93STycho Nightingale  * Common Development and Distribution License ("CDDL"), version 1.0.
31bf21cd93STycho Nightingale  * You may only use this file in accordance with the terms of version
32bf21cd93STycho Nightingale  * 1.0 of the CDDL.
33bf21cd93STycho Nightingale  *
34bf21cd93STycho Nightingale  * A full copy of the text of the CDDL should have accompanied this
35bf21cd93STycho Nightingale  * source.  A copy of the CDDL is also available via the Internet at
36bf21cd93STycho Nightingale  * http://www.illumos.org/license/CDDL.
37bf21cd93STycho Nightingale  *
38bf21cd93STycho Nightingale  * Copyright 2015 Pluribus Networks Inc.
394c87aefeSPatrick Mooney  * Copyright 2019 Joyent, Inc.
4072473353SPatrick Mooney  * Copyright 2023 Oxide Computer Company
41bf21cd93STycho Nightingale  */
42bf21cd93STycho Nightingale 
43bf21cd93STycho Nightingale #ifndef _VMMAPI_H_
44bf21cd93STycho Nightingale #define	_VMMAPI_H_
45bf21cd93STycho Nightingale 
46bf21cd93STycho Nightingale #include <sys/param.h>
474c87aefeSPatrick Mooney #include <sys/cpuset.h>
48b58b977eSPatrick Mooney #include <x86/segments.h>
494c87aefeSPatrick Mooney 
50154972afSPatrick Mooney #include <stdbool.h>
51154972afSPatrick Mooney 
524c87aefeSPatrick Mooney /*
534c87aefeSPatrick Mooney  * API version for out-of-tree consumers like grub-bhyve for making compile
544c87aefeSPatrick Mooney  * time decisions.
554c87aefeSPatrick Mooney  */
56*32640292SAndy Fiddaman #define	VMMAPI_VERSION	0200	/* 2 digit major followed by 2 digit minor */
57bf21cd93STycho Nightingale 
58bf21cd93STycho Nightingale struct iovec;
59*32640292SAndy Fiddaman struct vcpu;
60bf21cd93STycho Nightingale struct vmctx;
61bf21cd93STycho Nightingale enum x2apic_state;
62bf21cd93STycho Nightingale 
63bf21cd93STycho Nightingale /*
64bf21cd93STycho Nightingale  * Different styles of mapping the memory assigned to a VM into the address
65bf21cd93STycho Nightingale  * space of the controlling process.
66bf21cd93STycho Nightingale  */
67bf21cd93STycho Nightingale enum vm_mmap_style {
68bf21cd93STycho Nightingale 	VM_MMAP_NONE,		/* no mapping */
69bf21cd93STycho Nightingale 	VM_MMAP_ALL,		/* fully and statically mapped */
70bf21cd93STycho Nightingale 	VM_MMAP_SPARSE,		/* mappings created on-demand */
71bf21cd93STycho Nightingale };
72bf21cd93STycho Nightingale 
734c87aefeSPatrick Mooney /*
744c87aefeSPatrick Mooney  * 'flags' value passed to 'vm_set_memflags()'.
754c87aefeSPatrick Mooney  */
764c87aefeSPatrick Mooney #define	VM_MEM_F_INCORE	0x01	/* include guest memory in core file */
774c87aefeSPatrick Mooney #define	VM_MEM_F_WIRED	0x02	/* guest memory is wired */
784c87aefeSPatrick Mooney 
794c87aefeSPatrick Mooney /*
804c87aefeSPatrick Mooney  * Identifiers for memory segments:
814c87aefeSPatrick Mooney  * - vm_setup_memory() uses VM_SYSMEM for the system memory segment.
824c87aefeSPatrick Mooney  * - the remaining identifiers can be used to create devmem segments.
834c87aefeSPatrick Mooney  */
844c87aefeSPatrick Mooney enum {
854c87aefeSPatrick Mooney #ifdef __FreeBSD__
864c87aefeSPatrick Mooney 	VM_SYSMEM,
874c87aefeSPatrick Mooney #else
884c87aefeSPatrick Mooney 	VM_LOWMEM,
894c87aefeSPatrick Mooney 	VM_HIGHMEM,
904c87aefeSPatrick Mooney #endif
914c87aefeSPatrick Mooney 	VM_BOOTROM,
924c87aefeSPatrick Mooney 	VM_FRAMEBUFFER,
93d7b72f7bSAndy Fiddaman 	VM_PCIROM,
944c87aefeSPatrick Mooney };
954c87aefeSPatrick Mooney 
964f3f3e9aSAndy Fiddaman #ifdef	__cplusplus
974f3f3e9aSAndy Fiddaman extern "C" {
984f3f3e9aSAndy Fiddaman #endif
994f3f3e9aSAndy Fiddaman 
1004c87aefeSPatrick Mooney /*
1014c87aefeSPatrick Mooney  * Get the length and name of the memory segment identified by 'segid'.
1024c87aefeSPatrick Mooney  * Note that system memory segments are identified with a nul name.
1034c87aefeSPatrick Mooney  *
1044c87aefeSPatrick Mooney  * Returns 0 on success and non-zero otherwise.
1054c87aefeSPatrick Mooney  */
1064c87aefeSPatrick Mooney int	vm_get_memseg(struct vmctx *ctx, int ident, size_t *lenp, char *name,
1074c87aefeSPatrick Mooney 	    size_t namesiz);
1084c87aefeSPatrick Mooney 
1094c87aefeSPatrick Mooney /*
1104c87aefeSPatrick Mooney  * Iterate over the guest address space. This function finds an address range
1114c87aefeSPatrick Mooney  * that starts at an address >= *gpa.
1124c87aefeSPatrick Mooney  *
1134c87aefeSPatrick Mooney  * Returns 0 if the next address range was found and non-zero otherwise.
1144c87aefeSPatrick Mooney  */
1154c87aefeSPatrick Mooney int	vm_mmap_getnext(struct vmctx *ctx, vm_paddr_t *gpa, int *segid,
1164c87aefeSPatrick Mooney 	    vm_ooffset_t *segoff, size_t *len, int *prot, int *flags);
117*32640292SAndy Fiddaman 
118*32640292SAndy Fiddaman #ifdef	__FreeBSD__
119*32640292SAndy Fiddaman int	vm_get_guestmem_from_ctx(struct vmctx *ctx, char **guest_baseaddr,
120*32640292SAndy Fiddaman 				 size_t *lowmem_size, size_t *highmem_size);
121*32640292SAndy Fiddaman #endif
122*32640292SAndy Fiddaman 
1234c87aefeSPatrick Mooney /*
1244c87aefeSPatrick Mooney  * Create a device memory segment identified by 'segid'.
1254c87aefeSPatrick Mooney  *
1264c87aefeSPatrick Mooney  * Returns a pointer to the memory segment on success and MAP_FAILED otherwise.
1274c87aefeSPatrick Mooney  */
1284c87aefeSPatrick Mooney void	*vm_create_devmem(struct vmctx *ctx, int segid, const char *name,
1294c87aefeSPatrick Mooney 	    size_t len);
1304c87aefeSPatrick Mooney 
1319c3024a3SHans Rosenfeld #ifndef __FreeBSD__
1329c3024a3SHans Rosenfeld /*
1339c3024a3SHans Rosenfeld  * Return the map offset for the device memory segment 'segid'.
1349c3024a3SHans Rosenfeld  */
1359c3024a3SHans Rosenfeld int	vm_get_devmem_offset(struct vmctx *ctx, int segid, off_t *mapoff);
1369c3024a3SHans Rosenfeld #endif
1379c3024a3SHans Rosenfeld 
1384c87aefeSPatrick Mooney /*
1394c87aefeSPatrick Mooney  * Map the memory segment identified by 'segid' into the guest address space
1404c87aefeSPatrick Mooney  * at [gpa,gpa+len) with protection 'prot'.
1414c87aefeSPatrick Mooney  */
1424c87aefeSPatrick Mooney int	vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, int segid,
1434c87aefeSPatrick Mooney 	    vm_ooffset_t segoff, size_t len, int prot);
1444c87aefeSPatrick Mooney 
1452b948146SAndy Fiddaman int	vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len);
1462b948146SAndy Fiddaman 
147*32640292SAndy Fiddaman #ifdef __FreeBSD__
148bf21cd93STycho Nightingale int	vm_create(const char *name);
149*32640292SAndy Fiddaman #else
150*32640292SAndy Fiddaman int	vm_create(const char *name, uint64_t flags);
151b57f5d3eSPatrick Mooney #endif /* __FreeBSD__ */
152bf21cd93STycho Nightingale struct vmctx *vm_open(const char *name);
1539c3024a3SHans Rosenfeld void	vm_close(struct vmctx *ctx);
1544c87aefeSPatrick Mooney void	vm_destroy(struct vmctx *ctx);
155*32640292SAndy Fiddaman #ifdef	__FreeBSD__
156*32640292SAndy Fiddaman int	vm_limit_rights(struct vmctx *ctx);
157*32640292SAndy Fiddaman #endif
158*32640292SAndy Fiddaman struct vcpu *vm_vcpu_open(struct vmctx *ctx, int vcpuid);
159*32640292SAndy Fiddaman void	vm_vcpu_close(struct vcpu *vcpu);
160*32640292SAndy Fiddaman int	vcpu_id(struct vcpu *vcpu);
161*32640292SAndy Fiddaman #ifndef	__FreeBSD__
162*32640292SAndy Fiddaman struct vmctx *vcpu_ctx(struct vcpu *vcpu);
163*32640292SAndy Fiddaman #endif
164bf21cd93STycho Nightingale int	vm_parse_memsize(const char *optarg, size_t *memsize);
165bf21cd93STycho Nightingale int	vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
166bf21cd93STycho Nightingale void	*vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len);
167*32640292SAndy Fiddaman #ifdef	__FreeBSD__
168*32640292SAndy Fiddaman /* inverse operation to vm_map_gpa - extract guest address from host pointer */
169*32640292SAndy Fiddaman vm_paddr_t vm_rev_map_gpa(struct vmctx *ctx, void *addr);
170*32640292SAndy Fiddaman #endif
1714c87aefeSPatrick Mooney int	vm_get_gpa_pmap(struct vmctx *, uint64_t gpa, uint64_t *pte, int *num);
172*32640292SAndy Fiddaman int	vm_gla2gpa(struct vcpu *vcpu, struct vm_guest_paging *paging,
1734c87aefeSPatrick Mooney 		   uint64_t gla, int prot, uint64_t *gpa, int *fault);
174*32640292SAndy Fiddaman int	vm_gla2gpa_nofault(struct vcpu *vcpu,
1754c87aefeSPatrick Mooney 		   struct vm_guest_paging *paging, uint64_t gla, int prot,
1764c87aefeSPatrick Mooney 		   uint64_t *gpa, int *fault);
177bf21cd93STycho Nightingale uint32_t vm_get_lowmem_limit(struct vmctx *ctx);
178bf21cd93STycho Nightingale void	vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit);
1794c87aefeSPatrick Mooney void	vm_set_memflags(struct vmctx *ctx, int flags);
1804c87aefeSPatrick Mooney int	vm_get_memflags(struct vmctx *ctx);
181*32640292SAndy Fiddaman const char *vm_get_name(struct vmctx *ctx);
182bf21cd93STycho Nightingale size_t	vm_get_lowmem_size(struct vmctx *ctx);
183bf21cd93STycho Nightingale size_t	vm_get_highmem_size(struct vmctx *ctx);
184*32640292SAndy Fiddaman int	vm_set_desc(struct vcpu *vcpu, int reg,
185bf21cd93STycho Nightingale 		    uint64_t base, uint32_t limit, uint32_t access);
186*32640292SAndy Fiddaman int	vm_get_desc(struct vcpu *vcpu, int reg,
187bf21cd93STycho Nightingale 		    uint64_t *base, uint32_t *limit, uint32_t *access);
188*32640292SAndy Fiddaman int	vm_get_seg_desc(struct vcpu *vcpu, int reg, struct seg_desc *seg_desc);
189*32640292SAndy Fiddaman int	vm_set_register(struct vcpu *vcpu, int reg, uint64_t val);
190*32640292SAndy Fiddaman int	vm_get_register(struct vcpu *vcpu, int reg, uint64_t *retval);
191*32640292SAndy Fiddaman int	vm_set_register_set(struct vcpu *vcpu, unsigned int count,
1924c87aefeSPatrick Mooney     const int *regnums, uint64_t *regvals);
193*32640292SAndy Fiddaman int	vm_get_register_set(struct vcpu *vcpu, unsigned int count,
1944c87aefeSPatrick Mooney     const int *regnums, uint64_t *regvals);
195*32640292SAndy Fiddaman #ifdef	__FreeBSD__
196*32640292SAndy Fiddaman int	vm_run(struct vcpu *vcpu, struct vm_exit *ret_vmexit);
197*32640292SAndy Fiddaman #else
198*32640292SAndy Fiddaman int	vm_run(struct vcpu *vcpu, const struct vm_entry *vm_entry,
199e0c0d44eSPatrick Mooney     struct vm_exit *vm_exit);
200*32640292SAndy Fiddaman #endif
2014c87aefeSPatrick Mooney int	vm_suspend(struct vmctx *ctx, enum vm_suspend_how how);
202*32640292SAndy Fiddaman #ifdef __FreeBSD__
2034c87aefeSPatrick Mooney int	vm_reinit(struct vmctx *ctx);
204*32640292SAndy Fiddaman #else
205*32640292SAndy Fiddaman int	vm_reinit(struct vmctx *ctx, uint64_t);
20652fac30eSPatrick Mooney #endif
207bf21cd93STycho Nightingale int	vm_apicid2vcpu(struct vmctx *ctx, int apicid);
208*32640292SAndy Fiddaman int	vm_inject_exception(struct vcpu *vcpu, int vector,
209bf21cd93STycho Nightingale     int errcode_valid, uint32_t errcode, int restart_instruction);
210b58b977eSPatrick Mooney #ifndef __FreeBSD__
211*32640292SAndy Fiddaman void	vm_inject_fault(struct vcpu *vcpu, int vector,
212b58b977eSPatrick Mooney     int errcode_valid, int errcode);
213b58b977eSPatrick Mooney 
214b58b977eSPatrick Mooney static __inline void
vm_inject_gp(struct vcpu * vcpu)215*32640292SAndy Fiddaman vm_inject_gp(struct vcpu *vcpu)
216b58b977eSPatrick Mooney {
217*32640292SAndy Fiddaman 	vm_inject_fault(vcpu, IDT_GP, 1, 0);
218b58b977eSPatrick Mooney }
219b58b977eSPatrick Mooney 
220b58b977eSPatrick Mooney static __inline void
vm_inject_ac(struct vcpu * vcpu,int errcode)221*32640292SAndy Fiddaman vm_inject_ac(struct vcpu *vcpu, int errcode)
222b58b977eSPatrick Mooney {
223*32640292SAndy Fiddaman 	vm_inject_fault(vcpu, IDT_AC, 1, errcode);
224b58b977eSPatrick Mooney }
225b58b977eSPatrick Mooney static __inline void
vm_inject_ss(struct vcpu * vcpu,int errcode)226*32640292SAndy Fiddaman vm_inject_ss(struct vcpu *vcpu, int errcode)
227b58b977eSPatrick Mooney {
228*32640292SAndy Fiddaman 	vm_inject_fault(vcpu, IDT_SS, 1, errcode);
229b58b977eSPatrick Mooney }
230b58b977eSPatrick Mooney #endif
231*32640292SAndy Fiddaman int	vm_lapic_irq(struct vcpu *vcpu, int vector);
232*32640292SAndy Fiddaman int	vm_lapic_local_irq(struct vcpu *vcpu, int vector);
233bf21cd93STycho Nightingale int	vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg);
234bf21cd93STycho Nightingale int	vm_ioapic_assert_irq(struct vmctx *ctx, int irq);
235bf21cd93STycho Nightingale int	vm_ioapic_deassert_irq(struct vmctx *ctx, int irq);
236bf21cd93STycho Nightingale int	vm_ioapic_pulse_irq(struct vmctx *ctx, int irq);
237bf21cd93STycho Nightingale int	vm_ioapic_pincount(struct vmctx *ctx, int *pincount);
238*32640292SAndy Fiddaman int	vm_readwrite_kernemu_device(struct vcpu *vcpu,
239154972afSPatrick Mooney 	    vm_paddr_t gpa, bool write, int size, uint64_t *value);
240bf21cd93STycho Nightingale int	vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
241bf21cd93STycho Nightingale int	vm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
242bf21cd93STycho Nightingale int	vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
243bf21cd93STycho Nightingale int	vm_isa_set_irq_trigger(struct vmctx *ctx, int atpic_irq,
244bf21cd93STycho Nightingale 	    enum vm_intr_trigger trigger);
245*32640292SAndy Fiddaman int	vm_inject_nmi(struct vcpu *vcpu);
246bf21cd93STycho Nightingale int	vm_capability_name2type(const char *capname);
247bf21cd93STycho Nightingale const char *vm_capability_type2name(int type);
248*32640292SAndy Fiddaman int	vm_get_capability(struct vcpu *vcpu, enum vm_cap_type cap,
249bf21cd93STycho Nightingale 			  int *retval);
250*32640292SAndy Fiddaman int	vm_set_capability(struct vcpu *vcpu, enum vm_cap_type cap,
251bf21cd93STycho Nightingale 			  int val);
252eb9a1df2SHans Rosenfeld #ifdef __FreeBSD__
253bf21cd93STycho Nightingale int	vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
254bf21cd93STycho Nightingale int	vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
255bf21cd93STycho Nightingale int	vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
256bf21cd93STycho Nightingale 			   vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
2572b948146SAndy Fiddaman int	vm_unmap_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
2582b948146SAndy Fiddaman 			     vm_paddr_t gpa, size_t len);
259*32640292SAndy Fiddaman int	vm_setup_pptdev_msi(struct vmctx *ctx, int bus, int slot,
260bf21cd93STycho Nightingale 	    int func, uint64_t addr, uint64_t msg, int numvec);
261*32640292SAndy Fiddaman int	vm_setup_pptdev_msix(struct vmctx *ctx, int bus, int slot,
262bf21cd93STycho Nightingale 	    int func, int idx, uint64_t addr, uint64_t msg,
263bf21cd93STycho Nightingale 	    uint32_t vector_control);
2646960cd89SAndy Fiddaman int	vm_disable_pptdev_msix(struct vmctx *ctx, int bus, int slot, int func);
265eb9a1df2SHans Rosenfeld #else /* __FreeBSD__ */
266eb9a1df2SHans Rosenfeld int	vm_assign_pptdev(struct vmctx *ctx, int pptfd);
267eb9a1df2SHans Rosenfeld int	vm_unassign_pptdev(struct vmctx *ctx, int pptfd);
268eb9a1df2SHans Rosenfeld int	vm_map_pptdev_mmio(struct vmctx *ctx, int pptfd, vm_paddr_t gpa,
269eb9a1df2SHans Rosenfeld     size_t len, vm_paddr_t hpa);
2702b948146SAndy Fiddaman int	vm_unmap_pptdev_mmio(struct vmctx *ctx, int pptfd, vm_paddr_t gpa,
2712b948146SAndy Fiddaman     size_t len);
272*32640292SAndy Fiddaman int	vm_setup_pptdev_msi(struct vmctx *ctx, int pptfd, uint64_t addr,
273*32640292SAndy Fiddaman     uint64_t msg, int numvec);
274*32640292SAndy Fiddaman int	vm_setup_pptdev_msix(struct vmctx *ctx, int pptfd, int idx, uint64_t
275*32640292SAndy Fiddaman     addr, uint64_t msg, uint32_t vector_control);
2766960cd89SAndy Fiddaman int	vm_disable_pptdev_msix(struct vmctx *ctx, int pptfd);
277eb9a1df2SHans Rosenfeld int	vm_get_pptdev_limits(struct vmctx *ctx, int pptfd, int *msi_limit,
278eb9a1df2SHans Rosenfeld     int *msix_limit);
279eb9a1df2SHans Rosenfeld #endif /* __FreeBSD__ */
280bf21cd93STycho Nightingale 
281*32640292SAndy Fiddaman int	vm_get_intinfo(struct vcpu *vcpu, uint64_t *i1, uint64_t *i2);
282*32640292SAndy Fiddaman int	vm_set_intinfo(struct vcpu *vcpu, uint64_t exit_intinfo);
2834c87aefeSPatrick Mooney 
284bf21cd93STycho Nightingale /*
285bf21cd93STycho Nightingale  * Return a pointer to the statistics buffer. Note that this is not MT-safe.
286bf21cd93STycho Nightingale  */
287*32640292SAndy Fiddaman uint64_t *vm_get_stats(struct vcpu *vcpu, struct timeval *ret_tv,
288bf21cd93STycho Nightingale 		       int *ret_entries);
289bf21cd93STycho Nightingale const char *vm_get_stat_desc(struct vmctx *ctx, int index);
290bf21cd93STycho Nightingale 
291*32640292SAndy Fiddaman int	vm_get_x2apic_state(struct vcpu *vcpu, enum x2apic_state *s);
292*32640292SAndy Fiddaman int	vm_set_x2apic_state(struct vcpu *vcpu, enum x2apic_state s);
293bf21cd93STycho Nightingale 
294bf21cd93STycho Nightingale int	vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities);
295bf21cd93STycho Nightingale 
296bf21cd93STycho Nightingale /*
297bf21cd93STycho Nightingale  * Translate the GLA range [gla,gla+len) into GPA segments in 'iov'.
2984c87aefeSPatrick Mooney  * The 'iovcnt' should be big enough to accommodate all GPA segments.
2994c87aefeSPatrick Mooney  *
3004c87aefeSPatrick Mooney  * retval	fault		Interpretation
3014c87aefeSPatrick Mooney  *   0		  0		Success
3024c87aefeSPatrick Mooney  *   0		  1		An exception was injected into the guest
3034c87aefeSPatrick Mooney  * EFAULT	 N/A		Error
304bf21cd93STycho Nightingale  */
305*32640292SAndy Fiddaman int	vm_copy_setup(struct vcpu *vcpu, struct vm_guest_paging *pg,
3064c87aefeSPatrick Mooney 	    uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt,
3074c87aefeSPatrick Mooney 	    int *fault);
308*32640292SAndy Fiddaman void	vm_copyin(struct iovec *guest_iov, void *host_dst, size_t len);
309*32640292SAndy Fiddaman void	vm_copyout(const void *host_src, struct iovec *guest_iov, size_t len);
310*32640292SAndy Fiddaman void	vm_copy_teardown(struct iovec *iov, int iovcnt);
311bf21cd93STycho Nightingale 
3124c87aefeSPatrick Mooney /* RTC */
3134c87aefeSPatrick Mooney int	vm_rtc_write(struct vmctx *ctx, int offset, uint8_t value);
3144c87aefeSPatrick Mooney int	vm_rtc_read(struct vmctx *ctx, int offset, uint8_t *retval);
315a1d41cf9SPatrick Mooney #ifdef __FreeBSD__
3164c87aefeSPatrick Mooney int	vm_rtc_settime(struct vmctx *ctx, time_t secs);
3174c87aefeSPatrick Mooney int	vm_rtc_gettime(struct vmctx *ctx, time_t *secs);
318a1d41cf9SPatrick Mooney #else /* __FreeBSD__ */
319a1d41cf9SPatrick Mooney int	vm_rtc_settime(struct vmctx *ctx, const timespec_t *);
320a1d41cf9SPatrick Mooney int	vm_rtc_gettime(struct vmctx *ctx, timespec_t *);
321a1d41cf9SPatrick Mooney #endif /* __FreeBSD__ */
3224c87aefeSPatrick Mooney 
323bf21cd93STycho Nightingale /* Reset vcpu register state */
324*32640292SAndy Fiddaman int	vcpu_reset(struct vcpu *vcpu);
325bf21cd93STycho Nightingale 
3264c87aefeSPatrick Mooney int	vm_active_cpus(struct vmctx *ctx, cpuset_t *cpus);
32772473353SPatrick Mooney #ifdef	__FreeBSD__
3284c87aefeSPatrick Mooney int	vm_suspended_cpus(struct vmctx *ctx, cpuset_t *cpus);
32972473353SPatrick Mooney #endif	/* __FreeBSD__ */
3304c87aefeSPatrick Mooney int	vm_debug_cpus(struct vmctx *ctx, cpuset_t *cpus);
331*32640292SAndy Fiddaman int	vm_activate_cpu(struct vcpu *vcpu);
332*32640292SAndy Fiddaman int	vm_suspend_all_cpus(struct vmctx *ctx);
333*32640292SAndy Fiddaman int	vm_suspend_cpu(struct vcpu *vcpu);
334*32640292SAndy Fiddaman int	vm_resume_all_cpus(struct vmctx *ctx);
335*32640292SAndy Fiddaman int	vm_resume_cpu(struct vcpu *vcpu);
3364c87aefeSPatrick Mooney 
3374c87aefeSPatrick Mooney /* CPU topology */
3384c87aefeSPatrick Mooney int	vm_set_topology(struct vmctx *ctx, uint16_t sockets, uint16_t cores,
3394c87aefeSPatrick Mooney 	    uint16_t threads, uint16_t maxcpus);
3404c87aefeSPatrick Mooney int	vm_get_topology(struct vmctx *ctx, uint16_t *sockets, uint16_t *cores,
3414c87aefeSPatrick Mooney 	    uint16_t *threads, uint16_t *maxcpus);
3424c87aefeSPatrick Mooney 
3434c87aefeSPatrick Mooney #ifndef	__FreeBSD__
3444c87aefeSPatrick Mooney /* illumos-specific APIs */
3450e1453c3SPatrick Mooney int	vm_pmtmr_set_location(struct vmctx *ctx, uint16_t ioport);
3464c87aefeSPatrick Mooney int	vm_wrlock_cycle(struct vmctx *ctx);
347*32640292SAndy Fiddaman int vm_get_run_state(struct vcpu *vcpu, enum vcpu_run_state *state,
3482606939dSPatrick Mooney     uint8_t *sipi_vector);
349*32640292SAndy Fiddaman int vm_set_run_state(struct vcpu *vcpu, enum vcpu_run_state state,
3502606939dSPatrick Mooney     uint8_t sipi_vector);
351*32640292SAndy Fiddaman int vm_vcpu_barrier(struct vcpu *vcpu);
3524c87aefeSPatrick Mooney #endif	/* __FreeBSD__ */
353bf21cd93STycho Nightingale 
354bf21cd93STycho Nightingale #ifdef	__FreeBSD__
355bf21cd93STycho Nightingale /*
356bf21cd93STycho Nightingale  * FreeBSD specific APIs
357bf21cd93STycho Nightingale  */
358*32640292SAndy Fiddaman int	vm_setup_freebsd_registers(struct vcpu *vcpu,
359bf21cd93STycho Nightingale 				uint64_t rip, uint64_t cr3, uint64_t gdtbase,
360bf21cd93STycho Nightingale 				uint64_t rsp);
361*32640292SAndy Fiddaman int	vm_setup_freebsd_registers_i386(struct vcpu *vcpu,
362bf21cd93STycho Nightingale 					uint32_t eip, uint32_t gdtbase,
363bf21cd93STycho Nightingale 					uint32_t esp);
364bf21cd93STycho Nightingale void	vm_setup_freebsd_gdt(uint64_t *gdtr);
365bf21cd93STycho Nightingale #endif
3664f3f3e9aSAndy Fiddaman 
367*32640292SAndy Fiddaman /*
368*32640292SAndy Fiddaman  * Deprecated interfaces, do not use them in new code.
369*32640292SAndy Fiddaman  */
370*32640292SAndy Fiddaman int	vm_get_device_fd(struct vmctx *ctx);
371*32640292SAndy Fiddaman #ifdef	__FreeBSD__
372*32640292SAndy Fiddaman const cap_ioctl_t *vm_get_ioctls(size_t *len);
373*32640292SAndy Fiddaman #endif
374*32640292SAndy Fiddaman 
3754f3f3e9aSAndy Fiddaman #ifdef	__cplusplus
3764f3f3e9aSAndy Fiddaman }
3774f3f3e9aSAndy Fiddaman #endif
3784f3f3e9aSAndy Fiddaman 
379bf21cd93STycho Nightingale #endif	/* _VMMAPI_H_ */
380