VirtualBox

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

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

PDM, VMM, PCI: reworked MSI API: now MSIs delivered via IOAPIC API, not with MMIO access, LSI logic now can work in MSI mode

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