VUSBInternal.h revision 1cd0e554b1a529ae3f15b44277391f74610cd23d
/* $Id$ */
/** @file
* Virtual USB - Internal header.
*
* This subsystem implements USB devices in a host controller independent
* way. All the host controller code has to do is use VUSBHUB for its
* root hub implementation and any emulated USB device may be plugged into
* the virtual bus.
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* 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.
*/
#ifndef ___VUSBInternal_h
#define ___VUSBInternal_h
#include <iprt/queueatomic.h>
/** @name Internal Device Operations, Structures and Constants.
* @{
*/
/** Pointer to a Virtual USB device (core). */
/** Pointer to a VUSB hub device. */
/** Pointer to a VUSB root hub. */
typedef struct VUSBROOTHUB *PVUSBROOTHUB;
/** Number of the default control endpoint */
#define VUSB_PIPE_DEFAULT 0
/** @name Device addresses
* @{ */
#define VUSB_DEFAULT_ADDRESS 0
/** @} */
/** @name Feature bits (1<<FEATURE for the u16Status bit)
* @{ */
#define VUSB_DEV_SELF_POWERED 0
#define VUSB_DEV_REMOTE_WAKEUP 1
#define VUSB_EP_HALT 0
/** @} */
/** Maximum number of endpoint addresses */
#define VUSB_PIPE_MAX 16
/**
* Control-pipe stages.
*/
typedef enum CTLSTAGE
{
/** the control pipe is in the setup stage. */
CTLSTAGE_SETUP = 0,
/** the control pipe is in the data stage. */
/** the control pipe is in the status stage. */
} CTLSTAGE;
/**
* Extra data for a control pipe.
*
* This is state information needed for the special multi-stage
* transfers performed on this kind of pipes.
*/
typedef struct vusb_ctrl_extra
{
/** Current pipe stage. */
/** Success indicator. */
bool fOk;
/** Set if the message URB has been submitted. */
bool fSubmitted;
/** Pointer to the SETUP.
* This is a pointer to Urb->abData[0]. */
/** Current DATA pointer.
/** The amount of data left to read on IN operations.
* On OUT operations this is not used. */
/** The amount of data we can house.
* This starts at the default 8KB, and this structure will be reallocated to
* accommodate any larger request (unlikely). */
/** The message URB. */
/**
* A VUSB pipe
*/
typedef struct vusb_pipe
{
/** Pointer to the extra state data required to run a control pipe. */
/** Count of active async transfers. */
/** The periodic read-ahead buffer thread. */
/** Pointer to the reset thread arguments. */
void *pvReadAheadArgs;
/** Pointer to the first buffered URB. */
/** Pointer to the last buffered URB. */
/** Count of URBs in read-ahead buffer. */
/** Count of URBs submitted for read-ahead but not yet reaped. */
} VUSBPIPE;
/** Pointer to a VUSB pipe structure. */
/**
* Interface state and possible settings.
*/
typedef struct vusb_interface_state
{
/** Pointer to the interface descriptor of the currently selected (active)
* interface. */
/** Pointer to the interface settings. */
/** Pointer to interface state. */
typedef VUSBINTERFACESTATE *PVUSBINTERFACESTATE;
/** Pointer to const interface state. */
typedef const VUSBINTERFACESTATE *PCVUSBINTERFACESTATE;
/**
* A Virtual USB device (core).
*
* @implements VUSBIDEVICE
*/
typedef struct VUSBDEV
{
/** The device interface exposed to the HCI. */
/** Pointer to the PDM USB device instance. */
/** Next device in the chain maintained by the roothub. */
/** Pointer to the next device with the same address hash. */
/** Pointer to the hub this device is attached to. */
/** The device state.
* Only EMT changes this value. */
VUSBDEVICESTATE volatile enmState;
/** The device address. */
/** The new device address. */
/** The port. */
/** Device status. (VUSB_DEV_SELF_POWERED or not.) */
/** Pointer to the descriptor cache.
* (Provided by the device thru the pfnGetDescriptorCache method.) */
/** Current configuration. */
/** Current interface state (including alternate interface setting) - maximum
* valid index is config->bNumInterfaces
*/
/** Dumper state. */
union VUSBDEVURBDUMPERSTATE
{
/** The current scsi command. */
} Urb;
/** The reset thread. */
/** Pointer to the reset thread arguments. */
void *pvResetArgs;
/** The reset timer handle. */
/** URB submit and reap thread. */
/** Queue of URBs to submit. */
/** Request queue for cancelling URBs on the I/O thread. */
/** Flag whether the URB I/O thread should terminate. */
bool volatile fTerminate;
/** Flag whether the I/O thread was woken up. */
bool volatile fWokenUp;
#if HC_ARCH_BITS == 32
/** Align the size to a 8 byte boundary. */
bool afAlignment0[6];
#endif
} VUSBDEV;
/** Pointer to the virtual method table for a kind of USB devices. */
typedef struct vusb_dev_ops *PVUSBDEVOPS;
/** Pointer to the const virtual method table for a kind of USB devices. */
typedef const struct vusb_dev_ops *PCVUSBDEVOPS;
/**
* Virtual method table for USB devices - these are the functions you need to
* implement when writing a new device (or hub)
*
* Note that when creating your structure, you are required to zero the
* vusb_dev fields (ie. use calloc).
*/
typedef struct vusb_dev_ops
{
/* mandatory */
const char *name;
} VUSBDEVOPS;
int vusbDevCreateOld(const char *pszDeviceName, void *pvDriverInit, PCRTUUID pUuid, PVUSBDEV *ppDev);
{
}
DECLCALLBACK(int) vusbDevReset(PVUSBIDEVICE pDevice, bool fResetOnLinux, PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM);
bool vusbDevStandardRequest(PVUSBDEV pDev, int EndPt, PVUSBSETUP pSetup, void *pvBuf, uint32_t *pcbBuf);
/** @} */
/** @name Internal Hub Operations, Structures and Constants.
* @{
*/
/** Virtual method table for USB hub devices.
* Hub and roothub drivers need to implement these functions in addition to the
* vusb_dev_ops.
*/
typedef struct VUSBHUBOPS
{
} VUSBHUBOPS;
/** Pointer to a const HUB method table. */
typedef const VUSBHUBOPS *PCVUSBHUBOPS;
/** A VUSB Hub Device - Hub and roothub drivers need to use this struct
* @todo eliminate this (PDM / roothubs only).
*/
typedef struct VUSBHUB
{
/** Name of the hub. Used for logging. */
char *pszName;
} VUSBHUB;
/** @} */
/** @name Internal Root Hub Operations, Structures and Constants.
* @{
*/
/**
* Per transfer type statistics.
*/
typedef struct VUSBROOTHUBTYPESTATS
{
/** The address hash table size. */
#define VUSB_ADDR_HASHSZ 5
/**
* The instance data of a root hub driver.
*
* This extends the generic VUSB hub.
*
* @implements VUSBIROOTHUBCONNECTOR
*/
typedef struct VUSBROOTHUB
{
/** The HUB.
* @todo remove this? */
#if HC_ARCH_BITS == 32
#endif
/** Address hash table. */
/** List of async URBs. */
/** The default address. */
/** Pointer to the driver instance. */
/** Pointer to the root hub port interface we're attached to. */
/** Connector interface exposed upwards. */
/** Chain of devices attached to this hub. */
/** Availability Bitmap. */
/** Critical section protecting the free list. */
/** Chain of free URBs. (Singly linked) */
/** The number of URBs in the pool. */
/** Version of the attached Host Controller. */
#ifdef VBOX_WITH_STATISTICS
#if HC_ARCH_BITS == 32
#endif
struct
{
} aStatIsocDetails[8];
#endif
} VUSBROOTHUB;
#ifdef VBOX_WITH_STATISTICS
#endif
/** Converts a pointer to VUSBROOTHUB::IRhConnector to a PVUSBROOTHUB. */
#define VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface) (PVUSBROOTHUB)( (uintptr_t)(pInterface) - RT_OFFSETOF(VUSBROOTHUB, IRhConnector) )
/**
* URB cancellation modes
*/
typedef enum CANCELMODE
{
/** complete the URB with an error (CRC). */
CANCELMODE_FAIL = 0,
/** do not change the URB contents. */
} CANCELMODE;
/* @} */
/** @name Internal URB Operations, Structures and Constants.
* @{ */
void vusbReadAheadStop(void *pvReadAheadArgs);
{
}
/** @def vusbUrbAssert
* Asserts that a URB is valid.
*/
#ifdef VBOX_STRICT
# define vusbUrbAssert(pUrb) do { \
} while (0)
#else
# define vusbUrbAssert(pUrb) do {} while (0)
#endif
/** @} */
/**
* Addresses are between 0 and 127 inclusive
*/
{
return u8Hash;
}
/**
* Gets the roothub of a device.
*
* @returns Pointer to the roothub instance the device is attached to.
* @returns NULL if not attached to any hub.
* @param pDev Pointer to the device in question.
*/
{
return NULL;
}
/** Strings for the CTLSTAGE enum values. */
extern const char * const g_apszCtlStates[4];
/** Default message pipe. */
extern const VUSBDESCENDPOINTEX g_Endpoint0;
/** Default configuration. */
extern const VUSBDESCCONFIGEX g_Config0;
#endif