summaryrefslogtreecommitdiffstats
path: root/src/VBox/Main/src-server/GuestOSTypeImpl.cpp
blob: 25bfaea851c79a41be43394c074c7349d3d9ad4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/* $Id: GuestOSTypeImpl.cpp $ */
/** @file
 * VirtualBox COM class implementation
 */

/*
 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#define LOG_GROUP LOG_GROUP_MAIN_GUESTOSTYPE
#include "GuestOSTypeImpl.h"
#include "AutoCaller.h"
#include "LoggingNew.h"
#include <iprt/cpp/utils.h>

// constructor / destructor
/////////////////////////////////////////////////////////////////////////////

GuestOSType::GuestOSType()
    : mOSType(VBOXOSTYPE_Unknown)
    , mOSHint(VBOXOSHINT_NONE)
    , mRAMSize(0)
    , mCPUCount(1)
    , mGraphicsControllerType(GraphicsControllerType_Null)
    , mVRAMSize(0)
    , mHDDSize(0)
    , mNetworkAdapterType(NetworkAdapterType_Am79C973)
    , mNumSerialEnabled(0)
    , mDVDStorageControllerType(StorageControllerType_PIIX3)
    , mDVDStorageBusType(StorageBus_IDE)
    , mHDStorageControllerType(StorageControllerType_PIIX3)
    , mHDStorageBusType(StorageBus_IDE)
    , mChipsetType(ChipsetType_PIIX3)
    , mIommuType(IommuType_None)
    , mAudioControllerType(AudioControllerType_AC97)
    , mAudioCodecType(AudioCodecType_STAC9700)
{
}

GuestOSType::~GuestOSType()
{
}

HRESULT GuestOSType::FinalConstruct()
{
    return BaseFinalConstruct();
}

void GuestOSType::FinalRelease()
{
    uninit();

    BaseFinalRelease();
}

// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////

/**
 * Initializes the guest OS type object.
 *
 * @returns COM result indicator
 * @param ostype containing the following parts:
 * @a aFamilyId          os family short name string
 * @a aFamilyDescription os family name string
 * @a aId                os short name string
 * @a aDescription       os name string
 * @a aOSType            global OS type ID
 * @a aOSHint            os configuration hint
 * @a aRAMSize           recommended RAM size in megabytes
 * @a aVRAMSize          recommended video memory size in megabytes
 * @a aHDDSize           recommended HDD size in bytes
 */
HRESULT GuestOSType::init(const Global::OSType &ostype)
{
    ComAssertRet(ostype.familyId && ostype.familyDescription && ostype.id && ostype.description, E_INVALIDARG);

    /* Enclose the state transition NotReady->InInit->Ready */
    AutoInitSpan autoInitSpan(this);
    AssertReturn(autoInitSpan.isOk(), E_FAIL);

    unconst(mFamilyID)                  = ostype.familyId;
    unconst(mFamilyDescription)         = ostype.familyDescription;
    unconst(mID)                        = ostype.id;
    unconst(mDescription)               = ostype.description;
    unconst(mOSType)                    = ostype.osType;
    unconst(mOSHint)                    = ostype.osHint;
    unconst(mRAMSize)                   = ostype.recommendedRAM;
    unconst(mCPUCount)                  = ostype.recommendedCPUCount;
    unconst(mGraphicsControllerType)    = ostype.graphicsControllerType;
    unconst(mVRAMSize)                  = ostype.recommendedVRAM;
    unconst(mHDDSize)                   = ostype.recommendedHDD;
    unconst(mNetworkAdapterType)        = ostype.networkAdapterType;
    unconst(mNumSerialEnabled)          = ostype.numSerialEnabled;
    unconst(mDVDStorageControllerType)  = ostype.dvdStorageControllerType;
    unconst(mDVDStorageBusType)         = ostype.dvdStorageBusType;
    unconst(mHDStorageControllerType)   = ostype.hdStorageControllerType;
    unconst(mHDStorageBusType)          = ostype.hdStorageBusType;
    unconst(mChipsetType)               = ostype.chipsetType;
    unconst(mIommuType)                 = ostype.iommuType;
    unconst(mAudioControllerType)       = ostype.audioControllerType;
    unconst(mAudioCodecType)            = ostype.audioCodecType;

    /* Confirm a successful initialization when it's the case */
    autoInitSpan.setSucceeded();

    return S_OK;
}

/**
 *  Uninitializes the instance and sets the ready flag to FALSE.
 *  Called either from FinalRelease() or by the parent when it gets destroyed.
 */
void GuestOSType::uninit()
{
    /* Enclose the state transition Ready->InUninit->NotReady */
    AutoUninitSpan autoUninitSpan(this);
    if (autoUninitSpan.uninitDone())
        return;
}

// IGuestOSType properties
/////////////////////////////////////////////////////////////////////////////

HRESULT GuestOSType::getFamilyId(com::Utf8Str &aFamilyId)
{
    /* mFamilyID is constant during life time, no need to lock */
    aFamilyId = mFamilyID;
    return S_OK;
}


HRESULT GuestOSType::getFamilyDescription(com::Utf8Str &aFamilyDescription)
{
    /* mFamilyDescription is constant during life time, no need to lock */
    aFamilyDescription = mFamilyDescription;

    return S_OK;
}


HRESULT GuestOSType::getId(com::Utf8Str &aId)
{
    /* mID is constant during life time, no need to lock */
    aId = mID;

    return S_OK;
}


HRESULT GuestOSType::getDescription(com::Utf8Str &aDescription)
{
    /* mDescription is constant during life time, no need to lock */
    aDescription = mDescription;

    return S_OK;
}

HRESULT GuestOSType::getIs64Bit(BOOL *aIs64Bit)
{
    /* mIs64Bit is constant during life time, no need to lock */
    *aIs64Bit = !!(mOSHint & VBOXOSHINT_64BIT);

    return S_OK;
}

HRESULT GuestOSType::getRecommendedIOAPIC(BOOL *aRecommendedIOAPIC)
{
    /* mRecommendedIOAPIC is constant during life time, no need to lock */
    *aRecommendedIOAPIC = !!(mOSHint & VBOXOSHINT_IOAPIC);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedVirtEx(BOOL *aRecommendedVirtEx)
{
    /* mRecommendedVirtEx is constant during life time, no need to lock */
    *aRecommendedVirtEx = !!(mOSHint & VBOXOSHINT_HWVIRTEX);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedRAM(ULONG *aRAMSize)
{
    /* mRAMSize is constant during life time, no need to lock */
    *aRAMSize = mRAMSize;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedGraphicsController(GraphicsControllerType_T *aRecommendedGraphicsController)
{
    /* mGraphicsController is constant during life time, no need to lock */
    *aRecommendedGraphicsController = mGraphicsControllerType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedVRAM(ULONG *aVRAMSize)
{
    /* mVRAMSize is constant during life time, no need to lock */
    *aVRAMSize = mVRAMSize;

    return S_OK;
}


HRESULT GuestOSType::getRecommended2DVideoAcceleration(BOOL *aRecommended2DVideoAcceleration)
{
    /* Constant during life time, no need to lock */
    *aRecommended2DVideoAcceleration = !!(mOSHint & VBOXOSHINT_ACCEL2D);

    return S_OK;
}


HRESULT GuestOSType::getRecommended3DAcceleration(BOOL *aRecommended3DAcceleration)
{
    /* Constant during life time, no need to lock */
    *aRecommended3DAcceleration = !!(mOSHint & VBOXOSHINT_ACCEL3D);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedHDD(LONG64 *aHDDSize)
{
    /* mHDDSize is constant during life time, no need to lock */
    *aHDDSize = (LONG64)mHDDSize;

    return S_OK;
}


HRESULT GuestOSType::getAdapterType(NetworkAdapterType_T *aNetworkAdapterType)
{
    /* mNetworkAdapterType is constant during life time, no need to lock */
    *aNetworkAdapterType = mNetworkAdapterType;

    return S_OK;
}

HRESULT GuestOSType::getRecommendedPAE(BOOL *aRecommendedPAE)
{
    /* recommended PAE is constant during life time, no need to lock */
    *aRecommendedPAE = !!(mOSHint & VBOXOSHINT_PAE);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedFirmware(FirmwareType_T *aFirmwareType)
{
    /* firmware type is constant during life time, no need to lock */
    if (mOSHint & VBOXOSHINT_EFI)
        *aFirmwareType = FirmwareType_EFI;
    else
        *aFirmwareType = FirmwareType_BIOS;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedDVDStorageController(StorageControllerType_T *aStorageControllerType)
{
    /* storage controller type is constant during life time, no need to lock */
    *aStorageControllerType = mDVDStorageControllerType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedDVDStorageBus(StorageBus_T *aStorageBusType)
{
    /* storage controller type is constant during life time, no need to lock */
    *aStorageBusType = mDVDStorageBusType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedHDStorageController(StorageControllerType_T *aStorageControllerType)
{
    /* storage controller type is constant during life time, no need to lock */
    *aStorageControllerType = mHDStorageControllerType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedHDStorageBus(StorageBus_T *aStorageBusType)
{
    /* storage controller type is constant during life time, no need to lock */
    *aStorageBusType = mHDStorageBusType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedUSBHID(BOOL *aRecommendedUSBHID)
{
    /* HID type is constant during life time, no need to lock */
    *aRecommendedUSBHID = !!(mOSHint & VBOXOSHINT_USBHID);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedHPET(BOOL *aRecommendedHPET)
{
    /* HPET recommendation is constant during life time, no need to lock */
    *aRecommendedHPET = !!(mOSHint & VBOXOSHINT_HPET);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedUSBTablet(BOOL *aRecommendedUSBTablet)
{
    /* HID type is constant during life time, no need to lock */
    *aRecommendedUSBTablet = !!(mOSHint & VBOXOSHINT_USBTABLET);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedRTCUseUTC(BOOL *aRecommendedRTCUseUTC)
{
    /* Value is constant during life time, no need to lock */
    *aRecommendedRTCUseUTC = !!(mOSHint & VBOXOSHINT_RTCUTC);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedChipset(ChipsetType_T *aChipsetType)
{
    /* chipset type is constant during life time, no need to lock */
    *aChipsetType = mChipsetType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedIommuType(IommuType_T *aIommuType)
{
    /* IOMMU type is constant during life time, no need to lock */
    *aIommuType = mIommuType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedAudioController(AudioControllerType_T *aAudioController)
{
    *aAudioController = mAudioControllerType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedAudioCodec(AudioCodecType_T *aAudioCodec)
{
    *aAudioCodec = mAudioCodecType;

    return S_OK;
}


HRESULT GuestOSType::getRecommendedFloppy(BOOL *aRecommendedFloppy)
{
    /* Value is constant during life time, no need to lock */
    *aRecommendedFloppy = !!(mOSHint & VBOXOSHINT_FLOPPY);

    return S_OK;
}


HRESULT GuestOSType::getRecommendedUSB(BOOL *aRecommendedUSB)
{
    /* Value is constant during life time, no need to lock */
    *aRecommendedUSB = !(mOSHint & VBOXOSHINT_NOUSB);

    return S_OK;
}

HRESULT GuestOSType::getRecommendedUSB3(BOOL *aRecommendedUSB3)
{
    /* Value is constant during life time, no need to lock */
    *aRecommendedUSB3 = !!(mOSHint & VBOXOSHINT_USB3);

    return S_OK;
}

HRESULT GuestOSType::getRecommendedTFReset(BOOL *aRecommendedTFReset)
{
    /* recommended triple fault behavior is constant during life time, no need to lock */
    *aRecommendedTFReset = !!(mOSHint & VBOXOSHINT_TFRESET);

    return S_OK;
}

HRESULT GuestOSType::getRecommendedX2APIC(BOOL *aRecommendedX2APIC)
{
    /* mRecommendedX2APIC is constant during life time, no need to lock */
    *aRecommendedX2APIC = !!(mOSHint & VBOXOSHINT_X2APIC);

    return S_OK;
}

HRESULT GuestOSType::getRecommendedCPUCount(ULONG *aRecommendedCPUCount)
{
    /* mCPUCount is constant during life time, no need to lock */
    *aRecommendedCPUCount = mCPUCount;

    return S_OK;
}

HRESULT GuestOSType::getRecommendedTpmType(TpmType_T *aRecommendedTpmType)
{
    /* Value is constant during life time, no need to lock */
    if (mOSHint & VBOXOSHINT_TPM2)
        *aRecommendedTpmType = TpmType_v2_0;
    else if (mOSHint & VBOXOSHINT_TPM)
        *aRecommendedTpmType = TpmType_v1_2;
    else
        *aRecommendedTpmType = TpmType_None;

    return S_OK;
}

HRESULT GuestOSType::getRecommendedSecureBoot(BOOL *aRecommendedSecureBoot)
{
    /* Value is constant during life time, no need to lock */
    *aRecommendedSecureBoot = !!(mOSHint & VBOXOSHINT_EFI_SECUREBOOT);

    return S_OK;
}

HRESULT GuestOSType::getRecommendedWDDMGraphics(BOOL *aRecommendedWDDMGraphics)
{
    /* Value is constant during life time, no need to lock */
    *aRecommendedWDDMGraphics = !!(mOSHint & VBOXOSHINT_WDDM_GRAPHICS);

    return S_OK;
}

/* vi: set tabstop=4 shiftwidth=4 expandtab: */