VirtualBox

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

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

Another attempt to fix all the compile problems

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 76.6 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 Log(("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->SeamlessMode));
1169 switch(pData->SeamlessMode)
1170 {
1171 case PDM_SEAMLESS_MODE_DISABLED:
1172 seamlessChangeRequest->mode = VMMDev_Seamless_Disabled;
1173 break;
1174 case PDM_SEAMLESS_MODE_VISIBLE_REGION:
1175 seamlessChangeRequest->mode = VMMDev_Seamless_Visible_Region;
1176 break;
1177 case PDM_SEAMLESS_MODE_HOSTWINDOW:
1178 seamlessChangeRequest->mode = VMMDev_Seamless_Host_Window;
1179 break;
1180 }
1181
1182 if (seamlessChangeRequest->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
1183 {
1184 /* Remember which mode the client has queried. */
1185 pData->lastSeamlessMode = pData->SeamlessMode;
1186 }
1187
1188 requestHeader->rc = VINF_SUCCESS;
1189 }
1190 break;
1191 }
1192
1193
1194 case VMMDevReq_QueryCredentials:
1195 {
1196 if (requestHeader->size != sizeof(VMMDevCredentials))
1197 {
1198 AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
1199 requestHeader->rc = VERR_INVALID_PARAMETER;
1200 }
1201 else
1202 {
1203 VMMDevCredentials *credentials = (VMMDevCredentials*)requestHeader;
1204
1205 /* let's start by nulling out the data */
1206 memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1207 memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1208 memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1209
1210 /* should we return whether we got credentials for a logon? */
1211 if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
1212 {
1213 if ( pData->credentialsLogon.szUserName[0]
1214 || pData->credentialsLogon.szPassword[0]
1215 || pData->credentialsLogon.szDomain[0])
1216 {
1217 credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
1218 }
1219 else
1220 {
1221 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
1222 }
1223 }
1224
1225 /* does the guest want to read logon credentials? */
1226 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
1227 {
1228 if (pData->credentialsLogon.szUserName[0])
1229 strcpy(credentials->szUserName, pData->credentialsLogon.szUserName);
1230 if (pData->credentialsLogon.szPassword[0])
1231 strcpy(credentials->szPassword, pData->credentialsLogon.szPassword);
1232 if (pData->credentialsLogon.szDomain[0])
1233 strcpy(credentials->szDomain, pData->credentialsLogon.szDomain);
1234 if (!pData->credentialsLogon.fAllowInteractiveLogon)
1235 credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
1236 else
1237 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
1238 }
1239
1240 /* does the caller want us to destroy the logon credentials? */
1241 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
1242 {
1243 memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1244 memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1245 memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1246 }
1247
1248 /* does the guest want to read credentials for verification? */
1249 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
1250 {
1251 if (pData->credentialsJudge.szUserName[0])
1252 strcpy(credentials->szUserName, pData->credentialsJudge.szUserName);
1253 if (pData->credentialsJudge.szPassword[0])
1254 strcpy(credentials->szPassword, pData->credentialsJudge.szPassword);
1255 if (pData->credentialsJudge.szDomain[0])
1256 strcpy(credentials->szDomain, pData->credentialsJudge.szDomain);
1257 }
1258
1259 /* does the caller want us to destroy the judgement credentials? */
1260 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
1261 {
1262 memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1263 memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1264 memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1265 }
1266
1267 requestHeader->rc = VINF_SUCCESS;
1268 }
1269 break;
1270 }
1271
1272 case VMMDevReq_ReportCredentialsJudgement:
1273 {
1274 if (requestHeader->size != sizeof(VMMDevCredentials))
1275 {
1276 AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
1277 requestHeader->rc = VERR_INVALID_PARAMETER;
1278 }
1279 else
1280 {
1281 VMMDevCredentials *credentials = (VMMDevCredentials*)requestHeader;
1282
1283 /* what does the guest think about the credentials? (note: the order is important here!) */
1284 if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
1285 {
1286 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
1287 }
1288 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
1289 {
1290 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
1291 }
1292 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
1293 {
1294 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
1295 }
1296 else
1297 Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
1298
1299 requestHeader->rc = VINF_SUCCESS;
1300 }
1301 break;
1302 }
1303
1304#ifdef DEBUG
1305 case VMMDevReq_LogString:
1306 {
1307 if (requestHeader->size < sizeof(VMMDevReqLogString))
1308 {
1309 AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
1310 requestHeader->rc = VERR_INVALID_PARAMETER;
1311 }
1312 else
1313 {
1314 VMMDevReqLogString *pReqLogString = (VMMDevReqLogString*)requestHeader;
1315#undef LOG_GROUP
1316#define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR
1317// Log(("Guest Log: %s", pReqLogString->szString));
1318 Log(("DEBUG LOG: %s", pReqLogString->szString));
1319
1320#undef LOG_GROUP
1321#define LOG_GROUP LOG_GROUP_DEV_VMM
1322 requestHeader->rc = VINF_SUCCESS;
1323 }
1324 break;
1325 }
1326#endif
1327 default:
1328 {
1329 requestHeader->rc = VERR_NOT_IMPLEMENTED;
1330
1331 Log(("VMMDev unknown request type %d\n", requestHeader->requestType));
1332
1333 break;
1334 }
1335 }
1336
1337 return rcRet;
1338}
1339
1340/**
1341 * Callback function for mapping an PCI I/O region.
1342 *
1343 * @return VBox status code.
1344 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
1345 * @param iRegion The region number.
1346 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
1347 * I/O port, else it's a physical address.
1348 * This address is *NOT* relative to pci_mem_base like earlier!
1349 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1350 */
1351static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
1352{
1353 int rc;
1354 VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
1355 LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%VGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
1356
1357
1358 Assert(pData->pVMMDevRAMHC != NULL);
1359
1360 memset (pData->pVMMDevRAMHC, 0, sizeof (VMMDevMemory));
1361 pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
1362 pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
1363
1364 /*
1365 * VMMDev RAM mapping.
1366 */
1367 if (iRegion == 1 && enmType == PCI_ADDRESS_SPACE_MEM)
1368 {
1369 /*
1370 * Register and lock the RAM.
1371 *
1372 * Windows usually re-initializes the PCI devices, so we have to check whether the memory was
1373 * already registered before trying to do that all over again.
1374 */
1375 PVM pVM = PDMDevHlpGetVM(pPciDev->pDevIns);
1376
1377 if (pData->GCPhysVMMDevRAM)
1378 {
1379 /*
1380 * Relocate the already registered VMMDevRAM.
1381 */
1382 rc = MMR3PhysRelocate(pVM, pData->GCPhysVMMDevRAM, GCPhysAddress, VMMDEV_RAM_SIZE);
1383 if (VBOX_SUCCESS(rc))
1384 {
1385 pData->GCPhysVMMDevRAM = GCPhysAddress;
1386 return VINF_SUCCESS;
1387 }
1388 AssertReleaseMsgFailed(("Failed to relocate VMMDev RAM from %VGp to %VGp! rc=%Vra\n", pData->GCPhysVMMDevRAM, GCPhysAddress, rc));
1389 }
1390 else
1391 {
1392 /*
1393 * Register and lock the VMMDevRAM.
1394 */
1395 /** @todo MM_RAM_FLAGS_MMIO2 seems to be appropriate for a RW memory.
1396 * Need to check. May be a RO memory is enough for the device.
1397 */
1398 rc = MMR3PhysRegister(pVM, pData->pVMMDevRAMHC, GCPhysAddress, VMMDEV_RAM_SIZE, MM_RAM_FLAGS_MMIO2, "VBoxDev");
1399 if (VBOX_SUCCESS(rc))
1400 {
1401 pData->GCPhysVMMDevRAM = GCPhysAddress;
1402 return VINF_SUCCESS;
1403 }
1404 AssertReleaseMsgFailed(("Failed to register VMMDev RAM! rc=%Vra\n", rc));
1405 }
1406 return rc;
1407 }
1408
1409 AssertReleaseMsgFailed(("VMMDev wrong region type: iRegion=%d enmType=%d\n", iRegion, enmType));
1410 return VERR_INTERNAL_ERROR;
1411}
1412
1413
1414/**
1415 * Callback function for mapping a PCI I/O region.
1416 *
1417 * @return VBox status code.
1418 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
1419 * @param iRegion The region number.
1420 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
1421 * I/O port, else it's a physical address.
1422 * This address is *NOT* relative to pci_mem_base like earlier!
1423 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1424 */
1425static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
1426{
1427 VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
1428 int rc = VINF_SUCCESS;
1429
1430 Assert(enmType == PCI_ADDRESS_SPACE_IO);
1431 Assert(iRegion == 0);
1432 AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
1433
1434 /*
1435 * Save the base port address to simplify Port offset calculations.
1436 */
1437 pData->PortBase = (RTIOPORT)GCPhysAddress;
1438
1439 /*
1440 * Register our port IO handlers.
1441 */
1442 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
1443 (RTIOPORT)GCPhysAddress + PORT_VMMDEV_REQUEST_OFFSET, 1,
1444 (void*)pData, vmmdevRequestHandler,
1445 NULL, NULL, NULL, "VMMDev Request Handler");
1446 AssertRC(rc);
1447 return rc;
1448}
1449
1450/**
1451 * Queries an interface to the driver.
1452 *
1453 * @returns Pointer to interface.
1454 * @returns NULL if the interface was not supported by the driver.
1455 * @param pInterface Pointer to this interface structure.
1456 * @param enmInterface The requested interface identification.
1457 * @thread Any thread.
1458 */
1459static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
1460{
1461 VMMDevState *pData = (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Base));
1462 switch (enmInterface)
1463 {
1464 case PDMINTERFACE_BASE:
1465 return &pData->Base;
1466 case PDMINTERFACE_VMMDEV_PORT:
1467 return &pData->Port;
1468#ifdef VBOX_HGCM
1469 case PDMINTERFACE_HGCM_PORT:
1470 return &pData->HGCMPort;
1471#endif
1472 default:
1473 return NULL;
1474 }
1475}
1476
1477/* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
1478
1479/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
1480#define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Port)) )
1481
1482
1483/**
1484 * Return the current absolute mouse position in pixels
1485 *
1486 * @returns VBox status code
1487 * @param pAbsX Pointer of result value, can be NULL
1488 * @param pAbsY Pointer of result value, can be NULL
1489 */
1490static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t *pAbsX, uint32_t *pAbsY)
1491{
1492 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1493 if (pAbsX)
1494 *pAbsX = pData->mouseXAbs;
1495 if (pAbsY)
1496 *pAbsY = pData->mouseYAbs;
1497 return VINF_SUCCESS;
1498}
1499
1500/**
1501 * Set the new absolute mouse position in pixels
1502 *
1503 * @returns VBox status code
1504 * @param absX New absolute X position
1505 * @param absY New absolute Y position
1506 */
1507static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t absX, uint32_t absY)
1508{
1509 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1510 Log(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
1511 pData->mouseXAbs = absX;
1512 pData->mouseYAbs = absY;
1513 return VINF_SUCCESS;
1514}
1515
1516/**
1517 * Return the current mouse capability flags
1518 *
1519 * @returns VBox status code
1520 * @param pCapabilities Pointer of result value
1521 */
1522static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pCapabilities)
1523{
1524 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1525 if (!pCapabilities)
1526 return VERR_INVALID_PARAMETER;
1527 *pCapabilities = pData->mouseCapabilities;
1528 return VINF_SUCCESS;
1529}
1530
1531/**
1532 * Set the current mouse capability flag (host side)
1533 *
1534 * @returns VBox status code
1535 * @param capabilities Capability mask
1536 */
1537static DECLCALLBACK(int) vmmdevSetMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t capabilities)
1538{
1539 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1540
1541 bool bCapsChanged = ((capabilities & VMMDEV_MOUSEHOSTWANTSABS)
1542 != (pData->mouseCapabilities & VMMDEV_MOUSEHOSTWANTSABS));
1543
1544 Log(("vmmdevSetMouseCapabilities: bCapsChanged %d\n", bCapsChanged));
1545
1546 if (capabilities & VMMDEV_MOUSEHOSTCANNOTHWPOINTER)
1547 pData->mouseCapabilities |= VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
1548 else
1549 pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
1550
1551 if (capabilities & VMMDEV_MOUSEHOSTWANTSABS)
1552 pData->mouseCapabilities |= VMMDEV_MOUSEHOSTWANTSABS;
1553 else
1554 pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTWANTSABS;
1555
1556 if (bCapsChanged)
1557 VMMDevNotifyGuest (pData, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
1558
1559 return VINF_SUCCESS;
1560}
1561
1562
1563static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
1564{
1565 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1566
1567 /* Verify that the new resolution is different and that guest does not yet know about it. */
1568 bool fSameResolution = (!xres || (pData->lastReadDisplayChangeRequest.xres == xres)) &&
1569 (!yres || (pData->lastReadDisplayChangeRequest.yres == yres)) &&
1570 (!bpp || (pData->lastReadDisplayChangeRequest.bpp == bpp)) &&
1571 pData->lastReadDisplayChangeRequest.display == display;
1572
1573 if (!xres && !yres && !bpp)
1574 {
1575 /* Special case of reset video mode. */
1576 fSameResolution = false;
1577 }
1578
1579#ifdef DEBUG_sunlover
1580 Log(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
1581 fSameResolution, xres, yres, bpp, display, pData->lastReadDisplayChangeRequest.xres, pData->lastReadDisplayChangeRequest.yres, pData->lastReadDisplayChangeRequest.bpp, pData->lastReadDisplayChangeRequest.display));
1582#endif /* DEBUG_sunlover */
1583
1584 if (!fSameResolution)
1585 {
1586 LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
1587 xres, yres, bpp, display));
1588
1589 /* we could validate the information here but hey, the guest can do that as well! */
1590 pData->displayChangeRequest.xres = xres;
1591 pData->displayChangeRequest.yres = yres;
1592 pData->displayChangeRequest.bpp = bpp;
1593 pData->displayChangeRequest.display = display;
1594
1595 /* IRQ so the guest knows what's going on */
1596 VMMDevNotifyGuest (pData, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1597 }
1598
1599 return VINF_SUCCESS;
1600}
1601
1602static DECLCALLBACK(int) vmmdevRequestSeamlessChange(PPDMIVMMDEVPORT pInterface, PDMISEAMLESSMODE mode)
1603{
1604 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1605
1606 /* Verify that the new resolution is different and that guest does not yet know about it. */
1607 bool fSameMode = (pData->lastSeamlessMode == mode);
1608
1609 Log(("vmmdevRequestSeamlessChange: same=%d. new=%d\n", fSameMode, mode));
1610
1611 if (!fSameMode)
1612 {
1613 /* we could validate the information here but hey, the guest can do that as well! */
1614 pData->SeamlessMode = mode;
1615
1616 /* IRQ so the guest knows what's going on */
1617 VMMDevNotifyGuest (pData, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
1618 }
1619
1620 return VINF_SUCCESS;
1621}
1622
1623static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
1624 const char *pszPassword, const char *pszDomain,
1625 uint32_t u32Flags)
1626{
1627 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1628
1629 /* logon mode? */
1630 if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
1631 {
1632 /* memorize the data */
1633 strcpy(pData->credentialsLogon.szUserName, pszUsername);
1634 strcpy(pData->credentialsLogon.szPassword, pszPassword);
1635 strcpy(pData->credentialsLogon.szDomain, pszDomain);
1636 pData->credentialsLogon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
1637 }
1638 /* credentials verification mode? */
1639 else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
1640 {
1641 /* memorize the data */
1642 strcpy(pData->credentialsJudge.szUserName, pszUsername);
1643 strcpy(pData->credentialsJudge.szPassword, pszPassword);
1644 strcpy(pData->credentialsJudge.szDomain, pszDomain);
1645
1646 VMMDevNotifyGuest (pData, VMMDEV_EVENT_JUDGE_CREDENTIALS);
1647 }
1648 else
1649 return VERR_INVALID_PARAMETER;
1650
1651 return VINF_SUCCESS;
1652}
1653
1654/**
1655 * Notification from the Display. Especially useful when
1656 * acceleration is disabled after a video mode change.
1657 *
1658 * @param fEnable Current acceleration status.
1659 */
1660static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
1661{
1662 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1663
1664 Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
1665
1666 if (pData)
1667 {
1668 pData->u32VideoAccelEnabled = fEnabled;
1669 }
1670
1671 return;
1672}
1673
1674
1675/* -=-=-=-=-=- IHGCMPort -=-=-=-=-=- */
1676
1677/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
1678#define IHGCMPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, HGCMPort)) )
1679
1680
1681
1682#define VMMDEV_SSM_VERSION 5
1683
1684/**
1685 * Saves a state of the VMM device.
1686 *
1687 * @returns VBox status code.
1688 * @param pDevIns The device instance.
1689 * @param pSSMHandle The handle to save the state to.
1690 */
1691static DECLCALLBACK(int) vmmdevSaveState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1692{
1693 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1694 SSMR3PutU32(pSSMHandle, pData->hypervisorSize);
1695 SSMR3PutU32(pSSMHandle, pData->mouseCapabilities);
1696 SSMR3PutU32(pSSMHandle, pData->mouseXAbs);
1697 SSMR3PutU32(pSSMHandle, pData->mouseYAbs);
1698
1699 SSMR3PutBool(pSSMHandle, pData->fNewGuestFilterMask);
1700 SSMR3PutU32(pSSMHandle, pData->u32NewGuestFilterMask);
1701 SSMR3PutU32(pSSMHandle, pData->u32GuestFilterMask);
1702 SSMR3PutU32(pSSMHandle, pData->u32HostEventFlags);
1703 // here be dragons (probably)
1704// SSMR3PutBool(pSSMHandle, pData->pVMMDevRAMHC->V.V1_04.fHaveEvents);
1705 SSMR3PutMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
1706
1707 SSMR3PutMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
1708 SSMR3PutU32(pSSMHandle, pData->fu32AdditionsOk);
1709 SSMR3PutU32(pSSMHandle, pData->u32VideoAccelEnabled);
1710
1711 SSMR3PutU32(pSSMHandle, pData->guestCaps);
1712
1713#ifdef VBOX_HGCM
1714 vmmdevHGCMSaveState (pData, pSSMHandle);
1715#endif /* VBOX_HGCM */
1716
1717 return VINF_SUCCESS;
1718}
1719
1720/**
1721 * Loads the saved VMM device state.
1722 *
1723 * @returns VBox status code.
1724 * @param pDevIns The device instance.
1725 * @param pSSMHandle The handle to the saved state.
1726 * @param u32Version The data unit version number.
1727 */
1728static DECLCALLBACK(int) vmmdevLoadState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
1729{
1730 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1731 if (u32Version != VMMDEV_SSM_VERSION)
1732 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1733 SSMR3GetU32(pSSMHandle, &pData->hypervisorSize);
1734 SSMR3GetU32(pSSMHandle, &pData->mouseCapabilities);
1735 SSMR3GetU32(pSSMHandle, &pData->mouseXAbs);
1736 SSMR3GetU32(pSSMHandle, &pData->mouseYAbs);
1737
1738 SSMR3GetBool(pSSMHandle, &pData->fNewGuestFilterMask);
1739 SSMR3GetU32(pSSMHandle, &pData->u32NewGuestFilterMask);
1740 SSMR3GetU32(pSSMHandle, &pData->u32GuestFilterMask);
1741 SSMR3GetU32(pSSMHandle, &pData->u32HostEventFlags);
1742// SSMR3GetBool(pSSMHandle, &pData->pVMMDevRAMHC->fHaveEvents);
1743 // here be dragons (probably)
1744 SSMR3GetMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
1745
1746 SSMR3GetMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
1747 SSMR3GetU32(pSSMHandle, &pData->fu32AdditionsOk);
1748 SSMR3GetU32(pSSMHandle, &pData->u32VideoAccelEnabled);
1749
1750 SSMR3GetU32(pSSMHandle, &pData->guestCaps);
1751
1752#ifdef VBOX_HGCM
1753 vmmdevHGCMLoadState (pData, pSSMHandle);
1754#endif /* VBOX_HGCM */
1755
1756 /*
1757 * On a resume, we send the capabilities changed message so
1758 * that listeners can sync their state again
1759 */
1760 Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
1761 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
1762
1763 /* Reestablish the acceleration status. */
1764 if (pData->u32VideoAccelEnabled)
1765 {
1766 pData->pDrv->pfnVideoAccelEnable (pData->pDrv, !!pData->u32VideoAccelEnabled, &pData->pVMMDevRAMHC->vbvaMemory);
1767 }
1768
1769 if (pData->fu32AdditionsOk)
1770 {
1771 LogRel(("Guest Additions information report: additionsVersion = 0x%08X osType = 0x%08X\n",
1772 pData->guestInfo.additionsVersion,
1773 pData->guestInfo.osType));
1774 pData->pDrv->pfnUpdateGuestVersion(pData->pDrv, &pData->guestInfo);
1775 }
1776 pData->pDrv->pfnUpdateGuestCapabilities(pData->pDrv, pData->guestCaps);
1777
1778 return VINF_SUCCESS;
1779}
1780
1781/**
1782 * Load state done callback. Notify guest of restore event.
1783 *
1784 * @returns VBox status code.
1785 * @param pDevIns The device instance.
1786 * @param pSSMHandle The handle to the saved state.
1787 */
1788static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1789{
1790 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1791
1792#ifdef VBOX_HGCM
1793 vmmdevHGCMLoadStateDone (pData, pSSMHandle);
1794#endif /* VBOX_HGCM */
1795
1796 VMMDevNotifyGuest (pData, VMMDEV_EVENT_RESTORED);
1797
1798 return VINF_SUCCESS;
1799}
1800
1801/**
1802 * Construct a device instance for a VM.
1803 *
1804 * @returns VBox status.
1805 * @param pDevIns The device instance data.
1806 * If the registration structure is needed, pDevIns->pDevReg points to it.
1807 * @param iInstance Instance number. Use this to figure out which registers and such to use.
1808 * The device number is also found in pDevIns->iInstance, but since it's
1809 * likely to be freqently used PDM passes it as parameter.
1810 * @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
1811 * of the device instance. It's also found in pDevIns->pCfgHandle, but like
1812 * iInstance it's expected to be used a bit in this function.
1813 */
1814static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfgHandle)
1815{
1816 int rc;
1817 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState *);
1818
1819 Assert(iInstance == 0);
1820
1821 /*
1822 * Validate and read the configuration.
1823 */
1824 if (!CFGMR3AreValuesValid(pCfgHandle, "GetHostTimeDisabled\0BackdoorLogDisabled\0"))
1825 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
1826
1827 rc = CFGMR3QueryBool(pCfgHandle, "GetHostTimeDisabled", &pData->fGetHostTimeDisabled);
1828 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1829 pData->fGetHostTimeDisabled = false;
1830 else if (VBOX_FAILURE(rc))
1831 return PDMDEV_SET_ERROR(pDevIns, rc,
1832 N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
1833
1834 rc = CFGMR3QueryBool(pCfgHandle, "BackdoorLogDisabled", &pData->fBackdoorLogDisabled);
1835 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1836 pData->fBackdoorLogDisabled = false;
1837 else if (VBOX_FAILURE(rc))
1838 return PDMDEV_SET_ERROR(pDevIns, rc,
1839 N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
1840
1841 /*
1842 * Initialize data (most of it anyway).
1843 */
1844 /* Save PDM device instance data for future reference. */
1845 pData->pDevIns = pDevIns;
1846
1847 /* PCI vendor, just a free bogus value */
1848 pData->dev.config[0x00] = 0xee;
1849 pData->dev.config[0x01] = 0x80;
1850 /* device ID */
1851 pData->dev.config[0x02] = 0xfe;
1852 pData->dev.config[0x03] = 0xca;
1853 /* class sub code (other type of system peripheral) */
1854 pData->dev.config[0x0a] = 0x80;
1855 /* class base code (base system peripheral) */
1856 pData->dev.config[0x0b] = 0x08;
1857 /* header type */
1858 pData->dev.config[0x0e] = 0x00;
1859 /* interrupt on pin 0 */
1860 pData->dev.config[0x3d] = 0x01;
1861
1862 /*
1863 * Register the backdoor logging port
1864 */
1865 rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
1866 AssertRCReturn(rc, rc);
1867
1868#ifdef TIMESYNC_BACKDOOR
1869 /*
1870 * Alternative timesync source (temporary!)
1871 */
1872 rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
1873 AssertRCReturn(rc, rc);
1874#endif
1875
1876 /*
1877 * Register the PCI device.
1878 */
1879 rc = PDMDevHlpPCIRegister(pDevIns, &pData->dev);
1880 if (VBOX_FAILURE(rc))
1881 return rc;
1882 if (pData->dev.devfn == 32 || iInstance != 0)
1883 Log(("!!WARNING!!: pData->dev.devfn=%d (ignore if testcase or no started by Main)\n", pData->dev.devfn));
1884 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
1885 if (VBOX_FAILURE(rc))
1886 return rc;
1887 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
1888 if (VBOX_FAILURE(rc))
1889 return rc;
1890
1891 /*
1892 * Interfaces
1893 */
1894 /* Base */
1895 pData->Base.pfnQueryInterface = vmmdevPortQueryInterface;
1896
1897 /* VMMDev port */
1898 pData->Port.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
1899 pData->Port.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
1900 pData->Port.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
1901 pData->Port.pfnSetMouseCapabilities = vmmdevSetMouseCapabilities;
1902 pData->Port.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
1903 pData->Port.pfnSetCredentials = vmmdevSetCredentials;
1904 pData->Port.pfnVBVAChange = vmmdevVBVAChange;
1905 pData->Port.pfnRequestSeamlessChange = vmmdevRequestSeamlessChange;
1906
1907
1908#ifdef VBOX_HGCM
1909 /* HGCM port */
1910 pData->HGCMPort.pfnCompleted = hgcmCompleted;
1911#endif
1912
1913 /*
1914 * Get the corresponding connector interface
1915 */
1916 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pData->Base, &pData->pDrvBase, "VMM Driver Port");
1917 if (VBOX_SUCCESS(rc))
1918 {
1919 pData->pDrv = (PPDMIVMMDEVCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_VMMDEV_CONNECTOR);
1920 if (!pData->pDrv)
1921 AssertMsgFailedReturn(("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
1922#ifdef VBOX_HGCM
1923 pData->pHGCMDrv = (PPDMIHGCMCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_HGCM_CONNECTOR);
1924 if (!pData->pHGCMDrv)
1925 {
1926 Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Vrc\n", rc));
1927 /* this is not actually an error, just means that there is no support for HGCM */
1928 }
1929#endif
1930 }
1931 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
1932 {
1933 Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
1934 rc = VINF_SUCCESS;
1935 }
1936 else
1937 AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Vrc\n", rc), rc);
1938
1939 /*
1940 * Register saved state and init the HGCM CmdList critsect.
1941 */
1942 rc = PDMDevHlpSSMRegister(pDevIns, "VMMDev", iInstance, VMMDEV_SSM_VERSION, sizeof(*pData),
1943 NULL, vmmdevSaveState, NULL,
1944 NULL, vmmdevLoadState, vmmdevLoadStateDone);
1945 AssertRCReturn(rc, rc);
1946
1947#ifdef VBOX_HGCM
1948 pData->pHGCMCmdList = NULL;
1949 rc = RTCritSectInit(&pData->critsectHGCMCmdList);
1950 AssertRCReturn(rc, rc);
1951 pData->u32HGCMEnabled = 0;
1952#endif /* VBOX_HGCM */
1953
1954 /*
1955 * Allocate the VMMDev RAM region.
1956 */
1957 /** @todo freeing of the RAM. */
1958 rc = SUPPageAlloc(VMMDEV_RAM_SIZE >> PAGE_SHIFT, (void **)&pData->pVMMDevRAMHC);
1959 AssertMsgRCReturn(rc, ("VMMDev SUPPageAlloc(%#x,) -> %Vrc\n", VMMDEV_RAM_SIZE, rc), rc);
1960
1961 /* initialize the VMMDev memory */
1962 pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
1963 pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
1964
1965 return rc;
1966}
1967
1968/**
1969 * Reset notification.
1970 *
1971 * @returns VBox status.
1972 * @param pDrvIns The driver instance data.
1973 */
1974static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
1975{
1976 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1977 /*
1978 * Reset the mouse integration feature bit
1979 */
1980 if (pData->mouseCapabilities & (VMMDEV_MOUSEGUESTWANTSABS|VMMDEV_MOUSEGUESTNEEDSHOSTCUR))
1981 {
1982 pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTWANTSABS;
1983 /* notify the connector */
1984 Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
1985 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
1986 }
1987
1988 pData->hypervisorSize = 0;
1989
1990 pData->u32HostEventFlags = 0;
1991
1992 if (pData->pVMMDevRAMHC)
1993 {
1994 /* re-initialize the VMMDev memory */
1995 memset (pData->pVMMDevRAMHC, 0, VMMDEV_RAM_SIZE);
1996 pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
1997 pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
1998 }
1999
2000 /* credentials have to go away */
2001 memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
2002 memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
2003 memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
2004 memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
2005 memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
2006 memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
2007
2008 /* Reset means that additions will report again. */
2009 pData->fu32AdditionsOk = false;
2010 memset (&pData->guestInfo, 0, sizeof (pData->guestInfo));
2011 pData->guestCaps = 0;
2012
2013 memset (&pData->lastReadDisplayChangeRequest, 0, sizeof (pData->lastReadDisplayChangeRequest));
2014
2015 /* disable seamless mode */
2016
2017 pData->lastSeamlessMode = PDM_SEAMLESS_MODE_DISABLED;
2018
2019 /* Clear the event variables.
2020 *
2021 * Note: The pData->u32HostEventFlags is not cleared.
2022 * It is designed that way so host events do not
2023 * depend on guest resets.
2024 */
2025 pData->u32GuestFilterMask = 0;
2026 pData->u32NewGuestFilterMask = 0;
2027 pData->fNewGuestFilterMask = 0;
2028}
2029
2030
2031/**
2032 * The device registration structure.
2033 */
2034extern "C" const PDMDEVREG g_DeviceVMMDev =
2035{
2036 /* u32Version */
2037 PDM_DEVREG_VERSION,
2038 /* szDeviceName */
2039 "VMMDev",
2040 /* szGCMod */
2041 "",
2042 /* szR0Mod */
2043 "",
2044 /* pszDescription */
2045 "VirtualBox VMM Device\n",
2046 /* fFlags */
2047 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32,
2048 /* fClass */
2049 PDM_DEVREG_CLASS_VMM_DEV,
2050 /* cMaxInstances */
2051 1,
2052 /* cbInstance */
2053 sizeof(VMMDevState),
2054 /* pfnConstruct */
2055 vmmdevConstruct,
2056 /* pfnDestruct */
2057 NULL,
2058 /* pfnRelocate */
2059 NULL,
2060 /* pfnIOCtl */
2061 NULL,
2062 /* pfnPowerOn */
2063 NULL,
2064 /* pfnReset */
2065 vmmdevReset,
2066 /* pfnSuspend */
2067 NULL,
2068 /* pfnResume */
2069 NULL,
2070 /* pfnAttach */
2071 NULL,
2072 /* pfnDetach */
2073 NULL,
2074 /* pfnQueryInterface. */
2075 NULL
2076};
2077#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
2078
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