3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Unified interface for RootHub and Hub
28 // USB hub class specific requests. Although USB hub
29 // is related to an interface, these requests are sent
30 // to the control endpoint of the device.
35 USB hub control transfer to clear the hub feature
37 @param HubDev The device of the hub
38 @param Feature The feature to clear
40 @retval EFI_SUCCESS Feature of the hub is cleared
41 @retval Others Failed to clear the feature
46 UsbHubCtrlClearHubFeature (
47 IN USB_DEVICE
*HubDev
,
53 Status
= UsbCtrlRequest (
58 USB_HUB_REQ_CLEAR_FEATURE
,
70 Clear the feature of the device's port
72 @param HubDev The hub device
73 @param Port The port to clear feature
74 @param Feature The feature to clear
76 @retval EFI_SUCCESS The feature of the port is cleared.
77 @retval Others Failed to clear the feature.
82 UsbHubCtrlClearPortFeature (
83 IN USB_DEVICE
*HubDev
,
91 // In USB bus, all the port index starts from 0. But HUB
92 // indexes its port from 1. So, port number is added one.
94 Status
= UsbCtrlRequest (
99 USB_HUB_REQ_CLEAR_FEATURE
,
112 Clear the transaction translate buffer if full/low
113 speed control/bulk transfer failed and the transfer
114 uses this hub as translator.Remember to clear the TT
115 buffer of transaction translator, not that of the
118 @param HubDev The hub device
119 @param Port The port of the hub
120 @param DevAddr Address of the failed transaction
121 @param EpNum The endpoint number of the failed transaction
122 @param EpType The type of failed transaction
124 @retval EFI_SUCCESS The TT buffer is cleared
125 @retval Others Failed to clear the TT buffer
129 UsbHubCtrlClearTTBuffer (
130 IN USB_DEVICE
*HubDev
,
141 // Check USB2.0 spec page 424 for wValue's encoding
143 Value
= (UINT16
) ((EpNum
& 0x0F) | (DevAddr
<< 4) |
144 ((EpType
& 0x03) << 11) | ((EpNum
& 0x80) << 15));
146 Status
= UsbCtrlRequest (
151 USB_HUB_REQ_CLEAR_TT
,
163 Usb hub control transfer to get the hub descriptor
165 @param HubDev The hub device
166 @param Buf The buffer to hold the descriptor
167 @param Len The length to retrieve
169 @retval EFI_SUCCESS The hub descriptor is retrieved
170 @retval Others Failed to retrieve the hub descriptor
175 UsbHubCtrlGetHubDesc (
176 IN USB_DEVICE
*HubDev
,
183 Status
= UsbCtrlRequest (
188 USB_HUB_REQ_GET_DESC
,
189 (UINT16
) (USB_DESC_TYPE_HUB
<< 8),
200 Usb hub control transfer to get the hub status
202 @param HubDev The hub device
203 @param State The variable to return the status
205 @retval EFI_SUCCESS The hub status is returned in State
206 @retval Others Failed to get the hub status
211 UsbHubCtrlGetHubStatus (
212 IN USB_DEVICE
*HubDev
,
218 Status
= UsbCtrlRequest (
223 USB_HUB_REQ_GET_STATUS
,
235 Usb hub control transfer to get the port status
237 @param HubDev The hub device
238 @param Port The port of the hub
239 @param State Variable to return the hub port state
241 @retval EFI_SUCCESS The port state is returned in State
242 @retval Others Failed to retrive the port state
247 UsbHubCtrlGetPortStatus (
248 IN USB_DEVICE
*HubDev
,
256 // In USB bus, all the port index starts from 0. But HUB
257 // indexes its port from 1. So, port number is added one.
258 // No need to convert the hub bit to UEFI definition, they
261 Status
= UsbCtrlRequest (
266 USB_HUB_REQ_GET_STATUS
,
278 Usb hub control transfer to reset the TT (Transaction Transaltor)
280 @param HubDev The hub device
281 @param Port The port of the hub
283 @retval EFI_SUCCESS The TT of the hub is reset
284 @retval Others Failed to reset the port
290 IN USB_DEVICE
*HubDev
,
296 Status
= UsbCtrlRequest (
301 USB_HUB_REQ_RESET_TT
,
313 Usb hub control transfer to set the hub feature
315 @param HubDev The hub device
316 @param Feature The feature to set
318 @retval EFI_SUCESS The feature is set for the hub
319 @retval Others Failed to set the feature
324 UsbHubCtrlSetHubFeature (
325 IN USB_DEVICE
*HubDev
,
331 Status
= UsbCtrlRequest (
336 USB_HUB_REQ_SET_FEATURE
,
348 Usb hub control transfer to set the port feature
350 @param HubDev The Usb hub device
351 @param Port The Usb port to set feature for
352 @param Feature The feature to set
354 @retval EFI_SUCCESS The feature is set for the port
355 @retval Others Failed to set the feature
360 UsbHubCtrlSetPortFeature (
361 IN USB_DEVICE
*HubDev
,
369 // In USB bus, all the port index starts from 0. But HUB
370 // indexes its port from 1. So, port number is added one.
372 Status
= UsbCtrlRequest (
377 USB_HUB_REQ_SET_FEATURE
,
389 Read the whole usb hub descriptor. It is necessary
390 to do it in two steps because hub descriptor is of
393 @param HubDev The hub device
394 @param HubDesc The variable to return the descriptor
396 @retval EFI_SUCCESS The hub descriptor is read
397 @retval Others Failed to read the hub descriptor
403 IN USB_DEVICE
*HubDev
,
404 OUT EFI_USB_HUB_DESCRIPTOR
*HubDesc
410 // First get the hub descriptor length
412 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, 2);
414 if (EFI_ERROR (Status
)) {
419 // Get the whole hub descriptor
421 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, HubDesc
->Length
);
429 Ack the hub change bits. If these bits are not ACKed, Hub will
430 always return changed bit map from its interrupt endpoint.
432 @param HubDev The hub device
434 @retval EFI_SUCCESS The hub change status is ACKed
435 @retval Others Failed to ACK the hub status
440 IN USB_DEVICE
*HubDev
443 EFI_USB_PORT_STATUS HubState
;
446 Status
= UsbHubCtrlGetHubStatus (HubDev
, (UINT32
*) &HubState
);
448 if (EFI_ERROR (Status
)) {
452 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_LOCAL_POWER
)) {
453 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_LOCAL_POWER
);
456 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_OVER_CURRENT
)) {
457 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_OVER_CURRENT
);
465 Test whether the interface is a hub interface.
467 @param UsbIf The interface to test
469 @retval TRUE The interface is a hub interface
470 @retval FALSE The interface isn't a hub interface
475 IN USB_INTERFACE
*UsbIf
478 EFI_USB_INTERFACE_DESCRIPTOR
*Setting
;
481 // If the hub is a high-speed hub with multiple TT,
482 // the hub will has a default setting of single TT.
484 Setting
= &UsbIf
->IfSetting
->Desc
;
486 if ((Setting
->InterfaceClass
== USB_HUB_CLASS_CODE
) &&
487 (Setting
->InterfaceSubClass
== USB_HUB_SUBCLASS_CODE
)) {
497 The callback function to the USB hub status change
498 interrupt endpoint. It is called periodically by
499 the underlying host controller.
501 @param Data The data read
502 @param DataLength The length of the data read
503 @param Context The context
504 @param Result The result of the last interrupt transfer
506 @retval EFI_SUCCESS The process is OK
507 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource
519 USB_INTERFACE
*HubIf
;
520 EFI_USB_IO_PROTOCOL
*UsbIo
;
521 EFI_USB_ENDPOINT_DESCRIPTOR
*EpDesc
;
524 HubIf
= (USB_INTERFACE
*) Context
;
525 UsbIo
= &(HubIf
->UsbIo
);
526 EpDesc
= &(HubIf
->HubEp
->Desc
);
528 if (Result
!= EFI_USB_NOERROR
) {
530 // If endpoint is stalled, clear the stall. Use UsbIo to access
531 // the control transfer so internal status are maintained.
533 if (USB_BIT_IS_SET (Result
, EFI_USB_ERR_STALL
)) {
537 USB_FEATURE_ENDPOINT_HALT
,
538 EpDesc
->EndpointAddress
543 // Delete and submit a new async interrupt
545 Status
= UsbIo
->UsbAsyncInterruptTransfer (
547 EpDesc
->EndpointAddress
,
555 if (EFI_ERROR (Status
)) {
556 USB_ERROR (("UsbOnHubInterrupt: failed to remove async transfer - %r\n", Status
));
560 Status
= UsbIo
->UsbAsyncInterruptTransfer (
562 EpDesc
->EndpointAddress
,
564 USB_HUB_POLL_INTERVAL
,
565 HubIf
->NumOfPort
/ 8 + 1,
570 if (EFI_ERROR (Status
)) {
571 USB_ERROR (("UsbOnHubInterrupt: failed to submit new async transfer - %r\n", Status
));
577 if ((DataLength
== 0) || (Data
== NULL
)) {
582 // OK, actually something is changed, save the change map
583 // then signal the HUB to do enumeration. This is a good
584 // practise since UsbOnHubInterrupt is called in the context
585 // of host contrller's AsyncInterrupt monitor.
587 HubIf
->ChangeMap
= AllocateZeroPool (DataLength
);
589 if (HubIf
->ChangeMap
== NULL
) {
590 return EFI_OUT_OF_RESOURCES
;
593 CopyMem (HubIf
->ChangeMap
, Data
, DataLength
);
594 gBS
->SignalEvent (HubIf
->HubNotify
);
600 // Array that maps the change bit to feature value which is
601 // used to clear these change bit. USB HUB API will clear
602 // these change bit automatically. For non-root hub, these
603 // bits determine whether hub will report the port in changed
606 #define USB_HUB_MAP_SIZE 5
608 USB_CHANGE_FEATURE_MAP mHubFeatureMap
[USB_HUB_MAP_SIZE
] = {
609 {USB_PORT_STAT_C_CONNECTION
, USB_HUB_C_PORT_CONNECT
},
610 {USB_PORT_STAT_C_ENABLE
, USB_HUB_C_PORT_ENABLE
},
611 {USB_PORT_STAT_C_SUSPEND
, USB_HUB_C_PORT_SUSPEND
},
612 {USB_PORT_STAT_C_OVERCURRENT
, USB_HUB_C_PORT_OVER_CURRENT
},
613 {USB_PORT_STAT_C_RESET
, USB_HUB_C_PORT_RESET
},
616 #define USB_ROOT_HUB_MAP_SIZE 5
618 USB_CHANGE_FEATURE_MAP mRootHubFeatureMap
[USB_ROOT_HUB_MAP_SIZE
] = {
619 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
620 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
621 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
622 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
623 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
},
629 Initialize the device for a non-root hub
631 @param HubIf The USB hub interface
633 @retval EFI_SUCCESS The hub is initialized
634 @retval EFI_DEVICE_ERROR Failed to initialize the hub
640 IN USB_INTERFACE
*HubIf
643 EFI_USB_HUB_DESCRIPTOR HubDesc
;
644 USB_ENDPOINT_DESC
*EpDesc
;
645 USB_INTERFACE_SETTING
*Setting
;
646 EFI_USB_IO_PROTOCOL
*UsbIo
;
652 // Locate the interrupt endpoint for port change map
654 HubIf
->IsHub
= FALSE
;
655 Setting
= HubIf
->IfSetting
;
656 HubDev
= HubIf
->Device
;
659 for (Index
= 0; Index
< Setting
->Desc
.NumEndpoints
; Index
++) {
660 ASSERT ((Setting
->Endpoints
!= NULL
) && (Setting
->Endpoints
[Index
] != NULL
));
662 EpDesc
= Setting
->Endpoints
[Index
];
664 if (USB_BIT_IS_SET (EpDesc
->Desc
.EndpointAddress
, USB_ENDPOINT_DIR_IN
) &&
665 (USB_ENDPOINT_TYPE (&EpDesc
->Desc
) == USB_ENDPOINT_INTERRUPT
)) {
670 if (Index
== Setting
->Desc
.NumEndpoints
) {
671 USB_ERROR (("UsbHubInit: no interrupt endpoint found for hub %d\n", HubDev
->Address
));
672 return EFI_DEVICE_ERROR
;
675 Status
= UsbHubReadDesc (HubDev
, &HubDesc
);
677 if (EFI_ERROR (Status
)) {
678 USB_ERROR (("UsbHubInit: failed to read HUB descriptor %r\n", Status
));
682 HubIf
->NumOfPort
= HubDesc
.NumPorts
;
684 USB_DEBUG (("UsbHubInit: hub %d has %d ports\n", HubDev
->Address
,HubIf
->NumOfPort
));
687 // Create an event to enumerate the hub's port. On
689 Status
= gBS
->CreateEvent (
697 if (EFI_ERROR (Status
)) {
698 USB_ERROR (("UsbHubInit: failed to create signal for hub %d - %r\n",
699 HubDev
->Address
, Status
));
705 // Create AsyncInterrupt to query hub port change endpoint
706 // periodically. If the hub ports are changed, hub will return
707 // changed port map from the interrupt endpoint. The port map
708 // must be able to hold (HubIf->NumOfPort + 1) bits (one bit for
709 // host change status).
711 UsbIo
= &HubIf
->UsbIo
;
712 Status
= UsbIo
->UsbAsyncInterruptTransfer (
714 EpDesc
->Desc
.EndpointAddress
,
716 USB_HUB_POLL_INTERVAL
,
717 HubIf
->NumOfPort
/ 8 + 1,
722 if (EFI_ERROR (Status
)) {
723 USB_ERROR (("UsbHubInit: failed to queue interrupt transfer for hub %d - %r\n",
724 HubDev
->Address
, Status
));
726 gBS
->CloseEvent (HubIf
->HubNotify
);
727 HubIf
->HubNotify
= NULL
;
733 // OK, set IsHub to TRUE. Now usb bus can handle this device
734 // as a working HUB. If failed eariler, bus driver will not
735 // recognize it as a hub. Other parts of the bus should be able
739 HubIf
->HubApi
= &mUsbHubApi
;
740 HubIf
->HubEp
= EpDesc
;
743 // Feed power to all the hub ports. It should be ok
744 // for both gang/individual powered hubs.
746 for (Index
= 0; Index
< HubDesc
.NumPorts
; Index
++) {
747 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_POWER
);
750 gBS
->Stall (HubDesc
.PwrOn2PwrGood
* 2 * USB_STALL_1_MS
);
751 UsbHubAckHubStatus (HubIf
->Device
);
753 USB_DEBUG (("UsbHubInit: hub %d initialized\n", HubDev
->Address
));
760 Get the port status. This function is required to
761 ACK the port change bits although it will return
762 the port changes in PortState. Bus enumeration code
763 doesn't need to ACK the port change bits.
765 @param HubIf The hub interface
766 @param Port The port of the hub to get state
767 @param PortState Variable to return the port state
769 @retval EFI_SUCCESS The port status is successfully returned
770 @retval Others Failed to return the status
775 UsbHubGetPortStatus (
776 IN USB_INTERFACE
*HubIf
,
778 OUT EFI_USB_PORT_STATUS
*PortState
783 Status
= UsbHubCtrlGetPortStatus (HubIf
->Device
, Port
, PortState
);
791 Clear the port change status.
793 @param HubIf The hub interface
794 @param Port The hub port
801 UsbHubClearPortChange (
802 IN USB_INTERFACE
*HubIf
,
806 EFI_USB_PORT_STATUS PortState
;
807 USB_CHANGE_FEATURE_MAP
*Map
;
811 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
813 if (EFI_ERROR (Status
)) {
818 // OK, get the usb port status, now ACK the change bits.
819 // Don't return error when failed to clear the change bits.
820 // It may lead to extra port state report. USB bus should
821 // be able to handle this.
823 for (Index
= 0; Index
< USB_HUB_MAP_SIZE
; Index
++) {
824 Map
= &mHubFeatureMap
[Index
];
826 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
827 UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, Map
->Feature
);
835 Function to set the port feature for non-root hub
837 @param HubIf The hub interface
838 @param Port The port of the hub
839 @param Feature The feature of the port to set
841 @retval EFI_SUCCESS The hub port feature is set
842 @retval Others Failed to set the port feature
847 UsbHubSetPortFeature (
848 IN USB_INTERFACE
*HubIf
,
850 IN EFI_USB_PORT_FEATURE Feature
855 Status
= UsbHubCtrlSetPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
862 Interface function to clear the port feature for non-root hub
864 @param HubIf The hub interface
865 @param Port The port of the hub to clear feature for
866 @param Feature The feature to clear
868 @retval EFI_SUCCESS The port feature is cleared
869 @retval Others Failed to clear the port feature
874 UsbHubClearPortFeature (
875 IN USB_INTERFACE
*HubIf
,
877 IN EFI_USB_PORT_FEATURE Feature
882 Status
= UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
889 Interface funtion to reset the port
891 @param HubIf The hub interface
892 @param Port The port to reset
894 @retval EFI_SUCCESS The hub port is reset
895 @retval EFI_TIMEOUT Failed to reset the port in time
896 @retval Others Failed to reset the port
902 IN USB_INTERFACE
*HubIf
,
906 EFI_USB_PORT_STATUS PortState
;
910 Status
= UsbHubSetPortFeature (HubIf
, Port
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_RESET
);
912 if (EFI_ERROR (Status
)) {
917 // Drive the reset signal for at least 10ms. Check USB 2.0 Spec
918 // section 7.1.7.5 for timing requirements.
920 gBS
->Stall (20 * USB_STALL_1_MS
);
923 // USB hub will clear RESET bit if reset is actually finished.
925 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
927 for (Index
= 0; Index
< 20; Index
++) {
928 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
930 if (!EFI_ERROR (Status
) &&
931 !USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
936 gBS
->Stall (5 * USB_STALL_1_MS
);
944 Release the hub's control of the interface
946 @param HubIf The hub interface
948 @retval EFI_SUCCESS The interface is release of hub control
954 IN USB_INTERFACE
*HubIf
957 EFI_USB_IO_PROTOCOL
*UsbIo
;
960 UsbIo
= &HubIf
->UsbIo
;
961 Status
= UsbIo
->UsbAsyncInterruptTransfer (
963 HubIf
->HubEp
->Desc
.EndpointAddress
,
965 USB_HUB_POLL_INTERVAL
,
971 if (EFI_ERROR (Status
)) {
975 gBS
->CloseEvent (HubIf
->HubNotify
);
977 HubIf
->IsHub
= FALSE
;
978 HubIf
->HubApi
= NULL
;
980 HubIf
->HubNotify
= NULL
;
982 USB_DEBUG (("UsbHubRelease: hub device %d released\n", HubIf
->Device
->Address
));
989 Initialize the interface for root hub
991 @param HubIf The root hub interface
993 @retval EFI_SUCCESS The interface is initialied for root hub
994 @retval Others Failed to initialize the hub
1000 IN USB_INTERFACE
*HubIf
1008 Status
= UsbHcGetCapability (HubIf
->Device
->Bus
, &MaxSpeed
, &NumOfPort
, &Support64
);
1010 if (EFI_ERROR (Status
)) {
1014 USB_DEBUG (("UsbRootHubInit: root hub %x - max speed %d, %d ports\n",
1015 HubIf
, MaxSpeed
, NumOfPort
));
1017 HubIf
->IsHub
= TRUE
;
1018 HubIf
->HubApi
= &mUsbRootHubApi
;
1019 HubIf
->HubEp
= NULL
;
1020 HubIf
->MaxSpeed
= MaxSpeed
;
1021 HubIf
->NumOfPort
= NumOfPort
;
1022 HubIf
->HubNotify
= NULL
;
1025 // Create a timer to poll root hub ports periodically
1027 Status
= gBS
->CreateEvent (
1028 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1030 UsbRootHubEnumeration
,
1035 if (EFI_ERROR (Status
)) {
1039 Status
= gBS
->SetTimer (
1042 USB_ROOTHUB_POLL_INTERVAL
1045 if (EFI_ERROR (Status
)) {
1046 gBS
->CloseEvent (HubIf
->HubNotify
);
1055 Get the port status. This function is required to
1056 ACK the port change bits although it will return
1057 the port changes in PortState. Bus enumeration code
1058 doesn't need to ACK the port change bits.
1060 @param HubIf The root hub interface
1061 @param Port The root hub port to get the state
1062 @param PortState Variable to return the port state
1064 @retval EFI_SUCCESS The port state is returned
1065 @retval Others Failed to retrieve the port state
1070 UsbRootHubGetPortStatus (
1071 IN USB_INTERFACE
*HubIf
,
1073 OUT EFI_USB_PORT_STATUS
*PortState
1079 Bus
= HubIf
->Device
->Bus
;
1080 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, PortState
);
1087 Clear the port change status.
1089 @param HubIf The root hub interface
1090 @param Port The root hub port
1092 @retval EFI_SUCCESS The port state is returned
1093 @retval Others Failed to retrieve the port state
1098 UsbRootHubClearPortChange (
1099 IN USB_INTERFACE
*HubIf
,
1103 EFI_USB_PORT_STATUS PortState
;
1104 USB_CHANGE_FEATURE_MAP
*Map
;
1108 Status
= UsbRootHubGetPortStatus (HubIf
, Port
, &PortState
);
1110 if (EFI_ERROR (Status
)) {
1115 // OK, get the usb port status, now ACK the change bits.
1116 // Don't return error when failed to clear the change bits.
1117 // It may lead to extra port state report. USB bus should
1118 // be able to handle this.
1120 for (Index
= 0; Index
< USB_ROOT_HUB_MAP_SIZE
; Index
++) {
1121 Map
= &mRootHubFeatureMap
[Index
];
1123 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
1124 UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, (EFI_USB_PORT_FEATURE
) Map
->Feature
);
1132 Set the root hub port feature
1134 @param HubIf The Usb hub interface
1135 @param Port The hub port
1136 @param Feature The feature to set
1138 @retval EFI_SUCCESS The root hub port is set with the feature
1139 @retval Others Failed to set the feature
1144 UsbRootHubSetPortFeature (
1145 IN USB_INTERFACE
*HubIf
,
1147 IN EFI_USB_PORT_FEATURE Feature
1152 Status
= UsbHcSetRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1159 Clear the root hub port feature
1161 @param HubIf The root hub interface
1162 @param Port The root hub port
1163 @param Feature The feature to clear
1165 @retval EFI_SUCCESS The root hub port is cleared of the feature
1166 @retval Others Failed to clear the feature
1171 UsbRootHubClearPortFeature (
1172 IN USB_INTERFACE
*HubIf
,
1174 IN EFI_USB_PORT_FEATURE Feature
1179 Status
= UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1186 Interface funtion to reset the root hub port
1188 @param RootIf The root hub interface
1189 @param Port The port to reset
1191 @retval EFI_SUCCESS The hub port is reset
1192 @retval EFI_TIMEOUT Failed to reset the port in time
1193 @retval EFI_NOT_FOUND The low/full speed device connected to high speed
1194 root hub is released to the companion UHCI
1195 @retval Others Failed to reset the port
1200 UsbRootHubResetPort (
1201 IN USB_INTERFACE
*RootIf
,
1207 EFI_USB_PORT_STATUS PortState
;
1211 // Notice: although EHCI requires that ENABLED bit be cleared
1212 // when reset the port, we don't need to care that here. It
1213 // should be handled in the EHCI driver.
1215 Bus
= RootIf
->Device
->Bus
;
1216 Status
= UsbHcSetRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1218 if (EFI_ERROR (Status
)) {
1219 USB_ERROR (("UsbRootHubResetPort: failed to start reset on port %d\n", Port
));
1224 // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
1225 // section 7.1.7.5 for timing requirements.
1227 gBS
->Stall (50 * USB_STALL_1_MS
);
1229 Status
= UsbHcClearRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1231 if (EFI_ERROR (Status
)) {
1232 USB_ERROR (("UsbRootHubResetPort: failed to clear reset on port %d\n", Port
));
1236 gBS
->Stall (USB_STALL_1_MS
);
1239 // USB host controller won't clear the RESET bit until
1240 // reset is actually finished.
1242 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
1244 for (Index
= 0; Index
< USB_HUB_LOOP
; Index
++) {
1245 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, &PortState
);
1247 if (EFI_ERROR (Status
)) {
1251 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
1255 gBS
->Stall (10 * USB_STALL_1_MS
);
1258 if (Index
== USB_HUB_LOOP
) {
1259 USB_ERROR (("UsbRootHubResetPort: reset not finished in time on port %d\n", Port
));
1263 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_ENABLE
)) {
1265 // OK, the port is reset. If root hub is of high speed and
1266 // the device is of low/full speed, release the ownership to
1267 // companion UHCI. If root hub is of full speed, it won't
1268 // automatically enable the port, we need to enable it manually.
1270 if (RootIf
->MaxSpeed
== EFI_USB_SPEED_HIGH
) {
1271 USB_ERROR (("UsbRootHubResetPort: release low/full speed device (%d) to UHCI\n", Port
));
1273 UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortOwner
);
1274 return EFI_NOT_FOUND
;
1278 Status
= UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortEnable
);
1280 if (EFI_ERROR (Status
)) {
1281 USB_ERROR (("UsbRootHubResetPort: failed to enable port %d for UHCI\n", Port
));
1285 gBS
->Stall (20 * USB_STALL_1_MS
);
1294 Release the root hub's control of the interface
1296 @param HubIf The root hub interface
1298 @retval EFI_SUCCESS The root hub's control of the interface is
1305 IN USB_INTERFACE
*HubIf
1308 USB_DEBUG (("UsbRootHubRelease: root hub released for hub %x\n", HubIf
));
1310 gBS
->SetTimer (HubIf
->HubNotify
, TimerCancel
, USB_ROOTHUB_POLL_INTERVAL
);
1311 gBS
->CloseEvent (HubIf
->HubNotify
);
1316 USB_HUB_API mUsbHubApi
= {
1318 UsbHubGetPortStatus
,
1319 UsbHubClearPortChange
,
1320 UsbHubSetPortFeature
,
1321 UsbHubClearPortFeature
,
1326 USB_HUB_API mUsbRootHubApi
= {
1328 UsbRootHubGetPortStatus
,
1329 UsbRootHubClearPortChange
,
1330 UsbRootHubSetPortFeature
,
1331 UsbRootHubClearPortFeature
,
1332 UsbRootHubResetPort
,