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.
42 USB hub control transfer to set the hub depth.
44 @param HubDev The device of the hub.
45 @param Depth The depth to set.
47 @retval EFI_SUCCESS Depth of the hub is set.
48 @retval Others Failed to set the depth.
52 UsbHubCtrlSetHubDepth (
53 IN USB_DEVICE
*HubDev
,
59 Status
= UsbCtrlRequest (
64 USB_HUB_REQ_SET_DEPTH
,
75 USB hub control transfer to clear the hub feature.
77 @param HubDev The device of the hub.
78 @param Feature The feature to clear.
80 @retval EFI_SUCCESS Feature of the hub is cleared.
81 @retval Others Failed to clear the feature.
85 UsbHubCtrlClearHubFeature (
86 IN USB_DEVICE
*HubDev
,
92 Status
= UsbCtrlRequest (
97 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
,
147 Clear the transaction translate buffer if full/low
148 speed control/bulk transfer failed and the transfer
149 uses this hub as translator.Remember to clear the TT
150 buffer of transaction translator, not that of the
153 @param HubDev The hub device.
154 @param Port The port of the hub.
155 @param DevAddr Address of the failed transaction.
156 @param EpNum The endpoint number of the failed transaction.
157 @param EpType The type of failed transaction.
159 @retval EFI_SUCCESS The TT buffer is cleared.
160 @retval Others Failed to clear the TT buffer.
164 UsbHubCtrlClearTTBuffer (
165 IN USB_DEVICE
*HubDev
,
176 // Check USB2.0 spec page 424 for wValue's encoding
178 Value
= (UINT16
)((EpNum
& 0x0F) | (DevAddr
<< 4) |
179 ((EpType
& 0x03) << 11) | ((EpNum
& 0x80) << 15));
181 Status
= UsbCtrlRequest (
186 USB_HUB_REQ_CLEAR_TT
,
197 Usb hub control transfer to get the (super speed) hub descriptor.
199 @param HubDev The hub device.
200 @param Buf The buffer to hold the descriptor.
201 @param Len The length to retrieve.
203 @retval EFI_SUCCESS The hub descriptor is retrieved.
204 @retval Others Failed to retrieve the hub descriptor.
208 UsbHubCtrlGetHubDesc (
209 IN USB_DEVICE
*HubDev
,
217 DescType
= (HubDev
->Speed
== EFI_USB_SPEED_SUPER
) ?
218 USB_DESC_TYPE_HUB_SUPER_SPEED
:
221 Status
= UsbCtrlRequest (
226 USB_HUB_REQ_GET_DESC
,
227 (UINT16
)(DescType
<< 8),
237 Usb hub control transfer to get the hub status.
239 @param HubDev The hub device.
240 @param State The variable to return the status.
242 @retval EFI_SUCCESS The hub status is returned in State.
243 @retval Others Failed to get the hub status.
247 UsbHubCtrlGetHubStatus (
248 IN USB_DEVICE
*HubDev
,
254 Status
= UsbCtrlRequest (
259 USB_HUB_REQ_GET_STATUS
,
270 Usb hub control transfer to get the port status.
272 @param HubDev The hub device.
273 @param Port The port of the hub.
274 @param State Variable to return the hub port state.
276 @retval EFI_SUCCESS The port state is returned in State.
277 @retval Others Failed to retrieve the port state.
281 UsbHubCtrlGetPortStatus (
282 IN USB_DEVICE
*HubDev
,
290 // In USB bus, all the port index starts from 0. But HUB
291 // indexes its port from 1. So, port number is added one.
292 // No need to convert the hub bit to UEFI definition, they
295 Status
= UsbCtrlRequest (
300 USB_HUB_REQ_GET_STATUS
,
311 Usb hub control transfer to set the port feature.
313 @param HubDev The Usb hub device.
314 @param Port The Usb port to set feature for.
315 @param Feature The feature to set.
317 @retval EFI_SUCCESS The feature is set for the port.
318 @retval Others Failed to set the feature.
322 UsbHubCtrlSetPortFeature (
323 IN USB_DEVICE
*HubDev
,
331 // In USB bus, all the port index starts from 0. But HUB
332 // indexes its port from 1. So, port number is added one.
334 Status
= UsbCtrlRequest (
339 USB_HUB_REQ_SET_FEATURE
,
350 Read the whole usb hub descriptor. It is necessary
351 to do it in two steps because hub descriptor is of
354 @param HubDev The hub device.
355 @param HubDesc The variable to return the descriptor.
357 @retval EFI_SUCCESS The hub descriptor is read.
358 @retval Others Failed to read the hub descriptor.
363 IN USB_DEVICE
*HubDev
,
364 OUT EFI_USB_HUB_DESCRIPTOR
*HubDesc
370 // First get the hub descriptor length
372 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, 2);
374 if (EFI_ERROR (Status
)) {
379 // Get the whole hub descriptor
381 return UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, HubDesc
->Length
);
385 Ack the hub change bits. If these bits are not ACKed, Hub will
386 always return changed bit map from its interrupt endpoint.
388 @param HubDev The hub device.
390 @retval EFI_SUCCESS The hub change status is ACKed.
391 @retval Others Failed to ACK the hub status.
396 IN USB_DEVICE
*HubDev
399 EFI_USB_PORT_STATUS HubState
;
402 Status
= UsbHubCtrlGetHubStatus (HubDev
, (UINT32
*)&HubState
);
404 if (EFI_ERROR (Status
)) {
408 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_LOCAL_POWER
)) {
409 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_LOCAL_POWER
);
412 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_OVER_CURRENT
)) {
413 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_OVER_CURRENT
);
420 Test whether the interface is a hub interface.
422 @param UsbIf The interface to test.
424 @retval TRUE The interface is a hub interface.
425 @retval FALSE The interface isn't a hub interface.
430 IN USB_INTERFACE
*UsbIf
433 EFI_USB_INTERFACE_DESCRIPTOR
*Setting
;
436 // If the hub is a high-speed hub with multiple TT,
437 // the hub will has a default setting of single TT.
439 Setting
= &UsbIf
->IfSetting
->Desc
;
441 if ((Setting
->InterfaceClass
== USB_HUB_CLASS_CODE
) &&
442 (Setting
->InterfaceSubClass
== USB_HUB_SUBCLASS_CODE
))
451 The callback function to the USB hub status change
452 interrupt endpoint. It is called periodically by
453 the underlying host controller.
455 @param Data The data read.
456 @param DataLength The length of the data read.
457 @param Context The context.
458 @param Result The result of the last interrupt transfer.
460 @retval EFI_SUCCESS The process is OK.
461 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
473 USB_INTERFACE
*HubIf
;
474 EFI_USB_IO_PROTOCOL
*UsbIo
;
475 EFI_USB_ENDPOINT_DESCRIPTOR
*EpDesc
;
478 HubIf
= (USB_INTERFACE
*)Context
;
479 UsbIo
= &(HubIf
->UsbIo
);
480 EpDesc
= &(HubIf
->HubEp
->Desc
);
482 if (Result
!= EFI_USB_NOERROR
) {
484 // If endpoint is stalled, clear the stall. Use UsbIo to access
485 // the control transfer so internal status are maintained.
487 if (USB_BIT_IS_SET (Result
, EFI_USB_ERR_STALL
)) {
491 USB_FEATURE_ENDPOINT_HALT
,
492 EpDesc
->EndpointAddress
497 // Delete and submit a new async interrupt
499 Status
= UsbIo
->UsbAsyncInterruptTransfer (
501 EpDesc
->EndpointAddress
,
509 if (EFI_ERROR (Status
)) {
510 DEBUG ((DEBUG_ERROR
, "UsbOnHubInterrupt: failed to remove async transfer - %r\n", Status
));
514 Status
= UsbIo
->UsbAsyncInterruptTransfer (
516 EpDesc
->EndpointAddress
,
518 USB_HUB_POLL_INTERVAL
,
519 HubIf
->NumOfPort
/ 8 + 1,
524 if (EFI_ERROR (Status
)) {
525 DEBUG ((DEBUG_ERROR
, "UsbOnHubInterrupt: failed to submit new async transfer - %r\n", Status
));
531 if ((DataLength
== 0) || (Data
== NULL
)) {
536 // OK, actually something is changed, save the change map
537 // then signal the HUB to do enumeration. This is a good
538 // practise since UsbOnHubInterrupt is called in the context
539 // of host controller's AsyncInterrupt monitor.
541 HubIf
->ChangeMap
= AllocateZeroPool (DataLength
);
543 if (HubIf
->ChangeMap
== NULL
) {
544 return EFI_OUT_OF_RESOURCES
;
547 CopyMem (HubIf
->ChangeMap
, Data
, DataLength
);
548 gBS
->SignalEvent (HubIf
->HubNotify
);
554 Initialize the device for a non-root hub.
556 @param HubIf The USB hub interface.
558 @retval EFI_SUCCESS The hub is initialized.
559 @retval EFI_DEVICE_ERROR Failed to initialize the hub.
564 IN USB_INTERFACE
*HubIf
567 UINT8 HubDescBuffer
[256];
568 EFI_USB_HUB_DESCRIPTOR
*HubDesc
;
569 USB_ENDPOINT_DESC
*EpDesc
;
570 USB_INTERFACE_SETTING
*Setting
;
571 EFI_USB_IO_PROTOCOL
*UsbIo
;
579 // Locate the interrupt endpoint for port change map
581 HubIf
->IsHub
= FALSE
;
582 Setting
= HubIf
->IfSetting
;
583 HubDev
= HubIf
->Device
;
585 NumEndpoints
= Setting
->Desc
.NumEndpoints
;
587 for (Index
= 0; Index
< NumEndpoints
; Index
++) {
588 ASSERT ((Setting
->Endpoints
!= NULL
) && (Setting
->Endpoints
[Index
] != NULL
));
590 EpDesc
= Setting
->Endpoints
[Index
];
592 if (USB_BIT_IS_SET (EpDesc
->Desc
.EndpointAddress
, USB_ENDPOINT_DIR_IN
) &&
593 (USB_ENDPOINT_TYPE (&EpDesc
->Desc
) == USB_ENDPOINT_INTERRUPT
))
599 if (Index
== NumEndpoints
) {
600 DEBUG ((DEBUG_ERROR
, "UsbHubInit: no interrupt endpoint found for hub %d\n", HubDev
->Address
));
601 return EFI_DEVICE_ERROR
;
605 // The length field of descriptor is UINT8 type, so the buffer
606 // with 256 bytes is enough to hold the descriptor data.
608 HubDesc
= (EFI_USB_HUB_DESCRIPTOR
*)HubDescBuffer
;
609 Status
= UsbHubReadDesc (HubDev
, HubDesc
);
611 if (EFI_ERROR (Status
)) {
612 DEBUG ((DEBUG_ERROR
, "UsbHubInit: failed to read HUB descriptor - %r\n", Status
));
616 HubIf
->NumOfPort
= HubDesc
->NumPorts
;
618 DEBUG ((DEBUG_INFO
, "UsbHubInit: hub %d has %d ports\n", HubDev
->Address
, HubIf
->NumOfPort
));
621 // OK, set IsHub to TRUE. Now usb bus can handle this device
622 // as a working HUB. If failed earlier, bus driver will not
623 // recognize it as a hub. Other parts of the bus should be able
627 HubIf
->HubApi
= &mUsbHubApi
;
628 HubIf
->HubEp
= EpDesc
;
630 if (HubIf
->Device
->Speed
== EFI_USB_SPEED_SUPER
) {
631 Depth
= (UINT16
)(HubIf
->Device
->Tier
- 1);
632 DEBUG ((DEBUG_INFO
, "UsbHubInit: Set Hub Depth as 0x%x\n", Depth
));
633 UsbHubCtrlSetHubDepth (HubIf
->Device
, Depth
);
635 for (Index
= 0; Index
< HubDesc
->NumPorts
; Index
++) {
636 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, USB_HUB_PORT_REMOTE_WAKE_MASK
);
640 // Feed power to all the hub ports. It should be ok
641 // for both gang/individual powered hubs.
643 for (Index
= 0; Index
< HubDesc
->NumPorts
; Index
++) {
644 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, (EFI_USB_PORT_FEATURE
)USB_HUB_PORT_POWER
);
648 // Update for the usb hub has no power on delay requirement
650 if (HubDesc
->PwrOn2PwrGood
> 0) {
651 gBS
->Stall (HubDesc
->PwrOn2PwrGood
* USB_SET_PORT_POWER_STALL
);
654 UsbHubAckHubStatus (HubIf
->Device
);
658 // Create an event to enumerate the hub's port. On
660 Status
= gBS
->CreateEvent (
668 if (EFI_ERROR (Status
)) {
671 "UsbHubInit: failed to create signal for hub %d - %r\n",
680 // Create AsyncInterrupt to query hub port change endpoint
681 // periodically. If the hub ports are changed, hub will return
682 // changed port map from the interrupt endpoint. The port map
683 // must be able to hold (HubIf->NumOfPort + 1) bits (one bit for
684 // host change status).
686 UsbIo
= &HubIf
->UsbIo
;
687 Status
= UsbIo
->UsbAsyncInterruptTransfer (
689 EpDesc
->Desc
.EndpointAddress
,
691 USB_HUB_POLL_INTERVAL
,
692 HubIf
->NumOfPort
/ 8 + 1,
697 if (EFI_ERROR (Status
)) {
700 "UsbHubInit: failed to queue interrupt transfer for hub %d - %r\n",
705 gBS
->CloseEvent (HubIf
->HubNotify
);
706 HubIf
->HubNotify
= NULL
;
711 DEBUG ((DEBUG_INFO
, "UsbHubInit: hub %d initialized\n", HubDev
->Address
));
716 Get the port status. This function is required to
717 ACK the port change bits although it will return
718 the port changes in PortState. Bus enumeration code
719 doesn't need to ACK the port change bits.
721 @param HubIf The hub interface.
722 @param Port The port of the hub to get state.
723 @param PortState Variable to return the port state.
725 @retval EFI_SUCCESS The port status is successfully returned.
726 @retval Others Failed to return the status.
730 UsbHubGetPortStatus (
731 IN USB_INTERFACE
*HubIf
,
733 OUT EFI_USB_PORT_STATUS
*PortState
738 Status
= UsbHubCtrlGetPortStatus (HubIf
->Device
, Port
, PortState
);
744 Clear the port change status.
746 @param HubIf The hub interface.
747 @param Port The hub port.
751 UsbHubClearPortChange (
752 IN USB_INTERFACE
*HubIf
,
756 EFI_USB_PORT_STATUS PortState
;
757 USB_CHANGE_FEATURE_MAP
*Map
;
761 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
763 if (EFI_ERROR (Status
)) {
768 // OK, get the usb port status, now ACK the change bits.
769 // Don't return error when failed to clear the change bits.
770 // It may lead to extra port state report. USB bus should
771 // be able to handle this.
773 for (Index
= 0; Index
< ARRAY_SIZE (mHubFeatureMap
); Index
++) {
774 Map
= &mHubFeatureMap
[Index
];
776 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
777 UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT16
)Map
->Feature
);
783 Function to set the port feature for non-root hub.
785 @param HubIf The hub interface.
786 @param Port The port of the hub.
787 @param Feature The feature of the port to set.
789 @retval EFI_SUCCESS The hub port feature is set.
790 @retval Others Failed to set the port feature.
794 UsbHubSetPortFeature (
795 IN USB_INTERFACE
*HubIf
,
797 IN EFI_USB_PORT_FEATURE Feature
802 Status
= UsbHubCtrlSetPortFeature (HubIf
->Device
, Port
, (UINT8
)Feature
);
808 Interface function to clear the port feature for non-root hub.
810 @param HubIf The hub interface.
811 @param Port The port of the hub to clear feature for.
812 @param Feature The feature to clear.
814 @retval EFI_SUCCESS The port feature is cleared.
815 @retval Others Failed to clear the port feature.
819 UsbHubClearPortFeature (
820 IN USB_INTERFACE
*HubIf
,
822 IN EFI_USB_PORT_FEATURE Feature
827 Status
= UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT8
)Feature
);
833 Interface function to reset the port.
835 @param HubIf The hub interface.
836 @param Port The port to reset.
838 @retval EFI_SUCCESS The hub port is reset.
839 @retval EFI_TIMEOUT Failed to reset the port in time.
840 @retval Others Failed to reset the port.
845 IN USB_INTERFACE
*HubIf
,
849 EFI_USB_PORT_STATUS PortState
;
853 Status
= UsbHubSetPortFeature (HubIf
, Port
, (EFI_USB_PORT_FEATURE
)USB_HUB_PORT_RESET
);
855 if (EFI_ERROR (Status
)) {
860 // Drive the reset signal for worst 20ms. Check USB 2.0 Spec
861 // section 7.1.7.5 for timing requirements.
863 gBS
->Stall (USB_SET_PORT_RESET_STALL
);
866 // Check USB_PORT_STAT_C_RESET bit to see if the resetting state is done.
868 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
870 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
871 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
873 if (EFI_ERROR (Status
)) {
877 if (!EFI_ERROR (Status
) &&
878 USB_BIT_IS_SET (PortState
.PortChangeStatus
, USB_PORT_STAT_C_RESET
))
880 gBS
->Stall (USB_SET_PORT_RECOVERY_STALL
);
884 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
891 Release the hub's control of the interface.
893 @param HubIf The hub interface.
895 @retval EFI_SUCCESS The interface is release of hub control.
900 IN USB_INTERFACE
*HubIf
903 EFI_USB_IO_PROTOCOL
*UsbIo
;
906 UsbIo
= &HubIf
->UsbIo
;
907 Status
= UsbIo
->UsbAsyncInterruptTransfer (
909 HubIf
->HubEp
->Desc
.EndpointAddress
,
911 USB_HUB_POLL_INTERVAL
,
917 if (EFI_ERROR (Status
)) {
921 gBS
->CloseEvent (HubIf
->HubNotify
);
923 HubIf
->IsHub
= FALSE
;
924 HubIf
->HubApi
= NULL
;
926 HubIf
->HubNotify
= NULL
;
928 DEBUG ((DEBUG_INFO
, "UsbHubRelease: hub device %d released\n", HubIf
->Device
->Address
));
933 Initialize the interface for root hub.
935 @param HubIf The root hub interface.
937 @retval EFI_SUCCESS The interface is initialized for root hub.
938 @retval Others Failed to initialize the hub.
943 IN USB_INTERFACE
*HubIf
951 Status
= UsbHcGetCapability (HubIf
->Device
->Bus
, &MaxSpeed
, &NumOfPort
, &Support64
);
953 if (EFI_ERROR (Status
)) {
959 "UsbRootHubInit: root hub %p - max speed %d, %d ports\n",
966 HubIf
->HubApi
= &mUsbRootHubApi
;
968 HubIf
->MaxSpeed
= MaxSpeed
;
969 HubIf
->NumOfPort
= NumOfPort
;
970 HubIf
->HubNotify
= NULL
;
973 // Create a timer to poll root hub ports periodically
975 Status
= gBS
->CreateEvent (
976 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
978 UsbRootHubEnumeration
,
983 if (EFI_ERROR (Status
)) {
988 // It should signal the event immediately here, or device detection
989 // by bus enumeration might be delayed by the timer interval.
991 gBS
->SignalEvent (HubIf
->HubNotify
);
993 Status
= gBS
->SetTimer (
996 USB_ROOTHUB_POLL_INTERVAL
999 if (EFI_ERROR (Status
)) {
1000 gBS
->CloseEvent (HubIf
->HubNotify
);
1007 Get the port status. This function is required to
1008 ACK the port change bits although it will return
1009 the port changes in PortState. Bus enumeration code
1010 doesn't need to ACK the port change bits.
1012 @param HubIf The root hub interface.
1013 @param Port The root hub port to get the state.
1014 @param PortState Variable to return the port state.
1016 @retval EFI_SUCCESS The port state is returned.
1017 @retval Others Failed to retrieve the port state.
1021 UsbRootHubGetPortStatus (
1022 IN USB_INTERFACE
*HubIf
,
1024 OUT EFI_USB_PORT_STATUS
*PortState
1030 Bus
= HubIf
->Device
->Bus
;
1031 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, PortState
);
1037 Clear the port change status.
1039 @param HubIf The root hub interface.
1040 @param Port The root hub port.
1044 UsbRootHubClearPortChange (
1045 IN USB_INTERFACE
*HubIf
,
1049 EFI_USB_PORT_STATUS PortState
;
1050 USB_CHANGE_FEATURE_MAP
*Map
;
1054 Status
= UsbRootHubGetPortStatus (HubIf
, Port
, &PortState
);
1056 if (EFI_ERROR (Status
)) {
1061 // OK, get the usb port status, now ACK the change bits.
1062 // Don't return error when failed to clear the change bits.
1063 // It may lead to extra port state report. USB bus should
1064 // be able to handle this.
1066 for (Index
= 0; Index
< ARRAY_SIZE (mRootHubFeatureMap
); Index
++) {
1067 Map
= &mRootHubFeatureMap
[Index
];
1069 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
1070 UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, (EFI_USB_PORT_FEATURE
)Map
->Feature
);
1076 Set the root hub port feature.
1078 @param HubIf The Usb hub interface.
1079 @param Port The hub port.
1080 @param Feature The feature to set.
1082 @retval EFI_SUCCESS The root hub port is set with the feature.
1083 @retval Others Failed to set the feature.
1087 UsbRootHubSetPortFeature (
1088 IN USB_INTERFACE
*HubIf
,
1090 IN EFI_USB_PORT_FEATURE Feature
1095 Status
= UsbHcSetRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1101 Clear the root hub port feature.
1103 @param HubIf The root hub interface.
1104 @param Port The root hub port.
1105 @param Feature The feature to clear.
1107 @retval EFI_SUCCESS The root hub port is cleared of the feature.
1108 @retval Others Failed to clear the feature.
1112 UsbRootHubClearPortFeature (
1113 IN USB_INTERFACE
*HubIf
,
1115 IN EFI_USB_PORT_FEATURE Feature
1120 Status
= UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1126 Interface function to reset the root hub port.
1128 @param RootIf The root hub interface.
1129 @param Port The port to reset.
1131 @retval EFI_SUCCESS The hub port is reset.
1132 @retval EFI_TIMEOUT Failed to reset the port in time.
1133 @retval EFI_NOT_FOUND The low/full speed device connected to high speed.
1134 root hub is released to the companion UHCI.
1135 @retval Others Failed to reset the port.
1139 UsbRootHubResetPort (
1140 IN USB_INTERFACE
*RootIf
,
1146 EFI_USB_PORT_STATUS PortState
;
1150 // Notice: although EHCI requires that ENABLED bit be cleared
1151 // when reset the port, we don't need to care that here. It
1152 // should be handled in the EHCI driver.
1154 Bus
= RootIf
->Device
->Bus
;
1156 Status
= UsbHcSetRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1158 if (EFI_ERROR (Status
)) {
1159 DEBUG ((DEBUG_ERROR
, "UsbRootHubResetPort: failed to start reset on port %d\n", Port
));
1164 // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
1165 // section 7.1.7.5 for timing requirements.
1167 gBS
->Stall (USB_SET_ROOT_PORT_RESET_STALL
);
1169 Status
= UsbHcClearRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1171 if (EFI_ERROR (Status
)) {
1172 DEBUG ((DEBUG_ERROR
, "UsbRootHubResetPort: failed to clear reset on port %d\n", Port
));
1176 gBS
->Stall (USB_CLR_ROOT_PORT_RESET_STALL
);
1179 // USB host controller won't clear the RESET bit until
1180 // reset is actually finished.
1182 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
1184 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
1185 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, &PortState
);
1187 if (EFI_ERROR (Status
)) {
1191 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
1195 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
1198 if (Index
== USB_WAIT_PORT_STS_CHANGE_LOOP
) {
1199 DEBUG ((DEBUG_ERROR
, "UsbRootHubResetPort: reset not finished in time on port %d\n", Port
));
1203 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_ENABLE
)) {
1205 // OK, the port is reset. If root hub is of high speed and
1206 // the device is of low/full speed, release the ownership to
1207 // companion UHCI. If root hub is of full speed, it won't
1208 // automatically enable the port, we need to enable it manually.
1210 if (RootIf
->MaxSpeed
== EFI_USB_SPEED_HIGH
) {
1211 DEBUG ((DEBUG_ERROR
, "UsbRootHubResetPort: release low/full speed device (%d) to UHCI\n", Port
));
1213 UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortOwner
);
1214 return EFI_NOT_FOUND
;
1216 Status
= UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortEnable
);
1218 if (EFI_ERROR (Status
)) {
1219 DEBUG ((DEBUG_ERROR
, "UsbRootHubResetPort: failed to enable port %d for UHCI\n", Port
));
1223 gBS
->Stall (USB_SET_ROOT_PORT_ENABLE_STALL
);
1231 Release the root hub's control of the interface.
1233 @param HubIf The root hub interface.
1235 @retval EFI_SUCCESS The root hub's control of the interface is
1241 IN USB_INTERFACE
*HubIf
1244 DEBUG ((DEBUG_INFO
, "UsbRootHubRelease: root hub released for hub %p\n", HubIf
));
1246 gBS
->SetTimer (HubIf
->HubNotify
, TimerCancel
, USB_ROOTHUB_POLL_INTERVAL
);
1247 gBS
->CloseEvent (HubIf
->HubNotify
);
1252 USB_HUB_API mUsbHubApi
= {
1254 UsbHubGetPortStatus
,
1255 UsbHubClearPortChange
,
1256 UsbHubSetPortFeature
,
1257 UsbHubClearPortFeature
,
1262 USB_HUB_API mUsbRootHubApi
= {
1264 UsbRootHubGetPortStatus
,
1265 UsbRootHubClearPortChange
,
1266 UsbRootHubSetPortFeature
,
1267 UsbRootHubClearPortFeature
,
1268 UsbRootHubResetPort
,