VirtualBox

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

Last change on this file since 39882 was 39882, checked in by vboxsync, 13 years ago

Config.kmk,VMMDev,Main,QtGui,VBoxManage: Refactored IGuest::additionsVersion and associated acts, splitting it up into additionsVersion and additionsRevision like IVirtualBox and IExtPack handles versioning. Fixed missing saved state in VMMDev where the VMMDevReq_ReportGuestInfo2 info was not saved and Main+Frontends led to believe we were running guest additions older than 3.2. The changes have be subjected to limited testing. Added TODOs for another missing save in VMMDev.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 130.0 KB
Line 
1/* $Id: VMMDev.cpp 39882 2012-01-26 00:54:50Z vboxsync $ */
2/** @file
3 * VMMDev - Guest <-> VMM/Host communication device.
4 */
5
6/*
7 * Copyright (C) 2006-2011 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
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22
23/* Enable dev_vmm Log3 statements to get IRQ-related logging. */
24
25#define LOG_GROUP LOG_GROUP_DEV_VMM
26#include <VBox/VMMDev.h>
27#include <VBox/vmm/mm.h>
28#include <VBox/log.h>
29#include <VBox/param.h>
30#include <iprt/path.h>
31#include <iprt/dir.h>
32#include <iprt/file.h>
33#include <VBox/vmm/pgm.h>
34#include <VBox/err.h>
35#include <VBox/vmm/vm.h> /* for VM_IS_EMT */
36#include <VBox/dbg.h>
37#include <VBox/version.h>
38
39#include <iprt/asm.h>
40#include <iprt/asm-amd64-x86.h>
41#include <iprt/assert.h>
42#include <iprt/buildconfig.h>
43#include <iprt/string.h>
44#include <iprt/time.h>
45#ifndef IN_RC
46# include <iprt/mem.h>
47#endif
48#ifdef IN_RING3
49# include <iprt/uuid.h>
50#endif
51
52#include "VMMDevState.h"
53#ifdef VBOX_WITH_HGCM
54# include "VMMDevHGCM.h"
55#endif
56#ifndef VBOX_WITHOUT_TESTING_FEATURES
57# include "VMMDevTesting.h"
58#endif
59
60
61/*******************************************************************************
62* Defined Constants And Macros *
63*******************************************************************************/
64#define PCIDEV_2_VMMDEVSTATE(pPciDev) ( (VMMDevState *)(pPciDev) )
65#define VMMDEVSTATE_2_DEVINS(pVMMDevState) ( (pVMMDevState)->pDevIns )
66
67#define VBOX_GUEST_INTERFACE_VERSION_1_03(s) \
68 ( RT_HIWORD((s)->guestInfo.interfaceVersion) == 1 \
69 && RT_LOWORD((s)->guestInfo.interfaceVersion) == 3 )
70
71#define VBOX_GUEST_INTERFACE_VERSION_OK(additionsVersion) \
72 ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
73 && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) )
74
75#define VBOX_GUEST_INTERFACE_VERSION_OLD(additionsVersion) \
76 ( (RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) \
77 || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
78 && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) ) )
79
80#define VBOX_GUEST_INTERFACE_VERSION_TOO_OLD(additionsVersion) \
81 ( RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) )
82
83#define VBOX_GUEST_INTERFACE_VERSION_NEW(additionsVersion) \
84 ( RT_HIWORD(additionsVersion) > RT_HIWORD(VMMDEV_VERSION) \
85 || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
86 && RT_LOWORD(additionsVersion) > RT_LOWORD(VMMDEV_VERSION) ) )
87
88/** The saved state version. */
89#define VMMDEV_SAVED_STATE_VERSION 14
90/** The saved state version which is missing the guestInfo2 bits. */
91#define VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2 13
92/** The saved state version used by VirtualBox 3.0.
93 * This doesn't have the config part. */
94#define VMMDEV_SAVED_STATE_VERSION_VBOX_30 11
95
96
97#ifndef VBOX_DEVICE_STRUCT_TESTCASE
98
99/* Whenever host wants to inform guest about something
100 * an IRQ notification will be raised.
101 *
102 * VMMDev PDM interface will contain the guest notification method.
103 *
104 * There is a 32 bit event mask which will be read
105 * by guest on an interrupt. A non zero bit in the mask
106 * means that the specific event occurred and requires
107 * processing on guest side.
108 *
109 * After reading the event mask guest must issue a
110 * generic request AcknowlegdeEvents.
111 *
112 * IRQ line is set to 1 (request) if there are unprocessed
113 * events, that is the event mask is not zero.
114 *
115 * After receiving an interrupt and checking event mask,
116 * the guest must process events using the event specific
117 * mechanism.
118 *
119 * That is if mouse capabilities were changed,
120 * guest will use VMMDev_GetMouseStatus generic request.
121 *
122 * Event mask is only a set of flags indicating that guest
123 * must proceed with a procedure.
124 *
125 * Unsupported events are therefore ignored.
126 * The guest additions must inform host which events they
127 * want to receive, to avoid unnecessary IRQ processing.
128 * By default no events are signalled to guest.
129 *
130 * This seems to be fast method. It requires
131 * only one context switch for an event processing.
132 *
133 */
134
135static void vmmdevSetIRQ_Legacy_EMT (VMMDevState *pVMMDevState)
136{
137 if (!pVMMDevState->fu32AdditionsOk)
138 {
139 Log(("vmmdevSetIRQ: IRQ is not generated, guest has not yet reported to us.\n"));
140 return;
141 }
142
143 uint32_t u32IRQLevel = 0;
144
145 /* Filter unsupported events */
146 uint32_t u32EventFlags =
147 pVMMDevState->u32HostEventFlags
148 & pVMMDevState->pVMMDevRAMR3->V.V1_03.u32GuestEventMask;
149
150 Log(("vmmdevSetIRQ: u32EventFlags = 0x%08X, "
151 "pVMMDevState->u32HostEventFlags = 0x%08X, "
152 "pVMMDevState->pVMMDevRAMR3->u32GuestEventMask = 0x%08X\n",
153 u32EventFlags,
154 pVMMDevState->u32HostEventFlags,
155 pVMMDevState->pVMMDevRAMR3->V.V1_03.u32GuestEventMask));
156
157 /* Move event flags to VMMDev RAM */
158 pVMMDevState->pVMMDevRAMR3->V.V1_03.u32HostEvents = u32EventFlags;
159
160 if (u32EventFlags)
161 {
162 /* Clear host flags which will be delivered to guest. */
163 pVMMDevState->u32HostEventFlags &= ~u32EventFlags;
164 Log(("vmmdevSetIRQ: pVMMDevState->u32HostEventFlags = 0x%08X\n",
165 pVMMDevState->u32HostEventFlags));
166 u32IRQLevel = 1;
167 }
168
169 /* Set IRQ level for pin 0 */
170 /** @todo make IRQ pin configurable, at least a symbolic constant */
171 PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
172 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, u32IRQLevel);
173 Log(("vmmdevSetIRQ: IRQ set %d\n", u32IRQLevel));
174}
175
176static void vmmdevMaybeSetIRQ_EMT (VMMDevState *pVMMDevState)
177{
178 PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS (pVMMDevState);
179
180 Log3(("vmmdevMaybeSetIRQ_EMT: u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
181 pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
182
183 if (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask)
184 {
185 pVMMDevState->pVMMDevRAMR3->V.V1_04.fHaveEvents = true;
186 PDMDevHlpPCISetIrqNoWait (pDevIns, 0, 1);
187 Log3(("vmmdevMaybeSetIRQ_EMT: IRQ set.\n"));
188 }
189}
190
191static void vmmdevNotifyGuest_EMT (VMMDevState *pVMMDevState, uint32_t u32EventMask)
192{
193 Log3(("VMMDevNotifyGuest_EMT: u32EventMask = 0x%08X.\n", u32EventMask));
194
195 if (VBOX_GUEST_INTERFACE_VERSION_1_03 (pVMMDevState))
196 {
197 Log3(("VMMDevNotifyGuest_EMT: Old additions detected.\n"));
198
199 pVMMDevState->u32HostEventFlags |= u32EventMask;
200 vmmdevSetIRQ_Legacy_EMT (pVMMDevState);
201 }
202 else
203 {
204 Log3(("VMMDevNotifyGuest_EMT: New additions detected.\n"));
205
206 if (!pVMMDevState->fu32AdditionsOk)
207 {
208 pVMMDevState->u32HostEventFlags |= u32EventMask;
209 Log(("vmmdevNotifyGuest_EMT: IRQ is not generated, guest has not yet reported to us.\n"));
210 return;
211 }
212
213 const bool fHadEvents =
214 (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
215
216 Log3(("VMMDevNotifyGuest_EMT: fHadEvents = %d, u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
217 fHadEvents, pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
218
219 pVMMDevState->u32HostEventFlags |= u32EventMask;
220
221 if (!fHadEvents)
222 vmmdevMaybeSetIRQ_EMT (pVMMDevState);
223 }
224}
225
226void VMMDevCtlSetGuestFilterMask (VMMDevState *pVMMDevState,
227 uint32_t u32OrMask,
228 uint32_t u32NotMask)
229{
230 PDMCritSectEnter(&pVMMDevState->CritSect, VERR_SEM_BUSY);
231
232 const bool fHadEvents =
233 (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
234
235 Log(("VMMDevCtlSetGuestFilterMask: u32OrMask = 0x%08X, u32NotMask = 0x%08X, fHadEvents = %d.\n", u32OrMask, u32NotMask, fHadEvents));
236 if (fHadEvents)
237 {
238 if (!pVMMDevState->fNewGuestFilterMask)
239 pVMMDevState->u32NewGuestFilterMask = pVMMDevState->u32GuestFilterMask;
240
241 pVMMDevState->u32NewGuestFilterMask |= u32OrMask;
242 pVMMDevState->u32NewGuestFilterMask &= ~u32NotMask;
243 pVMMDevState->fNewGuestFilterMask = true;
244 }
245 else
246 {
247 pVMMDevState->u32GuestFilterMask |= u32OrMask;
248 pVMMDevState->u32GuestFilterMask &= ~u32NotMask;
249 vmmdevMaybeSetIRQ_EMT (pVMMDevState);
250 }
251 PDMCritSectLeave(&pVMMDevState->CritSect);
252}
253
254void VMMDevNotifyGuest (VMMDevState *pVMMDevState, uint32_t u32EventMask)
255{
256 PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
257
258 Log3(("VMMDevNotifyGuest: u32EventMask = 0x%08X.\n", u32EventMask));
259
260 /*
261 * Drop notifications if the VM is not running yet/anymore.
262 */
263 VMSTATE enmVMState = PDMDevHlpVMState(pDevIns);
264 if ( enmVMState != VMSTATE_RUNNING
265 && enmVMState != VMSTATE_RUNNING_LS)
266 return;
267
268 PDMCritSectEnter(&pVMMDevState->CritSect, VERR_SEM_BUSY);
269 /* No need to wait for the completion of this request. It is a notification
270 * about something, which has already happened.
271 */
272 vmmdevNotifyGuest_EMT(pVMMDevState, u32EventMask);
273 PDMCritSectLeave(&pVMMDevState->CritSect);
274}
275
276/**
277 * Port I/O Handler for OUT operations.
278 *
279 * @returns VBox status code.
280 *
281 * @param pDevIns The device instance.
282 * @param pvUser User argument - ignored.
283 * @param uPort Port number used for the IN operation.
284 * @param u32 The value to output.
285 * @param cb The value size in bytes.
286 */
287static DECLCALLBACK(int) vmmdevBackdoorLog(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
288{
289 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
290
291 if (!pThis->fBackdoorLogDisabled && cb == 1 && Port == RTLOG_DEBUG_PORT)
292 {
293
294 /* The raw version. */
295 switch (u32)
296 {
297 case '\r': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <return>\n")); break;
298 case '\n': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <newline>\n")); break;
299 case '\t': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <tab>\n")); break;
300 default: LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: %c (%02x)\n", u32, u32)); break;
301 }
302
303 /* The readable, buffered version. */
304 if (u32 == '\n' || u32 == '\r')
305 {
306 pThis->szMsg[pThis->iMsg] = '\0';
307 if (pThis->iMsg)
308 LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("Guest Log: %s\n", pThis->szMsg));
309 pThis->iMsg = 0;
310 }
311 else
312 {
313 if (pThis->iMsg >= sizeof(pThis->szMsg)-1)
314 {
315 pThis->szMsg[pThis->iMsg] = '\0';
316 LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("Guest Log: %s\n", pThis->szMsg));
317 pThis->iMsg = 0;
318 }
319 pThis->szMsg[pThis->iMsg] = (char )u32;
320 pThis->szMsg[++pThis->iMsg] = '\0';
321 }
322 }
323 return VINF_SUCCESS;
324}
325
326#ifdef TIMESYNC_BACKDOOR
327/**
328 * Port I/O Handler for OUT operations.
329 *
330 * @returns VBox status code.
331 *
332 * @param pDevIns The device instance.
333 * @param pvUser User argument - ignored.
334 * @param uPort Port number used for the IN operation.
335 * @param u32 The value to output.
336 * @param cb The value size in bytes.
337 */
338static DECLCALLBACK(int) vmmdevTimesyncBackdoorWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
339{
340 NOREF(pvUser);
341 if (cb == 4)
342 {
343 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
344 switch (u32)
345 {
346 case 0:
347 pThis->fTimesyncBackdoorLo = false;
348 break;
349 case 1:
350 pThis->fTimesyncBackdoorLo = true;
351 }
352 return VINF_SUCCESS;
353
354 }
355 return VINF_SUCCESS;
356}
357
358/**
359 * Port I/O Handler for backdoor timesync IN operations.
360 *
361 * @returns VBox status code.
362 *
363 * @param pDevIns The device instance.
364 * @param pvUser User argument - ignored.
365 * @param uPort Port number used for the IN operation.
366 * @param pu32 Where to store the result.
367 * @param cb Number of bytes read.
368 */
369static DECLCALLBACK(int) vmmdevTimesyncBackdoorRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
370{
371 int rc;
372 NOREF(pvUser);
373 if (cb == 4)
374 {
375 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
376 RTTIMESPEC now;
377
378 if (pThis->fTimesyncBackdoorLo)
379 *pu32 = (uint32_t)pThis->hostTime;
380 else
381 {
382 pThis->hostTime = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
383 *pu32 = (uint32_t)(pThis->hostTime >> 32);
384 }
385 rc = VINF_SUCCESS;
386 }
387 else
388 rc = VERR_IOM_IOPORT_UNUSED;
389 return rc;
390}
391#endif /* TIMESYNC_BACKDOOR */
392
393/**
394 * Validates a publisher tag.
395 *
396 * @returns true / false.
397 * @param pszTag Tag to validate.
398 */
399static bool vmmdevReqIsValidPublisherTag(const char *pszTag)
400{
401 /* Note! This character set is also found in Config.kmk. */
402 static char const s_szValidChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz()[]{}+-.,";
403
404 while (*pszTag != '\0')
405 {
406 if (!strchr(s_szValidChars, *pszTag))
407 return false;
408 pszTag++;
409 }
410 return true;
411}
412
413
414/**
415 * Validates a build tag.
416 *
417 * @returns true / false.
418 * @param pszTag Tag to validate.
419 */
420static bool vmmdevReqIsValidBuildTag(const char *pszTag)
421{
422 int cchPrefix;
423 if (!strncmp(pszTag, "RC", 2))
424 cchPrefix = 2;
425 else if (!strncmp(pszTag, "BETA", 4))
426 cchPrefix = 4;
427 else if (!strncmp(pszTag, "ALPHA", 5))
428 cchPrefix = 5;
429 else
430 return false;
431
432 if (pszTag[cchPrefix] == '\0')
433 return true;
434
435 uint8_t u8;
436 int rc = RTStrToUInt8Full(&pszTag[cchPrefix], 10, &u8);
437 return rc == VINF_SUCCESS;
438}
439
440/**
441 * Handles VMMDevReq_ReportGuestInfo2.
442 *
443 * @returns VBox status code that the guest should see.
444 * @param pThis The VMMDev instance data.
445 * @param pRequestHeader The header of the request to handle.
446 */
447static int vmmdevReqHandler_ReportGuestInfo2(VMMDevState *pThis, VMMDevRequestHeader *pRequestHeader)
448{
449 AssertMsgReturn(pRequestHeader->size == sizeof(VMMDevReportGuestInfo2), ("%u\n", pRequestHeader->size), VERR_INVALID_PARAMETER);
450 VBoxGuestInfo2 const *pInfo2 = &((VMMDevReportGuestInfo2 *)pRequestHeader)->guestInfo;
451
452 LogRel(("Guest Additions information report: Version %d.%d.%d r%d '%.*s'\n",
453 pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild,
454 pInfo2->additionsRevision, sizeof(pInfo2->szName), pInfo2->szName));
455
456 /* The interface was introduced in 3.2 and will definitely not be
457 backported beyond 3.0 (bird). */
458 AssertMsgReturn(pInfo2->additionsMajor >= 3,
459 ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
460 VERR_INVALID_PARAMETER);
461
462 /* The version must fit in a full version compression. */
463 uint32_t uFullVersion = VBOX_FULL_VERSION_MAKE(pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
464 AssertMsgReturn( VBOX_FULL_VERSION_GET_MAJOR(uFullVersion) == pInfo2->additionsMajor
465 && VBOX_FULL_VERSION_GET_MINOR(uFullVersion) == pInfo2->additionsMinor
466 && VBOX_FULL_VERSION_GET_BUILD(uFullVersion) == pInfo2->additionsBuild,
467 ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
468 VERR_OUT_OF_RANGE);
469
470 /*
471 * Validate the name.
472 * Be less strict towards older additions (< v4.1.50).
473 */
474 AssertCompile(sizeof(pThis->guestInfo2.szName) == sizeof(pInfo2->szName));
475 AssertReturn(memchr(pInfo2->szName, '\0', sizeof(pInfo2->szName)) != NULL, VERR_INVALID_PARAMETER);
476 const char *pszName = pInfo2->szName;
477
478 /* The version number which shouldn't be there. */
479 char szTmp[sizeof(pInfo2->szName)];
480 size_t cchStart = RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
481 AssertMsgReturn(!strncmp(pszName, szTmp, cchStart), ("%s != %s\n", pszName, szTmp), VERR_INVALID_PARAMETER);
482 pszName += cchStart;
483
484 /* Now we can either have nothing or a build tag or/and a publisher tag. */
485 if (*pszName != '\0')
486 {
487 const char *pszRelaxedName = "";
488 bool const fStrict = pInfo2->additionsMajor > 4
489 || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor > 1)
490 || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor == 1 && pInfo2->additionsBuild >= 50);
491 bool fOk = false;
492 if (*pszName == '_')
493 {
494 pszName++;
495 strcpy(szTmp, pszName);
496 char *pszTag2 = strchr(szTmp, '_');
497 if (!pszTag2)
498 {
499 fOk = vmmdevReqIsValidBuildTag(szTmp)
500 || vmmdevReqIsValidPublisherTag(szTmp);
501 }
502 else
503 {
504 *pszTag2++ = '\0';
505 fOk = vmmdevReqIsValidBuildTag(szTmp);
506 if (fOk)
507 {
508 fOk = vmmdevReqIsValidPublisherTag(pszTag2);
509 if (!fOk)
510 pszRelaxedName = szTmp;
511 }
512 }
513 }
514
515 if (!fOk)
516 {
517 AssertLogRelMsgReturn(!fStrict, ("%s", pszName), VERR_INVALID_PARAMETER);
518
519 /* non-strict mode, just zap the extra stuff. */
520 LogRel(("ReportGuestInfo2: Ignoring unparsable version name bits: '%s' -> '%s'.\n", pszName, pszRelaxedName));
521 pszName = pszRelaxedName;
522 }
523 }
524
525 /*
526 * Save the info and tell Main or whoever is listening.
527 */
528 pThis->guestInfo2.uFullVersion = uFullVersion;
529 pThis->guestInfo2.uRevision = pInfo2->additionsRevision;
530 pThis->guestInfo2.fFeatures = pInfo2->additionsFeatures;
531 strcpy(pThis->guestInfo2.szName, pszName);
532
533 pThis->pDrv->pfnUpdateGuestInfo2(pThis->pDrv, uFullVersion, pszName, pInfo2->additionsRevision, pInfo2->additionsFeatures);
534
535 return VINF_SUCCESS;
536}
537
538/**
539 * Port I/O Handler for the generic request interface
540 * @see FNIOMIOPORTOUT for details.
541 *
542 * @todo Too long, suggest doing the request copying here and moving the
543 * switch into a different function (or better case -> functions), and
544 * looing the gotos.
545 */
546static DECLCALLBACK(int) vmmdevRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
547{
548 VMMDevState *pThis = (VMMDevState*)pvUser;
549 int rcRet = VINF_SUCCESS;
550 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
551
552 /*
553 * The caller has passed the guest context physical address
554 * of the request structure. Copy the request packet.
555 */
556 VMMDevRequestHeader *pRequestHeader = NULL;
557 VMMDevRequestHeader requestHeader;
558 RT_ZERO(requestHeader);
559
560 PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
561
562 /* the structure size must be greater or equal to the header size */
563 if (requestHeader.size < sizeof(VMMDevRequestHeader))
564 {
565 Log(("VMMDev request header size too small! size = %d\n", requestHeader.size));
566 rcRet = VINF_SUCCESS;
567 goto l_end; /** @todo shouldn't (/ no need to) write back.*/
568 }
569
570 /* check the version of the header structure */
571 if (requestHeader.version != VMMDEV_REQUEST_HEADER_VERSION)
572 {
573 Log(("VMMDev: guest header version (0x%08X) differs from ours (0x%08X)\n", requestHeader.version, VMMDEV_REQUEST_HEADER_VERSION));
574 rcRet = VINF_SUCCESS;
575 goto l_end; /** @todo shouldn't (/ no need to) write back.*/
576 }
577
578 Log2(("VMMDev request issued: %d\n", requestHeader.requestType));
579
580 /* Newer additions starts with VMMDevReq_ReportGuestInfo2, older additions
581 started with VMMDevReq_ReportGuestInfo. */
582 if ( !pThis->fu32AdditionsOk
583 && requestHeader.requestType != VMMDevReq_ReportGuestInfo2
584 && requestHeader.requestType != VMMDevReq_ReportGuestInfo
585 && requestHeader.requestType != VMMDevReq_WriteCoreDump
586 && requestHeader.requestType != VMMDevReq_GetHostVersion) /* Always allow the guest to query the host capabilities. */
587 {
588 Log(("VMMDev: guest has not yet reported to us. Refusing operation of request #%d!\n",
589 requestHeader.requestType));
590 requestHeader.rc = VERR_NOT_SUPPORTED;
591 static int cRelWarn;
592 if (cRelWarn < 10)
593 {
594 cRelWarn++;
595 LogRel(("VMMDev: the guest has not yet reported to us -- refusing operation of request #%d\n",
596 requestHeader.requestType));
597 }
598 rcRet = VINF_SUCCESS;
599 goto l_end;
600 }
601
602 /* Check upper limit */
603 if (requestHeader.size > VMMDEV_MAX_VMMDEVREQ_SIZE)
604 {
605 static int cRelWarn;
606 if (cRelWarn < 50)
607 {
608 cRelWarn++;
609 LogRel(("VMMDev: request packet too big (%x). Refusing operation.\n", requestHeader.size));
610 }
611 requestHeader.rc = VERR_NOT_SUPPORTED;
612 rcRet = VINF_SUCCESS;
613 goto l_end;
614 }
615
616 /* Read the entire request packet */
617 pRequestHeader = (VMMDevRequestHeader *)RTMemAlloc(requestHeader.size);
618 if (!pRequestHeader)
619 {
620 Log(("VMMDev: RTMemAlloc failed!\n"));
621 rcRet = VINF_SUCCESS;
622 requestHeader.rc = VERR_NO_MEMORY;
623 goto l_end;
624 }
625 PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, pRequestHeader, requestHeader.size);
626
627 /* which request was sent? */
628 switch (pRequestHeader->requestType)
629 {
630 /*
631 * Guest wants to give up a timeslice
632 */
633 case VMMDevReq_Idle:
634 {
635 /* just return to EMT telling it that we want to halt */
636 rcRet = VINF_EM_HALT;
637 break;
638 }
639
640 /*
641 * Guest is reporting its information
642 */
643 case VMMDevReq_ReportGuestInfo:
644 {
645 AssertMsgBreakStmt(pRequestHeader->size == sizeof(VMMDevReportGuestInfo), ("%u\n", pRequestHeader->size),
646 pRequestHeader->rc = VERR_INVALID_PARAMETER);
647 VBoxGuestInfo *pGuestInfo = &((VMMDevReportGuestInfo*)pRequestHeader)->guestInfo;
648
649 if (memcmp(&pThis->guestInfo, pGuestInfo, sizeof(*pGuestInfo)) != 0)
650 {
651 /* make a copy of supplied information */
652 pThis->guestInfo = *pGuestInfo;
653
654 /* Check additions version */
655 pThis->fu32AdditionsOk = VBOX_GUEST_INTERFACE_VERSION_OK(pThis->guestInfo.interfaceVersion);
656
657 LogRel(("Guest Additions information report: Interface = 0x%08X osType = 0x%08X\n",
658 pThis->guestInfo.interfaceVersion,
659 pThis->guestInfo.osType));
660 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
661 }
662
663 if (pThis->fu32AdditionsOk)
664 pRequestHeader->rc = VINF_SUCCESS;
665 else
666 pRequestHeader->rc = VERR_VERSION_MISMATCH;
667 break;
668 }
669
670 case VMMDevReq_ReportGuestInfo2:
671 {
672 pRequestHeader->rc = vmmdevReqHandler_ReportGuestInfo2(pThis, pRequestHeader);
673 break;
674 }
675
676 case VMMDevReq_WriteCoreDump:
677 {
678 if (pRequestHeader->size != sizeof(VMMDevReqWriteCoreDump))
679 {
680 AssertMsgFailed(("VMMDev WriteCoreDump structure has an invalid size!\n"));
681 pRequestHeader->rc = VERR_INVALID_PARAMETER;
682 }
683 else
684 {
685 if (pThis->fGuestCoreDumpEnabled)
686 {
687 /*
688 * User makes sure the directory exists.
689 */
690 if (!RTDirExists(pThis->szGuestCoreDumpDir))
691 return VERR_PATH_NOT_FOUND;
692
693 char szCorePath[RTPATH_MAX];
694 RTStrCopy(szCorePath, sizeof(szCorePath), pThis->szGuestCoreDumpDir);
695 RTPathAppend(szCorePath, sizeof(szCorePath), "VBox.core");
696
697 /*
698 * Rotate existing cores based on number of additional cores to keep around.
699 */
700 if (pThis->cGuestCoreDumps > 0)
701 for (int64_t i = pThis->cGuestCoreDumps - 1; i >= 0; i--)
702 {
703 char szFilePathOld[RTPATH_MAX];
704 if (i == 0)
705 RTStrCopy(szFilePathOld, sizeof(szFilePathOld), szCorePath);
706 else
707 RTStrPrintf(szFilePathOld, sizeof(szFilePathOld), "%s.%d", szCorePath, i);
708
709 char szFilePathNew[RTPATH_MAX];
710 RTStrPrintf(szFilePathNew, sizeof(szFilePathNew), "%s.%d", szCorePath, i + 1);
711 int vrc = RTFileMove(szFilePathOld, szFilePathNew, RTFILEMOVE_FLAGS_REPLACE);
712 if (vrc == VERR_FILE_NOT_FOUND)
713 RTFileDelete(szFilePathNew);
714 }
715
716 /*
717 * Write the core file.
718 */
719 PVM pVM = PDMDevHlpGetVM(pDevIns);
720 pRequestHeader->rc = DBGFR3CoreWrite(pVM, szCorePath, true /*fReplaceFile*/);
721 }
722 else
723 pRequestHeader->rc = VERR_ACCESS_DENIED;
724 }
725 break;
726 }
727
728 case VMMDevReq_ReportGuestStatus:
729 {
730 if (pRequestHeader->size != sizeof(VMMDevReportGuestStatus))
731 {
732 AssertMsgFailed(("VMMDev guest status structure has an invalid size!\n"));
733 pRequestHeader->rc = VERR_INVALID_PARAMETER;
734 }
735 else
736 {
737 /** @todo r=bird: VMMDev (or GuestImpl.cpp) needs to remember this stuff and
738 * tell Main after a state restore! */
739 VBoxGuestStatus *guestStatus = &((VMMDevReportGuestStatus*)pRequestHeader)->guestStatus;
740 pThis->pDrv->pfnUpdateGuestStatus(pThis->pDrv, guestStatus);
741
742 pRequestHeader->rc = VINF_SUCCESS;
743 }
744 break;
745 }
746
747 /* Report guest capabilities */
748 case VMMDevReq_ReportGuestCapabilities:
749 {
750 if (pRequestHeader->size != sizeof(VMMDevReqGuestCapabilities))
751 {
752 AssertMsgFailed(("VMMDev guest caps structure has invalid size!\n"));
753 pRequestHeader->rc = VERR_INVALID_PARAMETER;
754 }
755 else
756 {
757 VMMDevReqGuestCapabilities *guestCaps = (VMMDevReqGuestCapabilities*)pRequestHeader;
758
759 /* Enable this automatically for guests using the old
760 request to report their capabilities. */
761 /** @todo change this when we next bump the interface version */
762 guestCaps->caps |= VMMDEV_GUEST_SUPPORTS_GRAPHICS;
763 if (pThis->guestCaps != guestCaps->caps)
764 {
765 /* make a copy of supplied information */
766 pThis->guestCaps = guestCaps->caps;
767
768 LogRel(("Guest Additions capability report: (0x%x) "
769 "seamless: %s, "
770 "hostWindowMapping: %s, "
771 "graphics: %s\n",
772 guestCaps->caps,
773 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
774 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
775 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
776
777 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, guestCaps->caps);
778 }
779 pRequestHeader->rc = VINF_SUCCESS;
780 }
781 break;
782 }
783
784 /* Change guest capabilities */
785 case VMMDevReq_SetGuestCapabilities:
786 {
787 if (pRequestHeader->size != sizeof(VMMDevReqGuestCapabilities2))
788 {
789 AssertMsgFailed(("VMMDev guest caps structure has invalid size!\n"));
790 pRequestHeader->rc = VERR_INVALID_PARAMETER;
791 }
792 else
793 {
794 VMMDevReqGuestCapabilities2 *guestCaps = (VMMDevReqGuestCapabilities2*)pRequestHeader;
795
796 pThis->guestCaps |= guestCaps->u32OrMask;
797 pThis->guestCaps &= ~guestCaps->u32NotMask;
798
799 LogRel(("Guest Additions capability report: (0x%x) "
800 "seamless: %s, "
801 "hostWindowMapping: %s, "
802 "graphics: %s\n",
803 pThis->guestCaps,
804 pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
805 pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
806 pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
807
808 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
809 pRequestHeader->rc = VINF_SUCCESS;
810 }
811 break;
812 }
813
814 /*
815 * Retrieve mouse information
816 */
817 case VMMDevReq_GetMouseStatus:
818 {
819 if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
820 {
821 AssertMsgFailed(("VMMDev mouse status structure has invalid size!\n"));
822 pRequestHeader->rc = VERR_INVALID_PARAMETER;
823 }
824 else
825 {
826 VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)pRequestHeader;
827 mouseStatus->mouseFeatures = pThis->mouseCapabilities
828 & VMMDEV_MOUSE_MASK;
829 mouseStatus->pointerXPos = pThis->mouseXAbs;
830 mouseStatus->pointerYPos = pThis->mouseYAbs;
831 LogRel2(("%s: VMMDevReq_GetMouseStatus: features = 0x%x, absX = %d, absY = %d\n",
832 __PRETTY_FUNCTION__,
833 mouseStatus->mouseFeatures,
834 mouseStatus->pointerXPos,
835 mouseStatus->pointerYPos));
836 pRequestHeader->rc = VINF_SUCCESS;
837 }
838 break;
839 }
840
841 /*
842 * Set mouse information
843 */
844 case VMMDevReq_SetMouseStatus:
845 {
846 if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
847 {
848 AssertMsgFailed(("VMMDev mouse status structure has invalid size %d (%#x) version=%d!\n",
849 pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
850 pRequestHeader->rc = VERR_INVALID_PARAMETER;
851 }
852 else
853 {
854 bool fNotify = false;
855
856 uint32_t fFeatures =
857 ((VMMDevReqMouseStatus*)pRequestHeader)->mouseFeatures;
858
859 LogRelFlowFunc(("VMMDevReqMouseStatus: mouseFeatures = 0x%x\n",
860 fFeatures));
861
862 if ( (fFeatures & VMMDEV_MOUSE_NOTIFY_HOST_MASK)
863 != ( pThis->mouseCapabilities
864 & VMMDEV_MOUSE_NOTIFY_HOST_MASK))
865 fNotify = true;
866 pThis->mouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
867 pThis->mouseCapabilities |=
868 (fFeatures & VMMDEV_MOUSE_GUEST_MASK);
869 LogRelFlowFunc(("VMMDevReq_SetMouseStatus: new host capabilities: 0x%x\n",
870 pThis->mouseCapabilities));
871
872 /*
873 * Notify connector if something has changed
874 */
875 if (fNotify)
876 {
877 LogRelFlowFunc(("VMMDevReq_SetMouseStatus: notifying connector\n"));
878 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
879 }
880 pRequestHeader->rc = VINF_SUCCESS;
881 }
882
883 break;
884 }
885
886 /*
887 * Set a new mouse pointer shape
888 */
889 case VMMDevReq_SetPointerShape:
890 {
891 if (pRequestHeader->size < sizeof(VMMDevReqMousePointer))
892 {
893 AssertMsg(pRequestHeader->size == 0x10028 && pRequestHeader->version == 10000, /* don't complain about legacy!!! */
894 ("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
895 pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
896 pRequestHeader->rc = VERR_INVALID_PARAMETER;
897 }
898 else
899 {
900 VMMDevReqMousePointer *pointerShape = (VMMDevReqMousePointer*)pRequestHeader;
901
902 bool fVisible = (pointerShape->fFlags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
903 bool fAlpha = (pointerShape->fFlags & VBOX_MOUSE_POINTER_ALPHA) != 0;
904 bool fShape = (pointerShape->fFlags & VBOX_MOUSE_POINTER_SHAPE) != 0;
905
906 Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
907 fVisible, fAlpha, fShape, pointerShape->width, pointerShape->height));
908
909 if (pRequestHeader->size == sizeof(VMMDevReqMousePointer))
910 {
911 /* The guest did not provide the shape actually. */
912 fShape = false;
913 }
914
915 /* forward call to driver */
916 if (fShape)
917 {
918 pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
919 fVisible,
920 fAlpha,
921 pointerShape->xHot, pointerShape->yHot,
922 pointerShape->width, pointerShape->height,
923 pointerShape->pointerData);
924 }
925 else
926 {
927 pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
928 fVisible,
929 0,
930 0, 0,
931 0, 0,
932 NULL);
933 }
934 pThis->fHostCursorRequested = fVisible;
935 pRequestHeader->rc = VINF_SUCCESS;
936 }
937 break;
938 }
939
940 /*
941 * Query the system time from the host
942 */
943 case VMMDevReq_GetHostTime:
944 {
945 if (pRequestHeader->size != sizeof(VMMDevReqHostTime))
946 {
947 AssertMsgFailed(("VMMDev host time structure has invalid size!\n"));
948 pRequestHeader->rc = VERR_INVALID_PARAMETER;
949 }
950 else if (RT_UNLIKELY(pThis->fGetHostTimeDisabled))
951 pRequestHeader->rc = VERR_NOT_SUPPORTED;
952 else
953 {
954 VMMDevReqHostTime *hostTimeReq = (VMMDevReqHostTime*)pRequestHeader;
955 RTTIMESPEC now;
956 hostTimeReq->time = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
957 pRequestHeader->rc = VINF_SUCCESS;
958 }
959 break;
960 }
961
962 /*
963 * Query information about the hypervisor
964 */
965 case VMMDevReq_GetHypervisorInfo:
966 {
967 if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
968 {
969 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
970 pRequestHeader->rc = VERR_INVALID_PARAMETER;
971 }
972 else
973 {
974 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
975 PVM pVM = PDMDevHlpGetVM(pDevIns);
976 pRequestHeader->rc = PGMR3MappingsSize(pVM, &hypervisorInfo->hypervisorSize);
977 }
978 break;
979 }
980
981 /*
982 * Set hypervisor information
983 */
984 case VMMDevReq_SetHypervisorInfo:
985 {
986 if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
987 {
988 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
989 pRequestHeader->rc = VERR_INVALID_PARAMETER;
990 }
991 else
992 {
993 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
994 PVM pVM = PDMDevHlpGetVM(pDevIns);
995 if (hypervisorInfo->hypervisorStart == 0)
996 pRequestHeader->rc = PGMR3MappingsUnfix(pVM);
997 else
998 {
999 /* only if the client has queried the size before! */
1000 uint32_t mappingsSize;
1001 pRequestHeader->rc = PGMR3MappingsSize(pVM, &mappingsSize);
1002 if (RT_SUCCESS(pRequestHeader->rc) && hypervisorInfo->hypervisorSize == mappingsSize)
1003 {
1004 /* new reservation */
1005 pRequestHeader->rc = PGMR3MappingsFix(pVM, hypervisorInfo->hypervisorStart,
1006 hypervisorInfo->hypervisorSize);
1007 LogRel(("Guest reported fixed hypervisor window at 0x%p (size = 0x%x, rc = %Rrc)\n",
1008 (uintptr_t)hypervisorInfo->hypervisorStart,
1009 hypervisorInfo->hypervisorSize,
1010 pRequestHeader->rc));
1011 }
1012 }
1013 }
1014 break;
1015 }
1016
1017 case VMMDevReq_RegisterPatchMemory:
1018 {
1019 if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
1020 {
1021 AssertMsgFailed(("VMMDevReq_RegisterPatchMemory structure has invalid size!\n"));
1022 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1023 }
1024 else
1025 {
1026 VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
1027
1028 pRequestHeader->rc = VMMR3RegisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
1029 }
1030 break;
1031 }
1032
1033 case VMMDevReq_DeregisterPatchMemory:
1034 {
1035 if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
1036 {
1037 AssertMsgFailed(("VMMDevReq_DeregisterPatchMemory structure has invalid size!\n"));
1038 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1039 }
1040 else
1041 {
1042 VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
1043
1044 pRequestHeader->rc = VMMR3DeregisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
1045 }
1046 break;
1047 }
1048
1049 /*
1050 * Set the system power status
1051 */
1052 case VMMDevReq_SetPowerStatus:
1053 {
1054 if (pRequestHeader->size != sizeof(VMMDevPowerStateRequest))
1055 {
1056 AssertMsgFailed(("VMMDev power state request structure has invalid size!\n"));
1057 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1058 }
1059 else
1060 {
1061 VMMDevPowerStateRequest *powerStateRequest = (VMMDevPowerStateRequest*)pRequestHeader;
1062 switch(powerStateRequest->powerState)
1063 {
1064 case VMMDevPowerState_Pause:
1065 {
1066 LogRel(("Guest requests the VM to be suspended (paused)\n"));
1067 pRequestHeader->rc = rcRet = PDMDevHlpVMSuspend(pDevIns);
1068 break;
1069 }
1070
1071 case VMMDevPowerState_PowerOff:
1072 {
1073 LogRel(("Guest requests the VM to be turned off\n"));
1074 pRequestHeader->rc = rcRet = PDMDevHlpVMPowerOff(pDevIns);
1075 break;
1076 }
1077
1078 case VMMDevPowerState_SaveState:
1079 {
1080 if (true /*pThis->fAllowGuestToSaveState*/)
1081 {
1082 LogRel(("Guest requests the VM to be saved and powered off\n"));
1083 pRequestHeader->rc = rcRet = PDMDevHlpVMSuspendSaveAndPowerOff(pDevIns);
1084 }
1085 else
1086 {
1087 LogRel(("Guest requests the VM to be saved and powered off, declined\n"));
1088 pRequestHeader->rc = VERR_ACCESS_DENIED;
1089 }
1090 break;
1091 }
1092
1093 default:
1094 AssertMsgFailed(("VMMDev invalid power state request: %d\n", powerStateRequest->powerState));
1095 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1096 break;
1097 }
1098 }
1099 break;
1100 }
1101
1102 /*
1103 * Retrieve a display resize request sent by the host using
1104 * @a IDisplay:setVideoModeHint. Deprecated.
1105 * See documentation in VMMDev.h.
1106 */
1107 /**
1108 * @todo It looks like a multi-monitor guest which only uses
1109 * @a VMMDevReq_GetDisplayChangeRequest (not the *2 version)
1110 * will get into a @a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST event
1111 * loop if it tries to acknowlege host requests for additional
1112 * monitors. Should the loop which checks for those requests
1113 * be removed?
1114 */
1115 case VMMDevReq_GetDisplayChangeRequest:
1116 {
1117 if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest))
1118 {
1119 /* Assert only if the size also not equal to a previous version size to prevent
1120 * assertion with old additions.
1121 */
1122 AssertMsg(pRequestHeader->size == sizeof(VMMDevDisplayChangeRequest) - sizeof (uint32_t),
1123 ("VMMDev display change request structure has invalid size!\n"));
1124 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1125 }
1126 else
1127 {
1128 VMMDevDisplayChangeRequest *displayChangeRequest = (VMMDevDisplayChangeRequest*)pRequestHeader;
1129
1130 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[0];
1131
1132 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1133 {
1134 /* Current request has been read at least once. */
1135 pRequest->fPending = false;
1136
1137 /* Check if there are more pending requests. */
1138 for (unsigned i = 1; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1139 {
1140 if (pThis->displayChangeData.aRequests[i].fPending)
1141 {
1142 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1143 break;
1144 }
1145 }
1146
1147 /* Remember which resolution the client has queried, subsequent reads
1148 * will return the same values. */
1149 pRequest->lastReadDisplayChangeRequest = pRequest->displayChangeRequest;
1150 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1151 }
1152
1153 if (pThis->displayChangeData.fGuestSentChangeEventAck)
1154 {
1155 displayChangeRequest->xres = pRequest->lastReadDisplayChangeRequest.xres;
1156 displayChangeRequest->yres = pRequest->lastReadDisplayChangeRequest.yres;
1157 displayChangeRequest->bpp = pRequest->lastReadDisplayChangeRequest.bpp;
1158 }
1159 else
1160 {
1161 /* This is not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1162 * read the last valid video mode hint. This happens when the guest X server
1163 * determines the initial mode. */
1164 displayChangeRequest->xres = pRequest->displayChangeRequest.xres;
1165 displayChangeRequest->yres = pRequest->displayChangeRequest.yres;
1166 displayChangeRequest->bpp = pRequest->displayChangeRequest.bpp;
1167 }
1168 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n",
1169 displayChangeRequest->xres, displayChangeRequest->yres, displayChangeRequest->bpp));
1170
1171 pRequestHeader->rc = VINF_SUCCESS;
1172 }
1173 break;
1174 }
1175
1176 /*
1177 * Retrieve a display resize request sent by the host using
1178 * @a IDisplay:setVideoModeHint.
1179 * See documentation in VMMDev.h.
1180 */
1181 case VMMDevReq_GetDisplayChangeRequest2:
1182 {
1183 if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest2))
1184 {
1185 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1186 }
1187 else
1188 {
1189 VMMDevDisplayChangeRequest2 *displayChangeRequest = (VMMDevDisplayChangeRequest2*)pRequestHeader;
1190
1191 DISPLAYCHANGEREQUEST *pRequest = NULL;
1192
1193 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1194 {
1195 /* Select a pending request to report. */
1196 unsigned i;
1197 for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1198 {
1199 if (pThis->displayChangeData.aRequests[i].fPending)
1200 {
1201 pRequest = &pThis->displayChangeData.aRequests[i];
1202 /* Remember which request should be reported. */
1203 pThis->displayChangeData.iCurrentMonitor = i;
1204 Log3(("VMMDev: will report pending request for %d\n",
1205 i));
1206 break;
1207 }
1208 }
1209
1210 /* Check if there are more pending requests. */
1211 i++;
1212 for (; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1213 {
1214 if (pThis->displayChangeData.aRequests[i].fPending)
1215 {
1216 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1217 Log3(("VMMDev: another pending at %d\n",
1218 i));
1219 break;
1220 }
1221 }
1222
1223 if (pRequest)
1224 {
1225 /* Current request has been read at least once. */
1226 pRequest->fPending = false;
1227
1228 /* Remember which resolution the client has queried, subsequent reads
1229 * will return the same values. */
1230 pRequest->lastReadDisplayChangeRequest = pRequest->displayChangeRequest;
1231 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1232 }
1233 else
1234 {
1235 Log3(("VMMDev: no pending request!!!\n"));
1236 }
1237 }
1238
1239 if (!pRequest)
1240 {
1241 Log3(("VMMDev: default to %d\n",
1242 pThis->displayChangeData.iCurrentMonitor));
1243 pRequest = &pThis->displayChangeData.aRequests[pThis->displayChangeData.iCurrentMonitor];
1244 }
1245
1246 if (pThis->displayChangeData.fGuestSentChangeEventAck)
1247 {
1248 displayChangeRequest->xres = pRequest->lastReadDisplayChangeRequest.xres;
1249 displayChangeRequest->yres = pRequest->lastReadDisplayChangeRequest.yres;
1250 displayChangeRequest->bpp = pRequest->lastReadDisplayChangeRequest.bpp;
1251 displayChangeRequest->display = pRequest->lastReadDisplayChangeRequest.display;
1252 }
1253 else
1254 {
1255 /* This is not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1256 * read the last valid video mode hint. This happens when the guest X server
1257 * determines the initial video mode. */
1258 displayChangeRequest->xres = pRequest->displayChangeRequest.xres;
1259 displayChangeRequest->yres = pRequest->displayChangeRequest.yres;
1260 displayChangeRequest->bpp = pRequest->displayChangeRequest.bpp;
1261 displayChangeRequest->display = pRequest->displayChangeRequest.display;
1262 }
1263 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
1264 displayChangeRequest->xres, displayChangeRequest->yres, displayChangeRequest->bpp, displayChangeRequest->display));
1265
1266 pRequestHeader->rc = VINF_SUCCESS;
1267 }
1268 break;
1269 }
1270
1271 /*
1272 * Query whether the given video mode is supported
1273 */
1274 case VMMDevReq_VideoModeSupported:
1275 {
1276 if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest))
1277 {
1278 AssertMsgFailed(("VMMDev video mode supported request structure has invalid size!\n"));
1279 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1280 }
1281 else
1282 {
1283 VMMDevVideoModeSupportedRequest *videoModeSupportedRequest = (VMMDevVideoModeSupportedRequest*)pRequestHeader;
1284 /* forward the call */
1285 pRequestHeader->rc = pThis->pDrv->pfnVideoModeSupported(pThis->pDrv,
1286 0, /* primary screen. */
1287 videoModeSupportedRequest->width,
1288 videoModeSupportedRequest->height,
1289 videoModeSupportedRequest->bpp,
1290 &videoModeSupportedRequest->fSupported);
1291 }
1292 break;
1293 }
1294
1295 /*
1296 * Query whether the given video mode is supported for a specific display
1297 */
1298 case VMMDevReq_VideoModeSupported2:
1299 {
1300 if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest2))
1301 {
1302 AssertMsgFailed(("VMMDev video mode supported request 2 structure has invalid size!\n"));
1303 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1304 }
1305 else
1306 {
1307 VMMDevVideoModeSupportedRequest2 *videoModeSupportedRequest2 = (VMMDevVideoModeSupportedRequest2*)pRequestHeader;
1308 /* forward the call */
1309 pRequestHeader->rc = pThis->pDrv->pfnVideoModeSupported(pThis->pDrv,
1310 videoModeSupportedRequest2->display,
1311 videoModeSupportedRequest2->width,
1312 videoModeSupportedRequest2->height,
1313 videoModeSupportedRequest2->bpp,
1314 &videoModeSupportedRequest2->fSupported);
1315 }
1316 break;
1317 }
1318
1319 /*
1320 * Query the height reduction in pixels
1321 */
1322 case VMMDevReq_GetHeightReduction:
1323 {
1324 if (pRequestHeader->size != sizeof(VMMDevGetHeightReductionRequest))
1325 {
1326 AssertMsgFailed(("VMMDev height reduction request structure has invalid size!\n"));
1327 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1328 }
1329 else
1330 {
1331 VMMDevGetHeightReductionRequest *heightReductionRequest = (VMMDevGetHeightReductionRequest*)pRequestHeader;
1332 /* forward the call */
1333 pRequestHeader->rc = pThis->pDrv->pfnGetHeightReduction(pThis->pDrv,
1334 &heightReductionRequest->heightReduction);
1335 }
1336 break;
1337 }
1338
1339 /*
1340 * Acknowledge VMMDev events
1341 */
1342 case VMMDevReq_AcknowledgeEvents:
1343 {
1344 if (pRequestHeader->size != sizeof(VMMDevEvents))
1345 {
1346 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
1347 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1348 }
1349 else
1350 {
1351 if (VBOX_GUEST_INTERFACE_VERSION_1_03 (pThis))
1352 {
1353 vmmdevSetIRQ_Legacy_EMT (pThis);
1354 }
1355 else
1356 {
1357 VMMDevEvents *pAckRequest;
1358
1359 if (pThis->fNewGuestFilterMask)
1360 {
1361 pThis->fNewGuestFilterMask = false;
1362 pThis->u32GuestFilterMask = pThis->u32NewGuestFilterMask;
1363 }
1364
1365 pAckRequest = (VMMDevEvents *)pRequestHeader;
1366 pAckRequest->events =
1367 pThis->u32HostEventFlags & pThis->u32GuestFilterMask;
1368
1369 pThis->u32HostEventFlags &= ~pThis->u32GuestFilterMask;
1370 pThis->pVMMDevRAMR3->V.V1_04.fHaveEvents = false;
1371 PDMDevHlpPCISetIrqNoWait (pThis->pDevIns, 0, 0);
1372 }
1373 pRequestHeader->rc = VINF_SUCCESS;
1374 }
1375 break;
1376 }
1377
1378 /*
1379 * Change guest filter mask
1380 */
1381 case VMMDevReq_CtlGuestFilterMask:
1382 {
1383 if (pRequestHeader->size != sizeof(VMMDevCtlGuestFilterMask))
1384 {
1385 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
1386 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1387 }
1388 else
1389 {
1390 VMMDevCtlGuestFilterMask *pCtlMaskRequest;
1391
1392 pCtlMaskRequest = (VMMDevCtlGuestFilterMask *)pRequestHeader;
1393 LogRelFlowFunc(("VMMDevCtlGuestFilterMask: or mask: 0x%x, not mask: 0x%x\n",
1394 pCtlMaskRequest->u32OrMask,
1395 pCtlMaskRequest->u32NotMask));
1396 /* HGCM event notification is enabled by the VMMDev device
1397 * automatically when any HGCM command is issued. The guest
1398 * cannot disable these notifications.
1399 */
1400 VMMDevCtlSetGuestFilterMask (pThis,
1401 pCtlMaskRequest->u32OrMask,
1402 pCtlMaskRequest->u32NotMask & ~VMMDEV_EVENT_HGCM);
1403 pRequestHeader->rc = VINF_SUCCESS;
1404
1405 }
1406 break;
1407 }
1408
1409#ifdef VBOX_WITH_HGCM
1410 /*
1411 * Process HGCM request
1412 */
1413 case VMMDevReq_HGCMConnect:
1414 {
1415 if (pRequestHeader->size < sizeof(VMMDevHGCMConnect))
1416 {
1417 AssertMsgFailed(("VMMDevReq_HGCMConnect structure has invalid size!\n"));
1418 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1419 }
1420 else if (!pThis->pHGCMDrv)
1421 {
1422 Log(("VMMDevReq_HGCMConnect HGCM Connector is NULL!\n"));
1423 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1424 }
1425 else
1426 {
1427 VMMDevHGCMConnect *pHGCMConnect = (VMMDevHGCMConnect *)pRequestHeader;
1428
1429 Log(("VMMDevReq_HGCMConnect\n"));
1430
1431 pRequestHeader->rc = vmmdevHGCMConnect (pThis, pHGCMConnect, (RTGCPHYS)u32);
1432 }
1433 break;
1434 }
1435
1436 case VMMDevReq_HGCMDisconnect:
1437 {
1438 if (pRequestHeader->size < sizeof(VMMDevHGCMDisconnect))
1439 {
1440 AssertMsgFailed(("VMMDevReq_HGCMDisconnect structure has invalid size!\n"));
1441 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1442 }
1443 else if (!pThis->pHGCMDrv)
1444 {
1445 Log(("VMMDevReq_HGCMDisconnect HGCM Connector is NULL!\n"));
1446 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1447 }
1448 else
1449 {
1450 VMMDevHGCMDisconnect *pHGCMDisconnect = (VMMDevHGCMDisconnect *)pRequestHeader;
1451
1452 Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
1453 pRequestHeader->rc = vmmdevHGCMDisconnect (pThis, pHGCMDisconnect, (RTGCPHYS)u32);
1454 }
1455 break;
1456 }
1457
1458#ifdef VBOX_WITH_64_BITS_GUESTS
1459 case VMMDevReq_HGCMCall32:
1460 case VMMDevReq_HGCMCall64:
1461#else
1462 case VMMDevReq_HGCMCall:
1463#endif /* VBOX_WITH_64_BITS_GUESTS */
1464 {
1465 if (pRequestHeader->size < sizeof(VMMDevHGCMCall))
1466 {
1467 AssertMsgFailed(("VMMDevReq_HGCMCall structure has invalid size!\n"));
1468 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1469 }
1470 else if (!pThis->pHGCMDrv)
1471 {
1472 Log(("VMMDevReq_HGCMCall HGCM Connector is NULL!\n"));
1473 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1474 }
1475 else
1476 {
1477 VMMDevHGCMCall *pHGCMCall = (VMMDevHGCMCall *)pRequestHeader;
1478
1479 Log2(("VMMDevReq_HGCMCall: sizeof (VMMDevHGCMRequest) = %04X\n", sizeof (VMMDevHGCMCall)));
1480 Log2(("%.*Rhxd\n", pRequestHeader->size, pRequestHeader));
1481
1482#ifdef VBOX_WITH_64_BITS_GUESTS
1483 bool f64Bits = (pRequestHeader->requestType == VMMDevReq_HGCMCall64);
1484#else
1485 bool f64Bits = false;
1486#endif /* VBOX_WITH_64_BITS_GUESTS */
1487
1488 pRequestHeader->rc = vmmdevHGCMCall (pThis, pHGCMCall, requestHeader.size, (RTGCPHYS)u32, f64Bits);
1489 }
1490 break;
1491 }
1492#endif /* VBOX_WITH_HGCM */
1493
1494 case VMMDevReq_HGCMCancel:
1495 {
1496 if (pRequestHeader->size < sizeof(VMMDevHGCMCancel))
1497 {
1498 AssertMsgFailed(("VMMDevReq_HGCMCancel structure has invalid size!\n"));
1499 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1500 }
1501 else if (!pThis->pHGCMDrv)
1502 {
1503 Log(("VMMDevReq_HGCMCancel HGCM Connector is NULL!\n"));
1504 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1505 }
1506 else
1507 {
1508 VMMDevHGCMCancel *pHGCMCancel = (VMMDevHGCMCancel *)pRequestHeader;
1509
1510 Log(("VMMDevReq_VMMDevHGCMCancel\n"));
1511 pRequestHeader->rc = vmmdevHGCMCancel (pThis, pHGCMCancel, (RTGCPHYS)u32);
1512 }
1513 break;
1514 }
1515
1516 case VMMDevReq_HGCMCancel2:
1517 {
1518 if (pRequestHeader->size != sizeof(VMMDevHGCMCancel2))
1519 {
1520 AssertMsgFailed(("VMMDevReq_HGCMCancel structure has invalid size!\n"));
1521 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1522 }
1523 else if (!pThis->pHGCMDrv)
1524 {
1525 Log(("VMMDevReq_HGCMCancel HGCM Connector is NULL!\n"));
1526 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1527 }
1528 else
1529 {
1530 VMMDevHGCMCancel2 *pHGCMCancel2 = (VMMDevHGCMCancel2 *)pRequestHeader;
1531
1532 Log(("VMMDevReq_VMMDevHGCMCancel\n"));
1533 pRequestHeader->rc = vmmdevHGCMCancel2 (pThis, pHGCMCancel2->physReqToCancel);
1534 }
1535 break;
1536 }
1537
1538 case VMMDevReq_VideoAccelEnable:
1539 {
1540 if (pRequestHeader->size < sizeof(VMMDevVideoAccelEnable))
1541 {
1542 Log(("VMMDevReq_VideoAccelEnable request size too small!!!\n"));
1543 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1544 }
1545 else if (!pThis->pDrv)
1546 {
1547 Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!!\n"));
1548 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1549 }
1550 else
1551 {
1552 VMMDevVideoAccelEnable *ptr = (VMMDevVideoAccelEnable *)pRequestHeader;
1553
1554 if (ptr->cbRingBuffer != VBVA_RING_BUFFER_SIZE)
1555 {
1556 /* The guest driver seems compiled with another headers. */
1557 Log(("VMMDevReq_VideoAccelEnable guest ring buffer size %d, should be %d!!!\n", ptr->cbRingBuffer, VBVA_RING_BUFFER_SIZE));
1558 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1559 }
1560 else
1561 {
1562 /* The request is correct. */
1563 ptr->fu32Status |= VBVA_F_STATUS_ACCEPTED;
1564
1565 LogFlow(("VMMDevReq_VideoAccelEnable ptr->u32Enable = %d\n", ptr->u32Enable));
1566
1567 pRequestHeader->rc = ptr->u32Enable?
1568 pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, true, &pThis->pVMMDevRAMR3->vbvaMemory):
1569 pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, false, NULL);
1570
1571 if ( ptr->u32Enable
1572 && RT_SUCCESS (pRequestHeader->rc))
1573 {
1574 ptr->fu32Status |= VBVA_F_STATUS_ENABLED;
1575
1576 /* Remember that guest successfully enabled acceleration.
1577 * We need to reestablish it on restoring the VM from saved state.
1578 */
1579 pThis->u32VideoAccelEnabled = 1;
1580 }
1581 else
1582 {
1583 /* The acceleration was not enabled. Remember that. */
1584 pThis->u32VideoAccelEnabled = 0;
1585 }
1586 }
1587 }
1588 break;
1589 }
1590
1591 case VMMDevReq_VideoAccelFlush:
1592 {
1593 if (pRequestHeader->size < sizeof(VMMDevVideoAccelFlush))
1594 {
1595 AssertMsgFailed(("VMMDevReq_VideoAccelFlush request size too small.\n"));
1596 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1597 }
1598 else if (!pThis->pDrv)
1599 {
1600 Log(("VMMDevReq_VideoAccelFlush Connector is NULL!\n"));
1601 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1602 }
1603 else
1604 {
1605 pThis->pDrv->pfnVideoAccelFlush (pThis->pDrv);
1606
1607 pRequestHeader->rc = VINF_SUCCESS;
1608 }
1609 break;
1610 }
1611
1612 case VMMDevReq_VideoSetVisibleRegion:
1613 {
1614 if ( pRequestHeader->size + sizeof(RTRECT)
1615 < sizeof(VMMDevVideoSetVisibleRegion))
1616 {
1617 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1618 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1619 }
1620 else if (!pThis->pDrv)
1621 {
1622 Log(("VMMDevReq_VideoSetVisibleRegion Connector is NULL!!!\n"));
1623 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1624 }
1625 else
1626 {
1627 VMMDevVideoSetVisibleRegion *ptr = (VMMDevVideoSetVisibleRegion *)pRequestHeader;
1628
1629 if ( ptr->cRect > _1M /* restrict to sane range */
1630 || pRequestHeader->size != sizeof(VMMDevVideoSetVisibleRegion) + ptr->cRect * sizeof(RTRECT) - sizeof(RTRECT))
1631 {
1632 Log(("VMMDevReq_VideoSetVisibleRegion: cRects=%#x doesn't match size=%#x or is out of bounds\n",
1633 ptr->cRect, pRequestHeader->size));
1634 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1635 }
1636 else
1637 {
1638 Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", ptr->cRect));
1639 /* forward the call */
1640 pRequestHeader->rc = pThis->pDrv->pfnSetVisibleRegion(pThis->pDrv, ptr->cRect, &ptr->Rect);
1641 }
1642 }
1643 break;
1644 }
1645
1646 case VMMDevReq_GetSeamlessChangeRequest:
1647 {
1648 if (pRequestHeader->size != sizeof(VMMDevSeamlessChangeRequest))
1649 {
1650 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1651 }
1652 else
1653 {
1654 VMMDevSeamlessChangeRequest *seamlessChangeRequest = (VMMDevSeamlessChangeRequest*)pRequestHeader;
1655 /* just pass on the information */
1656 Log(("VMMDev: returning seamless change request mode=%d\n", pThis->fSeamlessEnabled));
1657 if (pThis->fSeamlessEnabled)
1658 seamlessChangeRequest->mode = VMMDev_Seamless_Visible_Region;
1659 else
1660 seamlessChangeRequest->mode = VMMDev_Seamless_Disabled;
1661
1662 if (seamlessChangeRequest->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
1663 {
1664 /* Remember which mode the client has queried. */
1665 pThis->fLastSeamlessEnabled = pThis->fSeamlessEnabled;
1666 }
1667
1668 pRequestHeader->rc = VINF_SUCCESS;
1669 }
1670 break;
1671 }
1672
1673 case VMMDevReq_GetVRDPChangeRequest:
1674 {
1675 if (pRequestHeader->size != sizeof(VMMDevVRDPChangeRequest))
1676 {
1677 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1678 }
1679 else
1680 {
1681 VMMDevVRDPChangeRequest *vrdpChangeRequest = (VMMDevVRDPChangeRequest*)pRequestHeader;
1682 /* just pass on the information */
1683 Log(("VMMDev: returning VRDP status %d level %d\n", pThis->fVRDPEnabled, pThis->u32VRDPExperienceLevel));
1684
1685 vrdpChangeRequest->u8VRDPActive = pThis->fVRDPEnabled;
1686 vrdpChangeRequest->u32VRDPExperienceLevel = pThis->u32VRDPExperienceLevel;
1687
1688 pRequestHeader->rc = VINF_SUCCESS;
1689 }
1690 break;
1691 }
1692
1693 case VMMDevReq_GetMemBalloonChangeRequest:
1694 {
1695 Log(("VMMDevReq_GetMemBalloonChangeRequest\n"));
1696 if (pRequestHeader->size != sizeof(VMMDevGetMemBalloonChangeRequest))
1697 {
1698 AssertFailed();
1699 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1700 }
1701 else
1702 {
1703 VMMDevGetMemBalloonChangeRequest *memBalloonChangeRequest = (VMMDevGetMemBalloonChangeRequest*)pRequestHeader;
1704 /* just pass on the information */
1705 Log(("VMMDev: returning memory balloon size =%d\n", pThis->u32MemoryBalloonSize));
1706 memBalloonChangeRequest->cBalloonChunks = pThis->u32MemoryBalloonSize;
1707 memBalloonChangeRequest->cPhysMemChunks = pThis->cbGuestRAM / (uint64_t)_1M;
1708
1709 if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
1710 {
1711 /* Remember which mode the client has queried. */
1712 pThis->u32LastMemoryBalloonSize = pThis->u32MemoryBalloonSize;
1713 }
1714
1715 pRequestHeader->rc = VINF_SUCCESS;
1716 }
1717 break;
1718 }
1719
1720 case VMMDevReq_ChangeMemBalloon:
1721 {
1722 VMMDevChangeMemBalloon *memBalloonChange = (VMMDevChangeMemBalloon*)pRequestHeader;
1723
1724 Log(("VMMDevReq_ChangeMemBalloon\n"));
1725 if ( pRequestHeader->size < sizeof(VMMDevChangeMemBalloon)
1726 || memBalloonChange->cPages != VMMDEV_MEMORY_BALLOON_CHUNK_PAGES
1727 || pRequestHeader->size != (uint32_t)RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[memBalloonChange->cPages]))
1728 {
1729 AssertFailed();
1730 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1731 }
1732 else
1733 {
1734 pRequestHeader->rc = PGMR3PhysChangeMemBalloon(PDMDevHlpGetVM(pDevIns), !!memBalloonChange->fInflate, memBalloonChange->cPages, memBalloonChange->aPhysPage);
1735 if (memBalloonChange->fInflate)
1736 STAM_REL_U32_INC(&pThis->StatMemBalloonChunks);
1737 else
1738 STAM_REL_U32_DEC(&pThis->StatMemBalloonChunks);
1739 }
1740 break;
1741 }
1742
1743 case VMMDevReq_GetStatisticsChangeRequest:
1744 {
1745 Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
1746 if (pRequestHeader->size != sizeof(VMMDevGetStatisticsChangeRequest))
1747 {
1748 AssertFailed();
1749 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1750 }
1751 else
1752 {
1753 VMMDevGetStatisticsChangeRequest *statIntervalChangeRequest = (VMMDevGetStatisticsChangeRequest*)pRequestHeader;
1754 /* just pass on the information */
1755 Log(("VMMDev: returning statistics interval %d seconds\n", pThis->u32StatIntervalSize));
1756 statIntervalChangeRequest->u32StatInterval = pThis->u32StatIntervalSize;
1757
1758 if (statIntervalChangeRequest->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
1759 {
1760 /* Remember which mode the client has queried. */
1761 pThis->u32LastStatIntervalSize= pThis->u32StatIntervalSize;
1762 }
1763
1764 pRequestHeader->rc = VINF_SUCCESS;
1765 }
1766 break;
1767 }
1768
1769 case VMMDevReq_ReportGuestStats:
1770 {
1771 Log(("VMMDevReq_ReportGuestStats\n"));
1772 if (pRequestHeader->size != sizeof(VMMDevReportGuestStats))
1773 {
1774 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1775 }
1776 else
1777 {
1778 VMMDevReportGuestStats *stats = (VMMDevReportGuestStats*)pRequestHeader;
1779
1780#ifdef DEBUG
1781 VBoxGuestStatistics *pGuestStats = &stats->guestStats;
1782
1783 Log(("Current statistics:\n"));
1784 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
1785 Log(("CPU%d: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
1786
1787 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
1788 Log(("CPU%d: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
1789
1790 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
1791 Log(("CPU%d: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
1792
1793 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
1794 Log(("CPU%d: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
1795
1796 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
1797 Log(("CPU%d: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
1798
1799 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
1800 Log(("CPU%d: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
1801
1802 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
1803 Log(("CPU%d: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
1804
1805 /* Note that reported values are in pages; upper layers expect them in megabytes */
1806 Log(("CPU%d: Page size %-4d bytes\n", pGuestStats->u32CpuId, pGuestStats->u32PageSize));
1807 Assert(pGuestStats->u32PageSize == 4096);
1808
1809 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
1810 Log(("CPU%d: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/_4K)-1) / (_1M/_4K)));
1811
1812 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
1813 Log(("CPU%d: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/_4K)));
1814
1815 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
1816 Log(("CPU%d: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/_4K)));
1817
1818 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
1819 Log(("CPU%d: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/_4K)));
1820
1821 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
1822 Log(("CPU%d: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/_4K)));
1823
1824 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
1825 Log(("CPU%d: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/_4K)));
1826
1827 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
1828 Log(("CPU%d: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/_4K)));
1829
1830 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
1831 Log(("CPU%d: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/_4K)));
1832
1833 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
1834 Log(("CPU%d: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/_4K)));
1835 Log(("Statistics end *******************\n"));
1836#endif
1837
1838 /* forward the call */
1839 pRequestHeader->rc = pThis->pDrv->pfnReportStatistics(pThis->pDrv, &stats->guestStats);
1840 }
1841 break;
1842 }
1843
1844 case VMMDevReq_QueryCredentials:
1845 {
1846 if (pRequestHeader->size != sizeof(VMMDevCredentials))
1847 {
1848 AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
1849 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1850 }
1851 else
1852 {
1853 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
1854
1855 /* let's start by nulling out the data */
1856 memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1857 memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1858 memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1859
1860 /* should we return whether we got credentials for a logon? */
1861 if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
1862 {
1863 if ( pThis->pCredentials->Logon.szUserName[0]
1864 || pThis->pCredentials->Logon.szPassword[0]
1865 || pThis->pCredentials->Logon.szDomain[0])
1866 {
1867 credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
1868 }
1869 else
1870 {
1871 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
1872 }
1873 }
1874
1875 /* does the guest want to read logon credentials? */
1876 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
1877 {
1878 if (pThis->pCredentials->Logon.szUserName[0])
1879 strcpy(credentials->szUserName, pThis->pCredentials->Logon.szUserName);
1880 if (pThis->pCredentials->Logon.szPassword[0])
1881 strcpy(credentials->szPassword, pThis->pCredentials->Logon.szPassword);
1882 if (pThis->pCredentials->Logon.szDomain[0])
1883 strcpy(credentials->szDomain, pThis->pCredentials->Logon.szDomain);
1884 if (!pThis->pCredentials->Logon.fAllowInteractiveLogon)
1885 credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
1886 else
1887 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
1888 }
1889
1890 if (!pThis->fKeepCredentials)
1891 {
1892 /* does the caller want us to destroy the logon credentials? */
1893 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
1894 {
1895 memset(pThis->pCredentials->Logon.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1896 memset(pThis->pCredentials->Logon.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1897 memset(pThis->pCredentials->Logon.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1898 }
1899 }
1900
1901 /* does the guest want to read credentials for verification? */
1902 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
1903 {
1904 if (pThis->pCredentials->Judge.szUserName[0])
1905 strcpy(credentials->szUserName, pThis->pCredentials->Judge.szUserName);
1906 if (pThis->pCredentials->Judge.szPassword[0])
1907 strcpy(credentials->szPassword, pThis->pCredentials->Judge.szPassword);
1908 if (pThis->pCredentials->Judge.szDomain[0])
1909 strcpy(credentials->szDomain, pThis->pCredentials->Judge.szDomain);
1910 }
1911
1912 /* does the caller want us to destroy the judgement credentials? */
1913 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
1914 {
1915 memset(pThis->pCredentials->Judge.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1916 memset(pThis->pCredentials->Judge.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1917 memset(pThis->pCredentials->Judge.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1918 }
1919
1920 pRequestHeader->rc = VINF_SUCCESS;
1921 }
1922 break;
1923 }
1924
1925 case VMMDevReq_ReportCredentialsJudgement:
1926 {
1927 if (pRequestHeader->size != sizeof(VMMDevCredentials))
1928 {
1929 AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
1930 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1931 }
1932 else
1933 {
1934 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
1935
1936 /* what does the guest think about the credentials? (note: the order is important here!) */
1937 if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
1938 {
1939 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
1940 }
1941 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
1942 {
1943 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
1944 }
1945 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
1946 {
1947 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
1948 }
1949 else
1950 Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
1951
1952 pRequestHeader->rc = VINF_SUCCESS;
1953 }
1954 break;
1955 }
1956
1957 /*
1958 * Implemented in 3.1.0.
1959 *
1960 * Note! The ring-0 VBoxGuestLib uses this to check whether
1961 * VMMDevHGCMParmType_PageList is supported.
1962 */
1963 case VMMDevReq_GetHostVersion:
1964 {
1965 AssertMsgBreakStmt(pRequestHeader->size == sizeof(VMMDevReqHostVersion),
1966 ("%#x < %#x\n", pRequestHeader->size, sizeof(VMMDevReqLogString)),
1967 pRequestHeader->rc = VERR_INVALID_PARAMETER);
1968 VMMDevReqHostVersion *pReqHostVer = (VMMDevReqHostVersion*)pRequestHeader;
1969 pReqHostVer->major = RTBldCfgVersionMajor();
1970 pReqHostVer->minor = RTBldCfgVersionMinor();
1971 pReqHostVer->build = RTBldCfgVersionBuild();
1972 pReqHostVer->revision = RTBldCfgRevision();
1973 pReqHostVer->features = VMMDEV_HVF_HGCM_PHYS_PAGE_LIST;
1974 pReqHostVer->header.rc = VINF_SUCCESS;
1975 break;
1976 }
1977
1978 case VMMDevReq_GetCpuHotPlugRequest:
1979 {
1980 VMMDevGetCpuHotPlugRequest *pReqCpuHotPlug = (VMMDevGetCpuHotPlugRequest *)pRequestHeader;
1981
1982 if (pRequestHeader->size != sizeof(VMMDevGetCpuHotPlugRequest))
1983 {
1984 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1985 }
1986 else
1987 {
1988 pReqCpuHotPlug->enmEventType = pThis->enmCpuHotPlugEvent;
1989 pReqCpuHotPlug->idCpuCore = pThis->idCpuCore;
1990 pReqCpuHotPlug->idCpuPackage = pThis->idCpuPackage;
1991 pReqCpuHotPlug->header.rc = VINF_SUCCESS;
1992
1993 /* Clear the event */
1994 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_None;
1995 pThis->idCpuCore = UINT32_MAX;
1996 pThis->idCpuPackage = UINT32_MAX;
1997 }
1998 break;
1999 }
2000
2001 case VMMDevReq_SetCpuHotPlugStatus:
2002 {
2003 VMMDevCpuHotPlugStatusRequest *pReqCpuHotPlugStatus = (VMMDevCpuHotPlugStatusRequest *)pRequestHeader;
2004
2005 if (pRequestHeader->size != sizeof(VMMDevCpuHotPlugStatusRequest))
2006 {
2007 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2008 }
2009 else
2010 {
2011 pRequestHeader->rc = VINF_SUCCESS;
2012
2013 if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Disable)
2014 pThis->fCpuHotPlugEventsEnabled = false;
2015 else if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Enable)
2016 pThis->fCpuHotPlugEventsEnabled = true;
2017 else
2018 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2019 }
2020 break;
2021 }
2022
2023#ifdef VBOX_WITH_PAGE_SHARING
2024 case VMMDevReq_RegisterSharedModule:
2025 {
2026 VMMDevSharedModuleRegistrationRequest *pReqModule = (VMMDevSharedModuleRegistrationRequest *)pRequestHeader;
2027
2028 if ( pRequestHeader->size < sizeof(VMMDevSharedModuleRegistrationRequest)
2029 || pRequestHeader->size != RT_UOFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[pReqModule->cRegions]))
2030 {
2031 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2032 }
2033 else
2034 {
2035 pRequestHeader->rc = PGMR3SharedModuleRegister(PDMDevHlpGetVM(pDevIns), pReqModule->enmGuestOS, pReqModule->szName, pReqModule->szVersion,
2036 pReqModule->GCBaseAddr, pReqModule->cbModule,
2037 pReqModule->cRegions, pReqModule->aRegions);
2038 }
2039 break;
2040 }
2041
2042 case VMMDevReq_UnregisterSharedModule:
2043 {
2044 VMMDevSharedModuleUnregistrationRequest *pReqModule = (VMMDevSharedModuleUnregistrationRequest *)pRequestHeader;
2045
2046 if (pRequestHeader->size != sizeof(VMMDevSharedModuleUnregistrationRequest))
2047 {
2048 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2049 }
2050 else
2051 {
2052 pRequestHeader->rc = PGMR3SharedModuleUnregister(PDMDevHlpGetVM(pDevIns), pReqModule->szName, pReqModule->szVersion,
2053 pReqModule->GCBaseAddr, pReqModule->cbModule);
2054 }
2055 break;
2056 }
2057
2058 case VMMDevReq_CheckSharedModules:
2059 {
2060 VMMDevSharedModuleCheckRequest *pReqModule = (VMMDevSharedModuleCheckRequest *)pRequestHeader;
2061
2062 if (pRequestHeader->size != sizeof(VMMDevSharedModuleCheckRequest))
2063 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2064 else
2065 pRequestHeader->rc = PGMR3SharedModuleCheckAll(PDMDevHlpGetVM(pDevIns));
2066 break;
2067 }
2068
2069 case VMMDevReq_GetPageSharingStatus:
2070 {
2071 VMMDevPageSharingStatusRequest *pReqStatus = (VMMDevPageSharingStatusRequest *)pRequestHeader;
2072
2073 if (pRequestHeader->size != sizeof(VMMDevPageSharingStatusRequest))
2074 {
2075 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2076 }
2077 else
2078 {
2079 pReqStatus->fEnabled = false;
2080 pThis->pDrv->pfnIsPageFusionEnabled(pThis->pDrv, &pReqStatus->fEnabled);
2081 pRequestHeader->rc = VINF_SUCCESS;
2082 }
2083 break;
2084 }
2085
2086 case VMMDevReq_DebugIsPageShared:
2087 {
2088# ifdef DEBUG
2089 VMMDevPageIsSharedRequest *pReq = (VMMDevPageIsSharedRequest *)pRequestHeader;
2090
2091 if (pRequestHeader->size != sizeof(VMMDevPageIsSharedRequest))
2092 {
2093 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2094 }
2095 else
2096 {
2097 pRequestHeader->rc = PGMR3SharedModuleGetPageState(PDMDevHlpGetVM(pDevIns), pReq->GCPtrPage, &pReq->fShared, &pReq->uPageFlags);
2098 }
2099# else
2100 pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
2101# endif
2102 break;
2103 }
2104
2105#endif
2106
2107#ifdef DEBUG
2108 case VMMDevReq_LogString:
2109 {
2110 if (pRequestHeader->size < sizeof(VMMDevReqLogString))
2111 {
2112 AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
2113 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2114 }
2115 else
2116 {
2117 VMMDevReqLogString *pReqLogString = (VMMDevReqLogString *)pRequestHeader;
2118 LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR,
2119 ("DEBUG LOG: %s", pReqLogString->szString));
2120 pRequestHeader->rc = VINF_SUCCESS;
2121 }
2122 break;
2123 }
2124#endif
2125
2126 /*
2127 * Get a unique session id for this VM; the id will be different after each start, reset or restore of the VM
2128 * This can be used for restore detection inside the guest.
2129 */
2130 case VMMDevReq_GetSessionId:
2131 {
2132 if (pRequestHeader->size != sizeof(VMMDevReqSessionId))
2133 {
2134 AssertMsgFailed(("VMMDevReq_GetSessionId request size too small.\n"));
2135 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2136 }
2137 else
2138 {
2139 VMMDevReqSessionId *pReq = (VMMDevReqSessionId *)pRequestHeader;
2140 pReq->idSession = pThis->idSession;
2141 pRequestHeader->rc = VINF_SUCCESS;
2142 }
2143 break;
2144 }
2145
2146 default:
2147 {
2148 pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
2149 Log(("VMMDev unknown request type %d\n", pRequestHeader->requestType));
2150 break;
2151 }
2152 }
2153
2154l_end:
2155 /* Write the result back to guest memory */
2156 if (pRequestHeader)
2157 {
2158 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, pRequestHeader, pRequestHeader->size);
2159 RTMemFree(pRequestHeader);
2160 }
2161 else
2162 {
2163 /* early error case; write back header only */
2164 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
2165 }
2166
2167 PDMCritSectLeave(&pThis->CritSect);
2168 return rcRet;
2169}
2170
2171/**
2172 * Callback function for mapping an PCI I/O region.
2173 *
2174 * @return VBox status code.
2175 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
2176 * @param iRegion The region number.
2177 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
2178 * I/O port, else it's a physical address.
2179 * This address is *NOT* relative to pci_mem_base like earlier!
2180 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
2181 */
2182static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
2183{
2184 LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
2185 VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
2186 int rc;
2187
2188 if (iRegion == 1)
2189 {
2190 AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM, VERR_INTERNAL_ERROR);
2191 Assert(pThis->pVMMDevRAMR3 != NULL);
2192 if (GCPhysAddress != NIL_RTGCPHYS)
2193 {
2194 /*
2195 * Map the MMIO2 memory.
2196 */
2197 pThis->GCPhysVMMDevRAM = GCPhysAddress;
2198 Assert(pThis->GCPhysVMMDevRAM == GCPhysAddress);
2199 rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
2200 }
2201 else
2202 {
2203 /*
2204 * It is about to be unmapped, just clean up.
2205 */
2206 pThis->GCPhysVMMDevRAM = NIL_RTGCPHYS32;
2207 rc = VINF_SUCCESS;
2208 }
2209 }
2210 else if (iRegion == 2)
2211 {
2212 AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM_PREFETCH, VERR_INTERNAL_ERROR);
2213 Assert(pThis->pVMMDevHeapR3 != NULL);
2214 if (GCPhysAddress != NIL_RTGCPHYS)
2215 {
2216 /*
2217 * Map the MMIO2 memory.
2218 */
2219 pThis->GCPhysVMMDevHeap = GCPhysAddress;
2220 Assert(pThis->GCPhysVMMDevHeap == GCPhysAddress);
2221 rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
2222 if (RT_SUCCESS(rc))
2223 rc = PDMDevHlpRegisterVMMDevHeap(pPciDev->pDevIns, GCPhysAddress, pThis->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
2224 }
2225 else
2226 {
2227 /*
2228 * It is about to be unmapped, just clean up.
2229 */
2230 PDMDevHlpUnregisterVMMDevHeap(pPciDev->pDevIns, pThis->GCPhysVMMDevHeap);
2231 pThis->GCPhysVMMDevHeap = NIL_RTGCPHYS32;
2232 rc = VINF_SUCCESS;
2233 }
2234 }
2235 else
2236 {
2237 AssertMsgFailed(("%d\n", iRegion));
2238 rc = VERR_INVALID_PARAMETER;
2239 }
2240
2241 return rc;
2242}
2243
2244
2245/**
2246 * Callback function for mapping a PCI I/O region.
2247 *
2248 * @return VBox status code.
2249 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
2250 * @param iRegion The region number.
2251 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
2252 * I/O port, else it's a physical address.
2253 * This address is *NOT* relative to pci_mem_base like earlier!
2254 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
2255 */
2256static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
2257{
2258 VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
2259 int rc = VINF_SUCCESS;
2260
2261 Assert(enmType == PCI_ADDRESS_SPACE_IO);
2262 Assert(iRegion == 0);
2263 AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
2264
2265 /*
2266 * Save the base port address to simplify Port offset calculations.
2267 */
2268 pThis->PortBase = (RTIOPORT)GCPhysAddress;
2269
2270 /*
2271 * Register our port IO handlers.
2272 */
2273 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
2274 (RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST, 1,
2275 (void*)pThis, vmmdevRequestHandler,
2276 NULL, NULL, NULL, "VMMDev Request Handler");
2277 AssertRC(rc);
2278 return rc;
2279}
2280
2281/**
2282 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
2283 */
2284static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, const char *pszIID)
2285{
2286 VMMDevState *pThis = RT_FROM_MEMBER(pInterface, VMMDevState, IBase);
2287
2288 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
2289 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVPORT, &pThis->IPort);
2290#ifdef VBOX_WITH_HGCM
2291 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMPORT, &pThis->IHGCMPort);
2292#endif
2293 /* Currently only for shared folders. */
2294 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThis->SharedFolders.ILeds);
2295 return NULL;
2296}
2297
2298/**
2299 * Gets the pointer to the status LED of a unit.
2300 *
2301 * @returns VBox status code.
2302 * @param pInterface Pointer to the interface structure containing the called function pointer.
2303 * @param iLUN The unit which status LED we desire.
2304 * @param ppLed Where to store the LED pointer.
2305 */
2306static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
2307{
2308 VMMDevState *pThis = (VMMDevState *)( (uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, SharedFolders.ILeds) );
2309 if (iLUN == 0) /* LUN 0 is shared folders */
2310 {
2311 *ppLed = &pThis->SharedFolders.Led;
2312 return VINF_SUCCESS;
2313 }
2314 return VERR_PDM_LUN_NOT_FOUND;
2315}
2316
2317/* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
2318
2319/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
2320#define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, IPort)) )
2321
2322
2323/**
2324 * Return the current absolute mouse position in pixels
2325 *
2326 * @returns VBox status code
2327 * @param pAbsX Pointer of result value, can be NULL
2328 * @param pAbsY Pointer of result value, can be NULL
2329 */
2330static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t *pAbsX, int32_t *pAbsY)
2331{
2332 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2333 if (pAbsX)
2334 *pAbsX = ASMAtomicReadS32(&pThis->mouseXAbs); /* why the atomic read? */
2335 if (pAbsY)
2336 *pAbsY = ASMAtomicReadS32(&pThis->mouseYAbs);
2337 return VINF_SUCCESS;
2338}
2339
2340/**
2341 * Set the new absolute mouse position in pixels
2342 *
2343 * @returns VBox status code
2344 * @param absX New absolute X position
2345 * @param absY New absolute Y position
2346 */
2347static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t absX, int32_t absY)
2348{
2349 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2350 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2351
2352 if (pThis->mouseXAbs == absX && pThis->mouseYAbs == absY)
2353 {
2354 PDMCritSectLeave(&pThis->CritSect);
2355 return VINF_SUCCESS;
2356 }
2357 Log2(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
2358 pThis->mouseXAbs = absX;
2359 pThis->mouseYAbs = absY;
2360 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
2361 PDMCritSectLeave(&pThis->CritSect);
2362 return VINF_SUCCESS;
2363}
2364
2365/**
2366 * Return the current mouse capability flags
2367 *
2368 * @returns VBox status code
2369 * @param pCapabilities Pointer of result value
2370 */
2371static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pfCaps)
2372{
2373 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2374 if (!pfCaps)
2375 return VERR_INVALID_PARAMETER;
2376 *pfCaps = pThis->mouseCapabilities;
2377 return VINF_SUCCESS;
2378}
2379
2380/**
2381 * Set the current mouse capability flag (host side)
2382 *
2383 * @returns VBox status code
2384 * @param capabilities Capability mask
2385 */
2386static DECLCALLBACK(int) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t fCapsAdded, uint32_t fCapsRemoved)
2387{
2388 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2389 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2390
2391 uint32_t fOldCaps = pThis->mouseCapabilities;
2392 pThis->mouseCapabilities &= ~(fCapsRemoved & VMMDEV_MOUSE_HOST_MASK);
2393 pThis->mouseCapabilities |= (fCapsAdded & VMMDEV_MOUSE_HOST_MASK)
2394 | VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
2395 bool fNotify = fOldCaps != pThis->mouseCapabilities;
2396
2397 LogRelFlowFunc(("fCapsAdded=0x%x, fCapsRemoved=0x%x, fNotify %s\n",
2398 fCapsAdded, fCapsRemoved, fNotify ? "TRUE" : "FALSE"));
2399
2400 if (fNotify)
2401 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
2402
2403 PDMCritSectLeave(&pThis->CritSect);
2404 return VINF_SUCCESS;
2405}
2406
2407
2408static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
2409{
2410 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2411
2412 if (display >= RT_ELEMENTS(pThis->displayChangeData.aRequests))
2413 {
2414 return VERR_INVALID_PARAMETER;
2415 }
2416
2417 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2418
2419 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[display];
2420
2421 /* Verify that the new resolution is different and that guest does not yet know about it. */
2422 bool fSameResolution = (!xres || (pRequest->lastReadDisplayChangeRequest.xres == xres)) &&
2423 (!yres || (pRequest->lastReadDisplayChangeRequest.yres == yres)) &&
2424 (!bpp || (pRequest->lastReadDisplayChangeRequest.bpp == bpp)) &&
2425 pRequest->lastReadDisplayChangeRequest.display == display;
2426
2427 if (!xres && !yres && !bpp)
2428 {
2429 /* Special case of reset video mode. */
2430 fSameResolution = false;
2431 }
2432
2433 Log3(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
2434 fSameResolution, xres, yres, bpp, display, pRequest->lastReadDisplayChangeRequest.xres, pRequest->lastReadDisplayChangeRequest.yres, pRequest->lastReadDisplayChangeRequest.bpp, pRequest->lastReadDisplayChangeRequest.display));
2435
2436 if (!fSameResolution)
2437 {
2438 LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
2439 xres, yres, bpp, display));
2440
2441 /* we could validate the information here but hey, the guest can do that as well! */
2442 pRequest->displayChangeRequest.xres = xres;
2443 pRequest->displayChangeRequest.yres = yres;
2444 pRequest->displayChangeRequest.bpp = bpp;
2445 pRequest->displayChangeRequest.display = display;
2446 pRequest->fPending = true;
2447
2448 /* IRQ so the guest knows what's going on */
2449 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
2450 }
2451
2452 PDMCritSectLeave(&pThis->CritSect);
2453 return VINF_SUCCESS;
2454}
2455
2456static DECLCALLBACK(int) vmmdevRequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
2457{
2458 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2459 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2460
2461 /* Verify that the new resolution is different and that guest does not yet know about it. */
2462 bool fSameMode = (pThis->fLastSeamlessEnabled == fEnabled);
2463
2464 Log(("vmmdevRequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
2465
2466 if (!fSameMode)
2467 {
2468 /* we could validate the information here but hey, the guest can do that as well! */
2469 pThis->fSeamlessEnabled = fEnabled;
2470
2471 /* IRQ so the guest knows what's going on */
2472 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
2473 }
2474
2475 PDMCritSectLeave(&pThis->CritSect);
2476 return VINF_SUCCESS;
2477}
2478
2479static DECLCALLBACK(int) vmmdevSetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t ulBalloonSize)
2480{
2481 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2482 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2483
2484 /* Verify that the new resolution is different and that guest does not yet know about it. */
2485 bool fSame = (pThis->u32LastMemoryBalloonSize == ulBalloonSize);
2486
2487 Log(("vmmdevSetMemoryBalloon: old=%d. new=%d\n", pThis->u32LastMemoryBalloonSize, ulBalloonSize));
2488
2489 if (!fSame)
2490 {
2491 /* we could validate the information here but hey, the guest can do that as well! */
2492 pThis->u32MemoryBalloonSize = ulBalloonSize;
2493
2494 /* IRQ so the guest knows what's going on */
2495 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
2496 }
2497
2498 PDMCritSectLeave(&pThis->CritSect);
2499 return VINF_SUCCESS;
2500}
2501
2502static DECLCALLBACK(int) vmmdevVRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t u32VRDPExperienceLevel)
2503{
2504 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2505 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2506
2507 bool fSame = (pThis->fVRDPEnabled == fVRDPEnabled);
2508
2509 Log(("vmmdevVRDPChange: old=%d. new=%d\n", pThis->fVRDPEnabled, fVRDPEnabled));
2510
2511 if (!fSame)
2512 {
2513 pThis->fVRDPEnabled = fVRDPEnabled;
2514 pThis->u32VRDPExperienceLevel = u32VRDPExperienceLevel;
2515
2516 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_VRDP);
2517 }
2518
2519 PDMCritSectLeave(&pThis->CritSect);
2520 return VINF_SUCCESS;
2521}
2522
2523static DECLCALLBACK(int) vmmdevSetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t ulStatInterval)
2524{
2525 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2526 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2527
2528 /* Verify that the new resolution is different and that guest does not yet know about it. */
2529 bool fSame = (pThis->u32LastStatIntervalSize == ulStatInterval);
2530
2531 Log(("vmmdevSetStatisticsInterval: old=%d. new=%d\n", pThis->u32LastStatIntervalSize, ulStatInterval));
2532
2533 if (!fSame)
2534 {
2535 /* we could validate the information here but hey, the guest can do that as well! */
2536 pThis->u32StatIntervalSize = ulStatInterval;
2537
2538 /* IRQ so the guest knows what's going on */
2539 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
2540 }
2541
2542 PDMCritSectLeave(&pThis->CritSect);
2543 return VINF_SUCCESS;
2544}
2545
2546
2547static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
2548 const char *pszPassword, const char *pszDomain,
2549 uint32_t u32Flags)
2550{
2551 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2552 int rc = VINF_SUCCESS;
2553
2554 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2555
2556 /* logon mode? */
2557 if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
2558 {
2559 /* memorize the data */
2560 strcpy(pThis->pCredentials->Logon.szUserName, pszUsername);
2561 strcpy(pThis->pCredentials->Logon.szPassword, pszPassword);
2562 strcpy(pThis->pCredentials->Logon.szDomain, pszDomain);
2563 pThis->pCredentials->Logon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
2564 }
2565 /* credentials verification mode? */
2566 else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
2567 {
2568 /* memorize the data */
2569 strcpy(pThis->pCredentials->Judge.szUserName, pszUsername);
2570 strcpy(pThis->pCredentials->Judge.szPassword, pszPassword);
2571 strcpy(pThis->pCredentials->Judge.szDomain, pszDomain);
2572
2573 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_JUDGE_CREDENTIALS);
2574 }
2575 else
2576 rc = VERR_INVALID_PARAMETER;
2577
2578 PDMCritSectLeave(&pThis->CritSect);
2579 return rc;
2580}
2581
2582/**
2583 * Notification from the Display. Especially useful when
2584 * acceleration is disabled after a video mode change.
2585 *
2586 * @param fEnable Current acceleration status.
2587 */
2588static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
2589{
2590 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2591
2592 Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
2593
2594 if (pThis)
2595 {
2596 pThis->u32VideoAccelEnabled = fEnabled;
2597 }
2598 return;
2599}
2600
2601/**
2602 * Notification that a CPU is about to be unplugged from the VM.
2603 * The guest has to eject the CPU.
2604 *
2605 * @returns VBox status code.
2606 * @param idCpu The id of the CPU.
2607 * @param idCpuCore The core id of the CPU to remove.
2608 * @param idCpuPackage The package id of the CPU to remove.
2609 */
2610static DECLCALLBACK(int) vmmdevCpuHotUnplug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
2611{
2612 int rc = VINF_SUCCESS;
2613 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2614
2615 Log(("vmmdevCpuHotUnplug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
2616
2617 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2618
2619 if (pThis->fCpuHotPlugEventsEnabled)
2620 {
2621 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Unplug;
2622 pThis->idCpuCore = idCpuCore;
2623 pThis->idCpuPackage = idCpuPackage;
2624 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_CPU_HOTPLUG);
2625 }
2626 else
2627 rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
2628
2629 PDMCritSectLeave(&pThis->CritSect);
2630 return rc;
2631}
2632
2633/**
2634 * Notification that a CPU was attached to the VM
2635 * The guest may use it now.
2636 *
2637 * @returns VBox status code.
2638 * @param idCpuCore The core id of the CPU to add.
2639 * @param idCpuPackage The package id of the CPU to add.
2640 */
2641static DECLCALLBACK(int) vmmdevCpuHotPlug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
2642{
2643 int rc = VINF_SUCCESS;
2644 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2645
2646 Log(("vmmdevCpuPlug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
2647
2648 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2649
2650 if (pThis->fCpuHotPlugEventsEnabled)
2651 {
2652 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Plug;
2653 pThis->idCpuCore = idCpuCore;
2654 pThis->idCpuPackage = idCpuPackage;
2655 VMMDevNotifyGuest(pThis, VMMDEV_EVENT_CPU_HOTPLUG);
2656 }
2657 else
2658 rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
2659
2660 PDMCritSectLeave(&pThis->CritSect);
2661 return rc;
2662}
2663
2664/* -=-=-=-=-=- Saved State -=-=-=-=-=- */
2665
2666/**
2667 * @copydoc FNSSMDEVLIVEEXEC
2668 */
2669static DECLCALLBACK(int) vmmdevLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
2670{
2671 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2672
2673 SSMR3PutBool(pSSM, pThis->fGetHostTimeDisabled);
2674 SSMR3PutBool(pSSM, pThis->fBackdoorLogDisabled);
2675 SSMR3PutBool(pSSM, pThis->fKeepCredentials);
2676 SSMR3PutBool(pSSM, pThis->fHeapEnabled);
2677
2678 return VINF_SSM_DONT_CALL_AGAIN;
2679}
2680
2681
2682/**
2683 * @copydoc FNSSMDEVSAVEEXEC
2684 *
2685 */
2686static DECLCALLBACK(int) vmmdevSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
2687{
2688 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2689
2690 vmmdevLiveExec(pDevIns, pSSM, SSM_PASS_FINAL);
2691
2692 SSMR3PutU32(pSSM, pThis->hypervisorSize);
2693 SSMR3PutU32(pSSM, pThis->mouseCapabilities);
2694 SSMR3PutS32(pSSM, pThis->mouseXAbs);
2695 SSMR3PutS32(pSSM, pThis->mouseYAbs);
2696
2697 SSMR3PutBool(pSSM, pThis->fNewGuestFilterMask);
2698 SSMR3PutU32(pSSM, pThis->u32NewGuestFilterMask);
2699 SSMR3PutU32(pSSM, pThis->u32GuestFilterMask);
2700 SSMR3PutU32(pSSM, pThis->u32HostEventFlags);
2701 /* The following is not strictly necessary as PGM restores MMIO2, keeping it for historical reasons. */
2702 SSMR3PutMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof(pThis->pVMMDevRAMR3->V));
2703
2704 SSMR3PutMem(pSSM, &pThis->guestInfo, sizeof(pThis->guestInfo));
2705 SSMR3PutU32(pSSM, pThis->fu32AdditionsOk);
2706 SSMR3PutU32(pSSM, pThis->u32VideoAccelEnabled);
2707 SSMR3PutBool(pSSM, pThis->displayChangeData.fGuestSentChangeEventAck);
2708
2709 SSMR3PutU32(pSSM, pThis->guestCaps);
2710
2711#ifdef VBOX_WITH_HGCM
2712 vmmdevHGCMSaveState(pThis, pSSM);
2713#endif /* VBOX_WITH_HGCM */
2714
2715 SSMR3PutU32(pSSM, pThis->fHostCursorRequested);
2716
2717 SSMR3PutU32(pSSM, pThis->guestInfo2.uFullVersion);
2718 SSMR3PutU32(pSSM, pThis->guestInfo2.uRevision);
2719 SSMR3PutU32(pSSM, pThis->guestInfo2.fFeatures);
2720 SSMR3PutStrZ(pSSM, pThis->guestInfo2.szName);
2721
2722 return VINF_SUCCESS;
2723}
2724
2725/**
2726 * @copydoc FNSSMDEVLOADEXEC
2727 */
2728static DECLCALLBACK(int) vmmdevLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
2729{
2730 /** @todo The code load code is assuming we're always loaded into a freshly
2731 * constructed VM. */
2732 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2733 int rc;
2734
2735 if ( uVersion > VMMDEV_SAVED_STATE_VERSION
2736 || uVersion < 6)
2737 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
2738
2739 /* config */
2740 if (uVersion > VMMDEV_SAVED_STATE_VERSION_VBOX_30)
2741 {
2742 bool f;
2743 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2744 if (pThis->fGetHostTimeDisabled != f)
2745 LogRel(("VMMDev: Config mismatch - fGetHostTimeDisabled: config=%RTbool saved=%RTbool\n", pThis->fGetHostTimeDisabled, f));
2746
2747 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2748 if (pThis->fBackdoorLogDisabled != f)
2749 LogRel(("VMMDev: Config mismatch - fBackdoorLogDisabled: config=%RTbool saved=%RTbool\n", pThis->fBackdoorLogDisabled, f));
2750
2751 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2752 if (pThis->fKeepCredentials != f)
2753 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fKeepCredentials: config=%RTbool saved=%RTbool"),
2754 pThis->fKeepCredentials, f);
2755 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2756 if (pThis->fHeapEnabled != f)
2757 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fHeapEnabled: config=%RTbool saved=%RTbool"),
2758 pThis->fHeapEnabled, f);
2759 }
2760
2761 if (uPass != SSM_PASS_FINAL)
2762 return VINF_SUCCESS;
2763
2764 /* state */
2765 SSMR3GetU32(pSSM, &pThis->hypervisorSize);
2766 SSMR3GetU32(pSSM, &pThis->mouseCapabilities);
2767 SSMR3GetS32(pSSM, &pThis->mouseXAbs);
2768 SSMR3GetS32(pSSM, &pThis->mouseYAbs);
2769
2770 SSMR3GetBool(pSSM, &pThis->fNewGuestFilterMask);
2771 SSMR3GetU32(pSSM, &pThis->u32NewGuestFilterMask);
2772 SSMR3GetU32(pSSM, &pThis->u32GuestFilterMask);
2773 SSMR3GetU32(pSSM, &pThis->u32HostEventFlags);
2774
2775// SSMR3GetBool(pSSM, &pThis->pVMMDevRAMR3->fHaveEvents);
2776 // here be dragons (probably)
2777 SSMR3GetMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof (pThis->pVMMDevRAMR3->V));
2778
2779 SSMR3GetMem(pSSM, &pThis->guestInfo, sizeof (pThis->guestInfo));
2780 SSMR3GetU32(pSSM, &pThis->fu32AdditionsOk);
2781 SSMR3GetU32(pSSM, &pThis->u32VideoAccelEnabled);
2782 if (uVersion > 10)
2783 SSMR3GetBool(pSSM, &pThis->displayChangeData.fGuestSentChangeEventAck);
2784
2785 rc = SSMR3GetU32(pSSM, &pThis->guestCaps);
2786
2787 /* Attributes which were temporarily introduced in r30072 */
2788 if (uVersion == 7)
2789 {
2790 uint32_t temp;
2791 SSMR3GetU32(pSSM, &temp);
2792 rc = SSMR3GetU32(pSSM, &temp);
2793 }
2794 AssertRCReturn(rc, rc);
2795
2796#ifdef VBOX_WITH_HGCM
2797 rc = vmmdevHGCMLoadState(pThis, pSSM, uVersion);
2798 AssertRCReturn(rc, rc);
2799#endif /* VBOX_WITH_HGCM */
2800
2801 if (uVersion >= 10)
2802 rc = SSMR3GetU32(pSSM, &pThis->fHostCursorRequested);
2803 AssertRCReturn(rc, rc);
2804
2805 if (uVersion > VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2)
2806 {
2807 SSMR3GetU32(pSSM, &pThis->guestInfo2.uFullVersion);
2808 SSMR3GetU32(pSSM, &pThis->guestInfo2.uRevision);
2809 SSMR3GetU32(pSSM, &pThis->guestInfo2.fFeatures);
2810 rc = SSMR3GetStrZ(pSSM, &pThis->guestInfo2.szName[0], sizeof(pThis->guestInfo2.szName));
2811 AssertRCReturn(rc, rc);
2812 }
2813
2814 /*
2815 * On a resume, we send the capabilities changed message so
2816 * that listeners can sync their state again
2817 */
2818 Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
2819 if (pThis->pDrv)
2820 {
2821 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
2822 if (uVersion >= 10)
2823 pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
2824 /*fVisible=*/!!pThis->fHostCursorRequested,
2825 /*fAlpha=*/false,
2826 /*xHot=*/0, /*yHot=*/0,
2827 /*cx=*/0, /*cy=*/0,
2828 /*pvShape=*/NULL);
2829 }
2830
2831 /* Reestablish the acceleration status. */
2832 if ( pThis->u32VideoAccelEnabled
2833 && pThis->pDrv)
2834 {
2835 pThis->pDrv->pfnVideoAccelEnable(pThis->pDrv, !!pThis->u32VideoAccelEnabled, &pThis->pVMMDevRAMR3->vbvaMemory);
2836 }
2837
2838 if (pThis->fu32AdditionsOk)
2839 {
2840 LogRel(("Guest Additions information report: additionsVersion = 0x%08X, osType = 0x%08X\n",
2841 pThis->guestInfo.interfaceVersion,
2842 pThis->guestInfo.osType));
2843 if (pThis->pDrv)
2844 {
2845 if (pThis->guestInfo2.uFullVersion)
2846 pThis->pDrv->pfnUpdateGuestInfo2(pThis->pDrv, pThis->guestInfo2.uFullVersion, pThis->guestInfo2.szName,
2847 pThis->guestInfo2.uRevision, pThis->guestInfo2.fFeatures);
2848 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
2849 }
2850 }
2851 if (pThis->pDrv)
2852 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
2853
2854 return VINF_SUCCESS;
2855}
2856
2857/**
2858 * Load state done callback. Notify guest of restore event.
2859 *
2860 * @returns VBox status code.
2861 * @param pDevIns The device instance.
2862 * @param pSSM The handle to the saved state.
2863 */
2864static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
2865{
2866 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2867
2868#ifdef VBOX_WITH_HGCM
2869 int rc = vmmdevHGCMLoadStateDone(pThis, pSSM);
2870 AssertLogRelRCReturn(rc, rc);
2871#endif /* VBOX_WITH_HGCM */
2872
2873 VMMDevNotifyGuest(pThis, VMMDEV_EVENT_RESTORED);
2874
2875 return VINF_SUCCESS;
2876}
2877
2878/* -=-=-=-=- PDMDEVREG -=-=-=-=- */
2879
2880/**
2881 * (Re-)initializes the MMIO2 data.
2882 *
2883 * @param pThis Pointer to the VMMDev instance data.
2884 */
2885static void vmmdevInitRam(VMMDevState *pThis)
2886{
2887 memset(pThis->pVMMDevRAMR3, 0, sizeof(VMMDevMemory));
2888 pThis->pVMMDevRAMR3->u32Size = sizeof(VMMDevMemory);
2889 pThis->pVMMDevRAMR3->u32Version = VMMDEV_MEMORY_VERSION;
2890}
2891
2892/**
2893 * Reset notification.
2894 *
2895 * @returns VBox status.
2896 * @param pDrvIns The driver instance data.
2897 */
2898static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
2899{
2900 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2901
2902 /*
2903 * Reset the mouse integration feature bits
2904 */
2905 if (pThis->mouseCapabilities & VMMDEV_MOUSE_GUEST_MASK)
2906 {
2907 pThis->mouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
2908 /* notify the connector */
2909 Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
2910 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
2911 }
2912 pThis->fHostCursorRequested = false;
2913
2914 pThis->hypervisorSize = 0;
2915
2916 /* re-initialize the VMMDev memory */
2917 if (pThis->pVMMDevRAMR3)
2918 vmmdevInitRam(pThis);
2919
2920 /* credentials have to go away (by default) */
2921 if (!pThis->fKeepCredentials)
2922 {
2923 memset(pThis->pCredentials->Logon.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2924 memset(pThis->pCredentials->Logon.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2925 memset(pThis->pCredentials->Logon.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2926 }
2927 memset(pThis->pCredentials->Judge.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2928 memset(pThis->pCredentials->Judge.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2929 memset(pThis->pCredentials->Judge.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2930
2931 /* Reset means that additions will report again. */
2932 const bool fVersionChanged = pThis->fu32AdditionsOk
2933 || pThis->guestInfo.interfaceVersion
2934 || pThis->guestInfo.osType != VBOXOSTYPE_Unknown;
2935 if (fVersionChanged)
2936 Log(("vmmdevReset: fu32AdditionsOk=%d additionsVersion=%x osType=%#x\n",
2937 pThis->fu32AdditionsOk, pThis->guestInfo.interfaceVersion, pThis->guestInfo.osType));
2938 pThis->fu32AdditionsOk = false;
2939 memset (&pThis->guestInfo, 0, sizeof (pThis->guestInfo));
2940
2941 /* clear pending display change request. */
2942 for (unsigned i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
2943 {
2944 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
2945 memset (&pRequest->lastReadDisplayChangeRequest, 0, sizeof (pRequest->lastReadDisplayChangeRequest));
2946 }
2947 pThis->displayChangeData.iCurrentMonitor = 0;
2948 pThis->displayChangeData.fGuestSentChangeEventAck = false;
2949
2950 /* disable seamless mode */
2951 pThis->fLastSeamlessEnabled = false;
2952
2953 /* disabled memory ballooning */
2954 pThis->u32LastMemoryBalloonSize = 0;
2955
2956 /* disabled statistics updating */
2957 pThis->u32LastStatIntervalSize = 0;
2958
2959 /* Clear the "HGCM event enabled" flag so the event can be automatically reenabled. */
2960 pThis->u32HGCMEnabled = 0;
2961
2962 /*
2963 * Clear the event variables.
2964 *
2965 * XXX By design we should NOT clear pThis->u32HostEventFlags because it is designed
2966 * that way so host events do not depend on guest resets. However, the pending
2967 * event flags actually _were_ cleared since ages so we mask out events from
2968 * clearing which we really need to survive the reset. See xtracker 5767.
2969 */
2970 pThis->u32HostEventFlags &= VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
2971 pThis->u32GuestFilterMask = 0;
2972 pThis->u32NewGuestFilterMask = 0;
2973 pThis->fNewGuestFilterMask = 0;
2974
2975 /* This is the default, as Windows and OS/2 guests take this for granted. (Actually, neither does...) */
2976 /** @todo change this when we next bump the interface version */
2977 const bool fCapsChanged = pThis->guestCaps != VMMDEV_GUEST_SUPPORTS_GRAPHICS;
2978 if (fCapsChanged)
2979 Log(("vmmdevReset: fCapsChanged=%#x -> %#x\n", pThis->guestCaps, VMMDEV_GUEST_SUPPORTS_GRAPHICS));
2980 pThis->guestCaps = VMMDEV_GUEST_SUPPORTS_GRAPHICS; /** @todo r=bird: why? I cannot see this being done at construction?*/
2981
2982 /*
2983 * Call the update functions as required.
2984 */
2985 if (fVersionChanged)
2986 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
2987 if (fCapsChanged)
2988 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
2989
2990 /* Generate a unique session id for this VM; it will be changed for each start, reset or restore.
2991 * This can be used for restore detection inside the guest.
2992 */
2993 pThis->idSession = ASMReadTSC();
2994}
2995
2996
2997/**
2998 * @interface_method_impl{PDMDEVREG,pfnRelocate}
2999 */
3000static DECLCALLBACK(void) vmmdevRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
3001{
3002 NOREF(pDevIns);
3003 NOREF(offDelta);
3004}
3005
3006
3007/**
3008 * @interface_method_impl{PDMDEVREG,pfnDestruct}
3009 */
3010static DECLCALLBACK(int) vmmdevDestroy(PPDMDEVINS pDevIns)
3011{
3012 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3013 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
3014
3015 /*
3016 * Wipe and free the credentials.
3017 */
3018 if (pThis->pCredentials)
3019 {
3020 RTMemWipeThoroughly(pThis->pCredentials, sizeof(*pThis->pCredentials), 10);
3021 RTMemFree(pThis->pCredentials);
3022 pThis->pCredentials = NULL;
3023 }
3024
3025 return VINF_SUCCESS;
3026}
3027
3028
3029/**
3030 * @interface_method_impl{PDMDEVREG,pfnConstruct}
3031 */
3032static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
3033{
3034 int rc;
3035 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
3036
3037 Assert(iInstance == 0);
3038 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3039
3040 /*
3041 * Initialize data (most of it anyway).
3042 */
3043 /* Save PDM device instance data for future reference. */
3044 pThis->pDevIns = pDevIns;
3045
3046 /* PCI vendor, just a free bogus value */
3047 PCIDevSetVendorId(&pThis->dev, 0x80ee);
3048 /* device ID */
3049 PCIDevSetDeviceId(&pThis->dev, 0xcafe);
3050 /* class sub code (other type of system peripheral) */
3051 PCIDevSetClassSub(&pThis->dev, 0x80);
3052 /* class base code (base system peripheral) */
3053 PCIDevSetClassBase(&pThis->dev, 0x08);
3054 /* header type */
3055 PCIDevSetHeaderType(&pThis->dev, 0x00);
3056 /* interrupt on pin 0 */
3057 PCIDevSetInterruptPin(&pThis->dev, 0x01);
3058
3059 /*
3060 * Interfaces
3061 */
3062 /* IBase */
3063 pThis->IBase.pfnQueryInterface = vmmdevPortQueryInterface;
3064
3065 /* VMMDev port */
3066 pThis->IPort.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
3067 pThis->IPort.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
3068 pThis->IPort.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
3069 pThis->IPort.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
3070 pThis->IPort.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
3071 pThis->IPort.pfnSetCredentials = vmmdevSetCredentials;
3072 pThis->IPort.pfnVBVAChange = vmmdevVBVAChange;
3073 pThis->IPort.pfnRequestSeamlessChange = vmmdevRequestSeamlessChange;
3074 pThis->IPort.pfnSetMemoryBalloon = vmmdevSetMemoryBalloon;
3075 pThis->IPort.pfnSetStatisticsInterval = vmmdevSetStatisticsInterval;
3076 pThis->IPort.pfnVRDPChange = vmmdevVRDPChange;
3077 pThis->IPort.pfnCpuHotUnplug = vmmdevCpuHotUnplug;
3078 pThis->IPort.pfnCpuHotPlug = vmmdevCpuHotPlug;
3079
3080 /* Shared folder LED */
3081 pThis->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
3082 pThis->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
3083
3084#ifdef VBOX_WITH_HGCM
3085 /* HGCM port */
3086 pThis->IHGCMPort.pfnCompleted = hgcmCompleted;
3087#endif
3088
3089 pThis->pCredentials = (VMMDEVCREDS *)RTMemAllocZ(sizeof(*pThis->pCredentials));
3090 if (!pThis->pCredentials)
3091 return VERR_NO_MEMORY;
3092
3093
3094 /*
3095 * Validate and read the configuration.
3096 */
3097 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns,
3098 "GetHostTimeDisabled|"
3099 "BackdoorLogDisabled|"
3100 "KeepCredentials|"
3101 "HeapEnabled|"
3102 "RamSize|"
3103 "RZEnabled|"
3104 "GuestCoreDumpEnabled|"
3105 "GuestCoreDumpDir|"
3106 "GuestCoreDumpCount|"
3107 "TestingEnabled"
3108 ,
3109 "");
3110
3111 rc = CFGMR3QueryU64(pCfg, "RamSize", &pThis->cbGuestRAM);
3112 if (RT_FAILURE(rc))
3113 return PDMDEV_SET_ERROR(pDevIns, rc,
3114 N_("Configuration error: Failed querying \"RamSize\" as a 64-bit unsigned integer"));
3115
3116 rc = CFGMR3QueryBoolDef(pCfg, "GetHostTimeDisabled", &pThis->fGetHostTimeDisabled, false);
3117 if (RT_FAILURE(rc))
3118 return PDMDEV_SET_ERROR(pDevIns, rc,
3119 N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
3120
3121 rc = CFGMR3QueryBoolDef(pCfg, "BackdoorLogDisabled", &pThis->fBackdoorLogDisabled, false);
3122 if (RT_FAILURE(rc))
3123 return PDMDEV_SET_ERROR(pDevIns, rc,
3124 N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
3125
3126 rc = CFGMR3QueryBoolDef(pCfg, "KeepCredentials", &pThis->fKeepCredentials, false);
3127 if (RT_FAILURE(rc))
3128 return PDMDEV_SET_ERROR(pDevIns, rc,
3129 N_("Configuration error: Failed querying \"KeepCredentials\" as a boolean"));
3130
3131 rc = CFGMR3QueryBoolDef(pCfg, "HeapEnabled", &pThis->fHeapEnabled, true);
3132 if (RT_FAILURE(rc))
3133 return PDMDEV_SET_ERROR(pDevIns, rc,
3134 N_("Configuration error: Failed querying \"HeapEnabled\" as a boolean"));
3135
3136 rc = CFGMR3QueryBoolDef(pCfg, "RZEnabled", &pThis->fRZEnabled, true);
3137 if (RT_FAILURE(rc))
3138 return PDMDEV_SET_ERROR(pDevIns, rc,
3139 N_("Configuration error: Failed querying \"RZEnabled\" as a boolean"));
3140
3141 rc = CFGMR3QueryBoolDef(pCfg, "GuestCoreDumpEnabled", &pThis->fGuestCoreDumpEnabled, false);
3142 if (RT_FAILURE(rc))
3143 return PDMDEV_SET_ERROR(pDevIns, rc,
3144 N_("Configuration error: Failed querying \"GuestCoreDumpEnabled\" as a boolean"));
3145
3146 char *pszGuestCoreDumpDir = NULL;
3147 rc = CFGMR3QueryStringAllocDef(pCfg, "GuestCoreDumpDir", &pszGuestCoreDumpDir, "");
3148 if (RT_FAILURE(rc))
3149 return PDMDEV_SET_ERROR(pDevIns, rc,
3150 N_("Configuration error: Failed querying \"GuestCoreDumpDir\" as a string"));
3151
3152 RTStrCopy(pThis->szGuestCoreDumpDir, sizeof(pThis->szGuestCoreDumpDir), pszGuestCoreDumpDir);
3153 MMR3HeapFree(pszGuestCoreDumpDir);
3154
3155 rc = CFGMR3QueryU32Def(pCfg, "GuestCoreDumpCount", &pThis->cGuestCoreDumps, 3);
3156 if (RT_FAILURE(rc))
3157 return PDMDEV_SET_ERROR(pDevIns, rc,
3158 N_("Configuration error: Failed querying \"GuestCoreDumpCount\" as a 32-bit unsigned integer"));
3159
3160#ifndef VBOX_WITHOUT_TESTING_FEATURES
3161 rc = CFGMR3QueryBoolDef(pCfg, "TestingEnabled", &pThis->fTestingEnabled, false);
3162 if (RT_FAILURE(rc))
3163 return PDMDEV_SET_ERROR(pDevIns, rc,
3164 N_("Configuration error: Failed querying \"TestingEnabled\" as a boolean"));
3165 /** @todo image-to-load-filename? */
3166#endif
3167
3168 /*
3169 * Create the critical section for the device.
3170 */
3171 rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "VMMDev#u", iInstance);
3172 AssertRCReturn(rc, rc);
3173 /* Later: pDevIns->pCritSectR3 = &pThis->CritSect; */
3174
3175 /*
3176 * Register the backdoor logging port
3177 */
3178 rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
3179 AssertRCReturn(rc, rc);
3180
3181#ifdef TIMESYNC_BACKDOOR
3182 /*
3183 * Alternative timesync source (temporary!)
3184 */
3185 rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
3186 AssertRCReturn(rc, rc);
3187#endif
3188
3189 /*
3190 * Allocate and initialize the MMIO2 memory.
3191 */
3192 rc = PDMDevHlpMMIO2Register(pDevIns, 1 /*iRegion*/, VMMDEV_RAM_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevRAMR3, "VMMDev");
3193 if (RT_FAILURE(rc))
3194 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
3195 N_("Failed to allocate %u bytes of memory for the VMM device"), VMMDEV_RAM_SIZE);
3196 vmmdevInitRam(pThis);
3197
3198 if (pThis->fHeapEnabled)
3199 {
3200 rc = PDMDevHlpMMIO2Register(pDevIns, 2 /*iRegion*/, VMMDEV_HEAP_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevHeapR3, "VMMDev Heap");
3201 if (RT_FAILURE(rc))
3202 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
3203 N_("Failed to allocate %u bytes of memory for the VMM device heap"), PAGE_SIZE);
3204 }
3205
3206 /*
3207 * Register the PCI device.
3208 */
3209 rc = PDMDevHlpPCIRegister(pDevIns, &pThis->dev);
3210 if (RT_FAILURE(rc))
3211 return rc;
3212 if (pThis->dev.devfn != 32 || iInstance != 0)
3213 Log(("!!WARNING!!: pThis->dev.devfn=%d (ignore if testcase or no started by Main)\n", pThis->dev.devfn));
3214 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
3215 if (RT_FAILURE(rc))
3216 return rc;
3217 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
3218 if (RT_FAILURE(rc))
3219 return rc;
3220 if (pThis->fHeapEnabled)
3221 {
3222 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, VMMDEV_HEAP_SIZE, PCI_ADDRESS_SPACE_MEM_PREFETCH, vmmdevIORAMRegionMap);
3223 if (RT_FAILURE(rc))
3224 return rc;
3225 }
3226
3227#ifndef VBOX_WITHOUT_TESTING_FEATURES
3228 /*
3229 * Initialize testing.
3230 */
3231 rc = vmmdevTestingInitialize(pDevIns);
3232 if (RT_FAILURE(rc))
3233 return rc;
3234#endif
3235
3236 /*
3237 * Get the corresponding connector interface
3238 */
3239 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "VMM Driver Port");
3240 if (RT_SUCCESS(rc))
3241 {
3242 pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIVMMDEVCONNECTOR);
3243 AssertMsgReturn(pThis->pDrv, ("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
3244#ifdef VBOX_WITH_HGCM
3245 pThis->pHGCMDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIHGCMCONNECTOR);
3246 if (!pThis->pHGCMDrv)
3247 {
3248 Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Rrc\n", rc));
3249 /* this is not actually an error, just means that there is no support for HGCM */
3250 }
3251#endif
3252 /* Query the initial balloon size. */
3253 AssertPtr(pThis->pDrv->pfnQueryBalloonSize);
3254 rc = pThis->pDrv->pfnQueryBalloonSize(pThis->pDrv, &pThis->u32MemoryBalloonSize);
3255 AssertRC(rc);
3256
3257 Log(("Initial balloon size %x\n", pThis->u32MemoryBalloonSize));
3258 }
3259 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
3260 {
3261 Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pReg->szName, pDevIns->iInstance));
3262 rc = VINF_SUCCESS;
3263 }
3264 else
3265 AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Rrc\n", rc), rc);
3266
3267 /*
3268 * Attach status driver for shared folders (optional).
3269 */
3270 PPDMIBASE pBase;
3271 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port");
3272 if (RT_SUCCESS(rc))
3273 pThis->SharedFolders.pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
3274 else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
3275 {
3276 AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
3277 return rc;
3278 }
3279
3280 /*
3281 * Register saved state and init the HGCM CmdList critsect.
3282 */
3283 rc = PDMDevHlpSSMRegisterEx(pDevIns, VMMDEV_SAVED_STATE_VERSION, sizeof(*pThis), NULL,
3284 NULL, vmmdevLiveExec, NULL,
3285 NULL, vmmdevSaveExec, NULL,
3286 NULL, vmmdevLoadExec, vmmdevLoadStateDone);
3287 AssertRCReturn(rc, rc);
3288
3289#ifdef VBOX_WITH_HGCM
3290 pThis->pHGCMCmdList = NULL;
3291 rc = RTCritSectInit(&pThis->critsectHGCMCmdList);
3292 AssertRCReturn(rc, rc);
3293 pThis->u32HGCMEnabled = 0;
3294#endif /* VBOX_WITH_HGCM */
3295
3296 /* In this version of VirtualBox the GUI checks whether "needs host cursor"
3297 * changes. */
3298 pThis->mouseCapabilities |= VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
3299
3300 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMemBalloonChunks, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Memory balloon size", "/Devices/VMMDev/BalloonChunks");
3301
3302 /* Generate a unique session id for this VM; it will be changed for each start, reset or restore.
3303 * This can be used for restore detection inside the guest.
3304 */
3305 pThis->idSession = ASMReadTSC();
3306 return rc;
3307}
3308
3309/**
3310 * The device registration structure.
3311 */
3312extern "C" const PDMDEVREG g_DeviceVMMDev =
3313{
3314 /* u32Version */
3315 PDM_DEVREG_VERSION,
3316 /* szName */
3317 "VMMDev",
3318 /* szRCMod */
3319 "VBoxDDGC.gc",
3320 /* szR0Mod */
3321 "VBoxDDR0.r0",
3322 /* pszDescription */
3323 "VirtualBox VMM Device\n",
3324 /* fFlags */
3325 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
3326 /* fClass */
3327 PDM_DEVREG_CLASS_VMM_DEV,
3328 /* cMaxInstances */
3329 1,
3330 /* cbInstance */
3331 sizeof(VMMDevState),
3332 /* pfnConstruct */
3333 vmmdevConstruct,
3334 /* pfnDestruct */
3335 NULL,
3336 /* pfnRelocate */
3337 vmmdevRelocate,
3338 /* pfnIOCtl */
3339 NULL,
3340 /* pfnPowerOn */
3341 NULL,
3342 /* pfnReset */
3343 vmmdevReset,
3344 /* pfnSuspend */
3345 NULL,
3346 /* pfnResume */
3347 NULL,
3348 /* pfnAttach */
3349 NULL,
3350 /* pfnDetach */
3351 NULL,
3352 /* pfnQueryInterface. */
3353 NULL,
3354 /* pfnInitComplete */
3355 NULL,
3356 /* pfnPowerOff */
3357 NULL,
3358 /* pfnSoftReset */
3359 NULL,
3360 /* u32VersionEnd */
3361 PDM_DEVREG_VERSION
3362};
3363#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
Note: See TracBrowser for help on using the repository browser.

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