VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/NEMR3.cpp@ 70946

Last change on this file since 70946 was 70946, checked in by vboxsync, 7 years ago

VMM/NEM: More code. [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: NEMR3.cpp 70946 2018-02-09 23:48:02Z vboxsync $ */
2/** @file
3 * NEM - Native execution manager.
4 */
5
6/*
7 * Copyright (C) 2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/** @page pg_nem NEM - Native Execution Manager.
19 *
20 * Later.
21 *
22 */
23
24
25/*********************************************************************************************************************************
26* Header Files *
27*********************************************************************************************************************************/
28#define LOG_GROUP LOG_GROUP_NEM
29#include <VBox/vmm/nem.h>
30#include "NEMInternal.h"
31#include <VBox/vmm/vm.h>
32
33
34
35/**
36 * Basic init and configuration reading.
37 *
38 * Always call NEMR3Term after calling this.
39 *
40 * @returns VBox status code.
41 * @param pVM The cross context VM structure.
42 */
43VMMR3_INT_DECL(int) NEMR3InitConfig(PVM pVM)
44{
45 LogFlow(("NEMR3Init\n"));
46
47 /*
48 * Assert alignment and sizes.
49 */
50 AssertCompileMemberAlignment(VM, nem.s, 64);
51 AssertCompile(sizeof(pVM->nem.s) <= sizeof(pVM->nem.padding));
52
53 /*
54 * Initialize state info so NEMR3Term will always be happy.
55 * No returning prior to setting magics!
56 */
57 pVM->nem.s.u32Magic = NEM_MAGIC;
58 for (VMCPUID iCpu = 0; iCpu < pVM->cCpus; iCpu++)
59 pVM->aCpus[iCpu].nem.s.u32Magic = NEMCPU_MAGIC;
60
61 /*
62 * Read configuration.
63 */
64 PCFGMNODE pCfgNem = CFGMR3GetChild(CFGMR3GetRoot(pVM), "NEM/");
65
66 /*
67 * Validate the NEM settings.
68 */
69 int rc = CFGMR3ValidateConfig(pCfgNem,
70 "/NEM/",
71 "Enabled",
72 "" /* pszValidNodes */, "NEM" /* pszWho */, 0 /* uInstance */);
73 if (RT_FAILURE(rc))
74 return rc;
75
76 /** @cfgm{/NEM/NEMEnabled, bool, true}
77 * Whether NEM is enabled. */
78 rc = CFGMR3QueryBoolDef(pCfgNem, "Enabled", &pVM->nem.s.fEnabled, true);
79 AssertLogRelRCReturn(rc, rc);
80
81 return VINF_SUCCESS;
82}
83
84
85/**
86 * This is called by HMR3Init() when HM cannot be used.
87 *
88 * Sets VM::fNEMActive if we can use a native hypervisor API to execute the VM.
89 *
90 * @returns VBox status code.
91 * @param pVM The cross context VM structure.
92 * @param fFallback Whether this is a fallback call. Cleared if the VM is
93 * configured to use NEM instead of HM.
94 * @param fForced Whether /HM/HMForced was set. If set and we fail to
95 * enable NEM, we'll return a failure status code.
96 * Otherwise we'll assume HMR3Init falls back on raw-mode.
97 */
98VMMR3_INT_DECL(int) NEMR3Init(PVM pVM, bool fFallback, bool fForced)
99{
100 Assert(!pVM->fNEMActive);
101 int rc;
102 if (pVM->nem.s.fEnabled)
103 {
104#ifdef VBOX_WITH_NATIVE_NEM
105 rc = nemR3NativeInit(pVM, fFallback, fForced);
106#else
107 RT_NOREF(fFallback);
108 rc = VINF_SUCCESS;
109#endif
110 if (RT_SUCCESS(rc))
111 {
112 if (pVM->fNEMActive)
113 LogRel(("NEM: NEMR3Init: Active.\n"));
114 else
115 {
116 LogRel(("NEM: NEMR3Init: Not available.\n"));
117 if (fForced)
118 rc = VERR_NEM_NOT_AVAILABLE;
119 }
120 }
121 else
122 LogRel(("NEM: NEMR3Init: Native init failed: %Rrc.\n", rc));
123 }
124 else
125 {
126 LogRel(("NEM: NEMR3Init: Disabled.\n"));
127 rc = fForced ? VERR_NEM_NOT_ENABLED : VINF_SUCCESS;
128 }
129 return rc;
130}
131
132
133/**
134 * Perform initialization that depends on CPUM working.
135 *
136 * This is a noop if NEM wasn't activated by a previous NEMR3Init() call.
137 *
138 * @returns VBox status code.
139 * @param pVM The cross context VM structure.
140 */
141VMMR3_INT_DECL(int) NEMR3InitAfterCPUM(PVM pVM)
142{
143 int rc = VINF_SUCCESS;
144#ifdef VBOX_WITH_NATIVE_NEM
145 if (pVM->fNEMActive)
146 rc = nemR3NativeInitAfterCPUM(pVM);
147#else
148 RT_NOREF(pVM);
149#endif
150 return rc;
151}
152
153
154/**
155 * Called when a init phase has completed.
156 *
157 * @returns VBox status code.
158 * @param pVM The cross context VM structure.
159 * @param enmWhat The phase that completed.
160 */
161VMMR3_INT_DECL(int) NEMR3InitCompleted(PVM pVM, VMINITCOMPLETED enmWhat)
162{
163 int rc = VINF_SUCCESS;
164#ifdef VBOX_WITH_NATIVE_NEM
165 if (pVM->fNEMActive)
166 rc = nemR3NativeInitCompleted(pVM, enmWhat);
167#else
168 RT_NOREF(pVM, enmWhat);
169#endif
170 return rc;
171}
172
173
174/**
175 *
176 * @returns VBox status code.
177 * @param pVM The cross context VM structure.
178 */
179VMMR3_INT_DECL(int) NEMR3Term(PVM pVM)
180{
181 AssertReturn(pVM->nem.s.u32Magic == NEM_MAGIC, VERR_WRONG_ORDER);
182 for (VMCPUID iCpu = 0; iCpu < pVM->cCpus; iCpu++)
183 AssertReturn(pVM->aCpus[iCpu].nem.s.u32Magic == NEMCPU_MAGIC, VERR_WRONG_ORDER);
184
185 /* Do native termination. */
186 int rc = VINF_SUCCESS;
187#ifdef VBOX_WITH_NATIVE_NEM
188 if (pVM->fNEMActive)
189 rc = nemR3NativeTerm(pVM);
190#endif
191
192 /* Mark it as terminated. */
193 for (VMCPUID iCpu = 0; iCpu < pVM->cCpus; iCpu++)
194 pVM->aCpus[iCpu].nem.s.u32Magic = NEMCPU_MAGIC_DEAD;
195 pVM->nem.s.u32Magic = NEM_MAGIC_DEAD;
196 return rc;
197}
198
199
200/**
201 * The VM is being reset.
202 *
203 * @param pVM The cross context VM structure.
204 */
205VMMR3_INT_DECL(void) NEMR3Reset(PVM pVM)
206{
207#ifdef VBOX_WITH_NATIVE_NEM
208 if (pVM->fNEMActive)
209 nemR3NativeReset(pVM);
210#else
211 RT_NOREF(pVM);
212#endif
213}
214
215
216/**
217 * Resets a virtual CPU.
218 *
219 * Used to bring up secondary CPUs on SMP as well as CPU hot plugging.
220 *
221 * @param pVCpu The cross context virtual CPU structure to reset.
222 */
223VMMR3_INT_DECL(void) NEMR3ResetCpu(PVMCPU pVCpu)
224{
225#ifdef VBOX_WITH_NATIVE_NEM
226 if (pVCpu->pVMR3->fNEMActive)
227 nemR3NativeResetCpu(pVCpu);
228#else
229 RT_NOREF(pVCpu);
230#endif
231}
232
Note: See TracBrowser for help on using the repository browser.

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