PDM.cpp revision dee2201f96a012bfb966c8de4ab006c2c90a0eef
/* $Id$ */
/** @file
* PDM - Pluggable Device Manager.
*/
/*
* 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.
*/
/** @page pg_pdm PDM - The Pluggable Device Manager
*
* VBox is designed to be very configurable, i.e. the ability to select
* virtual devices and configure them uniquely for a VM. For this reason
* virtual devices are not statically linked with the VMM but loaded and
* linked at runtime thru the Configuration Manager (CFGM). PDM will use
* CFGM to enumerate devices which needs loading and instantiation.
*
*
* @section sec_pdm_dev The Pluggable Device
*
* Devices register themselves when the module containing them is loaded.
* PDM will call an entry point 'VBoxDevicesRegister' when loading a device
* module. The device module will then use the supplied callback table to
* check the VMM version and to register its devices. Each device have an
* unique (for the configured VM) name (string). The name is not only used
* in PDM but in CFGM - to organize device and device instance settings - and
* by anyone who wants to do ioctls to the device.
*
* When all device modules have been successfully loaded PDM will instantiate
* those devices which are configured for the VM. Mark that this might mean
* creating several instances of some devices. When instantiating a device
* PDM provides device instance memory and a callback table with the VM APIs
* which the device instance is trusted with.
*
* Some devices are trusted devices, most are not. The trusted devices are
* an integrated part of the VM and can obtain the VM handle from their
* device instance handles, thus enabling them to call any VM api. Untrusted
* devices are can only use the callbacks provided during device
* instantiation.
*
* The guest context extention (optional) of a device is initialized as part
* of the GC init. A device marks in it's registration structure that it have
* a GC part, in which module and which name the entry point have. PDM will
* use its loader facilities to load this module into GC and to find the
* specified entry point.
*
* When writing a GC extention the programmer must keep in mind that this
* won't work.
*
*
* @section sec_pdm_drv The Pluggable Drivers
*
* The VM devices are often accessing host hardware or OS facilities. For
* most devices these facilities can be abstracted in one or more levels.
* These abstractions are called drivers.
*
* controller, EIDE controller or SATA controller. The basics of the
* read, seek, and such. (For the scsi case, you might wanna speak SCSI
* directly to, but that can of course be fixed.) So, it makes much sense to
*
* it can be read from a real CD or DVD drive (there are probably other
* custom formats someone could desire to read or construct too). So, it
* would make sense to have abstracted interfaces for dealing with this
* in a generic way so the cdrom unit doesn't have to implement it all.
*
* So, for this example the IDE controller #1 (i.e. secondary) will have
* attached.
*
* It is possible to configure many levels of drivers inserting filters, loggers,
* or whatever you desire into the chain.
*
*
* @subsection sec_pdm_drv_interfaces Interfaces
*
* The pluggable drivers exposes one standard interface (callback table) which
* is used to construct, destruct, attach, detach, and query other interfaces.
* A device will query the interfaces required for it's operation during init
* and hotplug. PDM will query some interfaces during runtime mounting too.
*
* ... list interfaces ...
*
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PDM
#include "PDMInternal.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The PDM saved state version. */
#define PDM_SAVED_STATE_VERSION 3
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/**
* Initializes the PDM part of the UVM.
*
* This doesn't really do much right now but has to be here for the sake
* of completeness.
*
* @returns VBox status code.
* @param pUVM Pointer to the user mode VM structure.
*/
{
return VINF_SUCCESS;
}
/**
* Initializes the PDM.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
LogFlow(("PDMR3Init\n"));
/*
* Assert alignment and sizes.
*/
/*
* Init the structure.
*/
int rc = TMR3TimerCreateInternal(pVM, TMCLOCK_VIRTUAL, pdmR3PollerTimer, NULL, "PDM Poller", &pVM->pdm.s.pTimerPollers);
/*
* Initialize sub compontents.
*/
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
#endif
{
/*
* Register the saved state data unit.
*/
if (VBOX_SUCCESS(rc))
{
LogFlow(("PDM: Successfully initialized\n"));
return rc;
}
}
}
}
}
}
/*
* Cleanup and return failure.
*/
return rc;
}
/**
* Applies relocations to data and code managed by this
* component. This function will be called at init and
* whenever the VMM need to relocate it self inside the GC.
*
* @param pVM VM handle.
* @param offDelta Relocation delta relative to old location.
* @remark The loader subcomponent is relocated by PDMR3LdrRelocate() very
* early in the relocation phase.
*/
{
LogFlow(("PDMR3Relocate\n"));
/*
* Queues.
*/
/*
* Critical sections.
*/
/*
* The registered PIC.
*/
{
}
/*
* The registered APIC.
*/
{
}
/*
* The registered I/O APIC.
*/
{
}
/*
* The register PCI Buses.
*/
{
{
}
}
/*
* Devices.
*/
{
{
{
LogFlow(("PDMR3Relocate: Relocating device '%s'/%d\n",
}
}
}
}
/**
* Worker for pdmR3Term that terminates a LUN chain.
*
* @param pVM Pointer to the shared VM structure.
* @param pLun The head of the chain.
* @param pszDevice The name of the device (for logging).
* @param iInstance The device instance number (for logging).
*/
{
{
/*
* Destroy them one at a time from the bottom up.
*/
while (pDrvIns)
{
{
LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
}
//PDMR3QueueDestroyDriver(pVM, pDrvIns);
//pdmR3ThreadDestroyDriver(pVM, pDrvIns);
}
}
}
/**
* Terminates the PDM.
*
* Termination means cleaning up and freeing all resources,
* the VM it self is at this point powered off or suspended.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
*/
{
LogFlow(("PDMR3Term:\n"));
/*
* Iterate the device instances and attach drivers, doing
* relevant destruction processing.
*
* N.B. There is no need to mess around freeing memory allocated
* from any MM heap since MM will do that in its Term function.
*/
/* usb ones first. */
{
{
LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
}
//TMR3TimerDestroyUsb(pVM, pUsbIns);
//SSMR3DeregisterUsb(pVM, pUsbIns, NULL, 0);
}
/* then the 'normal' ones. */
{
pdmR3TermLuns(pVM, pDevIns->Internal.s.pLunsR3, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance);
{
LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n",
}
//SSMR3DeregisterDriver(pVM, pDevIns, NULL, 0);
//pdmR3ThreadDestroyDevice(pVM, pDevIns);
//PDMR3QueueDestroyDevice(pVM, pDevIns);
}
/*
* Destroy all threads.
*/
/*
* Free async completion managers.
*/
#endif
/*
* Free modules.
*/
/*
* Destroy the PDM lock.
*/
return VINF_SUCCESS;
}
/**
* Terminates the PDM part of the UVM.
*
* This will unload any modules left behind.
*
* @param pUVM Pointer to the user mode VM structure.
*/
{
/*
* In the normal cause of events we will now call pdmR3LdrTermU for
* the second time. In the case of init failure however, this might
* the first time, which is why we do it.
*/
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
{
LogFlow(("pdmR3Save:\n"));
/*
* Save interrupt and DMA states.
*/
/*
* Save the list of device instances so we can check that
* they're all still there when we load the state and that
* nothing new have been added.
*/
/** @todo We might have to filter out some device classes, like USB attached devices. */
uint32_t i = 0;
for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3, i++)
{
SSMR3PutU32(pSSM, i);
}
}
/**
* Prepare state load operation.
*
* This will dispatch pending operations and clear the FFs governed by PDM and its devices.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The SSM handle.
*/
{
LogFlow(("pdmR3LoadPrep: %s%s%s%s\n",
));
/*
* In case there is work pending that will raise an interrupt,
* start a DMA transfer, or release a lock. (unlikely)
*/
/* Clear the FFs. */
return VINF_SUCCESS;
}
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @param u32Version Data layout version.
*/
{
LogFlow(("pdmR3Load:\n"));
/*
* Validate version.
*/
if (u32Version != PDM_SAVED_STATE_VERSION)
{
}
/*
* Load the interrupt and DMA states.
*/
/* APIC interrupt */
RTUINT fInterruptPending = 0;
if (VBOX_FAILURE(rc))
return rc;
if (fInterruptPending & ~1)
{
}
if (fInterruptPending)
/* PIC interrupt */
fInterruptPending = 0;
if (VBOX_FAILURE(rc))
return rc;
if (fInterruptPending & ~1)
{
}
if (fInterruptPending)
/* DMA pending */
RTUINT fDMAPending = 0;
if (VBOX_FAILURE(rc))
return rc;
if (fDMAPending & ~1)
{
}
if (fDMAPending)
/*
* Load the list of devices and verify that they are all there.
*
* We boldly ASSUME that the order is fixed and that it's a good, this
* makes it way easier to validate...
*/
uint32_t i = 0;
{
/* Get the separator / terminator. */
if (VBOX_FAILURE(rc))
return rc;
break;
if (u32Sep != i)
AssertMsgFailedReturn(("Out of seqence. u32Sep=%#x i=%#x\n", u32Sep, i), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
/* get the name and instance number. */
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_FAILURE(rc))
return rc;
/* compare */
if (!pDevIns)
{
break;
}
{
LogRel(("u32Sep=%d loaded '%s'/%d configured '%s'/%d\n",
}
}
/*
* Too many devices?
*/
if (pDevIns)
{
LogRel(("Device '%s'/%d not found in saved state\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
}
return VINF_SUCCESS;
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being powered on.
*
* @param pVM VM Handle.
*/
{
LogFlow(("PDMR3PowerOn:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
{
/** @todo Inverse the order here? */
{
LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
}
{
LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n",
}
}
#ifdef VBOX_WITH_USB
{
{
LogFlow(("PDMR3PowerOn: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
}
{
LogFlow(("PDMR3PowerOn: Notifying - device '%s'/%d\n",
}
}
#endif
/*
* Resume all threads.
*/
LogFlow(("PDMR3PowerOn: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being reset.
*
* @param pVM VM Handle.
*/
{
LogFlow(("PDMR3Reset:\n"));
/*
* Clear all pending interrupts and DMA operations.
*/
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
{
/** @todo Inverse the order here? */
{
LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
}
{
LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n",
}
}
#ifdef VBOX_WITH_USB
{
{
LogFlow(("PDMR3Reset: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
}
{
LogFlow(("PDMR3Reset: Notifying - device '%s'/%d\n",
}
}
#endif
LogFlow(("PDMR3Reset: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being reset.
*
* @param pVM VM Handle.
*/
{
LogFlow(("PDMR3Suspend:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
{
{
LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
}
{
LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n",
}
}
#ifdef VBOX_WITH_USB
{
{
LogFlow(("PDMR3Suspend: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
}
{
LogFlow(("PDMR3Suspend: Notifying - device '%s'/%d\n",
}
}
#endif
/*
* Suspend all threads.
*/
LogFlow(("PDMR3Suspend: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM now being resumed.
*
* @param pVM VM Handle.
*/
{
LogFlow(("PDMR3Resume:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
{
{
LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
}
{
LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n",
}
}
#ifdef VBOX_WITH_USB
{
{
LogFlow(("PDMR3Resume: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
}
{
LogFlow(("PDMR3Resume: Notifying - device '%s'/%d\n",
}
}
#endif
/*
* Resume all threads.
*/
LogFlow(("PDMR3Resume: returns void\n"));
}
/**
* This function will notify all the devices and their
* attached drivers about the VM being powered off.
*
* @param pVM VM Handle.
*/
{
LogFlow(("PDMR3PowerOff:\n"));
/*
* Iterate the device instances.
* The attached drivers are processed first.
*/
{
{
LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
}
{
LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n",
}
}
#ifdef VBOX_WITH_USB
{
{
LogFlow(("PDMR3PowerOff: Notifying - driver '%s'/%d on LUN#%d of usb device '%s'/%d\n",
pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pLun->iLun, pUsbIns->pUsbReg->szDeviceName, pUsbIns->iInstance));
}
{
LogFlow(("PDMR3PowerOff: Notifying - device '%s'/%d\n",
}
}
#endif
/*
* Suspend all threads.
*/
LogFlow(("PDMR3PowerOff: returns void\n"));
}
/**
* Queries the base interace of a device instance.
*
* The caller can use this to query other interfaces the device implements
* and use them to talk to the device.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszDevice Device name.
* @param iInstance Device instance.
* @param ppBase Where to store the pointer to the base device interface on success.
* @remark We're not doing any locking ATM, so don't try call this at times when the
* device chain is known to be updated.
*/
PDMR3DECL(int) PDMR3QueryDevice(PVM pVM, const char *pszDevice, unsigned iInstance, PPDMIBASE *ppBase)
{
LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase));
/*
* Iterate registered devices looking for the device.
*/
{
{
/*
* Iterate device instances.
*/
for (PPDMDEVINS pDevIns = pDev->pInstances; pDevIns; pDevIns = pDevIns->Internal.s.pPerDeviceNextR3)
{
{
{
return VINF_SUCCESS;
}
LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n"));
}
}
LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n"));
}
}
LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n"));
return VERR_PDM_DEVICE_NOT_FOUND;
}
/**
* Queries the base interface of a device LUN.
*
* This differs from PDMR3QueryLun by that it returns the interface on the
* device and not the top level driver.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pszDevice Device name.
* @param iInstance Device instance.
* @param iLun The Logical Unit to obtain the interface of.
* @param ppBase Where to store the base interface pointer.
* @remark We're not doing any locking ATM, so don't try call this at times when the
* device chain is known to be updated.
*/
PDMR3DECL(int) PDMR3QueryDeviceLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
{
LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
/*
* Find the LUN.
*/
if (VBOX_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}
/**
* Query the interface of the top level driver on a LUN.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pszDevice Device name.
* @param iInstance Device instance.
* @param iLun The Logical Unit to obtain the interface of.
* @param ppBase Where to store the base interface pointer.
* @remark We're not doing any locking ATM, so don't try call this at times when the
* device chain is known to be updated.
*/
PDMR3DECL(int) PDMR3QueryLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase)
{
LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
/*
* Find the LUN.
*/
if (VBOX_SUCCESS(rc))
{
{
return VINF_SUCCESS;
}
}
return rc;
}
/**
* Executes pending DMA transfers.
* Forced Action handler.
*
* @param pVM VM handle.
*/
{
{
if (fMore)
}
}
/**
* Call polling function.
*
* @param pVM VM handle.
*/
{
/* This is temporary hack and shall be removed ASAP! */
if (iPoller)
{
while (iPoller-- > 0)
}
}
/**
* Internal timer callback function.
*
* @param pVM The VM.
* @param pTimer The timer handle.
* @param pvUser User argument specified upon timer creation.
*/
{
}
/**
* Service a VMMCALLHOST_PDM_LOCK call.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
{
}
/**
* Registers the VMM device heap
*
* @returns VBox status code.
* @param pVM VM handle.
* @param GCPhys The physical address.
* @param pvHeap Ring-3 pointer.
* @param cbSize Size of the heap.
*/
{
return VINF_SUCCESS;
}
/**
* Unregisters the VMM device heap
*
* @returns VBox status code.
* @param pVM VM handle.
* @param GCPhys The physical address.
*/
{
return VINF_SUCCESS;
}
/**
* Allocates memory from the VMM device heap
*
* @returns VBox status code.
* @param pVM VM handle.
* @param cbSize Allocation size.
* @param pv Ring-3 pointer. (out)
*/
{
/** @todo not a real heap as there's currently only one user. */
return VINF_SUCCESS;
}
/**
* Frees memory from the VMM device heap
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pv Ring-3 pointer.
*/
{
/** @todo not a real heap as there's currently only one user. */
return VINF_SUCCESS;
}