3 Provides some data struct used by EHCI controller driver.
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Protocol/Usb2HostController.h>
17 #include <Protocol/PciIo.h>
19 #include <Guid/EventGroup.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/PcdLib.h>
29 #include <Library/ReportStatusCodeLib.h>
31 #include <IndustryStandard/Pci.h>
33 typedef struct _USB2_HC_DEV USB2_HC_DEV
;
38 #include "EhciSched.h"
39 #include "EhciDebug.h"
40 #include "ComponentName.h"
43 // EHC timeout experience values
46 #define EHC_1_MICROSECOND 1
47 #define EHC_1_MILLISECOND (1000 * EHC_1_MICROSECOND)
48 #define EHC_1_SECOND (1000 * EHC_1_MILLISECOND)
51 // EHCI register operation timeout, set by experience
53 #define EHC_RESET_TIMEOUT (1 * EHC_1_SECOND)
54 #define EHC_GENERIC_TIMEOUT (10 * EHC_1_MILLISECOND)
57 // Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9]
59 #define EHC_ROOT_PORT_RECOVERY_STALL (20 * EHC_1_MILLISECOND)
62 // Sync and Async transfer polling interval, set by experience,
63 // and the unit of Async is 100us, means 1ms as interval.
65 #define EHC_SYNC_POLL_INTERVAL (1 * EHC_1_MILLISECOND)
66 #define EHC_ASYNC_POLL_INTERVAL EFI_TIMER_PERIOD_MILLISECONDS(1)
69 // EHCI debug port control status register bit definition
71 #define USB_DEBUG_PORT_IN_USE BIT10
72 #define USB_DEBUG_PORT_ENABLE BIT28
73 #define USB_DEBUG_PORT_OWNER BIT30
74 #define USB_DEBUG_PORT_IN_USE_MASK (USB_DEBUG_PORT_IN_USE | \
78 // EHC raises TPL to TPL_NOTIFY to serialize all its operations
79 // to protect shared data structures.
81 #define EHC_TPL TPL_NOTIFY
84 //Iterate through the double linked list. NOT delete safe
86 #define EFI_LIST_FOR_EACH(Entry, ListHead) \
87 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
90 //Iterate through the double linked list. This is delete-safe.
91 //Don't touch NextEntry
93 #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
94 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\
95 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)
97 #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
100 #define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))
101 #define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
102 #define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
104 #define EHC_REG_BIT_IS_SET(Ehc, Offset, Bit) \
105 (EHC_BIT_IS_SET(EhcReadOpReg ((Ehc), (Offset)), (Bit)))
107 #define USB2_HC_DEV_SIGNATURE SIGNATURE_32 ('e', 'h', 'c', 'i')
108 #define EHC_FROM_THIS(a) CR(a, USB2_HC_DEV, Usb2Hc, USB2_HC_DEV_SIGNATURE)
110 struct _USB2_HC_DEV
{
112 EFI_USB2_HC_PROTOCOL Usb2Hc
;
114 EFI_PCI_IO_PROTOCOL
*PciIo
;
115 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
116 UINT64 OriginalPciAttributes
;
117 USBHC_MEM_POOL
*MemPool
;
120 // Schedule data shared between asynchronous and periodic
122 // ShortReadStop, as its name indicates, is used to terminate
123 // the short read except the control transfer. EHCI follows
124 // the alternative next QTD point when a short read happens.
125 // For control transfer, even the short read happens, try the
128 EHC_QTD
*ShortReadStop
;
132 // ExitBootServicesEvent is used to stop the EHC DMA operation
133 // after exit boot service.
135 EFI_EVENT ExitBootServiceEvent
;
138 // Asynchronous(bulk and control) transfer schedule data:
139 // ReclaimHead is used as the head of the asynchronous transfer
140 // list. It acts as the reclamation header.
145 // Periodic (interrupt) transfer schedule data:
147 VOID
*PeriodFrame
; // the buffer pointed by this pointer is used to store pci bus address of the QH descriptor.
148 VOID
*PeriodFrameHost
; // the buffer pointed by this pointer is used to store host memory address of the QH descriptor.
149 VOID
*PeriodFrameMap
;
152 LIST_ENTRY AsyncIntTransfers
;
155 // EHCI configuration data
157 UINT32 HcStructParams
; // Cache of HC structure parameter, EHC_HCSPARAMS_OFFSET
158 UINT32 HcCapParams
; // Cache of HC capability parameter, HCCPARAMS
159 UINT32 CapLen
; // Capability length
164 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
167 // EHCI debug port info
169 UINT16 DebugPortOffset
; // The offset of debug port mmio register
170 UINT8 DebugPortBarNum
; // The bar number of debug port mmio register
171 UINT8 DebugPortNum
; // The port number of usb debug port
173 BOOLEAN Support64BitDma
; // Whether 64 bit DMA may be used with this device
177 extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding
;
178 extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName
;
179 extern EFI_COMPONENT_NAME2_PROTOCOL gEhciComponentName2
;
182 Test to see if this driver supports ControllerHandle. Any
183 ControllerHandle that has Usb2HcProtocol installed will
186 @param This Protocol instance pointer.
187 @param Controller Handle of device to test.
188 @param RemainingDevicePath Not used.
190 @return EFI_SUCCESS This driver supports this device.
191 @return EFI_UNSUPPORTED This driver does not support this device.
196 EhcDriverBindingSupported (
197 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
198 IN EFI_HANDLE Controller
,
199 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
203 Starting the Usb EHCI Driver.
205 @param This Protocol instance pointer.
206 @param Controller Handle of device to test.
207 @param RemainingDevicePath Not used.
209 @return EFI_SUCCESS supports this device.
210 @return EFI_UNSUPPORTED do not support this device.
211 @return EFI_DEVICE_ERROR cannot be started due to device Error.
212 @return EFI_OUT_OF_RESOURCES cannot allocate resources.
217 EhcDriverBindingStart (
218 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
219 IN EFI_HANDLE Controller
,
220 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
224 Stop this driver on ControllerHandle. Support stopping any child handles
225 created by this driver.
227 @param This Protocol instance pointer.
228 @param Controller Handle of device to stop driver on.
229 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
230 @param ChildHandleBuffer List of handles for the children we need to stop.
232 @return EFI_SUCCESS Success.
233 @return EFI_DEVICE_ERROR Fail.
238 EhcDriverBindingStop (
239 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
240 IN EFI_HANDLE Controller
,
241 IN UINTN NumberOfChildren
,
242 IN EFI_HANDLE
*ChildHandleBuffer