VirtualBox

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

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

More logging

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