VirtualBox

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

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

VBoxVideo: add some explicit typecasts

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 123.5 KB
Line 
1/* $Id: VMMDev.cpp 37378 2011-06-08 14:18:45Z 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(RTRECT)
1475 < sizeof(VMMDevVideoSetVisibleRegion))
1476 {
1477 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1478 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1479 }
1480 else if (!pThis->pDrv)
1481 {
1482 Log(("VMMDevReq_VideoSetVisibleRegion Connector is NULL!!!\n"));
1483 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1484 }
1485 else
1486 {
1487 VMMDevVideoSetVisibleRegion *ptr = (VMMDevVideoSetVisibleRegion *)pRequestHeader;
1488
1489 if (pRequestHeader->size != ((uint64_t)sizeof(VMMDevVideoSetVisibleRegion)) + ptr->cRect * sizeof(RTRECT) - sizeof(RTRECT))
1490 {
1491 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1492 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1493 }
1494 else
1495 {
1496 Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", ptr->cRect));
1497 /* forward the call */
1498 pRequestHeader->rc = pThis->pDrv->pfnSetVisibleRegion(pThis->pDrv, ptr->cRect, &ptr->Rect);
1499 }
1500 }
1501 break;
1502 }
1503
1504 case VMMDevReq_GetSeamlessChangeRequest:
1505 {
1506 if (pRequestHeader->size != sizeof(VMMDevSeamlessChangeRequest))
1507 {
1508 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1509 }
1510 else
1511 {
1512 VMMDevSeamlessChangeRequest *seamlessChangeRequest = (VMMDevSeamlessChangeRequest*)pRequestHeader;
1513 /* just pass on the information */
1514 Log(("VMMDev: returning seamless change request mode=%d\n", pThis->fSeamlessEnabled));
1515 if (pThis->fSeamlessEnabled)
1516 seamlessChangeRequest->mode = VMMDev_Seamless_Visible_Region;
1517 else
1518 seamlessChangeRequest->mode = VMMDev_Seamless_Disabled;
1519
1520 if (seamlessChangeRequest->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
1521 {
1522 /* Remember which mode the client has queried. */
1523 pThis->fLastSeamlessEnabled = pThis->fSeamlessEnabled;
1524 }
1525
1526 pRequestHeader->rc = VINF_SUCCESS;
1527 }
1528 break;
1529 }
1530
1531 case VMMDevReq_GetVRDPChangeRequest:
1532 {
1533 if (pRequestHeader->size != sizeof(VMMDevVRDPChangeRequest))
1534 {
1535 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1536 }
1537 else
1538 {
1539 VMMDevVRDPChangeRequest *vrdpChangeRequest = (VMMDevVRDPChangeRequest*)pRequestHeader;
1540 /* just pass on the information */
1541 Log(("VMMDev: returning VRDP status %d level %d\n", pThis->fVRDPEnabled, pThis->u32VRDPExperienceLevel));
1542
1543 vrdpChangeRequest->u8VRDPActive = pThis->fVRDPEnabled;
1544 vrdpChangeRequest->u32VRDPExperienceLevel = pThis->u32VRDPExperienceLevel;
1545
1546 pRequestHeader->rc = VINF_SUCCESS;
1547 }
1548 break;
1549 }
1550
1551 case VMMDevReq_GetMemBalloonChangeRequest:
1552 {
1553 Log(("VMMDevReq_GetMemBalloonChangeRequest\n"));
1554 if (pRequestHeader->size != sizeof(VMMDevGetMemBalloonChangeRequest))
1555 {
1556 AssertFailed();
1557 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1558 }
1559 else
1560 {
1561 VMMDevGetMemBalloonChangeRequest *memBalloonChangeRequest = (VMMDevGetMemBalloonChangeRequest*)pRequestHeader;
1562 /* just pass on the information */
1563 Log(("VMMDev: returning memory balloon size =%d\n", pThis->u32MemoryBalloonSize));
1564 memBalloonChangeRequest->cBalloonChunks = pThis->u32MemoryBalloonSize;
1565 memBalloonChangeRequest->cPhysMemChunks = pThis->cbGuestRAM / (uint64_t)_1M;
1566
1567 if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
1568 {
1569 /* Remember which mode the client has queried. */
1570 pThis->u32LastMemoryBalloonSize = pThis->u32MemoryBalloonSize;
1571 }
1572
1573 pRequestHeader->rc = VINF_SUCCESS;
1574 }
1575 break;
1576 }
1577
1578 case VMMDevReq_ChangeMemBalloon:
1579 {
1580 VMMDevChangeMemBalloon *memBalloonChange = (VMMDevChangeMemBalloon*)pRequestHeader;
1581
1582 Log(("VMMDevReq_ChangeMemBalloon\n"));
1583 if ( pRequestHeader->size < sizeof(VMMDevChangeMemBalloon)
1584 || memBalloonChange->cPages != VMMDEV_MEMORY_BALLOON_CHUNK_PAGES
1585 || pRequestHeader->size != (uint32_t)RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[memBalloonChange->cPages]))
1586 {
1587 AssertFailed();
1588 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1589 }
1590 else
1591 {
1592 pRequestHeader->rc = PGMR3PhysChangeMemBalloon(PDMDevHlpGetVM(pDevIns), !!memBalloonChange->fInflate, memBalloonChange->cPages, memBalloonChange->aPhysPage);
1593 if (memBalloonChange->fInflate)
1594 STAM_REL_U32_INC(&pThis->StatMemBalloonChunks);
1595 else
1596 STAM_REL_U32_DEC(&pThis->StatMemBalloonChunks);
1597 }
1598 break;
1599 }
1600
1601 case VMMDevReq_GetStatisticsChangeRequest:
1602 {
1603 Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
1604 if (pRequestHeader->size != sizeof(VMMDevGetStatisticsChangeRequest))
1605 {
1606 AssertFailed();
1607 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1608 }
1609 else
1610 {
1611 VMMDevGetStatisticsChangeRequest *statIntervalChangeRequest = (VMMDevGetStatisticsChangeRequest*)pRequestHeader;
1612 /* just pass on the information */
1613 Log(("VMMDev: returning statistics interval %d seconds\n", pThis->u32StatIntervalSize));
1614 statIntervalChangeRequest->u32StatInterval = pThis->u32StatIntervalSize;
1615
1616 if (statIntervalChangeRequest->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
1617 {
1618 /* Remember which mode the client has queried. */
1619 pThis->u32LastStatIntervalSize= pThis->u32StatIntervalSize;
1620 }
1621
1622 pRequestHeader->rc = VINF_SUCCESS;
1623 }
1624 break;
1625 }
1626
1627 case VMMDevReq_ReportGuestStats:
1628 {
1629 Log(("VMMDevReq_ReportGuestStats\n"));
1630 if (pRequestHeader->size != sizeof(VMMDevReportGuestStats))
1631 {
1632 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1633 }
1634 else
1635 {
1636 VMMDevReportGuestStats *stats = (VMMDevReportGuestStats*)pRequestHeader;
1637
1638#ifdef DEBUG
1639 VBoxGuestStatistics *pGuestStats = &stats->guestStats;
1640
1641 Log(("Current statistics:\n"));
1642 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
1643 Log(("CPU%d: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
1644
1645 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
1646 Log(("CPU%d: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
1647
1648 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
1649 Log(("CPU%d: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
1650
1651 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
1652 Log(("CPU%d: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
1653
1654 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
1655 Log(("CPU%d: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
1656
1657 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
1658 Log(("CPU%d: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
1659
1660 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
1661 Log(("CPU%d: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
1662
1663 /* Note that reported values are in pages; upper layers expect them in megabytes */
1664 Log(("CPU%d: Page size %-4d bytes\n", pGuestStats->u32CpuId, pGuestStats->u32PageSize));
1665 Assert(pGuestStats->u32PageSize == 4096);
1666
1667 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
1668 Log(("CPU%d: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/_4K)-1) / (_1M/_4K)));
1669
1670 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
1671 Log(("CPU%d: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/_4K)));
1672
1673 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
1674 Log(("CPU%d: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/_4K)));
1675
1676 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
1677 Log(("CPU%d: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/_4K)));
1678
1679 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
1680 Log(("CPU%d: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/_4K)));
1681
1682 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
1683 Log(("CPU%d: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/_4K)));
1684
1685 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
1686 Log(("CPU%d: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/_4K)));
1687
1688 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
1689 Log(("CPU%d: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/_4K)));
1690
1691 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
1692 Log(("CPU%d: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/_4K)));
1693 Log(("Statistics end *******************\n"));
1694#endif
1695
1696 /* forward the call */
1697 pRequestHeader->rc = pThis->pDrv->pfnReportStatistics(pThis->pDrv, &stats->guestStats);
1698 }
1699 break;
1700 }
1701
1702 case VMMDevReq_QueryCredentials:
1703 {
1704 if (pRequestHeader->size != sizeof(VMMDevCredentials))
1705 {
1706 AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
1707 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1708 }
1709 else
1710 {
1711 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
1712
1713 /* let's start by nulling out the data */
1714 memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1715 memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1716 memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1717
1718 /* should we return whether we got credentials for a logon? */
1719 if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
1720 {
1721 if ( pThis->pCredentials->Logon.szUserName[0]
1722 || pThis->pCredentials->Logon.szPassword[0]
1723 || pThis->pCredentials->Logon.szDomain[0])
1724 {
1725 credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
1726 }
1727 else
1728 {
1729 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
1730 }
1731 }
1732
1733 /* does the guest want to read logon credentials? */
1734 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
1735 {
1736 if (pThis->pCredentials->Logon.szUserName[0])
1737 strcpy(credentials->szUserName, pThis->pCredentials->Logon.szUserName);
1738 if (pThis->pCredentials->Logon.szPassword[0])
1739 strcpy(credentials->szPassword, pThis->pCredentials->Logon.szPassword);
1740 if (pThis->pCredentials->Logon.szDomain[0])
1741 strcpy(credentials->szDomain, pThis->pCredentials->Logon.szDomain);
1742 if (!pThis->pCredentials->Logon.fAllowInteractiveLogon)
1743 credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
1744 else
1745 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
1746 }
1747
1748 if (!pThis->fKeepCredentials)
1749 {
1750 /* does the caller want us to destroy the logon credentials? */
1751 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
1752 {
1753 memset(pThis->pCredentials->Logon.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1754 memset(pThis->pCredentials->Logon.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1755 memset(pThis->pCredentials->Logon.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1756 }
1757 }
1758
1759 /* does the guest want to read credentials for verification? */
1760 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
1761 {
1762 if (pThis->pCredentials->Judge.szUserName[0])
1763 strcpy(credentials->szUserName, pThis->pCredentials->Judge.szUserName);
1764 if (pThis->pCredentials->Judge.szPassword[0])
1765 strcpy(credentials->szPassword, pThis->pCredentials->Judge.szPassword);
1766 if (pThis->pCredentials->Judge.szDomain[0])
1767 strcpy(credentials->szDomain, pThis->pCredentials->Judge.szDomain);
1768 }
1769
1770 /* does the caller want us to destroy the judgement credentials? */
1771 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
1772 {
1773 memset(pThis->pCredentials->Judge.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1774 memset(pThis->pCredentials->Judge.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1775 memset(pThis->pCredentials->Judge.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
1776 }
1777
1778 pRequestHeader->rc = VINF_SUCCESS;
1779 }
1780 break;
1781 }
1782
1783 case VMMDevReq_ReportCredentialsJudgement:
1784 {
1785 if (pRequestHeader->size != sizeof(VMMDevCredentials))
1786 {
1787 AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
1788 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1789 }
1790 else
1791 {
1792 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
1793
1794 /* what does the guest think about the credentials? (note: the order is important here!) */
1795 if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
1796 {
1797 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
1798 }
1799 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
1800 {
1801 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
1802 }
1803 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
1804 {
1805 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
1806 }
1807 else
1808 Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
1809
1810 pRequestHeader->rc = VINF_SUCCESS;
1811 }
1812 break;
1813 }
1814
1815 /*
1816 * Implemented in 3.1.0.
1817 *
1818 * Note! The ring-0 VBoxGuestLib uses this to check whether
1819 * VMMDevHGCMParmType_PageList is supported.
1820 */
1821 case VMMDevReq_GetHostVersion:
1822 {
1823 AssertMsgBreakStmt(pRequestHeader->size == sizeof(VMMDevReqHostVersion),
1824 ("%#x < %#x\n", pRequestHeader->size, sizeof(VMMDevReqLogString)),
1825 pRequestHeader->rc = VERR_INVALID_PARAMETER);
1826 VMMDevReqHostVersion *pReqHostVer = (VMMDevReqHostVersion*)pRequestHeader;
1827 pReqHostVer->major = RTBldCfgVersionMajor();
1828 pReqHostVer->minor = RTBldCfgVersionMinor();
1829 pReqHostVer->build = RTBldCfgVersionBuild();
1830 pReqHostVer->revision = RTBldCfgRevision();
1831 pReqHostVer->features = VMMDEV_HVF_HGCM_PHYS_PAGE_LIST;
1832 pReqHostVer->header.rc = VINF_SUCCESS;
1833 break;
1834 }
1835
1836 case VMMDevReq_GetCpuHotPlugRequest:
1837 {
1838 VMMDevGetCpuHotPlugRequest *pReqCpuHotPlug = (VMMDevGetCpuHotPlugRequest *)pRequestHeader;
1839
1840 if (pRequestHeader->size != sizeof(VMMDevGetCpuHotPlugRequest))
1841 {
1842 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1843 }
1844 else
1845 {
1846 pReqCpuHotPlug->enmEventType = pThis->enmCpuHotPlugEvent;
1847 pReqCpuHotPlug->idCpuCore = pThis->idCpuCore;
1848 pReqCpuHotPlug->idCpuPackage = pThis->idCpuPackage;
1849 pReqCpuHotPlug->header.rc = VINF_SUCCESS;
1850
1851 /* Clear the event */
1852 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_None;
1853 pThis->idCpuCore = UINT32_MAX;
1854 pThis->idCpuPackage = UINT32_MAX;
1855 }
1856 break;
1857 }
1858
1859 case VMMDevReq_SetCpuHotPlugStatus:
1860 {
1861 VMMDevCpuHotPlugStatusRequest *pReqCpuHotPlugStatus = (VMMDevCpuHotPlugStatusRequest *)pRequestHeader;
1862
1863 if (pRequestHeader->size != sizeof(VMMDevCpuHotPlugStatusRequest))
1864 {
1865 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1866 }
1867 else
1868 {
1869 pRequestHeader->rc = VINF_SUCCESS;
1870
1871 if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Disable)
1872 pThis->fCpuHotPlugEventsEnabled = false;
1873 else if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Enable)
1874 pThis->fCpuHotPlugEventsEnabled = true;
1875 else
1876 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1877 }
1878 break;
1879 }
1880
1881#ifdef VBOX_WITH_PAGE_SHARING
1882 case VMMDevReq_RegisterSharedModule:
1883 {
1884 VMMDevSharedModuleRegistrationRequest *pReqModule = (VMMDevSharedModuleRegistrationRequest *)pRequestHeader;
1885
1886 if ( pRequestHeader->size < sizeof(VMMDevSharedModuleRegistrationRequest)
1887 || pRequestHeader->size != RT_UOFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[pReqModule->cRegions]))
1888 {
1889 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1890 }
1891 else
1892 {
1893 pRequestHeader->rc = PGMR3SharedModuleRegister(PDMDevHlpGetVM(pDevIns), pReqModule->enmGuestOS, pReqModule->szName, pReqModule->szVersion,
1894 pReqModule->GCBaseAddr, pReqModule->cbModule,
1895 pReqModule->cRegions, pReqModule->aRegions);
1896 }
1897 break;
1898 }
1899
1900 case VMMDevReq_UnregisterSharedModule:
1901 {
1902 VMMDevSharedModuleUnregistrationRequest *pReqModule = (VMMDevSharedModuleUnregistrationRequest *)pRequestHeader;
1903
1904 if (pRequestHeader->size != sizeof(VMMDevSharedModuleUnregistrationRequest))
1905 {
1906 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1907 }
1908 else
1909 {
1910 pRequestHeader->rc = PGMR3SharedModuleUnregister(PDMDevHlpGetVM(pDevIns), pReqModule->szName, pReqModule->szVersion,
1911 pReqModule->GCBaseAddr, pReqModule->cbModule);
1912 }
1913 break;
1914 }
1915
1916 case VMMDevReq_CheckSharedModules:
1917 {
1918 VMMDevSharedModuleCheckRequest *pReqModule = (VMMDevSharedModuleCheckRequest *)pRequestHeader;
1919
1920 if (pRequestHeader->size != sizeof(VMMDevSharedModuleCheckRequest))
1921 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1922 else
1923 pRequestHeader->rc = PGMR3SharedModuleCheckAll(PDMDevHlpGetVM(pDevIns));
1924 break;
1925 }
1926
1927 case VMMDevReq_GetPageSharingStatus:
1928 {
1929 VMMDevPageSharingStatusRequest *pReqStatus = (VMMDevPageSharingStatusRequest *)pRequestHeader;
1930
1931 if (pRequestHeader->size != sizeof(VMMDevPageSharingStatusRequest))
1932 {
1933 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1934 }
1935 else
1936 {
1937 pReqStatus->fEnabled = false;
1938 pThis->pDrv->pfnIsPageFusionEnabled(pThis->pDrv, &pReqStatus->fEnabled);
1939 pRequestHeader->rc = VINF_SUCCESS;
1940 }
1941 break;
1942 }
1943
1944 case VMMDevReq_DebugIsPageShared:
1945 {
1946# ifdef DEBUG
1947 VMMDevPageIsSharedRequest *pReq = (VMMDevPageIsSharedRequest *)pRequestHeader;
1948
1949 if (pRequestHeader->size != sizeof(VMMDevPageIsSharedRequest))
1950 {
1951 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1952 }
1953 else
1954 {
1955 pRequestHeader->rc = PGMR3SharedModuleGetPageState(PDMDevHlpGetVM(pDevIns), pReq->GCPtrPage, &pReq->fShared, &pReq->uPageFlags);
1956 }
1957# else
1958 pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
1959# endif
1960 break;
1961 }
1962
1963#endif
1964
1965#ifdef DEBUG
1966 case VMMDevReq_LogString:
1967 {
1968 if (pRequestHeader->size < sizeof(VMMDevReqLogString))
1969 {
1970 AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
1971 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1972 }
1973 else
1974 {
1975 VMMDevReqLogString *pReqLogString = (VMMDevReqLogString *)pRequestHeader;
1976 LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR,
1977 ("DEBUG LOG: %s", pReqLogString->szString));
1978 pRequestHeader->rc = VINF_SUCCESS;
1979 }
1980 break;
1981 }
1982#endif
1983
1984 /*
1985 * Get a unique session id for this VM; the id will be different after each start, reset or restore of the VM
1986 * This can be used for restore detection inside the guest.
1987 */
1988 case VMMDevReq_GetSessionId:
1989 {
1990 if (pRequestHeader->size != sizeof(VMMDevReqSessionId))
1991 {
1992 AssertMsgFailed(("VMMDevReq_GetSessionId request size too small.\n"));
1993 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1994 }
1995 else
1996 {
1997 VMMDevReqSessionId *pReq = (VMMDevReqSessionId *)pRequestHeader;
1998 pReq->idSession = pThis->idSession;
1999 pRequestHeader->rc = VINF_SUCCESS;
2000 }
2001 break;
2002 }
2003
2004 default:
2005 {
2006 pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
2007 Log(("VMMDev unknown request type %d\n", pRequestHeader->requestType));
2008 break;
2009 }
2010 }
2011
2012l_end:
2013 /* Write the result back to guest memory */
2014 if (pRequestHeader)
2015 {
2016 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, pRequestHeader, pRequestHeader->size);
2017 RTMemFree(pRequestHeader);
2018 }
2019 else
2020 {
2021 /* early error case; write back header only */
2022 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
2023 }
2024
2025 PDMCritSectLeave(&pThis->CritSect);
2026 return rcRet;
2027}
2028
2029/**
2030 * Callback function for mapping an PCI I/O region.
2031 *
2032 * @return VBox status code.
2033 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
2034 * @param iRegion The region number.
2035 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
2036 * I/O port, else it's a physical address.
2037 * This address is *NOT* relative to pci_mem_base like earlier!
2038 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
2039 */
2040static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
2041{
2042 LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
2043 VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
2044 int rc;
2045
2046 if (iRegion == 1)
2047 {
2048 AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM, VERR_INTERNAL_ERROR);
2049 Assert(pThis->pVMMDevRAMR3 != NULL);
2050 if (GCPhysAddress != NIL_RTGCPHYS)
2051 {
2052 /*
2053 * Map the MMIO2 memory.
2054 */
2055 pThis->GCPhysVMMDevRAM = GCPhysAddress;
2056 Assert(pThis->GCPhysVMMDevRAM == GCPhysAddress);
2057 rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
2058 }
2059 else
2060 {
2061 /*
2062 * It is about to be unmapped, just clean up.
2063 */
2064 pThis->GCPhysVMMDevRAM = NIL_RTGCPHYS32;
2065 rc = VINF_SUCCESS;
2066 }
2067 }
2068 else if (iRegion == 2)
2069 {
2070 AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM_PREFETCH, VERR_INTERNAL_ERROR);
2071 Assert(pThis->pVMMDevHeapR3 != NULL);
2072 if (GCPhysAddress != NIL_RTGCPHYS)
2073 {
2074 /*
2075 * Map the MMIO2 memory.
2076 */
2077 pThis->GCPhysVMMDevHeap = GCPhysAddress;
2078 Assert(pThis->GCPhysVMMDevHeap == GCPhysAddress);
2079 rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
2080 if (RT_SUCCESS(rc))
2081 rc = PDMDevHlpRegisterVMMDevHeap(pPciDev->pDevIns, GCPhysAddress, pThis->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
2082 }
2083 else
2084 {
2085 /*
2086 * It is about to be unmapped, just clean up.
2087 */
2088 PDMDevHlpUnregisterVMMDevHeap(pPciDev->pDevIns, pThis->GCPhysVMMDevHeap);
2089 pThis->GCPhysVMMDevHeap = NIL_RTGCPHYS32;
2090 rc = VINF_SUCCESS;
2091 }
2092 }
2093 else
2094 {
2095 AssertMsgFailed(("%d\n", iRegion));
2096 rc = VERR_INVALID_PARAMETER;
2097 }
2098
2099 return rc;
2100}
2101
2102
2103/**
2104 * Callback function for mapping a PCI I/O region.
2105 *
2106 * @return VBox status code.
2107 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
2108 * @param iRegion The region number.
2109 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
2110 * I/O port, else it's a physical address.
2111 * This address is *NOT* relative to pci_mem_base like earlier!
2112 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
2113 */
2114static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
2115{
2116 VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
2117 int rc = VINF_SUCCESS;
2118
2119 Assert(enmType == PCI_ADDRESS_SPACE_IO);
2120 Assert(iRegion == 0);
2121 AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
2122
2123 /*
2124 * Save the base port address to simplify Port offset calculations.
2125 */
2126 pThis->PortBase = (RTIOPORT)GCPhysAddress;
2127
2128 /*
2129 * Register our port IO handlers.
2130 */
2131 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
2132 (RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST, 1,
2133 (void*)pThis, vmmdevRequestHandler,
2134 NULL, NULL, NULL, "VMMDev Request Handler");
2135 AssertRC(rc);
2136 return rc;
2137}
2138
2139/**
2140 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
2141 */
2142static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, const char *pszIID)
2143{
2144 VMMDevState *pThis = RT_FROM_MEMBER(pInterface, VMMDevState, IBase);
2145
2146 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
2147 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVPORT, &pThis->IPort);
2148#ifdef VBOX_WITH_HGCM
2149 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMPORT, &pThis->IHGCMPort);
2150#endif
2151 /* Currently only for shared folders. */
2152 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThis->SharedFolders.ILeds);
2153 return NULL;
2154}
2155
2156/**
2157 * Gets the pointer to the status LED of a unit.
2158 *
2159 * @returns VBox status code.
2160 * @param pInterface Pointer to the interface structure containing the called function pointer.
2161 * @param iLUN The unit which status LED we desire.
2162 * @param ppLed Where to store the LED pointer.
2163 */
2164static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
2165{
2166 VMMDevState *pThis = (VMMDevState *)( (uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, SharedFolders.ILeds) );
2167 if (iLUN == 0) /* LUN 0 is shared folders */
2168 {
2169 *ppLed = &pThis->SharedFolders.Led;
2170 return VINF_SUCCESS;
2171 }
2172 return VERR_PDM_LUN_NOT_FOUND;
2173}
2174
2175/* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
2176
2177/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
2178#define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, IPort)) )
2179
2180
2181/**
2182 * Return the current absolute mouse position in pixels
2183 *
2184 * @returns VBox status code
2185 * @param pAbsX Pointer of result value, can be NULL
2186 * @param pAbsY Pointer of result value, can be NULL
2187 */
2188static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t *pAbsX, int32_t *pAbsY)
2189{
2190 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2191 if (pAbsX)
2192 *pAbsX = ASMAtomicReadS32(&pThis->mouseXAbs); /* why the atomic read? */
2193 if (pAbsY)
2194 *pAbsY = ASMAtomicReadS32(&pThis->mouseYAbs);
2195 return VINF_SUCCESS;
2196}
2197
2198/**
2199 * Set the new absolute mouse position in pixels
2200 *
2201 * @returns VBox status code
2202 * @param absX New absolute X position
2203 * @param absY New absolute Y position
2204 */
2205static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t absX, int32_t absY)
2206{
2207 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2208 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2209
2210 if (pThis->mouseXAbs == absX && pThis->mouseYAbs == absY)
2211 {
2212 PDMCritSectLeave(&pThis->CritSect);
2213 return VINF_SUCCESS;
2214 }
2215 Log2(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
2216 pThis->mouseXAbs = absX;
2217 pThis->mouseYAbs = absY;
2218 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
2219 PDMCritSectLeave(&pThis->CritSect);
2220 return VINF_SUCCESS;
2221}
2222
2223/**
2224 * Return the current mouse capability flags
2225 *
2226 * @returns VBox status code
2227 * @param pCapabilities Pointer of result value
2228 */
2229static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pfCaps)
2230{
2231 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2232 if (!pfCaps)
2233 return VERR_INVALID_PARAMETER;
2234 *pfCaps = pThis->mouseCapabilities;
2235 return VINF_SUCCESS;
2236}
2237
2238/**
2239 * Set the current mouse capability flag (host side)
2240 *
2241 * @returns VBox status code
2242 * @param capabilities Capability mask
2243 */
2244static DECLCALLBACK(int) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t fCapsAdded, uint32_t fCapsRemoved)
2245{
2246 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2247 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2248
2249 uint32_t fOldCaps = pThis->mouseCapabilities;
2250 pThis->mouseCapabilities &= ~(fCapsRemoved & VMMDEV_MOUSE_HOST_MASK);
2251 pThis->mouseCapabilities |= (fCapsAdded & VMMDEV_MOUSE_HOST_MASK)
2252 | VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
2253 bool fNotify = fOldCaps != pThis->mouseCapabilities;
2254
2255 LogRelFlowFunc(("fCapsAdded=0x%x, fCapsRemoved=0x%x, fNotify %s\n",
2256 fCapsAdded, fCapsRemoved, fNotify ? "TRUE" : "FALSE"));
2257
2258 if (fNotify)
2259 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
2260
2261 PDMCritSectLeave(&pThis->CritSect);
2262 return VINF_SUCCESS;
2263}
2264
2265
2266static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
2267{
2268 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2269
2270 if (display >= RT_ELEMENTS(pThis->displayChangeData.aRequests))
2271 {
2272 return VERR_INVALID_PARAMETER;
2273 }
2274
2275 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2276
2277 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[display];
2278
2279 /* Verify that the new resolution is different and that guest does not yet know about it. */
2280 bool fSameResolution = (!xres || (pRequest->lastReadDisplayChangeRequest.xres == xres)) &&
2281 (!yres || (pRequest->lastReadDisplayChangeRequest.yres == yres)) &&
2282 (!bpp || (pRequest->lastReadDisplayChangeRequest.bpp == bpp)) &&
2283 pRequest->lastReadDisplayChangeRequest.display == display;
2284
2285 if (!xres && !yres && !bpp)
2286 {
2287 /* Special case of reset video mode. */
2288 fSameResolution = false;
2289 }
2290
2291 Log3(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
2292 fSameResolution, xres, yres, bpp, display, pRequest->lastReadDisplayChangeRequest.xres, pRequest->lastReadDisplayChangeRequest.yres, pRequest->lastReadDisplayChangeRequest.bpp, pRequest->lastReadDisplayChangeRequest.display));
2293
2294 if (!fSameResolution)
2295 {
2296 LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
2297 xres, yres, bpp, display));
2298
2299 /* we could validate the information here but hey, the guest can do that as well! */
2300 pRequest->displayChangeRequest.xres = xres;
2301 pRequest->displayChangeRequest.yres = yres;
2302 pRequest->displayChangeRequest.bpp = bpp;
2303 pRequest->displayChangeRequest.display = display;
2304 pRequest->fPending = true;
2305
2306 /* IRQ so the guest knows what's going on */
2307 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
2308 }
2309
2310 PDMCritSectLeave(&pThis->CritSect);
2311 return VINF_SUCCESS;
2312}
2313
2314static DECLCALLBACK(int) vmmdevRequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
2315{
2316 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2317 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2318
2319 /* Verify that the new resolution is different and that guest does not yet know about it. */
2320 bool fSameMode = (pThis->fLastSeamlessEnabled == fEnabled);
2321
2322 Log(("vmmdevRequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
2323
2324 if (!fSameMode)
2325 {
2326 /* we could validate the information here but hey, the guest can do that as well! */
2327 pThis->fSeamlessEnabled = fEnabled;
2328
2329 /* IRQ so the guest knows what's going on */
2330 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
2331 }
2332
2333 PDMCritSectLeave(&pThis->CritSect);
2334 return VINF_SUCCESS;
2335}
2336
2337static DECLCALLBACK(int) vmmdevSetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t ulBalloonSize)
2338{
2339 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2340 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2341
2342 /* Verify that the new resolution is different and that guest does not yet know about it. */
2343 bool fSame = (pThis->u32LastMemoryBalloonSize == ulBalloonSize);
2344
2345 Log(("vmmdevSetMemoryBalloon: old=%d. new=%d\n", pThis->u32LastMemoryBalloonSize, ulBalloonSize));
2346
2347 if (!fSame)
2348 {
2349 /* we could validate the information here but hey, the guest can do that as well! */
2350 pThis->u32MemoryBalloonSize = ulBalloonSize;
2351
2352 /* IRQ so the guest knows what's going on */
2353 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
2354 }
2355
2356 PDMCritSectLeave(&pThis->CritSect);
2357 return VINF_SUCCESS;
2358}
2359
2360static DECLCALLBACK(int) vmmdevVRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t u32VRDPExperienceLevel)
2361{
2362 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2363 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2364
2365 bool fSame = (pThis->fVRDPEnabled == fVRDPEnabled);
2366
2367 Log(("vmmdevVRDPChange: old=%d. new=%d\n", pThis->fVRDPEnabled, fVRDPEnabled));
2368
2369 if (!fSame)
2370 {
2371 pThis->fVRDPEnabled = fVRDPEnabled;
2372 pThis->u32VRDPExperienceLevel = u32VRDPExperienceLevel;
2373
2374 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_VRDP);
2375 }
2376
2377 PDMCritSectLeave(&pThis->CritSect);
2378 return VINF_SUCCESS;
2379}
2380
2381static DECLCALLBACK(int) vmmdevSetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t ulStatInterval)
2382{
2383 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2384 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2385
2386 /* Verify that the new resolution is different and that guest does not yet know about it. */
2387 bool fSame = (pThis->u32LastStatIntervalSize == ulStatInterval);
2388
2389 Log(("vmmdevSetStatisticsInterval: old=%d. new=%d\n", pThis->u32LastStatIntervalSize, ulStatInterval));
2390
2391 if (!fSame)
2392 {
2393 /* we could validate the information here but hey, the guest can do that as well! */
2394 pThis->u32StatIntervalSize = ulStatInterval;
2395
2396 /* IRQ so the guest knows what's going on */
2397 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
2398 }
2399
2400 PDMCritSectLeave(&pThis->CritSect);
2401 return VINF_SUCCESS;
2402}
2403
2404
2405static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
2406 const char *pszPassword, const char *pszDomain,
2407 uint32_t u32Flags)
2408{
2409 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2410 int rc = VINF_SUCCESS;
2411
2412 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2413
2414 /* logon mode? */
2415 if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
2416 {
2417 /* memorize the data */
2418 strcpy(pThis->pCredentials->Logon.szUserName, pszUsername);
2419 strcpy(pThis->pCredentials->Logon.szPassword, pszPassword);
2420 strcpy(pThis->pCredentials->Logon.szDomain, pszDomain);
2421 pThis->pCredentials->Logon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
2422 }
2423 /* credentials verification mode? */
2424 else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
2425 {
2426 /* memorize the data */
2427 strcpy(pThis->pCredentials->Judge.szUserName, pszUsername);
2428 strcpy(pThis->pCredentials->Judge.szPassword, pszPassword);
2429 strcpy(pThis->pCredentials->Judge.szDomain, pszDomain);
2430
2431 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_JUDGE_CREDENTIALS);
2432 }
2433 else
2434 rc = VERR_INVALID_PARAMETER;
2435
2436 PDMCritSectLeave(&pThis->CritSect);
2437 return rc;
2438}
2439
2440/**
2441 * Notification from the Display. Especially useful when
2442 * acceleration is disabled after a video mode change.
2443 *
2444 * @param fEnable Current acceleration status.
2445 */
2446static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
2447{
2448 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2449
2450 Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
2451
2452 if (pThis)
2453 {
2454 pThis->u32VideoAccelEnabled = fEnabled;
2455 }
2456 return;
2457}
2458
2459/**
2460 * Notification that a CPU is about to be unplugged from the VM.
2461 * The guest has to eject the CPU.
2462 *
2463 * @returns VBox status code.
2464 * @param idCpu The id of the CPU.
2465 * @param idCpuCore The core id of the CPU to remove.
2466 * @param idCpuPackage The package id of the CPU to remove.
2467 */
2468static DECLCALLBACK(int) vmmdevCpuHotUnplug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
2469{
2470 int rc = VINF_SUCCESS;
2471 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2472
2473 Log(("vmmdevCpuHotUnplug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
2474
2475 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2476
2477 if (pThis->fCpuHotPlugEventsEnabled)
2478 {
2479 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Unplug;
2480 pThis->idCpuCore = idCpuCore;
2481 pThis->idCpuPackage = idCpuPackage;
2482 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_CPU_HOTPLUG);
2483 }
2484 else
2485 rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
2486
2487 PDMCritSectLeave(&pThis->CritSect);
2488 return rc;
2489}
2490
2491/**
2492 * Notification that a CPU was attached to the VM
2493 * The guest may use it now.
2494 *
2495 * @returns VBox status code.
2496 * @param idCpuCore The core id of the CPU to add.
2497 * @param idCpuPackage The package id of the CPU to add.
2498 */
2499static DECLCALLBACK(int) vmmdevCpuHotPlug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
2500{
2501 int rc = VINF_SUCCESS;
2502 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2503
2504 Log(("vmmdevCpuPlug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
2505
2506 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2507
2508 if (pThis->fCpuHotPlugEventsEnabled)
2509 {
2510 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Plug;
2511 pThis->idCpuCore = idCpuCore;
2512 pThis->idCpuPackage = idCpuPackage;
2513 VMMDevNotifyGuest(pThis, VMMDEV_EVENT_CPU_HOTPLUG);
2514 }
2515 else
2516 rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
2517
2518 PDMCritSectLeave(&pThis->CritSect);
2519 return rc;
2520}
2521
2522/* -=-=-=-=-=- Saved State -=-=-=-=-=- */
2523
2524/**
2525 * @copydoc FNSSMDEVLIVEEXEC
2526 */
2527static DECLCALLBACK(int) vmmdevLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
2528{
2529 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2530
2531 SSMR3PutBool(pSSM, pThis->fGetHostTimeDisabled);
2532 SSMR3PutBool(pSSM, pThis->fBackdoorLogDisabled);
2533 SSMR3PutBool(pSSM, pThis->fKeepCredentials);
2534 SSMR3PutBool(pSSM, pThis->fHeapEnabled);
2535
2536 return VINF_SSM_DONT_CALL_AGAIN;
2537}
2538
2539
2540/**
2541 * @copydoc FNSSMDEVSAVEEXEC
2542 *
2543 */
2544static DECLCALLBACK(int) vmmdevSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
2545{
2546 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2547
2548 vmmdevLiveExec(pDevIns, pSSM, SSM_PASS_FINAL);
2549
2550 SSMR3PutU32(pSSM, pThis->hypervisorSize);
2551 SSMR3PutU32(pSSM, pThis->mouseCapabilities);
2552 SSMR3PutS32(pSSM, pThis->mouseXAbs);
2553 SSMR3PutS32(pSSM, pThis->mouseYAbs);
2554
2555 SSMR3PutBool(pSSM, pThis->fNewGuestFilterMask);
2556 SSMR3PutU32(pSSM, pThis->u32NewGuestFilterMask);
2557 SSMR3PutU32(pSSM, pThis->u32GuestFilterMask);
2558 SSMR3PutU32(pSSM, pThis->u32HostEventFlags);
2559 /* The following is not strictly necessary as PGM restores MMIO2, keeping it for historical reasons. */
2560 SSMR3PutMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof(pThis->pVMMDevRAMR3->V));
2561
2562 SSMR3PutMem(pSSM, &pThis->guestInfo, sizeof (pThis->guestInfo));
2563 SSMR3PutU32(pSSM, pThis->fu32AdditionsOk);
2564 SSMR3PutU32(pSSM, pThis->u32VideoAccelEnabled);
2565 SSMR3PutBool(pSSM, pThis->displayChangeData.fGuestSentChangeEventAck);
2566
2567 SSMR3PutU32(pSSM, pThis->guestCaps);
2568
2569#ifdef VBOX_WITH_HGCM
2570 vmmdevHGCMSaveState(pThis, pSSM);
2571#endif /* VBOX_WITH_HGCM */
2572
2573 SSMR3PutU32(pSSM, pThis->fHostCursorRequested);
2574
2575 return VINF_SUCCESS;
2576}
2577
2578/**
2579 * @copydoc FNSSMDEVLOADEXEC
2580 */
2581static DECLCALLBACK(int) vmmdevLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
2582{
2583 /** @todo The code load code is assuming we're always loaded into a freshly
2584 * constructed VM. */
2585 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2586 int rc;
2587
2588 if ( uVersion > VMMDEV_SAVED_STATE_VERSION
2589 || uVersion < 6)
2590 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
2591
2592 /* config */
2593 if (uVersion > VMMDEV_SAVED_STATE_VERSION_VBOX_30)
2594 {
2595 bool f;
2596 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2597 if (pThis->fGetHostTimeDisabled != f)
2598 LogRel(("VMMDev: Config mismatch - fGetHostTimeDisabled: config=%RTbool saved=%RTbool\n", pThis->fGetHostTimeDisabled, f));
2599
2600 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2601 if (pThis->fBackdoorLogDisabled != f)
2602 LogRel(("VMMDev: Config mismatch - fBackdoorLogDisabled: config=%RTbool saved=%RTbool\n", pThis->fBackdoorLogDisabled, f));
2603
2604 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2605 if (pThis->fKeepCredentials != f)
2606 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fKeepCredentials: config=%RTbool saved=%RTbool"),
2607 pThis->fKeepCredentials, f);
2608 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2609 if (pThis->fHeapEnabled != f)
2610 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fHeapEnabled: config=%RTbool saved=%RTbool"),
2611 pThis->fHeapEnabled, f);
2612 }
2613
2614 if (uPass != SSM_PASS_FINAL)
2615 return VINF_SUCCESS;
2616
2617 /* state */
2618 SSMR3GetU32(pSSM, &pThis->hypervisorSize);
2619 SSMR3GetU32(pSSM, &pThis->mouseCapabilities);
2620 SSMR3GetS32(pSSM, &pThis->mouseXAbs);
2621 SSMR3GetS32(pSSM, &pThis->mouseYAbs);
2622
2623 SSMR3GetBool(pSSM, &pThis->fNewGuestFilterMask);
2624 SSMR3GetU32(pSSM, &pThis->u32NewGuestFilterMask);
2625 SSMR3GetU32(pSSM, &pThis->u32GuestFilterMask);
2626 SSMR3GetU32(pSSM, &pThis->u32HostEventFlags);
2627
2628// SSMR3GetBool(pSSM, &pThis->pVMMDevRAMR3->fHaveEvents);
2629 // here be dragons (probably)
2630 SSMR3GetMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof (pThis->pVMMDevRAMR3->V));
2631
2632 SSMR3GetMem(pSSM, &pThis->guestInfo, sizeof (pThis->guestInfo));
2633 SSMR3GetU32(pSSM, &pThis->fu32AdditionsOk);
2634 SSMR3GetU32(pSSM, &pThis->u32VideoAccelEnabled);
2635 if (uVersion > 10)
2636 SSMR3GetBool(pSSM, &pThis->displayChangeData.fGuestSentChangeEventAck);
2637
2638 rc = SSMR3GetU32(pSSM, &pThis->guestCaps);
2639
2640 /* Attributes which were temporarily introduced in r30072 */
2641 if (uVersion == 7)
2642 {
2643 uint32_t temp;
2644 SSMR3GetU32(pSSM, &temp);
2645 rc = SSMR3GetU32(pSSM, &temp);
2646 }
2647 AssertRCReturn(rc, rc);
2648
2649#ifdef VBOX_WITH_HGCM
2650 rc = vmmdevHGCMLoadState(pThis, pSSM, uVersion);
2651 AssertRCReturn(rc, rc);
2652#endif /* VBOX_WITH_HGCM */
2653
2654 if (uVersion >= 10)
2655 rc = SSMR3GetU32(pSSM, &pThis->fHostCursorRequested);
2656 AssertRCReturn(rc, rc);
2657
2658 /*
2659 * On a resume, we send the capabilities changed message so
2660 * that listeners can sync their state again
2661 */
2662 Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
2663 if (pThis->pDrv)
2664 {
2665 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
2666 if (uVersion >= 10)
2667 pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
2668 /*fVisible=*/!!pThis->fHostCursorRequested,
2669 /*fAlpha=*/false,
2670 /*xHot=*/0, /*yHot=*/0,
2671 /*cx=*/0, /*cy=*/0,
2672 /*pvShape=*/NULL);
2673 }
2674
2675 /* Reestablish the acceleration status. */
2676 if ( pThis->u32VideoAccelEnabled
2677 && pThis->pDrv)
2678 {
2679 pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, !!pThis->u32VideoAccelEnabled, &pThis->pVMMDevRAMR3->vbvaMemory);
2680 }
2681
2682 if (pThis->fu32AdditionsOk)
2683 {
2684 LogRel(("Guest Additions information report: additionsVersion = 0x%08X, osType = 0x%08X\n",
2685 pThis->guestInfo.interfaceVersion,
2686 pThis->guestInfo.osType));
2687 if (pThis->pDrv)
2688 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
2689/** @todo Missing pfnUpdateGuestInfo2 */
2690 }
2691 if (pThis->pDrv)
2692 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
2693
2694 return VINF_SUCCESS;
2695}
2696
2697/**
2698 * Load state done callback. Notify guest of restore event.
2699 *
2700 * @returns VBox status code.
2701 * @param pDevIns The device instance.
2702 * @param pSSM The handle to the saved state.
2703 */
2704static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
2705{
2706 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2707
2708#ifdef VBOX_WITH_HGCM
2709 int rc = vmmdevHGCMLoadStateDone(pThis, pSSM);
2710 AssertLogRelRCReturn(rc, rc);
2711#endif /* VBOX_WITH_HGCM */
2712
2713 VMMDevNotifyGuest(pThis, VMMDEV_EVENT_RESTORED);
2714
2715 return VINF_SUCCESS;
2716}
2717
2718/* -=-=-=-=- PDMDEVREG -=-=-=-=- */
2719
2720/**
2721 * (Re-)initializes the MMIO2 data.
2722 *
2723 * @param pThis Pointer to the VMMDev instance data.
2724 */
2725static void vmmdevInitRam(VMMDevState *pThis)
2726{
2727 memset(pThis->pVMMDevRAMR3, 0, sizeof(VMMDevMemory));
2728 pThis->pVMMDevRAMR3->u32Size = sizeof(VMMDevMemory);
2729 pThis->pVMMDevRAMR3->u32Version = VMMDEV_MEMORY_VERSION;
2730}
2731
2732/**
2733 * Reset notification.
2734 *
2735 * @returns VBox status.
2736 * @param pDrvIns The driver instance data.
2737 */
2738static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
2739{
2740 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2741
2742 /*
2743 * Reset the mouse integration feature bits
2744 */
2745 if (pThis->mouseCapabilities & VMMDEV_MOUSE_GUEST_MASK)
2746 {
2747 pThis->mouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
2748 /* notify the connector */
2749 Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
2750 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
2751 }
2752 pThis->fHostCursorRequested = false;
2753
2754 pThis->hypervisorSize = 0;
2755
2756 pThis->u32HostEventFlags = 0;
2757
2758 /* re-initialize the VMMDev memory */
2759 if (pThis->pVMMDevRAMR3)
2760 vmmdevInitRam(pThis);
2761
2762 /* credentials have to go away (by default) */
2763 if (!pThis->fKeepCredentials)
2764 {
2765 memset(pThis->pCredentials->Logon.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2766 memset(pThis->pCredentials->Logon.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2767 memset(pThis->pCredentials->Logon.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2768 }
2769 memset(pThis->pCredentials->Judge.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2770 memset(pThis->pCredentials->Judge.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2771 memset(pThis->pCredentials->Judge.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2772
2773 /* Reset means that additions will report again. */
2774 const bool fVersionChanged = pThis->fu32AdditionsOk
2775 || pThis->guestInfo.interfaceVersion
2776 || pThis->guestInfo.osType != VBOXOSTYPE_Unknown;
2777 if (fVersionChanged)
2778 Log(("vmmdevReset: fu32AdditionsOk=%d additionsVersion=%x osType=%#x\n",
2779 pThis->fu32AdditionsOk, pThis->guestInfo.interfaceVersion, pThis->guestInfo.osType));
2780 pThis->fu32AdditionsOk = false;
2781 memset (&pThis->guestInfo, 0, sizeof (pThis->guestInfo));
2782
2783 /* clear pending display change request. */
2784 for (unsigned i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
2785 {
2786 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
2787 memset (&pRequest->lastReadDisplayChangeRequest, 0, sizeof (pRequest->lastReadDisplayChangeRequest));
2788 }
2789 pThis->displayChangeData.iCurrentMonitor = 0;
2790 pThis->displayChangeData.fGuestSentChangeEventAck = false;
2791
2792 /* disable seamless mode */
2793 pThis->fLastSeamlessEnabled = false;
2794
2795 /* disabled memory ballooning */
2796 pThis->u32LastMemoryBalloonSize = 0;
2797
2798 /* disabled statistics updating */
2799 pThis->u32LastStatIntervalSize = 0;
2800
2801 /* Clear the "HGCM event enabled" flag so the event can be automatically reenabled. */
2802 pThis->u32HGCMEnabled = 0;
2803
2804 /*
2805 * Clear the event variables.
2806 *
2807 * Note: The pThis->u32HostEventFlags is not cleared.
2808 * It is designed that way so host events do not
2809 * depend on guest resets.
2810 */
2811 pThis->u32GuestFilterMask = 0;
2812 pThis->u32NewGuestFilterMask = 0;
2813 pThis->fNewGuestFilterMask = 0;
2814
2815 /* This is the default, as Windows and OS/2 guests take this for granted. (Actually, neither does...) */
2816 /** @todo change this when we next bump the interface version */
2817 const bool fCapsChanged = pThis->guestCaps != VMMDEV_GUEST_SUPPORTS_GRAPHICS;
2818 if (fCapsChanged)
2819 Log(("vmmdevReset: fCapsChanged=%#x -> %#x\n", pThis->guestCaps, VMMDEV_GUEST_SUPPORTS_GRAPHICS));
2820 pThis->guestCaps = VMMDEV_GUEST_SUPPORTS_GRAPHICS; /** @todo r=bird: why? I cannot see this being done at construction?*/
2821
2822 /*
2823 * Call the update functions as required.
2824 */
2825 if (fVersionChanged)
2826 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
2827 if (fCapsChanged)
2828 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
2829
2830 /* Generate a unique session id for this VM; it will be changed for each start, reset or restore.
2831 * This can be used for restore detection inside the guest.
2832 */
2833 pThis->idSession = ASMReadTSC();
2834}
2835
2836
2837/**
2838 * @interface_method_impl{PDMDEVREG,pfnRelocate}
2839 */
2840static DECLCALLBACK(void) vmmdevRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
2841{
2842 NOREF(pDevIns);
2843 NOREF(offDelta);
2844}
2845
2846
2847/**
2848 * @interface_method_impl{PDMDEVREG,pfnDestruct}
2849 */
2850static DECLCALLBACK(int) vmmdevDestroy(PPDMDEVINS pDevIns)
2851{
2852 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
2853 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
2854
2855 /*
2856 * Wipe and free the credentials.
2857 */
2858 if (pThis->pCredentials)
2859 {
2860 RTMemWipeThoroughly(pThis->pCredentials, sizeof(*pThis->pCredentials), 10);
2861 RTMemFree(pThis->pCredentials);
2862 pThis->pCredentials = NULL;
2863 }
2864
2865 return VINF_SUCCESS;
2866}
2867
2868
2869/**
2870 * @interface_method_impl{PDMDEVREG,pfnConstruct}
2871 */
2872static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
2873{
2874 int rc;
2875 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
2876
2877 Assert(iInstance == 0);
2878 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
2879
2880 /*
2881 * Initialize data (most of it anyway).
2882 */
2883 /* Save PDM device instance data for future reference. */
2884 pThis->pDevIns = pDevIns;
2885
2886 /* PCI vendor, just a free bogus value */
2887 PCIDevSetVendorId(&pThis->dev, 0x80ee);
2888 /* device ID */
2889 PCIDevSetDeviceId(&pThis->dev, 0xcafe);
2890 /* class sub code (other type of system peripheral) */
2891 PCIDevSetClassSub(&pThis->dev, 0x80);
2892 /* class base code (base system peripheral) */
2893 PCIDevSetClassBase(&pThis->dev, 0x08);
2894 /* header type */
2895 PCIDevSetHeaderType(&pThis->dev, 0x00);
2896 /* interrupt on pin 0 */
2897 PCIDevSetInterruptPin(&pThis->dev, 0x01);
2898
2899 /*
2900 * Interfaces
2901 */
2902 /* IBase */
2903 pThis->IBase.pfnQueryInterface = vmmdevPortQueryInterface;
2904
2905 /* VMMDev port */
2906 pThis->IPort.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
2907 pThis->IPort.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
2908 pThis->IPort.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
2909 pThis->IPort.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
2910 pThis->IPort.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
2911 pThis->IPort.pfnSetCredentials = vmmdevSetCredentials;
2912 pThis->IPort.pfnVBVAChange = vmmdevVBVAChange;
2913 pThis->IPort.pfnRequestSeamlessChange = vmmdevRequestSeamlessChange;
2914 pThis->IPort.pfnSetMemoryBalloon = vmmdevSetMemoryBalloon;
2915 pThis->IPort.pfnSetStatisticsInterval = vmmdevSetStatisticsInterval;
2916 pThis->IPort.pfnVRDPChange = vmmdevVRDPChange;
2917 pThis->IPort.pfnCpuHotUnplug = vmmdevCpuHotUnplug;
2918 pThis->IPort.pfnCpuHotPlug = vmmdevCpuHotPlug;
2919
2920 /* Shared folder LED */
2921 pThis->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
2922 pThis->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
2923
2924#ifdef VBOX_WITH_HGCM
2925 /* HGCM port */
2926 pThis->IHGCMPort.pfnCompleted = hgcmCompleted;
2927#endif
2928
2929 pThis->pCredentials = (VMMDEVCREDS *)RTMemAllocZ(sizeof(*pThis->pCredentials));
2930 if (!pThis->pCredentials)
2931 return VERR_NO_MEMORY;
2932
2933
2934 /*
2935 * Validate and read the configuration.
2936 */
2937 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns,
2938 "GetHostTimeDisabled|"
2939 "BackdoorLogDisabled|"
2940 "KeepCredentials|"
2941 "HeapEnabled|"
2942 "RamSize|"
2943 "RZEnabled|"
2944 "GuestCoreDumpEnabled|"
2945 "GuestCoreDumpDir|"
2946 "GuestCoreDumpCount|"
2947 "TestingEnabled"
2948 ,
2949 "");
2950
2951 rc = CFGMR3QueryU64(pCfg, "RamSize", &pThis->cbGuestRAM);
2952 if (RT_FAILURE(rc))
2953 return PDMDEV_SET_ERROR(pDevIns, rc,
2954 N_("Configuration error: Failed querying \"RamSize\" as a 64-bit unsigned integer"));
2955
2956 rc = CFGMR3QueryBoolDef(pCfg, "GetHostTimeDisabled", &pThis->fGetHostTimeDisabled, false);
2957 if (RT_FAILURE(rc))
2958 return PDMDEV_SET_ERROR(pDevIns, rc,
2959 N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
2960
2961 rc = CFGMR3QueryBoolDef(pCfg, "BackdoorLogDisabled", &pThis->fBackdoorLogDisabled, false);
2962 if (RT_FAILURE(rc))
2963 return PDMDEV_SET_ERROR(pDevIns, rc,
2964 N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
2965
2966 rc = CFGMR3QueryBoolDef(pCfg, "KeepCredentials", &pThis->fKeepCredentials, false);
2967 if (RT_FAILURE(rc))
2968 return PDMDEV_SET_ERROR(pDevIns, rc,
2969 N_("Configuration error: Failed querying \"KeepCredentials\" as a boolean"));
2970
2971 rc = CFGMR3QueryBoolDef(pCfg, "HeapEnabled", &pThis->fHeapEnabled, true);
2972 if (RT_FAILURE(rc))
2973 return PDMDEV_SET_ERROR(pDevIns, rc,
2974 N_("Configuration error: Failed querying \"HeapEnabled\" as a boolean"));
2975
2976 rc = CFGMR3QueryBoolDef(pCfg, "RZEnabled", &pThis->fRZEnabled, true);
2977 if (RT_FAILURE(rc))
2978 return PDMDEV_SET_ERROR(pDevIns, rc,
2979 N_("Configuration error: Failed querying \"RZEnabled\" as a boolean"));
2980
2981 rc = CFGMR3QueryBoolDef(pCfg, "GuestCoreDumpEnabled", &pThis->fGuestCoreDumpEnabled, false);
2982 if (RT_FAILURE(rc))
2983 return PDMDEV_SET_ERROR(pDevIns, rc,
2984 N_("Configuration error: Failed querying \"GuestCoreDumpEnabled\" as a boolean"));
2985
2986 char *pszGuestCoreDumpDir = NULL;
2987 rc = CFGMR3QueryStringAlloc(pCfg, "GuestCoreDumpDir", &pszGuestCoreDumpDir);
2988 if (RT_FAILURE(rc))
2989 return PDMDEV_SET_ERROR(pDevIns, rc,
2990 N_("Configuration error: Failed querying \"GuestCoreDumpDir\" as a string"));
2991
2992 RTStrCopy(pThis->szGuestCoreDumpDir, sizeof(pThis->szGuestCoreDumpDir), pszGuestCoreDumpDir);
2993 MMR3HeapFree(pszGuestCoreDumpDir);
2994
2995 rc = CFGMR3QueryU32Def(pCfg, "GuestCoreDumpCount", &pThis->cGuestCoreDumps, 3);
2996 if (RT_FAILURE(rc))
2997 return PDMDEV_SET_ERROR(pDevIns, rc,
2998 N_("Configuration error: Failed querying \"GuestCoreDumpCount\" as a 32-bit unsigned integer"));
2999
3000#ifndef VBOX_WITHOUT_TESTING_FEATURES
3001 rc = CFGMR3QueryBoolDef(pCfg, "TestingEnabled", &pThis->fTestingEnabled, false);
3002 if (RT_FAILURE(rc))
3003 return PDMDEV_SET_ERROR(pDevIns, rc,
3004 N_("Configuration error: Failed querying \"TestingEnabled\" as a boolean"));
3005 /** @todo image-to-load-filename? */
3006#endif
3007
3008 /*
3009 * Create the critical section for the device.
3010 */
3011 rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "VMMDev");
3012 AssertRCReturn(rc, rc);
3013 /* Later: pDevIns->pCritSectR3 = &pThis->CritSect; */
3014
3015 /*
3016 * Register the backdoor logging port
3017 */
3018 rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
3019 AssertRCReturn(rc, rc);
3020
3021#ifdef TIMESYNC_BACKDOOR
3022 /*
3023 * Alternative timesync source (temporary!)
3024 */
3025 rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
3026 AssertRCReturn(rc, rc);
3027#endif
3028
3029 /*
3030 * Allocate and initialize the MMIO2 memory.
3031 */
3032 rc = PDMDevHlpMMIO2Register(pDevIns, 1 /*iRegion*/, VMMDEV_RAM_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevRAMR3, "VMMDev");
3033 if (RT_FAILURE(rc))
3034 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
3035 N_("Failed to allocate %u bytes of memory for the VMM device"), VMMDEV_RAM_SIZE);
3036 vmmdevInitRam(pThis);
3037
3038 if (pThis->fHeapEnabled)
3039 {
3040 rc = PDMDevHlpMMIO2Register(pDevIns, 2 /*iRegion*/, VMMDEV_HEAP_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevHeapR3, "VMMDev Heap");
3041 if (RT_FAILURE(rc))
3042 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
3043 N_("Failed to allocate %u bytes of memory for the VMM device heap"), PAGE_SIZE);
3044 }
3045
3046 /*
3047 * Register the PCI device.
3048 */
3049 rc = PDMDevHlpPCIRegister(pDevIns, &pThis->dev);
3050 if (RT_FAILURE(rc))
3051 return rc;
3052 if (pThis->dev.devfn != 32 || iInstance != 0)
3053 Log(("!!WARNING!!: pThis->dev.devfn=%d (ignore if testcase or no started by Main)\n", pThis->dev.devfn));
3054 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
3055 if (RT_FAILURE(rc))
3056 return rc;
3057 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
3058 if (RT_FAILURE(rc))
3059 return rc;
3060 if (pThis->fHeapEnabled)
3061 {
3062 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, VMMDEV_HEAP_SIZE, PCI_ADDRESS_SPACE_MEM_PREFETCH, vmmdevIORAMRegionMap);
3063 if (RT_FAILURE(rc))
3064 return rc;
3065 }
3066
3067#ifndef VBOX_WITHOUT_TESTING_FEATURES
3068 /*
3069 * Initialize testing.
3070 */
3071 rc = vmmdevTestingInitialize(pDevIns);
3072 if (RT_FAILURE(rc))
3073 return rc;
3074#endif
3075
3076 /*
3077 * Get the corresponding connector interface
3078 */
3079 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "VMM Driver Port");
3080 if (RT_SUCCESS(rc))
3081 {
3082 pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIVMMDEVCONNECTOR);
3083 AssertMsgReturn(pThis->pDrv, ("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
3084#ifdef VBOX_WITH_HGCM
3085 pThis->pHGCMDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIHGCMCONNECTOR);
3086 if (!pThis->pHGCMDrv)
3087 {
3088 Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Rrc\n", rc));
3089 /* this is not actually an error, just means that there is no support for HGCM */
3090 }
3091#endif
3092 /* Query the initial balloon size. */
3093 AssertPtr(pThis->pDrv->pfnQueryBalloonSize);
3094 rc = pThis->pDrv->pfnQueryBalloonSize(pThis->pDrv, &pThis->u32MemoryBalloonSize);
3095 AssertRC(rc);
3096
3097 Log(("Initial balloon size %x\n", pThis->u32MemoryBalloonSize));
3098 }
3099 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
3100 {
3101 Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pReg->szName, pDevIns->iInstance));
3102 rc = VINF_SUCCESS;
3103 }
3104 else
3105 AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Rrc\n", rc), rc);
3106
3107 /*
3108 * Attach status driver for shared folders (optional).
3109 */
3110 PPDMIBASE pBase;
3111 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port");
3112 if (RT_SUCCESS(rc))
3113 pThis->SharedFolders.pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
3114 else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
3115 {
3116 AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
3117 return rc;
3118 }
3119
3120 /*
3121 * Register saved state and init the HGCM CmdList critsect.
3122 */
3123 rc = PDMDevHlpSSMRegisterEx(pDevIns, VMMDEV_SAVED_STATE_VERSION, sizeof(*pThis), NULL,
3124 NULL, vmmdevLiveExec, NULL,
3125 NULL, vmmdevSaveExec, NULL,
3126 NULL, vmmdevLoadExec, vmmdevLoadStateDone);
3127 AssertRCReturn(rc, rc);
3128
3129#ifdef VBOX_WITH_HGCM
3130 pThis->pHGCMCmdList = NULL;
3131 rc = RTCritSectInit(&pThis->critsectHGCMCmdList);
3132 AssertRCReturn(rc, rc);
3133 pThis->u32HGCMEnabled = 0;
3134#endif /* VBOX_WITH_HGCM */
3135
3136 /* In this version of VirtualBox the GUI checks whether "needs host cursor"
3137 * changes. */
3138 pThis->mouseCapabilities |= VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
3139
3140 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMemBalloonChunks, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Memory balloon size", "/Devices/VMMDev/BalloonChunks");
3141
3142 /* Generate a unique session id for this VM; it will be changed for each start, reset or restore.
3143 * This can be used for restore detection inside the guest.
3144 */
3145 pThis->idSession = ASMReadTSC();
3146 return rc;
3147}
3148
3149/**
3150 * The device registration structure.
3151 */
3152extern "C" const PDMDEVREG g_DeviceVMMDev =
3153{
3154 /* u32Version */
3155 PDM_DEVREG_VERSION,
3156 /* szName */
3157 "VMMDev",
3158 /* szRCMod */
3159 "VBoxDDGC.gc",
3160 /* szR0Mod */
3161 "VBoxDDR0.r0",
3162 /* pszDescription */
3163 "VirtualBox VMM Device\n",
3164 /* fFlags */
3165 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
3166 /* fClass */
3167 PDM_DEVREG_CLASS_VMM_DEV,
3168 /* cMaxInstances */
3169 1,
3170 /* cbInstance */
3171 sizeof(VMMDevState),
3172 /* pfnConstruct */
3173 vmmdevConstruct,
3174 /* pfnDestruct */
3175 NULL,
3176 /* pfnRelocate */
3177 vmmdevRelocate,
3178 /* pfnIOCtl */
3179 NULL,
3180 /* pfnPowerOn */
3181 NULL,
3182 /* pfnReset */
3183 vmmdevReset,
3184 /* pfnSuspend */
3185 NULL,
3186 /* pfnResume */
3187 NULL,
3188 /* pfnAttach */
3189 NULL,
3190 /* pfnDetach */
3191 NULL,
3192 /* pfnQueryInterface. */
3193 NULL,
3194 /* pfnInitComplete */
3195 NULL,
3196 /* pfnPowerOff */
3197 NULL,
3198 /* pfnSoftReset */
3199 NULL,
3200 /* u32VersionEnd */
3201 PDM_DEVREG_VERSION
3202};
3203#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