VirtualBox

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

Last change on this file since 21644 was 21644, checked in by vboxsync, 15 years ago

Register guest allocated memory (locked & executable) for patching purposes.

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