1 | /* $Id: PlatformImpl.cpp 101046 2023-09-07 11:42:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation - Platform settings.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2023 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 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #define LOG_GROUP LOG_GROUP_MAIN_PLATFORM
|
---|
29 | #include "PlatformImpl.h"
|
---|
30 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
31 | # include "PlatformARMImpl.h"
|
---|
32 | #endif
|
---|
33 | #include "PlatformX86Impl.h"
|
---|
34 | #include "PlatformPropertiesImpl.h"
|
---|
35 | #include "MachineImpl.h"
|
---|
36 | #include "LoggingNew.h"
|
---|
37 |
|
---|
38 | #include "AutoStateDep.h"
|
---|
39 |
|
---|
40 | #include <iprt/cpp/utils.h>
|
---|
41 |
|
---|
42 | #include <VBox/settings.h>
|
---|
43 |
|
---|
44 |
|
---|
45 | struct Platform::Data
|
---|
46 | {
|
---|
47 | Data() { }
|
---|
48 |
|
---|
49 | ComObjPtr<Platform> pPeer;
|
---|
50 |
|
---|
51 | // use the XML settings structure in the members for simplicity
|
---|
52 | Backupable<settings::Platform> bd;
|
---|
53 | };
|
---|
54 |
|
---|
55 |
|
---|
56 | /*
|
---|
57 | * Platform implementation.
|
---|
58 | */
|
---|
59 | Platform::Platform()
|
---|
60 | : mParent(NULL)
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | Platform::~Platform()
|
---|
65 | {
|
---|
66 | uninit();
|
---|
67 | }
|
---|
68 |
|
---|
69 | HRESULT Platform::FinalConstruct()
|
---|
70 | {
|
---|
71 | return BaseFinalConstruct();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void Platform::FinalRelease()
|
---|
75 | {
|
---|
76 | uninit();
|
---|
77 |
|
---|
78 | BaseFinalRelease();
|
---|
79 | }
|
---|
80 |
|
---|
81 | HRESULT Platform::init(Machine *aParent)
|
---|
82 | {
|
---|
83 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
84 | AutoInitSpan autoInitSpan(this);
|
---|
85 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
86 |
|
---|
87 | /* Share the parent weakly */
|
---|
88 | unconst(mParent) = aParent;
|
---|
89 |
|
---|
90 | m = new Data();
|
---|
91 |
|
---|
92 | m->bd.allocate();
|
---|
93 |
|
---|
94 | /* Confirm a successful initialization */
|
---|
95 | autoInitSpan.setSucceeded();
|
---|
96 |
|
---|
97 | return S_OK;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Initializes the platform object given another platform object
|
---|
102 | * (a kind of copy constructor). This object shares data with
|
---|
103 | * the object passed as an argument.
|
---|
104 | *
|
---|
105 | * @note This object must be destroyed before the original object
|
---|
106 | * it shares data with is destroyed.
|
---|
107 | */
|
---|
108 | HRESULT Platform::init(Machine *aParent, Platform *aThat)
|
---|
109 | {
|
---|
110 | LogFlowThisFuncEnter();
|
---|
111 | LogFlowThisFunc(("aParent: %p, aThat: %p\n", aParent, aThat));
|
---|
112 |
|
---|
113 | ComAssertRet(aParent && aThat, E_INVALIDARG);
|
---|
114 |
|
---|
115 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
116 | AutoInitSpan autoInitSpan(this);
|
---|
117 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
118 |
|
---|
119 | unconst(mParent) = aParent;
|
---|
120 |
|
---|
121 | m = new Data();
|
---|
122 | m->pPeer = aThat;
|
---|
123 |
|
---|
124 | AutoWriteLock thatlock(aThat COMMA_LOCKVAL_SRC_POS);
|
---|
125 | m->bd.share(aThat->m->bd);
|
---|
126 |
|
---|
127 | /* Allocates architecture-dependent stuff. */
|
---|
128 | HRESULT hrc = i_initArchitecture(aThat->m->bd->architectureType, aThat);
|
---|
129 | AssertComRCReturnRC(hrc);
|
---|
130 |
|
---|
131 | autoInitSpan.setSucceeded();
|
---|
132 |
|
---|
133 | LogFlowThisFuncLeave();
|
---|
134 | return S_OK;
|
---|
135 | }
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Initializes the guest object given another guest object
|
---|
139 | * (a kind of copy constructor). This object makes a private copy of data
|
---|
140 | * of the original object passed as an argument.
|
---|
141 | */
|
---|
142 | HRESULT Platform::initCopy(Machine *aParent, Platform *aThat)
|
---|
143 | {
|
---|
144 | LogFlowThisFuncEnter();
|
---|
145 | LogFlowThisFunc(("aParent: %p, aThat: %p\n", aParent, aThat));
|
---|
146 |
|
---|
147 | ComAssertRet(aParent && aThat, E_INVALIDARG);
|
---|
148 |
|
---|
149 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
150 | AutoInitSpan autoInitSpan(this);
|
---|
151 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
152 |
|
---|
153 | unconst(mParent) = aParent;
|
---|
154 |
|
---|
155 | m = new Data();
|
---|
156 | // m->pPeer is left null
|
---|
157 |
|
---|
158 | AutoWriteLock thatlock(aThat COMMA_LOCKVAL_SRC_POS); /** @todo r=andy Shouldn't a read lock be sufficient here? */
|
---|
159 | m->bd.attachCopy(aThat->m->bd);
|
---|
160 |
|
---|
161 | /* Allocates architecture-dependent stuff. */
|
---|
162 | HRESULT hrc = i_initArchitecture(aThat->m->bd->architectureType, aThat, true /* fCopy */);
|
---|
163 | AssertComRCReturnRC(hrc);
|
---|
164 |
|
---|
165 | autoInitSpan.setSucceeded();
|
---|
166 |
|
---|
167 | LogFlowThisFuncLeave();
|
---|
168 | return S_OK;
|
---|
169 | }
|
---|
170 |
|
---|
171 | void Platform::uninit()
|
---|
172 | {
|
---|
173 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
174 | AutoUninitSpan autoUninitSpan(this);
|
---|
175 | if (autoUninitSpan.uninitDone())
|
---|
176 | return;
|
---|
177 |
|
---|
178 | unconst(mParent) = NULL;
|
---|
179 |
|
---|
180 | uninitArchitecture();
|
---|
181 |
|
---|
182 | m->bd.free();
|
---|
183 |
|
---|
184 | unconst(m->pPeer) = NULL;
|
---|
185 |
|
---|
186 | delete m;
|
---|
187 | m = NULL;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Unitializes all platform-specific objects.
|
---|
192 | *
|
---|
193 | * Called by uninit() and i_setArchitecture().
|
---|
194 | */
|
---|
195 | void Platform::uninitArchitecture()
|
---|
196 | {
|
---|
197 | if (mX86)
|
---|
198 | {
|
---|
199 | mX86->uninit();
|
---|
200 | unconst(mX86).setNull();
|
---|
201 | }
|
---|
202 |
|
---|
203 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
204 | if (mARM)
|
---|
205 | {
|
---|
206 | mARM->uninit();
|
---|
207 | unconst(mARM).setNull();
|
---|
208 | }
|
---|
209 | #endif
|
---|
210 | }
|
---|
211 |
|
---|
212 |
|
---|
213 | // IPlatform properties
|
---|
214 | ////////////////////////////////////////////////////////////////////////////////
|
---|
215 |
|
---|
216 | HRESULT Platform::getArchitecture(PlatformArchitecture_T *aArchitecture)
|
---|
217 | {
|
---|
218 | /* sanity */
|
---|
219 | AutoCaller autoCaller(this);
|
---|
220 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
221 |
|
---|
222 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
223 |
|
---|
224 | *aArchitecture = m->bd->architectureType;
|
---|
225 |
|
---|
226 | return S_OK;
|
---|
227 | }
|
---|
228 |
|
---|
229 | HRESULT Platform::setArchitecture(PlatformArchitecture_T aArchitecture)
|
---|
230 | {
|
---|
231 | /* sanity */
|
---|
232 | AutoCaller autoCaller(this);
|
---|
233 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
234 |
|
---|
235 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
236 |
|
---|
237 | /** @todo BUGBUG Implement this! */
|
---|
238 | RT_NOREF(aArchitecture);
|
---|
239 |
|
---|
240 | return E_NOTIMPL;
|
---|
241 | }
|
---|
242 |
|
---|
243 | HRESULT Platform::getProperties(ComPtr<IPlatformProperties> &aProperties)
|
---|
244 | {
|
---|
245 | /* sanity */
|
---|
246 | AutoCaller autoCaller(this);
|
---|
247 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
248 |
|
---|
249 | ComObjPtr<PlatformProperties> properties;
|
---|
250 | HRESULT hrc = properties.createObject();
|
---|
251 | AssertComRCReturnRC(hrc);
|
---|
252 | hrc = properties->init(mParent->mParent);
|
---|
253 | AssertComRCReturnRC(hrc);
|
---|
254 |
|
---|
255 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
256 |
|
---|
257 | hrc = properties->i_setArchitecture(m->bd->architectureType);
|
---|
258 | AssertComRCReturnRC(hrc);
|
---|
259 |
|
---|
260 | return properties.queryInterfaceTo(aProperties.asOutParam());
|
---|
261 | }
|
---|
262 |
|
---|
263 | HRESULT Platform::getX86(ComPtr<IPlatformX86> &aX86)
|
---|
264 | {
|
---|
265 | /* sanity */
|
---|
266 | AutoCaller autoCaller(this);
|
---|
267 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
268 |
|
---|
269 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
270 |
|
---|
271 | switch (m->bd->architectureType)
|
---|
272 | {
|
---|
273 | case PlatformArchitecture_x86:
|
---|
274 | {
|
---|
275 | /* mX86 is constant during life time, no need to lock */
|
---|
276 | return mX86.queryInterfaceTo(aX86.asOutParam());
|
---|
277 | }
|
---|
278 |
|
---|
279 | default:
|
---|
280 | /* For anything else return an error. */
|
---|
281 | break;
|
---|
282 | }
|
---|
283 |
|
---|
284 | return VBOX_E_PLATFORM_ARCH_NOT_SUPPORTED;
|
---|
285 | }
|
---|
286 |
|
---|
287 | HRESULT Platform::getARM(ComPtr<IPlatformARM> &aARM)
|
---|
288 | {
|
---|
289 | /* sanity */
|
---|
290 | AutoCaller autoCaller(this);
|
---|
291 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
292 |
|
---|
293 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
294 |
|
---|
295 | switch (m->bd->architectureType)
|
---|
296 | {
|
---|
297 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
298 | case PlatformArchitecture_ARM:
|
---|
299 | {
|
---|
300 | /* mARM is constant during life time, no need to lock */
|
---|
301 | return mARM.queryInterfaceTo(aARM.asOutParam());
|
---|
302 | }
|
---|
303 | #else
|
---|
304 | RT_NOREF(aARM);
|
---|
305 | #endif
|
---|
306 | default:
|
---|
307 | /* For anything else return an error. */
|
---|
308 | break;
|
---|
309 | }
|
---|
310 |
|
---|
311 | return VBOX_E_PLATFORM_ARCH_NOT_SUPPORTED;
|
---|
312 | }
|
---|
313 |
|
---|
314 | HRESULT Platform::getChipsetType(ChipsetType_T *aChipsetType)
|
---|
315 | {
|
---|
316 | /* sanity */
|
---|
317 | AutoCaller autoCaller(this);
|
---|
318 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
319 |
|
---|
320 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
321 |
|
---|
322 | *aChipsetType = m->bd->chipsetType;
|
---|
323 |
|
---|
324 | return S_OK;
|
---|
325 | }
|
---|
326 |
|
---|
327 | HRESULT Platform::setChipsetType(ChipsetType_T aChipsetType)
|
---|
328 | {
|
---|
329 | /* sanity */
|
---|
330 | AutoCaller autoCaller(this);
|
---|
331 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
332 |
|
---|
333 | /* the machine needs to be mutable */
|
---|
334 | AutoMutableStateDependency adep(mParent);
|
---|
335 | if (FAILED(adep.hrc())) return adep.hrc();
|
---|
336 |
|
---|
337 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
338 |
|
---|
339 | if (aChipsetType != m->bd->chipsetType)
|
---|
340 | {
|
---|
341 | m->bd.backup();
|
---|
342 | m->bd->chipsetType = aChipsetType;
|
---|
343 |
|
---|
344 | alock.release();
|
---|
345 |
|
---|
346 | AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
347 | mParent->i_setModified(Machine::IsModified_Platform);
|
---|
348 |
|
---|
349 | // Resize network adapter array, to be finalized on commit/rollback.
|
---|
350 | // We must not throw away entries yet, otherwise settings are lost
|
---|
351 | // without a way to roll back.
|
---|
352 | size_t const newCount = PlatformProperties::s_getMaxNetworkAdapters(aChipsetType);
|
---|
353 | size_t const oldCount = mParent->mNetworkAdapters.size();
|
---|
354 | if (newCount > oldCount)
|
---|
355 | {
|
---|
356 | mParent->mNetworkAdapters.resize(newCount);
|
---|
357 | for (size_t slot = oldCount; slot < mParent->mNetworkAdapters.size(); slot++)
|
---|
358 | {
|
---|
359 | unconst(mParent->mNetworkAdapters[slot]).createObject();
|
---|
360 | mParent->mNetworkAdapters[slot]->init(mParent, (ULONG)slot);
|
---|
361 | }
|
---|
362 | }
|
---|
363 | }
|
---|
364 |
|
---|
365 | return S_OK;
|
---|
366 | }
|
---|
367 |
|
---|
368 | HRESULT Platform::getIommuType(IommuType_T *aIommuType)
|
---|
369 | {
|
---|
370 | /* sanity */
|
---|
371 | AutoCaller autoCaller(this);
|
---|
372 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
373 |
|
---|
374 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
375 |
|
---|
376 | *aIommuType = m->bd->iommuType;
|
---|
377 |
|
---|
378 | return S_OK;
|
---|
379 | }
|
---|
380 |
|
---|
381 | HRESULT Platform::setIommuType(IommuType_T aIommuType)
|
---|
382 | {
|
---|
383 | /* sanity */
|
---|
384 | AutoCaller autoCaller(this);
|
---|
385 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
386 |
|
---|
387 | /* the machine needs to be mutable */
|
---|
388 | AutoMutableStateDependency adep(mParent);
|
---|
389 | if (FAILED(adep.hrc())) return adep.hrc();
|
---|
390 |
|
---|
391 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
392 |
|
---|
393 | if (aIommuType != m->bd->iommuType)
|
---|
394 | {
|
---|
395 | if (aIommuType == IommuType_Intel)
|
---|
396 | {
|
---|
397 | #ifndef VBOX_WITH_IOMMU_INTEL
|
---|
398 | LogRelFunc(("Setting Intel IOMMU when Intel IOMMU support not available!\n"));
|
---|
399 | return E_UNEXPECTED;
|
---|
400 | #endif
|
---|
401 | }
|
---|
402 |
|
---|
403 | m->bd.backup();
|
---|
404 | m->bd->iommuType = aIommuType;
|
---|
405 |
|
---|
406 | alock.release();
|
---|
407 |
|
---|
408 | AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
409 | mParent->i_setModified(Machine::IsModified_Platform);
|
---|
410 | }
|
---|
411 |
|
---|
412 | return S_OK;
|
---|
413 | }
|
---|
414 |
|
---|
415 | HRESULT Platform::getRTCUseUTC(BOOL *aRTCUseUTC)
|
---|
416 | {
|
---|
417 | /* sanity */
|
---|
418 | AutoCaller autoCaller(this);
|
---|
419 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
420 |
|
---|
421 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
422 |
|
---|
423 | *aRTCUseUTC = m->bd->fRTCUseUTC;
|
---|
424 |
|
---|
425 | return S_OK;
|
---|
426 | }
|
---|
427 |
|
---|
428 | HRESULT Platform::setRTCUseUTC(BOOL aRTCUseUTC)
|
---|
429 | {
|
---|
430 | /* sanity */
|
---|
431 | AutoCaller autoCaller(this);
|
---|
432 | AssertComRCReturn(autoCaller.hrc(), autoCaller.hrc());
|
---|
433 |
|
---|
434 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
435 |
|
---|
436 | if (m->bd->fRTCUseUTC != RT_BOOL(aRTCUseUTC))
|
---|
437 | {
|
---|
438 | /* Only allow it to be set to true when PoweredOff or Aborted.
|
---|
439 | (Clearing it is always permitted.) */
|
---|
440 | if (aRTCUseUTC)
|
---|
441 | {
|
---|
442 | alock.release();
|
---|
443 |
|
---|
444 | /* the machine needs to be mutable */
|
---|
445 | AutoMutableStateDependency adep(mParent);
|
---|
446 | if (FAILED(adep.hrc())) return adep.hrc();
|
---|
447 |
|
---|
448 | alock.acquire();
|
---|
449 |
|
---|
450 | m->bd.backup();
|
---|
451 | m->bd->fRTCUseUTC = RT_BOOL(aRTCUseUTC);
|
---|
452 |
|
---|
453 | alock.release();
|
---|
454 |
|
---|
455 | AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
456 | mParent->i_setModified(Machine::IsModified_Platform);
|
---|
457 | }
|
---|
458 | else
|
---|
459 | {
|
---|
460 | m->bd.backup();
|
---|
461 | m->bd->fRTCUseUTC = RT_BOOL(aRTCUseUTC);
|
---|
462 | }
|
---|
463 | }
|
---|
464 |
|
---|
465 | return S_OK;
|
---|
466 | }
|
---|
467 |
|
---|
468 |
|
---|
469 | // public methods only for internal purposes
|
---|
470 | ////////////////////////////////////////////////////////////////////////////////
|
---|
471 |
|
---|
472 | /**
|
---|
473 | * Loads settings from the given platform node.
|
---|
474 | * May be called once right after this object creation.
|
---|
475 | *
|
---|
476 | * @returns HRESULT
|
---|
477 | * @param data Configuration settings.
|
---|
478 | *
|
---|
479 | * @note Locks this object for writing.
|
---|
480 | */
|
---|
481 | HRESULT Platform::i_loadSettings(const settings::Platform &data)
|
---|
482 | {
|
---|
483 | AutoCaller autoCaller(this);
|
---|
484 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
485 |
|
---|
486 | AutoReadLock mlock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
487 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
488 |
|
---|
489 | // simply copy
|
---|
490 | m->bd.assignCopy(&data);
|
---|
491 |
|
---|
492 | /* Allocates architecture-dependent stuff. */
|
---|
493 | HRESULT hrc = i_initArchitecture(m->bd->architectureType);
|
---|
494 | AssertComRCReturnRC(hrc);
|
---|
495 |
|
---|
496 | switch (m->bd->architectureType)
|
---|
497 | {
|
---|
498 | case PlatformArchitecture_x86:
|
---|
499 | return mX86->i_loadSettings(data.x86);
|
---|
500 |
|
---|
501 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
502 | case PlatformArchitecture_ARM:
|
---|
503 | return mARM->i_loadSettings(data.arm);
|
---|
504 | #endif
|
---|
505 | case PlatformArchitecture_None:
|
---|
506 | RT_FALL_THROUGH();
|
---|
507 | default:
|
---|
508 | break;
|
---|
509 | }
|
---|
510 |
|
---|
511 | AssertFailedReturn(VBOX_E_PLATFORM_ARCH_NOT_SUPPORTED);
|
---|
512 | }
|
---|
513 |
|
---|
514 | /**
|
---|
515 | * Saves settings to the given platform node.
|
---|
516 | *
|
---|
517 | * @returns HRESULT
|
---|
518 | * @param data Configuration settings.
|
---|
519 | *
|
---|
520 | * @note Locks this object for reading.
|
---|
521 | */
|
---|
522 | HRESULT Platform::i_saveSettings(settings::Platform &data)
|
---|
523 | {
|
---|
524 | AutoCaller autoCaller(this);
|
---|
525 | AssertComRCReturnRC(autoCaller.hrc());
|
---|
526 |
|
---|
527 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
528 |
|
---|
529 | data = *m->bd.data();
|
---|
530 |
|
---|
531 | switch (m->bd->architectureType)
|
---|
532 | {
|
---|
533 | case PlatformArchitecture_x86:
|
---|
534 | return mX86->i_saveSettings(data.x86);
|
---|
535 |
|
---|
536 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
537 | case PlatformArchitecture_ARM:
|
---|
538 | return mARM->i_saveSettings(data.arm);
|
---|
539 | #endif
|
---|
540 | case PlatformArchitecture_None:
|
---|
541 | RT_FALL_THROUGH();
|
---|
542 | default:
|
---|
543 | break;
|
---|
544 | }
|
---|
545 |
|
---|
546 | AssertFailedReturn(VBOX_E_PLATFORM_ARCH_NOT_SUPPORTED);
|
---|
547 | }
|
---|
548 |
|
---|
549 | void Platform::i_rollback()
|
---|
550 | {
|
---|
551 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
552 | m->bd.rollback();
|
---|
553 |
|
---|
554 | switch (m->bd->architectureType)
|
---|
555 | {
|
---|
556 | case PlatformArchitecture_x86:
|
---|
557 | return mX86->i_rollback();
|
---|
558 |
|
---|
559 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
560 | case PlatformArchitecture_ARM:
|
---|
561 | return mARM->i_rollback();
|
---|
562 | #endif
|
---|
563 | case PlatformArchitecture_None:
|
---|
564 | RT_FALL_THROUGH();
|
---|
565 | default:
|
---|
566 | break;
|
---|
567 | }
|
---|
568 |
|
---|
569 | AssertFailedReturnVoid();
|
---|
570 | }
|
---|
571 |
|
---|
572 | void Platform::i_commit()
|
---|
573 | {
|
---|
574 | /* sanity */
|
---|
575 | AutoCaller autoCaller(this);
|
---|
576 | AssertComRCReturnVoid(autoCaller.hrc());
|
---|
577 |
|
---|
578 | /* sanity too */
|
---|
579 | AutoCaller peerCaller(m->pPeer);
|
---|
580 | AssertComRCReturnVoid(peerCaller.hrc());
|
---|
581 |
|
---|
582 | /* lock both for writing since we modify both (mPeer is "master" so locked
|
---|
583 | * first) */
|
---|
584 | AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS);
|
---|
585 |
|
---|
586 | if (m->bd.isBackedUp())
|
---|
587 | {
|
---|
588 | m->bd.commit();
|
---|
589 |
|
---|
590 | if (m->pPeer)
|
---|
591 | {
|
---|
592 | /* attach new data to the peer and reshare it */
|
---|
593 | AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);
|
---|
594 | m->pPeer->m->bd.attach(m->bd);
|
---|
595 | }
|
---|
596 | }
|
---|
597 |
|
---|
598 | switch (m->bd->architectureType)
|
---|
599 | {
|
---|
600 | case PlatformArchitecture_x86:
|
---|
601 | return mX86->i_commit();
|
---|
602 |
|
---|
603 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
604 | case PlatformArchitecture_ARM:
|
---|
605 | return mARM->i_commit();
|
---|
606 | #endif
|
---|
607 | case PlatformArchitecture_None:
|
---|
608 | RT_FALL_THROUGH();
|
---|
609 | default:
|
---|
610 | break;
|
---|
611 | }
|
---|
612 |
|
---|
613 | AssertFailedReturnVoid();
|
---|
614 | }
|
---|
615 |
|
---|
616 | void Platform::i_copyFrom(Platform *aThat)
|
---|
617 | {
|
---|
618 | AssertReturnVoid(aThat != NULL);
|
---|
619 |
|
---|
620 | /* sanity */
|
---|
621 | AutoCaller autoCaller(this);
|
---|
622 | AssertComRCReturnVoid(autoCaller.hrc());
|
---|
623 |
|
---|
624 | /* sanity too */
|
---|
625 | AutoCaller thatCaller(aThat);
|
---|
626 | AssertComRCReturnVoid(thatCaller.hrc());
|
---|
627 |
|
---|
628 | /* peer is not modified, lock it for reading (aThat is "master" so locked
|
---|
629 | * first) */
|
---|
630 | AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS);
|
---|
631 | AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
|
---|
632 |
|
---|
633 | /* this will back up current data */
|
---|
634 | m->bd.assignCopy(aThat->m->bd);
|
---|
635 |
|
---|
636 | switch (m->bd->architectureType)
|
---|
637 | {
|
---|
638 | case PlatformArchitecture_x86:
|
---|
639 | return mX86->i_copyFrom(aThat->mX86);
|
---|
640 |
|
---|
641 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
642 | case PlatformArchitecture_ARM:
|
---|
643 | return mARM->i_copyFrom(aThat->mARM);
|
---|
644 | #endif
|
---|
645 | case PlatformArchitecture_None:
|
---|
646 | RT_FALL_THROUGH();
|
---|
647 | default:
|
---|
648 | break;
|
---|
649 | }
|
---|
650 |
|
---|
651 | AssertFailedReturnVoid();
|
---|
652 | }
|
---|
653 |
|
---|
654 | /**
|
---|
655 | * Initializes the platform architecture.
|
---|
656 | *
|
---|
657 | * @returns HRESULT
|
---|
658 | * @retval VERR_PLATFORM_ARCH_NOT_SUPPORTED if platform architecture is not supported.
|
---|
659 | * @param aArchitecture Platform architecture to set.
|
---|
660 | *
|
---|
661 | * @note Creates the platform-specific sub object (e.g. x86 or ARM).
|
---|
662 | * Usually only called when creating a new machine or loading settings.
|
---|
663 | */
|
---|
664 | HRESULT Platform::i_initArchitecture(PlatformArchitecture_T aArchitecture, Platform *aThat, bool fCopy /* = false */)
|
---|
665 | {
|
---|
666 | /* sanity */
|
---|
667 | AutoCaller autoCaller(this);
|
---|
668 | AssertComRCReturn(autoCaller.hrc(), autoCaller.hrc());
|
---|
669 |
|
---|
670 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
671 |
|
---|
672 | HRESULT hrc = S_OK;
|
---|
673 |
|
---|
674 | m->bd->architectureType = aArchitecture;
|
---|
675 |
|
---|
676 | /* Currently we only keep the current platform-specific object around,
|
---|
677 | * e.g. we destroy any data for the former architecture (if any). */
|
---|
678 | uninitArchitecture();
|
---|
679 |
|
---|
680 | switch (m->bd->architectureType)
|
---|
681 | {
|
---|
682 | case PlatformArchitecture_x86:
|
---|
683 | {
|
---|
684 | /* Create associated x86-specific platform object. */
|
---|
685 | Assert(mX86.isNull());
|
---|
686 | hrc = unconst(mX86).createObject();
|
---|
687 | ComAssertComRCRetRC(hrc);
|
---|
688 | if (aThat)
|
---|
689 | {
|
---|
690 | if (fCopy)
|
---|
691 | hrc = mX86->initCopy(this, mParent, aThat->mX86);
|
---|
692 | else
|
---|
693 | hrc = mX86->init(this, mParent, aThat->mX86);
|
---|
694 | }
|
---|
695 | else
|
---|
696 | hrc = mX86->init(this, mParent);
|
---|
697 | break;
|
---|
698 | }
|
---|
699 |
|
---|
700 | #ifdef VBOX_WITH_VIRT_ARMV8
|
---|
701 | case PlatformArchitecture_ARM:
|
---|
702 | {
|
---|
703 | /* Create associated ARM-specific platform object. */
|
---|
704 | Assert(mARM.isNull());
|
---|
705 | unconst(mARM).createObject();
|
---|
706 | ComAssertComRCRetRC(hrc);
|
---|
707 | if (aThat)
|
---|
708 | {
|
---|
709 | if (fCopy)
|
---|
710 | hrc = mARM->initCopy(this, mParent, aThat->mARM);
|
---|
711 | else
|
---|
712 | hrc = mARM->init(this, mParent, aThat->mARM);
|
---|
713 | }
|
---|
714 | else
|
---|
715 | hrc = mARM->init(this, mParent);
|
---|
716 | break;
|
---|
717 | }
|
---|
718 | #endif
|
---|
719 | default:
|
---|
720 | AssertFailedStmt(hrc = VBOX_E_PLATFORM_ARCH_NOT_SUPPORTED);
|
---|
721 | break;
|
---|
722 | }
|
---|
723 |
|
---|
724 | if (SUCCEEDED(hrc))
|
---|
725 | LogRel(("Platform architecture set to '%s'\n",
|
---|
726 | aArchitecture == PlatformArchitecture_x86 ? "x86" : "ARM"));
|
---|
727 |
|
---|
728 | return hrc;
|
---|
729 | }
|
---|
730 |
|
---|
731 | HRESULT Platform::i_applyDefaults(GuestOSType *aOsType)
|
---|
732 | {
|
---|
733 | /* sanity */
|
---|
734 | AutoCaller autoCaller(this);
|
---|
735 | AssertComRCReturn(autoCaller.hrc(), autoCaller.hrc());
|
---|
736 |
|
---|
737 | HRESULT hrc = S_OK;
|
---|
738 |
|
---|
739 | ChipsetType_T enmChipsetType;
|
---|
740 | IommuType_T enmIommuType;
|
---|
741 | BOOL fRTCUseUTC;
|
---|
742 |
|
---|
743 | if (aOsType)
|
---|
744 | {
|
---|
745 | hrc = aOsType->COMGETTER(RecommendedChipset)(&enmChipsetType);
|
---|
746 | AssertComRCReturnRC(hrc);
|
---|
747 |
|
---|
748 | hrc = aOsType->COMGETTER(RecommendedIommuType)(&enmIommuType);
|
---|
749 | AssertComRCReturnRC(hrc);
|
---|
750 |
|
---|
751 | hrc = aOsType->COMGETTER(RecommendedRTCUseUTC)(&fRTCUseUTC);
|
---|
752 | AssertComRCReturnRC(hrc);
|
---|
753 | }
|
---|
754 | else
|
---|
755 | {
|
---|
756 | /* No guest OS type object. Pick some plausible defaults which the
|
---|
757 | * host can handle. There's no way to know or validate anything. */
|
---|
758 |
|
---|
759 | /* Note: These are the value we ever had, so default to these. */
|
---|
760 | enmChipsetType = ChipsetType_PIIX3;
|
---|
761 | enmIommuType = IommuType_None;
|
---|
762 | fRTCUseUTC = FALSE;
|
---|
763 |
|
---|
764 | /* The above only holds for x86. */
|
---|
765 | AssertReturn(m->bd->architectureType == PlatformArchitecture_x86,
|
---|
766 | VBOX_E_NOT_SUPPORTED);
|
---|
767 | }
|
---|
768 |
|
---|
769 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
770 |
|
---|
771 | m->bd->chipsetType = enmChipsetType;
|
---|
772 | m->bd->iommuType = enmIommuType;
|
---|
773 | m->bd->fRTCUseUTC = fRTCUseUTC;
|
---|
774 |
|
---|
775 | alock.release();
|
---|
776 |
|
---|
777 | /* Allocates architecture-dependent stuff. */
|
---|
778 | hrc = i_initArchitecture(m->bd->architectureType);
|
---|
779 | AssertComRCReturnRC(hrc);
|
---|
780 |
|
---|
781 | /* Do the same for the platform specifics. */
|
---|
782 | switch (m->bd->architectureType)
|
---|
783 | {
|
---|
784 | case PlatformArchitecture_x86:
|
---|
785 | hrc = mX86->i_applyDefaults(aOsType);
|
---|
786 | break;
|
---|
787 |
|
---|
788 | case PlatformArchitecture_ARM:
|
---|
789 | AssertFailed(); /** @todo BUGBUG Implement this! */
|
---|
790 | break;
|
---|
791 |
|
---|
792 | case PlatformArchitecture_None:
|
---|
793 | RT_FALL_THROUGH();
|
---|
794 | default:
|
---|
795 | hrc = VBOX_E_NOT_SUPPORTED;
|
---|
796 | break;
|
---|
797 | }
|
---|
798 | AssertComRCReturnRC(hrc);
|
---|
799 |
|
---|
800 | /* Sanity. */
|
---|
801 | Assert(enmChipsetType != ChipsetType_Null);
|
---|
802 |
|
---|
803 | return hrc;
|
---|
804 | }
|
---|
805 |
|
---|