xref: /freebsd/sys/dev/vmm/vmm_dev.h (revision c46e5dc65ba5c9666bb4452878e332dc49730843)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2011 NetApp, Inc.
5  * Copyright (C) 2015 Mihai Carabas <mihai.carabas@gmail.com>
6  * All rights reserved.
7  */
8 
9 #ifndef	_DEV_VMM_DEV_H_
10 #define	_DEV_VMM_DEV_H_
11 
12 #include <sys/types.h>
13 #include <sys/ioccom.h>
14 
15 #include <machine/vmm_dev.h>
16 
17 #include <dev/vmm/vmm_param.h>
18 
19 #ifdef _KERNEL
20 struct thread;
21 struct vm;
22 struct vcpu;
23 
24 int	vmm_modinit(void);
25 int	vmm_modcleanup(void);
26 
27 int	vmmdev_machdep_ioctl(struct vm *vm, struct vcpu *vcpu, u_long cmd,
28 	    caddr_t data, int fflag, struct thread *td);
29 
30 /*
31  * Entry in an ioctl handler table.  A number of generic ioctls are defined,
32  * plus a table of machine-dependent ioctls.  The flags indicate the
33  * required preconditions for a given ioctl.
34  *
35  * Some ioctls encode a vcpuid as the first member of their ioctl structure.
36  * These ioctls must specify one of the following flags:
37  * - ALLOC_VCPU: create the vCPU if it does not already exist
38  * - LOCK_ONE_VCPU: create the vCPU if it does not already exist
39  *   and lock the vCPU for the duration of the ioctl
40  * - MAYBE_ALLOC_VCPU: if the vcpuid is -1, do nothing, otherwise
41  *   create the vCPU if it does not already exist
42  */
43 struct vmmdev_ioctl {
44 	unsigned long	cmd;
45 #define	VMMDEV_IOCTL_SLOCK_MEMSEGS	0x01
46 #define	VMMDEV_IOCTL_XLOCK_MEMSEGS	0x02
47 #define	VMMDEV_IOCTL_LOCK_ONE_VCPU	0x04
48 #define	VMMDEV_IOCTL_LOCK_ALL_VCPUS	0x08
49 #define	VMMDEV_IOCTL_ALLOC_VCPU		0x10
50 #define	VMMDEV_IOCTL_MAYBE_ALLOC_VCPU	0x20
51 #define	VMMDEV_IOCTL_PRIV_CHECK_DRIVER	0x40
52 	int		flags;
53 };
54 
55 #define	VMMDEV_IOCTL(_cmd, _flags)	{ .cmd = (_cmd), .flags = (_flags) }
56 
57 extern const struct vmmdev_ioctl vmmdev_machdep_ioctls[];
58 extern const size_t vmmdev_machdep_ioctl_count;
59 
60 /*
61  * Upper limit on vm_maxcpu.  Limited by use of uint16_t types for CPU counts as
62  * well as range of vpid values for VT-x on amd64 and by the capacity of
63  * cpuset_t masks.  The call to new_unrhdr() in vpid_init() in vmx.c requires
64  * 'vm_maxcpu + 1 <= 0xffff', hence the '- 1' below.
65  */
66 #define	VM_MAXCPU	MIN(0xffff - 1, CPU_SETSIZE)
67 
68 /* Maximum number of vCPUs in a single VM. */
69 extern u_int vm_maxcpu;
70 
71 #endif /* _KERNEL */
72 
73 struct vmmctl_vm_create {
74 	char name[VM_MAX_NAMELEN + 1];
75 	int reserved[16];
76 };
77 
78 struct vmmctl_vm_destroy {
79 	char name[VM_MAX_NAMELEN + 1];
80 	int reserved[16];
81 };
82 
83 #define	VMMCTL_VM_CREATE	_IOWR('V', 0, struct vmmctl_vm_create)
84 #define	VMMCTL_VM_DESTROY	_IOWR('V', 1, struct vmmctl_vm_destroy)
85 
86 #endif /* _DEV_VMM_DEV_H_ */
87