VirtualBox

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

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

VMMDev: changed IRQ logging from #ifdef DEBUG_sunlover to Log3, as it is potentially interesting for other people as well :)

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