StatusImpl.cpp revision 1c94c0a63ba68be1a7b2c640e70d7a06464e4fca
153N/A/** @file
153N/A *
153N/A * VBox frontends: Basic Frontend (BFE):
153N/A * Implementation of VMStatus class
943N/A */
153N/A
153N/A/*
919N/A * Copyright (C) 2006-2007 Sun Microsystems, Inc.
919N/A *
919N/A * This file is part of VirtualBox Open Source Edition (OSE), as
919N/A * available from http://www.virtualbox.org. This file is free software;
919N/A * you can redistribute it and/or modify it under the terms of the GNU
919N/A * General Public License (GPL) as published by the Free Software
919N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
919N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
919N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
919N/A *
919N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
919N/A * Clara, CA 95054 USA or visit http://www.sun.com if you need
919N/A * additional information or have any questions.
919N/A */
919N/A
919N/A#ifdef VBOXBFE_WITHOUT_COM
919N/A# include "COMDefs.h"
153N/A#else
153N/A# include <VBox/com/defs.h>
153N/A#endif
153N/A#include <VBox/pdm.h>
493N/A#include <VBox/cfgm.h>
153N/A#include <VBox/err.h>
153N/A#include <iprt/assert.h>
962N/A#include <VBox/log.h>
153N/A#include <iprt/asm.h>
911N/A#include "StatusImpl.h"
962N/A
962N/A// defines
911N/A////////////////////////////////////////////////////////////////////////////////
153N/A
153N/A// globals
153N/A////////////////////////////////////////////////////////////////////////////////
153N/A
153N/A/**
153N/A * The Main status driver instance data.
970N/A */
970N/Atypedef struct DRVMAINSTATUS
970N/A{
970N/A /** The LED connectors. */
970N/A PDMILEDCONNECTORS ILedConnectors;
970N/A /** Pointer to the LED ports interface above us. */
153N/A PPDMILEDPORTS pLedPorts;
153N/A /** Pointer to the array of LED pointers. */
493N/A PPDMLED *papLeds;
969N/A /** The unit number corresponding to the first entry in the LED array. */
153N/A RTUINT iFirstLUN;
493N/A /** The unit number corresponding to the last entry in the LED array.
153N/A * (The size of the LED array is iLastLUN - iFirstLUN + 1.) */
153N/A RTUINT iLastLUN;
153N/A} DRVMAINSTATUS, *PDRVMAINSTATUS;
153N/A
153N/A
493N/A/**
153N/A * Notification about a unit which have been changed.
970N/A *
970N/A * The driver must discard any pointers to data owned by
970N/A * the unit and requery it.
153N/A *
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @param iLUN The unit number.
*/
DECLCALLBACK(void) VMStatus::drvUnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN)
{
PDRVMAINSTATUS pData = (PDRVMAINSTATUS)(void *)pInterface;
if (iLUN >= pData->iFirstLUN && iLUN <= pData->iLastLUN)
{
PPDMLED pLed;
int rc = pData->pLedPorts->pfnQueryStatusLed(pData->pLedPorts, iLUN, &pLed);
if (VBOX_FAILURE(rc))
pLed = NULL;
ASMAtomicXchgPtr((void * volatile *)&pData->papLeds[iLUN - pData->iFirstLUN], pLed);
Log(("drvUnitChanged: iLUN=%d pLed=%p\n", iLUN, pLed));
}
}
/**
* 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.
*/
DECLCALLBACK(void *) VMStatus::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
{
PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
PDRVMAINSTATUS pDrv = PDMINS2DATA(pDrvIns, PDRVMAINSTATUS);
switch (enmInterface)
{
case PDMINTERFACE_BASE:
return &pDrvIns->IBase;
case PDMINTERFACE_LED_CONNECTORS:
return &pDrv->ILedConnectors;
default:
return NULL;
}
}
/**
* Destruct a status driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
*/
DECLCALLBACK(void) VMStatus::drvDestruct(PPDMDRVINS pDrvIns)
{
PDRVMAINSTATUS pData = PDMINS2DATA(pDrvIns, PDRVMAINSTATUS);
LogFlow(("VMStatus::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
if (pData->papLeds)
{
unsigned iLed = pData->iLastLUN - pData->iFirstLUN + 1;
while (iLed-- > 0)
ASMAtomicXchgPtr((void * volatile *)&pData->papLeds[iLed], NULL);
}
}
/**
* Construct a status 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.
*/
DECLCALLBACK(int) VMStatus::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
{
PDRVMAINSTATUS pData = PDMINS2DATA(pDrvIns, PDRVMAINSTATUS);
LogFlow(("VMStatus::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
/*
* Validate configuration.
*/
if (!CFGMR3AreValuesValid(pCfgHandle, "papLeds\0First\0Last\0"))
return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
PPDMIBASE pBaseIgnore;
int rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pBaseIgnore);
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;
}
/*
* Data.
*/
pDrvIns->IBase.pfnQueryInterface = VMStatus::drvQueryInterface;
pData->ILedConnectors.pfnUnitChanged = VMStatus::drvUnitChanged;
/*
* Read config.
*/
rc = CFGMR3QueryPtr(pCfgHandle, "papLeds", (void **)&pData->papLeds);
if (VBOX_FAILURE(rc))
{
AssertMsgFailed(("Configuration error: Failed to query the \"papLeds\" value! rc=%Vrc\n", rc));
return rc;
}
rc = CFGMR3QueryU32(pCfgHandle, "First", &pData->iFirstLUN);
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
pData->iFirstLUN = 0;
else if (VBOX_FAILURE(rc))
{
AssertMsgFailed(("Configuration error: Failed to query the \"First\" value! rc=%Vrc\n", rc));
return rc;
}
rc = CFGMR3QueryU32(pCfgHandle, "Last", &pData->iLastLUN);
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
pData->iLastLUN = 0;
else if (VBOX_FAILURE(rc))
{
AssertMsgFailed(("Configuration error: Failed to query the \"Last\" value! rc=%Vrc\n", rc));
return rc;
}
if (pData->iFirstLUN > pData->iLastLUN)
{
AssertMsgFailed(("Configuration error: Invalid unit range %u-%u\n", pData->iFirstLUN, pData->iLastLUN));
return VERR_GENERAL_FAILURE;
}
/*
* Get the ILedPorts interface of the above driver/device and
* query the LEDs we want.
*/
pData->pLedPorts = (PPDMILEDPORTS)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_LED_PORTS);
if (!pData->pLedPorts)
{
AssertMsgFailed(("Configuration error: No led ports interface above!\n"));
return VERR_PDM_MISSING_INTERFACE_ABOVE;
}
for (unsigned i = pData->iFirstLUN; i <= pData->iLastLUN; i++)
VMStatus::drvUnitChanged(&pData->ILedConnectors, i);
return VINF_SUCCESS;
}
/**
* VMStatus driver registration record.
*/
const PDMDRVREG VMStatus::DrvReg =
{
/* u32Version */
PDM_DRVREG_VERSION,
/* szDriverName */
"MainStatus",
/* pszDescription */
"Main status driver (Main as in the API).",
/* fFlags */
PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
/* fClass. */
PDM_DRVREG_CLASS_STATUS,
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVMAINSTATUS),
/* pfnConstruct */
VMStatus::drvConstruct,
/* pfnDestruct */
VMStatus::drvDestruct,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnDetach */
NULL
};