20 #include "UsbHubDevice.h"    21 #include "modules/system/usb/UsbDevice.h"    22 #include "modules/system/usb/UsbHub.h"    23 #include "pedigree/kernel/Log.h"    24 #include "pedigree/kernel/time/Time.h"    25 #include "pedigree/kernel/utilities/PointerGuard.h"    26 #include "pedigree/kernel/utilities/new"    32 UsbHubDevice::~UsbHubDevice()
    38     uint8_t len = getDescriptorLength(0, 0, UsbRequestType::Class);
    42         pDesc = getDescriptor(0, 0, len, UsbRequestType::Class);
    51         "USB: HUB: Found a hub with " << 
Dec << pDescriptor.nPorts << 
Hex    52                                       << 
" ports and hubCharacteristics = "    53                                       << pDescriptor.hubCharacteristics);
    54     m_nPorts = pDescriptor.nPorts;
    55     for (
size_t i = 0; i < m_nPorts; i++)
    58         uint32_t portStatus = getPortStatus(i);
    61         if (!(portStatus & (1 << 8)))
    64                 "USB: HUB: Powering up port "    65                 << 
Dec << i << 
Hex << 
" [status = " << portStatus << 
"]...");
    68             setPortFeature(i, PortPower);
    71             Time::delay(50 * Time::Multiplier::Millisecond);
    74             portStatus = getPortStatus(i);
    77             if (!(portStatus & (1 << 8)))
    80                     "USB: HUB: Port " << 
Dec << i << 
Hex    81                                       << 
" couldn't be powered up.");
    86                 "USB: HUB: Powered up port "    87                 << 
Dec << i << 
Hex << 
" [status = " << portStatus << 
"]...");
    93             portStatus = getPortStatus(i);
    94             if (portStatus & (1 << 10))
   100                     << 
" has a high-speed device attached to it.");
   103             else if (portStatus & (1 << 9))
   107                     "USB: HUB: Hub port "   109                     << 
" has a low-speed device attached to it.");
   116                     "USB: HUB: Hub port "   118                     << 
" has a full-speed device attached to it.");
   124     m_UsbState = HasDriver;
   130     setPortFeature(nPort, PortReset);
   133     Time::delay(50 * Time::Multiplier::Millisecond);
   136     clearPortFeature(nPort, PortReset);
   139     while ((getPortStatus(nPort) & (1 << 4)))
   144     uint32_t portStatus = getPortStatus(nPort);
   145     return ((portStatus & 0x3) == 0x3);
   148 bool UsbHubDevice::setPortFeature(
size_t port, PortFeatureSelectors feature)
   150     return controlRequest(
   151         HubPortRequest, UsbRequest::SetFeature, feature, (port + 1) & 0xFF, 0,
   155 bool UsbHubDevice::clearPortFeature(
size_t port, PortFeatureSelectors feature)
   157     return controlRequest(
   158         HubPortRequest, UsbRequest::ClearFeature, feature, (port + 1) & 0xFF, 0,
   164     uint32_t *portStatus = 
new uint32_t(0);
   167         UsbRequestDirection::In | HubPortRequest, UsbRequest::GetStatus, 0,
   168         (port + 1) & 0xFF, 4, reinterpret_cast<uintptr_t>(portStatus));
   174     uintptr_t pTransaction, 
bool bToggle, UsbPid pid, uintptr_t pBuffer,
   177     m_pHub->addTransferToTransaction(
   178         pTransaction, bToggle, pid, pBuffer, nBytes);
   183     if ((m_Speed == HighSpeed) && (endpointInfo.speed != HighSpeed) &&
   184         !endpointInfo.nHubAddress)
   185         endpointInfo.nHubAddress = m_nAddress;
   186     return m_pHub->createTransaction(endpointInfo);
   190     uintptr_t pTransaction, 
void (*pCallback)(uintptr_t, ssize_t),
   193     m_pHub->doAsync(pTransaction, pCallback, pParam);
   197     UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes,
   198     void (*pCallback)(uintptr_t, ssize_t), uintptr_t pParam)
   200     if ((m_Speed == HighSpeed) && (endpointInfo.speed != HighSpeed) &&
   201         (!endpointInfo.nHubAddress))
   202         endpointInfo.nHubAddress = m_nAddress;
   203     m_pHub->addInterruptInHandler(
   204         endpointInfo, pBuffer, nBytes, pCallback, pParam);
 virtual bool portReset(uint8_t nPort, bool bErrorResponse=false)=0
Gets a UsbDevice from a given vendor:product pair. 
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 void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff. 
uint32_t getPortStatus(size_t port)
Top 32 bits hold change status. 
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. 
bool deviceConnected(uint8_t nPort, UsbSpeed speed)
Called when a device is connected to a port on the hub. 
virtual void doAsync(uintptr_t pTransaction, void(*pCallback)(uintptr_t, ssize_t)=0, uintptr_t pParam=0)
virtual bool portReset(uint8_t nPort, bool bErrorResponse=false)
Gets a UsbDevice from a given vendor:product pair. 
virtual uintptr_t createTransaction(UsbEndpoint endpointInfo)
Creates a new transaction with the given endpoint data.