3 The definition for UHCI driver model and HC protocol routines.
5 Copyright (c) 2004 - 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.
22 #include <Protocol/Usb2HostController.h>
23 #include <Protocol/UsbHostController.h>
24 #include <Protocol/PciIo.h>
26 #include <Library/DebugLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/PcdLib.h>
35 #include <IndustryStandard/Pci22.h>
37 typedef struct _USB_HC_DEV USB_HC_DEV
;
40 #include "UhciQueue.h"
42 #include "UhciSched.h"
43 #include "UhciDebug.h"
44 #include "ComponentName.h"
47 UHC_1_MICROSECOND
= 1,
48 UHC_1_MILLISECOND
= 1000 * UHC_1_MICROSECOND
,
49 UHC_1_SECOND
= 1000 * UHC_1_MILLISECOND
,
52 // UHCI register operation timeout, set by experience
54 UHC_GENERIC_TIMEOUT
= UHC_1_SECOND
,
57 // Wait for force global resume(FGR) complete, refers to
58 // specification[UHCI11-2.1.1]
60 UHC_FORCE_GLOBAL_RESUME_STALL
= 20 * UHC_1_MILLISECOND
,
63 // Wait for roothub port reset and recovery, reset stall
64 // is set by experience, and recovery stall refers to
65 // specification[UHCI11-2.1.1]
67 UHC_ROOT_PORT_RESET_STALL
= 50 * UHC_1_MILLISECOND
,
68 UHC_ROOT_PORT_RECOVERY_STALL
= 10 * UHC_1_MILLISECOND
,
71 // Sync and Async transfer polling interval, set by experience,
72 // and the unit of Async is 100us.
74 UHC_SYNC_POLL_INTERVAL
= 50 * UHC_1_MICROSECOND
,
75 UHC_ASYNC_POLL_INTERVAL
= 50 * 10000UL
76 }UHC_TIMEOUT_EXPERIENCE_VALUE
;
80 // UHC raises TPL to TPL_NOTIFY to serialize all its operations
81 // to protect shared data structures.
83 #define UHCI_TPL TPL_NOTIFY
85 #define USB_HC_DEV_SIGNATURE SIGNATURE_32 ('u', 'h', 'c', 'i')
95 #define UHC_FROM_USB2_HC_PROTO(This) CR(This, USB_HC_DEV, Usb2Hc, USB_HC_DEV_SIGNATURE)
98 // USB_HC_DEV support the UHCI hardware controller. It schedules
99 // the asynchronous interrupt transfer with the same method as
100 // EHCI: a reversed tree structure. For synchronous interrupt,
101 // control and bulk transfer, it uses three static queue head to
102 // schedule them. SyncIntQh is for interrupt transfer. LsCtrlQh is
103 // for LOW speed control transfer, and FsCtrlBulkQh is for FULL
104 // speed control or bulk transfer. This is because FULL speed contrl
105 // or bulk transfer can reclaim the unused bandwidth. Some USB
106 // device requires this bandwidth reclamation capability.
110 EFI_USB2_HC_PROTOCOL Usb2Hc
;
111 EFI_PCI_IO_PROTOCOL
*PciIo
;
112 UINT64 OriginalPciAttributes
;
115 // Schedule data structures
118 UHCI_QH_SW
*SyncIntQh
;
123 // Structures to maintain asynchronus interrupt transfers.
124 // When asynchronous interrutp transfer is unlinked from
125 // the frame list, the hardware may still hold a pointer
126 // to it. To synchronize with hardware, its resoureces are
127 // released in two steps using Recycle and RecycleWait.
128 // Check the asynchronous interrupt management routines.
130 LIST_ENTRY AsyncIntList
;
131 EFI_EVENT AsyncIntMonitor
;
132 UHCI_ASYNC_REQUEST
*Recycle
;
133 UHCI_ASYNC_REQUEST
*RecycleWait
;
137 USBHC_MEM_POOL
*MemPool
;
138 EFI_UNICODE_STRING_TABLE
*CtrlNameTable
;
142 extern EFI_DRIVER_BINDING_PROTOCOL gUhciDriverBinding
;
143 extern EFI_COMPONENT_NAME_PROTOCOL gUhciComponentName
;
144 extern EFI_COMPONENT_NAME2_PROTOCOL gUhciComponentName2
;
147 Test to see if this driver supports ControllerHandle. Any
148 ControllerHandle that has UsbHcProtocol installed will be supported.
150 @param This Protocol instance pointer.
151 @param Controller Handle of device to test.
152 @param RemainingDevicePath Not used.
154 @return EFI_SUCCESS This driver supports this device.
155 @return EFI_UNSUPPORTED This driver does not support this device.
160 UhciDriverBindingSupported (
161 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
162 IN EFI_HANDLE Controller
,
163 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
167 Starting the Usb UHCI Driver.
169 @param This Protocol instance pointer.
170 @param Controller Handle of device to test.
171 @param RemainingDevicePath Not used.
173 @retval EFI_SUCCESS This driver supports this device.
174 @retval EFI_UNSUPPORTED This driver does not support this device.
175 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
176 EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
181 UhciDriverBindingStart (
182 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
183 IN EFI_HANDLE Controller
,
184 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
188 Stop this driver on ControllerHandle. Support stoping any child handles
189 created by this driver.
191 @param This Protocol instance pointer.
192 @param Controller Handle of device to stop driver on.
193 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
194 @param ChildHandleBuffer List of handles for the children we need to stop.
202 UhciDriverBindingStop (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN UINTN NumberOfChildren
,
206 IN EFI_HANDLE
*ChildHandleBuffer