1 /* $NetBSD: nvmm_internal.h,v 1.20 2021/03/26 15:59:53 reinoud Exp $ */
4 * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
7 * This code is part of the NVMM hypervisor.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef _NVMM_INTERNAL_H_
32 #define _NVMM_INTERNAL_H_
35 #error "This file should not be included by userland programs."
38 #define NVMM_MAX_MACHINES 128
39 #define NVMM_MAX_VCPUS 256
40 #define NVMM_MAX_HMAPPINGS 32
41 #define NVMM_MAX_RAM (128ULL * 1024ULL * (1 << 30))
54 struct nvmm_comm_page *comm;
56 /* Last host CPU on which the VCPU ran. */
59 /* Implementation-specific. */
63 struct nvmm_hmapping {
67 struct uvm_object *vmobj;
74 struct nvmm_owner *owner;
78 struct uvm_object *commvmobj;
86 struct nvmm_hmapping hmap[NVMM_MAX_HMAPPINGS];
89 volatile unsigned int ncpus;
90 struct nvmm_cpu cpus[NVMM_MAX_VCPUS];
92 /* Implementation-specific */
101 void (*capability)(struct nvmm_capability *);
103 size_t mach_conf_max;
104 const size_t *mach_conf_sizes;
106 size_t vcpu_conf_max;
107 const size_t *vcpu_conf_sizes;
111 void (*machine_create)(struct nvmm_machine *);
112 void (*machine_destroy)(struct nvmm_machine *);
113 int (*machine_configure)(struct nvmm_machine *, uint64_t, void *);
115 int (*vcpu_create)(struct nvmm_machine *, struct nvmm_cpu *);
116 void (*vcpu_destroy)(struct nvmm_machine *, struct nvmm_cpu *);
117 int (*vcpu_configure)(struct nvmm_cpu *, uint64_t, void *);
118 void (*vcpu_setstate)(struct nvmm_cpu *);
119 void (*vcpu_getstate)(struct nvmm_cpu *);
120 int (*vcpu_inject)(struct nvmm_cpu *);
121 int (*vcpu_run)(struct nvmm_machine *, struct nvmm_cpu *,
122 struct nvmm_vcpu_exit *);
125 #if defined(__x86_64__)
126 extern const struct nvmm_impl nvmm_x86_svm;
127 extern const struct nvmm_impl nvmm_x86_vmx;
131 nvmm_return_needed(void)
133 if (__predict_false(nvmm_break_wanted())) {
136 if (__predict_false(curlwp->lwp_mpflags & LWP_MP_URETMASK)) {
142 #endif /* _NVMM_INTERNAL_H_ */