VMMDevInterface.cpp revision cc766b66f7a660b01aca8fddb36e84327c8f2e07
/** @file
*
* VirtualBox Driver Interface to VMM device
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "VMMDev.h"
#include "ConsoleImpl.h"
#include "DisplayImpl.h"
#include "GuestImpl.h"
#include "Logging.h"
#include <VBox/VBoxGuest.h>
#ifdef VBOX_WITH_HGCM
#include "hgcm/HGCMObjects.h"
#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
/** Converts PDMIVMMDEVCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
#define PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, Connector)) )
#ifdef VBOX_WITH_HGCM
/** Converts PDMIHGCMCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
#define PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, HGCMConnector)) )
#endif
//
// constructor / destructor
//
{
#ifdef VBOX_WITH_HGCM
rc = HGCMHostInit ();
m_fHGCMActive = true;
#endif /* VBOX_WITH_HGCM */
mu32CredentialsFlags = 0;
}
{
if (mpDrv)
}
{
}
//
// public methods
//
/**
* Wait on event semaphore for guest credential judgement result.
*/
{
if (u32Timeout == 0)
{
u32Timeout = 5000;
}
if (RT_SUCCESS (rc))
{
}
return rc;
}
{
return rc;
}
/**
* Report guest 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) vmmdevUpdateGuestVersion(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestInfo *guestInfo)
{
if (!guestInfo)
return;
/* store that information in IGuest */
if (!guest)
return;
if (guestInfo->additionsVersion != 0)
{
char version[20];
/*
* 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.
*/
}
}
/**
* 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 */
if (!guest)
return;
/*
* 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 newCapabilities)
{
/*
* Tell the console interface about the event
* so that it can notify its consumers.
*/
pDrv->pVMMDev->getParent()->onMouseCapabilityChange(BOOL (newCapabilities & VMMDEV_MOUSEGUESTWANTSABS),
}
/**
* 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 */
}
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 width, uint32_t height,
{
if (!fSupported)
return VERR_INVALID_PARAMETER;
if (framebuffer)
else
*fSupported = true;
return VINF_SUCCESS;
}
DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
{
if (!heightReduction)
return VERR_INVALID_PARAMETER;
if (framebuffer)
else
*heightReduction = 0;
return VINF_SUCCESS;
}
DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
{
return rc;
}
DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
{
if (!cRect)
return VERR_INVALID_PARAMETER;
if (framebuffer)
return VINF_SUCCESS;
}
DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
{
if (framebuffer)
{
}
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 */
if (!guest)
return VERR_INVALID_PARAMETER; /** @todo wrong error */
*pulInterval = val;
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)
{
if (!pGuestStats)
return VERR_INVALID_POINTER;
/* store that information in IGuest */
if (!guest)
return VERR_INVALID_PARAMETER; /** @todo wrong error */
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_CPULoad_Idle, pGuestStats->u32CpuLoad_Idle);
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_CPULoad_Kernel, pGuestStats->u32CpuLoad_Kernel);
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_CPULoad_User, pGuestStats->u32CpuLoad_User);
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_Processes, pGuestStats->u32Processes);
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemoryLoad, pGuestStats->u32MemoryLoad);
/* Note that reported values are in pages; upper layers expect them in megabytes */
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PhysMemTotal, (pGuestStats->u32PhysMemTotal + (_1M/pGuestStats->u32PageSize)-1) / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PhysMemAvailable, pGuestStats->u32PhysMemAvail / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PhysMemBalloon, pGuestStats->u32PhysMemBalloon / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemCommitTotal, pGuestStats->u32MemCommitTotal / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemKernelTotal, pGuestStats->u32MemKernelTotal / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemKernelPaged, pGuestStats->u32MemKernelPaged / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemKernelNonpaged, pGuestStats->u32MemKernelNonPaged / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemSystemCache, pGuestStats->u32MemSystemCache / (_1M/pGuestStats->u32PageSize));
guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PageFileSize, pGuestStats->u32PageFileSize / (_1M/pGuestStats->u32PageSize));
/* increase sample number */
return VINF_SUCCESS;
}
/**
* Inflate or deflate the memory balloon
*
* @returns VBox status code.
* @param pInterface Pointer to this interface.
* @param fInflate Inflate or deflate
* @param cPages Number of physical pages (must be 256 as we allocate in 1 MB chunks)
* @param aPhysPage Array of physical page addresses
* @thread The emulation thread.
*/
DECLCALLBACK(int) vmmdevChangeMemoryBalloon(PPDMIVMMDEVCONNECTOR pInterface, bool fInflate, uint32_t cPages, RTGCPHYS *aPhysPage)
{
|| !aPhysPage)
return VERR_INVALID_PARAMETER;
Log(("vmmdevChangeMemoryBalloon @todo\n"));
return VINF_SUCCESS;
}
#ifdef VBOX_WITH_HGCM
/* HGCM connector interface */
static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
{
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, uint32_t u32Function,
{
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 u32Version Data layout version.
*/
{
LogFlowFunc(("Enter\n"));
if (u32Version != 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);
HGCMHostShutdown ();
}
#endif /* HGCM */
/**
* Queries an interface to the driver.
*
* @returns Pointer to interface.
* @returns NULL if the interface was not supported by the driver.
* @param pInterface Pointer to this interface structure.
* @param enmInterface The requested interface identification.
*/
{
switch (enmInterface)
{
case PDMINTERFACE_BASE:
#ifdef VBOX_WITH_HGCM
return &pDrv->HGCMConnector;
#endif
default:
return NULL;
}
}
/**
* Destruct a VMMDev driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
*/
{
#ifdef VBOX_WITH_HGCM
/* HGCM is shut down on the VMMDev destructor. */
#endif /* VBOX_WITH_HGCM */
{
}
}
/**
* Reset notification.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
*/
{
#ifdef VBOX_WITH_HGCM
HGCMHostReset ();
#endif /* VBOX_WITH_HGCM */
}
/**
* Construct a VMMDev driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
* If the registration structure is needed, pDrvIns->pDrvReg points to it.
* @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
* of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
* iInstance it's expected to be used a bit in this function.
*/
{
/*
* Validate configuration.
*/
if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
{
AssertMsgFailed(("Configuration error: Not possible to attach anything to this driver!\n"));
return VERR_PDM_DRVINS_NO_ATTACH;
}
/*
* IBase.
*/
#ifdef VBOX_WITH_HGCM
#endif
/*
*/
pData->pUpPort = (PPDMIVMMDEVPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_VMMDEV_PORT);
{
AssertMsgFailed(("Configuration error: No VMMDev port interface above!\n"));
return VERR_PDM_MISSING_INTERFACE_ABOVE;
}
#ifdef VBOX_WITH_HGCM
pData->pHGCMPort = (PPDMIHGCMPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_HGCM_PORT);
{
AssertMsgFailed(("Configuration error: No HGCM port interface above!\n"));
return 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"));
pLedPort = (PPDMILEDPORTS)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_LED_PORTS);
if (!pLedPort)
{
AssertMsgFailed(("Configuration error: No LED port interface above!\n"));
return VERR_PDM_MISSING_INTERFACE_ABOVE;
}
{
}
else
}
else
{
}
bool fEnabled;
/* Check CFGM option. */
if ( RT_SUCCESS(rc)
&& fEnabled)
{
if (RT_SUCCESS(rc))
{
LogRel(("Shared OpenGL service loaded.\n"));
}
else
{
}
}
pDrvIns->pDrvHlp->pfnSSMRegister(pDrvIns, "HGCM", 0, HGCM_SSM_VERSION, 4096/* bad guess */, NULL, iface_hgcmSave, NULL, NULL, iface_hgcmLoad, NULL);
#endif /* VBOX_WITH_HGCM */
return VINF_SUCCESS;
}
/**
* VMMDevice driver registration record.
*/
{
/* u32Version */
/* szDriverName */
"MainVMMDev",
/* pszDescription */
"Main VMMDev driver (Main as in the API).",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVMAINVMMDEV),
/* pfnConstruct */
/* pfnDestruct */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnDetach */
};