24 #define XHCI_MIN_ALIGN 64 27 #define XHCI_MTU 65536 30 #define XHCI_BAR PCI_BASE_ADDRESS_0 33 #define XHCI_CAP_CAPLENGTH 0x00 36 #define XHCI_CAP_HCIVERSION 0x02 39 #define XHCI_CAP_HCSPARAMS1 0x04 42 #define XHCI_HCSPARAMS1_SLOTS(params) ( ( (params) >> 0 ) & 0xff ) 45 #define XHCI_HCSPARAMS1_INTRS(params) ( ( (params) >> 8 ) & 0x3ff ) 48 #define XHCI_HCSPARAMS1_PORTS(params) ( ( (params) >> 24 ) & 0xff ) 51 #define XHCI_CAP_HCSPARAMS2 0x08 54 #define XHCI_HCSPARAMS2_SCRATCHPADS(params) \ 55 ( ( ( (params) >> 16 ) & 0x3e0 ) | ( ( (params) >> 27 ) & 0x1f ) ) 58 #define XHCI_CAP_HCCPARAMS1 0x10 61 #define XHCI_HCCPARAMS1_ADDR64(params) ( ( (params) >> 0 ) & 0x1 ) 64 #define XHCI_HCCPARAMS1_CSZ_SHIFT(params) ( 5 + ( ( (params) >> 2 ) & 0x1 ) ) 67 #define XHCI_HCCPARAMS1_XECP(params) ( ( ( (params) >> 16 ) & 0xffff ) << 2 ) 70 #define XHCI_CAP_DBOFF 0x14 73 #define XHCI_CAP_RTSOFF 0x18 76 #define XHCI_XECP_ID(xecp) ( ( (xecp) >> 0 ) & 0xff ) 79 #define XHCI_XECP_NEXT(xecp) ( ( ( (xecp) >> 8 ) & 0xff ) << 2 ) 82 #define XHCI_XECP_ID_LEGACY 1 85 #define XHCI_USBLEGSUP_BIOS 0x02 88 #define XHCI_USBLEGSUP_BIOS_OWNED 0x01 91 #define XHCI_USBLEGSUP_OS 0x03 94 #define XHCI_USBLEGSUP_OS_OWNED 0x01 97 #define XHCI_USBLEGSUP_CTLSTS 0x04 100 #define XHCI_XECP_ID_SUPPORTED 2 103 #define XHCI_SUPPORTED_REVISION 0x00 106 #define XHCI_SUPPORTED_REVISION_VER(revision) ( ( (revision) >> 16 ) & 0xffff ) 109 #define XHCI_SUPPORTED_NAME 0x04 112 #define XHCI_SUPPORTED_PORTS 0x08 115 #define XHCI_SUPPORTED_PORTS_OFFSET(ports) ( ( (ports) >> 0 ) & 0xff ) 118 #define XHCI_SUPPORTED_PORTS_COUNT(ports) ( ( (ports) >> 8 ) & 0xff ) 121 #define XHCI_SUPPORTED_PORTS_PSIC(ports) ( ( (ports) >> 28 ) & 0x0f ) 124 #define XHCI_SUPPORTED_SLOT 0x0c 127 #define XHCI_SUPPORTED_SLOT_TYPE(slot) ( ( (slot) >> 0 ) & 0x1f ) 130 #define XHCI_SUPPORTED_PSI(index) ( 0x10 + ( (index) * 4 ) ) 133 #define XHCI_SUPPORTED_PSI_VALUE(psi) ( ( (psi) >> 0 ) & 0x0f ) 136 #define XHCI_SUPPORTED_PSI_MANTISSA(psi) ( ( (psi) >> 16 ) & 0xffff ) 139 #define XHCI_SUPPORTED_PSI_EXPONENT(psi) ( ( (psi) >> 4 ) & 0x03 ) 154 #define XHCI_OP_USBCMD 0x00 157 #define XHCI_USBCMD_RUN 0x00000001UL 160 #define XHCI_USBCMD_HCRST 0x00000002UL 163 #define XHCI_OP_USBSTS 0x04 166 #define XHCI_USBSTS_HCH 0x00000001UL 169 #define XHCI_OP_PAGESIZE 0x08 172 #define XHCI_PAGESIZE(pagesize) ( (pagesize) << 12 ) 175 #define XHCI_OP_DNCTRL 0x14 178 #define XHCI_OP_CRCR 0x18 181 #define XHCI_CRCR_RCS 0x00000001UL 184 #define XHCI_CRCR_CA 0x00000004UL 187 #define XHCI_CRCR_CRR 0x00000008UL 190 #define XHCI_OP_DCBAAP 0x30 193 #define XHCI_OP_CONFIG 0x38 196 #define XHCI_CONFIG_MAX_SLOTS_EN(slots) ( (slots) << 0 ) 199 #define XHCI_CONFIG_MAX_SLOTS_EN_MASK \ 200 XHCI_CONFIG_MAX_SLOTS_EN ( 0xff ) 203 #define XHCI_OP_PORTSC(port) ( 0x400 - 0x10 + ( (port) << 4 ) ) 206 #define XHCI_PORTSC_CCS 0x00000001UL 209 #define XHCI_PORTSC_PED 0x00000002UL 212 #define XHCI_PORTSC_PR 0x00000010UL 215 #define XHCI_PORTSC_PLS(pls) ( (pls) << 5 ) 218 #define XHCI_PORTSC_PLS_DISABLED XHCI_PORTSC_PLS ( 4 ) 221 #define XHCI_PORTSC_PLS_RXDETECT XHCI_PORTSC_PLS ( 5 ) 224 #define XHCI_PORTSC_PLS_MASK XHCI_PORTSC_PLS ( 0xf ) 227 #define XHCI_PORTSC_PP 0x00000200UL 230 #define XHCI_PORT_POWER_DELAY_MS 20 233 #define XHCI_PORTSC_PSIV(portsc) ( ( (portsc) >> 10 ) & 0xf ) 236 #define XHCI_PORTSC_PIC(indicators) ( (indicators) << 14 ) 239 #define XHCI_PORTSC_PIC_MASK XHCI_PORTSC_PIC ( 3 ) 242 #define XHCI_PORTSC_LWS 0x00010000UL 245 #define XHCI_LINK_STATE_DELAY_MS 100 248 #define XHCI_PORTSC_CSC 0x00020000UL 251 #define XHCI_PORTSC_PEC 0x00040000UL 254 #define XHCI_PORTSC_WRC 0x00080000UL 257 #define XHCI_PORTSC_OCC 0x00100000UL 260 #define XHCI_PORTSC_PRC 0x00200000UL 263 #define XHCI_PORTSC_PLC 0x00400000UL 266 #define XHCI_PORTSC_CEC 0x00800000UL 269 #define XHCI_PORTSC_CHANGE \ 270 ( XHCI_PORTSC_CSC | XHCI_PORTSC_PEC | XHCI_PORTSC_WRC | \ 271 XHCI_PORTSC_OCC | XHCI_PORTSC_PRC | XHCI_PORTSC_PLC | \ 283 #define XHCI_PORTSC_PRESERVE ( XHCI_PORTSC_PP | XHCI_PORTSC_PIC_MASK ) 286 #define XHCI_OP_PORTPMSC(port) ( 0x404 - 0x10 + ( (port) << 4 ) ) 289 #define XHCI_OP_PORTLI(port) ( 0x408 - 0x10 + ( (port) << 4 ) ) 292 #define XHCI_OP_PORTHLPMC(port) ( 0x40c - 0x10 + ( (port) << 4 ) ) 295 #define XHCI_RUN_ERSTSZ(intr) ( 0x28 + ( (intr) << 5 ) ) 298 #define XHCI_RUN_ERSTBA(intr) ( 0x30 + ( (intr) << 5 ) ) 301 #define XHCI_RUN_ERDP(intr) ( 0x38 + ( (intr) << 5 ) ) 328 #define XHCI_TRB_C 0x01 331 #define XHCI_TRB_TC 0x02 334 #define XHCI_TRB_CH 0x10 337 #define XHCI_TRB_IOC 0x20 340 #define XHCI_TRB_IDT 0x40 343 #define XHCI_TRB_TYPE(type) ( (type) << 2 ) 346 #define XHCI_TRB_TYPE_MASK XHCI_TRB_TYPE ( 0x3f ) 363 #define XHCI_TRB_NORMAL XHCI_TRB_TYPE ( 1 ) 366 #define XHCI_TD_SIZE(remaining) \ 367 ( ( ( (remaining) <= 0xf ) ? remaining : 0xf ) << 17 ) 386 #define XHCI_TRB_SETUP XHCI_TRB_TYPE ( 2 ) 389 #define XHCI_SETUP_IN 3 392 #define XHCI_SETUP_OUT 2 411 #define XHCI_TRB_DATA XHCI_TRB_TYPE ( 3 ) 414 #define XHCI_DATA_IN 0x01 417 #define XHCI_DATA_OUT 0x00 436 #define XHCI_TRB_STATUS XHCI_TRB_TYPE ( 4 ) 439 #define XHCI_STATUS_IN 0x01 442 #define XHCI_STATUS_OUT 0x00 459 #define XHCI_TRB_LINK XHCI_TRB_TYPE ( 6 ) 462 #define XHCI_TRB_NOP XHCI_TRB_TYPE ( 8 ) 481 #define XHCI_TRB_ENABLE_SLOT XHCI_TRB_TYPE ( 9 ) 500 #define XHCI_TRB_DISABLE_SLOT XHCI_TRB_TYPE ( 10 ) 519 #define XHCI_TRB_ADDRESS_DEVICE XHCI_TRB_TYPE ( 11 ) 522 #define XHCI_TRB_CONFIGURE_ENDPOINT XHCI_TRB_TYPE ( 12 ) 525 #define XHCI_TRB_EVALUATE_CONTEXT XHCI_TRB_TYPE ( 13 ) 544 #define XHCI_TRB_RESET_ENDPOINT XHCI_TRB_TYPE ( 14 ) 563 #define XHCI_TRB_STOP_ENDPOINT XHCI_TRB_TYPE ( 15 ) 582 #define XHCI_TRB_SET_TR_DEQUEUE_POINTER XHCI_TRB_TYPE ( 16 ) 585 #define XHCI_TRB_NOP_CMD XHCI_TRB_TYPE ( 23 ) 608 #define XHCI_TRB_TRANSFER XHCI_TRB_TYPE ( 32 ) 629 #define XHCI_TRB_COMPLETE XHCI_TRB_TYPE ( 33 ) 660 #define XHCI_TRB_PORT_STATUS XHCI_TRB_TYPE ( 34 ) 679 #define XHCI_TRB_HOST_CONTROLLER XHCI_TRB_TYPE ( 37 ) 764 #define XHCI_SLOT_INFO( entries, hub, speed, route ) \ 765 ( ( (entries) << 27 ) | ( (hub) << 26 ) | ( (speed) << 20 ) | (route) ) 808 #define XHCI_ENDPOINT_STATE_MASK 0x07 811 #define XHCI_EP_TYPE(type) ( (type) << 3 ) 814 #define XHCI_EP_TYPE_CONTROL XHCI_EP_TYPE ( 4 ) 817 #define XHCI_EP_TYPE_IN XHCI_EP_TYPE ( 4 ) 820 #define XHCI_EP_TYPE_PERIODIC XHCI_EP_TYPE ( 1 ) 823 #define XHCI_EP_DCS 0x00000001UL 826 #define XHCI_EP0_TRB_LEN 8 888 #define XHCI_DBVAL( target, stream ) ( (target) | ( (stream) << 16 ) ) 924 assert ( fill <= ring->mask );
938 return virt_to_phys ( &ring->
trb[
index] );
942 #define XHCI_CTX_SLOT 0 945 #define XHCI_CTX(address) \ 946 ( (address) ? ( ( ( (address) & 0x0f ) << 1 ) | \ 947 ( ( (address) & 0x80 ) >> 7 ) ) : 1 ) 950 #define XHCI_CTX_EP0 XHCI_CTX ( 0x00 ) 953 #define XHCI_CTX_END 32 956 #define XHCI_DCI(ctx) ( (ctx) + 0 ) 959 #define XHCI_ICI(ctx) ( (ctx) + 1 ) 965 #define XHCI_CMD_TRBS_LOG2 2 971 #define XHCI_EVENT_TRBS_LOG2 6 977 #define XHCI_TRANSFER_TRBS_LOG2 6 983 #define XHCI_USBLEGSUP_MAX_WAIT_MS 100 989 #define XHCI_STOP_MAX_WAIT_MS 100 995 #define XHCI_RESET_MAX_WAIT_MS 500 1003 #define XHCI_COMMAND_MAX_WAIT_MS USB_CONTROL_MAX_WAIT_MS 1009 #define XHCI_COMMAND_ABORT_DELAY_MS 500 1015 #define XHCI_PORT_RESET_MAX_WAIT_MS 500 1026 #define XHCI_PCH 0x0001 1029 #define XHCI_PCH_XUSB2PR 0xd0 1032 #define XHCI_PCH_XUSB2PRM 0xd4 1035 #define XHCI_PCH_USB3PSSEN 0xd8 1038 #define XHCI_PCH_USB3PRM 0xdc 1041 #define XHCI_BAD_PSIV 0x0002 uint8_t intf
Interface number.
uint8_t burst
Maximum burst size.
uint32_t reserved
Reserved.
A disable slot transfer request block.
uint32_t reserved_b
Reserved.
uint8_t type
Endpoint type.
A status stage transfer request block.
struct xhci_trb_context context
Input context TRB.
uint64_t command
Command TRB pointer.
A transfer request block.
uint32_t dbval
Doorbell register value.
struct xhci_trb_common common
Common fields.
unsigned int ports
Number of ports.
void * buffer
Scratchpad buffer area.
struct xhci_dcbaa dcbaa
Device context base address array.
uint8_t reserved
Reserved.
uint8_t direction
Direction.
uint64_t data
Data buffer.
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
#define XHCI_CTX_END
End of contexts.
uint32_t reserved_b
Reserved.
uint8_t reserved_c
Reserved.
struct xhci_device * xhci
xHCI device
unsigned int cons
Consumer counter.
void * run
Runtime registers.
A set transfer ring dequeue pointer transfer request block.
size_t len
Length of transfer request blocks.
An input control context.
uint8_t reserved_b
Reserved.
unsigned int port
Root hub port number.
xhci_endpoint_state
Endpoint states.
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
A command completion event transfer request block.
struct dma_mapping segment_map
Event ring segment table DMA mapping.
uint8_t state
Endpoint state.
uint8_t reserved_a[3]
Reserved.
struct xhci_trb_transfer transfer
Transfer event.
A port status change transfer request block.
uint16_t trb_len
Average TRB length.
union xhci_trb * pending
Current command (if any)
uint64_t reserved_a
Reserved.
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
struct device * dev
Underlying hardware device.
uint64_t next
Next ring segment.
struct dma_mapping map
DMA mapping.
xhci_completion_code
xHCI completion codes
uint8_t code
Completion code.
struct xhci_trb_disable_slot disable
Disable slot TRB.
uint16_t reserved_c
Reserved.
uint16_t reserved_c
Reserved.
unsigned int route
Route string.
An enable slot transfer request block.
unsigned long long uint64_t
struct usb_bus * bus
USB bus.
struct xhci_trb_enable_slot enable
Enable slot TRB.
struct dma_mapping buffer_map
Buffer DMA mapping.
struct xhci_trb_setup setup
Setup stage TRB.
unsigned int count
Number of page-sized scratchpad buffers.
A data stage transfer request block.
uint8_t code
Completion code.
void * db
Doorbell register.
xhci_default_psi_value
Default PSI values.
uint8_t direction
Transfer direction.
unsigned int psiv
Protocol speed ID.
uint8_t reserved_b[3]
Reserved.
uint8_t endpoint
Endpoint ID.
uint64_t dequeue
Dequeue pointer.
unsigned int slots
Number of device slots.
uint32_t add
Add context flags.
uint64_t dequeue
Transfer ring dequeue pointer.
struct xhci_scratchpad scratch
Scratchpad buffer.
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
uint8_t esit_high
Max ESIT payload high.
uint64_t * array
Scratchpad array.
uint8_t address
USB address.
uint8_t ports
Number of downstream ports.
Endpoint is halted due to a TRB error.
unsigned int type
Endpoint type.
struct xhci_trb_host_controller host
Host controller event.
uint32_t reserved_a
Reserved.
uint64_t input
Input context.
uint16_t reserved_a
Reserved.
struct dma_mapping array_map
Array DMA mapping.
uint8_t endpoint
Endpoint ID.
uint32_t reserved_b
Reserved.
union xhci_trb * trb
Transfer request blocks.
Endpoint is halted due to a USB Halt condition.
uint8_t reserved_c
Reserved.
struct xhci_pch pch
Intel PCH quirk.
A reset endpoint transfer request block.
union xhci_trb * trb
Transfer request blocks.
uint32_t drop
Drop context flags.
uint8_t alt
Alternate setting.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ports
Number of ports (if this device is a hub)
uint64_t reserved_a
Reserved.
uint8_t reserved_c
Reserved.
struct xhci_trb_stop_endpoint stop
Stop endpoint TRB.
struct xhci_trb_template template
Template.
unsigned int ctx
Context index.
struct usb_device * usb
USB device.
uint32_t xusb2pr
USB2 port routing register original value.
uint8_t vf
Virtual function ID.
uint64_t reserved_a
Reserved.
uint8_t port
Root hub port number.
uint64_t reserved_a
Reserved.
uint64_t data
Data buffer.
A setup stage transfer request block.
uint16_t mtu
Maximum packet size.
A transfer event transfer request block.
uint8_t direction
Transfer direction.
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
uint8_t config
Configuration value.
uint32_t info
Device info.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct xhci_slot * slot
xHCI slot
struct xhci_endpoint_context * context
Endpoint context.
uint32_t reserved_b
Reserved.
uint32_t reserved_a[5]
Reserved.
A context transfer request block.
uint16_t reserved_c
Reserved.
uint64_t reserved_a
Reserved.
int failed
Command mechanism has permanently failed.
void xhci_unregister(struct xhci_device *xhci)
Unregister xHCI controller.
uint64_t base
Base address.
A link transfer request block.
A transfer request block.
uint64_t * context
Context base addresses.
Device context base address array.
struct xhci_trb_data data
Data stage TRB.
unsigned int intrs
Number of interrupters.
unsigned int tt_id
Transaction translator slot ID.
unsigned int prod
Producer counter.
struct xhci_trb_complete complete
Command completion event.
struct xhci_trb_set_tr_dequeue_pointer dequeue
Set transfer ring dequeue pointer TRB.
void * cap
Capability registers.
unsigned int xecp
xHCI extended capabilities offset
A normal transfer request block.
int addr64
64-bit addressing capability
A port status change transfer request block.
struct xhci_trb_normal normal
Normal TRB.
uint8_t stream
Stream configuration.
uint64_t reserved_a
Reserved.
struct xhci_trb_reset_endpoint reset
Reset endpoint TRB.
uint32_t reserved
Reserved.
uint8_t code
Completion code.
uint8_t tt_id
TT hub slot ID.
struct usb_endpoint * ep
USB endpoint.
uint64_t reserved_a
Reserved.
struct xhci_event_ring_segment * segment
Event ring segment table.
size_t pagesize
Page size.
Universal Serial Bus (USB)
uint16_t latency
Maximum exit latency.
uint16_t intr
Interrupter target.
A stop endpoint transfer request block.
unsigned int mask
Ring counter mask.
uint8_t interval
Polling interval.
uint8_t reserved_b[7]
Reserved.
uint8_t tt_port
TT port number.
uint32_t reserved_b[4]
Reserved.
struct dma_mapping map
DMA mapping.
uint32_t reserved_b
Reserved.
struct io_buffer ** iobuf
I/O buffers.
unsigned int cons
Consumer counter.
struct xhci_trb_ring ring
Transfer ring.
unsigned int tt_port
Transaction translator port.
struct xhci_slot_context * context
Slot context.
struct dma_mapping map
DMA mapping.
struct xhci_trb_port_status port
Port status changed event.
struct dma_device * dma
DMA device.
uint16_t residual
Residual transfer length.
unsigned int legacy
USB legacy support capability (if present and enabled)
struct xhci_trb_link * link
Link TRB (if applicable)
unsigned int shift
Ring size (log2)
A transfer request block command/transfer ring.
int xhci_register(struct xhci_device *xhci)
Register xHCI controller.
struct xhci_trb_status status
Status stage TRB.
uint16_t reserved
Reserved.
uint32_t reserved[3]
Reserved.
uint64_t transfer
Transfer TRB pointer.
unsigned int csz_shift
Context size shift.
struct usb_setup_packet packet
Setup packet.
void * db
Doorbell registers.
uint8_t reserved
Reserved.
unsigned int interval
Endpoint interval.
uint8_t endpoint
Endpoint ID.
uint8_t code
Completion code.
uint8_t reserved
Reserved.
uint16_t esit_low
Max ESIT payload low.
struct xhci_trb_link link
Link TRB.
struct xhci_slot ** slot
Device slots, indexed by slot ID.
uint32_t count
Number of TRBs.
A transfer request block template.
unsigned int quirks
Quirks.
uint64_t parameter
Parameter.
struct xhci_device * xhci
xHCI device
struct xhci_event_ring event
Event ring.
void * op
Operational registers.
uint16_t reserved_c
Reserved.
uint8_t endpoint
Endpoint ID.
uint8_t reserved_b
Reserved.
void xhci_init(struct xhci_device *xhci)
Initialise device.
struct dma_mapping trb_map
Transfer request blocks DMA mapping.
uint32_t reserved_a
Reserved.
uint32_t reserved_b
Reserved.