VirtualBox

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

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

Very noisy logging

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