3 Provides some data struct used by EHCI controller driver.
5 Copyright (c) 2006 - 2018, 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.
22 #include <Protocol/Usb2HostController.h>
23 #include <Protocol/PciIo.h>
25 #include <Guid/EventGroup.h>
27 #include <Library/DebugLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/PcdLib.h>
35 #include <Library/ReportStatusCodeLib.h>
37 #include <IndustryStandard/Pci.h>
39 typedef struct _USB2_HC_DEV USB2_HC_DEV
;
44 #include "EhciSched.h"
45 #include "EhciDebug.h"
46 #include "ComponentName.h"
49 // EHC timeout experience values
52 #define EHC_1_MICROSECOND 1
53 #define EHC_1_MILLISECOND (1000 * EHC_1_MICROSECOND)
54 #define EHC_1_SECOND (1000 * EHC_1_MILLISECOND)
57 // EHCI register operation timeout, set by experience
59 #define EHC_RESET_TIMEOUT (1 * EHC_1_SECOND)
60 #define EHC_GENERIC_TIMEOUT (10 * EHC_1_MILLISECOND)
63 // Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9]
65 #define EHC_ROOT_PORT_RECOVERY_STALL (20 * EHC_1_MILLISECOND)
68 // Sync and Async transfer polling interval, set by experience,
69 // and the unit of Async is 100us, means 1ms as interval.
71 #define EHC_SYNC_POLL_INTERVAL (1 * EHC_1_MILLISECOND)
72 #define EHC_ASYNC_POLL_INTERVAL EFI_TIMER_PERIOD_MILLISECONDS(1)
75 // EHCI debug port control status register bit definition
77 #define USB_DEBUG_PORT_IN_USE BIT10
78 #define USB_DEBUG_PORT_ENABLE BIT28
79 #define USB_DEBUG_PORT_OWNER BIT30
80 #define USB_DEBUG_PORT_IN_USE_MASK (USB_DEBUG_PORT_IN_USE | \
84 // EHC raises TPL to TPL_NOTIFY to serialize all its operations
85 // to protect shared data structures.
87 #define EHC_TPL TPL_NOTIFY
90 //Iterate through the double linked list. NOT delete safe
92 #define EFI_LIST_FOR_EACH(Entry, ListHead) \
93 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
96 //Iterate through the double linked list. This is delete-safe.
97 //Don't touch NextEntry
99 #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
100 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\
101 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)
103 #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
106 #define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))
107 #define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
108 #define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
110 #define EHC_REG_BIT_IS_SET(Ehc, Offset, Bit) \
111 (EHC_BIT_IS_SET(EhcReadOpReg ((Ehc), (Offset)), (Bit)))
113 #define USB2_HC_DEV_SIGNATURE SIGNATURE_32 ('e', 'h', 'c', 'i')
114 #define EHC_FROM_THIS(a) CR(a, USB2_HC_DEV, Usb2Hc, USB2_HC_DEV_SIGNATURE)
116 struct _USB2_HC_DEV
{
118 EFI_USB2_HC_PROTOCOL Usb2Hc
;
120 EFI_PCI_IO_PROTOCOL
*PciIo
;
121 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
122 UINT64 OriginalPciAttributes
;
123 USBHC_MEM_POOL
*MemPool
;
126 // Schedule data shared between asynchronous and periodic
128 // ShortReadStop, as its name indicates, is used to terminate
129 // the short read except the control transfer. EHCI follows
130 // the alternative next QTD point when a short read happens.
131 // For control transfer, even the short read happens, try the
134 EHC_QTD
*ShortReadStop
;
138 // ExitBootServicesEvent is used to stop the EHC DMA operation
139 // after exit boot service.
141 EFI_EVENT ExitBootServiceEvent
;
144 // Asynchronous(bulk and control) transfer schedule data:
145 // ReclaimHead is used as the head of the asynchronous transfer
146 // list. It acts as the reclamation header.
151 // Periodic (interrupt) transfer schedule data:
153 VOID
*PeriodFrame
; // the buffer pointed by this pointer is used to store pci bus address of the QH descriptor.
154 VOID
*PeriodFrameHost
; // the buffer pointed by this pointer is used to store host memory address of the QH descriptor.
155 VOID
*PeriodFrameMap
;
158 LIST_ENTRY AsyncIntTransfers
;
161 // EHCI configuration data
163 UINT32 HcStructParams
; // Cache of HC structure parameter, EHC_HCSPARAMS_OFFSET
164 UINT32 HcCapParams
; // Cache of HC capability parameter, HCCPARAMS
165 UINT32 CapLen
; // Capability length
170 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
173 // EHCI debug port info
175 UINT16 DebugPortOffset
; // The offset of debug port mmio register
176 UINT8 DebugPortBarNum
; // The bar number of debug port mmio register
177 UINT8 DebugPortNum
; // The port number of usb debug port
179 BOOLEAN Support64BitDma
; // Whether 64 bit DMA may be used with this device
183 extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding
;
184 extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName
;
185 extern EFI_COMPONENT_NAME2_PROTOCOL gEhciComponentName2
;
188 Test to see if this driver supports ControllerHandle. Any
189 ControllerHandle that has Usb2HcProtocol installed will
192 @param This Protocol instance pointer.
193 @param Controller Handle of device to test.
194 @param RemainingDevicePath Not used.
196 @return EFI_SUCCESS This driver supports this device.
197 @return EFI_UNSUPPORTED This driver does not support this device.
202 EhcDriverBindingSupported (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
209 Starting the Usb EHCI Driver.
211 @param This Protocol instance pointer.
212 @param Controller Handle of device to test.
213 @param RemainingDevicePath Not used.
215 @return EFI_SUCCESS supports this device.
216 @return EFI_UNSUPPORTED do not support this device.
217 @return EFI_DEVICE_ERROR cannot be started due to device Error.
218 @return EFI_OUT_OF_RESOURCES cannot allocate resources.
223 EhcDriverBindingStart (
224 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
225 IN EFI_HANDLE Controller
,
226 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
230 Stop this driver on ControllerHandle. Support stopping any child handles
231 created by this driver.
233 @param This Protocol instance pointer.
234 @param Controller Handle of device to stop driver on.
235 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
236 @param ChildHandleBuffer List of handles for the children we need to stop.
238 @return EFI_SUCCESS Success.
239 @return EFI_DEVICE_ERROR Fail.
244 EhcDriverBindingStop (
245 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
246 IN EFI_HANDLE Controller
,
247 IN UINTN NumberOfChildren
,
248 IN EFI_HANDLE
*ChildHandleBuffer