2 * Copyright (c) 2018-2021 Maxime Villard, m00nbsd.net
5 * This code is part of the NVMM hypervisor.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #ifndef _NVMM_INTERNAL_H_
30 #define _NVMM_INTERNAL_H_
33 #error "This file should not be included by userland programs."
38 #define NVMM_MAX_MACHINES 128
39 #define NVMM_MAX_VCPUS 128
40 #define NVMM_MAX_HMAPPINGS 32
42 #if defined(__NetBSD__)
43 #define NVMM_MAX_RAM (128ULL * (1 << 30))
44 #elif defined(__DragonFly__)
45 #define NVMM_MAX_RAM (127ULL * 1024ULL * (1 << 30))
47 #error "OS dependency for NVMM_MAX_RAM required"
50 #define NVMM_COMM_PAGE_SIZE \
51 (roundup(sizeof(struct nvmm_comm_page), PAGE_SIZE))
64 struct nvmm_comm_page *comm;
66 /* Last host CPU on which the VCPU ran. */
69 /* Implementation-specific. */
73 struct nvmm_hmapping {
84 struct nvmm_owner *owner;
88 os_vmobj_t *commvmobj;
96 struct nvmm_hmapping hmap[NVMM_MAX_HMAPPINGS];
99 volatile unsigned int ncpus;
100 struct nvmm_cpu cpus[NVMM_MAX_VCPUS];
102 /* Implementation-specific */
111 void (*capability)(struct nvmm_capability *);
113 size_t mach_conf_max;
114 const size_t *mach_conf_sizes;
116 size_t vcpu_conf_max;
117 const size_t *vcpu_conf_sizes;
121 void (*machine_create)(struct nvmm_machine *);
122 void (*machine_destroy)(struct nvmm_machine *);
123 int (*machine_configure)(struct nvmm_machine *, uint64_t, void *);
125 int (*vcpu_create)(struct nvmm_machine *, struct nvmm_cpu *);
126 void (*vcpu_destroy)(struct nvmm_machine *, struct nvmm_cpu *);
127 int (*vcpu_configure)(struct nvmm_cpu *, uint64_t, void *);
128 void (*vcpu_setstate)(struct nvmm_cpu *);
129 void (*vcpu_getstate)(struct nvmm_cpu *);
130 int (*vcpu_inject)(struct nvmm_cpu *);
131 int (*vcpu_run)(struct nvmm_machine *, struct nvmm_cpu *,
132 struct nvmm_vcpu_exit *);
135 #if defined(__x86_64__)
136 extern const struct nvmm_impl nvmm_x86_svm;
137 extern const struct nvmm_impl nvmm_x86_vmx;
140 extern struct nvmm_owner nvmm_root_owner;
141 extern volatile unsigned int nmachines;
142 extern const struct nvmm_impl *nvmm_impl;
144 const struct nvmm_impl *nvmm_ident(void);
146 void nvmm_fini(void);
147 int nvmm_ioctl(struct nvmm_owner *, unsigned long, void *);
148 void nvmm_kill_machines(struct nvmm_owner *);
150 #endif /* _NVMM_INTERNAL_H_ */