3 Unified interface for RootHub and Hub.
5 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // Array that maps the change bit to feature value which is
20 // used to clear these change bit. USB HUB API will clear
21 // these change bit automatically. For non-root hub, these
22 // bits determine whether hub will report the port in changed
25 USB_CHANGE_FEATURE_MAP mHubFeatureMap
[] = {
26 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
27 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
28 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
29 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
30 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
}
33 USB_CHANGE_FEATURE_MAP mRootHubFeatureMap
[] = {
34 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
35 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
36 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
37 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
38 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
},
42 // USB hub class specific requests. Although USB hub
43 // is related to an interface, these requests are sent
44 // to the control endpoint of the device.
47 USB hub control transfer to set the hub depth.
49 @param HubDev The device of the hub.
50 @param Depth The depth to set.
52 @retval EFI_SUCCESS Depth of the hub is set.
53 @retval Others Failed to set the depth.
57 UsbHubCtrlSetHubDepth (
58 IN USB_DEVICE
*HubDev
,
64 Status
= UsbCtrlRequest (
69 USB_HUB_REQ_SET_DEPTH
,
80 USB hub control transfer to clear the hub feature.
82 @param HubDev The device of the hub.
83 @param Feature The feature to clear.
85 @retval EFI_SUCCESS Feature of the hub is cleared.
86 @retval Others Failed to clear the feature.
90 UsbHubCtrlClearHubFeature (
91 IN USB_DEVICE
*HubDev
,
97 Status
= UsbCtrlRequest (
102 USB_HUB_REQ_CLEAR_FEATURE
,
114 Clear the feature of the device's port.
116 @param HubDev The hub device.
117 @param Port The port to clear feature.
118 @param Feature The feature to clear.
120 @retval EFI_SUCCESS The feature of the port is cleared.
121 @retval Others Failed to clear the feature.
125 UsbHubCtrlClearPortFeature (
126 IN USB_DEVICE
*HubDev
,
134 // In USB bus, all the port index starts from 0. But HUB
135 // indexes its port from 1. So, port number is added one.
137 Status
= UsbCtrlRequest (
142 USB_HUB_REQ_CLEAR_FEATURE
,
154 Clear the transaction translate buffer if full/low
155 speed control/bulk transfer failed and the transfer
156 uses this hub as translator.Remember to clear the TT
157 buffer of transaction translator, not that of the
160 @param HubDev The hub device.
161 @param Port The port of the hub.
162 @param DevAddr Address of the failed transaction.
163 @param EpNum The endpoint number of the failed transaction.
164 @param EpType The type of failed transaction.
166 @retval EFI_SUCCESS The TT buffer is cleared.
167 @retval Others Failed to clear the TT buffer.
171 UsbHubCtrlClearTTBuffer (
172 IN USB_DEVICE
*HubDev
,
183 // Check USB2.0 spec page 424 for wValue's encoding
185 Value
= (UINT16
) ((EpNum
& 0x0F) | (DevAddr
<< 4) |
186 ((EpType
& 0x03) << 11) | ((EpNum
& 0x80) << 15));
188 Status
= UsbCtrlRequest (
193 USB_HUB_REQ_CLEAR_TT
,
204 Usb hub control transfer to get the super speed hub descriptor.
206 @param HubDev The hub device.
207 @param Buf The buffer to hold the descriptor.
209 @retval EFI_SUCCESS The hub descriptor is retrieved.
210 @retval Others Failed to retrieve the hub descriptor.
214 UsbHubCtrlGetSuperSpeedHubDesc (
215 IN USB_DEVICE
*HubDev
,
221 Status
= EFI_INVALID_PARAMETER
;
223 Status
= UsbCtrlRequest (
228 USB_HUB_REQ_GET_DESC
,
229 (UINT16
) (USB_DESC_TYPE_HUB_SUPER_SPEED
<< 8),
239 Usb hub control transfer to get the hub descriptor.
241 @param HubDev The hub device.
242 @param Buf The buffer to hold the descriptor.
243 @param Len The length to retrieve.
245 @retval EFI_SUCCESS The hub descriptor is retrieved.
246 @retval Others Failed to retrieve the hub descriptor.
250 UsbHubCtrlGetHubDesc (
251 IN USB_DEVICE
*HubDev
,
258 Status
= UsbCtrlRequest (
263 USB_HUB_REQ_GET_DESC
,
264 (UINT16
) (USB_DESC_TYPE_HUB
<< 8),
275 Usb hub control transfer to get the hub status.
277 @param HubDev The hub device.
278 @param State The variable to return the status.
280 @retval EFI_SUCCESS The hub status is returned in State.
281 @retval Others Failed to get the hub status.
285 UsbHubCtrlGetHubStatus (
286 IN USB_DEVICE
*HubDev
,
292 Status
= UsbCtrlRequest (
297 USB_HUB_REQ_GET_STATUS
,
309 Usb hub control transfer to get the port status.
311 @param HubDev The hub device.
312 @param Port The port of the hub.
313 @param State Variable to return the hub port state.
315 @retval EFI_SUCCESS The port state is returned in State.
316 @retval Others Failed to retrieve the port state.
320 UsbHubCtrlGetPortStatus (
321 IN USB_DEVICE
*HubDev
,
329 // In USB bus, all the port index starts from 0. But HUB
330 // indexes its port from 1. So, port number is added one.
331 // No need to convert the hub bit to UEFI definition, they
334 Status
= UsbCtrlRequest (
339 USB_HUB_REQ_GET_STATUS
,
351 Usb hub control transfer to reset the TT (Transaction Transaltor).
353 @param HubDev The hub device.
354 @param Port The port of the hub.
356 @retval EFI_SUCCESS The TT of the hub is reset.
357 @retval Others Failed to reset the port.
362 IN USB_DEVICE
*HubDev
,
368 Status
= UsbCtrlRequest (
373 USB_HUB_REQ_RESET_TT
,
385 Usb hub control transfer to set the hub feature.
387 @param HubDev The hub device.
388 @param Feature The feature to set.
390 @retval EFI_SUCESS The feature is set for the hub.
391 @retval Others Failed to set the feature.
395 UsbHubCtrlSetHubFeature (
396 IN USB_DEVICE
*HubDev
,
402 Status
= UsbCtrlRequest (
407 USB_HUB_REQ_SET_FEATURE
,
419 Usb hub control transfer to set the port feature.
421 @param HubDev The Usb hub device.
422 @param Port The Usb port to set feature for.
423 @param Feature The feature to set.
425 @retval EFI_SUCCESS The feature is set for the port.
426 @retval Others Failed to set the feature.
430 UsbHubCtrlSetPortFeature (
431 IN USB_DEVICE
*HubDev
,
439 // In USB bus, all the port index starts from 0. But HUB
440 // indexes its port from 1. So, port number is added one.
442 Status
= UsbCtrlRequest (
447 USB_HUB_REQ_SET_FEATURE
,
459 Read the whole usb hub descriptor. It is necessary
460 to do it in two steps because hub descriptor is of
463 @param HubDev The hub device.
464 @param HubDesc The variable to return the descriptor.
466 @retval EFI_SUCCESS The hub descriptor is read.
467 @retval Others Failed to read the hub descriptor.
472 IN USB_DEVICE
*HubDev
,
473 OUT EFI_USB_HUB_DESCRIPTOR
*HubDesc
478 if (HubDev
->Speed
== EFI_USB_SPEED_SUPER
) {
480 // Get the super speed hub descriptor
482 Status
= UsbHubCtrlGetSuperSpeedHubDesc (HubDev
, HubDesc
);
486 // First get the hub descriptor length
488 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, 2);
490 if (EFI_ERROR (Status
)) {
495 // Get the whole hub descriptor
497 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, HubDesc
->Length
);
506 Ack the hub change bits. If these bits are not ACKed, Hub will
507 always return changed bit map from its interrupt endpoint.
509 @param HubDev The hub device.
511 @retval EFI_SUCCESS The hub change status is ACKed.
512 @retval Others Failed to ACK the hub status.
517 IN USB_DEVICE
*HubDev
520 EFI_USB_PORT_STATUS HubState
;
523 Status
= UsbHubCtrlGetHubStatus (HubDev
, (UINT32
*) &HubState
);
525 if (EFI_ERROR (Status
)) {
529 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_LOCAL_POWER
)) {
530 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_LOCAL_POWER
);
533 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_OVER_CURRENT
)) {
534 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_OVER_CURRENT
);
542 Test whether the interface is a hub interface.
544 @param UsbIf The interface to test.
546 @retval TRUE The interface is a hub interface.
547 @retval FALSE The interface isn't a hub interface.
552 IN USB_INTERFACE
*UsbIf
555 EFI_USB_INTERFACE_DESCRIPTOR
*Setting
;
558 // If the hub is a high-speed hub with multiple TT,
559 // the hub will has a default setting of single TT.
561 Setting
= &UsbIf
->IfSetting
->Desc
;
563 if ((Setting
->InterfaceClass
== USB_HUB_CLASS_CODE
) &&
564 (Setting
->InterfaceSubClass
== USB_HUB_SUBCLASS_CODE
)) {
574 The callback function to the USB hub status change
575 interrupt endpoint. It is called periodically by
576 the underlying host controller.
578 @param Data The data read.
579 @param DataLength The length of the data read.
580 @param Context The context.
581 @param Result The result of the last interrupt transfer.
583 @retval EFI_SUCCESS The process is OK.
584 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
596 USB_INTERFACE
*HubIf
;
597 EFI_USB_IO_PROTOCOL
*UsbIo
;
598 EFI_USB_ENDPOINT_DESCRIPTOR
*EpDesc
;
601 HubIf
= (USB_INTERFACE
*) Context
;
602 UsbIo
= &(HubIf
->UsbIo
);
603 EpDesc
= &(HubIf
->HubEp
->Desc
);
605 if (Result
!= EFI_USB_NOERROR
) {
607 // If endpoint is stalled, clear the stall. Use UsbIo to access
608 // the control transfer so internal status are maintained.
610 if (USB_BIT_IS_SET (Result
, EFI_USB_ERR_STALL
)) {
614 USB_FEATURE_ENDPOINT_HALT
,
615 EpDesc
->EndpointAddress
620 // Delete and submit a new async interrupt
622 Status
= UsbIo
->UsbAsyncInterruptTransfer (
624 EpDesc
->EndpointAddress
,
632 if (EFI_ERROR (Status
)) {
633 DEBUG (( EFI_D_ERROR
, "UsbOnHubInterrupt: failed to remove async transfer - %r\n", Status
));
637 Status
= UsbIo
->UsbAsyncInterruptTransfer (
639 EpDesc
->EndpointAddress
,
641 USB_HUB_POLL_INTERVAL
,
642 HubIf
->NumOfPort
/ 8 + 1,
647 if (EFI_ERROR (Status
)) {
648 DEBUG (( EFI_D_ERROR
, "UsbOnHubInterrupt: failed to submit new async transfer - %r\n", Status
));
654 if ((DataLength
== 0) || (Data
== NULL
)) {
659 // OK, actually something is changed, save the change map
660 // then signal the HUB to do enumeration. This is a good
661 // practise since UsbOnHubInterrupt is called in the context
662 // of host contrller's AsyncInterrupt monitor.
664 HubIf
->ChangeMap
= AllocateZeroPool (DataLength
);
666 if (HubIf
->ChangeMap
== NULL
) {
667 return EFI_OUT_OF_RESOURCES
;
670 CopyMem (HubIf
->ChangeMap
, Data
, DataLength
);
671 gBS
->SignalEvent (HubIf
->HubNotify
);
680 Initialize the device for a non-root hub.
682 @param HubIf The USB hub interface.
684 @retval EFI_SUCCESS The hub is initialized.
685 @retval EFI_DEVICE_ERROR Failed to initialize the hub.
690 IN USB_INTERFACE
*HubIf
693 EFI_USB_HUB_DESCRIPTOR HubDesc
;
694 USB_ENDPOINT_DESC
*EpDesc
;
695 USB_INTERFACE_SETTING
*Setting
;
696 EFI_USB_IO_PROTOCOL
*UsbIo
;
704 // Locate the interrupt endpoint for port change map
706 HubIf
->IsHub
= FALSE
;
707 Setting
= HubIf
->IfSetting
;
708 HubDev
= HubIf
->Device
;
710 NumEndpoints
= Setting
->Desc
.NumEndpoints
;
712 for (Index
= 0; Index
< NumEndpoints
; Index
++) {
713 ASSERT ((Setting
->Endpoints
!= NULL
) && (Setting
->Endpoints
[Index
] != NULL
));
715 EpDesc
= Setting
->Endpoints
[Index
];
717 if (USB_BIT_IS_SET (EpDesc
->Desc
.EndpointAddress
, USB_ENDPOINT_DIR_IN
) &&
718 (USB_ENDPOINT_TYPE (&EpDesc
->Desc
) == USB_ENDPOINT_INTERRUPT
)) {
723 if (Index
== NumEndpoints
) {
724 DEBUG (( EFI_D_ERROR
, "UsbHubInit: no interrupt endpoint found for hub %d\n", HubDev
->Address
));
725 return EFI_DEVICE_ERROR
;
728 Status
= UsbHubReadDesc (HubDev
, &HubDesc
);
730 if (EFI_ERROR (Status
)) {
731 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to read HUB descriptor %r\n", Status
));
735 HubIf
->NumOfPort
= HubDesc
.NumPorts
;
737 DEBUG (( EFI_D_INFO
, "UsbHubInit: hub %d has %d ports\n", HubDev
->Address
,HubIf
->NumOfPort
));
740 // OK, set IsHub to TRUE. Now usb bus can handle this device
741 // as a working HUB. If failed eariler, bus driver will not
742 // recognize it as a hub. Other parts of the bus should be able
746 HubIf
->HubApi
= &mUsbHubApi
;
747 HubIf
->HubEp
= EpDesc
;
749 if (HubIf
->Device
->Speed
== EFI_USB_SPEED_SUPER
) {
750 Depth
= (UINT16
)(HubIf
->Device
->Tier
- 1);
751 DEBUG ((EFI_D_INFO
, "UsbHubInit: Set Hub Depth as 0x%x\n", Depth
));
752 UsbHubCtrlSetHubDepth (HubIf
->Device
, Depth
);
754 for (Index
= 0; Index
< HubDesc
.NumPorts
; Index
++) {
755 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, USB_HUB_PORT_REMOTE_WAKE_MASK
);
759 // Feed power to all the hub ports. It should be ok
760 // for both gang/individual powered hubs.
762 for (Index
= 0; Index
< HubDesc
.NumPorts
; Index
++) {
763 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_POWER
);
767 // Update for the usb hub has no power on delay requirement
769 if (HubDesc
.PwrOn2PwrGood
> 0) {
770 gBS
->Stall (HubDesc
.PwrOn2PwrGood
* USB_SET_PORT_POWER_STALL
);
772 UsbHubAckHubStatus (HubIf
->Device
);
776 // Create an event to enumerate the hub's port. On
778 Status
= gBS
->CreateEvent (
786 if (EFI_ERROR (Status
)) {
787 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to create signal for hub %d - %r\n",
788 HubDev
->Address
, Status
));
794 // Create AsyncInterrupt to query hub port change endpoint
795 // periodically. If the hub ports are changed, hub will return
796 // changed port map from the interrupt endpoint. The port map
797 // must be able to hold (HubIf->NumOfPort + 1) bits (one bit for
798 // host change status).
800 UsbIo
= &HubIf
->UsbIo
;
801 Status
= UsbIo
->UsbAsyncInterruptTransfer (
803 EpDesc
->Desc
.EndpointAddress
,
805 USB_HUB_POLL_INTERVAL
,
806 HubIf
->NumOfPort
/ 8 + 1,
811 if (EFI_ERROR (Status
)) {
812 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to queue interrupt transfer for hub %d - %r\n",
813 HubDev
->Address
, Status
));
815 gBS
->CloseEvent (HubIf
->HubNotify
);
816 HubIf
->HubNotify
= NULL
;
821 DEBUG (( EFI_D_INFO
, "UsbHubInit: hub %d initialized\n", HubDev
->Address
));
828 Get the port status. This function is required to
829 ACK the port change bits although it will return
830 the port changes in PortState. Bus enumeration code
831 doesn't need to ACK the port change bits.
833 @param HubIf The hub interface.
834 @param Port The port of the hub to get state.
835 @param PortState Variable to return the port state.
837 @retval EFI_SUCCESS The port status is successfully returned.
838 @retval Others Failed to return the status.
842 UsbHubGetPortStatus (
843 IN USB_INTERFACE
*HubIf
,
845 OUT EFI_USB_PORT_STATUS
*PortState
850 Status
= UsbHubCtrlGetPortStatus (HubIf
->Device
, Port
, PortState
);
858 Clear the port change status.
860 @param HubIf The hub interface.
861 @param Port The hub port.
865 UsbHubClearPortChange (
866 IN USB_INTERFACE
*HubIf
,
870 EFI_USB_PORT_STATUS PortState
;
871 USB_CHANGE_FEATURE_MAP
*Map
;
875 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
877 if (EFI_ERROR (Status
)) {
882 // OK, get the usb port status, now ACK the change bits.
883 // Don't return error when failed to clear the change bits.
884 // It may lead to extra port state report. USB bus should
885 // be able to handle this.
887 for (Index
= 0; Index
< ARRAY_SIZE (mHubFeatureMap
); Index
++) {
888 Map
= &mHubFeatureMap
[Index
];
890 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
891 UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT16
) Map
->Feature
);
899 Function to set the port feature for non-root hub.
901 @param HubIf The hub interface.
902 @param Port The port of the hub.
903 @param Feature The feature of the port to set.
905 @retval EFI_SUCCESS The hub port feature is set.
906 @retval Others Failed to set the port feature.
910 UsbHubSetPortFeature (
911 IN USB_INTERFACE
*HubIf
,
913 IN EFI_USB_PORT_FEATURE Feature
918 Status
= UsbHubCtrlSetPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
925 Interface function to clear the port feature for non-root hub.
927 @param HubIf The hub interface.
928 @param Port The port of the hub to clear feature for.
929 @param Feature The feature to clear.
931 @retval EFI_SUCCESS The port feature is cleared.
932 @retval Others Failed to clear the port feature.
936 UsbHubClearPortFeature (
937 IN USB_INTERFACE
*HubIf
,
939 IN EFI_USB_PORT_FEATURE Feature
944 Status
= UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
951 Interface function to reset the port.
953 @param HubIf The hub interface.
954 @param Port The port to reset.
956 @retval EFI_SUCCESS The hub port is reset.
957 @retval EFI_TIMEOUT Failed to reset the port in time.
958 @retval Others Failed to reset the port.
963 IN USB_INTERFACE
*HubIf
,
967 EFI_USB_PORT_STATUS PortState
;
971 Status
= UsbHubSetPortFeature (HubIf
, Port
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_RESET
);
973 if (EFI_ERROR (Status
)) {
978 // Drive the reset signal for worst 20ms. Check USB 2.0 Spec
979 // section 7.1.7.5 for timing requirements.
981 gBS
->Stall (USB_SET_PORT_RESET_STALL
);
984 // Check USB_PORT_STAT_C_RESET bit to see if the resetting state is done.
986 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
988 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
989 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
991 if (EFI_ERROR (Status
)) {
995 if (!EFI_ERROR (Status
) &&
996 USB_BIT_IS_SET (PortState
.PortChangeStatus
, USB_PORT_STAT_C_RESET
)) {
997 gBS
->Stall (USB_SET_PORT_RECOVERY_STALL
);
1001 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
1009 Release the hub's control of the interface.
1011 @param HubIf The hub interface.
1013 @retval EFI_SUCCESS The interface is release of hub control.
1018 IN USB_INTERFACE
*HubIf
1021 EFI_USB_IO_PROTOCOL
*UsbIo
;
1024 UsbIo
= &HubIf
->UsbIo
;
1025 Status
= UsbIo
->UsbAsyncInterruptTransfer (
1027 HubIf
->HubEp
->Desc
.EndpointAddress
,
1029 USB_HUB_POLL_INTERVAL
,
1035 if (EFI_ERROR (Status
)) {
1039 gBS
->CloseEvent (HubIf
->HubNotify
);
1041 HubIf
->IsHub
= FALSE
;
1042 HubIf
->HubApi
= NULL
;
1043 HubIf
->HubEp
= NULL
;
1044 HubIf
->HubNotify
= NULL
;
1046 DEBUG (( EFI_D_INFO
, "UsbHubRelease: hub device %d released\n", HubIf
->Device
->Address
));
1053 Initialize the interface for root hub.
1055 @param HubIf The root hub interface.
1057 @retval EFI_SUCCESS The interface is initialized for root hub.
1058 @retval Others Failed to initialize the hub.
1063 IN USB_INTERFACE
*HubIf
1071 Status
= UsbHcGetCapability (HubIf
->Device
->Bus
, &MaxSpeed
, &NumOfPort
, &Support64
);
1073 if (EFI_ERROR (Status
)) {
1077 DEBUG (( EFI_D_INFO
, "UsbRootHubInit: root hub %p - max speed %d, %d ports\n",
1078 HubIf
, MaxSpeed
, NumOfPort
));
1080 HubIf
->IsHub
= TRUE
;
1081 HubIf
->HubApi
= &mUsbRootHubApi
;
1082 HubIf
->HubEp
= NULL
;
1083 HubIf
->MaxSpeed
= MaxSpeed
;
1084 HubIf
->NumOfPort
= NumOfPort
;
1085 HubIf
->HubNotify
= NULL
;
1088 // Create a timer to poll root hub ports periodically
1090 Status
= gBS
->CreateEvent (
1091 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1093 UsbRootHubEnumeration
,
1098 if (EFI_ERROR (Status
)) {
1103 // It should signal the event immediately here, or device detection
1104 // by bus enumeration might be delayed by the timer interval.
1106 gBS
->SignalEvent (HubIf
->HubNotify
);
1108 Status
= gBS
->SetTimer (
1111 USB_ROOTHUB_POLL_INTERVAL
1114 if (EFI_ERROR (Status
)) {
1115 gBS
->CloseEvent (HubIf
->HubNotify
);
1123 Get the port status. This function is required to
1124 ACK the port change bits although it will return
1125 the port changes in PortState. Bus enumeration code
1126 doesn't need to ACK the port change bits.
1128 @param HubIf The root hub interface.
1129 @param Port The root hub port to get the state.
1130 @param PortState Variable to return the port state.
1132 @retval EFI_SUCCESS The port state is returned.
1133 @retval Others Failed to retrieve the port state.
1137 UsbRootHubGetPortStatus (
1138 IN USB_INTERFACE
*HubIf
,
1140 OUT EFI_USB_PORT_STATUS
*PortState
1146 Bus
= HubIf
->Device
->Bus
;
1147 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, PortState
);
1154 Clear the port change status.
1156 @param HubIf The root hub interface.
1157 @param Port The root hub port.
1161 UsbRootHubClearPortChange (
1162 IN USB_INTERFACE
*HubIf
,
1166 EFI_USB_PORT_STATUS PortState
;
1167 USB_CHANGE_FEATURE_MAP
*Map
;
1171 Status
= UsbRootHubGetPortStatus (HubIf
, Port
, &PortState
);
1173 if (EFI_ERROR (Status
)) {
1178 // OK, get the usb port status, now ACK the change bits.
1179 // Don't return error when failed to clear the change bits.
1180 // It may lead to extra port state report. USB bus should
1181 // be able to handle this.
1183 for (Index
= 0; Index
< ARRAY_SIZE (mRootHubFeatureMap
); Index
++) {
1184 Map
= &mRootHubFeatureMap
[Index
];
1186 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
1187 UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, (EFI_USB_PORT_FEATURE
) Map
->Feature
);
1194 Set the root hub port feature.
1196 @param HubIf The Usb hub interface.
1197 @param Port The hub port.
1198 @param Feature The feature to set.
1200 @retval EFI_SUCCESS The root hub port is set with the feature.
1201 @retval Others Failed to set the feature.
1205 UsbRootHubSetPortFeature (
1206 IN USB_INTERFACE
*HubIf
,
1208 IN EFI_USB_PORT_FEATURE Feature
1213 Status
= UsbHcSetRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1220 Clear the root hub port feature.
1222 @param HubIf The root hub interface.
1223 @param Port The root hub port.
1224 @param Feature The feature to clear.
1226 @retval EFI_SUCCESS The root hub port is cleared of the feature.
1227 @retval Others Failed to clear the feature.
1231 UsbRootHubClearPortFeature (
1232 IN USB_INTERFACE
*HubIf
,
1234 IN EFI_USB_PORT_FEATURE Feature
1239 Status
= UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1246 Interface function to reset the root hub port.
1248 @param RootIf The root hub interface.
1249 @param Port The port to reset.
1251 @retval EFI_SUCCESS The hub port is reset.
1252 @retval EFI_TIMEOUT Failed to reset the port in time.
1253 @retval EFI_NOT_FOUND The low/full speed device connected to high speed.
1254 root hub is released to the companion UHCI.
1255 @retval Others Failed to reset the port.
1259 UsbRootHubResetPort (
1260 IN USB_INTERFACE
*RootIf
,
1266 EFI_USB_PORT_STATUS PortState
;
1270 // Notice: although EHCI requires that ENABLED bit be cleared
1271 // when reset the port, we don't need to care that here. It
1272 // should be handled in the EHCI driver.
1274 Bus
= RootIf
->Device
->Bus
;
1276 Status
= UsbHcSetRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1278 if (EFI_ERROR (Status
)) {
1279 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: failed to start reset on port %d\n", Port
));
1284 // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
1285 // section 7.1.7.5 for timing requirements.
1287 gBS
->Stall (USB_SET_ROOT_PORT_RESET_STALL
);
1289 Status
= UsbHcClearRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1291 if (EFI_ERROR (Status
)) {
1292 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: failed to clear reset on port %d\n", Port
));
1296 gBS
->Stall (USB_CLR_ROOT_PORT_RESET_STALL
);
1299 // USB host controller won't clear the RESET bit until
1300 // reset is actually finished.
1302 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
1304 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
1305 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, &PortState
);
1307 if (EFI_ERROR (Status
)) {
1311 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
1315 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
1318 if (Index
== USB_WAIT_PORT_STS_CHANGE_LOOP
) {
1319 DEBUG ((EFI_D_ERROR
, "UsbRootHubResetPort: reset not finished in time on port %d\n", Port
));
1323 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_ENABLE
)) {
1325 // OK, the port is reset. If root hub is of high speed and
1326 // the device is of low/full speed, release the ownership to
1327 // companion UHCI. If root hub is of full speed, it won't
1328 // automatically enable the port, we need to enable it manually.
1330 if (RootIf
->MaxSpeed
== EFI_USB_SPEED_HIGH
) {
1331 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: release low/full speed device (%d) to UHCI\n", Port
));
1333 UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortOwner
);
1334 return EFI_NOT_FOUND
;
1338 Status
= UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortEnable
);
1340 if (EFI_ERROR (Status
)) {
1341 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: failed to enable port %d for UHCI\n", Port
));
1345 gBS
->Stall (USB_SET_ROOT_PORT_ENABLE_STALL
);
1354 Release the root hub's control of the interface.
1356 @param HubIf The root hub interface.
1358 @retval EFI_SUCCESS The root hub's control of the interface is
1364 IN USB_INTERFACE
*HubIf
1367 DEBUG (( EFI_D_INFO
, "UsbRootHubRelease: root hub released for hub %p\n", HubIf
));
1369 gBS
->SetTimer (HubIf
->HubNotify
, TimerCancel
, USB_ROOTHUB_POLL_INTERVAL
);
1370 gBS
->CloseEvent (HubIf
->HubNotify
);
1375 USB_HUB_API mUsbHubApi
= {
1377 UsbHubGetPortStatus
,
1378 UsbHubClearPortChange
,
1379 UsbHubSetPortFeature
,
1380 UsbHubClearPortFeature
,
1385 USB_HUB_API mUsbRootHubApi
= {
1387 UsbRootHubGetPortStatus
,
1388 UsbRootHubClearPortChange
,
1389 UsbRootHubSetPortFeature
,
1390 UsbRootHubClearPortFeature
,
1391 UsbRootHubResetPort
,