Annotation of src/sys/dev/nvmm/nvmm_internal.h, Revision 1.17
1.17 ! maxv 1: /* $NetBSD: nvmm_internal.h,v 1.16 2020/07/03 16:09:54 maxv Exp $ */
1.1 maxv 2:
3: /*
1.16 maxv 4: * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
1.1 maxv 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
1.7 maxv 37: #define NVMM_MAX_HMAPPINGS 32
1.4 maxv 38: #define NVMM_MAX_RAM (128ULL * (1 << 30))
1.1 maxv 39:
1.8 maxv 40: struct nvmm_owner {
41: pid_t pid;
42: };
43:
1.1 maxv 44: struct nvmm_cpu {
45: /* Shared. */
46: bool present;
47: nvmm_cpuid_t cpuid;
48: kmutex_t lock;
49:
1.10 maxv 50: /* Comm page. */
51: struct nvmm_comm_page *comm;
1.3 maxv 52:
1.1 maxv 53: /* Last host CPU on which the VCPU ran. */
54: int hcpu_last;
55:
56: /* Implementation-specific. */
57: void *cpudata;
58: };
59:
1.7 maxv 60: struct nvmm_hmapping {
1.2 maxv 61: bool present;
62: uintptr_t hva;
63: size_t size;
64: struct uvm_object *uobj;
65: };
66:
1.1 maxv 67: struct nvmm_machine {
68: bool present;
69: nvmm_machid_t machid;
1.9 maxv 70: time_t time;
1.8 maxv 71: struct nvmm_owner *owner;
1.1 maxv 72: krwlock_t lock;
73:
1.10 maxv 74: /* Comm */
75: struct uvm_object *commuobj;
76:
1.1 maxv 77: /* Kernel */
78: struct vmspace *vm;
79: gpaddr_t gpa_begin;
80: gpaddr_t gpa_end;
81:
1.7 maxv 82: /* Host Mappings */
83: struct nvmm_hmapping hmap[NVMM_MAX_HMAPPINGS];
1.2 maxv 84:
1.1 maxv 85: /* CPU */
1.14 maxv 86: volatile unsigned int ncpus;
1.1 maxv 87: struct nvmm_cpu cpus[NVMM_MAX_VCPUS];
88:
89: /* Implementation-specific */
90: void *machdata;
91: };
92:
93: struct nvmm_impl {
1.16 maxv 94: const char *name;
1.1 maxv 95: bool (*ident)(void);
96: void (*init)(void);
97: void (*fini)(void);
98: void (*capability)(struct nvmm_capability *);
99:
1.13 maxv 100: size_t mach_conf_max;
101: const size_t *mach_conf_sizes;
102:
103: size_t vcpu_conf_max;
104: const size_t *vcpu_conf_sizes;
105:
1.1 maxv 106: size_t state_size;
107:
108: void (*machine_create)(struct nvmm_machine *);
109: void (*machine_destroy)(struct nvmm_machine *);
110: int (*machine_configure)(struct nvmm_machine *, uint64_t, void *);
111:
112: int (*vcpu_create)(struct nvmm_machine *, struct nvmm_cpu *);
113: void (*vcpu_destroy)(struct nvmm_machine *, struct nvmm_cpu *);
1.13 maxv 114: int (*vcpu_configure)(struct nvmm_cpu *, uint64_t, void *);
1.10 maxv 115: void (*vcpu_setstate)(struct nvmm_cpu *);
116: void (*vcpu_getstate)(struct nvmm_cpu *);
1.11 maxv 117: int (*vcpu_inject)(struct nvmm_cpu *);
1.1 maxv 118: int (*vcpu_run)(struct nvmm_machine *, struct nvmm_cpu *,
1.13 maxv 119: struct nvmm_vcpu_exit *);
1.1 maxv 120: };
121:
1.17 ! maxv 122: #if defined(__x86_64__)
1.1 maxv 123: extern const struct nvmm_impl nvmm_x86_svm;
1.5 maxv 124: extern const struct nvmm_impl nvmm_x86_vmx;
1.17 ! maxv 125: #endif
1.1 maxv 126:
1.15 maxv 127: static inline bool
128: nvmm_return_needed(void)
129: {
130: if (preempt_needed()) {
131: return true;
132: }
133: if (curlwp->l_flag & LW_USERRET) {
134: return true;
135: }
136: return false;
137: }
138:
1.1 maxv 139: #endif /* _NVMM_INTERNAL_H_ */
CVSweb <webmaster@jp.NetBSD.org>