TianoCore EDK2 master
Loading...
Searching...
No Matches
Xhci.h
Go to the documentation of this file.
1
12#ifndef _EFI_XHCI_H_
13#define _EFI_XHCI_H_
14
15#include <Uefi.h>
16
18#include <Protocol/PciIo.h>
19
20#include <Guid/EventGroup.h>
21
22#include <Library/BaseLib.h>
27#include <Library/UefiLib.h>
28#include <Library/DebugLib.h>
30#include <Library/TimerLib.h>
31#include <Library/PcdLib.h>
32
34
37
38#include "XhciReg.h"
39#include "XhciSched.h"
40#include "ComponentName.h"
41#include "UsbHcMem.h"
42
43//
44// Converts a count from microseconds to nanoseconds
45//
46#define XHC_MICROSECOND_TO_NANOSECOND(Time) (MultU64x32((Time), 1000))
47
48//
49// The unit is microsecond, setting it as 1us.
50//
51#define XHC_1_MICROSECOND (1)
52//
53// The unit is microsecond, setting it as 1ms.
54//
55#define XHC_1_MILLISECOND (1000)
56//
57// XHC generic timeout experience values.
58// The unit is millisecond, setting it as 10s.
59//
60#define XHC_GENERIC_TIMEOUT (10 * 1000)
61//
62// XHC reset timeout experience values.
63// The unit is millisecond, setting it as 1s.
64//
65#define XHC_RESET_TIMEOUT (1000)
66//
67// TRSTRCY delay requirement in usb 2.0 spec chapter 7.1.7.5.
68// The unit is microsecond, setting it as 10ms.
69//
70#define XHC_RESET_RECOVERY_DELAY (10 * 1000)
71//
72// XHC async transfer timer interval, set by experience.
73// The unit is 100us, takes 1ms as interval.
74//
75#define XHC_ASYNC_TIMER_INTERVAL EFI_TIMER_PERIOD_MILLISECONDS(1)
76
77//
78// XHC raises TPL to TPL_NOTIFY to serialize all its operations
79// to protect shared data structures.
80//
81#define XHC_TPL TPL_NOTIFY
82
83#define CMD_RING_TRB_NUMBER 0x100
84#define TR_RING_TRB_NUMBER 0x100
85#define ERST_NUMBER 0x01
86#define EVENT_RING_TRB_NUMBER 0x200
87
88#define CMD_INTER 0
89#define CTRL_INTER 1
90#define BULK_INTER 2
91#define INT_INTER 3
92#define INT_INTER_ASYNC 4
93
94#define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
95
96#define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0xFFFFFFFF))
97#define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINT64)(UINTN)(Addr64), 32) & 0xFFFFFFFF))
98#define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
99
100#define XHC_REG_BIT_IS_SET(Xhc, Offset, Bit) \
101 (XHC_BIT_IS_SET(XhcReadOpReg ((Xhc), (Offset)), (Bit)))
102
103#define XHCI_IS_DATAIN(EndpointAddr) XHC_BIT_IS_SET((EndpointAddr), 0x80)
104
105#define XHCI_INSTANCE_SIG SIGNATURE_32 ('x', 'h', 'c', 'i')
106#define XHC_FROM_THIS(a) CR(a, USB_XHCI_INSTANCE, Usb2Hc, XHCI_INSTANCE_SIG)
107
108#define USB_DESC_TYPE_HUB 0x29
109#define USB_DESC_TYPE_HUB_SUPER_SPEED 0x2a
110
111//
112// The RequestType in EFI_USB_DEVICE_REQUEST is composed of
113// three fields: One bit direction, 2 bit type, and 5 bit
114// target.
115//
116#define USB_REQUEST_TYPE(Dir, Type, Target) \
117 ((UINT8)((((Dir) == EfiUsbDataIn ? 0x01 : 0) << 7) | (Type) | (Target)))
118
119//
120// Xhci Data and Ctrl Structures
121//
122#pragma pack(1)
123typedef struct {
124 UINT8 ProgInterface;
125 UINT8 SubClassCode;
126 UINT8 BaseCode;
127} USB_CLASSC;
128
129typedef struct {
130 UINT8 Length;
131 UINT8 DescType;
132 UINT8 NumPorts;
133 UINT16 HubCharacter;
134 UINT8 PwrOn2PwrGood;
135 UINT8 HubContrCurrent;
136 UINT8 Filler[16];
138#pragma pack()
139
141 //
142 // Whether this entry in UsbDevContext array is used or not.
143 //
144 BOOLEAN Enabled;
145 //
146 // The slot id assigned to the new device through XHCI's Enable_Slot cmd.
147 //
148 UINT8 SlotId;
149 //
150 // The route string presented an attached usb device.
151 //
152 USB_DEV_ROUTE RouteString;
153 //
154 // The route string of parent device if it exists. Otherwise it's zero.
155 //
156 USB_DEV_ROUTE ParentRouteString;
157 //
158 // The actual device address assigned by XHCI through Address_Device command.
159 //
160 UINT8 XhciDevAddr;
161 //
162 // The requested device address from UsbBus driver through Set_Address standard usb request.
163 // As XHCI spec replaces this request with Address_Device command, we have to record the
164 // requested device address and establish a mapping relationship with the actual device address.
165 // Then UsbBus driver just need to be aware of the requested device address to access usb device
166 // through EFI_USB2_HC_PROTOCOL. Xhci driver would be responsible for translating it to actual
167 // device address and access the actual device.
168 //
169 UINT8 BusDevAddr;
170 //
171 // The pointer to the input device context.
172 //
173 VOID *InputContext;
174 //
175 // The pointer to the output device context.
176 //
177 VOID *OutputContext;
178 //
179 // The transfer queue for every endpoint.
180 //
181 VOID *EndpointTransferRing[31];
182 //
183 // The device descriptor which is stored to support XHCI's Evaluate_Context cmd.
184 //
186 //
187 // As a usb device may include multiple configuration descriptors, we dynamically allocate an array
188 // to store them.
189 // Note that every configuration descriptor stored here includes those lower level descriptors,
190 // such as Interface descriptor, Endpoint descriptor, and so on.
191 // These information is used to support XHCI's Config_Endpoint cmd.
192 //
193 EFI_USB_CONFIG_DESCRIPTOR **ConfDesc;
194 //
195 // A device has an active Configuration.
196 //
197 UINT8 ActiveConfiguration;
198 //
199 // Every interface has an active AlternateSetting.
200 //
201 UINT8 *ActiveAlternateSetting;
202};
203
205 UINT32 Signature;
206 EFI_PCI_IO_PROTOCOL *PciIo;
207 UINT64 OriginalPciAttributes;
208 USBHC_MEM_POOL *MemPool;
209
211
212 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
213
214 //
215 // ExitBootServicesEvent is used to set OS semaphore and
216 // stop the XHC DMA operation after exit boot service.
217 //
218 EFI_EVENT ExitBootServiceEvent;
219 EFI_EVENT PollTimer;
220 LIST_ENTRY AsyncIntTransfers;
221
222 UINT8 CapLength;
226 UINT32 DBOff;
227 UINT32 RTSOff;
228 UINT16 MaxInterrupt;
229 UINT32 PageSize;
230 UINT64 *ScratchBuf;
231 VOID *ScratchMap;
232 UINT32 MaxScratchpadBufs;
233 UINT64 *ScratchEntry;
234 UINTN *ScratchEntryMap;
235 UINT32 ExtCapRegBase;
236 UINT32 UsbLegSupOffset;
237 UINT32 DebugCapSupOffset;
238 UINT32 Usb2SupOffset;
239 UINT32 Usb3SupOffset;
240 UINT64 *DCBAA;
241 VOID *DCBAAMap;
242 UINT32 MaxSlotsEn;
243 URB *PendingUrb;
244 //
245 // Cmd Transfer Ring
246 //
247 TRANSFER_RING CmdRing;
248 //
249 // EventRing
250 //
251 EVENT_RING EventRing;
252 //
253 // Misc
254 //
255 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
256
257 //
258 // Store device contexts managed by XHCI instance
259 // The array supports up to 255 devices, entry 0 is reserved and should not be used.
260 //
261 USB_DEV_CONTEXT UsbDevContext[256];
262
263 BOOLEAN Support64BitDma; // Whether 64 bit DMA may be used with this device
264};
265
266extern EFI_DRIVER_BINDING_PROTOCOL gXhciDriverBinding;
267extern EFI_COMPONENT_NAME_PROTOCOL gXhciComponentName;
268extern EFI_COMPONENT_NAME2_PROTOCOL gXhciComponentName2;
269
284EFIAPI
287 IN EFI_HANDLE Controller,
288 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
289 );
290
305EFIAPI
308 IN EFI_HANDLE Controller,
309 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
310 );
311
326EFIAPI
329 IN EFI_HANDLE Controller,
330 IN UINTN NumberOfChildren,
331 IN EFI_HANDLE *ChildHandleBuffer
332 );
333
348EFIAPI
351 OUT UINT8 *MaxSpeed,
352 OUT UINT8 *PortNumber,
353 OUT UINT8 *Is64BitCapable
354 );
355
370EFIAPI
371XhcReset (
373 IN UINT16 Attributes
374 );
375
390EFIAPI
393 OUT EFI_USB_HC_STATE *State
394 );
395
409EFIAPI
412 IN EFI_USB_HC_STATE State
413 );
414
430EFIAPI
433 IN UINT8 PortNumber,
434 OUT EFI_USB_PORT_STATUS *PortStatus
435 );
436
450EFIAPI
453 IN UINT8 PortNumber,
454 IN EFI_USB_PORT_FEATURE PortFeature
455 );
456
473EFIAPI
476 IN UINT8 PortNumber,
477 IN EFI_USB_PORT_FEATURE PortFeature
478 );
479
505EFIAPI
508 IN UINT8 DeviceAddress,
509 IN UINT8 DeviceSpeed,
510 IN UINTN MaximumPacketLength,
511 IN EFI_USB_DEVICE_REQUEST *Request,
512 IN EFI_USB_DATA_DIRECTION TransferDirection,
513 IN OUT VOID *Data,
514 IN OUT UINTN *DataLength,
515 IN UINTN Timeout,
517 OUT UINT32 *TransferResult
518 );
519
551EFIAPI
554 IN UINT8 DeviceAddress,
555 IN UINT8 EndPointAddress,
556 IN UINT8 DeviceSpeed,
557 IN UINTN MaximumPacketLength,
558 IN UINT8 DataBuffersNumber,
559 IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM],
560 IN OUT UINTN *DataLength,
561 IN OUT UINT8 *DataToggle,
562 IN UINTN Timeout,
564 OUT UINT32 *TransferResult
565 );
566
597EFIAPI
600 IN UINT8 DeviceAddress,
601 IN UINT8 EndPointAddress,
602 IN UINT8 DeviceSpeed,
603 IN UINTN MaximumPacketLength,
604 IN BOOLEAN IsNewTransfer,
605 IN OUT UINT8 *DataToggle,
606 IN UINTN PollingInterval,
607 IN UINTN DataLength,
609 IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction,
610 IN VOID *Context OPTIONAL
611 );
612
641EFIAPI
644 IN UINT8 DeviceAddress,
645 IN UINT8 EndPointAddress,
646 IN UINT8 DeviceSpeed,
647 IN UINTN MaximumPacketLength,
648 IN OUT VOID *Data,
649 IN OUT UINTN *DataLength,
650 IN OUT UINT8 *DataToggle,
651 IN UINTN Timeout,
653 OUT UINT32 *TransferResult
654 );
655
678EFIAPI
681 IN UINT8 DeviceAddress,
682 IN UINT8 EndPointAddress,
683 IN UINT8 DeviceSpeed,
684 IN UINTN MaximumPacketLength,
685 IN UINT8 DataBuffersNumber,
686 IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM],
687 IN UINTN DataLength,
689 OUT UINT32 *TransferResult
690 );
691
716EFIAPI
719 IN UINT8 DeviceAddress,
720 IN UINT8 EndPointAddress,
721 IN UINT8 DeviceSpeed,
722 IN UINTN MaximumPacketLength,
723 IN UINT8 DataBuffersNumber,
724 IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM],
725 IN UINTN DataLength,
727 IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack,
728 IN VOID *Context
729 );
730
737UINT64
739 UINT64 Time
740 );
741
751UINT64
753 IN OUT UINT64 *PreviousTick
754 );
755
756#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_USB_PORT_FEATURE
EFI_USB_HC_STATE
EFI_USB_DATA_DIRECTION
Definition: UsbIo.h:44
EFI_STATUS(EFIAPI * EFI_ASYNC_USB_TRANSFER_CALLBACK)(IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Status)
Definition: UsbIo.h:80
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_STATUS EFIAPI XhcDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: Xhci.c:1725
EFI_STATUS EFIAPI XhcSetRootHubPortFeature(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 PortNumber, IN EFI_USB_PORT_FEATURE PortFeature)
Definition: Xhci.c:510
EFI_STATUS EFIAPI XhcReset(IN EFI_USB2_HC_PROTOCOL *This, IN UINT16 Attributes)
Definition: Xhci.c:151
EFI_STATUS EFIAPI XhcAsyncIsochronousTransfer(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, IN UINT8 DeviceSpeed, IN UINTN MaximumPacketLength, IN UINT8 DataBuffersNumber, IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], IN UINTN DataLength, IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, IN VOID *Context)
Definition: Xhci.c:1666
EFI_STATUS EFIAPI XhcControlTransfer(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 DeviceAddress, IN UINT8 DeviceSpeed, IN UINTN MaximumPacketLength, IN EFI_USB_DEVICE_REQUEST *Request, IN EFI_USB_DATA_DIRECTION TransferDirection, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN Timeout, IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, OUT UINT32 *TransferResult)
Definition: Xhci.c:870
EFI_STATUS EFIAPI XhcGetRootHubPortStatus(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 PortNumber, OUT EFI_USB_PORT_STATUS *PortStatus)
Definition: Xhci.c:368
EFI_STATUS EFIAPI XhcDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: Xhci.c:1963
UINT64 XhcGetElapsedTicks(IN OUT UINT64 *PreviousTick)
Definition: Xhci.c:2383
EFI_STATUS EFIAPI XhcSetState(IN EFI_USB2_HC_PROTOCOL *This, IN EFI_USB_HC_STATE State)
Definition: Xhci.c:290
EFI_STATUS EFIAPI XhcClearRootHubPortFeature(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 PortNumber, IN EFI_USB_PORT_FEATURE PortFeature)
Definition: Xhci.c:626
EFI_STATUS EFIAPI XhcGetCapability(IN EFI_USB2_HC_PROTOCOL *This, OUT UINT8 *MaxSpeed, OUT UINT8 *PortNumber, OUT UINT8 *Is64BitCapable)
Definition: Xhci.c:109
EFI_STATUS EFIAPI XhcIsochronousTransfer(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, IN UINT8 DeviceSpeed, IN UINTN MaximumPacketLength, IN UINT8 DataBuffersNumber, IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM], IN UINTN DataLength, IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, OUT UINT32 *TransferResult)
Definition: Xhci.c:1625
EFI_STATUS EFIAPI XhcAsyncInterruptTransfer(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, IN UINT8 DeviceSpeed, IN UINTN MaximumPacketLength, IN BOOLEAN IsNewTransfer, IN OUT UINT8 *DataToggle, IN UINTN PollingInterval, IN UINTN DataLength, IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction, IN VOID *Context OPTIONAL)
Definition: Xhci.c:1377
UINT64 XhcConvertTimeToTicks(UINT64 Time)
EFI_STATUS EFIAPI XhcGetState(IN EFI_USB2_HC_PROTOCOL *This, OUT EFI_USB_HC_STATE *State)
Definition: Xhci.c:248
EFI_STATUS EFIAPI XhcDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: Xhci.c:2205
EFI_STATUS EFIAPI XhcSyncInterruptTransfer(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, IN UINT8 DeviceSpeed, IN UINTN MaximumPacketLength, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN OUT UINT8 *DataToggle, IN UINTN Timeout, IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, OUT UINT32 *TransferResult)
Definition: Xhci.c:1519
EFI_STATUS EFIAPI XhcBulkTransfer(IN EFI_USB2_HC_PROTOCOL *This, IN UINT8 DeviceAddress, IN UINT8 EndPointAddress, IN UINT8 DeviceSpeed, IN UINTN MaximumPacketLength, IN UINT8 DataBuffersNumber, IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM], IN OUT UINTN *DataLength, IN OUT UINT8 *DataToggle, IN UINTN Timeout, IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, OUT UINT32 *TransferResult)
Definition: Xhci.c:1250
Definition: EhciUrb.h:200
UINT8 CapLength
Capability Register Length.
Definition: Xhci.h:222
XHC_HCSPARAMS2 HcSParams2
Structural Parameters 2.
Definition: Xhci.h:224
UINT32 DBOff
Doorbell Offset.
Definition: Xhci.h:226
XHC_HCCPARAMS HcCParams
Capability Parameters.
Definition: Xhci.h:225
UINT32 RTSOff
Runtime Register Space Offset.
Definition: Xhci.h:227
XHC_HCSPARAMS1 HcSParams1
Structural Parameters 1.
Definition: Xhci.h:223