VirtualBox

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

Last change on this file since 36730 was 36202, checked in by vboxsync, 14 years ago

VMMDev: be a bit more verbose

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