3 The definition for UHCI driver model and HC protocol routines.
5 Copyright (c) 2004 - 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.
22 #include <Protocol/Usb2HostController.h>
23 #include <Protocol/UsbHostController.h>
24 #include <Protocol/PciIo.h>
26 #include <Guid/EventGroup.h>
28 #include <Library/DebugLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/UefiLib.h>
33 #include <Library/BaseLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/PcdLib.h>
37 #include <IndustryStandard/Pci.h>
39 typedef struct _USB_HC_DEV USB_HC_DEV
;
42 #include "UhciQueue.h"
44 #include "UhciSched.h"
45 #include "UhciDebug.h"
46 #include "ComponentName.h"
49 UHC_1_MICROSECOND
= 1,
50 UHC_1_MILLISECOND
= 1000 * UHC_1_MICROSECOND
,
51 UHC_1_SECOND
= 1000 * UHC_1_MILLISECOND
,
54 // UHCI register operation timeout, set by experience
56 UHC_GENERIC_TIMEOUT
= UHC_1_SECOND
,
59 // Wait for force global resume(FGR) complete, refers to
60 // specification[UHCI11-2.1.1]
62 UHC_FORCE_GLOBAL_RESUME_STALL
= 20 * UHC_1_MILLISECOND
,
65 // Wait for roothub port reset and recovery, reset stall
66 // is set by experience, and recovery stall refers to
67 // specification[UHCI11-2.1.1]
69 UHC_ROOT_PORT_RESET_STALL
= 50 * UHC_1_MILLISECOND
,
70 UHC_ROOT_PORT_RECOVERY_STALL
= 10 * UHC_1_MILLISECOND
,
73 // Sync and Async transfer polling interval, set by experience,
74 // and the unit of Async is 100us.
76 UHC_SYNC_POLL_INTERVAL
= 1 * UHC_1_MILLISECOND
,
77 UHC_ASYNC_POLL_INTERVAL
= 50 * 10000UL
78 }UHC_TIMEOUT_EXPERIENCE_VALUE
;
82 // UHC raises TPL to TPL_NOTIFY to serialize all its operations
83 // to protect shared data structures.
85 #define UHCI_TPL TPL_NOTIFY
87 #define USB_HC_DEV_SIGNATURE SIGNATURE_32 ('u', 'h', 'c', 'i')
97 #define UHC_FROM_USB2_HC_PROTO(This) CR(This, USB_HC_DEV, Usb2Hc, USB_HC_DEV_SIGNATURE)
100 // USB_HC_DEV support the UHCI hardware controller. It schedules
101 // the asynchronous interrupt transfer with the same method as
102 // EHCI: a reversed tree structure. For synchronous interrupt,
103 // control and bulk transfer, it uses three static queue head to
104 // schedule them. SyncIntQh is for interrupt transfer. LsCtrlQh is
105 // for LOW speed control transfer, and FsCtrlBulkQh is for FULL
106 // speed control or bulk transfer. This is because FULL speed contrl
107 // or bulk transfer can reclaim the unused bandwidth. Some USB
108 // device requires this bandwidth reclamation capability.
112 EFI_USB2_HC_PROTOCOL Usb2Hc
;
113 EFI_PCI_IO_PROTOCOL
*PciIo
;
114 UINT64 OriginalPciAttributes
;
117 // Schedule data structures
120 UHCI_QH_SW
*SyncIntQh
;
125 // Structures to maintain asynchronus interrupt transfers.
126 // When asynchronous interrutp transfer is unlinked from
127 // the frame list, the hardware may still hold a pointer
128 // to it. To synchronize with hardware, its resoureces are
129 // released in two steps using Recycle and RecycleWait.
130 // Check the asynchronous interrupt management routines.
132 LIST_ENTRY AsyncIntList
;
133 EFI_EVENT AsyncIntMonitor
;
134 UHCI_ASYNC_REQUEST
*Recycle
;
135 UHCI_ASYNC_REQUEST
*RecycleWait
;
139 USBHC_MEM_POOL
*MemPool
;
140 EFI_UNICODE_STRING_TABLE
*CtrlNameTable
;
144 // ExitBootServicesEvent is used to stop the EHC DMA operation
145 // after exit boot service.
147 EFI_EVENT ExitBootServiceEvent
;
150 extern EFI_DRIVER_BINDING_PROTOCOL gUhciDriverBinding
;
151 extern EFI_COMPONENT_NAME_PROTOCOL gUhciComponentName
;
152 extern EFI_COMPONENT_NAME2_PROTOCOL gUhciComponentName2
;
155 Test to see if this driver supports ControllerHandle. Any
156 ControllerHandle that has UsbHcProtocol installed will be supported.
158 @param This Protocol instance pointer.
159 @param Controller Handle of device to test.
160 @param RemainingDevicePath Not used.
162 @return EFI_SUCCESS This driver supports this device.
163 @return EFI_UNSUPPORTED This driver does not support this device.
168 UhciDriverBindingSupported (
169 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
170 IN EFI_HANDLE Controller
,
171 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
175 Starting the Usb UHCI Driver.
177 @param This Protocol instance pointer.
178 @param Controller Handle of device to test.
179 @param RemainingDevicePath Not used.
181 @retval EFI_SUCCESS This driver supports this device.
182 @retval EFI_UNSUPPORTED This driver does not support this device.
183 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
184 EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
189 UhciDriverBindingStart (
190 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
191 IN EFI_HANDLE Controller
,
192 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
196 Stop this driver on ControllerHandle. Support stoping any child handles
197 created by this driver.
199 @param This Protocol instance pointer.
200 @param Controller Handle of device to stop driver on.
201 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
202 @param ChildHandleBuffer List of handles for the children we need to stop.
210 UhciDriverBindingStop (
211 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
212 IN EFI_HANDLE Controller
,
213 IN UINTN NumberOfChildren
,
214 IN EFI_HANDLE
*ChildHandleBuffer