1 /** @file 2 3 Provides some data struct used by EHCI controller driver. 4 5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> 6 Copyright (c) Microsoft Corporation.<BR> 7 SPDX-License-Identifier: BSD-2-Clause-Patent 8 9 **/ 10 11 #ifndef _EFI_EHCI_H_ 12 #define _EFI_EHCI_H_ 13 14 15 #include <Uefi.h> 16 17 #include <Protocol/Usb2HostController.h> 18 #include <Protocol/PciIo.h> 19 20 #include <Guid/EventGroup.h> 21 22 #include <Library/DebugLib.h> 23 #include <Library/BaseMemoryLib.h> 24 #include <Library/UefiDriverEntryPoint.h> 25 #include <Library/UefiBootServicesTableLib.h> 26 #include <Library/UefiLib.h> 27 #include <Library/BaseLib.h> 28 #include <Library/MemoryAllocationLib.h> 29 #include <Library/PcdLib.h> 30 #include <Library/ReportStatusCodeLib.h> 31 32 #include <IndustryStandard/Pci.h> 33 34 typedef struct _USB2_HC_DEV USB2_HC_DEV; 35 36 #include "UsbHcMem.h" 37 #include "EhciReg.h" 38 #include "EhciUrb.h" 39 #include "EhciSched.h" 40 #include "EhciDebug.h" 41 #include "ComponentName.h" 42 43 // 44 // EHC timeout experience values 45 // 46 47 #define EHC_1_MICROSECOND 1 48 #define EHC_1_MILLISECOND (1000 * EHC_1_MICROSECOND) 49 #define EHC_1_SECOND (1000 * EHC_1_MILLISECOND) 50 51 // 52 // EHCI register operation timeout, set by experience 53 // 54 #define EHC_RESET_TIMEOUT (1 * EHC_1_SECOND) 55 #define EHC_GENERIC_TIMEOUT (10 * EHC_1_MILLISECOND) 56 57 // 58 // Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9] 59 // 60 #define EHC_ROOT_PORT_RECOVERY_STALL (20 * EHC_1_MILLISECOND) 61 62 // 63 // Sync and Async transfer polling interval, set by experience, 64 // and the unit of Async is 100us, means 1ms as interval. 65 // 66 #define EHC_SYNC_POLL_INTERVAL (1 * EHC_1_MILLISECOND) 67 #define EHC_ASYNC_POLL_INTERVAL EFI_TIMER_PERIOD_MILLISECONDS(1) 68 69 // 70 // EHCI debug port control status register bit definition 71 // 72 #define USB_DEBUG_PORT_IN_USE BIT10 73 #define USB_DEBUG_PORT_ENABLE BIT28 74 #define USB_DEBUG_PORT_OWNER BIT30 75 #define USB_DEBUG_PORT_IN_USE_MASK (USB_DEBUG_PORT_IN_USE | \ 76 USB_DEBUG_PORT_OWNER) 77 78 // 79 // EHC raises TPL to TPL_NOTIFY to serialize all its operations 80 // to protect shared data structures. 81 // 82 #define EHC_TPL TPL_NOTIFY 83 84 #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field) 85 86 87 #define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF)) 88 #define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF)) 89 #define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit))) 90 91 #define EHC_REG_BIT_IS_SET(Ehc, Offset, Bit) \ 92 (EHC_BIT_IS_SET(EhcReadOpReg ((Ehc), (Offset)), (Bit))) 93 94 #define USB2_HC_DEV_SIGNATURE SIGNATURE_32 ('e', 'h', 'c', 'i') 95 #define EHC_FROM_THIS(a) CR(a, USB2_HC_DEV, Usb2Hc, USB2_HC_DEV_SIGNATURE) 96 97 struct _USB2_HC_DEV { 98 UINTN Signature; 99 EFI_USB2_HC_PROTOCOL Usb2Hc; 100 101 EFI_PCI_IO_PROTOCOL *PciIo; 102 EFI_DEVICE_PATH_PROTOCOL *DevicePath; 103 UINT64 OriginalPciAttributes; 104 USBHC_MEM_POOL *MemPool; 105 106 // 107 // Schedule data shared between asynchronous and periodic 108 // transfers: 109 // ShortReadStop, as its name indicates, is used to terminate 110 // the short read except the control transfer. EHCI follows 111 // the alternative next QTD point when a short read happens. 112 // For control transfer, even the short read happens, try the 113 // status stage. 114 // 115 EHC_QTD *ShortReadStop; 116 EFI_EVENT PollTimer; 117 118 // 119 // ExitBootServicesEvent is used to stop the EHC DMA operation 120 // after exit boot service. 121 // 122 EFI_EVENT ExitBootServiceEvent; 123 124 // 125 // Asynchronous(bulk and control) transfer schedule data: 126 // ReclaimHead is used as the head of the asynchronous transfer 127 // list. It acts as the reclamation header. 128 // 129 EHC_QH *ReclaimHead; 130 131 // 132 // Periodic (interrupt) transfer schedule data: 133 // 134 VOID *PeriodFrame; // the buffer pointed by this pointer is used to store pci bus address of the QH descriptor. 135 VOID *PeriodFrameHost; // the buffer pointed by this pointer is used to store host memory address of the QH descriptor. 136 VOID *PeriodFrameMap; 137 138 EHC_QH *PeriodOne; 139 LIST_ENTRY AsyncIntTransfers; 140 141 // 142 // EHCI configuration data 143 // 144 UINT32 HcStructParams; // Cache of HC structure parameter, EHC_HCSPARAMS_OFFSET 145 UINT32 HcCapParams; // Cache of HC capability parameter, HCCPARAMS 146 UINT32 CapLen; // Capability length 147 148 // 149 // Misc 150 // 151 EFI_UNICODE_STRING_TABLE *ControllerNameTable; 152 153 // 154 // EHCI debug port info 155 // 156 UINT16 DebugPortOffset; // The offset of debug port mmio register 157 UINT8 DebugPortBarNum; // The bar number of debug port mmio register 158 UINT8 DebugPortNum; // The port number of usb debug port 159 160 BOOLEAN Support64BitDma; // Whether 64 bit DMA may be used with this device 161 }; 162 163 164 extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding; 165 extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName; 166 extern EFI_COMPONENT_NAME2_PROTOCOL gEhciComponentName2; 167 168 /** 169 Test to see if this driver supports ControllerHandle. Any 170 ControllerHandle that has Usb2HcProtocol installed will 171 be supported. 172 173 @param This Protocol instance pointer. 174 @param Controller Handle of device to test. 175 @param RemainingDevicePath Not used. 176 177 @return EFI_SUCCESS This driver supports this device. 178 @return EFI_UNSUPPORTED This driver does not support this device. 179 180 **/ 181 EFI_STATUS 182 EFIAPI 183 EhcDriverBindingSupported ( 184 IN EFI_DRIVER_BINDING_PROTOCOL *This, 185 IN EFI_HANDLE Controller, 186 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 187 ); 188 189 /** 190 Starting the Usb EHCI Driver. 191 192 @param This Protocol instance pointer. 193 @param Controller Handle of device to test. 194 @param RemainingDevicePath Not used. 195 196 @return EFI_SUCCESS supports this device. 197 @return EFI_UNSUPPORTED do not support this device. 198 @return EFI_DEVICE_ERROR cannot be started due to device Error. 199 @return EFI_OUT_OF_RESOURCES cannot allocate resources. 200 201 **/ 202 EFI_STATUS 203 EFIAPI 204 EhcDriverBindingStart ( 205 IN EFI_DRIVER_BINDING_PROTOCOL *This, 206 IN EFI_HANDLE Controller, 207 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 208 ); 209 210 /** 211 Stop this driver on ControllerHandle. Support stopping any child handles 212 created by this driver. 213 214 @param This Protocol instance pointer. 215 @param Controller Handle of device to stop driver on. 216 @param NumberOfChildren Number of Children in the ChildHandleBuffer. 217 @param ChildHandleBuffer List of handles for the children we need to stop. 218 219 @return EFI_SUCCESS Success. 220 @return EFI_DEVICE_ERROR Fail. 221 222 **/ 223 EFI_STATUS 224 EFIAPI 225 EhcDriverBindingStop ( 226 IN EFI_DRIVER_BINDING_PROTOCOL *This, 227 IN EFI_HANDLE Controller, 228 IN UINTN NumberOfChildren, 229 IN EFI_HANDLE *ChildHandleBuffer 230 ); 231 232 #endif 233 234