Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

PDMInternal.h

Go to the documentation of this file.
/* $Id: PDMInternal.h 13519 2008-10-23 08:58:37Z vboxsync $ */
/** @file
 * PDM - Internal header file.
 */

/*
 * 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;
 * you can redistribute it and/or modify it under the terms of the GNU
 * 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.
 */

#ifndef ___PDMInternal_h
#define ___PDMInternal_h

#include <VBox/cdefs.h>
#include <VBox/types.h>
#include <VBox/param.h>
#include <VBox/cfgm.h>
#include <VBox/stam.h>
#include <VBox/vusb.h>
#include <VBox/pdmasynccompletion.h>
#include <iprt/critsect.h>
#ifdef IN_RING3
# include <iprt/thread.h>
#endif

__BEGIN_DECLS


/** @defgroup grp_pdm_int       Internal
 * @ingroup grp_pdm
 * @internal
 * @{
 */

/*******************************************************************************
*   Structures and Typedefs                                                    *
*******************************************************************************/

/** Pointer to a PDM Device. */
00051 typedef struct PDMDEV *PPDMDEV;
/** Pointer to a pointer to a PDM Device. */
00053 typedef PPDMDEV *PPPDMDEV;

/** Pointer to a PDM USB Device. */
00056 typedef struct PDMUSB *PPDMUSB;
/** Pointer to a pointer to a PDM USB Device. */
00058 typedef PPDMUSB *PPPDMUSB;

/** Pointer to a PDM Driver. */
00061 typedef struct PDMDRV *PPDMDRV;
/** Pointer to a pointer to a PDM Driver. */
00063 typedef PPDMDRV *PPPDMDRV;

/** Pointer to a PDM Logical Unit. */
00066 typedef struct PDMLUN *PPDMLUN;
/** Pointer to a pointer to a PDM Logical Unit. */
00068 typedef PPDMLUN *PPPDMLUN;

/** Pointer to a PDM PCI Bus instance. */
00071 typedef struct PDMPCIBUS *PPDMPCIBUS;
/** Pointer to a DMAC instance. */
00073 typedef struct PDMDMAC *PPDMDMAC;
/** Pointer to a RTC instance. */
00075 typedef struct PDMRTC *PPDMRTC;

/** Pointer to an USB HUB registration record. */
00078 typedef struct PDMUSBHUB *PPDMUSBHUB;

/**
 * Private device instance data.
 */
00083 typedef struct PDMDEVINSINT
{
    /** Pointer to the next instance (HC Ptr).
     * (Head is pointed to by PDM::pDevInstances.) */
    R3PTRTYPE(PPDMDEVINS)           pNextR3;
    /** Pointer to the next per device instance (HC Ptr).
     * (Head is pointed to by PDMDEV::pInstances.) */
    R3PTRTYPE(PPDMDEVINS)           pPerDeviceNextR3;
    /** Pointer to device structure - HC Ptr. */
    R3PTRTYPE(PPDMDEV)              pDevR3;
    /** Pointer to the list of logical units associated with the device. (FIFO) */
    R3PTRTYPE(PPDMLUN)              pLunsR3;
    /** Configuration handle to the instance node. */
    R3PTRTYPE(PCFGMNODE)            pCfgHandle;

    /** R3 pointer to the VM this instance was created for. */
00099     PVMR3                           pVMR3;
    /** R3 pointer to associated PCI device structure. */
    R3PTRTYPE(struct PCIDevice *)   pPciDeviceR3;
    /** R3 pointer to associated PCI bus structure. */
    R3PTRTYPE(PPDMPCIBUS)           pPciBusR3;

    /** R0 pointer to the VM this instance was created for. */
00106     PVMR0                           pVMR0;
    /** R0 pointer to associated PCI device structure. */
    R0PTRTYPE(struct PCIDevice *)   pPciDeviceR0;
    /** R0 pointer to associated PCI bus structure. */
    R0PTRTYPE(PPDMPCIBUS)           pPciBusR0;
    /** Alignment padding. */
00112     RTR0PTR                         Alignment0;

    /** RC pointer to the VM this instance was created for. */
00115     PVMRC                           pVMRC;
    /** RC pointer to associated PCI device structure. */
    RCPTRTYPE(struct PCIDevice *)   pPciDeviceRC;
    /** RC pointer to associated PCI bus structure. */
    RCPTRTYPE(PPDMPCIBUS)           pPciBusRC;
    /** Alignment padding. */
00121     RTRCPTR                         Alignment1;
} PDMDEVINSINT;


/**
 * Private USB device instance data.
 */
00128 typedef struct PDMUSBINSINT
{
    /** The UUID of this instance. */
00131     RTUUID                          Uuid;
    /** Pointer to the next instance.
     * (Head is pointed to by PDM::pUsbInstances.) */
    R3PTRTYPE(PPDMUSBINS)           pNext;
    /** Pointer to the next per USB device instance.
     * (Head is pointed to by PDMUSB::pInstances.) */
    R3PTRTYPE(PPDMUSBINS)           pPerDeviceNext;

    /** Pointer to device structure. */
    R3PTRTYPE(PPDMUSB)              pUsbDev;

    /** Pointer to the VM this instance was created for. */
00143     PVMR3                           pVM;
    /** Pointer to the list of logical units associated with the device. (FIFO) */
    R3PTRTYPE(PPDMLUN)              pLuns;
    /** The per instance device configuration. */
    R3PTRTYPE(PCFGMNODE)            pCfg;
    /** Same as pCfg if the configuration should be deleted when detaching the device. */
    R3PTRTYPE(PCFGMNODE)            pCfgDelete;
    /** The global device configuration. */
    R3PTRTYPE(PCFGMNODE)            pCfgGlobal;

    /** Pointer to the USB hub this device is attached to.
     * This is NULL if the device isn't connected to any HUB. */
    R3PTRTYPE(PPDMUSBHUB)           pHub;
    /** The port number that we're connected to. */
00157     uint32_t                        iPort;
#if HC_ARCH_BITS == 64
    uint32_t                        Alignment0;
#endif
} PDMUSBINSINT;


/**
 * Private driver instance data.
 */
00167 typedef struct PDMDRVINSINT
{
    /** Pointer to the driver instance above.
     * This is NULL for the topmost drive. */
00171     PPDMDRVINS                      pUp;
    /** Pointer to the driver instance below.
     * This is NULL for the bottommost driver. */
00174     PPDMDRVINS                      pDown;
    /** Pointer to the logical unit this driver chained on. */
00176     PPDMLUN                         pLun;
    /** Pointer to driver structure from which this was instantiated. */
00178     PPDMDRV                         pDrv;
    /** Pointer to the VM this instance was created for. */
00180     PVM                             pVM;
    /** Flag indicating that the driver is being detached and destroyed.
     * (Helps detect potential recursive detaching.) */
00183     bool                            fDetaching;
    /** Configuration handle to the instance node. */
00185     PCFGMNODE                       pCfgHandle;

} PDMDRVINSINT;


/**
 * Private critical section data.
 */
00193 typedef struct PDMCRITSECTINT
{
    /** The critical section core which is shared with IPRT. */
00196     RTCRITSECT                      Core;
    /** Pointer to the next critical section.
     * This chain is used for relocating pVMRC and device cleanup. */
    R3PTRTYPE(struct PDMCRITSECTINT *) pNext;
    /** Owner identifier.
     * This is pDevIns if the owner is a device. Similarily for a driver or service.
     * PDMR3CritSectInit() sets this to point to the critsect itself. */
00203     RTR3PTR                         pvKey;
    /** Pointer to the VM - R3Ptr. */
00205     PVMR3                           pVMR3;
    /** Pointer to the VM - R0Ptr. */
00207     PVMR0                           pVMR0;
    /** Pointer to the VM - GCPtr. */
00209     PVMRC                           pVMRC;
#if HC_ARCH_BITS == 64
    RTRCPTR                         padding;
#endif
    /** Event semaphore that is scheduled to be signaled upon leaving the
     * critical section. This is Ring-3 only of course. */
00215     RTSEMEVENT                      EventToSignal;
    /** R0/RC lock contention. */
00217     STAMCOUNTER                     StatContentionRZLock;
    /** R0/RC unlock contention. */
00219     STAMCOUNTER                     StatContentionRZUnlock;
    /** R3 lock contention. */
00221     STAMCOUNTER                     StatContentionR3;
    /** Profiling the time the section is locked. */
00223     STAMPROFILEADV                  StatLocked;
} PDMCRITSECTINT;
typedef PDMCRITSECTINT *PPDMCRITSECTINT;


/**
 * The usual device/driver/internal/external stuff.
 */
00231 typedef enum
{
    /** The usual invalid entry. */
00234     PDMTHREADTYPE_INVALID = 0,
    /** Device type. */
00236     PDMTHREADTYPE_DEVICE,
    /** USB Device type. */
00238     PDMTHREADTYPE_USB,
    /** Driver type. */
00240     PDMTHREADTYPE_DRIVER,
    /** Internal type. */
00242     PDMTHREADTYPE_INTERNAL,
    /** External type. */
00244     PDMTHREADTYPE_EXTERNAL,
    /** The usual 32-bit hack. */
00246     PDMTHREADTYPE_32BIT_HACK = 0x7fffffff
} PDMTHREADTYPE;


/**
 * The internal structure for the thread.
 */
00253 typedef struct PDMTHREADINT
{
    /** The VM pointer. */
00256     PVMR3                           pVM;
    /** The event semaphore the thread blocks on when not running. */
00258     RTSEMEVENTMULTI                 BlockEvent;
    /** The event semaphore the thread sleeps on while running. */
00260     RTSEMEVENTMULTI                 SleepEvent;
    /** Pointer to the next thread. */
    R3PTRTYPE(struct PDMTHREAD *)   pNext;
    /** The thread type. */
00264     PDMTHREADTYPE                   enmType;
} PDMTHREADINT;



/* Must be included after PDMDEVINSINT is defined. */
#define PDMDEVINSINT_DECLARED
#define PDMUSBINSINT_DECLARED
#define PDMDRVINSINT_DECLARED
#define PDMCRITSECTINT_DECLARED
#define PDMTHREADINT_DECLARED
#ifdef ___VBox_pdm_h
# error "Invalid header PDM order. Include PDMInternal.h before VBox/pdm.h!"
#endif
__END_DECLS
#include <VBox/pdm.h>
__BEGIN_DECLS

/**
 * PDM Logical Unit.
 *
 * This typically the representation of a physical port on a
 * device, like for instance the PS/2 keyboard port on the
 * keyboard controller device. The LUNs are chained on the
 * device the belong to (PDMDEVINSINT::pLunsR3).
 */
00290 typedef struct PDMLUN
{
    /** The LUN - The Logical Unit Number. */
00293     RTUINT                          iLun;
    /** Pointer to the next LUN. */
00295     PPDMLUN                         pNext;
    /** Pointer to the top driver in the driver chain. */
00297     PPDMDRVINS                      pTop;
    /** Pointer to the bottom driver in the driver chain. */
00299     PPDMDRVINS                      pBottom;
    /** Pointer to the device instance which the LUN belongs to.
     * Either this is set or pUsbIns is set. Both is never set at the same time. */
00302     PPDMDEVINS                      pDevIns;
    /** Pointer to the USB device instance which the LUN belongs to. */
00304     PPDMUSBINS                      pUsbIns;
    /** Pointer to the device base interface. */
00306     PPDMIBASE                       pBase;
    /** Description of this LUN. */
00308     const char                     *pszDesc;
} PDMLUN;


/**
 * PDM Device.
 */
00315 typedef struct PDMDEV
{
    /** Pointer to the next device (R3 Ptr). */
    R3PTRTYPE(PPDMDEV)              pNext;
    /** Device name length. (search optimization) */
00320     RTUINT                          cchName;
    /** Registration structure. */
    R3PTRTYPE(const struct PDMDEVREG *) pDevReg;
    /** Number of instances. */
00324     RTUINT                          cInstances;
    /** Pointer to chain of instances (R3 Ptr). */
00326     PPDMDEVINSR3                    pInstances;
} PDMDEV;


/**
 * PDM USB Device.
 */
00333 typedef struct PDMUSB
{
    /** Pointer to the next device (R3 Ptr). */
    R3PTRTYPE(PPDMUSB)              pNext;
    /** Device name length. (search optimization) */
00338     RTUINT                          cchName;
    /** Registration structure. */
    R3PTRTYPE(const struct PDMUSBREG *) pUsbReg;
    /** Next instance number. */
00342     RTUINT                          iNextInstance;
    /** Pointer to chain of instances (R3 Ptr). */
    R3PTRTYPE(PPDMUSBINS)           pInstances;
} PDMUSB;


/**
 * PDM Driver.
 */
00351 typedef struct PDMDRV
{
    /** Pointer to the next device. */
00354     PPDMDRV                         pNext;
    /** Registration structure. */
00356     const struct PDMDRVREG *        pDrvReg;
    /** Number of instances. */
00358     RTUINT                          cInstances;
} PDMDRV;


/**
 * PDM registered PIC device.
 */
00365 typedef struct PDMPIC
{
    /** Pointer to the PIC device instance - R3. */
00368     PPDMDEVINSR3                    pDevInsR3;
    /** @copydoc PDMPICREG::pfnSetIrqR3 */
    DECLR3CALLBACKMEMBER(void,      pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
    /** @copydoc PDMPICREG::pfnGetInterruptR3 */
    DECLR3CALLBACKMEMBER(int,       pfnGetInterruptR3,(PPDMDEVINS pDevIns));

    /** Pointer to the PIC device instance - R0. */
00375     PPDMDEVINSR0                    pDevInsR0;
    /** @copydoc PDMPICREG::pfnSetIrqR3 */
    DECLR0CALLBACKMEMBER(void,      pfnSetIrqR0,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
    /** @copydoc PDMPICREG::pfnGetInterruptR3 */
    DECLR0CALLBACKMEMBER(int,       pfnGetInterruptR0,(PPDMDEVINS pDevIns));

    /** Pointer to the PIC device instance - RC. */
00382     PPDMDEVINSRC                    pDevInsRC;
    /** @copydoc PDMPICREG::pfnSetIrqR3 */
    DECLRCCALLBACKMEMBER(void,      pfnSetIrqRC,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
    /** @copydoc PDMPICREG::pfnGetInterruptR3 */
    DECLRCCALLBACKMEMBER(int,       pfnGetInterruptRC,(PPDMDEVINS pDevIns));
    /** Alignment padding. */
00388     RTRCPTR                         RCPtrPadding;
} PDMPIC;


/**
 * PDM registered APIC device.
 */
00395 typedef struct PDMAPIC
{
    /** Pointer to the APIC device instance - R3 Ptr. */
00398     PPDMDEVINSR3                    pDevInsR3;
    /** @copydoc PDMAPICREG::pfnGetInterruptR3 */
    DECLR3CALLBACKMEMBER(int,       pfnGetInterruptR3,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnHasPendingIrqR3 */
    DECLR3CALLBACKMEMBER(bool,      pfnHasPendingIrqR3,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnSetBaseR3 */
    DECLR3CALLBACKMEMBER(void,      pfnSetBaseR3,(PPDMDEVINS pDevIns, uint64_t u64Base));
    /** @copydoc PDMAPICREG::pfnGetBaseR3 */
    DECLR3CALLBACKMEMBER(uint64_t,  pfnGetBaseR3,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnSetTPRR3 */
    DECLR3CALLBACKMEMBER(void,      pfnSetTPRR3,(PPDMDEVINS pDevIns, uint8_t u8TPR));
    /** @copydoc PDMAPICREG::pfnGetTPRR3 */
    DECLR3CALLBACKMEMBER(uint8_t,   pfnGetTPRR3,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnWriteMSRR3 */
    DECLR3CALLBACKMEMBER(int,       pfnWriteMSRR3, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t u64Value));
    /** @copydoc PDMAPICREG::pfnReadMSRR3 */
    DECLR3CALLBACKMEMBER(int,       pfnReadMSRR3, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t *pu64Value));
    /** @copydoc PDMAPICREG::pfnBusDeliverR3 */
    DECLR3CALLBACKMEMBER(void,      pfnBusDeliverR3,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
                                                     uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));

    /** Pointer to the APIC device instance - R0 Ptr. */
00420     PPDMDEVINSR0                    pDevInsR0;
    /** @copydoc PDMAPICREG::pfnGetInterruptR3 */
    DECLR0CALLBACKMEMBER(int,       pfnGetInterruptR0,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnHasPendingIrqR3 */
    DECLR0CALLBACKMEMBER(bool,      pfnHasPendingIrqR0,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnSetBaseR3 */
    DECLR0CALLBACKMEMBER(void,      pfnSetBaseR0,(PPDMDEVINS pDevIns, uint64_t u64Base));
    /** @copydoc PDMAPICREG::pfnGetBaseR3 */
    DECLR0CALLBACKMEMBER(uint64_t,  pfnGetBaseR0,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnSetTPRR3 */
    DECLR0CALLBACKMEMBER(void,      pfnSetTPRR0,(PPDMDEVINS pDevIns, uint8_t u8TPR));
    /** @copydoc PDMAPICREG::pfnGetTPRR3 */
    DECLR0CALLBACKMEMBER(uint8_t,   pfnGetTPRR0,(PPDMDEVINS pDevIns));
     /** @copydoc PDMAPICREG::pfnWriteMSRR3 */
    DECLR0CALLBACKMEMBER(uint32_t,  pfnWriteMSRR0, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t u64Value));
    /** @copydoc PDMAPICREG::pfnReadMSRR3 */
    DECLR0CALLBACKMEMBER(uint32_t,  pfnReadMSRR0, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t *pu64Value));
    /** @copydoc PDMAPICREG::pfnBusDeliverR3 */
    DECLR0CALLBACKMEMBER(void,      pfnBusDeliverR0,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
                                                     uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));

    /** Pointer to the APIC device instance - RC Ptr. */
00442     PPDMDEVINSRC                    pDevInsRC;
    /** @copydoc PDMAPICREG::pfnGetInterruptR3 */
    DECLRCCALLBACKMEMBER(int,       pfnGetInterruptRC,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnHasPendingIrqR3 */
    DECLRCCALLBACKMEMBER(bool,      pfnHasPendingIrqRC,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnSetBaseR3 */
    DECLRCCALLBACKMEMBER(void,      pfnSetBaseRC,(PPDMDEVINS pDevIns, uint64_t u64Base));
    /** @copydoc PDMAPICREG::pfnGetBaseR3 */
    DECLRCCALLBACKMEMBER(uint64_t,  pfnGetBaseRC,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnSetTPRR3 */
    DECLRCCALLBACKMEMBER(void,      pfnSetTPRRC,(PPDMDEVINS pDevIns, uint8_t u8TPR));
    /** @copydoc PDMAPICREG::pfnGetTPRR3 */
    DECLRCCALLBACKMEMBER(uint8_t,   pfnGetTPRRC,(PPDMDEVINS pDevIns));
    /** @copydoc PDMAPICREG::pfnWriteMSRR3 */
    DECLRCCALLBACKMEMBER(uint32_t,  pfnWriteMSRRC, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t u64Value));
    /** @copydoc PDMAPICREG::pfnReadMSRR3 */
    DECLRCCALLBACKMEMBER(uint32_t,  pfnReadMSRRC, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t *pu64Value));
    /** @copydoc PDMAPICREG::pfnBusDeliverR3 */
    DECLRCCALLBACKMEMBER(void,      pfnBusDeliverRC,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
                                                     uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
} PDMAPIC;


/**
 * PDM registered I/O APIC device.
 */
00468 typedef struct PDMIOAPIC
{
    /** Pointer to the APIC device instance - R3 Ptr. */
00471     PPDMDEVINSR3                    pDevInsR3;
    /** @copydoc PDMIOAPICREG::pfnSetIrqR3 */
    DECLR3CALLBACKMEMBER(void,      pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel));

    /** Pointer to the PIC device instance - R0. */
00476     PPDMDEVINSR0                    pDevInsR0;
    /** @copydoc PDMIOAPICREG::pfnSetIrqR3 */
    DECLR0CALLBACKMEMBER(void,      pfnSetIrqR0,(PPDMDEVINS pDevIns, int iIrq, int iLevel));

    /** Pointer to the APIC device instance - RC Ptr. */
00481     PPDMDEVINSRC                    pDevInsRC;
    /** @copydoc PDMIOAPICREG::pfnSetIrqR3 */
    DECLRCCALLBACKMEMBER(void,      pfnSetIrqRC,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
} PDMIOAPIC;

/** Maximum number of PCI busses for a VM. */
00487 #define PDM_PCI_BUSSES_MAX 8

/**
 * PDM PCI Bus instance.
 */
00492 typedef struct PDMPCIBUS
{
    /** PCI bus number. */
00495     RTUINT          iBus;
00496     RTUINT          uPadding0; /**< Alignment padding.*/

    /** Pointer to PCI Bus device instance. */
00499     PPDMDEVINSR3                    pDevInsR3;
    /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
    DECLR3CALLBACKMEMBER(void,      pfnSetIrqR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
    /** @copydoc PDMPCIBUSREG::pfnRegisterR3 */
    DECLR3CALLBACKMEMBER(int,       pfnRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev));
    /** @copydoc PDMPCIBUSREG::pfnIORegionRegisterR3 */
    DECLR3CALLBACKMEMBER(int,       pfnIORegionRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion,
                                                           PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
    /** @copydoc PDMPCIBUSREG::pfnSetConfigCallbacksR3 */
    DECLR3CALLBACKMEMBER(void,      pfnSetConfigCallbacksR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead,
                                                             PPFNPCICONFIGREAD ppfnReadOld, PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
    /** @copydoc PDMPCIBUSREG::pfnSaveExecR3 */
    DECLR3CALLBACKMEMBER(int,       pfnSaveExecR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
    /** @copydoc PDMPCIBUSREG::pfnLoadExecR3 */
    DECLR3CALLBACKMEMBER(int,       pfnLoadExecR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
    /** @copydoc PDMPCIBUSREG::pfnFakePCIBIOSR3 */
    DECLR3CALLBACKMEMBER(int,       pfnFakePCIBIOSR3,(PPDMDEVINS pDevIns));

    /** Pointer to the PIC device instance - R0. */
    R0PTRTYPE(PPDMDEVINS)           pDevInsR0;
    /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
    DECLR0CALLBACKMEMBER(void,      pfnSetIrqR0,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));

    /** Pointer to PCI Bus device instance. */
00523     PPDMDEVINSRC                    pDevInsRC;
    /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
    DECLRCCALLBACKMEMBER(void,      pfnSetIrqRC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
} PDMPCIBUS;


#ifdef IN_RING3
/**
 * PDM registered DMAC (DMA Controller) device.
 */
typedef struct PDMDMAC
{
    /** Pointer to the DMAC device instance. */
    PPDMDEVINSR3                    pDevIns;
    /** Copy of the registration structure. */
    PDMDMACREG                      Reg;
} PDMDMAC;


/**
 * PDM registered RTC (Real Time Clock) device.
 */
typedef struct PDMRTC
{
    /** Pointer to the RTC device instance. */
    PPDMDEVINSR3                    pDevIns;
    /** Copy of the registration structure. */
    PDMRTCREG                       Reg;
} PDMRTC;

#endif /* IN_RING3 */

/**
 * Module type.
 */
00558 typedef enum PDMMODTYPE
{
    /** Raw-mode (RC) context module. */
00561     PDMMOD_TYPE_RC,
    /** Ring-0 (host) context module. */
00563     PDMMOD_TYPE_R0,
    /** Ring-3 (host) context module. */
00565     PDMMOD_TYPE_R3
} PDMMODTYPE;


/** The module name length including the terminator. */
00570 #define PDMMOD_NAME_LEN             32

/**
 * Loaded module instance.
 */
00575 typedef struct PDMMOD
{
    /** Module name. This is used for refering to
     * the module internally, sort of like a handle. */
00579     char                            szName[PDMMOD_NAME_LEN];
    /** Module type. */
00581     PDMMODTYPE                      eType;
    /** Loader module handle. Not used for R0 modules. */
00583     RTLDRMOD                        hLdrMod;
    /** Loaded address.
     * This is the 'handle' for R0 modules. */
00586     RTUINTPTR                       ImageBase;
    /** Old loaded address.
     * This is used during relocation of GC modules. Not used for R0 modules. */
00589     RTUINTPTR                       OldImageBase;
    /** Where the R3 HC bits are stored.
     * This can be equal to ImageBase but doesn't have to. Not used for R0 modules. */
00592     void                           *pvBits;

    /** Pointer to next module. */
00595     struct PDMMOD                  *pNext;
    /** Module filename. */
00597     char                            szFilename[1];
} PDMMOD;
/** Pointer to loaded module instance. */
00600 typedef PDMMOD *PPDMMOD;



/** Extra space in the free array. */
00605 #define PDMQUEUE_FREE_SLACK         16

/**
 * Queue type.
 */
00610 typedef enum PDMQUEUETYPE
{
    /** Device consumer. */
00613     PDMQUEUETYPE_DEV = 1,
    /** Driver consumer. */
00615     PDMQUEUETYPE_DRV,
    /** Internal consumer. */
00617     PDMQUEUETYPE_INTERNAL,
    /** External consumer. */
00619     PDMQUEUETYPE_EXTERNAL
} PDMQUEUETYPE;

/** Pointer to a PDM Queue. */
00623 typedef struct PDMQUEUE *PPDMQUEUE;

/**
 * PDM Queue.
 */
00628 typedef struct PDMQUEUE
{
    /** Pointer to the next queue in the list. */
    R3PTRTYPE(PPDMQUEUE)            pNext;
    /** Type specific data. */
    union
    {
        /** PDMQUEUETYPE_DEV */
        struct
        {
            /** Pointer to consumer function. */
            R3PTRTYPE(PFNPDMQUEUEDEV)   pfnCallback;
            /** Pointer to the device instance owning the queue. */
            R3PTRTYPE(PPDMDEVINS)       pDevIns;
        } Dev;
        /** PDMQUEUETYPE_DRV */
        struct
        {
            /** Pointer to consumer function. */
            R3PTRTYPE(PFNPDMQUEUEDRV)   pfnCallback;
            /** Pointer to the driver instance owning the queue. */
            R3PTRTYPE(PPDMDRVINS)       pDrvIns;
        } Drv;
        /** PDMQUEUETYPE_INTERNAL */
        struct
        {
            /** Pointer to consumer function. */
            R3PTRTYPE(PFNPDMQUEUEINT)   pfnCallback;
        } Int;
        /** PDMQUEUETYPE_EXTERNAL */
        struct
        {
            /** Pointer to consumer function. */
            R3PTRTYPE(PFNPDMQUEUEEXT)   pfnCallback;
            /** Pointer to user argument. */
            R3PTRTYPE(void *)           pvUser;
        } Ext;
    } u;
    /** Queue type. */
00667     PDMQUEUETYPE                    enmType;
    /** The interval between checking the queue for events.
     * The realtime timer below is used to do the waiting.
     * If 0, the queue will use the VM_FF_PDM_QUEUE forced action. */
00671     uint32_t                        cMilliesInterval;
    /** Interval timer. Only used if cMilliesInterval is non-zero. */
00673     PTMTIMERR3                      pTimer;
    /** Pointer to the VM - R3. */
00675     PVMR3                           pVMR3;
    /** LIFO of pending items - R3. */
    R3PTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingR3;
    /** Pointer to the VM - R0. */
00679     PVMR0                           pVMR0;
    /** LIFO of pending items - R0. */
    R0PTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingR0;
    /** Pointer to the GC VM and indicator for GC enabled queue.
     * If this is NULL, the queue cannot be used in GC.
     */
00685     PVMRC                           pVMRC;
    /** LIFO of pending items - GC. */
    RCPTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingRC;
    /** Item size (bytes). */
00689     RTUINT                          cbItem;
    /** Number of items in the queue. */
00691     RTUINT                          cItems;
    /** Index to the free head (where we insert). */
00693     uint32_t volatile               iFreeHead;
    /** Index to the free tail (where we remove). */
00695     uint32_t volatile               iFreeTail;

    /** Array of pointers to free items. Variable size. */
00698     struct PDMQUEUEFREEITEM
    {
        /** Pointer to the free item - HC Ptr. */
        R3PTRTYPE(PPDMQUEUEITEMCORE) volatile   pItemR3;
        /** Pointer to the free item - HC Ptr. */
        R0PTRTYPE(PPDMQUEUEITEMCORE) volatile   pItemR0;
        /** Pointer to the free item - GC Ptr. */
        RCPTRTYPE(PPDMQUEUEITEMCORE) volatile   pItemRC;
#if HC_ARCH_BITS == 64
        RTRCPTR                                 Alignment0;
#endif
    }                               aFreeItems[1];
} PDMQUEUE;


/**
 * Queue device helper task operation.
 */
00716 typedef enum PDMDEVHLPTASKOP
{
    /** The usual invalid 0 entry. */
00719     PDMDEVHLPTASKOP_INVALID = 0,
    /** ISASetIrq */
00721     PDMDEVHLPTASKOP_ISA_SET_IRQ,
    /** PCISetIrq */
00723     PDMDEVHLPTASKOP_PCI_SET_IRQ,
    /** PCISetIrq */
00725     PDMDEVHLPTASKOP_IOAPIC_SET_IRQ,
    /** The usual 32-bit hack. */
00727     PDMDEVHLPTASKOP_32BIT_HACK = 0x7fffffff
} PDMDEVHLPTASKOP;

/**
 * Queued Device Helper Task.
 */
00733 typedef struct PDMDEVHLPTASK
{
    /** The queue item core (don't touch). */
00736     PDMQUEUEITEMCORE                Core;
    /** Pointer to the device instance (R3 Ptr). */
00738     PPDMDEVINSR3                    pDevInsR3;
    /** This operation to perform. */
00740     PDMDEVHLPTASKOP                 enmOp;
#if HC_ARCH_BITS == 64
    uint32_t                        Alignment0;
#endif
    /** Parameters to the operation. */
00745     union PDMDEVHLPTASKPARAMS
    {
        /**
         * PDMDEVHLPTASKOP_ISA_SET_IRQ and PDMDEVHLPTASKOP_PCI_SET_IRQ.
         */
00750         struct PDMDEVHLPTASKSETIRQ
        {
            /** The IRQ */
00753             int                     iIrq;
            /** The new level. */
00755             int                     iLevel;
        } SetIRQ;
    } u;
} PDMDEVHLPTASK;
/** Pointer to a queued Device Helper Task. */
00760 typedef PDMDEVHLPTASK *PPDMDEVHLPTASK;
/** Pointer to a const queued Device Helper Task. */
00762 typedef const PDMDEVHLPTASK *PCPDMDEVHLPTASK;



/**
 * An USB hub registration record.
 */
00769 typedef struct PDMUSBHUB
{
    /** The USB versions this hub support.
     * Note that 1.1 hubs can take on 2.0 devices. */
00773     uint32_t                        fVersions;
    /** The number of ports on the hub. */
00775     uint32_t                        cPorts;
    /** The number of available ports (0..cPorts). */
00777     uint32_t                        cAvailablePorts;
    /** The driver instance of the hub. */
00779     PPDMDRVINS                      pDrvIns;
    /** Copy of the to the registration structure. */
00781     PDMUSBHUBREG                    Reg;

    /** Pointer to the next hub in the list. */
00784     struct PDMUSBHUB               *pNext;
} PDMUSBHUB;

/** Pointer to a const USB HUB registration record. */
00788 typedef const PDMUSBHUB *PCPDMUSBHUB;

/** Pointer to a PDM Async I/O template. */
00791 typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;

/** Pointer to the main PDM Async completion structure. */
00794 typedef struct PDMASYNCCOMPLETIONMANAGER *PPDMASYNCCOMPLETIONMANAGER;

/**
 * Converts a PDM pointer into a VM pointer.
 * @returns Pointer to the VM structure the PDM is part of.
 * @param   pPDM   Pointer to PDM instance data.
 */
00801 #define PDM2VM(pPDM)  ( (PVM)((char*)pPDM - pPDM->offVM) )


/**
 * PDM VM Instance data.
 * Changes to this must checked against the padding of the cfgm union in VM!
 */
00808 typedef struct PDM
{
    /** Offset to the VM structure.
     * See PDM2VM(). */
00812     RTUINT                          offVM;
00813     RTUINT                          uPadding0; /**< Alignment padding.*/

    /** List of registered devices. (FIFO) */
    R3PTRTYPE(PPDMDEV)              pDevs;
    /** List of devices instances. (FIFO) */
    R3PTRTYPE(PPDMDEVINS)           pDevInstances;
    /** List of registered USB devices. (FIFO) */
    R3PTRTYPE(PPDMUSB)              pUsbDevs;
    /** List of USB devices instances. (FIFO) */
    R3PTRTYPE(PPDMUSBINS)           pUsbInstances;
    /** List of registered drivers. (FIFO) */
    R3PTRTYPE(PPDMDRV)              pDrvs;
    /** List of initialized critical sections. (LIFO) */
    R3PTRTYPE(PPDMCRITSECTINT)      pCritSects;
    /** PCI Buses. */
00828     PDMPCIBUS                       aPciBuses[PDM_PCI_BUSSES_MAX];
    /** The register PIC device. */
00830     PDMPIC                          Pic;
    /** The registerd APIC device. */
00832     PDMAPIC                         Apic;
    /** The registerd I/O APIC device. */
00834     PDMIOAPIC                       IoApic;
    /** The registered DMAC device. */
    R3PTRTYPE(PPDMDMAC)             pDmac;
    /** The registered RTC device. */
    R3PTRTYPE(PPDMRTC)              pRtc;
    /** The registered USB HUBs. (FIFO) */
    R3PTRTYPE(PPDMUSBHUB)           pUsbHubs;

    /** Queue in which devhlp tasks are queued for R3 execution - R3 Ptr. */
    R3PTRTYPE(PPDMQUEUE)            pDevHlpQueueR3;
    /** Queue in which devhlp tasks are queued for R3 execution - R0 Ptr. */
    R0PTRTYPE(PPDMQUEUE)            pDevHlpQueueR0;
    /** Queue in which devhlp tasks are queued for R3 execution - RC Ptr. */
    RCPTRTYPE(PPDMQUEUE)            pDevHlpQueueRC;

    /** The number of entries in the apQueuedCritSectsLeaves table that's currnetly in use. */
00850     RTUINT                          cQueuedCritSectLeaves;
    /** Critical sections queued in RC/R0 because of contention preventing leave to complete. (R3 Ptrs)
     * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
    R3PTRTYPE(PPDMCRITSECT)         apQueuedCritSectsLeaves[8];

    /** Linked list of timer driven PDM queues. */
    R3PTRTYPE(struct PDMQUEUE *)    pQueuesTimer;
    /** Linked list of force action driven PDM queues. */
    R3PTRTYPE(struct PDMQUEUE *)    pQueuesForced;
    /** Pointer to the queue which should be manually flushed - R0 Ptr.
     * Only touched by EMT. */
    R0PTRTYPE(struct PDMQUEUE *)    pQueueFlushR0;
    /** Pointer to the queue which should be manually flushed - RC Ptr.
     * Only touched by EMT. */
    RCPTRTYPE(struct PDMQUEUE *)    pQueueFlushRC;
#if HC_ARCH_BITS == 64
    RTRCPTR                         padding0;
#endif

    /** Head of the PDM Thread list. (singly linked) */
    R3PTRTYPE(PPDMTHREAD)           pThreads;
    /** Tail of the PDM Thread list. (singly linked) */
    R3PTRTYPE(PPDMTHREAD)           pThreadsTail;

    /** Head of the asychronous tasks managers. (singly linked) */
    R3PTRTYPE(PPDMASYNCCOMPLETIONMANAGER) pAsyncCompletionManagerHead;
    /** Head of the templates. (singly linked) */
    R3PTRTYPE(PPDMASYNCCOMPLETIONTEMPLATE) pAsyncCompletionTemplates;

    /** @name   VMM device heap
     * @{ */
    /** Pointer to the heap base (MMIO2 ring-3 mapping). NULL if not registered. */
00882     RTR3PTR                         pvVMMDevHeap;
    /** The heap size. */
00884     RTUINT                          cbVMMDevHeap;
    /** Free space. */
00886     RTUINT                          cbVMMDevHeapLeft;
    /** The current mapping. NIL_RTGCPHYS if not mapped or registered. */
00888     RTGCPHYS                        GCPhysVMMDevHeap;
    /** @} */

    /** TEMPORARY HACKS FOR NETWORK POLLING.
     * @todo fix NAT and kill this!
     * @{ */
00894     RTUINT                          cPollers;
#if HC_ARCH_BITS == 64
    RTUINT                          padding1;
#endif
    R3PTRTYPE(PFNPDMDRVPOLLER)      apfnPollers[16];
    R3PTRTYPE(PPDMDRVINS)           aDrvInsPollers[16];
    PTMTIMERR3                      pTimerPollers;
    /** @} */

    /** The PDM lock.
     * This is used to protect everything that deals with interrupts, i.e.
     * the PIC, APIC, IOAPIC and PCI devices pluss some PDM functions. */
00906     PDMCRITSECT                     CritSect;

    /** Number of times a critical section leave requesed needed to be queued for ring-3 execution. */
00909     STAMCOUNTER                     StatQueuedCritSectLeaves;
} PDM;
/** Pointer to PDM VM instance data. */
00912 typedef PDM *PPDM;


/**
 * PDM data kept in the UVM.
 */
00918 typedef struct PDMUSERPERVM
{
    /** Pointer to list of loaded modules. */
00921     PPDMMOD                         pModules;
    /** @todo move more stuff over here. */
} PDMUSERPERVM;
/** Pointer to the PDM data kept in the UVM. */
00925 typedef PDMUSERPERVM *PPDMUSERPERVM;



/*******************************************************************************
*   Global Variables                                                           *
*******************************************************************************/
#ifdef IN_RING3
extern const PDMDRVHLP      g_pdmR3DrvHlp;
extern const PDMDEVHLPR3    g_pdmR3DevHlpTrusted;
extern const PDMDEVHLPR3    g_pdmR3DevHlpUnTrusted;
extern const PDMPICHLPR3    g_pdmR3DevPicHlp;
extern const PDMAPICHLPR3   g_pdmR3DevApicHlp;
extern const PDMIOAPICHLPR3 g_pdmR3DevIoApicHlp;
extern const PDMPCIHLPR3    g_pdmR3DevPciHlp;
extern const PDMDMACHLP     g_pdmR3DevDmacHlp;
extern const PDMRTCHLP      g_pdmR3DevRtcHlp;
#endif


/*******************************************************************************
*   Defined Constants And Macros                                               *
*******************************************************************************/
/** @def PDMDEV_ASSERT_DEVINS
 * Asserts the validity of the device instance.
 */
#ifdef VBOX_STRICT
# define PDMDEV_ASSERT_DEVINS(pDevIns)   \
    do { \
        AssertPtr(pDevIns); \
        Assert(pDevIns->u32Version == PDM_DEVINS_VERSION); \
        Assert(pDevIns->CTX_SUFF(pvInstanceData) == (void *)&pDevIns->achInstanceData[0]); \
    } while (0)
#else
00959 # define PDMDEV_ASSERT_DEVINS(pDevIns)   do { } while (0)
#endif


/*******************************************************************************
*   Internal Functions                                                         *
*******************************************************************************/
#ifdef IN_RING3
int         pdmR3CritSectInit(PVM pVM);
int         pdmR3CritSectTerm(PVM pVM);
void        pdmR3CritSectRelocate(PVM pVM);
int         pdmR3CritSectInitDevice(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, const char *pszName);
int         pdmR3CritSectDeleteDevice(PVM pVM, PPDMDEVINS pDevIns);

int         pdmR3DevInit(PVM pVM);
PPDMDEV     pdmR3DevLookup(PVM pVM, const char *pszName);
int         pdmR3DevFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
DECLCALLBACK(bool) pdmR3DevHlpQueueConsumer(PVM pVM, PPDMQUEUEITEMCORE pItem);

int         pdmR3UsbLoadModules(PVM pVM);
int         pdmR3UsbInstantiateDevices(PVM pVM);
PPDMUSB     pdmR3UsbLookup(PVM pVM, const char *pszName);
int         pdmR3UsbFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
int         pdmR3UsbRegisterHub(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp);
int         pdmR3UsbVMInitComplete(PVM pVM);

int         pdmR3DrvInit(PVM pVM);
int         pdmR3DrvDetach(PPDMDRVINS pDrvIns);
void        pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns);
PPDMDRV     pdmR3DrvLookup(PVM pVM, const char *pszName);

int         pdmR3LdrInitU(PUVM pUVM);
void        pdmR3LdrTermU(PUVM pUVM);
char *      pdmR3FileR3(const char *pszFile, bool fShared = false);
int         pdmR3LoadR3U(PUVM pUVM, const char *pszFilename, const char *pszName);

void        pdmR3QueueRelocate(PVM pVM, RTGCINTPTR offDelta);

int         pdmR3ThreadCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
                                    PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
int         pdmR3ThreadCreateUsb(PVM pVM, PPDMDRVINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
                                 PFNPDMTHREADWAKEUPUSB pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
int         pdmR3ThreadCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
                                    PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
int         pdmR3ThreadDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
int         pdmR3ThreadDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
int         pdmR3ThreadDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
void        pdmR3ThreadDestroyAll(PVM pVM);
int         pdmR3ThreadResumeAll(PVM pVM);
int         pdmR3ThreadSuspendAll(PVM pVM);

#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
int         pdmR3AsyncCompletionInit(PVM pVM);
int         pdmR3AsyncCompletionTerm(PVM pVM);
#endif

#endif /* IN_RING3 */

void        pdmLock(PVM pVM);
int         pdmLockEx(PVM pVM, int rc);
void        pdmUnlock(PVM pVM);

/** @} */

__END_DECLS

#endif

Generated by  Doxygen 1.6.0   Back to index