VirtualBox

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

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

Devices/VMMDev: fix a signedness warning

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