@@ -153,15 +153,14 @@ void Controller::ResetPort(int port) {
153
153
while ((ReadPORTSC (port) & kPortSCBitPortReset )) {
154
154
// wait
155
155
}
156
- port_state_[port] = kNeedsSlotAssignment ;
157
- port_is_initializing_[port] = true ;
156
+ port_state_[port] = kDisabled ;
157
+ port_is_initializing_[port] = false ;
158
158
}
159
159
160
160
void Controller::DisablePort (int port) {
161
161
PutStringAndHex (" Disable port" , port);
162
162
WritePORTSC (port, 2 );
163
- port_state_[port] = kDisabled ;
164
- port_is_initializing_[port] = false ;
163
+ ResetPort (port);
165
164
}
166
165
167
166
class Controller ::EndpointContext {
@@ -712,6 +711,7 @@ void Controller::HandleAddressDeviceCompleted(int slot) {
712
711
uint8_t * buf = AllocMemoryForMappedIO<uint8_t *>(kSizeOfDescriptorBuffer );
713
712
descriptor_buffers_[slot] = buf;
714
713
port_is_initializing_[slot_info_[slot].port ] = false ;
714
+ kprintf (" AddressDevice for port %d completed\n " , slot_info_[slot].port );
715
715
RequestDeviceDescriptor (slot, SlotInfo::kWaitingForDeviceDescriptor );
716
716
}
717
717
@@ -858,24 +858,25 @@ void Controller::HandleTransferEvent(BasicTRB& e) {
858
858
}
859
859
}
860
860
861
+ static void PrintPortSCValue (uint32_t portsc) {
862
+ PutStringAndHex (" PORTSC" , portsc);
863
+ PutString (" PortSC: " );
864
+ PutHex64ZeroFilled (portsc);
865
+ PutString (" (" );
866
+ PutString ((portsc & (1 << 9 )) ? " 1" : " 0" );
867
+ PutString ((portsc & (1 << 0 )) ? " 1" : " 0" );
868
+ PutString ((portsc & (1 << 1 )) ? " 1" : " 0" );
869
+ PutString ((portsc & (1 << 4 )) ? " 1" : " 0" );
870
+ PutString (" ) " );
871
+ // 7.2.2.1.1 Default USB Speed ID Mapping
872
+ PutString (" Speed=0x" );
873
+ PutHex64 (GetBits<13 , 10 >(portsc));
874
+ PutString (" \n " );
875
+ }
861
876
void Controller::PrintPortSC () {
862
877
for (int slot = 1 ; slot <= num_of_slots_enabled_; slot++) {
863
- uint32_t portsc = ReadPORTSC (slot);
864
878
PutStringAndHex (" Port" , slot);
865
- PutStringAndHex (" PORTSC" , portsc);
866
- PutString (" PortSC: " );
867
- PutHex64ZeroFilled (portsc);
868
- PutString (" (" );
869
- PutString ((portsc & (1 << 9 )) ? " 1" : " 0" );
870
- PutString ((portsc & (1 << 0 )) ? " 1" : " 0" );
871
- PutString ((portsc & (1 << 1 )) ? " 1" : " 0" );
872
- PutString ((portsc & (1 << 4 )) ? " 1" : " 0" );
873
- PutString (" ) " );
874
- // 7.2.2.1.1 Default USB Speed ID Mapping
875
- PutString (" Speed=0x" );
876
- PutHex64 (GetBits<13 , 10 >(portsc));
877
-
878
- PutString (" \n " );
879
+ PrintPortSCValue (ReadPORTSC (slot));
879
880
}
880
881
}
881
882
void Controller::PrintUSBSTS () {
@@ -891,6 +892,7 @@ void Controller::PrintUSBSTS() {
891
892
}
892
893
893
894
void Controller::CheckPortAndInitiateProcess () {
895
+ HPET& hpet = HPET::GetInstance ();
894
896
for (int i = 0 ; i < kMaxNumOfPorts ; i++) {
895
897
if (port_state_[i] == kNeedsSlotAssignment ) {
896
898
port_state_[i] = kWaitingForSlotAssignment ;
@@ -903,16 +905,28 @@ void Controller::CheckPortAndInitiateProcess() {
903
905
enable_slot_trb.control = (BasicTRB::kTRBTypeEnableSlotCommand << 10 );
904
906
cmd_ring_->Push ();
905
907
NotifyHostControllerDoorbell ();
908
+ kprintf (" Sent slot assignment request for port%d\n " , i);
906
909
return ;
907
910
}
908
911
}
909
912
for (int i = 0 ; i < kMaxNumOfPorts ; i++) {
910
- if (port_is_initializing_[i])
911
- return ;
913
+ if (!port_is_initializing_[i]) {
914
+ continue ;
915
+ }
916
+ if (port_init_deadline_ < hpet.ReadMainCounterValue ()) {
917
+ kprintf (" Port init deadline exceeded for port %d\n " , i);
918
+ DisablePort (i);
919
+ }
920
+ return ;
912
921
}
913
922
for (int i = 0 ; i < kMaxNumOfPorts ; i++) {
914
923
if (port_state_[i] == kAttachedUSB2 ) {
915
924
ResetPort (i);
925
+ port_state_[i] = kNeedsSlotAssignment ;
926
+ port_is_initializing_[i] = true ;
927
+ kprintf (" Port init deadline for port %d is set.\n " , i);
928
+ port_init_deadline_ =
929
+ hpet.ReadMainCounterValue () + hpet.GetCountPerSecond ();
916
930
return ;
917
931
}
918
932
}
@@ -990,13 +1004,27 @@ void Controller::PollEvents() {
990
1004
}
991
1005
for (int port = 1 ; port <= max_ports_; port++) {
992
1006
uint32_t portsc = ReadPORTSC (port);
1007
+ if (!(portsc & kPortSCBitCurrentConnectStatus )) {
1008
+ // Device is disconnected
1009
+ if (port_state_[port] == kDisconnected ) {
1010
+ continue ;
1011
+ }
1012
+ DisablePort (port);
1013
+ port_state_[port] = kDisconnected ;
1014
+ kprintf (" port %d disconnected\n " , port);
1015
+ PrintPortSCValue (ReadPORTSC (port));
1016
+ continue ;
1017
+ }
993
1018
if (port_state_[port] == kDisconnected &&
994
1019
(portsc & kPortSCBitCurrentConnectStatus )) {
1020
+ kprintf (" port %d connected\n " , port);
1021
+ PrintPortSCValue (ReadPORTSC (port));
995
1022
port_state_[port] = kAttached ;
996
1023
}
997
1024
if (port_state_[port] == kAttached &&
998
1025
!(portsc & kPortSCBitPortEnableDisable ) &&
999
1026
!(portsc & kPortSCBitPortReset ) && ReadPORTSCLinkState (port) == 7 ) {
1027
+ kprintf (" port %d: kAttachedUSB2\n " , port);
1000
1028
port_state_[port] = kAttachedUSB2 ;
1001
1029
}
1002
1030
}
0 commit comments