nvmm_internal.h revision 1.7 1 /* $NetBSD: nvmm_internal.h,v 1.7 2019/03/07 15:22:21 maxv Exp $ */
2
3 /*
4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Maxime Villard.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _NVMM_INTERNAL_H_
33 #define _NVMM_INTERNAL_H_
34
35 #define NVMM_MAX_MACHINES 128
36 #define NVMM_MAX_VCPUS 256
37 #define NVMM_MAX_HMAPPINGS 32
38 #define NVMM_MAX_RAM (128ULL * (1 << 30))
39
40 struct nvmm_cpu {
41 /* Shared. */
42 bool present;
43 nvmm_cpuid_t cpuid;
44 kmutex_t lock;
45
46 /* State buffer. */
47 void *state;
48
49 /* Last host CPU on which the VCPU ran. */
50 int hcpu_last;
51
52 /* Implementation-specific. */
53 void *cpudata;
54 };
55
56 struct nvmm_hmapping {
57 bool present;
58 uintptr_t hva;
59 size_t size;
60 struct uvm_object *uobj;
61 };
62
63 struct nvmm_machine {
64 bool present;
65 nvmm_machid_t machid;
66 pid_t procid;
67 krwlock_t lock;
68
69 /* Kernel */
70 struct vmspace *vm;
71 gpaddr_t gpa_begin;
72 gpaddr_t gpa_end;
73
74 /* Host Mappings */
75 struct nvmm_hmapping hmap[NVMM_MAX_HMAPPINGS];
76
77 /* CPU */
78 struct nvmm_cpu cpus[NVMM_MAX_VCPUS];
79
80 /* Implementation-specific */
81 void *machdata;
82 };
83
84 struct nvmm_impl {
85 bool (*ident)(void);
86 void (*init)(void);
87 void (*fini)(void);
88 void (*capability)(struct nvmm_capability *);
89
90 size_t conf_max;
91 const size_t *conf_sizes;
92 size_t state_size;
93
94 void (*machine_create)(struct nvmm_machine *);
95 void (*machine_destroy)(struct nvmm_machine *);
96 int (*machine_configure)(struct nvmm_machine *, uint64_t, void *);
97
98 int (*vcpu_create)(struct nvmm_machine *, struct nvmm_cpu *);
99 void (*vcpu_destroy)(struct nvmm_machine *, struct nvmm_cpu *);
100 void (*vcpu_setstate)(struct nvmm_cpu *, const void *, uint64_t);
101 void (*vcpu_getstate)(struct nvmm_cpu *, void *, uint64_t);
102 int (*vcpu_inject)(struct nvmm_machine *, struct nvmm_cpu *,
103 struct nvmm_event *);
104 int (*vcpu_run)(struct nvmm_machine *, struct nvmm_cpu *,
105 struct nvmm_exit *);
106 };
107
108 int nvmm_vcpu_get(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_cpu **);
109 void nvmm_vcpu_put(struct nvmm_cpu *);
110
111 extern const struct nvmm_impl nvmm_x86_svm;
112 extern const struct nvmm_impl nvmm_x86_vmx;
113
114 #endif /* _NVMM_INTERNAL_H_ */
115