VirtualBox

source: vbox/trunk/src/VBox/Devices/VMMDev/VMMDev.cpp@ 91921

Last change on this file since 91921 was 91921, checked in by vboxsync, 3 years ago

VMM,Devices: Eliminate direct calls to PGMR3SharedModule* APIs and introduce callbacks in the device helper callback table, bugref:10074

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 201.0 KB
Line 
1/* $Id: VMMDev.cpp 91921 2021-10-21 07:41:36Z vboxsync $ */
2/** @file
3 * VMMDev - Guest <-> VMM/Host communication device.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/** @page pg_vmmdev The VMM Device.
19 *
20 * The VMM device is a custom hardware device emulation for communicating with
21 * the guest additions.
22 *
23 * Whenever host wants to inform guest about something an IRQ notification will
24 * be raised.
25 *
26 * VMMDev PDM interface will contain the guest notification method.
27 *
28 * There is a 32 bit event mask which will be read by guest on an interrupt. A
29 * non zero bit in the mask means that the specific event occurred and requires
30 * processing on guest side.
31 *
32 * After reading the event mask guest must issue a generic request
33 * AcknowlegdeEvents.
34 *
35 * IRQ line is set to 1 (request) if there are unprocessed events, that is the
36 * event mask is not zero.
37 *
38 * After receiving an interrupt and checking event mask, the guest must process
39 * events using the event specific mechanism.
40 *
41 * That is if mouse capabilities were changed, guest will use
42 * VMMDev_GetMouseStatus generic request.
43 *
44 * Event mask is only a set of flags indicating that guest must proceed with a
45 * procedure.
46 *
47 * Unsupported events are therefore ignored. The guest additions must inform
48 * host which events they want to receive, to avoid unnecessary IRQ processing.
49 * By default no events are signalled to guest.
50 *
51 * This seems to be fast method. It requires only one context switch for an
52 * event processing.
53 *
54 *
55 * @section sec_vmmdev_heartbeat Heartbeat
56 *
57 * The heartbeat is a feature to monitor whether the guest OS is hung or not.
58 *
59 * The main kernel component of the guest additions, VBoxGuest, sets up a timer
60 * at a frequency returned by VMMDevReq_HeartbeatConfigure
61 * (VMMDevReqHeartbeat::cNsInterval, VMMDEV::cNsHeartbeatInterval) and performs
62 * a VMMDevReq_GuestHeartbeat request every time the timer ticks.
63 *
64 * The host side (VMMDev) arms a timer with a more distant deadline
65 * (VMMDEV::cNsHeartbeatTimeout), twice cNsHeartbeatInterval by default. Each
66 * time a VMMDevReq_GuestHeartbeat request comes in, the timer is rearmed with
67 * the same relative deadline. So, as long as VMMDevReq_GuestHeartbeat comes
68 * when they should, the host timer will never fire.
69 *
70 * When the timer fires, we consider the guest as hung / flatlined / dead.
71 * Currently we only LogRel that, but it's easy to extend this with an event in
72 * Main API.
73 *
74 * Should the guest reawaken at some later point, we LogRel that event and
75 * continue as normal. Again something which would merit an API event.
76 *
77 */
78
79
80/*********************************************************************************************************************************
81* Header Files *
82*********************************************************************************************************************************/
83/* Enable dev_vmm Log3 statements to get IRQ-related logging. */
84#define LOG_GROUP LOG_GROUP_DEV_VMM
85#include <VBox/AssertGuest.h>
86#include <VBox/VMMDev.h>
87#include <VBox/vmm/dbgf.h>
88#include <VBox/vmm/mm.h>
89#include <VBox/log.h>
90#include <VBox/param.h>
91#include <iprt/path.h>
92#include <iprt/dir.h>
93#include <iprt/file.h>
94#include <VBox/vmm/pgm.h>
95#include <VBox/err.h>
96#include <VBox/dbg.h>
97#include <VBox/version.h>
98
99#include <iprt/asm.h>
100#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
101# include <iprt/asm-amd64-x86.h> /* ASMReadTsc */
102#endif
103#include <iprt/assert.h>
104#include <iprt/buildconfig.h>
105#include <iprt/string.h>
106#include <iprt/system.h>
107#include <iprt/time.h>
108#ifndef IN_RC
109# include <iprt/mem.h>
110# include <iprt/memsafer.h>
111#endif
112#ifdef IN_RING3
113# include <iprt/uuid.h>
114#endif
115
116#include "VMMDevState.h"
117#ifdef VBOX_WITH_HGCM
118# include "VMMDevHGCM.h"
119#endif
120#ifndef VBOX_WITHOUT_TESTING_FEATURES
121# include "VMMDevTesting.h"
122#endif
123
124
125/*********************************************************************************************************************************
126* Defined Constants And Macros *
127*********************************************************************************************************************************/
128#define VMMDEV_INTERFACE_VERSION_IS_1_03(s) \
129 ( RT_HIWORD((s)->guestInfo.interfaceVersion) == 1 \
130 && RT_LOWORD((s)->guestInfo.interfaceVersion) == 3 )
131
132#define VMMDEV_INTERFACE_VERSION_IS_OK(additionsVersion) \
133 ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
134 && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) )
135
136#define VMMDEV_INTERFACE_VERSION_IS_OLD(additionsVersion) \
137 ( (RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) \
138 || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
139 && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) ) )
140
141#define VMMDEV_INTERFACE_VERSION_IS_TOO_OLD(additionsVersion) \
142 ( RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) )
143
144#define VMMDEV_INTERFACE_VERSION_IS_NEW(additionsVersion) \
145 ( RT_HIWORD(additionsVersion) > RT_HIWORD(VMMDEV_VERSION) \
146 || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
147 && RT_LOWORD(additionsVersion) > RT_LOWORD(VMMDEV_VERSION) ) )
148
149/** Default interval in nanoseconds between guest heartbeats.
150 * Used when no HeartbeatInterval is set in CFGM and for setting
151 * HB check timer if the guest's heartbeat frequency is less than 1Hz. */
152#define VMMDEV_HEARTBEAT_DEFAULT_INTERVAL (2U*RT_NS_1SEC_64)
153
154
155#ifndef VBOX_DEVICE_STRUCT_TESTCASE
156#ifdef IN_RING3
157
158/* -=-=-=-=- Misc Helpers -=-=-=-=- */
159
160/**
161 * Log information about the Guest Additions.
162 *
163 * @param pGuestInfo The information we've got from the Guest Additions driver.
164 */
165static void vmmdevLogGuestOsInfo(VBoxGuestInfo *pGuestInfo)
166{
167 const char *pszOs;
168 switch (pGuestInfo->osType & ~VBOXOSTYPE_x64)
169 {
170 case VBOXOSTYPE_DOS: pszOs = "DOS"; break;
171 case VBOXOSTYPE_Win31: pszOs = "Windows 3.1"; break;
172 case VBOXOSTYPE_Win9x: pszOs = "Windows 9x"; break;
173 case VBOXOSTYPE_Win95: pszOs = "Windows 95"; break;
174 case VBOXOSTYPE_Win98: pszOs = "Windows 98"; break;
175 case VBOXOSTYPE_WinMe: pszOs = "Windows Me"; break;
176 case VBOXOSTYPE_WinNT: pszOs = "Windows NT"; break;
177 case VBOXOSTYPE_WinNT3x: pszOs = "Windows NT 3.x"; break;
178 case VBOXOSTYPE_WinNT4: pszOs = "Windows NT4"; break;
179 case VBOXOSTYPE_Win2k: pszOs = "Windows 2k"; break;
180 case VBOXOSTYPE_WinXP: pszOs = "Windows XP"; break;
181 case VBOXOSTYPE_Win2k3: pszOs = "Windows 2k3"; break;
182 case VBOXOSTYPE_WinVista: pszOs = "Windows Vista"; break;
183 case VBOXOSTYPE_Win2k8: pszOs = "Windows 2k8"; break;
184 case VBOXOSTYPE_Win7: pszOs = "Windows 7"; break;
185 case VBOXOSTYPE_Win8: pszOs = "Windows 8"; break;
186 case VBOXOSTYPE_Win2k12_x64 & ~VBOXOSTYPE_x64: pszOs = "Windows 2k12"; break;
187 case VBOXOSTYPE_Win81: pszOs = "Windows 8.1"; break;
188 case VBOXOSTYPE_Win10: pszOs = "Windows 10"; break;
189 case VBOXOSTYPE_Win2k16_x64 & ~VBOXOSTYPE_x64: pszOs = "Windows 2k16"; break;
190 case VBOXOSTYPE_Win2k19_x64 & ~VBOXOSTYPE_x64: pszOs = "Windows 2k19"; break;
191 case VBOXOSTYPE_Win11_x64 & ~VBOXOSTYPE_x64: pszOs = "Windows 11"; break;
192 case VBOXOSTYPE_OS2: pszOs = "OS/2"; break;
193 case VBOXOSTYPE_OS2Warp3: pszOs = "OS/2 Warp 3"; break;
194 case VBOXOSTYPE_OS2Warp4: pszOs = "OS/2 Warp 4"; break;
195 case VBOXOSTYPE_OS2Warp45: pszOs = "OS/2 Warp 4.5"; break;
196 case VBOXOSTYPE_ECS: pszOs = "OS/2 ECS"; break;
197 case VBOXOSTYPE_OS21x: pszOs = "OS/2 2.1x"; break;
198 case VBOXOSTYPE_Linux: pszOs = "Linux"; break;
199 case VBOXOSTYPE_Linux22: pszOs = "Linux 2.2"; break;
200 case VBOXOSTYPE_Linux24: pszOs = "Linux 2.4"; break;
201 case VBOXOSTYPE_Linux26: pszOs = "Linux >= 2.6"; break;
202 case VBOXOSTYPE_ArchLinux: pszOs = "ArchLinux"; break;
203 case VBOXOSTYPE_Debian: pszOs = "Debian"; break;
204 case VBOXOSTYPE_OpenSUSE: pszOs = "openSUSE"; break;
205 case VBOXOSTYPE_FedoraCore: pszOs = "Fedora"; break;
206 case VBOXOSTYPE_Gentoo: pszOs = "Gentoo"; break;
207 case VBOXOSTYPE_Mandriva: pszOs = "Mandriva"; break;
208 case VBOXOSTYPE_RedHat: pszOs = "RedHat"; break;
209 case VBOXOSTYPE_Turbolinux: pszOs = "TurboLinux"; break;
210 case VBOXOSTYPE_Ubuntu: pszOs = "Ubuntu"; break;
211 case VBOXOSTYPE_Xandros: pszOs = "Xandros"; break;
212 case VBOXOSTYPE_Oracle: pszOs = "Oracle Linux"; break;
213 case VBOXOSTYPE_FreeBSD: pszOs = "FreeBSD"; break;
214 case VBOXOSTYPE_OpenBSD: pszOs = "OpenBSD"; break;
215 case VBOXOSTYPE_NetBSD: pszOs = "NetBSD"; break;
216 case VBOXOSTYPE_Netware: pszOs = "Netware"; break;
217 case VBOXOSTYPE_Solaris: pszOs = "Solaris"; break;
218 case VBOXOSTYPE_OpenSolaris: pszOs = "OpenSolaris"; break;
219 case VBOXOSTYPE_Solaris11_x64 & ~VBOXOSTYPE_x64: pszOs = "Solaris 11"; break;
220 case VBOXOSTYPE_MacOS: pszOs = "Mac OS X"; break;
221 case VBOXOSTYPE_MacOS106: pszOs = "Mac OS X 10.6"; break;
222 case VBOXOSTYPE_MacOS107_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.7"; break;
223 case VBOXOSTYPE_MacOS108_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.8"; break;
224 case VBOXOSTYPE_MacOS109_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.9"; break;
225 case VBOXOSTYPE_MacOS1010_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.10"; break;
226 case VBOXOSTYPE_MacOS1011_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.11"; break;
227 case VBOXOSTYPE_MacOS1012_x64 & ~VBOXOSTYPE_x64: pszOs = "macOS 10.12"; break;
228 case VBOXOSTYPE_MacOS1013_x64 & ~VBOXOSTYPE_x64: pszOs = "macOS 10.13"; break;
229 case VBOXOSTYPE_Haiku: pszOs = "Haiku"; break;
230 default: pszOs = "unknown"; break;
231 }
232 LogRel(("VMMDev: Guest Additions information report: Interface = 0x%08X osType = 0x%08X (%s, %u-bit)\n",
233 pGuestInfo->interfaceVersion, pGuestInfo->osType, pszOs,
234 pGuestInfo->osType & VBOXOSTYPE_x64 ? 64 : 32));
235}
236
237
238/**
239 * Sets the IRQ (raise it or lower it) for 1.03 additions.
240 *
241 * @param pDevIns The device instance.
242 * @param pThis The VMMDev shared instance data.
243 * @param pThisCC The VMMDev ring-3 instance data.
244 * @thread Any.
245 * @remarks Must be called owning the critical section.
246 */
247static void vmmdevSetIRQ_Legacy(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC)
248{
249 if (pThis->fu32AdditionsOk)
250 {
251 /* Filter unsupported events */
252 uint32_t fEvents = pThis->fHostEventFlags & pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_03.u32GuestEventMask;
253
254 Log(("vmmdevSetIRQ: fEvents=%#010x, fHostEventFlags=%#010x, u32GuestEventMask=%#010x.\n",
255 fEvents, pThis->fHostEventFlags, pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_03.u32GuestEventMask));
256
257 /* Move event flags to VMMDev RAM */
258 pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_03.u32HostEvents = fEvents;
259
260 uint32_t uIRQLevel = 0;
261 if (fEvents)
262 {
263 /* Clear host flags which will be delivered to guest. */
264 pThis->fHostEventFlags &= ~fEvents;
265 Log(("vmmdevSetIRQ: fHostEventFlags=%#010x\n", pThis->fHostEventFlags));
266 uIRQLevel = 1;
267 }
268
269 /* Set IRQ level for pin 0 (see NoWait comment in vmmdevMaybeSetIRQ). */
270 /** @todo make IRQ pin configurable, at least a symbolic constant */
271 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, uIRQLevel);
272 Log(("vmmdevSetIRQ: IRQ set %d\n", uIRQLevel));
273 }
274 else
275 Log(("vmmdevSetIRQ: IRQ is not generated, guest has not yet reported to us.\n"));
276}
277
278
279/**
280 * Sets the IRQ if there are events to be delivered.
281 *
282 * @param pDevIns The device instance.
283 * @param pThis The VMMDev shared instance data.
284 * @param pThisCC The VMMDev ring-3 instance data.
285 * @thread Any.
286 * @remarks Must be called owning the critical section.
287 */
288static void vmmdevMaybeSetIRQ(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC)
289{
290 Log3(("vmmdevMaybeSetIRQ: fHostEventFlags=%#010x, fGuestFilterMask=%#010x.\n",
291 pThis->fHostEventFlags, pThis->fGuestFilterMask));
292
293 if (pThis->fHostEventFlags & pThis->fGuestFilterMask)
294 {
295 /*
296 * Note! No need to wait for the IRQs to be set (if we're not luck
297 * with the locks, etc). It is a notification about something,
298 * which has already happened.
299 */
300 pThisCC->pVMMDevRAMR3->V.V1_04.fHaveEvents = true;
301 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 1);
302 Log3(("vmmdevMaybeSetIRQ: IRQ set.\n"));
303 }
304}
305
306/**
307 * Notifies the guest about new events (@a fAddEvents).
308 *
309 * @param pDevIns The device instance.
310 * @param pThis The VMMDev shared instance data.
311 * @param pThisCC The VMMDev ring-3 instance data.
312 * @param fAddEvents New events to add.
313 * @thread Any.
314 * @remarks Must be called owning the critical section.
315 */
316static void vmmdevNotifyGuestWorker(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fAddEvents)
317{
318 Log3(("vmmdevNotifyGuestWorker: fAddEvents=%#010x.\n", fAddEvents));
319 Assert(PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect));
320
321 if (!VMMDEV_INTERFACE_VERSION_IS_1_03(pThis))
322 {
323 Log3(("vmmdevNotifyGuestWorker: New additions detected.\n"));
324
325 if (pThis->fu32AdditionsOk)
326 {
327 const bool fHadEvents = (pThis->fHostEventFlags & pThis->fGuestFilterMask) != 0;
328
329 Log3(("vmmdevNotifyGuestWorker: fHadEvents=%d, fHostEventFlags=%#010x, fGuestFilterMask=%#010x.\n",
330 fHadEvents, pThis->fHostEventFlags, pThis->fGuestFilterMask));
331
332 pThis->fHostEventFlags |= fAddEvents;
333
334 if (!fHadEvents)
335 vmmdevMaybeSetIRQ(pDevIns, pThis, pThisCC);
336 }
337 else
338 {
339 pThis->fHostEventFlags |= fAddEvents;
340 Log(("vmmdevNotifyGuestWorker: IRQ is not generated, guest has not yet reported to us.\n"));
341 }
342 }
343 else
344 {
345 Log3(("vmmdevNotifyGuestWorker: Old additions detected.\n"));
346
347 pThis->fHostEventFlags |= fAddEvents;
348 vmmdevSetIRQ_Legacy(pDevIns, pThis, pThisCC);
349 }
350}
351
352
353
354/* -=-=-=-=- Interfaces shared with VMMDevHGCM.cpp -=-=-=-=- */
355
356/**
357 * Notifies the guest about new events (@a fAddEvents).
358 *
359 * This is used by VMMDev.cpp as well as VMMDevHGCM.cpp.
360 *
361 * @param pDevIns The device instance.
362 * @param pThis The VMMDev shared instance data.
363 * @param pThisCC The VMMDev ring-3 instance data.
364 * @param fAddEvents New events to add.
365 * @thread Any.
366 */
367void VMMDevNotifyGuest(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fAddEvents)
368{
369 Log3(("VMMDevNotifyGuest: fAddEvents=%#010x\n", fAddEvents));
370
371 /*
372 * Only notify the VM when it's running.
373 */
374 VMSTATE enmVMState = PDMDevHlpVMState(pDevIns);
375 if ( enmVMState == VMSTATE_RUNNING
376 || enmVMState == VMSTATE_RUNNING_LS
377 || enmVMState == VMSTATE_LOADING
378 || enmVMState == VMSTATE_RESUMING
379 || enmVMState == VMSTATE_SUSPENDING
380 || enmVMState == VMSTATE_SUSPENDING_LS
381 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
382 || enmVMState == VMSTATE_DEBUGGING
383 || enmVMState == VMSTATE_DEBUGGING_LS
384 )
385 {
386 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
387 PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, &pThis->CritSect, rcLock);
388
389 vmmdevNotifyGuestWorker(pDevIns, pThis, pThisCC, fAddEvents);
390
391 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
392 }
393 else
394 LogRel(("VMMDevNotifyGuest: fAddEvents=%#x ignored because enmVMState=%d\n", fAddEvents, enmVMState));
395}
396
397/**
398 * Code shared by VMMDevReq_CtlGuestFilterMask and HGCM for controlling the
399 * events the guest are interested in.
400 *
401 * @param pDevIns The device instance.
402 * @param pThis The VMMDev shared instance data.
403 * @param pThisCC The VMMDev ring-3 instance data.
404 * @param fOrMask Events to add (VMMDEV_EVENT_XXX). Pass 0 for no
405 * change.
406 * @param fNotMask Events to remove (VMMDEV_EVENT_XXX). Pass 0 for no
407 * change.
408 *
409 * @remarks When HGCM will automatically enable VMMDEV_EVENT_HGCM when the guest
410 * starts submitting HGCM requests. Otherwise, the events are
411 * controlled by the guest.
412 */
413void VMMDevCtlSetGuestFilterMask(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fOrMask, uint32_t fNotMask)
414{
415 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
416 PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, &pThis->CritSect, rcLock);
417
418 const bool fHadEvents = (pThis->fHostEventFlags & pThis->fGuestFilterMask) != 0;
419
420 Log(("VMMDevCtlSetGuestFilterMask: fOrMask=%#010x, u32NotMask=%#010x, fHadEvents=%d.\n", fOrMask, fNotMask, fHadEvents));
421 if (fHadEvents)
422 {
423 if (!pThis->fNewGuestFilterMaskValid)
424 pThis->fNewGuestFilterMask = pThis->fGuestFilterMask;
425
426 pThis->fNewGuestFilterMask |= fOrMask;
427 pThis->fNewGuestFilterMask &= ~fNotMask;
428 pThis->fNewGuestFilterMaskValid = true;
429 }
430 else
431 {
432 pThis->fGuestFilterMask |= fOrMask;
433 pThis->fGuestFilterMask &= ~fNotMask;
434 vmmdevMaybeSetIRQ(pDevIns, pThis, pThisCC);
435 }
436
437 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
438}
439
440
441
442/* -=-=-=-=- Request processing functions. -=-=-=-=- */
443
444/**
445 * Handles VMMDevReq_ReportGuestInfo.
446 *
447 * @returns VBox status code that the guest should see.
448 * @param pDevIns The device instance.
449 * @param pThis The VMMDev shared instance data.
450 * @param pThisCC The VMMDev ring-3 instance data.
451 * @param pRequestHeader The header of the request to handle.
452 */
453static int vmmdevReqHandler_ReportGuestInfo(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
454 VMMDevRequestHeader *pRequestHeader)
455{
456 AssertMsgReturn(pRequestHeader->size == sizeof(VMMDevReportGuestInfo), ("%u\n", pRequestHeader->size), VERR_INVALID_PARAMETER);
457 VBoxGuestInfo const *pInfo = &((VMMDevReportGuestInfo *)pRequestHeader)->guestInfo;
458
459 if (memcmp(&pThis->guestInfo, pInfo, sizeof(*pInfo)) != 0)
460 {
461 /* Make a copy of supplied information. */
462 pThis->guestInfo = *pInfo;
463
464 /* Check additions interface version. */
465 pThis->fu32AdditionsOk = VMMDEV_INTERFACE_VERSION_IS_OK(pThis->guestInfo.interfaceVersion);
466
467 vmmdevLogGuestOsInfo(&pThis->guestInfo);
468
469 if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestInfo)
470 pThisCC->pDrv->pfnUpdateGuestInfo(pThisCC->pDrv, &pThis->guestInfo);
471 }
472
473 if (!pThis->fu32AdditionsOk)
474 return VERR_VERSION_MISMATCH;
475
476 /* Clear our IRQ in case it was high for whatever reason. */
477 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
478
479 return VINF_SUCCESS;
480}
481
482
483/**
484 * Handles VMMDevReq_GuestHeartbeat.
485 *
486 * @returns VBox status code that the guest should see.
487 * @param pDevIns The device instance.
488 * @param pThis The VMMDev shared instance data.
489 */
490static int vmmDevReqHandler_GuestHeartbeat(PPDMDEVINS pDevIns, PVMMDEV pThis)
491{
492 int rc;
493 if (pThis->fHeartbeatActive)
494 {
495 uint64_t const nsNowTS = PDMDevHlpTimerGetNano(pDevIns, pThis->hFlatlinedTimer);
496 if (!pThis->fFlatlined)
497 { /* likely */ }
498 else
499 {
500 LogRel(("VMMDev: GuestHeartBeat: Guest is alive (gone %'llu ns)\n", nsNowTS - pThis->nsLastHeartbeatTS));
501 ASMAtomicWriteBool(&pThis->fFlatlined, false);
502 }
503 ASMAtomicWriteU64(&pThis->nsLastHeartbeatTS, nsNowTS);
504
505 /* Postpone (or restart if we missed a beat) the timeout timer. */
506 rc = PDMDevHlpTimerSetNano(pDevIns, pThis->hFlatlinedTimer, pThis->cNsHeartbeatTimeout);
507 }
508 else
509 rc = VINF_SUCCESS;
510 return rc;
511}
512
513
514/**
515 * Timer that fires when where have been no heartbeats for a given time.
516 *
517 * @remarks Does not take the VMMDev critsect.
518 */
519static DECLCALLBACK(void) vmmDevHeartbeatFlatlinedTimer(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, void *pvUser)
520{
521 PVMMDEV pThis = (PVMMDEV)pvUser;
522 Assert(hTimer == pThis->hFlatlinedTimer);
523 if (pThis->fHeartbeatActive)
524 {
525 uint64_t cNsElapsed = PDMDevHlpTimerGetNano(pDevIns, hTimer) - pThis->nsLastHeartbeatTS;
526 if ( !pThis->fFlatlined
527 && cNsElapsed >= pThis->cNsHeartbeatInterval)
528 {
529 LogRel(("VMMDev: vmmDevHeartbeatFlatlinedTimer: Guest seems to be unresponsive. Last heartbeat received %RU64 seconds ago\n",
530 cNsElapsed / RT_NS_1SEC));
531 ASMAtomicWriteBool(&pThis->fFlatlined, true);
532 }
533 }
534}
535
536
537/**
538 * Handles VMMDevReq_HeartbeatConfigure.
539 *
540 * @returns VBox status code that the guest should see.
541 * @param pDevIns The device instance.
542 * @param pThis The VMMDev shared instance data.
543 * @param pReqHdr The header of the request to handle.
544 */
545static int vmmDevReqHandler_HeartbeatConfigure(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
546{
547 AssertMsgReturn(pReqHdr->size == sizeof(VMMDevReqHeartbeat), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
548 VMMDevReqHeartbeat *pReq = (VMMDevReqHeartbeat *)pReqHdr;
549 int rc;
550
551 pReq->cNsInterval = pThis->cNsHeartbeatInterval;
552
553 if (pReq->fEnabled != pThis->fHeartbeatActive)
554 {
555 ASMAtomicWriteBool(&pThis->fHeartbeatActive, pReq->fEnabled);
556 if (pReq->fEnabled)
557 {
558 /*
559 * Activate the heartbeat monitor.
560 */
561 pThis->nsLastHeartbeatTS = PDMDevHlpTimerGetNano(pDevIns, pThis->hFlatlinedTimer);
562 rc = PDMDevHlpTimerSetNano(pDevIns, pThis->hFlatlinedTimer, pThis->cNsHeartbeatTimeout);
563 if (RT_SUCCESS(rc))
564 LogRel(("VMMDev: Heartbeat flatline timer set to trigger after %'RU64 ns\n", pThis->cNsHeartbeatTimeout));
565 else
566 LogRel(("VMMDev: Error starting flatline timer (heartbeat): %Rrc\n", rc));
567 }
568 else
569 {
570 /*
571 * Deactivate the heartbeat monitor.
572 */
573 rc = PDMDevHlpTimerStop(pDevIns, pThis->hFlatlinedTimer);
574 LogRel(("VMMDev: Heartbeat checking timer has been stopped (rc=%Rrc)\n", rc));
575 }
576 }
577 else
578 {
579 LogRel(("VMMDev: vmmDevReqHandler_HeartbeatConfigure: No change (fHeartbeatActive=%RTbool)\n", pThis->fHeartbeatActive));
580 rc = VINF_SUCCESS;
581 }
582
583 return rc;
584}
585
586
587/**
588 * Handles VMMDevReq_NtBugCheck.
589 *
590 * @returns VBox status code that the guest should see.
591 * @param pDevIns The device instance.
592 * @param pReqHdr The header of the request to handle.
593 */
594static int vmmDevReqHandler_NtBugCheck(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
595{
596 if (pReqHdr->size == sizeof(VMMDevReqNtBugCheck))
597 {
598 VMMDevReqNtBugCheck const *pReq = (VMMDevReqNtBugCheck const *)pReqHdr;
599 DBGFR3ReportBugCheck(PDMDevHlpGetVM(pDevIns), PDMDevHlpGetVMCPU(pDevIns), DBGFEVENT_BSOD_VMMDEV,
600 pReq->uBugCheck, pReq->auParameters[0], pReq->auParameters[1],
601 pReq->auParameters[2], pReq->auParameters[3]);
602 }
603 else if (pReqHdr->size == sizeof(VMMDevRequestHeader))
604 {
605 LogRel(("VMMDev: NT BugCheck w/o data.\n"));
606 DBGFR3ReportBugCheck(PDMDevHlpGetVM(pDevIns), PDMDevHlpGetVMCPU(pDevIns), DBGFEVENT_BSOD_VMMDEV,
607 0, 0, 0, 0, 0);
608 }
609 else
610 return VERR_INVALID_PARAMETER;
611 return VINF_SUCCESS;
612}
613
614
615/**
616 * Validates a publisher tag.
617 *
618 * @returns true / false.
619 * @param pszTag Tag to validate.
620 */
621static bool vmmdevReqIsValidPublisherTag(const char *pszTag)
622{
623 /* Note! This character set is also found in Config.kmk. */
624 static char const s_szValidChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz()[]{}+-.,";
625
626 while (*pszTag != '\0')
627 {
628 if (!strchr(s_szValidChars, *pszTag))
629 return false;
630 pszTag++;
631 }
632 return true;
633}
634
635
636/**
637 * Validates a build tag.
638 *
639 * @returns true / false.
640 * @param pszTag Tag to validate.
641 */
642static bool vmmdevReqIsValidBuildTag(const char *pszTag)
643{
644 int cchPrefix;
645 if (!strncmp(pszTag, "RC", 2))
646 cchPrefix = 2;
647 else if (!strncmp(pszTag, "BETA", 4))
648 cchPrefix = 4;
649 else if (!strncmp(pszTag, "ALPHA", 5))
650 cchPrefix = 5;
651 else
652 return false;
653
654 if (pszTag[cchPrefix] == '\0')
655 return true;
656
657 uint8_t u8;
658 int rc = RTStrToUInt8Full(&pszTag[cchPrefix], 10, &u8);
659 return rc == VINF_SUCCESS;
660}
661
662
663/**
664 * Handles VMMDevReq_ReportGuestInfo2.
665 *
666 * @returns VBox status code that the guest should see.
667 * @param pDevIns The device instance.
668 * @param pThis The VMMDev shared instance data.
669 * @param pThisCC The VMMDev ring-3 instance data.
670 * @param pReqHdr The header of the request to handle.
671 */
672static int vmmdevReqHandler_ReportGuestInfo2(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
673{
674 AssertMsgReturn(pReqHdr->size == sizeof(VMMDevReportGuestInfo2), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
675 VBoxGuestInfo2 const *pInfo2 = &((VMMDevReportGuestInfo2 *)pReqHdr)->guestInfo;
676
677 LogRel(("VMMDev: Guest Additions information report: Version %d.%d.%d r%d '%.*s'\n",
678 pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild,
679 pInfo2->additionsRevision, sizeof(pInfo2->szName), pInfo2->szName));
680
681 /* The interface was introduced in 3.2 and will definitely not be
682 backported beyond 3.0 (bird). */
683 AssertMsgReturn(pInfo2->additionsMajor >= 3,
684 ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
685 VERR_INVALID_PARAMETER);
686
687 /* The version must fit in a full version compression. */
688 uint32_t uFullVersion = VBOX_FULL_VERSION_MAKE(pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
689 AssertMsgReturn( VBOX_FULL_VERSION_GET_MAJOR(uFullVersion) == pInfo2->additionsMajor
690 && VBOX_FULL_VERSION_GET_MINOR(uFullVersion) == pInfo2->additionsMinor
691 && VBOX_FULL_VERSION_GET_BUILD(uFullVersion) == pInfo2->additionsBuild,
692 ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
693 VERR_OUT_OF_RANGE);
694
695 /*
696 * Validate the name.
697 * Be less strict towards older additions (< v4.1.50).
698 */
699 AssertCompile(sizeof(pThis->guestInfo2.szName) == sizeof(pInfo2->szName));
700 AssertReturn(RTStrEnd(pInfo2->szName, sizeof(pInfo2->szName)) != NULL, VERR_INVALID_PARAMETER);
701 const char *pszName = pInfo2->szName;
702
703 /* The version number which shouldn't be there. */
704 char szTmp[sizeof(pInfo2->szName)];
705 size_t cchStart = RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
706 AssertMsgReturn(!strncmp(pszName, szTmp, cchStart), ("%s != %s\n", pszName, szTmp), VERR_INVALID_PARAMETER);
707 pszName += cchStart;
708
709 /* Now we can either have nothing or a build tag or/and a publisher tag. */
710 if (*pszName != '\0')
711 {
712 const char *pszRelaxedName = "";
713 bool const fStrict = pInfo2->additionsMajor > 4
714 || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor > 1)
715 || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor == 1 && pInfo2->additionsBuild >= 50);
716 bool fOk = false;
717 if (*pszName == '_')
718 {
719 pszName++;
720 strcpy(szTmp, pszName);
721 char *pszTag2 = strchr(szTmp, '_');
722 if (!pszTag2)
723 {
724 fOk = vmmdevReqIsValidBuildTag(szTmp)
725 || vmmdevReqIsValidPublisherTag(szTmp);
726 }
727 else
728 {
729 *pszTag2++ = '\0';
730 fOk = vmmdevReqIsValidBuildTag(szTmp);
731 if (fOk)
732 {
733 fOk = vmmdevReqIsValidPublisherTag(pszTag2);
734 if (!fOk)
735 pszRelaxedName = szTmp;
736 }
737 }
738 }
739
740 if (!fOk)
741 {
742 AssertLogRelMsgReturn(!fStrict, ("%s", pszName), VERR_INVALID_PARAMETER);
743
744 /* non-strict mode, just zap the extra stuff. */
745 LogRel(("VMMDev: ReportGuestInfo2: Ignoring unparsable version name bits: '%s' -> '%s'.\n", pszName, pszRelaxedName));
746 pszName = pszRelaxedName;
747 }
748 }
749
750 /*
751 * Save the info and tell Main or whoever is listening.
752 */
753 pThis->guestInfo2.uFullVersion = uFullVersion;
754 pThis->guestInfo2.uRevision = pInfo2->additionsRevision;
755 pThis->guestInfo2.fFeatures = pInfo2->additionsFeatures;
756 strcpy(pThis->guestInfo2.szName, pszName);
757
758 if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestInfo2)
759 pThisCC->pDrv->pfnUpdateGuestInfo2(pThisCC->pDrv, uFullVersion, pszName, pInfo2->additionsRevision,
760 pInfo2->additionsFeatures);
761
762 /* Clear our IRQ in case it was high for whatever reason. */
763 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
764
765 return VINF_SUCCESS;
766}
767
768
769/**
770 * Allocates a new facility status entry, initializing it to inactive.
771 *
772 * @returns Pointer to a facility status entry on success, NULL on failure
773 * (table full).
774 * @param pThis The VMMDev shared instance data.
775 * @param enmFacility The facility type code.
776 * @param fFixed This is set when allocating the standard entries
777 * from the constructor.
778 * @param pTimeSpecNow Optionally giving the entry timestamp to use (ctor).
779 */
780static PVMMDEVFACILITYSTATUSENTRY
781vmmdevAllocFacilityStatusEntry(PVMMDEV pThis, VBoxGuestFacilityType enmFacility, bool fFixed, PCRTTIMESPEC pTimeSpecNow)
782{
783 /* If full, expunge one inactive entry. */
784 if (pThis->cFacilityStatuses == RT_ELEMENTS(pThis->aFacilityStatuses))
785 {
786 uint32_t i = pThis->cFacilityStatuses;
787 while (i-- > 0)
788 {
789 if ( pThis->aFacilityStatuses[i].enmStatus == VBoxGuestFacilityStatus_Inactive
790 && !pThis->aFacilityStatuses[i].fFixed)
791 {
792 pThis->cFacilityStatuses--;
793 int cToMove = pThis->cFacilityStatuses - i;
794 if (cToMove)
795 memmove(&pThis->aFacilityStatuses[i], &pThis->aFacilityStatuses[i + 1],
796 cToMove * sizeof(pThis->aFacilityStatuses[i]));
797 RT_ZERO(pThis->aFacilityStatuses[pThis->cFacilityStatuses]);
798 break;
799 }
800 }
801
802 if (pThis->cFacilityStatuses == RT_ELEMENTS(pThis->aFacilityStatuses))
803 return NULL;
804 }
805
806 /* Find location in array (it's sorted). */
807 uint32_t i = pThis->cFacilityStatuses;
808 while (i-- > 0)
809 if ((uint32_t)pThis->aFacilityStatuses[i].enmFacility < (uint32_t)enmFacility)
810 break;
811 i++;
812
813 /* Move. */
814 int cToMove = pThis->cFacilityStatuses - i;
815 if (cToMove > 0)
816 memmove(&pThis->aFacilityStatuses[i + 1], &pThis->aFacilityStatuses[i],
817 cToMove * sizeof(pThis->aFacilityStatuses[i]));
818 pThis->cFacilityStatuses++;
819
820 /* Initialize. */
821 pThis->aFacilityStatuses[i].enmFacility = enmFacility;
822 pThis->aFacilityStatuses[i].enmStatus = VBoxGuestFacilityStatus_Inactive;
823 pThis->aFacilityStatuses[i].fFixed = fFixed;
824 pThis->aFacilityStatuses[i].afPadding[0] = 0;
825 pThis->aFacilityStatuses[i].afPadding[1] = 0;
826 pThis->aFacilityStatuses[i].afPadding[2] = 0;
827 pThis->aFacilityStatuses[i].fFlags = 0;
828 if (pTimeSpecNow)
829 pThis->aFacilityStatuses[i].TimeSpecTS = *pTimeSpecNow;
830 else
831 RTTimeSpecSetNano(&pThis->aFacilityStatuses[i].TimeSpecTS, 0);
832
833 return &pThis->aFacilityStatuses[i];
834}
835
836
837/**
838 * Gets a facility status entry, allocating a new one if not already present.
839 *
840 * @returns Pointer to a facility status entry on success, NULL on failure
841 * (table full).
842 * @param pThis The VMMDev shared instance data.
843 * @param enmFacility The facility type code.
844 */
845static PVMMDEVFACILITYSTATUSENTRY vmmdevGetFacilityStatusEntry(PVMMDEV pThis, VBoxGuestFacilityType enmFacility)
846{
847 /** @todo change to binary search. */
848 uint32_t i = pThis->cFacilityStatuses;
849 while (i-- > 0)
850 {
851 if (pThis->aFacilityStatuses[i].enmFacility == enmFacility)
852 return &pThis->aFacilityStatuses[i];
853 if ((uint32_t)pThis->aFacilityStatuses[i].enmFacility < (uint32_t)enmFacility)
854 break;
855 }
856 return vmmdevAllocFacilityStatusEntry(pThis, enmFacility, false /*fFixed*/, NULL);
857}
858
859
860/**
861 * Handles VMMDevReq_ReportGuestStatus.
862 *
863 * @returns VBox status code that the guest should see.
864 * @param pThis The VMMDev shared instance data.
865 * @param pThisCC The VMMDev ring-3 instance data.
866 * @param pReqHdr The header of the request to handle.
867 */
868static int vmmdevReqHandler_ReportGuestStatus(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
869{
870 /*
871 * Validate input.
872 */
873 AssertMsgReturn(pReqHdr->size == sizeof(VMMDevReportGuestStatus), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
874 VBoxGuestStatus *pStatus = &((VMMDevReportGuestStatus *)pReqHdr)->guestStatus;
875 AssertMsgReturn( pStatus->facility > VBoxGuestFacilityType_Unknown
876 && pStatus->facility <= VBoxGuestFacilityType_All,
877 ("%d\n", pStatus->facility),
878 VERR_INVALID_PARAMETER);
879 AssertMsgReturn(pStatus->status == (VBoxGuestFacilityStatus)(uint16_t)pStatus->status,
880 ("%#x (%u)\n", pStatus->status, pStatus->status),
881 VERR_OUT_OF_RANGE);
882
883 /*
884 * Do the update.
885 */
886 RTTIMESPEC Now;
887 RTTimeNow(&Now);
888 if (pStatus->facility == VBoxGuestFacilityType_All)
889 {
890 uint32_t i = pThis->cFacilityStatuses;
891 while (i-- > 0)
892 {
893 pThis->aFacilityStatuses[i].TimeSpecTS = Now;
894 pThis->aFacilityStatuses[i].enmStatus = pStatus->status;
895 pThis->aFacilityStatuses[i].fFlags = pStatus->flags;
896 }
897 }
898 else
899 {
900 PVMMDEVFACILITYSTATUSENTRY pEntry = vmmdevGetFacilityStatusEntry(pThis, pStatus->facility);
901 if (!pEntry)
902 {
903 LogRelMax(10, ("VMMDev: Facility table is full - facility=%u status=%u\n", pStatus->facility, pStatus->status));
904 return VERR_OUT_OF_RESOURCES;
905 }
906
907 pEntry->TimeSpecTS = Now;
908 pEntry->enmStatus = pStatus->status;
909 pEntry->fFlags = pStatus->flags;
910 }
911
912 if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestStatus)
913 pThisCC->pDrv->pfnUpdateGuestStatus(pThisCC->pDrv, pStatus->facility, pStatus->status, pStatus->flags, &Now);
914
915 return VINF_SUCCESS;
916}
917
918
919/**
920 * Handles VMMDevReq_ReportGuestUserState.
921 *
922 * @returns VBox status code that the guest should see.
923 * @param pThisCC The VMMDev ring-3 instance data.
924 * @param pReqHdr The header of the request to handle.
925 */
926static int vmmdevReqHandler_ReportGuestUserState(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
927{
928 /*
929 * Validate input.
930 */
931 VMMDevReportGuestUserState *pReq = (VMMDevReportGuestUserState *)pReqHdr;
932 AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
933
934 if ( pThisCC->pDrv
935 && pThisCC->pDrv->pfnUpdateGuestUserState)
936 {
937 /* Play safe. */
938 AssertReturn(pReq->header.size <= _2K, VERR_TOO_MUCH_DATA);
939 AssertReturn(pReq->status.cbUser <= 256, VERR_TOO_MUCH_DATA);
940 AssertReturn(pReq->status.cbDomain <= 256, VERR_TOO_MUCH_DATA);
941 AssertReturn(pReq->status.cbDetails <= _1K, VERR_TOO_MUCH_DATA);
942
943 /* pbDynamic marks the beginning of the struct's dynamically
944 * allocated data area. */
945 uint8_t *pbDynamic = (uint8_t *)&pReq->status.szUser;
946 uint32_t cbLeft = pReqHdr->size - RT_UOFFSETOF(VMMDevReportGuestUserState, status.szUser);
947
948 /* The user. */
949 AssertReturn(pReq->status.cbUser > 0, VERR_INVALID_PARAMETER); /* User name is required. */
950 AssertReturn(pReq->status.cbUser <= cbLeft, VERR_INVALID_PARAMETER);
951 const char *pszUser = (const char *)pbDynamic;
952 AssertReturn(RTStrEnd(pszUser, pReq->status.cbUser), VERR_INVALID_PARAMETER);
953 int rc = RTStrValidateEncoding(pszUser);
954 AssertRCReturn(rc, rc);
955
956 /* Advance to the next field. */
957 pbDynamic += pReq->status.cbUser;
958 cbLeft -= pReq->status.cbUser;
959
960 /* pszDomain can be NULL. */
961 AssertReturn(pReq->status.cbDomain <= cbLeft, VERR_INVALID_PARAMETER);
962 const char *pszDomain = NULL;
963 if (pReq->status.cbDomain)
964 {
965 pszDomain = (const char *)pbDynamic;
966 AssertReturn(RTStrEnd(pszDomain, pReq->status.cbDomain), VERR_INVALID_PARAMETER);
967 rc = RTStrValidateEncoding(pszDomain);
968 AssertRCReturn(rc, rc);
969
970 /* Advance to the next field. */
971 pbDynamic += pReq->status.cbDomain;
972 cbLeft -= pReq->status.cbDomain;
973 }
974
975 /* pbDetails can be NULL. */
976 const uint8_t *pbDetails = NULL;
977 AssertReturn(pReq->status.cbDetails <= cbLeft, VERR_INVALID_PARAMETER);
978 if (pReq->status.cbDetails > 0)
979 pbDetails = pbDynamic;
980
981 pThisCC->pDrv->pfnUpdateGuestUserState(pThisCC->pDrv, pszUser, pszDomain, (uint32_t)pReq->status.state,
982 pbDetails, pReq->status.cbDetails);
983 }
984
985 return VINF_SUCCESS;
986}
987
988
989/**
990 * Handles VMMDevReq_ReportGuestCapabilities.
991 *
992 * @returns VBox status code that the guest should see.
993 * @param pThis The VMMDev shared instance data.
994 * @param pThisCC The VMMDev ring-3 instance data.
995 * @param pReqHdr The header of the request to handle.
996 */
997static int vmmdevReqHandler_ReportGuestCapabilities(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
998{
999 VMMDevReqGuestCapabilities *pReq = (VMMDevReqGuestCapabilities *)pReqHdr;
1000 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1001
1002 /* Enable VMMDEV_GUEST_SUPPORTS_GRAPHICS automatically for guests using the old
1003 * request to report their capabilities.
1004 */
1005 const uint32_t fu32Caps = pReq->caps | VMMDEV_GUEST_SUPPORTS_GRAPHICS;
1006
1007 if (pThis->fGuestCaps != fu32Caps)
1008 {
1009 /* make a copy of supplied information */
1010 pThis->fGuestCaps = fu32Caps;
1011
1012 LogRel(("VMMDev: Guest Additions capability report (legacy): (0x%x) seamless: %s, hostWindowMapping: %s, graphics: yes\n",
1013 fu32Caps,
1014 fu32Caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
1015 fu32Caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no"));
1016
1017 if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
1018 pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, fu32Caps);
1019 }
1020 return VINF_SUCCESS;
1021}
1022
1023
1024/**
1025 * Handles VMMDevReq_SetGuestCapabilities.
1026 *
1027 * @returns VBox status code that the guest should see.
1028 * @param pThis The VMMDev shared instance data.
1029 * @param pThisCC The VMMDev ring-3 instance data.
1030 * @param pReqHdr The header of the request to handle.
1031 */
1032static int vmmdevReqHandler_SetGuestCapabilities(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1033{
1034 VMMDevReqGuestCapabilities2 *pReq = (VMMDevReqGuestCapabilities2 *)pReqHdr;
1035 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1036
1037 uint32_t fu32Caps = pThis->fGuestCaps;
1038 fu32Caps |= pReq->u32OrMask;
1039 fu32Caps &= ~pReq->u32NotMask;
1040
1041 LogRel(("VMMDev: Guest Additions capability report: (%#x -> %#x) seamless: %s, hostWindowMapping: %s, graphics: %s\n",
1042 pThis->fGuestCaps, fu32Caps,
1043 fu32Caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
1044 fu32Caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
1045 fu32Caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
1046
1047 pThis->fGuestCaps = fu32Caps;
1048
1049 if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
1050 pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, fu32Caps);
1051
1052 return VINF_SUCCESS;
1053}
1054
1055
1056/**
1057 * Handles VMMDevReq_GetMouseStatus.
1058 *
1059 * @returns VBox status code that the guest should see.
1060 * @param pThis The VMMDev shared instance data.
1061 * @param pReqHdr The header of the request to handle.
1062 */
1063static int vmmdevReqHandler_GetMouseStatus(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
1064{
1065 VMMDevReqMouseStatus *pReq = (VMMDevReqMouseStatus *)pReqHdr;
1066 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1067
1068 pReq->mouseFeatures = pThis->fMouseCapabilities
1069 & VMMDEV_MOUSE_MASK;
1070 pReq->pointerXPos = pThis->xMouseAbs;
1071 pReq->pointerYPos = pThis->yMouseAbs;
1072 LogRel2(("VMMDev: vmmdevReqHandler_GetMouseStatus: mouseFeatures=%#x, xAbs=%d, yAbs=%d\n",
1073 pReq->mouseFeatures, pReq->pointerXPos, pReq->pointerYPos));
1074 return VINF_SUCCESS;
1075}
1076
1077
1078/**
1079 * Handles VMMDevReq_SetMouseStatus.
1080 *
1081 * @returns VBox status code that the guest should see.
1082 * @param pThis The VMMDev shared instance data.
1083 * @param pThisCC The VMMDev ring-3 instance data.
1084 * @param pReqHdr The header of the request to handle.
1085 */
1086static int vmmdevReqHandler_SetMouseStatus(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1087{
1088 VMMDevReqMouseStatus *pReq = (VMMDevReqMouseStatus *)pReqHdr;
1089 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1090
1091 LogRelFlow(("VMMDev: vmmdevReqHandler_SetMouseStatus: mouseFeatures=%#x\n", pReq->mouseFeatures));
1092
1093 bool fNotify = false;
1094 if ( (pReq->mouseFeatures & VMMDEV_MOUSE_NOTIFY_HOST_MASK)
1095 != ( pThis->fMouseCapabilities
1096 & VMMDEV_MOUSE_NOTIFY_HOST_MASK))
1097 fNotify = true;
1098
1099 pThis->fMouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
1100 pThis->fMouseCapabilities |= (pReq->mouseFeatures & VMMDEV_MOUSE_GUEST_MASK);
1101
1102 LogRelFlow(("VMMDev: vmmdevReqHandler_SetMouseStatus: New host capabilities: %#x\n", pThis->fMouseCapabilities));
1103
1104 /*
1105 * Notify connector if something changed.
1106 */
1107 if (fNotify)
1108 {
1109 LogRelFlow(("VMMDev: vmmdevReqHandler_SetMouseStatus: Notifying connector\n"));
1110 pThisCC->pDrv->pfnUpdateMouseCapabilities(pThisCC->pDrv, pThis->fMouseCapabilities);
1111 }
1112
1113 return VINF_SUCCESS;
1114}
1115
1116static int vmmdevVerifyPointerShape(VMMDevReqMousePointer *pReq)
1117{
1118 /* Should be enough for most mouse pointers. */
1119 if (pReq->width > 8192 || pReq->height > 8192)
1120 return VERR_INVALID_PARAMETER;
1121
1122 uint32_t cbShape = (pReq->width + 7) / 8 * pReq->height; /* size of the AND mask */
1123 cbShape = ((cbShape + 3) & ~3) + pReq->width * 4 * pReq->height; /* + gap + size of the XOR mask */
1124 if (RT_UOFFSETOF(VMMDevReqMousePointer, pointerData) + cbShape > pReq->header.size)
1125 return VERR_INVALID_PARAMETER;
1126
1127 return VINF_SUCCESS;
1128}
1129
1130/**
1131 * Handles VMMDevReq_SetPointerShape.
1132 *
1133 * @returns VBox status code that the guest should see.
1134 * @param pThis The VMMDev shared instance data.
1135 * @param pThisCC The VMMDev ring-3 instance data.
1136 * @param pReqHdr The header of the request to handle.
1137 */
1138static int vmmdevReqHandler_SetPointerShape(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1139{
1140 VMMDevReqMousePointer *pReq = (VMMDevReqMousePointer *)pReqHdr;
1141 if (pReq->header.size < sizeof(*pReq))
1142 {
1143 AssertMsg(pReq->header.size == 0x10028 && pReq->header.version == 10000, /* don't complain about legacy!!! */
1144 ("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
1145 pReq->header.size, pReq->header.size, pReq->header.version));
1146 return VERR_INVALID_PARAMETER;
1147 }
1148
1149 bool fVisible = RT_BOOL(pReq->fFlags & VBOX_MOUSE_POINTER_VISIBLE);
1150 bool fAlpha = RT_BOOL(pReq->fFlags & VBOX_MOUSE_POINTER_ALPHA);
1151 bool fShape = RT_BOOL(pReq->fFlags & VBOX_MOUSE_POINTER_SHAPE);
1152
1153 Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
1154 fVisible, fAlpha, fShape, pReq->width, pReq->height));
1155
1156 if (pReq->header.size == sizeof(VMMDevReqMousePointer))
1157 {
1158 /* The guest did not provide the shape actually. */
1159 fShape = false;
1160 }
1161
1162 /* forward call to driver */
1163 if (fShape)
1164 {
1165 int rc = vmmdevVerifyPointerShape(pReq);
1166 if (RT_FAILURE(rc))
1167 return rc;
1168
1169 pThisCC->pDrv->pfnUpdatePointerShape(pThisCC->pDrv,
1170 fVisible,
1171 fAlpha,
1172 pReq->xHot, pReq->yHot,
1173 pReq->width, pReq->height,
1174 pReq->pointerData);
1175 }
1176 else
1177 {
1178 pThisCC->pDrv->pfnUpdatePointerShape(pThisCC->pDrv,
1179 fVisible,
1180 0,
1181 0, 0,
1182 0, 0,
1183 NULL);
1184 }
1185
1186 pThis->fHostCursorRequested = fVisible;
1187 return VINF_SUCCESS;
1188}
1189
1190
1191/**
1192 * Handles VMMDevReq_GetHostTime.
1193 *
1194 * @returns VBox status code that the guest should see.
1195 * @param pDevIns The device instance.
1196 * @param pThis The VMMDev shared instance data.
1197 * @param pReqHdr The header of the request to handle.
1198 */
1199static int vmmdevReqHandler_GetHostTime(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
1200{
1201 VMMDevReqHostTime *pReq = (VMMDevReqHostTime *)pReqHdr;
1202 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1203
1204 if (RT_LIKELY(!pThis->fGetHostTimeDisabled))
1205 {
1206 RTTIMESPEC now;
1207 pReq->time = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
1208 return VINF_SUCCESS;
1209 }
1210 return VERR_NOT_SUPPORTED;
1211}
1212
1213
1214/**
1215 * Handles VMMDevReq_GetHypervisorInfo.
1216 *
1217 * @returns VBox status code that the guest should see.
1218 * @param pDevIns The device instance.
1219 * @param pReqHdr The header of the request to handle.
1220 */
1221static int vmmdevReqHandler_GetHypervisorInfo(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
1222{
1223 VMMDevReqHypervisorInfo *pReq = (VMMDevReqHypervisorInfo *)pReqHdr;
1224 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1225
1226 return PGMR3MappingsSize(PDMDevHlpGetVM(pDevIns), &pReq->hypervisorSize);
1227}
1228
1229
1230/**
1231 * Handles VMMDevReq_SetHypervisorInfo.
1232 *
1233 * @returns VBox status code that the guest should see.
1234 * @param pDevIns The device instance.
1235 * @param pReqHdr The header of the request to handle.
1236 */
1237static int vmmdevReqHandler_SetHypervisorInfo(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
1238{
1239 VMMDevReqHypervisorInfo *pReq = (VMMDevReqHypervisorInfo *)pReqHdr;
1240 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1241
1242 int rc;
1243 PVM pVM = PDMDevHlpGetVM(pDevIns);
1244 if (pReq->hypervisorStart == 0)
1245 rc = PGMR3MappingsUnfix(pVM);
1246 else
1247 {
1248 /* only if the client has queried the size before! */
1249 uint32_t cbMappings;
1250 rc = PGMR3MappingsSize(pVM, &cbMappings);
1251 if (RT_SUCCESS(rc) && pReq->hypervisorSize == cbMappings)
1252 {
1253 /* new reservation */
1254 rc = PGMR3MappingsFix(pVM, pReq->hypervisorStart, pReq->hypervisorSize);
1255 LogRel(("VMMDev: Guest reported fixed hypervisor window at 0%010x LB %#x (rc=%Rrc)\n",
1256 pReq->hypervisorStart, pReq->hypervisorSize, rc));
1257 }
1258 else if (RT_FAILURE(rc))
1259 rc = VERR_TRY_AGAIN;
1260 }
1261 return rc;
1262}
1263
1264
1265/**
1266 * Handles VMMDevReq_RegisterPatchMemory.
1267 *
1268 * @returns VBox status code that the guest should see.
1269 * @param pDevIns The device instance.
1270 * @param pReqHdr The header of the request to handle.
1271 */
1272static int vmmdevReqHandler_RegisterPatchMemory(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
1273{
1274 VMMDevReqPatchMemory *pReq = (VMMDevReqPatchMemory *)pReqHdr;
1275 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1276
1277 return PDMDevHlpVMMRegisterPatchMemory(pDevIns, pReq->pPatchMem, pReq->cbPatchMem);
1278}
1279
1280
1281/**
1282 * Handles VMMDevReq_DeregisterPatchMemory.
1283 *
1284 * @returns VBox status code that the guest should see.
1285 * @param pDevIns The device instance.
1286 * @param pReqHdr The header of the request to handle.
1287 */
1288static int vmmdevReqHandler_DeregisterPatchMemory(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
1289{
1290 VMMDevReqPatchMemory *pReq = (VMMDevReqPatchMemory *)pReqHdr;
1291 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1292
1293 return PDMDevHlpVMMDeregisterPatchMemory(pDevIns, pReq->pPatchMem, pReq->cbPatchMem);
1294}
1295
1296
1297/**
1298 * Handles VMMDevReq_SetPowerStatus.
1299 *
1300 * @returns VBox status code that the guest should see.
1301 * @param pDevIns The device instance.
1302 * @param pThis The VMMDev shared instance data.
1303 * @param pReqHdr The header of the request to handle.
1304 */
1305static int vmmdevReqHandler_SetPowerStatus(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
1306{
1307 VMMDevPowerStateRequest *pReq = (VMMDevPowerStateRequest *)pReqHdr;
1308 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1309
1310 switch (pReq->powerState)
1311 {
1312 case VMMDevPowerState_Pause:
1313 {
1314 LogRel(("VMMDev: Guest requests the VM to be suspended (paused)\n"));
1315 return PDMDevHlpVMSuspend(pDevIns);
1316 }
1317
1318 case VMMDevPowerState_PowerOff:
1319 {
1320 LogRel(("VMMDev: Guest requests the VM to be turned off\n"));
1321 return PDMDevHlpVMPowerOff(pDevIns);
1322 }
1323
1324 case VMMDevPowerState_SaveState:
1325 {
1326 if (pThis->fAllowGuestToSaveState)
1327 {
1328 LogRel(("VMMDev: Guest requests the VM to be saved and powered off\n"));
1329 return PDMDevHlpVMSuspendSaveAndPowerOff(pDevIns);
1330 }
1331 LogRel(("VMMDev: Guest requests the VM to be saved and powered off, declined\n"));
1332 return VERR_ACCESS_DENIED;
1333 }
1334
1335 default:
1336 AssertMsgFailed(("VMMDev: Invalid power state request: %d\n", pReq->powerState));
1337 return VERR_INVALID_PARAMETER;
1338 }
1339}
1340
1341
1342/**
1343 * Handles VMMDevReq_GetDisplayChangeRequest
1344 *
1345 * @returns VBox status code that the guest should see.
1346 * @param pThis The VMMDev shared instance data.
1347 * @param pReqHdr The header of the request to handle.
1348 * @remarks Deprecated.
1349 */
1350static int vmmdevReqHandler_GetDisplayChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
1351{
1352 VMMDevDisplayChangeRequest *pReq = (VMMDevDisplayChangeRequest *)pReqHdr;
1353 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1354
1355 DISPLAYCHANGEREQUEST *pDispRequest = &pThis->displayChangeData.aRequests[0];
1356
1357 if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1358 {
1359 /* Current request has been read at least once. */
1360 pDispRequest->fPending = false;
1361
1362 /* Remember which resolution the client has queried, subsequent reads
1363 * will return the same values. */
1364 pDispRequest->lastReadDisplayChangeRequest = pDispRequest->displayChangeRequest;
1365 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1366 }
1367
1368 /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1369 * read the last valid video mode hint. This happens when the guest X server
1370 * determines the initial mode. */
1371 VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
1372 &pDispRequest->lastReadDisplayChangeRequest :
1373 &pDispRequest->displayChangeRequest;
1374 pReq->xres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CX) ? pDisplayDef->cx : 0;
1375 pReq->yres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CY) ? pDisplayDef->cy : 0;
1376 pReq->bpp = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_BPP) ? pDisplayDef->cBitsPerPixel : 0;
1377
1378 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n", pReq->xres, pReq->yres, pReq->bpp));
1379
1380 return VINF_SUCCESS;
1381}
1382
1383
1384/**
1385 * Handles VMMDevReq_GetDisplayChangeRequest2.
1386 *
1387 * @returns VBox status code that the guest should see.
1388 * @param pDevIns The device instance.
1389 * @param pThis The VMMDev shared instance data.
1390 * @param pThisCC The VMMDev ring-3 instance data.
1391 * @param pReqHdr The header of the request to handle.
1392 */
1393static int vmmdevReqHandler_GetDisplayChangeRequest2(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
1394 VMMDevRequestHeader *pReqHdr)
1395{
1396 VMMDevDisplayChangeRequest2 *pReq = (VMMDevDisplayChangeRequest2 *)pReqHdr;
1397 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1398
1399 DISPLAYCHANGEREQUEST *pDispRequest = NULL;
1400
1401 if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1402 {
1403 /* Select a pending request to report. */
1404 unsigned i;
1405 for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1406 {
1407 if (pThis->displayChangeData.aRequests[i].fPending)
1408 {
1409 pDispRequest = &pThis->displayChangeData.aRequests[i];
1410 /* Remember which request should be reported. */
1411 pThis->displayChangeData.iCurrentMonitor = i;
1412 Log3(("VMMDev: will report pending request for %u\n", i));
1413 break;
1414 }
1415 }
1416
1417 /* Check if there are more pending requests. */
1418 i++;
1419 for (; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1420 {
1421 if (pThis->displayChangeData.aRequests[i].fPending)
1422 {
1423 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1424 Log3(("VMMDev: another pending at %u\n", i));
1425 break;
1426 }
1427 }
1428
1429 if (pDispRequest)
1430 {
1431 /* Current request has been read at least once. */
1432 pDispRequest->fPending = false;
1433
1434 /* Remember which resolution the client has queried, subsequent reads
1435 * will return the same values. */
1436 pDispRequest->lastReadDisplayChangeRequest = pDispRequest->displayChangeRequest;
1437 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1438 }
1439 else
1440 {
1441 Log3(("VMMDev: no pending request!!!\n"));
1442 }
1443 }
1444
1445 if (!pDispRequest)
1446 {
1447 Log3(("VMMDev: default to %d\n", pThis->displayChangeData.iCurrentMonitor));
1448 pDispRequest = &pThis->displayChangeData.aRequests[pThis->displayChangeData.iCurrentMonitor];
1449 }
1450
1451 /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1452 * read the last valid video mode hint. This happens when the guest X server
1453 * determines the initial mode. */
1454 VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
1455 &pDispRequest->lastReadDisplayChangeRequest :
1456 &pDispRequest->displayChangeRequest;
1457 pReq->xres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CX) ? pDisplayDef->cx : 0;
1458 pReq->yres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CY) ? pDisplayDef->cy : 0;
1459 pReq->bpp = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_BPP) ? pDisplayDef->cBitsPerPixel : 0;
1460 pReq->display = pDisplayDef->idDisplay;
1461
1462 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
1463 pReq->xres, pReq->yres, pReq->bpp, pReq->display));
1464
1465 return VINF_SUCCESS;
1466}
1467
1468
1469/**
1470 * Handles VMMDevReq_GetDisplayChangeRequestEx.
1471 *
1472 * @returns VBox status code that the guest should see.
1473 * @param pDevIns The device instance.
1474 * @param pThis The VMMDev shared instance data.
1475 * @param pThisCC The VMMDev ring-3 instance data.
1476 * @param pReqHdr The header of the request to handle.
1477 */
1478static int vmmdevReqHandler_GetDisplayChangeRequestEx(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
1479 VMMDevRequestHeader *pReqHdr)
1480{
1481 VMMDevDisplayChangeRequestEx *pReq = (VMMDevDisplayChangeRequestEx *)pReqHdr;
1482 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1483
1484 DISPLAYCHANGEREQUEST *pDispRequest = NULL;
1485
1486 if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1487 {
1488 /* Select a pending request to report. */
1489 unsigned i;
1490 for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1491 {
1492 if (pThis->displayChangeData.aRequests[i].fPending)
1493 {
1494 pDispRequest = &pThis->displayChangeData.aRequests[i];
1495 /* Remember which request should be reported. */
1496 pThis->displayChangeData.iCurrentMonitor = i;
1497 Log3(("VMMDev: will report pending request for %d\n",
1498 i));
1499 break;
1500 }
1501 }
1502
1503 /* Check if there are more pending requests. */
1504 i++;
1505 for (; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1506 {
1507 if (pThis->displayChangeData.aRequests[i].fPending)
1508 {
1509 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1510 Log3(("VMMDev: another pending at %d\n",
1511 i));
1512 break;
1513 }
1514 }
1515
1516 if (pDispRequest)
1517 {
1518 /* Current request has been read at least once. */
1519 pDispRequest->fPending = false;
1520
1521 /* Remember which resolution the client has queried, subsequent reads
1522 * will return the same values. */
1523 pDispRequest->lastReadDisplayChangeRequest = pDispRequest->displayChangeRequest;
1524 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1525 }
1526 else
1527 {
1528 Log3(("VMMDev: no pending request!!!\n"));
1529 }
1530 }
1531
1532 if (!pDispRequest)
1533 {
1534 Log3(("VMMDev: default to %d\n",
1535 pThis->displayChangeData.iCurrentMonitor));
1536 pDispRequest = &pThis->displayChangeData.aRequests[pThis->displayChangeData.iCurrentMonitor];
1537 }
1538
1539 /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1540 * read the last valid video mode hint. This happens when the guest X server
1541 * determines the initial mode. */
1542 VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
1543 &pDispRequest->lastReadDisplayChangeRequest :
1544 &pDispRequest->displayChangeRequest;
1545 pReq->xres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CX) ? pDisplayDef->cx : 0;
1546 pReq->yres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CY) ? pDisplayDef->cy : 0;
1547 pReq->bpp = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_BPP) ? pDisplayDef->cBitsPerPixel : 0;
1548 pReq->display = pDisplayDef->idDisplay;
1549 pReq->cxOrigin = pDisplayDef->xOrigin;
1550 pReq->cyOrigin = pDisplayDef->yOrigin;
1551 pReq->fEnabled = !RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_DISABLED);
1552 pReq->fChangeOrigin = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN);
1553
1554 Log(("VMMDevEx: returning display change request xres = %d, yres = %d, bpp = %d id %d xPos = %d, yPos = %d & Enabled=%d\n",
1555 pReq->xres, pReq->yres, pReq->bpp, pReq->display, pReq->cxOrigin, pReq->cyOrigin, pReq->fEnabled));
1556
1557 return VINF_SUCCESS;
1558}
1559
1560
1561/**
1562 * Handles VMMDevReq_GetDisplayChangeRequestMulti.
1563 *
1564 * @returns VBox status code that the guest should see.
1565 * @param pThis The VMMDev shared instance data.
1566 * @param pReqHdr The header of the request to handle.
1567 */
1568static int vmmdevReqHandler_GetDisplayChangeRequestMulti(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
1569{
1570 VMMDevDisplayChangeRequestMulti *pReq = (VMMDevDisplayChangeRequestMulti *)pReqHdr;
1571 unsigned i;
1572
1573 ASSERT_GUEST_MSG_RETURN(pReq->header.size >= sizeof(*pReq),
1574 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1575 RT_UNTRUSTED_VALIDATED_FENCE();
1576
1577 uint32_t const cDisplays = pReq->cDisplays;
1578 ASSERT_GUEST_MSG_RETURN(cDisplays > 0 && cDisplays <= RT_ELEMENTS(pThis->displayChangeData.aRequests),
1579 ("cDisplays %u\n", cDisplays), VERR_INVALID_PARAMETER);
1580 RT_UNTRUSTED_VALIDATED_FENCE();
1581
1582 ASSERT_GUEST_MSG_RETURN(pReq->header.size >= sizeof(*pReq) + (cDisplays - 1) * sizeof(VMMDevDisplayDef),
1583 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1584 RT_UNTRUSTED_VALIDATED_FENCE();
1585
1586 if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1587 {
1588 uint32_t cDisplaysOut = 0;
1589 /* Remember which resolution the client has queried, subsequent reads
1590 * will return the same values. */
1591 for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); ++i)
1592 {
1593 DISPLAYCHANGEREQUEST *pDCR = &pThis->displayChangeData.aRequests[i];
1594
1595 pDCR->lastReadDisplayChangeRequest = pDCR->displayChangeRequest;
1596
1597 if (pDCR->fPending)
1598 {
1599 if (cDisplaysOut < cDisplays)
1600 pReq->aDisplays[cDisplaysOut] = pDCR->lastReadDisplayChangeRequest;
1601
1602 cDisplaysOut++;
1603 pDCR->fPending = false;
1604 }
1605 }
1606
1607 pReq->cDisplays = cDisplaysOut;
1608 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1609 }
1610 else
1611 {
1612 /* Fill the guest request with monitor layout data. */
1613 for (i = 0; i < cDisplays; ++i)
1614 {
1615 /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1616 * read the last valid video mode hint. This happens when the guest X server
1617 * determines the initial mode. */
1618 DISPLAYCHANGEREQUEST const *pDCR = &pThis->displayChangeData.aRequests[i];
1619 VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
1620 &pDCR->lastReadDisplayChangeRequest :
1621 &pDCR->displayChangeRequest;
1622 pReq->aDisplays[i] = *pDisplayDef;
1623 }
1624 }
1625
1626 Log(("VMMDev: returning multimonitor display change request cDisplays %d\n", cDisplays));
1627
1628 return VINF_SUCCESS;
1629}
1630
1631
1632/**
1633 * Handles VMMDevReq_VideoModeSupported.
1634 *
1635 * Query whether the given video mode is supported.
1636 *
1637 * @returns VBox status code that the guest should see.
1638 * @param pThisCC The VMMDev ring-3 instance data.
1639 * @param pReqHdr The header of the request to handle.
1640 */
1641static int vmmdevReqHandler_VideoModeSupported(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1642{
1643 VMMDevVideoModeSupportedRequest *pReq = (VMMDevVideoModeSupportedRequest *)pReqHdr;
1644 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1645
1646 /* forward the call */
1647 return pThisCC->pDrv->pfnVideoModeSupported(pThisCC->pDrv,
1648 0, /* primary screen. */
1649 pReq->width,
1650 pReq->height,
1651 pReq->bpp,
1652 &pReq->fSupported);
1653}
1654
1655
1656/**
1657 * Handles VMMDevReq_VideoModeSupported2.
1658 *
1659 * Query whether the given video mode is supported for a specific display
1660 *
1661 * @returns VBox status code that the guest should see.
1662 * @param pThisCC The VMMDev ring-3 instance data.
1663 * @param pReqHdr The header of the request to handle.
1664 */
1665static int vmmdevReqHandler_VideoModeSupported2(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1666{
1667 VMMDevVideoModeSupportedRequest2 *pReq = (VMMDevVideoModeSupportedRequest2 *)pReqHdr;
1668 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1669
1670 /* forward the call */
1671 return pThisCC->pDrv->pfnVideoModeSupported(pThisCC->pDrv,
1672 pReq->display,
1673 pReq->width,
1674 pReq->height,
1675 pReq->bpp,
1676 &pReq->fSupported);
1677}
1678
1679
1680
1681/**
1682 * Handles VMMDevReq_GetHeightReduction.
1683 *
1684 * @returns VBox status code that the guest should see.
1685 * @param pThisCC The VMMDev ring-3 instance data.
1686 * @param pReqHdr The header of the request to handle.
1687 */
1688static int vmmdevReqHandler_GetHeightReduction(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1689{
1690 VMMDevGetHeightReductionRequest *pReq = (VMMDevGetHeightReductionRequest *)pReqHdr;
1691 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1692
1693 /* forward the call */
1694 return pThisCC->pDrv->pfnGetHeightReduction(pThisCC->pDrv, &pReq->heightReduction);
1695}
1696
1697
1698/**
1699 * Handles VMMDevReq_AcknowledgeEvents.
1700 *
1701 * @returns VBox status code that the guest should see.
1702 * @param pDevIns The device instance.
1703 * @param pThis The VMMDev shared instance data.
1704 * @param pThisCC The VMMDev ring-3 instance data.
1705 * @param pReqHdr The header of the request to handle.
1706 */
1707static int vmmdevReqHandler_AcknowledgeEvents(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1708{
1709 VMMDevEvents *pReq = (VMMDevEvents *)pReqHdr;
1710 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1711 STAM_REL_COUNTER_INC(&pThis->StatSlowIrqAck);
1712
1713 if (!VMMDEV_INTERFACE_VERSION_IS_1_03(pThis))
1714 {
1715 /*
1716 * Note! This code is duplicated in vmmdevFastRequestIrqAck.
1717 */
1718 if (pThis->fNewGuestFilterMaskValid)
1719 {
1720 pThis->fNewGuestFilterMaskValid = false;
1721 pThis->fGuestFilterMask = pThis->fNewGuestFilterMask;
1722 }
1723
1724 pReq->events = pThis->fHostEventFlags & pThis->fGuestFilterMask;
1725
1726 pThis->fHostEventFlags &= ~pThis->fGuestFilterMask;
1727 pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_04.fHaveEvents = false;
1728
1729 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
1730 }
1731 else
1732 vmmdevSetIRQ_Legacy(pDevIns, pThis, pThisCC);
1733 return VINF_SUCCESS;
1734}
1735
1736
1737/**
1738 * Handles VMMDevReq_CtlGuestFilterMask.
1739 *
1740 * @returns VBox status code that the guest should see.
1741 * @param pDevIns The device instance.
1742 * @param pThis The VMMDev shared instance data.
1743 * @param pThisCC The VMMDev ring-3 instance data.
1744 * @param pReqHdr The header of the request to handle.
1745 */
1746static int vmmdevReqHandler_CtlGuestFilterMask(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1747{
1748 VMMDevCtlGuestFilterMask *pReq = (VMMDevCtlGuestFilterMask *)pReqHdr;
1749 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1750
1751 LogRelFlow(("VMMDev: vmmdevReqHandler_CtlGuestFilterMask: OR mask: %#x, NOT mask: %#x\n", pReq->u32OrMask, pReq->u32NotMask));
1752
1753 /* HGCM event notification is enabled by the VMMDev device
1754 * automatically when any HGCM command is issued. The guest
1755 * cannot disable these notifications. */
1756 VMMDevCtlSetGuestFilterMask(pDevIns, pThis, pThisCC, pReq->u32OrMask, pReq->u32NotMask & ~VMMDEV_EVENT_HGCM);
1757 return VINF_SUCCESS;
1758}
1759
1760#ifdef VBOX_WITH_HGCM
1761
1762/**
1763 * Handles VMMDevReq_HGCMConnect.
1764 *
1765 * @returns VBox status code that the guest should see.
1766 * @param pDevIns The device instance.
1767 * @param pThis The VMMDev shared instance data.
1768 * @param pThisCC The VMMDev ring-3 instance data.
1769 * @param pReqHdr The header of the request to handle.
1770 * @param GCPhysReqHdr The guest physical address of the request header.
1771 */
1772static int vmmdevReqHandler_HGCMConnect(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
1773 VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr)
1774{
1775 VMMDevHGCMConnect *pReq = (VMMDevHGCMConnect *)pReqHdr;
1776 AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this is >= ... */
1777
1778 if (pThisCC->pHGCMDrv)
1779 {
1780 Log(("VMMDevReq_HGCMConnect\n"));
1781 return vmmdevR3HgcmConnect(pDevIns, pThis, pThisCC, pReq, GCPhysReqHdr);
1782 }
1783
1784 Log(("VMMDevReq_HGCMConnect: HGCM Connector is NULL!\n"));
1785 return VERR_NOT_SUPPORTED;
1786}
1787
1788
1789/**
1790 * Handles VMMDevReq_HGCMDisconnect.
1791 *
1792 * @returns VBox status code that the guest should see.
1793 * @param pDevIns The device instance.
1794 * @param pThis The VMMDev shared instance data.
1795 * @param pThisCC The VMMDev ring-3 instance data.
1796 * @param pReqHdr The header of the request to handle.
1797 * @param GCPhysReqHdr The guest physical address of the request header.
1798 */
1799static int vmmdevReqHandler_HGCMDisconnect(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
1800 VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr)
1801{
1802 VMMDevHGCMDisconnect *pReq = (VMMDevHGCMDisconnect *)pReqHdr;
1803 AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
1804
1805 if (pThisCC->pHGCMDrv)
1806 {
1807 Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
1808 return vmmdevR3HgcmDisconnect(pDevIns, pThis, pThisCC, pReq, GCPhysReqHdr);
1809 }
1810
1811 Log(("VMMDevReq_VMMDevHGCMDisconnect: HGCM Connector is NULL!\n"));
1812 return VERR_NOT_SUPPORTED;
1813}
1814
1815
1816/**
1817 * Handles VMMDevReq_HGCMCall32 and VMMDevReq_HGCMCall64.
1818 *
1819 * @returns VBox status code that the guest should see.
1820 * @param pDevIns The device instance.
1821 * @param pThis The VMMDev shared instance data.
1822 * @param pThisCC The VMMDev ring-3 instance data.
1823 * @param pReqHdr The header of the request to handle.
1824 * @param GCPhysReqHdr The guest physical address of the request header.
1825 * @param tsArrival The STAM_GET_TS() value when the request arrived.
1826 * @param ppLock Pointer to the lock info pointer (latter can be
1827 * NULL). Set to NULL if HGCM takes lock ownership.
1828 */
1829static int vmmdevReqHandler_HGCMCall(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr,
1830 RTGCPHYS GCPhysReqHdr, uint64_t tsArrival, PVMMDEVREQLOCK *ppLock)
1831{
1832 VMMDevHGCMCall *pReq = (VMMDevHGCMCall *)pReqHdr;
1833 AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER);
1834
1835 if (pThisCC->pHGCMDrv)
1836 {
1837 Log2(("VMMDevReq_HGCMCall: sizeof(VMMDevHGCMRequest) = %04X\n", sizeof(VMMDevHGCMCall)));
1838 Log2(("%.*Rhxd\n", pReq->header.header.size, pReq));
1839
1840 return vmmdevR3HgcmCall(pDevIns, pThis, pThisCC, pReq, pReq->header.header.size, GCPhysReqHdr,
1841 pReq->header.header.requestType, tsArrival, ppLock);
1842 }
1843
1844 Log(("VMMDevReq_HGCMCall: HGCM Connector is NULL!\n"));
1845 return VERR_NOT_SUPPORTED;
1846}
1847
1848/**
1849 * Handles VMMDevReq_HGCMCancel.
1850 *
1851 * @returns VBox status code that the guest should see.
1852 * @param pThisCC The VMMDev ring-3 instance data.
1853 * @param pReqHdr The header of the request to handle.
1854 * @param GCPhysReqHdr The guest physical address of the request header.
1855 */
1856static int vmmdevReqHandler_HGCMCancel(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr)
1857{
1858 VMMDevHGCMCancel *pReq = (VMMDevHGCMCancel *)pReqHdr;
1859 AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
1860
1861 if (pThisCC->pHGCMDrv)
1862 {
1863 Log(("VMMDevReq_VMMDevHGCMCancel\n"));
1864 return vmmdevR3HgcmCancel(pThisCC, pReq, GCPhysReqHdr);
1865 }
1866
1867 Log(("VMMDevReq_VMMDevHGCMCancel: HGCM Connector is NULL!\n"));
1868 return VERR_NOT_SUPPORTED;
1869}
1870
1871
1872/**
1873 * Handles VMMDevReq_HGCMCancel2.
1874 *
1875 * @returns VBox status code that the guest should see.
1876 * @param pThisCC The VMMDev ring-3 instance data.
1877 * @param pReqHdr The header of the request to handle.
1878 */
1879static int vmmdevReqHandler_HGCMCancel2(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1880{
1881 VMMDevHGCMCancel2 *pReq = (VMMDevHGCMCancel2 *)pReqHdr;
1882 AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
1883
1884 if (pThisCC->pHGCMDrv)
1885 {
1886 Log(("VMMDevReq_HGCMCancel2\n"));
1887 return vmmdevR3HgcmCancel2(pThisCC, pReq->physReqToCancel);
1888 }
1889
1890 Log(("VMMDevReq_HGCMCancel2: HGCM Connector is NULL!\n"));
1891 return VERR_NOT_SUPPORTED;
1892}
1893
1894#endif /* VBOX_WITH_HGCM */
1895
1896
1897/**
1898 * Handles VMMDevReq_VideoAccelEnable.
1899 *
1900 * @returns VBox status code that the guest should see.
1901 * @param pThis The VMMDev shared instance data.
1902 * @param pThisCC The VMMDev ring-3 instance data.
1903 * @param pReqHdr The header of the request to handle.
1904 */
1905static int vmmdevReqHandler_VideoAccelEnable(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1906{
1907 VMMDevVideoAccelEnable *pReq = (VMMDevVideoAccelEnable *)pReqHdr;
1908 AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
1909
1910 if (!pThisCC->pDrv)
1911 {
1912 Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!\n"));
1913 return VERR_NOT_SUPPORTED;
1914 }
1915
1916 if (pReq->cbRingBuffer != VMMDEV_VBVA_RING_BUFFER_SIZE)
1917 {
1918 /* The guest driver seems compiled with different headers. */
1919 LogRelMax(16,("VMMDevReq_VideoAccelEnable guest ring buffer size %#x, should be %#x!!\n", pReq->cbRingBuffer, VMMDEV_VBVA_RING_BUFFER_SIZE));
1920 return VERR_INVALID_PARAMETER;
1921 }
1922
1923 /* The request is correct. */
1924 pReq->fu32Status |= VBVA_F_STATUS_ACCEPTED;
1925
1926 LogFlow(("VMMDevReq_VideoAccelEnable pReq->u32Enable = %d\n", pReq->u32Enable));
1927
1928 int rc = pReq->u32Enable
1929 ? pThisCC->pDrv->pfnVideoAccelEnable(pThisCC->pDrv, true, &pThisCC->pVMMDevRAMR3->vbvaMemory)
1930 : pThisCC->pDrv->pfnVideoAccelEnable(pThisCC->pDrv, false, NULL);
1931
1932 if ( pReq->u32Enable
1933 && RT_SUCCESS(rc))
1934 {
1935 pReq->fu32Status |= VBVA_F_STATUS_ENABLED;
1936
1937 /* Remember that guest successfully enabled acceleration.
1938 * We need to reestablish it on restoring the VM from saved state.
1939 */
1940 pThis->u32VideoAccelEnabled = 1;
1941 }
1942 else
1943 {
1944 /* The acceleration was not enabled. Remember that. */
1945 pThis->u32VideoAccelEnabled = 0;
1946 }
1947 return VINF_SUCCESS;
1948}
1949
1950
1951/**
1952 * Handles VMMDevReq_VideoAccelFlush.
1953 *
1954 * @returns VBox status code that the guest should see.
1955 * @param pThisCC The VMMDev ring-3 instance data.
1956 * @param pReqHdr The header of the request to handle.
1957 */
1958static int vmmdevReqHandler_VideoAccelFlush(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1959{
1960 VMMDevVideoAccelFlush *pReq = (VMMDevVideoAccelFlush *)pReqHdr;
1961 AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
1962
1963 if (!pThisCC->pDrv)
1964 {
1965 Log(("VMMDevReq_VideoAccelFlush: Connector is NULL!!!\n"));
1966 return VERR_NOT_SUPPORTED;
1967 }
1968
1969 pThisCC->pDrv->pfnVideoAccelFlush(pThisCC->pDrv);
1970 return VINF_SUCCESS;
1971}
1972
1973
1974/**
1975 * Handles VMMDevReq_VideoSetVisibleRegion.
1976 *
1977 * @returns VBox status code that the guest should see.
1978 * @param pThisCC The VMMDev ring-3 instance data.
1979 * @param pReqHdr The header of the request to handle.
1980 */
1981static int vmmdevReqHandler_VideoSetVisibleRegion(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
1982{
1983 VMMDevVideoSetVisibleRegion *pReq = (VMMDevVideoSetVisibleRegion *)pReqHdr;
1984 AssertMsgReturn(pReq->header.size + sizeof(RTRECT) >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
1985
1986 if (!pThisCC->pDrv)
1987 {
1988 Log(("VMMDevReq_VideoSetVisibleRegion: Connector is NULL!!!\n"));
1989 return VERR_NOT_SUPPORTED;
1990 }
1991
1992 if ( pReq->cRect > _1M /* restrict to sane range */
1993 || pReq->header.size != sizeof(VMMDevVideoSetVisibleRegion) + pReq->cRect * sizeof(RTRECT) - sizeof(RTRECT))
1994 {
1995 Log(("VMMDevReq_VideoSetVisibleRegion: cRects=%#x doesn't match size=%#x or is out of bounds\n",
1996 pReq->cRect, pReq->header.size));
1997 return VERR_INVALID_PARAMETER;
1998 }
1999
2000 Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", pReq->cRect));
2001 /* forward the call */
2002 return pThisCC->pDrv->pfnSetVisibleRegion(pThisCC->pDrv, pReq->cRect, &pReq->Rect);
2003}
2004
2005/**
2006 * Handles VMMDevReq_VideoUpdateMonitorPositions.
2007 *
2008 * @returns VBox status code that the guest should see.
2009 * @param pThisCC The VMMDev ring-3 instance data.
2010 * @param pReqHdr The header of the request to handle.
2011 */
2012static int vmmdevReqHandler_VideoUpdateMonitorPositions(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
2013{
2014 VMMDevVideoUpdateMonitorPositions *pReq = (VMMDevVideoUpdateMonitorPositions *)pReqHdr;
2015 AssertMsgReturn(pReq->header.size + sizeof(RTRECT) >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2016 if (!pThisCC->pDrv)
2017 {
2018 Log(("VMMDevReq_VideoUpdateMonitorPositions: Connector is NULL!!!\n"));
2019 return VERR_NOT_SUPPORTED;
2020 }
2021 if ( pReq->cPositions > _1M /* restrict to sane range */
2022 || pReq->header.size != sizeof(VMMDevVideoUpdateMonitorPositions) + pReq->cPositions * sizeof(RTPOINT) - sizeof(RTPOINT))
2023 {
2024 Log(("VMMDevReq_VideoUpdateMonitorPositions: cRects=%#x doesn't match size=%#x or is out of bounds\n",
2025 pReq->cPositions, pReq->header.size));
2026 return VERR_INVALID_PARAMETER;
2027 }
2028 Log(("VMMDevReq_VideoUpdateMonitorPositions %d rectangles\n", pReq->cPositions));
2029 /* forward the call */
2030 return pThisCC->pDrv->pfnUpdateMonitorPositions(pThisCC->pDrv, pReq->cPositions, &(pReq->aPositions[0]));
2031}
2032
2033/**
2034 * Handles VMMDevReq_GetSeamlessChangeRequest.
2035 *
2036 * @returns VBox status code that the guest should see.
2037 * @param pThis The VMMDev shared instance data.
2038 * @param pReqHdr The header of the request to handle.
2039 */
2040static int vmmdevReqHandler_GetSeamlessChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2041{
2042 VMMDevSeamlessChangeRequest *pReq = (VMMDevSeamlessChangeRequest *)pReqHdr;
2043 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2044
2045 /* just pass on the information */
2046 Log(("VMMDev: returning seamless change request mode=%d\n", pThis->fSeamlessEnabled));
2047 if (pThis->fSeamlessEnabled)
2048 pReq->mode = VMMDev_Seamless_Visible_Region;
2049 else
2050 pReq->mode = VMMDev_Seamless_Disabled;
2051
2052 if (pReq->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
2053 {
2054 /* Remember which mode the client has queried. */
2055 pThis->fLastSeamlessEnabled = pThis->fSeamlessEnabled;
2056 }
2057
2058 return VINF_SUCCESS;
2059}
2060
2061
2062/**
2063 * Handles VMMDevReq_GetVRDPChangeRequest.
2064 *
2065 * @returns VBox status code that the guest should see.
2066 * @param pThis The VMMDev shared instance data.
2067 * @param pReqHdr The header of the request to handle.
2068 */
2069static int vmmdevReqHandler_GetVRDPChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2070{
2071 VMMDevVRDPChangeRequest *pReq = (VMMDevVRDPChangeRequest *)pReqHdr;
2072 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2073
2074 /* just pass on the information */
2075 Log(("VMMDev: returning VRDP status %d level %d\n", pThis->fVRDPEnabled, pThis->uVRDPExperienceLevel));
2076
2077 pReq->u8VRDPActive = pThis->fVRDPEnabled;
2078 pReq->u32VRDPExperienceLevel = pThis->uVRDPExperienceLevel;
2079
2080 return VINF_SUCCESS;
2081}
2082
2083
2084/**
2085 * Handles VMMDevReq_GetMemBalloonChangeRequest.
2086 *
2087 * @returns VBox status code that the guest should see.
2088 * @param pThis The VMMDev shared instance data.
2089 * @param pReqHdr The header of the request to handle.
2090 */
2091static int vmmdevReqHandler_GetMemBalloonChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2092{
2093 VMMDevGetMemBalloonChangeRequest *pReq = (VMMDevGetMemBalloonChangeRequest *)pReqHdr;
2094 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2095
2096 /* just pass on the information */
2097 Log(("VMMDev: returning memory balloon size =%d\n", pThis->cMbMemoryBalloon));
2098 pReq->cBalloonChunks = pThis->cMbMemoryBalloon;
2099 pReq->cPhysMemChunks = pThis->cbGuestRAM / (uint64_t)_1M;
2100
2101 if (pReq->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
2102 {
2103 /* Remember which mode the client has queried. */
2104 pThis->cMbMemoryBalloonLast = pThis->cMbMemoryBalloon;
2105 }
2106
2107 return VINF_SUCCESS;
2108}
2109
2110
2111/**
2112 * Handles VMMDevReq_ChangeMemBalloon.
2113 *
2114 * @returns VBox status code that the guest should see.
2115 * @param pDevIns The device instance.
2116 * @param pThis The VMMDev shared instance data.
2117 * @param pReqHdr The header of the request to handle.
2118 */
2119static int vmmdevReqHandler_ChangeMemBalloon(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2120{
2121 VMMDevChangeMemBalloon *pReq = (VMMDevChangeMemBalloon *)pReqHdr;
2122 AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2123 AssertMsgReturn(pReq->cPages == VMMDEV_MEMORY_BALLOON_CHUNK_PAGES, ("%u\n", pReq->cPages), VERR_INVALID_PARAMETER);
2124 AssertMsgReturn(pReq->header.size == (uint32_t)RT_UOFFSETOF_DYN(VMMDevChangeMemBalloon, aPhysPage[pReq->cPages]),
2125 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2126
2127 Log(("VMMDevReq_ChangeMemBalloon\n"));
2128 int rc = PDMDevHlpPhysChangeMemBalloon(pDevIns, !!pReq->fInflate, pReq->cPages, pReq->aPhysPage);
2129 if (pReq->fInflate)
2130 STAM_REL_U32_INC(&pThis->StatMemBalloonChunks);
2131 else
2132 STAM_REL_U32_DEC(&pThis->StatMemBalloonChunks);
2133 return rc;
2134}
2135
2136
2137/**
2138 * Handles VMMDevReq_GetStatisticsChangeRequest.
2139 *
2140 * @returns VBox status code that the guest should see.
2141 * @param pThis The VMMDev shared instance data.
2142 * @param pReqHdr The header of the request to handle.
2143 */
2144static int vmmdevReqHandler_GetStatisticsChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2145{
2146 VMMDevGetStatisticsChangeRequest *pReq = (VMMDevGetStatisticsChangeRequest *)pReqHdr;
2147 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2148
2149 Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
2150 /* just pass on the information */
2151 Log(("VMMDev: returning statistics interval %d seconds\n", pThis->cSecsStatInterval));
2152 pReq->u32StatInterval = pThis->cSecsStatInterval;
2153
2154 if (pReq->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
2155 {
2156 /* Remember which mode the client has queried. */
2157 pThis->cSecsLastStatInterval = pThis->cSecsStatInterval;
2158 }
2159
2160 return VINF_SUCCESS;
2161}
2162
2163
2164/**
2165 * Handles VMMDevReq_ReportGuestStats.
2166 *
2167 * @returns VBox status code that the guest should see.
2168 * @param pThisCC The VMMDev ring-3 instance data.
2169 * @param pReqHdr The header of the request to handle.
2170 */
2171static int vmmdevReqHandler_ReportGuestStats(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
2172{
2173 VMMDevReportGuestStats *pReq = (VMMDevReportGuestStats *)pReqHdr;
2174 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2175
2176 Log(("VMMDevReq_ReportGuestStats\n"));
2177#ifdef LOG_ENABLED
2178 VBoxGuestStatistics *pGuestStats = &pReq->guestStats;
2179
2180 Log(("Current statistics:\n"));
2181 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
2182 Log(("CPU%u: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
2183
2184 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
2185 Log(("CPU%u: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
2186
2187 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
2188 Log(("CPU%u: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
2189
2190 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
2191 Log(("CPU%u: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
2192
2193 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
2194 Log(("CPU%u: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
2195
2196 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
2197 Log(("CPU%u: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
2198
2199 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
2200 Log(("CPU%u: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
2201
2202 /* Note that reported values are in pages; upper layers expect them in megabytes */
2203 Log(("CPU%u: Page size %-4d bytes\n", pGuestStats->u32CpuId, pGuestStats->u32PageSize));
2204 Assert(pGuestStats->u32PageSize == 4096);
2205
2206 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
2207 Log(("CPU%u: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/_4K)-1) / (_1M/_4K)));
2208
2209 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
2210 Log(("CPU%u: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/_4K)));
2211
2212 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
2213 Log(("CPU%u: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/_4K)));
2214
2215 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
2216 Log(("CPU%u: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/_4K)));
2217
2218 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
2219 Log(("CPU%u: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/_4K)));
2220
2221 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
2222 Log(("CPU%u: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/_4K)));
2223
2224 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
2225 Log(("CPU%u: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/_4K)));
2226
2227 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
2228 Log(("CPU%u: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/_4K)));
2229
2230 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
2231 Log(("CPU%u: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/_4K)));
2232 Log(("Statistics end *******************\n"));
2233#endif /* LOG_ENABLED */
2234
2235 /* forward the call */
2236 return pThisCC->pDrv->pfnReportStatistics(pThisCC->pDrv, &pReq->guestStats);
2237}
2238
2239
2240/**
2241 * Handles VMMDevReq_QueryCredentials.
2242 *
2243 * @returns VBox status code that the guest should see.
2244 * @param pThis The VMMDev shared instance data.
2245 * @param pThisCC The VMMDev ring-3 instance data.
2246 * @param pReqHdr The header of the request to handle.
2247 */
2248static int vmmdevReqHandler_QueryCredentials(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
2249{
2250 VMMDevCredentials *pReq = (VMMDevCredentials *)pReqHdr;
2251 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2252 VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
2253 AssertPtrReturn(pCredentials, VERR_NOT_SUPPORTED);
2254
2255 /* let's start by nulling out the data */
2256 RT_ZERO(pReq->szUserName);
2257 RT_ZERO(pReq->szPassword);
2258 RT_ZERO(pReq->szDomain);
2259
2260 /* should we return whether we got credentials for a logon? */
2261 if (pReq->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
2262 {
2263 if ( pCredentials->Logon.szUserName[0]
2264 || pCredentials->Logon.szPassword[0]
2265 || pCredentials->Logon.szDomain[0])
2266 pReq->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
2267 else
2268 pReq->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
2269 }
2270
2271 /* does the guest want to read logon credentials? */
2272 if (pReq->u32Flags & VMMDEV_CREDENTIALS_READ)
2273 {
2274 if (pCredentials->Logon.szUserName[0])
2275 RTStrCopy(pReq->szUserName, sizeof(pReq->szUserName), pCredentials->Logon.szUserName);
2276 if (pCredentials->Logon.szPassword[0])
2277 RTStrCopy(pReq->szPassword, sizeof(pReq->szPassword), pCredentials->Logon.szPassword);
2278 if (pCredentials->Logon.szDomain[0])
2279 RTStrCopy(pReq->szDomain, sizeof(pReq->szDomain), pCredentials->Logon.szDomain);
2280 if (!pCredentials->Logon.fAllowInteractiveLogon)
2281 pReq->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
2282 else
2283 pReq->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
2284 }
2285
2286 if (!pThis->fKeepCredentials)
2287 {
2288 /* does the caller want us to destroy the logon credentials? */
2289 if (pReq->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
2290 {
2291 RT_ZERO(pCredentials->Logon.szUserName);
2292 RT_ZERO(pCredentials->Logon.szPassword);
2293 RT_ZERO(pCredentials->Logon.szDomain);
2294 }
2295 }
2296
2297 /* does the guest want to read credentials for verification? */
2298 if (pReq->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
2299 {
2300 if (pCredentials->Judge.szUserName[0])
2301 RTStrCopy(pReq->szUserName, sizeof(pReq->szUserName), pCredentials->Judge.szUserName);
2302 if (pCredentials->Judge.szPassword[0])
2303 RTStrCopy(pReq->szPassword, sizeof(pReq->szPassword), pCredentials->Judge.szPassword);
2304 if (pCredentials->Judge.szDomain[0])
2305 RTStrCopy(pReq->szDomain, sizeof(pReq->szDomain), pCredentials->Judge.szDomain);
2306 }
2307
2308 /* does the caller want us to destroy the judgement credentials? */
2309 if (pReq->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
2310 {
2311 RT_ZERO(pCredentials->Judge.szUserName);
2312 RT_ZERO(pCredentials->Judge.szPassword);
2313 RT_ZERO(pCredentials->Judge.szDomain);
2314 }
2315
2316 return VINF_SUCCESS;
2317}
2318
2319
2320/**
2321 * Handles VMMDevReq_ReportCredentialsJudgement.
2322 *
2323 * @returns VBox status code that the guest should see.
2324 * @param pThisCC The VMMDev ring-3 instance data.
2325 * @param pReqHdr The header of the request to handle.
2326 */
2327static int vmmdevReqHandler_ReportCredentialsJudgement(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
2328{
2329 VMMDevCredentials *pReq = (VMMDevCredentials *)pReqHdr;
2330 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2331
2332 /* what does the guest think about the credentials? (note: the order is important here!) */
2333 if (pReq->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
2334 pThisCC->pDrv->pfnSetCredentialsJudgementResult(pThisCC->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
2335 else if (pReq->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
2336 pThisCC->pDrv->pfnSetCredentialsJudgementResult(pThisCC->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
2337 else if (pReq->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
2338 pThisCC->pDrv->pfnSetCredentialsJudgementResult(pThisCC->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
2339 else
2340 {
2341 Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", pReq->u32Flags));
2342 /** @todo why don't we return VERR_INVALID_PARAMETER to the guest? */
2343 }
2344
2345 return VINF_SUCCESS;
2346}
2347
2348
2349/**
2350 * Handles VMMDevReq_GetHostVersion.
2351 *
2352 * @returns VBox status code that the guest should see.
2353 * @param pReqHdr The header of the request to handle.
2354 * @since 3.1.0
2355 * @note The ring-0 VBoxGuestLib uses this to check whether
2356 * VMMDevHGCMParmType_PageList is supported.
2357 */
2358static int vmmdevReqHandler_GetHostVersion(VMMDevRequestHeader *pReqHdr)
2359{
2360 VMMDevReqHostVersion *pReq = (VMMDevReqHostVersion *)pReqHdr;
2361 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2362
2363 pReq->major = RTBldCfgVersionMajor();
2364 pReq->minor = RTBldCfgVersionMinor();
2365 pReq->build = RTBldCfgVersionBuild();
2366 pReq->revision = RTBldCfgRevision();
2367 pReq->features = VMMDEV_HVF_HGCM_PHYS_PAGE_LIST
2368 | VMMDEV_HVF_HGCM_EMBEDDED_BUFFERS
2369 | VMMDEV_HVF_HGCM_CONTIGUOUS_PAGE_LIST
2370 | VMMDEV_HVF_HGCM_NO_BOUNCE_PAGE_LIST
2371 | VMMDEV_HVF_FAST_IRQ_ACK;
2372 return VINF_SUCCESS;
2373}
2374
2375
2376/**
2377 * Handles VMMDevReq_GetCpuHotPlugRequest.
2378 *
2379 * @returns VBox status code that the guest should see.
2380 * @param pThis The VMMDev shared instance data.
2381 * @param pReqHdr The header of the request to handle.
2382 */
2383static int vmmdevReqHandler_GetCpuHotPlugRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2384{
2385 VMMDevGetCpuHotPlugRequest *pReq = (VMMDevGetCpuHotPlugRequest *)pReqHdr;
2386 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2387
2388 pReq->enmEventType = pThis->enmCpuHotPlugEvent;
2389 pReq->idCpuCore = pThis->idCpuCore;
2390 pReq->idCpuPackage = pThis->idCpuPackage;
2391
2392 /* Clear the event */
2393 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_None;
2394 pThis->idCpuCore = UINT32_MAX;
2395 pThis->idCpuPackage = UINT32_MAX;
2396
2397 return VINF_SUCCESS;
2398}
2399
2400
2401/**
2402 * Handles VMMDevReq_SetCpuHotPlugStatus.
2403 *
2404 * @returns VBox status code that the guest should see.
2405 * @param pThis The VMMDev shared instance data.
2406 * @param pReqHdr The header of the request to handle.
2407 */
2408static int vmmdevReqHandler_SetCpuHotPlugStatus(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2409{
2410 VMMDevCpuHotPlugStatusRequest *pReq = (VMMDevCpuHotPlugStatusRequest *)pReqHdr;
2411 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2412
2413 if (pReq->enmStatusType == VMMDevCpuStatusType_Disable)
2414 pThis->fCpuHotPlugEventsEnabled = false;
2415 else if (pReq->enmStatusType == VMMDevCpuStatusType_Enable)
2416 pThis->fCpuHotPlugEventsEnabled = true;
2417 else
2418 return VERR_INVALID_PARAMETER;
2419 return VINF_SUCCESS;
2420}
2421
2422
2423#ifdef DEBUG
2424/**
2425 * Handles VMMDevReq_LogString.
2426 *
2427 * @returns VBox status code that the guest should see.
2428 * @param pReqHdr The header of the request to handle.
2429 */
2430static int vmmdevReqHandler_LogString(VMMDevRequestHeader *pReqHdr)
2431{
2432 VMMDevReqLogString *pReq = (VMMDevReqLogString *)pReqHdr;
2433 AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2434 AssertMsgReturn(pReq->szString[pReq->header.size - RT_UOFFSETOF(VMMDevReqLogString, szString) - 1] == '\0',
2435 ("not null terminated\n"), VERR_INVALID_PARAMETER);
2436
2437 LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("DEBUG LOG: %s", pReq->szString));
2438 return VINF_SUCCESS;
2439}
2440#endif /* DEBUG */
2441
2442/**
2443 * Handles VMMDevReq_GetSessionId.
2444 *
2445 * Get a unique "session" ID for this VM, where the ID will be different after each
2446 * start, reset or restore of the VM. This can be used for restore detection
2447 * inside the guest.
2448 *
2449 * @returns VBox status code that the guest should see.
2450 * @param pThis The VMMDev shared instance data.
2451 * @param pReqHdr The header of the request to handle.
2452 */
2453static int vmmdevReqHandler_GetSessionId(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2454{
2455 VMMDevReqSessionId *pReq = (VMMDevReqSessionId *)pReqHdr;
2456 AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2457
2458 pReq->idSession = pThis->idSession;
2459 return VINF_SUCCESS;
2460}
2461
2462
2463#ifdef VBOX_WITH_PAGE_SHARING
2464
2465/**
2466 * Handles VMMDevReq_RegisterSharedModule.
2467 *
2468 * @returns VBox status code that the guest should see.
2469 * @param pDevIns The device instance.
2470 * @param pReqHdr The header of the request to handle.
2471 */
2472static int vmmdevReqHandler_RegisterSharedModule(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
2473{
2474 /*
2475 * Basic input validation (more done by GMM).
2476 */
2477 VMMDevSharedModuleRegistrationRequest *pReq = (VMMDevSharedModuleRegistrationRequest *)pReqHdr;
2478 AssertMsgReturn(pReq->header.size >= sizeof(VMMDevSharedModuleRegistrationRequest),
2479 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2480 AssertMsgReturn(pReq->header.size == RT_UOFFSETOF_DYN(VMMDevSharedModuleRegistrationRequest, aRegions[pReq->cRegions]),
2481 ("%u cRegions=%u\n", pReq->header.size, pReq->cRegions), VERR_INVALID_PARAMETER);
2482
2483 AssertReturn(RTStrEnd(pReq->szName, sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
2484 AssertReturn(RTStrEnd(pReq->szVersion, sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
2485 int rc = RTStrValidateEncoding(pReq->szName);
2486 AssertRCReturn(rc, rc);
2487 rc = RTStrValidateEncoding(pReq->szVersion);
2488 AssertRCReturn(rc, rc);
2489
2490 /*
2491 * Forward the request to the VMM.
2492 */
2493 return PDMDevHlpSharedModuleRegister(pDevIns, pReq->enmGuestOS, pReq->szName, pReq->szVersion,
2494 pReq->GCBaseAddr, pReq->cbModule, pReq->cRegions, pReq->aRegions);
2495}
2496
2497/**
2498 * Handles VMMDevReq_UnregisterSharedModule.
2499 *
2500 * @returns VBox status code that the guest should see.
2501 * @param pDevIns The device instance.
2502 * @param pReqHdr The header of the request to handle.
2503 */
2504static int vmmdevReqHandler_UnregisterSharedModule(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
2505{
2506 /*
2507 * Basic input validation.
2508 */
2509 VMMDevSharedModuleUnregistrationRequest *pReq = (VMMDevSharedModuleUnregistrationRequest *)pReqHdr;
2510 AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleUnregistrationRequest),
2511 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2512
2513 AssertReturn(RTStrEnd(pReq->szName, sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
2514 AssertReturn(RTStrEnd(pReq->szVersion, sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
2515 int rc = RTStrValidateEncoding(pReq->szName);
2516 AssertRCReturn(rc, rc);
2517 rc = RTStrValidateEncoding(pReq->szVersion);
2518 AssertRCReturn(rc, rc);
2519
2520 /*
2521 * Forward the request to the VMM.
2522 */
2523 return PDMDevHlpSharedModuleUnregister(pDevIns, pReq->szName, pReq->szVersion,
2524 pReq->GCBaseAddr, pReq->cbModule);
2525}
2526
2527/**
2528 * Handles VMMDevReq_CheckSharedModules.
2529 *
2530 * @returns VBox status code that the guest should see.
2531 * @param pDevIns The device instance.
2532 * @param pReqHdr The header of the request to handle.
2533 */
2534static int vmmdevReqHandler_CheckSharedModules(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
2535{
2536 VMMDevSharedModuleCheckRequest *pReq = (VMMDevSharedModuleCheckRequest *)pReqHdr;
2537 AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleCheckRequest),
2538 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2539 return PDMDevHlpSharedModuleCheckAll(pDevIns);
2540}
2541
2542/**
2543 * Handles VMMDevReq_GetPageSharingStatus.
2544 *
2545 * @returns VBox status code that the guest should see.
2546 * @param pThisCC The VMMDev ring-3 instance data.
2547 * @param pReqHdr The header of the request to handle.
2548 */
2549static int vmmdevReqHandler_GetPageSharingStatus(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
2550{
2551 VMMDevPageSharingStatusRequest *pReq = (VMMDevPageSharingStatusRequest *)pReqHdr;
2552 AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageSharingStatusRequest),
2553 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2554
2555 pReq->fEnabled = false;
2556 int rc = pThisCC->pDrv->pfnIsPageFusionEnabled(pThisCC->pDrv, &pReq->fEnabled);
2557 if (RT_FAILURE(rc))
2558 pReq->fEnabled = false;
2559 return VINF_SUCCESS;
2560}
2561
2562
2563/**
2564 * Handles VMMDevReq_DebugIsPageShared.
2565 *
2566 * @returns VBox status code that the guest should see.
2567 * @param pDevIns The device instance.
2568 * @param pReqHdr The header of the request to handle.
2569 */
2570static int vmmdevReqHandler_DebugIsPageShared(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
2571{
2572 VMMDevPageIsSharedRequest *pReq = (VMMDevPageIsSharedRequest *)pReqHdr;
2573 AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageIsSharedRequest),
2574 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2575
2576 return PDMDevHlpSharedModuleGetPageState(pDevIns, pReq->GCPtrPage, &pReq->fShared, &pReq->uPageFlags);
2577}
2578
2579#endif /* VBOX_WITH_PAGE_SHARING */
2580
2581
2582/**
2583 * Handles VMMDevReq_WriteCoreDumpe
2584 *
2585 * @returns VBox status code that the guest should see.
2586 * @param pDevIns The device instance.
2587 * @param pThis The VMMDev shared instance data.
2588 * @param pReqHdr Pointer to the request header.
2589 */
2590static int vmmdevReqHandler_WriteCoreDump(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
2591{
2592 VMMDevReqWriteCoreDump *pReq = (VMMDevReqWriteCoreDump *)pReqHdr;
2593 AssertMsgReturn(pReq->header.size == sizeof(VMMDevReqWriteCoreDump), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
2594
2595 /*
2596 * Only available if explicitly enabled by the user.
2597 */
2598 if (!pThis->fGuestCoreDumpEnabled)
2599 return VERR_ACCESS_DENIED;
2600
2601 /*
2602 * User makes sure the directory exists before composing the path.
2603 */
2604 if (!RTDirExists(pThis->szGuestCoreDumpDir))
2605 return VERR_PATH_NOT_FOUND;
2606
2607 char szCorePath[RTPATH_MAX];
2608 RTStrCopy(szCorePath, sizeof(szCorePath), pThis->szGuestCoreDumpDir);
2609 RTPathAppend(szCorePath, sizeof(szCorePath), "VBox.core");
2610
2611 /*
2612 * Rotate existing cores based on number of additional cores to keep around.
2613 */
2614 if (pThis->cGuestCoreDumps > 0)
2615 for (int64_t i = pThis->cGuestCoreDumps - 1; i >= 0; i--)
2616 {
2617 char szFilePathOld[RTPATH_MAX];
2618 if (i == 0)
2619 RTStrCopy(szFilePathOld, sizeof(szFilePathOld), szCorePath);
2620 else
2621 RTStrPrintf(szFilePathOld, sizeof(szFilePathOld), "%s.%lld", szCorePath, i);
2622
2623 char szFilePathNew[RTPATH_MAX];
2624 RTStrPrintf(szFilePathNew, sizeof(szFilePathNew), "%s.%lld", szCorePath, i + 1);
2625 int vrc = RTFileMove(szFilePathOld, szFilePathNew, RTFILEMOVE_FLAGS_REPLACE);
2626 if (vrc == VERR_FILE_NOT_FOUND)
2627 RTFileDelete(szFilePathNew);
2628 }
2629
2630 /*
2631 * Write the core file.
2632 */
2633 PUVM pUVM = PDMDevHlpGetUVM(pDevIns);
2634 return DBGFR3CoreWrite(pUVM, szCorePath, true /*fReplaceFile*/);
2635}
2636
2637
2638/**
2639 * Sets request status to VINF_HGCM_ASYNC_EXECUTE.
2640 *
2641 * @param pDevIns The device instance.
2642 * @param GCPhysReqHdr The guest physical address of the request.
2643 * @param pLock Pointer to the request locking info. NULL if not
2644 * locked.
2645 */
2646DECLINLINE(void) vmmdevReqHdrSetHgcmAsyncExecute(PPDMDEVINS pDevIns, RTGCPHYS GCPhysReqHdr, PVMMDEVREQLOCK pLock)
2647{
2648 if (pLock)
2649 ((VMMDevRequestHeader volatile *)pLock->pvReq)->rc = VINF_HGCM_ASYNC_EXECUTE;
2650 else
2651 {
2652 int32_t rcReq = VINF_HGCM_ASYNC_EXECUTE;
2653 PDMDevHlpPhysWrite(pDevIns, GCPhysReqHdr + RT_UOFFSETOF(VMMDevRequestHeader, rc), &rcReq, sizeof(rcReq));
2654 }
2655}
2656
2657
2658/** @name VMMDEVREQDISP_POST_F_XXX - post dispatcher optimizations.
2659 * @{ */
2660#define VMMDEVREQDISP_POST_F_NO_WRITE_OUT RT_BIT_32(0)
2661/** @} */
2662
2663
2664/**
2665 * Dispatch the request to the appropriate handler function.
2666 *
2667 * @returns Port I/O handler exit code.
2668 * @param pDevIns The device instance.
2669 * @param pThis The VMMDev shared instance data.
2670 * @param pThisCC The VMMDev ring-3 instance data.
2671 * @param pReqHdr The request header (cached in host memory).
2672 * @param GCPhysReqHdr The guest physical address of the request (for
2673 * HGCM).
2674 * @param tsArrival The STAM_GET_TS() value when the request arrived.
2675 * @param pfPostOptimize HGCM optimizations, VMMDEVREQDISP_POST_F_XXX.
2676 * @param ppLock Pointer to the lock info pointer (latter can be
2677 * NULL). Set to NULL if HGCM takes lock ownership.
2678 */
2679static VBOXSTRICTRC vmmdevReqDispatcher(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr,
2680 RTGCPHYS GCPhysReqHdr, uint64_t tsArrival, uint32_t *pfPostOptimize,
2681 PVMMDEVREQLOCK *ppLock)
2682{
2683 int rcRet = VINF_SUCCESS;
2684 Assert(*pfPostOptimize == 0);
2685 switch (pReqHdr->requestType)
2686 {
2687 case VMMDevReq_ReportGuestInfo:
2688 pReqHdr->rc = vmmdevReqHandler_ReportGuestInfo(pDevIns, pThis, pThisCC, pReqHdr);
2689 break;
2690
2691 case VMMDevReq_ReportGuestInfo2:
2692 pReqHdr->rc = vmmdevReqHandler_ReportGuestInfo2(pDevIns, pThis, pThisCC, pReqHdr);
2693 break;
2694
2695 case VMMDevReq_ReportGuestStatus:
2696 pReqHdr->rc = vmmdevReqHandler_ReportGuestStatus(pThis, pThisCC, pReqHdr);
2697 break;
2698
2699 case VMMDevReq_ReportGuestUserState:
2700 pReqHdr->rc = vmmdevReqHandler_ReportGuestUserState(pThisCC, pReqHdr);
2701 break;
2702
2703 case VMMDevReq_ReportGuestCapabilities:
2704 pReqHdr->rc = vmmdevReqHandler_ReportGuestCapabilities(pThis, pThisCC, pReqHdr);
2705 break;
2706
2707 case VMMDevReq_SetGuestCapabilities:
2708 pReqHdr->rc = vmmdevReqHandler_SetGuestCapabilities(pThis, pThisCC, pReqHdr);
2709 break;
2710
2711 case VMMDevReq_WriteCoreDump:
2712 pReqHdr->rc = vmmdevReqHandler_WriteCoreDump(pDevIns, pThis, pReqHdr);
2713 break;
2714
2715 case VMMDevReq_GetMouseStatus:
2716 pReqHdr->rc = vmmdevReqHandler_GetMouseStatus(pThis, pReqHdr);
2717 break;
2718
2719 case VMMDevReq_SetMouseStatus:
2720 pReqHdr->rc = vmmdevReqHandler_SetMouseStatus(pThis, pThisCC, pReqHdr);
2721 break;
2722
2723 case VMMDevReq_SetPointerShape:
2724 pReqHdr->rc = vmmdevReqHandler_SetPointerShape(pThis, pThisCC, pReqHdr);
2725 break;
2726
2727 case VMMDevReq_GetHostTime:
2728 pReqHdr->rc = vmmdevReqHandler_GetHostTime(pDevIns, pThis, pReqHdr);
2729 break;
2730
2731 case VMMDevReq_GetHypervisorInfo:
2732 pReqHdr->rc = vmmdevReqHandler_GetHypervisorInfo(pDevIns, pReqHdr);
2733 break;
2734
2735 case VMMDevReq_SetHypervisorInfo:
2736 pReqHdr->rc = vmmdevReqHandler_SetHypervisorInfo(pDevIns, pReqHdr);
2737 break;
2738
2739 case VMMDevReq_RegisterPatchMemory:
2740 pReqHdr->rc = vmmdevReqHandler_RegisterPatchMemory(pDevIns, pReqHdr);
2741 break;
2742
2743 case VMMDevReq_DeregisterPatchMemory:
2744 pReqHdr->rc = vmmdevReqHandler_DeregisterPatchMemory(pDevIns, pReqHdr);
2745 break;
2746
2747 case VMMDevReq_SetPowerStatus:
2748 {
2749 int rc = pReqHdr->rc = vmmdevReqHandler_SetPowerStatus(pDevIns, pThis, pReqHdr);
2750 if (rc != VINF_SUCCESS && RT_SUCCESS(rc))
2751 rcRet = rc;
2752 break;
2753 }
2754
2755 case VMMDevReq_GetDisplayChangeRequest:
2756 pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequest(pThis, pReqHdr);
2757 break;
2758
2759 case VMMDevReq_GetDisplayChangeRequest2:
2760 pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequest2(pDevIns, pThis, pThisCC, pReqHdr);
2761 break;
2762
2763 case VMMDevReq_GetDisplayChangeRequestEx:
2764 pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequestEx(pDevIns, pThis, pThisCC, pReqHdr);
2765 break;
2766
2767 case VMMDevReq_GetDisplayChangeRequestMulti:
2768 pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequestMulti(pThis, pReqHdr);
2769 break;
2770
2771 case VMMDevReq_VideoModeSupported:
2772 pReqHdr->rc = vmmdevReqHandler_VideoModeSupported(pThisCC, pReqHdr);
2773 break;
2774
2775 case VMMDevReq_VideoModeSupported2:
2776 pReqHdr->rc = vmmdevReqHandler_VideoModeSupported2(pThisCC, pReqHdr);
2777 break;
2778
2779 case VMMDevReq_GetHeightReduction:
2780 pReqHdr->rc = vmmdevReqHandler_GetHeightReduction(pThisCC, pReqHdr);
2781 break;
2782
2783 case VMMDevReq_AcknowledgeEvents:
2784 pReqHdr->rc = vmmdevReqHandler_AcknowledgeEvents(pDevIns, pThis, pThisCC, pReqHdr);
2785 break;
2786
2787 case VMMDevReq_CtlGuestFilterMask:
2788 pReqHdr->rc = vmmdevReqHandler_CtlGuestFilterMask(pDevIns, pThis, pThisCC, pReqHdr);
2789 break;
2790
2791#ifdef VBOX_WITH_HGCM
2792 case VMMDevReq_HGCMConnect:
2793 vmmdevReqHdrSetHgcmAsyncExecute(pDevIns, GCPhysReqHdr, *ppLock);
2794 pReqHdr->rc = vmmdevReqHandler_HGCMConnect(pDevIns, pThis, pThisCC, pReqHdr, GCPhysReqHdr);
2795 Assert(pReqHdr->rc == VINF_HGCM_ASYNC_EXECUTE || RT_FAILURE_NP(pReqHdr->rc));
2796 if (RT_SUCCESS(pReqHdr->rc))
2797 *pfPostOptimize |= VMMDEVREQDISP_POST_F_NO_WRITE_OUT;
2798 break;
2799
2800 case VMMDevReq_HGCMDisconnect:
2801 vmmdevReqHdrSetHgcmAsyncExecute(pDevIns, GCPhysReqHdr, *ppLock);
2802 pReqHdr->rc = vmmdevReqHandler_HGCMDisconnect(pDevIns, pThis, pThisCC, pReqHdr, GCPhysReqHdr);
2803 Assert(pReqHdr->rc == VINF_HGCM_ASYNC_EXECUTE || RT_FAILURE_NP(pReqHdr->rc));
2804 if (RT_SUCCESS(pReqHdr->rc))
2805 *pfPostOptimize |= VMMDEVREQDISP_POST_F_NO_WRITE_OUT;
2806 break;
2807
2808# ifdef VBOX_WITH_64_BITS_GUESTS
2809 case VMMDevReq_HGCMCall64:
2810# endif
2811 case VMMDevReq_HGCMCall32:
2812 vmmdevReqHdrSetHgcmAsyncExecute(pDevIns, GCPhysReqHdr, *ppLock);
2813 pReqHdr->rc = vmmdevReqHandler_HGCMCall(pDevIns, pThis, pThisCC, pReqHdr, GCPhysReqHdr, tsArrival, ppLock);
2814 Assert(pReqHdr->rc == VINF_HGCM_ASYNC_EXECUTE || RT_FAILURE_NP(pReqHdr->rc));
2815 if (RT_SUCCESS(pReqHdr->rc))
2816 *pfPostOptimize |= VMMDEVREQDISP_POST_F_NO_WRITE_OUT;
2817 break;
2818
2819 case VMMDevReq_HGCMCancel:
2820 pReqHdr->rc = vmmdevReqHandler_HGCMCancel(pThisCC, pReqHdr, GCPhysReqHdr);
2821 break;
2822
2823 case VMMDevReq_HGCMCancel2:
2824 pReqHdr->rc = vmmdevReqHandler_HGCMCancel2(pThisCC, pReqHdr);
2825 break;
2826#endif /* VBOX_WITH_HGCM */
2827
2828 case VMMDevReq_VideoAccelEnable:
2829 pReqHdr->rc = vmmdevReqHandler_VideoAccelEnable(pThis, pThisCC, pReqHdr);
2830 break;
2831
2832 case VMMDevReq_VideoAccelFlush:
2833 pReqHdr->rc = vmmdevReqHandler_VideoAccelFlush(pThisCC, pReqHdr);
2834 break;
2835
2836 case VMMDevReq_VideoSetVisibleRegion:
2837 pReqHdr->rc = vmmdevReqHandler_VideoSetVisibleRegion(pThisCC, pReqHdr);
2838 break;
2839
2840 case VMMDevReq_VideoUpdateMonitorPositions:
2841 pReqHdr->rc = vmmdevReqHandler_VideoUpdateMonitorPositions(pThisCC, pReqHdr);
2842 break;
2843
2844 case VMMDevReq_GetSeamlessChangeRequest:
2845 pReqHdr->rc = vmmdevReqHandler_GetSeamlessChangeRequest(pThis, pReqHdr);
2846 break;
2847
2848 case VMMDevReq_GetVRDPChangeRequest:
2849 pReqHdr->rc = vmmdevReqHandler_GetVRDPChangeRequest(pThis, pReqHdr);
2850 break;
2851
2852 case VMMDevReq_GetMemBalloonChangeRequest:
2853 pReqHdr->rc = vmmdevReqHandler_GetMemBalloonChangeRequest(pThis, pReqHdr);
2854 break;
2855
2856 case VMMDevReq_ChangeMemBalloon:
2857 pReqHdr->rc = vmmdevReqHandler_ChangeMemBalloon(pDevIns, pThis, pReqHdr);
2858 break;
2859
2860 case VMMDevReq_GetStatisticsChangeRequest:
2861 pReqHdr->rc = vmmdevReqHandler_GetStatisticsChangeRequest(pThis, pReqHdr);
2862 break;
2863
2864 case VMMDevReq_ReportGuestStats:
2865 pReqHdr->rc = vmmdevReqHandler_ReportGuestStats(pThisCC, pReqHdr);
2866 break;
2867
2868 case VMMDevReq_QueryCredentials:
2869 pReqHdr->rc = vmmdevReqHandler_QueryCredentials(pThis, pThisCC, pReqHdr);
2870 break;
2871
2872 case VMMDevReq_ReportCredentialsJudgement:
2873 pReqHdr->rc = vmmdevReqHandler_ReportCredentialsJudgement(pThisCC, pReqHdr);
2874 break;
2875
2876 case VMMDevReq_GetHostVersion:
2877 pReqHdr->rc = vmmdevReqHandler_GetHostVersion(pReqHdr);
2878 break;
2879
2880 case VMMDevReq_GetCpuHotPlugRequest:
2881 pReqHdr->rc = vmmdevReqHandler_GetCpuHotPlugRequest(pThis, pReqHdr);
2882 break;
2883
2884 case VMMDevReq_SetCpuHotPlugStatus:
2885 pReqHdr->rc = vmmdevReqHandler_SetCpuHotPlugStatus(pThis, pReqHdr);
2886 break;
2887
2888#ifdef VBOX_WITH_PAGE_SHARING
2889 case VMMDevReq_RegisterSharedModule:
2890 pReqHdr->rc = vmmdevReqHandler_RegisterSharedModule(pDevIns, pReqHdr);
2891 break;
2892
2893 case VMMDevReq_UnregisterSharedModule:
2894 pReqHdr->rc = vmmdevReqHandler_UnregisterSharedModule(pDevIns, pReqHdr);
2895 break;
2896
2897 case VMMDevReq_CheckSharedModules:
2898 pReqHdr->rc = vmmdevReqHandler_CheckSharedModules(pDevIns, pReqHdr);
2899 break;
2900
2901 case VMMDevReq_GetPageSharingStatus:
2902 pReqHdr->rc = vmmdevReqHandler_GetPageSharingStatus(pThisCC, pReqHdr);
2903 break;
2904
2905 case VMMDevReq_DebugIsPageShared:
2906 pReqHdr->rc = vmmdevReqHandler_DebugIsPageShared(pDevIns, pReqHdr);
2907 break;
2908
2909#endif /* VBOX_WITH_PAGE_SHARING */
2910
2911#ifdef DEBUG
2912 case VMMDevReq_LogString:
2913 pReqHdr->rc = vmmdevReqHandler_LogString(pReqHdr);
2914 break;
2915#endif
2916
2917 case VMMDevReq_GetSessionId:
2918 pReqHdr->rc = vmmdevReqHandler_GetSessionId(pThis, pReqHdr);
2919 break;
2920
2921 /*
2922 * Guest wants to give up a timeslice.
2923 * Note! This was only ever used by experimental GAs!
2924 */
2925 /** @todo maybe we could just remove this? */
2926 case VMMDevReq_Idle:
2927 {
2928 /* just return to EMT telling it that we want to halt */
2929 rcRet = VINF_EM_HALT;
2930 break;
2931 }
2932
2933 case VMMDevReq_GuestHeartbeat:
2934 pReqHdr->rc = vmmDevReqHandler_GuestHeartbeat(pDevIns, pThis);
2935 break;
2936
2937 case VMMDevReq_HeartbeatConfigure:
2938 pReqHdr->rc = vmmDevReqHandler_HeartbeatConfigure(pDevIns, pThis, pReqHdr);
2939 break;
2940
2941 case VMMDevReq_NtBugCheck:
2942 pReqHdr->rc = vmmDevReqHandler_NtBugCheck(pDevIns, pReqHdr);
2943 break;
2944
2945 default:
2946 {
2947 pReqHdr->rc = VERR_NOT_IMPLEMENTED;
2948 Log(("VMMDev unknown request type %d\n", pReqHdr->requestType));
2949 break;
2950 }
2951 }
2952 return rcRet;
2953}
2954
2955
2956/**
2957 * @callback_method_impl{FNIOMIOPORTNEWOUT,
2958 * Port I/O write andler for the generic request interface.}
2959 */
2960static DECLCALLBACK(VBOXSTRICTRC)
2961vmmdevRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
2962{
2963 uint64_t tsArrival;
2964 STAM_GET_TS(tsArrival);
2965
2966 RT_NOREF(offPort, cb, pvUser);
2967
2968 /*
2969 * The caller has passed the guest context physical address of the request
2970 * structure. We'll copy all of it into a heap buffer eventually, but we
2971 * will have to start off with the header.
2972 */
2973 VMMDevRequestHeader requestHeader;
2974 RT_ZERO(requestHeader);
2975 PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
2976
2977 /* The structure size must be greater or equal to the header size. */
2978 if (requestHeader.size < sizeof(VMMDevRequestHeader))
2979 {
2980 Log(("VMMDev request header size too small! size = %d\n", requestHeader.size));
2981 return VINF_SUCCESS;
2982 }
2983
2984 /* Check the version of the header structure. */
2985 if (requestHeader.version != VMMDEV_REQUEST_HEADER_VERSION)
2986 {
2987 Log(("VMMDev: guest header version (0x%08X) differs from ours (0x%08X)\n", requestHeader.version, VMMDEV_REQUEST_HEADER_VERSION));
2988 return VINF_SUCCESS;
2989 }
2990
2991 Log2(("VMMDev request issued: %d\n", requestHeader.requestType));
2992
2993 VBOXSTRICTRC rcRet = VINF_SUCCESS;
2994 /* Check that is doesn't exceed the max packet size. */
2995 if (requestHeader.size <= VMMDEV_MAX_VMMDEVREQ_SIZE)
2996 {
2997 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
2998 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
2999
3000 /*
3001 * We require the GAs to report it's information before we let it have
3002 * access to all the functions. The VMMDevReq_ReportGuestInfo request
3003 * is the one which unlocks the access. Newer additions will first
3004 * issue VMMDevReq_ReportGuestInfo2, older ones doesn't know this one.
3005 * Two exceptions: VMMDevReq_GetHostVersion and VMMDevReq_WriteCoreDump.
3006 */
3007 if ( pThis->fu32AdditionsOk
3008 || requestHeader.requestType == VMMDevReq_ReportGuestInfo2
3009 || requestHeader.requestType == VMMDevReq_ReportGuestInfo
3010 || requestHeader.requestType == VMMDevReq_WriteCoreDump
3011 || requestHeader.requestType == VMMDevReq_GetHostVersion
3012 )
3013 {
3014 /*
3015 * The request looks fine. Copy it into a buffer.
3016 *
3017 * The buffer is only used while on this thread, and this thread is one
3018 * of the EMTs, so we keep a 4KB buffer for each EMT around to avoid
3019 * wasting time with the heap. Larger allocations goes to the heap, though.
3020 */
3021 VMCPUID iCpu = PDMDevHlpGetCurrentCpuId(pDevIns);
3022 VMMDevRequestHeader *pRequestHeaderFree = NULL;
3023 VMMDevRequestHeader *pRequestHeader = NULL;
3024 if ( requestHeader.size <= _4K
3025 && iCpu < RT_ELEMENTS(pThisCC->apReqBufs))
3026 {
3027 pRequestHeader = pThisCC->apReqBufs[iCpu];
3028 if (pRequestHeader)
3029 { /* likely */ }
3030 else
3031 pThisCC->apReqBufs[iCpu] = pRequestHeader = (VMMDevRequestHeader *)RTMemPageAlloc(_4K);
3032 }
3033 else
3034 {
3035 Assert(iCpu != NIL_VMCPUID);
3036 STAM_REL_COUNTER_INC(&pThisCC->StatReqBufAllocs);
3037 pRequestHeaderFree = pRequestHeader = (VMMDevRequestHeader *)RTMemAlloc(RT_MAX(requestHeader.size, 512));
3038 }
3039 if (pRequestHeader)
3040 {
3041 memcpy(pRequestHeader, &requestHeader, sizeof(VMMDevRequestHeader));
3042
3043 /* Try lock the request if it's a HGCM call and not crossing a page boundrary.
3044 Saves on PGM interaction. */
3045 VMMDEVREQLOCK Lock = { NULL, { 0, NULL } };
3046 PVMMDEVREQLOCK pLock = NULL;
3047 size_t cbLeft = requestHeader.size - sizeof(VMMDevRequestHeader);
3048 if (cbLeft)
3049 {
3050 if ( ( requestHeader.requestType == VMMDevReq_HGCMCall32
3051 || requestHeader.requestType == VMMDevReq_HGCMCall64)
3052 && ((u32 + requestHeader.size) >> X86_PAGE_SHIFT) == (u32 >> X86_PAGE_SHIFT)
3053 && RT_SUCCESS(PDMDevHlpPhysGCPhys2CCPtr(pDevIns, u32, 0 /*fFlags*/, &Lock.pvReq, &Lock.Lock)) )
3054 {
3055 memcpy((uint8_t *)pRequestHeader + sizeof(VMMDevRequestHeader),
3056 (uint8_t *)Lock.pvReq + sizeof(VMMDevRequestHeader), cbLeft);
3057 pLock = &Lock;
3058 }
3059 else
3060 PDMDevHlpPhysRead(pDevIns,
3061 (RTGCPHYS)u32 + sizeof(VMMDevRequestHeader),
3062 (uint8_t *)pRequestHeader + sizeof(VMMDevRequestHeader),
3063 cbLeft);
3064 }
3065
3066 /*
3067 * Feed buffered request thru the dispatcher.
3068 */
3069 uint32_t fPostOptimize = 0;
3070 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3071 PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, &pThis->CritSect, rcLock);
3072
3073 rcRet = vmmdevReqDispatcher(pDevIns, pThis, pThisCC, pRequestHeader, u32, tsArrival, &fPostOptimize, &pLock);
3074
3075 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3076
3077 /*
3078 * Write the result back to guest memory (unless it is a locked HGCM call).
3079 */
3080 if (!(fPostOptimize & VMMDEVREQDISP_POST_F_NO_WRITE_OUT))
3081 {
3082 if (pLock)
3083 memcpy(pLock->pvReq, pRequestHeader, pRequestHeader->size);
3084 else
3085 PDMDevHlpPhysWrite(pDevIns, u32, pRequestHeader, pRequestHeader->size);
3086 }
3087
3088 if (!pRequestHeaderFree)
3089 { /* likely */ }
3090 else
3091 RTMemFreeZ(pRequestHeaderFree, RT_MAX(requestHeader.size, 512));
3092 return rcRet;
3093 }
3094
3095 Log(("VMMDev: RTMemAlloc failed!\n"));
3096 requestHeader.rc = VERR_NO_MEMORY;
3097 }
3098 else
3099 {
3100 LogRelMax(10, ("VMMDev: Guest has not yet reported to us -- refusing operation of request #%d\n",
3101 requestHeader.requestType));
3102 requestHeader.rc = VERR_NOT_SUPPORTED;
3103 }
3104 }
3105 else
3106 {
3107 LogRelMax(50, ("VMMDev: Request packet too big (%x), refusing operation\n", requestHeader.size));
3108 requestHeader.rc = VERR_NOT_SUPPORTED;
3109 }
3110
3111 /*
3112 * Write the result back to guest memory.
3113 */
3114 PDMDevHlpPhysWrite(pDevIns, u32, &requestHeader, sizeof(requestHeader));
3115
3116 return rcRet;
3117}
3118
3119#endif /* IN_RING3 */
3120
3121
3122/**
3123 * @callback_method_impl{FNIOMIOPORTOUT, Port I/O write handler for requests
3124 * that can be handled w/o going to ring-3.}
3125 */
3126static DECLCALLBACK(VBOXSTRICTRC)
3127vmmdevFastRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
3128{
3129#ifndef IN_RING3
3130# if 0 /* This functionality is offered through reading the port (vmmdevFastRequestIrqAck). Leaving it here for later. */
3131 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3132 RT_NOREF(pvUser, Port, cb);
3133
3134 /*
3135 * We only process a limited set of requests here, reflecting the rest down
3136 * to ring-3. So, try read the whole request into a stack buffer and check
3137 * if we can handle it.
3138 */
3139 union
3140 {
3141 VMMDevRequestHeader Hdr;
3142 VMMDevEvents Ack;
3143 } uReq;
3144 RT_ZERO(uReq);
3145
3146 VBOXSTRICTRC rcStrict;
3147 if (pThis->fu32AdditionsOk)
3148 {
3149 /* Read it into memory. */
3150 uint32_t cbToRead = sizeof(uReq); /* (Adjust to stay within a page if we support more than ack requests.) */
3151 rcStrict = PDMDevHlpPhysRead(pDevIns, u32, &uReq, cbToRead);
3152 if (rcStrict == VINF_SUCCESS)
3153 {
3154 /*
3155 * Validate the request and check that we want to handle it here.
3156 */
3157 if ( uReq.Hdr.size >= sizeof(uReq.Hdr)
3158 && uReq.Hdr.version == VMMDEV_REQUEST_HEADER_VERSION
3159 && ( uReq.Hdr.requestType == VMMDevReq_AcknowledgeEvents
3160 && uReq.Hdr.size == sizeof(uReq.Ack)
3161 && cbToRead == sizeof(uReq.Ack)
3162 && pThisCC->CTX_SUFF(pVMMDevRAM) != NULL)
3163 )
3164 {
3165 RT_UNTRUSTED_VALIDATED_FENCE();
3166
3167 /*
3168 * Try grab the critical section.
3169 */
3170 int rc2 = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VINF_IOM_R3_IOPORT_WRITE);
3171 if (rc2 == VINF_SUCCESS)
3172 {
3173 /*
3174 * Handle the request and write back the result to the guest.
3175 */
3176 uReq.Hdr.rc = vmmdevReqHandler_AcknowledgeEvents(pThis, &uReq.Hdr);
3177
3178 rcStrict = PDMDevHlpPhysWrite(pDevIns, u32, &uReq, uReq.Hdr.size);
3179 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3180 if (rcStrict == VINF_SUCCESS)
3181 { /* likely */ }
3182 else
3183 Log(("vmmdevFastRequestHandler: PDMDevHlpPhysWrite(%#RX32+rc,4) -> %Rrc (%RTbool)\n",
3184 u32, VBOXSTRICTRC_VAL(rcStrict), PGM_PHYS_RW_IS_SUCCESS(rcStrict) ));
3185 }
3186 else
3187 {
3188 Log(("vmmdevFastRequestHandler: PDMDevHlpPDMCritSectEnter -> %Rrc\n", rc2));
3189 rcStrict = rc2;
3190 }
3191 }
3192 else
3193 {
3194 Log(("vmmdevFastRequestHandler: size=%#x version=%#x requestType=%d (pVMMDevRAM=%p) -> R3\n",
3195 uReq.Hdr.size, uReq.Hdr.version, uReq.Hdr.requestType, pThisCC->CTX_SUFF(pVMMDevRAM) ));
3196 rcStrict = VINF_IOM_R3_IOPORT_WRITE;
3197 }
3198 }
3199 else
3200 Log(("vmmdevFastRequestHandler: PDMDevHlpPhysRead(%#RX32,%#RX32) -> %Rrc\n", u32, cbToRead, VBOXSTRICTRC_VAL(rcStrict)));
3201 }
3202 else
3203 {
3204 Log(("vmmdevFastRequestHandler: additions nok-okay\n"));
3205 rcStrict = VINF_IOM_R3_IOPORT_WRITE;
3206 }
3207
3208 return VBOXSTRICTRC_VAL(rcStrict);
3209# else
3210 RT_NOREF(pDevIns, pvUser, offPort, u32, cb);
3211 return VINF_IOM_R3_IOPORT_WRITE;
3212# endif
3213
3214#else /* IN_RING3 */
3215 return vmmdevRequestHandler(pDevIns, pvUser, offPort, u32, cb);
3216#endif /* IN_RING3 */
3217}
3218
3219
3220/**
3221 * @callback_method_impl{FNIOMIOPORTNEWIN,
3222 * Port I/O read handler for IRQ acknowledging and getting pending events (same
3223 * as VMMDevReq_AcknowledgeEvents - just faster).}
3224 */
3225static DECLCALLBACK(VBOXSTRICTRC)
3226vmmdevFastRequestIrqAck(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
3227{
3228 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3229 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
3230 Assert(PDMDEVINS_2_DATA(pDevIns, PVMMDEV) == pThis);
3231 RT_NOREF(pvUser, offPort);
3232
3233 /* Only 32-bit accesses. */
3234 ASSERT_GUEST_MSG_RETURN(cb == sizeof(uint32_t), ("cb=%d\n", cb), VERR_IOM_IOPORT_UNUSED);
3235
3236 /* The VMMDev memory mapping might've failed, go to ring-3 in that case. */
3237 VBOXSTRICTRC rcStrict;
3238#ifndef IN_RING3
3239 if (pThisCC->CTX_SUFF(pVMMDevRAM) != NULL)
3240#endif
3241 {
3242 /* Enter critical section and check that the additions has been properly
3243 initialized and that we're not in legacy v1.3 device mode. */
3244 rcStrict = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
3245 if (rcStrict == VINF_SUCCESS)
3246 {
3247 if ( pThis->fu32AdditionsOk
3248 && !VMMDEV_INTERFACE_VERSION_IS_1_03(pThis))
3249 {
3250 /*
3251 * Do the job.
3252 *
3253 * Note! This code is duplicated in vmmdevReqHandler_AcknowledgeEvents.
3254 */
3255 STAM_REL_COUNTER_INC(&pThis->CTX_SUFF_Z(StatFastIrqAck));
3256
3257 if (pThis->fNewGuestFilterMaskValid)
3258 {
3259 pThis->fNewGuestFilterMaskValid = false;
3260 pThis->fGuestFilterMask = pThis->fNewGuestFilterMask;
3261 }
3262
3263 *pu32 = pThis->fHostEventFlags & pThis->fGuestFilterMask;
3264
3265 pThis->fHostEventFlags &= ~pThis->fGuestFilterMask;
3266 pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_04.fHaveEvents = false;
3267
3268 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
3269 }
3270 else
3271 {
3272 Log(("vmmdevFastRequestIrqAck: fu32AdditionsOk=%d interfaceVersion=%#x\n", pThis->fu32AdditionsOk,
3273 pThis->guestInfo.interfaceVersion));
3274 *pu32 = UINT32_MAX;
3275 }
3276
3277 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3278 }
3279 }
3280#ifndef IN_RING3
3281 else
3282 rcStrict = VINF_IOM_R3_IOPORT_READ;
3283#endif
3284 return rcStrict;
3285}
3286
3287
3288
3289#ifdef IN_RING3
3290
3291/* -=-=-=-=-=- PCI Device -=-=-=-=-=- */
3292
3293/**
3294 * @callback_method_impl{FNPCIIOREGIONMAP,I/O Port Region}
3295 */
3296static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
3297 RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
3298{
3299 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3300 LogFlow(("vmmdevIOPortRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%RGp enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
3301 RT_NOREF(pPciDev, iRegion, cb, enmType);
3302
3303 Assert(pPciDev == pDevIns->apPciDevs[0]);
3304 Assert(enmType == PCI_ADDRESS_SPACE_IO);
3305 Assert(iRegion == 0);
3306
3307 int rc;
3308 if (GCPhysAddress != NIL_RTGCPHYS)
3309 {
3310 AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#RGp\n", GCPhysAddress));
3311
3312 rc = PDMDevHlpIoPortMap(pDevIns, pThis->hIoPortReq, (RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST);
3313 AssertLogRelRCReturn(rc, rc);
3314
3315 rc = PDMDevHlpIoPortMap(pDevIns, pThis->hIoPortFast, (RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST_FAST);
3316 AssertLogRelRCReturn(rc, rc);
3317 }
3318 else
3319 {
3320 rc = PDMDevHlpIoPortUnmap(pDevIns, pThis->hIoPortReq);
3321 AssertLogRelRCReturn(rc, rc);
3322
3323 rc = PDMDevHlpIoPortUnmap(pDevIns, pThis->hIoPortFast);
3324 AssertLogRelRCReturn(rc, rc);
3325 }
3326 return rc;
3327}
3328
3329
3330/**
3331 * @callback_method_impl{FNPCIIOREGIONMAP,VMMDev heap (MMIO2)}
3332 */
3333static DECLCALLBACK(int) vmmdevMmio2HeapRegionMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
3334 RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
3335{
3336 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
3337 LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%RGp enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
3338 RT_NOREF(cb, pPciDev);
3339
3340 Assert(pPciDev == pDevIns->apPciDevs[0]);
3341 AssertReturn(iRegion == 2, VERR_INTERNAL_ERROR_2);
3342 AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM_PREFETCH, VERR_INTERNAL_ERROR_3);
3343 Assert(pThisCC->pVMMDevHeapR3 != NULL);
3344
3345 int rc;
3346 if (GCPhysAddress != NIL_RTGCPHYS)
3347 {
3348 rc = PDMDevHlpRegisterVMMDevHeap(pDevIns, GCPhysAddress, pThisCC->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
3349 AssertRC(rc);
3350 }
3351 else
3352 {
3353 rc = PDMDevHlpRegisterVMMDevHeap(pDevIns, NIL_RTGCPHYS, pThisCC->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
3354 AssertRCStmt(rc, rc = VINF_SUCCESS);
3355 }
3356
3357 return rc;
3358}
3359
3360
3361/* -=-=-=-=-=- Backdoor Logging and Time Sync. -=-=-=-=-=- */
3362
3363/**
3364 * @callback_method_impl{FNIOMIOPORTNEWOUT, Backdoor Logging.}
3365 */
3366static DECLCALLBACK(VBOXSTRICTRC)
3367vmmdevBackdoorLog(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
3368{
3369 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3370 RT_NOREF(pvUser, offPort);
3371 Assert(offPort == 0);
3372
3373 if (!pThis->fBackdoorLogDisabled && cb == 1)
3374 {
3375
3376 /* The raw version. */
3377 switch (u32)
3378 {
3379 case '\r': LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <return>\n")); break;
3380 case '\n': LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <newline>\n")); break;
3381 case '\t': LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <tab>\n")); break;
3382 default: LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: %c (%02x)\n", u32, u32)); break;
3383 }
3384
3385 /* The readable, buffered version. */
3386 uint32_t offMsg = RT_MIN(pThis->offMsg, sizeof(pThis->szMsg) - 1);
3387 if (u32 == '\n' || u32 == '\r')
3388 {
3389 pThis->szMsg[offMsg] = '\0';
3390 if (offMsg)
3391 LogRelIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("VMMDev: Guest Log: %.*s\n", offMsg, pThis->szMsg));
3392 pThis->offMsg = 0;
3393 }
3394 else
3395 {
3396 if (offMsg >= sizeof(pThis->szMsg) - 1)
3397 {
3398 pThis->szMsg[sizeof(pThis->szMsg) - 1] = '\0';
3399 LogRelIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR,
3400 ("VMMDev: Guest Log: %.*s\n", sizeof(pThis->szMsg) - 1, pThis->szMsg));
3401 offMsg = 0;
3402 }
3403 pThis->szMsg[offMsg++] = (char )u32;
3404 pThis->szMsg[offMsg] = '\0';
3405 pThis->offMsg = offMsg;
3406 }
3407 }
3408 return VINF_SUCCESS;
3409}
3410
3411#ifdef VMMDEV_WITH_ALT_TIMESYNC
3412
3413/**
3414 * @callback_method_impl{FNIOMIOPORTNEWOUT, Alternative time synchronization.}
3415 */
3416static DECLCALLBACK(VBOXSTRICTRC)
3417vmmdevAltTimeSyncWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
3418{
3419 RT_NOREF(pvUser, offPort);
3420 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3421 if (cb == 4)
3422 {
3423 /* Selects high (0) or low (1) DWORD. The high has to be read first. */
3424 switch (u32)
3425 {
3426 case 0:
3427 pThis->fTimesyncBackdoorLo = false;
3428 break;
3429 case 1:
3430 pThis->fTimesyncBackdoorLo = true;
3431 break;
3432 default:
3433 Log(("vmmdevAltTimeSyncWrite: Invalid access cb=%#x u32=%#x\n", cb, u32));
3434 break;
3435 }
3436 }
3437 else
3438 Log(("vmmdevAltTimeSyncWrite: Invalid access cb=%#x u32=%#x\n", cb, u32));
3439 return VINF_SUCCESS;
3440}
3441
3442/**
3443 * @callback_method_impl{FNIOMIOPORTOUT, Alternative time synchronization.}
3444 */
3445static DECLCALLBACK(VBOXSTRICTRC)
3446vmmdevAltTimeSyncRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
3447{
3448 RT_NOREF(pvUser, offPort);
3449 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3450 VBOXSTRICTRC rc;
3451 if (cb == 4)
3452 {
3453 if (pThis->fTimesyncBackdoorLo)
3454 *pu32 = (uint32_t)pThis->msLatchedHostTime;
3455 else
3456 {
3457 /* Reading the high dword gets and saves the current time. */
3458 RTTIMESPEC Now;
3459 pThis->msLatchedHostTime = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &Now));
3460 *pu32 = (uint32_t)(pThis->msLatchedHostTime >> 32);
3461 }
3462 rc = VINF_SUCCESS;
3463 }
3464 else
3465 {
3466 Log(("vmmdevAltTimeSyncRead: Invalid access cb=%#x\n", cb));
3467 rc = VERR_IOM_IOPORT_UNUSED;
3468 }
3469 return rc;
3470}
3471
3472#endif /* VMMDEV_WITH_ALT_TIMESYNC */
3473
3474
3475/* -=-=-=-=-=- IBase -=-=-=-=-=- */
3476
3477/**
3478 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
3479 */
3480static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, const char *pszIID)
3481{
3482 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IBase);
3483
3484 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThisCC->IBase);
3485 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVPORT, &pThisCC->IPort);
3486#ifdef VBOX_WITH_HGCM
3487 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMPORT, &pThisCC->IHGCMPort);
3488#endif
3489 /* Currently only for shared folders. */
3490 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThisCC->SharedFolders.ILeds);
3491 return NULL;
3492}
3493
3494
3495/* -=-=-=-=-=- ILeds -=-=-=-=-=- */
3496
3497/**
3498 * Gets the pointer to the status LED of a unit.
3499 *
3500 * @returns VBox status code.
3501 * @param pInterface Pointer to the interface structure containing the called function pointer.
3502 * @param iLUN The unit which status LED we desire.
3503 * @param ppLed Where to store the LED pointer.
3504 */
3505static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
3506{
3507 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, SharedFolders.ILeds);
3508 if (iLUN == 0) /* LUN 0 is shared folders */
3509 {
3510 *ppLed = &pThisCC->SharedFolders.Led;
3511 return VINF_SUCCESS;
3512 }
3513 return VERR_PDM_LUN_NOT_FOUND;
3514}
3515
3516
3517/* -=-=-=-=-=- PDMIVMMDEVPORT (VMMDEV::IPort) -=-=-=-=-=- */
3518
3519/**
3520 * @interface_method_impl{PDMIVMMDEVPORT,pfnQueryAbsoluteMouse}
3521 */
3522static DECLCALLBACK(int) vmmdevIPort_QueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t *pxAbs, int32_t *pyAbs)
3523{
3524 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3525 PVMMDEV pThis = PDMDEVINS_2_DATA(pThisCC->pDevIns, PVMMDEV);
3526
3527 /** @todo at the first sign of trouble in this area, just enter the critsect.
3528 * As indicated by the comment below, the atomic reads serves no real purpose
3529 * here since we can assume cache coherency protocoles and int32_t alignment
3530 * rules making sure we won't see a halfwritten value. */
3531 if (pxAbs)
3532 *pxAbs = ASMAtomicReadS32(&pThis->xMouseAbs); /* why the atomic read? */
3533 if (pyAbs)
3534 *pyAbs = ASMAtomicReadS32(&pThis->yMouseAbs);
3535
3536 return VINF_SUCCESS;
3537}
3538
3539/**
3540 * @interface_method_impl{PDMIVMMDEVPORT,pfnSetAbsoluteMouse}
3541 */
3542static DECLCALLBACK(int) vmmdevIPort_SetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t xAbs, int32_t yAbs)
3543{
3544 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3545 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3546 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3547 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3548 AssertRCReturn(rcLock, rcLock);
3549
3550 if ( pThis->xMouseAbs != xAbs
3551 || pThis->yMouseAbs != yAbs)
3552 {
3553 Log2(("vmmdevIPort_SetAbsoluteMouse : settings absolute position to x = %d, y = %d\n", xAbs, yAbs));
3554 pThis->xMouseAbs = xAbs;
3555 pThis->yMouseAbs = yAbs;
3556 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
3557 }
3558
3559 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3560 return VINF_SUCCESS;
3561}
3562
3563/**
3564 * @interface_method_impl{PDMIVMMDEVPORT,pfnQueryMouseCapabilities}
3565 */
3566static DECLCALLBACK(int) vmmdevIPort_QueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pfCapabilities)
3567{
3568 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3569 PVMMDEV pThis = PDMDEVINS_2_DATA(pThisCC->pDevIns, PVMMDEV);
3570 AssertPtrReturn(pfCapabilities, VERR_INVALID_PARAMETER);
3571
3572 *pfCapabilities = pThis->fMouseCapabilities;
3573 return VINF_SUCCESS;
3574}
3575
3576/**
3577 * @interface_method_impl{PDMIVMMDEVPORT,pfnUpdateMouseCapabilities}
3578 */
3579static DECLCALLBACK(int)
3580vmmdevIPort_UpdateMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t fCapsAdded, uint32_t fCapsRemoved)
3581{
3582 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3583 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3584 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3585 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3586 AssertRCReturn(rcLock, rcLock);
3587
3588 uint32_t fOldCaps = pThis->fMouseCapabilities;
3589 pThis->fMouseCapabilities &= ~(fCapsRemoved & VMMDEV_MOUSE_HOST_MASK);
3590 pThis->fMouseCapabilities |= (fCapsAdded & VMMDEV_MOUSE_HOST_MASK)
3591 | VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
3592 bool fNotify = fOldCaps != pThis->fMouseCapabilities;
3593
3594 LogRelFlow(("VMMDev: vmmdevIPort_UpdateMouseCapabilities: fCapsAdded=0x%x, fCapsRemoved=0x%x, fNotify=%RTbool\n", fCapsAdded,
3595 fCapsRemoved, fNotify));
3596
3597 if (fNotify)
3598 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
3599
3600 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3601 return VINF_SUCCESS;
3602}
3603
3604static bool vmmdevIsMonitorDefEqual(VMMDevDisplayDef const *pNew, VMMDevDisplayDef const *pOld)
3605{
3606 bool fEqual = pNew->idDisplay == pOld->idDisplay;
3607
3608 fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN) /* No change. */
3609 || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN) /* Old value exists and */
3610 && pNew->xOrigin == pOld->xOrigin /* the old is equal to the new. */
3611 && pNew->yOrigin == pOld->yOrigin));
3612
3613 fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_CX)
3614 || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_CX)
3615 && pNew->cx == pOld->cx));
3616
3617 fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_CY)
3618 || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_CY)
3619 && pNew->cy == pOld->cy));
3620
3621 fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_BPP)
3622 || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_BPP)
3623 && pNew->cBitsPerPixel == pOld->cBitsPerPixel));
3624
3625 fEqual = fEqual && ( RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_DISABLED)
3626 == RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_DISABLED));
3627
3628 fEqual = fEqual && ( RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_PRIMARY)
3629 == RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_PRIMARY));
3630
3631 return fEqual;
3632}
3633
3634/**
3635 * @interface_method_impl{PDMIVMMDEVPORT,pfnRequestDisplayChange}
3636 */
3637static DECLCALLBACK(int)
3638vmmdevIPort_RequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t cDisplays, VMMDevDisplayDef const *paDisplays, bool fForce, bool fMayNotify)
3639{
3640 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3641 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3642 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3643 int rc = VINF_SUCCESS;
3644 bool fNotifyGuest = false;
3645 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3646 AssertRCReturn(rcLock, rcLock);
3647
3648 uint32_t i;
3649 for (i = 0; i < cDisplays; ++i)
3650 {
3651 VMMDevDisplayDef const *p = &paDisplays[i];
3652
3653 /* Either one display definition is provided or the display id must be equal to the array index. */
3654 AssertBreakStmt(cDisplays == 1 || p->idDisplay == i, rc = VERR_INVALID_PARAMETER);
3655 AssertBreakStmt(p->idDisplay < RT_ELEMENTS(pThis->displayChangeData.aRequests), rc = VERR_INVALID_PARAMETER);
3656
3657 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[p->idDisplay];
3658
3659 VMMDevDisplayDef const *pLastRead = &pRequest->lastReadDisplayChangeRequest;
3660
3661 /* Verify that the new resolution is different and that guest does not yet know about it. */
3662 bool const fDifferentResolution = fForce || !vmmdevIsMonitorDefEqual(p, pLastRead);
3663
3664 LogFunc(("same=%d. New: %dx%d, cBits=%d, id=%d. Old: %dx%d, cBits=%d, id=%d. @%d,%d, Enabled=%d, ChangeOrigin=%d\n",
3665 !fDifferentResolution, p->cx, p->cy, p->cBitsPerPixel, p->idDisplay,
3666 pLastRead->cx, pLastRead->cy, pLastRead->cBitsPerPixel, pLastRead->idDisplay,
3667 p->xOrigin, p->yOrigin,
3668 !RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_DISABLED),
3669 RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN)));
3670
3671 /* We could validate the information here but hey, the guest can do that as well! */
3672 pRequest->displayChangeRequest = *p;
3673 pRequest->fPending = fDifferentResolution && fMayNotify;
3674
3675 fNotifyGuest = fNotifyGuest || fDifferentResolution;
3676 }
3677
3678 if (RT_SUCCESS(rc) && fMayNotify)
3679 {
3680 if (fNotifyGuest)
3681 {
3682 for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); ++i)
3683 {
3684 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
3685 if (pRequest->fPending)
3686 {
3687 VMMDevDisplayDef const *p = &pRequest->displayChangeRequest;
3688 LogRel(("VMMDev: SetVideoModeHint: Got a video mode hint (%dx%dx%d)@(%dx%d),(%d;%d) at %d\n",
3689 p->cx, p->cy, p->cBitsPerPixel, p->xOrigin, p->yOrigin,
3690 !RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_DISABLED),
3691 RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN), i));
3692 }
3693 }
3694
3695 /* IRQ so the guest knows what's going on */
3696 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
3697 }
3698 }
3699
3700 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3701 return rc;
3702}
3703
3704/**
3705 * @interface_method_impl{PDMIVMMDEVPORT,pfnRequestSeamlessChange}
3706 */
3707static DECLCALLBACK(int) vmmdevIPort_RequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
3708{
3709 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3710 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3711 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3712 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3713 AssertRCReturn(rcLock, rcLock);
3714
3715 /* Verify that the new resolution is different and that guest does not yet know about it. */
3716 bool fSameMode = (pThis->fLastSeamlessEnabled == fEnabled);
3717
3718 Log(("vmmdevIPort_RequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
3719
3720 if (!fSameMode)
3721 {
3722 /* we could validate the information here but hey, the guest can do that as well! */
3723 pThis->fSeamlessEnabled = fEnabled;
3724
3725 /* IRQ so the guest knows what's going on */
3726 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
3727 }
3728
3729 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3730 return VINF_SUCCESS;
3731}
3732
3733/**
3734 * @interface_method_impl{PDMIVMMDEVPORT,pfnSetMemoryBalloon}
3735 */
3736static DECLCALLBACK(int) vmmdevIPort_SetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t cMbBalloon)
3737{
3738 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3739 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3740 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3741 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3742 AssertRCReturn(rcLock, rcLock);
3743
3744 /* Verify that the new resolution is different and that guest does not yet know about it. */
3745 Log(("vmmdevIPort_SetMemoryBalloon: old=%u new=%u\n", pThis->cMbMemoryBalloonLast, cMbBalloon));
3746 if (pThis->cMbMemoryBalloonLast != cMbBalloon)
3747 {
3748 /* we could validate the information here but hey, the guest can do that as well! */
3749 pThis->cMbMemoryBalloon = cMbBalloon;
3750
3751 /* IRQ so the guest knows what's going on */
3752 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
3753 }
3754
3755 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3756 return VINF_SUCCESS;
3757}
3758
3759/**
3760 * @interface_method_impl{PDMIVMMDEVPORT,pfnVRDPChange}
3761 */
3762static DECLCALLBACK(int) vmmdevIPort_VRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t uVRDPExperienceLevel)
3763{
3764 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3765 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3766 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3767 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3768 AssertRCReturn(rcLock, rcLock);
3769
3770 bool fSame = (pThis->fVRDPEnabled == fVRDPEnabled);
3771
3772 Log(("vmmdevIPort_VRDPChange: old=%d. new=%d\n", pThis->fVRDPEnabled, fVRDPEnabled));
3773
3774 if (!fSame)
3775 {
3776 pThis->fVRDPEnabled = fVRDPEnabled;
3777 pThis->uVRDPExperienceLevel = uVRDPExperienceLevel;
3778
3779 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_VRDP);
3780 }
3781
3782 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3783 return VINF_SUCCESS;
3784}
3785
3786/**
3787 * @interface_method_impl{PDMIVMMDEVPORT,pfnSetStatisticsInterval}
3788 */
3789static DECLCALLBACK(int) vmmdevIPort_SetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t cSecsStatInterval)
3790{
3791 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3792 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3793 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3794 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3795 AssertRCReturn(rcLock, rcLock);
3796
3797 /* Verify that the new resolution is different and that guest does not yet know about it. */
3798 bool fSame = (pThis->cSecsLastStatInterval == cSecsStatInterval);
3799
3800 Log(("vmmdevIPort_SetStatisticsInterval: old=%d. new=%d\n", pThis->cSecsLastStatInterval, cSecsStatInterval));
3801
3802 if (!fSame)
3803 {
3804 /* we could validate the information here but hey, the guest can do that as well! */
3805 pThis->cSecsStatInterval = cSecsStatInterval;
3806
3807 /* IRQ so the guest knows what's going on */
3808 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
3809 }
3810
3811 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3812 return VINF_SUCCESS;
3813}
3814
3815/**
3816 * @interface_method_impl{PDMIVMMDEVPORT,pfnSetCredentials}
3817 */
3818static DECLCALLBACK(int) vmmdevIPort_SetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
3819 const char *pszPassword, const char *pszDomain, uint32_t fFlags)
3820{
3821 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3822 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3823 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3824
3825 AssertReturn(fFlags & (VMMDEV_SETCREDENTIALS_GUESTLOGON | VMMDEV_SETCREDENTIALS_JUDGE), VERR_INVALID_PARAMETER);
3826 size_t const cchUsername = strlen(pszUsername);
3827 AssertReturn(cchUsername < VMMDEV_CREDENTIALS_SZ_SIZE, VERR_BUFFER_OVERFLOW);
3828 size_t const cchPassword = strlen(pszPassword);
3829 AssertReturn(cchPassword < VMMDEV_CREDENTIALS_SZ_SIZE, VERR_BUFFER_OVERFLOW);
3830 size_t const cchDomain = strlen(pszDomain);
3831 AssertReturn(cchDomain < VMMDEV_CREDENTIALS_SZ_SIZE, VERR_BUFFER_OVERFLOW);
3832
3833 VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
3834 AssertPtrReturn(pCredentials, VERR_NOT_SUPPORTED);
3835
3836 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3837 AssertRCReturn(rcLock, rcLock);
3838
3839 /*
3840 * Logon mode
3841 */
3842 if (fFlags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
3843 {
3844 /* memorize the data */
3845 memcpy(pCredentials->Logon.szUserName, pszUsername, cchUsername);
3846 pThisCC->pCredentials->Logon.szUserName[cchUsername] = '\0';
3847 memcpy(pCredentials->Logon.szPassword, pszPassword, cchPassword);
3848 pCredentials->Logon.szPassword[cchPassword] = '\0';
3849 memcpy(pCredentials->Logon.szDomain, pszDomain, cchDomain);
3850 pCredentials->Logon.szDomain[cchDomain] = '\0';
3851 pCredentials->Logon.fAllowInteractiveLogon = !(fFlags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
3852 }
3853 /*
3854 * Credentials verification mode?
3855 */
3856 else
3857 {
3858 /* memorize the data */
3859 memcpy(pCredentials->Judge.szUserName, pszUsername, cchUsername);
3860 pCredentials->Judge.szUserName[cchUsername] = '\0';
3861 memcpy(pCredentials->Judge.szPassword, pszPassword, cchPassword);
3862 pCredentials->Judge.szPassword[cchPassword] = '\0';
3863 memcpy(pCredentials->Judge.szDomain, pszDomain, cchDomain);
3864 pCredentials->Judge.szDomain[cchDomain] = '\0';
3865
3866 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_JUDGE_CREDENTIALS);
3867 }
3868
3869 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3870 return VINF_SUCCESS;
3871}
3872
3873/**
3874 * @interface_method_impl{PDMIVMMDEVPORT,pfnVBVAChange}
3875 *
3876 * Notification from the Display. Especially useful when acceleration is
3877 * disabled after a video mode change.
3878 */
3879static DECLCALLBACK(void) vmmdevIPort_VBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
3880{
3881 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3882 PVMMDEV pThis = PDMDEVINS_2_DATA(pThisCC->pDevIns, PVMMDEV);
3883 Log(("vmmdevIPort_VBVAChange: fEnabled = %d\n", fEnabled));
3884
3885 /* Only used by saved state, which I guess is why we don't bother with locking here. */
3886 pThis->u32VideoAccelEnabled = fEnabled;
3887}
3888
3889/**
3890 * @interface_method_impl{PDMIVMMDEVPORT,pfnCpuHotUnplug}
3891 */
3892static DECLCALLBACK(int) vmmdevIPort_CpuHotUnplug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
3893{
3894 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3895 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3896 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3897
3898 Log(("vmmdevIPort_CpuHotUnplug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
3899
3900 int rc = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3901 AssertRCReturn(rc, rc);
3902
3903 if (pThis->fCpuHotPlugEventsEnabled)
3904 {
3905 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Unplug;
3906 pThis->idCpuCore = idCpuCore;
3907 pThis->idCpuPackage = idCpuPackage;
3908 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_CPU_HOTPLUG);
3909 }
3910 else
3911 rc = VERR_VMMDEV_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
3912
3913 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3914 return rc;
3915}
3916
3917/**
3918 * @interface_method_impl{PDMIVMMDEVPORT,pfnCpuHotPlug}
3919 */
3920static DECLCALLBACK(int) vmmdevIPort_CpuHotPlug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
3921{
3922 PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
3923 PPDMDEVINS pDevIns = pThisCC->pDevIns;
3924 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3925
3926 Log(("vmmdevCpuPlug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
3927
3928 int rc = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3929 AssertRCReturn(rc, rc);
3930
3931 if (pThis->fCpuHotPlugEventsEnabled)
3932 {
3933 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Plug;
3934 pThis->idCpuCore = idCpuCore;
3935 pThis->idCpuPackage = idCpuPackage;
3936 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_CPU_HOTPLUG);
3937 }
3938 else
3939 rc = VERR_VMMDEV_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
3940
3941 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
3942 return rc;
3943}
3944
3945
3946/* -=-=-=-=-=- Saved State -=-=-=-=-=- */
3947
3948/**
3949 * @callback_method_impl{FNSSMDEVLIVEEXEC}
3950 */
3951static DECLCALLBACK(int) vmmdevLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
3952{
3953 RT_NOREF(uPass);
3954 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3955 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
3956
3957 pHlp->pfnSSMPutBool(pSSM, pThis->fGetHostTimeDisabled);
3958 pHlp->pfnSSMPutBool(pSSM, pThis->fBackdoorLogDisabled);
3959 pHlp->pfnSSMPutBool(pSSM, pThis->fKeepCredentials);
3960 pHlp->pfnSSMPutBool(pSSM, pThis->fHeapEnabled);
3961
3962 return VINF_SSM_DONT_CALL_AGAIN;
3963}
3964
3965
3966/**
3967 * @callback_method_impl{FNSSMDEVSAVEEXEC}
3968 */
3969static DECLCALLBACK(int) vmmdevSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
3970{
3971 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
3972 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
3973 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
3974 int rc = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
3975 AssertRCReturn(rc, rc);
3976
3977 vmmdevLiveExec(pDevIns, pSSM, SSM_PASS_FINAL);
3978
3979 pHlp->pfnSSMPutU32(pSSM, 0 /*was pThis->hypervisorSize, which was always zero*/);
3980 pHlp->pfnSSMPutU32(pSSM, pThis->fMouseCapabilities);
3981 pHlp->pfnSSMPutS32(pSSM, pThis->xMouseAbs);
3982 pHlp->pfnSSMPutS32(pSSM, pThis->yMouseAbs);
3983
3984 pHlp->pfnSSMPutBool(pSSM, pThis->fNewGuestFilterMaskValid);
3985 pHlp->pfnSSMPutU32(pSSM, pThis->fNewGuestFilterMask);
3986 pHlp->pfnSSMPutU32(pSSM, pThis->fGuestFilterMask);
3987 pHlp->pfnSSMPutU32(pSSM, pThis->fHostEventFlags);
3988 /* The following is not strictly necessary as PGM restores MMIO2, keeping it for historical reasons. */
3989 pHlp->pfnSSMPutMem(pSSM, &pThisCC->pVMMDevRAMR3->V, sizeof(pThisCC->pVMMDevRAMR3->V));
3990
3991 pHlp->pfnSSMPutMem(pSSM, &pThis->guestInfo, sizeof(pThis->guestInfo));
3992 pHlp->pfnSSMPutU32(pSSM, pThis->fu32AdditionsOk);
3993 pHlp->pfnSSMPutU32(pSSM, pThis->u32VideoAccelEnabled);
3994 pHlp->pfnSSMPutBool(pSSM, pThis->displayChangeData.fGuestSentChangeEventAck);
3995
3996 pHlp->pfnSSMPutU32(pSSM, pThis->fGuestCaps);
3997
3998#ifdef VBOX_WITH_HGCM
3999 vmmdevR3HgcmSaveState(pThisCC, pSSM);
4000#endif /* VBOX_WITH_HGCM */
4001
4002 pHlp->pfnSSMPutU32(pSSM, pThis->fHostCursorRequested);
4003
4004 pHlp->pfnSSMPutU32(pSSM, pThis->guestInfo2.uFullVersion);
4005 pHlp->pfnSSMPutU32(pSSM, pThis->guestInfo2.uRevision);
4006 pHlp->pfnSSMPutU32(pSSM, pThis->guestInfo2.fFeatures);
4007 pHlp->pfnSSMPutStrZ(pSSM, pThis->guestInfo2.szName);
4008 pHlp->pfnSSMPutU32(pSSM, pThis->cFacilityStatuses);
4009 for (uint32_t i = 0; i < pThis->cFacilityStatuses; i++)
4010 {
4011 pHlp->pfnSSMPutU32(pSSM, pThis->aFacilityStatuses[i].enmFacility);
4012 pHlp->pfnSSMPutU32(pSSM, pThis->aFacilityStatuses[i].fFlags);
4013 pHlp->pfnSSMPutU16(pSSM, (uint16_t)pThis->aFacilityStatuses[i].enmStatus);
4014 pHlp->pfnSSMPutS64(pSSM, RTTimeSpecGetNano(&pThis->aFacilityStatuses[i].TimeSpecTS));
4015 }
4016
4017 /* Heartbeat: */
4018 pHlp->pfnSSMPutBool(pSSM, pThis->fHeartbeatActive);
4019 pHlp->pfnSSMPutBool(pSSM, pThis->fFlatlined);
4020 pHlp->pfnSSMPutU64(pSSM, pThis->nsLastHeartbeatTS);
4021 PDMDevHlpTimerSave(pDevIns, pThis->hFlatlinedTimer, pSSM);
4022
4023 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
4024 return VINF_SUCCESS;
4025}
4026
4027/**
4028 * @callback_method_impl{FNSSMDEVLOADEXEC}
4029 */
4030static DECLCALLBACK(int) vmmdevLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
4031{
4032 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
4033 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
4034 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
4035 int rc;
4036
4037 if ( uVersion > VMMDEV_SAVED_STATE_VERSION
4038 || uVersion < 6)
4039 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
4040
4041 /* config */
4042 if (uVersion > VMMDEV_SAVED_STATE_VERSION_VBOX_30)
4043 {
4044 bool f;
4045 rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
4046 if (pThis->fGetHostTimeDisabled != f)
4047 LogRel(("VMMDev: Config mismatch - fGetHostTimeDisabled: config=%RTbool saved=%RTbool\n", pThis->fGetHostTimeDisabled, f));
4048
4049 rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
4050 if (pThis->fBackdoorLogDisabled != f)
4051 LogRel(("VMMDev: Config mismatch - fBackdoorLogDisabled: config=%RTbool saved=%RTbool\n", pThis->fBackdoorLogDisabled, f));
4052
4053 rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
4054 if (pThis->fKeepCredentials != f)
4055 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fKeepCredentials: config=%RTbool saved=%RTbool"),
4056 pThis->fKeepCredentials, f);
4057 rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
4058 if (pThis->fHeapEnabled != f)
4059 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fHeapEnabled: config=%RTbool saved=%RTbool"),
4060 pThis->fHeapEnabled, f);
4061 }
4062
4063 if (uPass != SSM_PASS_FINAL)
4064 return VINF_SUCCESS;
4065
4066 /* state */
4067 uint32_t uIgn;
4068 pHlp->pfnSSMGetU32(pSSM, &uIgn);
4069 pHlp->pfnSSMGetU32(pSSM, &pThis->fMouseCapabilities);
4070 pHlp->pfnSSMGetS32(pSSM, &pThis->xMouseAbs);
4071 pHlp->pfnSSMGetS32(pSSM, &pThis->yMouseAbs);
4072
4073 pHlp->pfnSSMGetBool(pSSM, &pThis->fNewGuestFilterMaskValid);
4074 pHlp->pfnSSMGetU32(pSSM, &pThis->fNewGuestFilterMask);
4075 pHlp->pfnSSMGetU32(pSSM, &pThis->fGuestFilterMask);
4076 pHlp->pfnSSMGetU32(pSSM, &pThis->fHostEventFlags);
4077
4078 //pHlp->pfnSSMGetBool(pSSM, &pThis->pVMMDevRAMR3->fHaveEvents);
4079 // here be dragons (probably)
4080 pHlp->pfnSSMGetMem(pSSM, &pThisCC->pVMMDevRAMR3->V, sizeof(pThisCC->pVMMDevRAMR3->V));
4081
4082 pHlp->pfnSSMGetMem(pSSM, &pThis->guestInfo, sizeof(pThis->guestInfo));
4083 pHlp->pfnSSMGetU32(pSSM, &pThis->fu32AdditionsOk);
4084 pHlp->pfnSSMGetU32(pSSM, &pThis->u32VideoAccelEnabled);
4085 if (uVersion > 10)
4086 pHlp->pfnSSMGetBool(pSSM, &pThis->displayChangeData.fGuestSentChangeEventAck);
4087
4088 rc = pHlp->pfnSSMGetU32(pSSM, &pThis->fGuestCaps);
4089
4090 /* Attributes which were temporarily introduced in r30072 */
4091 if (uVersion == 7)
4092 {
4093 uint32_t temp;
4094 pHlp->pfnSSMGetU32(pSSM, &temp);
4095 rc = pHlp->pfnSSMGetU32(pSSM, &temp);
4096 }
4097 AssertRCReturn(rc, rc);
4098
4099#ifdef VBOX_WITH_HGCM
4100 rc = vmmdevR3HgcmLoadState(pDevIns, pThis, pThisCC, pSSM, uVersion);
4101 AssertRCReturn(rc, rc);
4102#endif /* VBOX_WITH_HGCM */
4103
4104 if (uVersion >= 10)
4105 rc = pHlp->pfnSSMGetU32(pSSM, &pThis->fHostCursorRequested);
4106 AssertRCReturn(rc, rc);
4107
4108 if (uVersion > VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2)
4109 {
4110 pHlp->pfnSSMGetU32(pSSM, &pThis->guestInfo2.uFullVersion);
4111 pHlp->pfnSSMGetU32(pSSM, &pThis->guestInfo2.uRevision);
4112 pHlp->pfnSSMGetU32(pSSM, &pThis->guestInfo2.fFeatures);
4113 rc = pHlp->pfnSSMGetStrZ(pSSM, &pThis->guestInfo2.szName[0], sizeof(pThis->guestInfo2.szName));
4114 AssertRCReturn(rc, rc);
4115 }
4116
4117 if (uVersion > VMMDEV_SAVED_STATE_VERSION_MISSING_FACILITY_STATUSES)
4118 {
4119 uint32_t cFacilityStatuses;
4120 rc = pHlp->pfnSSMGetU32(pSSM, &cFacilityStatuses);
4121 AssertRCReturn(rc, rc);
4122
4123 for (uint32_t i = 0; i < cFacilityStatuses; i++)
4124 {
4125 uint32_t uFacility, fFlags;
4126 uint16_t uStatus;
4127 int64_t iTimeStampNano;
4128
4129 pHlp->pfnSSMGetU32(pSSM, &uFacility);
4130 pHlp->pfnSSMGetU32(pSSM, &fFlags);
4131 pHlp->pfnSSMGetU16(pSSM, &uStatus);
4132 rc = pHlp->pfnSSMGetS64(pSSM, &iTimeStampNano);
4133 AssertRCReturn(rc, rc);
4134
4135 PVMMDEVFACILITYSTATUSENTRY pEntry = vmmdevGetFacilityStatusEntry(pThis, (VBoxGuestFacilityType)uFacility);
4136 AssertLogRelMsgReturn(pEntry,
4137 ("VMMDev: Ran out of entries restoring the guest facility statuses. Saved state has %u.\n", cFacilityStatuses),
4138 VERR_OUT_OF_RESOURCES);
4139 pEntry->enmStatus = (VBoxGuestFacilityStatus)uStatus;
4140 pEntry->fFlags = fFlags;
4141 RTTimeSpecSetNano(&pEntry->TimeSpecTS, iTimeStampNano);
4142 }
4143 }
4144
4145 /*
4146 * Heartbeat.
4147 */
4148 if (uVersion >= VMMDEV_SAVED_STATE_VERSION_HEARTBEAT)
4149 {
4150 pHlp->pfnSSMGetBoolV(pSSM, &pThis->fHeartbeatActive);
4151 pHlp->pfnSSMGetBoolV(pSSM, &pThis->fFlatlined);
4152 pHlp->pfnSSMGetU64V(pSSM, &pThis->nsLastHeartbeatTS);
4153 rc = PDMDevHlpTimerLoad(pDevIns, pThis->hFlatlinedTimer, pSSM);
4154 AssertRCReturn(rc, rc);
4155 if (pThis->fFlatlined)
4156 LogRel(("vmmdevLoadState: Guest has flatlined. Last heartbeat %'RU64 ns before state was saved.\n",
4157 PDMDevHlpTimerGetNano(pDevIns, pThis->hFlatlinedTimer) - pThis->nsLastHeartbeatTS));
4158 }
4159
4160 /*
4161 * On a resume, we send the capabilities changed message so
4162 * that listeners can sync their state again
4163 */
4164 Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pThis->fMouseCapabilities));
4165 if (pThisCC->pDrv)
4166 {
4167 pThisCC->pDrv->pfnUpdateMouseCapabilities(pThisCC->pDrv, pThis->fMouseCapabilities);
4168 if (uVersion >= 10)
4169 pThisCC->pDrv->pfnUpdatePointerShape(pThisCC->pDrv,
4170 /*fVisible=*/!!pThis->fHostCursorRequested,
4171 /*fAlpha=*/false,
4172 /*xHot=*/0, /*yHot=*/0,
4173 /*cx=*/0, /*cy=*/0,
4174 /*pvShape=*/NULL);
4175 }
4176
4177 if (pThis->fu32AdditionsOk)
4178 {
4179 vmmdevLogGuestOsInfo(&pThis->guestInfo);
4180 if (pThisCC->pDrv)
4181 {
4182 if (pThis->guestInfo2.uFullVersion && pThisCC->pDrv->pfnUpdateGuestInfo2)
4183 pThisCC->pDrv->pfnUpdateGuestInfo2(pThisCC->pDrv, pThis->guestInfo2.uFullVersion, pThis->guestInfo2.szName,
4184 pThis->guestInfo2.uRevision, pThis->guestInfo2.fFeatures);
4185 if (pThisCC->pDrv->pfnUpdateGuestInfo)
4186 pThisCC->pDrv->pfnUpdateGuestInfo(pThisCC->pDrv, &pThis->guestInfo);
4187
4188 if (pThisCC->pDrv->pfnUpdateGuestStatus)
4189 {
4190 for (uint32_t i = 0; i < pThis->cFacilityStatuses; i++) /* ascending order! */
4191 if ( pThis->aFacilityStatuses[i].enmStatus != VBoxGuestFacilityStatus_Inactive
4192 || !pThis->aFacilityStatuses[i].fFixed)
4193 pThisCC->pDrv->pfnUpdateGuestStatus(pThisCC->pDrv,
4194 pThis->aFacilityStatuses[i].enmFacility,
4195 (uint16_t)pThis->aFacilityStatuses[i].enmStatus,
4196 pThis->aFacilityStatuses[i].fFlags,
4197 &pThis->aFacilityStatuses[i].TimeSpecTS);
4198 }
4199 }
4200 }
4201 if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
4202 pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, pThis->fGuestCaps);
4203
4204 return VINF_SUCCESS;
4205}
4206
4207/**
4208 * Load state done callback. Notify guest of restore event.
4209 *
4210 * @returns VBox status code.
4211 * @param pDevIns The device instance.
4212 * @param pSSM The handle to the saved state.
4213 */
4214static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
4215{
4216 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
4217 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
4218 RT_NOREF(pSSM);
4219
4220#ifdef VBOX_WITH_HGCM
4221 int rc = vmmdevR3HgcmLoadStateDone(pDevIns, pThis, pThisCC);
4222 AssertLogRelRCReturn(rc, rc);
4223#endif /* VBOX_WITH_HGCM */
4224
4225 /* Reestablish the acceleration status. */
4226 if ( pThis->u32VideoAccelEnabled
4227 && pThisCC->pDrv)
4228 pThisCC->pDrv->pfnVideoAccelEnable(pThisCC->pDrv, !!pThis->u32VideoAccelEnabled, &pThisCC->pVMMDevRAMR3->vbvaMemory);
4229
4230 VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_RESTORED);
4231
4232 return VINF_SUCCESS;
4233}
4234
4235
4236/* -=-=-=-=- PDMDEVREG -=-=-=-=- */
4237
4238/**
4239 * (Re-)initializes the MMIO2 data.
4240 *
4241 * @param pThisCC The VMMDev ring-3 instance data.
4242 */
4243static void vmmdevInitRam(PVMMDEVCC pThisCC)
4244{
4245 memset(pThisCC->pVMMDevRAMR3, 0, sizeof(VMMDevMemory));
4246 pThisCC->pVMMDevRAMR3->u32Size = sizeof(VMMDevMemory);
4247 pThisCC->pVMMDevRAMR3->u32Version = VMMDEV_MEMORY_VERSION;
4248}
4249
4250
4251/**
4252 * @interface_method_impl{PDMDEVREG,pfnReset}
4253 */
4254static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
4255{
4256 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
4257 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
4258 int const rcLock = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
4259 PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, &pThis->CritSect, rcLock);
4260
4261 /*
4262 * Reset the mouse integration feature bits
4263 */
4264 if (pThis->fMouseCapabilities & VMMDEV_MOUSE_GUEST_MASK)
4265 {
4266 pThis->fMouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
4267 /* notify the connector */
4268 Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pThis->fMouseCapabilities));
4269 pThisCC->pDrv->pfnUpdateMouseCapabilities(pThisCC->pDrv, pThis->fMouseCapabilities);
4270 }
4271 pThis->fHostCursorRequested = false;
4272
4273 /* re-initialize the VMMDev memory */
4274 if (pThisCC->pVMMDevRAMR3)
4275 vmmdevInitRam(pThisCC);
4276
4277 /* credentials have to go away (by default) */
4278 VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
4279 if (pCredentials)
4280 {
4281 if (!pThis->fKeepCredentials)
4282 {
4283 RT_ZERO(pCredentials->Logon.szUserName);
4284 RT_ZERO(pCredentials->Logon.szPassword);
4285 RT_ZERO(pCredentials->Logon.szDomain);
4286 }
4287 RT_ZERO(pCredentials->Judge.szUserName);
4288 RT_ZERO(pCredentials->Judge.szPassword);
4289 RT_ZERO(pCredentials->Judge.szDomain);
4290 }
4291
4292 /* Reset means that additions will report again. */
4293 const bool fVersionChanged = pThis->fu32AdditionsOk
4294 || pThis->guestInfo.interfaceVersion
4295 || pThis->guestInfo.osType != VBOXOSTYPE_Unknown;
4296 if (fVersionChanged)
4297 Log(("vmmdevReset: fu32AdditionsOk=%d additionsVersion=%x osType=%#x\n",
4298 pThis->fu32AdditionsOk, pThis->guestInfo.interfaceVersion, pThis->guestInfo.osType));
4299 pThis->fu32AdditionsOk = false;
4300 memset (&pThis->guestInfo, 0, sizeof (pThis->guestInfo));
4301 RT_ZERO(pThis->guestInfo2);
4302 const bool fCapsChanged = pThis->fGuestCaps != 0; /* Report transition to 0. */
4303 pThis->fGuestCaps = 0;
4304
4305 /* Clear facilities. No need to tell Main as it will get a
4306 pfnUpdateGuestInfo callback. */
4307 RTTIMESPEC TimeStampNow;
4308 RTTimeNow(&TimeStampNow);
4309 uint32_t iFacility = pThis->cFacilityStatuses;
4310 while (iFacility-- > 0)
4311 {
4312 pThis->aFacilityStatuses[iFacility].enmStatus = VBoxGuestFacilityStatus_Inactive;
4313 pThis->aFacilityStatuses[iFacility].TimeSpecTS = TimeStampNow;
4314 }
4315
4316 /* clear pending display change request. */
4317 for (unsigned i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
4318 {
4319 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
4320 memset(&pRequest->lastReadDisplayChangeRequest, 0, sizeof(pRequest->lastReadDisplayChangeRequest));
4321 pRequest->lastReadDisplayChangeRequest.fDisplayFlags = VMMDEV_DISPLAY_DISABLED;
4322 pRequest->lastReadDisplayChangeRequest.idDisplay = i;
4323 }
4324 pThis->displayChangeData.iCurrentMonitor = 0;
4325 pThis->displayChangeData.fGuestSentChangeEventAck = false;
4326
4327 /* disable seamless mode */
4328 pThis->fLastSeamlessEnabled = false;
4329
4330 /* disabled memory ballooning */
4331 pThis->cMbMemoryBalloonLast = 0;
4332
4333 /* disabled statistics updating */
4334 pThis->cSecsLastStatInterval = 0;
4335
4336#ifdef VBOX_WITH_HGCM
4337 /* Clear the "HGCM event enabled" flag so the event can be automatically reenabled. */
4338 pThisCC->u32HGCMEnabled = 0;
4339#endif
4340
4341 /*
4342 * Deactive heartbeat.
4343 */
4344 if (pThis->fHeartbeatActive)
4345 {
4346 PDMDevHlpTimerStop(pDevIns, pThis->hFlatlinedTimer);
4347 pThis->fFlatlined = false;
4348 pThis->fHeartbeatActive = true;
4349 }
4350
4351 /*
4352 * Clear the event variables.
4353 *
4354 * XXX By design we should NOT clear pThis->fHostEventFlags because it is designed
4355 * that way so host events do not depend on guest resets. However, the pending
4356 * event flags actually _were_ cleared since ages so we mask out events from
4357 * clearing which we really need to survive the reset. See xtracker 5767.
4358 */
4359 pThis->fHostEventFlags &= VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
4360 pThis->fGuestFilterMask = 0;
4361 pThis->fNewGuestFilterMask = 0;
4362 pThis->fNewGuestFilterMaskValid = 0;
4363
4364 /*
4365 * Call the update functions as required.
4366 */
4367 if (fVersionChanged && pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestInfo)
4368 pThisCC->pDrv->pfnUpdateGuestInfo(pThisCC->pDrv, &pThis->guestInfo);
4369 if (fCapsChanged && pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
4370 pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, pThis->fGuestCaps);
4371
4372 /*
4373 * Generate a unique session id for this VM; it will be changed for each start, reset or restore.
4374 * This can be used for restore detection inside the guest.
4375 */
4376 pThis->idSession = ASMReadTSC();
4377
4378 PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
4379}
4380
4381
4382#ifdef VBOX_WITH_RAW_MODE_KEEP
4383/**
4384 * @interface_method_impl{PDMDEVREG,pfnRelocate}
4385 */
4386static DECLCALLBACK(void) vmmdevRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
4387{
4388 if (offDelta)
4389 {
4390 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
4391 LogFlow(("vmmdevRelocate: offDelta=%RGv\n", offDelta));
4392
4393 if (pThis->pVMMDevRAMRC)
4394 pThis->pVMMDevRAMRC += offDelta;
4395 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
4396 }
4397}
4398#endif
4399
4400
4401/**
4402 * @interface_method_impl{PDMDEVREG,pfnDestruct}
4403 */
4404static DECLCALLBACK(int) vmmdevDestruct(PPDMDEVINS pDevIns)
4405{
4406 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
4407 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
4408
4409 /*
4410 * Wipe and free the credentials.
4411 */
4412 VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
4413 pThisCC->pCredentials = NULL;
4414 if (pCredentials)
4415 {
4416 if (pThisCC->fSaferCredentials)
4417 RTMemSaferFree(pCredentials, sizeof(*pCredentials));
4418 else
4419 {
4420 RTMemWipeThoroughly(pCredentials, sizeof(*pCredentials), 10);
4421 RTMemFree(pCredentials);
4422 }
4423 }
4424
4425#ifdef VBOX_WITH_HGCM
4426 /*
4427 * Everything HGCM.
4428 */
4429 vmmdevR3HgcmDestroy(pDevIns, PDMDEVINS_2_DATA(pDevIns, PVMMDEV), pThisCC);
4430#endif
4431
4432 /*
4433 * Free the request buffers.
4434 */
4435 for (uint32_t iCpu = 0; iCpu < RT_ELEMENTS(pThisCC->apReqBufs); iCpu++)
4436 {
4437 RTMemPageFree(pThisCC->apReqBufs[iCpu], _4K);
4438 pThisCC->apReqBufs[iCpu] = NULL;
4439 }
4440
4441#ifndef VBOX_WITHOUT_TESTING_FEATURES
4442 /*
4443 * Clean up the testing device.
4444 */
4445 vmmdevR3TestingTerminate(pDevIns);
4446#endif
4447
4448 return VINF_SUCCESS;
4449}
4450
4451
4452/**
4453 * @interface_method_impl{PDMDEVREG,pfnConstruct}
4454 */
4455static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
4456{
4457 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
4458 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
4459 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
4460 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
4461 int rc;
4462
4463 Assert(iInstance == 0);
4464 RT_NOREF(iInstance);
4465
4466 /*
4467 * Initialize data (most of it anyway).
4468 */
4469 pThisCC->pDevIns = pDevIns;
4470
4471 pThis->hFlatlinedTimer = NIL_TMTIMERHANDLE;
4472 pThis->hIoPortBackdoorLog = NIL_IOMIOPORTHANDLE;
4473 pThis->hIoPortAltTimesync = NIL_IOMIOPORTHANDLE;
4474 pThis->hIoPortReq = NIL_IOMIOPORTHANDLE;
4475 pThis->hIoPortFast = NIL_IOMIOPORTHANDLE;
4476 pThis->hMmio2VMMDevRAM = NIL_PGMMMIO2HANDLE;
4477 pThis->hMmio2Heap = NIL_PGMMMIO2HANDLE;
4478#ifndef VBOX_WITHOUT_TESTING_FEATURES
4479 pThis->hIoPortTesting = NIL_IOMIOPORTHANDLE;
4480 pThis->hMmioTesting = NIL_IOMMMIOHANDLE;
4481 pThis->hTestingLockEvt = NIL_SUPSEMEVENT;
4482#endif
4483
4484 PPDMPCIDEV pPciDev = pDevIns->apPciDevs[0];
4485 PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
4486
4487 /* PCI vendor, just a free bogus value */
4488 PDMPciDevSetVendorId(pPciDev, 0x80ee);
4489 /* device ID */
4490 PDMPciDevSetDeviceId(pPciDev, 0xcafe);
4491 /* class sub code (other type of system peripheral) */
4492 PDMPciDevSetClassSub(pPciDev, 0x80);
4493 /* class base code (base system peripheral) */
4494 PDMPciDevSetClassBase(pPciDev, 0x08);
4495 /* header type */
4496 PDMPciDevSetHeaderType(pPciDev, 0x00);
4497 /* interrupt on pin 0 */
4498 PDMPciDevSetInterruptPin(pPciDev, 0x01);
4499
4500 RTTIMESPEC TimeStampNow;
4501 RTTimeNow(&TimeStampNow);
4502 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxGuestDriver, true /*fFixed*/, &TimeStampNow);
4503 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxService, true /*fFixed*/, &TimeStampNow);
4504 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxTrayClient, true /*fFixed*/, &TimeStampNow);
4505 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_Seamless, true /*fFixed*/, &TimeStampNow);
4506 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_Graphics, true /*fFixed*/, &TimeStampNow);
4507 Assert(pThis->cFacilityStatuses == 5);
4508
4509 /* disable all screens (no better hints known yet). */
4510 /** @todo r=klaus need a way to represent "no hint known" */
4511 for (unsigned i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
4512 {
4513 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
4514 pRequest->displayChangeRequest.fDisplayFlags = VMMDEV_DISPLAY_DISABLED;
4515 pRequest->displayChangeRequest.idDisplay = i;
4516 pRequest->lastReadDisplayChangeRequest.fDisplayFlags = VMMDEV_DISPLAY_DISABLED;
4517 pRequest->lastReadDisplayChangeRequest.idDisplay = i;
4518 }
4519
4520 /*
4521 * Interfaces
4522 */
4523 /* IBase */
4524 pThisCC->IBase.pfnQueryInterface = vmmdevPortQueryInterface;
4525
4526 /* VMMDev port */
4527 pThisCC->IPort.pfnQueryAbsoluteMouse = vmmdevIPort_QueryAbsoluteMouse;
4528 pThisCC->IPort.pfnSetAbsoluteMouse = vmmdevIPort_SetAbsoluteMouse ;
4529 pThisCC->IPort.pfnQueryMouseCapabilities = vmmdevIPort_QueryMouseCapabilities;
4530 pThisCC->IPort.pfnUpdateMouseCapabilities = vmmdevIPort_UpdateMouseCapabilities;
4531 pThisCC->IPort.pfnRequestDisplayChange = vmmdevIPort_RequestDisplayChange;
4532 pThisCC->IPort.pfnSetCredentials = vmmdevIPort_SetCredentials;
4533 pThisCC->IPort.pfnVBVAChange = vmmdevIPort_VBVAChange;
4534 pThisCC->IPort.pfnRequestSeamlessChange = vmmdevIPort_RequestSeamlessChange;
4535 pThisCC->IPort.pfnSetMemoryBalloon = vmmdevIPort_SetMemoryBalloon;
4536 pThisCC->IPort.pfnSetStatisticsInterval = vmmdevIPort_SetStatisticsInterval;
4537 pThisCC->IPort.pfnVRDPChange = vmmdevIPort_VRDPChange;
4538 pThisCC->IPort.pfnCpuHotUnplug = vmmdevIPort_CpuHotUnplug;
4539 pThisCC->IPort.pfnCpuHotPlug = vmmdevIPort_CpuHotPlug;
4540
4541 /* Shared folder LED */
4542 pThisCC->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
4543 pThisCC->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
4544
4545#ifdef VBOX_WITH_HGCM
4546 /* HGCM port */
4547 pThisCC->IHGCMPort.pfnCompleted = hgcmR3Completed;
4548 pThisCC->IHGCMPort.pfnIsCmdRestored = hgcmR3IsCmdRestored;
4549 pThisCC->IHGCMPort.pfnIsCmdCancelled = hgcmR3IsCmdCancelled;
4550 pThisCC->IHGCMPort.pfnGetRequestor = hgcmR3GetRequestor;
4551 pThisCC->IHGCMPort.pfnGetVMMDevSessionId = hgcmR3GetVMMDevSessionId;
4552#endif
4553
4554 pThisCC->pCredentials = (VMMDEVCREDS *)RTMemSaferAllocZ(sizeof(*pThisCC->pCredentials));
4555 if (pThisCC->pCredentials)
4556 pThisCC->fSaferCredentials = true;
4557 else
4558 {
4559 pThisCC->pCredentials = (VMMDEVCREDS *)RTMemAllocZ(sizeof(*pThisCC->pCredentials));
4560 AssertReturn(pThisCC->pCredentials, VERR_NO_MEMORY);
4561 }
4562
4563
4564 /*
4565 * Validate and read the configuration.
4566 */
4567 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns,
4568 "AllowGuestToSaveState|"
4569 "GetHostTimeDisabled|"
4570 "BackdoorLogDisabled|"
4571 "KeepCredentials|"
4572 "HeapEnabled|"
4573 "GuestCoreDumpEnabled|"
4574 "GuestCoreDumpDir|"
4575 "GuestCoreDumpCount|"
4576 "HeartbeatInterval|"
4577 "HeartbeatTimeout|"
4578 "TestingEnabled|"
4579 "TestingMMIO|"
4580 "TestintXmlOutputFile|"
4581 "HGCMHeapBudgetDefault|"
4582 "HGCMHeapBudgetLegacy|"
4583 "HGCMHeapBudgetVBoxGuest|"
4584 "HGCMHeapBudgetOtherDrv|"
4585 "HGCMHeapBudgetRoot|"
4586 "HGCMHeapBudgetSystem|"
4587 "HGCMHeapBudgetReserved1|"
4588 "HGCMHeapBudgetUser|"
4589 "HGCMHeapBudgetGuest"
4590 ,
4591 "");
4592
4593 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "AllowGuestToSaveState", &pThis->fAllowGuestToSaveState, true);
4594 if (RT_FAILURE(rc))
4595 return PDMDEV_SET_ERROR(pDevIns, rc,
4596 N_("Configuration error: Failed querying \"AllowGuestToSaveState\" as a boolean"));
4597
4598 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "GetHostTimeDisabled", &pThis->fGetHostTimeDisabled, false);
4599 if (RT_FAILURE(rc))
4600 return PDMDEV_SET_ERROR(pDevIns, rc,
4601 N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
4602
4603 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "BackdoorLogDisabled", &pThis->fBackdoorLogDisabled, false);
4604 if (RT_FAILURE(rc))
4605 return PDMDEV_SET_ERROR(pDevIns, rc,
4606 N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
4607
4608 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "KeepCredentials", &pThis->fKeepCredentials, false);
4609 if (RT_FAILURE(rc))
4610 return PDMDEV_SET_ERROR(pDevIns, rc,
4611 N_("Configuration error: Failed querying \"KeepCredentials\" as a boolean"));
4612
4613 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "HeapEnabled", &pThis->fHeapEnabled, true);
4614 if (RT_FAILURE(rc))
4615 return PDMDEV_SET_ERROR(pDevIns, rc,
4616 N_("Configuration error: Failed querying \"HeapEnabled\" as a boolean"));
4617
4618 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "GuestCoreDumpEnabled", &pThis->fGuestCoreDumpEnabled, false);
4619 if (RT_FAILURE(rc))
4620 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"GuestCoreDumpEnabled\" as a boolean"));
4621
4622 char *pszGuestCoreDumpDir = NULL;
4623 rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "GuestCoreDumpDir", &pszGuestCoreDumpDir, "");
4624 if (RT_FAILURE(rc))
4625 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"GuestCoreDumpDir\" as a string"));
4626
4627 RTStrCopy(pThis->szGuestCoreDumpDir, sizeof(pThis->szGuestCoreDumpDir), pszGuestCoreDumpDir);
4628 PDMDevHlpMMHeapFree(pDevIns, pszGuestCoreDumpDir);
4629
4630 rc = pHlp->pfnCFGMQueryU32Def(pCfg, "GuestCoreDumpCount", &pThis->cGuestCoreDumps, 3);
4631 if (RT_FAILURE(rc))
4632 return PDMDEV_SET_ERROR(pDevIns, rc,
4633 N_("Configuration error: Failed querying \"GuestCoreDumpCount\" as a 32-bit unsigned integer"));
4634
4635 rc = pHlp->pfnCFGMQueryU64Def(pCfg, "HeartbeatInterval", &pThis->cNsHeartbeatInterval, VMMDEV_HEARTBEAT_DEFAULT_INTERVAL);
4636 if (RT_FAILURE(rc))
4637 return PDMDEV_SET_ERROR(pDevIns, rc,
4638 N_("Configuration error: Failed querying \"HeartbeatInterval\" as a 64-bit unsigned integer"));
4639 if (pThis->cNsHeartbeatInterval < RT_NS_100MS / 2)
4640 return PDMDEV_SET_ERROR(pDevIns, rc,
4641 N_("Configuration error: Heartbeat interval \"HeartbeatInterval\" too small"));
4642
4643 rc = pHlp->pfnCFGMQueryU64Def(pCfg, "HeartbeatTimeout", &pThis->cNsHeartbeatTimeout, pThis->cNsHeartbeatInterval * 2);
4644 if (RT_FAILURE(rc))
4645 return PDMDEV_SET_ERROR(pDevIns, rc,
4646 N_("Configuration error: Failed querying \"HeartbeatTimeout\" as a 64-bit unsigned integer"));
4647 if (pThis->cNsHeartbeatTimeout < RT_NS_100MS)
4648 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Heartbeat timeout \"HeartbeatTimeout\" too small"));
4649 if (pThis->cNsHeartbeatTimeout <= pThis->cNsHeartbeatInterval + RT_NS_10MS)
4650 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
4651 N_("Configuration error: Heartbeat timeout \"HeartbeatTimeout\" value (%'ull ns) is too close to the interval (%'ull ns)"),
4652 pThis->cNsHeartbeatTimeout, pThis->cNsHeartbeatInterval);
4653
4654#ifndef VBOX_WITHOUT_TESTING_FEATURES
4655 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "TestingEnabled", &pThis->fTestingEnabled, false);
4656 if (RT_FAILURE(rc))
4657 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"TestingEnabled\" as a boolean"));
4658 rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "TestingMMIO", &pThis->fTestingMMIO, false);
4659 if (RT_FAILURE(rc))
4660 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"TestingMMIO\" as a boolean"));
4661 rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "TestintXmlOutputFile", &pThisCC->pszTestingXmlOutput, NULL);
4662 if (RT_FAILURE(rc))
4663 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"TestintXmlOutputFile\" as a string"));
4664
4665 /** @todo image-to-load-filename? */
4666#endif
4667
4668#ifdef VBOX_WITH_HGCM
4669 /*
4670 * Heap budgets for HGCM requestor categories. Take the available host
4671 * memory as a rough hint of how much we can handle.
4672 */
4673 uint64_t cbDefaultBudget = 0;
4674 if (RT_FAILURE(RTSystemQueryTotalRam(&cbDefaultBudget)))
4675 cbDefaultBudget = 8 * _1G64;
4676 LogFunc(("RTSystemQueryTotalRam -> %'RU64 (%RX64)\n", cbDefaultBudget, cbDefaultBudget));
4677# if ARCH_BITS == 32
4678 cbDefaultBudget = RT_MIN(cbDefaultBudget, _512M);
4679# endif
4680 cbDefaultBudget /= 8; /* One eighth of physical memory ... */
4681 cbDefaultBudget /= RT_ELEMENTS(pThisCC->aHgcmAcc); /* over 3 accounting categories. (8GiB -> 341MiB) */
4682 cbDefaultBudget = RT_MIN(cbDefaultBudget, _1G); /* max 1024MiB */
4683 cbDefaultBudget = RT_MAX(cbDefaultBudget, _32M); /* min 32MiB */
4684 rc = pHlp->pfnCFGMQueryU64Def(pCfg, "HGCMHeapBudgetDefault", &cbDefaultBudget, cbDefaultBudget);
4685 if (RT_FAILURE(rc))
4686 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"HGCMHeapBudgetDefault\" as a 64-bit unsigned integer"));
4687
4688 LogRel(("VMMDev: cbDefaultBudget: %'RU64 (%RX64)\n", cbDefaultBudget, cbDefaultBudget));
4689 static const struct { const char *pszName; unsigned idx; } s_aCfgHeapBudget[] =
4690 {
4691 { "HGCMHeapBudgetKernel", VMMDEV_HGCM_CATEGORY_KERNEL },
4692 { "HGCMHeapBudgetRoot", VMMDEV_HGCM_CATEGORY_ROOT },
4693 { "HGCMHeapBudgetUser", VMMDEV_HGCM_CATEGORY_USER },
4694 };
4695 AssertCompile(RT_ELEMENTS(s_aCfgHeapBudget) == RT_ELEMENTS(pThisCC->aHgcmAcc));
4696 for (uintptr_t i = 0; i < RT_ELEMENTS(s_aCfgHeapBudget); i++)
4697 {
4698 uintptr_t const idx = s_aCfgHeapBudget[i].idx;
4699 rc = pHlp->pfnCFGMQueryU64Def(pCfg, s_aCfgHeapBudget[i].pszName,
4700 &pThisCC->aHgcmAcc[idx].cbHeapBudgetConfig, cbDefaultBudget);
4701 if (RT_FAILURE(rc))
4702 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
4703 N_("Configuration error: Failed querying \"%s\" as a 64-bit unsigned integer"),
4704 s_aCfgHeapBudget[i].pszName);
4705 pThisCC->aHgcmAcc[idx].cbHeapBudget = pThisCC->aHgcmAcc[idx].cbHeapBudgetConfig;
4706 if (pThisCC->aHgcmAcc[idx].cbHeapBudgetConfig != cbDefaultBudget)
4707 LogRel(("VMMDev: %s: %'RU64 (%#RX64)\n", s_aCfgHeapBudget[i].pszName,
4708 pThisCC->aHgcmAcc[idx].cbHeapBudgetConfig, pThisCC->aHgcmAcc[idx].cbHeapBudgetConfig));
4709
4710 const char * const pszCatName = &s_aCfgHeapBudget[i].pszName[sizeof("HGCMHeapBudget") - 1];
4711 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].cbHeapBudget, STAMTYPE_U64, STAMVISIBILITY_ALWAYS,
4712 STAMUNIT_BYTES, "Currently available budget", "HGCM-%s/BudgetAvailable", pszCatName);
4713 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].cbHeapBudgetConfig, STAMTYPE_U64, STAMVISIBILITY_ALWAYS,
4714 STAMUNIT_BYTES, "Configured budget", "HGCM-%s/BudgetConfig", pszCatName);
4715 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].StateMsgHeapUsage, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS,
4716 STAMUNIT_BYTES, "Message heap usage", "HGCM-%s/MessageHeapUsage", pszCatName);
4717 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->aHgcmAcc[idx].StatBudgetOverruns, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS,
4718 STAMUNIT_BYTES, "Budget overruns and allocation errors", "HGCM-%s/BudgetOverruns", pszCatName);
4719 }
4720#endif
4721
4722 /*
4723 * <missing comment>
4724 */
4725 pThis->cbGuestRAM = PDMDevHlpMMPhysGetRamSize(pDevIns);
4726
4727 /*
4728 * We do our own locking entirely. So, install NOP critsect for the device
4729 * and create our own critsect for use where it really matters (++).
4730 */
4731 rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
4732 AssertRCReturn(rc, rc);
4733 rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "VMMDev#%u", iInstance);
4734 AssertRCReturn(rc, rc);
4735
4736 /*
4737 * Register the backdoor logging port
4738 */
4739 rc = PDMDevHlpIoPortCreateAndMap(pDevIns, RTLOG_DEBUG_PORT, 1, vmmdevBackdoorLog, NULL /*pfnIn*/,
4740 "VMMDev backdoor logging", NULL, &pThis->hIoPortBackdoorLog);
4741 AssertRCReturn(rc, rc);
4742
4743#ifdef VMMDEV_WITH_ALT_TIMESYNC
4744 /*
4745 * Alternative timesync source.
4746 *
4747 * This was orignally added for creating a simple time sync service in an
4748 * OpenBSD guest without requiring VBoxGuest and VBoxService to be ported
4749 * first. We keep it in case it comes in handy.
4750 */
4751 rc = PDMDevHlpIoPortCreateAndMap(pDevIns, 0x505, 1, vmmdevAltTimeSyncWrite, vmmdevAltTimeSyncRead,
4752 "VMMDev timesync backdoor", NULL /*paExtDescs*/, &pThis->hIoPortAltTimesync);
4753 AssertRCReturn(rc, rc);
4754#endif
4755
4756 /*
4757 * Register the PCI device.
4758 */
4759 rc = PDMDevHlpPCIRegister(pDevIns, pPciDev);
4760 if (RT_FAILURE(rc))
4761 return rc;
4762 if (pPciDev->uDevFn != 32 || iInstance != 0)
4763 Log(("!!WARNING!!: pThis->PciDev.uDevFn=%d (ignore if testcase or no started by Main)\n", pPciDev->uDevFn));
4764
4765 /*
4766 * The I/O ports, PCI region #0. This has two separate I/O port mappings in it,
4767 * so we have to do it via the mapper callback.
4768 */
4769 rc = PDMDevHlpIoPortCreate(pDevIns, 1 /*cPorts*/, pPciDev, RT_MAKE_U32(0, 0), vmmdevRequestHandler, NULL /*pfnIn*/,
4770 NULL /*pvUser*/, "VMMDev Request Handler", NULL, &pThis->hIoPortReq);
4771 AssertRCReturn(rc, rc);
4772
4773 rc = PDMDevHlpIoPortCreate(pDevIns, 1 /*cPorts*/, pPciDev, RT_MAKE_U32(1, 0), vmmdevFastRequestHandler,
4774 vmmdevFastRequestIrqAck, NULL, "VMMDev Fast R0/RC Requests", NULL /*pvUser*/, &pThis->hIoPortFast);
4775 AssertRCReturn(rc, rc);
4776
4777 rc = PDMDevHlpPCIIORegionRegisterIoCustom(pDevIns, 0, 0x20, vmmdevIOPortRegionMap);
4778 AssertRCReturn(rc, rc);
4779
4780 /*
4781 * Allocate and initialize the MMIO2 memory, PCI region #1.
4782 */
4783 rc = PDMDevHlpPCIIORegionCreateMmio2(pDevIns, 1 /*iPciRegion*/, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, "VMMDev",
4784 (void **)&pThisCC->pVMMDevRAMR3, &pThis->hMmio2VMMDevRAM);
4785 if (RT_FAILURE(rc))
4786 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
4787 N_("Failed to create the %u (%#x) byte MMIO2 region for the VMM device"),
4788 VMMDEV_RAM_SIZE, VMMDEV_RAM_SIZE);
4789 vmmdevInitRam(pThisCC);
4790
4791 /*
4792 * The MMIO2 heap (used for real-mode VT-x trickery), PCI region #2.
4793 */
4794 if (pThis->fHeapEnabled)
4795 {
4796 rc = PDMDevHlpPCIIORegionCreateMmio2Ex(pDevIns, 2 /*iPciRegion*/, VMMDEV_HEAP_SIZE, PCI_ADDRESS_SPACE_MEM_PREFETCH,
4797 0 /*fFlags*/, vmmdevMmio2HeapRegionMap, "VMMDev Heap",
4798 (void **)&pThisCC->pVMMDevHeapR3, &pThis->hMmio2Heap);
4799 if (RT_FAILURE(rc))
4800 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
4801 N_("Failed to create the %u (%#x) bytes MMIO2 heap region for the VMM device"),
4802 VMMDEV_HEAP_SIZE, VMMDEV_HEAP_SIZE);
4803
4804 /* Register the memory area with PDM so HM can access it before it's mapped. */
4805 rc = PDMDevHlpRegisterVMMDevHeap(pDevIns, NIL_RTGCPHYS, pThisCC->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
4806 AssertLogRelRCReturn(rc, rc);
4807 }
4808
4809#ifndef VBOX_WITHOUT_TESTING_FEATURES
4810 /*
4811 * Initialize testing.
4812 */
4813 rc = vmmdevR3TestingInitialize(pDevIns);
4814 if (RT_FAILURE(rc))
4815 return rc;
4816#endif
4817
4818 /*
4819 * Get the corresponding connector interface
4820 */
4821 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThisCC->IBase, &pThisCC->pDrvBase, "VMM Driver Port");
4822 if (RT_SUCCESS(rc))
4823 {
4824 pThisCC->pDrv = PDMIBASE_QUERY_INTERFACE(pThisCC->pDrvBase, PDMIVMMDEVCONNECTOR);
4825 AssertMsgReturn(pThisCC->pDrv, ("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
4826#ifdef VBOX_WITH_HGCM
4827 pThisCC->pHGCMDrv = PDMIBASE_QUERY_INTERFACE(pThisCC->pDrvBase, PDMIHGCMCONNECTOR);
4828 if (!pThisCC->pHGCMDrv)
4829 {
4830 Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Rrc\n", rc));
4831 /* this is not actually an error, just means that there is no support for HGCM */
4832 }
4833#endif
4834 /* Query the initial balloon size. */
4835 AssertPtr(pThisCC->pDrv->pfnQueryBalloonSize);
4836 rc = pThisCC->pDrv->pfnQueryBalloonSize(pThisCC->pDrv, &pThis->cMbMemoryBalloon);
4837 AssertRC(rc);
4838
4839 Log(("Initial balloon size %x\n", pThis->cMbMemoryBalloon));
4840 }
4841 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
4842 {
4843 Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pReg->szName, pDevIns->iInstance));
4844 rc = VINF_SUCCESS;
4845 }
4846 else
4847 AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Rrc\n", rc), rc);
4848
4849 /*
4850 * Attach status driver for shared folders (optional).
4851 */
4852 PPDMIBASE pBase;
4853 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThisCC->IBase, &pBase, "Status Port");
4854 if (RT_SUCCESS(rc))
4855 pThisCC->SharedFolders.pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
4856 else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
4857 {
4858 AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
4859 return rc;
4860 }
4861
4862 /*
4863 * Register saved state and init the HGCM CmdList critsect.
4864 */
4865 rc = PDMDevHlpSSMRegisterEx(pDevIns, VMMDEV_SAVED_STATE_VERSION, sizeof(*pThis), NULL,
4866 NULL, vmmdevLiveExec, NULL,
4867 NULL, vmmdevSaveExec, NULL,
4868 NULL, vmmdevLoadExec, vmmdevLoadStateDone);
4869 AssertRCReturn(rc, rc);
4870
4871 /*
4872 * Create heartbeat checking timer.
4873 */
4874 rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vmmDevHeartbeatFlatlinedTimer, pThis,
4875 TMTIMER_FLAGS_NO_CRIT_SECT | TMTIMER_FLAGS_RING0, "Heartbeat flatlined", &pThis->hFlatlinedTimer);
4876 AssertRCReturn(rc, rc);
4877
4878#ifdef VBOX_WITH_HGCM
4879 rc = vmmdevR3HgcmInit(pThisCC);
4880 AssertRCReturn(rc, rc);
4881#endif
4882
4883 /*
4884 * In this version of VirtualBox the GUI checks whether "needs host cursor"
4885 * changes.
4886 */
4887 pThis->fMouseCapabilities |= VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
4888
4889 /*
4890 * Statistics.
4891 */
4892 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMemBalloonChunks, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
4893 "Memory balloon size", "BalloonChunks");
4894 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatFastIrqAckR3, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
4895 "Fast IRQ acknowledgments handled in ring-3.", "FastIrqAckR3");
4896 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatFastIrqAckRZ, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
4897 "Fast IRQ acknowledgments handled in ring-0 or raw-mode.", "FastIrqAckRZ");
4898 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatSlowIrqAck, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
4899 "Slow IRQ acknowledgments (old style).", "SlowIrqAck");
4900 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatReqBufAllocs, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
4901 "Times a larger request buffer was required.", "LargeReqBufAllocs");
4902#ifdef VBOX_WITH_HGCM
4903 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmCmdArrival, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
4904 "Profiling HGCM call arrival processing", "/HGCM/MsgArrival");
4905 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmCmdCompletion, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
4906 "Profiling HGCM call completion processing", "/HGCM/MsgCompletion");
4907 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmCmdTotal, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
4908 "Profiling whole HGCM call.", "/HGCM/MsgTotal");
4909 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmLargeCmdAllocs,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
4910 "Times the allocation cache could not be used.", "/HGCM/LargeCmdAllocs");
4911 PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmFailedPageListLocking,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
4912 "Times no-bounce page list locking failed.", "/HGCM/FailedPageListLocking");
4913#endif
4914
4915 /*
4916 * Generate a unique session id for this VM; it will be changed for each
4917 * start, reset or restore. This can be used for restore detection inside
4918 * the guest.
4919 */
4920 pThis->idSession = ASMReadTSC();
4921 return rc;
4922}
4923
4924#else /* !IN_RING3 */
4925
4926/**
4927 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
4928 */
4929static DECLCALLBACK(int) vmmdevRZConstruct(PPDMDEVINS pDevIns)
4930{
4931 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
4932 PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
4933 PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
4934
4935 int rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
4936 AssertRCReturn(rc, rc);
4937
4938#if 0
4939 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortBackdoorLog, vmmdevBackdoorLog, NULL /*pfnIn*/, NULL /*pvUser*/);
4940 AssertRCReturn(rc, rc);
4941#endif
4942#if 0 && defined(VMMDEV_WITH_ALT_TIMESYNC)
4943 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortAltTimesync, vmmdevAltTimeSyncWrite, vmmdevAltTimeSyncRead, NULL);
4944 AssertRCReturn(rc, rc);
4945#endif
4946
4947 /*
4948 * We map the first page of the VMMDevRAM into raw-mode and kernel contexts so we
4949 * can handle interrupt acknowledge requests more timely (vmmdevFastRequestIrqAck).
4950 */
4951 rc = PDMDevHlpMmio2SetUpContext(pDevIns, pThis->hMmio2VMMDevRAM, 0, PAGE_SIZE, (void **)&pThisCC->CTX_SUFF(pVMMDevRAM));
4952 AssertRCReturn(rc, rc);
4953
4954 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortFast, vmmdevFastRequestHandler, vmmdevFastRequestIrqAck, NULL);
4955 AssertRCReturn(rc, rc);
4956
4957# ifndef VBOX_WITHOUT_TESTING_FEATURES
4958 /*
4959 * Initialize testing.
4960 */
4961 rc = vmmdevRZTestingInitialize(pDevIns);
4962 AssertRCReturn(rc, rc);
4963# endif
4964
4965 return VINF_SUCCESS;
4966}
4967
4968#endif /* !IN_RING3 */
4969
4970/**
4971 * The device registration structure.
4972 */
4973extern "C" const PDMDEVREG g_DeviceVMMDev =
4974{
4975 /* .u32Version = */ PDM_DEVREG_VERSION,
4976 /* .uReserved0 = */ 0,
4977 /* .szName = */ "VMMDev",
4978 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
4979 /* .fClass = */ PDM_DEVREG_CLASS_VMM_DEV,
4980 /* .cMaxInstances = */ 1,
4981 /* .uSharedVersion = */ 42,
4982 /* .cbInstanceShared = */ sizeof(VMMDEV),
4983 /* .cbInstanceCC = */ sizeof(VMMDEVCC),
4984 /* .cbInstanceRC = */ sizeof(VMMDEVRC),
4985 /* .cMaxPciDevices = */ 1,
4986 /* .cMaxMsixVectors = */ 0,
4987 /* .pszDescription = */ "VirtualBox VMM Device\n",
4988#if defined(IN_RING3)
4989 /* .pszRCMod = */ "VBoxDDRC.rc",
4990 /* .pszR0Mod = */ "VBoxDDR0.r0",
4991 /* .pfnConstruct = */ vmmdevConstruct,
4992 /* .pfnDestruct = */ vmmdevDestruct,
4993# ifdef VBOX_WITH_RAW_MODE_KEEP
4994 /* .pfnRelocate = */ vmmdevRelocate,
4995# else
4996 /* .pfnRelocate = */ NULL,
4997# endif
4998 /* .pfnMemSetup = */ NULL,
4999 /* .pfnPowerOn = */ NULL,
5000 /* .pfnReset = */ vmmdevReset,
5001 /* .pfnSuspend = */ NULL,
5002 /* .pfnResume = */ NULL,
5003 /* .pfnAttach = */ NULL,
5004 /* .pfnDetach = */ NULL,
5005 /* .pfnQueryInterface = */ NULL,
5006 /* .pfnInitComplete = */ NULL,
5007 /* .pfnPowerOff = */ NULL,
5008 /* .pfnSoftReset = */ NULL,
5009 /* .pfnReserved0 = */ NULL,
5010 /* .pfnReserved1 = */ NULL,
5011 /* .pfnReserved2 = */ NULL,
5012 /* .pfnReserved3 = */ NULL,
5013 /* .pfnReserved4 = */ NULL,
5014 /* .pfnReserved5 = */ NULL,
5015 /* .pfnReserved6 = */ NULL,
5016 /* .pfnReserved7 = */ NULL,
5017#elif defined(IN_RING0)
5018 /* .pfnEarlyConstruct = */ NULL,
5019 /* .pfnConstruct = */ vmmdevRZConstruct,
5020 /* .pfnDestruct = */ NULL,
5021 /* .pfnFinalDestruct = */ NULL,
5022 /* .pfnRequest = */ NULL,
5023 /* .pfnReserved0 = */ NULL,
5024 /* .pfnReserved1 = */ NULL,
5025 /* .pfnReserved2 = */ NULL,
5026 /* .pfnReserved3 = */ NULL,
5027 /* .pfnReserved4 = */ NULL,
5028 /* .pfnReserved5 = */ NULL,
5029 /* .pfnReserved6 = */ NULL,
5030 /* .pfnReserved7 = */ NULL,
5031#elif defined(IN_RC)
5032 /* .pfnConstruct = */ vmmdevRZConstruct,
5033 /* .pfnReserved0 = */ NULL,
5034 /* .pfnReserved1 = */ NULL,
5035 /* .pfnReserved2 = */ NULL,
5036 /* .pfnReserved3 = */ NULL,
5037 /* .pfnReserved4 = */ NULL,
5038 /* .pfnReserved5 = */ NULL,
5039 /* .pfnReserved6 = */ NULL,
5040 /* .pfnReserved7 = */ NULL,
5041#else
5042# error "Not in IN_RING3, IN_RING0 or IN_RC!"
5043#endif
5044 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
5045};
5046
5047#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
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