VirtualBox

source: vbox/trunk/include/VBox/vmm/gvm.h@ 107401

Last change on this file since 107401 was 107113, checked in by vboxsync, 3 months ago

VMM: bugref:10759 Restructure the APIC to allow different backends to be used.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 10.5 KB
Line 
1/* $Id: gvm.h 107113 2024-11-22 10:48:00Z vboxsync $ */
2/** @file
3 * GVM - The Global VM Data.
4 */
5
6/*
7 * Copyright (C) 2007-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef VBOX_INCLUDED_vmm_gvm_h
38#define VBOX_INCLUDED_vmm_gvm_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#ifndef USING_VMM_COMMON_DEFS
44# error "Compile job does not include VMM_COMMON_DEFS from src/VBox/Config.kmk - make sure you really need to include this file!"
45#endif
46#include <VBox/types.h>
47#include <VBox/vmm/vm.h>
48#include <VBox/param.h>
49#include <iprt/thread.h>
50#include <iprt/assertcompile.h>
51
52
53/** @defgroup grp_gvmcpu GVMCPU - The Global VMCPU Data
54 * @ingroup grp_vmm
55 * @{
56 */
57
58#if defined(__cplusplus) && !defined(GVM_C_STYLE_STRUCTURES)
59typedef struct GVMCPU : public VMCPU
60#else
61typedef struct GVMCPU
62#endif
63{
64#if !defined(__cplusplus) || defined(GVM_C_STYLE_STRUCTURES)
65 VMCPU s;
66#endif
67
68 /** VCPU id (0 - (pVM->cCpus - 1). */
69 VMCPUID idCpu;
70 /** Padding. */
71 uint32_t uPadding0;
72
73 /** Handle to the EMT thread. */
74 RTNATIVETHREAD hEMT;
75
76 /** Pointer to the global (ring-0) VM structure this CPU belongs to. */
77 R0PTRTYPE(PGVM) pGVM;
78 /** Pointer to the GVM structure, for CTX_SUFF use in VMMAll code. */
79 PGVM pVMR0;
80 /** The ring-3 address of this structure (only VMCPU part). */
81 PVMCPUR3 pVCpuR3;
82
83 /** Padding so the noisy stuff on a 64 byte boundrary.
84 * @note Keeping this working for 32-bit header syntax checking. */
85 uint8_t abPadding1[HC_ARCH_BITS == 32 ? 40 : 24];
86
87 /** Which host CPU ID is this EMT running on.
88 * Only valid when in RC or HMR0 with scheduling disabled. */
89 RTCPUID volatile idHostCpu;
90 /** The CPU set index corresponding to idHostCpu, UINT32_MAX if not valid.
91 * @remarks Best to make sure iHostCpuSet shares cache line with idHostCpu! */
92 uint32_t volatile iHostCpuSet;
93
94 /** Padding so gvmm starts on a 64 byte boundrary.
95 * @note Keeping this working for 32-bit header syntax checking. */
96 uint8_t abPadding2[56];
97
98 /** The GVMM per vcpu data. */
99 union
100 {
101#ifdef VMM_INCLUDED_SRC_VMMR0_GVMMR0Internal_h
102 struct GVMMPERVCPU s;
103#endif
104 uint8_t padding[256];
105 } gvmm;
106
107 union
108 {
109#if defined(VMM_INCLUDED_SRC_include_VMMInternal_h) && defined(IN_RING0)
110 struct VMMR0PERVCPU s;
111#endif
112 uint8_t padding[896];
113 } vmmr0;
114
115#ifndef VBOX_WITH_MINIMAL_R0
116
117 /** The HM per vcpu data. */
118 union
119 {
120# if defined(VMM_INCLUDED_SRC_include_HMInternal_h) && defined(IN_RING0)
121 struct HMR0PERVCPU s;
122# endif
123 uint8_t padding[1024];
124 } hmr0;
125
126# ifdef VBOX_WITH_NEM_R0
127 /** The NEM per vcpu data. */
128 union
129 {
130# if defined(VMM_INCLUDED_SRC_include_NEMInternal_h) && defined(IN_RING0)
131 struct NEMR0PERVCPU s;
132# endif
133 uint8_t padding[64];
134 } nemr0;
135# endif
136
137 union
138 {
139# if defined(VMM_INCLUDED_SRC_include_PGMInternal_h) && defined(IN_RING0)
140 struct PGMR0PERVCPU s;
141# endif
142 uint8_t padding[576];
143 } pgmr0;
144
145#endif /* !VBOX_WITH_MINIMAL_R0 */
146
147 /** Padding the structure size to page boundrary. */
148#ifdef VBOX_WITH_MINIMAL_R0
149 uint8_t abPadding3[16384 - 64*2 - 256 - 896];
150#elif defined(VBOX_WITH_NEM_R0)
151 uint8_t abPadding3[16384 - 64*2 - 256 - 896 - 1024 - 64 - 576];
152#else
153 uint8_t abPadding3[16384 - 64*2 - 256 - 896 - 1024 - 576];
154#endif
155} GVMCPU;
156#ifndef IN_TSTVMSTRUCT
157# if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
158# pragma GCC diagnostic push
159# endif
160# if RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
161# pragma GCC diagnostic ignored "-Winvalid-offsetof"
162# endif
163AssertCompileMemberAlignment(GVMCPU, idCpu, 16384);
164AssertCompileMemberAlignment(GVMCPU, gvmm, 64);
165# ifndef VBOX_WITH_MINIMAL_R0
166# ifdef VBOX_WITH_NEM_R0
167AssertCompileMemberAlignment(GVMCPU, nemr0, 64);
168# endif
169# endif
170AssertCompileSizeAlignment(GVMCPU, 16384);
171# if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
172# pragma GCC diagnostic pop
173# endif
174#endif
175
176/** @} */
177
178/** @defgroup grp_gvm GVM - The Global VM Data
179 * @ingroup grp_vmm
180 * @{
181 */
182
183/**
184 * The Global VM Data.
185 *
186 * This is a ring-0 only structure where we put items we don't need to
187 * share with ring-3 or GC, like for instance various RTR0MEMOBJ handles.
188 *
189 * Unlike VM, there are no special alignment restrictions here. The
190 * paddings are checked by compile time assertions.
191 */
192#if defined(__cplusplus) && !defined(GVM_C_STYLE_STRUCTURES)
193typedef struct GVM : public VM
194#else
195typedef struct GVM
196#endif
197{
198#if !defined(__cplusplus) || defined(GVM_C_STYLE_STRUCTURES)
199 VM s;
200#endif
201 /** Magic / eye-catcher (GVM_MAGIC). */
202 uint32_t u32Magic;
203 /** The global VM handle for this VM. */
204 uint32_t hSelf;
205 /** Pointer to this structure (for validation purposes). */
206 PGVM pSelf;
207 /** The ring-3 mapping of the VM structure. */
208 PVMR3 pVMR3;
209 /** The support driver session the VM is associated with. */
210 PSUPDRVSESSION pSession;
211 /** Number of Virtual CPUs, i.e. how many entries there are in aCpus.
212 * Same same as VM::cCpus. */
213 uint32_t cCpus;
214 /** Padding so gvmm starts on a 64 byte boundrary. */
215 uint8_t abPadding[HC_ARCH_BITS == 32 ? 12 + 28 : 28];
216
217 /** The GVMM per vm data. */
218 union
219 {
220#ifdef VMM_INCLUDED_SRC_VMMR0_GVMMR0Internal_h
221 struct GVMMPERVM s;
222#endif
223 uint8_t padding[4352];
224 } gvmm;
225
226#ifndef VBOX_WITH_MINIMAL_R0
227
228 /** The GMM per vm data. */
229 union
230 {
231# ifdef VMM_INCLUDED_SRC_VMMR0_GMMR0Internal_h
232 struct GMMPERVM s;
233# endif
234 uint8_t padding[1024];
235 } gmm;
236
237 /** The HM per vm data. */
238 union
239 {
240# if defined(VMM_INCLUDED_SRC_include_HMInternal_h) && defined(IN_RING0)
241 struct HMR0PERVM s;
242# endif
243 uint8_t padding[256];
244 } hmr0;
245
246# ifdef VBOX_WITH_NEM_R0
247 /** The NEM per vcpu data. */
248 union
249 {
250# if defined(VMM_INCLUDED_SRC_include_NEMInternal_h) && defined(IN_RING0)
251 struct NEMR0PERVM s;
252# endif
253 uint8_t padding[256];
254 } nemr0;
255# endif
256
257 /** The RAWPCIVM per vm data. */
258 union
259 {
260# ifdef VBOX_INCLUDED_rawpci_h
261 struct RAWPCIPERVM s;
262# endif
263 uint8_t padding[64];
264 } rawpci;
265
266 union
267 {
268# if defined(VMM_INCLUDED_SRC_include_PDMInternal_h) && defined(IN_RING0)
269 struct PDMR0PERVM s;
270# endif
271 uint8_t padding[3264];
272 } pdmr0;
273
274 union
275 {
276# if defined(VMM_INCLUDED_SRC_include_PGMInternal_h) && defined(IN_RING0)
277 struct PGMR0PERVM s;
278# endif
279 uint8_t padding[90112];
280 } pgmr0;
281
282 union
283 {
284# if defined(VMM_INCLUDED_SRC_include_IOMInternal_h) && defined(IN_RING0)
285 struct IOMR0PERVM s;
286# endif
287 uint8_t padding[512];
288 } iomr0;
289
290 union
291 {
292# if defined(VMM_INCLUDED_SRC_include_APICInternal_h) && defined(IN_RING0)
293 struct APICR0PERVM s;
294# endif
295 uint8_t padding[64];
296 } apicr0;
297
298 union
299 {
300# if defined(VMM_INCLUDED_SRC_include_DBGFInternal_h) && defined(IN_RING0)
301 struct DBGFR0PERVM s;
302# endif
303 uint8_t padding[1024];
304 } dbgfr0;
305
306 union
307 {
308# if defined(VMM_INCLUDED_SRC_include_TMInternal_h) && defined(IN_RING0)
309 TMR0PERVM s;
310# endif
311 uint8_t padding[192];
312 } tmr0;
313
314#endif /* !VBOX_WITH_MINIMAL_R0 */
315
316 union
317 {
318#if defined(VMM_INCLUDED_SRC_include_VMMInternal_h) && defined(IN_RING0)
319 VMMR0PERVM s;
320#endif
321 uint8_t padding[704];
322 } vmmr0;
323
324 /** Padding so aCpus starts on a page boundrary. */
325#ifdef VBOX_WITH_MINIMAL_R0
326 uint8_t abPadding2[16384*1 - 64 - 4352 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
327#elif defined(VBOX_WITH_NEM_R0)
328 uint8_t abPadding2[16384*7 - 64 - 4352 - 1024 - 256 - 256 - 64 - 3264 - 90112 - 512 - 64 - 1024 - 192 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
329#else
330 uint8_t abPadding2[16384*7 - 64 - 4352 - 1024 - 256 - 64 - 3264 - 90112 - 512 - 64 - 1024 - 192 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
331#endif
332
333 /** For simplifying CPU enumeration in VMMAll code. */
334 PGVMCPU apCpusR0[VMM_MAX_CPU_COUNT];
335
336 /** GVMCPU array for the configured number of virtual CPUs. */
337 GVMCPU aCpus[1];
338} GVM;
339#if 0
340#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
341# pragma GCC diagnostic push
342#endif
343#if RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
344# pragma GCC diagnostic ignored "-Winvalid-offsetof"
345#endif
346AssertCompileMemberAlignment(GVM, u32Magic, 64);
347AssertCompileMemberAlignment(GVM, gvmm, 64);
348AssertCompileMemberAlignment(GVM, gmm, 64);
349#ifdef VBOX_WITH_NEM_R0
350AssertCompileMemberAlignment(GVM, nemr0, 64);
351#endif
352AssertCompileMemberAlignment(GVM, rawpci, 64);
353AssertCompileMemberAlignment(GVM, pdmr0, 64);
354AssertCompileMemberAlignment(GVM, aCpus, 16384);
355AssertCompileSizeAlignment(GVM, 16384);
356#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
357# pragma GCC diagnostic pop
358#endif
359#endif
360
361/** The GVM::u32Magic value (Wayne Shorter). */
362#define GVM_MAGIC 0x19330825
363
364/** @} */
365
366#endif /* !VBOX_INCLUDED_vmm_gvm_h */
367
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette