VirtualBox

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

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

Extend HGCM interface to support 64 bit pointers.

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