iPXE
Data Structures | Macros | Enumerations | Functions
xhci.h File Reference

USB eXtensible Host Controller Interface (xHCI) driver. More...

#include <assert.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>

Go to the source code of this file.

Data Structures

struct  xhci_trb_template
 A transfer request block template. More...
 
struct  xhci_trb_common
 A transfer request block. More...
 
struct  xhci_trb_normal
 A normal transfer request block. More...
 
struct  xhci_trb_setup
 A setup stage transfer request block. More...
 
struct  xhci_trb_data
 A data stage transfer request block. More...
 
struct  xhci_trb_status
 A status stage transfer request block. More...
 
struct  xhci_trb_link
 A link transfer request block. More...
 
struct  xhci_trb_enable_slot
 An enable slot transfer request block. More...
 
struct  xhci_trb_disable_slot
 A disable slot transfer request block. More...
 
struct  xhci_trb_context
 A context transfer request block. More...
 
struct  xhci_trb_reset_endpoint
 A reset endpoint transfer request block. More...
 
struct  xhci_trb_stop_endpoint
 A stop endpoint transfer request block. More...
 
struct  xhci_trb_set_tr_dequeue_pointer
 A set transfer ring dequeue pointer transfer request block. More...
 
struct  xhci_trb_transfer
 A transfer event transfer request block. More...
 
struct  xhci_trb_complete
 A command completion event transfer request block. More...
 
struct  xhci_trb_port_status
 A port status change transfer request block. More...
 
struct  xhci_trb_host_controller
 A port status change transfer request block. More...
 
union  xhci_trb
 A transfer request block. More...
 
struct  xhci_control_context
 An input control context. More...
 
struct  xhci_slot_context
 A slot context. More...
 
struct  xhci_endpoint_context
 An endpoint context. More...
 
struct  xhci_event_ring_segment
 An event ring segment. More...
 
struct  xhci_trb_ring
 A transfer request block command/transfer ring. More...
 
struct  xhci_event_ring
 An event ring. More...
 
struct  xhci_pch
 Intel PCH quirk. More...
 
struct  xhci_dcbaa
 Device context base address array. More...
 
struct  xhci_scratchpad
 Scratchpad buffer. More...
 
struct  xhci_device
 An xHCI device. More...
 
struct  xhci_slot
 An xHCI device slot. More...
 
struct  xhci_endpoint
 An xHCI endpoint. More...
 

Macros

#define XHCI_MIN_ALIGN   64
 Minimum alignment required for data structures. More...
 
#define XHCI_MTU   65536
 Maximum transfer size. More...
 
#define XHCI_BAR   PCI_BASE_ADDRESS_0
 xHCI PCI BAR More...
 
#define XHCI_CAP_CAPLENGTH   0x00
 Capability register length. More...
 
#define XHCI_CAP_HCIVERSION   0x02
 Host controller interface version number. More...
 
#define XHCI_CAP_HCSPARAMS1   0x04
 Structural parameters 1. More...
 
#define XHCI_HCSPARAMS1_SLOTS(params)   ( ( (params) >> 0 ) & 0xff )
 Number of device slots. More...
 
#define XHCI_HCSPARAMS1_INTRS(params)   ( ( (params) >> 8 ) & 0x3ff )
 Number of interrupters. More...
 
#define XHCI_HCSPARAMS1_PORTS(params)   ( ( (params) >> 24 ) & 0xff )
 Number of ports. More...
 
#define XHCI_CAP_HCSPARAMS2   0x08
 Structural parameters 2. More...
 
#define XHCI_HCSPARAMS2_SCRATCHPADS(params)   ( ( ( (params) >> 16 ) & 0x3e0 ) | ( ( (params) >> 27 ) & 0x1f ) )
 Number of page-sized scratchpad buffers. More...
 
#define XHCI_CAP_HCCPARAMS1   0x10
 Capability parameters. More...
 
#define XHCI_HCCPARAMS1_ADDR64(params)   ( ( (params) >> 0 ) & 0x1 )
 64-bit addressing capability More...
 
#define XHCI_HCCPARAMS1_CSZ_SHIFT(params)   ( 5 + ( ( (params) >> 2 ) & 0x1 ) )
 Context size shift. More...
 
#define XHCI_HCCPARAMS1_XECP(params)   ( ( ( (params) >> 16 ) & 0xffff ) << 2 )
 xHCI extended capabilities pointer More...
 
#define XHCI_CAP_DBOFF   0x14
 Doorbell offset. More...
 
#define XHCI_CAP_RTSOFF   0x18
 Runtime register space offset. More...
 
#define XHCI_XECP_ID(xecp)   ( ( (xecp) >> 0 ) & 0xff )
 xHCI extended capability ID More...
 
#define XHCI_XECP_NEXT(xecp)   ( ( ( (xecp) >> 8 ) & 0xff ) << 2 )
 Next xHCI extended capability pointer. More...
 
#define XHCI_XECP_ID_LEGACY   1
 USB legacy support extended capability. More...
 
#define XHCI_USBLEGSUP_BIOS   0x02
 USB legacy support BIOS owned semaphore. More...
 
#define XHCI_USBLEGSUP_BIOS_OWNED   0x01
 USB legacy support BIOS ownership flag. More...
 
#define XHCI_USBLEGSUP_OS   0x03
 USB legacy support OS owned semaphore. More...
 
#define XHCI_USBLEGSUP_OS_OWNED   0x01
 USB legacy support OS ownership flag. More...
 
#define XHCI_USBLEGSUP_CTLSTS   0x04
 USB legacy support control/status. More...
 
#define XHCI_XECP_ID_SUPPORTED   2
 Supported protocol extended capability. More...
 
#define XHCI_SUPPORTED_REVISION   0x00
 Supported protocol revision. More...
 
#define XHCI_SUPPORTED_REVISION_VER(revision)   ( ( (revision) >> 16 ) & 0xffff )
 Supported protocol minor revision. More...
 
#define XHCI_SUPPORTED_NAME   0x04
 Supported protocol name. More...
 
#define XHCI_SUPPORTED_PORTS   0x08
 Supported protocol ports. More...
 
#define XHCI_SUPPORTED_PORTS_OFFSET(ports)   ( ( (ports) >> 0 ) & 0xff )
 Supported protocol port offset. More...
 
#define XHCI_SUPPORTED_PORTS_COUNT(ports)   ( ( (ports) >> 8 ) & 0xff )
 Supported protocol port count. More...
 
#define XHCI_SUPPORTED_PORTS_PSIC(ports)   ( ( (ports) >> 28 ) & 0x0f )
 Supported protocol PSI count. More...
 
#define XHCI_SUPPORTED_SLOT   0x0c
 Supported protocol slot. More...
 
#define XHCI_SUPPORTED_SLOT_TYPE(slot)   ( ( (slot) >> 0 ) & 0x1f )
 Supported protocol slot type. More...
 
#define XHCI_SUPPORTED_PSI(index)   ( 0x10 + ( (index) * 4 ) )
 Supported protocol PSI. More...
 
#define XHCI_SUPPORTED_PSI_VALUE(psi)   ( ( (psi) >> 0 ) & 0x0f )
 Supported protocol PSI value. More...
 
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)   ( ( (psi) >> 16 ) & 0xffff )
 Supported protocol PSI mantissa. More...
 
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)   ( ( (psi) >> 4 ) & 0x03 )
 Supported protocol PSI exponent. More...
 
#define XHCI_OP_USBCMD   0x00
 USB command register. More...
 
#define XHCI_USBCMD_RUN   0x00000001UL
 Run/stop. More...
 
#define XHCI_USBCMD_HCRST   0x00000002UL
 Host controller reset. More...
 
#define XHCI_OP_USBSTS   0x04
 USB status register. More...
 
#define XHCI_USBSTS_HCH   0x00000001UL
 Host controller halted. More...
 
#define XHCI_OP_PAGESIZE   0x08
 Page size register. More...
 
#define XHCI_PAGESIZE(pagesize)   ( (pagesize) << 12 )
 Page size. More...
 
#define XHCI_OP_DNCTRL   0x14
 Device notifcation control register. More...
 
#define XHCI_OP_CRCR   0x18
 Command ring control register. More...
 
#define XHCI_CRCR_RCS   0x00000001UL
 Command ring cycle state. More...
 
#define XHCI_CRCR_CA   0x00000004UL
 Command abort. More...
 
#define XHCI_CRCR_CRR   0x00000008UL
 Command ring running. More...
 
#define XHCI_OP_DCBAAP   0x30
 Device context base address array pointer. More...
 
#define XHCI_OP_CONFIG   0x38
 Configure register. More...
 
#define XHCI_CONFIG_MAX_SLOTS_EN(slots)   ( (slots) << 0 )
 Maximum device slots enabled. More...
 
#define XHCI_CONFIG_MAX_SLOTS_EN_MASK   XHCI_CONFIG_MAX_SLOTS_EN ( 0xff )
 Maximum device slots enabled mask. More...
 
#define XHCI_OP_PORTSC(port)   ( 0x400 - 0x10 + ( (port) << 4 ) )
 Port status and control register. More...
 
#define XHCI_PORTSC_CCS   0x00000001UL
 Current connect status. More...
 
#define XHCI_PORTSC_PED   0x00000002UL
 Port enabled. More...
 
#define XHCI_PORTSC_PR   0x00000010UL
 Port reset. More...
 
#define XHCI_PORTSC_PLS(pls)   ( (pls) << 5 )
 Port link state. More...
 
#define XHCI_PORTSC_PLS_DISABLED   XHCI_PORTSC_PLS ( 4 )
 Disabled port link state. More...
 
#define XHCI_PORTSC_PLS_RXDETECT   XHCI_PORTSC_PLS ( 5 )
 RxDetect port link state. More...
 
#define XHCI_PORTSC_PLS_MASK   XHCI_PORTSC_PLS ( 0xf )
 Port link state mask. More...
 
#define XHCI_PORTSC_PP   0x00000200UL
 Port power. More...
 
#define XHCI_PORT_POWER_DELAY_MS   20
 Time to delay after enabling power to a port. More...
 
#define XHCI_PORTSC_PSIV(portsc)   ( ( (portsc) >> 10 ) & 0xf )
 Port speed ID value. More...
 
#define XHCI_PORTSC_PIC(indicators)   ( (indicators) << 14 )
 Port indicator control. More...
 
#define XHCI_PORTSC_PIC_MASK   XHCI_PORTSC_PIC ( 3 )
 Port indicator control mask. More...
 
#define XHCI_PORTSC_LWS   0x00010000UL
 Port link state write strobe. More...
 
#define XHCI_LINK_STATE_DELAY_MS   100
 Time to delay after writing the port link state. More...
 
#define XHCI_PORTSC_CSC   0x00020000UL
 Connect status change. More...
 
#define XHCI_PORTSC_PEC   0x00040000UL
 Port enabled/disabled change. More...
 
#define XHCI_PORTSC_WRC   0x00080000UL
 Warm port reset change. More...
 
#define XHCI_PORTSC_OCC   0x00100000UL
 Over-current change. More...
 
#define XHCI_PORTSC_PRC   0x00200000UL
 Port reset change. More...
 
#define XHCI_PORTSC_PLC   0x00400000UL
 Port link state change. More...
 
#define XHCI_PORTSC_CEC   0x00800000UL
 Port config error change. More...
 
#define XHCI_PORTSC_CHANGE
 Port status change mask. More...
 
#define XHCI_PORTSC_PRESERVE   ( XHCI_PORTSC_PP | XHCI_PORTSC_PIC_MASK )
 Port status and control bits which should be preserved. More...
 
#define XHCI_OP_PORTPMSC(port)   ( 0x404 - 0x10 + ( (port) << 4 ) )
 Port power management status and control register. More...
 
#define XHCI_OP_PORTLI(port)   ( 0x408 - 0x10 + ( (port) << 4 ) )
 Port link info register. More...
 
#define XHCI_OP_PORTHLPMC(port)   ( 0x40c - 0x10 + ( (port) << 4 ) )
 Port hardware link power management control register. More...
 
#define XHCI_RUN_ERSTSZ(intr)   ( 0x28 + ( (intr) << 5 ) )
 Event ring segment table size register. More...
 
#define XHCI_RUN_ERSTBA(intr)   ( 0x30 + ( (intr) << 5 ) )
 Event ring segment table base address register. More...
 
#define XHCI_RUN_ERDP(intr)   ( 0x38 + ( (intr) << 5 ) )
 Event ring dequeue pointer register. More...
 
#define XHCI_TRB_C   0x01
 Transfer request block cycle bit flag. More...
 
#define XHCI_TRB_TC   0x02
 Transfer request block toggle cycle bit flag. More...
 
#define XHCI_TRB_CH   0x10
 Transfer request block chain flag. More...
 
#define XHCI_TRB_IOC   0x20
 Transfer request block interrupt on completion flag. More...
 
#define XHCI_TRB_IDT   0x40
 Transfer request block immediate data flag. More...
 
#define XHCI_TRB_TYPE(type)   ( (type) << 2 )
 Transfer request block type. More...
 
#define XHCI_TRB_TYPE_MASK   XHCI_TRB_TYPE ( 0x3f )
 Transfer request block type mask. More...
 
#define XHCI_TRB_NORMAL   XHCI_TRB_TYPE ( 1 )
 A normal transfer request block. More...
 
#define XHCI_TD_SIZE(remaining)   ( ( ( (remaining) <= 0xf ) ? remaining : 0xf ) << 17 )
 Construct TD size field. More...
 
#define XHCI_TRB_SETUP   XHCI_TRB_TYPE ( 2 )
 A setup stage transfer request block. More...
 
#define XHCI_SETUP_IN   3
 Setup stage input data direction. More...
 
#define XHCI_SETUP_OUT   2
 Setup stage output data direction. More...
 
#define XHCI_TRB_DATA   XHCI_TRB_TYPE ( 3 )
 A data stage transfer request block. More...
 
#define XHCI_DATA_IN   0x01
 Input data direction. More...
 
#define XHCI_DATA_OUT   0x00
 Output data direction. More...
 
#define XHCI_TRB_STATUS   XHCI_TRB_TYPE ( 4 )
 A status stage transfer request block. More...
 
#define XHCI_STATUS_IN   0x01
 Input status direction. More...
 
#define XHCI_STATUS_OUT   0x00
 Output status direction. More...
 
#define XHCI_TRB_LINK   XHCI_TRB_TYPE ( 6 )
 A link transfer request block. More...
 
#define XHCI_TRB_NOP   XHCI_TRB_TYPE ( 8 )
 A no-op transfer request block. More...
 
#define XHCI_TRB_ENABLE_SLOT   XHCI_TRB_TYPE ( 9 )
 An enable slot transfer request block. More...
 
#define XHCI_TRB_DISABLE_SLOT   XHCI_TRB_TYPE ( 10 )
 A disable slot transfer request block. More...
 
#define XHCI_TRB_ADDRESS_DEVICE   XHCI_TRB_TYPE ( 11 )
 An address device transfer request block. More...
 
#define XHCI_TRB_CONFIGURE_ENDPOINT   XHCI_TRB_TYPE ( 12 )
 A configure endpoint transfer request block. More...
 
#define XHCI_TRB_EVALUATE_CONTEXT   XHCI_TRB_TYPE ( 13 )
 An evaluate context transfer request block. More...
 
#define XHCI_TRB_RESET_ENDPOINT   XHCI_TRB_TYPE ( 14 )
 A reset endpoint transfer request block. More...
 
#define XHCI_TRB_STOP_ENDPOINT   XHCI_TRB_TYPE ( 15 )
 A stop endpoint transfer request block. More...
 
#define XHCI_TRB_SET_TR_DEQUEUE_POINTER   XHCI_TRB_TYPE ( 16 )
 A set transfer ring dequeue pointer transfer request block. More...
 
#define XHCI_TRB_NOP_CMD   XHCI_TRB_TYPE ( 23 )
 A no-op command transfer request block. More...
 
#define XHCI_TRB_TRANSFER   XHCI_TRB_TYPE ( 32 )
 A transfer event transfer request block. More...
 
#define XHCI_TRB_COMPLETE   XHCI_TRB_TYPE ( 33 )
 A command completion event transfer request block. More...
 
#define XHCI_TRB_PORT_STATUS   XHCI_TRB_TYPE ( 34 )
 A port status change transfer request block. More...
 
#define XHCI_TRB_HOST_CONTROLLER   XHCI_TRB_TYPE ( 37 )
 A port status change transfer request block. More...
 
#define XHCI_SLOT_INFO(entries, hub, speed, route)   ( ( (entries) << 27 ) | ( (hub) << 26 ) | ( (speed) << 20 ) | (route) )
 Construct slot context device info. More...
 
#define XHCI_ENDPOINT_STATE_MASK   0x07
 Endpoint state mask. More...
 
#define XHCI_EP_TYPE(type)   ( (type) << 3 )
 Endpoint type. More...
 
#define XHCI_EP_TYPE_CONTROL   XHCI_EP_TYPE ( 4 )
 Control endpoint type. More...
 
#define XHCI_EP_TYPE_IN   XHCI_EP_TYPE ( 4 )
 Input endpoint type. More...
 
#define XHCI_EP_TYPE_PERIODIC   XHCI_EP_TYPE ( 1 )
 Periodic endpoint type. More...
 
#define XHCI_EP_DCS   0x00000001UL
 Endpoint dequeue cycle state. More...
 
#define XHCI_EP0_TRB_LEN   8
 Control endpoint average TRB length. More...
 
#define XHCI_DBVAL(target, stream)   ( (target) | ( (stream) << 16 ) )
 Calculate doorbell register value. More...
 
#define XHCI_CTX_SLOT   0
 Slot context index. More...
 
#define XHCI_CTX(address)
 Calculate context index from USB endpoint address. More...
 
#define XHCI_CTX_EP0   XHCI_CTX ( 0x00 )
 Endpoint zero context index. More...
 
#define XHCI_CTX_END   32
 End of contexts. More...
 
#define XHCI_DCI(ctx)   ( (ctx) + 0 )
 Device context index. More...
 
#define XHCI_ICI(ctx)   ( (ctx) + 1 )
 Input context index. More...
 
#define XHCI_CMD_TRBS_LOG2   2
 Number of TRBs (excluding Link TRB) in the command ring. More...
 
#define XHCI_EVENT_TRBS_LOG2   6
 Number of TRBs in the event ring. More...
 
#define XHCI_TRANSFER_TRBS_LOG2   6
 Number of TRBs in a transfer ring. More...
 
#define XHCI_USBLEGSUP_MAX_WAIT_MS   100
 Maximum time to wait for BIOS to release ownership. More...
 
#define XHCI_STOP_MAX_WAIT_MS   100
 Maximum time to wait for host controller to stop. More...
 
#define XHCI_RESET_MAX_WAIT_MS   500
 Maximum time to wait for reset to complete. More...
 
#define XHCI_COMMAND_MAX_WAIT_MS   USB_CONTROL_MAX_WAIT_MS
 Maximum time to wait for a command to complete. More...
 
#define XHCI_COMMAND_ABORT_DELAY_MS   500
 Time to delay after aborting a command. More...
 
#define XHCI_PORT_RESET_MAX_WAIT_MS   500
 Maximum time to wait for a port reset to complete. More...
 
#define XHCI_PCH   0x0001
 Intel PCH quirk flag. More...
 
#define XHCI_PCH_XUSB2PR   0xd0
 Intel PCH USB2 port routing register. More...
 
#define XHCI_PCH_XUSB2PRM   0xd4
 Intel PCH USB2 port routing mask register. More...
 
#define XHCI_PCH_USB3PSSEN   0xd8
 Intel PCH SuperSpeed enable register. More...
 
#define XHCI_PCH_USB3PRM   0xdc
 Intel PCH USB3 port routing mask register. More...
 
#define XHCI_BAD_PSIV   0x0002
 Invalid protocol speed ID values quirk. More...
 

Enumerations

enum  xhci_default_psi_value { XHCI_SPEED_FULL = 1, XHCI_SPEED_LOW = 2, XHCI_SPEED_HIGH = 3, XHCI_SPEED_SUPER = 4 }
 Default PSI values. More...
 
enum  xhci_completion_code { XHCI_CMPLT_SUCCESS = 1, XHCI_CMPLT_SHORT = 13, XHCI_CMPLT_CMD_STOPPED = 24 }
 xHCI completion codes More...
 
enum  xhci_endpoint_state {
  XHCI_ENDPOINT_DISABLED = 0, XHCI_ENDPOINT_RUNNING = 1, XHCI_ENDPOINT_HALTED = 2, XHCI_ENDPOINT_STOPPED = 3,
  XHCI_ENDPOINT_ERROR = 4
}
 Endpoint states. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static unsigned int xhci_ring_fill (struct xhci_trb_ring *ring)
 Calculate space used in TRB ring. More...
 
static unsigned int xhci_ring_remaining (struct xhci_trb_ring *ring)
 Calculate space remaining in TRB ring. More...
 
static physaddr_t xhci_ring_consumed (struct xhci_trb_ring *ring)
 Calculate physical address of most recently consumed TRB. More...
 
void xhci_init (struct xhci_device *xhci)
 Initialise device. More...
 
int xhci_register (struct xhci_device *xhci)
 Register xHCI controller. More...
 
void xhci_unregister (struct xhci_device *xhci)
 Unregister xHCI controller. More...
 

Detailed Description

USB eXtensible Host Controller Interface (xHCI) driver.

Definition in file xhci.h.

Macro Definition Documentation

◆ XHCI_MIN_ALIGN

#define XHCI_MIN_ALIGN   64

Minimum alignment required for data structures.

With the exception of the scratchpad buffer pages (which are page-aligned), data structures used by xHCI generally require from 16 to 64 byte alignment and must not cross an (xHCI) page boundary. We simplify this requirement by aligning each structure on its own size, with a minimum of a 64 byte alignment.

Definition at line 24 of file xhci.h.

◆ XHCI_MTU

#define XHCI_MTU   65536

Maximum transfer size.

Definition at line 27 of file xhci.h.

◆ XHCI_BAR

#define XHCI_BAR   PCI_BASE_ADDRESS_0

xHCI PCI BAR

Definition at line 30 of file xhci.h.

◆ XHCI_CAP_CAPLENGTH

#define XHCI_CAP_CAPLENGTH   0x00

Capability register length.

Definition at line 33 of file xhci.h.

◆ XHCI_CAP_HCIVERSION

#define XHCI_CAP_HCIVERSION   0x02

Host controller interface version number.

Definition at line 36 of file xhci.h.

◆ XHCI_CAP_HCSPARAMS1

#define XHCI_CAP_HCSPARAMS1   0x04

Structural parameters 1.

Definition at line 39 of file xhci.h.

◆ XHCI_HCSPARAMS1_SLOTS

#define XHCI_HCSPARAMS1_SLOTS (   params)    ( ( (params) >> 0 ) & 0xff )

Number of device slots.

Definition at line 42 of file xhci.h.

◆ XHCI_HCSPARAMS1_INTRS

#define XHCI_HCSPARAMS1_INTRS (   params)    ( ( (params) >> 8 ) & 0x3ff )

Number of interrupters.

Definition at line 45 of file xhci.h.

◆ XHCI_HCSPARAMS1_PORTS

#define XHCI_HCSPARAMS1_PORTS (   params)    ( ( (params) >> 24 ) & 0xff )

Number of ports.

Definition at line 48 of file xhci.h.

◆ XHCI_CAP_HCSPARAMS2

#define XHCI_CAP_HCSPARAMS2   0x08

Structural parameters 2.

Definition at line 51 of file xhci.h.

◆ XHCI_HCSPARAMS2_SCRATCHPADS

#define XHCI_HCSPARAMS2_SCRATCHPADS (   params)    ( ( ( (params) >> 16 ) & 0x3e0 ) | ( ( (params) >> 27 ) & 0x1f ) )

Number of page-sized scratchpad buffers.

Definition at line 54 of file xhci.h.

◆ XHCI_CAP_HCCPARAMS1

#define XHCI_CAP_HCCPARAMS1   0x10

Capability parameters.

Definition at line 58 of file xhci.h.

◆ XHCI_HCCPARAMS1_ADDR64

#define XHCI_HCCPARAMS1_ADDR64 (   params)    ( ( (params) >> 0 ) & 0x1 )

64-bit addressing capability

Definition at line 61 of file xhci.h.

◆ XHCI_HCCPARAMS1_CSZ_SHIFT

#define XHCI_HCCPARAMS1_CSZ_SHIFT (   params)    ( 5 + ( ( (params) >> 2 ) & 0x1 ) )

Context size shift.

Definition at line 64 of file xhci.h.

◆ XHCI_HCCPARAMS1_XECP

#define XHCI_HCCPARAMS1_XECP (   params)    ( ( ( (params) >> 16 ) & 0xffff ) << 2 )

xHCI extended capabilities pointer

Definition at line 67 of file xhci.h.

◆ XHCI_CAP_DBOFF

#define XHCI_CAP_DBOFF   0x14

Doorbell offset.

Definition at line 70 of file xhci.h.

◆ XHCI_CAP_RTSOFF

#define XHCI_CAP_RTSOFF   0x18

Runtime register space offset.

Definition at line 73 of file xhci.h.

◆ XHCI_XECP_ID

#define XHCI_XECP_ID (   xecp)    ( ( (xecp) >> 0 ) & 0xff )

xHCI extended capability ID

Definition at line 76 of file xhci.h.

◆ XHCI_XECP_NEXT

#define XHCI_XECP_NEXT (   xecp)    ( ( ( (xecp) >> 8 ) & 0xff ) << 2 )

Next xHCI extended capability pointer.

Definition at line 79 of file xhci.h.

◆ XHCI_XECP_ID_LEGACY

#define XHCI_XECP_ID_LEGACY   1

USB legacy support extended capability.

Definition at line 82 of file xhci.h.

◆ XHCI_USBLEGSUP_BIOS

#define XHCI_USBLEGSUP_BIOS   0x02

USB legacy support BIOS owned semaphore.

Definition at line 85 of file xhci.h.

◆ XHCI_USBLEGSUP_BIOS_OWNED

#define XHCI_USBLEGSUP_BIOS_OWNED   0x01

USB legacy support BIOS ownership flag.

Definition at line 88 of file xhci.h.

◆ XHCI_USBLEGSUP_OS

#define XHCI_USBLEGSUP_OS   0x03

USB legacy support OS owned semaphore.

Definition at line 91 of file xhci.h.

◆ XHCI_USBLEGSUP_OS_OWNED

#define XHCI_USBLEGSUP_OS_OWNED   0x01

USB legacy support OS ownership flag.

Definition at line 94 of file xhci.h.

◆ XHCI_USBLEGSUP_CTLSTS

#define XHCI_USBLEGSUP_CTLSTS   0x04

USB legacy support control/status.

Definition at line 97 of file xhci.h.

◆ XHCI_XECP_ID_SUPPORTED

#define XHCI_XECP_ID_SUPPORTED   2

Supported protocol extended capability.

Definition at line 100 of file xhci.h.

◆ XHCI_SUPPORTED_REVISION

#define XHCI_SUPPORTED_REVISION   0x00

Supported protocol revision.

Definition at line 103 of file xhci.h.

◆ XHCI_SUPPORTED_REVISION_VER

#define XHCI_SUPPORTED_REVISION_VER (   revision)    ( ( (revision) >> 16 ) & 0xffff )

Supported protocol minor revision.

Definition at line 106 of file xhci.h.

◆ XHCI_SUPPORTED_NAME

#define XHCI_SUPPORTED_NAME   0x04

Supported protocol name.

Definition at line 109 of file xhci.h.

◆ XHCI_SUPPORTED_PORTS

#define XHCI_SUPPORTED_PORTS   0x08

Supported protocol ports.

Definition at line 112 of file xhci.h.

◆ XHCI_SUPPORTED_PORTS_OFFSET

#define XHCI_SUPPORTED_PORTS_OFFSET (   ports)    ( ( (ports) >> 0 ) & 0xff )

Supported protocol port offset.

Definition at line 115 of file xhci.h.

◆ XHCI_SUPPORTED_PORTS_COUNT

#define XHCI_SUPPORTED_PORTS_COUNT (   ports)    ( ( (ports) >> 8 ) & 0xff )

Supported protocol port count.

Definition at line 118 of file xhci.h.

◆ XHCI_SUPPORTED_PORTS_PSIC

#define XHCI_SUPPORTED_PORTS_PSIC (   ports)    ( ( (ports) >> 28 ) & 0x0f )

Supported protocol PSI count.

Definition at line 121 of file xhci.h.

◆ XHCI_SUPPORTED_SLOT

#define XHCI_SUPPORTED_SLOT   0x0c

Supported protocol slot.

Definition at line 124 of file xhci.h.

◆ XHCI_SUPPORTED_SLOT_TYPE

#define XHCI_SUPPORTED_SLOT_TYPE (   slot)    ( ( (slot) >> 0 ) & 0x1f )

Supported protocol slot type.

Definition at line 127 of file xhci.h.

◆ XHCI_SUPPORTED_PSI

#define XHCI_SUPPORTED_PSI (   index)    ( 0x10 + ( (index) * 4 ) )

Supported protocol PSI.

Definition at line 130 of file xhci.h.

◆ XHCI_SUPPORTED_PSI_VALUE

#define XHCI_SUPPORTED_PSI_VALUE (   psi)    ( ( (psi) >> 0 ) & 0x0f )

Supported protocol PSI value.

Definition at line 133 of file xhci.h.

◆ XHCI_SUPPORTED_PSI_MANTISSA

#define XHCI_SUPPORTED_PSI_MANTISSA (   psi)    ( ( (psi) >> 16 ) & 0xffff )

Supported protocol PSI mantissa.

Definition at line 136 of file xhci.h.

◆ XHCI_SUPPORTED_PSI_EXPONENT

#define XHCI_SUPPORTED_PSI_EXPONENT (   psi)    ( ( (psi) >> 4 ) & 0x03 )

Supported protocol PSI exponent.

Definition at line 139 of file xhci.h.

◆ XHCI_OP_USBCMD

#define XHCI_OP_USBCMD   0x00

USB command register.

Definition at line 154 of file xhci.h.

◆ XHCI_USBCMD_RUN

#define XHCI_USBCMD_RUN   0x00000001UL

Run/stop.

Definition at line 157 of file xhci.h.

◆ XHCI_USBCMD_HCRST

#define XHCI_USBCMD_HCRST   0x00000002UL

Host controller reset.

Definition at line 160 of file xhci.h.

◆ XHCI_OP_USBSTS

#define XHCI_OP_USBSTS   0x04

USB status register.

Definition at line 163 of file xhci.h.

◆ XHCI_USBSTS_HCH

#define XHCI_USBSTS_HCH   0x00000001UL

Host controller halted.

Definition at line 166 of file xhci.h.

◆ XHCI_OP_PAGESIZE

#define XHCI_OP_PAGESIZE   0x08

Page size register.

Definition at line 169 of file xhci.h.

◆ XHCI_PAGESIZE

#define XHCI_PAGESIZE (   pagesize)    ( (pagesize) << 12 )

Page size.

Definition at line 172 of file xhci.h.

◆ XHCI_OP_DNCTRL

#define XHCI_OP_DNCTRL   0x14

Device notifcation control register.

Definition at line 175 of file xhci.h.

◆ XHCI_OP_CRCR

#define XHCI_OP_CRCR   0x18

Command ring control register.

Definition at line 178 of file xhci.h.

◆ XHCI_CRCR_RCS

#define XHCI_CRCR_RCS   0x00000001UL

Command ring cycle state.

Definition at line 181 of file xhci.h.

◆ XHCI_CRCR_CA

#define XHCI_CRCR_CA   0x00000004UL

Command abort.

Definition at line 184 of file xhci.h.

◆ XHCI_CRCR_CRR

#define XHCI_CRCR_CRR   0x00000008UL

Command ring running.

Definition at line 187 of file xhci.h.

◆ XHCI_OP_DCBAAP

#define XHCI_OP_DCBAAP   0x30

Device context base address array pointer.

Definition at line 190 of file xhci.h.

◆ XHCI_OP_CONFIG

#define XHCI_OP_CONFIG   0x38

Configure register.

Definition at line 193 of file xhci.h.

◆ XHCI_CONFIG_MAX_SLOTS_EN

#define XHCI_CONFIG_MAX_SLOTS_EN (   slots)    ( (slots) << 0 )

Maximum device slots enabled.

Definition at line 196 of file xhci.h.

◆ XHCI_CONFIG_MAX_SLOTS_EN_MASK

#define XHCI_CONFIG_MAX_SLOTS_EN_MASK   XHCI_CONFIG_MAX_SLOTS_EN ( 0xff )

Maximum device slots enabled mask.

Definition at line 199 of file xhci.h.

◆ XHCI_OP_PORTSC

#define XHCI_OP_PORTSC (   port)    ( 0x400 - 0x10 + ( (port) << 4 ) )

Port status and control register.

Definition at line 203 of file xhci.h.

◆ XHCI_PORTSC_CCS

#define XHCI_PORTSC_CCS   0x00000001UL

Current connect status.

Definition at line 206 of file xhci.h.

◆ XHCI_PORTSC_PED

#define XHCI_PORTSC_PED   0x00000002UL

Port enabled.

Definition at line 209 of file xhci.h.

◆ XHCI_PORTSC_PR

#define XHCI_PORTSC_PR   0x00000010UL

Port reset.

Definition at line 212 of file xhci.h.

◆ XHCI_PORTSC_PLS

#define XHCI_PORTSC_PLS (   pls)    ( (pls) << 5 )

Port link state.

Definition at line 215 of file xhci.h.

◆ XHCI_PORTSC_PLS_DISABLED

#define XHCI_PORTSC_PLS_DISABLED   XHCI_PORTSC_PLS ( 4 )

Disabled port link state.

Definition at line 218 of file xhci.h.

◆ XHCI_PORTSC_PLS_RXDETECT

#define XHCI_PORTSC_PLS_RXDETECT   XHCI_PORTSC_PLS ( 5 )

RxDetect port link state.

Definition at line 221 of file xhci.h.

◆ XHCI_PORTSC_PLS_MASK

#define XHCI_PORTSC_PLS_MASK   XHCI_PORTSC_PLS ( 0xf )

Port link state mask.

Definition at line 224 of file xhci.h.

◆ XHCI_PORTSC_PP

#define XHCI_PORTSC_PP   0x00000200UL

Port power.

Definition at line 227 of file xhci.h.

◆ XHCI_PORT_POWER_DELAY_MS

#define XHCI_PORT_POWER_DELAY_MS   20

Time to delay after enabling power to a port.

Definition at line 230 of file xhci.h.

◆ XHCI_PORTSC_PSIV

#define XHCI_PORTSC_PSIV (   portsc)    ( ( (portsc) >> 10 ) & 0xf )

Port speed ID value.

Definition at line 233 of file xhci.h.

◆ XHCI_PORTSC_PIC

#define XHCI_PORTSC_PIC (   indicators)    ( (indicators) << 14 )

Port indicator control.

Definition at line 236 of file xhci.h.

◆ XHCI_PORTSC_PIC_MASK

#define XHCI_PORTSC_PIC_MASK   XHCI_PORTSC_PIC ( 3 )

Port indicator control mask.

Definition at line 239 of file xhci.h.

◆ XHCI_PORTSC_LWS

#define XHCI_PORTSC_LWS   0x00010000UL

Port link state write strobe.

Definition at line 242 of file xhci.h.

◆ XHCI_LINK_STATE_DELAY_MS

#define XHCI_LINK_STATE_DELAY_MS   100

Time to delay after writing the port link state.

Definition at line 245 of file xhci.h.

◆ XHCI_PORTSC_CSC

#define XHCI_PORTSC_CSC   0x00020000UL

Connect status change.

Definition at line 248 of file xhci.h.

◆ XHCI_PORTSC_PEC

#define XHCI_PORTSC_PEC   0x00040000UL

Port enabled/disabled change.

Definition at line 251 of file xhci.h.

◆ XHCI_PORTSC_WRC

#define XHCI_PORTSC_WRC   0x00080000UL

Warm port reset change.

Definition at line 254 of file xhci.h.

◆ XHCI_PORTSC_OCC

#define XHCI_PORTSC_OCC   0x00100000UL

Over-current change.

Definition at line 257 of file xhci.h.

◆ XHCI_PORTSC_PRC

#define XHCI_PORTSC_PRC   0x00200000UL

Port reset change.

Definition at line 260 of file xhci.h.

◆ XHCI_PORTSC_PLC

#define XHCI_PORTSC_PLC   0x00400000UL

Port link state change.

Definition at line 263 of file xhci.h.

◆ XHCI_PORTSC_CEC

#define XHCI_PORTSC_CEC   0x00800000UL

Port config error change.

Definition at line 266 of file xhci.h.

◆ XHCI_PORTSC_CHANGE

#define XHCI_PORTSC_CHANGE
Value:
XHCI_PORTSC_OCC | XHCI_PORTSC_PRC | XHCI_PORTSC_PLC | \
XHCI_PORTSC_CEC )
#define XHCI_PORTSC_WRC
Warm port reset change.
Definition: xhci.h:254
#define XHCI_PORTSC_PRC
Port reset change.
Definition: xhci.h:260
#define XHCI_PORTSC_PEC
Port enabled/disabled change.
Definition: xhci.h:251
#define XHCI_PORTSC_CSC
Connect status change.
Definition: xhci.h:248
#define XHCI_PORTSC_PLC
Port link state change.
Definition: xhci.h:263

Port status change mask.

Definition at line 269 of file xhci.h.

◆ XHCI_PORTSC_PRESERVE

#define XHCI_PORTSC_PRESERVE   ( XHCI_PORTSC_PP | XHCI_PORTSC_PIC_MASK )

Port status and control bits which should be preserved.

The port status and control register is a horrendous mix of differing semantics. Some bits are written to only when a separate write strobe bit is set. Some bits should be preserved when modifying other bits. Some bits will be cleared if written back as a one. Most excitingly, the "port enabled" bit has the semantics that 1=enabled, 0=disabled, yet writing a 1 will disable the port.

Definition at line 283 of file xhci.h.

◆ XHCI_OP_PORTPMSC

#define XHCI_OP_PORTPMSC (   port)    ( 0x404 - 0x10 + ( (port) << 4 ) )

Port power management status and control register.

Definition at line 286 of file xhci.h.

◆ XHCI_OP_PORTLI

#define XHCI_OP_PORTLI (   port)    ( 0x408 - 0x10 + ( (port) << 4 ) )

Port link info register.

Definition at line 289 of file xhci.h.

◆ XHCI_OP_PORTHLPMC

#define XHCI_OP_PORTHLPMC (   port)    ( 0x40c - 0x10 + ( (port) << 4 ) )

Port hardware link power management control register.

Definition at line 292 of file xhci.h.

◆ XHCI_RUN_ERSTSZ

#define XHCI_RUN_ERSTSZ (   intr)    ( 0x28 + ( (intr) << 5 ) )

Event ring segment table size register.

Definition at line 295 of file xhci.h.

◆ XHCI_RUN_ERSTBA

#define XHCI_RUN_ERSTBA (   intr)    ( 0x30 + ( (intr) << 5 ) )

Event ring segment table base address register.

Definition at line 298 of file xhci.h.

◆ XHCI_RUN_ERDP

#define XHCI_RUN_ERDP (   intr)    ( 0x38 + ( (intr) << 5 ) )

Event ring dequeue pointer register.

Definition at line 301 of file xhci.h.

◆ XHCI_TRB_C

#define XHCI_TRB_C   0x01

Transfer request block cycle bit flag.

Definition at line 328 of file xhci.h.

◆ XHCI_TRB_TC

#define XHCI_TRB_TC   0x02

Transfer request block toggle cycle bit flag.

Definition at line 331 of file xhci.h.

◆ XHCI_TRB_CH

#define XHCI_TRB_CH   0x10

Transfer request block chain flag.

Definition at line 334 of file xhci.h.

◆ XHCI_TRB_IOC

#define XHCI_TRB_IOC   0x20

Transfer request block interrupt on completion flag.

Definition at line 337 of file xhci.h.

◆ XHCI_TRB_IDT

#define XHCI_TRB_IDT   0x40

Transfer request block immediate data flag.

Definition at line 340 of file xhci.h.

◆ XHCI_TRB_TYPE

#define XHCI_TRB_TYPE (   type)    ( (type) << 2 )

Transfer request block type.

Definition at line 343 of file xhci.h.

◆ XHCI_TRB_TYPE_MASK

#define XHCI_TRB_TYPE_MASK   XHCI_TRB_TYPE ( 0x3f )

Transfer request block type mask.

Definition at line 346 of file xhci.h.

◆ XHCI_TRB_NORMAL

#define XHCI_TRB_NORMAL   XHCI_TRB_TYPE ( 1 )

A normal transfer request block.

Definition at line 363 of file xhci.h.

◆ XHCI_TD_SIZE

#define XHCI_TD_SIZE (   remaining)    ( ( ( (remaining) <= 0xf ) ? remaining : 0xf ) << 17 )

Construct TD size field.

Definition at line 366 of file xhci.h.

◆ XHCI_TRB_SETUP

#define XHCI_TRB_SETUP   XHCI_TRB_TYPE ( 2 )

A setup stage transfer request block.

Definition at line 386 of file xhci.h.

◆ XHCI_SETUP_IN

#define XHCI_SETUP_IN   3

Setup stage input data direction.

Definition at line 389 of file xhci.h.

◆ XHCI_SETUP_OUT

#define XHCI_SETUP_OUT   2

Setup stage output data direction.

Definition at line 392 of file xhci.h.

◆ XHCI_TRB_DATA

#define XHCI_TRB_DATA   XHCI_TRB_TYPE ( 3 )

A data stage transfer request block.

Definition at line 411 of file xhci.h.

◆ XHCI_DATA_IN

#define XHCI_DATA_IN   0x01

Input data direction.

Definition at line 414 of file xhci.h.

◆ XHCI_DATA_OUT

#define XHCI_DATA_OUT   0x00

Output data direction.

Definition at line 417 of file xhci.h.

◆ XHCI_TRB_STATUS

#define XHCI_TRB_STATUS   XHCI_TRB_TYPE ( 4 )

A status stage transfer request block.

Definition at line 436 of file xhci.h.

◆ XHCI_STATUS_IN

#define XHCI_STATUS_IN   0x01

Input status direction.

Definition at line 439 of file xhci.h.

◆ XHCI_STATUS_OUT

#define XHCI_STATUS_OUT   0x00

Output status direction.

Definition at line 442 of file xhci.h.

◆ XHCI_TRB_LINK

#define XHCI_TRB_LINK   XHCI_TRB_TYPE ( 6 )

A link transfer request block.

Definition at line 459 of file xhci.h.

◆ XHCI_TRB_NOP

#define XHCI_TRB_NOP   XHCI_TRB_TYPE ( 8 )

A no-op transfer request block.

Definition at line 462 of file xhci.h.

◆ XHCI_TRB_ENABLE_SLOT

#define XHCI_TRB_ENABLE_SLOT   XHCI_TRB_TYPE ( 9 )

An enable slot transfer request block.

Definition at line 481 of file xhci.h.

◆ XHCI_TRB_DISABLE_SLOT

#define XHCI_TRB_DISABLE_SLOT   XHCI_TRB_TYPE ( 10 )

A disable slot transfer request block.

Definition at line 500 of file xhci.h.

◆ XHCI_TRB_ADDRESS_DEVICE

#define XHCI_TRB_ADDRESS_DEVICE   XHCI_TRB_TYPE ( 11 )

An address device transfer request block.

Definition at line 519 of file xhci.h.

◆ XHCI_TRB_CONFIGURE_ENDPOINT

#define XHCI_TRB_CONFIGURE_ENDPOINT   XHCI_TRB_TYPE ( 12 )

A configure endpoint transfer request block.

Definition at line 522 of file xhci.h.

◆ XHCI_TRB_EVALUATE_CONTEXT

#define XHCI_TRB_EVALUATE_CONTEXT   XHCI_TRB_TYPE ( 13 )

An evaluate context transfer request block.

Definition at line 525 of file xhci.h.

◆ XHCI_TRB_RESET_ENDPOINT

#define XHCI_TRB_RESET_ENDPOINT   XHCI_TRB_TYPE ( 14 )

A reset endpoint transfer request block.

Definition at line 544 of file xhci.h.

◆ XHCI_TRB_STOP_ENDPOINT

#define XHCI_TRB_STOP_ENDPOINT   XHCI_TRB_TYPE ( 15 )

A stop endpoint transfer request block.

Definition at line 563 of file xhci.h.

◆ XHCI_TRB_SET_TR_DEQUEUE_POINTER

#define XHCI_TRB_SET_TR_DEQUEUE_POINTER   XHCI_TRB_TYPE ( 16 )

A set transfer ring dequeue pointer transfer request block.

Definition at line 582 of file xhci.h.

◆ XHCI_TRB_NOP_CMD

#define XHCI_TRB_NOP_CMD   XHCI_TRB_TYPE ( 23 )

A no-op command transfer request block.

Definition at line 585 of file xhci.h.

◆ XHCI_TRB_TRANSFER

#define XHCI_TRB_TRANSFER   XHCI_TRB_TYPE ( 32 )

A transfer event transfer request block.

Definition at line 608 of file xhci.h.

◆ XHCI_TRB_COMPLETE

#define XHCI_TRB_COMPLETE   XHCI_TRB_TYPE ( 33 )

A command completion event transfer request block.

Definition at line 629 of file xhci.h.

◆ XHCI_TRB_PORT_STATUS

#define XHCI_TRB_PORT_STATUS   XHCI_TRB_TYPE ( 34 )

A port status change transfer request block.

Definition at line 660 of file xhci.h.

◆ XHCI_TRB_HOST_CONTROLLER

#define XHCI_TRB_HOST_CONTROLLER   XHCI_TRB_TYPE ( 37 )

A port status change transfer request block.

Definition at line 679 of file xhci.h.

◆ XHCI_SLOT_INFO

#define XHCI_SLOT_INFO (   entries,
  hub,
  speed,
  route 
)    ( ( (entries) << 27 ) | ( (hub) << 26 ) | ( (speed) << 20 ) | (route) )

Construct slot context device info.

Definition at line 764 of file xhci.h.

◆ XHCI_ENDPOINT_STATE_MASK

#define XHCI_ENDPOINT_STATE_MASK   0x07

Endpoint state mask.

Definition at line 808 of file xhci.h.

◆ XHCI_EP_TYPE

#define XHCI_EP_TYPE (   type)    ( (type) << 3 )

Endpoint type.

Definition at line 811 of file xhci.h.

◆ XHCI_EP_TYPE_CONTROL

#define XHCI_EP_TYPE_CONTROL   XHCI_EP_TYPE ( 4 )

Control endpoint type.

Definition at line 814 of file xhci.h.

◆ XHCI_EP_TYPE_IN

#define XHCI_EP_TYPE_IN   XHCI_EP_TYPE ( 4 )

Input endpoint type.

Definition at line 817 of file xhci.h.

◆ XHCI_EP_TYPE_PERIODIC

#define XHCI_EP_TYPE_PERIODIC   XHCI_EP_TYPE ( 1 )

Periodic endpoint type.

Definition at line 820 of file xhci.h.

◆ XHCI_EP_DCS

#define XHCI_EP_DCS   0x00000001UL

Endpoint dequeue cycle state.

Definition at line 823 of file xhci.h.

◆ XHCI_EP0_TRB_LEN

#define XHCI_EP0_TRB_LEN   8

Control endpoint average TRB length.

Definition at line 826 of file xhci.h.

◆ XHCI_DBVAL

#define XHCI_DBVAL (   target,
  stream 
)    ( (target) | ( (stream) << 16 ) )

Calculate doorbell register value.

Parameters
targetDoorbell target
streamDoorbell stream ID
Return values
dbvalDoorbell register value

Definition at line 888 of file xhci.h.

◆ XHCI_CTX_SLOT

#define XHCI_CTX_SLOT   0

Slot context index.

Definition at line 942 of file xhci.h.

◆ XHCI_CTX

#define XHCI_CTX (   address)
Value:
( (address) ? ( ( ( (address) & 0x0f ) << 1 ) | \
( ( (address) & 0x80 ) >> 7 ) ) : 1 )
uint64_t address
Base address.
Definition: ena.h:24

Calculate context index from USB endpoint address.

Definition at line 945 of file xhci.h.

◆ XHCI_CTX_EP0

#define XHCI_CTX_EP0   XHCI_CTX ( 0x00 )

Endpoint zero context index.

Definition at line 950 of file xhci.h.

◆ XHCI_CTX_END

#define XHCI_CTX_END   32

End of contexts.

Definition at line 953 of file xhci.h.

◆ XHCI_DCI

#define XHCI_DCI (   ctx)    ( (ctx) + 0 )

Device context index.

Definition at line 956 of file xhci.h.

◆ XHCI_ICI

#define XHCI_ICI (   ctx)    ( (ctx) + 1 )

Input context index.

Definition at line 959 of file xhci.h.

◆ XHCI_CMD_TRBS_LOG2

#define XHCI_CMD_TRBS_LOG2   2

Number of TRBs (excluding Link TRB) in the command ring.

This is a policy decision.

Definition at line 965 of file xhci.h.

◆ XHCI_EVENT_TRBS_LOG2

#define XHCI_EVENT_TRBS_LOG2   6

Number of TRBs in the event ring.

This is a policy decision.

Definition at line 971 of file xhci.h.

◆ XHCI_TRANSFER_TRBS_LOG2

#define XHCI_TRANSFER_TRBS_LOG2   6

Number of TRBs in a transfer ring.

This is a policy decision.

Definition at line 977 of file xhci.h.

◆ XHCI_USBLEGSUP_MAX_WAIT_MS

#define XHCI_USBLEGSUP_MAX_WAIT_MS   100

Maximum time to wait for BIOS to release ownership.

This is a policy decision.

Definition at line 983 of file xhci.h.

◆ XHCI_STOP_MAX_WAIT_MS

#define XHCI_STOP_MAX_WAIT_MS   100

Maximum time to wait for host controller to stop.

This is a policy decision.

Definition at line 989 of file xhci.h.

◆ XHCI_RESET_MAX_WAIT_MS

#define XHCI_RESET_MAX_WAIT_MS   500

Maximum time to wait for reset to complete.

This is a policy decision.

Definition at line 995 of file xhci.h.

◆ XHCI_COMMAND_MAX_WAIT_MS

#define XHCI_COMMAND_MAX_WAIT_MS   USB_CONTROL_MAX_WAIT_MS

Maximum time to wait for a command to complete.

The "address device" command involves waiting for a response to a USB control transaction, and so we must wait for up to the 5000ms that USB allows for devices to respond to control transactions.

Definition at line 1003 of file xhci.h.

◆ XHCI_COMMAND_ABORT_DELAY_MS

#define XHCI_COMMAND_ABORT_DELAY_MS   500

Time to delay after aborting a command.

This is a policy decision

Definition at line 1009 of file xhci.h.

◆ XHCI_PORT_RESET_MAX_WAIT_MS

#define XHCI_PORT_RESET_MAX_WAIT_MS   500

Maximum time to wait for a port reset to complete.

This is a policy decision.

Definition at line 1015 of file xhci.h.

◆ XHCI_PCH

#define XHCI_PCH   0x0001

Intel PCH quirk flag.

Definition at line 1026 of file xhci.h.

◆ XHCI_PCH_XUSB2PR

#define XHCI_PCH_XUSB2PR   0xd0

Intel PCH USB2 port routing register.

Definition at line 1029 of file xhci.h.

◆ XHCI_PCH_XUSB2PRM

#define XHCI_PCH_XUSB2PRM   0xd4

Intel PCH USB2 port routing mask register.

Definition at line 1032 of file xhci.h.

◆ XHCI_PCH_USB3PSSEN

#define XHCI_PCH_USB3PSSEN   0xd8

Intel PCH SuperSpeed enable register.

Definition at line 1035 of file xhci.h.

◆ XHCI_PCH_USB3PRM

#define XHCI_PCH_USB3PRM   0xdc

Intel PCH USB3 port routing mask register.

Definition at line 1038 of file xhci.h.

◆ XHCI_BAD_PSIV

#define XHCI_BAD_PSIV   0x0002

Invalid protocol speed ID values quirk.

Definition at line 1041 of file xhci.h.

Enumeration Type Documentation

◆ xhci_default_psi_value

Default PSI values.

Enumerator
XHCI_SPEED_FULL 

Full speed (12Mbps)

XHCI_SPEED_LOW 

Low speed (1.5Mbps)

XHCI_SPEED_HIGH 

High speed (480Mbps)

XHCI_SPEED_SUPER 

Super speed.

Definition at line 142 of file xhci.h.

142  {
143  /** Full speed (12Mbps) */
144  XHCI_SPEED_FULL = 1,
145  /** Low speed (1.5Mbps) */
146  XHCI_SPEED_LOW = 2,
147  /** High speed (480Mbps) */
148  XHCI_SPEED_HIGH = 3,
149  /** Super speed */
150  XHCI_SPEED_SUPER = 4,
151 };
Full speed (12Mbps)
Definition: xhci.h:144
Super speed.
Definition: xhci.h:150
Low speed (1.5Mbps)
Definition: xhci.h:146
High speed (480Mbps)
Definition: xhci.h:148

◆ xhci_completion_code

xHCI completion codes

Enumerator
XHCI_CMPLT_SUCCESS 

Success.

XHCI_CMPLT_SHORT 

Short packet.

XHCI_CMPLT_CMD_STOPPED 

Command ring stopped.

Definition at line 632 of file xhci.h.

632  {
633  /** Success */
634  XHCI_CMPLT_SUCCESS = 1,
635  /** Short packet */
636  XHCI_CMPLT_SHORT = 13,
637  /** Command ring stopped */
639 };
Short packet.
Definition: xhci.h:636
Success.
Definition: xhci.h:634
Command ring stopped.
Definition: xhci.h:638

◆ xhci_endpoint_state

Endpoint states.

Enumerator
XHCI_ENDPOINT_DISABLED 

Endpoint is disabled.

XHCI_ENDPOINT_RUNNING 

Endpoint is running.

XHCI_ENDPOINT_HALTED 

Endpoint is halted due to a USB Halt condition.

XHCI_ENDPOINT_STOPPED 

Endpoint is stopped.

XHCI_ENDPOINT_ERROR 

Endpoint is halted due to a TRB error.

Definition at line 794 of file xhci.h.

794  {
795  /** Endpoint is disabled */
797  /** Endpoint is running */
799  /** Endpoint is halted due to a USB Halt condition */
801  /** Endpoint is stopped */
803  /** Endpoint is halted due to a TRB error */
805 };
Endpoint is halted due to a TRB error.
Definition: xhci.h:804
Endpoint is halted due to a USB Halt condition.
Definition: xhci.h:800
Endpoint is disabled.
Definition: xhci.h:796
Endpoint is stopped.
Definition: xhci.h:802
Endpoint is running.
Definition: xhci.h:798

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xhci_ring_fill()

static unsigned int xhci_ring_fill ( struct xhci_trb_ring ring)
inlinestatic

Calculate space used in TRB ring.

Parameters
ringTRB ring
Return values
fillNumber of entries used

Definition at line 897 of file xhci.h.

897  {
898 
899  return ( ring->prod - ring->cons );
900 }
unsigned int cons
Consumer counter.
Definition: xhci.h:843
unsigned int prod
Producer counter.
Definition: xhci.h:841

References xhci_trb_ring::cons, and xhci_trb_ring::prod.

Referenced by xhci_dequeue(), xhci_endpoint_close(), and xhci_ring_remaining().

◆ xhci_ring_remaining()

static unsigned int xhci_ring_remaining ( struct xhci_trb_ring ring)
inlinestatic

Calculate space remaining in TRB ring.

Parameters
ringTRB ring
Return values
remainingNumber of entries remaining

xHCI does not allow us to completely fill a ring; there must be at least one free entry (excluding the Link TRB).

Definition at line 912 of file xhci.h.

912  {
913  unsigned int fill = xhci_ring_fill ( ring );
914 
915  /* We choose to utilise rings with ( 2^n + 1 ) entries, with
916  * the final entry being a Link TRB. The maximum fill level
917  * is therefore
918  *
919  * ( ( 2^n + 1 ) - 1 (Link TRB) - 1 (one slot always empty)
920  * == ( 2^n - 1 )
921  *
922  * which is therefore equal to the ring mask.
923  */
924  assert ( fill <= ring->mask );
925  return ( ring->mask - fill );
926 }
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:897
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int mask
Ring counter mask.
Definition: xhci.h:847
static int fill
Definition: string.h:208

References assert(), fill, xhci_trb_ring::mask, and xhci_ring_fill().

Referenced by xhci_enqueue(), and xhci_enqueue_multi().

◆ xhci_ring_consumed()

static physaddr_t xhci_ring_consumed ( struct xhci_trb_ring ring)
inlinestatic

Calculate physical address of most recently consumed TRB.

Parameters
ringTRB ring
Return values
trbTRB physical address

Definition at line 935 of file xhci.h.

935  {
936  unsigned int index = ( ( ring->cons - 1 ) & ring->mask );
937 
938  return virt_to_phys ( &ring->trb[index] );
939 }
unsigned int cons
Consumer counter.
Definition: xhci.h:843
long index
Definition: bigint.h:62
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
unsigned int mask
Ring counter mask.
Definition: xhci.h:847

References xhci_trb_ring::cons, index, xhci_trb_ring::mask, and xhci_trb_ring::trb.

Referenced by xhci_complete(), and xhci_transfer().

◆ xhci_init()

void xhci_init ( struct xhci_device xhci)

Initialise device.

Parameters
xhcixHCI device

Definition at line 263 of file xhci.c.

263  {
264  uint32_t hcsparams1;
265  uint32_t hcsparams2;
266  uint32_t hccparams1;
267  uint32_t pagesize;
268  size_t caplength;
269  size_t rtsoff;
270  size_t dboff;
271 
272  /* Set device name */
273  xhci->name = xhci->dev->name;
274 
275  /* Locate capability, operational, runtime, and doorbell registers */
276  xhci->cap = xhci->regs;
277  caplength = readb ( xhci->cap + XHCI_CAP_CAPLENGTH );
278  rtsoff = readl ( xhci->cap + XHCI_CAP_RTSOFF );
279  dboff = readl ( xhci->cap + XHCI_CAP_DBOFF );
280  xhci->op = ( xhci->cap + caplength );
281  xhci->run = ( xhci->cap + rtsoff );
282  xhci->db = ( xhci->cap + dboff );
283  DBGC2 ( xhci, "XHCI %s cap %08lx op %08lx run %08lx db %08lx\n",
284  xhci->name, virt_to_phys ( xhci->cap ),
285  virt_to_phys ( xhci->op ), virt_to_phys ( xhci->run ),
286  virt_to_phys ( xhci->db ) );
287 
288  /* Read structural parameters 1 */
289  hcsparams1 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS1 );
290  xhci->slots = XHCI_HCSPARAMS1_SLOTS ( hcsparams1 );
291  xhci->intrs = XHCI_HCSPARAMS1_INTRS ( hcsparams1 );
292  xhci->ports = XHCI_HCSPARAMS1_PORTS ( hcsparams1 );
293  DBGC ( xhci, "XHCI %s has %d slots %d intrs %d ports\n",
294  xhci->name, xhci->slots, xhci->intrs, xhci->ports );
295 
296  /* Read structural parameters 2 */
297  hcsparams2 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS2 );
298  xhci->scratch.count = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
299  DBGC2 ( xhci, "XHCI %s needs %d scratchpads\n",
300  xhci->name, xhci->scratch.count );
301 
302  /* Read capability parameters 1 */
303  hccparams1 = readl ( xhci->cap + XHCI_CAP_HCCPARAMS1 );
304  xhci->addr64 = XHCI_HCCPARAMS1_ADDR64 ( hccparams1 );
305  xhci->csz_shift = XHCI_HCCPARAMS1_CSZ_SHIFT ( hccparams1 );
306  xhci->xecp = XHCI_HCCPARAMS1_XECP ( hccparams1 );
307 
308  /* Read page size */
309  pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
310  xhci->pagesize = XHCI_PAGESIZE ( pagesize );
311  assert ( xhci->pagesize != 0 );
312  assert ( ( ( xhci->pagesize ) & ( xhci->pagesize - 1 ) ) == 0 );
313  DBGC2 ( xhci, "XHCI %s page size %zd bytes\n",
314  xhci->name, xhci->pagesize );
315 
316  /* Configure DMA device */
317  if ( xhci->dma && xhci->addr64 )
318  dma_set_mask_64bit ( xhci->dma );
319 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
unsigned int ports
Number of ports.
Definition: xhci.h:1092
void * run
Runtime registers.
Definition: xhci.h:1083
void * regs
Registers.
Definition: xhci.h:1068
#define XHCI_HCSPARAMS1_PORTS(params)
Number of ports.
Definition: xhci.h:48
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
struct device * dev
Underlying hardware device.
Definition: xhci.h:1070
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:78
#define XHCI_HCSPARAMS1_INTRS(params)
Number of interrupters.
Definition: xhci.h:45
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
Definition: dma.h:466
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1054
unsigned int slots
Number of device slots.
Definition: xhci.h:1088
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1111
#define XHCI_CAP_RTSOFF
Runtime register space offset.
Definition: xhci.h:73
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * name
Name.
Definition: xhci.h:1074
#define XHCI_HCCPARAMS1_XECP(params)
xHCI extended capabilities pointer
Definition: xhci.h:67
#define XHCI_HCCPARAMS1_ADDR64(params)
64-bit addressing capability
Definition: xhci.h:61
#define XHCI_CAP_CAPLENGTH
Capability register length.
Definition: xhci.h:33
unsigned int intrs
Number of interrupters.
Definition: xhci.h:1090
#define XHCI_HCSPARAMS1_SLOTS(params)
Number of device slots.
Definition: xhci.h:42
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1099
#define XHCI_OP_PAGESIZE
Page size register.
Definition: xhci.h:169
int addr64
64-bit addressing capability
Definition: xhci.h:1095
#define XHCI_PAGESIZE(pagesize)
Page size.
Definition: xhci.h:172
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1102
#define XHCI_CAP_DBOFF
Doorbell offset.
Definition: xhci.h:70
#define XHCI_HCCPARAMS1_CSZ_SHIFT(params)
Context size shift.
Definition: xhci.h:64
#define XHCI_CAP_HCSPARAMS1
Structural parameters 1.
Definition: xhci.h:39
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
#define XHCI_CAP_HCCPARAMS1
Capability parameters.
Definition: xhci.h:58
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1097
void * db
Doorbell registers.
Definition: xhci.h:1085
#define XHCI_HCSPARAMS2_SCRATCHPADS(params)
Number of page-sized scratchpad buffers.
Definition: xhci.h:54
#define XHCI_CAP_HCSPARAMS2
Structural parameters 2.
Definition: xhci.h:51
void * op
Operational registers.
Definition: xhci.h:1081

References xhci_device::addr64, assert(), xhci_device::cap, xhci_scratchpad::count, xhci_device::csz_shift, xhci_device::db, DBGC, DBGC2, xhci_device::dev, xhci_device::dma, dma_set_mask_64bit(), xhci_device::intrs, device::name, xhci_device::name, xhci_device::op, xhci_device::pagesize, xhci_device::ports, readb(), readl(), xhci_device::regs, xhci_device::run, xhci_device::scratch, xhci_device::slots, xhci_device::xecp, XHCI_CAP_CAPLENGTH, XHCI_CAP_DBOFF, XHCI_CAP_HCCPARAMS1, XHCI_CAP_HCSPARAMS1, XHCI_CAP_HCSPARAMS2, XHCI_CAP_RTSOFF, XHCI_HCCPARAMS1_ADDR64, XHCI_HCCPARAMS1_CSZ_SHIFT, XHCI_HCCPARAMS1_XECP, XHCI_HCSPARAMS1_INTRS, XHCI_HCSPARAMS1_PORTS, XHCI_HCSPARAMS1_SLOTS, XHCI_HCSPARAMS2_SCRATCHPADS, XHCI_OP_PAGESIZE, and XHCI_PAGESIZE.

Referenced by dwusb_probe(), and xhci_probe().

◆ xhci_register()

int xhci_register ( struct xhci_device xhci)

Register xHCI controller.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 3318 of file xhci.c.

3318  {
3319  struct usb_port *port;
3320  unsigned int i;
3321  int rc;
3322 
3323  /* Reset device */
3324  if ( ( rc = xhci_reset ( xhci ) ) != 0 )
3325  goto err_reset;
3326 
3327  /* Allocate USB bus */
3328  xhci->bus = alloc_usb_bus ( xhci->dev, xhci->ports, XHCI_MTU,
3329  &xhci_operations );
3330  if ( ! xhci->bus ) {
3331  rc = -ENOMEM;
3332  goto err_alloc_bus;
3333  }
3334  usb_bus_set_hostdata ( xhci->bus, xhci );
3335  usb_hub_set_drvdata ( xhci->bus->hub, xhci );
3336 
3337  /* Set port protocols */
3338  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3339  port = usb_port ( xhci->bus->hub, i );
3340  port->protocol = xhci_port_protocol ( xhci, i );
3341  }
3342 
3343  /* Register USB bus */
3344  if ( ( rc = register_usb_bus ( xhci->bus ) ) != 0 )
3345  goto err_register;
3346 
3347  return 0;
3348 
3349  unregister_usb_bus ( xhci->bus );
3350  err_register:
3351  free_usb_bus ( xhci->bus );
3352  err_alloc_bus:
3353  xhci_reset ( xhci );
3354  err_reset:
3355  return rc;
3356 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int ports
Number of ports.
Definition: xhci.h:1092
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
Definition: usb.c:2094
struct device * dev
Underlying hardware device.
Definition: xhci.h:1070
struct usb_bus * bus
USB bus.
Definition: xhci.h:1126
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1050
A USB port.
Definition: usb.h:812
#define ENOMEM
Not enough space.
Definition: errno.h:534
u8 port
Port number.
Definition: CIB_PRM.h:31
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2170
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:27
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1141
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2130
static unsigned int xhci_port_protocol(struct xhci_device *xhci, unsigned int port)
Find port protocol.
Definition: xhci.c:705
struct usb_hub * hub
Root hub.
Definition: usb.h:994
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:936
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:959
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2194
static struct usb_host_operations xhci_operations
USB host controller operations.
Definition: xhci.c:3279

References alloc_usb_bus(), xhci_device::bus, xhci_device::dev, ENOMEM, free_usb_bus(), usb_bus::hub, port, xhci_device::ports, rc, register_usb_bus(), unregister_usb_bus(), usb_bus_set_hostdata(), usb_hub_set_drvdata(), usb_port(), XHCI_MTU, xhci_operations, xhci_port_protocol(), and xhci_reset().

Referenced by dwusb_probe(), and xhci_probe().

◆ xhci_unregister()

void xhci_unregister ( struct xhci_device xhci)

Unregister xHCI controller.

Parameters
xhcixHCI device

Definition at line 3363 of file xhci.c.

3363  {
3364  struct usb_bus *bus = xhci->bus;
3365 
3366  /* Unregister and free USB bus */
3367  unregister_usb_bus ( bus );
3368  free_usb_bus ( bus );
3369 
3370  /* Reset device */
3371  xhci_reset ( xhci );
3372 }
struct usb_bus * bus
USB bus.
Definition: xhci.h:1126
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2170
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1141
A USB bus.
Definition: usb.h:965
uint8_t bus
Bus.
Definition: edd.h:14
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2194

References bus, xhci_device::bus, free_usb_bus(), unregister_usb_bus(), and xhci_reset().

Referenced by dwusb_probe(), dwusb_remove(), xhci_probe(), and xhci_remove().