iPXE
uhci.h File Reference

USB Universal Host Controller Interface (UHCI) driver. More...

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

Go to the source code of this file.

Data Structures

struct  uhci_frame_list
 A frame list. More...
struct  uhci_transfer_descriptor
 A transfer descriptor. More...
struct  uhci_queue_head
 A queue head. More...
struct  uhci_transfer
 A single UHCI transfer. More...
struct  uhci_ring
 A transfer ring. More...
struct  uhci_device
 A UHCI device. More...
struct  uhci_endpoint
 A UHCI endpoint. More...

Macros

#define UHCI_ALIGN   16
 Minimum alignment required for data structures.
#define UHCI_PORTS   2
 Number of ports.
#define UHCI_MTU   1280
 Maximum transfer size.
#define UHCI_BAR_SIZE   0x14
 I/O BAR size.
#define UHCI_USBCMD   0x00
 USB command register.
#define UHCI_USBCMD_MAX64   0x0080
 Max packet is 64 bytes.
#define UHCI_USBCMD_HCRESET   0x0002
 Host controller reset.
#define UHCI_USBCMD_RUN   0x0001
 Run/stop.
#define UHCI_USBSTS   0x02
 USB status register.
#define UHCI_USBSTS_HCHALTED   0x0020
 Host controller halted.
#define UHCI_USBSTS_USBINT   0x0001
 USB interrupt.
#define UHCI_FLBASEADD   0x08
 Frame list base address register.
#define UHCI_PORTSC(port)
 Port status and control register.
#define UHCI_PORTSC_PR   0x0200
 Port reset.
#define UHCI_PORTSC_LS   0x0100
 Low-speed device attached.
#define UHCI_PORTSC_PEC   0x0008
 Port enabled/disabled change.
#define UHCI_PORTSC_PED   0x0004
 Port enabled.
#define UHCI_PORTSC_CSC   0x0002
 Connect status change.
#define UHCI_PORTSC_CCS   0x0001
 Current connect status.
#define UHCI_PORTSC_CHANGE   ( UHCI_PORTSC_CSC | UHCI_PORTSC_PEC )
 Port status change mask.
#define UHCI_LINK_DEPTH_FIRST   0x00000004UL
 Depth-first processing.
#define UHCI_LINK_TYPE_QH   0x00000002UL
 Queue head type.
#define UHCI_LINK_TERMINATE   0x00000001UL
 List terminator.
#define UHCI_FRAMES   1024
 Number of frames in frame list.
#define UHCI_LEN_MASK   0x7ff
 Length mask.
#define UHCI_ACTUAL_LEN(actual)
 Actual length.
#define UHCI_STATUS_ACTIVE   0x80
 Active.
#define UHCI_STATUS_STALLED   0x40
 Stalled.
#define UHCI_STATUS_BUFFER   0x20
 Data buffer error.
#define UHCI_STATUS_BABBLE   0x10
 Babble detected.
#define UHCI_STATUS_NAK   0x08
 NAK received.
#define UHCI_STATUS_CRC_TIMEOUT   0x04
 CRC/timeout error.
#define UHCI_STATUS_BITSTUFF   0x02
 Bitstuff error.
#define UHCI_FL_SPD   0x20
 Short packet detect.
#define UHCI_FL_CERR(count)
 Error counter.
#define UHCI_FL_CERR_MAX   UHCI_FL_CERR ( 3 )
 Error counter maximum value.
#define UHCI_FL_LS   0x04
 Low speed device.
#define UHCI_FL_IOC   0x01
 Interrupt on completion.
#define UHCI_CONTROL_PID(pid)
 Packet ID.
#define UHCI_CONTROL_PID_MASK   UHCI_CONTROL_PID ( 0xff )
 Packet ID mask.
#define UHCI_CONTROL_DEVICE(address)
 Device address.
#define UHCI_CONTROL_ENDPOINT(address)
 Endpoint address.
#define UHCI_CONTROL_TOGGLE   ( 1 << 19 )
 Data toggle.
#define UHCI_CONTROL_LEN(len)
 Data length.
#define UHCI_DATA_PACKET(control)
 Check for data packet.
#define UHCI_SHORT_PACKET(control, actual)
 Check for short packet.
#define UHCI_USBLEGSUP   0xc0
 USB legacy support register (in PCI configuration space)
#define UHCI_USBLEGSUP_DEFAULT   0x2000
 USB legacy support default value.
#define UHCI_RING_COUNT   16
 Number of transfer descriptors in a ring.
#define UHCI_STOP_MAX_WAIT_MS   100
 Maximum time to wait for host controller to stop.
#define UHCI_RESET_MAX_WAIT_MS   500
 Maximum time to wait for reset to complete.
#define UHCI_PORT_ENABLE_MAX_WAIT_MS   500
 Maximum time to wait for a port to be enabled.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static unsigned int uhci_ring_fill (struct uhci_ring *ring)
 Calculate space used in transfer ring.
static unsigned int uhci_ring_remaining (struct uhci_ring *ring)
 Calculate space remaining in transfer ring.

Detailed Description

USB Universal Host Controller Interface (UHCI) driver.

Definition in file uhci.h.

Macro Definition Documentation

◆ UHCI_ALIGN

#define UHCI_ALIGN   16

Minimum alignment required for data structures.

With the exception of the frame list (which is page-aligned), data structures used by UHCI generally require 16-byte alignment.

Definition at line 22 of file uhci.h.

Referenced by uhci_bus_open(), uhci_endpoint_poll(), uhci_enqueue(), and uhci_ring_alloc().

◆ UHCI_PORTS

#define UHCI_PORTS   2

Number of ports.

Definition at line 25 of file uhci.h.

Referenced by uhci_bus_poll(), and uhci_probe().

◆ UHCI_MTU

#define UHCI_MTU   1280

Maximum transfer size.

Definition at line 28 of file uhci.h.

Referenced by uhci_probe().

◆ UHCI_BAR_SIZE

#define UHCI_BAR_SIZE   0x14

I/O BAR size.

Definition at line 31 of file uhci.h.

◆ UHCI_USBCMD

#define UHCI_USBCMD   0x00

USB command register.

Definition at line 34 of file uhci.h.

Referenced by uhci_reset(), uhci_run(), and uhci_stop().

◆ UHCI_USBCMD_MAX64

#define UHCI_USBCMD_MAX64   0x0080

Max packet is 64 bytes.

Definition at line 37 of file uhci.h.

Referenced by uhci_run().

◆ UHCI_USBCMD_HCRESET

#define UHCI_USBCMD_HCRESET   0x0002

Host controller reset.

Definition at line 40 of file uhci.h.

Referenced by uhci_reset().

◆ UHCI_USBCMD_RUN

#define UHCI_USBCMD_RUN   0x0001

Run/stop.

Definition at line 43 of file uhci.h.

Referenced by uhci_run(), and uhci_stop().

◆ UHCI_USBSTS

#define UHCI_USBSTS   0x02

USB status register.

Definition at line 46 of file uhci.h.

Referenced by uhci_stop().

◆ UHCI_USBSTS_HCHALTED

#define UHCI_USBSTS_HCHALTED   0x0020

Host controller halted.

Definition at line 49 of file uhci.h.

Referenced by uhci_stop().

◆ UHCI_USBSTS_USBINT

#define UHCI_USBSTS_USBINT   0x0001

USB interrupt.

Definition at line 52 of file uhci.h.

◆ UHCI_FLBASEADD

#define UHCI_FLBASEADD   0x08

Frame list base address register.

Definition at line 55 of file uhci.h.

Referenced by uhci_bus_open().

◆ UHCI_PORTSC

#define UHCI_PORTSC ( port)
Value:
( 0x0e + ( (port) << 1 ) )
u8 port
Port number.
Definition CIB_PRM.h:3

Port status and control register.

Definition at line 58 of file uhci.h.

Referenced by uhci_root_disable(), uhci_root_enable(), uhci_root_poll(), and uhci_root_speed().

◆ UHCI_PORTSC_PR

#define UHCI_PORTSC_PR   0x0200

Port reset.

Definition at line 61 of file uhci.h.

Referenced by uhci_root_enable().

◆ UHCI_PORTSC_LS

#define UHCI_PORTSC_LS   0x0100

Low-speed device attached.

Definition at line 64 of file uhci.h.

Referenced by uhci_root_speed().

◆ UHCI_PORTSC_PEC

#define UHCI_PORTSC_PEC   0x0008

Port enabled/disabled change.

Definition at line 67 of file uhci.h.

◆ UHCI_PORTSC_PED

#define UHCI_PORTSC_PED   0x0004

Port enabled.

Definition at line 70 of file uhci.h.

Referenced by uhci_root_disable(), and uhci_root_enable().

◆ UHCI_PORTSC_CSC

#define UHCI_PORTSC_CSC   0x0002

Connect status change.

Definition at line 73 of file uhci.h.

Referenced by uhci_root_poll(), and uhci_root_speed().

◆ UHCI_PORTSC_CCS

#define UHCI_PORTSC_CCS   0x0001

Current connect status.

Definition at line 76 of file uhci.h.

Referenced by uhci_root_speed().

◆ UHCI_PORTSC_CHANGE

#define UHCI_PORTSC_CHANGE   ( UHCI_PORTSC_CSC | UHCI_PORTSC_PEC )

Port status change mask.

Definition at line 79 of file uhci.h.

Referenced by uhci_root_poll().

◆ UHCI_LINK_DEPTH_FIRST

#define UHCI_LINK_DEPTH_FIRST   0x00000004UL

Depth-first processing.

Definition at line 82 of file uhci.h.

Referenced by uhci_enqueue().

◆ UHCI_LINK_TYPE_QH

#define UHCI_LINK_TYPE_QH   0x00000002UL

Queue head type.

Definition at line 85 of file uhci.h.

Referenced by uhci_link_qh().

◆ UHCI_LINK_TERMINATE

#define UHCI_LINK_TERMINATE   0x00000001UL

List terminator.

Definition at line 88 of file uhci.h.

Referenced by uhci_async_schedule(), uhci_bus_open(), uhci_endpoint_poll(), uhci_enqueue(), uhci_restart(), and uhci_ring_alloc().

◆ UHCI_FRAMES

#define UHCI_FRAMES   1024

Number of frames in frame list.

Definition at line 91 of file uhci.h.

Referenced by uhci_periodic_schedule().

◆ UHCI_LEN_MASK

#define UHCI_LEN_MASK   0x7ff

Length mask.

Definition at line 116 of file uhci.h.

◆ UHCI_ACTUAL_LEN

#define UHCI_ACTUAL_LEN ( actual)
Value:
( ( (actual) + 1 ) & UHCI_LEN_MASK )
#define UHCI_LEN_MASK
Length mask.
Definition uhci.h:116

Actual length.

Definition at line 119 of file uhci.h.

Referenced by uhci_endpoint_poll().

◆ UHCI_STATUS_ACTIVE

#define UHCI_STATUS_ACTIVE   0x80

Active.

Definition at line 122 of file uhci.h.

Referenced by uhci_describe(), and uhci_endpoint_poll().

◆ UHCI_STATUS_STALLED

#define UHCI_STATUS_STALLED   0x40

Stalled.

Definition at line 125 of file uhci.h.

Referenced by uhci_endpoint_poll().

◆ UHCI_STATUS_BUFFER

#define UHCI_STATUS_BUFFER   0x20

Data buffer error.

Definition at line 128 of file uhci.h.

◆ UHCI_STATUS_BABBLE

#define UHCI_STATUS_BABBLE   0x10

Babble detected.

Definition at line 131 of file uhci.h.

◆ UHCI_STATUS_NAK

#define UHCI_STATUS_NAK   0x08

NAK received.

Definition at line 134 of file uhci.h.

◆ UHCI_STATUS_CRC_TIMEOUT

#define UHCI_STATUS_CRC_TIMEOUT   0x04

CRC/timeout error.

Definition at line 137 of file uhci.h.

◆ UHCI_STATUS_BITSTUFF

#define UHCI_STATUS_BITSTUFF   0x02

Bitstuff error.

Definition at line 140 of file uhci.h.

◆ UHCI_FL_SPD

#define UHCI_FL_SPD   0x20

Short packet detect.

Definition at line 143 of file uhci.h.

Referenced by uhci_describe(), and uhci_endpoint_poll().

◆ UHCI_FL_CERR

#define UHCI_FL_CERR ( count)
Value:
( (count) << 3 )
static unsigned int count
Number of entries.
Definition dwmac.h:220

Error counter.

Definition at line 146 of file uhci.h.

◆ UHCI_FL_CERR_MAX

#define UHCI_FL_CERR_MAX   UHCI_FL_CERR ( 3 )

Error counter maximum value.

Definition at line 149 of file uhci.h.

Referenced by uhci_endpoint_open().

◆ UHCI_FL_LS

#define UHCI_FL_LS   0x04

Low speed device.

Definition at line 152 of file uhci.h.

Referenced by uhci_endpoint_open().

◆ UHCI_FL_IOC

#define UHCI_FL_IOC   0x01

Interrupt on completion.

Definition at line 155 of file uhci.h.

Referenced by uhci_enqueue().

◆ UHCI_CONTROL_PID

#define UHCI_CONTROL_PID ( pid)
Value:
( (pid) << 0 )

Packet ID.

Definition at line 158 of file uhci.h.

Referenced by uhci_describe(), and uhci_is_message().

◆ UHCI_CONTROL_PID_MASK

#define UHCI_CONTROL_PID_MASK   UHCI_CONTROL_PID ( 0xff )

Packet ID mask.

Definition at line 161 of file uhci.h.

Referenced by uhci_is_message().

◆ UHCI_CONTROL_DEVICE

#define UHCI_CONTROL_DEVICE ( address)
Value:
( (address) << 8 )
uint64_t address
Base address.
Definition ena.h:13

Device address.

Definition at line 164 of file uhci.h.

Referenced by uhci_device_address(), and uhci_endpoint_open().

◆ UHCI_CONTROL_ENDPOINT

#define UHCI_CONTROL_ENDPOINT ( address)
Value:
( (address) << 15 )

Endpoint address.

Definition at line 167 of file uhci.h.

Referenced by uhci_endpoint_open().

◆ UHCI_CONTROL_TOGGLE

#define UHCI_CONTROL_TOGGLE   ( 1 << 19 )

Data toggle.

Definition at line 170 of file uhci.h.

Referenced by uhci_describe(), uhci_endpoint_message(), uhci_endpoint_poll(), and uhci_restart().

◆ UHCI_CONTROL_LEN

#define UHCI_CONTROL_LEN ( len)
Value:
( ( ( (len) - 1 ) & UHCI_LEN_MASK ) << 21 )
ring len
Length.
Definition dwmac.h:226

Data length.

Definition at line 173 of file uhci.h.

Referenced by uhci_describe().

◆ UHCI_DATA_PACKET

#define UHCI_DATA_PACKET ( control)
Value:
( ! ( control & 0x04 ) )
uint32_t control
Control.
Definition myson.h:3

Check for data packet.

This check is based on the fact that only USB_PID_SETUP has bit 2 set.

Definition at line 180 of file uhci.h.

Referenced by uhci_endpoint_poll().

◆ UHCI_SHORT_PACKET

#define UHCI_SHORT_PACKET ( control,
actual )
Value:
( ( ( (control) >> 21 ) ^ (actual) ) & UHCI_LEN_MASK )

Check for short packet.

Definition at line 183 of file uhci.h.

183#define UHCI_SHORT_PACKET( control, actual ) \
184 ( ( ( (control) >> 21 ) ^ (actual) ) & UHCI_LEN_MASK )

Referenced by uhci_endpoint_poll().

◆ UHCI_USBLEGSUP

#define UHCI_USBLEGSUP   0xc0

USB legacy support register (in PCI configuration space)

Definition at line 187 of file uhci.h.

Referenced by uhci_probe().

◆ UHCI_USBLEGSUP_DEFAULT

#define UHCI_USBLEGSUP_DEFAULT   0x2000

USB legacy support default value.

Definition at line 190 of file uhci.h.

Referenced by uhci_probe().

◆ UHCI_RING_COUNT

#define UHCI_RING_COUNT   16

Number of transfer descriptors in a ring.

This is a policy decision.

Definition at line 229 of file uhci.h.

Referenced by uhci_dequeue(), uhci_endpoint_poll(), uhci_enqueue(), uhci_restart(), uhci_ring_fill(), uhci_ring_free(), and uhci_ring_remaining().

◆ UHCI_STOP_MAX_WAIT_MS

#define UHCI_STOP_MAX_WAIT_MS   100

Maximum time to wait for host controller to stop.

This is a policy decision.

Definition at line 293 of file uhci.h.

Referenced by uhci_stop().

◆ UHCI_RESET_MAX_WAIT_MS

#define UHCI_RESET_MAX_WAIT_MS   500

Maximum time to wait for reset to complete.

This is a policy decision.

Definition at line 299 of file uhci.h.

Referenced by uhci_reset().

◆ UHCI_PORT_ENABLE_MAX_WAIT_MS

#define UHCI_PORT_ENABLE_MAX_WAIT_MS   500

Maximum time to wait for a port to be enabled.

This is a policy decision.

Definition at line 305 of file uhci.h.

Referenced by uhci_root_enable().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ uhci_ring_fill()

unsigned int uhci_ring_fill ( struct uhci_ring * ring)
inlinestatic

Calculate space used in transfer ring.

Parameters
ringTransfer ring
Return values
fillNumber of entries used

Definition at line 268 of file uhci.h.

268 {
269 unsigned int fill;
270
271 fill = ( ring->prod - ring->cons );
273 return fill;
274}
static int fill
Definition string.h:209
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
unsigned int prod
Producer counter.
Definition uhci.h:234
unsigned int cons
Consumer counter.
Definition uhci.h:236
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition uhci.h:229

References assert, uhci_ring::cons, fill, uhci_ring::prod, and UHCI_RING_COUNT.

Referenced by uhci_dequeue(), uhci_endpoint_close(), uhci_endpoint_poll(), uhci_enqueue(), uhci_restart(), uhci_ring_free(), and uhci_ring_remaining().

◆ uhci_ring_remaining()

unsigned int uhci_ring_remaining ( struct uhci_ring * ring)
inlinestatic

Calculate space remaining in transfer ring.

Parameters
ringTransfer ring
Return values
remainingNumber of entries remaining

Definition at line 283 of file uhci.h.

283 {
284 unsigned int fill = uhci_ring_fill ( ring );
285
286 return ( UHCI_RING_COUNT - fill );
287}
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition uhci.h:268

References fill, UHCI_RING_COUNT, and uhci_ring_fill().

Referenced by uhci_enqueue().