The Pedigree Project 0.1
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
UsbMassStorageDevice Class Reference
+ Inheritance diagram for UsbMassStorageDevice:
+ Collaboration diagram for UsbMassStorageDevice:

Classes

struct  Cbw
 
struct  Csw
 

Public Member Functions

 UsbMassStorageDevice (UsbDevice *dev)
 
virtual void initialiseDriver ()
 Implemented by the driver class, initialises driver-specific stuff.
 
void prepareForDisconnection () override
 
virtual bool sendCommand (size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite)
 
virtual void getUsbDeviceName (String &str)
 
virtual bool hasSubtree () const
 Do we expose our own Device tree?
 
virtual Device * getDevice ()
 
- Public Member Functions inherited from ScsiController
 ScsiController (Controller *pDev, bool startWorker=true)
 
bool prepareDiskRemoval ()
 
void cancelDiskRemoval ()
 
virtual bool supportsConcurrentReads () const
 
virtual uint64_t executeRequest (uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8)
 
- Public Member Functions inherited from Controller
 Controller (Device *pDev)
 
virtual Type getType ()
 
virtual void getName (String &str)
 
virtual void dump (String &str)
 
- Public Member Functions inherited from Device
 Device (Device *p)
 
Device * getParent () const
 
void setParent (Device *p)
 
virtual const String & getSpecificType ()
 
virtual void setSpecificType (String str)
 
void setPciPosition (uint32_t bus, uint32_t device, uint32_t func)
 
void setPciIdentifiers (uint8_t classCode, uint8_t subclassCode, uint16_t vendorId, uint16_t deviceId, uint8_t progIf)
 
void setPciConfigHeader (const PciBus::ConfigSpace &space)
 
PciBus::ConfigSpace getPciConfigHeader () const
 
uint8_t getPciClassCode ()
 
uint8_t getPciSubclassCode ()
 
uint16_t getPciVendorId ()
 
uint16_t getPciDeviceId ()
 
uint8_t getPciProgInterface ()
 
uint32_t getPciBusPosition ()
 
uint32_t getPciDevicePosition ()
 
uint32_t getPciFunctionNumber ()
 
Device * getPhysicalFunction () const
 
size_t getVirtualFunctionIndex () const
 
void setVirtualFunction (Device *physicalFunction, size_t index)
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
Device * getChild (size_t n)
 
size_t getNumChildren ()
 
void removeChild (size_t n)
 
void removeChild (Device *d)
 
void replaceChild (Device *src, Device *dest)
 
- Public Member Functions inherited from RequestQueue
 RequestQueue (const String &name)
 
virtual void initialise ()
 
virtual void destroy ()
 
MUST_USE_RESULT uint64_t addRequest (size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
MUST_USE_RESULT uint64_t addRequest (size_t priority, ActionOnDuplicate action, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
uint64_t addAsyncRequest (size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
MUST_USE_RESULT bool publishAsyncRequest (size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
bool canWaitForCompletion ()
 
MUST_USE_RESULT bool waitForPreallocated (PreallocatedRequest &request)
 
MUST_USE_RESULT PreallocatedPublishResult publishPreallocated (PreallocatedRequest &request, size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
MUST_USE_RESULT PreallocatedPublishResult republishPreallocatedWhileReleasing (PreallocatedRequest &request, size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0)
 
MUST_USE_RESULT bool halt ()
 
MUST_USE_RESULT bool resume ()
 
LifecycleState getLifecycleState ()
 
bool drain ()
 
- Public Member Functions inherited from UsbDevice
 UsbDevice (UsbHub *pHub, uint8_t nPort, UsbSpeed speed)
 Default constructor.
 
 UsbDevice (UsbDevice *pDev)
 Copy constructor.
 
virtual ~UsbDevice ()
 Destructor.
 
void initialise (uint8_t nAddress)
 Initialises the device at the given address.
 
uint8_t getAddress ()
 Returns the current address of the device.
 
uint8_t getPort ()
 Returns the number of the port on which the device is connected.
 
UsbHub * getHub () const
 
UsbSpeed getSpeed ()
 Returns the speed at which the device operates.
 
UsbState getUsbState ()
 Returns the current state of the device.
 
DeviceDescriptor * getDescriptor ()
 Returns the device descriptor of the device.
 
ConfigDescriptor * getConfiguration ()
 Returns the configuration in use.
 
Interface * getInterface ()
 Returns the interface in use.
 
void useConfiguration (uint8_t nConfig)
 Switches to the given configuration.
 
void useInterface (uint8_t nInterface)
 Switches to the given interface.
 
UsbDeviceContainer * getContainer () const
 Gets our Device container, for replacing parents on hubs etc.
 
virtual void prepareForDriverRetirement ()
 
virtual void quiesceForRetirement ()
 

Protected Member Functions

virtual size_t getNumUnits ()
 
- Protected Member Functions inherited from ScsiController
virtual void cancelRequest (const Request &request)
 
void shutdownDiskCaches (bool deviceAvailable=true)
 
void searchDisks ()
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 
- Protected Member Functions inherited from RequestQueue
virtual bool workerPlacement (ThreadPlacement &) const
 
 RequestQueue (const RequestQueue &)
 
void operator= (const RequestQueue &)
 
virtual bool compareRequests (const Request &a, const Request &b)
 
int work ()
 
NextRequestResult getNextRequest (Request *&request)
 
bool drainIntakeLocked (size_t priority)
 
void publishRequest (Request *request)
 
Request * findDuplicate (const Request &request)
 
void discardRequest (Request *request)
 
uint64_t addAsyncRequestInternal (size_t priority, uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8)
 
PreallocatedPublishResult publishPreallocatedRequest (PreallocatedRequest &request, PreallocatedRequest::State availableState, size_t priority, uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8)
 
void releasePreallocatedRequest (Request *request)
 
void invokeCancelRequest (const Request &request)
 
bool callbackActiveOnCurrentThread () const
 
void releaseRequest (Request *request)
 
uint64_t waitForRequest (Request *request)
 
bool startWorker ()
 
bool stopWorker ()
 
void closePreallocatedAdmission ()
 
void waitForPreallocatedPublishers ()
 
- Protected Member Functions inherited from UsbDevice
ssize_t doSync (Endpoint *pEndpoint, UsbPid pid, uintptr_t pBuffer, size_t nBytes, size_t timeout)
 
ssize_t syncIn (Endpoint *pEndpoint, uintptr_t pBuffer, size_t nBytes, size_t timeout=5000)
 
ssize_t syncOut (Endpoint *pEndpoint, uintptr_t pBuffer, size_t nBytes, size_t timeout=5000)
 
MUST_USE_RESULT bool addInterruptInHandler (Endpoint *pEndpoint, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), UsbInterruptInHandle &handle, uintptr_t pParam=0)
 
bool controlRequest (uint8_t nRequestType, uint8_t nRequest, uint16_t nValue, uint16_t nIndex, uint16_t nLength=0, uintptr_t pBuffer=0, uint32_t timeout=5000)
 Performs an USB control request.
 
ssize_t controlRequestResult (uint8_t nRequestType, uint8_t nRequest, uint16_t nValue, uint16_t nIndex, uint16_t nLength=0, uintptr_t pBuffer=0, uint32_t timeout=5000)
 Returns data bytes transferred, or a negative UsbError.
 
uint16_t getStatus ()
 Gets device's current status.
 
bool clearEndpointHalt (Endpoint *pEndpoint)
 Clears a halt on the given endpoint.
 
void * getDescriptor (uint8_t nDescriptorType, uint8_t nDescriptorIndex, uint16_t nBytes, uint8_t requestType=0)
 Gets a descriptor from the device.
 
uint8_t getDescriptorLength (uint8_t nDescriptorType, uint8_t nDescriptorIndex, uint8_t requestType=0)
 Gets a descriptor's length from the device.
 
String getString (uint8_t nString)
 Gets a string.
 

Private Types

enum class  BotStatus { Passed , Failed , RecoveryRequired }
 
enum  MassStorageRequests { MassStorageRequest , MassStorageReset = 0xFF , MassStorageGetMaxLUN = 0xFE }
 
enum  MassStorageSigs { CbwSig = HOST_TO_LITTLE32(0x43425355) , CswSig = HOST_TO_LITTLE32(0x53425355) }
 

Private Member Functions

bool massStorageReset ()
 
MUST_USE_RESULT bool performResetRecovery ()
 
MUST_USE_RESULT BotStatus readStatus (uint32_t tag, uint32_t expectedBytes)
 

Private Attributes

struct UsbMassStorageDevice::Cbw PACKED
 
struct UsbMassStorageDevice::Csw PACKED
 
Mutex m_CommandLock
 
size_t m_nUnits
 
Endpoint * m_pInEndpoint
 
Endpoint * m_pOutEndpoint
 
uint32_t m_NextTag
 
bool m_ResetRecoveryRequired
 
bool m_DeviceAvailable
 

Additional Inherited Members

- Public Types inherited from Device
enum  Type {
  Generic , Root , Disk , Bus ,
  Display , Network , Sound , Console ,
  Mouse , Controller , UsbController , UsbGeneric ,
  UsbContainer
}
 
typedef Device *(* Callback) (Device *)
 
- Public Types inherited from RequestQueue
enum class  OverrunStatus { Clear , Armed , Stalled , Overloaded }
 
enum class  PreallocatedPublishResult {
  Accepted , TokenBusy , QueueStopped , QueueFull ,
  InvalidPriority
}
 
enum  ActionOnDuplicate { Block , NewRequest , ReturnImmediately }
 
enum class  LifecycleState { Stopped , Accepting , Stopping , Destroyed }
 
- Public Types inherited from UsbDevice
enum  UsbState {
  Connected = 0 , Addressed , HasDescriptors , Configured ,
  HasInterface , HasDriver
}
 Possible states for an USB device. More...
 
- Static Public Member Functions inherited from Device
static bool treeLockHeldByCurrentThread ()
 
static void foreach (Callback callback, Device *root=0)
 
template<class F , class... Args>
static void foreach (pedigree_std::Callable< F > &callback, Device *root, Args... args)
 
static void addToRoot (Device *device)
 
static void searchByVendorId (uint16_t vendorId, void(*callback)(Device *), Device *root=0)
 
static void searchByVendorIdAndDeviceId (uint16_t vendorId, uint16_t deviceId, void(*callback)(Device *), Device *root=0)
 
static void searchByClass (uint16_t classCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassAndSubclass (uint16_t classCode, uint16_t subclassCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassSubclassAndProgInterface (uint16_t classCode, uint16_t subclassCode, uint8_t progInterface, void(*callback)(Device *), Device *root=0)
 
- Public Attributes inherited from UsbDevice
struct UsbDevice::Setup PACKED
 
struct UsbDevice::DeviceQualifier PACKED
 
- Protected Types inherited from RequestQueue
enum class  NextRequestResult { Item , Empty , Retry }
 
- Static Protected Member Functions inherited from Device
static Device & root ()
 
- Static Protected Member Functions inherited from RequestQueue
static int trampoline (void *p)
 
static void completeRequest (Request *request, uint64_t returnValue, bool rejected)
 
static void retainRequest (Request *request)
 
- Protected Attributes inherited from Device
Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Device * m_pParent
 
Device * m_PhysicalFunction
 
size_t m_VirtualFunctionIndex
 
uintptr_t m_InterruptNumber
 
String m_SpecificType
 
PciBus::ConfigSpace m_ConfigHeader
 
uint8_t m_ClassCode
 
uint8_t m_SubclassCode
 
uint16_t m_VendorId
 
uint16_t m_DeviceId
 
uint8_t m_ProgInterface
 
uint32_t m_PciBusPos
 
uint32_t m_PciDevicePos
 
uint32_t m_PciFunctionNum
 
- Protected Attributes inherited from RequestQueue
IntakeLane m_IntakeLanes [REQUEST_QUEUE_NUM_PRIORITIES]
 
Request * m_pRequestQueue [REQUEST_QUEUE_NUM_PRIORITIES]
 
Request * m_pRequestQueueTail [REQUEST_QUEUE_NUM_PRIORITIES]
 
Request * m_pActiveRequest
 
Atomic< size_t > m_State
 
Mutex m_LifecycleMutex
 
WaitQueue m_RequestQueueWaiters
 
WaitQueue m_WorkerWaiters
 
Thread * m_pThread
 
Atomic< PerProcessorScheduler * > m_pWorkerScheduler
 
SchedulerWorkerWake m_WorkerWake
 
Atomic< size_t > m_bWorkerReady
 
Atomic< size_t > m_bWorkerActive
 
size_t m_WorkerProgressGeneration
 
RequestQueueOverrunChecker m_OverrunChecker
 
Timer * m_pOverrunTimer
 
Atomic< size_t > m_PublicationState
 
size_t m_nMaxAsyncRequests
 
Atomic< size_t > m_nAsyncRequests
 
Atomic< size_t > m_nTotalRequests
 
Atomic< size_t > m_nActiveRequests
 
NormalStaticString m_Name
 
- Protected Attributes inherited from UsbDevice
uint8_t m_nAddress
 The current address of the device.
 
uint16_t m_ControlPacketSize
 
uint8_t m_nPort
 The number of the port on which the device is connected.
 
uint8_t m_nRootPort
 Root-controller connection which owns this device generation.
 
size_t m_nRootPortGeneration
 
UsbSpeed m_Speed
 The speed at which the device operates.
 
UsbState m_UsbState
 The current state of the device.
 
DeviceDescriptor * m_pDescriptor
 Device descriptor for this device.
 
ConfigDescriptor * m_pConfiguration
 Configuration in use.
 
Interface * m_pInterface
 Interface in use.
 
UsbHub * m_pHub
 Parent USB hub.
 
UsbDeviceContainer * m_pContainer
 Our current container.
 
- Static Protected Attributes inherited from Device
static Device m_Root
 
static Mutex m_TreeLock
 
- Static Protected Attributes inherited from RequestQueue
static constexpr size_t PublicationClosed = static_cast<size_t>(1) << ((sizeof(size_t) * 8) - 1)
 
static constexpr size_t PublicationCountMask = ~PublicationClosed
 

Detailed Description

Definition at line 39 of file UsbMassStorageDevice.h.

Member Enumeration Documentation

◆ BotStatus

enum class UsbMassStorageDevice::BotStatus
strongprivate

Definition at line 67 of file UsbMassStorageDevice.h.

◆ MassStorageRequests

enum UsbMassStorageDevice::MassStorageRequests
private

Definition at line 73 of file UsbMassStorageDevice.h.

◆ MassStorageSigs

enum UsbMassStorageDevice::MassStorageSigs
private

Definition at line 81 of file UsbMassStorageDevice.h.

Constructor & Destructor Documentation

◆ UsbMassStorageDevice()

UsbMassStorageDevice::UsbMassStorageDevice ( UsbDevice *  dev)

Definition at line 29 of file UsbMassStorageDevice.cc.

◆ ~UsbMassStorageDevice()

UsbMassStorageDevice::~UsbMassStorageDevice ( )
virtual

Definition at line 41 of file UsbMassStorageDevice.cc.

Member Function Documentation

◆ getDevice()

virtual Device * UsbMassStorageDevice::getDevice ( )
inlinevirtual

Get a usable Device for this particular UsbDevice, if it has a subtree.

Returns
NULL if this operation is not supported.

Reimplemented from UsbDevice.

Definition at line 58 of file UsbMassStorageDevice.h.

◆ getNumUnits()

virtual size_t UsbMassStorageDevice::getNumUnits ( )
inlineprotectedvirtual

Implements ScsiController.

Definition at line 115 of file UsbMassStorageDevice.h.

◆ getUsbDeviceName()

virtual void UsbMassStorageDevice::getUsbDeviceName ( String &  str)
inlinevirtual

Reimplemented from UsbDevice.

Definition at line 50 of file UsbMassStorageDevice.h.

◆ hasSubtree()

virtual bool UsbMassStorageDevice::hasSubtree ( ) const
inlinevirtual

Do we expose our own Device tree?

Reimplemented from UsbDevice.

Definition at line 54 of file UsbMassStorageDevice.h.

◆ initialiseDriver()

void UsbMassStorageDevice::initialiseDriver ( )
virtual

Implemented by the driver class, initialises driver-specific stuff.

Reimplemented from UsbDevice.

Definition at line 60 of file UsbMassStorageDevice.cc.

References UsbDevice::controlRequestResult(), UsbDevice::m_pInterface, and UsbDevice::m_UsbState.

◆ massStorageReset()

bool UsbMassStorageDevice::massStorageReset ( )
private

Definition at line 102 of file UsbMassStorageDevice.cc.

◆ performResetRecovery()

bool UsbMassStorageDevice::performResetRecovery ( )
private

Definition at line 106 of file UsbMassStorageDevice.cc.

◆ prepareForDisconnection()

void UsbMassStorageDevice::prepareForDisconnection ( )
overridevirtual

Prepares a driver after its physical device has disappeared.

Reimplemented from UsbDevice.

Definition at line 48 of file UsbMassStorageDevice.cc.

References RequestQueue::destroy(), and ScsiController::shutdownDiskCaches().

◆ readStatus()

UsbMassStorageDevice::BotStatus UsbMassStorageDevice::readStatus ( uint32_t  tag,
uint32_t  expectedBytes 
)
private

Definition at line 119 of file UsbMassStorageDevice.cc.

◆ sendCommand()

bool UsbMassStorageDevice::sendCommand ( size_t  nUnit,
uintptr_t  pCommand,
uint8_t  nCommandSize,
uintptr_t  pRespBuffer,
uint16_t  nRespBytes,
bool  bWrite 
)
virtual

Implements ScsiController.

Definition at line 148 of file UsbMassStorageDevice.cc.

Member Data Documentation

◆ m_CommandLock

Mutex UsbMassStorageDevice::m_CommandLock
private

Definition at line 106 of file UsbMassStorageDevice.h.

◆ m_DeviceAvailable

bool UsbMassStorageDevice::m_DeviceAvailable
private

Definition at line 112 of file UsbMassStorageDevice.h.

◆ m_NextTag

uint32_t UsbMassStorageDevice::m_NextTag
private

Definition at line 110 of file UsbMassStorageDevice.h.

◆ m_nUnits

size_t UsbMassStorageDevice::m_nUnits
private

Definition at line 107 of file UsbMassStorageDevice.h.

◆ m_pInEndpoint

Endpoint* UsbMassStorageDevice::m_pInEndpoint
private

Definition at line 108 of file UsbMassStorageDevice.h.

◆ m_pOutEndpoint

Endpoint* UsbMassStorageDevice::m_pOutEndpoint
private

Definition at line 109 of file UsbMassStorageDevice.h.

◆ m_ResetRecoveryRequired

bool UsbMassStorageDevice::m_ResetRecoveryRequired
private

Definition at line 111 of file UsbMassStorageDevice.h.


The documentation for this class was generated from the following files: