VirtualBox

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

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

shorten the guest additions cap report strings a little bit

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 92.5 KB
Line 
1/* $Id: VBoxDev.cpp 8325 2008-04-23 12:34:37Z 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 case VMMDevReq_SetMaxGuestResolution:
580 {
581 if (pRequestHeader->size != sizeof(VMMDevReqGuestResolution))
582 {
583 AssertMsgFailed(("VMMDev guest resolution structure has invalid size!\n"));
584 pRequestHeader->rc = VERR_INVALID_PARAMETER;
585 }
586 else
587 {
588 VMMDevReqGuestResolution *guestRes = (VMMDevReqGuestResolution*)pRequestHeader;
589
590 pData->u32MaxGuestWidth = guestRes->u32MaxWidth;
591 pData->u32MaxGuestHeight = guestRes->u32MaxHeight;
592
593 LogRel(("Guest Additions maximum resolution of %dx%d reported\n",
594 pData->u32MaxGuestWidth, pData->u32MaxGuestHeight));
595
596 /* Only notify frontends that are interested (i.e. Main, but not BFE) */
597 if (NULL != pData->pDrv->pfnUpdateMaxGuestResolution)
598 pData->pDrv->pfnUpdateMaxGuestResolution(pData->pDrv, pData->u32MaxGuestWidth, pData->u32MaxGuestHeight);
599 pRequestHeader->rc = VINF_SUCCESS;
600 }
601 break;
602 }
603
604 /*
605 * Retrieve mouse information
606 */
607 case VMMDevReq_GetMouseStatus:
608 {
609 if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
610 {
611 AssertMsgFailed(("VMMDev mouse status structure has invalid size!\n"));
612 pRequestHeader->rc = VERR_INVALID_PARAMETER;
613 }
614 else
615 {
616 VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)pRequestHeader;
617 mouseStatus->mouseFeatures = 0;
618 if (pData->mouseCapabilities & VMMDEV_MOUSEHOSTWANTSABS)
619 {
620 mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_HOST_CAN_ABSOLUTE;
621 }
622 if (pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS)
623 {
624 mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE;
625 }
626 if (pData->mouseCapabilities & VMMDEV_MOUSEHOSTCANNOTHWPOINTER)
627 {
628 mouseStatus->mouseFeatures |= VBOXGUEST_MOUSE_HOST_CANNOT_HWPOINTER;
629 }
630 mouseStatus->pointerXPos = pData->mouseXAbs;
631 mouseStatus->pointerYPos = pData->mouseYAbs;
632 Log2(("returning mouse status: features = %d, absX = %d, absY = %d\n", mouseStatus->mouseFeatures,
633 mouseStatus->pointerXPos, mouseStatus->pointerYPos));
634 pRequestHeader->rc = VINF_SUCCESS;
635 }
636 break;
637 }
638
639 /*
640 * Set mouse information
641 */
642 case VMMDevReq_SetMouseStatus:
643 {
644 if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
645 {
646 AssertMsgFailed(("VMMDev mouse status structure has invalid size %d (%#x) version=%d!\n",
647 pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
648 pRequestHeader->rc = VERR_INVALID_PARAMETER;
649 }
650 else
651 {
652 bool bCapsChanged = false;
653
654 VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)pRequestHeader;
655
656 /* check if the guest wants absolute coordinates */
657 if (mouseStatus->mouseFeatures & VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE)
658 {
659 /* set the capability flag and the changed flag if it's actually a change */
660 if (!(pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS))
661 {
662 pData->mouseCapabilities |= VMMDEV_MOUSEGUESTWANTSABS;
663 bCapsChanged = true;
664 LogRel(("Guest requests mouse pointer integration\n"));
665 }
666 } else
667 {
668 if (pData->mouseCapabilities & VMMDEV_MOUSEGUESTWANTSABS)
669 {
670 pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTWANTSABS;
671 bCapsChanged = true;
672 LogRel(("Guest disables mouse pointer integration\n"));
673 }
674 }
675 if (mouseStatus->mouseFeatures & VBOXGUEST_MOUSE_GUEST_NEEDS_HOST_CURSOR)
676 pData->mouseCapabilities |= VMMDEV_MOUSEGUESTNEEDSHOSTCUR;
677 else
678 pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTNEEDSHOSTCUR;
679
680 /*
681 * Notify connector if something has changed
682 */
683 if (bCapsChanged)
684 {
685 Log(("VMMDevReq_SetMouseStatus: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
686 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
687 }
688 pRequestHeader->rc = VINF_SUCCESS;
689 }
690
691 break;
692 }
693
694 /*
695 * Set a new mouse pointer shape
696 */
697 case VMMDevReq_SetPointerShape:
698 {
699 if (pRequestHeader->size < sizeof(VMMDevReqMousePointer))
700 {
701 AssertMsg(pRequestHeader->size == 0x10028 && pRequestHeader->version == 10000, /* don't bitch about legacy!!! */
702 ("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
703 pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
704 pRequestHeader->rc = VERR_INVALID_PARAMETER;
705 }
706 else
707 {
708 VMMDevReqMousePointer *pointerShape = (VMMDevReqMousePointer*)pRequestHeader;
709
710 bool fVisible = (pointerShape->fFlags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
711 bool fAlpha = (pointerShape->fFlags & VBOX_MOUSE_POINTER_ALPHA) != 0;
712 bool fShape = (pointerShape->fFlags & VBOX_MOUSE_POINTER_SHAPE) != 0;
713
714 Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
715 fVisible, fAlpha, fShape, pointerShape->width, pointerShape->height));
716
717 if (pRequestHeader->size == sizeof(VMMDevReqMousePointer))
718 {
719 /* The guest did not provide the shape actually. */
720 fShape = false;
721 }
722
723 /* forward call to driver */
724 if (fShape)
725 {
726 pData->pDrv->pfnUpdatePointerShape(pData->pDrv,
727 fVisible,
728 fAlpha,
729 pointerShape->xHot, pointerShape->yHot,
730 pointerShape->width, pointerShape->height,
731 pointerShape->pointerData);
732 }
733 else
734 {
735 pData->pDrv->pfnUpdatePointerShape(pData->pDrv,
736 fVisible,
737 0,
738 0, 0,
739 0, 0,
740 NULL);
741 }
742 pRequestHeader->rc = VINF_SUCCESS;
743 }
744 break;
745 }
746
747 /*
748 * Query the system time from the host
749 */
750 case VMMDevReq_GetHostTime:
751 {
752 if (pRequestHeader->size != sizeof(VMMDevReqHostTime))
753 {
754 AssertMsgFailed(("VMMDev host time structure has invalid size!\n"));
755 pRequestHeader->rc = VERR_INVALID_PARAMETER;
756 }
757 else if (RT_UNLIKELY(pData->fGetHostTimeDisabled))
758 pRequestHeader->rc = VERR_NOT_SUPPORTED;
759 else
760 {
761 VMMDevReqHostTime *hostTimeReq = (VMMDevReqHostTime*)pRequestHeader;
762 RTTIMESPEC now;
763 hostTimeReq->time = RTTimeSpecGetMilli(PDMDevHlpUTCNow(pDevIns, &now));
764 pRequestHeader->rc = VINF_SUCCESS;
765 }
766 break;
767 }
768
769 /*
770 * Query information about the hypervisor
771 */
772 case VMMDevReq_GetHypervisorInfo:
773 {
774 if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
775 {
776 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
777 pRequestHeader->rc = VERR_INVALID_PARAMETER;
778 }
779 else
780 {
781 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
782 PVM pVM = PDMDevHlpGetVM(pDevIns);
783 pRequestHeader->rc = PGMR3MappingsSize(pVM, &hypervisorInfo->hypervisorSize);
784 }
785 break;
786 }
787
788 /*
789 * Set hypervisor information
790 */
791 case VMMDevReq_SetHypervisorInfo:
792 {
793 if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
794 {
795 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
796 pRequestHeader->rc = VERR_INVALID_PARAMETER;
797 }
798 else
799 {
800 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
801 PVM pVM = PDMDevHlpGetVM(pDevIns);
802 if (hypervisorInfo->hypervisorStart == 0)
803 pRequestHeader->rc = PGMR3MappingsUnfix(pVM);
804 else
805 {
806 /* only if the client has queried the size before! */
807 uint32_t mappingsSize;
808 pRequestHeader->rc = PGMR3MappingsSize(pVM, &mappingsSize);
809 if (VBOX_SUCCESS(pRequestHeader->rc) && hypervisorInfo->hypervisorSize == mappingsSize)
810 {
811 /* new reservation */
812 pRequestHeader->rc = PGMR3MappingsFix(pVM, hypervisorInfo->hypervisorStart,
813 hypervisorInfo->hypervisorSize);
814 LogRel(("Guest reported fixed hypervisor window at 0x%p (size = 0x%x, rc = %Vrc)\n",
815 hypervisorInfo->hypervisorStart,
816 hypervisorInfo->hypervisorSize,
817 pRequestHeader->rc));
818 }
819 }
820 }
821 break;
822 }
823
824 /*
825 * Set the system power status
826 */
827 case VMMDevReq_SetPowerStatus:
828 {
829 if (pRequestHeader->size != sizeof(VMMDevPowerStateRequest))
830 {
831 AssertMsgFailed(("VMMDev power state request structure has invalid size!\n"));
832 pRequestHeader->rc = VERR_INVALID_PARAMETER;
833 }
834 else
835 {
836 VMMDevPowerStateRequest *powerStateRequest = (VMMDevPowerStateRequest*)pRequestHeader;
837 switch(powerStateRequest->powerState)
838 {
839 case VMMDevPowerState_Pause:
840 {
841 LogRel(("Guest requests the VM to be suspended (paused)\n"));
842 pRequestHeader->rc = rcRet = PDMDevHlpVMSuspend(pDevIns);
843 break;
844 }
845
846 case VMMDevPowerState_PowerOff:
847 {
848 LogRel(("Guest requests the VM to be turned off\n"));
849 pRequestHeader->rc = rcRet = PDMDevHlpVMPowerOff(pDevIns);
850 break;
851 }
852
853 case VMMDevPowerState_SaveState:
854 {
855 /** @todo no API for that yet */
856 pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
857 break;
858 }
859
860 default:
861 AssertMsgFailed(("VMMDev invalid power state request: %d\n", powerStateRequest->powerState));
862 pRequestHeader->rc = VERR_INVALID_PARAMETER;
863 break;
864 }
865 }
866 break;
867 }
868
869 /*
870 * Get display change request
871 */
872 case VMMDevReq_GetDisplayChangeRequest:
873 {
874 if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest))
875 {
876 /* Assert only if the size also not equal to a previous version size to prevent
877 * assertion with old additions.
878 */
879 AssertMsg(pRequestHeader->size == sizeof(VMMDevDisplayChangeRequest) - sizeof (uint32_t),
880 ("VMMDev display change request structure has invalid size!\n"));
881 pRequestHeader->rc = VERR_INVALID_PARAMETER;
882 }
883 else
884 {
885 VMMDevDisplayChangeRequest *displayChangeRequest = (VMMDevDisplayChangeRequest*)pRequestHeader;
886 /* just pass on the information */
887 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n",
888 pData->displayChangeRequest.xres, pData->displayChangeRequest.yres, pData->displayChangeRequest.bpp));
889 displayChangeRequest->xres = pData->displayChangeRequest.xres;
890 displayChangeRequest->yres = pData->displayChangeRequest.yres;
891 displayChangeRequest->bpp = pData->displayChangeRequest.bpp;
892
893 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
894 {
895 /* Remember which resolution the client has queried. */
896 pData->lastReadDisplayChangeRequest = pData->displayChangeRequest;
897 }
898
899 pRequestHeader->rc = VINF_SUCCESS;
900 }
901 break;
902 }
903
904 case VMMDevReq_GetDisplayChangeRequest2:
905 {
906 if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest2))
907 {
908 pRequestHeader->rc = VERR_INVALID_PARAMETER;
909 }
910 else
911 {
912 VMMDevDisplayChangeRequest2 *displayChangeRequest = (VMMDevDisplayChangeRequest2*)pRequestHeader;
913 /* just pass on the information */
914 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
915 pData->displayChangeRequest.xres, pData->displayChangeRequest.yres, pData->displayChangeRequest.bpp, pData->displayChangeRequest.display));
916 displayChangeRequest->xres = pData->displayChangeRequest.xres;
917 displayChangeRequest->yres = pData->displayChangeRequest.yres;
918 displayChangeRequest->bpp = pData->displayChangeRequest.bpp;
919 displayChangeRequest->display = pData->displayChangeRequest.display;
920
921 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
922 {
923 /* Remember which resolution the client has queried. */
924 pData->lastReadDisplayChangeRequest = pData->displayChangeRequest;
925 }
926
927 pRequestHeader->rc = VINF_SUCCESS;
928 }
929 break;
930 }
931
932 /*
933 * Query whether the given video mode is supported
934 */
935 case VMMDevReq_VideoModeSupported:
936 {
937 if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest))
938 {
939 AssertMsgFailed(("VMMDev video mode supported request structure has invalid size!\n"));
940 pRequestHeader->rc = VERR_INVALID_PARAMETER;
941 }
942 else
943 {
944 VMMDevVideoModeSupportedRequest *videoModeSupportedRequest = (VMMDevVideoModeSupportedRequest*)pRequestHeader;
945 /* forward the call */
946 pRequestHeader->rc = pData->pDrv->pfnVideoModeSupported(pData->pDrv,
947 videoModeSupportedRequest->width,
948 videoModeSupportedRequest->height,
949 videoModeSupportedRequest->bpp,
950 &videoModeSupportedRequest->fSupported);
951 }
952 break;
953 }
954
955 /*
956 * Query the height reduction in pixels
957 */
958 case VMMDevReq_GetHeightReduction:
959 {
960 if (pRequestHeader->size != sizeof(VMMDevGetHeightReductionRequest))
961 {
962 AssertMsgFailed(("VMMDev height reduction request structure has invalid size!\n"));
963 pRequestHeader->rc = VERR_INVALID_PARAMETER;
964 }
965 else
966 {
967 VMMDevGetHeightReductionRequest *heightReductionRequest = (VMMDevGetHeightReductionRequest*)pRequestHeader;
968 /* forward the call */
969 pRequestHeader->rc = pData->pDrv->pfnGetHeightReduction(pData->pDrv,
970 &heightReductionRequest->heightReduction);
971 }
972 break;
973 }
974
975 /*
976 * Acknowledge VMMDev events
977 */
978 case VMMDevReq_AcknowledgeEvents:
979 {
980 if (pRequestHeader->size != sizeof(VMMDevEvents))
981 {
982 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
983 pRequestHeader->rc = VERR_INVALID_PARAMETER;
984 }
985 else
986 {
987 if (VBOX_GUEST_ADDITIONS_VERSION_1_03 (pData))
988 {
989 vmmdevSetIRQ_Legacy_EMT (pData);
990 }
991 else
992 {
993 VMMDevEvents *pAckRequest;
994
995 if (pData->fNewGuestFilterMask)
996 {
997 pData->fNewGuestFilterMask = false;
998 pData->u32GuestFilterMask = pData->u32NewGuestFilterMask;
999 }
1000
1001 pAckRequest = (VMMDevEvents *)pRequestHeader;
1002 pAckRequest->events =
1003 pData->u32HostEventFlags & pData->u32GuestFilterMask;
1004
1005 pData->u32HostEventFlags &= ~pData->u32GuestFilterMask;
1006 pData->pVMMDevRAMHC->V.V1_04.fHaveEvents = false;
1007 PDMDevHlpPCISetIrqNoWait (pData->pDevIns, 0, 0);
1008 }
1009 pRequestHeader->rc = VINF_SUCCESS;
1010 }
1011 break;
1012 }
1013
1014 /*
1015 * Change guest filter mask
1016 */
1017 case VMMDevReq_CtlGuestFilterMask:
1018 {
1019 if (pRequestHeader->size != sizeof(VMMDevCtlGuestFilterMask))
1020 {
1021 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
1022 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1023 }
1024 else
1025 {
1026 VMMDevCtlGuestFilterMask *pCtlMaskRequest;
1027
1028 pCtlMaskRequest = (VMMDevCtlGuestFilterMask *)pRequestHeader;
1029 /* The HGCM events are enabled by the VMMDev device automatically when any
1030 * HGCM command is issued. The guest then can not disable these events.
1031 */
1032 vmmdevCtlGuestFilterMask_EMT (pData,
1033 pCtlMaskRequest->u32OrMask,
1034 pCtlMaskRequest->u32NotMask & ~VMMDEV_EVENT_HGCM);
1035 pRequestHeader->rc = VINF_SUCCESS;
1036
1037 }
1038 break;
1039 }
1040
1041#ifdef VBOX_HGCM
1042 /*
1043 * Process HGCM request
1044 */
1045 case VMMDevReq_HGCMConnect:
1046 {
1047 if (pRequestHeader->size < sizeof(VMMDevHGCMConnect))
1048 {
1049 AssertMsgFailed(("VMMDevReq_HGCMConnect structure has invalid size!\n"));
1050 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1051 }
1052 else if (!pData->pHGCMDrv)
1053 {
1054 Log(("VMMDevReq_HGCMConnect HGCM Connector is NULL!\n"));
1055 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1056 }
1057 else
1058 {
1059 VMMDevHGCMConnect *pHGCMConnect = (VMMDevHGCMConnect *)pRequestHeader;
1060
1061 Log(("VMMDevReq_HGCMConnect\n"));
1062
1063 pRequestHeader->rc = vmmdevHGCMConnect (pData, pHGCMConnect, (RTGCPHYS)u32);
1064 }
1065 break;
1066 }
1067
1068 case VMMDevReq_HGCMDisconnect:
1069 {
1070 if (pRequestHeader->size < sizeof(VMMDevHGCMDisconnect))
1071 {
1072 AssertMsgFailed(("VMMDevReq_HGCMDisconnect structure has invalid size!\n"));
1073 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1074 }
1075 else if (!pData->pHGCMDrv)
1076 {
1077 Log(("VMMDevReq_HGCMDisconnect HGCM Connector is NULL!\n"));
1078 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1079 }
1080 else
1081 {
1082 VMMDevHGCMDisconnect *pHGCMDisconnect = (VMMDevHGCMDisconnect *)pRequestHeader;
1083
1084 Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
1085 pRequestHeader->rc = vmmdevHGCMDisconnect (pData, pHGCMDisconnect, (RTGCPHYS)u32);
1086 }
1087 break;
1088 }
1089
1090 case VMMDevReq_HGCMCall:
1091 {
1092 if (pRequestHeader->size < sizeof(VMMDevHGCMCall))
1093 {
1094 AssertMsgFailed(("VMMDevReq_HGCMCall structure has invalid size!\n"));
1095 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1096 }
1097 else if (!pData->pHGCMDrv)
1098 {
1099 Log(("VMMDevReq_HGCMCall HGCM Connector is NULL!\n"));
1100 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1101 }
1102 else
1103 {
1104 VMMDevHGCMCall *pHGCMCall = (VMMDevHGCMCall *)pRequestHeader;
1105
1106 Log2(("VMMDevReq_HGCMCall: sizeof (VMMDevHGCMRequest) = %04X\n", sizeof (VMMDevHGCMCall)));
1107 Log2(("%.*Vhxd\n", pRequestHeader->size, pRequestHeader));
1108
1109 pRequestHeader->rc = vmmdevHGCMCall (pData, pHGCMCall, (RTGCPHYS)u32);
1110 }
1111 break;
1112 }
1113#endif /* VBOX_HGCM */
1114
1115 case VMMDevReq_VideoAccelEnable:
1116 {
1117 if (pRequestHeader->size < sizeof(VMMDevVideoAccelEnable))
1118 {
1119 Log(("VMMDevReq_VideoAccelEnable request size too small!!!\n"));
1120 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1121 }
1122 else if (!pData->pDrv)
1123 {
1124 Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!!\n"));
1125 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1126 }
1127 else
1128 {
1129 VMMDevVideoAccelEnable *ptr = (VMMDevVideoAccelEnable *)pRequestHeader;
1130
1131 if (ptr->cbRingBuffer != VBVA_RING_BUFFER_SIZE)
1132 {
1133 /* The guest driver seems compiled with another headers. */
1134 Log(("VMMDevReq_VideoAccelEnable guest ring buffer size %d, should be %d!!!\n", ptr->cbRingBuffer, VBVA_RING_BUFFER_SIZE));
1135 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1136 }
1137 else
1138 {
1139 /* The request is correct. */
1140 ptr->fu32Status |= VBVA_F_STATUS_ACCEPTED;
1141
1142 LogFlow(("VMMDevReq_VideoAccelEnable ptr->u32Enable = %d\n", ptr->u32Enable));
1143
1144 pRequestHeader->rc = ptr->u32Enable?
1145 pData->pDrv->pfnVideoAccelEnable (pData->pDrv, true, &pData->pVMMDevRAMHC->vbvaMemory):
1146 pData->pDrv->pfnVideoAccelEnable (pData->pDrv, false, NULL);
1147
1148 if ( ptr->u32Enable
1149 && VBOX_SUCCESS (pRequestHeader->rc))
1150 {
1151 ptr->fu32Status |= VBVA_F_STATUS_ENABLED;
1152
1153 /* Remember that guest successfully enabled acceleration.
1154 * We need to reestablish it on restoring the VM from saved state.
1155 */
1156 pData->u32VideoAccelEnabled = 1;
1157 }
1158 else
1159 {
1160 /* The acceleration was not enabled. Remember that. */
1161 pData->u32VideoAccelEnabled = 0;
1162 }
1163 }
1164 }
1165 break;
1166 }
1167
1168 case VMMDevReq_VideoAccelFlush:
1169 {
1170 if (pRequestHeader->size < sizeof(VMMDevVideoAccelFlush))
1171 {
1172 AssertMsgFailed(("VMMDevReq_VideoAccelFlush request size too small.\n"));
1173 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1174 }
1175 else if (!pData->pDrv)
1176 {
1177 Log(("VMMDevReq_VideoAccelFlush Connector is NULL!\n"));
1178 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1179 }
1180 else
1181 {
1182 pData->pDrv->pfnVideoAccelFlush (pData->pDrv);
1183
1184 pRequestHeader->rc = VINF_SUCCESS;
1185 }
1186 break;
1187 }
1188
1189 case VMMDevReq_VideoSetVisibleRegion:
1190 {
1191 if (pRequestHeader->size < sizeof(VMMDevVideoSetVisibleRegion))
1192 {
1193 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1194 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1195 }
1196 else if (!pData->pDrv)
1197 {
1198 Log(("VMMDevReq_VideoSetVisibleRegion Connector is NULL!!!\n"));
1199 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1200 }
1201 else
1202 {
1203 VMMDevVideoSetVisibleRegion *ptr = (VMMDevVideoSetVisibleRegion *)pRequestHeader;
1204
1205 if (!ptr->cRect)
1206 {
1207 Log(("VMMDevReq_VideoSetVisibleRegion no rectangles!!!\n"));
1208 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1209 }
1210 else
1211 if (pRequestHeader->size != sizeof(VMMDevVideoSetVisibleRegion) + (ptr->cRect-1)*sizeof(RTRECT))
1212 {
1213 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1214 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1215 }
1216 else
1217 {
1218 Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", ptr->cRect));
1219 /* forward the call */
1220 pRequestHeader->rc = pData->pDrv->pfnSetVisibleRegion(pData->pDrv, ptr->cRect, &ptr->Rect);
1221 }
1222 }
1223 break;
1224 }
1225
1226 case VMMDevReq_GetSeamlessChangeRequest:
1227 {
1228 if (pRequestHeader->size != sizeof(VMMDevSeamlessChangeRequest))
1229 {
1230 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1231 }
1232 else
1233 {
1234 VMMDevSeamlessChangeRequest *seamlessChangeRequest = (VMMDevSeamlessChangeRequest*)pRequestHeader;
1235 /* just pass on the information */
1236 Log(("VMMDev: returning seamless change request mode=%d\n", pData->fSeamlessEnabled));
1237 if (pData->fSeamlessEnabled)
1238 seamlessChangeRequest->mode = VMMDev_Seamless_Visible_Region;
1239 else
1240 seamlessChangeRequest->mode = VMMDev_Seamless_Disabled;
1241
1242 if (seamlessChangeRequest->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
1243 {
1244 /* Remember which mode the client has queried. */
1245 pData->fLastSeamlessEnabled = pData->fSeamlessEnabled;
1246 }
1247
1248 pRequestHeader->rc = VINF_SUCCESS;
1249 }
1250 break;
1251 }
1252
1253 case VMMDevReq_GetVRDPChangeRequest:
1254 {
1255 if (pRequestHeader->size != sizeof(VMMDevVRDPChangeRequest))
1256 {
1257 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1258 }
1259 else
1260 {
1261 VMMDevVRDPChangeRequest *vrdpChangeRequest = (VMMDevVRDPChangeRequest*)pRequestHeader;
1262 /* just pass on the information */
1263 Log(("VMMDev: returning VRDP status %d level %d\n", pData->fVRDPEnabled, pData->u32VRDPExperienceLevel));
1264
1265 vrdpChangeRequest->u8VRDPActive = pData->fVRDPEnabled;
1266 vrdpChangeRequest->u32VRDPExperienceLevel = pData->u32VRDPExperienceLevel;
1267
1268 pRequestHeader->rc = VINF_SUCCESS;
1269 }
1270 break;
1271 }
1272
1273 case VMMDevReq_GetMemBalloonChangeRequest:
1274 {
1275 Log(("VMMDevReq_GetMemBalloonChangeRequest\n"));
1276 if (pRequestHeader->size != sizeof(VMMDevGetMemBalloonChangeRequest))
1277 {
1278 AssertFailed();
1279 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1280 }
1281 else
1282 {
1283 VMMDevGetMemBalloonChangeRequest *memBalloonChangeRequest = (VMMDevGetMemBalloonChangeRequest*)pRequestHeader;
1284 /* just pass on the information */
1285 Log(("VMMDev: returning memory balloon size =%d\n", pData->u32MemoryBalloonSize));
1286 memBalloonChangeRequest->u32BalloonSize = pData->u32MemoryBalloonSize;
1287 memBalloonChangeRequest->u32PhysMemSize = pData->cbGuestRAM / (uint64_t)_1M;
1288
1289 if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
1290 {
1291 /* Remember which mode the client has queried. */
1292 pData->u32LastMemoryBalloonSize = pData->u32MemoryBalloonSize;
1293 }
1294
1295 pRequestHeader->rc = VINF_SUCCESS;
1296 }
1297 break;
1298 }
1299
1300 case VMMDevReq_ChangeMemBalloon:
1301 {
1302 VMMDevChangeMemBalloon *memBalloonChange = (VMMDevChangeMemBalloon*)pRequestHeader;
1303
1304 Log(("VMMDevReq_ChangeMemBalloon\n"));
1305 if ( pRequestHeader->size < sizeof(VMMDevChangeMemBalloon)
1306 || memBalloonChange->cPages != VMMDEV_MEMORY_BALLOON_CHUNK_PAGES
1307 || pRequestHeader->size != (uint32_t)RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[memBalloonChange->cPages]))
1308 {
1309 AssertFailed();
1310 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1311 }
1312 else
1313 {
1314 pRequestHeader->rc = pData->pDrv->pfnChangeMemoryBalloon(pData->pDrv, !!memBalloonChange->fInflate, memBalloonChange->cPages, memBalloonChange->aPhysPage);
1315 }
1316 break;
1317 }
1318
1319 case VMMDevReq_GetStatisticsChangeRequest:
1320 {
1321 Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
1322 if (pRequestHeader->size != sizeof(VMMDevGetStatisticsChangeRequest))
1323 {
1324 AssertFailed();
1325 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1326 }
1327 else
1328 {
1329 VMMDevGetStatisticsChangeRequest *statIntervalChangeRequest = (VMMDevGetStatisticsChangeRequest*)pRequestHeader;
1330 /* just pass on the information */
1331 Log(("VMMDev: returning statistics interval %d seconds\n", pData->u32StatIntervalSize));
1332 statIntervalChangeRequest->u32StatInterval = pData->u32StatIntervalSize;
1333
1334 if (statIntervalChangeRequest->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
1335 {
1336 /* Remember which mode the client has queried. */
1337 pData->u32LastStatIntervalSize= pData->u32StatIntervalSize;
1338 }
1339
1340 pRequestHeader->rc = VINF_SUCCESS;
1341 }
1342 break;
1343 }
1344
1345 case VMMDevReq_ReportGuestStats:
1346 {
1347 Log(("VMMDevReq_ReportGuestStats\n"));
1348 if (pRequestHeader->size != sizeof(VMMDevReportGuestStats))
1349 {
1350 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1351 }
1352 else
1353 {
1354 VMMDevReportGuestStats *stats = (VMMDevReportGuestStats*)pRequestHeader;
1355
1356#ifdef DEBUG
1357 VBoxGuestStatistics *pGuestStats = &stats->guestStats;
1358
1359 Log(("Current statistics:\n"));
1360 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
1361 Log(("CPU%d: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
1362
1363 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
1364 Log(("CPU%d: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
1365
1366 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
1367 Log(("CPU%d: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
1368
1369 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
1370 Log(("CPU%d: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
1371
1372 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
1373 Log(("CPU%d: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
1374
1375 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
1376 Log(("CPU%d: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
1377
1378 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
1379 Log(("CPU%d: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
1380
1381 /* Note that reported values are in pages; upper layers expect them in megabytes */
1382 Assert(pGuestStats->u32PageSize == 4096);
1383 if (pGuestStats->u32PageSize != 4096)
1384 pGuestStats->u32PageSize = 4096;
1385
1386 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
1387 Log(("CPU%d: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/pGuestStats->u32PageSize)-1)/ (_1M/pGuestStats->u32PageSize)));
1388
1389 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
1390 Log(("CPU%d: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/pGuestStats->u32PageSize)));
1391
1392 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
1393 Log(("CPU%d: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/pGuestStats->u32PageSize)));
1394
1395 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
1396 Log(("CPU%d: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/pGuestStats->u32PageSize)));
1397
1398 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
1399 Log(("CPU%d: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/pGuestStats->u32PageSize)));
1400
1401 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
1402 Log(("CPU%d: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/pGuestStats->u32PageSize)));
1403
1404 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
1405 Log(("CPU%d: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/pGuestStats->u32PageSize)));
1406
1407 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
1408 Log(("CPU%d: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/pGuestStats->u32PageSize)));
1409
1410 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
1411 Log(("CPU%d: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/pGuestStats->u32PageSize)));
1412 Log(("Statistics end *******************\n"));
1413#endif
1414
1415 /* forward the call */
1416 pRequestHeader->rc = pData->pDrv->pfnReportStatistics(pData->pDrv, &stats->guestStats);
1417 }
1418 break;
1419 }
1420
1421 case VMMDevReq_QueryCredentials:
1422 {
1423 if (pRequestHeader->size != sizeof(VMMDevCredentials))
1424 {
1425 AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
1426 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1427 }
1428 else
1429 {
1430 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
1431
1432 /* let's start by nulling out the data */
1433 memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1434 memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1435 memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1436
1437 /* should we return whether we got credentials for a logon? */
1438 if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
1439 {
1440 if ( pData->credentialsLogon.szUserName[0]
1441 || pData->credentialsLogon.szPassword[0]
1442 || pData->credentialsLogon.szDomain[0])
1443 {
1444 credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
1445 }
1446 else
1447 {
1448 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
1449 }
1450 }
1451
1452 /* does the guest want to read logon credentials? */
1453 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
1454 {
1455 if (pData->credentialsLogon.szUserName[0])
1456 strcpy(credentials->szUserName, pData->credentialsLogon.szUserName);
1457 if (pData->credentialsLogon.szPassword[0])
1458 strcpy(credentials->szPassword, pData->credentialsLogon.szPassword);
1459 if (pData->credentialsLogon.szDomain[0])
1460 strcpy(credentials->szDomain, pData->credentialsLogon.szDomain);
1461 if (!pData->credentialsLogon.fAllowInteractiveLogon)
1462 credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
1463 else
1464 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
1465 }
1466
1467 if (!pData->fKeepCredentials)
1468 {
1469 /* does the caller want us to destroy the logon credentials? */
1470 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
1471 {
1472 memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1473 memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1474 memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1475 }
1476 }
1477
1478 /* does the guest want to read credentials for verification? */
1479 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
1480 {
1481 if (pData->credentialsJudge.szUserName[0])
1482 strcpy(credentials->szUserName, pData->credentialsJudge.szUserName);
1483 if (pData->credentialsJudge.szPassword[0])
1484 strcpy(credentials->szPassword, pData->credentialsJudge.szPassword);
1485 if (pData->credentialsJudge.szDomain[0])
1486 strcpy(credentials->szDomain, pData->credentialsJudge.szDomain);
1487 }
1488
1489 /* does the caller want us to destroy the judgement credentials? */
1490 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
1491 {
1492 memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
1493 memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
1494 memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
1495 }
1496
1497 pRequestHeader->rc = VINF_SUCCESS;
1498 }
1499 break;
1500 }
1501
1502 case VMMDevReq_ReportCredentialsJudgement:
1503 {
1504 if (pRequestHeader->size != sizeof(VMMDevCredentials))
1505 {
1506 AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
1507 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1508 }
1509 else
1510 {
1511 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
1512
1513 /* what does the guest think about the credentials? (note: the order is important here!) */
1514 if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
1515 {
1516 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
1517 }
1518 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
1519 {
1520 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
1521 }
1522 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
1523 {
1524 pData->pDrv->pfnSetCredentialsJudgementResult(pData->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
1525 }
1526 else
1527 Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
1528
1529 pRequestHeader->rc = VINF_SUCCESS;
1530 }
1531 break;
1532 }
1533
1534#ifdef DEBUG
1535 case VMMDevReq_LogString:
1536 {
1537 if (pRequestHeader->size < sizeof(VMMDevReqLogString))
1538 {
1539 AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
1540 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1541 }
1542 else
1543 {
1544 VMMDevReqLogString *pReqLogString = (VMMDevReqLogString*)pRequestHeader;
1545#undef LOG_GROUP
1546#define LOG_GROUP LOG_GROUP_DEV_VMM_BACKDOOR
1547// Log(("Guest Log: %s", pReqLogString->szString));
1548 Log(("DEBUG LOG: %s", pReqLogString->szString));
1549
1550#undef LOG_GROUP
1551#define LOG_GROUP LOG_GROUP_DEV_VMM
1552 pRequestHeader->rc = VINF_SUCCESS;
1553 }
1554 break;
1555 }
1556#endif
1557 default:
1558 {
1559 pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
1560
1561 Log(("VMMDev unknown request type %d\n", pRequestHeader->requestType));
1562
1563 break;
1564 }
1565 }
1566
1567end:
1568 /* Write the result back to guest memory */
1569 if (pRequestHeader)
1570 {
1571 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, pRequestHeader, pRequestHeader->size);
1572 RTMemFree(pRequestHeader);
1573 }
1574 else
1575 {
1576 /* early error case; write back header only */
1577 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
1578 }
1579 return rcRet;
1580}
1581
1582/**
1583 * Callback function for mapping an PCI I/O region.
1584 *
1585 * @return VBox status code.
1586 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
1587 * @param iRegion The region number.
1588 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
1589 * I/O port, else it's a physical address.
1590 * This address is *NOT* relative to pci_mem_base like earlier!
1591 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1592 */
1593static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
1594{
1595 LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%VGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
1596 VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
1597 int rc;
1598
1599 AssertReturn(iRegion == 1 && enmType == PCI_ADDRESS_SPACE_MEM, VERR_INTERNAL_ERROR);
1600 Assert(pData->pVMMDevRAMHC != NULL);
1601
1602 if (GCPhysAddress != NIL_RTGCPHYS)
1603 {
1604 /*
1605 * Map the MMIO2 memory.
1606 */
1607 pData->GCPhysVMMDevRAM = GCPhysAddress;
1608 Assert(pData->GCPhysVMMDevRAM == GCPhysAddress);
1609 rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
1610 }
1611 else
1612 {
1613 /*
1614 * It is about to be unmapped, just clean up.
1615 */
1616 pData->GCPhysVMMDevRAM = NIL_RTGCPHYS32;
1617 rc = VINF_SUCCESS;
1618 }
1619
1620 return rc;
1621}
1622
1623
1624/**
1625 * Callback function for mapping a PCI I/O region.
1626 *
1627 * @return VBox status code.
1628 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
1629 * @param iRegion The region number.
1630 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
1631 * I/O port, else it's a physical address.
1632 * This address is *NOT* relative to pci_mem_base like earlier!
1633 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
1634 */
1635static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
1636{
1637 VMMDevState *pData = PCIDEV_2_VMMDEVSTATE(pPciDev);
1638 int rc = VINF_SUCCESS;
1639
1640 Assert(enmType == PCI_ADDRESS_SPACE_IO);
1641 Assert(iRegion == 0);
1642 AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
1643
1644 /*
1645 * Save the base port address to simplify Port offset calculations.
1646 */
1647 pData->PortBase = (RTIOPORT)GCPhysAddress;
1648
1649 /*
1650 * Register our port IO handlers.
1651 */
1652 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
1653 (RTIOPORT)GCPhysAddress + PORT_VMMDEV_REQUEST_OFFSET, 1,
1654 (void*)pData, vmmdevRequestHandler,
1655 NULL, NULL, NULL, "VMMDev Request Handler");
1656 AssertRC(rc);
1657 return rc;
1658}
1659
1660/**
1661 * Queries an interface to the driver.
1662 *
1663 * @returns Pointer to interface.
1664 * @returns NULL if the interface was not supported by the driver.
1665 * @param pInterface Pointer to this interface structure.
1666 * @param enmInterface The requested interface identification.
1667 * @thread Any thread.
1668 */
1669static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
1670{
1671 VMMDevState *pData = (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Base));
1672 switch (enmInterface)
1673 {
1674 case PDMINTERFACE_BASE:
1675 return &pData->Base;
1676 case PDMINTERFACE_VMMDEV_PORT:
1677 return &pData->Port;
1678#ifdef VBOX_HGCM
1679 case PDMINTERFACE_HGCM_PORT:
1680 return &pData->HGCMPort;
1681#endif
1682 case PDMINTERFACE_LED_PORTS:
1683 /* Currently only for shared folders */
1684 return &pData->SharedFolders.ILeds;
1685 default:
1686 return NULL;
1687 }
1688}
1689
1690/**
1691 * Gets the pointer to the status LED of a unit.
1692 *
1693 * @returns VBox status code.
1694 * @param pInterface Pointer to the interface structure containing the called function pointer.
1695 * @param iLUN The unit which status LED we desire.
1696 * @param ppLed Where to store the LED pointer.
1697 */
1698static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
1699{
1700 VMMDevState *pData = (VMMDevState *)( (uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, SharedFolders.ILeds) );
1701 if (iLUN == 0) /* LUN 0 is shared folders */
1702 {
1703 *ppLed = &pData->SharedFolders.Led;
1704 return VINF_SUCCESS;
1705 }
1706 return VERR_PDM_LUN_NOT_FOUND;
1707}
1708
1709/* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
1710
1711/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
1712#define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, Port)) )
1713
1714
1715/**
1716 * Return the current absolute mouse position in pixels
1717 *
1718 * @returns VBox status code
1719 * @param pAbsX Pointer of result value, can be NULL
1720 * @param pAbsY Pointer of result value, can be NULL
1721 */
1722static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t *pAbsX, uint32_t *pAbsY)
1723{
1724 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1725 if (pAbsX)
1726 *pAbsX = pData->mouseXAbs;
1727 if (pAbsY)
1728 *pAbsY = pData->mouseYAbs;
1729 return VINF_SUCCESS;
1730}
1731
1732/**
1733 * Set the new absolute mouse position in pixels
1734 *
1735 * @returns VBox status code
1736 * @param absX New absolute X position
1737 * @param absY New absolute Y position
1738 */
1739static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, uint32_t absX, uint32_t absY)
1740{
1741 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1742 Log2(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
1743 pData->mouseXAbs = absX;
1744 pData->mouseYAbs = absY;
1745 return VINF_SUCCESS;
1746}
1747
1748/**
1749 * Return the current mouse capability flags
1750 *
1751 * @returns VBox status code
1752 * @param pCapabilities Pointer of result value
1753 */
1754static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pCapabilities)
1755{
1756 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1757 if (!pCapabilities)
1758 return VERR_INVALID_PARAMETER;
1759 *pCapabilities = pData->mouseCapabilities;
1760 return VINF_SUCCESS;
1761}
1762
1763/**
1764 * Set the current mouse capability flag (host side)
1765 *
1766 * @returns VBox status code
1767 * @param capabilities Capability mask
1768 */
1769static DECLCALLBACK(int) vmmdevSetMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t capabilities)
1770{
1771 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1772
1773 bool bCapsChanged = ((capabilities & VMMDEV_MOUSEHOSTWANTSABS)
1774 != (pData->mouseCapabilities & VMMDEV_MOUSEHOSTWANTSABS));
1775
1776 Log(("vmmdevSetMouseCapabilities: bCapsChanged %d\n", bCapsChanged));
1777
1778 if (capabilities & VMMDEV_MOUSEHOSTCANNOTHWPOINTER)
1779 pData->mouseCapabilities |= VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
1780 else
1781 pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
1782
1783 if (capabilities & VMMDEV_MOUSEHOSTWANTSABS)
1784 pData->mouseCapabilities |= VMMDEV_MOUSEHOSTWANTSABS;
1785 else
1786 pData->mouseCapabilities &= ~VMMDEV_MOUSEHOSTWANTSABS;
1787
1788 if (bCapsChanged)
1789 VMMDevNotifyGuest (pData, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
1790
1791 return VINF_SUCCESS;
1792}
1793
1794
1795static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
1796{
1797 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1798
1799 /* Verify that the new resolution is different and that guest does not yet know about it. */
1800 bool fSameResolution = (!xres || (pData->lastReadDisplayChangeRequest.xres == xres)) &&
1801 (!yres || (pData->lastReadDisplayChangeRequest.yres == yres)) &&
1802 (!bpp || (pData->lastReadDisplayChangeRequest.bpp == bpp)) &&
1803 pData->lastReadDisplayChangeRequest.display == display;
1804
1805 if (!xres && !yres && !bpp)
1806 {
1807 /* Special case of reset video mode. */
1808 fSameResolution = false;
1809 }
1810
1811 Log3(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
1812 fSameResolution, xres, yres, bpp, display, pData->lastReadDisplayChangeRequest.xres, pData->lastReadDisplayChangeRequest.yres, pData->lastReadDisplayChangeRequest.bpp, pData->lastReadDisplayChangeRequest.display));
1813
1814 if (!fSameResolution)
1815 {
1816 LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
1817 xres, yres, bpp, display));
1818
1819 /* we could validate the information here but hey, the guest can do that as well! */
1820 pData->displayChangeRequest.xres = xres;
1821 pData->displayChangeRequest.yres = yres;
1822 pData->displayChangeRequest.bpp = bpp;
1823 pData->displayChangeRequest.display = display;
1824
1825 /* IRQ so the guest knows what's going on */
1826 VMMDevNotifyGuest (pData, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1827 }
1828
1829 return VINF_SUCCESS;
1830}
1831
1832static DECLCALLBACK(int) vmmdevRequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
1833{
1834 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1835
1836 /* Verify that the new resolution is different and that guest does not yet know about it. */
1837 bool fSameMode = (pData->fLastSeamlessEnabled == fEnabled);
1838
1839 Log(("vmmdevRequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
1840
1841 if (!fSameMode)
1842 {
1843 /* we could validate the information here but hey, the guest can do that as well! */
1844 pData->fSeamlessEnabled = fEnabled;
1845
1846 /* IRQ so the guest knows what's going on */
1847 VMMDevNotifyGuest (pData, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
1848 }
1849
1850 return VINF_SUCCESS;
1851}
1852
1853static DECLCALLBACK(int) vmmdevSetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t ulBalloonSize)
1854{
1855 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1856
1857 /* Verify that the new resolution is different and that guest does not yet know about it. */
1858 bool fSame = (pData->u32LastMemoryBalloonSize == ulBalloonSize);
1859
1860 Log(("vmmdevSetMemoryBalloon: old=%d. new=%d\n", pData->u32LastMemoryBalloonSize, ulBalloonSize));
1861
1862 if (!fSame)
1863 {
1864 /* we could validate the information here but hey, the guest can do that as well! */
1865 pData->u32MemoryBalloonSize = ulBalloonSize;
1866
1867 /* IRQ so the guest knows what's going on */
1868 VMMDevNotifyGuest (pData, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
1869 }
1870
1871 return VINF_SUCCESS;
1872}
1873
1874static DECLCALLBACK(int) vmmdevVRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t u32VRDPExperienceLevel)
1875{
1876 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1877
1878 bool fSame = (pData->fVRDPEnabled == fVRDPEnabled);
1879
1880 Log(("vmmdevVRDPChange: old=%d. new=%d\n", pData->fVRDPEnabled, fVRDPEnabled));
1881
1882 if (!fSame)
1883 {
1884 pData->fVRDPEnabled = fVRDPEnabled;
1885 pData->u32VRDPExperienceLevel = u32VRDPExperienceLevel;
1886
1887 VMMDevNotifyGuest (pData, VMMDEV_EVENT_VRDP);
1888 }
1889
1890 return VINF_SUCCESS;
1891}
1892
1893static DECLCALLBACK(int) vmmdevSetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t ulStatInterval)
1894{
1895 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1896
1897 /* Verify that the new resolution is different and that guest does not yet know about it. */
1898 bool fSame = (pData->u32LastStatIntervalSize == ulStatInterval);
1899
1900 Log(("vmmdevSetStatisticsInterval: old=%d. new=%d\n", pData->u32LastStatIntervalSize, ulStatInterval));
1901
1902 if (!fSame)
1903 {
1904 /* we could validate the information here but hey, the guest can do that as well! */
1905 pData->u32StatIntervalSize = ulStatInterval;
1906
1907 /* IRQ so the guest knows what's going on */
1908 VMMDevNotifyGuest (pData, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
1909 }
1910
1911 return VINF_SUCCESS;
1912}
1913
1914
1915static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
1916 const char *pszPassword, const char *pszDomain,
1917 uint32_t u32Flags)
1918{
1919 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1920
1921 /* logon mode? */
1922 if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
1923 {
1924 /* memorize the data */
1925 strcpy(pData->credentialsLogon.szUserName, pszUsername);
1926 strcpy(pData->credentialsLogon.szPassword, pszPassword);
1927 strcpy(pData->credentialsLogon.szDomain, pszDomain);
1928 pData->credentialsLogon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
1929 }
1930 /* credentials verification mode? */
1931 else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
1932 {
1933 /* memorize the data */
1934 strcpy(pData->credentialsJudge.szUserName, pszUsername);
1935 strcpy(pData->credentialsJudge.szPassword, pszPassword);
1936 strcpy(pData->credentialsJudge.szDomain, pszDomain);
1937
1938 VMMDevNotifyGuest (pData, VMMDEV_EVENT_JUDGE_CREDENTIALS);
1939 }
1940 else
1941 return VERR_INVALID_PARAMETER;
1942
1943 return VINF_SUCCESS;
1944}
1945
1946/**
1947 * Notification from the Display. Especially useful when
1948 * acceleration is disabled after a video mode change.
1949 *
1950 * @param fEnable Current acceleration status.
1951 */
1952static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
1953{
1954 VMMDevState *pData = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
1955
1956 Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
1957
1958 if (pData)
1959 {
1960 pData->u32VideoAccelEnabled = fEnabled;
1961 }
1962
1963 return;
1964}
1965
1966
1967/* -=-=-=-=-=- IHGCMPort -=-=-=-=-=- */
1968
1969/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
1970#define IHGCMPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, HGCMPort)) )
1971
1972
1973
1974#define VMMDEV_SSM_VERSION 7
1975
1976/**
1977 * Saves a state of the VMM device.
1978 *
1979 * @returns VBox status code.
1980 * @param pDevIns The device instance.
1981 * @param pSSMHandle The handle to save the state to.
1982 */
1983static DECLCALLBACK(int) vmmdevSaveState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
1984{
1985 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
1986 SSMR3PutU32(pSSMHandle, pData->hypervisorSize);
1987 SSMR3PutU32(pSSMHandle, pData->mouseCapabilities);
1988 SSMR3PutU32(pSSMHandle, pData->mouseXAbs);
1989 SSMR3PutU32(pSSMHandle, pData->mouseYAbs);
1990
1991 SSMR3PutBool(pSSMHandle, pData->fNewGuestFilterMask);
1992 SSMR3PutU32(pSSMHandle, pData->u32NewGuestFilterMask);
1993 SSMR3PutU32(pSSMHandle, pData->u32GuestFilterMask);
1994 SSMR3PutU32(pSSMHandle, pData->u32HostEventFlags);
1995 // here be dragons (probably)
1996// SSMR3PutBool(pSSMHandle, pData->pVMMDevRAMHC->V.V1_04.fHaveEvents);
1997 SSMR3PutMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
1998
1999 SSMR3PutMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
2000 SSMR3PutU32(pSSMHandle, pData->fu32AdditionsOk);
2001 SSMR3PutU32(pSSMHandle, pData->u32VideoAccelEnabled);
2002
2003 SSMR3PutU32(pSSMHandle, pData->guestCaps);
2004
2005 SSMR3PutU32(pSSMHandle, pData->u32MaxGuestWidth);
2006 SSMR3PutU32(pSSMHandle, pData->u32MaxGuestHeight);
2007
2008#ifdef VBOX_HGCM
2009 vmmdevHGCMSaveState (pData, pSSMHandle);
2010#endif /* VBOX_HGCM */
2011
2012 return VINF_SUCCESS;
2013}
2014
2015/**
2016 * Loads the saved VMM device state.
2017 *
2018 * @returns VBox status code.
2019 * @param pDevIns The device instance.
2020 * @param pSSMHandle The handle to the saved state.
2021 * @param u32Version The data unit version number.
2022 */
2023static DECLCALLBACK(int) vmmdevLoadState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
2024{
2025 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
2026 if ( SSM_VERSION_MAJOR_CHANGED(u32Version, VMMDEV_SSM_VERSION)
2027 || (SSM_VERSION_MINOR(u32Version) < 6))
2028 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
2029 SSMR3GetU32(pSSMHandle, &pData->hypervisorSize);
2030 SSMR3GetU32(pSSMHandle, &pData->mouseCapabilities);
2031 SSMR3GetU32(pSSMHandle, &pData->mouseXAbs);
2032 SSMR3GetU32(pSSMHandle, &pData->mouseYAbs);
2033
2034 SSMR3GetBool(pSSMHandle, &pData->fNewGuestFilterMask);
2035 SSMR3GetU32(pSSMHandle, &pData->u32NewGuestFilterMask);
2036 SSMR3GetU32(pSSMHandle, &pData->u32GuestFilterMask);
2037 SSMR3GetU32(pSSMHandle, &pData->u32HostEventFlags);
2038// SSMR3GetBool(pSSMHandle, &pData->pVMMDevRAMHC->fHaveEvents);
2039 // here be dragons (probably)
2040 SSMR3GetMem(pSSMHandle, &pData->pVMMDevRAMHC->V, sizeof (pData->pVMMDevRAMHC->V));
2041
2042 SSMR3GetMem(pSSMHandle, &pData->guestInfo, sizeof (pData->guestInfo));
2043 SSMR3GetU32(pSSMHandle, &pData->fu32AdditionsOk);
2044 SSMR3GetU32(pSSMHandle, &pData->u32VideoAccelEnabled);
2045
2046 SSMR3GetU32(pSSMHandle, &pData->guestCaps);
2047
2048 if ( SSM_VERSION_MAJOR(u32Version) > 0
2049 || SSM_VERSION_MINOR(u32Version) >= 7)
2050 {
2051 SSMR3GetU32(pSSMHandle, &pData->u32MaxGuestWidth);
2052 SSMR3GetU32(pSSMHandle, &pData->u32MaxGuestHeight);
2053 }
2054
2055#ifdef VBOX_HGCM
2056 vmmdevHGCMLoadState (pData, pSSMHandle);
2057#endif /* VBOX_HGCM */
2058
2059 /*
2060 * On a resume, we send the capabilities changed message so
2061 * that listeners can sync their state again
2062 */
2063 Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
2064 if (pData->pDrv)
2065 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
2066
2067 /* Reestablish the acceleration status. */
2068 if ( pData->u32VideoAccelEnabled
2069 && pData->pDrv)
2070 {
2071 pData->pDrv->pfnVideoAccelEnable (pData->pDrv, !!pData->u32VideoAccelEnabled, &pData->pVMMDevRAMHC->vbvaMemory);
2072 }
2073
2074 if (pData->fu32AdditionsOk)
2075 {
2076 LogRel(("Guest Additions information report: additionsVersion = 0x%08X, osType = 0x%08X\n",
2077 pData->guestInfo.additionsVersion,
2078 pData->guestInfo.osType));
2079 if (pData->pDrv)
2080 pData->pDrv->pfnUpdateGuestVersion(pData->pDrv, &pData->guestInfo);
2081 }
2082 if (pData->pDrv)
2083 pData->pDrv->pfnUpdateGuestCapabilities(pData->pDrv, pData->guestCaps);
2084
2085 if ( pData->pDrv && pData->pDrv->pfnUpdateMaxGuestResolution)
2086 pData->pDrv->pfnUpdateMaxGuestResolution(pData->pDrv, pData->u32MaxGuestWidth, pData->u32MaxGuestHeight);
2087
2088 return VINF_SUCCESS;
2089}
2090
2091/**
2092 * Load state done callback. Notify guest of restore event.
2093 *
2094 * @returns VBox status code.
2095 * @param pDevIns The device instance.
2096 * @param pSSMHandle The handle to the saved state.
2097 */
2098static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
2099{
2100 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
2101
2102#ifdef VBOX_HGCM
2103 vmmdevHGCMLoadStateDone (pData, pSSMHandle);
2104#endif /* VBOX_HGCM */
2105
2106 VMMDevNotifyGuest (pData, VMMDEV_EVENT_RESTORED);
2107
2108 return VINF_SUCCESS;
2109}
2110
2111/**
2112 * (Re-)initializes the MMIO2 data.
2113 *
2114 * @param pData Pointer to the VMMDev instance data.
2115 */
2116static void vmmdevInitRam(VMMDevState *pData)
2117{
2118 memset(pData->pVMMDevRAMHC, 0, sizeof(VMMDevMemory));
2119 pData->pVMMDevRAMHC->u32Size = sizeof(VMMDevMemory);
2120 pData->pVMMDevRAMHC->u32Version = VMMDEV_MEMORY_VERSION;
2121}
2122
2123/**
2124 * Construct a device instance for a VM.
2125 *
2126 * @returns VBox status.
2127 * @param pDevIns The device instance data.
2128 * If the registration structure is needed, pDevIns->pDevReg points to it.
2129 * @param iInstance Instance number. Use this to figure out which registers and such to use.
2130 * The device number is also found in pDevIns->iInstance, but since it's
2131 * likely to be freqently used PDM passes it as parameter.
2132 * @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
2133 * of the device instance. It's also found in pDevIns->pCfgHandle, but like
2134 * iInstance it's expected to be used a bit in this function.
2135 */
2136static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfgHandle)
2137{
2138 int rc;
2139 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState *);
2140
2141 Assert(iInstance == 0);
2142
2143 /*
2144 * Validate and read the configuration.
2145 */
2146 if (!CFGMR3AreValuesValid(pCfgHandle, "GetHostTimeDisabled\0BackdoorLogDisabled\0KeepCredentials\0"))
2147 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
2148
2149 rc = CFGMR3QueryBool(pCfgHandle, "GetHostTimeDisabled", &pData->fGetHostTimeDisabled);
2150 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
2151 pData->fGetHostTimeDisabled = false;
2152 else if (VBOX_FAILURE(rc))
2153 return PDMDEV_SET_ERROR(pDevIns, rc,
2154 N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
2155
2156 rc = CFGMR3QueryBool(pCfgHandle, "BackdoorLogDisabled", &pData->fBackdoorLogDisabled);
2157 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
2158 pData->fBackdoorLogDisabled = false;
2159 else if (VBOX_FAILURE(rc))
2160 return PDMDEV_SET_ERROR(pDevIns, rc,
2161 N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
2162
2163 rc = CFGMR3QueryBool(pCfgHandle, "KeepCredentials", &pData->fKeepCredentials);
2164 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
2165 pData->fKeepCredentials = false;
2166 else if (VBOX_FAILURE(rc))
2167 return PDMDEV_SET_ERROR(pDevIns, rc,
2168 N_("Configuration error: Failed querying \"KeepCredentials\" as a boolean"));
2169
2170 /*
2171 * Initialize data (most of it anyway).
2172 */
2173 /* Save PDM device instance data for future reference. */
2174 pData->pDevIns = pDevIns;
2175
2176 /* PCI vendor, just a free bogus value */
2177 pData->dev.config[0x00] = 0xee;
2178 pData->dev.config[0x01] = 0x80;
2179 /* device ID */
2180 pData->dev.config[0x02] = 0xfe;
2181 pData->dev.config[0x03] = 0xca;
2182 /* class sub code (other type of system peripheral) */
2183 pData->dev.config[0x0a] = 0x80;
2184 /* class base code (base system peripheral) */
2185 pData->dev.config[0x0b] = 0x08;
2186 /* header type */
2187 pData->dev.config[0x0e] = 0x00;
2188 /* interrupt on pin 0 */
2189 pData->dev.config[0x3d] = 0x01;
2190
2191 /*
2192 * Interfaces
2193 */
2194 /* Base */
2195 pData->Base.pfnQueryInterface = vmmdevPortQueryInterface;
2196
2197 /* VMMDev port */
2198 pData->Port.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
2199 pData->Port.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
2200 pData->Port.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
2201 pData->Port.pfnSetMouseCapabilities = vmmdevSetMouseCapabilities;
2202 pData->Port.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
2203 pData->Port.pfnSetCredentials = vmmdevSetCredentials;
2204 pData->Port.pfnVBVAChange = vmmdevVBVAChange;
2205 pData->Port.pfnRequestSeamlessChange = vmmdevRequestSeamlessChange;
2206 pData->Port.pfnSetMemoryBalloon = vmmdevSetMemoryBalloon;
2207 pData->Port.pfnSetStatisticsInterval = vmmdevSetStatisticsInterval;
2208 pData->Port.pfnVRDPChange = vmmdevVRDPChange;
2209
2210 /* Shared folder LED */
2211 pData->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
2212 pData->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
2213
2214#ifdef VBOX_HGCM
2215 /* HGCM port */
2216 pData->HGCMPort.pfnCompleted = hgcmCompleted;
2217#endif
2218
2219 /** @todo convert this into a config parameter like we do everywhere else.*/
2220 pData->cbGuestRAM = MMR3PhysGetRamSize(PDMDevHlpGetVM(pDevIns));
2221
2222 /*
2223 * Register the backdoor logging port
2224 */
2225 rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
2226 AssertRCReturn(rc, rc);
2227
2228#ifdef TIMESYNC_BACKDOOR
2229 /*
2230 * Alternative timesync source (temporary!)
2231 */
2232 rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
2233 AssertRCReturn(rc, rc);
2234#endif
2235
2236 /*
2237 * Allocate and initialize the MMIO2 memory.
2238 */
2239 rc = PDMDevHlpMMIO2Register(pDevIns, 1 /*iRegion*/, VMMDEV_RAM_SIZE, 0, (void **)&pData->pVMMDevRAMHC, "VMMDev");
2240 if (RT_FAILURE(rc))
2241 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
2242 N_("Failed to allocate %u bytes of memory for the VMM device"), VMMDEV_RAM_SIZE);
2243 vmmdevInitRam(pData);
2244
2245 /*
2246 * Register the PCI device.
2247 */
2248 rc = PDMDevHlpPCIRegister(pDevIns, &pData->dev);
2249 if (VBOX_FAILURE(rc))
2250 return rc;
2251 if (pData->dev.devfn == 32 || iInstance != 0)
2252 Log(("!!WARNING!!: pData->dev.devfn=%d (ignore if testcase or no started by Main)\n", pData->dev.devfn));
2253 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
2254 if (VBOX_FAILURE(rc))
2255 return rc;
2256 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
2257 if (VBOX_FAILURE(rc))
2258 return rc;
2259
2260 /*
2261 * Get the corresponding connector interface
2262 */
2263 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pData->Base, &pData->pDrvBase, "VMM Driver Port");
2264 if (VBOX_SUCCESS(rc))
2265 {
2266 pData->pDrv = (PPDMIVMMDEVCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_VMMDEV_CONNECTOR);
2267 if (!pData->pDrv)
2268 AssertMsgFailedReturn(("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
2269#ifdef VBOX_HGCM
2270 pData->pHGCMDrv = (PPDMIHGCMCONNECTOR)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_HGCM_CONNECTOR);
2271 if (!pData->pHGCMDrv)
2272 {
2273 Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Vrc\n", rc));
2274 /* this is not actually an error, just means that there is no support for HGCM */
2275 }
2276#endif
2277 }
2278 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
2279 {
2280 Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
2281 rc = VINF_SUCCESS;
2282 }
2283 else
2284 AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Vrc\n", rc), rc);
2285
2286 /*
2287 * Attach status driver for shared folders (optional).
2288 */
2289 PPDMIBASE pBase;
2290 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pData->Base, &pBase, "Status Port");
2291 if (VBOX_SUCCESS(rc))
2292 pData->SharedFolders.pLedsConnector = (PPDMILEDCONNECTORS)
2293 pBase->pfnQueryInterface(pBase, PDMINTERFACE_LED_CONNECTORS);
2294 else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
2295 {
2296 AssertMsgFailed(("Failed to attach to status driver. rc=%Vrc\n", rc));
2297 return rc;
2298 }
2299
2300 /*
2301 * Register saved state and init the HGCM CmdList critsect.
2302 */
2303 rc = PDMDevHlpSSMRegister(pDevIns, "VMMDev", iInstance, VMMDEV_SSM_VERSION, sizeof(*pData),
2304 NULL, vmmdevSaveState, NULL,
2305 NULL, vmmdevLoadState, vmmdevLoadStateDone);
2306 AssertRCReturn(rc, rc);
2307
2308#ifdef VBOX_HGCM
2309 pData->pHGCMCmdList = NULL;
2310 rc = RTCritSectInit(&pData->critsectHGCMCmdList);
2311 AssertRCReturn(rc, rc);
2312 pData->u32HGCMEnabled = 0;
2313#endif /* VBOX_HGCM */
2314
2315 return rc;
2316}
2317
2318/**
2319 * Reset notification.
2320 *
2321 * @returns VBox status.
2322 * @param pDrvIns The driver instance data.
2323 */
2324static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
2325{
2326 VMMDevState *pData = PDMINS2DATA(pDevIns, VMMDevState*);
2327 /*
2328 * Reset the mouse integration feature bit
2329 */
2330 if (pData->mouseCapabilities & (VMMDEV_MOUSEGUESTWANTSABS|VMMDEV_MOUSEGUESTNEEDSHOSTCUR))
2331 {
2332 pData->mouseCapabilities &= ~VMMDEV_MOUSEGUESTWANTSABS;
2333 /* notify the connector */
2334 Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pData->mouseCapabilities));
2335 pData->pDrv->pfnUpdateMouseCapabilities(pData->pDrv, pData->mouseCapabilities);
2336 }
2337
2338 pData->hypervisorSize = 0;
2339
2340 pData->u32HostEventFlags = 0;
2341
2342 /* re-initialize the VMMDev memory */
2343 if (pData->pVMMDevRAMHC)
2344 vmmdevInitRam(pData);
2345
2346 /* credentials have to go away (by default) */
2347 if (!pData->fKeepCredentials)
2348 {
2349 memset(pData->credentialsLogon.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
2350 memset(pData->credentialsLogon.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
2351 memset(pData->credentialsLogon.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
2352 }
2353 memset(pData->credentialsJudge.szUserName, '\0', VMMDEV_CREDENTIALS_STRLEN);
2354 memset(pData->credentialsJudge.szPassword, '\0', VMMDEV_CREDENTIALS_STRLEN);
2355 memset(pData->credentialsJudge.szDomain, '\0', VMMDEV_CREDENTIALS_STRLEN);
2356
2357 /* Reset means that additions will report again. */
2358 pData->fu32AdditionsOk = false;
2359 memset (&pData->guestInfo, 0, sizeof (pData->guestInfo));
2360
2361 /* No maximum resolution specified yet */
2362 pData->u32MaxGuestWidth = 0;
2363 pData->u32MaxGuestHeight = 0;
2364
2365 memset (&pData->lastReadDisplayChangeRequest, 0, sizeof (pData->lastReadDisplayChangeRequest));
2366
2367 /* disable seamless mode */
2368 pData->fLastSeamlessEnabled = false;
2369
2370 /* disabled memory ballooning */
2371 pData->u32LastMemoryBalloonSize = 0;
2372
2373 /* disabled statistics updating */
2374 pData->u32LastStatIntervalSize = 0;
2375
2376 /* Clear the event variables.
2377 *
2378 * Note: The pData->u32HostEventFlags is not cleared.
2379 * It is designed that way so host events do not
2380 * depend on guest resets.
2381 */
2382 pData->u32GuestFilterMask = 0;
2383 pData->u32NewGuestFilterMask = 0;
2384 pData->fNewGuestFilterMask = 0;
2385
2386 /* This is the default, as Windows and OS/2 guests take this for granted. */
2387 /** @todo change this when we next bump the interface version */
2388 pData->guestCaps = VMMDEV_GUEST_SUPPORTS_GRAPHICS;
2389 pData->pDrv->pfnUpdateGuestCapabilities(pData->pDrv, pData->guestCaps);
2390}
2391
2392
2393/**
2394 * The device registration structure.
2395 */
2396extern "C" const PDMDEVREG g_DeviceVMMDev =
2397{
2398 /* u32Version */
2399 PDM_DEVREG_VERSION,
2400 /* szDeviceName */
2401 "VMMDev",
2402 /* szGCMod */
2403 "",
2404 /* szR0Mod */
2405 "",
2406 /* pszDescription */
2407 "VirtualBox VMM Device\n",
2408 /* fFlags */
2409 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32,
2410 /* fClass */
2411 PDM_DEVREG_CLASS_VMM_DEV,
2412 /* cMaxInstances */
2413 1,
2414 /* cbInstance */
2415 sizeof(VMMDevState),
2416 /* pfnConstruct */
2417 vmmdevConstruct,
2418 /* pfnDestruct */
2419 NULL,
2420 /* pfnRelocate */
2421 NULL,
2422 /* pfnIOCtl */
2423 NULL,
2424 /* pfnPowerOn */
2425 NULL,
2426 /* pfnReset */
2427 vmmdevReset,
2428 /* pfnSuspend */
2429 NULL,
2430 /* pfnResume */
2431 NULL,
2432 /* pfnAttach */
2433 NULL,
2434 /* pfnDetach */
2435 NULL,
2436 /* pfnQueryInterface. */
2437 NULL
2438};
2439#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
2440
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