3 Unified interface for RootHub and Hub.
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 // Array that maps the change bit to feature value which is
14 // used to clear these change bit. USB HUB API will clear
15 // these change bit automatically. For non-root hub, these
16 // bits determine whether hub will report the port in changed
19 USB_CHANGE_FEATURE_MAP mHubFeatureMap
[] = {
20 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
21 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
22 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
23 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
24 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
}
27 USB_CHANGE_FEATURE_MAP mRootHubFeatureMap
[] = {
28 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
29 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
30 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
31 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
32 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
},
36 // USB hub class specific requests. Although USB hub
37 // is related to an interface, these requests are sent
38 // to the control endpoint of the device.
41 USB hub control transfer to set the hub depth.
43 @param HubDev The device of the hub.
44 @param Depth The depth to set.
46 @retval EFI_SUCCESS Depth of the hub is set.
47 @retval Others Failed to set the depth.
51 UsbHubCtrlSetHubDepth (
52 IN USB_DEVICE
*HubDev
,
58 Status
= UsbCtrlRequest (
63 USB_HUB_REQ_SET_DEPTH
,
74 USB hub control transfer to clear the hub feature.
76 @param HubDev The device of the hub.
77 @param Feature The feature to clear.
79 @retval EFI_SUCCESS Feature of the hub is cleared.
80 @retval Others Failed to clear the feature.
84 UsbHubCtrlClearHubFeature (
85 IN USB_DEVICE
*HubDev
,
91 Status
= UsbCtrlRequest (
96 USB_HUB_REQ_CLEAR_FEATURE
,
108 Clear the feature of the device's port.
110 @param HubDev The hub device.
111 @param Port The port to clear feature.
112 @param Feature The feature to clear.
114 @retval EFI_SUCCESS The feature of the port is cleared.
115 @retval Others Failed to clear the feature.
119 UsbHubCtrlClearPortFeature (
120 IN USB_DEVICE
*HubDev
,
128 // In USB bus, all the port index starts from 0. But HUB
129 // indexes its port from 1. So, port number is added one.
131 Status
= UsbCtrlRequest (
136 USB_HUB_REQ_CLEAR_FEATURE
,
148 Clear the transaction translate buffer if full/low
149 speed control/bulk transfer failed and the transfer
150 uses this hub as translator.Remember to clear the TT
151 buffer of transaction translator, not that of the
154 @param HubDev The hub device.
155 @param Port The port of the hub.
156 @param DevAddr Address of the failed transaction.
157 @param EpNum The endpoint number of the failed transaction.
158 @param EpType The type of failed transaction.
160 @retval EFI_SUCCESS The TT buffer is cleared.
161 @retval Others Failed to clear the TT buffer.
165 UsbHubCtrlClearTTBuffer (
166 IN USB_DEVICE
*HubDev
,
177 // Check USB2.0 spec page 424 for wValue's encoding
179 Value
= (UINT16
) ((EpNum
& 0x0F) | (DevAddr
<< 4) |
180 ((EpType
& 0x03) << 11) | ((EpNum
& 0x80) << 15));
182 Status
= UsbCtrlRequest (
187 USB_HUB_REQ_CLEAR_TT
,
198 Usb hub control transfer to get the (super speed) hub descriptor.
200 @param HubDev The hub device.
201 @param Buf The buffer to hold the descriptor.
202 @param Len The length to retrieve.
204 @retval EFI_SUCCESS The hub descriptor is retrieved.
205 @retval Others Failed to retrieve the hub descriptor.
209 UsbHubCtrlGetHubDesc (
210 IN USB_DEVICE
*HubDev
,
218 DescType
= (HubDev
->Speed
== EFI_USB_SPEED_SUPER
) ?
219 USB_DESC_TYPE_HUB_SUPER_SPEED
:
222 Status
= UsbCtrlRequest (
227 USB_HUB_REQ_GET_DESC
,
228 (UINT16
) (DescType
<< 8),
239 Usb hub control transfer to get the hub status.
241 @param HubDev The hub device.
242 @param State The variable to return the status.
244 @retval EFI_SUCCESS The hub status is returned in State.
245 @retval Others Failed to get the hub status.
249 UsbHubCtrlGetHubStatus (
250 IN USB_DEVICE
*HubDev
,
256 Status
= UsbCtrlRequest (
261 USB_HUB_REQ_GET_STATUS
,
273 Usb hub control transfer to get the port status.
275 @param HubDev The hub device.
276 @param Port The port of the hub.
277 @param State Variable to return the hub port state.
279 @retval EFI_SUCCESS The port state is returned in State.
280 @retval Others Failed to retrieve the port state.
284 UsbHubCtrlGetPortStatus (
285 IN USB_DEVICE
*HubDev
,
293 // In USB bus, all the port index starts from 0. But HUB
294 // indexes its port from 1. So, port number is added one.
295 // No need to convert the hub bit to UEFI definition, they
298 Status
= UsbCtrlRequest (
303 USB_HUB_REQ_GET_STATUS
,
315 Usb hub control transfer to set the port feature.
317 @param HubDev The Usb hub device.
318 @param Port The Usb port to set feature for.
319 @param Feature The feature to set.
321 @retval EFI_SUCCESS The feature is set for the port.
322 @retval Others Failed to set the feature.
326 UsbHubCtrlSetPortFeature (
327 IN USB_DEVICE
*HubDev
,
335 // In USB bus, all the port index starts from 0. But HUB
336 // indexes its port from 1. So, port number is added one.
338 Status
= UsbCtrlRequest (
343 USB_HUB_REQ_SET_FEATURE
,
355 Read the whole usb hub descriptor. It is necessary
356 to do it in two steps because hub descriptor is of
359 @param HubDev The hub device.
360 @param HubDesc The variable to return the descriptor.
362 @retval EFI_SUCCESS The hub descriptor is read.
363 @retval Others Failed to read the hub descriptor.
368 IN USB_DEVICE
*HubDev
,
369 OUT EFI_USB_HUB_DESCRIPTOR
*HubDesc
375 // First get the hub descriptor length
377 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, 2);
379 if (EFI_ERROR (Status
)) {
384 // Get the whole hub descriptor
386 return UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, HubDesc
->Length
);
392 Ack the hub change bits. If these bits are not ACKed, Hub will
393 always return changed bit map from its interrupt endpoint.
395 @param HubDev The hub device.
397 @retval EFI_SUCCESS The hub change status is ACKed.
398 @retval Others Failed to ACK the hub status.
403 IN USB_DEVICE
*HubDev
406 EFI_USB_PORT_STATUS HubState
;
409 Status
= UsbHubCtrlGetHubStatus (HubDev
, (UINT32
*) &HubState
);
411 if (EFI_ERROR (Status
)) {
415 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_LOCAL_POWER
)) {
416 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_LOCAL_POWER
);
419 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_OVER_CURRENT
)) {
420 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_OVER_CURRENT
);
428 Test whether the interface is a hub interface.
430 @param UsbIf The interface to test.
432 @retval TRUE The interface is a hub interface.
433 @retval FALSE The interface isn't a hub interface.
438 IN USB_INTERFACE
*UsbIf
441 EFI_USB_INTERFACE_DESCRIPTOR
*Setting
;
444 // If the hub is a high-speed hub with multiple TT,
445 // the hub will has a default setting of single TT.
447 Setting
= &UsbIf
->IfSetting
->Desc
;
449 if ((Setting
->InterfaceClass
== USB_HUB_CLASS_CODE
) &&
450 (Setting
->InterfaceSubClass
== USB_HUB_SUBCLASS_CODE
)) {
460 The callback function to the USB hub status change
461 interrupt endpoint. It is called periodically by
462 the underlying host controller.
464 @param Data The data read.
465 @param DataLength The length of the data read.
466 @param Context The context.
467 @param Result The result of the last interrupt transfer.
469 @retval EFI_SUCCESS The process is OK.
470 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
482 USB_INTERFACE
*HubIf
;
483 EFI_USB_IO_PROTOCOL
*UsbIo
;
484 EFI_USB_ENDPOINT_DESCRIPTOR
*EpDesc
;
487 HubIf
= (USB_INTERFACE
*) Context
;
488 UsbIo
= &(HubIf
->UsbIo
);
489 EpDesc
= &(HubIf
->HubEp
->Desc
);
491 if (Result
!= EFI_USB_NOERROR
) {
493 // If endpoint is stalled, clear the stall. Use UsbIo to access
494 // the control transfer so internal status are maintained.
496 if (USB_BIT_IS_SET (Result
, EFI_USB_ERR_STALL
)) {
500 USB_FEATURE_ENDPOINT_HALT
,
501 EpDesc
->EndpointAddress
506 // Delete and submit a new async interrupt
508 Status
= UsbIo
->UsbAsyncInterruptTransfer (
510 EpDesc
->EndpointAddress
,
518 if (EFI_ERROR (Status
)) {
519 DEBUG (( DEBUG_ERROR
, "UsbOnHubInterrupt: failed to remove async transfer - %r\n", Status
));
523 Status
= UsbIo
->UsbAsyncInterruptTransfer (
525 EpDesc
->EndpointAddress
,
527 USB_HUB_POLL_INTERVAL
,
528 HubIf
->NumOfPort
/ 8 + 1,
533 if (EFI_ERROR (Status
)) {
534 DEBUG (( DEBUG_ERROR
, "UsbOnHubInterrupt: failed to submit new async transfer - %r\n", Status
));
540 if ((DataLength
== 0) || (Data
== NULL
)) {
545 // OK, actually something is changed, save the change map
546 // then signal the HUB to do enumeration. This is a good
547 // practise since UsbOnHubInterrupt is called in the context
548 // of host controller's AsyncInterrupt monitor.
550 HubIf
->ChangeMap
= AllocateZeroPool (DataLength
);
552 if (HubIf
->ChangeMap
== NULL
) {
553 return EFI_OUT_OF_RESOURCES
;
556 CopyMem (HubIf
->ChangeMap
, Data
, DataLength
);
557 gBS
->SignalEvent (HubIf
->HubNotify
);
566 Initialize the device for a non-root hub.
568 @param HubIf The USB hub interface.
570 @retval EFI_SUCCESS The hub is initialized.
571 @retval EFI_DEVICE_ERROR Failed to initialize the hub.
576 IN USB_INTERFACE
*HubIf
579 UINT8 HubDescBuffer
[256];
580 EFI_USB_HUB_DESCRIPTOR
*HubDesc
;
581 USB_ENDPOINT_DESC
*EpDesc
;
582 USB_INTERFACE_SETTING
*Setting
;
583 EFI_USB_IO_PROTOCOL
*UsbIo
;
591 // Locate the interrupt endpoint for port change map
593 HubIf
->IsHub
= FALSE
;
594 Setting
= HubIf
->IfSetting
;
595 HubDev
= HubIf
->Device
;
597 NumEndpoints
= Setting
->Desc
.NumEndpoints
;
599 for (Index
= 0; Index
< NumEndpoints
; Index
++) {
600 ASSERT ((Setting
->Endpoints
!= NULL
) && (Setting
->Endpoints
[Index
] != NULL
));
602 EpDesc
= Setting
->Endpoints
[Index
];
604 if (USB_BIT_IS_SET (EpDesc
->Desc
.EndpointAddress
, USB_ENDPOINT_DIR_IN
) &&
605 (USB_ENDPOINT_TYPE (&EpDesc
->Desc
) == USB_ENDPOINT_INTERRUPT
)) {
610 if (Index
== NumEndpoints
) {
611 DEBUG (( DEBUG_ERROR
, "UsbHubInit: no interrupt endpoint found for hub %d\n", HubDev
->Address
));
612 return EFI_DEVICE_ERROR
;
616 // The length field of descriptor is UINT8 type, so the buffer
617 // with 256 bytes is enough to hold the descriptor data.
619 HubDesc
= (EFI_USB_HUB_DESCRIPTOR
*) HubDescBuffer
;
620 Status
= UsbHubReadDesc (HubDev
, HubDesc
);
622 if (EFI_ERROR (Status
)) {
623 DEBUG (( DEBUG_ERROR
, "UsbHubInit: failed to read HUB descriptor %r\n", Status
));
627 HubIf
->NumOfPort
= HubDesc
->NumPorts
;
629 DEBUG (( DEBUG_INFO
, "UsbHubInit: hub %d has %d ports\n", HubDev
->Address
,HubIf
->NumOfPort
));
632 // OK, set IsHub to TRUE. Now usb bus can handle this device
633 // as a working HUB. If failed earlier, bus driver will not
634 // recognize it as a hub. Other parts of the bus should be able
638 HubIf
->HubApi
= &mUsbHubApi
;
639 HubIf
->HubEp
= EpDesc
;
641 if (HubIf
->Device
->Speed
== EFI_USB_SPEED_SUPER
) {
642 Depth
= (UINT16
)(HubIf
->Device
->Tier
- 1);
643 DEBUG ((DEBUG_INFO
, "UsbHubInit: Set Hub Depth as 0x%x\n", Depth
));
644 UsbHubCtrlSetHubDepth (HubIf
->Device
, Depth
);
646 for (Index
= 0; Index
< HubDesc
->NumPorts
; Index
++) {
647 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, USB_HUB_PORT_REMOTE_WAKE_MASK
);
651 // Feed power to all the hub ports. It should be ok
652 // for both gang/individual powered hubs.
654 for (Index
= 0; Index
< HubDesc
->NumPorts
; Index
++) {
655 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_POWER
);
659 // Update for the usb hub has no power on delay requirement
661 if (HubDesc
->PwrOn2PwrGood
> 0) {
662 gBS
->Stall (HubDesc
->PwrOn2PwrGood
* USB_SET_PORT_POWER_STALL
);
664 UsbHubAckHubStatus (HubIf
->Device
);
668 // Create an event to enumerate the hub's port. On
670 Status
= gBS
->CreateEvent (
678 if (EFI_ERROR (Status
)) {
679 DEBUG (( DEBUG_ERROR
, "UsbHubInit: failed to create signal for hub %d - %r\n",
680 HubDev
->Address
, Status
));
686 // Create AsyncInterrupt to query hub port change endpoint
687 // periodically. If the hub ports are changed, hub will return
688 // changed port map from the interrupt endpoint. The port map
689 // must be able to hold (HubIf->NumOfPort + 1) bits (one bit for
690 // host change status).
692 UsbIo
= &HubIf
->UsbIo
;
693 Status
= UsbIo
->UsbAsyncInterruptTransfer (
695 EpDesc
->Desc
.EndpointAddress
,
697 USB_HUB_POLL_INTERVAL
,
698 HubIf
->NumOfPort
/ 8 + 1,
703 if (EFI_ERROR (Status
)) {
704 DEBUG (( DEBUG_ERROR
, "UsbHubInit: failed to queue interrupt transfer for hub %d - %r\n",
705 HubDev
->Address
, Status
));
707 gBS
->CloseEvent (HubIf
->HubNotify
);
708 HubIf
->HubNotify
= NULL
;
713 DEBUG (( DEBUG_INFO
, "UsbHubInit: hub %d initialized\n", HubDev
->Address
));
720 Get the port status. This function is required to
721 ACK the port change bits although it will return
722 the port changes in PortState. Bus enumeration code
723 doesn't need to ACK the port change bits.
725 @param HubIf The hub interface.
726 @param Port The port of the hub to get state.
727 @param PortState Variable to return the port state.
729 @retval EFI_SUCCESS The port status is successfully returned.
730 @retval Others Failed to return the status.
734 UsbHubGetPortStatus (
735 IN USB_INTERFACE
*HubIf
,
737 OUT EFI_USB_PORT_STATUS
*PortState
742 Status
= UsbHubCtrlGetPortStatus (HubIf
->Device
, Port
, PortState
);
750 Clear the port change status.
752 @param HubIf The hub interface.
753 @param Port The hub port.
757 UsbHubClearPortChange (
758 IN USB_INTERFACE
*HubIf
,
762 EFI_USB_PORT_STATUS PortState
;
763 USB_CHANGE_FEATURE_MAP
*Map
;
767 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
769 if (EFI_ERROR (Status
)) {
774 // OK, get the usb port status, now ACK the change bits.
775 // Don't return error when failed to clear the change bits.
776 // It may lead to extra port state report. USB bus should
777 // be able to handle this.
779 for (Index
= 0; Index
< ARRAY_SIZE (mHubFeatureMap
); Index
++) {
780 Map
= &mHubFeatureMap
[Index
];
782 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
783 UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT16
) Map
->Feature
);
791 Function to set the port feature for non-root hub.
793 @param HubIf The hub interface.
794 @param Port The port of the hub.
795 @param Feature The feature of the port to set.
797 @retval EFI_SUCCESS The hub port feature is set.
798 @retval Others Failed to set the port feature.
802 UsbHubSetPortFeature (
803 IN USB_INTERFACE
*HubIf
,
805 IN EFI_USB_PORT_FEATURE Feature
810 Status
= UsbHubCtrlSetPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
817 Interface function to clear the port feature for non-root hub.
819 @param HubIf The hub interface.
820 @param Port The port of the hub to clear feature for.
821 @param Feature The feature to clear.
823 @retval EFI_SUCCESS The port feature is cleared.
824 @retval Others Failed to clear the port feature.
828 UsbHubClearPortFeature (
829 IN USB_INTERFACE
*HubIf
,
831 IN EFI_USB_PORT_FEATURE Feature
836 Status
= UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
843 Interface function to reset the port.
845 @param HubIf The hub interface.
846 @param Port The port to reset.
848 @retval EFI_SUCCESS The hub port is reset.
849 @retval EFI_TIMEOUT Failed to reset the port in time.
850 @retval Others Failed to reset the port.
855 IN USB_INTERFACE
*HubIf
,
859 EFI_USB_PORT_STATUS PortState
;
863 Status
= UsbHubSetPortFeature (HubIf
, Port
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_RESET
);
865 if (EFI_ERROR (Status
)) {
870 // Drive the reset signal for worst 20ms. Check USB 2.0 Spec
871 // section 7.1.7.5 for timing requirements.
873 gBS
->Stall (USB_SET_PORT_RESET_STALL
);
876 // Check USB_PORT_STAT_C_RESET bit to see if the resetting state is done.
878 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
880 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
881 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
883 if (EFI_ERROR (Status
)) {
887 if (!EFI_ERROR (Status
) &&
888 USB_BIT_IS_SET (PortState
.PortChangeStatus
, USB_PORT_STAT_C_RESET
)) {
889 gBS
->Stall (USB_SET_PORT_RECOVERY_STALL
);
893 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
901 Release the hub's control of the interface.
903 @param HubIf The hub interface.
905 @retval EFI_SUCCESS The interface is release of hub control.
910 IN USB_INTERFACE
*HubIf
913 EFI_USB_IO_PROTOCOL
*UsbIo
;
916 UsbIo
= &HubIf
->UsbIo
;
917 Status
= UsbIo
->UsbAsyncInterruptTransfer (
919 HubIf
->HubEp
->Desc
.EndpointAddress
,
921 USB_HUB_POLL_INTERVAL
,
927 if (EFI_ERROR (Status
)) {
931 gBS
->CloseEvent (HubIf
->HubNotify
);
933 HubIf
->IsHub
= FALSE
;
934 HubIf
->HubApi
= NULL
;
936 HubIf
->HubNotify
= NULL
;
938 DEBUG (( DEBUG_INFO
, "UsbHubRelease: hub device %d released\n", HubIf
->Device
->Address
));
945 Initialize the interface for root hub.
947 @param HubIf The root hub interface.
949 @retval EFI_SUCCESS The interface is initialized for root hub.
950 @retval Others Failed to initialize the hub.
955 IN USB_INTERFACE
*HubIf
963 Status
= UsbHcGetCapability (HubIf
->Device
->Bus
, &MaxSpeed
, &NumOfPort
, &Support64
);
965 if (EFI_ERROR (Status
)) {
969 DEBUG (( DEBUG_INFO
, "UsbRootHubInit: root hub %p - max speed %d, %d ports\n",
970 HubIf
, MaxSpeed
, NumOfPort
));
973 HubIf
->HubApi
= &mUsbRootHubApi
;
975 HubIf
->MaxSpeed
= MaxSpeed
;
976 HubIf
->NumOfPort
= NumOfPort
;
977 HubIf
->HubNotify
= NULL
;
980 // Create a timer to poll root hub ports periodically
982 Status
= gBS
->CreateEvent (
983 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
985 UsbRootHubEnumeration
,
990 if (EFI_ERROR (Status
)) {
995 // It should signal the event immediately here, or device detection
996 // by bus enumeration might be delayed by the timer interval.
998 gBS
->SignalEvent (HubIf
->HubNotify
);
1000 Status
= gBS
->SetTimer (
1003 USB_ROOTHUB_POLL_INTERVAL
1006 if (EFI_ERROR (Status
)) {
1007 gBS
->CloseEvent (HubIf
->HubNotify
);
1015 Get the port status. This function is required to
1016 ACK the port change bits although it will return
1017 the port changes in PortState. Bus enumeration code
1018 doesn't need to ACK the port change bits.
1020 @param HubIf The root hub interface.
1021 @param Port The root hub port to get the state.
1022 @param PortState Variable to return the port state.
1024 @retval EFI_SUCCESS The port state is returned.
1025 @retval Others Failed to retrieve the port state.
1029 UsbRootHubGetPortStatus (
1030 IN USB_INTERFACE
*HubIf
,
1032 OUT EFI_USB_PORT_STATUS
*PortState
1038 Bus
= HubIf
->Device
->Bus
;
1039 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, PortState
);
1046 Clear the port change status.
1048 @param HubIf The root hub interface.
1049 @param Port The root hub port.
1053 UsbRootHubClearPortChange (
1054 IN USB_INTERFACE
*HubIf
,
1058 EFI_USB_PORT_STATUS PortState
;
1059 USB_CHANGE_FEATURE_MAP
*Map
;
1063 Status
= UsbRootHubGetPortStatus (HubIf
, Port
, &PortState
);
1065 if (EFI_ERROR (Status
)) {
1070 // OK, get the usb port status, now ACK the change bits.
1071 // Don't return error when failed to clear the change bits.
1072 // It may lead to extra port state report. USB bus should
1073 // be able to handle this.
1075 for (Index
= 0; Index
< ARRAY_SIZE (mRootHubFeatureMap
); Index
++) {
1076 Map
= &mRootHubFeatureMap
[Index
];
1078 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
1079 UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, (EFI_USB_PORT_FEATURE
) Map
->Feature
);
1086 Set the root hub port feature.
1088 @param HubIf The Usb hub interface.
1089 @param Port The hub port.
1090 @param Feature The feature to set.
1092 @retval EFI_SUCCESS The root hub port is set with the feature.
1093 @retval Others Failed to set the feature.
1097 UsbRootHubSetPortFeature (
1098 IN USB_INTERFACE
*HubIf
,
1100 IN EFI_USB_PORT_FEATURE Feature
1105 Status
= UsbHcSetRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1112 Clear the root hub port feature.
1114 @param HubIf The root hub interface.
1115 @param Port The root hub port.
1116 @param Feature The feature to clear.
1118 @retval EFI_SUCCESS The root hub port is cleared of the feature.
1119 @retval Others Failed to clear the feature.
1123 UsbRootHubClearPortFeature (
1124 IN USB_INTERFACE
*HubIf
,
1126 IN EFI_USB_PORT_FEATURE Feature
1131 Status
= UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1138 Interface function to reset the root hub port.
1140 @param RootIf The root hub interface.
1141 @param Port The port to reset.
1143 @retval EFI_SUCCESS The hub port is reset.
1144 @retval EFI_TIMEOUT Failed to reset the port in time.
1145 @retval EFI_NOT_FOUND The low/full speed device connected to high speed.
1146 root hub is released to the companion UHCI.
1147 @retval Others Failed to reset the port.
1151 UsbRootHubResetPort (
1152 IN USB_INTERFACE
*RootIf
,
1158 EFI_USB_PORT_STATUS PortState
;
1162 // Notice: although EHCI requires that ENABLED bit be cleared
1163 // when reset the port, we don't need to care that here. It
1164 // should be handled in the EHCI driver.
1166 Bus
= RootIf
->Device
->Bus
;
1168 Status
= UsbHcSetRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1170 if (EFI_ERROR (Status
)) {
1171 DEBUG (( DEBUG_ERROR
, "UsbRootHubResetPort: failed to start reset on port %d\n", Port
));
1176 // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
1177 // section 7.1.7.5 for timing requirements.
1179 gBS
->Stall (USB_SET_ROOT_PORT_RESET_STALL
);
1181 Status
= UsbHcClearRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1183 if (EFI_ERROR (Status
)) {
1184 DEBUG (( DEBUG_ERROR
, "UsbRootHubResetPort: failed to clear reset on port %d\n", Port
));
1188 gBS
->Stall (USB_CLR_ROOT_PORT_RESET_STALL
);
1191 // USB host controller won't clear the RESET bit until
1192 // reset is actually finished.
1194 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
1196 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
1197 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, &PortState
);
1199 if (EFI_ERROR (Status
)) {
1203 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
1207 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
1210 if (Index
== USB_WAIT_PORT_STS_CHANGE_LOOP
) {
1211 DEBUG ((DEBUG_ERROR
, "UsbRootHubResetPort: reset not finished in time on port %d\n", Port
));
1215 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_ENABLE
)) {
1217 // OK, the port is reset. If root hub is of high speed and
1218 // the device is of low/full speed, release the ownership to
1219 // companion UHCI. If root hub is of full speed, it won't
1220 // automatically enable the port, we need to enable it manually.
1222 if (RootIf
->MaxSpeed
== EFI_USB_SPEED_HIGH
) {
1223 DEBUG (( DEBUG_ERROR
, "UsbRootHubResetPort: release low/full speed device (%d) to UHCI\n", Port
));
1225 UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortOwner
);
1226 return EFI_NOT_FOUND
;
1230 Status
= UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortEnable
);
1232 if (EFI_ERROR (Status
)) {
1233 DEBUG (( DEBUG_ERROR
, "UsbRootHubResetPort: failed to enable port %d for UHCI\n", Port
));
1237 gBS
->Stall (USB_SET_ROOT_PORT_ENABLE_STALL
);
1246 Release the root hub's control of the interface.
1248 @param HubIf The root hub interface.
1250 @retval EFI_SUCCESS The root hub's control of the interface is
1256 IN USB_INTERFACE
*HubIf
1259 DEBUG (( DEBUG_INFO
, "UsbRootHubRelease: root hub released for hub %p\n", HubIf
));
1261 gBS
->SetTimer (HubIf
->HubNotify
, TimerCancel
, USB_ROOTHUB_POLL_INTERVAL
);
1262 gBS
->CloseEvent (HubIf
->HubNotify
);
1267 USB_HUB_API mUsbHubApi
= {
1269 UsbHubGetPortStatus
,
1270 UsbHubClearPortChange
,
1271 UsbHubSetPortFeature
,
1272 UsbHubClearPortFeature
,
1277 USB_HUB_API mUsbRootHubApi
= {
1279 UsbRootHubGetPortStatus
,
1280 UsbRootHubClearPortChange
,
1281 UsbRootHubSetPortFeature
,
1282 UsbRootHubClearPortFeature
,
1283 UsbRootHubResetPort
,