The Pedigree Project  0.1
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Private Types | Private Member Functions | 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)
 
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. More...
 
virtual uintptr_t createTransaction (UsbEndpoint endpointInfo)
 Creates a new transaction with the given endpoint data.
 
virtual void doAsync (uintptr_t pTransaction, void(*pCallback)(uintptr_t, ssize_t)=0, uintptr_t pParam=0)
 
virtual void addInterruptInHandler (UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), uintptr_t pParam=0)
 Adds a new handler for an interrupt IN transaction.
 
virtual bool irq (irq_id_t number, InterruptState &state)
 IRQ handler. More...
 
virtual bool portReset (uint8_t nPort, bool bErrorResponse=false)
 Gets a UsbDevice from a given vendor:product pair. More...
 
- Public Member Functions inherited from UsbHub
 UsbHub (Device *p)
 
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)
 
void ignoreConnectionChanges (uint8_t nPort, bool bIgnore=true)
 
- Public Member Functions inherited from Device
 Device (Device *p)
 
DevicegetParent () const
 
void setParent (Device *p)
 
virtual 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 ()
 
virtual void dump (String &str)
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
DevicegetChild (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)
 
void halt ()
 
void resume ()
 

Public Attributes

struct Ohci::Hcca PACKED
 

Protected Member Functions

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)
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 
- Protected Member Functions inherited from IrqHandler
virtual ~IrqHandler ()
 
- Protected Member Functions inherited from RequestQueue
 RequestQueue (const RequestQueue &)
 
void operator= (const RequestQueue &)
 
virtual bool compareRequests (const Request &a, const Request &b)
 
bool isRequestValid (const Request *r)
 
int work ()
 
RequestgetNextRequest ()
 

Private Types

enum  Lists { PeriodicList = 0x4, IsochronousList = 0x8, ControlList = 0x10, BulkList = 0x20 }
 Enumeration of lists that can be stopped or started.
 
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, OhciControlListsEnable = 0x30, OhciCommandRequestOwnership = 0x08,
  OhciCommandBulkListFilled = 0x04, OhciCommandControlListFilled = 0x02, OhciCommandHcReset = 0x01, OhciInterruptMIE = 0x80000000,
  OhciInterruptRhStsChange = 0x40, OhciInterruptUnrecoverableError = 0x10, OhciInterruptWbDoneHead = 0x02, OhciInterruptStartOfFrame = 0x04,
  OhciRhPortStsResCh = 0x100000, OhciRhPortStsConnStsCh = 0x10000, OhciRhPortStsLoSpeed = 0x200, OhciRhPortStsPower = 0x100,
  OhciRhPortStsReset = 0x10, OhciRhPortStsEnable = 0x02, OhciRhPortStsConnected = 0x01
}
 

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 removeED (ED *pED)
 Prepares an ED to be reclaimed. More...
 
physical_uintptr_t vtp_ed (ED *pED)
 Converts a software ED pointer to a physical address.
 
EDptv_ed (physical_uintptr_t phys)
 Converts a physical address to an ED pointer. Maybe. More...
 
 Ohci (const Ohci &)
 
void operator= (const Ohci &)
 

Private Attributes

IoBasem_pBase
 
uint8_t m_nPorts
 
Mutex m_Mutex
 Global lock.
 
Hccam_pHcca
 
uintptr_t m_pHccaPhys
 
Spinlock m_ScheduleChangeLock
 Lock for modifying the schedule list itself (m_FullSchedule)
 
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.
 
EDm_pPeriodicEDList
 
uintptr_t m_pPeriodicEDListPhys
 
ExtensibleBitmap m_PeriodicEDBitmap
 
EDm_pControlEDList
 
uintptr_t m_pControlEDListPhys
 
ExtensibleBitmap m_ControlEDBitmap
 
EDm_pBulkEDList
 
uintptr_t m_pBulkEDListPhys
 
ExtensibleBitmap m_BulkEDBitmap
 
TDm_pTDList
 
uintptr_t m_pTDListPhys
 
ExtensibleBitmap m_TDBitmap
 
EDm_pBulkQueueHead
 
EDm_pControlQueueHead
 
EDm_pBulkQueueTail
 
EDm_pControlQueueTail
 
EDm_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
 

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  ActionOnDuplicate { Block, NewRequest, ReturnImmediately }
 
- Static Public Member Functions inherited from Device
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)
 
- Static Protected Member Functions inherited from Device
static Deviceroot ()
 
- Static Protected Member Functions inherited from RequestQueue
static int trampoline (void *p)
 
static int doAsync (void *p)
 
- Protected Attributes inherited from UsbHub
ExtensibleBitmap m_IgnoredPorts
 Bitmap of ports to ignore connection changes on.
 
- Protected Attributes inherited from Device
Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Devicem_pParent
 
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
Requestm_pRequestQueue [REQUEST_QUEUE_NUM_PRIORITIES]
 
volatile bool m_Stop
 
Mutex m_RequestQueueMutex
 
ConditionVariable m_RequestQueueCondition
 
ConditionVariable m_AsyncRequestQueueCondition
 
Threadm_pThread
 
bool m_Halted
 
Mutex m_HaltAcknowledged
 
RequestQueueOverrunChecker m_OverrunChecker
 
size_t m_nMaxAsyncRequests
 
size_t m_nAsyncRequests
 
size_t m_nTotalRequests
 
String m_Name
 
- Static Protected Attributes inherited from Device
static Device m_Root
 
static Mutex m_TreeLock
 

Detailed Description

Device driver for the Ohci class

Definition at line 44 of file Ohci.h.

Member Function Documentation

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

Adds a new transfer to an existent transaction.

Todo:
Clean up!

Implements UsbHub.

Definition at line 661 of file Ohci.cc.

References Dec, ERROR, VirtualAddressSpace::getMapping(), Hex, Processor::information(), VirtualAddressSpace::isMapped(), and List< T, nodePoolSize >::pushBack().

Referenced by getName().

+ Here is the caller graph for this function:

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

Performs a transaction asynchronously, calling the given callback on completion

Implements UsbHub.

Definition at line 842 of file Ohci.cc.

References Spinlock::acquire(), DEBUG_LOG, ERROR, and Spinlock::release().

Referenced by getName().

+ Here is the caller graph for this function:

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 1110 of file Ohci.cc.

References DEBUG_LOG, Dec, and Hex.

Referenced by getName().

+ Here is the caller graph for this function:

virtual void Ohci::getName ( String str)
inlinevirtual

Stores the device's name in str.

Reimplemented from Device.

Definition at line 165 of file Ohci.h.

References addInterruptInHandler(), addTransferToTransaction(), createTransaction(), doAsync(), executeRequest(), irq(), portReset(), removeED(), start(), and stop().

bool Ohci::irq ( irq_id_t  number,
InterruptState &  state 
)
virtual

IRQ handler.

Todo:
Handle.
Note
List processing won't start until the NEXT SOF.
It might be nice to document this.

Implements IrqHandler.

Definition at line 376 of file Ohci.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::count(), DEBUG_LOG, Dec, List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), ERROR, Hex, List< T, nodePoolSize >::popFront(), List< T, nodePoolSize >::pushBack(), List< T, nodePoolSize >::pushFront(), and WARNING.

Referenced by getName().

+ Here is the caller graph for this function:

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 1089 of file Ohci.cc.

Referenced by getName().

+ Here is the caller graph for this function:

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 226 of file Ohci.h.

void Ohci::removeED ( ED pED)
private

Prepares an ED to be reclaimed.

Note
Refer to page 56 in the OHCI spec for this function.
Todo:
Isochronous and Periodic.

Definition at line 261 of file Ohci.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::count(), DEBUG_LOG, List< T, nodePoolSize >::end(), and ERROR.

Referenced by getName().

+ Here is the caller graph for this function:

Member Data Documentation

List<ED *> Ohci::m_FullSchedule
private

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

Definition at line 350 of file Ohci.h.


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