20 #include "modules/system/usb/UsbHub.h" 21 #include "modules/system/usb/Usb.h" 22 #include "modules/system/usb/UsbDevice.h" 23 #include "modules/system/usb/UsbPnP.h" 24 #include "pedigree/kernel/Log.h" 25 #include "pedigree/kernel/utilities/ExtensibleBitmap.h" 26 #include "pedigree/kernel/utilities/Vector.h" 27 #include "pedigree/kernel/utilities/new" 49 NOTICE(
"USB: Adding device on port " <<
Dec << nPort <<
Hex);
54 pRootHub = static_cast<UsbHub *>(pRootHub->
getParent());
57 uint8_t lastAddress = 0, nAddress = 0;
69 ERROR(
"USB: HUB: Out of addresses!");
78 "USB: Allocated device on port " <<
Dec << nPort <<
Hex 79 <<
" address " << nAddress);
82 pDevice =
new UsbDevice(
this, nPort, speed);
89 if (pDevice->
getUsbState() != UsbDevice::Configured)
92 "USB: Device initialisation ended up not giving a configured " 94 << nRetry <<
" of 2].");
97 if (pDevice->
getUsbState() >= UsbDevice::HasDescriptors)
103 NOTICE(
"USB: Performing a port reset on port " << nPort);
104 if ((!pRootHub->
portReset(nPort,
true)) && (nRetry < 1))
107 NOTICE(
"USB: Port reset failed (port " << nPort <<
")");
116 "USB: Device on port " <<
Dec << nPort <<
Hex 117 <<
" accepted address " << nAddress);
121 lastAddress = nAddress;
129 NOTICE(
"Device initialisation couldn't configure the device.");
139 for (
size_t i = 0; i < interfaceList.
count(); i++)
144 if (pInterface->nAlternateSetting)
160 "USB: Device (address " 161 << nAddress <<
"): " << pDescriptor->sVendor <<
" " 162 << pDescriptor->sProduct <<
", class " <<
Dec << pInterface->nClass
163 <<
":" << pInterface->nSubclass <<
":" << pInterface->nProtocol
175 uint8_t nAddress = 0;
186 if (pDevice->
getPort() != nPort)
192 ERROR(
"USB: HUB: Found devices on the same port with different " 195 if (pDevice->
getUsbState() >= UsbDevice::HasDescriptors)
200 ERROR(
"USB: HUB: Found devices on the same port with different " 201 "device descriptors");
216 pRootHub = static_cast<UsbHub *>(pRootHub->
getParent());
227 pSyncParam->nResult = nResult;
228 pSyncParam->semaphore.
release();
230 if (pSyncParam->timedOut)
241 nTransaction, syncCallback, reinterpret_cast<uintptr_t>(pSyncParam));
247 bool bTimeout = !pSyncParam->semaphore.
acquire(
248 1, timeout / 1000, (timeout % 1000) * 1000);
252 WARNING(
"USB: a transaction timed out.");
253 pSyncParam->timedOut =
true;
254 return -TransactionError;
258 ssize_t ret = pSyncParam->nResult;
virtual bool portReset(uint8_t nPort, bool bErrorResponse=false)=0
Gets a UsbDevice from a given vendor:product pair.
bool acquire(size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0)
ConfigDescriptor * getConfiguration()
Returns the configuration in use.
void deviceDisconnected(uint8_t nPort)
Called when a device is disconnected from a port on the hub.
ExtensibleBitmap m_UsedAddresses
void initialise(uint8_t nAddress)
Initialises the device at the given address.
bool probeDevice(Device *pDeviceBase)
Tries to find a suitable driver for the given USB device.
Structure used synchronous transactions.
Same as Controller, but exposes USB devices.
void addChild(Device *pDevice)
uint8_t getAddress()
Returns the current address of the device.
bool deviceConnected(uint8_t nPort, UsbSpeed speed)
Called when a device is connected to a port on the hub.
void setParent(Device *p)
DeviceDescriptor * getDescriptor()
Returns the device descriptor of the device.
static void syncCallback(uintptr_t pParam, ssize_t ret)
Callback used by synchronous transactions.
ssize_t doSync(uintptr_t nTransaction, uint32_t timeout=5000)
static UsbPnP & instance()
Singleton design.
uint8_t getPort()
Returns the number of the port on which the device is connected.
UsbState getUsbState()
Returns the current state of the device.
Device * getParent() const
void ignoreConnectionChanges(uint8_t nPort, bool bIgnore=true)
void useInterface(uint8_t nInterface)
Switches to the given interface.
Vector< Device * > m_Children