3 The Ehci controller driver.
5 Copyright (c) 2006 - 2009, 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.
20 // Two arrays used to translate the EHCI port state (change)
21 // to the UEFI protocol's port state (change).
23 USB_PORT_STATE_MAP mUsbPortStateMap
[] = {
24 {PORTSC_CONN
, USB_PORT_STAT_CONNECTION
},
25 {PORTSC_ENABLED
, USB_PORT_STAT_ENABLE
},
26 {PORTSC_SUSPEND
, USB_PORT_STAT_SUSPEND
},
27 {PORTSC_OVERCUR
, USB_PORT_STAT_OVERCURRENT
},
28 {PORTSC_RESET
, USB_PORT_STAT_RESET
},
29 {PORTSC_POWER
, USB_PORT_STAT_POWER
},
30 {PORTSC_OWNER
, USB_PORT_STAT_OWNER
}
33 USB_PORT_STATE_MAP mUsbPortChangeMap
[] = {
34 {PORTSC_CONN_CHANGE
, USB_PORT_STAT_C_CONNECTION
},
35 {PORTSC_ENABLE_CHANGE
, USB_PORT_STAT_C_ENABLE
},
36 {PORTSC_OVERCUR_CHANGE
, USB_PORT_STAT_C_OVERCURRENT
}
39 EFI_DRIVER_BINDING_PROTOCOL
40 gEhciDriverBinding
= {
41 EhcDriverBindingSupported
,
42 EhcDriverBindingStart
,
50 /// USB host controller Programming Interface.
52 #define PCI_CLASSC_PI_UHCI 0x00
53 #define PCI_CLASSC_PI_EHCI 0x20
56 Retrieves the capability of root hub ports.
58 @param This This EFI_USB_HC_PROTOCOL instance.
59 @param MaxSpeed Max speed supported by the controller.
60 @param PortNumber Number of the root hub ports.
61 @param Is64BitCapable Whether the controller supports 64-bit memory
64 @retval EFI_SUCCESS Host controller capability were retrieved successfully.
65 @retval EFI_INVALID_PARAMETER Either of the three capability pointer is NULL.
71 IN EFI_USB2_HC_PROTOCOL
*This
,
73 OUT UINT8
*PortNumber
,
74 OUT UINT8
*Is64BitCapable
80 if ((MaxSpeed
== NULL
) || (PortNumber
== NULL
) || (Is64BitCapable
== NULL
)) {
81 return EFI_INVALID_PARAMETER
;
84 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
85 Ehc
= EHC_FROM_THIS (This
);
87 *MaxSpeed
= EFI_USB_SPEED_HIGH
;
88 *PortNumber
= (UINT8
) (Ehc
->HcStructParams
& HCSP_NPORTS
);
89 *Is64BitCapable
= (UINT8
) (Ehc
->HcCapParams
& HCCP_64BIT
);
91 DEBUG ((EFI_D_INFO
, "EhcGetCapability: %d ports, 64 bit %d\n", *PortNumber
, *Is64BitCapable
));
93 gBS
->RestoreTPL (OldTpl
);
99 Provides software reset for the USB host controller.
101 @param This This EFI_USB2_HC_PROTOCOL instance.
102 @param Attributes A bit mask of the reset operation to perform.
104 @retval EFI_SUCCESS The reset operation succeeded.
105 @retval EFI_INVALID_PARAMETER Attributes is not valid.
106 @retval EFI_UNSUPPOURTED The type of reset specified by Attributes is
107 not currently supported by the host controller.
108 @retval EFI_DEVICE_ERROR Host controller isn't halted to reset.
114 IN EFI_USB2_HC_PROTOCOL
*This
,
122 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
123 Ehc
= EHC_FROM_THIS (This
);
125 switch (Attributes
) {
126 case EFI_USB_HC_RESET_GLOBAL
:
128 // Flow through, same behavior as Host Controller Reset
130 case EFI_USB_HC_RESET_HOST_CONTROLLER
:
132 // Host Controller must be Halt when Reset it
134 if (!EhcIsHalt (Ehc
)) {
135 Status
= EhcHaltHC (Ehc
, EHC_GENERIC_TIMEOUT
);
137 if (EFI_ERROR (Status
)) {
138 Status
= EFI_DEVICE_ERROR
;
144 // Clean up the asynchronous transfers, currently only
145 // interrupt supports asynchronous operation.
147 EhciDelAllAsyncIntTransfers (Ehc
);
148 EhcAckAllInterrupt (Ehc
);
151 Status
= EhcResetHC (Ehc
, EHC_RESET_TIMEOUT
);
153 if (EFI_ERROR (Status
)) {
157 Status
= EhcInitHC (Ehc
);
160 case EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG
:
161 case EFI_USB_HC_RESET_HOST_WITH_DEBUG
:
162 Status
= EFI_UNSUPPORTED
;
166 Status
= EFI_INVALID_PARAMETER
;
170 DEBUG ((EFI_D_INFO
, "EhcReset: exit status %r\n", Status
));
171 gBS
->RestoreTPL (OldTpl
);
177 Retrieve the current state of the USB host controller.
179 @param This This EFI_USB2_HC_PROTOCOL instance.
180 @param State Variable to return the current host controller
183 @retval EFI_SUCCESS Host controller state was returned in State.
184 @retval EFI_INVALID_PARAMETER State is NULL.
185 @retval EFI_DEVICE_ERROR An error was encountered while attempting to
186 retrieve the host controller's current state.
192 IN CONST EFI_USB2_HC_PROTOCOL
*This
,
193 OUT EFI_USB_HC_STATE
*State
200 return EFI_INVALID_PARAMETER
;
203 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
204 Ehc
= EHC_FROM_THIS (This
);
206 if (EHC_REG_BIT_IS_SET (Ehc
, EHC_USBSTS_OFFSET
, USBSTS_HALT
)) {
207 *State
= EfiUsbHcStateHalt
;
209 *State
= EfiUsbHcStateOperational
;
212 gBS
->RestoreTPL (OldTpl
);
214 DEBUG ((EFI_D_INFO
, "EhcGetState: current state %d\n", *State
));
220 Sets the USB host controller to a specific state.
222 @param This This EFI_USB2_HC_PROTOCOL instance.
223 @param State The state of the host controller that will be set.
225 @retval EFI_SUCCESS The USB host controller was successfully placed
226 in the state specified by State.
227 @retval EFI_INVALID_PARAMETER State is invalid.
228 @retval EFI_DEVICE_ERROR Failed to set the state due to device error.
234 IN EFI_USB2_HC_PROTOCOL
*This
,
235 IN EFI_USB_HC_STATE State
241 EFI_USB_HC_STATE CurState
;
243 Status
= EhcGetState (This
, &CurState
);
245 if (EFI_ERROR (Status
)) {
246 return EFI_DEVICE_ERROR
;
249 if (CurState
== State
) {
253 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
254 Ehc
= EHC_FROM_THIS (This
);
257 case EfiUsbHcStateHalt
:
258 Status
= EhcHaltHC (Ehc
, EHC_GENERIC_TIMEOUT
);
261 case EfiUsbHcStateOperational
:
262 if (EHC_REG_BIT_IS_SET (Ehc
, EHC_USBSTS_OFFSET
, USBSTS_SYS_ERROR
)) {
263 Status
= EFI_DEVICE_ERROR
;
268 // Software must not write a one to this field unless the host controller
269 // is in the Halted state. Doing so will yield undefined results.
270 // refers to Spec[EHCI1.0-2.3.1]
272 if (!EHC_REG_BIT_IS_SET (Ehc
, EHC_USBSTS_OFFSET
, USBSTS_HALT
)) {
273 Status
= EFI_DEVICE_ERROR
;
277 Status
= EhcRunHC (Ehc
, EHC_GENERIC_TIMEOUT
);
280 case EfiUsbHcStateSuspend
:
281 Status
= EFI_UNSUPPORTED
;
285 Status
= EFI_INVALID_PARAMETER
;
288 DEBUG ((EFI_D_INFO
, "EhcSetState: exit status %r\n", Status
));
289 gBS
->RestoreTPL (OldTpl
);
295 Retrieves the current status of a USB root hub port.
297 @param This This EFI_USB2_HC_PROTOCOL instance.
298 @param PortNumber The root hub port to retrieve the state from.
299 This value is zero-based.
300 @param PortStatus Variable to receive the port state.
302 @retval EFI_SUCCESS The status of the USB root hub port specified.
303 by PortNumber was returned in PortStatus.
304 @retval EFI_INVALID_PARAMETER PortNumber is invalid.
305 @retval EFI_DEVICE_ERROR Can't read register.
310 EhcGetRootHubPortStatus (
311 IN CONST EFI_USB2_HC_PROTOCOL
*This
,
312 IN CONST UINT8 PortNumber
,
313 OUT EFI_USB_PORT_STATUS
*PortStatus
325 if (PortStatus
== NULL
) {
326 return EFI_INVALID_PARAMETER
;
329 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
331 Ehc
= EHC_FROM_THIS (This
);
332 Status
= EFI_SUCCESS
;
334 TotalPort
= (Ehc
->HcStructParams
& HCSP_NPORTS
);
336 if (PortNumber
>= TotalPort
) {
337 Status
= EFI_INVALID_PARAMETER
;
341 Offset
= (UINT32
) (EHC_PORT_STAT_OFFSET
+ (4 * PortNumber
));
342 PortStatus
->PortStatus
= 0;
343 PortStatus
->PortChangeStatus
= 0;
345 State
= EhcReadOpReg (Ehc
, Offset
);
348 // Identify device speed. If in K state, it is low speed.
349 // If the port is enabled after reset, the device is of
350 // high speed. The USB bus driver should retrieve the actual
351 // port speed after reset.
353 if (EHC_BIT_IS_SET (State
, PORTSC_LINESTATE_K
)) {
354 PortStatus
->PortStatus
|= USB_PORT_STAT_LOW_SPEED
;
356 } else if (EHC_BIT_IS_SET (State
, PORTSC_ENABLED
)) {
357 PortStatus
->PortStatus
|= USB_PORT_STAT_HIGH_SPEED
;
361 // Convert the EHCI port/port change state to UEFI status
363 MapSize
= sizeof (mUsbPortStateMap
) / sizeof (USB_PORT_STATE_MAP
);
365 for (Index
= 0; Index
< MapSize
; Index
++) {
366 if (EHC_BIT_IS_SET (State
, mUsbPortStateMap
[Index
].HwState
)) {
367 PortStatus
->PortStatus
= (UINT16
) (PortStatus
->PortStatus
| mUsbPortStateMap
[Index
].UefiState
);
371 MapSize
= sizeof (mUsbPortChangeMap
) / sizeof (USB_PORT_STATE_MAP
);
373 for (Index
= 0; Index
< MapSize
; Index
++) {
374 if (EHC_BIT_IS_SET (State
, mUsbPortChangeMap
[Index
].HwState
)) {
375 PortStatus
->PortChangeStatus
= (UINT16
) (PortStatus
->PortChangeStatus
| mUsbPortChangeMap
[Index
].UefiState
);
380 gBS
->RestoreTPL (OldTpl
);
386 Sets a feature for the specified root hub port.
388 @param This This EFI_USB2_HC_PROTOCOL instance.
389 @param PortNumber Root hub port to set.
390 @param PortFeature Feature to set.
392 @retval EFI_SUCCESS The feature specified by PortFeature was set.
393 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
394 @retval EFI_DEVICE_ERROR Can't read register.
399 EhcSetRootHubPortFeature (
400 IN EFI_USB2_HC_PROTOCOL
*This
,
402 IN EFI_USB_PORT_FEATURE PortFeature
412 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
413 Ehc
= EHC_FROM_THIS (This
);
414 Status
= EFI_SUCCESS
;
416 TotalPort
= (Ehc
->HcStructParams
& HCSP_NPORTS
);
418 if (PortNumber
>= TotalPort
) {
419 Status
= EFI_INVALID_PARAMETER
;
423 Offset
= (UINT32
) (EHC_PORT_STAT_OFFSET
+ (4 * PortNumber
));
424 State
= EhcReadOpReg (Ehc
, Offset
);
427 // Mask off the port status change bits, these bits are
430 State
&= ~PORTSC_CHANGE_MASK
;
432 switch (PortFeature
) {
433 case EfiUsbPortEnable
:
435 // Sofeware can't set this bit, Port can only be enable by
436 // EHCI as a part of the reset and enable
438 State
|= PORTSC_ENABLED
;
439 EhcWriteOpReg (Ehc
, Offset
, State
);
442 case EfiUsbPortSuspend
:
443 State
|= PORTSC_SUSPEND
;
444 EhcWriteOpReg (Ehc
, Offset
, State
);
447 case EfiUsbPortReset
:
449 // Make sure Host Controller not halt before reset it
451 if (EhcIsHalt (Ehc
)) {
452 Status
= EhcRunHC (Ehc
, EHC_GENERIC_TIMEOUT
);
454 if (EFI_ERROR (Status
)) {
455 DEBUG ((EFI_D_INFO
, "EhcSetRootHubPortFeature :failed to start HC - %r\n", Status
));
461 // Set one to PortReset bit must also set zero to PortEnable bit
463 State
|= PORTSC_RESET
;
464 State
&= ~PORTSC_ENABLED
;
465 EhcWriteOpReg (Ehc
, Offset
, State
);
468 case EfiUsbPortPower
:
470 // Not supported, ignore the operation
472 Status
= EFI_SUCCESS
;
475 case EfiUsbPortOwner
:
476 State
|= PORTSC_OWNER
;
477 EhcWriteOpReg (Ehc
, Offset
, State
);
481 Status
= EFI_INVALID_PARAMETER
;
485 DEBUG ((EFI_D_INFO
, "EhcSetRootHubPortFeature: exit status %r\n", Status
));
487 gBS
->RestoreTPL (OldTpl
);
493 Clears a feature for the specified root hub port.
495 @param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
496 @param PortNumber Specifies the root hub port whose feature is
497 requested to be cleared.
498 @param PortFeature Indicates the feature selector associated with the
499 feature clear request.
501 @retval EFI_SUCCESS The feature specified by PortFeature was cleared
502 for the USB root hub port specified by PortNumber.
503 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
504 @retval EFI_DEVICE_ERROR Can't read register.
509 EhcClearRootHubPortFeature (
510 IN EFI_USB2_HC_PROTOCOL
*This
,
512 IN EFI_USB_PORT_FEATURE PortFeature
522 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
523 Ehc
= EHC_FROM_THIS (This
);
524 Status
= EFI_SUCCESS
;
526 TotalPort
= (Ehc
->HcStructParams
& HCSP_NPORTS
);
528 if (PortNumber
>= TotalPort
) {
529 Status
= EFI_INVALID_PARAMETER
;
533 Offset
= EHC_PORT_STAT_OFFSET
+ (4 * PortNumber
);
534 State
= EhcReadOpReg (Ehc
, Offset
);
535 State
&= ~PORTSC_CHANGE_MASK
;
537 switch (PortFeature
) {
538 case EfiUsbPortEnable
:
540 // Clear PORT_ENABLE feature means disable port.
542 State
&= ~PORTSC_ENABLED
;
543 EhcWriteOpReg (Ehc
, Offset
, State
);
546 case EfiUsbPortSuspend
:
548 // A write of zero to this bit is ignored by the host
549 // controller. The host controller will unconditionally
550 // set this bit to a zero when:
551 // 1. software sets the Forct Port Resume bit to a zero from a one.
552 // 2. software sets the Port Reset bit to a one frome a zero.
554 State
&= ~PORSTSC_RESUME
;
555 EhcWriteOpReg (Ehc
, Offset
, State
);
558 case EfiUsbPortReset
:
560 // Clear PORT_RESET means clear the reset signal.
562 State
&= ~PORTSC_RESET
;
563 EhcWriteOpReg (Ehc
, Offset
, State
);
566 case EfiUsbPortOwner
:
568 // Clear port owner means this port owned by EHC
570 State
&= ~PORTSC_OWNER
;
571 EhcWriteOpReg (Ehc
, Offset
, State
);
574 case EfiUsbPortConnectChange
:
576 // Clear connect status change
578 State
|= PORTSC_CONN_CHANGE
;
579 EhcWriteOpReg (Ehc
, Offset
, State
);
582 case EfiUsbPortEnableChange
:
584 // Clear enable status change
586 State
|= PORTSC_ENABLE_CHANGE
;
587 EhcWriteOpReg (Ehc
, Offset
, State
);
590 case EfiUsbPortOverCurrentChange
:
592 // Clear PortOverCurrent change
594 State
|= PORTSC_OVERCUR_CHANGE
;
595 EhcWriteOpReg (Ehc
, Offset
, State
);
598 case EfiUsbPortPower
:
599 case EfiUsbPortSuspendChange
:
600 case EfiUsbPortResetChange
:
602 // Not supported or not related operation
607 Status
= EFI_INVALID_PARAMETER
;
612 DEBUG ((EFI_D_INFO
, "EhcClearRootHubPortFeature: exit status %r\n", Status
));
613 gBS
->RestoreTPL (OldTpl
);
619 Submits control transfer to a target USB device.
621 @param This This EFI_USB2_HC_PROTOCOL instance.
622 @param DeviceAddress The target device address.
623 @param DeviceSpeed Target device speed.
624 @param MaximumPacketLength Maximum packet size the default control transfer
625 endpoint is capable of sending or receiving.
626 @param Request USB device request to send.
627 @param TransferDirection Specifies the data direction for the data stage
628 @param Data Data buffer to be transmitted or received from USB
630 @param DataLength The size (in bytes) of the data buffer.
631 @param TimeOut Indicates the maximum timeout, in millisecond.
632 @param Translator Transaction translator to be used by this device.
633 @param TransferResult Return the result of this control transfer.
635 @retval EFI_SUCCESS Transfer was completed successfully.
636 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
637 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
638 @retval EFI_TIMEOUT Transfer failed due to timeout.
639 @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
645 IN EFI_USB2_HC_PROTOCOL
*This
,
646 IN UINT8 DeviceAddress
,
647 IN UINT8 DeviceSpeed
,
648 IN UINTN MaximumPacketLength
,
649 IN EFI_USB_DEVICE_REQUEST
*Request
,
650 IN EFI_USB_DATA_DIRECTION TransferDirection
,
652 IN OUT UINTN
*DataLength
,
654 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
655 OUT UINT32
*TransferResult
665 // Validate parameters
667 if ((Request
== NULL
) || (TransferResult
== NULL
)) {
668 return EFI_INVALID_PARAMETER
;
671 if ((TransferDirection
!= EfiUsbDataIn
) &&
672 (TransferDirection
!= EfiUsbDataOut
) &&
673 (TransferDirection
!= EfiUsbNoData
)) {
674 return EFI_INVALID_PARAMETER
;
677 if ((TransferDirection
== EfiUsbNoData
) &&
678 ((Data
!= NULL
) || (*DataLength
!= 0))) {
679 return EFI_INVALID_PARAMETER
;
682 if ((TransferDirection
!= EfiUsbNoData
) &&
683 ((Data
== NULL
) || (*DataLength
== 0))) {
684 return EFI_INVALID_PARAMETER
;
687 if ((MaximumPacketLength
!= 8) && (MaximumPacketLength
!= 16) &&
688 (MaximumPacketLength
!= 32) && (MaximumPacketLength
!= 64)) {
689 return EFI_INVALID_PARAMETER
;
692 if ((DeviceSpeed
== EFI_USB_SPEED_LOW
) && (MaximumPacketLength
!= 8)) {
693 return EFI_INVALID_PARAMETER
;
696 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
697 Ehc
= EHC_FROM_THIS (This
);
699 Status
= EFI_DEVICE_ERROR
;
700 *TransferResult
= EFI_USB_ERR_SYSTEM
;
702 if (EhcIsHalt (Ehc
) || EhcIsSysError (Ehc
)) {
703 DEBUG ((EFI_D_ERROR
, "EhcControlTransfer: HC halted at entrance\n"));
705 EhcAckAllInterrupt (Ehc
);
709 EhcAckAllInterrupt (Ehc
);
712 // Create a new URB, insert it into the asynchronous
713 // schedule list, then poll the execution status.
716 // Encode the direction in address, although default control
717 // endpoint is bidirectional. EhcCreateUrb expects this
718 // combination of Ep addr and its direction.
720 Endpoint
= (UINT8
) (0 | ((TransferDirection
== EfiUsbDataIn
) ? 0x80 : 0));
739 DEBUG ((EFI_D_ERROR
, "EhcControlTransfer: failed to create URB"));
741 Status
= EFI_OUT_OF_RESOURCES
;
745 EhcLinkQhToAsync (Ehc
, Urb
->Qh
);
746 Status
= EhcExecTransfer (Ehc
, Urb
, TimeOut
);
747 EhcUnlinkQhFromAsync (Ehc
, Urb
->Qh
);
750 // Get the status from URB. The result is updated in EhcCheckUrbResult
751 // which is called by EhcExecTransfer
753 *TransferResult
= Urb
->Result
;
754 *DataLength
= Urb
->Completed
;
756 if (*TransferResult
== EFI_USB_NOERROR
) {
757 Status
= EFI_SUCCESS
;
760 EhcAckAllInterrupt (Ehc
);
761 EhcFreeUrb (Ehc
, Urb
);
764 Ehc
->PciIo
->Flush (Ehc
->PciIo
);
765 gBS
->RestoreTPL (OldTpl
);
767 if (EFI_ERROR (Status
)) {
768 DEBUG ((EFI_D_ERROR
, "EhcControlTransfer: error - %r, transfer - %x\n", Status
, *TransferResult
));
776 Submits bulk transfer to a bulk endpoint of a USB device.
778 @param This This EFI_USB2_HC_PROTOCOL instance.
779 @param DeviceAddress Target device address.
780 @param EndPointAddress Endpoint number and its direction in bit 7.
781 @param DeviceSpeed Device speed, Low speed device doesn't support bulk
783 @param MaximumPacketLength Maximum packet size the endpoint is capable of
784 sending or receiving.
785 @param DataBuffersNumber Number of data buffers prepared for the transfer.
786 @param Data Array of pointers to the buffers of data to transmit
787 from or receive into.
788 @param DataLength The lenght of the data buffer.
789 @param DataToggle On input, the initial data toggle for the transfer;
790 On output, it is updated to to next data toggle to
791 use of the subsequent bulk transfer.
792 @param TimeOut Indicates the maximum time, in millisecond, which
793 the transfer is allowed to complete.
794 @param Translator A pointr to the transaction translator data.
795 @param TransferResult A pointer to the detailed result information of the
798 @retval EFI_SUCCESS The transfer was completed successfully.
799 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
800 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
801 @retval EFI_TIMEOUT The transfer failed due to timeout.
802 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
808 IN EFI_USB2_HC_PROTOCOL
*This
,
809 IN UINT8 DeviceAddress
,
810 IN UINT8 EndPointAddress
,
811 IN UINT8 DeviceSpeed
,
812 IN UINTN MaximumPacketLength
,
813 IN UINT8 DataBuffersNumber
,
814 IN OUT VOID
*Data
[EFI_USB_MAX_BULK_BUFFER_NUM
],
815 IN OUT UINTN
*DataLength
,
816 IN OUT UINT8
*DataToggle
,
818 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
819 OUT UINT32
*TransferResult
828 // Validate the parameters
830 if ((DataLength
== NULL
) || (*DataLength
== 0) ||
831 (Data
== NULL
) || (Data
[0] == NULL
) || (TransferResult
== NULL
)) {
832 return EFI_INVALID_PARAMETER
;
835 if ((*DataToggle
!= 0) && (*DataToggle
!= 1)) {
836 return EFI_INVALID_PARAMETER
;
839 if ((DeviceSpeed
== EFI_USB_SPEED_LOW
) ||
840 ((DeviceSpeed
== EFI_USB_SPEED_FULL
) && (MaximumPacketLength
> 64)) ||
841 ((EFI_USB_SPEED_HIGH
== DeviceSpeed
) && (MaximumPacketLength
> 512))) {
842 return EFI_INVALID_PARAMETER
;
845 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
846 Ehc
= EHC_FROM_THIS (This
);
848 *TransferResult
= EFI_USB_ERR_SYSTEM
;
849 Status
= EFI_DEVICE_ERROR
;
851 if (EhcIsHalt (Ehc
) || EhcIsSysError (Ehc
)) {
852 DEBUG ((EFI_D_ERROR
, "EhcBulkTransfer: HC is halted\n"));
854 EhcAckAllInterrupt (Ehc
);
858 EhcAckAllInterrupt (Ehc
);
861 // Create a new URB, insert it into the asynchronous
862 // schedule list, then poll the execution status.
882 DEBUG ((EFI_D_ERROR
, "EhcBulkTransfer: failed to create URB\n"));
884 Status
= EFI_OUT_OF_RESOURCES
;
888 EhcLinkQhToAsync (Ehc
, Urb
->Qh
);
889 Status
= EhcExecTransfer (Ehc
, Urb
, TimeOut
);
890 EhcUnlinkQhFromAsync (Ehc
, Urb
->Qh
);
892 *TransferResult
= Urb
->Result
;
893 *DataLength
= Urb
->Completed
;
894 *DataToggle
= Urb
->DataToggle
;
896 if (*TransferResult
== EFI_USB_NOERROR
) {
897 Status
= EFI_SUCCESS
;
900 EhcAckAllInterrupt (Ehc
);
901 EhcFreeUrb (Ehc
, Urb
);
904 Ehc
->PciIo
->Flush (Ehc
->PciIo
);
905 gBS
->RestoreTPL (OldTpl
);
907 if (EFI_ERROR (Status
)) {
908 DEBUG ((EFI_D_ERROR
, "EhcBulkTransfer: error - %r, transfer - %x\n", Status
, *TransferResult
));
916 Submits an asynchronous interrupt transfer to an
917 interrupt endpoint of a USB device.
919 @param This This EFI_USB2_HC_PROTOCOL instance.
920 @param DeviceAddress Target device address.
921 @param EndPointAddress Endpoint number and its direction encoded in bit 7
922 @param DeviceSpeed Indicates device speed.
923 @param MaximumPacketLength Maximum packet size the target endpoint is capable
924 @param IsNewTransfer If TRUE, to submit an new asynchronous interrupt
925 transfer If FALSE, to remove the specified
926 asynchronous interrupt.
927 @param DataToggle On input, the initial data toggle to use; on output,
928 it is updated to indicate the next data toggle.
929 @param PollingInterval The he interval, in milliseconds, that the transfer
931 @param DataLength The length of data to receive at the rate specified
933 @param Translator Transaction translator to use.
934 @param CallBackFunction Function to call at the rate specified by
936 @param Context Context to CallBackFunction.
938 @retval EFI_SUCCESS The request has been successfully submitted or canceled.
939 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
940 @retval EFI_OUT_OF_RESOURCES The request failed due to a lack of resources.
941 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
946 EhcAsyncInterruptTransfer (
947 IN EFI_USB2_HC_PROTOCOL
* This
,
948 IN UINT8 DeviceAddress
,
949 IN UINT8 EndPointAddress
,
950 IN UINT8 DeviceSpeed
,
951 IN UINTN MaximumPacketLength
,
952 IN BOOLEAN IsNewTransfer
,
953 IN OUT UINT8
*DataToggle
,
954 IN UINTN PollingInterval
,
956 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
* Translator
,
957 IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction
,
958 IN VOID
*Context OPTIONAL
968 // Validate parameters
970 if (!EHCI_IS_DATAIN (EndPointAddress
)) {
971 return EFI_INVALID_PARAMETER
;
975 if (DataLength
== 0) {
976 return EFI_INVALID_PARAMETER
;
979 if ((*DataToggle
!= 1) && (*DataToggle
!= 0)) {
980 return EFI_INVALID_PARAMETER
;
983 if ((PollingInterval
> 255) || (PollingInterval
< 1)) {
984 return EFI_INVALID_PARAMETER
;
988 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
989 Ehc
= EHC_FROM_THIS (This
);
992 // Delete Async interrupt transfer request. DataToggle will return
993 // the next data toggle to use.
995 if (!IsNewTransfer
) {
996 Status
= EhciDelAsyncIntTransfer (Ehc
, DeviceAddress
, EndPointAddress
, DataToggle
);
998 DEBUG ((EFI_D_INFO
, "EhcAsyncInterruptTransfer: remove old transfer - %r\n", Status
));
1002 Status
= EFI_SUCCESS
;
1004 if (EhcIsHalt (Ehc
) || EhcIsSysError (Ehc
)) {
1005 DEBUG ((EFI_D_ERROR
, "EhcAsyncInterruptTransfer: HC is halt\n"));
1006 EhcAckAllInterrupt (Ehc
);
1008 Status
= EFI_DEVICE_ERROR
;
1012 EhcAckAllInterrupt (Ehc
);
1014 Data
= AllocatePool (DataLength
);
1017 DEBUG ((EFI_D_ERROR
, "EhcAsyncInterruptTransfer: failed to allocate buffer\n"));
1019 Status
= EFI_OUT_OF_RESOURCES
;
1023 Urb
= EhcCreateUrb (
1029 MaximumPacketLength
,
1031 EHC_INT_TRANSFER_ASYNC
,
1041 DEBUG ((EFI_D_ERROR
, "EhcAsyncInterruptTransfer: failed to create URB\n"));
1043 gBS
->FreePool (Data
);
1044 Status
= EFI_OUT_OF_RESOURCES
;
1049 // New asynchronous transfer must inserted to the head.
1050 // Check the comments in EhcMoniteAsyncRequests
1052 EhcLinkQhToPeriod (Ehc
, Urb
->Qh
);
1053 InsertHeadList (&Ehc
->AsyncIntTransfers
, &Urb
->UrbList
);
1056 Ehc
->PciIo
->Flush (Ehc
->PciIo
);
1057 gBS
->RestoreTPL (OldTpl
);
1064 Submits synchronous interrupt transfer to an interrupt endpoint
1067 @param This This EFI_USB2_HC_PROTOCOL instance.
1068 @param DeviceAddress Target device address.
1069 @param EndPointAddress Endpoint number and its direction encoded in bit 7
1070 @param DeviceSpeed Indicates device speed.
1071 @param MaximumPacketLength Maximum packet size the target endpoint is capable
1072 of sending or receiving.
1073 @param Data Buffer of data that will be transmitted to USB
1074 device or received from USB device.
1075 @param DataLength On input, the size, in bytes, of the data buffer; On
1076 output, the number of bytes transferred.
1077 @param DataToggle On input, the initial data toggle to use; on output,
1078 it is updated to indicate the next data toggle.
1079 @param TimeOut Maximum time, in second, to complete.
1080 @param Translator Transaction translator to use.
1081 @param TransferResult Variable to receive the transfer result.
1083 @return EFI_SUCCESS The transfer was completed successfully.
1084 @return EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
1085 @return EFI_INVALID_PARAMETER Some parameters are invalid.
1086 @return EFI_TIMEOUT The transfer failed due to timeout.
1087 @return EFI_DEVICE_ERROR The failed due to host controller or device error
1092 EhcSyncInterruptTransfer (
1093 IN EFI_USB2_HC_PROTOCOL
*This
,
1094 IN UINT8 DeviceAddress
,
1095 IN UINT8 EndPointAddress
,
1096 IN UINT8 DeviceSpeed
,
1097 IN UINTN MaximumPacketLength
,
1099 IN OUT UINTN
*DataLength
,
1100 IN OUT UINT8
*DataToggle
,
1102 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
1103 OUT UINT32
*TransferResult
1112 // Validates parameters
1114 if ((DataLength
== NULL
) || (*DataLength
== 0) ||
1115 (Data
== NULL
) || (TransferResult
== NULL
)) {
1116 return EFI_INVALID_PARAMETER
;
1119 if (!EHCI_IS_DATAIN (EndPointAddress
)) {
1120 return EFI_INVALID_PARAMETER
;
1123 if ((*DataToggle
!= 1) && (*DataToggle
!= 0)) {
1124 return EFI_INVALID_PARAMETER
;
1127 if (((DeviceSpeed
== EFI_USB_SPEED_LOW
) && (MaximumPacketLength
!= 8)) ||
1128 ((DeviceSpeed
== EFI_USB_SPEED_FULL
) && (MaximumPacketLength
> 64)) ||
1129 ((DeviceSpeed
== EFI_USB_SPEED_HIGH
) && (MaximumPacketLength
> 3072))) {
1130 return EFI_INVALID_PARAMETER
;
1133 OldTpl
= gBS
->RaiseTPL (EHC_TPL
);
1134 Ehc
= EHC_FROM_THIS (This
);
1136 *TransferResult
= EFI_USB_ERR_SYSTEM
;
1137 Status
= EFI_DEVICE_ERROR
;
1139 if (EhcIsHalt (Ehc
) || EhcIsSysError (Ehc
)) {
1140 DEBUG ((EFI_D_ERROR
, "EhcSyncInterruptTransfer: HC is halt\n"));
1142 EhcAckAllInterrupt (Ehc
);
1146 EhcAckAllInterrupt (Ehc
);
1148 Urb
= EhcCreateUrb (
1154 MaximumPacketLength
,
1156 EHC_INT_TRANSFER_SYNC
,
1166 DEBUG ((EFI_D_ERROR
, "EhcSyncInterruptTransfer: failed to create URB\n"));
1168 Status
= EFI_OUT_OF_RESOURCES
;
1172 EhcLinkQhToPeriod (Ehc
, Urb
->Qh
);
1173 Status
= EhcExecTransfer (Ehc
, Urb
, TimeOut
);
1174 EhcUnlinkQhFromPeriod (Ehc
, Urb
->Qh
);
1176 *TransferResult
= Urb
->Result
;
1177 *DataLength
= Urb
->Completed
;
1178 *DataToggle
= Urb
->DataToggle
;
1180 if (*TransferResult
== EFI_USB_NOERROR
) {
1181 Status
= EFI_SUCCESS
;
1185 Ehc
->PciIo
->Flush (Ehc
->PciIo
);
1186 gBS
->RestoreTPL (OldTpl
);
1188 if (EFI_ERROR (Status
)) {
1189 DEBUG ((EFI_D_ERROR
, "EhcSyncInterruptTransfer: error - %r, transfer - %x\n", Status
, *TransferResult
));
1197 Submits isochronous transfer to a target USB device.
1199 @param This This EFI_USB2_HC_PROTOCOL instance.
1200 @param DeviceAddress Target device address.
1201 @param EndPointAddress End point address with its direction.
1202 @param DeviceSpeed Device speed, Low speed device doesn't support this
1204 @param MaximumPacketLength Maximum packet size that the endpoint is capable of
1205 sending or receiving.
1206 @param DataBuffersNumber Number of data buffers prepared for the transfer.
1207 @param Data Array of pointers to the buffers of data that will
1208 be transmitted to USB device or received from USB
1210 @param DataLength The size, in bytes, of the data buffer.
1211 @param Translator Transaction translator to use.
1212 @param TransferResult Variable to receive the transfer result.
1214 @return EFI_UNSUPPORTED Isochronous transfer is unsupported.
1219 EhcIsochronousTransfer (
1220 IN EFI_USB2_HC_PROTOCOL
*This
,
1221 IN UINT8 DeviceAddress
,
1222 IN UINT8 EndPointAddress
,
1223 IN UINT8 DeviceSpeed
,
1224 IN UINTN MaximumPacketLength
,
1225 IN UINT8 DataBuffersNumber
,
1226 IN OUT VOID
*Data
[EFI_USB_MAX_ISO_BUFFER_NUM
],
1227 IN UINTN DataLength
,
1228 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
1229 OUT UINT32
*TransferResult
1232 return EFI_UNSUPPORTED
;
1237 Submits Async isochronous transfer to a target USB device.
1239 @param This This EFI_USB2_HC_PROTOCOL instance.
1240 @param DeviceAddress Target device address.
1241 @param EndPointAddress End point address with its direction.
1242 @param DeviceSpeed Device speed, Low speed device doesn't support this
1244 @param MaximumPacketLength Maximum packet size that the endpoint is capable of
1245 sending or receiving.
1246 @param DataBuffersNumber Number of data buffers prepared for the transfer.
1247 @param Data Array of pointers to the buffers of data that will
1248 be transmitted to USB device or received from USB
1250 @param DataLength The size, in bytes, of the data buffer.
1251 @param Translator Transaction translator to use.
1252 @param IsochronousCallBack Function to be called when the transfer complete.
1253 @param Context Context passed to the call back function as
1256 @return EFI_UNSUPPORTED Isochronous transfer isn't supported.
1261 EhcAsyncIsochronousTransfer (
1262 IN EFI_USB2_HC_PROTOCOL
*This
,
1263 IN UINT8 DeviceAddress
,
1264 IN UINT8 EndPointAddress
,
1265 IN UINT8 DeviceSpeed
,
1266 IN UINTN MaximumPacketLength
,
1267 IN UINT8 DataBuffersNumber
,
1268 IN OUT VOID
*Data
[EFI_USB_MAX_ISO_BUFFER_NUM
],
1269 IN UINTN DataLength
,
1270 IN EFI_USB2_HC_TRANSACTION_TRANSLATOR
*Translator
,
1271 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack
,
1275 return EFI_UNSUPPORTED
;
1279 Entry point for EFI drivers.
1281 @param ImageHandle EFI_HANDLE.
1282 @param SystemTable EFI_SYSTEM_TABLE.
1284 @return EFI_SUCCESS Success.
1285 EFI_DEVICE_ERROR Fail.
1290 EhcDriverEntryPoint (
1291 IN EFI_HANDLE ImageHandle
,
1292 IN EFI_SYSTEM_TABLE
*SystemTable
1295 return EfiLibInstallDriverBindingComponentName2 (
1298 &gEhciDriverBinding
,
1300 &gEhciComponentName
,
1301 &gEhciComponentName2
1307 Test to see if this driver supports ControllerHandle. Any
1308 ControllerHandle that has Usb2HcProtocol installed will
1311 @param This Protocol instance pointer.
1312 @param Controller Handle of device to test.
1313 @param RemainingDevicePath Not used.
1315 @return EFI_SUCCESS This driver supports this device.
1316 @return EFI_UNSUPPORTED This driver does not support this device.
1321 EhcDriverBindingSupported (
1322 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1323 IN EFI_HANDLE Controller
,
1324 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
1328 EFI_PCI_IO_PROTOCOL
*PciIo
;
1329 USB_CLASSC UsbClassCReg
;
1332 // Test whether there is PCI IO Protocol attached on the controller handle.
1334 Status
= gBS
->OpenProtocol (
1336 &gEfiPciIoProtocolGuid
,
1338 This
->DriverBindingHandle
,
1340 EFI_OPEN_PROTOCOL_BY_DRIVER
1343 if (EFI_ERROR (Status
)) {
1344 return EFI_UNSUPPORTED
;
1347 Status
= PciIo
->Pci
.Read (
1351 sizeof (USB_CLASSC
) / sizeof (UINT8
),
1355 if (EFI_ERROR (Status
)) {
1356 Status
= EFI_UNSUPPORTED
;
1361 // Test whether the controller belongs to Ehci type
1363 if ((UsbClassCReg
.BaseCode
!= PCI_CLASS_SERIAL
) || (UsbClassCReg
.SubClassCode
!= PCI_CLASS_SERIAL_USB
)
1364 || ((UsbClassCReg
.PI
!= EHC_PCI_CLASSC_PI
) && (UsbClassCReg
.PI
!=PCI_CLASSC_PI_UHCI
))) {
1366 Status
= EFI_UNSUPPORTED
;
1370 gBS
->CloseProtocol (
1372 &gEfiPciIoProtocolGuid
,
1373 This
->DriverBindingHandle
,
1382 Create and initialize a USB2_HC_DEV.
1384 @param PciIo The PciIo on this device.
1385 @param OriginalPciAttributes Original PCI attributes.
1387 @return The allocated and initialized USB2_HC_DEV structure if created,
1393 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1394 IN UINT64 OriginalPciAttributes
1400 Ehc
= AllocateZeroPool (sizeof (USB2_HC_DEV
));
1407 // Init EFI_USB2_HC_PROTOCOL interface and private data structure
1409 Ehc
->Signature
= USB2_HC_DEV_SIGNATURE
;
1411 Ehc
->Usb2Hc
.GetCapability
= EhcGetCapability
;
1412 Ehc
->Usb2Hc
.Reset
= EhcReset
;
1413 Ehc
->Usb2Hc
.GetState
= EhcGetState
;
1414 Ehc
->Usb2Hc
.SetState
= EhcSetState
;
1415 Ehc
->Usb2Hc
.ControlTransfer
= EhcControlTransfer
;
1416 Ehc
->Usb2Hc
.BulkTransfer
= EhcBulkTransfer
;
1417 Ehc
->Usb2Hc
.AsyncInterruptTransfer
= EhcAsyncInterruptTransfer
;
1418 Ehc
->Usb2Hc
.SyncInterruptTransfer
= EhcSyncInterruptTransfer
;
1419 Ehc
->Usb2Hc
.IsochronousTransfer
= EhcIsochronousTransfer
;
1420 Ehc
->Usb2Hc
.AsyncIsochronousTransfer
= EhcAsyncIsochronousTransfer
;
1421 Ehc
->Usb2Hc
.GetRootHubPortStatus
= EhcGetRootHubPortStatus
;
1422 Ehc
->Usb2Hc
.SetRootHubPortFeature
= EhcSetRootHubPortFeature
;
1423 Ehc
->Usb2Hc
.ClearRootHubPortFeature
= EhcClearRootHubPortFeature
;
1424 Ehc
->Usb2Hc
.MajorRevision
= 0x2;
1425 Ehc
->Usb2Hc
.MinorRevision
= 0x0;
1428 Ehc
->OriginalPciAttributes
= OriginalPciAttributes
;
1430 InitializeListHead (&Ehc
->AsyncIntTransfers
);
1432 Ehc
->HcStructParams
= EhcReadCapRegister (Ehc
, EHC_HCSPARAMS_OFFSET
);
1433 Ehc
->HcCapParams
= EhcReadCapRegister (Ehc
, EHC_HCCPARAMS_OFFSET
);
1434 Ehc
->CapLen
= EhcReadCapRegister (Ehc
, EHC_CAPLENGTH_OFFSET
) & 0x0FF;
1436 DEBUG ((EFI_D_INFO
, "EhcCreateUsb2Hc: capability length %d\n", Ehc
->CapLen
));
1439 // Create AsyncRequest Polling Timer
1441 Status
= gBS
->CreateEvent (
1442 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
1444 EhcMonitorAsyncRequests
,
1449 if (EFI_ERROR (Status
)) {
1450 gBS
->FreePool (Ehc
);
1458 One notified function to stop the Host Controller when gBS->ExitBootServices() called.
1460 @param Event Pointer to this event
1461 @param Context Event hanlder private data
1466 EhcExitBootService (
1474 Ehc
= (USB2_HC_DEV
*) Context
;
1477 // Stop the Host Controller
1479 EhcHaltHC (Ehc
, EHC_GENERIC_TIMEOUT
);
1486 Starting the Usb EHCI Driver.
1488 @param This Protocol instance pointer.
1489 @param Controller Handle of device to test.
1490 @param RemainingDevicePath Not used.
1492 @return EFI_SUCCESS supports this device.
1493 @return EFI_UNSUPPORTED do not support this device.
1494 @return EFI_DEVICE_ERROR cannot be started due to device Error.
1495 @return EFI_OUT_OF_RESOURCES cannot allocate resources.
1500 EhcDriverBindingStart (
1501 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1502 IN EFI_HANDLE Controller
,
1503 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
1508 EFI_PCI_IO_PROTOCOL
*PciIo
;
1509 EFI_PCI_IO_PROTOCOL
*Instance
;
1511 UINT64 OriginalPciAttributes
;
1512 BOOLEAN PciAttributesSaved
;
1513 USB_CLASSC UsbClassCReg
;
1514 EFI_HANDLE
*HandleBuffer
;
1515 UINTN NumberOfHandles
;
1517 UINTN UhciSegmentNumber
;
1518 UINTN UhciBusNumber
;
1519 UINTN UhciDeviceNumber
;
1520 UINTN UhciFunctionNumber
;
1521 UINTN EhciSegmentNumber
;
1522 UINTN EhciBusNumber
;
1523 UINTN EhciDeviceNumber
;
1524 UINTN EhciFunctionNumber
;
1527 // Open the PciIo Protocol, then enable the USB host controller
1529 Status
= gBS
->OpenProtocol (
1531 &gEfiPciIoProtocolGuid
,
1533 This
->DriverBindingHandle
,
1535 EFI_OPEN_PROTOCOL_BY_DRIVER
1538 if (EFI_ERROR (Status
)) {
1542 PciAttributesSaved
= FALSE
;
1544 // Save original PCI attributes
1546 Status
= PciIo
->Attributes (
1548 EfiPciIoAttributeOperationGet
,
1550 &OriginalPciAttributes
1553 if (EFI_ERROR (Status
)) {
1556 PciAttributesSaved
= TRUE
;
1558 Status
= PciIo
->Attributes (
1560 EfiPciIoAttributeOperationSupported
,
1564 if (!EFI_ERROR (Status
)) {
1565 Supports
&= EFI_PCI_DEVICE_ENABLE
;
1566 Status
= PciIo
->Attributes (
1568 EfiPciIoAttributeOperationEnable
,
1574 if (EFI_ERROR (Status
)) {
1575 DEBUG ((EFI_D_ERROR
, "EhcDriverBindingStart: failed to enable controller\n"));
1579 Status
= PciIo
->Pci
.Read (
1583 sizeof (USB_CLASSC
) / sizeof (UINT8
),
1587 if (EFI_ERROR (Status
)) {
1588 Status
= EFI_UNSUPPORTED
;
1592 if ((UsbClassCReg
.PI
== PCI_CLASSC_PI_UHCI
) &&
1593 (UsbClassCReg
.BaseCode
== PCI_CLASS_SERIAL
) &&
1594 (UsbClassCReg
.SubClassCode
== PCI_CLASS_SERIAL_USB
)) {
1595 Status
= PciIo
->GetLocation (
1602 if (EFI_ERROR (Status
)) {
1606 Status
= gBS
->LocateHandleBuffer (
1608 &gEfiPciIoProtocolGuid
,
1613 if (EFI_ERROR (Status
)) {
1617 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
1619 // Get the device path on this handle
1621 Status
= gBS
->HandleProtocol (
1622 HandleBuffer
[Index
],
1623 &gEfiPciIoProtocolGuid
,
1626 ASSERT_EFI_ERROR (Status
);
1628 Status
= Instance
->Pci
.Read (
1632 sizeof (USB_CLASSC
) / sizeof (UINT8
),
1636 if (EFI_ERROR (Status
)) {
1637 Status
= EFI_UNSUPPORTED
;
1641 if ((UsbClassCReg
.PI
== PCI_CLASSC_PI_EHCI
) &&
1642 (UsbClassCReg
.BaseCode
== PCI_CLASS_SERIAL
) &&
1643 (UsbClassCReg
.SubClassCode
== PCI_CLASS_SERIAL_USB
)) {
1644 Status
= Instance
->GetLocation (
1651 if (EFI_ERROR (Status
)) {
1654 if (EhciBusNumber
== UhciBusNumber
) {
1655 gBS
->CloseProtocol (
1657 &gEfiPciIoProtocolGuid
,
1658 This
->DriverBindingHandle
,
1661 EhcDriverBindingStart(This
, HandleBuffer
[Index
], NULL
);
1665 Status
= EFI_NOT_FOUND
;
1670 // Create then install USB2_HC_PROTOCOL
1672 Ehc
= EhcCreateUsb2Hc (PciIo
, OriginalPciAttributes
);
1675 DEBUG ((EFI_D_ERROR
, "EhcDriverBindingStart: failed to create USB2_HC\n"));
1677 Status
= EFI_OUT_OF_RESOURCES
;
1681 Status
= gBS
->InstallProtocolInterface (
1683 &gEfiUsb2HcProtocolGuid
,
1684 EFI_NATIVE_INTERFACE
,
1688 if (EFI_ERROR (Status
)) {
1689 DEBUG ((EFI_D_ERROR
, "EhcDriverBindingStart: failed to install USB2_HC Protocol\n"));
1694 // Robustnesss improvement such as for UoL
1695 // Default is not required.
1697 if (FeaturePcdGet (PcdTurnOffUsbLegacySupport
)) {
1698 EhcClearLegacySupport (Ehc
);
1700 EhcResetHC (Ehc
, EHC_RESET_TIMEOUT
);
1702 Status
= EhcInitHC (Ehc
);
1704 if (EFI_ERROR (Status
)) {
1705 DEBUG ((EFI_D_ERROR
, "EhcDriverBindingStart: failed to init host controller\n"));
1706 goto UNINSTALL_USBHC
;
1710 // Start the asynchronous interrupt monitor
1712 Status
= gBS
->SetTimer (Ehc
->PollTimer
, TimerPeriodic
, EHC_ASYNC_POLL_INTERVAL
);
1714 if (EFI_ERROR (Status
)) {
1715 DEBUG ((EFI_D_ERROR
, "EhcDriverBindingStart: failed to start async interrupt monitor\n"));
1717 EhcHaltHC (Ehc
, EHC_GENERIC_TIMEOUT
);
1718 goto UNINSTALL_USBHC
;
1722 // Create event to stop the HC when exit boot service.
1724 Status
= gBS
->CreateEventEx (
1729 &gEfiEventExitBootServicesGuid
,
1730 &Ehc
->ExitBootServiceEvent
1732 if (EFI_ERROR (Status
)) {
1733 goto UNINSTALL_USBHC
;
1737 // Install the component name protocol, don't fail the start
1738 // because of something for display.
1742 gEhciComponentName
.SupportedLanguages
,
1743 &Ehc
->ControllerNameTable
,
1744 L
"Enhanced Host Controller (USB 2.0)",
1749 gEhciComponentName2
.SupportedLanguages
,
1750 &Ehc
->ControllerNameTable
,
1751 L
"Enhanced Host Controller (USB 2.0)",
1756 DEBUG ((EFI_D_INFO
, "EhcDriverBindingStart: EHCI started for controller @ %p\n", Controller
));
1760 gBS
->UninstallProtocolInterface (
1762 &gEfiUsb2HcProtocolGuid
,
1768 gBS
->CloseEvent (Ehc
->PollTimer
);
1769 gBS
->FreePool (Ehc
);
1772 if (PciAttributesSaved
) {
1774 // Restore original PCI attributes
1778 EfiPciIoAttributeOperationSet
,
1779 OriginalPciAttributes
,
1784 gBS
->CloseProtocol (
1786 &gEfiPciIoProtocolGuid
,
1787 This
->DriverBindingHandle
,
1796 Stop this driver on ControllerHandle. Support stoping any child handles
1797 created by this driver.
1799 @param This Protocol instance pointer.
1800 @param Controller Handle of device to stop driver on.
1801 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
1802 @param ChildHandleBuffer List of handles for the children we need to stop.
1804 @return EFI_SUCCESS Success.
1805 @return EFI_DEVICE_ERROR Fail.
1810 EhcDriverBindingStop (
1811 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1812 IN EFI_HANDLE Controller
,
1813 IN UINTN NumberOfChildren
,
1814 IN EFI_HANDLE
*ChildHandleBuffer
1818 EFI_USB2_HC_PROTOCOL
*Usb2Hc
;
1819 EFI_PCI_IO_PROTOCOL
*PciIo
;
1823 // Test whether the Controller handler passed in is a valid
1824 // Usb controller handle that should be supported, if not,
1825 // return the error status directly
1827 Status
= gBS
->OpenProtocol (
1829 &gEfiUsb2HcProtocolGuid
,
1831 This
->DriverBindingHandle
,
1833 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1836 if (EFI_ERROR (Status
)) {
1840 Ehc
= EHC_FROM_THIS (Usb2Hc
);
1844 // Stop AsyncRequest Polling timer then stop the EHCI driver
1845 // and uninstall the EHCI protocl.
1847 gBS
->SetTimer (Ehc
->PollTimer
, TimerCancel
, EHC_ASYNC_POLL_INTERVAL
);
1848 EhcHaltHC (Ehc
, EHC_GENERIC_TIMEOUT
);
1850 Status
= gBS
->UninstallProtocolInterface (
1852 &gEfiUsb2HcProtocolGuid
,
1856 if (EFI_ERROR (Status
)) {
1860 if (Ehc
->PollTimer
!= NULL
) {
1861 gBS
->CloseEvent (Ehc
->PollTimer
);
1864 if (Ehc
->ExitBootServiceEvent
!= NULL
) {
1865 gBS
->CloseEvent (Ehc
->ExitBootServiceEvent
);
1870 if (Ehc
->ControllerNameTable
!= NULL
) {
1871 FreeUnicodeStringTable (Ehc
->ControllerNameTable
);
1875 // Restore original PCI attributes
1879 EfiPciIoAttributeOperationSet
,
1880 Ehc
->OriginalPciAttributes
,
1884 gBS
->CloseProtocol (
1886 &gEfiPciIoProtocolGuid
,
1887 This
->DriverBindingHandle
,