38#define XHCI_VENDOR_INTEL 0x8086
39#define XHCI_VENDOR_AMD 0x1022
40#define XHCI_VENDOR_ASMEDIA 0x1B21
41#define XHCI_VENDOR_LINUX_FOUNDATION 0x1D6A
42#define XHCI_VENDOR_NEC 0x1033
43#define XHCI_VENDOR_NVIDIA 0x10DE
44#define XHCI_VENDOR_FRESCO 0x1E31
45#define XHCI_VENDOR_VIA 0x1106
47#define XHCI_USB_CMD_INTE (1<<2)
48#define XHCI_USB_CMD_HSEE (1<<3)
50#define XHCI_USB_STS_HCH (1<<0)
51#define XHCI_USB_STS_HSE (1<<2)
52#define XHCI_USB_STS_EINT (1<<3)
53#define XHCI_USB_STS_PCD (1<<4)
54#define XHCI_USB_STS_SSS (1<<8)
55#define XHCI_USB_STS_RSS (1<<9)
56#define XHCI_USB_STS_SRE (1<<10)
57#define XHCI_USB_STS_CNR (1<<11)
58#define XHCI_USB_STS_HCE (1<<12)
60#define XHCI_USB_CFG_MXSLOT_ENABLE 0xFF
61#define XHCI_USB_CFG_U3_EN (1<<8)
62#define XHCI_USB_CFG_CINFO_EN (1 << 9)
64#define XHCI_USB_CCR_RCS (1<<0)
65#define XHCI_USB_CCR_CS (1<<1)
66#define XHCI_USB_CCR_CA (1<<2)
67#define XHCI_USB_CCR_CRR (1<<3)
69#define XHCI_USB_CCR_PTR_LO 0xFFFFFFC0
70#define XCHI_USB_CCR_PTR 0xFFFFFFFFFFFFFFC0
72#define XHCI_PORTSC_CCS (1<<0)
73#define XHCI_PORTSC_PED (1<<1)
74#define XHCI_PORTSC_OCA (1<<3)
75#define XHCI_PORTSC_PR (1<<4)
76#define XHCI_PORTSC_PP (1<<9)
77#define XHCI_PORTSC_CSC (1<<17)
78#define XHCI_PORTSC_PEC (1<<18)
79#define XHCI_PORTSC_PRC (1<<21)
80#define XHCI_PORTSC_WPR (1<<31)
82#define XHCI_INT_ERDP_BUSY (1<<3)
85#define XHCI_TRB_SIZE 16
86#define XHCI_EVENT_RING_SEG_TBL_ENTRY_SIZE 16
88#define XHCI_TRB_ENT 0x200000000
89#define XHCI_TRB_ISP 0x400000000
90#define XHCI_TRB_IOC 0x2000000000
91#define XHCI_TRB_IDT 0x4000000000
92#define XHCI_TRB_TRT(x) ((uint64_t)x << 48)
93#define XHCI_TRB_DIR_IN ((uint64_t)1 << 48)
95#define XHCI_DOORBELL_ENDPOINT_0 1
96#define XHCI_DOORBELL_ENDPOINT_1 2
99#define USB_SPEED_RESERVED 0
100#define USB_FULL_SPEED 1
101#define USB_LOW_SPEED 2
102#define USB_HIGH_SPEED 3
103#define USB_SUPER_SPEED 4
104#define USB_SUPER_SPEED_PLUS 5
109#define TRB_TRANSFER_NORMAL 1
110#define TRB_TRANSFER_SETUP_STAGE 2
111#define TRB_TRANSFER_DATA_STAGE 3
112#define TRB_TRANSFER_STATUS_STAGE 4
113#define TRB_TRANSFER_ISOCH 5
114#define TRB_TRANSFER_LINK 6
115#define TRB_TRANSFER_EVENT_DATA 7
116#define TRB_TRANSFER_NO_OP 8
117#define TRB_CMD_ENABLE_SLOT 9
118#define TRB_CMD_DISABLE_SLOT 10
119#define TRB_CMD_ADDRESS_DEV 11
120#define TRB_CMD_CONFIG_ENDPOINT 12
121#define TRB_CMD_EVALUATE_CTX 13
122#define TRB_CMD_RESET_ENDPOINT 14
123#define TRB_CMD_STOP_ENDPOINT 15
124#define TRB_CMD_SET_TR_DEQ_POINTER 16
125#define TRB_CMD_RESET_DEV 17
126#define TRB_CMD_FORCE_EVENT 18
127#define TRB_CMD_NEGOTIATE_BANDWIDTH 19
128#define TRB_CMD_SET_LATENCY_TOLERANCE_VALUE 20
129#define TRB_CMD_GET_PORT_BANDWIDTH 21
130#define TRB_CMD_FORCE_HEADER 22
131#define TRB_CMD_NO_OP 23
132#define TRB_CMD_GET_EXT_PROPERTY 24
133#define TRB_CMD_SET_EXT_PROPERTY 25
134#define TRB_EVENT_TRANSFER 32
135#define TRB_EVENT_CMD_COMPLETION 33
136#define TRB_EVENT_PORT_STATUS_CHANGE 34
137#define TRB_EVENT_BANDWIDTH_REQUEST 35
138#define TRB_EVENT_DOORBELL 36
139#define TRB_EVENT_HOST_CONTROLLER 37
140#define TRB_EVENT_DEVICE_NOTIFICATION 38
141#define TRB_EVENT_MFINDEX 39
361 unsigned char name[4];
448#define CTL_TRANSFER_TRT_NO_DATA 0
449#define CTL_TRANSFER_TRT_RESV 1
450#define CTL_TRANSFER_TRT_OUT_DATA 2
451#define CTL_TRANSFER_TRT_IN_DATA 3
453#define USB_SLOT_CTX_DWORD0(entries, hub, multi_tt, speed, route_string) \
454 (((entries & 0x1F) << 27) | ((hub & 1) << 26) | ((multi_tt & 1) << 25) | ((speed & 0xF) << 20) | (route_string & ((1 << 20) - 1)))
456#define USB_SLOT_CTX_DWORD1(num_ports, root_hub_port, max_exit_latency) \
457 (((num_ports & 0xFF) << 24) | ((root_hub_port & 0xFF) << 16) | (max_exit_latency & 0xFFFF))
459#define USB_ENDPOINT_CTX_DWORD0(max_esit_high, interval, lsa, max_p_streams, mult, ep_state) \
460 (((max_esit_high & 0xFF) << 24) | ((interval & 0xFF) << 16) | ((lsa & 1) << 15) | ((max_p_streams & 0x1F) << 10) | ((mult & 0x3) << 8) | (ep_state & 0x7))
462#define USB_ENDPOINT_CTX_DWORD1(max_packet_size, max_burst_size, hid, ep_type, cerr) \
463 (((max_packet_size & 0xFFFF) << 16) | ((max_burst_size & 0xFF) << 8) | ((hid & 1) << 7) | ((ep_type & 0x7) << 3) | ((cerr & 0x3) << 1))
465#define USB_ENDPOINT_CTX_DWORD2(trdp, dcs) \
466 ((trdp & 0xFFFFFFFF) | (dcs & 1))
468#define USB_ENDPOINT_CTX_DWORD3(trdp) \
469 ((trdp >> 32) & 0xFFFFFFFF)
471#define USB_ENDPOINT_CTX_DWORD4(max_esit_lo, average_trb_len) \
472 (((max_esit_lo & 0xFFFF) << 16) | (average_trb_len & 0xFFFF))
void * endpoint
Definition main.cpp:149
USBDevice * usb_device
Definition main.cpp:47
struct _xhci_slot_ XHCISlot
struct _endp_ XHCIEndpoint
void(* endpoint_callback)(void *dev, void *slot, void *Endp)
Definition xhci.h:95
struct _xhci_noop_trb_ xhci_noop_cmd_trb_t
struct _xhci_event_trb_ xhci_event_trb_t
struct _xhci_link_trb_ xhci_link_trb_t
struct _xhci_op_regs_ xhci_op_regs_t
struct _xhci_data_trb_ xhci_data_trb_t
struct _xhci_ex_cap_protocol_ xhci_ex_cap_protocol_t
struct _xhci_setup_trb_t_ xhci_setup_trb_t
struct _xhci_status_trb_ xhci_status_trb_t
struct _xhci_runtime_regs_ xhci_runtime_regs_t
struct _xhci_erst_ xhci_erst_t
struct _xhci_ex_cap_ xhci_ext_cap_t
struct _xhci_trb_ xhci_trb_t
struct _xhci_intr_reg_ xhci_interrupter_reg_t
struct _xhci_input_ctx_ XHCIInputContext
struct _xhci_doorbell_ xhci_doorbell_regs_t
struct _xhci_cap_regs_ xhci_cap_regs_t
struct _xhci_port_reg_ xhci_port_regs_t
void XHCISendCmdDefaultEP(XHCISlot *slot, uint32_t param1, uint32_t param2, uint32_t status, uint32_t ctrl)
Definition xhci.cpp:135
void(* endpoint_callback)(void *dev, void *slot, void *Endp)
Definition xhci.h:143
int XHCIPollEvent(XHCIDevice *usb_device, int trb_type)
Definition xhci.cpp:247
void XHCIRingDoorbellSlot(XHCIDevice *dev, uint8_t slot, uint32_t endpoint)
Definition xhci.cpp:235
void XHCIRingDoorbellHost(XHCIDevice *dev)
Definition xhci.cpp:223
void XHCICreateStatusTRB(XHCISlot *slot, bool in_direction)
Definition xhci_cmd.cpp:98
void XHCISlotRemove(XHCIDevice *dev, uint8_t slot_id)
Definition xhci.cpp:91
void XHCICreateDataTRB(XHCISlot *slot, uint64_t buffer, uint16_t size, bool in_direction)
Definition xhci_cmd.cpp:84
void XHCIEvaluateContextCmd(XHCIDevice *dev, uint64_t input_ctx_ptr, uint8_t slot_id)
Definition cmd.cpp:42
struct _usb_hotplug_ USBHotPlug
void XHCISendCmdToHost(XHCIDevice *dev, uint32_t param1, uint32_t param2, uint32_t status, uint32_t ctrl)
Definition xhci.cpp:199
XHCIDevice * XHCIGetHost()
Definition main.cpp:565
void XHCISendControlCmd(XHCIDevice *dev, XHCISlot *slot, uint8_t slot_id, const USB_REQUEST_PACKET *request, uint64_t buffer_addr, const size_t len, uint8_t trt=CTL_TRANSFER_TRT_IN_DATA)
Definition cmd.cpp:146
size_t XHCIGetMaxPacketSize(uint8_t speed)
Definition usb3.cpp:135
struct _xhci_dev_ XHCIDevice
XHCIEndpoint * XHCISlotGetEP_DCI(XHCISlot *slot, uint8_t endp_num)
Definition usb3.cpp:221
void XHCIAddSlot(XHCIDevice *dev, XHCISlot *slot)
Definition xhci.cpp:82
void XHCIBulkTransfer(XHCIDevice *dev, XHCISlot *slot, uint64_t buffer, uint16_t data_len, XHCIEndpoint *ep_)
Definition cmd.cpp:223
void XHCICreateSetupTRB(XHCISlot *slot, uint8_t rType, uint8_t bRequest, uint16_t value, uint16_t wIndex, uint16_t wLength, uint8_t trt)
Definition xhci_cmd.cpp:73
XHCISlot * XHCIGetSlotByID(XHCIDevice *dev, uint8_t slot_id)
Definition xhci.cpp:54
void XHCIDisableSlot(XHCIDevice *dev, uint8_t slot_num)
Definition cmd.cpp:122
void XHCIConfigureEndpoint(XHCIDevice *dev, uint64_t input_ctx_ptr, uint8_t slot_id)
Definition cmd.cpp:51
void XHCIEnableSlot(XHCIDevice *dev, uint8_t slot_type)
Definition cmd.cpp:111
void XHCISendNormalTRB(XHCIDevice *dev, XHCISlot *slot, uint64_t data_buffer, uint16_t data_len, XHCIEndpoint *ep)
Definition cmd.cpp:180
void XHCISendNoopCmd(XHCIDevice *dev)
Definition cmd.cpp:132
void XHCISendCmdOtherEP(XHCISlot *slot, uint8_t endp_num, uint32_t param1, uint32_t param2, uint32_t status, uint32_t ctrl)
Definition xhci.cpp:165
void XHCISendAddressDevice(XHCIDevice *dev, XHCISlot *slot, uint8_t bsr, uint64_t input_ctx_ptr, uint8_t slot_id)
Definition cmd.cpp:64
#define CTL_TRANSFER_TRT_IN_DATA
Definition xhci.h:451
struct __xhci_legacy_cap__ xhci_legacy_cap_t
unsigned int uint32_t
Definition acefiex.h:163
unsigned char uint8_t
Definition acefiex.h:161
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
unsigned short int uint16_t
Definition acefiex.h:162
uint8_t request
Definition usb3.h:152
uint16_t index
Definition usb3.h:154
uint16_t length
Definition usb3.h:155
uint8_t request_type
Definition usb3.h:151
uint16_t value
Definition usb3.h:153
volatile uint32_t cap_id_and_next
Definition xhci.h:369
volatile uint32_t legctlsts
Definition xhci.h:370
Definition x86_64_sched.h:118
endpoint_callback callback
Definition xhci.h:197
uint8_t ep_type
Definition xhci.h:195
unsigned cmd_ring_max
Definition xhci.h:190
uint8_t endpointAttr
Definition xhci.h:234
uint8_t interval
Definition xhci.h:187
unsigned cmd_ring_index
Definition xhci.h:189
xhci_trb_t * cmd_ring
Definition xhci.h:184
uint8_t endpoint_num
Definition xhci.h:185
uint32_t offset
Definition xhci.h:193
uint16_t max_packet_sz
Definition xhci.h:238
unsigned cmd_ring_cycle
Definition xhci.h:191
uint8_t endpointAddress
Definition xhci.h:233
uint32_t dc_offset
Definition xhci.h:194
uint8_t endpoint_type
Definition xhci.h:186
uint8_t dci
Definition xhci.h:192
uint8_t dir
Definition xhci.h:196
unsigned int portNum
Definition xhci.h:443
bool initialized
Definition xhci.h:444
uint32_t cap_hccparams2
Definition xhci.h:107
uint32_t cap_hcsparams3
Definition xhci.h:104
uint16_t hci_version
Definition xhci.h:101
uint32_t cap_hcsparams1
Definition xhci.h:102
uint32_t cap_dboff
Definition xhci.h:106
uint32_t cap_hcsparams2
Definition xhci.h:103
uint8_t reserved
Definition xhci.h:100
uint8_t cap_caplen_version
Definition xhci.h:99
uint32_t cap_hccparams1
Definition xhci.h:105
uint32_t evaluateNextTRB
Definition xhci.h:279
uint32_t immediate_data
Definition xhci.h:284
uint64_t dataBuffer
Definition xhci.h:274
uint32_t direction
Definition xhci.h:287
uint32_t trb_type
Definition xhci.h:286
uint32_t transferLength
Definition xhci.h:275
uint32_t no_snoop
Definition xhci.h:281
uint32_t interrupterTarget
Definition xhci.h:277
uint32_t rsvdZ2
Definition xhci.h:288
uint32_t interrupt_on_short_packet
Definition xhci.h:280
uint32_t cycleBit
Definition xhci.h:278
uint32_t rsvdZ
Definition xhci.h:285
uint32_t size
Definition xhci.h:276
uint32_t chain_bit
Definition xhci.h:282
uint32_t ioc
Definition xhci.h:283
bool is_csz_64
Definition xhci.h:409
unsigned evnt_ring_index
Definition xhci.h:429
bool event_available
Definition xhci.h:433
unsigned cmd_ring_cycle
Definition xhci.h:426
xhci_doorbell_regs_t * db_regs
Definition xhci.h:413
uint64_t cmd_ring_phys
Definition xhci.h:423
xhci_trb_t * cmd_ring
Definition xhci.h:422
unsigned cmd_ring_index
Definition xhci.h:424
int poll_return_trb_type
Definition xhci.h:434
xhci_op_regs_t * op_regs
Definition xhci.h:412
int trb_event_index
Definition xhci.h:435
uint16_t max_intrs
Definition xhci.h:419
unsigned evnt_ring_max
Definition xhci.h:431
uint64_t * event_ring_segment
Definition xhci.h:427
int poll_event_for_trb
Definition xhci.h:432
xhci_runtime_regs_t * rt_regs
Definition xhci.h:414
list_t * slot_list
Definition xhci.h:410
xhci_cap_regs_t * cap_regs
Definition xhci.h:411
AuThread * usbThread
Definition xhci.h:438
uint16_t vendor
Definition xhci.h:436
uint32_t num_ports
Definition xhci.h:418
uint32_t num_slots
Definition xhci.h:417
uint64_t * event_ring_seg_phys
Definition xhci.h:428
xhci_ext_cap_t * ext_cap
Definition xhci.h:415
unsigned cmd_ring_max
Definition xhci.h:425
xhci_port_regs_t * ports
Definition xhci.h:416
bool initialised
Definition xhci.h:408
uint64_t * dev_ctx_base_array
Definition xhci.h:421
Spinlock * usb_lock
Definition xhci.h:437
uint8_t irq
Definition xhci.h:420
unsigned evnt_ring_cycle
Definition xhci.h:430
unsigned doorbell[256]
Definition xhci.h:149
uint32_t rerserved
Definition xhci.h:332
uint32_t ring_seg_size
Definition xhci.h:331
uint32_t event_ring_seg_hi
Definition xhci.h:330
uint32_t event_ring_segment_lo
Definition xhci.h:329
uint32_t rsvd3
Definition xhci.h:230
uint32_t trbType
Definition xhci.h:229
uint32_t completionCode
Definition xhci.h:226
uint32_t rsvd2
Definition xhci.h:228
uint32_t rsvd
Definition xhci.h:225
uint64_t ptr
Definition xhci.h:224
uint32_t cycleBit
Definition xhci.h:227
uint32_t rsvd
Definition xhci.h:167
uint32_t rsvd2
Definition xhci.h:169
uint32_t controller_os_sem
Definition xhci.h:168
uint32_t next
Definition xhci.h:165
uint32_t controller_bios_semaphore
Definition xhci.h:166
uint32_t id
Definition xhci.h:164
uint32_t port_cap_field2
Definition xhci.h:313
uint32_t port_cap_field
Definition xhci.h:312
xhci_ext_cap_t base
Definition xhci.h:310
unsigned char name[4]
Definition xhci.h:311
unsigned evtRngSegTabSz
Definition xhci.h:130
unsigned res
Definition xhci.h:131
unsigned intr_mod
Definition xhci.h:129
unsigned evtRngDeqPtrHi
Definition xhci.h:135
unsigned evtRngSegBaseHi
Definition xhci.h:133
unsigned intr_man
Definition xhci.h:128
unsigned evtRngDeqPtrLo
Definition xhci.h:134
unsigned evtRngSegBaseLo
Definition xhci.h:132
uint32_t chain_bit
Definition xhci.h:242
uint64_t segment_ptr
Definition xhci.h:236
uint32_t rsvd
Definition xhci.h:237
uint32_t cycle_bit
Definition xhci.h:239
uint32_t rsvd2
Definition xhci.h:241
uint32_t interrupter_target
Definition xhci.h:238
uint32_t rsvd4
Definition xhci.h:246
uint32_t rsvd3
Definition xhci.h:244
uint32_t ioc
Definition xhci.h:243
uint32_t trb_type
Definition xhci.h:245
uint32_t toggle_cycle
Definition xhci.h:240
uint32_t rsvdZ[3]
Definition xhci.h:319
uint32_t rsvdZ3
Definition xhci.h:323
uint32_t rsvdZ2
Definition xhci.h:321
uint32_t trb_type
Definition xhci.h:322
uint32_t cycleBit
Definition xhci.h:320
uint32_t op_pad1[2]
Definition xhci.h:116
uint32_t op_dnctrl
Definition xhci.h:117
uint32_t op_dcbaap_hi
Definition xhci.h:121
uint64_t op_crcr
Definition xhci.h:118
uint32_t op_usbcmd
Definition xhci.h:113
uint32_t op_usbsts
Definition xhci.h:114
uint32_t op_config
Definition xhci.h:122
uint32_t op_pagesize
Definition xhci.h:115
uint32_t op_pad2[4]
Definition xhci.h:119
uint32_t op_dcbaap_lo
Definition xhci.h:120
uint32_t port_hardware_LMP_ctl
Definition xhci.h:178
uint32_t port_sc
Definition xhci.h:175
uint32_t port_link_info
Definition xhci.h:177
uint32_t port_pmsc
Definition xhci.h:176
char res[28]
Definition xhci.h:142
unsigned micro_frame_index
Definition xhci.h:141
xhci_interrupter_reg_t intr_reg[]
Definition xhci.h:143
uint32_t immediateData
Definition xhci.h:263
uint32_t rsvdZ4
Definition xhci.h:267
uint32_t interrupterTarget
Definition xhci.h:259
uint32_t ioc
Definition xhci.h:262
uint32_t rsvdZ
Definition xhci.h:258
uint32_t bmRequestType
Definition xhci.h:252
uint32_t rsvdZ3
Definition xhci.h:264
uint32_t bRequest
Definition xhci.h:253
uint32_t wIndex
Definition xhci.h:255
uint32_t trbType
Definition xhci.h:265
uint32_t transferType
Definition xhci.h:266
uint32_t wValue
Definition xhci.h:254
uint32_t trbTransferLength
Definition xhci.h:257
uint32_t cycleBit
Definition xhci.h:260
uint32_t wLength
Definition xhci.h:256
uint32_t rsvdZ2
Definition xhci.h:261
uint8_t classC
Definition xhci.h:209
unsigned cmd_ring_max
Definition xhci.h:214
uint64_t descriptor_buff
Definition xhci.h:216
list_t * endpoints
Definition xhci.h:218
xhci_trb_t * cmd_ring
Definition xhci.h:212
uint8_t port_speed
Definition xhci.h:205
uint8_t subClassC
Definition xhci.h:210
uint8_t root_hub_port_num
Definition xhci.h:204
uint64_t output_context_phys
Definition xhci.h:208
uint64_t cmd_ring_base
Definition xhci.h:206
uint64_t input_context_phys
Definition xhci.h:207
uint8_t prot
Definition xhci.h:211
unsigned cmd_ring_cycle
Definition xhci.h:215
unsigned cmd_ring_index
Definition xhci.h:213
uint16_t interface_val
Definition xhci.h:217
uint8_t slot_id
Definition xhci.h:203
uint32_t rsvdZ
Definition xhci.h:294
uint32_t rsvdZ4
Definition xhci.h:304
uint32_t interrupter_target
Definition xhci.h:295
uint32_t trb_type
Definition xhci.h:302
uint32_t cycle_bit
Definition xhci.h:296
uint32_t ioc
Definition xhci.h:300
uint32_t evaluateNextTRB
Definition xhci.h:297
uint32_t chainBit
Definition xhci.h:299
uint32_t direction
Definition xhci.h:303
uint32_t rsvdZ2
Definition xhci.h:298
uint32_t rsvdZ0[2]
Definition xhci.h:293
uint32_t rsvdZ3
Definition xhci.h:301
uint32_t trb_param_1
Definition xhci.h:155
uint32_t trb_control
Definition xhci.h:158
uint32_t trb_param_2
Definition xhci.h:156
uint32_t trb_status
Definition xhci.h:157