3 Unified interface for RootHub and Hub.
5 Copyright (c) 2007, Intel Corporation
6 All rights reserved. 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 // USB hub class specific requests. Although USB hub
20 // is related to an interface, these requests are sent
21 // to the control endpoint of the device.
26 USB hub control transfer to clear the hub feature.
28 @param HubDev The device of the hub.
29 @param Feature The feature to clear.
31 @retval EFI_SUCCESS Feature of the hub is cleared.
32 @retval Others Failed to clear the feature.
36 UsbHubCtrlClearHubFeature (
37 IN USB_DEVICE
*HubDev
,
43 Status
= UsbCtrlRequest (
48 USB_HUB_REQ_CLEAR_FEATURE
,
60 Clear the feature of the device's port.
62 @param HubDev The hub device.
63 @param Port The port to clear feature.
64 @param Feature The feature to clear.
66 @retval EFI_SUCCESS The feature of the port is cleared.
67 @retval Others Failed to clear the feature.
71 UsbHubCtrlClearPortFeature (
72 IN USB_DEVICE
*HubDev
,
80 // In USB bus, all the port index starts from 0. But HUB
81 // indexes its port from 1. So, port number is added one.
83 Status
= UsbCtrlRequest (
88 USB_HUB_REQ_CLEAR_FEATURE
,
100 Clear the transaction translate buffer if full/low
101 speed control/bulk transfer failed and the transfer
102 uses this hub as translator.Remember to clear the TT
103 buffer of transaction translator, not that of the
106 @param HubDev The hub device.
107 @param Port The port of the hub.
108 @param DevAddr Address of the failed transaction.
109 @param EpNum The endpoint number of the failed transaction.
110 @param EpType The type of failed transaction.
112 @retval EFI_SUCCESS The TT buffer is cleared.
113 @retval Others Failed to clear the TT buffer.
117 UsbHubCtrlClearTTBuffer (
118 IN USB_DEVICE
*HubDev
,
129 // Check USB2.0 spec page 424 for wValue's encoding
131 Value
= (UINT16
) ((EpNum
& 0x0F) | (DevAddr
<< 4) |
132 ((EpType
& 0x03) << 11) | ((EpNum
& 0x80) << 15));
134 Status
= UsbCtrlRequest (
139 USB_HUB_REQ_CLEAR_TT
,
151 Usb hub control transfer to get the hub descriptor.
153 @param HubDev The hub device.
154 @param Buf The buffer to hold the descriptor.
155 @param Len The length to retrieve.
157 @retval EFI_SUCCESS The hub descriptor is retrieved.
158 @retval Others Failed to retrieve the hub descriptor.
162 UsbHubCtrlGetHubDesc (
163 IN USB_DEVICE
*HubDev
,
170 Status
= UsbCtrlRequest (
175 USB_HUB_REQ_GET_DESC
,
176 (UINT16
) (USB_DESC_TYPE_HUB
<< 8),
187 Usb hub control transfer to get the hub status.
189 @param HubDev The hub device.
190 @param State The variable to return the status.
192 @retval EFI_SUCCESS The hub status is returned in State.
193 @retval Others Failed to get the hub status.
197 UsbHubCtrlGetHubStatus (
198 IN USB_DEVICE
*HubDev
,
204 Status
= UsbCtrlRequest (
209 USB_HUB_REQ_GET_STATUS
,
221 Usb hub control transfer to get the port status.
223 @param HubDev The hub device.
224 @param Port The port of the hub.
225 @param State Variable to return the hub port state.
227 @retval EFI_SUCCESS The port state is returned in State.
228 @retval Others Failed to retrive the port state.
232 UsbHubCtrlGetPortStatus (
233 IN USB_DEVICE
*HubDev
,
241 // In USB bus, all the port index starts from 0. But HUB
242 // indexes its port from 1. So, port number is added one.
243 // No need to convert the hub bit to UEFI definition, they
246 Status
= UsbCtrlRequest (
251 USB_HUB_REQ_GET_STATUS
,
263 Usb hub control transfer to reset the TT (Transaction Transaltor).
265 @param HubDev The hub device.
266 @param Port The port of the hub.
268 @retval EFI_SUCCESS The TT of the hub is reset.
269 @retval Others Failed to reset the port.
274 IN USB_DEVICE
*HubDev
,
280 Status
= UsbCtrlRequest (
285 USB_HUB_REQ_RESET_TT
,
297 Usb hub control transfer to set the hub feature.
299 @param HubDev The hub device.
300 @param Feature The feature to set.
302 @retval EFI_SUCESS The feature is set for the hub.
303 @retval Others Failed to set the feature.
307 UsbHubCtrlSetHubFeature (
308 IN USB_DEVICE
*HubDev
,
314 Status
= UsbCtrlRequest (
319 USB_HUB_REQ_SET_FEATURE
,
331 Usb hub control transfer to set the port feature.
333 @param HubDev The Usb hub device.
334 @param Port The Usb port to set feature for.
335 @param Feature The feature to set.
337 @retval EFI_SUCCESS The feature is set for the port.
338 @retval Others Failed to set the feature.
342 UsbHubCtrlSetPortFeature (
343 IN USB_DEVICE
*HubDev
,
351 // In USB bus, all the port index starts from 0. But HUB
352 // indexes its port from 1. So, port number is added one.
354 Status
= UsbCtrlRequest (
359 USB_HUB_REQ_SET_FEATURE
,
371 Read the whole usb hub descriptor. It is necessary
372 to do it in two steps because hub descriptor is of
375 @param HubDev The hub device.
376 @param HubDesc The variable to return the descriptor.
378 @retval EFI_SUCCESS The hub descriptor is read.
379 @retval Others Failed to read the hub descriptor.
384 IN USB_DEVICE
*HubDev
,
385 OUT EFI_USB_HUB_DESCRIPTOR
*HubDesc
391 // First get the hub descriptor length
393 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, 2);
395 if (EFI_ERROR (Status
)) {
400 // Get the whole hub descriptor
402 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, HubDesc
->Length
);
410 Ack the hub change bits. If these bits are not ACKed, Hub will
411 always return changed bit map from its interrupt endpoint.
413 @param HubDev The hub device.
415 @retval EFI_SUCCESS The hub change status is ACKed.
416 @retval Others Failed to ACK the hub status.
421 IN USB_DEVICE
*HubDev
424 EFI_USB_PORT_STATUS HubState
;
427 Status
= UsbHubCtrlGetHubStatus (HubDev
, (UINT32
*) &HubState
);
429 if (EFI_ERROR (Status
)) {
433 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_LOCAL_POWER
)) {
434 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_LOCAL_POWER
);
437 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_OVER_CURRENT
)) {
438 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_OVER_CURRENT
);
446 Test whether the interface is a hub interface.
448 @param UsbIf The interface to test.
450 @retval TRUE The interface is a hub interface.
451 @retval FALSE The interface isn't a hub interface.
456 IN USB_INTERFACE
*UsbIf
459 EFI_USB_INTERFACE_DESCRIPTOR
*Setting
;
462 // If the hub is a high-speed hub with multiple TT,
463 // the hub will has a default setting of single TT.
465 Setting
= &UsbIf
->IfSetting
->Desc
;
467 if ((Setting
->InterfaceClass
== USB_HUB_CLASS_CODE
) &&
468 (Setting
->InterfaceSubClass
== USB_HUB_SUBCLASS_CODE
)) {
478 The callback function to the USB hub status change
479 interrupt endpoint. It is called periodically by
480 the underlying host controller.
482 @param Data The data read.
483 @param DataLength The length of the data read.
484 @param Context The context.
485 @param Result The result of the last interrupt transfer.
487 @retval EFI_SUCCESS The process is OK.
488 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
499 USB_INTERFACE
*HubIf
;
500 EFI_USB_IO_PROTOCOL
*UsbIo
;
501 EFI_USB_ENDPOINT_DESCRIPTOR
*EpDesc
;
504 HubIf
= (USB_INTERFACE
*) Context
;
505 UsbIo
= &(HubIf
->UsbIo
);
506 EpDesc
= &(HubIf
->HubEp
->Desc
);
508 if (Result
!= EFI_USB_NOERROR
) {
510 // If endpoint is stalled, clear the stall. Use UsbIo to access
511 // the control transfer so internal status are maintained.
513 if (USB_BIT_IS_SET (Result
, EFI_USB_ERR_STALL
)) {
517 USB_FEATURE_ENDPOINT_HALT
,
518 EpDesc
->EndpointAddress
523 // Delete and submit a new async interrupt
525 Status
= UsbIo
->UsbAsyncInterruptTransfer (
527 EpDesc
->EndpointAddress
,
535 if (EFI_ERROR (Status
)) {
536 DEBUG (( EFI_D_ERROR
, "UsbOnHubInterrupt: failed to remove async transfer - %r\n", Status
));
540 Status
= UsbIo
->UsbAsyncInterruptTransfer (
542 EpDesc
->EndpointAddress
,
544 USB_HUB_POLL_INTERVAL
,
545 HubIf
->NumOfPort
/ 8 + 1,
550 if (EFI_ERROR (Status
)) {
551 DEBUG (( EFI_D_ERROR
, "UsbOnHubInterrupt: failed to submit new async transfer - %r\n", Status
));
557 if ((DataLength
== 0) || (Data
== NULL
)) {
562 // OK, actually something is changed, save the change map
563 // then signal the HUB to do enumeration. This is a good
564 // practise since UsbOnHubInterrupt is called in the context
565 // of host contrller's AsyncInterrupt monitor.
567 HubIf
->ChangeMap
= AllocateZeroPool (DataLength
);
569 if (HubIf
->ChangeMap
== NULL
) {
570 return EFI_OUT_OF_RESOURCES
;
573 CopyMem (HubIf
->ChangeMap
, Data
, DataLength
);
574 gBS
->SignalEvent (HubIf
->HubNotify
);
580 // Array that maps the change bit to feature value which is
581 // used to clear these change bit. USB HUB API will clear
582 // these change bit automatically. For non-root hub, these
583 // bits determine whether hub will report the port in changed
586 #define USB_HUB_MAP_SIZE 5
588 USB_CHANGE_FEATURE_MAP mHubFeatureMap
[USB_HUB_MAP_SIZE
] = {
589 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
590 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
591 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
592 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
593 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
},
596 #define USB_ROOT_HUB_MAP_SIZE 5
598 USB_CHANGE_FEATURE_MAP mRootHubFeatureMap
[USB_ROOT_HUB_MAP_SIZE
] = {
599 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
600 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
601 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
602 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
603 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
},
609 Initialize the device for a non-root hub.
611 @param HubIf The USB hub interface.
613 @retval EFI_SUCCESS The hub is initialized.
614 @retval EFI_DEVICE_ERROR Failed to initialize the hub.
619 IN USB_INTERFACE
*HubIf
622 EFI_USB_HUB_DESCRIPTOR HubDesc
;
623 USB_ENDPOINT_DESC
*EpDesc
;
624 USB_INTERFACE_SETTING
*Setting
;
625 EFI_USB_IO_PROTOCOL
*UsbIo
;
631 // Locate the interrupt endpoint for port change map
633 HubIf
->IsHub
= FALSE
;
634 Setting
= HubIf
->IfSetting
;
635 HubDev
= HubIf
->Device
;
638 for (Index
= 0; Index
< Setting
->Desc
.NumEndpoints
; Index
++) {
639 ASSERT ((Setting
->Endpoints
!= NULL
) && (Setting
->Endpoints
[Index
] != NULL
));
641 EpDesc
= Setting
->Endpoints
[Index
];
643 if (USB_BIT_IS_SET (EpDesc
->Desc
.EndpointAddress
, USB_ENDPOINT_DIR_IN
) &&
644 (USB_ENDPOINT_TYPE (&EpDesc
->Desc
) == USB_ENDPOINT_INTERRUPT
)) {
649 if (Index
== Setting
->Desc
.NumEndpoints
) {
650 DEBUG (( EFI_D_ERROR
, "UsbHubInit: no interrupt endpoint found for hub %d\n", HubDev
->Address
));
651 return EFI_DEVICE_ERROR
;
654 Status
= UsbHubReadDesc (HubDev
, &HubDesc
);
656 if (EFI_ERROR (Status
)) {
657 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to read HUB descriptor %r\n", Status
));
661 HubIf
->NumOfPort
= HubDesc
.NumPorts
;
663 DEBUG (( EFI_D_INFO
, "UsbHubInit: hub %d has %d ports\n", HubDev
->Address
,HubIf
->NumOfPort
));
666 // Create an event to enumerate the hub's port. On
668 Status
= gBS
->CreateEvent (
676 if (EFI_ERROR (Status
)) {
677 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to create signal for hub %d - %r\n",
678 HubDev
->Address
, Status
));
684 // Create AsyncInterrupt to query hub port change endpoint
685 // periodically. If the hub ports are changed, hub will return
686 // changed port map from the interrupt endpoint. The port map
687 // must be able to hold (HubIf->NumOfPort + 1) bits (one bit for
688 // host change status).
690 UsbIo
= &HubIf
->UsbIo
;
691 Status
= UsbIo
->UsbAsyncInterruptTransfer (
693 EpDesc
->Desc
.EndpointAddress
,
695 USB_HUB_POLL_INTERVAL
,
696 HubIf
->NumOfPort
/ 8 + 1,
701 if (EFI_ERROR (Status
)) {
702 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to queue interrupt transfer for hub %d - %r\n",
703 HubDev
->Address
, Status
));
705 gBS
->CloseEvent (HubIf
->HubNotify
);
706 HubIf
->HubNotify
= NULL
;
712 // OK, set IsHub to TRUE. Now usb bus can handle this device
713 // as a working HUB. If failed eariler, bus driver will not
714 // recognize it as a hub. Other parts of the bus should be able
718 HubIf
->HubApi
= &mUsbHubApi
;
719 HubIf
->HubEp
= EpDesc
;
722 // Feed power to all the hub ports. It should be ok
723 // for both gang/individual powered hubs.
725 for (Index
= 0; Index
< HubDesc
.NumPorts
; Index
++) {
726 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_POWER
);
729 gBS
->Stall (HubDesc
.PwrOn2PwrGood
* USB_SET_PORT_POWER_STALL
);
730 UsbHubAckHubStatus (HubIf
->Device
);
732 DEBUG (( EFI_D_INFO
, "UsbHubInit: hub %d initialized\n", HubDev
->Address
));
739 Get the port status. This function is required to
740 ACK the port change bits although it will return
741 the port changes in PortState. Bus enumeration code
742 doesn't need to ACK the port change bits.
744 @param HubIf The hub interface.
745 @param Port The port of the hub to get state.
746 @param PortState Variable to return the port state.
748 @retval EFI_SUCCESS The port status is successfully returned.
749 @retval Others Failed to return the status.
753 UsbHubGetPortStatus (
754 IN USB_INTERFACE
*HubIf
,
756 OUT EFI_USB_PORT_STATUS
*PortState
761 Status
= UsbHubCtrlGetPortStatus (HubIf
->Device
, Port
, PortState
);
769 Clear the port change status.
771 @param HubIf The hub interface.
772 @param Port The hub port.
778 UsbHubClearPortChange (
779 IN USB_INTERFACE
*HubIf
,
783 EFI_USB_PORT_STATUS PortState
;
784 USB_CHANGE_FEATURE_MAP
*Map
;
788 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
790 if (EFI_ERROR (Status
)) {
795 // OK, get the usb port status, now ACK the change bits.
796 // Don't return error when failed to clear the change bits.
797 // It may lead to extra port state report. USB bus should
798 // be able to handle this.
800 for (Index
= 0; Index
< USB_HUB_MAP_SIZE
; Index
++) {
801 Map
= &mHubFeatureMap
[Index
];
803 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
804 UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT16
) Map
->Feature
);
812 Function to set the port feature for non-root hub.
814 @param HubIf The hub interface.
815 @param Port The port of the hub.
816 @param Feature The feature of the port to set.
818 @retval EFI_SUCCESS The hub port feature is set.
819 @retval Others Failed to set the port feature.
823 UsbHubSetPortFeature (
824 IN USB_INTERFACE
*HubIf
,
826 IN EFI_USB_PORT_FEATURE Feature
831 Status
= UsbHubCtrlSetPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
838 Interface function to clear the port feature for non-root hub.
840 @param HubIf The hub interface.
841 @param Port The port of the hub to clear feature for.
842 @param Feature The feature to clear.
844 @retval EFI_SUCCESS The port feature is cleared.
845 @retval Others Failed to clear the port feature.
849 UsbHubClearPortFeature (
850 IN USB_INTERFACE
*HubIf
,
852 IN EFI_USB_PORT_FEATURE Feature
857 Status
= UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
864 Interface funtion to reset the port.
866 @param HubIf The hub interface.
867 @param Port The port to reset.
869 @retval EFI_SUCCESS The hub port is reset.
870 @retval EFI_TIMEOUT Failed to reset the port in time.
871 @retval Others Failed to reset the port.
876 IN USB_INTERFACE
*HubIf
,
880 EFI_USB_PORT_STATUS PortState
;
884 Status
= UsbHubSetPortFeature (HubIf
, Port
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_RESET
);
886 if (EFI_ERROR (Status
)) {
891 // Drive the reset signal for at least 10ms. Check USB 2.0 Spec
892 // section 7.1.7.5 for timing requirements.
894 gBS
->Stall (USB_SET_PORT_RESET_STALL
);
897 // USB hub will clear RESET bit if reset is actually finished.
899 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
901 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
902 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
904 if (!EFI_ERROR (Status
) &&
905 !USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
910 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
918 Release the hub's control of the interface.
920 @param HubIf The hub interface.
922 @retval EFI_SUCCESS The interface is release of hub control.
927 IN USB_INTERFACE
*HubIf
930 EFI_USB_IO_PROTOCOL
*UsbIo
;
933 UsbIo
= &HubIf
->UsbIo
;
934 Status
= UsbIo
->UsbAsyncInterruptTransfer (
936 HubIf
->HubEp
->Desc
.EndpointAddress
,
938 USB_HUB_POLL_INTERVAL
,
944 if (EFI_ERROR (Status
)) {
948 gBS
->CloseEvent (HubIf
->HubNotify
);
950 HubIf
->IsHub
= FALSE
;
951 HubIf
->HubApi
= NULL
;
953 HubIf
->HubNotify
= NULL
;
955 DEBUG (( EFI_D_INFO
, "UsbHubRelease: hub device %d released\n", HubIf
->Device
->Address
));
962 Initialize the interface for root hub.
964 @param HubIf The root hub interface.
966 @retval EFI_SUCCESS The interface is initialied for root hub.
967 @retval Others Failed to initialize the hub.
972 IN USB_INTERFACE
*HubIf
980 Status
= UsbHcGetCapability (HubIf
->Device
->Bus
, &MaxSpeed
, &NumOfPort
, &Support64
);
982 if (EFI_ERROR (Status
)) {
986 DEBUG (( EFI_D_INFO
, "UsbRootHubInit: root hub %x - max speed %d, %d ports\n",
987 HubIf
, MaxSpeed
, NumOfPort
));
990 HubIf
->HubApi
= &mUsbRootHubApi
;
992 HubIf
->MaxSpeed
= MaxSpeed
;
993 HubIf
->NumOfPort
= NumOfPort
;
994 HubIf
->HubNotify
= NULL
;
997 // Create a timer to poll root hub ports periodically
999 Status
= gBS
->CreateEvent (
1000 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1002 UsbRootHubEnumeration
,
1007 if (EFI_ERROR (Status
)) {
1012 // It should signal the event immediately here, or device detection
1013 // by bus enumeration might be delayed by the timer interval.
1015 gBS
->SignalEvent (HubIf
->HubNotify
);
1017 Status
= gBS
->SetTimer (
1020 USB_ROOTHUB_POLL_INTERVAL
1023 if (EFI_ERROR (Status
)) {
1024 gBS
->CloseEvent (HubIf
->HubNotify
);
1032 Get the port status. This function is required to
1033 ACK the port change bits although it will return
1034 the port changes in PortState. Bus enumeration code
1035 doesn't need to ACK the port change bits.
1037 @param HubIf The root hub interface.
1038 @param Port The root hub port to get the state.
1039 @param PortState Variable to return the port state.
1041 @retval EFI_SUCCESS The port state is returned.
1042 @retval Others Failed to retrieve the port state.
1046 UsbRootHubGetPortStatus (
1047 IN USB_INTERFACE
*HubIf
,
1049 OUT EFI_USB_PORT_STATUS
*PortState
1055 Bus
= HubIf
->Device
->Bus
;
1056 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, PortState
);
1063 Clear the port change status.
1065 @param HubIf The root hub interface.
1066 @param Port The root hub port.
1072 UsbRootHubClearPortChange (
1073 IN USB_INTERFACE
*HubIf
,
1077 EFI_USB_PORT_STATUS PortState
;
1078 USB_CHANGE_FEATURE_MAP
*Map
;
1082 Status
= UsbRootHubGetPortStatus (HubIf
, Port
, &PortState
);
1084 if (EFI_ERROR (Status
)) {
1089 // OK, get the usb port status, now ACK the change bits.
1090 // Don't return error when failed to clear the change bits.
1091 // It may lead to extra port state report. USB bus should
1092 // be able to handle this.
1094 for (Index
= 0; Index
< USB_ROOT_HUB_MAP_SIZE
; Index
++) {
1095 Map
= &mRootHubFeatureMap
[Index
];
1097 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
1098 UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, (EFI_USB_PORT_FEATURE
) Map
->Feature
);
1105 Set the root hub port feature.
1107 @param HubIf The Usb hub interface.
1108 @param Port The hub port.
1109 @param Feature The feature to set.
1111 @retval EFI_SUCCESS The root hub port is set with the feature.
1112 @retval Others Failed to set the feature.
1116 UsbRootHubSetPortFeature (
1117 IN USB_INTERFACE
*HubIf
,
1119 IN EFI_USB_PORT_FEATURE Feature
1124 Status
= UsbHcSetRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1131 Clear the root hub port feature.
1133 @param HubIf The root hub interface.
1134 @param Port The root hub port.
1135 @param Feature The feature to clear.
1137 @retval EFI_SUCCESS The root hub port is cleared of the feature.
1138 @retval Others Failed to clear the feature.
1142 UsbRootHubClearPortFeature (
1143 IN USB_INTERFACE
*HubIf
,
1145 IN EFI_USB_PORT_FEATURE Feature
1150 Status
= UsbHcClearRootHubPortFeature (HubIf
->Device
->Bus
, Port
, Feature
);
1157 Interface funtion to reset the root hub port.
1159 @param RootIf The root hub interface.
1160 @param Port The port to reset.
1162 @retval EFI_SUCCESS The hub port is reset.
1163 @retval EFI_TIMEOUT Failed to reset the port in time.
1164 @retval EFI_NOT_FOUND The low/full speed device connected to high speed.
1165 root hub is released to the companion UHCI.
1166 @retval Others Failed to reset the port.
1170 UsbRootHubResetPort (
1171 IN USB_INTERFACE
*RootIf
,
1177 EFI_USB_PORT_STATUS PortState
;
1181 // Notice: although EHCI requires that ENABLED bit be cleared
1182 // when reset the port, we don't need to care that here. It
1183 // should be handled in the EHCI driver.
1185 Bus
= RootIf
->Device
->Bus
;
1186 Status
= UsbHcSetRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1188 if (EFI_ERROR (Status
)) {
1189 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: failed to start reset on port %d\n", Port
));
1194 // Drive the reset signal for at least 50ms. Check USB 2.0 Spec
1195 // section 7.1.7.5 for timing requirements.
1197 gBS
->Stall (USB_SET_ROOT_PORT_RESET_STALL
);
1199 Status
= UsbHcClearRootHubPortFeature (Bus
, Port
, EfiUsbPortReset
);
1201 if (EFI_ERROR (Status
)) {
1202 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: failed to clear reset on port %d\n", Port
));
1206 gBS
->Stall (USB_CLR_ROOT_PORT_RESET_STALL
);
1209 // USB host controller won't clear the RESET bit until
1210 // reset is actually finished.
1212 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
1214 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
1215 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, &PortState
);
1217 if (EFI_ERROR (Status
)) {
1221 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
1225 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
1228 if (Index
== USB_WAIT_PORT_STS_CHANGE_LOOP
) {
1229 DEBUG ((EFI_D_ERROR
, "UsbRootHubResetPort: reset not finished in time on port %d\n", Port
));
1233 if (!USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_ENABLE
)) {
1235 // OK, the port is reset. If root hub is of high speed and
1236 // the device is of low/full speed, release the ownership to
1237 // companion UHCI. If root hub is of full speed, it won't
1238 // automatically enable the port, we need to enable it manually.
1240 if (RootIf
->MaxSpeed
== EFI_USB_SPEED_HIGH
) {
1241 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: release low/full speed device (%d) to UHCI\n", Port
));
1243 UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortOwner
);
1244 return EFI_NOT_FOUND
;
1248 Status
= UsbRootHubSetPortFeature (RootIf
, Port
, EfiUsbPortEnable
);
1250 if (EFI_ERROR (Status
)) {
1251 DEBUG (( EFI_D_ERROR
, "UsbRootHubResetPort: failed to enable port %d for UHCI\n", Port
));
1255 gBS
->Stall (USB_SET_ROOT_PORT_ENABLE_STALL
);
1264 Release the root hub's control of the interface.
1266 @param HubIf The root hub interface.
1268 @retval EFI_SUCCESS The root hub's control of the interface is
1274 IN USB_INTERFACE
*HubIf
1277 DEBUG (( EFI_D_INFO
, "UsbRootHubRelease: root hub released for hub %x\n", HubIf
));
1279 gBS
->SetTimer (HubIf
->HubNotify
, TimerCancel
, USB_ROOTHUB_POLL_INTERVAL
);
1280 gBS
->CloseEvent (HubIf
->HubNotify
);
1285 USB_HUB_API mUsbHubApi
= {
1287 UsbHubGetPortStatus
,
1288 UsbHubClearPortChange
,
1289 UsbHubSetPortFeature
,
1290 UsbHubClearPortFeature
,
1295 USB_HUB_API mUsbRootHubApi
= {
1297 UsbRootHubGetPortStatus
,
1298 UsbRootHubClearPortChange
,
1299 UsbRootHubSetPortFeature
,
1300 UsbRootHubClearPortFeature
,
1301 UsbRootHubResetPort
,