3 Provides some data structure definitions used by the XHCI host controller driver.
5 Copyright (c) 2011, 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.
21 #include <Protocol/Usb2HostController.h>
22 #include <Protocol/PciIo.h>
24 #include <Guid/EventGroup.h>
26 #include <Library/BaseLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/PcdLib.h>
33 #include <Library/DebugLib.h>
35 #include <IndustryStandard/Pci.h>
37 typedef struct _USB_XHCI_DEV USB_XHCI_DEV
;
38 typedef struct _USB_DEV_CONTEXT USB_DEV_CONTEXT
;
41 #include "XhciSched.h"
42 #include "ComponentName.h"
45 // XHC timeout experience values
47 #define XHC_1_MICROSECOND 1
48 #define XHC_1_MILLISECOND (1000 * XHC_1_MICROSECOND)
49 #define XHC_1_SECOND (1000 * XHC_1_MILLISECOND)
52 // XHCI register operation timeout, set by experience
54 #define XHC_RESET_TIMEOUT (1 * XHC_1_SECOND)
55 #define XHC_GENERIC_TIMEOUT (10 * XHC_1_MILLISECOND)
58 // Wait for roothub port power stable, refers to Spec[XHCI1.0-2.3.9]
60 #define XHC_ROOT_PORT_RECOVERY_STALL (20 * XHC_1_MILLISECOND)
63 // Sync and Async transfer polling interval, set by experience,
64 // and the unit of Async is 100us, means 50ms as interval.
66 #define XHC_SYNC_POLL_INTERVAL (20 * XHC_1_MILLISECOND)
67 #define XHC_ASYNC_POLL_INTERVAL (50 * 10000U)
70 // XHC raises TPL to TPL_NOTIFY to serialize all its operations
71 // to protect shared data structures.
73 #define XHC_TPL TPL_NOTIFY
75 #define CMD_RING_TRB_NUMBER 0x40
76 #define TR_RING_TRB_NUMBER 0x40
77 #define ERST_NUMBER 0x01
78 #define EVENT_RING_TRB_NUMBER 0x80
84 #define INT_INTER_ASYNC 4
87 // Iterate through the doule linked list. This is delete-safe.
88 // Don't touch NextEntry
90 #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
91 for (Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\
92 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)
94 #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
96 #define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0xFFFFFFFF))
97 #define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0xFFFFFFFF))
98 #define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
100 #define XHC_REG_BIT_IS_SET(Xhc, Offset, Bit) \
101 (XHC_BIT_IS_SET(XhcReadOpReg ((Xhc), (Offset)), (Bit)))
103 #define XHCI_IS_DATAIN(EndpointAddr) XHC_BIT_IS_SET((EndpointAddr), 0x80)
105 #define USB_XHCI_DEV_SIGNATURE SIGNATURE_32 ('x', 'h', 'c', 'i')
106 #define XHC_FROM_THIS(a) CR(a, USB_XHCI_DEV, Usb2Hc, USB_XHCI_DEV_SIGNATURE)
108 #define USB_DESC_TYPE_HUB 0x29
109 #define USB_DESC_TYPE_HUB_SUPER_SPEED 0x2a
112 // Xhci Data and Ctrl Structures
127 UINT8 HubContrCurrent
;
129 } EFI_USB_HUB_DESCRIPTOR
;
132 struct _USB_XHCI_DEV
{
134 EFI_PCI_IO_PROTOCOL
*PciIo
;
135 UINT64 OriginalPciAttributes
;
137 EFI_USB2_HC_PROTOCOL Usb2Hc
;
139 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
142 // ExitBootServicesEvent is used to set OS semaphore and
143 // stop the XHC DMA operation after exit boot service.
145 EFI_EVENT ExitBootServiceEvent
;
147 LIST_ENTRY AsyncIntTransfers
;
149 UINT8 CapLength
; ///< Capability Register Length
150 XHC_HCSPARAMS1 HcSParams1
; ///< Structural Parameters 1
151 XHC_HCSPARAMS2 HcSParams2
; ///< Structural Parameters 2
152 XHC_HCCPARAMS HcCParams
; ///< Capability Parameters
153 UINT32 DBOff
; ///< Doorbell Offset
154 UINT32 RTSOff
; ///< Runtime Register Space Offset
158 UINT32 MaxScratchpadBufs
;
159 UINT32 ExtCapRegBase
;
160 UINT32 UsbLegSupOffset
;
166 TRANSFER_RING CmdRing
;
170 EVENT_RING CmdEventRing
;
172 // ControlTREventRing
174 EVENT_RING CtrlTrEventRing
;
178 EVENT_RING BulkTrEventRing
;
182 EVENT_RING IntTrEventRing
;
184 // AsyncIntTREventRing
186 EVENT_RING AsynIntTrEventRing
;
190 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
194 struct _USB_DEV_CONTEXT
{
196 // Whether this entry in UsbDevContext array is used or not.
200 // The slot id assigned to the new device through XHCI's Enable_Slot cmd.
204 // The route string presented an attached usb device.
206 USB_DEV_ROUTE RouteString
;
208 // The route string of parent device if it exists. Otherwise it's zero.
210 USB_DEV_ROUTE ParentRouteString
;
212 // The actual device address assigned by XHCI through Address_Device command.
216 // The requested device address from UsbBus driver through Set_Address standard usb request.
217 // As XHCI spec replaces this request with Address_Device command, we have to record the
218 // requested device address and establish a mapping relationship with the actual device address.
219 // Then UsbBus driver just need to be aware of the requested device address to access usb device
220 // through EFI_USB2_HC_PROTOCOL. Xhci driver would be responsible for translating it to actual
221 // device address and access the actual device.
225 // The pointer to the input device context.
229 // The pointer to the output device context.
231 VOID
*OutputDevContxt
;
233 // The transfer queue for every endpoint.
235 VOID
*EndpointTransferRing
[31];
237 // The device descriptor which is stored to support XHCI's Evaluate_Context cmd.
239 EFI_USB_DEVICE_DESCRIPTOR DevDesc
;
241 // As a usb device may include multiple configuration descriptors, we dynamically allocate an array
243 // Note that every configuration descriptor stored here includes those lower level descriptors,
244 // such as Interface descriptor, Endpoint descriptor, and so on.
245 // These information is used to support XHCI's Config_Endpoint cmd.
247 EFI_USB_CONFIG_DESCRIPTOR
**ConfDesc
;
250 extern EFI_DRIVER_BINDING_PROTOCOL gXhciDriverBinding
;
251 extern EFI_COMPONENT_NAME_PROTOCOL gXhciComponentName
;
252 extern EFI_COMPONENT_NAME2_PROTOCOL gXhciComponentName2
;
253 extern USB_DEV_CONTEXT UsbDevContext
[];
256 Test to see if this driver supports ControllerHandle. Any
257 ControllerHandle that has Usb2HcProtocol installed will
260 @param This Protocol instance pointer.
261 @param Controller Handle of device to test.
262 @param RemainingDevicePath Not used.
264 @return EFI_SUCCESS This driver supports this device.
265 @return EFI_UNSUPPORTED This driver does not support this device.
270 XhcDriverBindingSupported (
271 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
272 IN EFI_HANDLE Controller
,
273 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
277 Starting the Usb XHCI Driver.
279 @param This Protocol instance pointer.
280 @param Controller Handle of device to test.
281 @param RemainingDevicePath Not used.
283 @return EFI_SUCCESS supports this device.
284 @return EFI_UNSUPPORTED do not support this device.
285 @return EFI_DEVICE_ERROR cannot be started due to device Error.
286 @return EFI_OUT_OF_RESOURCES cannot allocate resources.
291 XhcDriverBindingStart (
292 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
293 IN EFI_HANDLE Controller
,
294 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
298 Stop this driver on ControllerHandle. Support stoping any child handles
299 created by this driver.
301 @param This Protocol instance pointer.
302 @param Controller Handle of device to stop driver on.
303 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
304 @param ChildHandleBuffer List of handles for the children we need to stop.
306 @return EFI_SUCCESS Success.
307 @return EFI_DEVICE_ERROR Fail.
312 XhcDriverBindingStop (
313 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
314 IN EFI_HANDLE Controller
,
315 IN UINTN NumberOfChildren
,
316 IN EFI_HANDLE
*ChildHandleBuffer
320 Sets a feature for the specified root hub port.
322 @param This This EFI_USB2_HC_PROTOCOL instance.
323 @param PortNumber Root hub port to set.
324 @param PortFeature Feature to set.
326 @retval EFI_SUCCESS The feature specified by PortFeature was set.
327 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
328 @retval EFI_DEVICE_ERROR Can't read register.
333 XhcSetRootHubPortFeature (
334 IN EFI_USB2_HC_PROTOCOL
*This
,
336 IN EFI_USB_PORT_FEATURE PortFeature
340 Clears a feature for the specified root hub port.
342 @param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
343 @param PortNumber Specifies the root hub port whose feature is
344 requested to be cleared.
345 @param PortFeature Indicates the feature selector associated with the
346 feature clear request.
348 @retval EFI_SUCCESS The feature specified by PortFeature was cleared
349 for the USB root hub port specified by PortNumber.
350 @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
351 @retval EFI_DEVICE_ERROR Can't read register.
356 XhcClearRootHubPortFeature (
357 IN EFI_USB2_HC_PROTOCOL
*This
,
359 IN EFI_USB_PORT_FEATURE PortFeature