VirtualBox

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

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

Devices/VMMDev: inform the guest if we have an absolute pointing device

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