PDMInternal.h revision baa99076e1be974e65c769fd5c958f75a8164286
/* $Id$ */
/** @file
* PDM - Internal header file.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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.
*/
#ifndef ___PDMInternal_h
#define ___PDMInternal_h
#include <VBox/pdmasynccompletion.h>
#include <iprt/critsect.h>
#ifdef IN_RING3
#endif
/** @defgroup grp_pdm_int Internal
* @ingroup grp_pdm
* @internal
* @{
*/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** Pointer to a PDM Device. */
/** Pointer to a pointer to a PDM Device. */
/** Pointer to a PDM USB Device. */
/** Pointer to a pointer to a PDM USB Device. */
/** Pointer to a PDM Driver. */
/** Pointer to a pointer to a PDM Driver. */
/** Pointer to a PDM Logical Unit. */
/** Pointer to a pointer to a PDM Logical Unit. */
/** Pointer to a PDM PCI Bus instance. */
typedef struct PDMPCIBUS *PPDMPCIBUS;
/** Pointer to a DMAC instance. */
/** Pointer to a RTC instance. */
/** Pointer to an USB HUB registration record. */
typedef struct PDMUSBHUB *PPDMUSBHUB;
/**
* Private device instance data.
*/
typedef struct PDMDEVINSINT
{
/** Pointer to the next instance (HC Ptr).
* (Head is pointed to by PDM::pDevInstances.) */
/** Pointer to the next per device instance (HC Ptr).
* (Head is pointed to by PDMDEV::pInstances.) */
/** Pointer to device structure - HC Ptr. */
/** Pointer to the VM this instance was created for - HC Ptr. */
/** Pointer to the list of logical units associated with the device. (FIFO) */
/** Configuration handle to the instance node. */
/** HC pointer to associated PCI device structure. */
/** HC pointer to associated PCI bus structure. */
/** GC pointer to associated PCI device structure. */
/** Pointer to the VM this instance was created for - GC Ptr. */
/** GC pointer to associated PCI bus structure. */
#if GC_ARCH_BITS == 32
#endif
} PDMDEVINSINT;
/**
* Private USB device instance data.
*/
typedef struct PDMUSBINSINT
{
/** The UUID of this instance. */
/** Pointer to the next instance.
* (Head is pointed to by PDM::pUsbInstances.) */
/** Pointer to the next per USB device instance.
* (Head is pointed to by PDMUSB::pInstances.) */
/** Pointer to device structure. */
/** Pointer to the VM this instance was created for. */
/** Pointer to the list of logical units associated with the device. (FIFO) */
/** The per instance device configuration. */
/** Same as pCfg if the configuration should be deleted when detaching the device. */
/** The global device configuration. */
/** Pointer to the USB hub this device is attached to.
* This is NULL if the device isn't connected to any HUB. */
/** The port number that we're connected to. */
#if HC_ARCH_BITS == 64
#endif
} PDMUSBINSINT;
/**
* Private driver instance data.
*/
typedef struct PDMDRVINSINT
{
/** Pointer to the driver instance above.
* This is NULL for the topmost drive. */
/** Pointer to the driver instance below.
* This is NULL for the bottommost driver. */
/** Pointer to the logical unit this driver chained on. */
/** Pointer to driver structure from which this was instantiated. */
/** Pointer to the VM this instance was created for. */
/** Flag indicating that the driver is being detached and destroyed.
* (Helps detect potential recursive detaching.) */
bool fDetaching;
/** Configuration handle to the instance node. */
} PDMDRVINSINT;
/**
* Private critical section data.
*/
typedef struct PDMCRITSECTINT
{
/** The critical section core which is shared with IPRT. */
/** Pointer to the next critical section.
* This chain is used for relocating pVMGC and device cleanup. */
/** 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. */
/** Pointer to the VM - R3Ptr. */
/** Pointer to the VM - R0Ptr. */
/** Pointer to the VM - GCPtr. */
#endif
/** Event semaphore that is scheduled to be signaled upon leaving the
* critical section. This is Ring-3 only of course. */
/** R3 lock contention. */
/** Profiling the time the section is locked. */
/**
*/
typedef enum
{
/** The usual invalid entry. */
/** Device type. */
/** USB Device type. */
/** Driver type. */
/** Internal type. */
/** External type. */
/** The usual 32-bit hack. */
PDMTHREADTYPE_32BIT_HACK = 0x7fffffff
/**
* The internal structure for the thread.
*/
typedef struct PDMTHREADINT
{
/** The VM pointer. */
/** The event semaphore the thread blocks on. */
/** Pointer to the next thread. */
/** The thread type. */
} 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
/**
* 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::pLunsHC).
*/
typedef struct PDMLUN
{
/** The LUN - The Logical Unit Number. */
/** Pointer to the next LUN. */
/** Pointer to the top driver in the driver chain. */
/** Pointer to the bottom driver in the driver chain. */
/** 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. */
/** Pointer to the USB device instance which the LUN belongs to. */
/** Pointer to the device base interface. */
/** Description of this LUN. */
const char *pszDesc;
} PDMLUN;
/**
* PDM Device.
*/
typedef struct PDMDEV
{
/** Pointer to the next device (HC Ptr). */
/** Device name length. (search optimization) */
/** Registration structure. */
/** Number of instances. */
/** Pointer to chain of instances (HC Ptr). */
} PDMDEV;
/**
* PDM USB Device.
*/
typedef struct PDMUSB
{
/** Pointer to the next device (R3 Ptr). */
/** Device name length. (search optimization) */
/** Registration structure. */
/** Next instance number. */
/** Pointer to chain of instances (R3 Ptr). */
} PDMUSB;
/**
* PDM Driver.
*/
typedef struct PDMDRV
{
/** Pointer to the next device. */
/** Registration structure. */
/** Number of instances. */
} PDMDRV;
/**
* PDM registered PIC device.
*/
typedef struct PDMPIC
{
/** Pointer to the PIC device instance - HC. */
/** @copydoc PDMPICREG::pfnSetIrqHC */
/** @copydoc PDMPICREG::pfnGetInterruptHC */
/** Pointer to the PIC device instance - R0. */
/** @copydoc PDMPICREG::pfnSetIrqHC */
/** @copydoc PDMPICREG::pfnGetInterruptHC */
/** Pointer to the PIC device instance - GC. */
/** @copydoc PDMPICREG::pfnSetIrqHC */
/** @copydoc PDMPICREG::pfnGetInterruptHC */
#if GC_ARCH_BITS == 32
#endif
} PDMPIC;
/**
* PDM registered APIC device.
*/
typedef struct PDMAPIC
{
/** Pointer to the APIC device instance - HC Ptr. */
/** @copydoc PDMAPICREG::pfnGetInterruptHC */
/** @copydoc PDMAPICREG::pfnSetBaseHC */
/** @copydoc PDMAPICREG::pfnGetBaseHC */
/** @copydoc PDMAPICREG::pfnSetTPRHC */
/** @copydoc PDMAPICREG::pfnGetTPRHC */
/** @copydoc PDMAPICREG::pfnBusDeliverHC */
DECLR3CALLBACKMEMBER(void, pfnBusDeliverR3,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
/** Pointer to the PIC device instance - R0. */
/** @copydoc PDMAPICREG::pfnGetInterruptHC */
/** @copydoc PDMAPICREG::pfnSetBaseHC */
/** @copydoc PDMAPICREG::pfnGetBaseHC */
/** @copydoc PDMAPICREG::pfnSetTPRHC */
/** @copydoc PDMAPICREG::pfnGetTPRHC */
/** @copydoc PDMAPICREG::pfnBusDeliverHC */
DECLR0CALLBACKMEMBER(void, pfnBusDeliverR0,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
/** Pointer to the APIC device instance - GC Ptr. */
/** @copydoc PDMAPICREG::pfnGetInterruptHC */
/** @copydoc PDMAPICREG::pfnSetBaseHC */
/** @copydoc PDMAPICREG::pfnGetBaseHC */
/** @copydoc PDMAPICREG::pfnSetTPRHC */
/** @copydoc PDMAPICREG::pfnGetTPRHC */
/** @copydoc PDMAPICREG::pfnBusDeliverHC */
DECLGCCALLBACKMEMBER(void, pfnBusDeliverGC,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
#if GC_ARCH_BITS == 32
#endif
} PDMAPIC;
/**
* PDM registered I/O APIC device.
*/
typedef struct PDMIOAPIC
{
/** Pointer to the APIC device instance - HC Ptr. */
/** @copydoc PDMIOAPICREG::pfnSetIrqHC */
/** Pointer to the PIC device instance - R0. */
/** @copydoc PDMIOAPICREG::pfnSetIrqHC */
/** Pointer to the APIC device instance - GC Ptr. */
/** @copydoc PDMIOAPICREG::pfnSetIrqHC */
} PDMIOAPIC;
/**
* PDM PCI Bus instance.
*/
typedef struct PDMPCIBUS
{
/** PCI bus number. */
/** Pointer to PCI Bus device instance. */
/** @copydoc PDMPCIBUSREG::pfnSetIrqHC */
DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
/** @copydoc PDMPCIBUSREG::pfnRegisterHC */
DECLR3CALLBACKMEMBER(int, pfnRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev));
/** @copydoc PDMPCIBUSREG::pfnIORegionRegisterHC */
DECLR3CALLBACKMEMBER(int, pfnIORegionRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion,
/** @copydoc PDMPCIBUSREG::pfnSetConfigCallbacksHC */
DECLR3CALLBACKMEMBER(void, pfnSetConfigCallbacksR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead,
/** @copydoc PDMPCIBUSREG::pfnSaveExecHC */
DECLR3CALLBACKMEMBER(int, pfnSaveExecR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
/** @copydoc PDMPCIBUSREG::pfnLoadExecHC */
DECLR3CALLBACKMEMBER(int, pfnLoadExecR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
/** @copydoc PDMPCIBUSREG::pfnFakePCIBIOSHC */
/** Pointer to the PIC device instance - R0. */
/** @copydoc PDMPCIBUSREG::pfnSetIrqHC */
DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
/** Pointer to PCI Bus device instance. */
/** @copydoc PDMPCIBUSREG::pfnSetIrqHC */
DECLGCCALLBACKMEMBER(void, pfnSetIrqGC,(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. */
/** Copy of the registration structure. */
} PDMDMAC;
/**
* PDM registered RTC (Real Time Clock) device.
*/
typedef struct PDMRTC
{
/** Pointer to the RTC device instance. */
/** Copy of the registration structure. */
} PDMRTC;
#endif /* IN_RING3 */
/**
* Module type.
*/
typedef enum PDMMODTYPE
{
/** Guest context module. */
/** Ring-0 (host) context module. */
/** Ring-3 (host) context module. */
} PDMMODTYPE, *PPDMMODTYPE;
/** The module name length including the terminator. */
#define PDMMOD_NAME_LEN 32
/**
* Loaded module instance.
*/
typedef struct PDMMOD
{
/** Module name. This is used for refering to
* the module internally, sort of like a handle. */
char szName[PDMMOD_NAME_LEN];
/** Module type. */
/** Loader module handle. Not used for R0 modules. */
/** Loaded address.
* This is the 'handle' for R0 modules. */
/** Old loaded address.
* This is used during relocation of GC modules. Not used for R0 modules. */
/** Where the R3 HC bits are stored.
* This can be equal to ImageBase but doesn't have to. Not used for R0 modules. */
void *pvBits;
/** Pointer to next module. */
/** Module filename. */
char szFilename[1];
} PDMMOD;
/** Pointer to loaded module instance. */
/** Extra space in the free array. */
#define PDMQUEUE_FREE_SLACK 16
/**
* Queue type.
*/
typedef enum PDMQUEUETYPE
{
/** Device consumer. */
PDMQUEUETYPE_DEV = 1,
/** Driver consumer. */
/** Internal consumer. */
/** External consumer. */
} PDMQUEUETYPE;
/** Pointer to a PDM Queue. */
/**
* PDM Queue.
*/
typedef struct PDMQUEUE
{
/** Pointer to the next queue in the list. */
/** Type specific data. */
union
{
/** PDMQUEUETYPE_DEV */
struct
{
/** Pointer to consumer function. */
/** Pointer to the device instance owning the queue. */
} Dev;
/** PDMQUEUETYPE_DRV */
struct
{
/** Pointer to consumer function. */
/** Pointer to the driver instance owning the queue. */
} Drv;
/** PDMQUEUETYPE_INTERNAL */
struct
{
/** Pointer to consumer function. */
} Int;
/** PDMQUEUETYPE_EXTERNAL */
struct
{
/** Pointer to consumer function. */
/** Pointer to user argument. */
} Ext;
} u;
/** Queue type. */
/** 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. */
/** Interval timer. Only used if cMilliesInterval is non-zero. */
/** Pointer to the VM. */
/** LIFO of pending items - HC. */
/** Pointer to the GC VM and indicator for GC enabled queue.
* If this is NULL, the queue cannot be used in GC.
*/
/** LIFO of pending items - GC. */
/** Item size (bytes). */
/** Number of items in the queue. */
/** Index to the free head (where we insert). */
/** Index to the free tail (where we remove). */
/** Array of pointers to free items. Variable size. */
struct PDMQUEUEFREEITEM
{
/** Pointer to the free item - HC Ptr. */
/** Pointer to the free item - GC Ptr. */
#endif
} aFreeItems[1];
} PDMQUEUE;
/**
* Queue device helper task operation.
*/
typedef enum PDMDEVHLPTASKOP
{
/** The usual invalid 0 entry. */
/** ISASetIrq */
/** PCISetIrq */
/** PCISetIrq */
/** The usual 32-bit hack. */
PDMDEVHLPTASKOP_32BIT_HACK = 0x7fffffff
/**
* Queued Device Helper Task.
*/
typedef struct PDMDEVHLPTASK
{
/** The queue item core (don't touch). */
/** Pointer to the device instance (HC Ptr). */
/** This operation to perform. */
#if HC_ARCH_BITS == 64
#endif
/** Parameters to the operation. */
union PDMDEVHLPTASKPARAMS
{
/**
* PDMDEVHLPTASKOP_ISA_SET_IRQ and PDMDEVHLPTASKOP_PCI_SET_IRQ.
*/
struct PDMDEVHLPTASKSETIRQ
{
/** The IRQ */
int iIrq;
/** The new level. */
int iLevel;
} SetIRQ;
} u;
/** Pointer to a queued Device Helper Task. */
typedef PDMDEVHLPTASK *PPDMDEVHLPTASK;
/** Pointer to a const queued Device Helper Task. */
typedef const PDMDEVHLPTASK *PCPDMDEVHLPTASK;
/**
* An USB hub registration record.
*/
typedef struct PDMUSBHUB
{
/** The USB versions this hub support.
* Note that 1.1 hubs can take on 2.0 devices. */
/** The number of ports on the hub. */
/** The number of available ports (0..cPorts). */
/** The driver instance of the hub. */
/** Copy of the to the registration structure. */
/** Pointer to the next hub in the list. */
} PDMUSBHUB;
/** Pointer to a const USB HUB registration record. */
typedef const PDMUSBHUB *PCPDMUSBHUB;
/** Pointer to a PDM Async I/O template. */
typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;
/** Pointer to the main PDM Async completion structure. */
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.
*/
/**
* PDM VM Instance data.
* Changes to this must checked against the padding of the cfgm union in VM!
*/
typedef struct PDM
{
/** Offset to the VM structure.
* See PDM2VM(). */
/** Pointer to list of loaded modules. This is HC only! */
/** List of registered devices. (FIFO) */
/** List of devices instances. (FIFO) */
/** List of registered USB devices. (FIFO) */
/** List of USB devices instances. (FIFO) */
/** List of registered drivers. (FIFO) */
/** List of initialized critical sections. (LIFO) */
/** PCI Buses. */
/** The register PIC device. */
/** The registerd APIC device. */
/** The registerd I/O APIC device. */
/** The registered DMAC device. */
/** The registered RTC device. */
/** The registered USB HUBs. (FIFO) */
/** Queue in which devhlp tasks are queued for R3 execution - HC Ptr. */
/** Queue in which devhlp tasks are queued for R3 execution - GC Ptr. */
/** The number of entries in the apQueuedCritSectsLeaves table that's currnetly in use. */
* We will return to Ring-3 ASAP, so this queue doesn't has to be very long. */
/** Linked list of timer driven PDM queues. */
/** Linked list of force action driven PDM queues. */
/** Pointer to the queue which should be manually flushed - HCPtr.
* Only touched by EMT. */
/** Pointer to the queue which should be manually flushed - GCPtr. */
#if HC_ARCH_BITS == 64
#endif
/** Head of the PDM Thread list. (singly linked) */
/** Tail of the PDM Thread list. (singly linked) */
/** Head of the asychronous tasks managers. (singly linked) */
/** Head of the templates. (singly linked) */
/** TEMPORARY HACKS FOR NETWORK POLLING.
* @todo fix NAT and kill this!
* @{ */
#if HC_ARCH_BITS == 64
#endif
/** @} */
#ifdef VBOX_WITH_PDM_LOCK
/** 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. */
#endif
/** Number of times a critical section leave requesed needed to be queued for ring-3 execution. */
} PDM;
/** Pointer to PDM VM instance data. */
/*******************************************************************************
* Global Variables *
*******************************************************************************/
#ifdef IN_RING3
extern const PDMDRVHLP g_pdmR3DrvHlp;
#endif
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
#ifdef IN_RING3
int pdmR3CritSectInitDevice(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, const char *pszName);
int pdmR3DevFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
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 pdmR3ThreadCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
int pdmR3ThreadCreateUsb(PVM pVM, PPDMDRVINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
int pdmR3ThreadCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
#endif
#endif /* IN_RING3 */
#ifdef VBOX_WITH_PDM_LOCK
#else
#endif
/** @} */
#endif