VirtualBox

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

Last change on this file since 25643 was 25643, checked in by vboxsync, 15 years ago

VMMDev: loading of HGCM saved state does not rely on saved size of structures anymore (xTracker 4500)

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