VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/ConsoleImplConfigArmV8.cpp@ 108973

Last change on this file since 108973 was 108973, checked in by vboxsync, 6 weeks ago

Main: bugref:10877 Add GIC ITS setting to the VM configuration and API.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 53.0 KB
Line 
1/* $Id: ConsoleImplConfigArmV8.cpp 108973 2025-04-15 09:01:23Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation - VM Configuration Bits for ARMv8.
4 */
5
6/*
7 * Copyright (C) 2023-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.215389.xyz.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_MAIN_CONSOLE
33#include "LoggingNew.h"
34
35#include "ConsoleImpl.h"
36#include "ResourceStoreImpl.h"
37#include "Global.h"
38#include "VMMDev.h"
39
40// generated header
41#include "SchemaDefs.h"
42
43#include "AutoCaller.h"
44
45#include <iprt/buildconfig.h>
46#include <iprt/ctype.h>
47#include <iprt/dir.h>
48#include <iprt/fdt.h>
49#include <iprt/file.h>
50#include <iprt/param.h>
51#include <iprt/path.h>
52#include <iprt/string.h>
53#include <iprt/system.h>
54#if 0 /* enable to play with lots of memory. */
55# include <iprt/env.h>
56#endif
57#include <iprt/stream.h>
58
59#include <iprt/formats/arm-psci.h>
60
61#include <VBox/vmm/vmmr3vtable.h>
62#include <VBox/vmm/vmapi.h>
63#include <VBox/err.h>
64#include <VBox/gic.h>
65#include <VBox/param.h>
66#include <VBox/version.h>
67#include <VBox/platforms/vbox-armv8.h>
68
69#include "BusAssignmentManager.h"
70#include "ResourceAssignmentManager.h"
71#include "SystemTableBuilder.h"
72#ifdef VBOX_WITH_EXTPACK
73# include "ExtPackManagerImpl.h"
74#endif
75
76
77/*********************************************************************************************************************************
78* Internal Functions *
79*********************************************************************************************************************************/
80
81/* Darwin compile kludge */
82#undef PVM
83
84#ifdef VBOX_WITH_VIRT_ARMV8
85/**
86 * Worker for configConstructor.
87 *
88 * @return VBox status code.
89 * @param pUVM The user mode VM handle.
90 * @param pVM The cross context VM handle.
91 * @param pVMM The VMM vtable.
92 * @param pAlock The automatic lock instance. This is for when we have
93 * to leave it in order to avoid deadlocks (ext packs and
94 * more).
95 */
96int Console::i_configConstructorArmV8(PUVM pUVM, PVM pVM, PCVMMR3VTABLE pVMM, AutoWriteLock *pAlock)
97{
98 RT_NOREF(pVM /* when everything is disabled */);
99 ComPtr<IMachine> pMachine = i_machine();
100
101 HRESULT hrc;
102 Utf8Str strTmp;
103 Bstr bstr;
104
105 RTFDT hFdt = NIL_RTFDT;
106 int vrc = RTFdtCreateEmpty(&hFdt);
107 AssertRCReturn(vrc, vrc);
108
109#define H() AssertLogRelMsgReturnStmt(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), RTFdtDestroy(hFdt), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR)
110#define VRC() AssertLogRelMsgReturnStmt(RT_SUCCESS(vrc), ("vrc=%Rrc\n", vrc), RTFdtDestroy(hFdt), vrc)
111
112 /*
113 * Get necessary objects and frequently used parameters.
114 */
115 ComPtr<IVirtualBox> virtualBox;
116 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
117
118 ComPtr<IHost> host;
119 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
120
121 PlatformArchitecture_T platformArchHost;
122 hrc = host->COMGETTER(Architecture)(&platformArchHost); H();
123
124 ComPtr<ISystemProperties> systemProperties;
125 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
126
127 ComPtr<IFirmwareSettings> firmwareSettings;
128 hrc = pMachine->COMGETTER(FirmwareSettings)(firmwareSettings.asOutParam()); H();
129
130 ComPtr<INvramStore> nvramStore;
131 hrc = pMachine->COMGETTER(NonVolatileStore)(nvramStore.asOutParam()); H();
132
133 hrc = pMachine->COMGETTER(HardwareUUID)(bstr.asOutParam()); H();
134 RTUUID HardwareUuid;
135 vrc = RTUuidFromUtf16(&HardwareUuid, bstr.raw());
136 AssertRCReturn(vrc, vrc);
137
138 ULONG cRamMBs;
139 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
140 uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
141
142 ComPtr<IPlatform> platform;
143 hrc = pMachine->COMGETTER(Platform)(platform.asOutParam()); H();
144
145 /* Note: Should be guarded by VBOX_WITH_VIRT_ARMV8, but we check this anyway here.
146 Update: It is guarded by VBOX_WITH_VIRT_ARMV8, see line 84 and caller. Duh. */
147#if 0 /* For now we only support running ARM VMs on ARM hosts. */
148 PlatformArchitecture_T platformArchMachine;
149 hrc = platform->COMGETTER(Architecture)(&platformArchMachine); H();
150 if (platformArchMachine != platformArchHost)
151 return pVMM->pfnVMR3SetError(pUVM, VERR_PLATFORM_ARCH_NOT_SUPPORTED, RT_SRC_POS,
152 N_("VM platform architecture (%s) not supported on this host (%s)."),
153 Global::stringifyPlatformArchitecture(platformArchMachine),
154 Global::stringifyPlatformArchitecture(platformArchHost));
155#endif
156
157 /* Get the ARM platform object. */
158 ComPtr<IPlatformARM> platformARM;
159 hrc = platform->COMGETTER(ARM)(platformARM.asOutParam()); H();
160
161 ComPtr<IPlatformProperties> pPlatformProperties;
162 hrc = platform->COMGETTER(Properties)(pPlatformProperties.asOutParam()); H();
163
164 ChipsetType_T chipsetType;
165 hrc = platform->COMGETTER(ChipsetType)(&chipsetType); H();
166
167 ULONG cCpus = 1;
168 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
169 Assert(cCpus);
170
171 ULONG ulCpuExecutionCap = 100;
172 hrc = pMachine->COMGETTER(CPUExecutionCap)(&ulCpuExecutionCap); H();
173
174 VMExecutionEngine_T enmExecEngine = VMExecutionEngine_NotSet;
175 hrc = pMachine->COMGETTER(VMExecutionEngine)(&enmExecEngine); H();
176
177 if ( enmExecEngine != VMExecutionEngine_Default
178 && enmExecEngine != VMExecutionEngine_NativeApi)
179 {
180 return pVMM->pfnVMR3SetError(pUVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
181 N_("The ARM backend doesn't support any other execution engine than 'default' or 'native-api' right now."));
182 }
183
184 LogRel(("Guest architecture: ARM\n"));
185
186 Bstr osTypeId;
187 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
188 LogRel(("Guest OS type: '%s'\n", Utf8Str(osTypeId).c_str()));
189
190 BusAssignmentManager *pBusMgr = mBusMgr = BusAssignmentManager::createInstance(pVMM, chipsetType, IommuType_None);
191 ResourceAssignmentManager *pResMgr = ResourceAssignmentManager::createInstance(pVMM, chipsetType, IommuType_None, 32 /*cInterrupts*/,
192 _4G); /* Start looking for free MMIO regions at 4GiB downwards. */
193 SystemTableBuilder *pSysTblsBldAcpi = NULL;
194
195 /*
196 * ACPI
197 */
198 BOOL fACPI;
199 hrc = firmwareSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
200 if (fACPI)
201 pSysTblsBldAcpi = SystemTableBuilder::createInstance(kSystemTableType_Acpi);
202
203
204 /*
205 * Get root node first.
206 * This is the only node in the tree.
207 */
208 PCFGMNODE pRoot = pVMM->pfnCFGMR3GetRootU(pUVM);
209 Assert(pRoot);
210
211 /*
212 * The VBox platform descriptor, FDT and ACPI tables will reside at the end of the 4GiB
213 * address space and we reserve 2MiB for those.
214 */
215 RTGCPHYS cbPlatformDesc = _2M;
216 RTGCPHYS GCPhysPlatformDesc = VBOXPLATFORMARMV8_PHYS_ADDR - (cbPlatformDesc - _64K);
217
218 RTGCPHYS GCPhysRamBase = 128 * _1M;
219 RTGCPHYS cbRamBase = RT_MIN(cbRam, _4G - _512M - 128 * _1M);
220
221 RTGCPHYS GCPhysFw = 0;
222 RTGCPHYS cbFw = _64M;
223
224 // catching throws from InsertConfigString and friends.
225 try
226 {
227
228 /*
229 * Set the root (and VMM) level values.
230 */
231 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
232 InsertConfigString(pRoot, "Name", bstr);
233 InsertConfigBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid));
234 InsertConfigInteger(pRoot, "NumCPUs", cCpus);
235 InsertConfigInteger(pRoot, "CpuExecutionCap", ulCpuExecutionCap);
236 InsertConfigInteger(pRoot, "TimerMillies", 10);
237
238 /*
239 * NEM
240 */
241 PCFGMNODE pNEM;
242 InsertConfigNode(pRoot, "NEM", &pNEM);
243
244 uint32_t idPHandleIntCtrl = RTFdtPHandleAllocate(hFdt);
245 Assert(idPHandleIntCtrl != UINT32_MAX);
246 uint32_t idPHandleIntCtrlMsi = RTFdtPHandleAllocate(hFdt);
247 Assert(idPHandleIntCtrlMsi != UINT32_MAX); RT_NOREF(idPHandleIntCtrlMsi);
248 uint32_t idPHandleAbpPClk = RTFdtPHandleAllocate(hFdt);
249 Assert(idPHandleAbpPClk != UINT32_MAX);
250 uint32_t idPHandleGpio = RTFdtPHandleAllocate(hFdt);
251 Assert(idPHandleGpio != UINT32_MAX);
252
253 uint32_t aidPHandleCpus[VMM_MAX_CPU_COUNT];
254 for (uint32_t i = 0; i < cCpus; i++)
255 {
256 aidPHandleCpus[i] = RTFdtPHandleAllocate(hFdt);
257 Assert(aidPHandleCpus[i] != UINT32_MAX);
258 }
259
260 vrc = RTFdtNodePropertyAddU32( hFdt, "interrupt-parent", idPHandleIntCtrl); VRC();
261 vrc = RTFdtNodePropertyAddString(hFdt, "model", "linux,dummy-virt"); VRC();
262 vrc = RTFdtNodePropertyAddU32( hFdt, "#size-cells", 2); VRC();
263 vrc = RTFdtNodePropertyAddU32( hFdt, "#address-cells", 2); VRC();
264 vrc = RTFdtNodePropertyAddString(hFdt, "compatible", "linux,dummy-virt"); VRC();
265
266 /* Configure the Power State Coordination Interface. */
267 vrc = RTFdtNodeAdd(hFdt, "psci"); VRC();
268 vrc = RTFdtNodePropertyAddU32( hFdt, "migrate", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_MIGRATE)); VRC();
269 vrc = RTFdtNodePropertyAddU32( hFdt, "cpu_on", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_CPU_ON)); VRC();
270 vrc = RTFdtNodePropertyAddU32( hFdt, "cpu_off", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_CPU_OFF)); VRC();
271 vrc = RTFdtNodePropertyAddU32( hFdt, "cpu_suspend", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_CPU_SUSPEND)); VRC();
272 vrc = RTFdtNodePropertyAddString(hFdt, "method", "hvc"); VRC();
273 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 3,
274 "arm,psci-1.0", "arm,psci-0.2", "arm,psci"); VRC();
275 vrc = RTFdtNodeFinalize(hFdt); VRC();
276
277 /* Configure the timer and clock. */
278 InsertConfigInteger(pNEM, "VTimerInterrupt", 0xb);
279 vrc = RTFdtNodeAdd(hFdt, "timer"); VRC();
280 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 12,
281 0x01, 0x0d, 0x104,
282 0x01, 0x0e, 0x104,
283 0x01, 0x0b, 0x104,
284 0x01, 0x0a, 0x104); VRC();
285 vrc = RTFdtNodePropertyAddEmpty( hFdt, "always-on"); VRC();
286 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "arm,armv8-timer"); VRC();
287 vrc = RTFdtNodeFinalize(hFdt); VRC();
288
289 vrc = RTFdtNodeAdd(hFdt, "apb-clk"); VRC();
290 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleAbpPClk); VRC();
291 vrc = RTFdtNodePropertyAddString( hFdt, "clock-output-names", "clk24mhz"); VRC();
292# ifdef RT_ARCH_ARM64
293 vrc = RTFdtNodePropertyAddU32( hFdt, "clock-frequency", ASMReadCntFrqEl0()); VRC();
294# else
295 vrc = RTFdtNodePropertyAddU32( hFdt, "clock-frequency", 24000000); VRC(); /** @todo clock-frequency hack*/
296# endif
297 vrc = RTFdtNodePropertyAddU32( hFdt, "#clock-cells", 0); VRC();
298 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "fixed-clock"); VRC();
299 vrc = RTFdtNodeFinalize(hFdt); VRC();
300
301 if (pSysTblsBldAcpi)
302 {
303 vrc = pSysTblsBldAcpi->configureClock();
304 VRC();
305 }
306
307 /*
308 * MM values.
309 */
310 PCFGMNODE pMM;
311 InsertConfigNode(pRoot, "MM", &pMM);
312
313 /*
314 * Memory setup.
315 */
316 PCFGMNODE pMem = NULL;
317 InsertConfigNode(pMM, "MemRegions", &pMem);
318
319 /*
320 * Windows requires the TPM to be available at 0xfed40000 so reserve this region first, even
321 * if no TPM is configured.
322 */
323 RTGCPHYS GCPhysTpm = 0xfed40000;
324 RTGCPHYS cbTpm = 0x5000 + 0x1000; /* TPM + PPI region. */
325 hrc = pResMgr->assignFixedMmioRegion("tpm", GCPhysTpm, cbTpm); H();
326
327 /*
328 * The firmware ROM will start at the beginning of the address space and span 64MiB
329 * After that comes the flash and spans another 64MiB (even if the real size is smaller).
330 */
331 hrc = pResMgr->assignFixedRomRegion("firmware", GCPhysFw, cbFw); H();
332
333 RTGCPHYS GCPhysFlash = _64M;
334 RTGCPHYS cbFlash = _64M;
335 hrc = pResMgr->assignFixedMmioRegion("flash", GCPhysFlash, cbFlash); H();
336
337 hrc = pResMgr->assignFixedRomRegion("platform-tables", GCPhysPlatformDesc, cbPlatformDesc); H();
338
339 /*
340 * The base RAM will start at 128MiB (end of flash region) and goes up to 4GiB - 512MiB
341 * (for the MMIO hole).
342 * If more RAM is configured the high region will start at 4GiB.
343 */
344 hrc = pResMgr->assignFixedRamRegion("RAM Base", GCPhysRamBase, cbRamBase); H();
345
346 PCFGMNODE pMemRegion = NULL;
347 InsertConfigNode(pMem, "Base", &pMemRegion);
348 InsertConfigInteger(pMemRegion, "GCPhysStart", GCPhysRamBase);
349 InsertConfigInteger(pMemRegion, "Size", cbRamBase);
350
351 vrc = RTFdtNodeAddF(hFdt, "memory@%RGp", GCPhysRamBase); VRC();
352 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysRamBase, cbRamBase); VRC();
353 vrc = RTFdtNodePropertyAddString( hFdt, "device_type", "memory"); VRC();
354 vrc = RTFdtNodeFinalize(hFdt); VRC();
355
356 if (pSysTblsBldAcpi)
357 {
358 vrc = pSysTblsBldAcpi->addMemory(GCPhysRamBase, cbRamBase);
359 VRC();
360 }
361
362 if (cbRamBase < cbRam)
363 {
364 RTGCPHYS GCPhysRamHigh = _4G;
365 RTGCPHYS cbRamHigh = cbRam - cbRamBase;
366
367 hrc = pResMgr->assignFixedRamRegion("RAM High", GCPhysRamHigh, cbRamHigh); H();
368
369 InsertConfigNode(pMem, "High", &pMemRegion);
370 InsertConfigInteger(pMemRegion, "GCPhysStart", GCPhysRamHigh);
371 InsertConfigInteger(pMemRegion, "Size", cbRamHigh);
372
373 vrc = RTFdtNodeAddF(hFdt, "memory@%RGp", GCPhysRamHigh); VRC();
374 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysRamHigh, cbRamHigh); VRC();
375 vrc = RTFdtNodePropertyAddString( hFdt, "device_type", "memory"); VRC();
376 vrc = RTFdtNodeFinalize(hFdt); VRC();
377
378 if (pSysTblsBldAcpi)
379 {
380 vrc = pSysTblsBldAcpi->addMemory(GCPhysRamHigh, cbRamHigh);
381 VRC();
382 }
383 }
384
385 /* Configure the CPUs in the system, only one socket and cluster at the moment. */
386 vrc = RTFdtNodeAdd(hFdt, "cpus"); VRC();
387 vrc = RTFdtNodePropertyAddU32(hFdt, "#size-cells", 0); VRC();
388 vrc = RTFdtNodePropertyAddU32(hFdt, "#address-cells", 1); VRC();
389
390 vrc = RTFdtNodeAdd(hFdt, "socket0"); VRC();
391 vrc = RTFdtNodeAdd(hFdt, "cluster0"); VRC();
392
393 for (uint32_t i = 0; i < cCpus; i++)
394 {
395 vrc = RTFdtNodeAddF(hFdt, "core%u", i); VRC();
396 vrc = RTFdtNodePropertyAddU32(hFdt, "cpu", aidPHandleCpus[i]); VRC();
397 vrc = RTFdtNodeFinalize(hFdt); VRC();
398 }
399
400 vrc = RTFdtNodeFinalize(hFdt); VRC();
401 vrc = RTFdtNodeFinalize(hFdt); VRC();
402
403 for (uint32_t i = 0; i < cCpus; i++)
404 {
405 vrc = RTFdtNodeAddF(hFdt, "cpu@%u", i); VRC();
406 vrc = RTFdtNodePropertyAddU32(hFdt, "phandle", aidPHandleCpus[i]); VRC();
407 vrc = RTFdtNodePropertyAddU32(hFdt, "reg", i); VRC();
408 vrc = RTFdtNodePropertyAddString(hFdt, "compatible", "arm,cortex-a15"); VRC();
409 vrc = RTFdtNodePropertyAddString(hFdt, "device_type", "cpu"); VRC();
410 if (cCpus > 1)
411 {
412 vrc = RTFdtNodePropertyAddString(hFdt, "enable-method", "psci"); VRC();
413 }
414 vrc = RTFdtNodeFinalize(hFdt); VRC();
415
416 if (pSysTblsBldAcpi)
417 {
418 vrc = pSysTblsBldAcpi->addCpu(i);
419 VRC();
420 }
421 }
422
423 vrc = RTFdtNodeFinalize(hFdt); VRC();
424
425
426 /*
427 * CPUM values.
428 */
429 PCFGMNODE pCpum;
430 InsertConfigNode(pRoot, "CPUM", &pCpum);
431
432 /* Nested Virtualization. */
433 BOOL fNestedHWVirt = FALSE;
434 hrc = platformARM->GetCPUProperty(CPUPropertyTypeARM_HWVirt, &fNestedHWVirt); H();
435 InsertConfigInteger(pCpum, "NestedHWVirt", fNestedHWVirt ? true : false);
436
437 /* GIC. */
438 uint8_t const uGicArchRev = GIC_DIST_REG_PIDR2_ARCHREV_GICV3;
439 InsertConfigInteger(pCpum, "GicArchRev", uGicArchRev);
440
441 /* GIC ITS. */
442 BOOL fGicIts = FALSE;
443 hrc = platformARM->GetCPUProperty(CPUPropertyTypeARM_GICITS, &fGicIts); H();
444
445 /*
446 * PDM config.
447 * Load drivers in VBoxC.[so|dll]
448 */
449 vrc = i_configPdm(pMachine, pVMM, pUVM, pRoot); VRC();
450
451
452 /*
453 * VGA.
454 */
455 ComPtr<IGraphicsAdapter> pGraphicsAdapter;
456 hrc = pMachine->COMGETTER(GraphicsAdapter)(pGraphicsAdapter.asOutParam()); H();
457 GraphicsControllerType_T enmGraphicsController;
458 hrc = pGraphicsAdapter->COMGETTER(GraphicsControllerType)(&enmGraphicsController); H();
459
460 /*
461 * Devices
462 */
463 PCFGMNODE pDevices = NULL; /* /Devices */
464 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
465 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
466 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
467 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
468
469 InsertConfigNode(pRoot, "Devices", &pDevices);
470
471 InsertConfigNode(pDevices, "pci-generic-ecam-bridge", NULL);
472
473 InsertConfigNode(pDevices, "platform", &pDev);
474 InsertConfigNode(pDev, "0", &pInst);
475 InsertConfigNode(pInst, "Config", &pCfg);
476 InsertConfigNode(pInst, "LUN#0", &pLunL0);
477 InsertConfigString(pLunL0, "Driver", "ResourceStore");
478
479 /* Add the resources. */
480 PCFGMNODE pResources = NULL; /* /Devices/platform/Config/Resources */
481 PCFGMNODE pRes = NULL; /* /Devices/platform/Config/Resources/<Resource> */
482 InsertConfigString(pCfg, "ResourceNamespace", "resources");
483 InsertConfigNode(pCfg, "Resources", &pResources);
484 InsertConfigNode(pResources, "EfiRom", &pRes);
485 InsertConfigInteger(pRes, "RegisterAsRom", 1);
486 InsertConfigInteger(pRes, "GCPhysLoadAddress", 0);
487
488 /** @todo r=aeichner 32-bit guests and query the firmware type from VBoxSVC. */
489 /*
490 * Firmware.
491 */
492 FirmwareType_T eFwType = FirmwareType_EFI64;
493#ifdef VBOX_WITH_EFI_IN_DD2
494 const char *pszEfiRomFile = eFwType == FirmwareType_EFIDUAL ? "<INVALID>"
495 : eFwType == FirmwareType_EFI32 ? "VBoxEFI-arm32.fd"
496 : "VBoxEFI-arm64.fd";
497 const char *pszKey = "ResourceId";
498#else
499 Utf8Str efiRomFile;
500 vrc = findEfiRom(virtualBox, PlatformArchitecture_ARM, eFwType, &efiRomFile);
501 AssertRCReturn(vrc, vrc);
502 const char *pszEfiRomFile = efiRomFile.c_str();
503 const char *pszKey = "Filename";
504#endif
505 InsertConfigString(pRes, pszKey, pszEfiRomFile);
506
507 InsertConfigNode(pResources, "ArmV8Desc", &pRes);
508 InsertConfigInteger(pRes, "RegisterAsRom", 1);
509 InsertConfigInteger(pRes, "GCPhysLoadAddress", GCPhysPlatformDesc);
510 InsertConfigString(pRes, "ResourceId", "VBoxArmV8Desc");
511
512 /*
513 * Configure the interrupt controller.
514 */
515 RTGCPHYS GCPhysIntcDist;
516 RTGCPHYS GCPhysIntcIts;
517 RTGCPHYS cbMmioIntcDist;
518 RTGCPHYS cbMmioIntcIts;
519 RTGCPHYS GCPhysIntcReDist;
520 RTGCPHYS cbMmioIntcReDist;
521
522 /* Allow for up to 256 vCPUs in the future without changing the address space layout. */
523 hrc = pResMgr->assignMmioRegion("gic", _64K + 256 * _128K, &GCPhysIntcDist, &cbMmioIntcDist); H();
524 GCPhysIntcReDist = GCPhysIntcDist + _64K;
525 cbMmioIntcReDist = 256 * _128K;
526 cbMmioIntcDist = _64K;
527
528 /* Reserve an MMIO region for the GIC ITS even if it might not be configured for the VM. */
529 hrc = pResMgr->assignMmioRegion("gic-its", 2 * _64K, &GCPhysIntcIts, &cbMmioIntcIts); H();
530
531#if defined(RT_OS_DARWIN) || !defined(RT_ARCH_ARM64)
532 InsertConfigNode(pDevices, "gic", &pDev);
533#else
534 /* On Linux we default to the KVM in-kernel GIC and on Windows we are forced to the Hyper-V GIC for now. */
535 InsertConfigNode(pDevices, "gic-nem", &pDev);
536#endif
537 InsertConfigNode(pDev, "0", &pInst);
538 InsertConfigInteger(pInst, "Trusted", 1);
539 InsertConfigNode(pInst, "Config", &pCfg);
540 InsertConfigInteger(pCfg, "ArchRev", uGicArchRev);
541 InsertConfigInteger(pCfg, "DistributorMmioBase", GCPhysIntcDist);
542 InsertConfigInteger(pCfg, "RedistributorMmioBase", GCPhysIntcReDist);
543 if (fGicIts == TRUE)
544 {
545 InsertConfigInteger(pCfg, "ItsMmioBase", GCPhysIntcIts);
546 InsertConfigInteger(pCfg, "Lpi", 1);
547 InsertConfigInteger(pCfg, "Mbi", 1);
548 }
549 else
550 GCPhysIntcIts = cbMmioIntcIts = 0;
551
552 vrc = RTFdtNodeAddF(hFdt, "intc@%RGp", GCPhysIntcDist); VRC();
553 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleIntCtrl); VRC();
554 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 4,
555 GCPhysIntcDist, cbMmioIntcDist, /* Distributor */
556 GCPhysIntcReDist, cbMmioIntcReDist); /* Re-Distributor */ VRC();
557 vrc = RTFdtNodePropertyAddU32( hFdt, "#redistributor-regions", 1); VRC();
558 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "arm,gic-v3"); VRC();
559 vrc = RTFdtNodePropertyAddEmpty( hFdt, "ranges"); VRC();
560 vrc = RTFdtNodePropertyAddU32( hFdt, "#size-cells", 2); VRC();
561 vrc = RTFdtNodePropertyAddU32( hFdt, "#address-cells", 2); VRC();
562 vrc = RTFdtNodePropertyAddEmpty( hFdt, "interrupt-controller"); VRC();
563 vrc = RTFdtNodePropertyAddU32( hFdt, "#interrupt-cells", 3); VRC();
564
565 if (pSysTblsBldAcpi)
566 {
567 vrc = pSysTblsBldAcpi->configureGic(cCpus, GCPhysIntcDist, cbMmioIntcDist,
568 GCPhysIntcReDist, cbMmioIntcReDist, GCPhysIntcIts, cbMmioIntcIts);
569 VRC();
570 }
571
572#if 0
573 vrc = RTFdtNodeAddF(hFdt, "its@%RX32", 0x08080000); VRC();
574 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleIntCtrlMsi); VRC();
575 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4, 0, 0x08080000, 0, 0x20000); VRC();
576 vrc = RTFdtNodePropertyAddU32( hFdt, "#msi-cells", 1); VRC();
577 vrc = RTFdtNodePropertyAddEmpty( hFdt, "msi-controller"); VRC();
578 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "arm,gic-v3-its"); VRC();
579 vrc = RTFdtNodeFinalize(hFdt); VRC();
580#endif
581
582 vrc = RTFdtNodeFinalize(hFdt); VRC();
583
584 /*
585 * Configure the performance monitoring unit.
586 */
587 /** @todo Make this configurable and enable as default for Windows VMs because they assume a working PMU
588 * (which is not available in hardware on AppleSilicon).
589 */
590 InsertConfigNode(pDevices, "pmu", &pDev);
591 InsertConfigNode(pDev, "0", &pInst);
592 InsertConfigInteger(pInst, "Trusted", 1);
593 InsertConfigNode(pInst, "Config", &pCfg);
594
595 RTGCPHYS GCPhysMmioStart;
596 RTGCPHYS cbMmio;
597 if (enmGraphicsController == GraphicsControllerType_QemuRamFB)
598 {
599 hrc = pResMgr->assignMmioRegion("qemu-fw-cfg", _4K, &GCPhysMmioStart, &cbMmio); H();
600
601 InsertConfigNode(pDevices, "qemu-fw-cfg", &pDev);
602 InsertConfigNode(pDev, "0", &pInst);
603 InsertConfigNode(pInst, "Config", &pCfg);
604 InsertConfigInteger(pCfg, "MmioSize", cbMmio);
605 InsertConfigInteger(pCfg, "MmioBase", GCPhysMmioStart);
606 InsertConfigInteger(pCfg, "DmaEnabled", 1);
607 InsertConfigInteger(pCfg, "QemuRamfbSupport", 1);
608 InsertConfigNode(pInst, "LUN#0", &pLunL0);
609 InsertConfigString(pLunL0, "Driver", "MainDisplay");
610
611 vrc = RTFdtNodeAddF(hFdt, "fw-cfg@%RGp", GCPhysMmioStart); VRC();
612 vrc = RTFdtNodePropertyAddEmpty( hFdt, "dma-coherent"); VRC();
613 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysMmioStart, cbMmio); VRC();
614 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "qemu,fw-cfg-mmio"); VRC();
615 vrc = RTFdtNodeFinalize(hFdt); VRC();
616
617 if (pSysTblsBldAcpi)
618 {
619 vrc = pSysTblsBldAcpi->addMmioDeviceNoIrq("qemu-fw-cfg", 0, GCPhysMmioStart, cbMmio);
620 VRC();
621 }
622 }
623
624 InsertConfigNode(pDevices, "flash-cfi", &pDev);
625 InsertConfigNode(pDev, "0", &pInst);
626 InsertConfigNode(pInst, "Config", &pCfg);
627 InsertConfigInteger(pCfg, "BaseAddress", GCPhysFlash);
628 InsertConfigInteger(pCfg, "Size", 768 * _1K);
629 InsertConfigString(pCfg, "FlashFile", "nvram");
630 /* Attach the NVRAM storage driver. */
631 InsertConfigNode(pInst, "LUN#0", &pLunL0);
632 InsertConfigString(pLunL0, "Driver", "NvramStore");
633
634 vrc = RTFdtNodeAddF(hFdt, "flash@%RX32", 0); VRC();
635 vrc = RTFdtNodePropertyAddU32( hFdt, "bank-width", 4); VRC();
636 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 4,
637 GCPhysFw, cbFw, /* First region (EFI). */
638 GCPhysFlash, 3 * _256K); /* Second region (NVRAM), see NvramStoreImpl.cpp for an explanation of the size choice. */ VRC();
639 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "cfi-flash"); VRC();
640 vrc = RTFdtNodeFinalize(hFdt); VRC();
641
642 InsertConfigNode(pDevices, "arm-pl011", &pDev);
643 for (ULONG ulInstance = 0; ulInstance < 1 /** @todo SchemaDefs::SerialPortCount*/; ++ulInstance)
644 {
645 ComPtr<ISerialPort> serialPort;
646 hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam()); H();
647 BOOL fEnabledSerPort = FALSE;
648 if (serialPort)
649 {
650 hrc = serialPort->COMGETTER(Enabled)(&fEnabledSerPort); H();
651 }
652 if (!fEnabledSerPort)
653 {
654 m_aeSerialPortMode[ulInstance] = PortMode_Disconnected;
655 continue;
656 }
657
658 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
659 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
660 InsertConfigNode(pInst, "Config", &pCfg);
661
662 uint32_t iIrq = 0;
663 hrc = pResMgr->assignSingleInterrupt("arm-pl011", &iIrq); H();
664 hrc = pResMgr->assignMmioRegion("arm-pl011", _4K, &GCPhysMmioStart, &cbMmio); H();
665
666 InsertConfigInteger(pCfg, "Irq", iIrq);
667 InsertConfigInteger(pCfg, "MmioBase", GCPhysMmioStart);
668
669 vrc = RTFdtNodeAddF(hFdt, "pl011@%RGp", GCPhysMmioStart); VRC();
670 vrc = RTFdtNodePropertyAddStringList(hFdt, "clock-names", 2, "uartclk", "apb_pclk"); VRC();
671 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "clocks", 2,
672 idPHandleAbpPClk, idPHandleAbpPClk); VRC();
673 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 3, 0x00, iIrq, 0x04); VRC();
674 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysMmioStart, cbMmio); VRC();
675 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 2,
676 "arm,pl011", "arm,primecell"); VRC();
677 vrc = RTFdtNodeFinalize(hFdt); VRC();
678
679 if (pSysTblsBldAcpi)
680 {
681 vrc = pSysTblsBldAcpi->addMmioDevice("arm-pl011", ulInstance, GCPhysMmioStart, cbMmio, iIrq);
682 VRC();
683 }
684
685 BOOL fServer;
686 hrc = serialPort->COMGETTER(Server)(&fServer); H();
687 hrc = serialPort->COMGETTER(Path)(bstr.asOutParam()); H();
688
689 PortMode_T eHostMode;
690 hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
691
692 m_aeSerialPortMode[ulInstance] = eHostMode;
693 if (eHostMode != PortMode_Disconnected)
694 {
695 vrc = i_configSerialPort(pInst, eHostMode, Utf8Str(bstr).c_str(), RT_BOOL(fServer));
696 if (RT_FAILURE(vrc))
697 return vrc;
698 }
699 }
700
701 BOOL fRTCUseUTC;
702 hrc = platform->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
703
704 uint32_t iIrq = 0;
705 hrc = pResMgr->assignSingleInterrupt("arm-pl031-rtc", &iIrq); H();
706 hrc = pResMgr->assignMmioRegion("arm-pl031-rtc", _4K, &GCPhysMmioStart, &cbMmio); H();
707 InsertConfigNode(pDevices, "arm-pl031-rtc", &pDev);
708 InsertConfigNode(pDev, "0", &pInst);
709 InsertConfigNode(pInst, "Config", &pCfg);
710 InsertConfigInteger(pCfg, "Irq", iIrq);
711 InsertConfigInteger(pCfg, "MmioBase", GCPhysMmioStart);
712 InsertConfigInteger(pCfg, "UtcOffset", fRTCUseUTC ? 1 : 0);
713
714 vrc = RTFdtNodeAddF(hFdt, "pl032@%RGp", GCPhysMmioStart); VRC();
715 vrc = RTFdtNodePropertyAddString( hFdt, "clock-names", "apb_pclk"); VRC();
716 vrc = RTFdtNodePropertyAddU32( hFdt, "clocks", idPHandleAbpPClk); VRC();
717 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 3, 0x00, iIrq, 0x04); VRC();
718 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysMmioStart, cbMmio); VRC();
719 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 2,
720 "arm,pl031", "arm,primecell"); VRC();
721 vrc = RTFdtNodeFinalize(hFdt); VRC();
722
723 /* Configure gpio keys (The Windows GPIO PL061 driver doesn't like 64-bit MMIO addresses...). */
724 hrc = pResMgr->assignSingleInterrupt("arm-pl061-gpio", &iIrq); H();
725 hrc = pResMgr->assignMmio32Region("arm-pl061-gpio", _4K, &GCPhysMmioStart, &cbMmio); H();
726 InsertConfigNode(pDevices, "arm-pl061-gpio",&pDev);
727 InsertConfigNode(pDev, "0", &pInst);
728 InsertConfigNode(pInst, "Config", &pCfg);
729 InsertConfigInteger(pCfg, "Irq", iIrq);
730 InsertConfigInteger(pCfg, "MmioBase", GCPhysMmioStart);
731 vrc = RTFdtNodeAddF(hFdt, "pl061@%RGp", GCPhysMmioStart); VRC();
732 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleGpio); VRC();
733 vrc = RTFdtNodePropertyAddString( hFdt, "clock-names", "apb_pclk"); VRC();
734 vrc = RTFdtNodePropertyAddU32( hFdt, "clocks", idPHandleAbpPClk); VRC();
735 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 3, 0x00, iIrq, 0x04); VRC();
736 vrc = RTFdtNodePropertyAddEmpty( hFdt, "gpio-controller"); VRC();
737 vrc = RTFdtNodePropertyAddU32( hFdt, "#gpio-cells", 2); VRC();
738 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 2,
739 "arm,pl061", "arm,primecell"); VRC();
740 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysMmioStart, cbMmio); VRC();
741 vrc = RTFdtNodeFinalize(hFdt); VRC();
742
743 InsertConfigNode(pInst, "LUN#0", &pLunL0);
744 InsertConfigString(pLunL0, "Driver", "GpioButton");
745 InsertConfigNode(pLunL0, "Config", &pCfg);
746 InsertConfigInteger(pCfg, "PowerButtonGpio", 3);
747 InsertConfigInteger(pCfg, "SleepButtonGpio", 4);
748
749 vrc = RTFdtNodeAdd(hFdt, "gpio-keys"); VRC();
750 vrc = RTFdtNodePropertyAddString(hFdt, "compatible", "gpio-keys"); VRC();
751
752 vrc = RTFdtNodeAdd(hFdt, "poweroff"); VRC();
753 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "gpios", 3, idPHandleGpio, 3, 0); VRC();
754 vrc = RTFdtNodePropertyAddU32( hFdt, "linux,code", 0x74); VRC();
755 vrc = RTFdtNodePropertyAddString( hFdt, "label", "GPIO Key Poweroff"); VRC();
756 vrc = RTFdtNodeFinalize(hFdt); VRC();
757
758 vrc = RTFdtNodeAdd(hFdt, "suspend"); VRC();
759 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "gpios", 3, idPHandleGpio, 4, 0); VRC();
760 vrc = RTFdtNodePropertyAddU32( hFdt, "linux,code", 0xcd); VRC();
761 vrc = RTFdtNodePropertyAddString( hFdt, "label", "GPIO Key Suspend"); VRC();
762 vrc = RTFdtNodeFinalize(hFdt); VRC();
763
764 vrc = RTFdtNodeFinalize(hFdt); VRC();
765
766 if (pSysTblsBldAcpi)
767 {
768 vrc = pSysTblsBldAcpi->configureGpioDevice("arm-pl061-gpio", 0, GCPhysMmioStart, cbMmio, iIrq,
769 3 /*u16PinShutdown*/, 4 /*u16PinSuspend*/);
770 VRC();
771 }
772
773#if defined(VBOX_WITH_TPM)
774 /*
775 * Configure the Trusted Platform Module.
776 */
777 ComObjPtr<ITrustedPlatformModule> ptrTpm;
778 TpmType_T enmTpmType = TpmType_None;
779
780 hrc = pMachine->COMGETTER(TrustedPlatformModule)(ptrTpm.asOutParam()); H();
781 hrc = ptrTpm->COMGETTER(Type)(&enmTpmType); H();
782 if (enmTpmType != TpmType_None)
783 {
784 hrc = pResMgr->assignSingleInterrupt("tpm", &iIrq); H();
785
786 vrc = i_configTpm(ptrTpm, enmTpmType, pDevices, GCPhysTpm, iIrq /*uIrq*/,
787 GCPhysTpm + 0x5000, true /*fCrb*/); VRC();
788
789 vrc = RTFdtNodeAddF(hFdt, "tpm@%RGp", GCPhysTpm); VRC();
790 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 3, 0x00, iIrq, 0x04); VRC();
791 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysTpm, cbTpm); VRC();
792 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 1, "tcg,tpm-tis-mmio"); VRC();
793 vrc = RTFdtNodeFinalize(hFdt); VRC();
794
795 if (pSysTblsBldAcpi)
796 {
797 vrc = pSysTblsBldAcpi->configureTpm2(true /*fCrb*/, GCPhysTpm, cbTpm, iIrq);
798 VRC();
799 }
800 }
801#endif
802
803 hrc = pResMgr->assignInterrupts("pci-generic-ecam", 4 /*cInterrupts*/, &iIrq); H();
804 uint32_t aPinIrqs[] = { iIrq, iIrq + 1, iIrq + 2, iIrq + 3 };
805 RTGCPHYS GCPhysPciMmioEcam, GCPhysPciMmio, GCPhysPciMmio32;
806 RTGCPHYS cbPciMmioEcam, cbPciMmio, cbPciMmio32;
807
808 hrc = pResMgr->assignMmioRegionAligned("pci-pio", _64K, _64K, &GCPhysMmioStart, &cbMmio, false /*fOnly32Bit*/); H();
809 hrc = pResMgr->assignMmioRegion( "pci-ecam", 16 * _1M, &GCPhysPciMmioEcam, &cbPciMmioEcam); H();
810 hrc = pResMgr->assignMmio64Region( "pci-mmio", _2G, &GCPhysPciMmio, &cbPciMmio); H();
811 hrc = pResMgr->assignMmio32Region( "pci-mmio32", _256M, &GCPhysPciMmio32, &cbPciMmio32); H();
812
813 InsertConfigNode(pDevices, "pci-generic-ecam", &pDev);
814 InsertConfigNode(pDev, "0", &pInst);
815 InsertConfigNode(pInst, "Config", &pCfg);
816 InsertConfigInteger(pCfg, "MmioEcamBase", GCPhysPciMmioEcam);
817 InsertConfigInteger(pCfg, "MmioEcamLength", cbPciMmioEcam);
818 InsertConfigInteger(pCfg, "MmioPioBase", GCPhysMmioStart);
819 InsertConfigInteger(pCfg, "MmioPioSize", cbMmio);
820 InsertConfigInteger(pCfg, "IntPinA", aPinIrqs[0]);
821 InsertConfigInteger(pCfg, "IntPinB", aPinIrqs[1]);
822 InsertConfigInteger(pCfg, "IntPinC", aPinIrqs[2]);
823 InsertConfigInteger(pCfg, "IntPinD", aPinIrqs[3]);
824 vrc = RTFdtNodeAddF(hFdt, "pcie@%RGp", GCPhysPciMmio); VRC();
825 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupt-map-mask", 4, 0xf800, 0, 0, 7); VRC();
826
827 uint32_t aIrqCells[32 * 4 * 10]; RT_ZERO(aIrqCells); /* Maximum of 32 devices on the root bus, each supporting 4 interrupts (INTA# ... INTD#). */
828 uint32_t *pau32IrqCell = &aIrqCells[0];
829 uint32_t iIrqPinSwizzle = 0;
830
831 for (uint32_t i = 0; i < 32; i++)
832 {
833 for (uint32_t iIrqPin = 0; iIrqPin < 4; iIrqPin++)
834 {
835 pau32IrqCell[0] = i << 11; /* The dev part, composed as dev.fn. */
836 pau32IrqCell[1] = 0;
837 pau32IrqCell[2] = 0;
838 pau32IrqCell[3] = iIrqPin + 1;
839 pau32IrqCell[4] = idPHandleIntCtrl;
840 pau32IrqCell[5] = 0;
841 pau32IrqCell[6] = 0;
842 pau32IrqCell[7] = 0;
843 pau32IrqCell[8] = aPinIrqs[(iIrqPinSwizzle + iIrqPin) % RT_ELEMENTS(aPinIrqs)];
844 pau32IrqCell[9] = 0x04;
845 pau32IrqCell += 10;
846 }
847
848 iIrqPinSwizzle++;
849 }
850
851 vrc = RTFdtNodePropertyAddCellsU32AsArray(hFdt, "interrupt-map", RT_ELEMENTS(aIrqCells), &aIrqCells[0]); VRC();
852 vrc = RTFdtNodePropertyAddU32( hFdt, "#interrupt-cells", 1); VRC();
853 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "ranges", 21,
854 0x1000000, 0, 0,
855 GCPhysMmioStart >> 32, GCPhysMmioStart, cbMmio >> 32, cbMmio,
856 0x2000000, GCPhysPciMmio32 >> 32, GCPhysPciMmio32, GCPhysPciMmio32 >> 32, GCPhysPciMmio32,
857 cbPciMmio32 >> 32, cbPciMmio32,
858 0x3000000, GCPhysPciMmio >> 32, GCPhysPciMmio, GCPhysPciMmio >> 32, GCPhysPciMmio,
859 cbPciMmio >> 32, cbPciMmio); VRC();
860 vrc = RTFdtNodePropertyAddCellsU64(hFdt, "reg", 2, GCPhysPciMmioEcam, cbPciMmioEcam); VRC();
861 /** @todo msi-map */
862 vrc = RTFdtNodePropertyAddEmpty( hFdt, "dma-coherent"); VRC();
863 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "bus-range", 2, 0, 0xf); VRC();
864 vrc = RTFdtNodePropertyAddU32( hFdt, "linux,pci-domain", 0); VRC();
865 vrc = RTFdtNodePropertyAddU32( hFdt, "#size-cells", 2); VRC();
866 vrc = RTFdtNodePropertyAddU32( hFdt, "#address-cells", 3); VRC();
867 vrc = RTFdtNodePropertyAddString( hFdt, "device_type", "pci"); VRC();
868 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "pci-host-ecam-generic"); VRC();
869 vrc = RTFdtNodeFinalize(hFdt); VRC();
870
871 if (pSysTblsBldAcpi)
872 {
873 vrc = pSysTblsBldAcpi->configurePcieRootBus("pci-generic-ecam", aPinIrqs, GCPhysMmioStart, GCPhysPciMmioEcam,
874 cbPciMmioEcam, GCPhysMmioStart, cbMmio, GCPhysPciMmio32, cbPciMmio32);
875 VRC();
876 }
877
878 /*
879 * VMSVGA compliant graphics controller.
880 */
881 if ( enmGraphicsController != GraphicsControllerType_QemuRamFB
882 && enmGraphicsController != GraphicsControllerType_Null)
883 {
884 vrc = i_configGraphicsController(pDevices, enmGraphicsController, pBusMgr, pMachine,
885 pGraphicsAdapter, firmwareSettings,
886 true /*fForceVmSvga3*/, false /*fExposeLegacyVga*/); VRC();
887 }
888
889 /*
890 * The USB Controllers and input devices.
891 */
892#if 0 /** @todo Make us of this and disallow PS/2 for ARM VMs for now. */
893 KeyboardHIDType_T aKbdHID;
894 hrc = pMachine->COMGETTER(KeyboardHIDType)(&aKbdHID); H();
895#endif
896
897 PointingHIDType_T aPointingHID;
898 hrc = pMachine->COMGETTER(PointingHIDType)(&aPointingHID); H();
899
900 PCFGMNODE pUsbDevices = NULL;
901 vrc = i_configUsb(pMachine, pBusMgr, pRoot, pDevices, KeyboardHIDType_USBKeyboard, aPointingHID, &pUsbDevices);
902
903 /*
904 * Storage controllers.
905 */
906 bool fFdcEnabled = false;
907 vrc = i_configStorageCtrls(pMachine, pBusMgr, pVMM, pUVM,
908 pDevices, pUsbDevices, NULL /*pBiosCfg*/, &fFdcEnabled); VRC();
909
910 /*
911 * Network adapters
912 */
913 std::list<BootNic> llBootNics;
914 vrc = i_configNetworkCtrls(pMachine, pPlatformProperties, chipsetType, pBusMgr,
915 pVMM, pUVM, pDevices, pUsbDevices, llBootNics); VRC();
916
917 /*
918 * The VMM device.
919 */
920 vrc = i_configVmmDev(pMachine, pBusMgr, pDevices, true /*fMmioReq*/); VRC();
921
922 /*
923 * Audio configuration.
924 */
925 bool fAudioEnabled = false;
926 vrc = i_configAudioCtrl(virtualBox, pMachine, pBusMgr, pDevices,
927 false /*fOsXGuest*/, &fAudioEnabled); VRC();
928
929 /*
930 * Configure DBGF (Debug(ger) Facility) and DBGC (Debugger Console).
931 */
932 vrc = i_configGuestDbg(virtualBox, pMachine, pRoot); VRC();
933 }
934 catch (ConfigError &x)
935 {
936 RTFdtDestroy(hFdt);
937
938 // InsertConfig threw something:
939 pVMM->pfnVMR3SetError(pUVM, x.m_vrc, RT_SRC_POS, "Caught ConfigError: %Rrc - %s", x.m_vrc, x.what());
940 return x.m_vrc;
941 }
942 catch (HRESULT hrcXcpt)
943 {
944 RTFdtDestroy(hFdt);
945 AssertLogRelMsgFailedReturn(("hrc=%Rhrc\n", hrcXcpt), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR);
946 }
947
948#ifdef VBOX_WITH_EXTPACK
949 /*
950 * Call the extension pack hooks if everything went well thus far.
951 */
952 if (RT_SUCCESS(vrc))
953 {
954 pAlock->release();
955 vrc = mptrExtPackManager->i_callAllVmConfigureVmmHooks(this, pVM, pVMM);
956 pAlock->acquire();
957 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
958 }
959#endif
960
961#if 0
962 vrc = RTFdtNodeAdd(hFdt, "chosen"); VRC();
963 vrc = RTFdtNodePropertyAddString( hFdt, "stdout-path", "pl011@9000000"); VRC();
964 vrc = RTFdtNodePropertyAddString( hFdt, "stdin-path", "pl011@9000000"); VRC();
965 vrc = RTFdtNodeFinalize(hFdt);
966#endif
967
968 /* Finalize the FDT and add it to the resource store. */
969 vrc = RTFdtFinalize(hFdt);
970 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
971
972 RTVFSFILE hVfsFileDesc = NIL_RTVFSFILE;
973 vrc = RTVfsMemFileCreate(NIL_RTVFSIOSTREAM, 0 /*cbEstimate*/, &hVfsFileDesc);
974 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
975 RTVFSIOSTREAM hVfsIosDesc = RTVfsFileToIoStream(hVfsFileDesc);
976 AssertRelease(hVfsIosDesc != NIL_RTVFSIOSTREAM);
977
978 /* Initialize the VBox platform descriptor. */
979 VBOXPLATFORMARMV8 ArmV8Platform; RT_ZERO(ArmV8Platform);
980
981 vrc = RTFdtDumpToVfsIoStrm(hFdt, RTFDTTYPE_DTB, 0 /*fFlags*/, hVfsIosDesc, NULL /*pErrInfo*/);
982 uint64_t cbFdt = 0;
983 if (RT_SUCCESS(vrc))
984 vrc = RTVfsFileQuerySize(hVfsFileDesc, &cbFdt);
985 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
986
987 vrc = RTVfsIoStrmZeroFill(hVfsIosDesc, (RTFOFF)(RT_ALIGN_64(cbFdt, _64K) - cbFdt));
988 AssertRCReturn(vrc, vrc);
989
990 cbFdt = RT_ALIGN_64(cbFdt, _64K);
991
992 RTGCPHYS GCPhysMmioStart;
993 RTGCPHYS cbMmio;
994 hrc = pResMgr->queryMmioRegion(&GCPhysMmioStart, &cbMmio);
995 Assert(SUCCEEDED(hrc));
996
997 RTGCPHYS GCPhysMmio32Start;
998 RTGCPHYS cbMmio32;
999 hrc = pResMgr->queryMmio32Region(&GCPhysMmio32Start, &cbMmio32);
1000 Assert(SUCCEEDED(hrc));
1001
1002 RTGCPHYS GCPhysXsdp = NIL_RTGCPHYS;
1003 size_t cbAcpiXsdp = 0;
1004 size_t cbAcpi = 0;
1005 if (pSysTblsBldAcpi)
1006 {
1007 vrc = pSysTblsBldAcpi->finishTables(GCPhysPlatformDesc + cbFdt,
1008 hVfsIosDesc, &GCPhysXsdp, &cbAcpiXsdp, &cbAcpi);
1009 AssertRCReturn(vrc, vrc);
1010 Assert( GCPhysXsdp > GCPhysPlatformDesc
1011 && GCPhysXsdp < VBOXPLATFORMARMV8_PHYS_ADDR);
1012
1013 /* Dump the ACPI table for debugging purposes if requested. */
1014 Bstr SysTblsDumpVal;
1015 hrc = mMachine->GetExtraData(Bstr("VBoxInternal2/DumpSysTables").raw(),
1016 SysTblsDumpVal.asOutParam());
1017 if ( hrc == S_OK
1018 && SysTblsDumpVal.isNotEmpty())
1019 {
1020 vrc = pSysTblsBldAcpi->dumpTables(Utf8Str(SysTblsDumpVal).c_str());
1021 AssertRCReturn(vrc, vrc);
1022 }
1023
1024 delete pSysTblsBldAcpi;
1025
1026 vrc = RTVfsIoStrmZeroFill(hVfsIosDesc, (RTFOFF)(RT_ALIGN_64(cbAcpi, _64K) - cbAcpi));
1027 AssertRCReturn(vrc, vrc);
1028
1029 cbAcpi = RT_ALIGN_64(cbAcpi, _64K);
1030 }
1031
1032 /* Fill the room until the end where the platform descriptor lives. */
1033 vrc = RTVfsIoStrmZeroFill(hVfsIosDesc, cbPlatformDesc - sizeof(ArmV8Platform) - cbFdt - cbAcpi);
1034 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
1035
1036 RTGCPHYS GCPhysMmio = 0;
1037 RTGCPHYS cbMmioAbove4G = 0;
1038 pResMgr->queryMmioRegion(&GCPhysMmio, &cbMmioAbove4G);
1039
1040 ArmV8Platform.u32Magic = VBOXPLATFORMARMV8_MAGIC;
1041 ArmV8Platform.u32Version = VBOXPLATFORMARMV8_VERSION;
1042 ArmV8Platform.cbDesc = sizeof(ArmV8Platform);
1043 ArmV8Platform.fFlags = 0;
1044 ArmV8Platform.u64PhysAddrRamBase = GCPhysRamBase;
1045 ArmV8Platform.cbRamBase = cbRamBase;
1046 ArmV8Platform.i64OffFdt = (int64_t)GCPhysPlatformDesc - VBOXPLATFORMARMV8_PHYS_ADDR;
1047 ArmV8Platform.cbFdt = cbFdt;
1048 if (cbAcpi)
1049 {
1050 ArmV8Platform.i64OffAcpi = (int64_t)(GCPhysPlatformDesc + cbFdt) - VBOXPLATFORMARMV8_PHYS_ADDR;
1051 ArmV8Platform.cbAcpi = cbAcpi;
1052 ArmV8Platform.i64OffAcpiXsdp = (int64_t)GCPhysXsdp - VBOXPLATFORMARMV8_PHYS_ADDR;
1053 ArmV8Platform.cbAcpiXsdp = cbAcpiXsdp;
1054 }
1055 ArmV8Platform.i64OffUefiRom = (int64_t)GCPhysFw - VBOXPLATFORMARMV8_PHYS_ADDR;
1056 ArmV8Platform.cbUefiRom = _64M;
1057 ArmV8Platform.i64OffMmio = GCPhysMmio ? (int64_t)GCPhysMmio - VBOXPLATFORMARMV8_PHYS_ADDR : 0;
1058 ArmV8Platform.cbMmio = cbMmioAbove4G;
1059 ArmV8Platform.i64OffMmio32 = (int64_t)(_4G - _512M) - VBOXPLATFORMARMV8_PHYS_ADDR;
1060 ArmV8Platform.cbMmio32 = _512M - _2M; /* Just assign the whole MMIO hole (except for the platform descriptor region). */
1061
1062 /* Add the VBox platform descriptor to the resource store. */
1063 vrc = RTVfsIoStrmWrite(hVfsIosDesc, &ArmV8Platform, sizeof(ArmV8Platform), true /*fBlocking*/, NULL /*pcbWritten*/);
1064 RTVfsIoStrmRelease(hVfsIosDesc);
1065 AssertRCReturnStmt(vrc, RTVfsFileRelease(hVfsFileDesc), vrc);
1066
1067 vrc = mptrResourceStore->i_addItem("resources", "VBoxArmV8Desc", hVfsFileDesc);
1068 RTVfsFileRelease(hVfsFileDesc);
1069 AssertRCReturn(vrc, vrc);
1070
1071 /* Dump the DTB for debugging purposes if requested. */
1072 Bstr DtbDumpVal;
1073 hrc = mMachine->GetExtraData(Bstr("VBoxInternal2/DumpDtb").raw(),
1074 DtbDumpVal.asOutParam());
1075 if ( hrc == S_OK
1076 && DtbDumpVal.isNotEmpty())
1077 {
1078 vrc = RTFdtDumpToFile(hFdt, RTFDTTYPE_DTB, 0 /*fFlags*/, Utf8Str(DtbDumpVal).c_str(), NULL /*pErrInfo*/);
1079 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
1080 }
1081
1082 pResMgr->dumpMemoryRegionsToReleaseLog();
1083
1084 delete pResMgr; /* Delete the address/interrupt assignment manager. */
1085
1086 /*
1087 * Apply the CFGM overlay.
1088 */
1089 if (RT_SUCCESS(vrc))
1090 vrc = i_configCfgmOverlay(pRoot, virtualBox, pMachine);
1091
1092 /*
1093 * Dump all extradata API settings tweaks, both global and per VM.
1094 */
1095 if (RT_SUCCESS(vrc))
1096 vrc = i_configDumpAPISettingsTweaks(virtualBox, pMachine);
1097
1098#undef H
1099
1100 pAlock->release(); /* Avoid triggering the lock order inversion check. */
1101
1102 /*
1103 * Register VM state change handler.
1104 */
1105 int vrc2 = pVMM->pfnVMR3AtStateRegister(pUVM, Console::i_vmstateChangeCallback, this);
1106 AssertRC(vrc2);
1107 if (RT_SUCCESS(vrc))
1108 vrc = vrc2;
1109
1110 /*
1111 * Register VM runtime error handler.
1112 */
1113 vrc2 = pVMM->pfnVMR3AtRuntimeErrorRegister(pUVM, Console::i_atVMRuntimeErrorCallback, this);
1114 AssertRC(vrc2);
1115 if (RT_SUCCESS(vrc))
1116 vrc = vrc2;
1117
1118 pAlock->acquire();
1119
1120 LogFlowFunc(("vrc = %Rrc\n", vrc));
1121 LogFlowFuncLeave();
1122
1123 return vrc;
1124}
1125#endif /* !VBOX_WITH_VIRT_ARMV8 */
1126
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