xref: /freebsd/usr.sbin/bhyve/bhyverun.h (revision 390e44988aeaa824a9ea4f0e352f9a252093c170)
1e285ef8dSPeter Grehan /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
4e285ef8dSPeter Grehan  * Copyright (c) 2011 NetApp, Inc.
5e285ef8dSPeter Grehan  * All rights reserved.
6e285ef8dSPeter Grehan  *
7e285ef8dSPeter Grehan  * Redistribution and use in source and binary forms, with or without
8e285ef8dSPeter Grehan  * modification, are permitted provided that the following conditions
9e285ef8dSPeter Grehan  * are met:
10e285ef8dSPeter Grehan  * 1. Redistributions of source code must retain the above copyright
11e285ef8dSPeter Grehan  *    notice, this list of conditions and the following disclaimer.
12e285ef8dSPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
13e285ef8dSPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
14e285ef8dSPeter Grehan  *    documentation and/or other materials provided with the distribution.
15e285ef8dSPeter Grehan  *
16e285ef8dSPeter Grehan  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17e285ef8dSPeter Grehan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18e285ef8dSPeter Grehan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19e285ef8dSPeter Grehan  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20e285ef8dSPeter Grehan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21e285ef8dSPeter Grehan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22e285ef8dSPeter Grehan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23e285ef8dSPeter Grehan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24e285ef8dSPeter Grehan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25e285ef8dSPeter Grehan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e285ef8dSPeter Grehan  * SUCH DAMAGE.
27e285ef8dSPeter Grehan  */
28e285ef8dSPeter Grehan 
29e20b74daSMark Johnston #ifndef	_BHYVERUN_H_
30e20b74daSMark Johnston #define	_BHYVERUN_H_
31e20b74daSMark Johnston 
32e20b74daSMark Johnston #include <stdbool.h>
33e285ef8dSPeter Grehan 
34d087a399SNeel Natu #define	VMEXIT_CONTINUE		(0)
35d087a399SNeel Natu #define	VMEXIT_ABORT		(-1)
363d5444c8SNeel Natu 
37e285ef8dSPeter Grehan extern int guest_ncpus;
383b6cb9b4SMark Johnston extern uint16_t cpu_cores, cpu_sockets, cpu_threads;
39e285ef8dSPeter Grehan 
40*390e4498SMark Johnston #ifdef BHYVE_SNAPSHOT
41*390e4498SMark Johnston extern char *restore_file;
42*390e4498SMark Johnston #endif
43*390e4498SMark Johnston 
447d9ef309SJohn Baldwin struct vcpu;
45f703dc0eSMark Johnston struct vmctx;
46e17eca32SMark Johnston struct vm_run;
47f703dc0eSMark Johnston 
48b060ba50SNeel Natu void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len);
49483d953aSJohn Baldwin #ifdef BHYVE_SNAPSHOT
50483d953aSJohn Baldwin uintptr_t paddr_host2guest(struct vmctx *ctx, void *addr);
51483d953aSJohn Baldwin #endif
52e285ef8dSPeter Grehan 
5372f9c9d8SMark Johnston struct vcpu;
5472f9c9d8SMark Johnston struct vcpu *fbsdrun_vcpu(int vcpuid);
55e20b74daSMark Johnston void fbsdrun_addcpu(int vcpuid);
5672f9c9d8SMark Johnston void fbsdrun_deletecpu(int vcpuid);
5772f9c9d8SMark Johnston int fbsdrun_suspendcpu(int vcpuid);
5872f9c9d8SMark Johnston 
59062b878fSPeter Grehan int  fbsdrun_virtio_msix(void);
60621b5090SJohn Baldwin 
6172f9c9d8SMark Johnston typedef int (*vmexit_handler_t)(struct vmctx *, struct vcpu *, struct vm_run *);
6272f9c9d8SMark Johnston 
63e20b74daSMark Johnston /* Interfaces implemented by machine-dependent code. */
64e20b74daSMark Johnston void bhyve_init_config(void);
65981f9f74SMark Johnston void bhyve_optparse(int argc, char **argv);
66981f9f74SMark Johnston void bhyve_usage(int code);
67981f9f74SMark Johnston 
68981f9f74SMark Johnston /* Interfaces used by command-line option-parsing code. */
69981f9f74SMark Johnston bool bhyve_parse_config_option(const char *option);
70981f9f74SMark Johnston void bhyve_parse_simple_config_file(const char *path);
71981f9f74SMark Johnston #ifdef BHYVE_GDB
72981f9f74SMark Johnston void bhyve_parse_gdb_options(const char *opt);
73981f9f74SMark Johnston #endif
74981f9f74SMark Johnston int bhyve_pincpu_parse(const char *opt);
75981f9f74SMark Johnston int bhyve_topology_parse(const char *opt);
76981f9f74SMark Johnston 
77e20b74daSMark Johnston void bhyve_init_vcpu(struct vcpu *vcpu);
78e20b74daSMark Johnston void bhyve_start_vcpu(struct vcpu *vcpu, bool bsp);
79f82af74cSMark Johnston int bhyve_init_platform(struct vmctx *ctx, struct vcpu *bsp);
80f82af74cSMark Johnston int bhyve_init_platform_late(struct vmctx *ctx, struct vcpu *bsp);
81e20b74daSMark Johnston 
82e285ef8dSPeter Grehan #endif
83