9#ifndef __USB3_DEBUG_PORT_LIB_INTERNAL__
10#define __USB3_DEBUG_PORT_LIB_INTERNAL__
31#define USB3_DBG_GUID \
33 0xb2a56f4d, 0x9177, 0x4fc8, { 0xa6, 0x77, 0xdd, 0x96, 0x3e, 0xb4, 0xcb, 0x1b } \
39#define USB3DBG_NO_DBG_CAB 0
40#define USB3DBG_DBG_CAB 1
41#define USB3DBG_ENABLED 2
42#define USB3DBG_NOT_ENABLED 4
43#define USB3DBG_UNINITIALIZED 255
45#define USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE 0x08
50#define XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE 0x400
52#define XHCI_DEBUG_DEVICE_VENDOR_ID 0x0525
53#define XHCI_DEBUG_DEVICE_PRODUCT_ID 0x127A
54#define XHCI_DEBUG_DEVICE_PROTOCOL 0xFF
55#define XHCI_DEBUG_DEVICE_REVISION 0x00
57#define XHCI_BASE_ADDRESS_64_BIT_MASK 0xFFFFFFFFFFFF0000ULL
58#define XHCI_BASE_ADDRESS_32_BIT_MASK 0xFFFF0000
60#define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A
61#define XHC_HCCPARAMS_OFFSET 0x10
62#define XHC_CAPABILITY_ID_MASK 0xFF
63#define XHC_NEXT_CAPABILITY_MASK 0xFF00
65#define XHC_HCSPARAMS1_OFFSET 0x4
66#define XHC_USBCMD_OFFSET 0x0
67#define XHC_USBSTS_OFFSET 0x4
68#define XHC_PORTSC_OFFSET 0x400
70#define XHC_USBCMD_RUN BIT0
71#define XHC_USBCMD_RESET BIT1
73#define XHC_USBSTS_HALT BIT0
78#define DATA_TRANSFER_WRITE_TIMEOUT 0
79#define DATA_TRANSFER_READ_TIMEOUT 50000
80#define DATA_TRANSFER_POLL_TIMEOUT 1000
81#define XHC_DEBUG_PORT_1_MILLISECOND 1000
85#define XHC_DEBUG_PORT_ON_OFF_DELAY 100000
90#define STRING0_DESC_LEN 4
91#define MANU_DESC_LEN 12
92#define PRODUCT_DESC_LEN 40
93#define SERIAL_DESC_LEN 4
98#define XHC_DC_DCID 0x0
99#define XHC_DC_DCDB 0x4
100#define XHC_DC_DCERSTSZ 0x8
101#define XHC_DC_DCERSTBA 0x10
102#define XHC_DC_DCERDP 0x18
103#define XHC_DC_DCCTRL 0x20
104#define XHC_DC_DCST 0x24
105#define XHC_DC_DCPORTSC 0x28
106#define XHC_DC_DCCP 0x30
107#define XHC_DC_DCDDI1 0x38
108#define XHC_DC_DCDDI2 0x3C
110#define TRB_TYPE_LINK 6
112#define ERST_NUMBER 0x01
113#define TR_RING_TRB_NUMBER 0x100
114#define EVENT_RING_TRB_NUMBER 0x200
119#define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0xFFFFFFFF))
120#define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINT64)(UINTN)(Addr64), 32) & 0xFFFFFFFF))
121#define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
126#define ED_NOT_VALID 0
127#define ED_ISOCH_OUT 1
129#define ED_INTERRUPT_OUT 3
130#define ED_CONTROL_BIDIR 4
133#define ED_INTERRUPT_IN 7
138#define TRB_COMPLETION_INVALID 0
139#define TRB_COMPLETION_SUCCESS 1
140#define TRB_COMPLETION_DATA_BUFFER_ERROR 2
141#define TRB_COMPLETION_BABBLE_ERROR 3
142#define TRB_COMPLETION_USB_TRANSACTION_ERROR 4
143#define TRB_COMPLETION_TRB_ERROR 5
144#define TRB_COMPLETION_STALL_ERROR 6
145#define TRB_COMPLETION_SHORT_PACKET 13
150#define TRB_TYPE_NORMAL 1
151#define TRB_TYPE_SETUP_STAGE 2
152#define TRB_TYPE_DATA_STAGE 3
153#define TRB_TYPE_STATUS_STAGE 4
154#define TRB_TYPE_ISOCH 5
155#define TRB_TYPE_LINK 6
156#define TRB_TYPE_EVENT_DATA 7
157#define TRB_TYPE_NO_OP 8
158#define TRB_TYPE_EN_SLOT 9
159#define TRB_TYPE_DIS_SLOT 10
160#define TRB_TYPE_ADDRESS_DEV 11
161#define TRB_TYPE_CON_ENDPOINT 12
162#define TRB_TYPE_EVALU_CONTXT 13
163#define TRB_TYPE_RESET_ENDPOINT 14
164#define TRB_TYPE_STOP_ENDPOINT 15
165#define TRB_TYPE_SET_TR_DEQUE 16
166#define TRB_TYPE_RESET_DEV 17
167#define TRB_TYPE_GET_PORT_BANW 21
168#define TRB_TYPE_FORCE_HEADER 22
169#define TRB_TYPE_NO_OP_COMMAND 23
170#define TRB_TYPE_TRANS_EVENT 32
171#define TRB_TYPE_COMMAND_COMPLT_EVENT 33
172#define TRB_TYPE_PORT_STATUS_CHANGE_EVENT 34
173#define TRB_TYPE_HOST_CONTROLLER_EVENT 37
174#define TRB_TYPE_DEVICE_NOTIFI_EVENT 38
175#define TRB_TYPE_MFINDEX_WRAP_EVENT 39
180#define XHC_1_MILLISECOND (1000)
181#define XHC_POLL_DELAY (1000)
182#define XHC_GENERIC_TIMEOUT (10 * 1000)
184#define EFI_USB_SPEED_FULL 0x0000
185#define EFI_USB_SPEED_LOW 0x0001
186#define EFI_USB_SPEED_HIGH 0x0002
187#define EFI_USB_SPEED_SUPER 0x0003
192#define XHC_CTRL_TRANSFER 0x01
193#define XHC_BULK_TRANSFER 0x02
194#define XHC_INT_TRANSFER_SYNC 0x04
195#define XHC_INT_TRANSFER_ASYNC 0x08
196#define XHC_INT_ONLY_TRANSFER_ASYNC 0x10
201#define EFI_USB_NOERROR 0x00
202#define EFI_USB_ERR_NOTEXECUTE 0x01
203#define EFI_USB_ERR_STALL 0x02
204#define EFI_USB_ERR_BUFFER 0x04
205#define EFI_USB_ERR_BABBLE 0x08
206#define EFI_USB_ERR_NAK 0x10
207#define EFI_USB_ERR_CRC 0x20
208#define EFI_USB_ERR_TIMEOUT 0x40
209#define EFI_USB_ERR_BITSTUFF 0x80
210#define EFI_USB_ERR_SYSTEM 0x100
222 UINT32 MaxPStreams : 5;
232 UINT32 MaxBurstSize : 8;
233 UINT32 MaxPacketSize : 16;
239 UINT32 AverageTRBLength : 16;
240 UINT32 MaxESITPayload : 16;
270 UINT32 IntTarget : 10;
296 UINT32 Completecode : 8;
303 UINT32 EndpointId : 5;
318 UINT32 InterTarget : 10;
352 UINT32 RingTrbSize : 16;
382 UINT64 String0DescAddress;
383 UINT64 ManufacturerStrDescAddress;
384 UINT64 ProductStrDescAddress;
385 UINT64 SerialNumberStrDescAddress;
386 UINT64 String0Length : 8;
387 UINT64 ManufacturerStrLength : 8;
388 UINT64 ProductStrLength : 8;
389 UINT64 SerialNumberStrLength : 8;
456 BOOLEAN DebugSupport;
481 BOOLEAN ChangePortPower;
501 UINT64 DebugCapabilityOffset;
EFI_STATUS EFIAPI XhcDataTransfer(IN USB3_DEBUG_PORT_HANDLE *Handle, IN EFI_USB_DATA_DIRECTION Direction, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN Timeout)
UINT16 GetXhciPciCommand(VOID)
VOID XhcSetDebugRegBit(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset, IN UINT32 Bit)
VOID * AllocateAlignBuffer(IN UINTN BufferSize)
VOID XhcClearR32Bit(IN OUT UINTN Register, IN UINT32 BitMask)
USB3_DEBUG_PORT_HANDLE * GetUsb3DebugPortInstance(VOID)
EFI_PHYSICAL_ADDRESS * GetUsb3DebugPortInstanceAddrPtr(VOID)
UINT32 XhcReadDebugReg(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset)
BOOLEAN XhcIsBitSet(UINTN Register, UINT32 BitMask)
VOID XhcWriteDebugReg(IN USB3_DEBUG_PORT_HANDLE *Handle, IN UINT32 Offset, IN UINT32 Data)
RETURN_STATUS EFIAPI USB3InitializeReal(VOID)
RETURN_STATUS EFIAPI InitializeUsbDebugHardware(IN USB3_DEBUG_PORT_HANDLE *Handle)
VOID XhcSetR32Bit(UINTN Register, UINT32 BitMask)
RETURN_STATUS EFIAPI USB3Initialize(VOID)
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
UINT64 EFI_PHYSICAL_ADDRESS