3 Unified interface for RootHub and Hub.
5 Copyright (c) 2007 - 2009, 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 #define USB_HUB_MAP_SIZE 5
27 USB_CHANGE_FEATURE_MAP mHubFeatureMap
[USB_HUB_MAP_SIZE
] = {
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
},
35 #define USB_ROOT_HUB_MAP_SIZE 5
37 USB_CHANGE_FEATURE_MAP mRootHubFeatureMap
[USB_ROOT_HUB_MAP_SIZE
] = {
38 {USB_PORT_STAT_C_CONNECTION
, EfiUsbPortConnectChange
},
39 {USB_PORT_STAT_C_ENABLE
, EfiUsbPortEnableChange
},
40 {USB_PORT_STAT_C_SUSPEND
, EfiUsbPortSuspendChange
},
41 {USB_PORT_STAT_C_OVERCURRENT
, EfiUsbPortOverCurrentChange
},
42 {USB_PORT_STAT_C_RESET
, EfiUsbPortResetChange
},
46 // USB hub class specific requests. Although USB hub
47 // is related to an interface, these requests are sent
48 // to the control endpoint of the device.
53 USB hub control transfer to clear the hub feature.
55 @param HubDev The device of the hub.
56 @param Feature The feature to clear.
58 @retval EFI_SUCCESS Feature of the hub is cleared.
59 @retval Others Failed to clear the feature.
63 UsbHubCtrlClearHubFeature (
64 IN USB_DEVICE
*HubDev
,
70 Status
= UsbCtrlRequest (
75 USB_HUB_REQ_CLEAR_FEATURE
,
87 Clear the feature of the device's port.
89 @param HubDev The hub device.
90 @param Port The port to clear feature.
91 @param Feature The feature to clear.
93 @retval EFI_SUCCESS The feature of the port is cleared.
94 @retval Others Failed to clear the feature.
98 UsbHubCtrlClearPortFeature (
99 IN USB_DEVICE
*HubDev
,
107 // In USB bus, all the port index starts from 0. But HUB
108 // indexes its port from 1. So, port number is added one.
110 Status
= UsbCtrlRequest (
115 USB_HUB_REQ_CLEAR_FEATURE
,
127 Clear the transaction translate buffer if full/low
128 speed control/bulk transfer failed and the transfer
129 uses this hub as translator.Remember to clear the TT
130 buffer of transaction translator, not that of the
133 @param HubDev The hub device.
134 @param Port The port of the hub.
135 @param DevAddr Address of the failed transaction.
136 @param EpNum The endpoint number of the failed transaction.
137 @param EpType The type of failed transaction.
139 @retval EFI_SUCCESS The TT buffer is cleared.
140 @retval Others Failed to clear the TT buffer.
144 UsbHubCtrlClearTTBuffer (
145 IN USB_DEVICE
*HubDev
,
156 // Check USB2.0 spec page 424 for wValue's encoding
158 Value
= (UINT16
) ((EpNum
& 0x0F) | (DevAddr
<< 4) |
159 ((EpType
& 0x03) << 11) | ((EpNum
& 0x80) << 15));
161 Status
= UsbCtrlRequest (
166 USB_HUB_REQ_CLEAR_TT
,
178 Usb hub control transfer to get the hub descriptor.
180 @param HubDev The hub device.
181 @param Buf The buffer to hold the descriptor.
182 @param Len The length to retrieve.
184 @retval EFI_SUCCESS The hub descriptor is retrieved.
185 @retval Others Failed to retrieve the hub descriptor.
189 UsbHubCtrlGetHubDesc (
190 IN USB_DEVICE
*HubDev
,
197 Status
= UsbCtrlRequest (
202 USB_HUB_REQ_GET_DESC
,
203 (UINT16
) (USB_DESC_TYPE_HUB
<< 8),
214 Usb hub control transfer to get the hub status.
216 @param HubDev The hub device.
217 @param State The variable to return the status.
219 @retval EFI_SUCCESS The hub status is returned in State.
220 @retval Others Failed to get the hub status.
224 UsbHubCtrlGetHubStatus (
225 IN USB_DEVICE
*HubDev
,
231 Status
= UsbCtrlRequest (
236 USB_HUB_REQ_GET_STATUS
,
248 Usb hub control transfer to get the port status.
250 @param HubDev The hub device.
251 @param Port The port of the hub.
252 @param State Variable to return the hub port state.
254 @retval EFI_SUCCESS The port state is returned in State.
255 @retval Others Failed to retrieve the port state.
259 UsbHubCtrlGetPortStatus (
260 IN USB_DEVICE
*HubDev
,
268 // In USB bus, all the port index starts from 0. But HUB
269 // indexes its port from 1. So, port number is added one.
270 // No need to convert the hub bit to UEFI definition, they
273 Status
= UsbCtrlRequest (
278 USB_HUB_REQ_GET_STATUS
,
290 Usb hub control transfer to reset the TT (Transaction Transaltor).
292 @param HubDev The hub device.
293 @param Port The port of the hub.
295 @retval EFI_SUCCESS The TT of the hub is reset.
296 @retval Others Failed to reset the port.
301 IN USB_DEVICE
*HubDev
,
307 Status
= UsbCtrlRequest (
312 USB_HUB_REQ_RESET_TT
,
324 Usb hub control transfer to set the hub feature.
326 @param HubDev The hub device.
327 @param Feature The feature to set.
329 @retval EFI_SUCESS The feature is set for the hub.
330 @retval Others Failed to set the feature.
334 UsbHubCtrlSetHubFeature (
335 IN USB_DEVICE
*HubDev
,
341 Status
= UsbCtrlRequest (
346 USB_HUB_REQ_SET_FEATURE
,
358 Usb hub control transfer to set the port feature.
360 @param HubDev The Usb hub device.
361 @param Port The Usb port to set feature for.
362 @param Feature The feature to set.
364 @retval EFI_SUCCESS The feature is set for the port.
365 @retval Others Failed to set the feature.
369 UsbHubCtrlSetPortFeature (
370 IN USB_DEVICE
*HubDev
,
378 // In USB bus, all the port index starts from 0. But HUB
379 // indexes its port from 1. So, port number is added one.
381 Status
= UsbCtrlRequest (
386 USB_HUB_REQ_SET_FEATURE
,
398 Read the whole usb hub descriptor. It is necessary
399 to do it in two steps because hub descriptor is of
402 @param HubDev The hub device.
403 @param HubDesc The variable to return the descriptor.
405 @retval EFI_SUCCESS The hub descriptor is read.
406 @retval Others Failed to read the hub descriptor.
411 IN USB_DEVICE
*HubDev
,
412 OUT EFI_USB_HUB_DESCRIPTOR
*HubDesc
418 // First get the hub descriptor length
420 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, 2);
422 if (EFI_ERROR (Status
)) {
427 // Get the whole hub descriptor
429 Status
= UsbHubCtrlGetHubDesc (HubDev
, HubDesc
, HubDesc
->Length
);
437 Ack the hub change bits. If these bits are not ACKed, Hub will
438 always return changed bit map from its interrupt endpoint.
440 @param HubDev The hub device.
442 @retval EFI_SUCCESS The hub change status is ACKed.
443 @retval Others Failed to ACK the hub status.
448 IN USB_DEVICE
*HubDev
451 EFI_USB_PORT_STATUS HubState
;
454 Status
= UsbHubCtrlGetHubStatus (HubDev
, (UINT32
*) &HubState
);
456 if (EFI_ERROR (Status
)) {
460 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_LOCAL_POWER
)) {
461 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_LOCAL_POWER
);
464 if (USB_BIT_IS_SET (HubState
.PortChangeStatus
, USB_HUB_STAT_C_OVER_CURRENT
)) {
465 UsbHubCtrlClearHubFeature (HubDev
, USB_HUB_C_HUB_OVER_CURRENT
);
473 Test whether the interface is a hub interface.
475 @param UsbIf The interface to test.
477 @retval TRUE The interface is a hub interface.
478 @retval FALSE The interface isn't a hub interface.
483 IN USB_INTERFACE
*UsbIf
486 EFI_USB_INTERFACE_DESCRIPTOR
*Setting
;
489 // If the hub is a high-speed hub with multiple TT,
490 // the hub will has a default setting of single TT.
492 Setting
= &UsbIf
->IfSetting
->Desc
;
494 if ((Setting
->InterfaceClass
== USB_HUB_CLASS_CODE
) &&
495 (Setting
->InterfaceSubClass
== USB_HUB_SUBCLASS_CODE
)) {
505 The callback function to the USB hub status change
506 interrupt endpoint. It is called periodically by
507 the underlying host controller.
509 @param Data The data read.
510 @param DataLength The length of the data read.
511 @param Context The context.
512 @param Result The result of the last interrupt transfer.
514 @retval EFI_SUCCESS The process is OK.
515 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
527 USB_INTERFACE
*HubIf
;
528 EFI_USB_IO_PROTOCOL
*UsbIo
;
529 EFI_USB_ENDPOINT_DESCRIPTOR
*EpDesc
;
532 HubIf
= (USB_INTERFACE
*) Context
;
533 UsbIo
= &(HubIf
->UsbIo
);
534 EpDesc
= &(HubIf
->HubEp
->Desc
);
536 if (Result
!= EFI_USB_NOERROR
) {
538 // If endpoint is stalled, clear the stall. Use UsbIo to access
539 // the control transfer so internal status are maintained.
541 if (USB_BIT_IS_SET (Result
, EFI_USB_ERR_STALL
)) {
545 USB_FEATURE_ENDPOINT_HALT
,
546 EpDesc
->EndpointAddress
551 // Delete and submit a new async interrupt
553 Status
= UsbIo
->UsbAsyncInterruptTransfer (
555 EpDesc
->EndpointAddress
,
563 if (EFI_ERROR (Status
)) {
564 DEBUG (( EFI_D_ERROR
, "UsbOnHubInterrupt: failed to remove async transfer - %r\n", Status
));
568 Status
= UsbIo
->UsbAsyncInterruptTransfer (
570 EpDesc
->EndpointAddress
,
572 USB_HUB_POLL_INTERVAL
,
573 HubIf
->NumOfPort
/ 8 + 1,
578 if (EFI_ERROR (Status
)) {
579 DEBUG (( EFI_D_ERROR
, "UsbOnHubInterrupt: failed to submit new async transfer - %r\n", Status
));
585 if ((DataLength
== 0) || (Data
== NULL
)) {
590 // OK, actually something is changed, save the change map
591 // then signal the HUB to do enumeration. This is a good
592 // practise since UsbOnHubInterrupt is called in the context
593 // of host contrller's AsyncInterrupt monitor.
595 HubIf
->ChangeMap
= AllocateZeroPool (DataLength
);
597 if (HubIf
->ChangeMap
== NULL
) {
598 return EFI_OUT_OF_RESOURCES
;
601 CopyMem (HubIf
->ChangeMap
, Data
, DataLength
);
602 gBS
->SignalEvent (HubIf
->HubNotify
);
611 Initialize the device for a non-root hub.
613 @param HubIf The USB hub interface.
615 @retval EFI_SUCCESS The hub is initialized.
616 @retval EFI_DEVICE_ERROR Failed to initialize the hub.
621 IN USB_INTERFACE
*HubIf
624 EFI_USB_HUB_DESCRIPTOR HubDesc
;
625 USB_ENDPOINT_DESC
*EpDesc
;
626 USB_INTERFACE_SETTING
*Setting
;
627 EFI_USB_IO_PROTOCOL
*UsbIo
;
634 // Locate the interrupt endpoint for port change map
636 HubIf
->IsHub
= FALSE
;
637 Setting
= HubIf
->IfSetting
;
638 HubDev
= HubIf
->Device
;
640 NumEndpoints
= Setting
->Desc
.NumEndpoints
;
642 for (Index
= 0; Index
< NumEndpoints
; Index
++) {
643 ASSERT ((Setting
->Endpoints
!= NULL
) && (Setting
->Endpoints
[Index
] != NULL
));
645 EpDesc
= Setting
->Endpoints
[Index
];
647 if (USB_BIT_IS_SET (EpDesc
->Desc
.EndpointAddress
, USB_ENDPOINT_DIR_IN
) &&
648 (USB_ENDPOINT_TYPE (&EpDesc
->Desc
) == USB_ENDPOINT_INTERRUPT
)) {
653 if (Index
== NumEndpoints
) {
654 DEBUG (( EFI_D_ERROR
, "UsbHubInit: no interrupt endpoint found for hub %d\n", HubDev
->Address
));
655 return EFI_DEVICE_ERROR
;
658 Status
= UsbHubReadDesc (HubDev
, &HubDesc
);
660 if (EFI_ERROR (Status
)) {
661 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to read HUB descriptor %r\n", Status
));
665 HubIf
->NumOfPort
= HubDesc
.NumPorts
;
667 DEBUG (( EFI_D_INFO
, "UsbHubInit: hub %d has %d ports\n", HubDev
->Address
,HubIf
->NumOfPort
));
670 // Create an event to enumerate the hub's port. On
672 Status
= gBS
->CreateEvent (
680 if (EFI_ERROR (Status
)) {
681 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to create signal for hub %d - %r\n",
682 HubDev
->Address
, Status
));
688 // Create AsyncInterrupt to query hub port change endpoint
689 // periodically. If the hub ports are changed, hub will return
690 // changed port map from the interrupt endpoint. The port map
691 // must be able to hold (HubIf->NumOfPort + 1) bits (one bit for
692 // host change status).
694 UsbIo
= &HubIf
->UsbIo
;
695 Status
= UsbIo
->UsbAsyncInterruptTransfer (
697 EpDesc
->Desc
.EndpointAddress
,
699 USB_HUB_POLL_INTERVAL
,
700 HubIf
->NumOfPort
/ 8 + 1,
705 if (EFI_ERROR (Status
)) {
706 DEBUG (( EFI_D_ERROR
, "UsbHubInit: failed to queue interrupt transfer for hub %d - %r\n",
707 HubDev
->Address
, Status
));
709 gBS
->CloseEvent (HubIf
->HubNotify
);
710 HubIf
->HubNotify
= NULL
;
716 // OK, set IsHub to TRUE. Now usb bus can handle this device
717 // as a working HUB. If failed eariler, bus driver will not
718 // recognize it as a hub. Other parts of the bus should be able
722 HubIf
->HubApi
= &mUsbHubApi
;
723 HubIf
->HubEp
= EpDesc
;
726 // Feed power to all the hub ports. It should be ok
727 // for both gang/individual powered hubs.
729 for (Index
= 0; Index
< HubDesc
.NumPorts
; Index
++) {
730 UsbHubCtrlSetPortFeature (HubIf
->Device
, Index
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_POWER
);
733 gBS
->Stall (HubDesc
.PwrOn2PwrGood
* USB_SET_PORT_POWER_STALL
);
734 UsbHubAckHubStatus (HubIf
->Device
);
736 DEBUG (( EFI_D_INFO
, "UsbHubInit: hub %d initialized\n", HubDev
->Address
));
743 Get the port status. This function is required to
744 ACK the port change bits although it will return
745 the port changes in PortState. Bus enumeration code
746 doesn't need to ACK the port change bits.
748 @param HubIf The hub interface.
749 @param Port The port of the hub to get state.
750 @param PortState Variable to return the port state.
752 @retval EFI_SUCCESS The port status is successfully returned.
753 @retval Others Failed to return the status.
757 UsbHubGetPortStatus (
758 IN USB_INTERFACE
*HubIf
,
760 OUT EFI_USB_PORT_STATUS
*PortState
765 Status
= UsbHubCtrlGetPortStatus (HubIf
->Device
, Port
, PortState
);
773 Clear the port change status.
775 @param HubIf The hub interface.
776 @param Port The hub port.
780 UsbHubClearPortChange (
781 IN USB_INTERFACE
*HubIf
,
785 EFI_USB_PORT_STATUS PortState
;
786 USB_CHANGE_FEATURE_MAP
*Map
;
790 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
792 if (EFI_ERROR (Status
)) {
797 // OK, get the usb port status, now ACK the change bits.
798 // Don't return error when failed to clear the change bits.
799 // It may lead to extra port state report. USB bus should
800 // be able to handle this.
802 for (Index
= 0; Index
< USB_HUB_MAP_SIZE
; Index
++) {
803 Map
= &mHubFeatureMap
[Index
];
805 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, Map
->ChangedBit
)) {
806 UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT16
) Map
->Feature
);
814 Function to set the port feature for non-root hub.
816 @param HubIf The hub interface.
817 @param Port The port of the hub.
818 @param Feature The feature of the port to set.
820 @retval EFI_SUCCESS The hub port feature is set.
821 @retval Others Failed to set the port feature.
825 UsbHubSetPortFeature (
826 IN USB_INTERFACE
*HubIf
,
828 IN EFI_USB_PORT_FEATURE Feature
833 Status
= UsbHubCtrlSetPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
840 Interface function to clear the port feature for non-root hub.
842 @param HubIf The hub interface.
843 @param Port The port of the hub to clear feature for.
844 @param Feature The feature to clear.
846 @retval EFI_SUCCESS The port feature is cleared.
847 @retval Others Failed to clear the port feature.
851 UsbHubClearPortFeature (
852 IN USB_INTERFACE
*HubIf
,
854 IN EFI_USB_PORT_FEATURE Feature
859 Status
= UsbHubCtrlClearPortFeature (HubIf
->Device
, Port
, (UINT8
) Feature
);
866 Interface function to reset the port.
868 @param HubIf The hub interface.
869 @param Port The port to reset.
871 @retval EFI_SUCCESS The hub port is reset.
872 @retval EFI_TIMEOUT Failed to reset the port in time.
873 @retval Others Failed to reset the port.
878 IN USB_INTERFACE
*HubIf
,
882 EFI_USB_PORT_STATUS PortState
;
886 Status
= UsbHubSetPortFeature (HubIf
, Port
, (EFI_USB_PORT_FEATURE
) USB_HUB_PORT_RESET
);
888 if (EFI_ERROR (Status
)) {
893 // Drive the reset signal for at least 10ms. Check USB 2.0 Spec
894 // section 7.1.7.5 for timing requirements.
896 gBS
->Stall (USB_SET_PORT_RESET_STALL
);
899 // USB hub will clear RESET bit if reset is actually finished.
901 ZeroMem (&PortState
, sizeof (EFI_USB_PORT_STATUS
));
903 for (Index
= 0; Index
< USB_WAIT_PORT_STS_CHANGE_LOOP
; Index
++) {
904 Status
= UsbHubGetPortStatus (HubIf
, Port
, &PortState
);
906 if (!EFI_ERROR (Status
) &&
907 !USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_RESET
)) {
912 gBS
->Stall (USB_WAIT_PORT_STS_CHANGE_STALL
);
920 Release the hub's control of the interface.
922 @param HubIf The hub interface.
924 @retval EFI_SUCCESS The interface is release of hub control.
929 IN USB_INTERFACE
*HubIf
932 EFI_USB_IO_PROTOCOL
*UsbIo
;
935 UsbIo
= &HubIf
->UsbIo
;
936 Status
= UsbIo
->UsbAsyncInterruptTransfer (
938 HubIf
->HubEp
->Desc
.EndpointAddress
,
940 USB_HUB_POLL_INTERVAL
,
946 if (EFI_ERROR (Status
)) {
950 gBS
->CloseEvent (HubIf
->HubNotify
);
952 HubIf
->IsHub
= FALSE
;
953 HubIf
->HubApi
= NULL
;
955 HubIf
->HubNotify
= NULL
;
957 DEBUG (( EFI_D_INFO
, "UsbHubRelease: hub device %d released\n", HubIf
->Device
->Address
));
964 Initialize the interface for root hub.
966 @param HubIf The root hub interface.
968 @retval EFI_SUCCESS The interface is initialized for root hub.
969 @retval Others Failed to initialize the hub.
974 IN USB_INTERFACE
*HubIf
982 Status
= UsbHcGetCapability (HubIf
->Device
->Bus
, &MaxSpeed
, &NumOfPort
, &Support64
);
984 if (EFI_ERROR (Status
)) {
988 DEBUG (( EFI_D_INFO
, "UsbRootHubInit: root hub %p - max speed %d, %d ports\n",
989 HubIf
, MaxSpeed
, NumOfPort
));
992 HubIf
->HubApi
= &mUsbRootHubApi
;
994 HubIf
->MaxSpeed
= MaxSpeed
;
995 HubIf
->NumOfPort
= NumOfPort
;
996 HubIf
->HubNotify
= NULL
;
999 // Create a timer to poll root hub ports periodically
1001 Status
= gBS
->CreateEvent (
1002 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1004 UsbRootHubEnumeration
,
1009 if (EFI_ERROR (Status
)) {
1014 // It should signal the event immediately here, or device detection
1015 // by bus enumeration might be delayed by the timer interval.
1017 gBS
->SignalEvent (HubIf
->HubNotify
);
1019 Status
= gBS
->SetTimer (
1022 USB_ROOTHUB_POLL_INTERVAL
1025 if (EFI_ERROR (Status
)) {
1026 gBS
->CloseEvent (HubIf
->HubNotify
);
1034 Get the port status. This function is required to
1035 ACK the port change bits although it will return
1036 the port changes in PortState. Bus enumeration code
1037 doesn't need to ACK the port change bits.
1039 @param HubIf The root hub interface.
1040 @param Port The root hub port to get the state.
1041 @param PortState Variable to return the port state.
1043 @retval EFI_SUCCESS The port state is returned.
1044 @retval Others Failed to retrieve the port state.
1048 UsbRootHubGetPortStatus (
1049 IN USB_INTERFACE
*HubIf
,
1051 OUT EFI_USB_PORT_STATUS
*PortState
1057 Bus
= HubIf
->Device
->Bus
;
1058 Status
= UsbHcGetRootHubPortStatus (Bus
, Port
, PortState
);
1065 Clear the port change status.
1067 @param HubIf The root hub interface.
1068 @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 function 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 %p\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
,