VirtualBox

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

Last change on this file since 7684 was 7684, checked in by vboxsync, 17 years ago

overflow check.

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