VirtualBox

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

Last change on this file since 101574 was 101574, checked in by vboxsync, 15 months ago

Main/src-client/ConsoleImplConfigArmv8.cpp: Some cleanups, bugref:10528

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.2 KB
Line 
1/* $Id: ConsoleImplConfigArmV8.cpp 101574 2023-10-24 08:27:38Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation - VM Configuration Bits for ARMv8.
4 */
5
6/*
7 * Copyright (C) 2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
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/param.h>
65#include <VBox/version.h>
66#include <VBox/platforms/vbox-armv8.h>
67
68#include "BusAssignmentManager.h"
69#ifdef VBOX_WITH_EXTPACK
70# include "ExtPackManagerImpl.h"
71#endif
72
73
74/*********************************************************************************************************************************
75* Internal Functions *
76*********************************************************************************************************************************/
77
78/* Darwin compile kludge */
79#undef PVM
80
81#ifdef VBOX_WITH_VIRT_ARMV8
82/**
83 * Worker for configConstructor.
84 *
85 * @return VBox status code.
86 * @param pUVM The user mode VM handle.
87 * @param pVM The cross context VM handle.
88 * @param pVMM The VMM vtable.
89 * @param pAlock The automatic lock instance. This is for when we have
90 * to leave it in order to avoid deadlocks (ext packs and
91 * more).
92 *
93 * @todo This is a big hack at the moment and provides a static VM config to work with, will be adjusted later
94 * on to adhere to the VM config when sorting out the API bits.
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 /** @todo Find a way to figure it out before CPUM is set up, can't use CPUMGetGuestAddrWidths() and on macOS we need
113 * access to Hypervisor.framework to query the ID registers (Linux can in theory parse /proc/cpuinfo, no idea for Windows). */
114 RTGCPHYS GCPhysTopOfAddrSpace = RT_BIT_64(36);
115
116 /*
117 * Get necessary objects and frequently used parameters.
118 */
119 ComPtr<IVirtualBox> virtualBox;
120 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
121
122 ComPtr<IHost> host;
123 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
124
125 PlatformArchitecture_T platformArchHost;
126 hrc = host->COMGETTER(Architecture)(&platformArchHost); H();
127
128 ComPtr<ISystemProperties> systemProperties;
129 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
130
131 ComPtr<IFirmwareSettings> firmwareSettings;
132 hrc = pMachine->COMGETTER(FirmwareSettings)(firmwareSettings.asOutParam()); H();
133
134 ComPtr<INvramStore> nvramStore;
135 hrc = pMachine->COMGETTER(NonVolatileStore)(nvramStore.asOutParam()); H();
136
137 hrc = pMachine->COMGETTER(HardwareUUID)(bstr.asOutParam()); H();
138 RTUUID HardwareUuid;
139 vrc = RTUuidFromUtf16(&HardwareUuid, bstr.raw());
140 AssertRCReturn(vrc, vrc);
141
142 ULONG cRamMBs;
143 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
144 uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
145
146 ComPtr<IPlatform> platform;
147 hrc = pMachine->COMGETTER(Platform)(platform.asOutParam()); H();
148
149 /* Note: Should be guarded by VBOX_WITH_VIRT_ARMV8, but we check this anyway here. */
150#if 1 /* For now we only support running ARM VMs on ARM hosts. */
151 PlatformArchitecture_T platformArchMachine;
152 hrc = platform->COMGETTER(Architecture)(&platformArchMachine); H();
153 if (platformArchMachine != platformArchHost)
154 return pVMM->pfnVMR3SetError(pUVM, VERR_PLATFORM_ARCH_NOT_SUPPORTED, RT_SRC_POS,
155 N_("VM platform architecture (%s) not supported on this host (%s)."),
156 Global::stringifyPlatformArchitecture(platformArchMachine),
157 Global::stringifyPlatformArchitecture(platformArchHost));
158#endif
159
160 ComPtr<IPlatformProperties> pPlatformProperties;
161 hrc = platform->COMGETTER(Properties)(pPlatformProperties.asOutParam()); H();
162
163 ChipsetType_T chipsetType;
164 hrc = platform->COMGETTER(ChipsetType)(&chipsetType); H();
165
166 ULONG cCpus = 1;
167 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
168 Assert(cCpus);
169
170 ULONG ulCpuExecutionCap = 100;
171 hrc = pMachine->COMGETTER(CPUExecutionCap)(&ulCpuExecutionCap); H();
172
173 LogRel(("Guest architecture: ARM\n"));
174
175 Bstr osTypeId;
176 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
177 LogRel(("Guest OS type: '%s'\n", Utf8Str(osTypeId).c_str()));
178
179 BusAssignmentManager *pBusMgr = mBusMgr = BusAssignmentManager::createInstance(pVMM, chipsetType, IommuType_None);
180
181 /*
182 * Get root node first.
183 * This is the only node in the tree.
184 */
185 PCFGMNODE pRoot = pVMM->pfnCFGMR3GetRootU(pUVM);
186 Assert(pRoot);
187
188 // catching throws from InsertConfigString and friends.
189 try
190 {
191
192 /*
193 * Set the root (and VMM) level values.
194 */
195 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
196 InsertConfigString(pRoot, "Name", bstr);
197 InsertConfigBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid));
198 InsertConfigInteger(pRoot, "NumCPUs", cCpus);
199 InsertConfigInteger(pRoot, "CpuExecutionCap", ulCpuExecutionCap);
200 InsertConfigInteger(pRoot, "TimerMillies", 10);
201
202 /*
203 * NEM
204 */
205 PCFGMNODE pNEM;
206 InsertConfigNode(pRoot, "NEM", &pNEM);
207
208 uint32_t idPHandleIntCtrl = RTFdtPHandleAllocate(hFdt);
209 Assert(idPHandleIntCtrl != UINT32_MAX);
210 uint32_t idPHandleIntCtrlMsi = RTFdtPHandleAllocate(hFdt);
211 Assert(idPHandleIntCtrlMsi != UINT32_MAX); RT_NOREF(idPHandleIntCtrlMsi);
212 uint32_t idPHandleAbpPClk = RTFdtPHandleAllocate(hFdt);
213 Assert(idPHandleAbpPClk != UINT32_MAX);
214 uint32_t idPHandleGpio = RTFdtPHandleAllocate(hFdt);
215 Assert(idPHandleGpio != UINT32_MAX);
216
217 uint32_t aidPHandleCpus[VMM_MAX_CPU_COUNT];
218 for (uint32_t i = 0; i < cCpus; i++)
219 {
220 aidPHandleCpus[i] = RTFdtPHandleAllocate(hFdt);
221 Assert(aidPHandleCpus[i] != UINT32_MAX);
222 }
223
224 vrc = RTFdtNodePropertyAddU32( hFdt, "interrupt-parent", idPHandleIntCtrl); VRC();
225 vrc = RTFdtNodePropertyAddString(hFdt, "model", "linux,dummy-virt"); VRC();
226 vrc = RTFdtNodePropertyAddU32( hFdt, "#size-cells", 2); VRC();
227 vrc = RTFdtNodePropertyAddU32( hFdt, "#address-cells", 2); VRC();
228 vrc = RTFdtNodePropertyAddString(hFdt, "compatible", "linux,dummy-virt"); VRC();
229
230 /* Configure the Power State Coordination Interface. */
231 vrc = RTFdtNodeAdd(hFdt, "psci"); VRC();
232 vrc = RTFdtNodePropertyAddU32( hFdt, "migrate", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_MIGRATE)); VRC();
233 vrc = RTFdtNodePropertyAddU32( hFdt, "cpu_on", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_CPU_ON)); VRC();
234 vrc = RTFdtNodePropertyAddU32( hFdt, "cpu_off", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_CPU_OFF)); VRC();
235 vrc = RTFdtNodePropertyAddU32( hFdt, "cpu_suspend", ARM_PSCI_FUNC_ID_CREATE_FAST_32(ARM_PSCI_FUNC_ID_CPU_SUSPEND)); VRC();
236 vrc = RTFdtNodePropertyAddString(hFdt, "method", "hvc"); VRC();
237 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 3,
238 "arm,psci-1.0", "arm,psci-0.2", "arm,psci"); VRC();
239 vrc = RTFdtNodeFinalize(hFdt); VRC();
240
241 /* Configure the timer and clock. */
242 InsertConfigInteger(pNEM, "VTimerInterrupt", 0xb);
243 vrc = RTFdtNodeAdd(hFdt, "timer"); VRC();
244 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 12,
245 0x01, 0x0d, 0x104,
246 0x01, 0x0e, 0x104,
247 0x01, 0x0b, 0x104,
248 0x01, 0x0a, 0x104); VRC();
249 vrc = RTFdtNodePropertyAddEmpty( hFdt, "always-on"); VRC();
250 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "arm,armv7-timer"); VRC();
251 vrc = RTFdtNodeFinalize(hFdt);
252
253 vrc = RTFdtNodeAdd(hFdt, "apb-clk"); VRC();
254 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleAbpPClk); VRC();
255 vrc = RTFdtNodePropertyAddString( hFdt, "clock-output-names", "clk24mhz"); VRC();
256 vrc = RTFdtNodePropertyAddU32( hFdt, "clock-frequency", 24 * 1000 * 1000); VRC();
257 vrc = RTFdtNodePropertyAddU32( hFdt, "#clock-cells", 0); VRC();
258 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "fixed-clock"); VRC();
259 vrc = RTFdtNodeFinalize(hFdt);
260
261 /* Configure gpio keys (non functional at the moment). */
262 vrc = RTFdtNodeAdd(hFdt, "gpio-keys"); VRC();
263 vrc = RTFdtNodePropertyAddString(hFdt, "compatible", "gpio-keys"); VRC();
264
265 vrc = RTFdtNodeAdd(hFdt, "poweroff"); VRC();
266 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "gpios", 3, idPHandleGpio, 3, 0); VRC();
267 vrc = RTFdtNodePropertyAddU32( hFdt, "linux,code", 0x74); VRC();
268 vrc = RTFdtNodePropertyAddString( hFdt, "label", "GPIO Key Poweroff"); VRC();
269 vrc = RTFdtNodeFinalize(hFdt); VRC();
270
271 vrc = RTFdtNodeFinalize(hFdt); VRC();
272
273 /*
274 * MM values.
275 */
276 PCFGMNODE pMM;
277 InsertConfigNode(pRoot, "MM", &pMM);
278
279 /*
280 * Memory setup.
281 */
282 PCFGMNODE pMem = NULL;
283 InsertConfigNode(pMM, "MemRegions", &pMem);
284
285 PCFGMNODE pMemRegion = NULL;
286 InsertConfigNode(pMem, "Conventional", &pMemRegion);
287 InsertConfigInteger(pMemRegion, "GCPhysStart", 0x40000000);
288 InsertConfigInteger(pMemRegion, "Size", cbRam);
289
290 vrc = RTFdtNodeAddF(hFdt, "memory@%RX32", 0x40000000); VRC();
291 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4,
292 0, 0x40000000,
293 (uint32_t)(cbRam >> 32), cbRam & UINT32_MAX); VRC();
294 vrc = RTFdtNodePropertyAddString( hFdt, "device_type", "memory"); VRC();
295 vrc = RTFdtNodeFinalize(hFdt); VRC();
296
297 /* Configure the CPUs in the system, only one socket and cluster at the moment. */
298 vrc = RTFdtNodeAdd(hFdt, "cpus"); VRC();
299 vrc = RTFdtNodePropertyAddU32(hFdt, "#size-cells", 0); VRC();
300 vrc = RTFdtNodePropertyAddU32(hFdt, "#address-cells", 1); VRC();
301
302 vrc = RTFdtNodeAdd(hFdt, "socket0"); VRC();
303 vrc = RTFdtNodeAdd(hFdt, "cluster0"); VRC();
304
305 for (uint32_t i = 0; i < cCpus; i++)
306 {
307 vrc = RTFdtNodeAddF(hFdt, "core%u", i); VRC();
308 vrc = RTFdtNodePropertyAddU32(hFdt, "cpu", aidPHandleCpus[i]); VRC();
309 vrc = RTFdtNodeFinalize(hFdt); VRC();
310 }
311
312 vrc = RTFdtNodeFinalize(hFdt); VRC();
313 vrc = RTFdtNodeFinalize(hFdt); VRC();
314
315 for (uint32_t i = 0; i < cCpus; i++)
316 {
317 vrc = RTFdtNodeAddF(hFdt, "cpu@%u", i); VRC();
318 vrc = RTFdtNodePropertyAddU32(hFdt, "phandle", aidPHandleCpus[i]); VRC();
319 vrc = RTFdtNodePropertyAddU32(hFdt, "reg", i); VRC();
320 vrc = RTFdtNodePropertyAddString(hFdt, "compatible", "arm,cortex-a15"); VRC();
321 vrc = RTFdtNodePropertyAddString(hFdt, "device_type", "cpu"); VRC();
322 if (cCpus > 1)
323 {
324 vrc = RTFdtNodePropertyAddString(hFdt, "enable-method", "psci"); VRC();
325 }
326 vrc = RTFdtNodeFinalize(hFdt); VRC();
327 }
328
329 vrc = RTFdtNodeFinalize(hFdt); VRC();
330
331
332 /*
333 * PDM config.
334 * Load drivers in VBoxC.[so|dll]
335 */
336 vrc = i_configPdm(pMachine, pVMM, pUVM, pRoot); VRC();
337
338
339 /*
340 * VGA.
341 */
342 ComPtr<IGraphicsAdapter> pGraphicsAdapter;
343 hrc = pMachine->COMGETTER(GraphicsAdapter)(pGraphicsAdapter.asOutParam()); H();
344 GraphicsControllerType_T enmGraphicsController;
345 hrc = pGraphicsAdapter->COMGETTER(GraphicsControllerType)(&enmGraphicsController); H();
346
347 /*
348 * Devices
349 */
350 PCFGMNODE pDevices = NULL; /* /Devices */
351 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
352 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
353 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
354 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
355
356 InsertConfigNode(pRoot, "Devices", &pDevices);
357
358 InsertConfigNode(pDevices, "pci-generic-ecam-bridge", NULL);
359
360 InsertConfigNode(pDevices, "platform", &pDev);
361 InsertConfigNode(pDev, "0", &pInst);
362 InsertConfigNode(pInst, "Config", &pCfg);
363 InsertConfigNode(pInst, "LUN#0", &pLunL0);
364 InsertConfigString(pLunL0, "Driver", "ResourceStore");
365
366 /* Add the resources. */
367 PCFGMNODE pResources = NULL; /* /Devices/platform/Config/Resources */
368 PCFGMNODE pRes = NULL; /* /Devices/platform/Config/Resources/<Resource> */
369 InsertConfigString(pCfg, "ResourceNamespace", "resources");
370 InsertConfigNode(pCfg, "Resources", &pResources);
371 InsertConfigNode(pResources, "EfiRom", &pRes);
372 InsertConfigInteger(pRes, "RegisterAsRom", 1);
373 InsertConfigInteger(pRes, "GCPhysLoadAddress", 0);
374
375 /** @todo r=aeichner 32-bit guests and query the firmware type from VBoxSVC. */
376 /*
377 * Firmware.
378 */
379 FirmwareType_T eFwType = FirmwareType_EFI64;
380#ifdef VBOX_WITH_EFI_IN_DD2
381 const char *pszEfiRomFile = eFwType == FirmwareType_EFIDUAL ? "<INVALID>"
382 : eFwType == FirmwareType_EFI32 ? "VBoxEFIAArch32.fd"
383 : "VBoxEFIAArch64.fd";
384 const char *pszKey = "ResourceId";
385#else
386 Utf8Str efiRomFile;
387 vrc = findEfiRom(virtualBox, PlatformArchitecture_ARM, eFwType, &efiRomFile);
388 AssertRCReturn(vrc, vrc);
389 const char *pszEfiRomFile = efiRomFile.c_str();
390 const char *pszKey = "Filename";
391#endif
392 InsertConfigString(pRes, pszKey, pszEfiRomFile);
393
394 InsertConfigNode(pResources, "ArmV8Desc", &pRes);
395 InsertConfigInteger(pRes, "RegisterAsRom", 1);
396 InsertConfigInteger(pRes, "GCPhysLoadAddress", UINT64_MAX); /* End of physical address space. */
397 InsertConfigString(pRes, "ResourceId", "VBoxArmV8Desc");
398
399 /*
400 * Configure the interrupt controller.
401 */
402 InsertConfigNode(pDevices, "gic", &pDev);
403 InsertConfigNode(pDev, "0", &pInst);
404 InsertConfigInteger(pInst, "Trusted", 1);
405 InsertConfigNode(pInst, "Config", &pCfg);
406 InsertConfigInteger(pCfg, "DistributorMmioBase", 0x08000000);
407 InsertConfigInteger(pCfg, "RedistributorMmioBase", 0x080a0000);
408
409 vrc = RTFdtNodeAddF(hFdt, "intc@%RX32", 0x08000000); VRC();
410 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleIntCtrl); VRC();
411 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 8,
412 0, 0x08000000, 0, 0x10000,
413 0, 0x080a0000, 0, 0xf60000); VRC();
414 vrc = RTFdtNodePropertyAddU32( hFdt, "#redistributor-regions", 1); VRC();
415 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "arm,gic-v3"); VRC();
416 vrc = RTFdtNodePropertyAddEmpty( hFdt, "ranges"); VRC();
417 vrc = RTFdtNodePropertyAddU32( hFdt, "#size-cells", 2); VRC();
418 vrc = RTFdtNodePropertyAddU32( hFdt, "#address-cells", 2); VRC();
419 vrc = RTFdtNodePropertyAddEmpty( hFdt, "interrupt-controller"); VRC();
420 vrc = RTFdtNodePropertyAddU32( hFdt, "#interrupt-cells", 3); VRC();
421
422#if 0
423 vrc = RTFdtNodeAddF(hFdt, "its@%RX32", 0x08080000); VRC();
424 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleIntCtrlMsi); VRC();
425 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4, 0, 0x08080000, 0, 0x20000); VRC();
426 vrc = RTFdtNodePropertyAddU32( hFdt, "#msi-cells", 1); VRC();
427 vrc = RTFdtNodePropertyAddEmpty( hFdt, "msi-controller"); VRC();
428 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "arm,gic-v3-its"); VRC();
429 vrc = RTFdtNodeFinalize(hFdt); VRC();
430#endif
431
432 vrc = RTFdtNodeFinalize(hFdt); VRC();
433
434 if (enmGraphicsController == GraphicsControllerType_QemuRamFB)
435 {
436 InsertConfigNode(pDevices, "qemu-fw-cfg", &pDev);
437 InsertConfigNode(pDev, "0", &pInst);
438 InsertConfigNode(pInst, "Config", &pCfg);
439 InsertConfigInteger(pCfg, "MmioSize", 4096);
440 InsertConfigInteger(pCfg, "MmioBase", 0x09020000);
441 InsertConfigInteger(pCfg, "DmaEnabled", 1);
442 InsertConfigInteger(pCfg, "QemuRamfbSupport", 1);
443 InsertConfigNode(pInst, "LUN#0", &pLunL0);
444 InsertConfigString(pLunL0, "Driver", "MainDisplay");
445
446 vrc = RTFdtNodeAddF(hFdt, "fw-cfg@%RX32", 0x09020000); VRC();
447 vrc = RTFdtNodePropertyAddEmpty( hFdt, "dma-coherent"); VRC();
448 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4, 0, 0x09020000, 0, 0x18); VRC();
449 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "qemu,fw-cfg-mmio"); VRC();
450 vrc = RTFdtNodeFinalize(hFdt); VRC();
451 }
452
453 InsertConfigNode(pDevices, "flash-cfi", &pDev);
454 InsertConfigNode(pDev, "0", &pInst);
455 InsertConfigNode(pInst, "Config", &pCfg);
456 InsertConfigInteger(pCfg, "BaseAddress", 64 * _1M);
457 InsertConfigInteger(pCfg, "Size", 768 * _1K);
458 InsertConfigString(pCfg, "FlashFile", "nvram");
459 /* Attach the NVRAM storage driver. */
460 InsertConfigNode(pInst, "LUN#0", &pLunL0);
461 InsertConfigString(pLunL0, "Driver", "NvramStore");
462
463 vrc = RTFdtNodeAddF(hFdt, "flash@%RX32", 0); VRC();
464 vrc = RTFdtNodePropertyAddU32( hFdt, "bank-width", 4); VRC();
465 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 8,
466 0, 0, 0, 0x04000000,
467 0, 0x04000000, 0, 0x04000000); VRC();
468 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "cfi-flash"); VRC();
469 vrc = RTFdtNodeFinalize(hFdt); VRC();
470
471 InsertConfigNode(pDevices, "arm-pl011", &pDev);
472 for (ULONG ulInstance = 0; ulInstance < 1 /** @todo SchemaDefs::SerialPortCount*/; ++ulInstance)
473 {
474 ComPtr<ISerialPort> serialPort;
475 hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam()); H();
476 BOOL fEnabledSerPort = FALSE;
477 if (serialPort)
478 {
479 hrc = serialPort->COMGETTER(Enabled)(&fEnabledSerPort); H();
480 }
481 if (!fEnabledSerPort)
482 {
483 m_aeSerialPortMode[ulInstance] = PortMode_Disconnected;
484 continue;
485 }
486
487 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
488 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
489 InsertConfigNode(pInst, "Config", &pCfg);
490
491 InsertConfigInteger(pCfg, "Irq", 1);
492 InsertConfigInteger(pCfg, "MmioBase", 0x09000000);
493
494 vrc = RTFdtNodeAddF(hFdt, "pl011@%RX32", 0x09000000); VRC();
495 vrc = RTFdtNodePropertyAddStringList(hFdt, "clock-names", 2, "uartclk", "apb_pclk"); VRC();
496 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "clocks", 2,
497 idPHandleAbpPClk, idPHandleAbpPClk); VRC();
498 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 3, 0x00, 0x01, 0x04); VRC();
499 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4, 0, 0x09000000, 0, 0x1000); VRC();
500 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 2,
501 "arm,pl011", "arm,primecell"); VRC();
502 vrc = RTFdtNodeFinalize(hFdt); VRC();
503
504 BOOL fServer;
505 hrc = serialPort->COMGETTER(Server)(&fServer); H();
506 hrc = serialPort->COMGETTER(Path)(bstr.asOutParam()); H();
507
508 PortMode_T eHostMode;
509 hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
510
511 m_aeSerialPortMode[ulInstance] = eHostMode;
512 if (eHostMode != PortMode_Disconnected)
513 {
514 vrc = i_configSerialPort(pInst, eHostMode, Utf8Str(bstr).c_str(), RT_BOOL(fServer));
515 if (RT_FAILURE(vrc))
516 return vrc;
517 }
518 }
519
520 BOOL fRTCUseUTC;
521 hrc = platform->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
522
523 InsertConfigNode(pDevices, "arm-pl031-rtc", &pDev);
524 InsertConfigNode(pDev, "0", &pInst);
525 InsertConfigNode(pInst, "Config", &pCfg);
526 InsertConfigInteger(pCfg, "Irq", 2);
527 InsertConfigInteger(pCfg, "MmioBase", 0x09010000);
528 InsertConfigInteger(pCfg, "UtcOffset", fRTCUseUTC ? 1 : 0);
529
530 vrc = RTFdtNodeAddF(hFdt, "pl032@%RX32", 0x09010000); VRC();
531 vrc = RTFdtNodePropertyAddString( hFdt, "clock-names", "apb_pclk"); VRC();
532 vrc = RTFdtNodePropertyAddU32( hFdt, "clocks", idPHandleAbpPClk); VRC();
533 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 3, 0x00, 0x02, 0x04); VRC();
534 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4, 0, 0x09010000, 0, 0x1000); VRC();
535 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 2,
536 "arm,pl031", "arm,primecell"); VRC();
537 vrc = RTFdtNodeFinalize(hFdt); VRC();
538
539 InsertConfigNode(pDevices, "arm-pl061-gpio",&pDev);
540 InsertConfigNode(pDev, "0", &pInst);
541 InsertConfigNode(pInst, "Config", &pCfg);
542 InsertConfigInteger(pCfg, "Irq", 7);
543 InsertConfigInteger(pCfg, "MmioBase", 0x09030000);
544 vrc = RTFdtNodeAddF(hFdt, "pl061@%RX32", 0x09030000); VRC();
545 vrc = RTFdtNodePropertyAddU32( hFdt, "phandle", idPHandleGpio); VRC();
546 vrc = RTFdtNodePropertyAddString( hFdt, "clock-names", "apb_pclk"); VRC();
547 vrc = RTFdtNodePropertyAddU32( hFdt, "clocks", idPHandleAbpPClk); VRC();
548 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupts", 3, 0x00, 0x07, 0x04); VRC();
549 vrc = RTFdtNodePropertyAddEmpty( hFdt, "gpio-controller"); VRC();
550 vrc = RTFdtNodePropertyAddU32( hFdt, "#gpio-cells", 2); VRC();
551 vrc = RTFdtNodePropertyAddStringList(hFdt, "compatible", 2,
552 "arm,pl061", "arm,primecell"); VRC();
553 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4, 0, 0x09030000, 0, 0x1000); VRC();
554 vrc = RTFdtNodeFinalize(hFdt); VRC();
555
556 uint32_t aPinIrqs[] = { 3, 4, 5, 6 };
557 InsertConfigNode(pDevices, "pci-generic-ecam", &pDev);
558 InsertConfigNode(pDev, "0", &pInst);
559 InsertConfigNode(pInst, "Config", &pCfg);
560 InsertConfigInteger(pCfg, "MmioEcamBase", 0x3f000000);
561 InsertConfigInteger(pCfg, "MmioEcamLength", 0x01000000);
562 InsertConfigInteger(pCfg, "MmioPioBase", 0x3eff0000);
563 InsertConfigInteger(pCfg, "MmioPioSize", 0x0000ffff);
564 InsertConfigInteger(pCfg, "IntPinA", aPinIrqs[0]);
565 InsertConfigInteger(pCfg, "IntPinB", aPinIrqs[1]);
566 InsertConfigInteger(pCfg, "IntPinC", aPinIrqs[2]);
567 InsertConfigInteger(pCfg, "IntPinD", aPinIrqs[3]);
568 vrc = RTFdtNodeAddF(hFdt, "pcie@%RX32", 0x10000000); VRC();
569 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "interrupt-map-mask", 4, 0xf800, 0, 0, 7); VRC();
570
571 uint32_t aIrqCells[32 * 4 * 10]; RT_ZERO(aIrqCells); /* Maximum of 32 devices on the root bus, each supporting 4 interrupts (INTA# ... INTD#). */
572 uint32_t *pau32IrqCell = &aIrqCells[0];
573 uint32_t iIrqPinSwizzle = 0;
574
575 for (uint32_t i = 0; i < 32; i++)
576 {
577 for (uint32_t iIrqPin = 0; iIrqPin < 4; iIrqPin++)
578 {
579 pau32IrqCell[0] = i << 11; /* The dev part, composed as dev.fn. */
580 pau32IrqCell[1] = 0;
581 pau32IrqCell[2] = 0;
582 pau32IrqCell[3] = iIrqPin + 1;
583 pau32IrqCell[4] = idPHandleIntCtrl;
584 pau32IrqCell[5] = 0;
585 pau32IrqCell[6] = 0;
586 pau32IrqCell[7] = 0;
587 pau32IrqCell[8] = aPinIrqs[(iIrqPinSwizzle + iIrqPin) % RT_ELEMENTS(aPinIrqs)];
588 pau32IrqCell[9] = 0x04;
589 pau32IrqCell += 10;
590 }
591
592 iIrqPinSwizzle++;
593 }
594
595 vrc = RTFdtNodePropertyAddCellsU32AsArray(hFdt, "interrupt-map", RT_ELEMENTS(aIrqCells), &aIrqCells[0]);
596 vrc = RTFdtNodePropertyAddU32( hFdt, "#interrupt-cells", 1); VRC();
597 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "ranges", 14,
598 0x1000000, 0, 0, 0, 0x3eff0000, 0, 0x10000,
599 0x2000000, 0, 0x10000000, 0, 0x10000000, 0,
600 0x2eff0000); VRC();
601 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "reg", 4, 0, 0x3f000000, 0, 0x1000000); VRC();
602 /** @todo msi-map */
603 vrc = RTFdtNodePropertyAddEmpty( hFdt, "dma-coherent"); VRC();
604 vrc = RTFdtNodePropertyAddCellsU32(hFdt, "bus-range", 2, 0, 0xf); VRC();
605 vrc = RTFdtNodePropertyAddU32( hFdt, "linux,pci-domain", 0); VRC();
606 vrc = RTFdtNodePropertyAddU32( hFdt, "#size-cells", 2); VRC();
607 vrc = RTFdtNodePropertyAddU32( hFdt, "#address-cells", 3); VRC();
608 vrc = RTFdtNodePropertyAddString( hFdt, "device_type", "pci"); VRC();
609 vrc = RTFdtNodePropertyAddString( hFdt, "compatible", "pci-host-ecam-generic"); VRC();
610 vrc = RTFdtNodeFinalize(hFdt); VRC();
611
612 /*
613 * VMSVGA compliant graphics controller.
614 */
615 if ( enmGraphicsController != GraphicsControllerType_QemuRamFB
616 && enmGraphicsController != GraphicsControllerType_Null)
617 {
618 vrc = i_configGraphicsController(pDevices, enmGraphicsController, pBusMgr, pMachine,
619 pGraphicsAdapter, firmwareSettings,
620 true /*fForceVmSvga3*/, false /*fExposeLegacyVga*/); VRC();
621 }
622
623 /*
624 * The USB Controllers and input devices.
625 */
626#if 0 /** @todo Make us of this and disallow PS/2 for ARM VMs for now. */
627 KeyboardHIDType_T aKbdHID;
628 hrc = pMachine->COMGETTER(KeyboardHIDType)(&aKbdHID); H();
629#endif
630
631 PointingHIDType_T aPointingHID;
632 hrc = pMachine->COMGETTER(PointingHIDType)(&aPointingHID); H();
633
634 PCFGMNODE pUsbDevices = NULL;
635 vrc = i_configUsb(pMachine, pBusMgr, pRoot, pDevices, KeyboardHIDType_USBKeyboard, aPointingHID, &pUsbDevices);
636
637 /*
638 * Storage controllers.
639 */
640 bool fFdcEnabled = false;
641 vrc = i_configStorageCtrls(pMachine, pBusMgr, pVMM, pUVM,
642 pDevices, pUsbDevices, NULL /*pBiosCfg*/, &fFdcEnabled); VRC();
643
644 /*
645 * Network adapters
646 */
647 std::list<BootNic> llBootNics;
648 vrc = i_configNetworkCtrls(pMachine, pPlatformProperties, chipsetType, pBusMgr,
649 pVMM, pUVM, pDevices, llBootNics); VRC();
650
651 /*
652 * The VMM device.
653 */
654 vrc = i_configVmmDev(pMachine, pBusMgr, pDevices, true /*fMmioReq*/); VRC();
655
656 /*
657 * Audio configuration.
658 */
659 bool fAudioEnabled = false;
660 vrc = i_configAudioCtrl(virtualBox, pMachine, pBusMgr, pDevices,
661 false /*fOsXGuest*/, &fAudioEnabled); VRC();
662 }
663 catch (ConfigError &x)
664 {
665 RTFdtDestroy(hFdt);
666
667 // InsertConfig threw something:
668 pVMM->pfnVMR3SetError(pUVM, x.m_vrc, RT_SRC_POS, "Caught ConfigError: %Rrc - %s", x.m_vrc, x.what());
669 return x.m_vrc;
670 }
671 catch (HRESULT hrcXcpt)
672 {
673 RTFdtDestroy(hFdt);
674 AssertLogRelMsgFailedReturn(("hrc=%Rhrc\n", hrcXcpt), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR);
675 }
676
677#ifdef VBOX_WITH_EXTPACK
678 /*
679 * Call the extension pack hooks if everything went well thus far.
680 */
681 if (RT_SUCCESS(vrc))
682 {
683 pAlock->release();
684 vrc = mptrExtPackManager->i_callAllVmConfigureVmmHooks(this, pVM, pVMM);
685 pAlock->acquire();
686 }
687#endif
688
689#if 0
690 vrc = RTFdtNodeAdd(hFdt, "chosen"); VRC();
691 vrc = RTFdtNodePropertyAddString( hFdt, "stdout-path", "pl011@9000000"); VRC();
692 vrc = RTFdtNodePropertyAddString( hFdt, "stdin-path", "pl011@9000000"); VRC();
693 vrc = RTFdtNodeFinalize(hFdt);
694#endif
695
696 /* Finalize the FDT and add it to the resource store. */
697 vrc = RTFdtFinalize(hFdt);
698 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
699
700 RTVFSFILE hVfsFileDesc = NIL_RTVFSFILE;
701 vrc = RTVfsMemFileCreate(NIL_RTVFSIOSTREAM, 0 /*cbEstimate*/, &hVfsFileDesc);
702 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
703 RTVFSIOSTREAM hVfsIosDesc = RTVfsFileToIoStream(hVfsFileDesc);
704 AssertRelease(hVfsIosDesc != NIL_RTVFSIOSTREAM);
705
706 /* Initialize the VBox platform descriptor. */
707 VBOXPLATFORMARMV8 ArmV8Platform; RT_ZERO(ArmV8Platform);
708
709 vrc = RTFdtDumpToVfsIoStrm(hFdt, RTFDTTYPE_DTB, 0 /*fFlags*/, hVfsIosDesc, NULL /*pErrInfo*/);
710 if (RT_SUCCESS(vrc))
711 vrc = RTVfsFileQuerySize(hVfsFileDesc, &ArmV8Platform.cbFdt);
712 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
713
714 vrc = RTVfsIoStrmZeroFill(hVfsIosDesc, (RTFOFF)(RT_ALIGN_64(ArmV8Platform.cbFdt, _64K) - ArmV8Platform.cbFdt));
715 AssertRCReturn(vrc, vrc);
716
717 ArmV8Platform.u32Magic = VBOXPLATFORMARMV8_MAGIC;
718 ArmV8Platform.u32Version = VBOXPLATFORMARMV8_VERSION;
719 ArmV8Platform.cbDesc = sizeof(ArmV8Platform);
720 ArmV8Platform.fFlags = 0;
721 ArmV8Platform.u64PhysAddrRamBase = UINT64_C(0x40000000);
722 ArmV8Platform.cbRamBase = cbRam;
723 ArmV8Platform.u64OffBackFdt = RT_ALIGN_64(ArmV8Platform.cbFdt, _64K);
724 ArmV8Platform.cbFdt = RT_ALIGN_64(ArmV8Platform.cbFdt, _64K);
725 ArmV8Platform.u64OffBackAcpiXsdp = 0;
726 ArmV8Platform.cbAcpiXsdp = 0;
727 ArmV8Platform.u64OffBackUefiRom = GCPhysTopOfAddrSpace - sizeof(ArmV8Platform);
728 ArmV8Platform.cbUefiRom = _64M; /** @todo Fixed reservation but the ROM region is usually much smaller. */
729 ArmV8Platform.u64OffBackMmio = GCPhysTopOfAddrSpace - sizeof(ArmV8Platform) - 0x08000000; /** @todo Start of generic MMIO area containing the GIC,UART,RTC, etc. Will be changed soon */
730 ArmV8Platform.cbMmio = _128M;
731
732 /* Add the VBox platform descriptor to the resource store. */
733 vrc = RTVfsIoStrmWrite(hVfsIosDesc, &ArmV8Platform, sizeof(ArmV8Platform), true /*fBlocking*/, NULL /*pcbWritten*/);
734 RTVfsIoStrmRelease(hVfsIosDesc);
735 vrc = mptrResourceStore->i_addItem("resources", "VBoxArmV8Desc", hVfsFileDesc);
736 RTVfsFileRelease(hVfsFileDesc);
737 AssertRCReturn(vrc, vrc);
738
739 /* Dump the DTB for debugging purposes if requested. */
740 Bstr DtbDumpVal;
741 hrc = mMachine->GetExtraData(Bstr("VBoxInternal2/DumpDtb").raw(),
742 DtbDumpVal.asOutParam());
743 if ( hrc == S_OK
744 && DtbDumpVal.isNotEmpty())
745 {
746 vrc = RTFdtDumpToFile(hFdt, RTFDTTYPE_DTB, 0 /*fFlags*/, Utf8Str(DtbDumpVal).c_str(), NULL /*pErrInfo*/);
747 AssertRCReturnStmt(vrc, RTFdtDestroy(hFdt), vrc);
748 }
749
750
751 /*
752 * Apply the CFGM overlay.
753 */
754 if (RT_SUCCESS(vrc))
755 vrc = i_configCfgmOverlay(pRoot, virtualBox, pMachine);
756
757 /*
758 * Dump all extradata API settings tweaks, both global and per VM.
759 */
760 if (RT_SUCCESS(vrc))
761 vrc = i_configDumpAPISettingsTweaks(virtualBox, pMachine);
762
763#undef H
764
765 pAlock->release(); /* Avoid triggering the lock order inversion check. */
766
767 /*
768 * Register VM state change handler.
769 */
770 int vrc2 = pVMM->pfnVMR3AtStateRegister(pUVM, Console::i_vmstateChangeCallback, this);
771 AssertRC(vrc2);
772 if (RT_SUCCESS(vrc))
773 vrc = vrc2;
774
775 /*
776 * Register VM runtime error handler.
777 */
778 vrc2 = pVMM->pfnVMR3AtRuntimeErrorRegister(pUVM, Console::i_atVMRuntimeErrorCallback, this);
779 AssertRC(vrc2);
780 if (RT_SUCCESS(vrc))
781 vrc = vrc2;
782
783 pAlock->acquire();
784
785 LogFlowFunc(("vrc = %Rrc\n", vrc));
786 LogFlowFuncLeave();
787
788 return vrc;
789}
790#endif /* !VBOX_WITH_VIRT_ARMV8 */
791
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette