VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/BIOSSettingsImpl.cpp@ 90828

Last change on this file since 90828 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
1/* $Id: BIOSSettingsImpl.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation - Machine BIOS settings.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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#define LOG_GROUP LOG_GROUP_MAIN_BIOSSETTINGS
19#include "BIOSSettingsImpl.h"
20#include "MachineImpl.h"
21#include "GuestOSTypeImpl.h"
22
23#include <iprt/cpp/utils.h>
24#include <VBox/settings.h>
25
26#include "AutoStateDep.h"
27#include "AutoCaller.h"
28#include "LoggingNew.h"
29
30
31////////////////////////////////////////////////////////////////////////////////
32//
33// BIOSSettings private data definition
34//
35////////////////////////////////////////////////////////////////////////////////
36
37struct BIOSSettings::Data
38{
39 Data()
40 : pMachine(NULL)
41 { }
42
43 Machine * const pMachine;
44 ComObjPtr<BIOSSettings> pPeer;
45
46 // use the XML settings structure in the members for simplicity
47 Backupable<settings::BIOSSettings> bd;
48};
49
50// constructor / destructor
51/////////////////////////////////////////////////////////////////////////////
52
53DEFINE_EMPTY_CTOR_DTOR(BIOSSettings)
54
55HRESULT BIOSSettings::FinalConstruct()
56{
57 return BaseFinalConstruct();
58}
59
60void BIOSSettings::FinalRelease()
61{
62 uninit();
63 BaseFinalRelease();
64}
65
66// public initializer/uninitializer for internal purposes only
67/////////////////////////////////////////////////////////////////////////////
68
69/**
70 * Initializes the BIOS settings object.
71 *
72 * @returns COM result indicator
73 */
74HRESULT BIOSSettings::init(Machine *aParent)
75{
76 LogFlowThisFuncEnter();
77 LogFlowThisFunc(("aParent: %p\n", aParent));
78
79 ComAssertRet(aParent, E_INVALIDARG);
80
81 /* Enclose the state transition NotReady->InInit->Ready */
82 AutoInitSpan autoInitSpan(this);
83 AssertReturn(autoInitSpan.isOk(), E_FAIL);
84
85 m = new Data();
86
87 /* share the parent weakly */
88 unconst(m->pMachine) = aParent;
89
90 m->bd.allocate();
91
92 autoInitSpan.setSucceeded();
93
94 LogFlowThisFuncLeave();
95 return S_OK;
96}
97
98/**
99 * Initializes the BIOS settings object given another BIOS settings object
100 * (a kind of copy constructor). This object shares data with
101 * the object passed as an argument.
102 *
103 * @note This object must be destroyed before the original object
104 * it shares data with is destroyed.
105 */
106HRESULT BIOSSettings::init(Machine *aParent, BIOSSettings *that)
107{
108 LogFlowThisFuncEnter();
109 LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
110
111 ComAssertRet(aParent && that, E_INVALIDARG);
112
113 /* Enclose the state transition NotReady->InInit->Ready */
114 AutoInitSpan autoInitSpan(this);
115 AssertReturn(autoInitSpan.isOk(), E_FAIL);
116
117 m = new Data();
118
119 unconst(m->pMachine) = aParent;
120 m->pPeer = that;
121
122 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
123 m->bd.share(that->m->bd);
124
125 autoInitSpan.setSucceeded();
126
127 LogFlowThisFuncLeave();
128 return S_OK;
129}
130
131/**
132 * Initializes the guest object given another guest object
133 * (a kind of copy constructor). This object makes a private copy of data
134 * of the original object passed as an argument.
135 */
136HRESULT BIOSSettings::initCopy(Machine *aParent, BIOSSettings *that)
137{
138 LogFlowThisFuncEnter();
139 LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
140
141 ComAssertRet(aParent && that, E_INVALIDARG);
142
143 /* Enclose the state transition NotReady->InInit->Ready */
144 AutoInitSpan autoInitSpan(this);
145 AssertReturn(autoInitSpan.isOk(), E_FAIL);
146
147 m = new Data();
148
149 unconst(m->pMachine) = aParent;
150 // mPeer is left null
151
152 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
153 m->bd.attachCopy(that->m->bd);
154
155 // Intentionally "forget" the NVRAM file since it must be unique and set
156 // to the correct value before the copy of the settings makes sense.
157 m->bd->strNVRAMPath.setNull();
158
159 autoInitSpan.setSucceeded();
160
161 LogFlowThisFuncLeave();
162 return S_OK;
163}
164
165/**
166 * Uninitializes the instance and sets the ready flag to FALSE.
167 * Called either from FinalRelease() or by the parent when it gets destroyed.
168 */
169void BIOSSettings::uninit()
170{
171 LogFlowThisFuncEnter();
172
173 /* Enclose the state transition Ready->InUninit->NotReady */
174 AutoUninitSpan autoUninitSpan(this);
175 if (autoUninitSpan.uninitDone())
176 return;
177
178 m->bd.free();
179
180 unconst(m->pPeer) = NULL;
181 unconst(m->pMachine) = NULL;
182
183 delete m;
184 m = NULL;
185
186 LogFlowThisFuncLeave();
187}
188
189// IBIOSSettings properties
190/////////////////////////////////////////////////////////////////////////////
191
192
193HRESULT BIOSSettings::getLogoFadeIn(BOOL *enabled)
194{
195 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
196
197 *enabled = m->bd->fLogoFadeIn;
198
199 return S_OK;
200}
201
202HRESULT BIOSSettings::setLogoFadeIn(BOOL enable)
203{
204 /* the machine needs to be mutable */
205 AutoMutableStateDependency adep(m->pMachine);
206 if (FAILED(adep.rc())) return adep.rc();
207
208 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
209
210 m->bd.backup();
211 m->bd->fLogoFadeIn = RT_BOOL(enable);
212
213 alock.release();
214 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
215 m->pMachine->i_setModified(Machine::IsModified_BIOS);
216
217 return S_OK;
218}
219
220
221HRESULT BIOSSettings::getLogoFadeOut(BOOL *enabled)
222{
223 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
224
225 *enabled = m->bd->fLogoFadeOut;
226
227 return S_OK;
228}
229
230HRESULT BIOSSettings::setLogoFadeOut(BOOL enable)
231{
232 /* the machine needs to be mutable */
233 AutoMutableStateDependency adep(m->pMachine);
234 if (FAILED(adep.rc())) return adep.rc();
235
236 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
237
238 m->bd.backup();
239 m->bd->fLogoFadeOut = RT_BOOL(enable);
240
241 alock.release();
242 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
243 m->pMachine->i_setModified(Machine::IsModified_BIOS);
244
245 return S_OK;
246}
247
248
249HRESULT BIOSSettings::getLogoDisplayTime(ULONG *displayTime)
250{
251 if (!displayTime)
252 return E_POINTER;
253
254 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
255
256 *displayTime = m->bd->ulLogoDisplayTime;
257
258 return S_OK;
259}
260
261HRESULT BIOSSettings::setLogoDisplayTime(ULONG displayTime)
262{
263 /* the machine needs to be mutable */
264 AutoMutableStateDependency adep(m->pMachine);
265 if (FAILED(adep.rc())) return adep.rc();
266
267 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
268
269 m->bd.backup();
270 m->bd->ulLogoDisplayTime = displayTime;
271
272 alock.release();
273 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
274 m->pMachine->i_setModified(Machine::IsModified_BIOS);
275
276 return S_OK;
277}
278
279
280HRESULT BIOSSettings::getLogoImagePath(com::Utf8Str &imagePath)
281{
282 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
283
284 imagePath = m->bd->strLogoImagePath;
285 return S_OK;
286}
287
288HRESULT BIOSSettings::setLogoImagePath(const com::Utf8Str &imagePath)
289{
290 /* the machine needs to be mutable */
291 AutoMutableStateDependency adep(m->pMachine);
292 if (FAILED(adep.rc())) return adep.rc();
293
294 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
295
296 m->bd.backup();
297 m->bd->strLogoImagePath = imagePath;
298
299 alock.release();
300 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
301 m->pMachine->i_setModified(Machine::IsModified_BIOS);
302
303 return S_OK;
304}
305
306HRESULT BIOSSettings::getBootMenuMode(BIOSBootMenuMode_T *bootMenuMode)
307{
308 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
309
310 *bootMenuMode = m->bd->biosBootMenuMode;
311 return S_OK;
312}
313
314HRESULT BIOSSettings::setBootMenuMode(BIOSBootMenuMode_T bootMenuMode)
315{
316 /* the machine needs to be mutable */
317 AutoMutableStateDependency adep(m->pMachine);
318 if (FAILED(adep.rc())) return adep.rc();
319
320 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
321
322 m->bd.backup();
323 m->bd->biosBootMenuMode = bootMenuMode;
324
325 alock.release();
326 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
327 m->pMachine->i_setModified(Machine::IsModified_BIOS);
328
329 return S_OK;
330}
331
332
333HRESULT BIOSSettings::getACPIEnabled(BOOL *enabled)
334{
335 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
336
337 *enabled = m->bd->fACPIEnabled;
338
339 return S_OK;
340}
341
342HRESULT BIOSSettings::setACPIEnabled(BOOL enable)
343{
344 /* the machine needs to be mutable */
345 AutoMutableStateDependency adep(m->pMachine);
346 if (FAILED(adep.rc())) return adep.rc();
347
348 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
349
350 m->bd.backup();
351 m->bd->fACPIEnabled = RT_BOOL(enable);
352
353 alock.release();
354 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
355 m->pMachine->i_setModified(Machine::IsModified_BIOS);
356
357 return S_OK;
358}
359
360
361HRESULT BIOSSettings::getIOAPICEnabled(BOOL *aIOAPICEnabled)
362{
363 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
364
365 *aIOAPICEnabled = m->bd->fIOAPICEnabled;
366
367 return S_OK;
368}
369
370HRESULT BIOSSettings::setIOAPICEnabled(BOOL aIOAPICEnabled)
371{
372 /* the machine needs to be mutable */
373 AutoMutableStateDependency adep(m->pMachine);
374 if (FAILED(adep.rc())) return adep.rc();
375
376 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
377
378 m->bd.backup();
379 m->bd->fIOAPICEnabled = RT_BOOL(aIOAPICEnabled);
380
381 alock.release();
382 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
383 m->pMachine->i_setModified(Machine::IsModified_BIOS);
384
385 return S_OK;
386}
387
388
389HRESULT BIOSSettings::getAPICMode(APICMode_T *aAPICMode)
390{
391 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
392
393 *aAPICMode = m->bd->apicMode;
394
395 return S_OK;
396}
397
398HRESULT BIOSSettings::setAPICMode(APICMode_T aAPICMode)
399{
400 /* the machine needs to be mutable */
401 AutoMutableStateDependency adep(m->pMachine);
402 if (FAILED(adep.rc())) return adep.rc();
403
404 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
405
406 m->bd.backup();
407 m->bd->apicMode = aAPICMode;
408
409 alock.release();
410 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
411 m->pMachine->i_setModified(Machine::IsModified_BIOS);
412
413 return S_OK;
414}
415
416
417HRESULT BIOSSettings::getPXEDebugEnabled(BOOL *enabled)
418{
419 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
420
421 *enabled = m->bd->fPXEDebugEnabled;
422
423 return S_OK;
424}
425
426HRESULT BIOSSettings::setPXEDebugEnabled(BOOL enable)
427{
428 /* the machine needs to be mutable */
429 AutoMutableStateDependency adep(m->pMachine);
430 if (FAILED(adep.rc())) return adep.rc();
431
432 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
433
434 m->bd.backup();
435 m->bd->fPXEDebugEnabled = RT_BOOL(enable);
436
437 alock.release();
438 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
439 m->pMachine->i_setModified(Machine::IsModified_BIOS);
440
441 return S_OK;
442}
443
444
445HRESULT BIOSSettings::getTimeOffset(LONG64 *offset)
446{
447 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
448
449 *offset = m->bd->llTimeOffset;
450
451 return S_OK;
452}
453
454HRESULT BIOSSettings::setTimeOffset(LONG64 offset)
455{
456 /* the machine needs to be mutable */
457 AutoMutableStateDependency adep(m->pMachine);
458 if (FAILED(adep.rc())) return adep.rc();
459
460 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
461
462 m->bd.backup();
463 m->bd->llTimeOffset = offset;
464
465 alock.release();
466 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
467 m->pMachine->i_setModified(Machine::IsModified_BIOS);
468
469 return S_OK;
470}
471
472
473HRESULT BIOSSettings::getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile)
474{
475 Utf8Str strTmp;
476 {
477 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
478 strTmp = m->bd->strNVRAMPath;
479 }
480
481 AutoReadLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
482 if (strTmp.isEmpty())
483 strTmp = m->pMachine->i_getDefaultNVRAMFilename();
484 if (strTmp.isNotEmpty())
485 m->pMachine->i_calculateFullPath(strTmp, aNonVolatileStorageFile);
486
487 return S_OK;
488}
489
490
491HRESULT BIOSSettings::getSMBIOSUuidLittleEndian(BOOL *enabled)
492{
493 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
494
495 *enabled = m->bd->fSmbiosUuidLittleEndian;
496
497 return S_OK;
498}
499
500HRESULT BIOSSettings::setSMBIOSUuidLittleEndian(BOOL enable)
501{
502 /* the machine needs to be mutable */
503 AutoMutableStateDependency adep(m->pMachine);
504 if (FAILED(adep.rc())) return adep.rc();
505
506 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
507
508 m->bd.backup();
509 m->bd->fSmbiosUuidLittleEndian = RT_BOOL(enable);
510
511 alock.release();
512 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
513 m->pMachine->i_setModified(Machine::IsModified_BIOS);
514
515 return S_OK;
516}
517
518
519// IBIOSSettings methods
520/////////////////////////////////////////////////////////////////////////////
521
522// public methods only for internal purposes
523/////////////////////////////////////////////////////////////////////////////
524
525/**
526 * Loads settings from the given machine node.
527 * May be called once right after this object creation.
528 *
529 * @param data Configuration settings.
530 *
531 * @note Locks this object for writing.
532 */
533HRESULT BIOSSettings::i_loadSettings(const settings::BIOSSettings &data)
534{
535 AutoCaller autoCaller(this);
536 AssertComRCReturnRC(autoCaller.rc());
537
538 AutoReadLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
539 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
540
541 // simply copy
542 m->bd.assignCopy(&data);
543
544 Utf8Str strTmp(m->bd->strNVRAMPath);
545 if (strTmp.isNotEmpty())
546 m->pMachine->i_copyPathRelativeToMachine(strTmp, m->bd->strNVRAMPath);
547 if ( m->pMachine->i_getFirmwareType() == FirmwareType_BIOS
548 || m->bd->strNVRAMPath == m->pMachine->i_getDefaultNVRAMFilename())
549 m->bd->strNVRAMPath.setNull();
550
551 return S_OK;
552}
553
554/**
555 * Saves settings to the given machine node.
556 *
557 * @param data Configuration settings.
558 *
559 * @note Locks this object for reading.
560 */
561HRESULT BIOSSettings::i_saveSettings(settings::BIOSSettings &data)
562{
563 AutoCaller autoCaller(this);
564 AssertComRCReturnRC(autoCaller.rc());
565
566 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
567
568 data = *m->bd.data();
569
570 return S_OK;
571}
572
573void BIOSSettings::i_rollback()
574{
575 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
576 m->bd.rollback();
577}
578
579void BIOSSettings::i_commit()
580{
581 /* sanity */
582 AutoCaller autoCaller(this);
583 AssertComRCReturnVoid(autoCaller.rc());
584
585 /* sanity too */
586 AutoCaller peerCaller(m->pPeer);
587 AssertComRCReturnVoid(peerCaller.rc());
588
589 /* lock both for writing since we modify both (mPeer is "master" so locked
590 * first) */
591 AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS);
592
593 if (m->bd.isBackedUp())
594 {
595 m->bd.commit();
596 if (m->pPeer)
597 {
598 /* attach new data to the peer and reshare it */
599 AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);
600 m->pPeer->m->bd.attach(m->bd);
601 }
602 }
603}
604
605void BIOSSettings::i_copyFrom(BIOSSettings *aThat)
606{
607 AssertReturnVoid(aThat != NULL);
608
609 /* sanity */
610 AutoCaller autoCaller(this);
611 AssertComRCReturnVoid(autoCaller.rc());
612
613 /* sanity too */
614 AutoCaller thatCaller(aThat);
615 AssertComRCReturnVoid(thatCaller.rc());
616
617 /* peer is not modified, lock it for reading (aThat is "master" so locked
618 * first) */
619 AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS);
620 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
621
622 /* this will back up current data */
623 m->bd.assignCopy(aThat->m->bd);
624
625 // Intentionally "forget" the NVRAM file since it must be unique and set
626 // to the correct value before the copy of the settings makes sense.
627 m->bd->strNVRAMPath.setNull();
628
629}
630
631void BIOSSettings::i_applyDefaults(GuestOSType *aOsType)
632{
633 /* sanity */
634 AutoCaller autoCaller(this);
635 AssertComRCReturnVoid(autoCaller.rc());
636
637 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
638
639 /* Initialize default BIOS settings here */
640 if (aOsType)
641 m->bd->fIOAPICEnabled = aOsType->i_recommendedIOAPIC();
642 else
643 m->bd->fIOAPICEnabled = true;
644}
645
646Utf8Str BIOSSettings::i_getNonVolatileStorageFile()
647{
648 AutoCaller autoCaller(this);
649 AssertComRCReturn(autoCaller.rc(), Utf8Str::Empty);
650
651 Utf8Str strTmp;
652 BIOSSettings::getNonVolatileStorageFile(strTmp);
653 return strTmp;
654}
655
656void BIOSSettings::i_updateNonVolatileStorageFile(const Utf8Str &aNonVolatileStorageFile)
657{
658 /* sanity */
659 AutoCaller autoCaller(this);
660 AssertComRCReturnVoid(autoCaller.rc());
661
662 AutoReadLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
663 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
664
665 Utf8Str strTmp(aNonVolatileStorageFile);
666 if (strTmp == m->pMachine->i_getDefaultNVRAMFilename())
667 strTmp.setNull();
668
669 if (strTmp == m->bd->strNVRAMPath)
670 return;
671
672 m->bd.backup();
673 m->bd->strNVRAMPath = strTmp;
674}
675
676/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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