@@ -245,9 +245,20 @@ void Controller::Init() {
245
245
NotifyHostControllerDoorbell ();
246
246
247
247
// 4.3.1 Resetting a Root Hub Port
248
+ /*
248
249
for (int slot = 1; slot <= num_of_slots_enabled_; slot++) {
249
250
ResetPort(slot);
250
251
}
252
+ */
253
+ for (int port = 1 ; port <= max_ports_; port++) {
254
+ uint32_t portsc = ReadPORTSC (port);
255
+ if (!portsc) continue ;
256
+ PutStringAndHex (" port" , port);
257
+ PutStringAndHex (" PORTSC" , portsc);
258
+ if (portsc & 1 && port_state_[port] == kDisconnected ) {
259
+ port_state_[port] = kNeedsPortReset ;
260
+ }
261
+ }
251
262
}
252
263
253
264
void Controller::ResetPort (int port) {
@@ -318,6 +329,10 @@ class Controller::DeviceContext {
318
329
endpoint_ctx[kDCISlotContext ][0 ] =
319
330
CombineFieldBits<31 , 27 >(endpoint_ctx[kDCISlotContext ][0 ], num_of_ent);
320
331
}
332
+ void SetPortSpeed (uint32_t port_speed) {
333
+ endpoint_ctx[kDCISlotContext ][0 ] = CombineFieldBits<23 , 20 >(
334
+ endpoint_ctx[kDCISlotContext ][0 ], port_speed);
335
+ }
321
336
void SetRootHubPortNumber (uint32_t root_port_num) {
322
337
endpoint_ctx[kDCISlotContext ][1 ] = CombineFieldBits<23 , 16 >(
323
338
endpoint_ctx[kDCISlotContext ][1 ], root_port_num);
@@ -415,6 +430,7 @@ class Controller::InputContext {
415
430
};
416
431
static_assert (sizeof (Controller::InputContext) == 0x420 );
417
432
433
+ constexpr uint32_t kPortSpeedFS = 1 ;
418
434
constexpr uint32_t kPortSpeedLS = 2 ;
419
435
constexpr uint32_t kPortSpeedHS = 3 ;
420
436
constexpr uint32_t kPortSpeedSS = 4 ;
@@ -426,7 +442,7 @@ static uint16_t GetMaxPacketSizeFromPORTSCPortSpeed(uint32_t port_speed) {
426
442
// • Max Packet Size = The default maximum packet size for the Default
427
443
// Control Endpoint, as function of the PORTSC Port Speed field.
428
444
// 7.2.2.1.1 Default USB Speed ID Mapping
429
- if (port_speed == kPortSpeedLS )
445
+ if (port_speed == kPortSpeedLS || port_speed || kPortSpeedFS )
430
446
return 8 ;
431
447
if (port_speed == kPortSpeedHS )
432
448
return 64 ;
@@ -436,13 +452,16 @@ static uint16_t GetMaxPacketSizeFromPORTSCPortSpeed(uint32_t port_speed) {
436
452
}
437
453
438
454
static const char * GetSpeedNameFromPORTSCPortSpeed (uint32_t port_speed) {
455
+ if (port_speed == kPortSpeedFS )
456
+ return " Full-speed" ;
439
457
if (port_speed == kPortSpeedLS )
440
458
return " Low-speed" ;
441
459
if (port_speed == kPortSpeedHS )
442
460
return " High-speed" ;
443
461
if (port_speed == kPortSpeedSS )
444
462
return " SuperSpeed Gen1 x1" ;
445
463
PutString (" GetSpeedNameFromPORTSCPortSpeed: Not supported speed\n " );
464
+ PutStringAndHex (" port_speed" , port_speed);
446
465
return nullptr ;
447
466
}
448
467
@@ -474,6 +493,7 @@ void Controller::HandleEnableSlotCompleted(int slot, int port) {
474
493
// 5. Initialize the Input default control Endpoint 0 Context (6.2.3)
475
494
uint32_t portsc = ReadPORTSC (port);
476
495
uint32_t port_speed = GetBits<13 , 10 , uint32_t , uint32_t >(portsc);
496
+ dctx.SetPortSpeed (port_speed);
477
497
PutString (" Port Speed: " );
478
498
const char * speed_str = GetSpeedNameFromPORTSCPortSpeed (port_speed);
479
499
if (!speed_str) {
@@ -945,6 +965,13 @@ void Controller::CheckPortAndInitiateProcess() {
945
965
return ;
946
966
}
947
967
}
968
+ for (int i = 0 ; i < kMaxNumOfPorts ; i++) {
969
+ if (port_state_[i] == kNeedsPortReset ) {
970
+ ResetPort (i);
971
+ port_state_[i] = kNeedsInitializing ;
972
+ return ;
973
+ }
974
+ }
948
975
}
949
976
950
977
void Controller::PollEvents () {
@@ -1005,11 +1032,13 @@ void Controller::PollEvents() {
1005
1032
}
1006
1033
break ;
1007
1034
case kTRBTypePortStatusChangeEvent :
1035
+ /*
1008
1036
if (e.IsCompletedWithSuccess()) {
1009
1037
HandlePortStatusChange(
1010
1038
static_cast<int>(GetBits<31, 24, uint64_t>(e.data)));
1011
1039
break;
1012
1040
}
1041
+ */
1013
1042
PutString (" PortStatusChangeEvent\n " );
1014
1043
e.PrintCompletionCode ();
1015
1044
break ;
0 commit comments