VirtualBox

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

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

Spelling

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 74.3 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 Log2(("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 LogRel(("Guest Additions capability report: (0x%x) "
523 "VMMDEV_GUEST_SUPPORTS_SEAMLESS: %s "
524 "VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING: %s\n",
525 guestCaps->caps,
526 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
527 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no"));
528
529 pData->pDrv->pfnUpdateGuestCapabilities(pData->pDrv, guestCaps->caps);
530 }
531 requestHeader->rc = VINF_SUCCESS;
532 }
533 break;
534 }
535
536 /*
537 * Retrieve mouse information
538 */
539 case VMMDevReq_GetMouseStatus:
540 {
541 if (requestHeader->size != sizeof(VMMDevReqMouseStatus))
542 {
543 AssertMsgFailed(("VMMDev mouse status structure has invalid size!\n"));
544 requestHeader->rc = VERR_INVALID_PARAMETER;
545 }
546 else
547 {
548 VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)requestHeader;
549 mouseStatus->mouseFeatures = 0;
550 if (pData->mouseCapabilities & VMMDEV_MOUSEHOSTWANTSABS)
551 {
552 mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_HOST_CAN_ABSOLUTE;
553 }
554 if (pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS)
555 {
556 mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE;
557 }
558 if (pData->mouseCapabilities & VMMDEV_MOUSEHOSTCANNOTHWPOINTER)
559 {
560 mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_HOST_CANNOT_HWPOINTER;
561 }
562 mouseStatus->pointerXPos = pData->mouseXAbs;
563 mouseStatus->pointerYPos = pData->mouseYAbs;
564 Log(("returning mouse status: features = %d, absX = %d, absY = %d\n", mouseStatus->mouseFeatures,
565 mouseStatus->pointerXPos, mouseStatus->pointerYPos));
566 requestHeader->rc = VINF_SUCCESS;
567 }
568 break;
569 }
570
571 /*
572 * Set mouse information
573 */
574 case VMMDevReq_SetMouseStatus:
575 {
576 if (requestHeader->size != sizeof(VMMDevReqMouseStatus))
577 {
578 AssertMsgFailed(("VMMDev mouse status structure has invalid size %d (%#x) version=%d!\n",
579 requestHeader->size, requestHeader->size, requestHeader->size, requestHeader->version));
580 requestHeader->rc = VERR_INVALID_PARAMETER;
581 }
582 else
583 {
584 bool bCapsChanged = false;
585
586 VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)requestHeader;
587
588 /* check if the guest wants absolute coordinates */
589 if (mouseStatus->mouseFeatures & VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE)
590 {
591 /* set the capability flag and the changed flag if it's actually a change */
592 if (!(pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS))
593 {
594 pData->mouseCapabilities |= VMMDEV_MOUSEGUESTWANTSABS;
595 bCapsChanged = true;
596 LogRel(("Guest requests mouse pointer integration\n"));
597 }
598 } else
599 {
600 if (pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS)
601 {
602 pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTWANTSABS;
603 bCapsChanged = true;
604 LogRel(("Guest disables mouse pointer integration\n"));
605 }
606 }
607 if (mouseStatus->mouseFeatures & VBOXGUEST_MOUSE_GUEST_NEEDS_HOST_CURSOR)
608 pData->mouseCapabilities |= VMMDEV_MOUSEGUESTNEEDSHOSTCUR;
609 else
610 pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTNEEDSHOSTCUR;
611
612 /*
613 * Notify connector if something has changed
614 */
615 if (bCapsChanged)
616 {
617 Log(("VMMDevReq_SetMouseStatus: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
618 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
619 }
620 requestHeader->rc = VINF_SUCCESS;
621 }
622
623 break;
624 }
625
626 /*
627 * Set a new mouse pointer shape
628 */
629 case VMMDevReq_SetPointerShape:
630 {
631 if (requestHeader->size < sizeof(VMMDevReqMousePointer))
632 {
633 AssertMsg(requestHeader->size == 0x10028 && requestHeader->version == 10000, /* don't bitch about legacy!!! */
634 ("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
635 requestHeader->size, requestHeader->size, requestHeader->size, requestHeader->version));
636 requestHeader->rc = VERR_INVALID_PARAMETER;
637 }
638 else
639 {
640 VMMDevReqMousePointer *pointerShape = (VMMDevReqMousePointer*)requestHeader;
641
642 bool fVisible = (pointerShape->fFlags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
643 bool fAlpha = (pointerShape->fFlags & VBOX_MOUSE_POINTER_ALPHA) != 0;
644 bool fShape = (pointerShape->fFlags & VBOX_MOUSE_POINTER_SHAPE) != 0;
645
646 Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
647 fVisible, fAlpha, fShape, pointerShape->width, pointerShape->height));
648
649 /* forward call to driver */
650 if (fShape)
651 {
652 pData->pDrv->pfnUpdatePointerShape(pData->pDrv,
653 fVisible,
654 fAlpha,
655 pointerShape->xHot, pointerShape->yHot,
656 pointerShape->width, pointerShape->height,
657 pointerShape->pointerData);
658 }
659 else
660 {
661 pData->pDrv->pfnUpdatePointerShape(pData->pDrv,
662 fVisible,
663 0,
664 0, 0,
665 0, 0,
666 NULL);
667 }
668 requestHeader->rc = VINF_SUCCESS;
669 }
670 break;
671 }
672
673 /*
674 * Query the system time from the host
675 */
676 case VMMDevReq_GetHostTime:
677 {
678 if (requestHeader->size != sizeof(VMMDevReqHostTime))
679 {
680 AssertMsgFailed(("VMMDev host time structure has invalid size!\n"));
681 requestHeader->rc = VERR_INVALID_PARAMETER;
682 }
683 else if (RT_UNLIKELY(pData->fGetHostTimeDisabled))
684 requestHeader->rc = VERR_NOT_SUPPORTED;
685 else
686 {
687 VMMDevReqHostTime *hostTimeReq = (VMMDevReqHostTime*)requestHeader;
688 RTTIMESPEC now;
689 hostTimeReq->time = RTTimeSpecGetMilli(PDMDevHlpUTCNow(pDevIns, &now));
690 requestHeader->rc = VINF_SUCCESS;
691 }
692 break;
693 }
694
695 /*
696 * Query information about the hypervisor
697 */
698 case VMMDevReq_GetHypervisorInfo:
699 {
700 if (requestHeader->size != sizeof(VMMDevReqHypervisorInfo))
701 {
702 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
703 requestHeader->rc = VERR_INVALID_PARAMETER;
704 }
705 else
706 {
707 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)requestHeader;
708 PVM pVM = PDMDevHlpGetVM(pDevIns);
709 size_t hypervisorSize = 0;
710 requestHeader->rc = PGMR3MappingsSize(pVM, &hypervisorSize);
711 hypervisorInfo->hypervisorSize = (uint32_t)hypervisorSize;
712 Assert(hypervisorInfo->hypervisorSize == hypervisorSize);
713 }
714 break;
715 }
716
717 /*
718 * Set hypervisor information
719 */
720 case VMMDevReq_SetHypervisorInfo:
721 {
722 if (requestHeader->size != sizeof(VMMDevReqHypervisorInfo))
723 {
724 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
725 requestHeader->rc = VERR_INVALID_PARAMETER;
726 }
727 else
728 {
729 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)requestHeader;
730 PVM pVM = PDMDevHlpGetVM(pDevIns);
731 if (hypervisorInfo->hypervisorStart == 0)
732 {
733 requestHeader->rc = PGMR3MappingsUnfix(pVM);
734 } else
735 {
736 /* only if the client has queried the size before! */
737 size_t mappingsSize;
738 requestHeader->rc = PGMR3MappingsSize(pVM, &mappingsSize);
739 if (VBOX_SUCCESS(requestHeader->rc) && (hypervisorInfo->hypervisorSize == mappingsSize))
740 {
741 /* new reservation */
742 requestHeader->rc = PGMR3MappingsFix(pVM, hypervisorInfo->hypervisorStart,
743 hypervisorInfo->hypervisorSize);
744 LogRel(("Guest reported fixed hypervisor window at 0x%p (size = 0x%x, rc = %Vrc)\n",
745 hypervisorInfo->hypervisorStart,
746 hypervisorInfo->hypervisorSize,
747 requestHeader->rc));
748 }
749 }
750 }
751 break;
752 }
753
754 /*
755 * Set the system power status
756 */
757 case VMMDevReq_SetPowerStatus:
758 {
759 if (requestHeader->size != sizeof(VMMDevPowerStateRequest))
760 {
761 AssertMsgFailed(("VMMDev power state request structure has invalid size!\n"));
762 requestHeader->rc = VERR_INVALID_PARAMETER;
763 }
764 else
765 {
766 VMMDevPowerStateRequest *powerStateRequest = (VMMDevPowerStateRequest*)requestHeader;
767 switch(powerStateRequest->powerState)
768 {
769 case VMMDevPowerState_Pause:
770 {
771 LogRel(("Guest requests the VM to be suspended (paused)\n"));
772 requestHeader->rc = rcRet = PDMDevHlpVMSuspend(pDevIns);
773 break;
774 }
775
776 case VMMDevPowerState_PowerOff:
777 {
778 LogRel(("Guest requests the VM to be turned off\n"));
779 requestHeader->rc = rcRet = PDMDevHlpVMPowerOff(pDevIns);
780 break;
781 }
782
783 case VMMDevPowerState_SaveState:
784 {
785 /** @todo no API for that yet */
786 requestHeader->rc = VERR_NOT_IMPLEMENTED;
787 break;
788 }
789
790 default:
791 AssertMsgFailed(("VMMDev invalid power state request: %d\n", powerStateRequest->powerState));
792 requestHeader->rc = VERR_INVALID_PARAMETER;
793 break;
794 }
795 }
796 break;
797 }
798
799 /*
800 * Get display change request
801 */
802 case VMMDevReq_GetDisplayChangeRequest:
803 {
804 if (requestHeader->size != sizeof(VMMDevDisplayChangeRequest))
805 {
806 /* Assert only if the size also not equal to a previous version size to prevent
807 * assertion with old additions.
808 */
809 AssertMsg(requestHeader->size == sizeof(VMMDevDisplayChangeRequest) - sizeof (uint32_t),
810 ("VMMDev display change request structure has invalid size!\n"));
811 requestHeader->rc = VERR_INVALID_PARAMETER;
812 }
813 else
814 {
815 VMMDevDisplayChangeRequest *displayChangeRequest = (VMMDevDisplayChangeRequest*)requestHeader;
816 /* just pass on the information */
817 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n",
818 pData->displayChangeRequest.xres, pData->displayChangeRequest.yres, pData->displayChangeRequest.bpp));
819 displayChangeRequest->xres = pData->displayChangeRequest.xres;
820 displayChangeRequest->yres = pData->displayChangeRequest.yres;
821 displayChangeRequest->bpp = pData->displayChangeRequest.bpp;
822
823 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
824 {
825 /* Remember which resolution the client has queried. */
826 pData->lastReadDisplayChangeRequest = pData->displayChangeRequest;
827 }
828
829 requestHeader->rc = VINF_SUCCESS;
830 }
831 break;
832 }
833
834 case VMMDevReq_GetDisplayChangeRequest2:
835 {
836 if (requestHeader->size != sizeof(VMMDevDisplayChangeRequest2))
837 {
838 requestHeader->rc = VERR_INVALID_PARAMETER;
839 }
840 else
841 {
842 VMMDevDisplayChangeRequest2 *displayChangeRequest = (VMMDevDisplayChangeRequest2*)requestHeader;
843 /* just pass on the information */
844 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
845 pData->displayChangeRequest.xres, pData->displayChangeRequest.yres, pData->displayChangeRequest.bpp, pData->displayChangeRequest.display));
846 displayChangeRequest->xres = pData->displayChangeRequest.xres;
847 displayChangeRequest->yres = pData->displayChangeRequest.yres;
848 displayChangeRequest->bpp = pData->displayChangeRequest.bpp;
849 displayChangeRequest->display = pData->displayChangeRequest.display;
850
851 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
852 {
853 /* Remember which resolution the client has queried. */
854 pData->lastReadDisplayChangeRequest = pData->displayChangeRequest;
855 }
856
857 requestHeader->rc = VINF_SUCCESS;
858 }
859 break;
860 }
861
862 /*
863 * Query whether the given video mode is supported
864 */
865 case VMMDevReq_VideoModeSupported:
866 {
867 if (requestHeader->size != sizeof(VMMDevVideoModeSupportedRequest))
868 {
869 AssertMsgFailed(("VMMDev video mode supported request structure has invalid size!\n"));
870 requestHeader->rc = VERR_INVALID_PARAMETER;
871 }
872 else
873 {
874 VMMDevVideoModeSupportedRequest *videoModeSupportedRequest = (VMMDevVideoModeSupportedRequest*)requestHeader;
875 /* forward the call */
876 requestHeader->rc = pData->pDrv->pfnVideoModeSupported(pData->pDrv,
877 videoModeSupportedRequest->width,
878 videoModeSupportedRequest->height,
879 videoModeSupportedRequest->bpp,
880 &videoModeSupportedRequest->fSupported);
881 }
882 break;
883 }
884
885 /*
886 * Query the height reduction in pixels
887 */
888 case VMMDevReq_GetHeightReduction:
889 {
890 if (requestHeader->size != sizeof(VMMDevGetHeightReductionRequest))
891 {
892 AssertMsgFailed(("VMMDev height reduction request structure has invalid size!\n"));
893 requestHeader->rc = VERR_INVALID_PARAMETER;
894 }
895 else
896 {
897 VMMDevGetHeightReductionRequest *heightReductionRequest = (VMMDevGetHeightReductionRequest*)requestHeader;
898 /* forward the call */
899 requestHeader->rc = pData->pDrv->pfnGetHeightReduction(pData->pDrv,
900 &heightReductionRequest->heightReduction);
901 }
902 break;
903 }
904
905 /*
906 * Acknowledge VMMDev events
907 */
908 case VMMDevReq_AcknowledgeEvents:
909 {
910 if (requestHeader->size != sizeof(VMMDevEvents))
911 {
912 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
913 requestHeader->rc = VERR_INVALID_PARAMETER;
914 }
915 else
916 {
917 if (VBOX_GUEST_ADDITIONS_VERSION_1_03 (pData))
918 {
919 vmmdevSetIRQ_Legacy_EMT (pData);
920 }
921 else
922 {
923 VMMDevEvents *pAckRequest;
924
925 if (pData->fNewGuestFilterMask)
926 {
927 pData->fNewGuestFilterMask = false;
928 pData->u32GuestFilterMask = pData->u32NewGuestFilterMask;
929 }
930
931 pAckRequest = (VMMDevEvents *) requestHeader;
932 pAckRequest->events =
933 pData->u32HostEventFlags & pData->u32GuestFilterMask;
934
935 pData->u32HostEventFlags &= ~pData->u32GuestFilterMask;
936 pData->pVMMDevRAMHC->V.V1_04.fHaveEvents = false;
937 PDMDevHlpPCISetIrqNoWait (pData->pDevIns, 0, 0);
938 }
939 requestHeader->rc = VINF_SUCCESS;
940 }
941 break;
942 }
943
944 /*
945 * Change guest filter mask
946 */
947 case VMMDevReq_CtlGuestFilterMask:
948 {
949 if (requestHeader->size != sizeof(VMMDevCtlGuestFilterMask))
950 {
951 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
952 requestHeader->rc = VERR_INVALID_PARAMETER;
953 }
954 else
955 {
956 VMMDevCtlGuestFilterMask *pCtlMaskRequest;
957
958 pCtlMaskRequest = (VMMDevCtlGuestFilterMask *) requestHeader;
959 /* The HGCM events are enabled by the VMMDev device automatically when any
960 * HGCM command is issued. The guest then can not disable these events.
961 */
962 vmmdevCtlGuestFilterMask_EMT (pData,
963 pCtlMaskRequest->u32OrMask,
964 pCtlMaskRequest->u32NotMask & ~VMMDEV_EVENT_HGCM);
965 requestHeader->rc = VINF_SUCCESS;
966
967 }
968 break;
969 }
970
971#ifdef VBOX_HGCM
972 /*
973 * Process HGCM request
974 */
975 case VMMDevReq_HGCMConnect:
976 {
977 if (requestHeader->size < sizeof(VMMDevHGCMConnect))
978 {
979 AssertMsgFailed(("VMMDevReq_HGCMConnect structure has invalid size!\n"));
980 requestHeader->rc = VERR_INVALID_PARAMETER;
981 }
982 else if (!pData->pHGCMDrv)
983 {
984 Log(("VMMDevReq_HGCMConnect HGCM Connector is NULL!\n"));
985 requestHeader->rc = VERR_NOT_SUPPORTED;
986 }
987 else
988 {
989 VMMDevHGCMConnect *pHGCMConnect = (VMMDevHGCMConnect *)requestHeader;
990
991 Log(("VMMDevReq_HGCMConnect\n"));
992
993 requestHeader->rc = vmmdevHGCMConnect (pData, pHGCMConnect, (RTGCPHYS)u32);
994 }
995 break;
996 }
997
998 case VMMDevReq_HGCMDisconnect:
999 {
1000 if (requestHeader->size < sizeof(VMMDevHGCMDisconnect))
1001 {
1002 AssertMsgFailed(("VMMDevReq_HGCMDisconnect structure has invalid size!\n"));
1003 requestHeader->rc = VERR_INVALID_PARAMETER;
1004 }
1005 else if (!pData->pHGCMDrv)
1006 {
1007 Log(("VMMDevReq_HGCMDisconnect HGCM Connector is NULL!\n"));
1008 requestHeader->rc = VERR_NOT_SUPPORTED;
1009 }
1010 else
1011 {
1012 VMMDevHGCMDisconnect *pHGCMDisconnect = (VMMDevHGCMDisconnect *)requestHeader;
1013
1014 Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
1015 requestHeader->rc = vmmdevHGCMDisconnect (pData, pHGCMDisconnect, (RTGCPHYS)u32);
1016 }
1017 break;
1018 }
1019
1020 case VMMDevReq_HGCMCall:
1021 {
1022 if (requestHeader->size < sizeof(VMMDevHGCMCall))
1023 {
1024 AssertMsgFailed(("VMMDevReq_HGCMCall structure has invalid size!\n"));
1025 requestHeader->rc = VERR_INVALID_PARAMETER;
1026 }
1027 else if (!pData->pHGCMDrv)
1028 {
1029 Log(("VMMDevReq_HGCMCall HGCM Connector is NULL!\n"));
1030 requestHeader->rc = VERR_NOT_SUPPORTED;
1031 }
1032 else
1033 {
1034 VMMDevHGCMCall *pHGCMCall = (VMMDevHGCMCall *)requestHeader;
1035
1036 Log(("VMMDevReq_HGCMCall: sizeof (VMMDevHGCMRequest) = %04X\n", sizeof (VMMDevHGCMCall)));
1037
1038 Log(("%.*Vhxd\n", requestHeader->size, requestHeader));
1039
1040 requestHeader->rc = vmmdevHGCMCall (pData, pHGCMCall, (RTGCPHYS)u32);
1041 }
1042 break;
1043 }
1044#endif /* VBOX_HGCM */
1045
1046 case VMMDevReq_VideoAccelEnable:
1047 {
1048 if (requestHeader->size < sizeof(VMMDevVideoAccelEnable))
1049 {
1050 Log(("VMMDevReq_VideoAccelEnable request size too small!!!\n"));
1051 requestHeader->rc = VERR_INVALID_PARAMETER;
1052 }
1053 else if (!pData->pDrv)
1054 {
1055 Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!!\n"));
1056 requestHeader->rc = VERR_NOT_SUPPORTED;
1057 }
1058 else
1059 {
1060 VMMDevVideoAccelEnable *ptr = (VMMDevVideoAccelEnable *)requestHeader;
1061
1062 if (ptr->cbRingBuffer != VBVA_RING_BUFFER_SIZE)
1063 {
1064 /* The guest driver seems compiled with another headers. */
1065 Log(("VMMDevReq_VideoAccelEnable guest ring buffer size %d, should be %d!!!\n", ptr->cbRingBuffer, VBVA_RING_BUFFER_SIZE));
1066 requestHeader->rc = VERR_INVALID_PARAMETER;
1067 }
1068 else
1069 {
1070 /* The request is correct. */
1071 ptr->fu32Status |= VBVA_F_STATUS_ACCEPTED;
1072
1073 LogFlow(("VMMDevReq_VideoAccelEnable ptr->u32Enable = %d\n", ptr->u32Enable));
1074
1075 requestHeader->rc = ptr->u32Enable?
1076 pData->pDrv->pfnVideoAccelEnable (pData->pDrv, true, &pData->pVMMDevRAMHC->vbvaMemory):
1077 pData->pDrv->pfnVideoAccelEnable (pData->pDrv, false, NULL);
1078
1079 if ( ptr->u32Enable
1080 && VBOX_SUCCESS (requestHeader->rc))
1081 {
1082 ptr->fu32Status |= VBVA_F_STATUS_ENABLED;
1083
1084 /* Remember that guest successfully enabled acceleration.
1085 * We need to reestablish it on restoring the VM from saved state.
1086 */
1087 pData->u32VideoAccelEnabled = 1;
1088 }
1089 else
1090 {
1091 /* The acceleration was not enabled. Remember that. */
1092 pData->u32VideoAccelEnabled = 0;
1093 }
1094 }
1095 }
1096 break;
1097 }
1098
1099 case VMMDevReq_VideoAccelFlush:
1100 {
1101 if (requestHeader->size < sizeof(VMMDevVideoAccelFlush))
1102 {
1103 AssertMsgFailed(("VMMDevReq_VideoAccelFlush request size too small.\n"));
1104 requestHeader->rc = VERR_INVALID_PARAMETER;
1105 }
1106 else if (!pData->pDrv)
1107 {
1108 Log(("VMMDevReq_VideoAccelFlush Connector is NULL!\n"));
1109 requestHeader->rc = VERR_NOT_SUPPORTED;
1110 }
1111 else
1112 {
1113 pData->pDrv->pfnVideoAccelFlush (pData->pDrv);
1114
1115 requestHeader->rc = VINF_SUCCESS;
1116 }
1117 break;
1118 }
1119
1120 case VMMDevReq_VideoSetVisibleRegion:
1121 {
1122 if (requestHeader->size < sizeof(VMMDevVideoSetVisibleRegion))
1123 {
1124 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1125 requestHeader->rc = VERR_INVALID_PARAMETER;
1126 }
1127 else if (!pData->pDrv)
1128 {
1129 Log(("VMMDevReq_VideoSetVisibleRegion Connector is NULL!!!\n"));
1130 requestHeader->rc = VERR_NOT_SUPPORTED;
1131 }
1132 else
1133 {
1134 VMMDevVideoSetVisibleRegion *ptr = (VMMDevVideoSetVisibleRegion *)requestHeader;
1135
1136 if (!ptr->cRect)
1137 {
1138 Log(("VMMDevReq_VideoSetVisibleRegion no rectangles!!!\n"));
1139 requestHeader->rc = VERR_INVALID_PARAMETER;
1140 }
1141 else
1142 if (requestHeader->size != sizeof(VMMDevVideoSetVisibleRegion) + (ptr->cRect-1)*sizeof(RTRECT))
1143 {
1144 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1145 requestHeader->rc = VERR_INVALID_PARAMETER;
1146 }
1147 else
1148 {
1149 Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", ptr->cRect));
1150 /* forward the call */
1151 requestHeader->rc = pData->pDrv->pfnSetVisibleRegion(pData->pDrv, ptr->cRect, &ptr->Rect);
1152 }
1153 }
1154 break;
1155 }
1156
1157 case VMMDevReq_QueryCredentials:
1158 {
1159 if (requestHeader->size != sizeof(VMMDevCredentials))
1160 {
1161 AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
1162 requestHeader->rc = VERR_INVALID_PARAMETER;
1163 }
1164 else
1165 {
1166 VMMDevCredentials *credentials = (VMMDevCredentials*)requestHeader;
1167
1168 /* let's start by nulling out the data */
1169 memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1170 memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1171 memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1172
1173 /* should we return whether we got credentials for a logon? */
1174 if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
1175 {
1176 if ( pData->credentialsLogon.szUserName[0]
1177 || pData->credentialsLogon.szPassword[0]
1178 || pData->credentialsLogon.szDomain[0])
1179 {
1180 credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
1181 }
1182 else
1183 {
1184 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
1185 }
1186 }
1187
1188 /* does the guest want to read logon credentials? */
1189 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
1190 {
1191 if (pData->credentialsLogon.szUserName[0])
1192 strcpy(credentials->szUserName, pData->credentialsLogon.szUserName);
1193 if (pData->credentialsLogon.szPassword[0])
1194 strcpy(credentials->szPassword, pData->credentialsLogon.szPassword);
1195 if (pData->credentialsLogon.szDomain[0])
1196 strcpy(credentials->szDomain, pData->credentialsLogon.szDomain);
1197 if (!pData->credentialsLogon.fAllowInteractiveLogon)
1198 credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
1199 else
1200 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
1201 }
1202
1203 /* does the caller want us to destroy the logon credentials? */
1204 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
1205 {
1206 memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1207 memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1208 memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1209 }
1210
1211 /* does the guest want to read credentials for verification? */
1212 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
1213 {
1214 if (pData->credentialsJudge.szUserName[0])
1215 strcpy(credentials->szUserName, pData->credentialsJudge.szUserName);
1216 if (pData->credentialsJudge.szPassword[0])
1217 strcpy(credentials->szPassword, pData->credentialsJudge.szPassword);
1218 if (pData->credentialsJudge.szDomain[0])
1219 strcpy(credentials->szDomain, pData->credentialsJudge.szDomain);
1220 }
1221
1222 /* does the caller want us to destroy the judgement credentials? */
1223 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
1224 {
1225 memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1226 memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1227 memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1228 }
1229
1230 requestHeader->rc = VINF_SUCCESS;
1231 }
1232 break;
1233 }
1234
1235 case VMMDevReq_ReportCredentialsJudgement:
1236 {
1237 if (requestHeader->size != sizeof(VMMDevCredentials))
1238 {
1239 AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
1240 requestHeader->rc = VERR_INVALID_PARAMETER;
1241 }
1242 else
1243 {
1244 VMMDevCredentials *credentials = (VMMDevCredentials*)requestHeader;
1245
1246 /* what does the guest think about the credentials? (note: the order is important here!) */
1247 if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
1248 {
1249 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
1250 }
1251 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
1252 {
1253 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
1254 }
1255 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
1256 {
1257 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
1258 }
1259 else
1260 Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
1261
1262 requestHeader->rc = VINF_SUCCESS;
1263 }
1264 break;
1265 }
1266
1267#ifdef DEBUG
1268 case VMMDevReq_LogString:
1269 {
1270 if (requestHeader->size < sizeof(VMMDevReqLogString))
1271 {
1272 AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
1273 requestHeader->rc = VERR_INVALID_PARAMETER;
1274 }
1275 else
1276 {
1277 VMMDevReqLogString *pReqLogString = (VMMDevReqLogString*)requestHeader;
1278#undef LOG_GROUP
1279#define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR
1280// Log(("Guest Log: %s", pReqLogString->szString));
1281 Log(("DEBUG LOG: %s", pReqLogString->szString));
1282
1283#undef LOG_GROUP
1284#define LOG_GROUP LOG_GROUP_DEV_VMM
1285 requestHeader->rc = VINF_SUCCESS;
1286 }
1287 break;
1288 }
1289#endif
1290 default:
1291 {
1292 requestHeader->rc = VERR_NOT_IMPLEMENTED;
1293
1294 Log(("VMMDev unknown request type %d\n", requestHeader->requestType));
1295
1296 break;
1297 }
1298 }
1299
1300 return rcRet;
1301}
1302
1303/**
1304 * Callback function for mapping an PCI I/O region.
1305 *
1306 * @return VBox status code.
1307 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
1308 * @param iRegion The region number.
1309 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
1310 * I/O port, else it's a physical address.
1311 * This address is *NOT* relative to pci_mem_base like earlier!
1312 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1313 */
1314static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
1315{
1316 int rc;
1317 VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
1318 LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%VGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
1319
1320
1321 Assert(pData->pVMMDevRAMHC != NULL);
1322
1323 memset (pData->pVMMDevRAMHC, 0, sizeof (VMMDevMemory));
1324 pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
1325 pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
1326
1327 /*
1328 * VMMDev RAM mapping.
1329 */
1330 if (iRegion == 1 && enmType == PCI_ADDRESS_SPACE_MEM)
1331 {
1332 /*
1333 * Register and lock the RAM.
1334 *
1335 * Windows usually re-initializes the PCI devices, so we have to check whether the memory was
1336 * already registered before trying to do that all over again.
1337 */
1338 PVM pVM = PDMDevHlpGetVM(pPciDev->pDevIns);
1339
1340 if (pData->GCPhysVMMDevRAM)
1341 {
1342 /*
1343 * Relocate the already registered VMMDevRAM.
1344 */
1345 rc = MMR3PhysRelocate(pVM, pData->GCPhysVMMDevRAM, GCPhysAddress, VMMDEV_RAM_SIZE);
1346 if (VBOX_SUCCESS(rc))
1347 {
1348 pData->GCPhysVMMDevRAM = GCPhysAddress;
1349 return VINF_SUCCESS;
1350 }
1351 AssertReleaseMsgFailed(("Failed to relocate VMMDev RAM from %VGp to %VGp! rc=%Vra\n", pData->GCPhysVMMDevRAM, GCPhysAddress, rc));
1352 }
1353 else
1354 {
1355 /*
1356 * Register and lock the VMMDevRAM.
1357 */
1358 /** @todo MM_RAM_FLAGS_MMIO2 seems to be appropriate for a RW memory.
1359 * Need to check. May be a RO memory is enough for the device.
1360 */
1361 rc = MMR3PhysRegister(pVM, pData->pVMMDevRAMHC, GCPhysAddress, VMMDEV_RAM_SIZE, MM_RAM_FLAGS_MMIO2, "VBoxDev");
1362 if (VBOX_SUCCESS(rc))
1363 {
1364 pData->GCPhysVMMDevRAM = GCPhysAddress;
1365 return VINF_SUCCESS;
1366 }
1367 AssertReleaseMsgFailed(("Failed to register VMMDev RAM! rc=%Vra\n", rc));
1368 }
1369 return rc;
1370 }
1371
1372 AssertReleaseMsgFailed(("VMMDev wrong region type: iRegion=%d enmType=%d\n", iRegion, enmType));
1373 return VERR_INTERNAL_ERROR;
1374}
1375
1376
1377/**
1378 * Callback function for mapping a PCI I/O region.
1379 *
1380 * @return VBox status code.
1381 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
1382 * @param iRegion The region number.
1383 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
1384 * I/O port, else it's a physical address.
1385 * This address is *NOT* relative to pci_mem_base like earlier!
1386 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1387 */
1388static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
1389{
1390 VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
1391 int rc = VINF_SUCCESS;
1392
1393 Assert(enmType == PCI_ADDRESS_SPACE_IO);
1394 Assert(iRegion == 0);
1395 AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
1396
1397 /*
1398 * Save the base port address to simplify Port offset calculations.
1399 */
1400 pData->PortBase = (RTIOPORT)GCPhysAddress;
1401
1402 /*
1403 * Register our port IO handlers.
1404 */
1405 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
1406 (RTIOPORT)GCPhysAddress + PORT_VMMDEV_REQUEST_OFFSET, 1,
1407 (void*)pData, vmmdevRequestHandler,
1408 NULL, NULL, NULL, "VMMDev Request Handler");
1409 AssertRC(rc);
1410 return rc;
1411}
1412
1413/**
1414 * Queries an interface to the driver.
1415 *
1416 * @returns Pointer to interface.
1417 * @returns NULL if the interface was not supported by the driver.
1418 * @param pInterface Pointer to this interface structure.
1419 * @param enmInterface The requested interface identification.
1420 * @thread Any thread.
1421 */
1422static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
1423{
1424 VMMDevState *pData = (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Base));
1425 switch (enmInterface)
1426 {
1427 case PDMINTERFACE_BASE:
1428 return &pData->Base;
1429 case PDMINTERFACE_VMMDEV_PORT:
1430 return &pData->Port;
1431#ifdef VBOX_HGCM
1432 case PDMINTERFACE_HGCM_PORT:
1433 return &pData->HGCMPort;
1434#endif
1435 default:
1436 return NULL;
1437 }
1438}
1439
1440/* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
1441
1442/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
1443#define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Port)) )
1444
1445
1446/**
1447 * Return the current absolute mouse position in pixels
1448 *
1449 * @returns VBox status code
1450 * @param pAbsX Pointer of result value, can be NULL
1451 * @param pAbsY Pointer of result value, can be NULL
1452 */
1453static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t *pAbsX, uint32_t *pAbsY)
1454{
1455 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1456 if (pAbsX)
1457 *pAbsX = pData->mouseXAbs;
1458 if (pAbsY)
1459 *pAbsY = pData->mouseYAbs;
1460 return VINF_SUCCESS;
1461}
1462
1463/**
1464 * Set the new absolute mouse position in pixels
1465 *
1466 * @returns VBox status code
1467 * @param absX New absolute X position
1468 * @param absY New absolute Y position
1469 */
1470static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t absX, uint32_t absY)
1471{
1472 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1473 Log(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
1474 pData->mouseXAbs = absX;
1475 pData->mouseYAbs = absY;
1476 return VINF_SUCCESS;
1477}
1478
1479/**
1480 * Return the current mouse capability flags
1481 *
1482 * @returns VBox status code
1483 * @param pCapabilities Pointer of result value
1484 */
1485static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pCapabilities)
1486{
1487 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1488 if (!pCapabilities)
1489 return VERR_INVALID_PARAMETER;
1490 *pCapabilities = pData->mouseCapabilities;
1491 return VINF_SUCCESS;
1492}
1493
1494/**
1495 * Set the current mouse capability flag (host side)
1496 *
1497 * @returns VBox status code
1498 * @param capabilities Capability mask
1499 */
1500static DECLCALLBACK(int) vmmdevSetMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t capabilities)
1501{
1502 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1503
1504 bool bCapsChanged = ((capabilities & VMMDEV_MOUSEHOSTWANTSABS)
1505 != (pData->mouseCapabilities & VMMDEV_MOUSEHOSTWANTSABS));
1506
1507 Log(("vmmdevSetMouseCapabilities: bCapsChanged %d\n", bCapsChanged));
1508
1509 if (capabilities & VMMDEV_MOUSEHOSTCANNOTHWPOINTER)
1510 pData->mouseCapabilities |= VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
1511 else
1512 pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
1513
1514 if (capabilities & VMMDEV_MOUSEHOSTWANTSABS)
1515 pData->mouseCapabilities |= VMMDEV_MOUSEHOSTWANTSABS;
1516 else
1517 pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTWANTSABS;
1518
1519 if (bCapsChanged)
1520 VMMDevNotifyGuest (pData, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
1521
1522 return VINF_SUCCESS;
1523}
1524
1525
1526static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
1527{
1528 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1529
1530 /* Verify that the new resolution is different and that guest does not yet know about it. */
1531 bool fSameResolution = (!xres || (pData->lastReadDisplayChangeRequest.xres == xres)) &&
1532 (!yres || (pData->lastReadDisplayChangeRequest.yres == yres)) &&
1533 (!bpp || (pData->lastReadDisplayChangeRequest.bpp == bpp)) &&
1534 pData->lastReadDisplayChangeRequest.display == display;
1535
1536 if (!xres && !yres && !bpp)
1537 {
1538 /* Special case of reset video mode. */
1539 fSameResolution = false;
1540 }
1541
1542#ifdef DEBUG_sunlover
1543 Log(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
1544 fSameResolution, xres, yres, bpp, display, pData->lastReadDisplayChangeRequest.xres, pData->lastReadDisplayChangeRequest.yres, pData->lastReadDisplayChangeRequest.bpp, pData->lastReadDisplayChangeRequest.display));
1545#endif /* DEBUG_sunlover */
1546
1547 if (!fSameResolution)
1548 {
1549 LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
1550 xres, yres, bpp, display));
1551
1552 /* we could validate the information here but hey, the guest can do that as well! */
1553 pData->displayChangeRequest.xres = xres;
1554 pData->displayChangeRequest.yres = yres;
1555 pData->displayChangeRequest.bpp = bpp;
1556 pData->displayChangeRequest.display = display;
1557
1558 /* IRQ so the guest knows what's going on */
1559 VMMDevNotifyGuest (pData, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1560 }
1561
1562 return VINF_SUCCESS;
1563}
1564
1565static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
1566 const char *pszPassword, const char *pszDomain,
1567 uint32_t u32Flags)
1568{
1569 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1570
1571 /* logon mode? */
1572 if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
1573 {
1574 /* memorize the data */
1575 strcpy(pData->credentialsLogon.szUserName, pszUsername);
1576 strcpy(pData->credentialsLogon.szPassword, pszPassword);
1577 strcpy(pData->credentialsLogon.szDomain, pszDomain);
1578 pData->credentialsLogon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
1579 }
1580 /* credentials verification mode? */
1581 else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
1582 {
1583 /* memorize the data */
1584 strcpy(pData->credentialsJudge.szUserName, pszUsername);
1585 strcpy(pData->credentialsJudge.szPassword, pszPassword);
1586 strcpy(pData->credentialsJudge.szDomain, pszDomain);
1587
1588 VMMDevNotifyGuest (pData, VMMDEV_EVENT_JUDGE_CREDENTIALS);
1589 }
1590 else
1591 return VERR_INVALID_PARAMETER;
1592
1593 return VINF_SUCCESS;
1594}
1595
1596/**
1597 * Notification from the Display. Especially useful when
1598 * acceleration is disabled after a video mode change.
1599 *
1600 * @param fEnable Current acceleration status.
1601 */
1602static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
1603{
1604 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1605
1606 Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
1607
1608 if (pData)
1609 {
1610 pData->u32VideoAccelEnabled = fEnabled;
1611 }
1612
1613 return;
1614}
1615
1616
1617/* -=-=-=-=-=- IHGCMPort -=-=-=-=-=- */
1618
1619/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
1620#define IHGCMPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, HGCMPort)) )
1621
1622
1623
1624#define VMMDEV_SSM_VERSION 4
1625
1626/**
1627 * Saves a state of the VMM device.
1628 *
1629 * @returns VBox status code.
1630 * @param pDevIns The device instance.
1631 * @param pSSMHandle The handle to save the state to.
1632 */
1633static DECLCALLBACK(int) vmmdevSaveState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1634{
1635 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1636 SSMR3PutU32(pSSMHandle, pData->hypervisorSize);
1637 SSMR3PutU32(pSSMHandle, pData->mouseCapabilities);
1638 SSMR3PutU32(pSSMHandle, pData->mouseXAbs);
1639 SSMR3PutU32(pSSMHandle, pData->mouseYAbs);
1640
1641 SSMR3PutBool(pSSMHandle, pData->fNewGuestFilterMask);
1642 SSMR3PutU32(pSSMHandle, pData->u32NewGuestFilterMask);
1643 SSMR3PutU32(pSSMHandle, pData->u32GuestFilterMask);
1644 SSMR3PutU32(pSSMHandle, pData->u32HostEventFlags);
1645 // here be dragons (probably)
1646// SSMR3PutBool(pSSMHandle, pData->pVMMDevRAMHC->V.V1_04.fHaveEvents);
1647 SSMR3PutMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
1648
1649 SSMR3PutMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
1650 SSMR3PutU32(pSSMHandle, pData->fu32AdditionsOk);
1651 SSMR3PutU32(pSSMHandle, pData->u32VideoAccelEnabled);
1652
1653 SSMR3PutU32(pSSMHandle, pData->guestCaps);
1654
1655#ifdef VBOX_HGCM
1656 vmmdevHGCMSaveState (pData, pSSMHandle);
1657#endif /* VBOX_HGCM */
1658
1659 return VINF_SUCCESS;
1660}
1661
1662/**
1663 * Loads the saved VMM device state.
1664 *
1665 * @returns VBox status code.
1666 * @param pDevIns The device instance.
1667 * @param pSSMHandle The handle to the saved state.
1668 * @param u32Version The data unit version number.
1669 */
1670static DECLCALLBACK(int) vmmdevLoadState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
1671{
1672 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1673 if (u32Version != VMMDEV_SSM_VERSION)
1674 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1675 SSMR3GetU32(pSSMHandle, &pData->hypervisorSize);
1676 SSMR3GetU32(pSSMHandle, &pData->mouseCapabilities);
1677 SSMR3GetU32(pSSMHandle, &pData->mouseXAbs);
1678 SSMR3GetU32(pSSMHandle, &pData->mouseYAbs);
1679
1680 SSMR3GetBool(pSSMHandle, &pData->fNewGuestFilterMask);
1681 SSMR3GetU32(pSSMHandle, &pData->u32NewGuestFilterMask);
1682 SSMR3GetU32(pSSMHandle, &pData->u32GuestFilterMask);
1683 SSMR3GetU32(pSSMHandle, &pData->u32HostEventFlags);
1684// SSMR3GetBool(pSSMHandle, &pData->pVMMDevRAMHC->fHaveEvents);
1685 // here be dragons (probably)
1686 SSMR3GetMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
1687
1688 SSMR3GetMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
1689 SSMR3GetU32(pSSMHandle, &pData->fu32AdditionsOk);
1690 SSMR3GetU32(pSSMHandle, &pData->u32VideoAccelEnabled);
1691
1692 SSMR3GetU32(pSSMHandle, &pData->guestCaps);
1693
1694#ifdef VBOX_HGCM
1695 vmmdevHGCMLoadState (pData, pSSMHandle);
1696#endif /* VBOX_HGCM */
1697
1698 /*
1699 * On a resume, we send the capabilities changed message so
1700 * that listeners can sync their state again
1701 */
1702 Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
1703 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
1704
1705 /* Reestablish the acceleration status. */
1706 if (pData->u32VideoAccelEnabled)
1707 {
1708 pData->pDrv->pfnVideoAccelEnable (pData->pDrv, !!pData->u32VideoAccelEnabled, &pData->pVMMDevRAMHC->vbvaMemory);
1709 }
1710
1711 if (pData->fu32AdditionsOk)
1712 {
1713 LogRel(("Guest Additions information report: additionsVersion = 0x%08X osType = 0x%08X\n",
1714 pData->guestInfo.additionsVersion,
1715 pData->guestInfo.osType));
1716 pData->pDrv->pfnUpdateGuestVersion(pData->pDrv, &pData->guestInfo);
1717 }
1718 pData->pDrv->pfnUpdateGuestCapabilities(pData->pDrv, pData->guestCaps);
1719
1720 return VINF_SUCCESS;
1721}
1722
1723/**
1724 * Load state done callback. Notify guest of restore event.
1725 *
1726 * @returns VBox status code.
1727 * @param pDevIns The device instance.
1728 * @param pSSMHandle The handle to the saved state.
1729 */
1730static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1731{
1732 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1733
1734#ifdef VBOX_HGCM
1735 vmmdevHGCMLoadStateDone (pData, pSSMHandle);
1736#endif /* VBOX_HGCM */
1737
1738 VMMDevNotifyGuest (pData, VMMDEV_EVENT_RESTORED);
1739
1740 return VINF_SUCCESS;
1741}
1742
1743/**
1744 * Construct a device instance for a VM.
1745 *
1746 * @returns VBox status.
1747 * @param pDevIns The device instance data.
1748 * If the registration structure is needed, pDevIns->pDevReg points to it.
1749 * @param iInstance Instance number. Use this to figure out which registers and such to use.
1750 * The device number is also found in pDevIns->iInstance, but since it's
1751 * likely to be freqently used PDM passes it as parameter.
1752 * @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
1753 * of the device instance. It's also found in pDevIns->pCfgHandle, but like
1754 * iInstance it's expected to be used a bit in this function.
1755 */
1756static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfgHandle)
1757{
1758 int rc;
1759 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState *);
1760
1761 Assert(iInstance == 0);
1762
1763 /*
1764 * Validate and read the configuration.
1765 */
1766 if (!CFGMR3AreValuesValid(pCfgHandle, "GetHostTimeDisabled\0BackdoorLogDisabled\0"))
1767 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
1768
1769 rc = CFGMR3QueryBool(pCfgHandle, "GetHostTimeDisabled", &pData->fGetHostTimeDisabled);
1770 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1771 pData->fGetHostTimeDisabled = false;
1772 else if (VBOX_FAILURE(rc))
1773 return PDMDEV_SET_ERROR(pDevIns, rc,
1774 N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
1775
1776 rc = CFGMR3QueryBool(pCfgHandle, "BackdoorLogDisabled", &pData->fBackdoorLogDisabled);
1777 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1778 pData->fBackdoorLogDisabled = false;
1779 else if (VBOX_FAILURE(rc))
1780 return PDMDEV_SET_ERROR(pDevIns, rc,
1781 N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
1782
1783 /*
1784 * Initialize data (most of it anyway).
1785 */
1786 /* Save PDM device instance data for future reference. */
1787 pData->pDevIns = pDevIns;
1788
1789 /* PCI vendor, just a free bogus value */
1790 pData->dev.config[0x00] = 0xee;
1791 pData->dev.config[0x01] = 0x80;
1792 /* device ID */
1793 pData->dev.config[0x02] = 0xfe;
1794 pData->dev.config[0x03] = 0xca;
1795 /* class sub code (other type of system peripheral) */
1796 pData->dev.config[0x0a] = 0x80;
1797 /* class base code (base system peripheral) */
1798 pData->dev.config[0x0b] = 0x08;
1799 /* header type */
1800 pData->dev.config[0x0e] = 0x00;
1801 /* interrupt on pin 0 */
1802 pData->dev.config[0x3d] = 0x01;
1803
1804 /*
1805 * Register the backdoor logging port
1806 */
1807 rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
1808 AssertRCReturn(rc, rc);
1809
1810#ifdef TIMESYNC_BACKDOOR
1811 /*
1812 * Alternative timesync source (temporary!)
1813 */
1814 rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
1815 AssertRCReturn(rc, rc);
1816#endif
1817
1818 /*
1819 * Register the PCI device.
1820 */
1821 rc = PDMDevHlpPCIRegister(pDevIns, &pData->dev);
1822 if (VBOX_FAILURE(rc))
1823 return rc;
1824 if (pData->dev.devfn == 32 || iInstance != 0)
1825 Log(("!!WARNING!!: pData->dev.devfn=%d (ignore if testcase or no started by Main)\n", pData->dev.devfn));
1826 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
1827 if (VBOX_FAILURE(rc))
1828 return rc;
1829 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
1830 if (VBOX_FAILURE(rc))
1831 return rc;
1832
1833 /*
1834 * Interfaces
1835 */
1836 /* Base */
1837 pData->Base.pfnQueryInterface = vmmdevPortQueryInterface;
1838
1839 /* VMMDev port */
1840 pData->Port.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
1841 pData->Port.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
1842 pData->Port.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
1843 pData->Port.pfnSetMouseCapabilities = vmmdevSetMouseCapabilities;
1844 pData->Port.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
1845 pData->Port.pfnSetCredentials = vmmdevSetCredentials;
1846 pData->Port.pfnVBVAChange = vmmdevVBVAChange;
1847
1848
1849#ifdef VBOX_HGCM
1850 /* HGCM port */
1851 pData->HGCMPort.pfnCompleted = hgcmCompleted;
1852#endif
1853
1854 /*
1855 * Get the corresponding connector interface
1856 */
1857 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pData->Base, &pData->pDrvBase, "VMM Driver Port");
1858 if (VBOX_SUCCESS(rc))
1859 {
1860 pData->pDrv = (PPDMIVMMDEVCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_VMMDEV_CONNECTOR);
1861 if (!pData->pDrv)
1862 AssertMsgFailedReturn(("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
1863#ifdef VBOX_HGCM
1864 pData->pHGCMDrv = (PPDMIHGCMCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_HGCM_CONNECTOR);
1865 if (!pData->pHGCMDrv)
1866 {
1867 Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Vrc\n", rc));
1868 /* this is not actually an error, just means that there is no support for HGCM */
1869 }
1870#endif
1871 }
1872 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
1873 {
1874 Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
1875 rc = VINF_SUCCESS;
1876 }
1877 else
1878 AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Vrc\n", rc), rc);
1879
1880 /*
1881 * Register saved state and init the HGCM CmdList critsect.
1882 */
1883 rc = PDMDevHlpSSMRegister(pDevIns, "VMMDev", iInstance, VMMDEV_SSM_VERSION, sizeof(*pData),
1884 NULL, vmmdevSaveState, NULL,
1885 NULL, vmmdevLoadState, vmmdevLoadStateDone);
1886 AssertRCReturn(rc, rc);
1887
1888#ifdef VBOX_HGCM
1889 pData->pHGCMCmdList = NULL;
1890 rc = RTCritSectInit(&pData->critsectHGCMCmdList);
1891 AssertRCReturn(rc, rc);
1892 pData->u32HGCMEnabled = 0;
1893#endif /* VBOX_HGCM */
1894
1895 /*
1896 * Allocate the VMMDev RAM region.
1897 */
1898 /** @todo freeing of the RAM. */
1899 rc = SUPPageAlloc(VMMDEV_RAM_SIZE >> PAGE_SHIFT, (void **)&pData->pVMMDevRAMHC);
1900 AssertMsgRCReturn(rc, ("VMMDev SUPPageAlloc(%#x,) -> %Vrc\n", VMMDEV_RAM_SIZE, rc), rc);
1901
1902 /* initialize the VMMDev memory */
1903 pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
1904 pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
1905
1906 return rc;
1907}
1908
1909/**
1910 * Reset notification.
1911 *
1912 * @returns VBox status.
1913 * @param pDrvIns The driver instance data.
1914 */
1915static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
1916{
1917 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1918 /*
1919 * Reset the mouse integration feature bit
1920 */
1921 if (pData->mouseCapabilities & (VMMDEV_MOUSEGUESTWANTSABS|VMMDEV_MOUSEGUESTNEEDSHOSTCUR))
1922 {
1923 pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTWANTSABS;
1924 /* notify the connector */
1925 Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
1926 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
1927 }
1928
1929 pData->hypervisorSize = 0;
1930
1931 pData->u32HostEventFlags = 0;
1932
1933 if (pData->pVMMDevRAMHC)
1934 {
1935 /* re-initialize the VMMDev memory */
1936 memset (pData->pVMMDevRAMHC, 0, VMMDEV_RAM_SIZE);
1937 pData->pVMMDevRAMHC->u32Size = sizeof (VMMDevMemory);
1938 pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
1939 }
1940
1941 /* credentials have to go away */
1942 memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1943 memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1944 memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1945 memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1946 memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1947 memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1948
1949 /* Reset means that additions will report again. */
1950 pData->fu32AdditionsOk = false;
1951 memset (&pData->guestInfo, 0, sizeof (pData->guestInfo));
1952 pData->guestCaps = 0;
1953
1954 memset (&pData->lastReadDisplayChangeRequest, 0, sizeof (pData->lastReadDisplayChangeRequest));
1955
1956 /* Clear the event variables.
1957 *
1958 * Note: The pData->u32HostEventFlags is not cleared.
1959 * It is designed that way so host events do not
1960 * depend on guest resets.
1961 */
1962 pData->u32GuestFilterMask = 0;
1963 pData->u32NewGuestFilterMask = 0;
1964 pData->fNewGuestFilterMask = 0;
1965}
1966
1967
1968/**
1969 * The device registration structure.
1970 */
1971extern "C" const PDMDEVREG g_DeviceVMMDev =
1972{
1973 /* u32Version */
1974 PDM_DEVREG_VERSION,
1975 /* szDeviceName */
1976 "VMMDev",
1977 /* szGCMod */
1978 "",
1979 /* szR0Mod */
1980 "",
1981 /* pszDescription */
1982 "VirtualBox VMM Device\n",
1983 /* fFlags */
1984 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32,
1985 /* fClass */
1986 PDM_DEVREG_CLASS_VMM_DEV,
1987 /* cMaxInstances */
1988 1,
1989 /* cbInstance */
1990 sizeof(VMMDevState),
1991 /* pfnConstruct */
1992 vmmdevConstruct,
1993 /* pfnDestruct */
1994 NULL,
1995 /* pfnRelocate */
1996 NULL,
1997 /* pfnIOCtl */
1998 NULL,
1999 /* pfnPowerOn */
2000 NULL,
2001 /* pfnReset */
2002 vmmdevReset,
2003 /* pfnSuspend */
2004 NULL,
2005 /* pfnResume */
2006 NULL,
2007 /* pfnAttach */
2008 NULL,
2009 /* pfnDetach */
2010 NULL,
2011 /* pfnQueryInterface. */
2012 NULL
2013};
2014#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
2015
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