VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/ConsoleImplConfigX86.cpp@ 101468

Last change on this file since 101468 was 101468, checked in by vboxsync, 19 months ago

Main: Allow running x86 VMs (via IEM) on ARM hosts again. Running ARM VMs on x86 is not supported though. bugref:10384

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 100.4 KB
Line 
1/* $Id: ConsoleImplConfigX86.cpp 101468 2023-10-17 10:13:30Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation - VM Configuration Bits.
4 *
5 * @remark We've split out the code that the 64-bit VC++ v8 compiler finds
6 * problematic to optimize so we can disable optimizations and later,
7 * perhaps, find a real solution for it (like rewriting the code and
8 * to stop resemble a tonne of spaghetti).
9 */
10
11/*
12 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
13 *
14 * This file is part of VirtualBox base platform packages, as
15 * available from https://www.215389.xyz.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation, in version 3 of the
20 * License.
21 *
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, see <https://www.gnu.org/licenses>.
29 *
30 * SPDX-License-Identifier: GPL-3.0-only
31 */
32
33
34/*********************************************************************************************************************************
35* Header Files *
36*********************************************************************************************************************************/
37#define LOG_GROUP LOG_GROUP_MAIN_CONSOLE
38#include "LoggingNew.h"
39
40// VBoxNetCfg-win.h needs winsock2.h and thus MUST be included before any other
41// header file includes Windows.h.
42#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
43# include <VBox/VBoxNetCfg-win.h>
44#endif
45
46#include "ConsoleImpl.h"
47#include "DisplayImpl.h"
48#include "NvramStoreImpl.h"
49#include "PlatformImpl.h"
50#include "VMMDev.h"
51#include "Global.h"
52#ifdef VBOX_WITH_PCI_PASSTHROUGH
53# include "PCIRawDevImpl.h"
54#endif
55
56// generated header
57#include "SchemaDefs.h"
58
59#include "AutoCaller.h"
60
61#include <iprt/base64.h>
62#include <iprt/buildconfig.h>
63#include <iprt/ctype.h>
64#include <iprt/dir.h>
65#include <iprt/file.h>
66#include <iprt/param.h>
67#include <iprt/path.h>
68#include <iprt/string.h>
69#include <iprt/system.h>
70#if 0 /* enable to play with lots of memory. */
71# include <iprt/env.h>
72#endif
73#include <iprt/stream.h>
74
75#include <iprt/http.h>
76#include <iprt/socket.h>
77#include <iprt/uri.h>
78
79#include <VBox/vmm/vmmr3vtable.h>
80#include <VBox/vmm/vmapi.h>
81#include <VBox/err.h>
82#include <VBox/param.h>
83#include <VBox/settings.h> /* For MachineConfigFile::getHostDefaultAudioDriver(). */
84#include <VBox/vmm/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach. */
85#include <VBox/vmm/pdmusb.h> /* For PDMR3UsbCreateEmulatedDevice. */
86#include <VBox/vmm/pdmdev.h> /* For PDMAPICMODE enum. */
87#include <VBox/vmm/pdmstorageifs.h>
88#include <VBox/vmm/gcm.h>
89#include <VBox/version.h>
90#ifdef VBOX_WITH_GUEST_PROPS
91# include <VBox/HostServices/GuestPropertySvc.h>
92# include <VBox/com/defs.h>
93# include <VBox/com/array.h>
94# include <vector>
95#endif /* VBOX_WITH_GUEST_PROPS */
96#include <VBox/intnet.h>
97
98#include <VBox/com/com.h>
99#include <VBox/com/string.h>
100#include <VBox/com/array.h>
101
102#ifdef VBOX_WITH_NETFLT
103# if defined(RT_OS_SOLARIS)
104# include <zone.h>
105# elif defined(RT_OS_LINUX)
106# include <unistd.h>
107# include <sys/ioctl.h>
108# include <sys/socket.h>
109# include <linux/types.h>
110# include <linux/if.h>
111# elif defined(RT_OS_FREEBSD)
112# include <unistd.h>
113# include <sys/types.h>
114# include <sys/ioctl.h>
115# include <sys/socket.h>
116# include <net/if.h>
117# include <net80211/ieee80211_ioctl.h>
118# endif
119# if defined(RT_OS_WINDOWS)
120# include <iprt/win/ntddndis.h>
121# include <devguid.h>
122# else
123# include <HostNetworkInterfaceImpl.h>
124# include <netif.h>
125# include <stdlib.h>
126# endif
127#endif /* VBOX_WITH_NETFLT */
128
129#ifdef VBOX_WITH_AUDIO_VRDE
130# include "DrvAudioVRDE.h"
131#endif
132#ifdef VBOX_WITH_AUDIO_RECORDING
133# include "DrvAudioRec.h"
134#endif
135#include "NetworkServiceRunner.h"
136#include "BusAssignmentManager.h"
137#ifdef VBOX_WITH_EXTPACK
138# include "ExtPackManagerImpl.h"
139#endif
140
141
142/*********************************************************************************************************************************
143* Internal Functions *
144*********************************************************************************************************************************/
145
146/* Darwin compile kludge */
147#undef PVM
148
149/* Comment out the following line to remove VMWare compatibility hack. */
150#define VMWARE_NET_IN_SLOT_11
151
152/**
153 * Simple class for storing network boot information.
154 */
155struct BootNic
156{
157 ULONG mInstance;
158 PCIBusAddress mPCIAddress;
159
160 ULONG mBootPrio;
161 bool operator < (const BootNic &rhs) const
162 {
163 ULONG lval = mBootPrio - 1; /* 0 will wrap around and get the lowest priority. */
164 ULONG rval = rhs.mBootPrio - 1;
165 return lval < rval; /* Zero compares as highest number (lowest prio). */
166 }
167};
168
169/**
170 * @throws HRESULT on extra data retrival error.
171 */
172static int getSmcDeviceKey(IVirtualBox *pVirtualBox, IMachine *pMachine, Utf8Str *pStrKey, bool *pfGetKeyFromRealSMC)
173{
174 *pfGetKeyFromRealSMC = false;
175
176 /*
177 * The extra data takes precedence (if non-zero).
178 */
179 GetExtraDataBoth(pVirtualBox, pMachine, "VBoxInternal2/SmcDeviceKey", pStrKey);
180 if (pStrKey->isNotEmpty())
181 return VINF_SUCCESS;
182
183#ifdef RT_OS_DARWIN
184
185 /*
186 * Work done in EFI/DevSmc
187 */
188 *pfGetKeyFromRealSMC = true;
189 int vrc = VINF_SUCCESS;
190
191#else
192 /*
193 * Is it apple hardware in bootcamp?
194 */
195 /** @todo implement + test RTSYSDMISTR_MANUFACTURER on all hosts.
196 * Currently falling back on the product name. */
197 char szManufacturer[256];
198 szManufacturer[0] = '\0';
199 RTSystemQueryDmiString(RTSYSDMISTR_MANUFACTURER, szManufacturer, sizeof(szManufacturer));
200 if (szManufacturer[0] != '\0')
201 {
202 if ( !strcmp(szManufacturer, "Apple Computer, Inc.")
203 || !strcmp(szManufacturer, "Apple Inc.")
204 )
205 *pfGetKeyFromRealSMC = true;
206 }
207 else
208 {
209 char szProdName[256];
210 szProdName[0] = '\0';
211 RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szProdName, sizeof(szProdName));
212 if ( ( !strncmp(szProdName, RT_STR_TUPLE("Mac"))
213 || !strncmp(szProdName, RT_STR_TUPLE("iMac"))
214 || !strncmp(szProdName, RT_STR_TUPLE("Xserve"))
215 )
216 && !strchr(szProdName, ' ') /* no spaces */
217 && RT_C_IS_DIGIT(szProdName[strlen(szProdName) - 1]) /* version number */
218 )
219 *pfGetKeyFromRealSMC = true;
220 }
221
222 int vrc = VINF_SUCCESS;
223#endif
224
225 return vrc;
226}
227
228
229/*
230 * VC++ 8 / amd64 has some serious trouble with the next functions.
231 * As a temporary measure, we'll drop global optimizations.
232 */
233#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
234# if _MSC_VER >= RT_MSC_VER_VC80 && _MSC_VER < RT_MSC_VER_VC100
235# pragma optimize("g", off)
236# endif
237#endif
238
239/** Helper that finds out the next HBA port used
240 */
241static LONG GetNextUsedPort(LONG aPortUsed[30], LONG lBaseVal, uint32_t u32Size)
242{
243 LONG lNextPortUsed = 30;
244 for (size_t j = 0; j < u32Size; ++j)
245 {
246 if ( aPortUsed[j] > lBaseVal
247 && aPortUsed[j] <= lNextPortUsed)
248 lNextPortUsed = aPortUsed[j];
249 }
250 return lNextPortUsed;
251}
252
253#define MAX_BIOS_LUN_COUNT 4
254
255int Console::SetBiosDiskInfo(ComPtr<IMachine> pMachine, PCFGMNODE pCfg, PCFGMNODE pBiosCfg,
256 Bstr controllerName, const char * const s_apszBiosConfig[4])
257{
258 RT_NOREF(pCfg);
259 HRESULT hrc;
260#define MAX_DEVICES 30
261#define H() AssertLogRelMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR)
262#define VRC() AssertLogRelMsgReturn(RT_SUCCESS(vrc), ("vrc=%Rrc\n", vrc), vrc)
263
264 LONG lPortLUN[MAX_BIOS_LUN_COUNT];
265 LONG lPortUsed[MAX_DEVICES];
266 uint32_t u32HDCount = 0;
267
268 /* init to max value */
269 lPortLUN[0] = MAX_DEVICES;
270
271 com::SafeIfaceArray<IMediumAttachment> atts;
272 hrc = pMachine->GetMediumAttachmentsOfController(controllerName.raw(),
273 ComSafeArrayAsOutParam(atts)); H();
274 size_t uNumAttachments = atts.size();
275 if (uNumAttachments > MAX_DEVICES)
276 {
277 LogRel(("Number of Attachments > Max=%d.\n", uNumAttachments));
278 uNumAttachments = MAX_DEVICES;
279 }
280
281 /* Find the relevant ports/IDs, i.e the ones to which a HD is attached. */
282 for (size_t j = 0; j < uNumAttachments; ++j)
283 {
284 IMediumAttachment *pMediumAtt = atts[j];
285 LONG lPortNum = 0;
286 hrc = pMediumAtt->COMGETTER(Port)(&lPortNum); H();
287 if (SUCCEEDED(hrc))
288 {
289 DeviceType_T lType;
290 hrc = pMediumAtt->COMGETTER(Type)(&lType); H();
291 if (SUCCEEDED(hrc) && lType == DeviceType_HardDisk)
292 {
293 /* find min port number used for HD */
294 if (lPortNum < lPortLUN[0])
295 lPortLUN[0] = lPortNum;
296 lPortUsed[u32HDCount++] = lPortNum;
297 LogFlowFunc(("HD port Count=%d\n", u32HDCount));
298 }
299 }
300 }
301
302
303 /* Pick only the top 4 used HD Ports as CMOS doesn't have space
304 * to save details for all 30 ports
305 */
306 uint32_t u32MaxPortCount = MAX_BIOS_LUN_COUNT;
307 if (u32HDCount < MAX_BIOS_LUN_COUNT)
308 u32MaxPortCount = u32HDCount;
309 for (size_t j = 1; j < u32MaxPortCount; j++)
310 lPortLUN[j] = GetNextUsedPort(lPortUsed, lPortLUN[j-1], u32HDCount);
311 if (pBiosCfg)
312 {
313 for (size_t j = 0; j < u32MaxPortCount; j++)
314 {
315 InsertConfigInteger(pBiosCfg, s_apszBiosConfig[j], lPortLUN[j]);
316 LogFlowFunc(("Top %d HBA ports = %s, %d\n", j, s_apszBiosConfig[j], lPortLUN[j]));
317 }
318 }
319 return VINF_SUCCESS;
320}
321
322#ifdef VBOX_WITH_PCI_PASSTHROUGH
323HRESULT Console::i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *pBusMgr, PCFGMNODE pDevices)
324{
325# ifndef VBOX_WITH_EXTPACK
326 RT_NOREF(pUVM);
327# endif
328 HRESULT hrc = S_OK;
329 PCFGMNODE pInst, pCfg, pLunL0, pLunL1;
330
331 SafeIfaceArray<IPCIDeviceAttachment> assignments;
332 ComPtr<IMachine> aMachine = i_machine();
333
334 hrc = aMachine->COMGETTER(PCIDeviceAssignments)(ComSafeArrayAsOutParam(assignments));
335 if ( hrc != S_OK
336 || assignments.size() < 1)
337 return hrc;
338
339 /*
340 * PCI passthrough is only available if the proper ExtPack is installed.
341 *
342 * Note. Configuring PCI passthrough here and providing messages about
343 * the missing extpack isn't exactly clean, but it is a necessary evil
344 * to patch over legacy compatability issues introduced by the new
345 * distribution model.
346 */
347# ifdef VBOX_WITH_EXTPACK
348 static const char *s_pszPCIRawExtPackName = "Oracle VM VirtualBox Extension Pack";
349 if (!mptrExtPackManager->i_isExtPackUsable(s_pszPCIRawExtPackName))
350 /* Always fatal! */
351 return pVMM->pfnVMR3SetError(pUVM, VERR_NOT_FOUND, RT_SRC_POS,
352 N_("Implementation of the PCI passthrough framework not found!\n"
353 "The VM cannot be started. To fix this problem, either "
354 "install the '%s' or disable PCI passthrough via VBoxManage"),
355 s_pszPCIRawExtPackName);
356# endif
357
358 /* Now actually add devices */
359 PCFGMNODE pPCIDevs = NULL;
360
361 if (assignments.size() > 0)
362 {
363 InsertConfigNode(pDevices, "pciraw", &pPCIDevs);
364
365 PCFGMNODE pRoot = CFGMR3GetParent(pDevices); Assert(pRoot);
366
367 /* Tell PGM to tell GPCIRaw about guest mappings. */
368 CFGMR3InsertNode(pRoot, "PGM", NULL);
369 InsertConfigInteger(CFGMR3GetChild(pRoot, "PGM"), "PciPassThrough", 1);
370
371 /*
372 * Currently, using IOMMU needed for PCI passthrough
373 * requires RAM preallocation.
374 */
375 /** @todo check if we can lift this requirement */
376 CFGMR3RemoveValue(pRoot, "RamPreAlloc");
377 InsertConfigInteger(pRoot, "RamPreAlloc", 1);
378 }
379
380 for (size_t iDev = 0; iDev < assignments.size(); iDev++)
381 {
382 ComPtr<IPCIDeviceAttachment> const assignment = assignments[iDev];
383
384 LONG host;
385 hrc = assignment->COMGETTER(HostAddress)(&host); H();
386 LONG guest;
387 hrc = assignment->COMGETTER(GuestAddress)(&guest); H();
388 Bstr bstrDevName;
389 hrc = assignment->COMGETTER(Name)(bstrDevName.asOutParam()); H();
390
391 InsertConfigNodeF(pPCIDevs, &pInst, "%d", iDev);
392 InsertConfigInteger(pInst, "Trusted", 1);
393
394 PCIBusAddress HostPCIAddress(host);
395 Assert(HostPCIAddress.valid());
396 InsertConfigNode(pInst, "Config", &pCfg);
397 InsertConfigString(pCfg, "DeviceName", bstrDevName);
398
399 InsertConfigInteger(pCfg, "DetachHostDriver", 1);
400 InsertConfigInteger(pCfg, "HostPCIBusNo", HostPCIAddress.miBus);
401 InsertConfigInteger(pCfg, "HostPCIDeviceNo", HostPCIAddress.miDevice);
402 InsertConfigInteger(pCfg, "HostPCIFunctionNo", HostPCIAddress.miFn);
403
404 PCIBusAddress GuestPCIAddress(guest);
405 Assert(GuestPCIAddress.valid());
406 hrc = pBusMgr->assignHostPCIDevice("pciraw", pInst, HostPCIAddress, GuestPCIAddress, true);
407 if (hrc != S_OK)
408 return hrc;
409
410 InsertConfigInteger(pCfg, "GuestPCIBusNo", GuestPCIAddress.miBus);
411 InsertConfigInteger(pCfg, "GuestPCIDeviceNo", GuestPCIAddress.miDevice);
412 InsertConfigInteger(pCfg, "GuestPCIFunctionNo", GuestPCIAddress.miFn);
413
414 /* the driver */
415 InsertConfigNode(pInst, "LUN#0", &pLunL0);
416 InsertConfigString(pLunL0, "Driver", "pciraw");
417 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
418
419 /* the Main driver */
420 InsertConfigString(pLunL1, "Driver", "MainPciRaw");
421 InsertConfigNode(pLunL1, "Config", &pCfg);
422 PCIRawDev *pMainDev = new PCIRawDev(this);
423# error This is not allowed any more
424 InsertConfigInteger(pCfg, "Object", (uintptr_t)pMainDev);
425 }
426
427 return hrc;
428}
429#endif
430
431
432/**
433 * Worker for configConstructor.
434 *
435 * @return VBox status code.
436 * @param pUVM The user mode VM handle.
437 * @param pVM The cross context VM handle.
438 * @param pVMM The VMM vtable.
439 * @param pAlock The automatic lock instance. This is for when we have
440 * to leave it in order to avoid deadlocks (ext packs and
441 * more).
442 */
443int Console::i_configConstructorX86(PUVM pUVM, PVM pVM, PCVMMR3VTABLE pVMM, AutoWriteLock *pAlock)
444{
445 RT_NOREF(pVM /* when everything is disabled */);
446 ComPtr<IMachine> pMachine = i_machine();
447
448 int vrc;
449 HRESULT hrc;
450 Utf8Str strTmp;
451 Bstr bstr;
452
453#define H() AssertLogRelMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR)
454
455 /*
456 * Get necessary objects and frequently used parameters.
457 */
458 ComPtr<IVirtualBox> virtualBox;
459 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
460
461 ComPtr<IHost> host;
462 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
463
464 ComPtr<ISystemProperties> systemProperties;
465 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
466
467 ComPtr<IFirmwareSettings> firmwareSettings;
468 hrc = pMachine->COMGETTER(FirmwareSettings)(firmwareSettings.asOutParam()); H();
469
470 ComPtr<INvramStore> nvramStore;
471 hrc = pMachine->COMGETTER(NonVolatileStore)(nvramStore.asOutParam()); H();
472
473 hrc = pMachine->COMGETTER(HardwareUUID)(bstr.asOutParam()); H();
474 RTUUID HardwareUuid;
475 vrc = RTUuidFromUtf16(&HardwareUuid, bstr.raw());
476 AssertRCReturn(vrc, vrc);
477
478 ULONG cRamMBs;
479 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
480#if 0 /* enable to play with lots of memory. */
481 if (RTEnvExist("VBOX_RAM_SIZE"))
482 cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
483#endif
484 uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
485 uint32_t cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
486 uint64_t uMcfgBase = 0;
487 uint32_t cbMcfgLength = 0;
488
489 ParavirtProvider_T enmParavirtProvider;
490 hrc = pMachine->GetEffectiveParavirtProvider(&enmParavirtProvider); H();
491
492 Bstr strParavirtDebug;
493 hrc = pMachine->COMGETTER(ParavirtDebug)(strParavirtDebug.asOutParam()); H();
494
495 BOOL fIOAPIC;
496 uint32_t uIoApicPciAddress = NIL_PCIBDF;
497 hrc = firmwareSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
498
499 ComPtr<IPlatform> platform;
500 pMachine->COMGETTER(Platform)(platform.asOutParam()); H();
501
502 ChipsetType_T chipsetType;
503 hrc = platform->COMGETTER(ChipsetType)(&chipsetType); H();
504 if (chipsetType == ChipsetType_ICH9)
505 {
506 /* We'd better have 0x10000000 region, to cover 256 buses but this put
507 * too much load on hypervisor heap. Linux 4.8 currently complains with
508 * ``acpi PNP0A03:00: [Firmware Info]: MMCONFIG for domain 0000 [bus 00-3f]
509 * only partially covers this bridge'' */
510 cbMcfgLength = 0x4000000; //0x10000000;
511 cbRamHole += cbMcfgLength;
512 uMcfgBase = _4G - cbRamHole;
513 }
514
515 /* Get the CPU profile name. */
516 Bstr bstrCpuProfile;
517 hrc = pMachine->COMGETTER(CPUProfile)(bstrCpuProfile.asOutParam()); H();
518
519 /* Get the X86 platform object. */
520 ComPtr<IPlatformX86> platformX86;
521 hrc = platform->COMGETTER(X86)(platformX86.asOutParam()); H();
522
523 /* Check if long mode is enabled. */
524 BOOL fIsGuest64Bit;
525 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_LongMode, &fIsGuest64Bit); H();
526
527 /*
528 * Figure out the IOMMU config.
529 */
530#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
531 IommuType_T enmIommuType;
532 hrc = platform->COMGETTER(IommuType)(&enmIommuType); H();
533
534 /* Resolve 'automatic' type to an Intel or AMD IOMMU based on the host CPU. */
535 if (enmIommuType == IommuType_Automatic)
536 {
537 if ( bstrCpuProfile.startsWith("AMD")
538 || bstrCpuProfile.startsWith("Quad-Core AMD")
539 || bstrCpuProfile.startsWith("Hygon"))
540 enmIommuType = IommuType_AMD;
541 else if (bstrCpuProfile.startsWith("Intel"))
542 {
543 if ( bstrCpuProfile.equals("Intel 8086")
544 || bstrCpuProfile.equals("Intel 80186")
545 || bstrCpuProfile.equals("Intel 80286")
546 || bstrCpuProfile.equals("Intel 80386")
547 || bstrCpuProfile.equals("Intel 80486"))
548 enmIommuType = IommuType_None;
549 else
550 enmIommuType = IommuType_Intel;
551 }
552# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
553 else if (ASMIsAmdCpu())
554 enmIommuType = IommuType_AMD;
555 else if (ASMIsIntelCpu())
556 enmIommuType = IommuType_Intel;
557# endif
558 else
559 {
560 /** @todo Should we handle other CPUs like Shanghai, VIA etc. here? */
561 LogRel(("WARNING! Unrecognized CPU type, IOMMU disabled.\n"));
562 enmIommuType = IommuType_None;
563 }
564 }
565
566 if (enmIommuType == IommuType_AMD)
567 {
568# ifdef VBOX_WITH_IOMMU_AMD
569 /*
570 * Reserve the specific PCI address of the "SB I/O APIC" when using
571 * an AMD IOMMU. Required by Linux guests, see @bugref{9654#c23}.
572 */
573 uIoApicPciAddress = VBOX_PCI_BDF_SB_IOAPIC;
574# else
575 LogRel(("WARNING! AMD IOMMU not supported, IOMMU disabled.\n"));
576 enmIommuType = IommuType_None;
577# endif
578 }
579
580 if (enmIommuType == IommuType_Intel)
581 {
582# ifdef VBOX_WITH_IOMMU_INTEL
583 /*
584 * Reserve a unique PCI address for the I/O APIC when using
585 * an Intel IOMMU. For convenience we use the same address as
586 * we do on AMD, see @bugref{9967#c13}.
587 */
588 uIoApicPciAddress = VBOX_PCI_BDF_SB_IOAPIC;
589# else
590 LogRel(("WARNING! Intel IOMMU not supported, IOMMU disabled.\n"));
591 enmIommuType = IommuType_None;
592# endif
593 }
594
595 if ( enmIommuType == IommuType_AMD
596 || enmIommuType == IommuType_Intel)
597 {
598 if (chipsetType != ChipsetType_ICH9)
599 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
600 N_("IOMMU uses MSIs which requires the ICH9 chipset implementation."));
601 if (!fIOAPIC)
602 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
603 N_("IOMMU requires an I/O APIC for remapping interrupts."));
604 }
605#else
606 IommuType_T const enmIommuType = IommuType_None;
607#endif
608
609 /* Instantiate the bus assignment manager. */
610 Assert(enmIommuType != IommuType_Automatic);
611 BusAssignmentManager *pBusMgr = mBusMgr = BusAssignmentManager::createInstance(pVMM, chipsetType, enmIommuType);
612
613 ULONG cCpus = 1;
614 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
615
616 ULONG ulCpuExecutionCap = 100;
617 hrc = pMachine->COMGETTER(CPUExecutionCap)(&ulCpuExecutionCap); H();
618
619 LogRel(("Guest architecture: x86\n"));
620
621 Bstr osTypeId;
622 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
623 LogRel(("Guest OS type: '%s'\n", Utf8Str(osTypeId).c_str()));
624
625 APICMode_T apicMode;
626 hrc = firmwareSettings->COMGETTER(APICMode)(&apicMode); H();
627 uint32_t uFwAPIC;
628 switch (apicMode)
629 {
630 case APICMode_Disabled:
631 uFwAPIC = 0;
632 break;
633 case APICMode_APIC:
634 uFwAPIC = 1;
635 break;
636 case APICMode_X2APIC:
637 uFwAPIC = 2;
638 break;
639 default:
640 AssertMsgFailed(("Invalid APICMode=%d\n", apicMode));
641 uFwAPIC = 1;
642 break;
643 }
644
645 ComPtr<IGuestOSType> pGuestOSType;
646 virtualBox->GetGuestOSType(osTypeId.raw(), pGuestOSType.asOutParam());
647
648 BOOL fOsXGuest = FALSE;
649 BOOL fWinGuest = FALSE;
650 BOOL fOs2Guest = FALSE;
651 BOOL fW9xGuest = FALSE;
652 BOOL fDosGuest = FALSE;
653 if (pGuestOSType.isNotNull())
654 {
655 Bstr guestTypeFamilyId;
656 hrc = pGuestOSType->COMGETTER(FamilyId)(guestTypeFamilyId.asOutParam()); H();
657 fOsXGuest = guestTypeFamilyId == Bstr("MacOS");
658 fWinGuest = guestTypeFamilyId == Bstr("Windows");
659 fOs2Guest = osTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("OS2"));
660 fW9xGuest = osTypeId.startsWith(GUEST_OS_ID_STR_PARTIAL("Windows9")); /* Does not include Windows Me. */
661 fDosGuest = osTypeId.equals(GUEST_OS_ID_STR_X86("DOS")) || osTypeId.equals(GUEST_OS_ID_STR_X86("Windows31"));
662 }
663
664 ComPtr<IPlatformProperties> platformProperties;
665 virtualBox->GetPlatformProperties(PlatformArchitecture_x86, platformProperties.asOutParam());
666
667 ULONG maxNetworkAdapters;
668 hrc = platformProperties->GetMaxNetworkAdapters(chipsetType, &maxNetworkAdapters); H();
669
670 /*
671 * Get root node first.
672 * This is the only node in the tree.
673 */
674 PCFGMNODE pRoot = pVMM->pfnCFGMR3GetRootU(pUVM);
675 Assert(pRoot);
676
677 // catching throws from InsertConfigString and friends.
678 try
679 {
680
681 /*
682 * Set the root (and VMM) level values.
683 */
684 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
685 InsertConfigString(pRoot, "Name", bstr);
686 InsertConfigBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid));
687 InsertConfigInteger(pRoot, "RamSize", cbRam);
688 InsertConfigInteger(pRoot, "RamHoleSize", cbRamHole);
689 InsertConfigInteger(pRoot, "NumCPUs", cCpus);
690 InsertConfigInteger(pRoot, "CpuExecutionCap", ulCpuExecutionCap);
691 InsertConfigInteger(pRoot, "TimerMillies", 10);
692
693 BOOL fPageFusion = FALSE;
694 hrc = pMachine->COMGETTER(PageFusionEnabled)(&fPageFusion); H();
695 InsertConfigInteger(pRoot, "PageFusionAllowed", fPageFusion); /* boolean */
696
697 /* Not necessary, but makes sure this setting ends up in the release log. */
698 ULONG ulBalloonSize = 0;
699 hrc = pMachine->COMGETTER(MemoryBalloonSize)(&ulBalloonSize); H();
700 InsertConfigInteger(pRoot, "MemBalloonSize", ulBalloonSize);
701
702 /*
703 * EM values (before CPUM as it may need to set IemExecutesAll).
704 */
705 PCFGMNODE pEM;
706 InsertConfigNode(pRoot, "EM", &pEM);
707
708 /* Triple fault behavior. */
709 BOOL fTripleFaultReset = false;
710 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_TripleFaultReset, &fTripleFaultReset); H();
711 InsertConfigInteger(pEM, "TripleFaultReset", fTripleFaultReset);
712
713 /*
714 * CPUM values.
715 */
716 PCFGMNODE pCPUM;
717 InsertConfigNode(pRoot, "CPUM", &pCPUM);
718 PCFGMNODE pIsaExts;
719 InsertConfigNode(pCPUM, "IsaExts", &pIsaExts);
720
721 /* Host CPUID leaf overrides. */
722 for (uint32_t iOrdinal = 0; iOrdinal < _4K; iOrdinal++)
723 {
724 ULONG uLeaf, uSubLeaf, uEax, uEbx, uEcx, uEdx;
725 hrc = platformX86->GetCPUIDLeafByOrdinal(iOrdinal, &uLeaf, &uSubLeaf, &uEax, &uEbx, &uEcx, &uEdx);
726 if (hrc == E_INVALIDARG)
727 break;
728 H();
729 PCFGMNODE pLeaf;
730 InsertConfigNode(pCPUM, Utf8StrFmt("HostCPUID/%RX32", uLeaf).c_str(), &pLeaf);
731 /** @todo Figure out how to tell the VMM about uSubLeaf */
732 InsertConfigInteger(pLeaf, "eax", uEax);
733 InsertConfigInteger(pLeaf, "ebx", uEbx);
734 InsertConfigInteger(pLeaf, "ecx", uEcx);
735 InsertConfigInteger(pLeaf, "edx", uEdx);
736 }
737
738 /* We must limit CPUID count for Windows NT 4, as otherwise it stops
739 with error 0x3e (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED). */
740 if (osTypeId == GUEST_OS_ID_STR_X86("WindowsNT4"))
741 {
742 LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
743 InsertConfigInteger(pCPUM, "NT4LeafLimit", true);
744 }
745
746 if (fOsXGuest)
747 {
748 /* Expose extended MWAIT features to Mac OS X guests. */
749 LogRel(("Using MWAIT extensions\n"));
750 InsertConfigInteger(pIsaExts, "MWaitExtensions", true);
751
752 /* Fake the CPU family/model so the guest works. This is partly
753 because older mac releases really doesn't work on newer cpus,
754 and partly because mac os x expects more from systems with newer
755 cpus (MSRs, power features, whatever). */
756 uint32_t uMaxIntelFamilyModelStep = UINT32_MAX;
757 if ( osTypeId == GUEST_OS_ID_STR_X86("MacOS")
758 || osTypeId == GUEST_OS_ID_STR_X64("MacOS"))
759 uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 0); /* Penryn / X5482. */
760 else if ( osTypeId == GUEST_OS_ID_STR_X86("MacOS106")
761 || osTypeId == GUEST_OS_ID_STR_X64("MacOS106"))
762 uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 0); /* Penryn / X5482 */
763 else if ( osTypeId == GUEST_OS_ID_STR_X86("MacOS107")
764 || osTypeId == GUEST_OS_ID_STR_X64("MacOS107"))
765 uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 0); /* Penryn / X5482 */ /** @todo figure out
766 what is required here. */
767 else if ( osTypeId == GUEST_OS_ID_STR_X86("MacOS108")
768 || osTypeId == GUEST_OS_ID_STR_X64("MacOS108"))
769 uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 0); /* Penryn / X5482 */ /** @todo figure out
770 what is required here. */
771 else if ( osTypeId == GUEST_OS_ID_STR_X86("MacOS109")
772 || osTypeId == GUEST_OS_ID_STR_X64("MacOS109"))
773 uMaxIntelFamilyModelStep = RT_MAKE_U32_FROM_U8(1, 23, 6, 0); /* Penryn / X5482 */ /** @todo figure
774 out what is required here. */
775 if (uMaxIntelFamilyModelStep != UINT32_MAX)
776 InsertConfigInteger(pCPUM, "MaxIntelFamilyModelStep", uMaxIntelFamilyModelStep);
777 }
778
779 /* CPU Portability level, */
780 ULONG uCpuIdPortabilityLevel = 0;
781 hrc = pMachine->COMGETTER(CPUIDPortabilityLevel)(&uCpuIdPortabilityLevel); H();
782 InsertConfigInteger(pCPUM, "PortableCpuIdLevel", uCpuIdPortabilityLevel);
783
784 /* Physical Address Extension (PAE) */
785 BOOL fEnablePAE = false;
786 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_PAE, &fEnablePAE); H();
787 fEnablePAE |= fIsGuest64Bit;
788 InsertConfigInteger(pRoot, "EnablePAE", fEnablePAE);
789
790 /* 64-bit guests (long mode) */
791 InsertConfigInteger(pCPUM, "Enable64bit", fIsGuest64Bit);
792
793 /* APIC/X2APIC configuration */
794 BOOL fEnableAPIC = true;
795 BOOL fEnableX2APIC = true;
796 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_APIC, &fEnableAPIC); H();
797 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_X2APIC, &fEnableX2APIC); H();
798 if (fEnableX2APIC)
799 Assert(fEnableAPIC);
800
801 /* CPUM profile name. */
802 InsertConfigString(pCPUM, "GuestCpuName", bstrCpuProfile);
803
804 /*
805 * Temporary(?) hack to make sure we emulate the ancient 16-bit CPUs
806 * correctly. There are way too many #UDs we'll miss using VT-x,
807 * raw-mode or qemu for the 186 and 286, while we'll get undefined opcodes
808 * dead wrong on 8086 (see http://www.os2museum.com/wp/undocumented-8086-opcodes/).
809 */
810 if ( bstrCpuProfile.equals("Intel 80386") /* just for now */
811 || bstrCpuProfile.equals("Intel 80286")
812 || bstrCpuProfile.equals("Intel 80186")
813 || bstrCpuProfile.equals("Nec V20")
814 || bstrCpuProfile.equals("Intel 8086") )
815 {
816 InsertConfigInteger(pEM, "IemExecutesAll", true);
817 if (!bstrCpuProfile.equals("Intel 80386"))
818 {
819 fEnableAPIC = false;
820 fIOAPIC = false;
821 }
822 fEnableX2APIC = false;
823 }
824
825 /* Adjust firmware APIC handling to stay within the VCPU limits. */
826 if (uFwAPIC == 2 && !fEnableX2APIC)
827 {
828 if (fEnableAPIC)
829 uFwAPIC = 1;
830 else
831 uFwAPIC = 0;
832 LogRel(("Limiting the firmware APIC level from x2APIC to %s\n", fEnableAPIC ? "APIC" : "Disabled"));
833 }
834 else if (uFwAPIC == 1 && !fEnableAPIC)
835 {
836 uFwAPIC = 0;
837 LogRel(("Limiting the firmware APIC level from APIC to Disabled\n"));
838 }
839
840 /* Speculation Control. */
841 BOOL fSpecCtrl = FALSE;
842 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_SpecCtrl, &fSpecCtrl); H();
843 InsertConfigInteger(pCPUM, "SpecCtrl", fSpecCtrl);
844
845 /* Nested VT-x / AMD-V. */
846 BOOL fNestedHWVirt = FALSE;
847 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_HWVirt, &fNestedHWVirt); H();
848 InsertConfigInteger(pCPUM, "NestedHWVirt", fNestedHWVirt ? true : false);
849
850 /*
851 * Hardware virtualization extensions.
852 */
853 /* Sanitize valid/useful APIC combinations, see @bugref{8868}. */
854 if (!fEnableAPIC)
855 {
856 if (fIsGuest64Bit)
857 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
858 N_("Cannot disable the APIC for a 64-bit guest."));
859 if (cCpus > 1)
860 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
861 N_("Cannot disable the APIC for an SMP guest."));
862 if (fIOAPIC)
863 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
864 N_("Cannot disable the APIC when the I/O APIC is present."));
865 }
866
867 BOOL fHMEnabled;
868 hrc = platformX86->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &fHMEnabled); H();
869 if (cCpus > 1 && !fHMEnabled)
870 {
871 LogRel(("Forced fHMEnabled to TRUE by SMP guest.\n"));
872 fHMEnabled = TRUE;
873 }
874
875 BOOL fHMForced;
876 fHMEnabled = fHMForced = TRUE;
877 LogRel(("fHMForced=true - No raw-mode support in this build!\n"));
878 if (!fHMForced) /* No need to query if already forced above. */
879 {
880 hrc = platformX86->GetHWVirtExProperty(HWVirtExPropertyType_Force, &fHMForced); H();
881 if (fHMForced)
882 LogRel(("fHMForced=true - HWVirtExPropertyType_Force\n"));
883 }
884 InsertConfigInteger(pRoot, "HMEnabled", fHMEnabled);
885
886 /* /HM/xyz */
887 PCFGMNODE pHM;
888 InsertConfigNode(pRoot, "HM", &pHM);
889 InsertConfigInteger(pHM, "HMForced", fHMForced);
890 if (fHMEnabled)
891 {
892 /* Indicate whether 64-bit guests are supported or not. */
893 InsertConfigInteger(pHM, "64bitEnabled", fIsGuest64Bit);
894
895 /** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better,
896 but that requires quite a bit of API change in Main. */
897 if ( fIOAPIC
898 && ( osTypeId == GUEST_OS_ID_STR_X86("WindowsNT4")
899 || osTypeId == GUEST_OS_ID_STR_X86("Windows2000")
900 || osTypeId == GUEST_OS_ID_STR_X86("WindowsXP")
901 || osTypeId == GUEST_OS_ID_STR_X86("Windows2003")))
902 {
903 /* Only allow TPR patching for NT, Win2k, XP and Windows Server 2003. (32 bits mode)
904 * We may want to consider adding more guest OSes (Solaris) later on.
905 */
906 InsertConfigInteger(pHM, "TPRPatchingEnabled", 1);
907 }
908 }
909
910 /* HWVirtEx exclusive mode */
911 BOOL fHMExclusive = true;
912 hrc = platformProperties->COMGETTER(ExclusiveHwVirt)(&fHMExclusive); H();
913 InsertConfigInteger(pHM, "Exclusive", fHMExclusive);
914
915 /* Nested paging (VT-x/AMD-V) */
916 BOOL fEnableNestedPaging = false;
917 hrc = platformX86->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging); H();
918 InsertConfigInteger(pHM, "EnableNestedPaging", fEnableNestedPaging);
919
920 /* Large pages; requires nested paging */
921 BOOL fEnableLargePages = false;
922 hrc = platformX86->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &fEnableLargePages); H();
923 InsertConfigInteger(pHM, "EnableLargePages", fEnableLargePages);
924
925 /* VPID (VT-x) */
926 BOOL fEnableVPID = false;
927 hrc = platformX86->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID); H();
928 InsertConfigInteger(pHM, "EnableVPID", fEnableVPID);
929
930 /* Unrestricted execution aka UX (VT-x) */
931 BOOL fEnableUX = false;
932 hrc = platformX86->GetHWVirtExProperty(HWVirtExPropertyType_UnrestrictedExecution, &fEnableUX); H();
933 InsertConfigInteger(pHM, "EnableUX", fEnableUX);
934
935 /* Virtualized VMSAVE/VMLOAD (AMD-V) */
936 BOOL fVirtVmsaveVmload = true;
937 hrc = host->GetProcessorFeature(ProcessorFeature_VirtVmsaveVmload, &fVirtVmsaveVmload); H();
938 InsertConfigInteger(pHM, "SvmVirtVmsaveVmload", fVirtVmsaveVmload);
939
940 /* Indirect branch prediction boundraries. */
941 BOOL fIBPBOnVMExit = false;
942 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_IBPBOnVMExit, &fIBPBOnVMExit); H();
943 InsertConfigInteger(pHM, "IBPBOnVMExit", fIBPBOnVMExit);
944
945 BOOL fIBPBOnVMEntry = false;
946 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_IBPBOnVMEntry, &fIBPBOnVMEntry); H();
947 InsertConfigInteger(pHM, "IBPBOnVMEntry", fIBPBOnVMEntry);
948
949 BOOL fSpecCtrlByHost = false;
950 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_SpecCtrlByHost, &fSpecCtrlByHost); H();
951 InsertConfigInteger(pHM, "SpecCtrlByHost", fSpecCtrlByHost);
952
953 BOOL fL1DFlushOnSched = true;
954 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_L1DFlushOnEMTScheduling, &fL1DFlushOnSched); H();
955 InsertConfigInteger(pHM, "L1DFlushOnSched", fL1DFlushOnSched);
956
957 BOOL fL1DFlushOnVMEntry = false;
958 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_L1DFlushOnVMEntry, &fL1DFlushOnVMEntry); H();
959 InsertConfigInteger(pHM, "L1DFlushOnVMEntry", fL1DFlushOnVMEntry);
960
961 BOOL fMDSClearOnSched = true;
962 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_MDSClearOnEMTScheduling, &fMDSClearOnSched); H();
963 InsertConfigInteger(pHM, "MDSClearOnSched", fMDSClearOnSched);
964
965 BOOL fMDSClearOnVMEntry = false;
966 hrc = platformX86->GetCPUProperty(CPUPropertyTypeX86_MDSClearOnVMEntry, &fMDSClearOnVMEntry); H();
967 InsertConfigInteger(pHM, "MDSClearOnVMEntry", fMDSClearOnVMEntry);
968
969 /* Reset overwrite. */
970 mfTurnResetIntoPowerOff = GetExtraDataBoth(virtualBox, pMachine,
971 "VBoxInternal2/TurnResetIntoPowerOff", &strTmp)->equals("1");
972 if (mfTurnResetIntoPowerOff)
973 InsertConfigInteger(pRoot, "PowerOffInsteadOfReset", 1);
974
975 /* Use NEM rather than HM. */
976 BOOL fUseNativeApi = false;
977 hrc = platformX86->GetHWVirtExProperty(HWVirtExPropertyType_UseNativeApi, &fUseNativeApi); H();
978 InsertConfigInteger(pHM, "UseNEMInstead", fUseNativeApi);
979
980 /* Enable workaround for missing TLB flush for OS/2 guests, see ticketref:20625. */
981 if (fOs2Guest)
982 InsertConfigInteger(pHM, "MissingOS2TlbFlushWorkaround", 1);
983
984 /*
985 * NEM
986 */
987 PCFGMNODE pNEM;
988 InsertConfigNode(pRoot, "NEM", &pNEM);
989 InsertConfigInteger(pNEM, "Allow64BitGuests", fIsGuest64Bit);
990
991 /*
992 * Paravirt. provider.
993 */
994 PCFGMNODE pParavirtNode;
995 InsertConfigNode(pRoot, "GIM", &pParavirtNode);
996 const char *pcszParavirtProvider;
997 bool fGimDeviceNeeded = true;
998 switch (enmParavirtProvider)
999 {
1000 case ParavirtProvider_None:
1001 pcszParavirtProvider = "None";
1002 fGimDeviceNeeded = false;
1003 break;
1004
1005 case ParavirtProvider_Minimal:
1006 pcszParavirtProvider = "Minimal";
1007 break;
1008
1009 case ParavirtProvider_HyperV:
1010 pcszParavirtProvider = "HyperV";
1011 break;
1012
1013 case ParavirtProvider_KVM:
1014 pcszParavirtProvider = "KVM";
1015 break;
1016
1017 default:
1018 AssertMsgFailed(("Invalid enmParavirtProvider=%d\n", enmParavirtProvider));
1019 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS, N_("Invalid paravirt. provider '%d'"),
1020 enmParavirtProvider);
1021 }
1022 InsertConfigString(pParavirtNode, "Provider", pcszParavirtProvider);
1023
1024 /*
1025 * Parse paravirt. debug options.
1026 */
1027 bool fGimDebug = false;
1028 com::Utf8Str strGimDebugAddress = "127.0.0.1";
1029 uint32_t uGimDebugPort = 50000;
1030 if (strParavirtDebug.isNotEmpty())
1031 {
1032 /* Hyper-V debug options. */
1033 if (enmParavirtProvider == ParavirtProvider_HyperV)
1034 {
1035 bool fGimHvDebug = false;
1036 com::Utf8Str strGimHvVendor;
1037 bool fGimHvVsIf = false;
1038 bool fGimHvHypercallIf = false;
1039
1040 size_t uPos = 0;
1041 com::Utf8Str strDebugOptions = strParavirtDebug;
1042 com::Utf8Str strKey;
1043 com::Utf8Str strVal;
1044 while ((uPos = strDebugOptions.parseKeyValue(strKey, strVal, uPos)) != com::Utf8Str::npos)
1045 {
1046 if (strKey == "enabled")
1047 {
1048 if (strVal.toUInt32() == 1)
1049 {
1050 /* Apply defaults.
1051 The defaults are documented in the user manual,
1052 changes need to be reflected accordingly. */
1053 fGimHvDebug = true;
1054 strGimHvVendor = "Microsoft Hv";
1055 fGimHvVsIf = true;
1056 fGimHvHypercallIf = false;
1057 }
1058 /* else: ignore, i.e. don't assert below with 'enabled=0'. */
1059 }
1060 else if (strKey == "address")
1061 strGimDebugAddress = strVal;
1062 else if (strKey == "port")
1063 uGimDebugPort = strVal.toUInt32();
1064 else if (strKey == "vendor")
1065 strGimHvVendor = strVal;
1066 else if (strKey == "vsinterface")
1067 fGimHvVsIf = RT_BOOL(strVal.toUInt32());
1068 else if (strKey == "hypercallinterface")
1069 fGimHvHypercallIf = RT_BOOL(strVal.toUInt32());
1070 else
1071 {
1072 AssertMsgFailed(("Unrecognized Hyper-V debug option '%s'\n", strKey.c_str()));
1073 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1074 N_("Unrecognized Hyper-V debug option '%s' in '%s'"), strKey.c_str(),
1075 strDebugOptions.c_str());
1076 }
1077 }
1078
1079 /* Update HyperV CFGM node with active debug options. */
1080 if (fGimHvDebug)
1081 {
1082 PCFGMNODE pHvNode;
1083 InsertConfigNode(pParavirtNode, "HyperV", &pHvNode);
1084 InsertConfigString(pHvNode, "VendorID", strGimHvVendor);
1085 InsertConfigInteger(pHvNode, "VSInterface", fGimHvVsIf ? 1 : 0);
1086 InsertConfigInteger(pHvNode, "HypercallDebugInterface", fGimHvHypercallIf ? 1 : 0);
1087 fGimDebug = true;
1088 }
1089 }
1090 }
1091
1092 /*
1093 * Guest Compatibility Manager.
1094 */
1095 PCFGMNODE pGcmNode;
1096 uint32_t u32FixerSet = 0;
1097 InsertConfigNode(pRoot, "GCM", &pGcmNode);
1098 /* OS/2 and Win9x guests can run DOS apps so they get
1099 * the DOS specific fixes as well.
1100 */
1101 if (fOs2Guest)
1102 u32FixerSet = GCMFIXER_DBZ_DOS | GCMFIXER_DBZ_OS2;
1103 else if (fW9xGuest)
1104 u32FixerSet = GCMFIXER_DBZ_DOS | GCMFIXER_DBZ_WIN9X;
1105 else if (fDosGuest)
1106 u32FixerSet = GCMFIXER_DBZ_DOS;
1107 InsertConfigInteger(pGcmNode, "FixerSet", u32FixerSet);
1108
1109
1110 /*
1111 * MM values.
1112 */
1113 PCFGMNODE pMM;
1114 InsertConfigNode(pRoot, "MM", &pMM);
1115 InsertConfigInteger(pMM, "CanUseLargerHeap", chipsetType == ChipsetType_ICH9);
1116
1117 /*
1118 * PDM config.
1119 * Load drivers in VBoxC.[so|dll]
1120 */
1121 vrc = i_configPdm(pMachine, pVMM, pUVM, pRoot); VRC();
1122
1123 /*
1124 * Devices
1125 */
1126 PCFGMNODE pDevices = NULL; /* /Devices */
1127 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
1128 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
1129 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
1130 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
1131 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
1132 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
1133 PCFGMNODE pNetBootCfg = NULL; /* /Devices/pcbios/0/Config/NetBoot/ */
1134
1135 InsertConfigNode(pRoot, "Devices", &pDevices);
1136
1137 /*
1138 * GIM Device
1139 */
1140 if (fGimDeviceNeeded)
1141 {
1142 InsertConfigNode(pDevices, "GIMDev", &pDev);
1143 InsertConfigNode(pDev, "0", &pInst);
1144 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1145 //InsertConfigNode(pInst, "Config", &pCfg);
1146
1147 if (fGimDebug)
1148 {
1149 InsertConfigNode(pInst, "LUN#998", &pLunL0);
1150 InsertConfigString(pLunL0, "Driver", "UDP");
1151 InsertConfigNode(pLunL0, "Config", &pLunL1);
1152 InsertConfigString(pLunL1, "ServerAddress", strGimDebugAddress);
1153 InsertConfigInteger(pLunL1, "ServerPort", uGimDebugPort);
1154 }
1155 }
1156
1157 /*
1158 * PC Arch.
1159 */
1160 InsertConfigNode(pDevices, "pcarch", &pDev);
1161 InsertConfigNode(pDev, "0", &pInst);
1162 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1163 InsertConfigNode(pInst, "Config", &pCfg);
1164
1165 /*
1166 * The time offset
1167 */
1168 LONG64 timeOffset;
1169 hrc = firmwareSettings->COMGETTER(TimeOffset)(&timeOffset); H();
1170 PCFGMNODE pTMNode;
1171 InsertConfigNode(pRoot, "TM", &pTMNode);
1172 InsertConfigInteger(pTMNode, "UTCOffset", timeOffset * 1000000);
1173
1174 /*
1175 * DMA
1176 */
1177 InsertConfigNode(pDevices, "8237A", &pDev);
1178 InsertConfigNode(pDev, "0", &pInst);
1179 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1180
1181 /*
1182 * PCI buses.
1183 */
1184 uint32_t uIocPCIAddress, uHbcPCIAddress;
1185 switch (chipsetType)
1186 {
1187 default:
1188 AssertFailed();
1189 RT_FALL_THRU();
1190 case ChipsetType_PIIX3:
1191 /* Create the base for adding bridges on demand */
1192 InsertConfigNode(pDevices, "pcibridge", NULL);
1193
1194 InsertConfigNode(pDevices, "pci", &pDev);
1195 uHbcPCIAddress = (0x0 << 16) | 0;
1196 uIocPCIAddress = (0x1 << 16) | 0; // ISA controller
1197 break;
1198 case ChipsetType_ICH9:
1199 /* Create the base for adding bridges on demand */
1200 InsertConfigNode(pDevices, "ich9pcibridge", NULL);
1201
1202 InsertConfigNode(pDevices, "ich9pci", &pDev);
1203 uHbcPCIAddress = (0x1e << 16) | 0;
1204 uIocPCIAddress = (0x1f << 16) | 0; // LPC controller
1205 break;
1206 }
1207 InsertConfigNode(pDev, "0", &pInst);
1208 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1209 InsertConfigNode(pInst, "Config", &pCfg);
1210 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
1211 if (chipsetType == ChipsetType_ICH9)
1212 {
1213 /* Provide MCFG info */
1214 InsertConfigInteger(pCfg, "McfgBase", uMcfgBase);
1215 InsertConfigInteger(pCfg, "McfgLength", cbMcfgLength);
1216
1217#ifdef VBOX_WITH_PCI_PASSTHROUGH
1218 /* Add PCI passthrough devices */
1219 hrc = i_attachRawPCIDevices(pUVM, pBusMgr, pDevices); H();
1220#endif
1221
1222 if (enmIommuType == IommuType_AMD)
1223 {
1224 /* AMD IOMMU. */
1225 InsertConfigNode(pDevices, "iommu-amd", &pDev);
1226 InsertConfigNode(pDev, "0", &pInst);
1227 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1228 InsertConfigNode(pInst, "Config", &pCfg);
1229 hrc = pBusMgr->assignPCIDevice("iommu-amd", pInst); H();
1230
1231 /* The AMD IOMMU device needs to know which PCI slot it's in, see @bugref{9654#c104}. */
1232 {
1233 PCIBusAddress Address;
1234 if (pBusMgr->findPCIAddress("iommu-amd", 0, Address))
1235 {
1236 uint32_t const u32IommuAddress = (Address.miDevice << 16) | Address.miFn;
1237 InsertConfigInteger(pCfg, "PCIAddress", u32IommuAddress);
1238 }
1239 else
1240 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1241 N_("Failed to find PCI address of the assigned IOMMU device!"));
1242 }
1243
1244 PCIBusAddress PCIAddr = PCIBusAddress((int32_t)uIoApicPciAddress);
1245 hrc = pBusMgr->assignPCIDevice("sb-ioapic", NULL /* pCfg */, PCIAddr, true /*fGuestAddressRequired*/); H();
1246 }
1247 else if (enmIommuType == IommuType_Intel)
1248 {
1249 /* Intel IOMMU. */
1250 InsertConfigNode(pDevices, "iommu-intel", &pDev);
1251 InsertConfigNode(pDev, "0", &pInst);
1252 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1253 InsertConfigNode(pInst, "Config", &pCfg);
1254 hrc = pBusMgr->assignPCIDevice("iommu-intel", pInst); H();
1255
1256 PCIBusAddress PCIAddr = PCIBusAddress((int32_t)uIoApicPciAddress);
1257 hrc = pBusMgr->assignPCIDevice("sb-ioapic", NULL /* pCfg */, PCIAddr, true /*fGuestAddressRequired*/); H();
1258 }
1259 }
1260
1261 /*
1262 * Enable the following devices: HPET, SMC and LPC on MacOS X guests or on ICH9 chipset
1263 */
1264
1265 /*
1266 * High Precision Event Timer (HPET)
1267 */
1268 BOOL fHPETEnabled;
1269 /* Other guests may wish to use HPET too, but MacOS X not functional without it */
1270 hrc = platformX86->COMGETTER(HPETEnabled)(&fHPETEnabled); H();
1271 /* so always enable HPET in extended profile */
1272 fHPETEnabled |= fOsXGuest;
1273 /* HPET is always present on ICH9 */
1274 fHPETEnabled |= (chipsetType == ChipsetType_ICH9);
1275 if (fHPETEnabled)
1276 {
1277 InsertConfigNode(pDevices, "hpet", &pDev);
1278 InsertConfigNode(pDev, "0", &pInst);
1279 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1280 InsertConfigNode(pInst, "Config", &pCfg);
1281 InsertConfigInteger(pCfg, "ICH9", (chipsetType == ChipsetType_ICH9) ? 1 : 0); /* boolean */
1282 }
1283
1284 /*
1285 * System Management Controller (SMC)
1286 */
1287 BOOL fSmcEnabled;
1288 fSmcEnabled = fOsXGuest;
1289 if (fSmcEnabled)
1290 {
1291 InsertConfigNode(pDevices, "smc", &pDev);
1292 InsertConfigNode(pDev, "0", &pInst);
1293 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1294 InsertConfigNode(pInst, "Config", &pCfg);
1295
1296 bool fGetKeyFromRealSMC;
1297 Utf8Str strKey;
1298 vrc = getSmcDeviceKey(virtualBox, pMachine, &strKey, &fGetKeyFromRealSMC);
1299 AssertRCReturn(vrc, vrc);
1300
1301 if (!fGetKeyFromRealSMC)
1302 InsertConfigString(pCfg, "DeviceKey", strKey);
1303 InsertConfigInteger(pCfg, "GetKeyFromRealSMC", fGetKeyFromRealSMC);
1304 }
1305
1306 /*
1307 * Low Pin Count (LPC) bus
1308 */
1309 BOOL fLpcEnabled;
1310 /** @todo implement appropriate getter */
1311 fLpcEnabled = fOsXGuest || (chipsetType == ChipsetType_ICH9);
1312 if (fLpcEnabled)
1313 {
1314 InsertConfigNode(pDevices, "lpc", &pDev);
1315 InsertConfigNode(pDev, "0", &pInst);
1316 hrc = pBusMgr->assignPCIDevice("lpc", pInst); H();
1317 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1318 }
1319
1320 BOOL fShowRtc;
1321 fShowRtc = fOsXGuest || (chipsetType == ChipsetType_ICH9);
1322
1323 /*
1324 * PS/2 keyboard & mouse.
1325 */
1326 InsertConfigNode(pDevices, "pckbd", &pDev);
1327 InsertConfigNode(pDev, "0", &pInst);
1328 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1329 InsertConfigNode(pInst, "Config", &pCfg);
1330
1331 KeyboardHIDType_T aKbdHID;
1332 hrc = pMachine->COMGETTER(KeyboardHIDType)(&aKbdHID); H();
1333 if (aKbdHID != KeyboardHIDType_None)
1334 {
1335 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1336 InsertConfigString(pLunL0, "Driver", "KeyboardQueue");
1337 InsertConfigNode(pLunL0, "Config", &pCfg);
1338 InsertConfigInteger(pCfg, "QueueSize", 64);
1339
1340 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1341 InsertConfigString(pLunL1, "Driver", "MainKeyboard");
1342 }
1343
1344 PointingHIDType_T aPointingHID;
1345 hrc = pMachine->COMGETTER(PointingHIDType)(&aPointingHID); H();
1346 if (aPointingHID != PointingHIDType_None)
1347 {
1348 InsertConfigNode(pInst, "LUN#1", &pLunL0);
1349 InsertConfigString(pLunL0, "Driver", "MouseQueue");
1350 InsertConfigNode(pLunL0, "Config", &pCfg);
1351 InsertConfigInteger(pCfg, "QueueSize", 128);
1352
1353 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1354 InsertConfigString(pLunL1, "Driver", "MainMouse");
1355 }
1356
1357 /*
1358 * i8254 Programmable Interval Timer And Dummy Speaker
1359 */
1360 InsertConfigNode(pDevices, "i8254", &pDev);
1361 InsertConfigNode(pDev, "0", &pInst);
1362 InsertConfigNode(pInst, "Config", &pCfg);
1363#ifdef DEBUG
1364 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1365#endif
1366
1367 /*
1368 * i8259 Programmable Interrupt Controller.
1369 */
1370 InsertConfigNode(pDevices, "i8259", &pDev);
1371 InsertConfigNode(pDev, "0", &pInst);
1372 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1373 InsertConfigNode(pInst, "Config", &pCfg);
1374
1375 /*
1376 * Advanced Programmable Interrupt Controller.
1377 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
1378 * thus only single insert
1379 */
1380 if (fEnableAPIC)
1381 {
1382 InsertConfigNode(pDevices, "apic", &pDev);
1383 InsertConfigNode(pDev, "0", &pInst);
1384 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1385 InsertConfigNode(pInst, "Config", &pCfg);
1386 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
1387 PDMAPICMODE enmAPICMode = PDMAPICMODE_APIC;
1388 if (fEnableX2APIC)
1389 enmAPICMode = PDMAPICMODE_X2APIC;
1390 else if (!fEnableAPIC)
1391 enmAPICMode = PDMAPICMODE_NONE;
1392 InsertConfigInteger(pCfg, "Mode", enmAPICMode);
1393 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
1394
1395 if (fIOAPIC)
1396 {
1397 /*
1398 * I/O Advanced Programmable Interrupt Controller.
1399 */
1400 InsertConfigNode(pDevices, "ioapic", &pDev);
1401 InsertConfigNode(pDev, "0", &pInst);
1402 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1403 InsertConfigNode(pInst, "Config", &pCfg);
1404 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
1405 if (enmIommuType == IommuType_AMD)
1406 InsertConfigInteger(pCfg, "PCIAddress", uIoApicPciAddress);
1407 else if (enmIommuType == IommuType_Intel)
1408 {
1409 InsertConfigString(pCfg, "ChipType", "DMAR");
1410 InsertConfigInteger(pCfg, "PCIAddress", uIoApicPciAddress);
1411 }
1412 }
1413 }
1414
1415 /*
1416 * RTC MC146818.
1417 */
1418 InsertConfigNode(pDevices, "mc146818", &pDev);
1419 InsertConfigNode(pDev, "0", &pInst);
1420 InsertConfigNode(pInst, "Config", &pCfg);
1421 BOOL fRTCUseUTC;
1422 hrc = platform->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
1423 InsertConfigInteger(pCfg, "UseUTC", fRTCUseUTC ? 1 : 0);
1424
1425 /*
1426 * VGA.
1427 */
1428 ComPtr<IGraphicsAdapter> pGraphicsAdapter;
1429 hrc = pMachine->COMGETTER(GraphicsAdapter)(pGraphicsAdapter.asOutParam()); H();
1430 GraphicsControllerType_T enmGraphicsController;
1431 hrc = pGraphicsAdapter->COMGETTER(GraphicsControllerType)(&enmGraphicsController); H();
1432 switch (enmGraphicsController)
1433 {
1434 case GraphicsControllerType_Null:
1435 break;
1436#ifdef VBOX_WITH_VMSVGA
1437 case GraphicsControllerType_VMSVGA:
1438 InsertConfigInteger(pHM, "LovelyMesaDrvWorkaround", 1); /* hits someone else logging backdoor. */
1439 InsertConfigInteger(pNEM, "LovelyMesaDrvWorkaround", 1); /* hits someone else logging backdoor. */
1440 RT_FALL_THROUGH();
1441 case GraphicsControllerType_VBoxSVGA:
1442#endif
1443 case GraphicsControllerType_VBoxVGA:
1444 vrc = i_configGraphicsController(pDevices, enmGraphicsController, pBusMgr, pMachine, pGraphicsAdapter, firmwareSettings,
1445 RT_BOOL(fHMEnabled));
1446 if (FAILED(vrc))
1447 return vrc;
1448 break;
1449 default:
1450 AssertMsgFailed(("Invalid graphicsController=%d\n", enmGraphicsController));
1451 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1452 N_("Invalid graphics controller type '%d'"), enmGraphicsController);
1453 }
1454
1455 /*
1456 * Firmware.
1457 */
1458 FirmwareType_T eFwType = FirmwareType_BIOS;
1459 hrc = firmwareSettings->COMGETTER(FirmwareType)(&eFwType); H();
1460
1461#ifdef VBOX_WITH_EFI
1462 BOOL fEfiEnabled = (eFwType >= FirmwareType_EFI) && (eFwType <= FirmwareType_EFIDUAL);
1463#else
1464 BOOL fEfiEnabled = false;
1465#endif
1466 if (!fEfiEnabled)
1467 {
1468 /*
1469 * PC Bios.
1470 */
1471 InsertConfigNode(pDevices, "pcbios", &pDev);
1472 InsertConfigNode(pDev, "0", &pInst);
1473 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1474 InsertConfigNode(pInst, "Config", &pBiosCfg);
1475 InsertConfigInteger(pBiosCfg, "NumCPUs", cCpus);
1476 InsertConfigString(pBiosCfg, "HardDiskDevice", "piix3ide");
1477 InsertConfigString(pBiosCfg, "FloppyDevice", "i82078");
1478 InsertConfigInteger(pBiosCfg, "IOAPIC", fIOAPIC);
1479 InsertConfigInteger(pBiosCfg, "APIC", uFwAPIC);
1480 BOOL fPXEDebug;
1481 hrc = firmwareSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
1482 InsertConfigInteger(pBiosCfg, "PXEDebug", fPXEDebug);
1483 InsertConfigBytes(pBiosCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
1484 BOOL fUuidLe;
1485 hrc = firmwareSettings->COMGETTER(SMBIOSUuidLittleEndian)(&fUuidLe); H();
1486 InsertConfigInteger(pBiosCfg, "UuidLe", fUuidLe);
1487 BOOL fAutoSerialNumGen;
1488 hrc = firmwareSettings->COMGETTER(AutoSerialNumGen)(&fAutoSerialNumGen); H();
1489 if (fAutoSerialNumGen)
1490 InsertConfigString(pBiosCfg, "DmiSystemSerial", "VirtualBox-<DmiSystemUuid>");
1491 InsertConfigNode(pBiosCfg, "NetBoot", &pNetBootCfg);
1492 InsertConfigInteger(pBiosCfg, "McfgBase", uMcfgBase);
1493 InsertConfigInteger(pBiosCfg, "McfgLength", cbMcfgLength);
1494
1495 AssertMsgReturn(SchemaDefs::MaxBootPosition <= 9, ("Too many boot devices %d\n", SchemaDefs::MaxBootPosition),
1496 VERR_INVALID_PARAMETER);
1497
1498 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; ++pos)
1499 {
1500 DeviceType_T enmBootDevice;
1501 hrc = pMachine->GetBootOrder(pos, &enmBootDevice); H();
1502
1503 char szParamName[] = "BootDeviceX";
1504 szParamName[sizeof(szParamName) - 2] = (char)(pos - 1 + '0');
1505
1506 const char *pszBootDevice;
1507 switch (enmBootDevice)
1508 {
1509 case DeviceType_Null:
1510 pszBootDevice = "NONE";
1511 break;
1512 case DeviceType_HardDisk:
1513 pszBootDevice = "IDE";
1514 break;
1515 case DeviceType_DVD:
1516 pszBootDevice = "DVD";
1517 break;
1518 case DeviceType_Floppy:
1519 pszBootDevice = "FLOPPY";
1520 break;
1521 case DeviceType_Network:
1522 pszBootDevice = "LAN";
1523 break;
1524 default:
1525 AssertMsgFailed(("Invalid enmBootDevice=%d\n", enmBootDevice));
1526 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1527 N_("Invalid boot device '%d'"), enmBootDevice);
1528 }
1529 InsertConfigString(pBiosCfg, szParamName, pszBootDevice);
1530 }
1531
1532 /** @todo @bugref{7145}: We might want to enable this by default for new VMs. For now,
1533 * this is required for Windows 2012 guests. */
1534 if (osTypeId == GUEST_OS_ID_STR_X64("Windows2012"))
1535 InsertConfigInteger(pBiosCfg, "DmiExposeMemoryTable", 1); /* boolean */
1536 }
1537 else
1538 {
1539 /* Autodetect firmware type, basing on guest type */
1540 if (eFwType == FirmwareType_EFI)
1541 eFwType = fIsGuest64Bit ? FirmwareType_EFI64 : FirmwareType_EFI32;
1542 bool const f64BitEntry = eFwType == FirmwareType_EFI64;
1543
1544 Assert(eFwType == FirmwareType_EFI64 || eFwType == FirmwareType_EFI32 || eFwType == FirmwareType_EFIDUAL);
1545#ifdef VBOX_WITH_EFI_IN_DD2
1546 const char *pszEfiRomFile = eFwType == FirmwareType_EFIDUAL ? "VBoxEFIDual.fd"
1547 : eFwType == FirmwareType_EFI32 ? "VBoxEFI32.fd"
1548 : "VBoxEFI64.fd";
1549#else
1550 Utf8Str efiRomFile;
1551 vrc = findEfiRom(virtualBox, PlatformArchitecture_x86, eFwType, &efiRomFile);
1552 AssertRCReturn(vrc, vrc);
1553 const char *pszEfiRomFile = efiRomFile.c_str();
1554#endif
1555
1556 /* Get boot args */
1557 Utf8Str bootArgs;
1558 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiBootArgs", &bootArgs);
1559
1560 /* Get device props */
1561 Utf8Str deviceProps;
1562 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiDeviceProps", &deviceProps);
1563
1564 /* Get NVRAM file name */
1565 Utf8Str strNvram = mptrNvramStore->i_getNonVolatileStorageFile();
1566
1567 BOOL fUuidLe;
1568 hrc = firmwareSettings->COMGETTER(SMBIOSUuidLittleEndian)(&fUuidLe); H();
1569
1570 BOOL fAutoSerialNumGen;
1571 hrc = firmwareSettings->COMGETTER(AutoSerialNumGen)(&fAutoSerialNumGen); H();
1572
1573 /* Get graphics mode settings */
1574 uint32_t u32GraphicsMode = UINT32_MAX;
1575 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiGraphicsMode", &strTmp);
1576 if (strTmp.isEmpty())
1577 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiGopMode", &strTmp);
1578 if (!strTmp.isEmpty())
1579 u32GraphicsMode = strTmp.toUInt32();
1580
1581 /* Get graphics resolution settings, with some sanity checking */
1582 Utf8Str strResolution;
1583 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiGraphicsResolution", &strResolution);
1584 if (!strResolution.isEmpty())
1585 {
1586 size_t pos = strResolution.find("x");
1587 if (pos != strResolution.npos)
1588 {
1589 Utf8Str strH, strV;
1590 strH.assignEx(strResolution, 0, pos);
1591 strV.assignEx(strResolution, pos+1, strResolution.length()-pos-1);
1592 uint32_t u32H = strH.toUInt32();
1593 uint32_t u32V = strV.toUInt32();
1594 if (u32H == 0 || u32V == 0)
1595 strResolution.setNull();
1596 }
1597 else
1598 strResolution.setNull();
1599 }
1600 else
1601 {
1602 uint32_t u32H = 0;
1603 uint32_t u32V = 0;
1604 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiHorizontalResolution", &strTmp);
1605 if (strTmp.isEmpty())
1606 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiUgaHorizontalResolution", &strTmp);
1607 if (!strTmp.isEmpty())
1608 u32H = strTmp.toUInt32();
1609
1610 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiVerticalResolution", &strTmp);
1611 if (strTmp.isEmpty())
1612 GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiUgaVerticalResolution", &strTmp);
1613 if (!strTmp.isEmpty())
1614 u32V = strTmp.toUInt32();
1615 if (u32H != 0 && u32V != 0)
1616 strResolution = Utf8StrFmt("%ux%u", u32H, u32V);
1617 }
1618
1619 /*
1620 * EFI subtree.
1621 */
1622 InsertConfigNode(pDevices, "efi", &pDev);
1623 InsertConfigNode(pDev, "0", &pInst);
1624 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1625 InsertConfigNode(pInst, "Config", &pCfg);
1626 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
1627 InsertConfigInteger(pCfg, "McfgBase", uMcfgBase);
1628 InsertConfigInteger(pCfg, "McfgLength", cbMcfgLength);
1629 InsertConfigString(pCfg, "EfiRom", pszEfiRomFile);
1630 InsertConfigString(pCfg, "BootArgs", bootArgs);
1631 InsertConfigString(pCfg, "DeviceProps", deviceProps);
1632 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
1633 InsertConfigInteger(pCfg, "APIC", uFwAPIC);
1634 InsertConfigBytes(pCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
1635 InsertConfigInteger(pCfg, "UuidLe", fUuidLe);
1636 if (fAutoSerialNumGen)
1637 InsertConfigString(pCfg, "DmiSystemSerial", "VirtualBox-<DmiSystemUuid>");
1638 InsertConfigInteger(pCfg, "64BitEntry", f64BitEntry); /* boolean */
1639 InsertConfigString(pCfg, "NvramFile", strNvram);
1640 if (u32GraphicsMode != UINT32_MAX)
1641 InsertConfigInteger(pCfg, "GraphicsMode", u32GraphicsMode);
1642 if (!strResolution.isEmpty())
1643 InsertConfigString(pCfg, "GraphicsResolution", strResolution);
1644
1645 /* For OS X guests we'll force passing host's DMI info to the guest */
1646 if (fOsXGuest)
1647 {
1648 InsertConfigInteger(pCfg, "DmiUseHostInfo", 1);
1649 InsertConfigInteger(pCfg, "DmiExposeMemoryTable", 1);
1650 }
1651
1652 /* Attach the NVRAM storage driver. */
1653 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1654 InsertConfigString(pLunL0, "Driver", "NvramStore");
1655 }
1656
1657 /*
1658 * The USB Controllers.
1659 */
1660 PCFGMNODE pUsbDevices = NULL;
1661 vrc = i_configUsb(pMachine, pBusMgr, pRoot, pDevices, aKbdHID, aPointingHID, &pUsbDevices);
1662
1663 /*
1664 * Storage controllers.
1665 */
1666 bool fFdcEnabled = false;
1667 vrc = i_configStorageCtrls(pMachine, pBusMgr, pVMM, pUVM,
1668 pDevices, pUsbDevices, pBiosCfg, &fFdcEnabled); VRC();
1669
1670 /*
1671 * Network adapters
1672 */
1673#ifdef VMWARE_NET_IN_SLOT_11
1674 bool fSwapSlots3and11 = false;
1675#endif
1676 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1677 InsertConfigNode(pDevices, "pcnet", &pDevPCNet);
1678#ifdef VBOX_WITH_E1000
1679 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1680 InsertConfigNode(pDevices, "e1000", &pDevE1000);
1681#endif
1682#ifdef VBOX_WITH_VIRTIO
1683 PCFGMNODE pDevVirtioNet = NULL; /* Virtio network devices */
1684 InsertConfigNode(pDevices, "virtio-net", &pDevVirtioNet);
1685#endif /* VBOX_WITH_VIRTIO */
1686 PCFGMNODE pDevDP8390 = NULL; /* DP8390-type devices */
1687 InsertConfigNode(pDevices, "dp8390", &pDevDP8390);
1688 PCFGMNODE pDev3C501 = NULL; /* EtherLink-type devices */
1689 InsertConfigNode(pDevices, "3c501", &pDev3C501);
1690
1691 std::list<BootNic> llBootNics;
1692 for (ULONG uInstance = 0; uInstance < maxNetworkAdapters; ++uInstance)
1693 {
1694 ComPtr<INetworkAdapter> networkAdapter;
1695 hrc = pMachine->GetNetworkAdapter(uInstance, networkAdapter.asOutParam()); H();
1696 BOOL fEnabledNetAdapter = FALSE;
1697 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabledNetAdapter); H();
1698 if (!fEnabledNetAdapter)
1699 continue;
1700
1701 /*
1702 * The virtual hardware type. Create appropriate device first.
1703 */
1704 const char *pszAdapterName = "pcnet";
1705 NetworkAdapterType_T adapterType;
1706 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1707 switch (adapterType)
1708 {
1709 case NetworkAdapterType_Am79C970A:
1710 case NetworkAdapterType_Am79C973:
1711 case NetworkAdapterType_Am79C960:
1712 pDev = pDevPCNet;
1713 break;
1714#ifdef VBOX_WITH_E1000
1715 case NetworkAdapterType_I82540EM:
1716 case NetworkAdapterType_I82543GC:
1717 case NetworkAdapterType_I82545EM:
1718 pDev = pDevE1000;
1719 pszAdapterName = "e1000";
1720 break;
1721#endif
1722#ifdef VBOX_WITH_VIRTIO
1723 case NetworkAdapterType_Virtio:
1724 pDev = pDevVirtioNet;
1725 pszAdapterName = "virtio-net";
1726 break;
1727#endif /* VBOX_WITH_VIRTIO */
1728 case NetworkAdapterType_NE1000:
1729 case NetworkAdapterType_NE2000:
1730 case NetworkAdapterType_WD8003:
1731 case NetworkAdapterType_WD8013:
1732 case NetworkAdapterType_ELNK2:
1733 pDev = pDevDP8390;
1734 break;
1735 case NetworkAdapterType_ELNK1:
1736 pDev = pDev3C501;
1737 break;
1738 default:
1739 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'", adapterType, uInstance));
1740 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1741 N_("Invalid network adapter type '%d' for slot '%d'"), adapterType, uInstance);
1742 }
1743
1744 InsertConfigNode(pDev, Utf8StrFmt("%u", uInstance).c_str(), &pInst);
1745 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1746 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1747 * next 4 get 16..19. */
1748 int iPCIDeviceNo;
1749 switch (uInstance)
1750 {
1751 case 0:
1752 iPCIDeviceNo = 3;
1753 break;
1754 case 1: case 2: case 3:
1755 iPCIDeviceNo = uInstance - 1 + 8;
1756 break;
1757 case 4: case 5: case 6: case 7:
1758 iPCIDeviceNo = uInstance - 4 + 16;
1759 break;
1760 default:
1761 /* auto assignment */
1762 iPCIDeviceNo = -1;
1763 break;
1764 }
1765#ifdef VMWARE_NET_IN_SLOT_11
1766 /*
1767 * Dirty hack for PCI slot compatibility with VMWare,
1768 * it assigns slot 0x11 to the first network controller.
1769 */
1770 if (iPCIDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
1771 {
1772 iPCIDeviceNo = 0x11;
1773 fSwapSlots3and11 = true;
1774 }
1775 else if (iPCIDeviceNo == 0x11 && fSwapSlots3and11)
1776 iPCIDeviceNo = 3;
1777#endif
1778 PCIBusAddress PCIAddr = PCIBusAddress(0, iPCIDeviceNo, 0);
1779 hrc = pBusMgr->assignPCIDevice(pszAdapterName, pInst, PCIAddr); H();
1780
1781 InsertConfigNode(pInst, "Config", &pCfg);
1782#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */ /** @todo Make PCNet ring-0 safe on 32-bit mac kernels! */
1783 if (pDev == pDevPCNet)
1784 InsertConfigInteger(pCfg, "R0Enabled", false);
1785#endif
1786 /*
1787 * Collect information needed for network booting and add it to the list.
1788 */
1789 BootNic nic;
1790
1791 nic.mInstance = uInstance;
1792 /* Could be updated by reference, if auto assigned */
1793 nic.mPCIAddress = PCIAddr;
1794
1795 hrc = networkAdapter->COMGETTER(BootPriority)(&nic.mBootPrio); H();
1796
1797 llBootNics.push_back(nic);
1798
1799 /*
1800 * The virtual hardware type. PCNet supports three types, E1000 three,
1801 * but VirtIO only one.
1802 */
1803 switch (adapterType)
1804 {
1805 case NetworkAdapterType_Am79C970A:
1806 InsertConfigString(pCfg, "ChipType", "Am79C970A");
1807 break;
1808 case NetworkAdapterType_Am79C973:
1809 InsertConfigString(pCfg, "ChipType", "Am79C973");
1810 break;
1811 case NetworkAdapterType_Am79C960:
1812 InsertConfigString(pCfg, "ChipType", "Am79C960");
1813 break;
1814 case NetworkAdapterType_I82540EM:
1815 InsertConfigInteger(pCfg, "AdapterType", 0);
1816 break;
1817 case NetworkAdapterType_I82543GC:
1818 InsertConfigInteger(pCfg, "AdapterType", 1);
1819 break;
1820 case NetworkAdapterType_I82545EM:
1821 InsertConfigInteger(pCfg, "AdapterType", 2);
1822 break;
1823 case NetworkAdapterType_Virtio:
1824 break;
1825 case NetworkAdapterType_NE1000:
1826 InsertConfigString(pCfg, "DeviceType", "NE1000");
1827 break;
1828 case NetworkAdapterType_NE2000:
1829 InsertConfigString(pCfg, "DeviceType", "NE2000");
1830 break;
1831 case NetworkAdapterType_WD8003:
1832 InsertConfigString(pCfg, "DeviceType", "WD8003");
1833 break;
1834 case NetworkAdapterType_WD8013:
1835 InsertConfigString(pCfg, "DeviceType", "WD8013");
1836 break;
1837 case NetworkAdapterType_ELNK2:
1838 InsertConfigString(pCfg, "DeviceType", "3C503");
1839 break;
1840 case NetworkAdapterType_ELNK1:
1841 break;
1842 case NetworkAdapterType_Null: AssertFailedBreak(); /* (compiler warnings) */
1843#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
1844 case NetworkAdapterType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
1845#endif
1846 }
1847
1848 /*
1849 * Get the MAC address and convert it to binary representation
1850 */
1851 Bstr macAddr;
1852 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1853 Assert(!macAddr.isEmpty());
1854 Utf8Str macAddrUtf8 = macAddr;
1855#ifdef VBOX_WITH_CLOUD_NET
1856 NetworkAttachmentType_T eAttachmentType;
1857 hrc = networkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
1858 if (eAttachmentType == NetworkAttachmentType_Cloud)
1859 {
1860 mGateway.setLocalMacAddress(macAddrUtf8);
1861 /* We'll insert cloud MAC later, when it becomes known. */
1862 }
1863 else
1864 {
1865#endif
1866 char *macStr = (char*)macAddrUtf8.c_str();
1867 Assert(strlen(macStr) == 12);
1868 RTMAC Mac;
1869 RT_ZERO(Mac);
1870 char *pMac = (char*)&Mac;
1871 for (uint32_t i = 0; i < 6; ++i)
1872 {
1873 int c1 = *macStr++ - '0';
1874 if (c1 > 9)
1875 c1 -= 7;
1876 int c2 = *macStr++ - '0';
1877 if (c2 > 9)
1878 c2 -= 7;
1879 *pMac++ = (char)(((c1 & 0x0f) << 4) | (c2 & 0x0f));
1880 }
1881 InsertConfigBytes(pCfg, "MAC", &Mac, sizeof(Mac));
1882#ifdef VBOX_WITH_CLOUD_NET
1883 }
1884#endif
1885 /*
1886 * Check if the cable is supposed to be unplugged
1887 */
1888 BOOL fCableConnected;
1889 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1890 InsertConfigInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0);
1891
1892 /*
1893 * Line speed to report from custom drivers
1894 */
1895 ULONG ulLineSpeed;
1896 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1897 InsertConfigInteger(pCfg, "LineSpeed", ulLineSpeed);
1898
1899 /*
1900 * Attach the status driver.
1901 */
1902 i_attachStatusDriver(pInst, DeviceType_Network);
1903
1904 /*
1905 * Configure the network card now
1906 */
1907 bool fIgnoreConnectFailure = mMachineState == MachineState_Restoring;
1908 vrc = i_configNetwork(pszAdapterName,
1909 uInstance,
1910 0,
1911 networkAdapter,
1912 pCfg,
1913 pLunL0,
1914 pInst,
1915 false /*fAttachDetach*/,
1916 fIgnoreConnectFailure,
1917 pUVM,
1918 pVMM);
1919 if (RT_FAILURE(vrc))
1920 return vrc;
1921 }
1922
1923 /*
1924 * Build network boot information and transfer it to the BIOS.
1925 */
1926 if (pNetBootCfg && !llBootNics.empty()) /* NetBoot node doesn't exist for EFI! */
1927 {
1928 llBootNics.sort(); /* Sort the list by boot priority. */
1929
1930 char achBootIdx[] = "0";
1931 unsigned uBootIdx = 0;
1932
1933 for (std::list<BootNic>::iterator it = llBootNics.begin(); it != llBootNics.end(); ++it)
1934 {
1935 /* A NIC with priority 0 is only used if it's first in the list. */
1936 if (it->mBootPrio == 0 && uBootIdx != 0)
1937 break;
1938
1939 PCFGMNODE pNetBtDevCfg;
1940 achBootIdx[0] = (char)('0' + uBootIdx++); /* Boot device order. */
1941 InsertConfigNode(pNetBootCfg, achBootIdx, &pNetBtDevCfg);
1942 InsertConfigInteger(pNetBtDevCfg, "NIC", it->mInstance);
1943 InsertConfigInteger(pNetBtDevCfg, "PCIBusNo", it->mPCIAddress.miBus);
1944 InsertConfigInteger(pNetBtDevCfg, "PCIDeviceNo", it->mPCIAddress.miDevice);
1945 InsertConfigInteger(pNetBtDevCfg, "PCIFunctionNo", it->mPCIAddress.miFn);
1946 }
1947 }
1948
1949 /*
1950 * Serial (UART) Ports
1951 */
1952 /* serial enabled mask to be passed to dev ACPI */
1953 uint16_t auSerialIoPortBase[SchemaDefs::SerialPortCount] = {0};
1954 uint8_t auSerialIrq[SchemaDefs::SerialPortCount] = {0};
1955 InsertConfigNode(pDevices, "serial", &pDev);
1956 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ++ulInstance)
1957 {
1958 ComPtr<ISerialPort> serialPort;
1959 hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam()); H();
1960 BOOL fEnabledSerPort = FALSE;
1961 if (serialPort)
1962 {
1963 hrc = serialPort->COMGETTER(Enabled)(&fEnabledSerPort); H();
1964 }
1965 if (!fEnabledSerPort)
1966 {
1967 m_aeSerialPortMode[ulInstance] = PortMode_Disconnected;
1968 continue;
1969 }
1970
1971 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
1972 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1973 InsertConfigNode(pInst, "Config", &pCfg);
1974
1975 ULONG ulIRQ;
1976 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1977 InsertConfigInteger(pCfg, "IRQ", ulIRQ);
1978 auSerialIrq[ulInstance] = (uint8_t)ulIRQ;
1979
1980 ULONG ulIOBase;
1981 hrc = serialPort->COMGETTER(IOAddress)(&ulIOBase); H();
1982 InsertConfigInteger(pCfg, "IOAddress", ulIOBase);
1983 auSerialIoPortBase[ulInstance] = (uint16_t)ulIOBase;
1984
1985 BOOL fServer;
1986 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1987 hrc = serialPort->COMGETTER(Path)(bstr.asOutParam()); H();
1988 UartType_T eUartType;
1989 const char *pszUartType;
1990 hrc = serialPort->COMGETTER(UartType)(&eUartType); H();
1991 switch (eUartType)
1992 {
1993 case UartType_U16450: pszUartType = "16450"; break;
1994 case UartType_U16750: pszUartType = "16750"; break;
1995 default: AssertFailed(); RT_FALL_THRU();
1996 case UartType_U16550A: pszUartType = "16550A"; break;
1997 }
1998 InsertConfigString(pCfg, "UartType", pszUartType);
1999
2000 PortMode_T eHostMode;
2001 hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
2002
2003 m_aeSerialPortMode[ulInstance] = eHostMode;
2004 if (eHostMode != PortMode_Disconnected)
2005 {
2006 vrc = i_configSerialPort(pInst, eHostMode, Utf8Str(bstr).c_str(), RT_BOOL(fServer));
2007 if (RT_FAILURE(vrc))
2008 return vrc;
2009 }
2010 }
2011
2012 /*
2013 * Parallel (LPT) Ports
2014 */
2015 /* parallel enabled mask to be passed to dev ACPI */
2016 uint16_t auParallelIoPortBase[SchemaDefs::ParallelPortCount] = {0};
2017 uint8_t auParallelIrq[SchemaDefs::ParallelPortCount] = {0};
2018 InsertConfigNode(pDevices, "parallel", &pDev);
2019 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ++ulInstance)
2020 {
2021 ComPtr<IParallelPort> parallelPort;
2022 hrc = pMachine->GetParallelPort(ulInstance, parallelPort.asOutParam()); H();
2023 BOOL fEnabledParPort = FALSE;
2024 if (parallelPort)
2025 {
2026 hrc = parallelPort->COMGETTER(Enabled)(&fEnabledParPort); H();
2027 }
2028 if (!fEnabledParPort)
2029 continue;
2030
2031 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
2032 InsertConfigNode(pInst, "Config", &pCfg);
2033
2034 ULONG ulIRQ;
2035 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
2036 InsertConfigInteger(pCfg, "IRQ", ulIRQ);
2037 auParallelIrq[ulInstance] = (uint8_t)ulIRQ;
2038 ULONG ulIOBase;
2039 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
2040 InsertConfigInteger(pCfg, "IOBase", ulIOBase);
2041 auParallelIoPortBase[ulInstance] = (uint16_t)ulIOBase;
2042
2043 hrc = parallelPort->COMGETTER(Path)(bstr.asOutParam()); H();
2044 if (!bstr.isEmpty())
2045 {
2046 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2047 InsertConfigString(pLunL0, "Driver", "HostParallel");
2048 InsertConfigNode(pLunL0, "Config", &pLunL1);
2049 InsertConfigString(pLunL1, "DevicePath", bstr);
2050 }
2051 }
2052
2053 vrc = i_configVmmDev(pMachine, pBusMgr, pDevices); VRC();
2054
2055 /*
2056 * Audio configuration.
2057 */
2058 bool fAudioEnabled = false;
2059 vrc = i_configAudioCtrl(virtualBox, pMachine, pBusMgr, pDevices,
2060 fOsXGuest, &fAudioEnabled); VRC();
2061
2062#if defined(VBOX_WITH_TPM)
2063 /*
2064 * Configure the Trusted Platform Module.
2065 */
2066 ComObjPtr<ITrustedPlatformModule> ptrTpm;
2067 TpmType_T enmTpmType = TpmType_None;
2068
2069 hrc = pMachine->COMGETTER(TrustedPlatformModule)(ptrTpm.asOutParam()); H();
2070 hrc = ptrTpm->COMGETTER(Type)(&enmTpmType); H();
2071 if (enmTpmType != TpmType_None)
2072 {
2073 InsertConfigNode(pDevices, "tpm", &pDev);
2074 InsertConfigNode(pDev, "0", &pInst);
2075 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2076 InsertConfigNode(pInst, "Config", &pCfg);
2077 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2078
2079 switch (enmTpmType)
2080 {
2081 case TpmType_v1_2:
2082 case TpmType_v2_0:
2083 InsertConfigString(pLunL0, "Driver", "TpmEmuTpms");
2084 InsertConfigNode(pLunL0, "Config", &pCfg);
2085 InsertConfigInteger(pCfg, "TpmVersion", enmTpmType == TpmType_v1_2 ? 1 : 2);
2086 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2087 InsertConfigString(pLunL1, "Driver", "NvramStore");
2088 break;
2089 case TpmType_Host:
2090#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
2091 InsertConfigString(pLunL0, "Driver", "TpmHost");
2092 InsertConfigNode(pLunL0, "Config", &pCfg);
2093#endif
2094 break;
2095 case TpmType_Swtpm:
2096 hrc = ptrTpm->COMGETTER(Location)(bstr.asOutParam()); H();
2097 InsertConfigString(pLunL0, "Driver", "TpmEmu");
2098 InsertConfigNode(pLunL0, "Config", &pCfg);
2099 InsertConfigString(pCfg, "Location", bstr);
2100 break;
2101 default:
2102 AssertFailedBreak();
2103 }
2104 }
2105#endif
2106
2107 /*
2108 * ACPI
2109 */
2110 BOOL fACPI;
2111 hrc = firmwareSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
2112 if (fACPI)
2113 {
2114 /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
2115 * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
2116 * intelppm driver refuses to register an idle state handler.
2117 * Always show CPU leafs for OS X guests. */
2118 BOOL fShowCpu = fOsXGuest;
2119 if (cCpus > 1 || fIOAPIC)
2120 fShowCpu = true;
2121
2122 BOOL fCpuHotPlug;
2123 hrc = pMachine->COMGETTER(CPUHotPlugEnabled)(&fCpuHotPlug); H();
2124
2125 InsertConfigNode(pDevices, "acpi", &pDev);
2126 InsertConfigNode(pDev, "0", &pInst);
2127 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2128 InsertConfigNode(pInst, "Config", &pCfg);
2129 hrc = pBusMgr->assignPCIDevice("acpi", pInst); H();
2130
2131 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
2132
2133 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
2134 InsertConfigInteger(pCfg, "FdcEnabled", fFdcEnabled);
2135 InsertConfigInteger(pCfg, "HpetEnabled", fHPETEnabled);
2136 InsertConfigInteger(pCfg, "SmcEnabled", fSmcEnabled);
2137 InsertConfigInteger(pCfg, "ShowRtc", fShowRtc);
2138 if (fOsXGuest && !llBootNics.empty())
2139 {
2140 BootNic aNic = llBootNics.front();
2141 uint32_t u32NicPCIAddr = (aNic.mPCIAddress.miDevice << 16) | aNic.mPCIAddress.miFn;
2142 InsertConfigInteger(pCfg, "NicPciAddress", u32NicPCIAddr);
2143 }
2144 if (fOsXGuest && fAudioEnabled)
2145 {
2146 PCIBusAddress Address;
2147 if (pBusMgr->findPCIAddress("hda", 0, Address))
2148 {
2149 uint32_t u32AudioPCIAddr = (Address.miDevice << 16) | Address.miFn;
2150 InsertConfigInteger(pCfg, "AudioPciAddress", u32AudioPCIAddr);
2151 }
2152 }
2153 if (fOsXGuest)
2154 {
2155 PCIBusAddress Address;
2156 if (pBusMgr->findPCIAddress("nvme", 0, Address))
2157 {
2158 uint32_t u32NvmePCIAddr = (Address.miDevice << 16) | Address.miFn;
2159 InsertConfigInteger(pCfg, "NvmePciAddress", u32NvmePCIAddr);
2160 }
2161 }
2162 if (enmIommuType == IommuType_AMD)
2163 {
2164 PCIBusAddress Address;
2165 if (pBusMgr->findPCIAddress("iommu-amd", 0, Address))
2166 {
2167 uint32_t u32IommuAddress = (Address.miDevice << 16) | Address.miFn;
2168 InsertConfigInteger(pCfg, "IommuAmdEnabled", true);
2169 InsertConfigInteger(pCfg, "IommuPciAddress", u32IommuAddress);
2170 if (pBusMgr->findPCIAddress("sb-ioapic", 0, Address))
2171 {
2172 uint32_t const u32SbIoapicAddress = (Address.miDevice << 16) | Address.miFn;
2173 InsertConfigInteger(pCfg, "SbIoApicPciAddress", u32SbIoapicAddress);
2174 }
2175 else
2176 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
2177 N_("AMD IOMMU is enabled, but the I/O APIC is not assigned a PCI address!"));
2178 }
2179 }
2180 else if (enmIommuType == IommuType_Intel)
2181 {
2182 PCIBusAddress Address;
2183 if (pBusMgr->findPCIAddress("iommu-intel", 0, Address))
2184 {
2185 uint32_t u32IommuAddress = (Address.miDevice << 16) | Address.miFn;
2186 InsertConfigInteger(pCfg, "IommuIntelEnabled", true);
2187 InsertConfigInteger(pCfg, "IommuPciAddress", u32IommuAddress);
2188 if (pBusMgr->findPCIAddress("sb-ioapic", 0, Address))
2189 {
2190 uint32_t const u32SbIoapicAddress = (Address.miDevice << 16) | Address.miFn;
2191 InsertConfigInteger(pCfg, "SbIoApicPciAddress", u32SbIoapicAddress);
2192 }
2193 else
2194 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
2195 N_("Intel IOMMU is enabled, but the I/O APIC is not assigned a PCI address!"));
2196 }
2197 }
2198
2199 InsertConfigInteger(pCfg, "IocPciAddress", uIocPCIAddress);
2200 if (chipsetType == ChipsetType_ICH9)
2201 {
2202 InsertConfigInteger(pCfg, "McfgBase", uMcfgBase);
2203 InsertConfigInteger(pCfg, "McfgLength", cbMcfgLength);
2204 /* 64-bit prefetch window root resource: Only for ICH9 and if PAE or Long Mode is enabled (@bugref{5454}). */
2205 if (fIsGuest64Bit || fEnablePAE)
2206 InsertConfigInteger(pCfg, "PciPref64Enabled", 1);
2207 }
2208 InsertConfigInteger(pCfg, "HostBusPciAddress", uHbcPCIAddress);
2209 InsertConfigInteger(pCfg, "ShowCpu", fShowCpu);
2210 InsertConfigInteger(pCfg, "CpuHotPlug", fCpuHotPlug);
2211
2212 InsertConfigInteger(pCfg, "Serial0IoPortBase", auSerialIoPortBase[0]);
2213 InsertConfigInteger(pCfg, "Serial0Irq", auSerialIrq[0]);
2214
2215 InsertConfigInteger(pCfg, "Serial1IoPortBase", auSerialIoPortBase[1]);
2216 InsertConfigInteger(pCfg, "Serial1Irq", auSerialIrq[1]);
2217
2218 if (auSerialIoPortBase[2])
2219 {
2220 InsertConfigInteger(pCfg, "Serial2IoPortBase", auSerialIoPortBase[2]);
2221 InsertConfigInteger(pCfg, "Serial2Irq", auSerialIrq[2]);
2222 }
2223
2224 if (auSerialIoPortBase[3])
2225 {
2226 InsertConfigInteger(pCfg, "Serial3IoPortBase", auSerialIoPortBase[3]);
2227 InsertConfigInteger(pCfg, "Serial3Irq", auSerialIrq[3]);
2228 }
2229
2230 InsertConfigInteger(pCfg, "Parallel0IoPortBase", auParallelIoPortBase[0]);
2231 InsertConfigInteger(pCfg, "Parallel0Irq", auParallelIrq[0]);
2232
2233 InsertConfigInteger(pCfg, "Parallel1IoPortBase", auParallelIoPortBase[1]);
2234 InsertConfigInteger(pCfg, "Parallel1Irq", auParallelIrq[1]);
2235
2236#if defined(VBOX_WITH_TPM)
2237 switch (enmTpmType)
2238 {
2239 case TpmType_v1_2:
2240 InsertConfigString(pCfg, "TpmMode", "tis1.2");
2241 break;
2242 case TpmType_v2_0:
2243 InsertConfigString(pCfg, "TpmMode", "fifo2.0");
2244 break;
2245 /** @todo Host and swtpm. */
2246 default:
2247 break;
2248 }
2249#endif
2250
2251 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2252 InsertConfigString(pLunL0, "Driver", "ACPIHost");
2253 InsertConfigNode(pLunL0, "Config", &pCfg);
2254
2255 /* Attach the dummy CPU drivers */
2256 for (ULONG iCpuCurr = 1; iCpuCurr < cCpus; iCpuCurr++)
2257 {
2258 BOOL fCpuAttached = true;
2259
2260 if (fCpuHotPlug)
2261 {
2262 hrc = pMachine->GetCPUStatus(iCpuCurr, &fCpuAttached); H();
2263 }
2264
2265 if (fCpuAttached)
2266 {
2267 InsertConfigNode(pInst, Utf8StrFmt("LUN#%u", iCpuCurr).c_str(), &pLunL0);
2268 InsertConfigString(pLunL0, "Driver", "ACPICpu");
2269 InsertConfigNode(pLunL0, "Config", &pCfg);
2270 }
2271 }
2272 }
2273
2274 /*
2275 * Configure DBGF (Debug(ger) Facility) and DBGC (Debugger Console).
2276 */
2277 vrc = i_configGuestDbg(virtualBox, pMachine, pRoot); VRC();
2278 }
2279 catch (ConfigError &x)
2280 {
2281 // InsertConfig threw something:
2282 pVMM->pfnVMR3SetError(pUVM, x.m_vrc, RT_SRC_POS, "Caught ConfigError: %Rrc - %s", x.m_vrc, x.what());
2283 return x.m_vrc;
2284 }
2285 catch (HRESULT hrcXcpt)
2286 {
2287 AssertLogRelMsgFailedReturn(("hrc=%Rhrc\n", hrcXcpt), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR);
2288 }
2289
2290#ifdef VBOX_WITH_EXTPACK
2291 /*
2292 * Call the extension pack hooks if everything went well thus far.
2293 */
2294 if (RT_SUCCESS(vrc))
2295 {
2296 pAlock->release();
2297 vrc = mptrExtPackManager->i_callAllVmConfigureVmmHooks(this, pVM, pVMM);
2298 pAlock->acquire();
2299 }
2300#endif
2301
2302 /*
2303 * Apply the CFGM overlay.
2304 */
2305 if (RT_SUCCESS(vrc))
2306 vrc = i_configCfgmOverlay(pRoot, virtualBox, pMachine);
2307
2308 /*
2309 * Dump all extradata API settings tweaks, both global and per VM.
2310 */
2311 if (RT_SUCCESS(vrc))
2312 vrc = i_configDumpAPISettingsTweaks(virtualBox, pMachine);
2313
2314#undef H
2315
2316 pAlock->release(); /* Avoid triggering the lock order inversion check. */
2317
2318 /*
2319 * Register VM state change handler.
2320 */
2321 int vrc2 = pVMM->pfnVMR3AtStateRegister(pUVM, Console::i_vmstateChangeCallback, this);
2322 AssertRC(vrc2);
2323 if (RT_SUCCESS(vrc))
2324 vrc = vrc2;
2325
2326 /*
2327 * Register VM runtime error handler.
2328 */
2329 vrc2 = pVMM->pfnVMR3AtRuntimeErrorRegister(pUVM, Console::i_atVMRuntimeErrorCallback, this);
2330 AssertRC(vrc2);
2331 if (RT_SUCCESS(vrc))
2332 vrc = vrc2;
2333
2334 pAlock->acquire();
2335
2336 LogFlowFunc(("vrc = %Rrc\n", vrc));
2337 LogFlowFuncLeave();
2338
2339 return vrc;
2340}
2341
2342
2343int Console::i_configGraphicsController(PCFGMNODE pDevices,
2344 const GraphicsControllerType_T enmGraphicsController,
2345 BusAssignmentManager *pBusMgr,
2346 const ComPtr<IMachine> &ptrMachine,
2347 const ComPtr<IGraphicsAdapter> &ptrGraphicsAdapter,
2348 const ComPtr<IFirmwareSettings> &ptrFirmwareSettings,
2349 bool fHMEnabled)
2350{
2351 // InsertConfig* throws
2352 try
2353 {
2354 PCFGMNODE pDev, pInst, pCfg, pLunL0;
2355 HRESULT hrc;
2356 Bstr bstr;
2357 const char *pcszDevice = "vga";
2358
2359#define H() AssertLogRelMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR)
2360 InsertConfigNode(pDevices, pcszDevice, &pDev);
2361 InsertConfigNode(pDev, "0", &pInst);
2362 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2363
2364 hrc = pBusMgr->assignPCIDevice(pcszDevice, pInst); H();
2365 InsertConfigNode(pInst, "Config", &pCfg);
2366 ULONG cVRamMBs;
2367 hrc = ptrGraphicsAdapter->COMGETTER(VRAMSize)(&cVRamMBs); H();
2368 InsertConfigInteger(pCfg, "VRamSize", cVRamMBs * _1M);
2369 ULONG cMonitorCount;
2370 hrc = ptrGraphicsAdapter->COMGETTER(MonitorCount)(&cMonitorCount); H();
2371 InsertConfigInteger(pCfg, "MonitorCount", cMonitorCount);
2372#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
2373 InsertConfigInteger(pCfg, "R0Enabled", fHMEnabled);
2374#else
2375 NOREF(fHMEnabled);
2376#endif
2377 BOOL f3DEnabled;
2378 hrc = ptrGraphicsAdapter->COMGETTER(Accelerate3DEnabled)(&f3DEnabled); H();
2379 InsertConfigInteger(pCfg, "3DEnabled", f3DEnabled);
2380
2381 i_attachStatusDriver(pInst, DeviceType_Graphics3D);
2382
2383#ifdef VBOX_WITH_VMSVGA
2384 if ( enmGraphicsController == GraphicsControllerType_VMSVGA
2385 || enmGraphicsController == GraphicsControllerType_VBoxSVGA)
2386 {
2387 InsertConfigInteger(pCfg, "VMSVGAEnabled", true);
2388 if (enmGraphicsController == GraphicsControllerType_VMSVGA)
2389 {
2390 InsertConfigInteger(pCfg, "VMSVGAPciBarLayout", true);
2391 InsertConfigInteger(pCfg, "VMSVGAPciId", true);
2392 }
2393# ifdef VBOX_WITH_VMSVGA3D
2394 InsertConfigInteger(pCfg, "VMSVGA3dEnabled", f3DEnabled);
2395# else
2396 LogRel(("VMSVGA3d not available in this build!\n"));
2397# endif /* VBOX_WITH_VMSVGA3D */
2398 }
2399#else
2400 RT_NOREF(enmGraphicsController);
2401#endif /* VBOX_WITH_VMSVGA */
2402
2403 /* Custom VESA mode list */
2404 unsigned cModes = 0;
2405 for (unsigned iMode = 1; iMode <= 16; ++iMode)
2406 {
2407 char szExtraDataKey[sizeof("CustomVideoModeXX")];
2408 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%u", iMode);
2409 hrc = ptrMachine->GetExtraData(Bstr(szExtraDataKey).raw(), bstr.asOutParam()); H();
2410 if (bstr.isEmpty())
2411 break;
2412 InsertConfigString(pCfg, szExtraDataKey, bstr);
2413 ++cModes;
2414 }
2415 InsertConfigInteger(pCfg, "CustomVideoModes", cModes);
2416
2417 /* VESA height reduction */
2418 ULONG ulHeightReduction;
2419 IFramebuffer *pFramebuffer = NULL;
2420 hrc = i_getDisplay()->QueryFramebuffer(0, &pFramebuffer);
2421 if (SUCCEEDED(hrc) && pFramebuffer)
2422 {
2423 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
2424 pFramebuffer->Release();
2425 pFramebuffer = NULL;
2426 }
2427 else
2428 {
2429 /* If framebuffer is not available, there is no height reduction. */
2430 ulHeightReduction = 0;
2431 }
2432 InsertConfigInteger(pCfg, "HeightReduction", ulHeightReduction);
2433
2434 /*
2435 * BIOS logo
2436 */
2437 BOOL fFadeIn;
2438 hrc = ptrFirmwareSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
2439 InsertConfigInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0);
2440 BOOL fFadeOut;
2441 hrc = ptrFirmwareSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
2442 InsertConfigInteger(pCfg, "FadeOut", fFadeOut ? 1: 0);
2443 ULONG logoDisplayTime;
2444 hrc = ptrFirmwareSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
2445 InsertConfigInteger(pCfg, "LogoTime", logoDisplayTime);
2446 Bstr bstrLogoImagePath;
2447 hrc = ptrFirmwareSettings->COMGETTER(LogoImagePath)(bstrLogoImagePath.asOutParam()); H();
2448 InsertConfigString(pCfg, "LogoFile", bstrLogoImagePath);
2449
2450 /*
2451 * Boot menu
2452 */
2453 FirmwareBootMenuMode_T enmBootMenuMode;
2454 int iShowBootMenu;
2455 hrc = ptrFirmwareSettings->COMGETTER(BootMenuMode)(&enmBootMenuMode); H();
2456 switch (enmBootMenuMode)
2457 {
2458 case FirmwareBootMenuMode_Disabled: iShowBootMenu = 0; break;
2459 case FirmwareBootMenuMode_MenuOnly: iShowBootMenu = 1; break;
2460 default: iShowBootMenu = 2; break;
2461 }
2462 InsertConfigInteger(pCfg, "ShowBootMenu", iShowBootMenu);
2463
2464 /* Attach the display. */
2465 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2466 InsertConfigString(pLunL0, "Driver", "MainDisplay");
2467 InsertConfigNode(pLunL0, "Config", &pCfg);
2468 }
2469 catch (ConfigError &x)
2470 {
2471 // InsertConfig threw something:
2472 return x.m_vrc;
2473 }
2474
2475#undef H
2476
2477 return VINF_SUCCESS;
2478}
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