xref: /illumos-gate/usr/src/uts/intel/sys/vmm_dev.h (revision b9b43e84)
1bf21cd93STycho Nightingale /*-
232640292SAndy 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.
40*b9b43e84SPatrick Mooney  * Copyright 2024 Oxide Computer Company
41bf21cd93STycho Nightingale  */
42bf21cd93STycho Nightingale 
43bf21cd93STycho Nightingale #ifndef	_VMM_DEV_H_
44bf21cd93STycho Nightingale #define	_VMM_DEV_H_
45bf21cd93STycho Nightingale 
464c87aefeSPatrick Mooney #include <machine/vmm.h>
474c87aefeSPatrick Mooney 
48b57f5d3eSPatrick Mooney #include <sys/param.h>
49b57f5d3eSPatrick Mooney #include <sys/cpuset.h>
50d515dd77SPatrick Mooney #include <sys/vmm_data.h>
51b57f5d3eSPatrick Mooney 
52b57f5d3eSPatrick Mooney struct vm_create_req {
53b57f5d3eSPatrick Mooney 	char		name[VM_MAX_NAMELEN];
54b57f5d3eSPatrick Mooney 	uint64_t	flags;
55b57f5d3eSPatrick Mooney };
56b57f5d3eSPatrick Mooney 
57b57f5d3eSPatrick Mooney 
58b57f5d3eSPatrick Mooney struct vm_destroy_req {
59b57f5d3eSPatrick Mooney 	char		name[VM_MAX_NAMELEN];
60b57f5d3eSPatrick Mooney };
61b57f5d3eSPatrick Mooney 
624c87aefeSPatrick Mooney struct vm_memmap {
634c87aefeSPatrick Mooney 	vm_paddr_t	gpa;
644c87aefeSPatrick Mooney 	int		segid;		/* memory segment */
654c87aefeSPatrick Mooney 	vm_ooffset_t	segoff;		/* offset into memory segment */
664c87aefeSPatrick Mooney 	size_t		len;		/* mmap length */
674c87aefeSPatrick Mooney 	int		prot;		/* RWX */
684c87aefeSPatrick Mooney 	int		flags;
694c87aefeSPatrick Mooney };
704c87aefeSPatrick Mooney #define	VM_MEMMAP_F_WIRED	0x01
714c87aefeSPatrick Mooney #define	VM_MEMMAP_F_IOMMU	0x02
72bf21cd93STycho Nightingale 
732b948146SAndy Fiddaman struct vm_munmap {
742b948146SAndy Fiddaman 	vm_paddr_t	gpa;
752b948146SAndy Fiddaman 	size_t		len;
762b948146SAndy Fiddaman };
772b948146SAndy Fiddaman 
784c87aefeSPatrick Mooney #define	VM_MEMSEG_NAME(m)	((m)->name[0] != '\0' ? (m)->name : NULL)
794c87aefeSPatrick Mooney struct vm_memseg {
804c87aefeSPatrick Mooney 	int		segid;
81bf21cd93STycho Nightingale 	size_t		len;
82b57f5d3eSPatrick Mooney 	char		name[VM_MAX_SEG_NAMELEN];
83bf21cd93STycho Nightingale };
84bf21cd93STycho Nightingale 
85bf21cd93STycho Nightingale struct vm_register {
86bf21cd93STycho Nightingale 	int		cpuid;
87bf21cd93STycho Nightingale 	int		regnum;		/* enum vm_reg_name */
88bf21cd93STycho Nightingale 	uint64_t	regval;
89bf21cd93STycho Nightingale };
90bf21cd93STycho Nightingale 
91bf21cd93STycho Nightingale struct vm_seg_desc {			/* data or code segment */
92bf21cd93STycho Nightingale 	int		cpuid;
93bf21cd93STycho Nightingale 	int		regnum;		/* enum vm_reg_name */
94bf21cd93STycho Nightingale 	struct seg_desc desc;
95bf21cd93STycho Nightingale };
96bf21cd93STycho Nightingale 
974c87aefeSPatrick Mooney struct vm_register_set {
984c87aefeSPatrick Mooney 	int		cpuid;
994c87aefeSPatrick Mooney 	unsigned int	count;
1004c87aefeSPatrick Mooney 	const int	*regnums;	/* enum vm_reg_name */
1014c87aefeSPatrick Mooney 	uint64_t	*regvals;
1024c87aefeSPatrick Mooney };
1034c87aefeSPatrick Mooney 
104bf21cd93STycho Nightingale struct vm_exception {
105bf21cd93STycho Nightingale 	int		cpuid;
106bf21cd93STycho Nightingale 	int		vector;
107bf21cd93STycho Nightingale 	uint32_t	error_code;
108bf21cd93STycho Nightingale 	int		error_code_valid;
109bf21cd93STycho Nightingale 	int		restart_instruction;
110bf21cd93STycho Nightingale };
111bf21cd93STycho Nightingale 
112bf21cd93STycho Nightingale struct vm_lapic_msi {
113bf21cd93STycho Nightingale 	uint64_t	msg;
114bf21cd93STycho Nightingale 	uint64_t	addr;
115bf21cd93STycho Nightingale };
116bf21cd93STycho Nightingale 
117bf21cd93STycho Nightingale struct vm_lapic_irq {
118bf21cd93STycho Nightingale 	int		cpuid;
119bf21cd93STycho Nightingale 	int		vector;
120bf21cd93STycho Nightingale };
121bf21cd93STycho Nightingale 
122bf21cd93STycho Nightingale struct vm_ioapic_irq {
123bf21cd93STycho Nightingale 	int		irq;
124bf21cd93STycho Nightingale };
125bf21cd93STycho Nightingale 
126bf21cd93STycho Nightingale struct vm_isa_irq {
127bf21cd93STycho Nightingale 	int		atpic_irq;
128bf21cd93STycho Nightingale 	int		ioapic_irq;
129bf21cd93STycho Nightingale };
130bf21cd93STycho Nightingale 
131bf21cd93STycho Nightingale struct vm_isa_irq_trigger {
132bf21cd93STycho Nightingale 	int		atpic_irq;
133bf21cd93STycho Nightingale 	enum vm_intr_trigger trigger;
134bf21cd93STycho Nightingale };
135bf21cd93STycho Nightingale 
136bf21cd93STycho Nightingale struct vm_capability {
137bf21cd93STycho Nightingale 	int		cpuid;
138bf21cd93STycho Nightingale 	enum vm_cap_type captype;
139bf21cd93STycho Nightingale 	int		capval;
140bf21cd93STycho Nightingale 	int		allcpus;
141bf21cd93STycho Nightingale };
142bf21cd93STycho Nightingale 
143eb9a1df2SHans Rosenfeld struct vm_pptdev {
144eb9a1df2SHans Rosenfeld 	int		pptfd;
145eb9a1df2SHans Rosenfeld };
146eb9a1df2SHans Rosenfeld 
147eb9a1df2SHans Rosenfeld struct vm_pptdev_mmio {
148eb9a1df2SHans Rosenfeld 	int		pptfd;
149eb9a1df2SHans Rosenfeld 	vm_paddr_t	gpa;
150eb9a1df2SHans Rosenfeld 	vm_paddr_t	hpa;
151eb9a1df2SHans Rosenfeld 	size_t		len;
152eb9a1df2SHans Rosenfeld };
153eb9a1df2SHans Rosenfeld 
154eb9a1df2SHans Rosenfeld struct vm_pptdev_msi {
155eb9a1df2SHans Rosenfeld 	int		vcpu;
156eb9a1df2SHans Rosenfeld 	int		pptfd;
157eb9a1df2SHans Rosenfeld 	int		numvec;		/* 0 means disabled */
158eb9a1df2SHans Rosenfeld 	uint64_t	msg;
159eb9a1df2SHans Rosenfeld 	uint64_t	addr;
160eb9a1df2SHans Rosenfeld };
161eb9a1df2SHans Rosenfeld 
162eb9a1df2SHans Rosenfeld struct vm_pptdev_msix {
163eb9a1df2SHans Rosenfeld 	int		vcpu;
164eb9a1df2SHans Rosenfeld 	int		pptfd;
165eb9a1df2SHans Rosenfeld 	int		idx;
166eb9a1df2SHans Rosenfeld 	uint64_t	msg;
167eb9a1df2SHans Rosenfeld 	uint32_t	vector_control;
168eb9a1df2SHans Rosenfeld 	uint64_t	addr;
169eb9a1df2SHans Rosenfeld };
170eb9a1df2SHans Rosenfeld 
171eb9a1df2SHans Rosenfeld struct vm_pptdev_limits {
172eb9a1df2SHans Rosenfeld 	int		pptfd;
173eb9a1df2SHans Rosenfeld 	int		msi_limit;
174eb9a1df2SHans Rosenfeld 	int		msix_limit;
175eb9a1df2SHans Rosenfeld };
176eb9a1df2SHans Rosenfeld 
177bf21cd93STycho Nightingale struct vm_nmi {
178bf21cd93STycho Nightingale 	int		cpuid;
179bf21cd93STycho Nightingale };
180bf21cd93STycho Nightingale 
181d7b72f7bSAndy Fiddaman #define	MAX_VM_STATS	64
1824c87aefeSPatrick Mooney 
183bf21cd93STycho Nightingale struct vm_stats {
184bf21cd93STycho Nightingale 	int		cpuid;				/* in */
185d7b72f7bSAndy Fiddaman 	int		index;				/* in */
186bf21cd93STycho Nightingale 	int		num_entries;			/* out */
187bf21cd93STycho Nightingale 	struct timeval	tv;
188bf21cd93STycho Nightingale 	uint64_t	statbuf[MAX_VM_STATS];
189bf21cd93STycho Nightingale };
190bf21cd93STycho Nightingale 
191bf21cd93STycho Nightingale struct vm_stat_desc {
192bf21cd93STycho Nightingale 	int		index;				/* in */
193bf21cd93STycho Nightingale 	char		desc[128];			/* out */
194bf21cd93STycho Nightingale };
195bf21cd93STycho Nightingale 
196bf21cd93STycho Nightingale struct vm_x2apic {
197bf21cd93STycho Nightingale 	int			cpuid;
198bf21cd93STycho Nightingale 	enum x2apic_state	state;
199bf21cd93STycho Nightingale };
200bf21cd93STycho Nightingale 
201bf21cd93STycho Nightingale struct vm_gpa_pte {
202bf21cd93STycho Nightingale 	uint64_t	gpa;				/* in */
203bf21cd93STycho Nightingale 	uint64_t	pte[4];				/* out */
204bf21cd93STycho Nightingale 	int		ptenum;
205bf21cd93STycho Nightingale };
206bf21cd93STycho Nightingale 
207bf21cd93STycho Nightingale struct vm_hpet_cap {
208bf21cd93STycho Nightingale 	uint32_t	capabilities;	/* lower 32 bits of HPET capabilities */
209bf21cd93STycho Nightingale };
210bf21cd93STycho Nightingale 
2114c87aefeSPatrick Mooney struct vm_suspend {
2124c87aefeSPatrick Mooney 	enum vm_suspend_how how;
21372473353SPatrick Mooney 	int source;
214bf21cd93STycho Nightingale };
215bf21cd93STycho Nightingale 
21672473353SPatrick Mooney /*
21772473353SPatrick Mooney  * Deprecated flags for vm_reinit`flags:
21872473353SPatrick Mooney  *
21972473353SPatrick Mooney  * Suspend (by force) VM as part of reinit.  Effectively a no-op since
22072473353SPatrick Mooney  * suspension requirements during reinit have been lifted.
22172473353SPatrick Mooney  *
22272473353SPatrick Mooney  * #define VM_REINIT_F_FORCE_SUSPEND	(1 << 0)
22372473353SPatrick Mooney  */
22452fac30eSPatrick Mooney 
22552fac30eSPatrick Mooney struct vm_reinit {
22652fac30eSPatrick Mooney 	uint64_t	flags;
22752fac30eSPatrick Mooney };
22852fac30eSPatrick Mooney 
229bf21cd93STycho Nightingale struct vm_gla2gpa {
230bf21cd93STycho Nightingale 	int		vcpuid;		/* inputs */
23184971882SPatrick Mooney 	int		prot;		/* PROT_READ or PROT_WRITE */
232bf21cd93STycho Nightingale 	uint64_t	gla;
233bf21cd93STycho Nightingale 	struct vm_guest_paging paging;
234bf21cd93STycho Nightingale 	int		fault;		/* outputs */
235bf21cd93STycho Nightingale 	uint64_t	gpa;
236bf21cd93STycho Nightingale };
237bf21cd93STycho Nightingale 
2384c87aefeSPatrick Mooney struct vm_activate_cpu {
2394c87aefeSPatrick Mooney 	int		vcpuid;
2404c87aefeSPatrick Mooney };
2414c87aefeSPatrick Mooney 
242bf21cd93STycho Nightingale struct vm_cpuset {
243bf21cd93STycho Nightingale 	int		which;
244bf21cd93STycho Nightingale 	int		cpusetsize;
2454c87aefeSPatrick Mooney #ifndef _KERNEL
246bf21cd93STycho Nightingale 	cpuset_t	*cpus;
2474c87aefeSPatrick Mooney #else
2484c87aefeSPatrick Mooney 	void		*cpus;
2494c87aefeSPatrick Mooney #endif
250bf21cd93STycho Nightingale };
251bf21cd93STycho Nightingale #define	VM_ACTIVE_CPUS		0
25272473353SPatrick Mooney /*
25372473353SPatrick Mooney  * Deprecated:
25472473353SPatrick Mooney  * #define VM_SUSPENDED_CPUS	1
25572473353SPatrick Mooney  */
2564c87aefeSPatrick Mooney #define	VM_DEBUG_CPUS		2
2574c87aefeSPatrick Mooney 
2584c87aefeSPatrick Mooney struct vm_intinfo {
2594c87aefeSPatrick Mooney 	int		vcpuid;
2604c87aefeSPatrick Mooney 	uint64_t	info1;
2614c87aefeSPatrick Mooney 	uint64_t	info2;
2624c87aefeSPatrick Mooney };
2634c87aefeSPatrick Mooney 
2644c87aefeSPatrick Mooney struct vm_rtc_data {
2654c87aefeSPatrick Mooney 	int		offset;
2664c87aefeSPatrick Mooney 	uint8_t		value;
2674c87aefeSPatrick Mooney };
2684c87aefeSPatrick Mooney 
2694c87aefeSPatrick Mooney struct vm_devmem_offset {
2704c87aefeSPatrick Mooney 	int		segid;
2714c87aefeSPatrick Mooney 	off_t		offset;
2724c87aefeSPatrick Mooney };
2734c87aefeSPatrick Mooney 
2744c87aefeSPatrick Mooney struct vm_cpu_topology {
2754c87aefeSPatrick Mooney 	uint16_t	sockets;
2764c87aefeSPatrick Mooney 	uint16_t	cores;
2774c87aefeSPatrick Mooney 	uint16_t	threads;
2784c87aefeSPatrick Mooney 	uint16_t	maxcpus;
2794c87aefeSPatrick Mooney };
280bf21cd93STycho Nightingale 
281154972afSPatrick Mooney struct vm_readwrite_kernemu_device {
282154972afSPatrick Mooney 	int		vcpuid;
283154972afSPatrick Mooney 	unsigned	access_width : 3;
284154972afSPatrick Mooney 	unsigned	_unused : 29;
285154972afSPatrick Mooney 	uint64_t	gpa;
286154972afSPatrick Mooney 	uint64_t	value;
287154972afSPatrick Mooney };
288154972afSPatrick Mooney _Static_assert(sizeof(struct vm_readwrite_kernemu_device) == 24, "ABI");
289154972afSPatrick Mooney 
2902606939dSPatrick Mooney enum vcpu_reset_kind {
2912606939dSPatrick Mooney 	VRK_RESET = 0,
2922606939dSPatrick Mooney 	/*
2932606939dSPatrick Mooney 	 * The reset performed by an INIT IPI clears much of the CPU state, but
2942606939dSPatrick Mooney 	 * some portions are left untouched, unlike VRK_RESET, which represents
2952606939dSPatrick Mooney 	 * a "full" reset as if the system was freshly powered on.
2962606939dSPatrick Mooney 	 */
2972606939dSPatrick Mooney 	VRK_INIT = 1,
2982606939dSPatrick Mooney };
2992606939dSPatrick Mooney 
3002606939dSPatrick Mooney struct vm_vcpu_reset {
3012606939dSPatrick Mooney 	int		vcpuid;
3022606939dSPatrick Mooney 	uint32_t	kind;	/* contains: enum vcpu_reset_kind */
3032606939dSPatrick Mooney };
3042606939dSPatrick Mooney 
3052606939dSPatrick Mooney struct vm_run_state {
3062606939dSPatrick Mooney 	int		vcpuid;
3072606939dSPatrick Mooney 	uint32_t	state;	/* of enum cpu_init_status type */
3082606939dSPatrick Mooney 	uint8_t		sipi_vector;	/* vector of SIPI, if any */
3092606939dSPatrick Mooney 	uint8_t		_pad[3];
3102606939dSPatrick Mooney };
3112606939dSPatrick Mooney 
312957246c9SPatrick Mooney /* Transfer data for VM_GET_FPU and VM_SET_FPU */
313957246c9SPatrick Mooney struct vm_fpu_state {
314957246c9SPatrick Mooney 	int		vcpuid;
315957246c9SPatrick Mooney 	void		*buf;
316957246c9SPatrick Mooney 	size_t		len;
317957246c9SPatrick Mooney };
318957246c9SPatrick Mooney 
319957246c9SPatrick Mooney struct vm_fpu_desc_entry {
320957246c9SPatrick Mooney 	uint64_t	vfde_feature;
321957246c9SPatrick Mooney 	uint32_t	vfde_size;
322957246c9SPatrick Mooney 	uint32_t	vfde_off;
323957246c9SPatrick Mooney };
324957246c9SPatrick Mooney 
325957246c9SPatrick Mooney struct vm_fpu_desc {
326957246c9SPatrick Mooney 	struct vm_fpu_desc_entry	*vfd_entry_data;
327957246c9SPatrick Mooney 	size_t				vfd_req_size;
328957246c9SPatrick Mooney 	uint32_t			vfd_num_entries;
329957246c9SPatrick Mooney };
330957246c9SPatrick Mooney 
331b57f5d3eSPatrick Mooney struct vmm_resv_query {
332b57f5d3eSPatrick Mooney 	size_t	vrq_free_sz;
333b57f5d3eSPatrick Mooney 	size_t	vrq_alloc_sz;
334b57f5d3eSPatrick Mooney 	size_t	vrq_alloc_transient_sz;
335b57f5d3eSPatrick Mooney 	size_t	vrq_limit;
336b57f5d3eSPatrick Mooney };
337b57f5d3eSPatrick Mooney 
3386bba8b59SPatrick Mooney struct vmm_resv_target {
3396bba8b59SPatrick Mooney 	/* Target size for VMM reservoir */
3406bba8b59SPatrick Mooney 	size_t	vrt_target_sz;
3416bba8b59SPatrick Mooney 
3426bba8b59SPatrick Mooney 	/*
3436bba8b59SPatrick Mooney 	 * Change of reservoir size to meet target will be done in multiple
3446bba8b59SPatrick Mooney 	 * steps of chunk size (or smaller)
3456bba8b59SPatrick Mooney 	 */
3466bba8b59SPatrick Mooney 	size_t	vrt_chunk_sz;
3476bba8b59SPatrick Mooney 
3486bba8b59SPatrick Mooney 	/*
3496bba8b59SPatrick Mooney 	 * Resultant size of reservoir after operation.  Should match target
3506bba8b59SPatrick Mooney 	 * size, except when interrupted.
3516bba8b59SPatrick Mooney 	 */
3526bba8b59SPatrick Mooney 	size_t	vrt_result_sz;
3536bba8b59SPatrick Mooney };
3546bba8b59SPatrick Mooney 
3558779b448SDan Cross /*
356*b9b43e84SPatrick Mooney  * The VM_TRACK_DIRTY_PAGES ioctl uses the vmm_dirty_page_tracker struct as
357*b9b43e84SPatrick Mooney  * input.  That ioctl is deprecated in favor of VM_NPT_OPERATION, which exposes
358*b9b43e84SPatrick Mooney  * equivalent functionality.
3598779b448SDan Cross  *
3608779b448SDan Cross  * - The `vdt_start_gpa` field specifies the offset from the beginning of
3618779b448SDan Cross  *   guest physical memory to track;
3628779b448SDan Cross  * - `vdt_pfns` points to a bit vector indexed by guest PFN relative to the
3638779b448SDan Cross  *   given start address.  Each bit indicates whether the given guest page
3648779b448SDan Cross  *   is dirty or not.
3658779b448SDan Cross  * - `vdt_pfns_len` specifies the length of the of the guest physical memory
3668779b448SDan Cross  *   region in bytes.  It also de facto bounds the range of guest addresses
3678779b448SDan Cross  *   we will examine on any one `VM_TRACK_DIRTY_PAGES` ioctl().  If the
3688779b448SDan Cross  *   range of the bit vector spans an unallocated region (or extends beyond
3698779b448SDan Cross  *   the end of the guest physical address space) the corresponding bits in
3708779b448SDan Cross  *   `vdt_pfns` will be zeroed.
3718779b448SDan Cross  */
3728779b448SDan Cross struct vmm_dirty_tracker {
3738779b448SDan Cross 	uint64_t	vdt_start_gpa;
3748779b448SDan Cross 	size_t		vdt_len;	/* length of region */
3758779b448SDan Cross 	void		*vdt_pfns;	/* bit vector of dirty bits */
3768779b448SDan Cross };
3778779b448SDan Cross 
378*b9b43e84SPatrick Mooney /*
379*b9b43e84SPatrick Mooney  * Perform an operation the nested page tables for the guest.
380*b9b43e84SPatrick Mooney  *
381*b9b43e84SPatrick Mooney  * The vno_operation field determines how (if at all) the other fields are used.
382*b9b43e84SPatrick Mooney  * If the VNO_FLAG_BITMAP_IN or VNO_FLAG_BITMAP_OUT flags are present in
383*b9b43e84SPatrick Mooney  * vno_operation, then vno_bitmap is expected to point to a region of memory
384*b9b43e84SPatrick Mooney  * sized adequately (1 bit per page) for the region specified by vno_gpa and
385*b9b43e84SPatrick Mooney  * vno_len.  Presently that region size is limited to 1GiB (256k 4k pages).
386*b9b43e84SPatrick Mooney  *
387*b9b43e84SPatrick Mooney  * Several operations act on the entire guest memory space as whole, and thus
388*b9b43e84SPatrick Mooney  * expect that no memory region (or bitmap) are provided.  These operations are:
389*b9b43e84SPatrick Mooney  *
390*b9b43e84SPatrick Mooney  * - VNO_OP_GET_TRACK_DIRTY: Get status of dirty-page-tracking for the VM.
391*b9b43e84SPatrick Mooney  *   Return value of the ioctl will indicate the status (0 = off, 1 = on).
392*b9b43e84SPatrick Mooney  * - VNO_OP_EN_TRACK_DIRTY: Enable dirty-page-tracking for the VM.  Will emit an
393*b9b43e84SPatrick Mooney  *   error if such tracking is not supported by hardware.
394*b9b43e84SPatrick Mooney  * - VNO_OP_DIS_TRACK_DIRTY: Disable dirty-page-tracking for the VM.
395*b9b43e84SPatrick Mooney  *
396*b9b43e84SPatrick Mooney  * The remaining operations act upon PTEs in the range specified by vno_gpa and
397*b9b43e84SPatrick Mooney  * vno_len.
398*b9b43e84SPatrick Mooney  *
399*b9b43e84SPatrick Mooney  * If the VNO_FLAG_BITMAP_IN flag is set, the operation will be executed only
400*b9b43e84SPatrick Mooney  * for pages with a corresponding bit set in the bitmap.  When the flag is not
401*b9b43e84SPatrick Mooney  * set, the operation is applied to all pages in the region specified by
402*b9b43e84SPatrick Mooney  * vno_gpa/vno_len.
403*b9b43e84SPatrick Mooney  *
404*b9b43e84SPatrick Mooney  * For operations which yield per-page results, that will be returned to the
405*b9b43e84SPatrick Mooney  * caller via the bitmap if the VNO_FLAG_BITMAP_OUT flag is set.  Those
406*b9b43e84SPatrick Mooney  * operations are as follows:
407*b9b43e84SPatrick Mooney  *
408*b9b43e84SPatrick Mooney  * - VNO_OP_GET_DIRTY: Gets the state of the dirty bit for the page(s)
409*b9b43e84SPatrick Mooney  * - VNO_OP_RESET_DIRTY: Clears any existing dirty bit for the page(s),
410*b9b43e84SPatrick Mooney  *   returning it via the bitmap
411*b9b43e84SPatrick Mooney  * - VNO_OP_SET_DIRTY: Asserts the state of the dirty bit for the page(s).  This
412*b9b43e84SPatrick Mooney  *   is only performed for pages which are mapped into the guest as writable.
413*b9b43e84SPatrick Mooney  *
414*b9b43e84SPatrick Mooney  * The above bitmap operations on dirty bits in the NPTs are possible
415*b9b43e84SPatrick Mooney  * independent of whether dirty-page-tracking is enabled for the vmspace.
416*b9b43e84SPatrick Mooney  * Querying dirty bits from a vmspace without such tracking enabled will return
417*b9b43e84SPatrick Mooney  * only bits which have been manually set via a preceding NPT operation.
418*b9b43e84SPatrick Mooney  */
419*b9b43e84SPatrick Mooney struct vm_npt_operation {
420*b9b43e84SPatrick Mooney 	uint64_t	vno_gpa;
421*b9b43e84SPatrick Mooney 	uint64_t	vno_len;
422*b9b43e84SPatrick Mooney 	uint8_t		*vno_bitmap;
423*b9b43e84SPatrick Mooney 	uint32_t	vno_operation;
424*b9b43e84SPatrick Mooney };
425*b9b43e84SPatrick Mooney 
426*b9b43e84SPatrick Mooney #define	VNO_OP_RESET_DIRTY	0x1
427*b9b43e84SPatrick Mooney #define	VNO_OP_SET_DIRTY	0x2
428*b9b43e84SPatrick Mooney #define	VNO_OP_GET_DIRTY	0x3
429*b9b43e84SPatrick Mooney #define	VNO_OP_GET_TRACK_DIRTY	0x20
430*b9b43e84SPatrick Mooney #define	VNO_OP_EN_TRACK_DIRTY	0x21
431*b9b43e84SPatrick Mooney #define	VNO_OP_DIS_TRACK_DIRTY	0x22
432*b9b43e84SPatrick Mooney #define	VNO_FLAG_BITMAP_IN	(1 << 30)
433*b9b43e84SPatrick Mooney #define	VNO_FLAG_BITMAP_OUT	(1 << 31)
434*b9b43e84SPatrick Mooney 
435d515dd77SPatrick Mooney /* Current (arbitrary) max length for vm_data_xfer */
436d515dd77SPatrick Mooney #define VM_DATA_XFER_LIMIT	8192
437d515dd77SPatrick Mooney 
438d515dd77SPatrick Mooney #define	VDX_FLAG_READ_COPYIN	(1 << 0)
439d515dd77SPatrick Mooney #define	VDX_FLAG_WRITE_COPYOUT	(1 << 1)
440d515dd77SPatrick Mooney 
441d515dd77SPatrick Mooney #define	VDX_FLAGS_VALID		(VDX_FLAG_READ_COPYIN | VDX_FLAG_WRITE_COPYOUT)
442d515dd77SPatrick Mooney 
443d515dd77SPatrick Mooney struct vm_data_xfer {
444d515dd77SPatrick Mooney 	int		vdx_vcpuid;
445d515dd77SPatrick Mooney 	uint16_t	vdx_class;
446d515dd77SPatrick Mooney 	uint16_t	vdx_version;
447d515dd77SPatrick Mooney 	uint32_t	vdx_flags;
448d515dd77SPatrick Mooney 	uint32_t	vdx_len;
44954cf5b63SPatrick Mooney 	uint32_t	vdx_result_len;
450d515dd77SPatrick Mooney 	void		*vdx_data;
451d515dd77SPatrick Mooney };
452d515dd77SPatrick Mooney 
453578d9a56SPatrick Mooney struct vm_vcpu_cpuid_config {
454578d9a56SPatrick Mooney 	int		vvcc_vcpuid;
455578d9a56SPatrick Mooney 	uint32_t	vvcc_flags;
456578d9a56SPatrick Mooney 	uint32_t	vvcc_nent;
457578d9a56SPatrick Mooney 	uint32_t	_pad;
458578d9a56SPatrick Mooney 	void		*vvcc_entries;
459578d9a56SPatrick Mooney };
460578d9a56SPatrick Mooney 
461578d9a56SPatrick Mooney /* Query the computed legacy cpuid value for a vcpuid with VM_LEGACY_CPUID */
462578d9a56SPatrick Mooney struct vm_legacy_cpuid {
463578d9a56SPatrick Mooney 	int		vlc_vcpuid;
464578d9a56SPatrick Mooney 	uint32_t	vlc_eax;
465578d9a56SPatrick Mooney 	uint32_t	vlc_ebx;
466578d9a56SPatrick Mooney 	uint32_t	vlc_ecx;
467578d9a56SPatrick Mooney 	uint32_t	vlc_edx;
468578d9a56SPatrick Mooney };
469578d9a56SPatrick Mooney 
4703466010bSPatrick Mooney /*
4713466010bSPatrick Mooney  * VMM Interface Version
4723466010bSPatrick Mooney  *
4733466010bSPatrick Mooney  * Despite the fact that the kernel interface to bhyve is explicitly considered
4743466010bSPatrick Mooney  * Private, there are out-of-gate consumers which utilize it.  While they assume
4753466010bSPatrick Mooney  * the risk of any breakage incurred by changes to bhyve, we can at least try to
4763466010bSPatrick Mooney  * make it easier to detect changes by exposing a "version" of the interface.
4773466010bSPatrick Mooney  * It can also be used by the in-gate userland to detect if packaging updates
4783466010bSPatrick Mooney  * somehow result in the userland and kernel falling out of sync.
4793466010bSPatrick Mooney  *
4803466010bSPatrick Mooney  * There are no established criteria for the magnitude of change which requires
4813466010bSPatrick Mooney  * this version to be incremented, and maintenance of it is considered a
4823466010bSPatrick Mooney  * best-effort activity.  Nothing is to be inferred about the magnitude of a
4833466010bSPatrick Mooney  * change when the version is modified.  It follows no rules like semver.
4843466010bSPatrick Mooney  */
485*b9b43e84SPatrick Mooney #define	VMM_CURRENT_INTERFACE_VERSION	17
4863466010bSPatrick Mooney 
4873466010bSPatrick Mooney 
488e156a47bSPatrick Mooney #define	VMMCTL_IOC_BASE		(('V' << 16) | ('M' << 8))
489e156a47bSPatrick Mooney #define	VMM_IOC_BASE		(('v' << 16) | ('m' << 8))
490e156a47bSPatrick Mooney #define	VMM_LOCK_IOC_BASE	(('v' << 16) | ('l' << 8))
491e156a47bSPatrick Mooney #define	VMM_CPU_IOC_BASE	(('v' << 16) | ('p' << 8))
492e156a47bSPatrick Mooney 
493e156a47bSPatrick Mooney /* Operations performed on the vmmctl device */
494e156a47bSPatrick Mooney #define	VMM_CREATE_VM		(VMMCTL_IOC_BASE | 0x01)
495e156a47bSPatrick Mooney #define	VMM_DESTROY_VM		(VMMCTL_IOC_BASE | 0x02)
496e156a47bSPatrick Mooney #define	VMM_VM_SUPPORTED	(VMMCTL_IOC_BASE | 0x03)
4973466010bSPatrick Mooney #define	VMM_INTERFACE_VERSION	(VMMCTL_IOC_BASE | 0x04)
498e760f150SPatrick Mooney #define	VMM_CHECK_IOMMU		(VMMCTL_IOC_BASE | 0x05)
499e156a47bSPatrick Mooney 
500b57f5d3eSPatrick Mooney #define	VMM_RESV_QUERY		(VMMCTL_IOC_BASE | 0x10)
5016bba8b59SPatrick Mooney #define	VMM_RESV_SET_TARGET	(VMMCTL_IOC_BASE | 0x11)
502b57f5d3eSPatrick Mooney 
503e156a47bSPatrick Mooney /* Operations performed in the context of a given vCPU */
504e156a47bSPatrick Mooney #define	VM_RUN				(VMM_CPU_IOC_BASE | 0x01)
505e156a47bSPatrick Mooney #define	VM_SET_REGISTER			(VMM_CPU_IOC_BASE | 0x02)
506e156a47bSPatrick Mooney #define	VM_GET_REGISTER			(VMM_CPU_IOC_BASE | 0x03)
507e156a47bSPatrick Mooney #define	VM_SET_SEGMENT_DESCRIPTOR	(VMM_CPU_IOC_BASE | 0x04)
508e156a47bSPatrick Mooney #define	VM_GET_SEGMENT_DESCRIPTOR	(VMM_CPU_IOC_BASE | 0x05)
509e156a47bSPatrick Mooney #define	VM_SET_REGISTER_SET		(VMM_CPU_IOC_BASE | 0x06)
510e156a47bSPatrick Mooney #define	VM_GET_REGISTER_SET		(VMM_CPU_IOC_BASE | 0x07)
511e156a47bSPatrick Mooney #define	VM_INJECT_EXCEPTION		(VMM_CPU_IOC_BASE | 0x08)
512e156a47bSPatrick Mooney #define	VM_SET_CAPABILITY		(VMM_CPU_IOC_BASE | 0x09)
513e156a47bSPatrick Mooney #define	VM_GET_CAPABILITY		(VMM_CPU_IOC_BASE | 0x0a)
514e156a47bSPatrick Mooney #define	VM_PPTDEV_MSI			(VMM_CPU_IOC_BASE | 0x0b)
515e156a47bSPatrick Mooney #define	VM_PPTDEV_MSIX			(VMM_CPU_IOC_BASE | 0x0c)
516e156a47bSPatrick Mooney #define	VM_SET_X2APIC_STATE		(VMM_CPU_IOC_BASE | 0x0d)
517e156a47bSPatrick Mooney #define	VM_GLA2GPA			(VMM_CPU_IOC_BASE | 0x0e)
518e156a47bSPatrick Mooney #define	VM_GLA2GPA_NOFAULT		(VMM_CPU_IOC_BASE | 0x0f)
519e156a47bSPatrick Mooney #define	VM_ACTIVATE_CPU			(VMM_CPU_IOC_BASE | 0x10)
520e156a47bSPatrick Mooney #define	VM_SET_INTINFO			(VMM_CPU_IOC_BASE | 0x11)
521e156a47bSPatrick Mooney #define	VM_GET_INTINFO			(VMM_CPU_IOC_BASE | 0x12)
522e156a47bSPatrick Mooney #define	VM_RESTART_INSTRUCTION		(VMM_CPU_IOC_BASE | 0x13)
523e156a47bSPatrick Mooney #define	VM_SET_KERNEMU_DEV		(VMM_CPU_IOC_BASE | 0x14)
524e156a47bSPatrick Mooney #define	VM_GET_KERNEMU_DEV		(VMM_CPU_IOC_BASE | 0x15)
5252606939dSPatrick Mooney #define	VM_RESET_CPU			(VMM_CPU_IOC_BASE | 0x16)
5262606939dSPatrick Mooney #define	VM_GET_RUN_STATE		(VMM_CPU_IOC_BASE | 0x17)
5272606939dSPatrick Mooney #define	VM_SET_RUN_STATE		(VMM_CPU_IOC_BASE | 0x18)
528957246c9SPatrick Mooney #define	VM_GET_FPU			(VMM_CPU_IOC_BASE | 0x19)
529957246c9SPatrick Mooney #define	VM_SET_FPU			(VMM_CPU_IOC_BASE | 0x1a)
530578d9a56SPatrick Mooney #define	VM_GET_CPUID			(VMM_CPU_IOC_BASE | 0x1b)
531578d9a56SPatrick Mooney #define	VM_SET_CPUID			(VMM_CPU_IOC_BASE | 0x1c)
532578d9a56SPatrick Mooney #define	VM_LEGACY_CPUID			(VMM_CPU_IOC_BASE | 0x1d)
533e156a47bSPatrick Mooney 
534e156a47bSPatrick Mooney /* Operations requiring write-locking the VM */
535e156a47bSPatrick Mooney #define	VM_REINIT		(VMM_LOCK_IOC_BASE | 0x01)
536e156a47bSPatrick Mooney #define	VM_BIND_PPTDEV		(VMM_LOCK_IOC_BASE | 0x02)
537e156a47bSPatrick Mooney #define	VM_UNBIND_PPTDEV	(VMM_LOCK_IOC_BASE | 0x03)
538e156a47bSPatrick Mooney #define	VM_MAP_PPTDEV_MMIO	(VMM_LOCK_IOC_BASE | 0x04)
539e156a47bSPatrick Mooney #define	VM_ALLOC_MEMSEG		(VMM_LOCK_IOC_BASE | 0x05)
540e156a47bSPatrick Mooney #define	VM_MMAP_MEMSEG		(VMM_LOCK_IOC_BASE | 0x06)
5410e1453c3SPatrick Mooney #define	VM_PMTMR_LOCATE		(VMM_LOCK_IOC_BASE | 0x07)
5422b948146SAndy Fiddaman #define	VM_MUNMAP_MEMSEG	(VMM_LOCK_IOC_BASE | 0x08)
5432b948146SAndy Fiddaman #define	VM_UNMAP_PPTDEV_MMIO	(VMM_LOCK_IOC_BASE | 0x09)
5442cac0506SPatrick Mooney #define	VM_PAUSE		(VMM_LOCK_IOC_BASE | 0x0a)
5452cac0506SPatrick Mooney #define	VM_RESUME		(VMM_LOCK_IOC_BASE | 0x0b)
546e156a47bSPatrick Mooney 
547e156a47bSPatrick Mooney #define	VM_WRLOCK_CYCLE		(VMM_LOCK_IOC_BASE | 0xff)
548e156a47bSPatrick Mooney 
549e156a47bSPatrick Mooney /* All other ioctls */
550e156a47bSPatrick Mooney #define	VM_GET_GPA_PMAP			(VMM_IOC_BASE | 0x01)
551e156a47bSPatrick Mooney #define	VM_GET_MEMSEG			(VMM_IOC_BASE | 0x02)
552e156a47bSPatrick Mooney #define	VM_MMAP_GETNEXT			(VMM_IOC_BASE | 0x03)
553e156a47bSPatrick Mooney 
55484971882SPatrick Mooney #define	VM_LAPIC_IRQ			(VMM_IOC_BASE | 0x04)
55584971882SPatrick Mooney #define	VM_LAPIC_LOCAL_IRQ		(VMM_IOC_BASE | 0x05)
556e156a47bSPatrick Mooney #define	VM_LAPIC_MSI			(VMM_IOC_BASE | 0x06)
557e156a47bSPatrick Mooney 
558e156a47bSPatrick Mooney #define	VM_IOAPIC_ASSERT_IRQ		(VMM_IOC_BASE | 0x07)
559e156a47bSPatrick Mooney #define	VM_IOAPIC_DEASSERT_IRQ		(VMM_IOC_BASE | 0x08)
560e156a47bSPatrick Mooney #define	VM_IOAPIC_PULSE_IRQ		(VMM_IOC_BASE | 0x09)
561e156a47bSPatrick Mooney 
562e156a47bSPatrick Mooney #define	VM_ISA_ASSERT_IRQ		(VMM_IOC_BASE | 0x0a)
563e156a47bSPatrick Mooney #define	VM_ISA_DEASSERT_IRQ		(VMM_IOC_BASE | 0x0b)
564e156a47bSPatrick Mooney #define	VM_ISA_PULSE_IRQ		(VMM_IOC_BASE | 0x0c)
565e156a47bSPatrick Mooney #define	VM_ISA_SET_IRQ_TRIGGER		(VMM_IOC_BASE | 0x0d)
566e156a47bSPatrick Mooney 
567e156a47bSPatrick Mooney #define	VM_RTC_WRITE			(VMM_IOC_BASE | 0x0e)
568e156a47bSPatrick Mooney #define	VM_RTC_READ			(VMM_IOC_BASE | 0x0f)
569e156a47bSPatrick Mooney #define	VM_RTC_SETTIME			(VMM_IOC_BASE | 0x10)
570e156a47bSPatrick Mooney #define	VM_RTC_GETTIME			(VMM_IOC_BASE | 0x11)
571e156a47bSPatrick Mooney 
572e156a47bSPatrick Mooney #define	VM_SUSPEND			(VMM_IOC_BASE | 0x12)
573e156a47bSPatrick Mooney 
574e156a47bSPatrick Mooney #define	VM_IOAPIC_PINCOUNT		(VMM_IOC_BASE | 0x13)
575e156a47bSPatrick Mooney #define	VM_GET_PPTDEV_LIMITS		(VMM_IOC_BASE | 0x14)
576e156a47bSPatrick Mooney #define	VM_GET_HPET_CAPABILITIES	(VMM_IOC_BASE | 0x15)
577e156a47bSPatrick Mooney 
578e156a47bSPatrick Mooney #define	VM_STATS_IOC			(VMM_IOC_BASE | 0x16)
579e156a47bSPatrick Mooney #define	VM_STAT_DESC			(VMM_IOC_BASE | 0x17)
580e156a47bSPatrick Mooney 
581e156a47bSPatrick Mooney #define	VM_INJECT_NMI			(VMM_IOC_BASE | 0x18)
582e156a47bSPatrick Mooney #define	VM_GET_X2APIC_STATE		(VMM_IOC_BASE | 0x19)
583e156a47bSPatrick Mooney #define	VM_SET_TOPOLOGY			(VMM_IOC_BASE | 0x1a)
584e156a47bSPatrick Mooney #define	VM_GET_TOPOLOGY			(VMM_IOC_BASE | 0x1b)
585e156a47bSPatrick Mooney #define	VM_GET_CPUS			(VMM_IOC_BASE | 0x1c)
586e156a47bSPatrick Mooney #define	VM_SUSPEND_CPU			(VMM_IOC_BASE | 0x1d)
587e156a47bSPatrick Mooney #define	VM_RESUME_CPU			(VMM_IOC_BASE | 0x1e)
588e156a47bSPatrick Mooney 
5896960cd89SAndy Fiddaman #define	VM_PPTDEV_DISABLE_MSIX		(VMM_IOC_BASE | 0x1f)
590e156a47bSPatrick Mooney 
5918779b448SDan Cross /* Note: forces a barrier on a flush operation before returning. */
5928779b448SDan Cross #define	VM_TRACK_DIRTY_PAGES		(VMM_IOC_BASE | 0x20)
593957246c9SPatrick Mooney #define	VM_DESC_FPU_AREA		(VMM_IOC_BASE | 0x21)
5948779b448SDan Cross 
595d515dd77SPatrick Mooney #define	VM_DATA_READ			(VMM_IOC_BASE | 0x22)
596d515dd77SPatrick Mooney #define	VM_DATA_WRITE			(VMM_IOC_BASE | 0x23)
597d515dd77SPatrick Mooney 
598aa39f6d0SPatrick Mooney #define	VM_SET_AUTODESTRUCT		(VMM_IOC_BASE | 0x24)
59942640e49SPatrick Mooney #define	VM_DESTROY_SELF			(VMM_IOC_BASE | 0x25)
60042640e49SPatrick Mooney #define	VM_DESTROY_PENDING		(VMM_IOC_BASE | 0x26)
601aa39f6d0SPatrick Mooney 
60272473353SPatrick Mooney #define	VM_VCPU_BARRIER			(VMM_IOC_BASE | 0x27)
603*b9b43e84SPatrick Mooney #define	VM_NPT_OPERATION		(VMM_IOC_BASE | 0x28)
60472473353SPatrick Mooney 
605e156a47bSPatrick Mooney #define	VM_DEVMEM_GETOFFSET		(VMM_IOC_BASE | 0xff)
6064c87aefeSPatrick Mooney 
6074c87aefeSPatrick Mooney #define	VMM_CTL_DEV		"/dev/vmmctl"
6084c87aefeSPatrick Mooney 
6094c87aefeSPatrick Mooney #endif
610