24#define EHCI_MIN_ALIGN 32
34#define EHCI_PAGE_ALIGN 4096
37#define EHCI_BAR PCI_BASE_ADDRESS_0
40#define EHCI_CAP_CAPLENGTH 0x00
43#define EHCI_CAP_HCIVERSION 0x02
46#define EHCI_CAP_HCSPARAMS 0x04
49#define EHCI_HCSPARAMS_PORTS(params) ( ( (params) >> 0 ) & 0x0f )
52#define EHCI_CAP_HCCPARAMS 0x08
55#define EHCI_HCCPARAMS_ADDR64(params) ( ( (params) >> 0 ) & 0x1 )
58#define EHCI_HCCPARAMS_FLSIZE(params) ( ( (params) >> 1 ) & 0x1 )
61#define EHCI_HCCPARAMS_EECP(params) ( ( ( (params) >> 8 ) & 0xff ) )
64#define EHCI_EECP_ID(eecp) ( ( (eecp) >> 0 ) & 0xff )
67#define EHCI_EECP_NEXT(eecp) ( ( ( (eecp) >> 8 ) & 0xff ) )
70#define EHCI_EECP_ID_LEGACY 1
73#define EHCI_USBLEGSUP_BIOS 0x02
76#define EHCI_USBLEGSUP_BIOS_OWNED 0x01
79#define EHCI_USBLEGSUP_OS 0x03
82#define EHCI_USBLEGSUP_OS_OWNED 0x01
85#define EHCI_USBLEGSUP_CTLSTS 0x04
88#define EHCI_OP_USBCMD 0x00
91#define EHCI_USBCMD_RUN 0x00000001UL
94#define EHCI_USBCMD_HCRST 0x00000002UL
97#define EHCI_USBCMD_FLSIZE(flsize) ( (flsize) << 2 )
100#define EHCI_USBCMD_FLSIZE_MASK EHCI_USBCMD_FLSIZE ( 3 )
103#define EHCI_FLSIZE_DEFAULT 0
106#define EHCI_FLSIZE_SMALL 2
109#define EHCI_PERIODIC_FRAMES(flsize) ( 1024 >> (flsize) )
112#define EHCI_USBCMD_PERIODIC 0x00000010UL
115#define EHCI_USBCMD_ASYNC 0x00000020UL
118#define EHCI_USBCMD_ASYNC_ADVANCE 0x000040UL
121#define EHCI_OP_USBSTS 0x04
124#define EHCI_USBSTS_USBINT 0x00000001UL
127#define EHCI_USBSTS_USBERRINT 0x00000002UL
130#define EHCI_USBSTS_PORT 0x00000004UL
133#define EHCI_USBSTS_ROLLOVER 0x00000008UL
136#define EHCI_USBSTS_SYSERR 0x00000010UL
139#define EHCI_USBSTS_ASYNC_ADVANCE 0x00000020UL
142#define EHCI_USBSTS_PERIODIC 0x00004000UL
145#define EHCI_USBSTS_ASYNC 0x00008000UL
148#define EHCI_USBSTS_HCH 0x00001000UL
151#define EHCI_USBSTS_CHANGE \
152 ( EHCI_USBSTS_USBINT | EHCI_USBSTS_USBERRINT | \
153 EHCI_USBSTS_PORT | EHCI_USBSTS_ROLLOVER | \
154 EHCI_USBSTS_SYSERR | EHCI_USBSTS_ASYNC_ADVANCE )
157#define EHCI_OP_USBINTR 0x08
160#define EHCI_OP_FRINDEX 0x0c
163#define EHCI_OP_CTRLDSSEGMENT 0x10
166#define EHCI_OP_PERIODICLISTBASE 0x14
169#define EHCI_OP_ASYNCLISTADDR 0x18
172#define EHCI_OP_CONFIGFLAG 0x40
175#define EHCI_CONFIGFLAG_CF 0x00000001UL
178#define EHCI_OP_PORTSC(port) ( 0x40 + ( (port) << 2 ) )
181#define EHCI_PORTSC_CCS 0x00000001UL
184#define EHCI_PORTSC_CSC 0x00000002UL
187#define EHCI_PORTSC_PED 0x00000004UL
190#define EHCI_PORTSC_PEC 0x00000008UL
193#define EHCI_PORTSC_OCC 0x00000020UL
196#define EHCI_PORTSC_PR 0x00000100UL
199#define EHCI_PORTSC_LINE_STATUS(portsc) ( ( (portsc) >> 10 ) & 0x3 )
202#define EHCI_PORTSC_LINE_STATUS_LOW 0x1
205#define EHCI_PORTSC_PP 0x00001000UL
208#define EHCI_PORTSC_OWNER 0x00002000UL
211#define EHCI_PORTSC_CHANGE \
212 ( EHCI_PORTSC_CSC | EHCI_PORTSC_PEC | EHCI_PORTSC_OCC )
215#define EHCI_LINK_TERMINATE 0x00000001UL
218#define EHCI_LINK_TYPE(type) ( (type) << 1 )
221#define EHCI_LINK_TYPE_QH EHCI_LINK_TYPE ( 1 )
250#define EHCI_STATUS_XACT_ERR 0x08
253#define EHCI_STATUS_BABBLE 0x10
256#define EHCI_STATUS_BUFFER 0x20
259#define EHCI_STATUS_HALTED 0x40
262#define EHCI_STATUS_ACTIVE 0x80
265#define EHCI_FL_PID(code) ( (code) << 0 )
268#define EHCI_FL_PID_OUT EHCI_FL_PID ( 0 )
271#define EHCI_FL_PID_IN EHCI_FL_PID ( 1 )
274#define EHCI_FL_PID_SETUP EHCI_FL_PID ( 2 )
277#define EHCI_FL_CERR( count ) ( (count) << 2 )
280#define EHCI_FL_CERR_MAX EHCI_FL_CERR ( 3 )
283#define EHCI_FL_IOC 0x80
286#define EHCI_LEN_MASK 0x7fff
289#define EHCI_LEN_TOGGLE 0x8000
306#define EHCI_CHR_ADDRESS( address ) ( (address) << 0 )
309#define EHCI_CHR_ENDPOINT( address ) ( ( (address) & 0xf ) << 8 )
312#define EHCI_CHR_EPS( eps ) ( (eps) << 12 )
315#define EHCI_CHR_EPS_FULL EHCI_CHR_EPS ( 0 )
318#define EHCI_CHR_EPS_LOW EHCI_CHR_EPS ( 1 )
321#define EHCI_CHR_EPS_HIGH EHCI_CHR_EPS ( 2 )
324#define EHCI_CHR_TOGGLE 0x00004000UL
327#define EHCI_CHR_HEAD 0x00008000UL
330#define EHCI_CHR_MAX_LEN( len ) ( (len) << 16 )
333#define EHCI_CHR_CONTROL 0x08000000UL
336#define EHCI_CAP_INTR_SCHED( uframe ) ( 1 << ( (uframe) + 0 ) )
339#define EHCI_CAP_SPLIT_SCHED( uframe ) ( 1 << ( (uframe) + 8 ) )
355#define EHCI_CAP_SPLIT_SCHED_DEFAULT \
356 ( EHCI_CAP_SPLIT_SCHED ( 2 ) | EHCI_CAP_SPLIT_SCHED ( 3 ) | \
357 EHCI_CAP_SPLIT_SCHED ( 4 ) | EHCI_CAP_SPLIT_SCHED ( 5 ) | \
358 EHCI_CAP_SPLIT_SCHED ( 6 ) | EHCI_CAP_SPLIT_SCHED ( 7 ) )
361#define EHCI_CAP_TT_HUB( address ) ( (address) << 16 )
364#define EHCI_CAP_TT_PORT( port ) ( (port) << 23 )
367#define EHCI_CAP_MULT( mult ) ( (mult) << 30 )
392#define EHCI_RING_COUNT 64
426#define EHCI_PORT_POWER_DELAY_MS 20
432#define EHCI_DISOWN_DELAY_MS 100
438#define EHCI_USBLEGSUP_MAX_WAIT_MS 100
444#define EHCI_ASYNC_ADVANCE_MAX_WAIT_MS 100
450#define EHCI_STOP_MAX_WAIT_MS 100
456#define EHCI_RESET_MAX_WAIT_MS 500
462#define EHCI_PORT_RESET_MAX_WAIT_MS 500
481#define EHCI_FL_TOGGLE 0x8000
#define assert(condition)
Assert a condition at run-time.
static unsigned int ehci_ring_remaining(struct ehci_ring *ring)
Calculate space remaining in transfer descriptor ring.
unsigned int ehci_companion(struct pci_device *pci)
Locate EHCI companion controller.
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
static unsigned int ehci_ring_fill(struct ehci_ring *ring)
Calculate space used in transfer descriptor ring.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Universal Serial Bus (USB)
unsigned int eecp
EHCI extended capabilities offset.
void * cap
Capability registers.
unsigned int legacy
USB legacy support capability (if present and enabled)
struct list_head endpoints
List of all endpoints.
struct list_head async
Asynchronous schedule.
struct list_head periodic
Periodic schedule.
uint32_t ctrldssegment
Control data structure segment.
int addr64
64-bit addressing capability
unsigned int flsize
Frame list size.
struct ehci_periodic_frame * frame
Periodic frame list.
struct ehci_queue_head * head
Asynchronous queue head.
void * op
Operational registers.
unsigned int ports
Number of ports.
struct usb_bus * bus
USB bus.
struct usb_endpoint * ep
USB endpoint.
struct ehci_device * ehci
EHCI device.
struct ehci_ring ring
Transfer descriptor ring.
struct list_head list
List of all endpoints.
struct list_head schedule
Endpoint schedule.
A periodic frame list entry.
uint32_t link
First queue head.
struct ehci_transfer_descriptor cache
Transfer descriptor cache.
uint32_t link
Horizontal link pointer.
uint32_t cap
Endpoint capabilities.
uint32_t chr
Endpoint characteristics.
uint32_t current
Current transfer descriptor.
A transfer descriptor ring.
unsigned int prod
Producer counter.
size_t residual
Residual untransferred data.
struct ehci_transfer_descriptor * desc
Transfer descriptors.
struct ehci_queue_head * head
Queue head.
struct io_buffer ** iobuf
I/O buffers.
unsigned int cons
Consumer counter.
uint8_t reserved[12]
Reserved.
uint32_t alt
Alternate next transfer descriptor.
uint16_t len
Transfer length.
uint32_t high[5]
Extended buffer pointers (high 32 bits)
uint32_t low[5]
Buffer pointers (low 32 bits)
uint32_t next
Next transfer descriptor.
A doubly-linked list entry (or list head)