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

Functions

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

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 21 of file uhci.h.

◆ UHCI_PORTS

#define UHCI_PORTS   2

Number of ports.

Definition at line 24 of file uhci.h.

◆ UHCI_MTU

#define UHCI_MTU   1280

Maximum transfer size.

Definition at line 27 of file uhci.h.

◆ UHCI_BAR_SIZE

#define UHCI_BAR_SIZE   0x14

I/O BAR size.

Definition at line 30 of file uhci.h.

◆ UHCI_USBCMD

#define UHCI_USBCMD   0x00

USB command register.

Definition at line 33 of file uhci.h.

◆ UHCI_USBCMD_MAX64

#define UHCI_USBCMD_MAX64   0x0080

Max packet is 64 bytes.

Definition at line 36 of file uhci.h.

◆ UHCI_USBCMD_HCRESET

#define UHCI_USBCMD_HCRESET   0x0002

Host controller reset.

Definition at line 39 of file uhci.h.

◆ UHCI_USBCMD_RUN

#define UHCI_USBCMD_RUN   0x0001

Run/stop.

Definition at line 42 of file uhci.h.

◆ UHCI_USBSTS

#define UHCI_USBSTS   0x02

USB status register.

Definition at line 45 of file uhci.h.

◆ UHCI_USBSTS_HCHALTED

#define UHCI_USBSTS_HCHALTED   0x0020

Host controller halted.

Definition at line 48 of file uhci.h.

◆ UHCI_USBSTS_USBINT

#define UHCI_USBSTS_USBINT   0x0001

USB interrupt.

Definition at line 51 of file uhci.h.

◆ UHCI_FLBASEADD

#define UHCI_FLBASEADD   0x08

Frame list base address register.

Definition at line 54 of file uhci.h.

◆ UHCI_PORTSC

#define UHCI_PORTSC (   port)    ( 0x0e + ( (port) << 1 ) )

Port status and control register.

Definition at line 57 of file uhci.h.

◆ UHCI_PORTSC_PR

#define UHCI_PORTSC_PR   0x0200

Port reset.

Definition at line 60 of file uhci.h.

◆ UHCI_PORTSC_LS

#define UHCI_PORTSC_LS   0x0100

Low-speed device attached.

Definition at line 63 of file uhci.h.

◆ UHCI_PORTSC_PEC

#define UHCI_PORTSC_PEC   0x0008

Port enabled/disabled change.

Definition at line 66 of file uhci.h.

◆ UHCI_PORTSC_PED

#define UHCI_PORTSC_PED   0x0004

Port enabled.

Definition at line 69 of file uhci.h.

◆ UHCI_PORTSC_CSC

#define UHCI_PORTSC_CSC   0x0002

Connect status change.

Definition at line 72 of file uhci.h.

◆ UHCI_PORTSC_CCS

#define UHCI_PORTSC_CCS   0x0001

Current connect status.

Definition at line 75 of file uhci.h.

◆ UHCI_PORTSC_CHANGE

#define UHCI_PORTSC_CHANGE   ( UHCI_PORTSC_CSC | UHCI_PORTSC_PEC )

Port status change mask.

Definition at line 78 of file uhci.h.

◆ UHCI_LINK_DEPTH_FIRST

#define UHCI_LINK_DEPTH_FIRST   0x00000004UL

Depth-first processing.

Definition at line 81 of file uhci.h.

◆ UHCI_LINK_TYPE_QH

#define UHCI_LINK_TYPE_QH   0x00000002UL

Queue head type.

Definition at line 84 of file uhci.h.

◆ UHCI_LINK_TERMINATE

#define UHCI_LINK_TERMINATE   0x00000001UL

List terminator.

Definition at line 87 of file uhci.h.

◆ UHCI_FRAMES

#define UHCI_FRAMES   1024

Number of frames in frame list.

Definition at line 90 of file uhci.h.

◆ UHCI_LEN_MASK

#define UHCI_LEN_MASK   0x7ff

Length mask.

Definition at line 115 of file uhci.h.

◆ UHCI_ACTUAL_LEN

#define UHCI_ACTUAL_LEN (   actual)    ( ( (actual) + 1 ) & UHCI_LEN_MASK )

Actual length.

Definition at line 118 of file uhci.h.

◆ UHCI_STATUS_ACTIVE

#define UHCI_STATUS_ACTIVE   0x80

Active.

Definition at line 121 of file uhci.h.

◆ UHCI_STATUS_STALLED

#define UHCI_STATUS_STALLED   0x40

Stalled.

Definition at line 124 of file uhci.h.

◆ UHCI_STATUS_BUFFER

#define UHCI_STATUS_BUFFER   0x20

Data buffer error.

Definition at line 127 of file uhci.h.

◆ UHCI_STATUS_BABBLE

#define UHCI_STATUS_BABBLE   0x10

Babble detected.

Definition at line 130 of file uhci.h.

◆ UHCI_STATUS_NAK

#define UHCI_STATUS_NAK   0x08

NAK received.

Definition at line 133 of file uhci.h.

◆ UHCI_STATUS_CRC_TIMEOUT

#define UHCI_STATUS_CRC_TIMEOUT   0x04

CRC/timeout error.

Definition at line 136 of file uhci.h.

◆ UHCI_STATUS_BITSTUFF

#define UHCI_STATUS_BITSTUFF   0x02

Bitstuff error.

Definition at line 139 of file uhci.h.

◆ UHCI_FL_SPD

#define UHCI_FL_SPD   0x20

Short packet detect.

Definition at line 142 of file uhci.h.

◆ UHCI_FL_CERR

#define UHCI_FL_CERR (   count)    ( (count) << 3 )

Error counter.

Definition at line 145 of file uhci.h.

◆ UHCI_FL_CERR_MAX

#define UHCI_FL_CERR_MAX   UHCI_FL_CERR ( 3 )

Error counter maximum value.

Definition at line 148 of file uhci.h.

◆ UHCI_FL_LS

#define UHCI_FL_LS   0x04

Low speed device.

Definition at line 151 of file uhci.h.

◆ UHCI_FL_IOC

#define UHCI_FL_IOC   0x01

Interrupt on completion.

Definition at line 154 of file uhci.h.

◆ UHCI_CONTROL_PID

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

Packet ID.

Definition at line 157 of file uhci.h.

◆ UHCI_CONTROL_PID_MASK

#define UHCI_CONTROL_PID_MASK   UHCI_CONTROL_PID ( 0xff )

Packet ID mask.

Definition at line 160 of file uhci.h.

◆ UHCI_CONTROL_DEVICE

#define UHCI_CONTROL_DEVICE (   address)    ( (address) << 8 )

Device address.

Definition at line 163 of file uhci.h.

◆ UHCI_CONTROL_ENDPOINT

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

Endpoint address.

Definition at line 166 of file uhci.h.

◆ UHCI_CONTROL_TOGGLE

#define UHCI_CONTROL_TOGGLE   ( 1 << 19 )

Data toggle.

Definition at line 169 of file uhci.h.

◆ UHCI_CONTROL_LEN

#define UHCI_CONTROL_LEN (   len)    ( ( ( (len) - 1 ) & UHCI_LEN_MASK ) << 21 )

Data length.

Definition at line 172 of file uhci.h.

◆ UHCI_DATA_PACKET

#define UHCI_DATA_PACKET (   control)    ( ! ( control & 0x04 ) )

Check for data packet.

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

Definition at line 179 of file uhci.h.

◆ UHCI_SHORT_PACKET

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

Check for short packet.

Definition at line 182 of file uhci.h.

◆ UHCI_USBLEGSUP

#define UHCI_USBLEGSUP   0xc0

USB legacy support register (in PCI configuration space)

Definition at line 186 of file uhci.h.

◆ UHCI_USBLEGSUP_DEFAULT

#define UHCI_USBLEGSUP_DEFAULT   0x2000

USB legacy support default value.

Definition at line 189 of file uhci.h.

◆ UHCI_RING_COUNT

#define UHCI_RING_COUNT   16

Number of transfer descriptors in a ring.

This is a policy decision.

Definition at line 228 of file uhci.h.

◆ 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 292 of file uhci.h.

◆ 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 298 of file uhci.h.

◆ 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 304 of file uhci.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ uhci_ring_fill()

static 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 267 of file uhci.h.

267  {
268  unsigned int fill;
269 
270  fill = ( ring->prod - ring->cons );
271  assert ( fill <= UHCI_RING_COUNT );
272  return fill;
273 }
unsigned int cons
Consumer counter.
Definition: uhci.h:235
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: uhci.h:228
unsigned int prod
Producer counter.
Definition: uhci.h:233
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint8_t fill
Length pair.
Definition: deflate.h:12

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()

static 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 282 of file uhci.h.

282  {
283  unsigned int fill = uhci_ring_fill ( ring );
284 
285  return ( UHCI_RING_COUNT - fill );
286 }
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition: uhci.h:267
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: uhci.h:228
uint8_t fill
Length pair.
Definition: deflate.h:12

References fill, UHCI_RING_COUNT, and uhci_ring_fill().

Referenced by uhci_enqueue().