mirror of
https://github.com/opnsense/src.git
synced 2026-06-05 06:42:56 -04:00
This file contains the vmm device file implementation. Most of this code is not machine-dependent and so shouldn't be duplicated this way. Move most of it into a generic dev/vmm/vmm_dev.c. This will make it easier to introduce a cdev-based interface for VM creation, which in turn makes it possible to implement support for running bhyve as an unprivileged user. Machine-dependent ioctls continue to be handled in machine-dependent code. To make the split a bit easier to handle, introduce a pair of tables which define MI and MD ioctls. Each table entry can set flags which determine which locks need to be held in order to execute the handler. vmmdev_ioctl() now looks up the ioctl in one of the tables, acquires locks and either handles the ioctl directly or calls vmmdev_machdep_ioctl() to handle it. No functional change intended. There is a lot of churn in this change but the underlying logic in the ioctl handlers is the same. For now, vmm_dev.h is still mostly separate, even though some parts could be merged in principle. This would involve changing include paths for userspace, though. Reviewed by: corvink, jhb Differential Revision: https://reviews.freebsd.org/D46431
57 lines
1.7 KiB
C
57 lines
1.7 KiB
C
/*-
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Copyright (c) 2011 NetApp, Inc.
|
|
* Copyright (C) 2015 Mihai Carabas <mihai.carabas@gmail.com>
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#ifndef _DEV_VMM_DEV_H_
|
|
#define _DEV_VMM_DEV_H_
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/ioccom.h>
|
|
#include <machine/vmm_dev.h>
|
|
|
|
#ifdef _KERNEL
|
|
struct thread;
|
|
struct vm;
|
|
struct vcpu;
|
|
|
|
void vmmdev_init(void);
|
|
int vmmdev_cleanup(void);
|
|
int vmmdev_machdep_ioctl(struct vm *vm, struct vcpu *vcpu, u_long cmd,
|
|
caddr_t data, int fflag, struct thread *td);
|
|
|
|
/*
|
|
* Entry in an ioctl handler table. A number of generic ioctls are defined,
|
|
* plus a table of machine-dependent ioctls. The flags indicate the
|
|
* required preconditions for a given ioctl.
|
|
*
|
|
* Some ioctls encode a vcpuid as the first member of their ioctl structure.
|
|
* These ioctls must specify one of the following flags:
|
|
* - ALLOC_VCPU: create the vCPU if it does not already exist
|
|
* - LOCK_ONE_VCPU: create the vCPU if it does not already exist
|
|
* and lock the vCPU for the duration of the ioctl
|
|
* - MAYBE_ALLOC_VCPU: if the vcpuid is -1, do nothing, otherwise
|
|
* create the vCPU if it does not already exist
|
|
*/
|
|
struct vmmdev_ioctl {
|
|
unsigned long cmd;
|
|
#define VMMDEV_IOCTL_SLOCK_MEMSEGS 0x01
|
|
#define VMMDEV_IOCTL_XLOCK_MEMSEGS 0x02
|
|
#define VMMDEV_IOCTL_LOCK_ONE_VCPU 0x04
|
|
#define VMMDEV_IOCTL_LOCK_ALL_VCPUS 0x08
|
|
#define VMMDEV_IOCTL_ALLOC_VCPU 0x10
|
|
#define VMMDEV_IOCTL_MAYBE_ALLOC_VCPU 0x20
|
|
int flags;
|
|
};
|
|
|
|
#define VMMDEV_IOCTL(_cmd, _flags) { .cmd = (_cmd), .flags = (_flags) }
|
|
|
|
extern const struct vmmdev_ioctl vmmdev_machdep_ioctls[];
|
|
extern const size_t vmmdev_machdep_ioctl_count;
|
|
|
|
#endif /* _KERNEL */
|
|
|
|
#endif /* _DEV_VMM_DEV_H_ */
|