The Pedigree Project 0.1
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Ohci Class Reference

#include <Ohci.h>

+ Inheritance diagram for Ohci:
+ Collaboration diagram for Ohci:

Classes

struct  ED
 
struct  Hcca
 
struct  TD
 

Public Member Functions

 Ohci (Device *pDev)
 
bool initialised () const
 
struct Ohci::TD ALIGN (16)
 
struct Ohci::ED ALIGN (16)
 
virtual void getName (String &str)
 
virtual void addTransferToTransaction (uintptr_t pTransaction, bool bToggle, UsbPid pid, uintptr_t pBuffer, size_t nBytes)
 Adds a new transfer to an existent transaction.
 
virtual uintptr_t createTransaction (UsbEndpoint endpointInfo)
 Creates a new transaction with the given endpoint data.
 
virtual MUST_USE_RESULT bool doAsync (uintptr_t pTransaction, void(*pCallback)(uintptr_t, ssize_t)=0, uintptr_t pParam=0)
 
virtual MUST_USE_RESULT bool addInterruptInHandler (UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), UsbInterruptInHandle &handle, uintptr_t pParam=0)
 Adds an owned recurring interrupt-IN transaction.
 
IrqDisposition irq (irq_id_t number) override
 IRQ handler.
 
virtual bool portReset (uint8_t nPort, bool bErrorResponse=false)
 Gets a UsbDevice from a given vendor:product pair.
 
- Public Member Functions inherited from UsbHub
 UsbHub (Device *p)
 
RootConnection rootConnectionForChild (uint8_t childPort) const
 
virtual bool controllerAssignsAddresses () const
 
virtual bool supportsHubDevices () const
 
virtual bool prepareDevice (uint8_t, const UsbEndpoint &)
 
virtual bool addressDevice (uint8_t, const UsbEndpoint &)
 
virtual bool resetEndpoint (const UsbEndpoint &)
 
virtual Type getType ()
 
bool deviceConnected (uint8_t nPort, UsbSpeed speed)
 Called when a device is connected to a port on the hub.
 
void deviceDisconnected (uint8_t nPort)
 Called when a device is disconnected from a port on the hub.
 
ssize_t doSync (uintptr_t nTransaction, uint32_t timeout=5000)
 
- 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 void dump (String &str)
 
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 IrqHandler
virtual bool acceptsSpuriousInterrupts () const
 
- 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 Attributes

struct Ohci::Hcca PACKED
 

Protected Member Functions

virtual void cancelAsyncAndDrain (uintptr_t pTransaction, void(*pCallback)(uintptr_t, ssize_t), uintptr_t pParam)
 
MUST_USE_RESULT bool cancelInterruptInAndDrain (const UsbInterruptInToken &token, void(*callback)(uintptr_t, ssize_t), uintptr_t parameter, bool producerAlreadyStopped) override
 
bool inInterruptCallbackContext () const override
 
void replaySuppressedConnectionChange (size_t port) override
 
virtual uint64_t executeRequest (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)
 
void cancelRequest (const Request &request) override
 
- Protected Member Functions inherited from UsbHub
virtual bool portSpeed (uint8_t, UsbSpeed &)
 
virtual bool beginStartupActivity ()
 
virtual void endStartupActivity (UsbStartup::Outcome)
 
virtual void releaseDeviceAddress (uint8_t)
 
MUST_USE_RESULT bool publishInterruptInHandle (UsbInterruptInHandle &handle, const UsbInterruptInToken &token, void(*callback)(uintptr_t, ssize_t), uintptr_t parameter)
 
void disconnectAllDevices ()
 
void retainDisconnectedAddressesUntilControllerTeardown ()
 
void attachToUpstreamHub (UsbHub *upstream, const RootConnection &connection)
 
UsbHub * rootHub () const
 
MUST_USE_RESULT bool suppressConnectionChanges (size_t port, ConnectionChangeSuppression &suppression)
 
MUST_USE_RESULT bool deferConnectionChangeIfSuppressed (size_t port)
 
virtual size_t currentRootPortGeneration (size_t port) const
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 
- Protected Member Functions inherited from IrqHandler
virtual ~IrqHandler ()
 
- Protected Member Functions inherited from IrqHandlerBase
virtual ~IrqHandlerBase ()
 
- 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 ()
 

Private Types

enum  Lists { PeriodicList = 0x4 , IsochronousList = 0x8 , ControlList = 0x10 , BulkList = 0x20 }
 Enumeration of lists that can be stopped or started. More...
 
enum  OhciConstants {
  OhciVersion = 0x00 , OhciControl = 0x04 , OhciCommandStatus = 0x08 , OhciInterruptStatus = 0x0c ,
  OhciInterruptEnable = 0x10 , OhciInterruptDisable = 0x14 , OhciHcca = 0x18 , OhciControlHeadED = 0x20 ,
  OhciControlCurrentED = 0x24 , OhciBulkHeadED = 0x28 , OhciBulkCurrentED = 0x2c , OhciFmInterval = 0x34 ,
  OhciRhDescriptorA = 0x48 , OhciRhStatus = 0x50 , OhciRhPortStatus = 0x54 , OhciControlStateFunctionalMask = 0xC0 ,
  OhciControlInterruptRoute = 0x100 , OhciControlStateRunning = 0x80 , OhciControlStateSuspended = 0xC0 , OhciControlListsEnable = 0x30 ,
  OhciCommandRequestOwnership = 0x08 , OhciCommandBulkListFilled = 0x04 , OhciCommandControlListFilled = 0x02 , OhciCommandHcReset = 0x01 ,
  OhciInterruptMIE = 0x80000000 , OhciInterruptOwnershipChange = 0x40000000 , OhciInterruptRhStsChange = 0x40 , OhciInterruptFrameNumberOverflow = 0x20 ,
  OhciInterruptUnrecoverableError = 0x10 , OhciInterruptResumeDetected = 0x08 , OhciInterruptWbDoneHead = 0x02 , OhciInterruptSchedulingOverrun = 0x01 ,
  OhciInterruptStartOfFrame = 0x04 , OhciInterruptAll = OhciInterruptMIE | OhciInterruptOwnershipChange | 0x7F , OhciInterruptOperational , OhciRhHubStsSetGlobalPower = 0x10000 ,
  OhciRhHubStsOverCurrentCh = 0x20000 , OhciRhPortStsResCh = 0x100000 , OhciRhPortStsOverCurrentCh = 0x80000 , OhciRhPortStsSuspendCh = 0x40000 ,
  OhciRhPortStsEnableCh = 0x20000 , OhciRhPortStsConnStsCh = 0x10000 , OhciRhPortStsChangeMask , OhciRhPortStsLoSpeed = 0x200 ,
  OhciRhPortStsPower = 0x100 , OhciRhPortStsReset = 0x10 , OhciRhPortStsEnable = 0x02 , OhciRhPortStsConnected = 0x01
}
 
using ControllerLock = Mutex
 
using IrqProcessingLock = Mutex
 

Private Member Functions

void stop (Lists list)
 Stops the controller from processing the given list.
 
void start (Lists list)
 Starts processing of the given list.
 
void setRootHubStatusChangeSource (bool enabled)
 
void transitionControllerState (uint32_t control, const char *timeoutMessage)
 
void removeED (ED *pED)
 Detaches an ED and queues it for reclamation at the next frame.
 
void detachED (ED *pED)
 
void removeFromFullSchedule (ED *pED)
 
void removeFromDequeueList (ED *pED)
 
void reclaimTransferDescriptors (ED *pED)
 
void retireEDStorage (ED *pED)
 
UsbHcd::CallbackDeliveryQueue::Record * prepareCompletion (ED *pED, const UsbHcd::TransferCompletion::Claim &claim)
 
void terminalizeEDForTeardown (ED *pED, List< UsbHcd::CallbackDeliveryQueue::Record * > &completions)
 
physical_uintptr_t vtp_ed (ED *pED)
 Converts a software ED pointer to a physical address.
 
ED * ptv_ed (physical_uintptr_t phys)
 Converts a physical address to an ED pointer. Maybe.
 
 Ohci (const Ohci &)
 
void operator= (const Ohci &)
 

Static Private Member Functions

static void finishDeferredCompletion (void *context)
 

Private Attributes

IoBase * m_pBase
 
uint8_t m_nPorts
 
bool m_Initialised
 
UsbHcd::PortChangeRequest m_PortChanges [UsbHcd::OhciRootPortCount]
 
UsbHcd::DeferredPortChanges m_DeferredPortChanges
 
ControllerLock m_Mutex
 Global lock.
 
ControllerLock m_PortResetMutex
 
Hcca * m_pHcca
 
uintptr_t m_pHccaPhys
 
IrqProcessingLock m_IrqProcessingLock
 Lock for modifying the schedule list itself (m_FullSchedule)
 
UsbHcd::CallbackDeliveryQueue m_CompletionDeliveries
 
Spinlock m_RootHubLock
 Serializes root-hub register access between reset and IRQ paths.
 
bool m_RootHubStatusChangeDesired
 
bool m_PortResetActive
 
Atomic< size_t > m_TeardownPhase
 
Spinlock m_ScheduleChangeLock
 
Spinlock m_PeriodicListChangeLock
 Lock for changing the periodic list.
 
Spinlock m_ControlListChangeLock
 Lock for changing the control list.
 
Spinlock m_BulkListChangeLock
 Lock for changing the bulk list.
 
ED * m_pPeriodicEDList
 
uintptr_t m_pPeriodicEDListPhys
 
ExtensibleBitmap m_PeriodicEDBitmap
 
ED * m_pControlEDList
 
uintptr_t m_pControlEDListPhys
 
ExtensibleBitmap m_ControlEDBitmap
 
ED * m_pBulkEDList
 
uintptr_t m_pBulkEDListPhys
 
ExtensibleBitmap m_BulkEDBitmap
 
TD * m_pTDList
 
uintptr_t m_pTDListPhys
 
ExtensibleBitmap m_TDBitmap
 
ED * m_pBulkQueueHead
 
ED * m_pControlQueueHead
 
ED * m_pBulkQueueTail
 
ED * m_pControlQueueTail
 
ED * m_pPeriodicQueueTail
 
Spinlock m_DequeueListLock
 Dequeue list lock.
 
List< ED * > m_FullSchedule
 
List< ED * > m_DequeueList
 List of EDs ready for dequeue (reclaiming)
 
Semaphore m_DequeueCount
 Semaphore for the dequeue list.
 
MemoryRegion m_OhciMR
 
OperationBarrier m_CallbackOperations
 
OperationBarrier m_SubmissionOperations
 
OperationBarrier m_CancellationOperations
 
OperationBarrier m_AcceptedOperations
 
irq_id_t m_IrqId
 

Static Private Attributes

static constexpr size_t EdRegionBytes = 4096
 
static constexpr size_t EdRegionOffsetMask = EdRegionBytes - 1
 

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 }
 
- 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)
 
- 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
 
- 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

Device driver for the Ohci class

Definition at line 50 of file Ohci.h.

Member Typedef Documentation

◆ ControllerLock

using Ohci::ControllerLock = Mutex
private

Definition at line 60 of file Ohci.h.

◆ IrqProcessingLock

using Ohci::IrqProcessingLock = Mutex
private

Definition at line 68 of file Ohci.h.

Member Enumeration Documentation

◆ Lists

enum Ohci::Lists
private

Enumeration of lists that can be stopped or started.

Definition at line 74 of file Ohci.h.

◆ OhciConstants

enum Ohci::OhciConstants
private

Definition at line 296 of file Ohci.h.

Constructor & Destructor Documentation

◆ Ohci()

Ohci::Ohci ( Device *  pDev)

Definition at line 91 of file Ohci.cc.

◆ ~Ohci()

Ohci::~Ohci ( )
virtual

Definition at line 424 of file Ohci.cc.

Member Function Documentation

◆ addInterruptInHandler()

bool Ohci::addInterruptInHandler ( UsbEndpoint  endpointInfo,
uintptr_t  pBuffer,
uint16_t  nBytes,
void(*)(uintptr_t, ssize_t)  pCallback,
UsbInterruptInHandle &  handle,
uintptr_t  pParam = 0 
)
virtual

Adds an owned recurring interrupt-IN transaction.

Implements UsbHub.

Definition at line 1643 of file Ohci.cc.

◆ addTransferToTransaction()

void Ohci::addTransferToTransaction ( uintptr_t  pTransaction,
bool  bToggle,
UsbPid  pid,
uintptr_t  pBuffer,
size_t  nBytes 
)
virtual

◆ cancelAsyncAndDrain()

void Ohci::cancelAsyncAndDrain ( uintptr_t  pTransaction,
void(*)(uintptr_t, ssize_t)  pCallback,
uintptr_t  pParam 
)
protectedvirtual

Cancels an accepted transaction or drains a completion which won the race. On return, the matching callback has run exactly once and the controller can no longer access any transfer buffer.

The callback and parameter identify the original transaction generation, preventing a stale numeric transaction handle from cancelling a reused controller slot.

Implements UsbHub.

Definition at line 1541 of file Ohci.cc.

References UsbHcd::TransferCompletion::claimCancellation(), List< T, nodePoolSize >::count(), UsbHcd::CallbackDeliveryQueue::deliver(), detachED(), UsbHcd::CallbackDeliveryQueue::drain(), m_CancellationOperations, m_CompletionDeliveries, m_IrqProcessingLock, m_Mutex, List< T, nodePoolSize >::popFront(), prepareCompletion(), UsbHcd::CallbackDeliveryQueue::publish(), List< T, nodePoolSize >::pushBack(), IoBase::read32(), removeFromDequeueList(), removeFromFullSchedule(), ExtensibleBitmap::test(), transitionControllerState(), OperationBarrier::tryAcquire(), and IoBase::write32().

◆ cancelInterruptInAndDrain()

bool Ohci::cancelInterruptInAndDrain ( const UsbInterruptInToken &  token,
void(*)(uintptr_t, ssize_t)  callback,
uintptr_t  parameter,
bool  producerAlreadyStopped 
)
overrideprotectedvirtual

Stops and drains one exact recurring interrupt-IN subscription.

Implements UsbHub.

Definition at line 1632 of file Ohci.cc.

References panic().

◆ cancelRequest()

void Ohci::cancelRequest ( const Request &  request)
overrideprotectedvirtual

Releases payload ownership for a request that will not execute.

This runs without the queue guard for rejected candidates (including stopped queues, duplicates and capacity limits) and queued requests cancelled by destroy(). Implementations used by allocation-free producers must not sleep. Derived destructors must call destroy() while their override and member state are still alive. During destroy(), the lifecycle is serialized: halt() and resume() on this queue return false, while recursive destroy() is a fatal contract violation.

Reimplemented from RequestQueue.

Definition at line 1792 of file Ohci.cc.

◆ createTransaction()

uintptr_t Ohci::createTransaction ( UsbEndpoint  endpointInfo)
virtual

Creates a new transaction with the given endpoint data.

Implements UsbHub.

Definition at line 1322 of file Ohci.cc.

References ExtensibleBitmap::getFirstClear(), m_IrqProcessingLock, m_Mutex, m_SubmissionOperations, Ohci::ED::MetaData::pCallback, ExtensibleBitmap::set(), and OperationBarrier::tryAcquire().

◆ detachED()

void Ohci::detachED ( ED *  pED)
private

Detaches a control or bulk ED without arming SOF or restarting a list.

Todo:
Isochronous and Periodic.

Definition at line 645 of file Ohci.cc.

References EMIT_IF, m_BulkListChangeLock, m_ControlListChangeLock, vtp_ed(), and IoBase::write32().

Referenced by cancelAsyncAndDrain(), removeED(), and terminalizeEDForTeardown().

+ Here is the caller graph for this function:

◆ doAsync()

bool Ohci::doAsync ( uintptr_t  pTransaction,
void(*)(uintptr_t, ssize_t)  pCallback = 0,
uintptr_t  pParam = 0 
)
virtual

Performs a transaction asynchronously.

Returning true transfers one completion obligation to the controller: it must call the callback exactly once, and only after it can no longer access any transfer buffer. Returning false guarantees that the callback was not and will not be called, and that the rejected transaction no longer owns controller or transfer-buffer state.

Implements UsbHub.

Definition at line 1383 of file Ohci.cc.

References Spinlock::acquire(), UsbHcd::TransferCompletion::arm(), EMIT_IF, m_AcceptedOperations, m_BulkListChangeLock, m_CompletionDeliveries, m_ControlListChangeLock, m_FullSchedule, m_IrqProcessingLock, m_Mutex, m_SubmissionOperations, IoBase::read32(), Spinlock::release(), retireEDStorage(), start(), ExtensibleBitmap::test(), OperationBarrier::tryAcquire(), OperationBarrier::tryEnter(), vtp_ed(), and IoBase::write32().

◆ executeRequest()

uint64_t Ohci::executeRequest ( 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 
)
protectedvirtual

Callback - classes are expected to inherit and override this function. It's called when a request needs to be executed (by the worker thread).

Implements RequestQueue.

Definition at line 1762 of file Ohci.cc.

References Dec, UsbHub::deviceConnected(), UsbHub::deviceDisconnected(), Hex, portReset(), and IoBase::read32().

◆ finishDeferredCompletion()

void Ohci::finishDeferredCompletion ( void *  context)
staticprivate

Definition at line 77 of file Ohci.cc.

◆ getName()

virtual void Ohci::getName ( String &  str)
inlinevirtual

Stores the device's name in str.

Reimplemented from Device.

Definition at line 177 of file Ohci.h.

◆ inInterruptCallbackContext()

bool Ohci::inInterruptCallbackContext ( ) const
inlineoverrideprotectedvirtual

True when this execution context must not wait for a USB callback.

Reimplemented from UsbHub.

Definition at line 208 of file Ohci.h.

References UsbHcd::CallbackDeliveryQueue::isInCallbackContext().

◆ initialised()

bool Ohci::initialised ( ) const
inline

Definition at line 80 of file Ohci.h.

◆ irq()

IrqDisposition Ohci::irq ( irq_id_t  number)
overridevirtual

◆ portReset()

bool Ohci::portReset ( uint8_t  nPort,
bool  bErrorResponse = false 
)
virtual

Gets a UsbDevice from a given vendor:product pair.

Performs a port reset for the given port. Should only be used in situations where a device cannot recover from an error without a complete reset.

Note
Assumes the port is at CONNECTED with a VALID DEVICE attached.
Parameters
bErrorResponsetrue if this is a reset as a response to an error. Error responses are allowed to use significantly longer delays in their reset logic.
Todo:
Error handling? Device fails to reset? Not present after reset?

Implements UsbHub.

Definition at line 1690 of file Ohci.cc.

References m_PortResetMutex, m_RootHubLock, IoBase::read32(), setRootHubStatusChangeSource(), and IoBase::write32().

Referenced by executeRequest().

+ Here is the caller graph for this function:

◆ prepareCompletion()

UsbHcd::CallbackDeliveryQueue::Record * Ohci::prepareCompletion ( ED *  pED,
const UsbHcd::TransferCompletion::Claim &  claim 
)
private

Builds the sole delivery record for a claimed one-shot transfer.

Definition at line 781 of file Ohci.cc.

References m_CompletionDeliveries, and reclaimTransferDescriptors().

Referenced by cancelAsyncAndDrain(), irq(), and terminalizeEDForTeardown().

+ Here is the caller graph for this function:

◆ ptv_ed()

ED * Ohci::ptv_ed ( physical_uintptr_t  phys)
inlineprivate

Converts a physical address to an ED pointer. Maybe.

Todo:
defines for the list sizes so changing one doesn't involve rewriting heaps of code

Definition at line 281 of file Ohci.h.

◆ reclaimTransferDescriptors()

void Ohci::reclaimTransferDescriptors ( ED *  pED)
private

Releases every TD owned by an ED after the DMA ownership boundary.

Definition at line 735 of file Ohci.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::clear(), ExtensibleBitmap::clear(), and List< T, nodePoolSize >::end().

Referenced by prepareCompletion(), and retireEDStorage().

+ Here is the caller graph for this function:

◆ removeED()

void Ohci::removeED ( ED *  pED)
private

Detaches an ED and queues it for reclamation at the next frame.

Note
Refer to page 56 in the OHCI spec for this function.

Definition at line 618 of file Ohci.cc.

References detachED(), EMIT_IF, m_DequeueList, m_DequeueListLock, stop(), and IoBase::write32().

Referenced by irq().

+ Here is the caller graph for this function:

◆ removeFromDequeueList()

void Ohci::removeFromDequeueList ( ED *  pED)
private

Removes an ED from the next-frame reclaim list if present.

Definition at line 724 of file Ohci.cc.

References m_DequeueList, and m_DequeueListLock.

Referenced by cancelAsyncAndDrain(), and terminalizeEDForTeardown().

+ Here is the caller graph for this function:

◆ removeFromFullSchedule()

void Ohci::removeFromFullSchedule ( ED *  pED)
private

Removes an ED from the software completion schedule if present.

Definition at line 713 of file Ohci.cc.

References m_FullSchedule.

Referenced by cancelAsyncAndDrain(), and terminalizeEDForTeardown().

+ Here is the caller graph for this function:

◆ replaySuppressedConnectionChange()

void Ohci::replaySuppressedConnectionChange ( size_t  port)
overrideprotectedvirtual

Re-publishes one coalesced observation in ordinary thread context.

Reimplemented from UsbHub.

Definition at line 1658 of file Ohci.cc.

References Dec, m_IrqProcessingLock, m_RootHubLock, and setRootHubStatusChangeSource().

◆ retireEDStorage()

void Ohci::retireEDStorage ( ED *  pED)
private

Releases ED metadata and its accepted-operation lease.

Definition at line 758 of file Ohci.cc.

References ExtensibleBitmap::clear(), OperationBarrier::leave(), m_AcceptedOperations, and reclaimTransferDescriptors().

Referenced by doAsync(), and terminalizeEDForTeardown().

+ Here is the caller graph for this function:

◆ setRootHubStatusChangeSource()

void Ohci::setRootHubStatusChangeSource ( bool  enabled)
private

Changes only the RootHubStatusChange interrupt source.

Callers hold m_RootHubLock so reset and interrupt paths cannot race the source mask.

Definition at line 598 of file Ohci.cc.

References IoBase::read32(), and IoBase::write32().

Referenced by irq(), portReset(), and replaySuppressedConnectionChange().

+ Here is the caller graph for this function:

◆ start()

void Ohci::start ( Lists  list)
private

Starts processing of the given list.

Definition at line 1807 of file Ohci.cc.

References IoBase::read32(), and IoBase::write32().

Referenced by doAsync(), and irq().

+ Here is the caller graph for this function:

◆ stop()

void Ohci::stop ( Lists  list)
private

Stops the controller from processing the given list.

Definition at line 1798 of file Ohci.cc.

References IoBase::read32(), and IoBase::write32().

Referenced by removeED().

+ Here is the caller graph for this function:

◆ terminalizeEDForTeardown()

void Ohci::terminalizeEDForTeardown ( ED *  pED,
List< UsbHcd::CallbackDeliveryQueue::Record * > &  completions 
)
private

Claims and materializes one ED while the suspended controller is owned.

Definition at line 796 of file Ohci.cc.

References UsbHcd::TransferCompletion::claimForTeardown(), detachED(), prepareCompletion(), List< T, nodePoolSize >::pushBack(), removeFromDequeueList(), removeFromFullSchedule(), and retireEDStorage().

◆ transitionControllerState()

void Ohci::transitionControllerState ( uint32_t  control,
const char *  timeoutMessage 
)
private

Writes HcControl and waits for the requested functional state.

Definition at line 603 of file Ohci.cc.

References panic(), IoBase::read32(), and IoBase::write32().

Referenced by cancelAsyncAndDrain().

+ Here is the caller graph for this function:

◆ vtp_ed()

physical_uintptr_t Ohci::vtp_ed ( ED *  pED)
inlineprivate

Converts a software ED pointer to a physical address.

Definition at line 264 of file Ohci.h.

Referenced by detachED(), and doAsync().

+ Here is the caller graph for this function:

Member Data Documentation

◆ EdRegionBytes

constexpr size_t Ohci::EdRegionBytes = 4096
staticconstexprprivate

Definition at line 56 of file Ohci.h.

◆ EdRegionOffsetMask

constexpr size_t Ohci::EdRegionOffsetMask = EdRegionBytes - 1
staticconstexprprivate

Definition at line 57 of file Ohci.h.

◆ m_AcceptedOperations

OperationBarrier Ohci::m_AcceptedOperations
private

One lease per accepted one-shot or periodic subscription.

Definition at line 453 of file Ohci.h.

Referenced by doAsync(), and retireEDStorage().

◆ m_BulkEDBitmap

ExtensibleBitmap Ohci::m_BulkEDBitmap
private

Definition at line 411 of file Ohci.h.

◆ m_BulkListChangeLock

Spinlock Ohci::m_BulkListChangeLock
private

Lock for changing the bulk list.

Definition at line 399 of file Ohci.h.

Referenced by detachED(), and doAsync().

◆ m_CallbackOperations

OperationBarrier Ohci::m_CallbackOperations
private

Closes and drains interrupt callbacks before controller teardown.

Definition at line 444 of file Ohci.h.

Referenced by irq().

◆ m_CancellationOperations

OperationBarrier Ohci::m_CancellationOperations
private

Cancellation calls remain admitted until terminal callbacks drain.

Definition at line 450 of file Ohci.h.

Referenced by cancelAsyncAndDrain().

◆ m_CompletionDeliveries

UsbHcd::CallbackDeliveryQueue Ohci::m_CompletionDeliveries
private

Per-generation callback publication and cancellation drain boundary.

Definition at line 382 of file Ohci.h.

Referenced by cancelAsyncAndDrain(), doAsync(), irq(), and prepareCompletion().

◆ m_ControlEDBitmap

ExtensibleBitmap Ohci::m_ControlEDBitmap
private

Definition at line 407 of file Ohci.h.

◆ m_ControlListChangeLock

Spinlock Ohci::m_ControlListChangeLock
private

Lock for changing the control list.

Definition at line 396 of file Ohci.h.

Referenced by detachED(), and doAsync().

◆ m_DeferredPortChanges

UsbHcd::DeferredPortChanges Ohci::m_DeferredPortChanges
private

Definition at line 366 of file Ohci.h.

◆ m_DequeueCount

Semaphore Ohci::m_DequeueCount
private

Semaphore for the dequeue list.

Definition at line 439 of file Ohci.h.

◆ m_DequeueList

List<ED*> Ohci::m_DequeueList
private

List of EDs ready for dequeue (reclaiming)

Definition at line 436 of file Ohci.h.

Referenced by irq(), removeED(), and removeFromDequeueList().

◆ m_DequeueListLock

Spinlock Ohci::m_DequeueListLock
private

Dequeue list lock.

Definition at line 429 of file Ohci.h.

Referenced by irq(), removeED(), and removeFromDequeueList().

◆ m_FullSchedule

List<ED*> Ohci::m_FullSchedule
private

List of ED pointers in both the control and bulk queues. Used for IRQ handling.

Definition at line 433 of file Ohci.h.

Referenced by doAsync(), irq(), and removeFromFullSchedule().

◆ m_Initialised

bool Ohci::m_Initialised
private

Definition at line 364 of file Ohci.h.

◆ m_IrqId

irq_id_t Ohci::m_IrqId
private

Definition at line 454 of file Ohci.h.

◆ m_IrqProcessingLock

IrqProcessingLock Ohci::m_IrqProcessingLock
private

Lock for modifying the schedule list itself (m_FullSchedule)

Definition at line 379 of file Ohci.h.

Referenced by addTransferToTransaction(), cancelAsyncAndDrain(), createTransaction(), doAsync(), irq(), and replaySuppressedConnectionChange().

◆ m_Mutex

ControllerLock Ohci::m_Mutex
private

Global lock.

Definition at line 369 of file Ohci.h.

Referenced by addTransferToTransaction(), cancelAsyncAndDrain(), createTransaction(), and doAsync().

◆ m_nPorts

uint8_t Ohci::m_nPorts
private

Definition at line 363 of file Ohci.h.

◆ m_OhciMR

MemoryRegion Ohci::m_OhciMR
private

Definition at line 441 of file Ohci.h.

◆ m_pBase

IoBase* Ohci::m_pBase
private

Definition at line 361 of file Ohci.h.

◆ m_pBulkEDList

ED* Ohci::m_pBulkEDList
private

Definition at line 409 of file Ohci.h.

◆ m_pBulkEDListPhys

uintptr_t Ohci::m_pBulkEDListPhys
private

Definition at line 410 of file Ohci.h.

◆ m_pBulkQueueHead

ED* Ohci::m_pBulkQueueHead
private

Definition at line 418 of file Ohci.h.

◆ m_pBulkQueueTail

ED* Ohci::m_pBulkQueueTail
private

Definition at line 422 of file Ohci.h.

◆ m_pControlEDList

ED* Ohci::m_pControlEDList
private

Definition at line 405 of file Ohci.h.

◆ m_pControlEDListPhys

uintptr_t Ohci::m_pControlEDListPhys
private

Definition at line 406 of file Ohci.h.

◆ m_pControlQueueHead

ED* Ohci::m_pControlQueueHead
private

Definition at line 419 of file Ohci.h.

◆ m_pControlQueueTail

ED* Ohci::m_pControlQueueTail
private

Definition at line 423 of file Ohci.h.

◆ m_PeriodicEDBitmap

ExtensibleBitmap Ohci::m_PeriodicEDBitmap
private

Definition at line 403 of file Ohci.h.

◆ m_PeriodicListChangeLock

Spinlock Ohci::m_PeriodicListChangeLock
private

Lock for changing the periodic list.

Definition at line 393 of file Ohci.h.

◆ m_pHcca

Hcca* Ohci::m_pHcca
private

Definition at line 375 of file Ohci.h.

◆ m_pHccaPhys

uintptr_t Ohci::m_pHccaPhys
private

Definition at line 376 of file Ohci.h.

◆ m_PortChanges

UsbHcd::PortChangeRequest Ohci::m_PortChanges[UsbHcd::OhciRootPortCount]
private

Definition at line 365 of file Ohci.h.

◆ m_PortResetActive

bool Ohci::m_PortResetActive
private

Definition at line 387 of file Ohci.h.

◆ m_PortResetMutex

ControllerLock Ohci::m_PortResetMutex
private

Serializes threaded root-port resets without holding an IRQ-safe lock while waiting for hardware.

Definition at line 373 of file Ohci.h.

Referenced by portReset().

◆ m_pPeriodicEDList

ED* Ohci::m_pPeriodicEDList
private

Definition at line 401 of file Ohci.h.

◆ m_pPeriodicEDListPhys

uintptr_t Ohci::m_pPeriodicEDListPhys
private

Definition at line 402 of file Ohci.h.

◆ m_pPeriodicQueueTail

ED* Ohci::m_pPeriodicQueueTail
private

Definition at line 426 of file Ohci.h.

◆ m_pTDList

TD* Ohci::m_pTDList
private

Definition at line 413 of file Ohci.h.

◆ m_pTDListPhys

uintptr_t Ohci::m_pTDListPhys
private

Definition at line 414 of file Ohci.h.

◆ m_RootHubLock

Spinlock Ohci::m_RootHubLock
private

Serializes root-hub register access between reset and IRQ paths.

Definition at line 385 of file Ohci.h.

Referenced by irq(), portReset(), and replaySuppressedConnectionChange().

◆ m_RootHubStatusChangeDesired

bool Ohci::m_RootHubStatusChangeDesired
private

Definition at line 386 of file Ohci.h.

◆ m_ScheduleChangeLock

Spinlock Ohci::m_ScheduleChangeLock
private

Definition at line 390 of file Ohci.h.

◆ m_SubmissionOperations

OperationBarrier Ohci::m_SubmissionOperations
private

Short-lived create/build/submit operations closed before ED scanning.

Definition at line 447 of file Ohci.h.

Referenced by addTransferToTransaction(), createTransaction(), and doAsync().

◆ m_TDBitmap

ExtensibleBitmap Ohci::m_TDBitmap
private

Definition at line 415 of file Ohci.h.

◆ m_TeardownPhase

Atomic<size_t> Ohci::m_TeardownPhase
private

Definition at line 388 of file Ohci.h.


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