xref: /freebsd/sys/dev/vmm/vmm_dev.h (revision a97f683fe3c425b425cf8cc466319f54ea957c20)
1b9ef152bSMark Johnston /*-
2b9ef152bSMark Johnston  * SPDX-License-Identifier: BSD-2-Clause
3b9ef152bSMark Johnston  *
4b9ef152bSMark Johnston  * Copyright (c) 2011 NetApp, Inc.
5b9ef152bSMark Johnston  * Copyright (C) 2015 Mihai Carabas <mihai.carabas@gmail.com>
6b9ef152bSMark Johnston  * All rights reserved.
7b9ef152bSMark Johnston  */
8b9ef152bSMark Johnston 
9b9ef152bSMark Johnston #ifndef	_DEV_VMM_DEV_H_
10b9ef152bSMark Johnston #define	_DEV_VMM_DEV_H_
11b9ef152bSMark Johnston 
12b9ef152bSMark Johnston #include <sys/types.h>
13b9ef152bSMark Johnston #include <sys/ioccom.h>
14b9ef152bSMark Johnston #include <machine/vmm_dev.h>
15b9ef152bSMark Johnston 
16b9ef152bSMark Johnston #ifdef _KERNEL
17b9ef152bSMark Johnston struct thread;
18b9ef152bSMark Johnston struct vm;
19b9ef152bSMark Johnston struct vcpu;
20b9ef152bSMark Johnston 
21*a97f683fSMark Johnston int	vmmdev_init(void);
22b9ef152bSMark Johnston int	vmmdev_cleanup(void);
23b9ef152bSMark Johnston int	vmmdev_machdep_ioctl(struct vm *vm, struct vcpu *vcpu, u_long cmd,
24b9ef152bSMark Johnston 	    caddr_t data, int fflag, struct thread *td);
25b9ef152bSMark Johnston 
26b9ef152bSMark Johnston /*
27b9ef152bSMark Johnston  * Entry in an ioctl handler table.  A number of generic ioctls are defined,
28b9ef152bSMark Johnston  * plus a table of machine-dependent ioctls.  The flags indicate the
29b9ef152bSMark Johnston  * required preconditions for a given ioctl.
30b9ef152bSMark Johnston  *
31b9ef152bSMark Johnston  * Some ioctls encode a vcpuid as the first member of their ioctl structure.
32b9ef152bSMark Johnston  * These ioctls must specify one of the following flags:
33b9ef152bSMark Johnston  * - ALLOC_VCPU: create the vCPU if it does not already exist
34b9ef152bSMark Johnston  * - LOCK_ONE_VCPU: create the vCPU if it does not already exist
35b9ef152bSMark Johnston  *   and lock the vCPU for the duration of the ioctl
36b9ef152bSMark Johnston  * - MAYBE_ALLOC_VCPU: if the vcpuid is -1, do nothing, otherwise
37b9ef152bSMark Johnston  *   create the vCPU if it does not already exist
38b9ef152bSMark Johnston  */
39b9ef152bSMark Johnston struct vmmdev_ioctl {
40b9ef152bSMark Johnston 	unsigned long	cmd;
41b9ef152bSMark Johnston #define	VMMDEV_IOCTL_SLOCK_MEMSEGS	0x01
42b9ef152bSMark Johnston #define	VMMDEV_IOCTL_XLOCK_MEMSEGS	0x02
43b9ef152bSMark Johnston #define	VMMDEV_IOCTL_LOCK_ONE_VCPU	0x04
44b9ef152bSMark Johnston #define	VMMDEV_IOCTL_LOCK_ALL_VCPUS	0x08
45b9ef152bSMark Johnston #define	VMMDEV_IOCTL_ALLOC_VCPU		0x10
46b9ef152bSMark Johnston #define	VMMDEV_IOCTL_MAYBE_ALLOC_VCPU	0x20
47b9ef152bSMark Johnston 	int		flags;
48b9ef152bSMark Johnston };
49b9ef152bSMark Johnston 
50b9ef152bSMark Johnston #define	VMMDEV_IOCTL(_cmd, _flags)	{ .cmd = (_cmd), .flags = (_flags) }
51b9ef152bSMark Johnston 
52b9ef152bSMark Johnston extern const struct vmmdev_ioctl vmmdev_machdep_ioctls[];
53b9ef152bSMark Johnston extern const size_t vmmdev_machdep_ioctl_count;
54b9ef152bSMark Johnston 
55b9ef152bSMark Johnston #endif /* _KERNEL */
56b9ef152bSMark Johnston 
57*a97f683fSMark Johnston struct vmmctl_vm_create {
58*a97f683fSMark Johnston 	char name[VM_MAX_NAMELEN + 1];
59*a97f683fSMark Johnston 	int reserved[16];
60*a97f683fSMark Johnston };
61*a97f683fSMark Johnston 
62*a97f683fSMark Johnston struct vmmctl_vm_destroy {
63*a97f683fSMark Johnston 	char name[VM_MAX_NAMELEN + 1];
64*a97f683fSMark Johnston 	int reserved[16];
65*a97f683fSMark Johnston };
66*a97f683fSMark Johnston 
67*a97f683fSMark Johnston #define	VMMCTL_VM_CREATE	_IOWR('V', 0, struct vmmctl_vm_create)
68*a97f683fSMark Johnston #define	VMMCTL_VM_DESTROY	_IOWR('V', 1, struct vmmctl_vm_destroy)
69*a97f683fSMark Johnston 
70b9ef152bSMark Johnston #endif /* _DEV_VMM_DEV_H_ */
71