VMMDevInterface.cpp revision 02408b6eb88b972d00f66fad1831cf57db55d619
/* $Id$ */
/** @file
* VirtualBox Driver Interface to VMM device.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "VMMDev.h"
#include "ConsoleImpl.h"
#include "DisplayImpl.h"
#include "GuestImpl.h"
#include "MouseImpl.h"
#include "Logging.h"
#ifdef VBOX_WITH_HGCM
# include "HGCM.h"
# include "HGCMObjects.h"
# if defined(RT_OS_DARWIN) && defined(VBOX_WITH_CROGL)
# endif
#endif
//
// defines
//
#ifdef RT_OS_OS2
# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
#else
# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
#endif
//
// globals
//
/**
* VMMDev driver instance data.
*/
typedef struct DRVMAINVMMDEV
{
/** Pointer to the VMMDev object. */
/** Pointer to the driver instance structure. */
/** Our VMM device connector interface. */
#ifdef VBOX_WITH_HGCM
/** Our HGCM connector interface. */
#endif
//
// constructor / destructor
//
{
#ifdef VBOX_WITH_HGCM
rc = HGCMHostInit ();
m_fHGCMActive = true;
#endif /* VBOX_WITH_HGCM */
mu32CredentialsFlags = 0;
}
{
#ifdef VBOX_WITH_HGCM
if (hgcmIsActive())
{
ASMAtomicWriteBool(&m_fHGCMActive, false);
}
#endif /* VBOX_WITH_HGCM */
if (mpDrv)
}
{
if (!mpDrv)
return NULL;
}
//
// public methods
//
/**
* Wait on event semaphore for guest credential judgement result.
*/
{
if (u32Timeout == 0)
{
u32Timeout = 5000;
}
if (RT_SUCCESS(rc))
{
}
return rc;
}
{
return rc;
}
/**
* @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestStatus}
*/
DECLCALLBACK(void) vmmdevUpdateGuestStatus(PPDMIVMMDEVCONNECTOR pInterface, uint32_t uFacility, uint16_t uStatus,
{
/* Store that information in IGuest */
guest->setAdditionsStatus((VBoxGuestFacilityType)uFacility, (VBoxGuestFacilityStatus)uStatus, fFlags, pTimeSpecTS);
}
/**
* @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestUserState}
*/
{
/* Store that information in IGuest. */
}
/**
* Reports Guest Additions API and OS version.
*
* Called whenever the Additions issue a guest version report request or the VM
* is reset.
*
* @param pInterface Pointer to this interface.
* @param guestInfo Pointer to guest information structure.
* @thread The emulation thread.
*/
DECLCALLBACK(void) vmmdevUpdateGuestInfo(PPDMIVMMDEVCONNECTOR pInterface, const VBoxGuestInfo *guestInfo)
{
/* Store that information in IGuest */
if (guestInfo->interfaceVersion != 0)
{
char version[16];
/*
* Tell the console interface about the event
* so that it can notify its consumers.
*/
}
else
{
/*
* The guest additions was disabled because of a reset
* or driver unload.
*/
/** @todo Would be better if GuestImpl.cpp did all this in the above method call
* while holding down the. */
guest->setAdditionsStatus(VBoxGuestFacilityType_All, VBoxGuestFacilityStatus_Inactive, 0 /*fFlags*/, &TimeSpecTS);
}
}
/**
* @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestInfo2}
*/
{
/* Store that information in IGuest. */
/* Just pass it on... */
/*
* No need to tell the console interface about the update;
* vmmdevUpdateGuestInfo takes care of that when called as the
* last event in the chain.
*/
}
/**
* Update the guest additions capabilities.
* This is called when the guest additions capabilities change. The new capabilities
* are given and the connector should update its internal state.
*
* @param pInterface Pointer to this interface.
* @param newCapabilities New capabilities.
* @thread The emulation thread.
*/
DECLCALLBACK(void) vmmdevUpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
{
/* store that information in IGuest */
/*
* Report our current capabilities (and assume none is active yet).
*/
/*
* Tell the console interface about the event
* so that it can notify its consumers.
*/
}
/**
* Update the mouse capabilities.
* This is called when the mouse capabilities change. The new capabilities
* are given and the connector should update its internal state.
*
* @param pInterface Pointer to this interface.
* @param newCapabilities New capabilities.
* @thread The emulation thread.
*/
DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t fNewCaps)
{
/*
* Tell the console interface about the event
* so that it can notify its consumers.
*/
if (pMouse) /** @todo and if not? Can that actually happen? */
}
/**
* Update the pointer shape or visibility.
*
* This is called when the mouse pointer shape changes or pointer is hidden/displaying.
* The new shape is passed as a caller allocated buffer that will be freed after returning.
*
* @param pInterface Pointer to this interface.
* @param fVisible Whether the pointer is visible or not.
* @param fAlpha Alpha channel information is present.
* @param xHot Horizontal coordinate of the pointer hot spot.
* @param yHot Vertical coordinate of the pointer hot spot.
* @param width Pointer width in pixels.
* @param height Pointer height in pixels.
* @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
* @thread The emulation thread.
*/
DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
void *pShape)
{
/* tell the console about it */
size_t cbShapeSize = 0;
if (pShape)
{
}
if (pShape)
pConsole->i_onMousePointerShapeChange(fVisible, fAlpha, xHot, yHot, width, height, ComSafeArrayAsInParam(shapeData));
}
DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
{
if (display)
{
}
return VERR_NOT_SUPPORTED;
}
{
if (display)
{
LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
display->VideoAccelFlush ();
}
}
DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
{
if (!fSupported)
return VERR_INVALID_PARAMETER;
#ifdef DEBUG_sunlover
#endif
{
framebuffer->Release();
}
else
{
#ifdef DEBUG_sunlover
#endif
*fSupported = true;
}
return VINF_SUCCESS;
}
DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
{
if (!heightReduction)
return VERR_INVALID_PARAMETER;
{
framebuffer->Release();
}
else
*heightReduction = 0;
return VINF_SUCCESS;
}
DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
{
return VERR_GENERAL_FAILURE;
}
DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
{
/* Forward to Display, which calls corresponding framebuffers. */
return VINF_SUCCESS;
}
DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
{
/* Forward to Display, which calls corresponding framebuffers. */
return VINF_SUCCESS;
}
/**
* Request the statistics interval
*
* @returns VBox status code.
* @param pInterface Pointer to this interface.
* @param pulInterval Pointer to interval in seconds
* @thread The emulation thread.
*/
DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
{
if (!pulInterval)
return VERR_INVALID_POINTER;
/* store that information in IGuest */
*pulInterval = val;
return VINF_SUCCESS;
}
/**
* Query the current balloon size
*
* @returns VBox status code.
* @param pInterface Pointer to this interface.
* @param pcbBalloon Balloon size
* @thread The emulation thread.
*/
{
if (!pcbBalloon)
return VERR_INVALID_POINTER;
/* store that information in IGuest */
*pcbBalloon = val;
return VINF_SUCCESS;
}
/**
* Query the current page fusion setting
*
* @returns VBox status code.
* @param pInterface Pointer to this interface.
* @param pfPageFusionEnabled Pointer to boolean
* @thread The emulation thread.
*/
DECLCALLBACK(int) vmmdevIsPageFusionEnabled(PPDMIVMMDEVCONNECTOR pInterface, bool *pfPageFusionEnabled)
{
if (!pfPageFusionEnabled)
return VERR_INVALID_POINTER;
/* store that information in IGuest */
return VINF_SUCCESS;
}
/**
* Report new guest statistics
*
* @returns VBox status code.
* @param pInterface Pointer to this interface.
* @param pGuestStats Guest statistics
* @thread The emulation thread.
*/
DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
{
/* store that information in IGuest */
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
/** @todo r=bird: Convert from 4KB to 1KB units?
* CollectorGuestHAL::i_getGuestMemLoad says it returns KB units to
* preCollect(). I might be wrong ofc, this is convoluted code... */
guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
return VINF_SUCCESS;
}
#ifdef VBOX_WITH_HGCM
/* HGCM connector interface */
{
LogSunlover(("Enter\n"));
if ( !pServiceLocation
{
return VERR_INVALID_PARAMETER;
}
return VERR_INVALID_STATE;
}
static DECLCALLBACK(int) iface_hgcmDisconnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
{
LogSunlover(("Enter\n"));
return VERR_INVALID_STATE;
}
static DECLCALLBACK(int) iface_hgcmCall(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID,
{
LogSunlover(("Enter\n"));
return VERR_INVALID_STATE;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
LogSunlover(("Enter\n"));
return HGCMHostSaveState(pSSM);
}
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
* @param uVersion Data layout version.
* @param uPass The data pass.
*/
static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
{
LogFlowFunc(("Enter\n"));
if (uVersion != HGCM_SSM_VERSION)
return HGCMHostLoadState(pSSM);
}
{
if (!hgcmIsActive())
return VERR_INVALID_STATE;
}
{
if (!hgcmIsActive())
return VERR_INVALID_STATE;
}
void VMMDev::hgcmShutdown(void)
{
ASMAtomicWriteBool(&m_fHGCMActive, false);
}
# ifdef VBOX_WITH_CRHGSMI
{
if (!hgcmIsActive())
return VERR_INVALID_STATE;
}
{
if (!hgcmIsActive())
return VERR_INVALID_STATE;
return HGCMHostSvcHandleDestroy(hSvc);
}
{
if (!hgcmIsActive())
return VERR_INVALID_STATE;
}
# endif
#endif /* HGCM */
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
{
#ifdef VBOX_WITH_HGCM
#endif
return NULL;
}
/**
* @interface_method_impl{PDMDRVREG,pfnReset}
*/
{
#ifdef VBOX_WITH_HGCM
HGCMHostReset ();
#endif /* VBOX_WITH_HGCM */
}
/**
* @interface_method_impl{PDMDRVREG,pfnDestruct}
*/
{
#ifdef VBOX_WITH_HGCM
/* HGCM is shut down on the VMMDev destructor. */
#endif /* VBOX_WITH_HGCM */
}
/**
* @interface_method_impl{PDMDRVREG,pfnConstruct}
*/
{
/*
* Validate configuration.
*/
("Configuration error: Not possible to attach anything to this driver!\n"),
/*
* IBase.
*/
#ifdef VBOX_WITH_HGCM
#endif
/*
*/
AssertMsgReturn(pThis->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
#ifdef VBOX_WITH_HGCM
AssertMsgReturn(pThis->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
#endif
/*
* Get the Console object pointer and update the mpDrv member.
*/
void *pv;
if (RT_FAILURE(rc))
{
return rc;
}
#ifdef VBOX_WITH_HGCM
"VBoxSharedFolders");
if (RT_SUCCESS(rc))
{
LogRel(("Shared Folders service loaded\n"));
AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
{
}
else
}
else
if (RT_FAILURE(rc))
return rc;
#endif /* VBOX_WITH_HGCM */
return VINF_SUCCESS;
}
/**
* VMMDevice driver registration record.
*/
{
/* u32Version */
/* szName */
"HGCM",
/* szRCMod */
"",
/* szR0Mod */
"",
/* pszDescription */
"Main VMMDev driver (Main as in the API).",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0U,
/* cbInstance */
sizeof(DRVMAINVMMDEV),
/* pfnConstruct */
/* pfnDestruct */
/* pfnRelocate */
NULL,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32EndVersion */
};
/* vi: set tabstop=4 shiftwidth=4 expandtab: */