1
/* $Id: VMMDevInterface.cpp $ */
3
* VirtualBox Driver Interface to VMM device.
7
* Copyright (C) 2006-2010 Oracle Corporation
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.
19
#include "ConsoleImpl.h"
20
#include "DisplayImpl.h"
21
#include "GuestImpl.h"
22
#include "MouseImpl.h"
26
#include <VBox/pdmdrv.h>
27
#include <VBox/VMMDev.h>
28
#include <VBox/shflsvc.h>
32
#include "hgcm/HGCM.h"
33
#include "hgcm/HGCMObjects.h"
34
# if defined(RT_OS_DARWIN) && defined(VBOX_WITH_CROGL)
35
# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
44
# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
46
# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
55
* VMMDev driver instance data.
57
typedef struct DRVMAINVMMDEV
59
/** Pointer to the VMMDev object. */
61
/** Pointer to the driver instance structure. */
63
/** Pointer to the VMMDev port interface of the driver/device above us. */
64
PPDMIVMMDEVPORT pUpPort;
65
/** Our VMM device connector interface. */
66
PDMIVMMDEVCONNECTOR Connector;
69
/** Pointer to the HGCM port interface of the driver/device above us. */
70
PPDMIHGCMPORT pHGCMPort;
71
/** Our HGCM connector interface. */
72
PDMIHGCMCONNECTOR HGCMConnector;
74
} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
76
/** Converts PDMIVMMDEVCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
77
#define PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, Connector)) )
80
/** Converts PDMIHGCMCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
81
#define PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, HGCMConnector)) )
85
// constructor / destructor
87
VMMDev::VMMDev(Console *console)
91
int rc = RTSemEventCreate(&mCredentialsEvent);
97
#endif /* VBOX_WITH_HGCM */
98
mu32CredentialsFlags = 0;
103
#ifdef VBOX_WITH_HGCM
106
ASMAtomicWriteBool(&m_fHGCMActive, false);
109
#endif /* VBOX_WITH_HGCM */
110
RTSemEventDestroy (mCredentialsEvent);
112
mpDrv->pVMMDev = NULL;
116
PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
118
AssertReturn(mpDrv, NULL);
119
return mpDrv->pUpPort;
129
* Wait on event semaphore for guest credential judgement result.
131
int VMMDev::WaitCredentialsJudgement(uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
138
int rc = RTSemEventWait (mCredentialsEvent, u32Timeout);
142
*pu32CredentialsFlags = mu32CredentialsFlags;
148
int VMMDev::SetCredentialsJudgementResult(uint32_t u32Flags)
150
mu32CredentialsFlags = u32Flags;
152
int rc = RTSemEventSignal (mCredentialsEvent);
160
* Reports Guest Additions status.
161
* Called whenever the Additions issue a guest status report request or the VM is reset.
163
* @param pInterface Pointer to this interface.
164
* @param guestInfo Pointer to guest information structure
165
* @thread The emulation thread.
167
DECLCALLBACK(void) vmmdevUpdateGuestStatus(PPDMIVMMDEVCONNECTOR pInterface, const VBoxGuestStatus *guestStatus)
169
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
175
Console *pConsole = pDrv->pVMMDev->getParent();
177
/* Store that information in IGuest */
178
Guest* guest = pConsole->getGuest();
183
guest->setAdditionsStatus((VBoxGuestStatusFacility)guestStatus->facility,
184
(VBoxGuestStatusCurrent)guestStatus->status,
186
pConsole->onAdditionsStateChange();
191
* Reports Guest Additions API and OS version.
192
* Called whenever the Additions issue a guest version report request or the VM is reset.
194
* @param pInterface Pointer to this interface.
195
* @param guestInfo Pointer to guest information structure
196
* @thread The emulation thread.
198
DECLCALLBACK(void) vmmdevUpdateGuestInfo(PPDMIVMMDEVCONNECTOR pInterface, const VBoxGuestInfo *guestInfo)
200
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
206
Console *pConsole = pDrv->pVMMDev->getParent();
208
/* Store that information in IGuest */
209
Guest* guest = pConsole->getGuest();
214
if (guestInfo->additionsVersion != 0)
217
RTStrPrintf(version, sizeof(version), "%d", guestInfo->additionsVersion);
218
guest->setAdditionsInfo(Bstr(version), guestInfo->osType);
221
* Tell the console interface about the event
222
* so that it can notify its consumers.
224
pConsole->onAdditionsStateChange();
226
if (guestInfo->additionsVersion < VMMDEV_VERSION)
227
pConsole->onAdditionsOutdated();
232
* The guest additions was disabled because of a reset
235
guest->setAdditionsInfo(Bstr(), guestInfo->osType);
236
guest->setAdditionsStatus(VBoxGuestStatusFacility_Unknown,
237
VBoxGuestStatusCurrent_Disabled,
238
0); /* Flags; not used. */
239
pConsole->onAdditionsStateChange();
244
* Update the guest additions capabilities.
245
* This is called when the guest additions capabilities change. The new capabilities
246
* are given and the connector should update its internal state.
248
* @param pInterface Pointer to this interface.
249
* @param newCapabilities New capabilities.
250
* @thread The emulation thread.
252
DECLCALLBACK(void) vmmdevUpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
254
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
255
Console *pConsole = pDrv->pVMMDev->getParent();
257
/* store that information in IGuest */
258
Guest* guest = pConsole->getGuest();
264
* Report our current capabilites (and assume none is active yet).
266
guest->setSupportedFeatures((ULONG64)newCapabilities, 0 /* Active capabilities, not used here. */);
269
* Tell the console interface about the event
270
* so that it can notify its consumers.
272
pConsole->onAdditionsStateChange();
277
* Update the mouse capabilities.
278
* This is called when the mouse capabilities change. The new capabilities
279
* are given and the connector should update its internal state.
281
* @param pInterface Pointer to this interface.
282
* @param newCapabilities New capabilities.
283
* @thread The emulation thread.
285
DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
287
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
288
Console *pConsole = pDrv->pVMMDev->getParent();
291
* Tell the console interface about the event
292
* so that it can notify its consumers.
294
Mouse *pMouse = pConsole->getMouse();
295
if (pMouse) /** @todo and if not? Can that actually happen? */
297
pMouse->onVMMDevCanAbsChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE));
298
pMouse->onVMMDevNeedsHostChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR));
304
* Update the pointer shape or visibility.
306
* This is called when the mouse pointer shape changes or pointer is hidden/displaying.
307
* The new shape is passed as a caller allocated buffer that will be freed after returning.
309
* @param pInterface Pointer to this interface.
310
* @param fVisible Whether the pointer is visible or not.
311
* @param fAlpha Alpha channel information is present.
312
* @param xHot Horizontal coordinate of the pointer hot spot.
313
* @param yHot Vertical coordinate of the pointer hot spot.
314
* @param width Pointer width in pixels.
315
* @param height Pointer height in pixels.
316
* @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
317
* @thread The emulation thread.
319
DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
320
uint32_t xHot, uint32_t yHot,
321
uint32_t width, uint32_t height,
324
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
325
Console *pConsole = pDrv->pVMMDev->getParent();
327
/* tell the console about it */
328
size_t cbShapeSize = 0;
332
cbShapeSize = (width + 7) / 8 * height; /* size of the AND mask */
333
cbShapeSize = ((cbShapeSize + 3) & ~3) + width * 4 * height; /* + gap + size of the XOR mask */
335
com::SafeArray<BYTE> shapeData(cbShapeSize);
337
::memcpy(shapeData.raw(), pShape, cbShapeSize);
338
pConsole->onMousePointerShapeChange(fVisible, fAlpha, xHot, yHot, width, height, ComSafeArrayAsInParam(shapeData));
341
DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
343
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
344
Console *pConsole = pDrv->pVMMDev->getParent();
346
Display *display = pConsole->getDisplay();
350
LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
351
return display->VideoAccelEnable(fEnable, pVbvaMemory);
354
return VERR_NOT_SUPPORTED;
356
DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
358
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
359
Console *pConsole = pDrv->pVMMDev->getParent();
361
Display *display = pConsole->getDisplay();
365
LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
366
display->VideoAccelFlush ();
370
DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
371
uint32_t bpp, bool *fSupported)
373
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
374
Console *pConsole = pDrv->pVMMDev->getParent();
377
return VERR_INVALID_PARAMETER;
378
#ifdef DEBUG_sunlover
379
Log(("vmmdevVideoModeSupported: [%d]: %dx%dx%d\n", display, width, height, bpp));
381
IFramebuffer *framebuffer = NULL;
384
HRESULT hrc = pConsole->getDisplay()->GetFramebuffer(display, &framebuffer, &xOrigin, &yOrigin);
385
if (SUCCEEDED(hrc) && framebuffer)
387
framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
388
framebuffer->Release();
392
#ifdef DEBUG_sunlover
393
Log(("vmmdevVideoModeSupported: hrc %x, framebuffer %p!!!\n", hrc, framebuffer));
400
DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
402
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
403
Console *pConsole = pDrv->pVMMDev->getParent();
405
if (!heightReduction)
406
return VERR_INVALID_PARAMETER;
407
IFramebuffer *framebuffer = pConsole->getDisplay()->getFramebuffer();
409
framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
411
*heightReduction = 0;
415
DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
417
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
420
return pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
422
return VERR_GENERAL_FAILURE;
425
DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
427
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
428
Console *pConsole = pDrv->pVMMDev->getParent();
431
return VERR_INVALID_PARAMETER;
433
/* Forward to Display, which calls corresponding framebuffers. */
434
pConsole->getDisplay()->handleSetVisibleRegion(cRect, pRect);
436
IFramebuffer *framebuffer = pConsole->getDisplay()->getFramebuffer();
439
framebuffer->SetVisibleRegion((BYTE *)pRect, cRect);
440
#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
444
pConsole->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
448
VBOXHGCMSVCPARM parms[2];
450
parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
451
parms[0].u.pointer.addr = pRect;
452
parms[0].u.pointer.size = 0; /* We don't actually care. */
453
parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
454
parms[1].u.uint32 = cRect;
457
return pDrv->pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
467
DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
469
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
470
Console *pConsole = pDrv->pVMMDev->getParent();
473
/* Forward to Display, which calls corresponding framebuffers. */
474
pConsole->getDisplay()->handleQueryVisibleRegion(pcRect, pRect);
476
IFramebuffer *framebuffer = pConsole->getDisplay()->getFramebuffer();
480
framebuffer->GetVisibleRegion((BYTE *)pRect, cRect, &cRect);
490
* Request the statistics interval
492
* @returns VBox status code.
493
* @param pInterface Pointer to this interface.
494
* @param pulInterval Pointer to interval in seconds
495
* @thread The emulation thread.
497
DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
499
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
500
Console *pConsole = pDrv->pVMMDev->getParent();
504
return VERR_INVALID_POINTER;
506
/* store that information in IGuest */
507
Guest* guest = pConsole->getGuest();
510
return VERR_GENERAL_FAILURE;
512
guest->COMGETTER(StatisticsUpdateInterval)(&val);
518
* Query the current balloon size
520
* @returns VBox status code.
521
* @param pInterface Pointer to this interface.
522
* @param pcbBalloon Balloon size
523
* @thread The emulation thread.
525
DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
527
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
528
Console *pConsole = pDrv->pVMMDev->getParent();
532
return VERR_INVALID_POINTER;
534
/* store that information in IGuest */
535
Guest* guest = pConsole->getGuest();
538
return VERR_GENERAL_FAILURE;
540
guest->COMGETTER(MemoryBalloonSize)(&val);
546
* Query the current page fusion setting
548
* @returns VBox status code.
549
* @param pInterface Pointer to this interface.
550
* @param pfPageFusionEnabled Pointer to boolean
551
* @thread The emulation thread.
553
DECLCALLBACK(int) vmmdevIsPageFusionEnabled(PPDMIVMMDEVCONNECTOR pInterface, bool *pfPageFusionEnabled)
555
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
556
Console *pConsole = pDrv->pVMMDev->getParent();
559
if (!pfPageFusionEnabled)
560
return VERR_INVALID_POINTER;
562
/* store that information in IGuest */
563
Guest* guest = pConsole->getGuest();
566
return VERR_GENERAL_FAILURE;
568
guest->COMGETTER(PageFusionEnabled)(&val);
569
*pfPageFusionEnabled = !!val;
574
* Report new guest statistics
576
* @returns VBox status code.
577
* @param pInterface Pointer to this interface.
578
* @param pGuestStats Guest statistics
579
* @thread The emulation thread.
581
DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
583
PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
584
Console *pConsole = pDrv->pVMMDev->getParent();
588
return VERR_INVALID_POINTER;
590
/* store that information in IGuest */
591
Guest* guest = pConsole->getGuest();
594
return VERR_GENERAL_FAILURE;
596
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
597
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
599
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
600
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
602
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
603
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
606
/** @todo r=bird: Convert from 4KB to 1KB units?
607
* CollectorGuestHAL::getGuestMemLoad says it returns KB units to
608
* preCollect(). I might be wrong ofc, this is convoluted code... */
609
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
610
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
612
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
613
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
615
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
616
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
618
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
619
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
621
if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
622
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
627
#ifdef VBOX_WITH_HGCM
629
/* HGCM connector interface */
631
static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
633
LogSunlover(("Enter\n"));
635
PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
637
if ( !pServiceLocation
638
|| ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
639
&& pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
641
return VERR_INVALID_PARAMETER;
644
if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
645
return VERR_INVALID_STATE;
647
return HGCMGuestConnect(pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
650
static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
652
LogSunlover(("Enter\n"));
654
PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
656
if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
657
return VERR_INVALID_STATE;
659
return HGCMGuestDisconnect(pDrv->pHGCMPort, pCmd, u32ClientID);
662
static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
663
uint32_t cParms, PVBOXHGCMSVCPARM paParms)
665
LogSunlover(("Enter\n"));
667
PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
669
if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
670
return VERR_INVALID_STATE;
672
return HGCMGuestCall(pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
676
* Execute state save operation.
678
* @returns VBox status code.
679
* @param pDrvIns Driver instance of the driver which registered the data unit.
680
* @param pSSM SSM operation handle.
682
static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
684
LogSunlover(("Enter\n"));
685
return HGCMHostSaveState(pSSM);
690
* Execute state load operation.
692
* @returns VBox status code.
693
* @param pDrvIns Driver instance of the driver which registered the data unit.
694
* @param pSSM SSM operation handle.
695
* @param uVersion Data layout version.
696
* @param uPass The data pass.
698
static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
700
LogFlowFunc(("Enter\n"));
702
if (uVersion != HGCM_SSM_VERSION)
703
return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
704
Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
706
return HGCMHostLoadState(pSSM);
709
int VMMDev::hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName)
712
return VERR_INVALID_STATE;
714
return HGCMHostLoad(pszServiceLibrary, pszServiceName);
717
int VMMDev::hgcmHostCall(const char *pszServiceName, uint32_t u32Function,
718
uint32_t cParms, PVBOXHGCMSVCPARM paParms)
721
return VERR_INVALID_STATE;
722
return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
725
void VMMDev::hgcmShutdown(void)
727
ASMAtomicWriteBool(&m_fHGCMActive, false);
735
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
737
DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
739
PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
740
PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
742
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
743
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
744
#ifdef VBOX_WITH_HGCM
745
PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
751
* Destruct a VMMDev driver instance.
753
* @returns VBox status.
754
* @param pDrvIns The driver instance data.
756
DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
758
PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
759
LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
760
#ifdef VBOX_WITH_HGCM
761
/* HGCM is shut down on the VMMDev destructor. */
762
#endif /* VBOX_WITH_HGCM */
764
pData->pVMMDev->mpDrv = NULL;
768
* Reset notification.
770
* @returns VBox status.
771
* @param pDrvIns The driver instance data.
773
DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
775
LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
776
#ifdef VBOX_WITH_HGCM
778
#endif /* VBOX_WITH_HGCM */
782
* Construct a VMMDev driver instance.
784
* @copydoc FNPDMDRVCONSTRUCT
786
DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
788
PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
789
LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
792
* Validate configuration.
794
if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
795
return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
796
AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
797
("Configuration error: Not possible to attach anything to this driver!\n"),
798
VERR_PDM_DRVINS_NO_ATTACH);
803
pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
805
pData->Connector.pfnUpdateGuestStatus = vmmdevUpdateGuestStatus;
806
pData->Connector.pfnUpdateGuestInfo = vmmdevUpdateGuestInfo;
807
pData->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
808
pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
809
pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
810
pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
811
pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
812
pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
813
pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
814
pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
815
pData->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
816
pData->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
817
pData->Connector.pfnReportStatistics = vmmdevReportStatistics;
818
pData->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
819
pData->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
820
pData->Connector.pfnIsPageFusionEnabled = vmmdevIsPageFusionEnabled;
822
#ifdef VBOX_WITH_HGCM
823
pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
824
pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
825
pData->HGCMConnector.pfnCall = iface_hgcmCall;
829
* Get the IVMMDevPort interface of the above driver/device.
831
pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
832
AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
834
#ifdef VBOX_WITH_HGCM
835
pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
836
AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
840
* Get the Console object pointer and update the mpDrv member.
843
int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
846
AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
850
pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
851
pData->pVMMDev->mpDrv = pData;
853
#ifdef VBOX_WITH_HGCM
854
rc = pData->pVMMDev->hgcmLoadService(VBOXSHAREDFOLDERS_DLL,
855
"VBoxSharedFolders");
856
pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
860
PPDMILEDPORTS pLedPort;
862
LogRel(("Shared Folders service loaded.\n"));
863
pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
864
AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
865
rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
866
if (RT_SUCCESS(rc) && pLed)
868
VBOXHGCMSVCPARM parm;
870
parm.type = VBOX_HGCM_SVC_PARM_PTR;
871
parm.u.pointer.addr = pLed;
872
parm.u.pointer.size = sizeof(*pLed);
874
rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
877
AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
880
LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
882
rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
884
NULL, iface_hgcmSave, NULL,
885
NULL, iface_hgcmLoad, NULL);
889
#endif /* VBOX_WITH_HGCM */
896
* VMMDevice driver registration record.
898
const PDMDRVREG VMMDev::DrvReg =
909
"Main VMMDev driver (Main as in the API).",
911
PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
913
PDM_DRVREG_CLASS_VMMDEV,
917
sizeof(DRVMAINVMMDEV),
919
VMMDev::drvConstruct,
945
/* vi: set tabstop=4 shiftwidth=4 expandtab: */